Greasy Fork is available in English.

LeetCode Toolkit

Find & Save Editorial, Copy problem as Markdown or Download as Jupyter Notebook, Format on Save, Unlock IntelliSense

Ajankohdalta 10.5.2025. Katso uusin versio.

  1. // ==UserScript==
  2. // @name LeetCode Toolkit
  3. // @name:zh-CN LeetCode工具箱
  4. // @namespace https://github.com/eclipher/leetcode-toolkit
  5. // @version 2.5.3
  6. // @author eclipher
  7. // @description Find & Save Editorial, Copy problem as Markdown or Download as Jupyter Notebook, Format on Save, Unlock IntelliSense
  8. // @description:zh-CN 复制题目为 Markdown | 下载为 Jupyter Notebook | 保存时自动格式化 | 免费自动补全
  9. // @license MIT
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  11. // @homepage https://github.com/eclipher/leetcode-toolkit
  12. // @include /https?:\/\/leetcode\.com\/problems\/.*/
  13. // @include /https?:\/\/leetcode\.cn\/problems\/.*/
  14. // @include /https?:\/\/leetcode\.com\/explore\/learn\/card\/.*/
  15. // @exclude *://leetcode.com/problems/*/post-solution/*
  16. // @exclude *://leetcode.cn/problems/*/post-solution/*
  17. // @resource editorials https://raw.githubusercontent.com/akhilkammila/leetcode-screenshotter/refs/heads/main/ReadMe.md
  18. // @connect assets.leetcode.com
  19. // @connect *
  20. // @grant GM_addStyle
  21. // @grant GM_getResourceText
  22. // @grant GM_xmlhttpRequest
  23. // @grant unsafeWindow
  24. // ==/UserScript==
  25.  
  26. (t=>{if(typeof GM_addStyle=="function"){GM_addStyle(t);return}const a=document.createElement("style");a.textContent=t,document.head.append(a)})(' :where(html[dir=ltr]),:where([data-sonner-toaster][dir=ltr]){--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}:where(html[dir=rtl]),:where([data-sonner-toaster][dir=rtl]){--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}:where([data-sonner-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}:where([data-sonner-toaster][data-x-position=right]){right:max(var(--offset),env(safe-area-inset-right))}:where([data-sonner-toaster][data-x-position=left]){left:max(var(--offset),env(safe-area-inset-left))}:where([data-sonner-toaster][data-x-position=center]){left:50%;transform:translate(-50%)}:where([data-sonner-toaster][data-y-position=top]){top:max(var(--offset),env(safe-area-inset-top))}:where([data-sonner-toaster][data-y-position=bottom]){bottom:max(var(--offset),env(safe-area-inset-bottom))}:where([data-sonner-toast]){--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}:where([data-sonner-toast][data-styled=true]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}:where([data-sonner-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast][data-y-position=top]){top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}:where([data-sonner-toast][data-y-position=bottom]){bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}:where([data-sonner-toast]) :where([data-description]){font-weight:400;line-height:1.4;color:inherit}:where([data-sonner-toast]) :where([data-title]){font-weight:500;line-height:1.5;color:inherit}:where([data-sonner-toast]) :where([data-icon]){display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}:where([data-sonner-toast][data-promise=true]) :where([data-icon])>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}:where([data-sonner-toast]) :where([data-icon])>*{flex-shrink:0}:where([data-sonner-toast]) :where([data-icon]) svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}:where([data-sonner-toast]) :where([data-content]){display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}:where([data-sonner-toast]) :where([data-button]):focus-visible{box-shadow:0 0 0 2px #0006}:where([data-sonner-toast]) :where([data-button]):first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}:where([data-sonner-toast]) :where([data-cancel]){color:var(--normal-text);background:#00000014}:where([data-sonner-toast][data-theme=dark]) :where([data-cancel]){background:#ffffff4d}:where([data-sonner-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}:where([data-sonner-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}:where([data-sonner-toast]) :where([data-disabled=true]){cursor:not-allowed}:where([data-sonner-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}:where([data-sonner-toast][data-swiping=true]):before{content:"";position:absolute;left:0;right:0;height:100%;z-index:-1}:where([data-sonner-toast][data-y-position=top][data-swiping=true]):before{bottom:50%;transform:scaleY(3) translateY(50%)}:where([data-sonner-toast][data-y-position=bottom][data-swiping=true]):before{top:50%;transform:scaleY(3) translateY(-50%)}:where([data-sonner-toast][data-swiping=false][data-removed=true]):before{content:"";position:absolute;top:0;right:0;bottom:0;left:0;transform:scaleY(2)}:where([data-sonner-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}:where([data-sonner-toast][data-mounted=true]){--y: translateY(0);opacity:1}:where([data-sonner-toast][data-expanded=false][data-front=false]){--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}:where([data-sonner-toast])>*{transition:opacity .4s}:where([data-sonner-toast][data-expanded=false][data-front=false][data-styled=true])>*{opacity:0}:where([data-sonner-toast][data-visible=false]){opacity:0;pointer-events:none}:where([data-sonner-toast][data-mounted=true][data-expanded=true]){--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}:where([data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]){--y: translateY(calc(var(--lift) * -100%));opacity:0}:where([data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]){--y: translateY( calc(var(--lift) * var(--offset) + var(--lift) * -100%) );opacity:0}:where([data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]){--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}:where([data-sonner-toast][data-removed=true][data-front=false]):before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount, 0px));transition:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation:swipe-out .2s ease-out forwards}@keyframes swipe-out{0%{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount)));opacity:1}to{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount) + var(--lift) * -100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;--mobile-offset: 16px;right:var(--mobile-offset);left:var(--mobile-offset);width:100%}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset)}[data-sonner-toaster][data-y-position=bottom]{bottom:20px}[data-sonner-toaster][data-y-position=top]{top:20px}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset);right:var(--mobile-offset);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 91%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 91%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 100%, 12%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 12%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-rich-colors=true] [data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-theme=dark] [data-sonner-toast][data-type=default] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-rich-colors=true] [data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true] [data-sonner-toast][data-type=info],[data-rich-colors=true] [data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true] [data-sonner-toast][data-type=warning],[data-rich-colors=true] [data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true] [data-sonner-toast][data-type=error],[data-rich-colors=true] [data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;top:0;right:0;bottom:0;left:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}button.svelte-1dnnoz1{color:#fff;background-color:var(--bg, #6c5ce7);box-shadow:0 3px 0 0 var(--shadow, #a29bfe);padding:5px 20px;font-size:.8rem;font-weight:500;border-radius:5px;transition:all ease .1s;display:inline-flex;align-items:center;gap:.25rem;-webkit-user-select:none;user-select:none}button.svelte-1dnnoz1:active{transform:translateY(3px);box-shadow:0 0 0 0 var(--shadow, #a29bfe)}button.svelte-1dnnoz1:disabled{pointer-events:none;opacity:50%}div.svelte-1q3elx8{display:flex;flex-wrap:wrap;gap:.4rem}div.svelte-1ckqqtt{z-index:10} ');
  27.  
  28. (function () {
  29. 'use strict';
  30.  
  31. var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
  32. var __defProp = Object.defineProperty;
  33. var __typeError = (msg) => {
  34. throw TypeError(msg);
  35. };
  36. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  37. var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  38. var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
  39. var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
  40. var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  41. var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
  42. var _a, _site;
  43. const DEV = false;
  44. var is_array = Array.isArray;
  45. var index_of = Array.prototype.indexOf;
  46. var array_from = Array.from;
  47. var define_property = Object.defineProperty;
  48. var get_descriptor = Object.getOwnPropertyDescriptor;
  49. var get_descriptors = Object.getOwnPropertyDescriptors;
  50. var object_prototype = Object.prototype;
  51. var array_prototype = Array.prototype;
  52. var get_prototype_of = Object.getPrototypeOf;
  53. var is_extensible = Object.isExtensible;
  54. function is_function(thing) {
  55. return typeof thing === "function";
  56. }
  57. const noop = () => {
  58. };
  59. function run(fn) {
  60. return fn();
  61. }
  62. function run_all(arr) {
  63. for (var i2 = 0; i2 < arr.length; i2++) {
  64. arr[i2]();
  65. }
  66. }
  67. const DERIVED = 1 << 1;
  68. const EFFECT = 1 << 2;
  69. const RENDER_EFFECT = 1 << 3;
  70. const BLOCK_EFFECT = 1 << 4;
  71. const BRANCH_EFFECT = 1 << 5;
  72. const ROOT_EFFECT = 1 << 6;
  73. const BOUNDARY_EFFECT = 1 << 7;
  74. const UNOWNED = 1 << 8;
  75. const DISCONNECTED = 1 << 9;
  76. const CLEAN = 1 << 10;
  77. const DIRTY = 1 << 11;
  78. const MAYBE_DIRTY = 1 << 12;
  79. const INERT = 1 << 13;
  80. const DESTROYED = 1 << 14;
  81. const EFFECT_RAN = 1 << 15;
  82. const EFFECT_TRANSPARENT = 1 << 16;
  83. const LEGACY_DERIVED_PROP = 1 << 17;
  84. const HEAD_EFFECT = 1 << 19;
  85. const EFFECT_HAS_DERIVED = 1 << 20;
  86. const EFFECT_IS_UPDATING = 1 << 21;
  87. const STATE_SYMBOL = Symbol("$state");
  88. const LEGACY_PROPS = Symbol("legacy props");
  89. const LOADING_ATTR_SYMBOL = Symbol("");
  90. function equals(value) {
  91. return value === this.v;
  92. }
  93. function safe_not_equal(a2, b) {
  94. return a2 != a2 ? b == b : a2 !== b || a2 !== null && typeof a2 === "object" || typeof a2 === "function";
  95. }
  96. function safe_equals(value) {
  97. return !safe_not_equal(value, this.v);
  98. }
  99. function effect_in_teardown(rune) {
  100. {
  101. throw new Error(`https://svelte.dev/e/effect_in_teardown`);
  102. }
  103. }
  104. function effect_in_unowned_derived() {
  105. {
  106. throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
  107. }
  108. }
  109. function effect_orphan(rune) {
  110. {
  111. throw new Error(`https://svelte.dev/e/effect_orphan`);
  112. }
  113. }
  114. function effect_update_depth_exceeded() {
  115. {
  116. throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
  117. }
  118. }
  119. function props_invalid_value(key) {
  120. {
  121. throw new Error(`https://svelte.dev/e/props_invalid_value`);
  122. }
  123. }
  124. function state_descriptors_fixed() {
  125. {
  126. throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
  127. }
  128. }
  129. function state_prototype_fixed() {
  130. {
  131. throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
  132. }
  133. }
  134. function state_unsafe_mutation() {
  135. {
  136. throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
  137. }
  138. }
  139. let legacy_mode_flag = false;
  140. let tracing_mode_flag = false;
  141. function enable_legacy_mode_flag() {
  142. legacy_mode_flag = true;
  143. }
  144. const EACH_ITEM_REACTIVE = 1;
  145. const EACH_INDEX_REACTIVE = 1 << 1;
  146. const EACH_IS_CONTROLLED = 1 << 2;
  147. const EACH_IS_ANIMATED = 1 << 3;
  148. const EACH_ITEM_IMMUTABLE = 1 << 4;
  149. const PROPS_IS_IMMUTABLE = 1;
  150. const PROPS_IS_RUNES = 1 << 1;
  151. const PROPS_IS_UPDATED = 1 << 2;
  152. const PROPS_IS_BINDABLE = 1 << 3;
  153. const PROPS_IS_LAZY_INITIAL = 1 << 4;
  154. const TEMPLATE_FRAGMENT = 1;
  155. const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
  156. const UNINITIALIZED = Symbol();
  157. const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
  158. function lifecycle_outside_component(name) {
  159. {
  160. throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
  161. }
  162. }
  163. let component_context = null;
  164. function set_component_context(context) {
  165. component_context = context;
  166. }
  167. function push(props, runes = false, fn) {
  168. var ctx = component_context = {
  169. p: component_context,
  170. c: null,
  171. d: false,
  172. e: null,
  173. m: false,
  174. s: props,
  175. x: null,
  176. l: null
  177. };
  178. if (legacy_mode_flag && !runes) {
  179. component_context.l = {
  180. s: null,
  181. u: null,
  182. r1: [],
  183. r2: source(false)
  184. };
  185. }
  186. teardown(() => {
  187. ctx.d = true;
  188. });
  189. }
  190. function pop(component2) {
  191. const context_stack_item = component_context;
  192. if (context_stack_item !== null) {
  193. const component_effects = context_stack_item.e;
  194. if (component_effects !== null) {
  195. var previous_effect = active_effect;
  196. var previous_reaction = active_reaction;
  197. context_stack_item.e = null;
  198. try {
  199. for (var i2 = 0; i2 < component_effects.length; i2++) {
  200. var component_effect = component_effects[i2];
  201. set_active_effect(component_effect.effect);
  202. set_active_reaction(component_effect.reaction);
  203. effect(component_effect.fn);
  204. }
  205. } finally {
  206. set_active_effect(previous_effect);
  207. set_active_reaction(previous_reaction);
  208. }
  209. }
  210. component_context = context_stack_item.p;
  211. context_stack_item.m = true;
  212. }
  213. return (
  214. /** @type {T} */
  215. {}
  216. );
  217. }
  218. function is_runes() {
  219. return !legacy_mode_flag || component_context !== null && component_context.l === null;
  220. }
  221. function proxy(value, prev) {
  222. if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
  223. return value;
  224. }
  225. const prototype = get_prototype_of(value);
  226. if (prototype !== object_prototype && prototype !== array_prototype) {
  227. return value;
  228. }
  229. var sources = /* @__PURE__ */ new Map();
  230. var is_proxied_array = is_array(value);
  231. var version = state(0);
  232. var reaction = active_reaction;
  233. var with_parent = (fn) => {
  234. var previous_reaction = active_reaction;
  235. set_active_reaction(reaction);
  236. var result;
  237. {
  238. result = fn();
  239. }
  240. set_active_reaction(previous_reaction);
  241. return result;
  242. };
  243. if (is_proxied_array) {
  244. sources.set("length", state(
  245. /** @type {any[]} */
  246. value.length
  247. ));
  248. }
  249. return new Proxy(
  250. /** @type {any} */
  251. value,
  252. {
  253. defineProperty(_, prop2, descriptor) {
  254. if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
  255. state_descriptors_fixed();
  256. }
  257. var s = sources.get(prop2);
  258. if (s === void 0) {
  259. s = with_parent(() => state(descriptor.value));
  260. sources.set(prop2, s);
  261. } else {
  262. set(
  263. s,
  264. with_parent(() => proxy(descriptor.value))
  265. );
  266. }
  267. return true;
  268. },
  269. deleteProperty(target, prop2) {
  270. var s = sources.get(prop2);
  271. if (s === void 0) {
  272. if (prop2 in target) {
  273. sources.set(
  274. prop2,
  275. with_parent(() => state(UNINITIALIZED))
  276. );
  277. }
  278. } else {
  279. if (is_proxied_array && typeof prop2 === "string") {
  280. var ls = (
  281. /** @type {Source<number>} */
  282. sources.get("length")
  283. );
  284. var n = Number(prop2);
  285. if (Number.isInteger(n) && n < ls.v) {
  286. set(ls, n);
  287. }
  288. }
  289. set(s, UNINITIALIZED);
  290. update_version(version);
  291. }
  292. return true;
  293. },
  294. get(target, prop2, receiver) {
  295. var _a2;
  296. if (prop2 === STATE_SYMBOL) {
  297. return value;
  298. }
  299. var s = sources.get(prop2);
  300. var exists = prop2 in target;
  301. if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  302. s = with_parent(() => state(proxy(exists ? target[prop2] : UNINITIALIZED)));
  303. sources.set(prop2, s);
  304. }
  305. if (s !== void 0) {
  306. var v2 = get$1(s);
  307. return v2 === UNINITIALIZED ? void 0 : v2;
  308. }
  309. return Reflect.get(target, prop2, receiver);
  310. },
  311. getOwnPropertyDescriptor(target, prop2) {
  312. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  313. if (descriptor && "value" in descriptor) {
  314. var s = sources.get(prop2);
  315. if (s) descriptor.value = get$1(s);
  316. } else if (descriptor === void 0) {
  317. var source2 = sources.get(prop2);
  318. var value2 = source2 == null ? void 0 : source2.v;
  319. if (source2 !== void 0 && value2 !== UNINITIALIZED) {
  320. return {
  321. enumerable: true,
  322. configurable: true,
  323. value: value2,
  324. writable: true
  325. };
  326. }
  327. }
  328. return descriptor;
  329. },
  330. has(target, prop2) {
  331. var _a2;
  332. if (prop2 === STATE_SYMBOL) {
  333. return true;
  334. }
  335. var s = sources.get(prop2);
  336. var has2 = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop2);
  337. if (s !== void 0 || active_effect !== null && (!has2 || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  338. if (s === void 0) {
  339. s = with_parent(() => state(has2 ? proxy(target[prop2]) : UNINITIALIZED));
  340. sources.set(prop2, s);
  341. }
  342. var value2 = get$1(s);
  343. if (value2 === UNINITIALIZED) {
  344. return false;
  345. }
  346. }
  347. return has2;
  348. },
  349. set(target, prop2, value2, receiver) {
  350. var _a2;
  351. var s = sources.get(prop2);
  352. var has2 = prop2 in target;
  353. if (is_proxied_array && prop2 === "length") {
  354. for (var i2 = value2; i2 < /** @type {Source<number>} */
  355. s.v; i2 += 1) {
  356. var other_s = sources.get(i2 + "");
  357. if (other_s !== void 0) {
  358. set(other_s, UNINITIALIZED);
  359. } else if (i2 in target) {
  360. other_s = with_parent(() => state(UNINITIALIZED));
  361. sources.set(i2 + "", other_s);
  362. }
  363. }
  364. }
  365. if (s === void 0) {
  366. if (!has2 || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable)) {
  367. s = with_parent(() => state(void 0));
  368. set(
  369. s,
  370. with_parent(() => proxy(value2))
  371. );
  372. sources.set(prop2, s);
  373. }
  374. } else {
  375. has2 = s.v !== UNINITIALIZED;
  376. set(
  377. s,
  378. with_parent(() => proxy(value2))
  379. );
  380. }
  381. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  382. if (descriptor == null ? void 0 : descriptor.set) {
  383. descriptor.set.call(receiver, value2);
  384. }
  385. if (!has2) {
  386. if (is_proxied_array && typeof prop2 === "string") {
  387. var ls = (
  388. /** @type {Source<number>} */
  389. sources.get("length")
  390. );
  391. var n = Number(prop2);
  392. if (Number.isInteger(n) && n >= ls.v) {
  393. set(ls, n + 1);
  394. }
  395. }
  396. update_version(version);
  397. }
  398. return true;
  399. },
  400. ownKeys(target) {
  401. get$1(version);
  402. var own_keys = Reflect.ownKeys(target).filter((key2) => {
  403. var source3 = sources.get(key2);
  404. return source3 === void 0 || source3.v !== UNINITIALIZED;
  405. });
  406. for (var [key, source2] of sources) {
  407. if (source2.v !== UNINITIALIZED && !(key in target)) {
  408. own_keys.push(key);
  409. }
  410. }
  411. return own_keys;
  412. },
  413. setPrototypeOf() {
  414. state_prototype_fixed();
  415. }
  416. }
  417. );
  418. }
  419. function update_version(signal, d = 1) {
  420. set(signal, signal.v + d);
  421. }
  422. const old_values = /* @__PURE__ */ new Map();
  423. function source(v2, stack) {
  424. var signal = {
  425. f: 0,
  426. // TODO ideally we could skip this altogether, but it causes type errors
  427. v: v2,
  428. reactions: null,
  429. equals,
  430. rv: 0,
  431. wv: 0
  432. };
  433. return signal;
  434. }
  435. function state(v2, stack) {
  436. const s = source(v2);
  437. push_reaction_value(s);
  438. return s;
  439. }
  440. // @__NO_SIDE_EFFECTS__
  441. function mutable_source(initial_value, immutable = false) {
  442. var _a2;
  443. const s = source(initial_value);
  444. if (!immutable) {
  445. s.equals = safe_equals;
  446. }
  447. if (legacy_mode_flag && component_context !== null && component_context.l !== null) {
  448. ((_a2 = component_context.l).s ?? (_a2.s = [])).push(s);
  449. }
  450. return s;
  451. }
  452. function set(source2, value, should_proxy = false) {
  453. if (active_reaction !== null && !untracking && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 && !(reaction_sources == null ? void 0 : reaction_sources.includes(source2))) {
  454. state_unsafe_mutation();
  455. }
  456. let new_value = should_proxy ? proxy(value) : value;
  457. return internal_set(source2, new_value);
  458. }
  459. function internal_set(source2, value) {
  460. if (!source2.equals(value)) {
  461. var old_value = source2.v;
  462. if (is_destroying_effect) {
  463. old_values.set(source2, value);
  464. } else {
  465. old_values.set(source2, old_value);
  466. }
  467. source2.v = value;
  468. source2.wv = increment_write_version();
  469. mark_reactions(source2, DIRTY);
  470. if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
  471. if (untracked_writes === null) {
  472. set_untracked_writes([source2]);
  473. } else {
  474. untracked_writes.push(source2);
  475. }
  476. }
  477. }
  478. return value;
  479. }
  480. function update(source2, d = 1) {
  481. var value = get$1(source2);
  482. var result = d === 1 ? value++ : value--;
  483. set(source2, value);
  484. return result;
  485. }
  486. function mark_reactions(signal, status) {
  487. var reactions = signal.reactions;
  488. if (reactions === null) return;
  489. var runes = is_runes();
  490. var length = reactions.length;
  491. for (var i2 = 0; i2 < length; i2++) {
  492. var reaction = reactions[i2];
  493. var flags = reaction.f;
  494. if ((flags & DIRTY) !== 0) continue;
  495. if (!runes && reaction === active_effect) continue;
  496. set_signal_status(reaction, status);
  497. if ((flags & (CLEAN | UNOWNED)) !== 0) {
  498. if ((flags & DERIVED) !== 0) {
  499. mark_reactions(
  500. /** @type {Derived} */
  501. reaction,
  502. MAYBE_DIRTY
  503. );
  504. } else {
  505. schedule_effect(
  506. /** @type {Effect} */
  507. reaction
  508. );
  509. }
  510. }
  511. }
  512. }
  513. let hydrating = false;
  514. var $window;
  515. var is_firefox;
  516. var first_child_getter;
  517. var next_sibling_getter;
  518. function init_operations() {
  519. if ($window !== void 0) {
  520. return;
  521. }
  522. $window = window;
  523. is_firefox = /Firefox/.test(navigator.userAgent);
  524. var element_prototype = Element.prototype;
  525. var node_prototype = Node.prototype;
  526. var text_prototype = Text.prototype;
  527. first_child_getter = get_descriptor(node_prototype, "firstChild").get;
  528. next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
  529. if (is_extensible(element_prototype)) {
  530. element_prototype.__click = void 0;
  531. element_prototype.__className = void 0;
  532. element_prototype.__attributes = null;
  533. element_prototype.__style = void 0;
  534. element_prototype.__e = void 0;
  535. }
  536. if (is_extensible(text_prototype)) {
  537. text_prototype.__t = void 0;
  538. }
  539. }
  540. function create_text(value = "") {
  541. return document.createTextNode(value);
  542. }
  543. // @__NO_SIDE_EFFECTS__
  544. function get_first_child(node) {
  545. return first_child_getter.call(node);
  546. }
  547. // @__NO_SIDE_EFFECTS__
  548. function get_next_sibling(node) {
  549. return next_sibling_getter.call(node);
  550. }
  551. function child(node, is_text) {
  552. {
  553. return /* @__PURE__ */ get_first_child(node);
  554. }
  555. }
  556. function first_child(fragment, is_text) {
  557. {
  558. var first = (
  559. /** @type {DocumentFragment} */
  560. /* @__PURE__ */ get_first_child(
  561. /** @type {Node} */
  562. fragment
  563. )
  564. );
  565. if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
  566. return first;
  567. }
  568. }
  569. function sibling(node, count = 1, is_text = false) {
  570. let next_sibling = node;
  571. while (count--) {
  572. next_sibling = /** @type {TemplateNode} */
  573. /* @__PURE__ */ get_next_sibling(next_sibling);
  574. }
  575. {
  576. return next_sibling;
  577. }
  578. }
  579. function clear_text_content(node) {
  580. node.textContent = "";
  581. }
  582. // @__NO_SIDE_EFFECTS__
  583. function derived(fn) {
  584. var flags = DERIVED | DIRTY;
  585. var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
  586. /** @type {Derived} */
  587. active_reaction
  588. ) : null;
  589. if (active_effect === null || parent_derived !== null && (parent_derived.f & UNOWNED) !== 0) {
  590. flags |= UNOWNED;
  591. } else {
  592. active_effect.f |= EFFECT_HAS_DERIVED;
  593. }
  594. const signal = {
  595. ctx: component_context,
  596. deps: null,
  597. effects: null,
  598. equals,
  599. f: flags,
  600. fn,
  601. reactions: null,
  602. rv: 0,
  603. v: (
  604. /** @type {V} */
  605. null
  606. ),
  607. wv: 0,
  608. parent: parent_derived ?? active_effect
  609. };
  610. return signal;
  611. }
  612. // @__NO_SIDE_EFFECTS__
  613. function derived_safe_equal(fn) {
  614. const signal = /* @__PURE__ */ derived(fn);
  615. signal.equals = safe_equals;
  616. return signal;
  617. }
  618. function destroy_derived_effects(derived2) {
  619. var effects = derived2.effects;
  620. if (effects !== null) {
  621. derived2.effects = null;
  622. for (var i2 = 0; i2 < effects.length; i2 += 1) {
  623. destroy_effect(
  624. /** @type {Effect} */
  625. effects[i2]
  626. );
  627. }
  628. }
  629. }
  630. function get_derived_parent_effect(derived2) {
  631. var parent = derived2.parent;
  632. while (parent !== null) {
  633. if ((parent.f & DERIVED) === 0) {
  634. return (
  635. /** @type {Effect} */
  636. parent
  637. );
  638. }
  639. parent = parent.parent;
  640. }
  641. return null;
  642. }
  643. function execute_derived(derived2) {
  644. var value;
  645. var prev_active_effect = active_effect;
  646. set_active_effect(get_derived_parent_effect(derived2));
  647. {
  648. try {
  649. destroy_derived_effects(derived2);
  650. value = update_reaction(derived2);
  651. } finally {
  652. set_active_effect(prev_active_effect);
  653. }
  654. }
  655. return value;
  656. }
  657. function update_derived(derived2) {
  658. var value = execute_derived(derived2);
  659. var status = (skip_reaction || (derived2.f & UNOWNED) !== 0) && derived2.deps !== null ? MAYBE_DIRTY : CLEAN;
  660. set_signal_status(derived2, status);
  661. if (!derived2.equals(value)) {
  662. derived2.v = value;
  663. derived2.wv = increment_write_version();
  664. }
  665. }
  666. function validate_effect(rune) {
  667. if (active_effect === null && active_reaction === null) {
  668. effect_orphan();
  669. }
  670. if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) {
  671. effect_in_unowned_derived();
  672. }
  673. if (is_destroying_effect) {
  674. effect_in_teardown();
  675. }
  676. }
  677. function push_effect(effect2, parent_effect) {
  678. var parent_last = parent_effect.last;
  679. if (parent_last === null) {
  680. parent_effect.last = parent_effect.first = effect2;
  681. } else {
  682. parent_last.next = effect2;
  683. effect2.prev = parent_last;
  684. parent_effect.last = effect2;
  685. }
  686. }
  687. function create_effect(type, fn, sync, push2 = true) {
  688. var parent = active_effect;
  689. var effect2 = {
  690. ctx: component_context,
  691. deps: null,
  692. nodes_start: null,
  693. nodes_end: null,
  694. f: type | DIRTY,
  695. first: null,
  696. fn,
  697. last: null,
  698. next: null,
  699. parent,
  700. prev: null,
  701. teardown: null,
  702. transitions: null,
  703. wv: 0
  704. };
  705. if (sync) {
  706. try {
  707. update_effect(effect2);
  708. effect2.f |= EFFECT_RAN;
  709. } catch (e2) {
  710. destroy_effect(effect2);
  711. throw e2;
  712. }
  713. } else if (fn !== null) {
  714. schedule_effect(effect2);
  715. }
  716. var inert = sync && effect2.deps === null && effect2.first === null && effect2.nodes_start === null && effect2.teardown === null && (effect2.f & (EFFECT_HAS_DERIVED | BOUNDARY_EFFECT)) === 0;
  717. if (!inert && push2) {
  718. if (parent !== null) {
  719. push_effect(effect2, parent);
  720. }
  721. if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
  722. var derived2 = (
  723. /** @type {Derived} */
  724. active_reaction
  725. );
  726. (derived2.effects ?? (derived2.effects = [])).push(effect2);
  727. }
  728. }
  729. return effect2;
  730. }
  731. function teardown(fn) {
  732. const effect2 = create_effect(RENDER_EFFECT, null, false);
  733. set_signal_status(effect2, CLEAN);
  734. effect2.teardown = fn;
  735. return effect2;
  736. }
  737. function user_effect(fn) {
  738. validate_effect();
  739. var defer = active_effect !== null && (active_effect.f & BRANCH_EFFECT) !== 0 && component_context !== null && !component_context.m;
  740. if (defer) {
  741. var context = (
  742. /** @type {ComponentContext} */
  743. component_context
  744. );
  745. (context.e ?? (context.e = [])).push({
  746. fn,
  747. effect: active_effect,
  748. reaction: active_reaction
  749. });
  750. } else {
  751. var signal = effect(fn);
  752. return signal;
  753. }
  754. }
  755. function user_pre_effect(fn) {
  756. validate_effect();
  757. return render_effect(fn);
  758. }
  759. function component_root(fn) {
  760. const effect2 = create_effect(ROOT_EFFECT, fn, true);
  761. return (options = {}) => {
  762. return new Promise((fulfil) => {
  763. if (options.outro) {
  764. pause_effect(effect2, () => {
  765. destroy_effect(effect2);
  766. fulfil(void 0);
  767. });
  768. } else {
  769. destroy_effect(effect2);
  770. fulfil(void 0);
  771. }
  772. });
  773. };
  774. }
  775. function effect(fn) {
  776. return create_effect(EFFECT, fn, false);
  777. }
  778. function legacy_pre_effect(deps, fn) {
  779. var context = (
  780. /** @type {ComponentContextLegacy} */
  781. component_context
  782. );
  783. var token = { effect: null, ran: false };
  784. context.l.r1.push(token);
  785. token.effect = render_effect(() => {
  786. deps();
  787. if (token.ran) return;
  788. token.ran = true;
  789. set(context.l.r2, true);
  790. untrack(fn);
  791. });
  792. }
  793. function legacy_pre_effect_reset() {
  794. var context = (
  795. /** @type {ComponentContextLegacy} */
  796. component_context
  797. );
  798. render_effect(() => {
  799. if (!get$1(context.l.r2)) return;
  800. for (var token of context.l.r1) {
  801. var effect2 = token.effect;
  802. if ((effect2.f & CLEAN) !== 0) {
  803. set_signal_status(effect2, MAYBE_DIRTY);
  804. }
  805. if (check_dirtiness(effect2)) {
  806. update_effect(effect2);
  807. }
  808. token.ran = false;
  809. }
  810. context.l.r2.v = false;
  811. });
  812. }
  813. function render_effect(fn) {
  814. return create_effect(RENDER_EFFECT, fn, true);
  815. }
  816. function template_effect(fn, thunks = [], d = derived) {
  817. const deriveds = thunks.map(d);
  818. const effect2 = () => fn(...deriveds.map(get$1));
  819. return block(effect2);
  820. }
  821. function block(fn, flags = 0) {
  822. return create_effect(RENDER_EFFECT | BLOCK_EFFECT | flags, fn, true);
  823. }
  824. function branch(fn, push2 = true) {
  825. return create_effect(RENDER_EFFECT | BRANCH_EFFECT, fn, true, push2);
  826. }
  827. function execute_effect_teardown(effect2) {
  828. var teardown2 = effect2.teardown;
  829. if (teardown2 !== null) {
  830. const previously_destroying_effect = is_destroying_effect;
  831. const previous_reaction = active_reaction;
  832. set_is_destroying_effect(true);
  833. set_active_reaction(null);
  834. try {
  835. teardown2.call(null);
  836. } finally {
  837. set_is_destroying_effect(previously_destroying_effect);
  838. set_active_reaction(previous_reaction);
  839. }
  840. }
  841. }
  842. function destroy_effect_children(signal, remove_dom = false) {
  843. var effect2 = signal.first;
  844. signal.first = signal.last = null;
  845. while (effect2 !== null) {
  846. var next2 = effect2.next;
  847. if ((effect2.f & ROOT_EFFECT) !== 0) {
  848. effect2.parent = null;
  849. } else {
  850. destroy_effect(effect2, remove_dom);
  851. }
  852. effect2 = next2;
  853. }
  854. }
  855. function destroy_block_effect_children(signal) {
  856. var effect2 = signal.first;
  857. while (effect2 !== null) {
  858. var next2 = effect2.next;
  859. if ((effect2.f & BRANCH_EFFECT) === 0) {
  860. destroy_effect(effect2);
  861. }
  862. effect2 = next2;
  863. }
  864. }
  865. function destroy_effect(effect2, remove_dom = true) {
  866. var removed = false;
  867. if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes_start !== null) {
  868. var node = effect2.nodes_start;
  869. var end = effect2.nodes_end;
  870. while (node !== null) {
  871. var next2 = node === end ? null : (
  872. /** @type {TemplateNode} */
  873. /* @__PURE__ */ get_next_sibling(node)
  874. );
  875. node.remove();
  876. node = next2;
  877. }
  878. removed = true;
  879. }
  880. destroy_effect_children(effect2, remove_dom && !removed);
  881. remove_reactions(effect2, 0);
  882. set_signal_status(effect2, DESTROYED);
  883. var transitions = effect2.transitions;
  884. if (transitions !== null) {
  885. for (const transition of transitions) {
  886. transition.stop();
  887. }
  888. }
  889. execute_effect_teardown(effect2);
  890. var parent = effect2.parent;
  891. if (parent !== null && parent.first !== null) {
  892. unlink_effect(effect2);
  893. }
  894. effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes_start = effect2.nodes_end = null;
  895. }
  896. function unlink_effect(effect2) {
  897. var parent = effect2.parent;
  898. var prev = effect2.prev;
  899. var next2 = effect2.next;
  900. if (prev !== null) prev.next = next2;
  901. if (next2 !== null) next2.prev = prev;
  902. if (parent !== null) {
  903. if (parent.first === effect2) parent.first = next2;
  904. if (parent.last === effect2) parent.last = prev;
  905. }
  906. }
  907. function pause_effect(effect2, callback) {
  908. var transitions = [];
  909. pause_children(effect2, transitions, true);
  910. run_out_transitions(transitions, () => {
  911. destroy_effect(effect2);
  912. if (callback) callback();
  913. });
  914. }
  915. function run_out_transitions(transitions, fn) {
  916. var remaining = transitions.length;
  917. if (remaining > 0) {
  918. var check = () => --remaining || fn();
  919. for (var transition of transitions) {
  920. transition.out(check);
  921. }
  922. } else {
  923. fn();
  924. }
  925. }
  926. function pause_children(effect2, transitions, local) {
  927. if ((effect2.f & INERT) !== 0) return;
  928. effect2.f ^= INERT;
  929. if (effect2.transitions !== null) {
  930. for (const transition of effect2.transitions) {
  931. if (transition.is_global || local) {
  932. transitions.push(transition);
  933. }
  934. }
  935. }
  936. var child2 = effect2.first;
  937. while (child2 !== null) {
  938. var sibling2 = child2.next;
  939. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  940. pause_children(child2, transitions, transparent ? local : false);
  941. child2 = sibling2;
  942. }
  943. }
  944. function resume_effect(effect2) {
  945. resume_children(effect2, true);
  946. }
  947. function resume_children(effect2, local) {
  948. if ((effect2.f & INERT) === 0) return;
  949. effect2.f ^= INERT;
  950. if ((effect2.f & CLEAN) === 0) {
  951. effect2.f ^= CLEAN;
  952. }
  953. if (check_dirtiness(effect2)) {
  954. set_signal_status(effect2, DIRTY);
  955. schedule_effect(effect2);
  956. }
  957. var child2 = effect2.first;
  958. while (child2 !== null) {
  959. var sibling2 = child2.next;
  960. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  961. resume_children(child2, transparent ? local : false);
  962. child2 = sibling2;
  963. }
  964. if (effect2.transitions !== null) {
  965. for (const transition of effect2.transitions) {
  966. if (transition.is_global || local) {
  967. transition.in();
  968. }
  969. }
  970. }
  971. }
  972. let micro_tasks = [];
  973. let idle_tasks = [];
  974. function run_micro_tasks() {
  975. var tasks = micro_tasks;
  976. micro_tasks = [];
  977. run_all(tasks);
  978. }
  979. function run_idle_tasks() {
  980. var tasks = idle_tasks;
  981. idle_tasks = [];
  982. run_all(tasks);
  983. }
  984. function queue_micro_task(fn) {
  985. if (micro_tasks.length === 0) {
  986. queueMicrotask(run_micro_tasks);
  987. }
  988. micro_tasks.push(fn);
  989. }
  990. function flush_tasks() {
  991. if (micro_tasks.length > 0) {
  992. run_micro_tasks();
  993. }
  994. if (idle_tasks.length > 0) {
  995. run_idle_tasks();
  996. }
  997. }
  998. let is_throwing_error = false;
  999. let is_flushing = false;
  1000. let last_scheduled_effect = null;
  1001. let is_updating_effect = false;
  1002. let is_destroying_effect = false;
  1003. function set_is_destroying_effect(value) {
  1004. is_destroying_effect = value;
  1005. }
  1006. let queued_root_effects = [];
  1007. let active_reaction = null;
  1008. let untracking = false;
  1009. function set_active_reaction(reaction) {
  1010. active_reaction = reaction;
  1011. }
  1012. let active_effect = null;
  1013. function set_active_effect(effect2) {
  1014. active_effect = effect2;
  1015. }
  1016. let reaction_sources = null;
  1017. function set_reaction_sources(sources) {
  1018. reaction_sources = sources;
  1019. }
  1020. function push_reaction_value(value) {
  1021. if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
  1022. if (reaction_sources === null) {
  1023. set_reaction_sources([value]);
  1024. } else {
  1025. reaction_sources.push(value);
  1026. }
  1027. }
  1028. }
  1029. let new_deps = null;
  1030. let skipped_deps = 0;
  1031. let untracked_writes = null;
  1032. function set_untracked_writes(value) {
  1033. untracked_writes = value;
  1034. }
  1035. let write_version = 1;
  1036. let read_version = 0;
  1037. let skip_reaction = false;
  1038. function increment_write_version() {
  1039. return ++write_version;
  1040. }
  1041. function check_dirtiness(reaction) {
  1042. var _a2;
  1043. var flags = reaction.f;
  1044. if ((flags & DIRTY) !== 0) {
  1045. return true;
  1046. }
  1047. if ((flags & MAYBE_DIRTY) !== 0) {
  1048. var dependencies = reaction.deps;
  1049. var is_unowned = (flags & UNOWNED) !== 0;
  1050. if (dependencies !== null) {
  1051. var i2;
  1052. var dependency;
  1053. var is_disconnected = (flags & DISCONNECTED) !== 0;
  1054. var is_unowned_connected = is_unowned && active_effect !== null && !skip_reaction;
  1055. var length = dependencies.length;
  1056. if (is_disconnected || is_unowned_connected) {
  1057. var derived2 = (
  1058. /** @type {Derived} */
  1059. reaction
  1060. );
  1061. var parent = derived2.parent;
  1062. for (i2 = 0; i2 < length; i2++) {
  1063. dependency = dependencies[i2];
  1064. if (is_disconnected || !((_a2 = dependency == null ? void 0 : dependency.reactions) == null ? void 0 : _a2.includes(derived2))) {
  1065. (dependency.reactions ?? (dependency.reactions = [])).push(derived2);
  1066. }
  1067. }
  1068. if (is_disconnected) {
  1069. derived2.f ^= DISCONNECTED;
  1070. }
  1071. if (is_unowned_connected && parent !== null && (parent.f & UNOWNED) === 0) {
  1072. derived2.f ^= UNOWNED;
  1073. }
  1074. }
  1075. for (i2 = 0; i2 < length; i2++) {
  1076. dependency = dependencies[i2];
  1077. if (check_dirtiness(
  1078. /** @type {Derived} */
  1079. dependency
  1080. )) {
  1081. update_derived(
  1082. /** @type {Derived} */
  1083. dependency
  1084. );
  1085. }
  1086. if (dependency.wv > reaction.wv) {
  1087. return true;
  1088. }
  1089. }
  1090. }
  1091. if (!is_unowned || active_effect !== null && !skip_reaction) {
  1092. set_signal_status(reaction, CLEAN);
  1093. }
  1094. }
  1095. return false;
  1096. }
  1097. function propagate_error(error, effect2) {
  1098. var current = effect2;
  1099. while (current !== null) {
  1100. if ((current.f & BOUNDARY_EFFECT) !== 0) {
  1101. try {
  1102. current.fn(error);
  1103. return;
  1104. } catch {
  1105. current.f ^= BOUNDARY_EFFECT;
  1106. }
  1107. }
  1108. current = current.parent;
  1109. }
  1110. is_throwing_error = false;
  1111. throw error;
  1112. }
  1113. function should_rethrow_error(effect2) {
  1114. return (effect2.f & DESTROYED) === 0 && (effect2.parent === null || (effect2.parent.f & BOUNDARY_EFFECT) === 0);
  1115. }
  1116. function handle_error(error, effect2, previous_effect, component_context2) {
  1117. if (is_throwing_error) {
  1118. if (previous_effect === null) {
  1119. is_throwing_error = false;
  1120. }
  1121. if (should_rethrow_error(effect2)) {
  1122. throw error;
  1123. }
  1124. return;
  1125. }
  1126. if (previous_effect !== null) {
  1127. is_throwing_error = true;
  1128. }
  1129. {
  1130. propagate_error(error, effect2);
  1131. return;
  1132. }
  1133. }
  1134. function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
  1135. var reactions = signal.reactions;
  1136. if (reactions === null) return;
  1137. for (var i2 = 0; i2 < reactions.length; i2++) {
  1138. var reaction = reactions[i2];
  1139. if (reaction_sources == null ? void 0 : reaction_sources.includes(signal)) continue;
  1140. if ((reaction.f & DERIVED) !== 0) {
  1141. schedule_possible_effect_self_invalidation(
  1142. /** @type {Derived} */
  1143. reaction,
  1144. effect2,
  1145. false
  1146. );
  1147. } else if (effect2 === reaction) {
  1148. if (root2) {
  1149. set_signal_status(reaction, DIRTY);
  1150. } else if ((reaction.f & CLEAN) !== 0) {
  1151. set_signal_status(reaction, MAYBE_DIRTY);
  1152. }
  1153. schedule_effect(
  1154. /** @type {Effect} */
  1155. reaction
  1156. );
  1157. }
  1158. }
  1159. }
  1160. function update_reaction(reaction) {
  1161. var _a2;
  1162. var previous_deps = new_deps;
  1163. var previous_skipped_deps = skipped_deps;
  1164. var previous_untracked_writes = untracked_writes;
  1165. var previous_reaction = active_reaction;
  1166. var previous_skip_reaction = skip_reaction;
  1167. var previous_reaction_sources = reaction_sources;
  1168. var previous_component_context = component_context;
  1169. var previous_untracking = untracking;
  1170. var flags = reaction.f;
  1171. new_deps = /** @type {null | Value[]} */
  1172. null;
  1173. skipped_deps = 0;
  1174. untracked_writes = null;
  1175. skip_reaction = (flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
  1176. active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
  1177. reaction_sources = null;
  1178. set_component_context(reaction.ctx);
  1179. untracking = false;
  1180. read_version++;
  1181. reaction.f |= EFFECT_IS_UPDATING;
  1182. try {
  1183. var result = (
  1184. /** @type {Function} */
  1185. (0, reaction.fn)()
  1186. );
  1187. var deps = reaction.deps;
  1188. if (new_deps !== null) {
  1189. var i2;
  1190. remove_reactions(reaction, skipped_deps);
  1191. if (deps !== null && skipped_deps > 0) {
  1192. deps.length = skipped_deps + new_deps.length;
  1193. for (i2 = 0; i2 < new_deps.length; i2++) {
  1194. deps[skipped_deps + i2] = new_deps[i2];
  1195. }
  1196. } else {
  1197. reaction.deps = deps = new_deps;
  1198. }
  1199. if (!skip_reaction) {
  1200. for (i2 = skipped_deps; i2 < deps.length; i2++) {
  1201. ((_a2 = deps[i2]).reactions ?? (_a2.reactions = [])).push(reaction);
  1202. }
  1203. }
  1204. } else if (deps !== null && skipped_deps < deps.length) {
  1205. remove_reactions(reaction, skipped_deps);
  1206. deps.length = skipped_deps;
  1207. }
  1208. if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
  1209. for (i2 = 0; i2 < /** @type {Source[]} */
  1210. untracked_writes.length; i2++) {
  1211. schedule_possible_effect_self_invalidation(
  1212. untracked_writes[i2],
  1213. /** @type {Effect} */
  1214. reaction
  1215. );
  1216. }
  1217. }
  1218. if (previous_reaction !== reaction) {
  1219. read_version++;
  1220. if (untracked_writes !== null) {
  1221. if (previous_untracked_writes === null) {
  1222. previous_untracked_writes = untracked_writes;
  1223. } else {
  1224. previous_untracked_writes.push(.../** @type {Source[]} */
  1225. untracked_writes);
  1226. }
  1227. }
  1228. }
  1229. return result;
  1230. } finally {
  1231. new_deps = previous_deps;
  1232. skipped_deps = previous_skipped_deps;
  1233. untracked_writes = previous_untracked_writes;
  1234. active_reaction = previous_reaction;
  1235. skip_reaction = previous_skip_reaction;
  1236. reaction_sources = previous_reaction_sources;
  1237. set_component_context(previous_component_context);
  1238. untracking = previous_untracking;
  1239. reaction.f ^= EFFECT_IS_UPDATING;
  1240. }
  1241. }
  1242. function remove_reaction(signal, dependency) {
  1243. let reactions = dependency.reactions;
  1244. if (reactions !== null) {
  1245. var index2 = index_of.call(reactions, signal);
  1246. if (index2 !== -1) {
  1247. var new_length = reactions.length - 1;
  1248. if (new_length === 0) {
  1249. reactions = dependency.reactions = null;
  1250. } else {
  1251. reactions[index2] = reactions[new_length];
  1252. reactions.pop();
  1253. }
  1254. }
  1255. }
  1256. if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
  1257. // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
  1258. // allows us to skip the expensive work of disconnecting and immediately reconnecting it
  1259. (new_deps === null || !new_deps.includes(dependency))) {
  1260. set_signal_status(dependency, MAYBE_DIRTY);
  1261. if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) {
  1262. dependency.f ^= DISCONNECTED;
  1263. }
  1264. destroy_derived_effects(
  1265. /** @type {Derived} **/
  1266. dependency
  1267. );
  1268. remove_reactions(
  1269. /** @type {Derived} **/
  1270. dependency,
  1271. 0
  1272. );
  1273. }
  1274. }
  1275. function remove_reactions(signal, start_index) {
  1276. var dependencies = signal.deps;
  1277. if (dependencies === null) return;
  1278. for (var i2 = start_index; i2 < dependencies.length; i2++) {
  1279. remove_reaction(signal, dependencies[i2]);
  1280. }
  1281. }
  1282. function update_effect(effect2) {
  1283. var flags = effect2.f;
  1284. if ((flags & DESTROYED) !== 0) {
  1285. return;
  1286. }
  1287. set_signal_status(effect2, CLEAN);
  1288. var previous_effect = active_effect;
  1289. var previous_component_context = component_context;
  1290. var was_updating_effect = is_updating_effect;
  1291. active_effect = effect2;
  1292. is_updating_effect = true;
  1293. try {
  1294. if ((flags & BLOCK_EFFECT) !== 0) {
  1295. destroy_block_effect_children(effect2);
  1296. } else {
  1297. destroy_effect_children(effect2);
  1298. }
  1299. execute_effect_teardown(effect2);
  1300. var teardown2 = update_reaction(effect2);
  1301. effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
  1302. effect2.wv = write_version;
  1303. var deps = effect2.deps;
  1304. var dep;
  1305. if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && deps !== null) ;
  1306. if (DEV) ;
  1307. } catch (error) {
  1308. handle_error(error, effect2, previous_effect, previous_component_context || effect2.ctx);
  1309. } finally {
  1310. is_updating_effect = was_updating_effect;
  1311. active_effect = previous_effect;
  1312. }
  1313. }
  1314. function infinite_loop_guard() {
  1315. try {
  1316. effect_update_depth_exceeded();
  1317. } catch (error) {
  1318. if (last_scheduled_effect !== null) {
  1319. {
  1320. handle_error(error, last_scheduled_effect, null);
  1321. }
  1322. } else {
  1323. throw error;
  1324. }
  1325. }
  1326. }
  1327. function flush_queued_root_effects() {
  1328. var was_updating_effect = is_updating_effect;
  1329. try {
  1330. var flush_count = 0;
  1331. is_updating_effect = true;
  1332. while (queued_root_effects.length > 0) {
  1333. if (flush_count++ > 1e3) {
  1334. infinite_loop_guard();
  1335. }
  1336. var root_effects = queued_root_effects;
  1337. var length = root_effects.length;
  1338. queued_root_effects = [];
  1339. for (var i2 = 0; i2 < length; i2++) {
  1340. var collected_effects = process_effects(root_effects[i2]);
  1341. flush_queued_effects(collected_effects);
  1342. }
  1343. old_values.clear();
  1344. }
  1345. } finally {
  1346. is_flushing = false;
  1347. is_updating_effect = was_updating_effect;
  1348. last_scheduled_effect = null;
  1349. }
  1350. }
  1351. function flush_queued_effects(effects) {
  1352. var length = effects.length;
  1353. if (length === 0) return;
  1354. for (var i2 = 0; i2 < length; i2++) {
  1355. var effect2 = effects[i2];
  1356. if ((effect2.f & (DESTROYED | INERT)) === 0) {
  1357. try {
  1358. if (check_dirtiness(effect2)) {
  1359. update_effect(effect2);
  1360. if (effect2.deps === null && effect2.first === null && effect2.nodes_start === null) {
  1361. if (effect2.teardown === null) {
  1362. unlink_effect(effect2);
  1363. } else {
  1364. effect2.fn = null;
  1365. }
  1366. }
  1367. }
  1368. } catch (error) {
  1369. handle_error(error, effect2, null, effect2.ctx);
  1370. }
  1371. }
  1372. }
  1373. }
  1374. function schedule_effect(signal) {
  1375. if (!is_flushing) {
  1376. is_flushing = true;
  1377. queueMicrotask(flush_queued_root_effects);
  1378. }
  1379. var effect2 = last_scheduled_effect = signal;
  1380. while (effect2.parent !== null) {
  1381. effect2 = effect2.parent;
  1382. var flags = effect2.f;
  1383. if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
  1384. if ((flags & CLEAN) === 0) return;
  1385. effect2.f ^= CLEAN;
  1386. }
  1387. }
  1388. queued_root_effects.push(effect2);
  1389. }
  1390. function process_effects(root2) {
  1391. var effects = [];
  1392. var effect2 = root2;
  1393. while (effect2 !== null) {
  1394. var flags = effect2.f;
  1395. var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
  1396. var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
  1397. if (!is_skippable_branch && (flags & INERT) === 0) {
  1398. if ((flags & EFFECT) !== 0) {
  1399. effects.push(effect2);
  1400. } else if (is_branch) {
  1401. effect2.f ^= CLEAN;
  1402. } else {
  1403. var previous_active_reaction = active_reaction;
  1404. try {
  1405. active_reaction = effect2;
  1406. if (check_dirtiness(effect2)) {
  1407. update_effect(effect2);
  1408. }
  1409. } catch (error) {
  1410. handle_error(error, effect2, null, effect2.ctx);
  1411. } finally {
  1412. active_reaction = previous_active_reaction;
  1413. }
  1414. }
  1415. var child2 = effect2.first;
  1416. if (child2 !== null) {
  1417. effect2 = child2;
  1418. continue;
  1419. }
  1420. }
  1421. var parent = effect2.parent;
  1422. effect2 = effect2.next;
  1423. while (effect2 === null && parent !== null) {
  1424. effect2 = parent.next;
  1425. parent = parent.parent;
  1426. }
  1427. }
  1428. return effects;
  1429. }
  1430. function flushSync(fn) {
  1431. var result;
  1432. flush_tasks();
  1433. while (queued_root_effects.length > 0) {
  1434. is_flushing = true;
  1435. flush_queued_root_effects();
  1436. flush_tasks();
  1437. }
  1438. return (
  1439. /** @type {T} */
  1440. result
  1441. );
  1442. }
  1443. async function tick() {
  1444. await Promise.resolve();
  1445. flushSync();
  1446. }
  1447. function get$1(signal) {
  1448. var flags = signal.f;
  1449. var is_derived = (flags & DERIVED) !== 0;
  1450. if (active_reaction !== null && !untracking) {
  1451. if (!(reaction_sources == null ? void 0 : reaction_sources.includes(signal))) {
  1452. var deps = active_reaction.deps;
  1453. if (signal.rv < read_version) {
  1454. signal.rv = read_version;
  1455. if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
  1456. skipped_deps++;
  1457. } else if (new_deps === null) {
  1458. new_deps = [signal];
  1459. } else if (!skip_reaction || !new_deps.includes(signal)) {
  1460. new_deps.push(signal);
  1461. }
  1462. }
  1463. }
  1464. } else if (is_derived && /** @type {Derived} */
  1465. signal.deps === null && /** @type {Derived} */
  1466. signal.effects === null) {
  1467. var derived2 = (
  1468. /** @type {Derived} */
  1469. signal
  1470. );
  1471. var parent = derived2.parent;
  1472. if (parent !== null && (parent.f & UNOWNED) === 0) {
  1473. derived2.f ^= UNOWNED;
  1474. }
  1475. }
  1476. if (is_derived) {
  1477. derived2 = /** @type {Derived} */
  1478. signal;
  1479. if (check_dirtiness(derived2)) {
  1480. update_derived(derived2);
  1481. }
  1482. }
  1483. if (is_destroying_effect && old_values.has(signal)) {
  1484. return old_values.get(signal);
  1485. }
  1486. return signal.v;
  1487. }
  1488. function untrack(fn) {
  1489. var previous_untracking = untracking;
  1490. try {
  1491. untracking = true;
  1492. return fn();
  1493. } finally {
  1494. untracking = previous_untracking;
  1495. }
  1496. }
  1497. const STATUS_MASK = -7169;
  1498. function set_signal_status(signal, status) {
  1499. signal.f = signal.f & STATUS_MASK | status;
  1500. }
  1501. function deep_read_state(value) {
  1502. if (typeof value !== "object" || !value || value instanceof EventTarget) {
  1503. return;
  1504. }
  1505. if (STATE_SYMBOL in value) {
  1506. deep_read(value);
  1507. } else if (!Array.isArray(value)) {
  1508. for (let key in value) {
  1509. const prop2 = value[key];
  1510. if (typeof prop2 === "object" && prop2 && STATE_SYMBOL in prop2) {
  1511. deep_read(prop2);
  1512. }
  1513. }
  1514. }
  1515. }
  1516. function deep_read(value, visited = /* @__PURE__ */ new Set()) {
  1517. if (typeof value === "object" && value !== null && // We don't want to traverse DOM elements
  1518. !(value instanceof EventTarget) && !visited.has(value)) {
  1519. visited.add(value);
  1520. if (value instanceof Date) {
  1521. value.getTime();
  1522. }
  1523. for (let key in value) {
  1524. try {
  1525. deep_read(value[key], visited);
  1526. } catch (e2) {
  1527. }
  1528. }
  1529. const proto = get_prototype_of(value);
  1530. if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
  1531. const descriptors = get_descriptors(proto);
  1532. for (let key in descriptors) {
  1533. const get2 = descriptors[key].get;
  1534. if (get2) {
  1535. try {
  1536. get2.call(value);
  1537. } catch (e2) {
  1538. }
  1539. }
  1540. }
  1541. }
  1542. }
  1543. }
  1544. function is_capture_event(name) {
  1545. return name.endsWith("capture") && name !== "gotpointercapture" && name !== "lostpointercapture";
  1546. }
  1547. const DELEGATED_EVENTS = [
  1548. "beforeinput",
  1549. "click",
  1550. "change",
  1551. "dblclick",
  1552. "contextmenu",
  1553. "focusin",
  1554. "focusout",
  1555. "input",
  1556. "keydown",
  1557. "keyup",
  1558. "mousedown",
  1559. "mousemove",
  1560. "mouseout",
  1561. "mouseover",
  1562. "mouseup",
  1563. "pointerdown",
  1564. "pointermove",
  1565. "pointerout",
  1566. "pointerover",
  1567. "pointerup",
  1568. "touchend",
  1569. "touchmove",
  1570. "touchstart"
  1571. ];
  1572. function is_delegated(event_name) {
  1573. return DELEGATED_EVENTS.includes(event_name);
  1574. }
  1575. const ATTRIBUTE_ALIASES = {
  1576. // no `class: 'className'` because we handle that separately
  1577. formnovalidate: "formNoValidate",
  1578. ismap: "isMap",
  1579. nomodule: "noModule",
  1580. playsinline: "playsInline",
  1581. readonly: "readOnly",
  1582. defaultvalue: "defaultValue",
  1583. defaultchecked: "defaultChecked",
  1584. srcobject: "srcObject",
  1585. novalidate: "noValidate",
  1586. allowfullscreen: "allowFullscreen",
  1587. disablepictureinpicture: "disablePictureInPicture",
  1588. disableremoteplayback: "disableRemotePlayback"
  1589. };
  1590. function normalize_attribute(name) {
  1591. name = name.toLowerCase();
  1592. return ATTRIBUTE_ALIASES[name] ?? name;
  1593. }
  1594. const PASSIVE_EVENTS = ["touchstart", "touchmove"];
  1595. function is_passive_event(name) {
  1596. return PASSIVE_EVENTS.includes(name);
  1597. }
  1598. function autofocus(dom, value) {
  1599. if (value) {
  1600. const body = document.body;
  1601. dom.autofocus = true;
  1602. queue_micro_task(() => {
  1603. if (document.activeElement === body) {
  1604. dom.focus();
  1605. }
  1606. });
  1607. }
  1608. }
  1609. function without_reactive_context(fn) {
  1610. var previous_reaction = active_reaction;
  1611. var previous_effect = active_effect;
  1612. set_active_reaction(null);
  1613. set_active_effect(null);
  1614. try {
  1615. return fn();
  1616. } finally {
  1617. set_active_reaction(previous_reaction);
  1618. set_active_effect(previous_effect);
  1619. }
  1620. }
  1621. const all_registered_events = /* @__PURE__ */ new Set();
  1622. const root_event_handles = /* @__PURE__ */ new Set();
  1623. function create_event(event_name, dom, handler, options = {}) {
  1624. function target_handler(event2) {
  1625. if (!options.capture) {
  1626. handle_event_propagation.call(dom, event2);
  1627. }
  1628. if (!event2.cancelBubble) {
  1629. return without_reactive_context(() => {
  1630. return handler == null ? void 0 : handler.call(this, event2);
  1631. });
  1632. }
  1633. }
  1634. if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
  1635. queue_micro_task(() => {
  1636. dom.addEventListener(event_name, target_handler, options);
  1637. });
  1638. } else {
  1639. dom.addEventListener(event_name, target_handler, options);
  1640. }
  1641. return target_handler;
  1642. }
  1643. function event(event_name, dom, handler, capture, passive) {
  1644. var options = { capture, passive };
  1645. var target_handler = create_event(event_name, dom, handler, options);
  1646. if (dom === document.body || dom === window || dom === document) {
  1647. teardown(() => {
  1648. dom.removeEventListener(event_name, target_handler, options);
  1649. });
  1650. }
  1651. }
  1652. function delegate(events) {
  1653. for (var i2 = 0; i2 < events.length; i2++) {
  1654. all_registered_events.add(events[i2]);
  1655. }
  1656. for (var fn of root_event_handles) {
  1657. fn(events);
  1658. }
  1659. }
  1660. function handle_event_propagation(event2) {
  1661. var _a2;
  1662. var handler_element = this;
  1663. var owner_document = (
  1664. /** @type {Node} */
  1665. handler_element.ownerDocument
  1666. );
  1667. var event_name = event2.type;
  1668. var path = ((_a2 = event2.composedPath) == null ? void 0 : _a2.call(event2)) || [];
  1669. var current_target = (
  1670. /** @type {null | Element} */
  1671. path[0] || event2.target
  1672. );
  1673. var path_idx = 0;
  1674. var handled_at = event2.__root;
  1675. if (handled_at) {
  1676. var at_idx = path.indexOf(handled_at);
  1677. if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
  1678. window)) {
  1679. event2.__root = handler_element;
  1680. return;
  1681. }
  1682. var handler_idx = path.indexOf(handler_element);
  1683. if (handler_idx === -1) {
  1684. return;
  1685. }
  1686. if (at_idx <= handler_idx) {
  1687. path_idx = at_idx;
  1688. }
  1689. }
  1690. current_target = /** @type {Element} */
  1691. path[path_idx] || event2.target;
  1692. if (current_target === handler_element) return;
  1693. define_property(event2, "currentTarget", {
  1694. configurable: true,
  1695. get() {
  1696. return current_target || owner_document;
  1697. }
  1698. });
  1699. var previous_reaction = active_reaction;
  1700. var previous_effect = active_effect;
  1701. set_active_reaction(null);
  1702. set_active_effect(null);
  1703. try {
  1704. var throw_error;
  1705. var other_errors = [];
  1706. while (current_target !== null) {
  1707. var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
  1708. current_target.host || null;
  1709. try {
  1710. var delegated = current_target["__" + event_name];
  1711. if (delegated != null && (!/** @type {any} */
  1712. current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
  1713. // -> the target could not have been disabled because it emits the event in the first place
  1714. event2.target === current_target)) {
  1715. if (is_array(delegated)) {
  1716. var [fn, ...data] = delegated;
  1717. fn.apply(current_target, [event2, ...data]);
  1718. } else {
  1719. delegated.call(current_target, event2);
  1720. }
  1721. }
  1722. } catch (error) {
  1723. if (throw_error) {
  1724. other_errors.push(error);
  1725. } else {
  1726. throw_error = error;
  1727. }
  1728. }
  1729. if (event2.cancelBubble || parent_element === handler_element || parent_element === null) {
  1730. break;
  1731. }
  1732. current_target = parent_element;
  1733. }
  1734. if (throw_error) {
  1735. for (let error of other_errors) {
  1736. queueMicrotask(() => {
  1737. throw error;
  1738. });
  1739. }
  1740. throw throw_error;
  1741. }
  1742. } finally {
  1743. event2.__root = handler_element;
  1744. delete event2.currentTarget;
  1745. set_active_reaction(previous_reaction);
  1746. set_active_effect(previous_effect);
  1747. }
  1748. }
  1749. function create_fragment_from_html(html) {
  1750. var elem = document.createElement("template");
  1751. elem.innerHTML = html;
  1752. return elem.content;
  1753. }
  1754. function assign_nodes(start, end) {
  1755. var effect2 = (
  1756. /** @type {Effect} */
  1757. active_effect
  1758. );
  1759. if (effect2.nodes_start === null) {
  1760. effect2.nodes_start = start;
  1761. effect2.nodes_end = end;
  1762. }
  1763. }
  1764. // @__NO_SIDE_EFFECTS__
  1765. function template(content, flags) {
  1766. var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
  1767. var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
  1768. var node;
  1769. var has_start = !content.startsWith("<!>");
  1770. return () => {
  1771. if (node === void 0) {
  1772. node = create_fragment_from_html(has_start ? content : "<!>" + content);
  1773. if (!is_fragment) node = /** @type {Node} */
  1774. /* @__PURE__ */ get_first_child(node);
  1775. }
  1776. var clone = (
  1777. /** @type {TemplateNode} */
  1778. use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
  1779. );
  1780. if (is_fragment) {
  1781. var start = (
  1782. /** @type {TemplateNode} */
  1783. /* @__PURE__ */ get_first_child(clone)
  1784. );
  1785. var end = (
  1786. /** @type {TemplateNode} */
  1787. clone.lastChild
  1788. );
  1789. assign_nodes(start, end);
  1790. } else {
  1791. assign_nodes(clone, clone);
  1792. }
  1793. return clone;
  1794. };
  1795. }
  1796. // @__NO_SIDE_EFFECTS__
  1797. function ns_template(content, flags, ns = "svg") {
  1798. var has_start = !content.startsWith("<!>");
  1799. var wrapped = `<${ns}>${has_start ? content : "<!>" + content}</${ns}>`;
  1800. var node;
  1801. return () => {
  1802. if (!node) {
  1803. var fragment = (
  1804. /** @type {DocumentFragment} */
  1805. create_fragment_from_html(wrapped)
  1806. );
  1807. var root2 = (
  1808. /** @type {Element} */
  1809. /* @__PURE__ */ get_first_child(fragment)
  1810. );
  1811. {
  1812. node = /** @type {Element} */
  1813. /* @__PURE__ */ get_first_child(root2);
  1814. }
  1815. }
  1816. var clone = (
  1817. /** @type {TemplateNode} */
  1818. node.cloneNode(true)
  1819. );
  1820. {
  1821. assign_nodes(clone, clone);
  1822. }
  1823. return clone;
  1824. };
  1825. }
  1826. function text(value = "") {
  1827. {
  1828. var t = create_text(value + "");
  1829. assign_nodes(t, t);
  1830. return t;
  1831. }
  1832. }
  1833. function comment() {
  1834. var frag = document.createDocumentFragment();
  1835. var start = document.createComment("");
  1836. var anchor = create_text();
  1837. frag.append(start, anchor);
  1838. assign_nodes(start, anchor);
  1839. return frag;
  1840. }
  1841. function append(anchor, dom) {
  1842. if (anchor === null) {
  1843. return;
  1844. }
  1845. anchor.before(
  1846. /** @type {Node} */
  1847. dom
  1848. );
  1849. }
  1850. function set_text(text2, value) {
  1851. var str = value == null ? "" : typeof value === "object" ? value + "" : value;
  1852. if (str !== (text2.__t ?? (text2.__t = text2.nodeValue))) {
  1853. text2.__t = str;
  1854. text2.nodeValue = str + "";
  1855. }
  1856. }
  1857. function mount(component2, options) {
  1858. return _mount(component2, options);
  1859. }
  1860. const document_listeners = /* @__PURE__ */ new Map();
  1861. function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
  1862. init_operations();
  1863. var registered_events = /* @__PURE__ */ new Set();
  1864. var event_handle = (events2) => {
  1865. for (var i2 = 0; i2 < events2.length; i2++) {
  1866. var event_name = events2[i2];
  1867. if (registered_events.has(event_name)) continue;
  1868. registered_events.add(event_name);
  1869. var passive = is_passive_event(event_name);
  1870. target.addEventListener(event_name, handle_event_propagation, { passive });
  1871. var n = document_listeners.get(event_name);
  1872. if (n === void 0) {
  1873. document.addEventListener(event_name, handle_event_propagation, { passive });
  1874. document_listeners.set(event_name, 1);
  1875. } else {
  1876. document_listeners.set(event_name, n + 1);
  1877. }
  1878. }
  1879. };
  1880. event_handle(array_from(all_registered_events));
  1881. root_event_handles.add(event_handle);
  1882. var component2 = void 0;
  1883. var unmount = component_root(() => {
  1884. var anchor_node = anchor ?? target.appendChild(create_text());
  1885. branch(() => {
  1886. if (context) {
  1887. push({});
  1888. var ctx = (
  1889. /** @type {ComponentContext} */
  1890. component_context
  1891. );
  1892. ctx.c = context;
  1893. }
  1894. if (events) {
  1895. props.$$events = events;
  1896. }
  1897. component2 = Component(anchor_node, props) || {};
  1898. if (context) {
  1899. pop();
  1900. }
  1901. });
  1902. return () => {
  1903. var _a2;
  1904. for (var event_name of registered_events) {
  1905. target.removeEventListener(event_name, handle_event_propagation);
  1906. var n = (
  1907. /** @type {number} */
  1908. document_listeners.get(event_name)
  1909. );
  1910. if (--n === 0) {
  1911. document.removeEventListener(event_name, handle_event_propagation);
  1912. document_listeners.delete(event_name);
  1913. } else {
  1914. document_listeners.set(event_name, n);
  1915. }
  1916. }
  1917. root_event_handles.delete(event_handle);
  1918. if (anchor_node !== anchor) {
  1919. (_a2 = anchor_node.parentNode) == null ? void 0 : _a2.removeChild(anchor_node);
  1920. }
  1921. };
  1922. });
  1923. mounted_components.set(component2, unmount);
  1924. return component2;
  1925. }
  1926. let mounted_components = /* @__PURE__ */ new WeakMap();
  1927. function if_block(node, fn, [root_index, hydrate_index] = [0, 0]) {
  1928. var anchor = node;
  1929. var consequent_effect = null;
  1930. var alternate_effect = null;
  1931. var condition = UNINITIALIZED;
  1932. var flags = root_index > 0 ? EFFECT_TRANSPARENT : 0;
  1933. var has_branch = false;
  1934. const set_branch = (fn2, flag = true) => {
  1935. has_branch = true;
  1936. update_branch(flag, fn2);
  1937. };
  1938. const update_branch = (new_condition, fn2) => {
  1939. if (condition === (condition = new_condition)) return;
  1940. if (condition) {
  1941. if (consequent_effect) {
  1942. resume_effect(consequent_effect);
  1943. } else if (fn2) {
  1944. consequent_effect = branch(() => fn2(anchor));
  1945. }
  1946. if (alternate_effect) {
  1947. pause_effect(alternate_effect, () => {
  1948. alternate_effect = null;
  1949. });
  1950. }
  1951. } else {
  1952. if (alternate_effect) {
  1953. resume_effect(alternate_effect);
  1954. } else if (fn2) {
  1955. alternate_effect = branch(() => fn2(anchor, [root_index + 1, hydrate_index]));
  1956. }
  1957. if (consequent_effect) {
  1958. pause_effect(consequent_effect, () => {
  1959. consequent_effect = null;
  1960. });
  1961. }
  1962. }
  1963. };
  1964. block(() => {
  1965. has_branch = false;
  1966. fn(set_branch);
  1967. if (!has_branch) {
  1968. update_branch(null, null);
  1969. }
  1970. }, flags);
  1971. }
  1972. function index(_, i2) {
  1973. return i2;
  1974. }
  1975. function pause_effects(state2, items, controlled_anchor, items_map) {
  1976. var transitions = [];
  1977. var length = items.length;
  1978. for (var i2 = 0; i2 < length; i2++) {
  1979. pause_children(items[i2].e, transitions, true);
  1980. }
  1981. var is_controlled = length > 0 && transitions.length === 0 && controlled_anchor !== null;
  1982. if (is_controlled) {
  1983. var parent_node = (
  1984. /** @type {Element} */
  1985. /** @type {Element} */
  1986. controlled_anchor.parentNode
  1987. );
  1988. clear_text_content(parent_node);
  1989. parent_node.append(
  1990. /** @type {Element} */
  1991. controlled_anchor
  1992. );
  1993. items_map.clear();
  1994. link(state2, items[0].prev, items[length - 1].next);
  1995. }
  1996. run_out_transitions(transitions, () => {
  1997. for (var i3 = 0; i3 < length; i3++) {
  1998. var item = items[i3];
  1999. if (!is_controlled) {
  2000. items_map.delete(item.k);
  2001. link(state2, item.prev, item.next);
  2002. }
  2003. destroy_effect(item.e, !is_controlled);
  2004. }
  2005. });
  2006. }
  2007. function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
  2008. var anchor = node;
  2009. var state2 = { flags, items: /* @__PURE__ */ new Map(), first: null };
  2010. var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
  2011. if (is_controlled) {
  2012. var parent_node = (
  2013. /** @type {Element} */
  2014. node
  2015. );
  2016. anchor = parent_node.appendChild(create_text());
  2017. }
  2018. var fallback = null;
  2019. var was_empty = false;
  2020. var each_array = /* @__PURE__ */ derived_safe_equal(() => {
  2021. var collection = get_collection();
  2022. return is_array(collection) ? collection : collection == null ? [] : array_from(collection);
  2023. });
  2024. block(() => {
  2025. var array = get$1(each_array);
  2026. var length = array.length;
  2027. if (was_empty && length === 0) {
  2028. return;
  2029. }
  2030. was_empty = length === 0;
  2031. {
  2032. reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection);
  2033. }
  2034. if (fallback_fn !== null) {
  2035. if (length === 0) {
  2036. if (fallback) {
  2037. resume_effect(fallback);
  2038. } else {
  2039. fallback = branch(() => fallback_fn(anchor));
  2040. }
  2041. } else if (fallback !== null) {
  2042. pause_effect(fallback, () => {
  2043. fallback = null;
  2044. });
  2045. }
  2046. }
  2047. get$1(each_array);
  2048. });
  2049. }
  2050. function reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection) {
  2051. var _a2, _b, _c, _d;
  2052. var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
  2053. var should_update = (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
  2054. var length = array.length;
  2055. var items = state2.items;
  2056. var first = state2.first;
  2057. var current = first;
  2058. var seen;
  2059. var prev = null;
  2060. var to_animate;
  2061. var matched = [];
  2062. var stashed = [];
  2063. var value;
  2064. var key;
  2065. var item;
  2066. var i2;
  2067. if (is_animated) {
  2068. for (i2 = 0; i2 < length; i2 += 1) {
  2069. value = array[i2];
  2070. key = get_key(value, i2);
  2071. item = items.get(key);
  2072. if (item !== void 0) {
  2073. (_a2 = item.a) == null ? void 0 : _a2.measure();
  2074. (to_animate ?? (to_animate = /* @__PURE__ */ new Set())).add(item);
  2075. }
  2076. }
  2077. }
  2078. for (i2 = 0; i2 < length; i2 += 1) {
  2079. value = array[i2];
  2080. key = get_key(value, i2);
  2081. item = items.get(key);
  2082. if (item === void 0) {
  2083. var child_anchor = current ? (
  2084. /** @type {TemplateNode} */
  2085. current.e.nodes_start
  2086. ) : anchor;
  2087. prev = create_item(
  2088. child_anchor,
  2089. state2,
  2090. prev,
  2091. prev === null ? state2.first : prev.next,
  2092. value,
  2093. key,
  2094. i2,
  2095. render_fn,
  2096. flags,
  2097. get_collection
  2098. );
  2099. items.set(key, prev);
  2100. matched = [];
  2101. stashed = [];
  2102. current = prev.next;
  2103. continue;
  2104. }
  2105. if (should_update) {
  2106. update_item(item, value, i2, flags);
  2107. }
  2108. if ((item.e.f & INERT) !== 0) {
  2109. resume_effect(item.e);
  2110. if (is_animated) {
  2111. (_b = item.a) == null ? void 0 : _b.unfix();
  2112. (to_animate ?? (to_animate = /* @__PURE__ */ new Set())).delete(item);
  2113. }
  2114. }
  2115. if (item !== current) {
  2116. if (seen !== void 0 && seen.has(item)) {
  2117. if (matched.length < stashed.length) {
  2118. var start = stashed[0];
  2119. var j;
  2120. prev = start.prev;
  2121. var a2 = matched[0];
  2122. var b = matched[matched.length - 1];
  2123. for (j = 0; j < matched.length; j += 1) {
  2124. move(matched[j], start, anchor);
  2125. }
  2126. for (j = 0; j < stashed.length; j += 1) {
  2127. seen.delete(stashed[j]);
  2128. }
  2129. link(state2, a2.prev, b.next);
  2130. link(state2, prev, a2);
  2131. link(state2, b, start);
  2132. current = start;
  2133. prev = b;
  2134. i2 -= 1;
  2135. matched = [];
  2136. stashed = [];
  2137. } else {
  2138. seen.delete(item);
  2139. move(item, current, anchor);
  2140. link(state2, item.prev, item.next);
  2141. link(state2, item, prev === null ? state2.first : prev.next);
  2142. link(state2, prev, item);
  2143. prev = item;
  2144. }
  2145. continue;
  2146. }
  2147. matched = [];
  2148. stashed = [];
  2149. while (current !== null && current.k !== key) {
  2150. if ((current.e.f & INERT) === 0) {
  2151. (seen ?? (seen = /* @__PURE__ */ new Set())).add(current);
  2152. }
  2153. stashed.push(current);
  2154. current = current.next;
  2155. }
  2156. if (current === null) {
  2157. continue;
  2158. }
  2159. item = current;
  2160. }
  2161. matched.push(item);
  2162. prev = item;
  2163. current = item.next;
  2164. }
  2165. if (current !== null || seen !== void 0) {
  2166. var to_destroy = seen === void 0 ? [] : array_from(seen);
  2167. while (current !== null) {
  2168. if ((current.e.f & INERT) === 0) {
  2169. to_destroy.push(current);
  2170. }
  2171. current = current.next;
  2172. }
  2173. var destroy_length = to_destroy.length;
  2174. if (destroy_length > 0) {
  2175. var controlled_anchor = (flags & EACH_IS_CONTROLLED) !== 0 && length === 0 ? anchor : null;
  2176. if (is_animated) {
  2177. for (i2 = 0; i2 < destroy_length; i2 += 1) {
  2178. (_c = to_destroy[i2].a) == null ? void 0 : _c.measure();
  2179. }
  2180. for (i2 = 0; i2 < destroy_length; i2 += 1) {
  2181. (_d = to_destroy[i2].a) == null ? void 0 : _d.fix();
  2182. }
  2183. }
  2184. pause_effects(state2, to_destroy, controlled_anchor, items);
  2185. }
  2186. }
  2187. if (is_animated) {
  2188. queue_micro_task(() => {
  2189. var _a3;
  2190. if (to_animate === void 0) return;
  2191. for (item of to_animate) {
  2192. (_a3 = item.a) == null ? void 0 : _a3.apply();
  2193. }
  2194. });
  2195. }
  2196. active_effect.first = state2.first && state2.first.e;
  2197. active_effect.last = prev && prev.e;
  2198. }
  2199. function update_item(item, value, index2, type) {
  2200. if ((type & EACH_ITEM_REACTIVE) !== 0) {
  2201. internal_set(item.v, value);
  2202. }
  2203. if ((type & EACH_INDEX_REACTIVE) !== 0) {
  2204. internal_set(
  2205. /** @type {Value<number>} */
  2206. item.i,
  2207. index2
  2208. );
  2209. } else {
  2210. item.i = index2;
  2211. }
  2212. }
  2213. function create_item(anchor, state2, prev, next2, value, key, index2, render_fn, flags, get_collection) {
  2214. var reactive = (flags & EACH_ITEM_REACTIVE) !== 0;
  2215. var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0;
  2216. var v2 = reactive ? mutable ? /* @__PURE__ */ mutable_source(value) : source(value) : value;
  2217. var i2 = (flags & EACH_INDEX_REACTIVE) === 0 ? index2 : source(index2);
  2218. var item = {
  2219. i: i2,
  2220. v: v2,
  2221. k: key,
  2222. a: null,
  2223. // @ts-expect-error
  2224. e: null,
  2225. prev,
  2226. next: next2
  2227. };
  2228. try {
  2229. item.e = branch(() => render_fn(anchor, v2, i2, get_collection), hydrating);
  2230. item.e.prev = prev && prev.e;
  2231. item.e.next = next2 && next2.e;
  2232. if (prev === null) {
  2233. state2.first = item;
  2234. } else {
  2235. prev.next = item;
  2236. prev.e.next = item.e;
  2237. }
  2238. if (next2 !== null) {
  2239. next2.prev = item;
  2240. next2.e.prev = item.e;
  2241. }
  2242. return item;
  2243. } finally {
  2244. }
  2245. }
  2246. function move(item, next2, anchor) {
  2247. var end = item.next ? (
  2248. /** @type {TemplateNode} */
  2249. item.next.e.nodes_start
  2250. ) : anchor;
  2251. var dest = next2 ? (
  2252. /** @type {TemplateNode} */
  2253. next2.e.nodes_start
  2254. ) : anchor;
  2255. var node = (
  2256. /** @type {TemplateNode} */
  2257. item.e.nodes_start
  2258. );
  2259. while (node !== end) {
  2260. var next_node = (
  2261. /** @type {TemplateNode} */
  2262. /* @__PURE__ */ get_next_sibling(node)
  2263. );
  2264. dest.before(node);
  2265. node = next_node;
  2266. }
  2267. }
  2268. function link(state2, prev, next2) {
  2269. if (prev === null) {
  2270. state2.first = next2;
  2271. } else {
  2272. prev.next = next2;
  2273. prev.e.next = next2 && next2.e;
  2274. }
  2275. if (next2 !== null) {
  2276. next2.prev = prev;
  2277. next2.e.prev = prev && prev.e;
  2278. }
  2279. }
  2280. function slot(anchor, $$props, name, slot_props, fallback_fn) {
  2281. var _a2;
  2282. var slot_fn = (_a2 = $$props.$$slots) == null ? void 0 : _a2[name];
  2283. var is_interop = false;
  2284. if (slot_fn === true) {
  2285. slot_fn = $$props[name === "default" ? "children" : name];
  2286. is_interop = true;
  2287. }
  2288. if (slot_fn === void 0) {
  2289. if (fallback_fn !== null) {
  2290. fallback_fn(anchor);
  2291. }
  2292. } else {
  2293. slot_fn(anchor, is_interop ? () => slot_props : slot_props);
  2294. }
  2295. }
  2296. function snippet(node, get_snippet, ...args) {
  2297. var anchor = node;
  2298. var snippet2 = noop;
  2299. var snippet_effect;
  2300. block(() => {
  2301. if (snippet2 === (snippet2 = get_snippet())) return;
  2302. if (snippet_effect) {
  2303. destroy_effect(snippet_effect);
  2304. snippet_effect = null;
  2305. }
  2306. snippet_effect = branch(() => (
  2307. /** @type {SnippetFn} */
  2308. snippet2(anchor, ...args)
  2309. ));
  2310. }, EFFECT_TRANSPARENT);
  2311. }
  2312. function component(node, get_component, render_fn) {
  2313. var anchor = node;
  2314. var component2;
  2315. var effect2;
  2316. block(() => {
  2317. if (component2 === (component2 = get_component())) return;
  2318. if (effect2) {
  2319. pause_effect(effect2);
  2320. effect2 = null;
  2321. }
  2322. if (component2) {
  2323. effect2 = branch(() => render_fn(anchor, component2));
  2324. }
  2325. }, EFFECT_TRANSPARENT);
  2326. }
  2327. function r(e2) {
  2328. var t, f, n = "";
  2329. if ("string" == typeof e2 || "number" == typeof e2) n += e2;
  2330. else if ("object" == typeof e2) if (Array.isArray(e2)) {
  2331. var o2 = e2.length;
  2332. for (t = 0; t < o2; t++) e2[t] && (f = r(e2[t])) && (n && (n += " "), n += f);
  2333. } else for (f in e2) e2[f] && (n && (n += " "), n += f);
  2334. return n;
  2335. }
  2336. function clsx$1() {
  2337. for (var e2, t, f = 0, n = "", o2 = arguments.length; f < o2; f++) (e2 = arguments[f]) && (t = r(e2)) && (n && (n += " "), n += t);
  2338. return n;
  2339. }
  2340. function clsx(value) {
  2341. if (typeof value === "object") {
  2342. return clsx$1(value);
  2343. } else {
  2344. return value ?? "";
  2345. }
  2346. }
  2347. const whitespace = [..." \n\r\f \v\uFEFF"];
  2348. function to_class(value, hash, directives) {
  2349. var classname = value == null ? "" : "" + value;
  2350. if (hash) {
  2351. classname = classname ? classname + " " + hash : hash;
  2352. }
  2353. if (directives) {
  2354. for (var key in directives) {
  2355. if (directives[key]) {
  2356. classname = classname ? classname + " " + key : key;
  2357. } else if (classname.length) {
  2358. var len = key.length;
  2359. var a2 = 0;
  2360. while ((a2 = classname.indexOf(key, a2)) >= 0) {
  2361. var b = a2 + len;
  2362. if ((a2 === 0 || whitespace.includes(classname[a2 - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
  2363. classname = (a2 === 0 ? "" : classname.substring(0, a2)) + classname.substring(b + 1);
  2364. } else {
  2365. a2 = b;
  2366. }
  2367. }
  2368. }
  2369. }
  2370. }
  2371. return classname === "" ? null : classname;
  2372. }
  2373. function append_styles(styles, important = false) {
  2374. var separator = important ? " !important;" : ";";
  2375. var css = "";
  2376. for (var key in styles) {
  2377. var value = styles[key];
  2378. if (value != null && value !== "") {
  2379. css += " " + key + ": " + value + separator;
  2380. }
  2381. }
  2382. return css;
  2383. }
  2384. function to_css_name(name) {
  2385. if (name[0] !== "-" || name[1] !== "-") {
  2386. return name.toLowerCase();
  2387. }
  2388. return name;
  2389. }
  2390. function to_style(value, styles) {
  2391. if (styles) {
  2392. var new_style = "";
  2393. var normal_styles;
  2394. var important_styles;
  2395. if (Array.isArray(styles)) {
  2396. normal_styles = styles[0];
  2397. important_styles = styles[1];
  2398. } else {
  2399. normal_styles = styles;
  2400. }
  2401. if (value) {
  2402. value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
  2403. var in_str = false;
  2404. var in_apo = 0;
  2405. var in_comment = false;
  2406. var reserved_names = [];
  2407. if (normal_styles) {
  2408. reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
  2409. }
  2410. if (important_styles) {
  2411. reserved_names.push(...Object.keys(important_styles).map(to_css_name));
  2412. }
  2413. var start_index = 0;
  2414. var name_index = -1;
  2415. const len = value.length;
  2416. for (var i2 = 0; i2 < len; i2++) {
  2417. var c2 = value[i2];
  2418. if (in_comment) {
  2419. if (c2 === "/" && value[i2 - 1] === "*") {
  2420. in_comment = false;
  2421. }
  2422. } else if (in_str) {
  2423. if (in_str === c2) {
  2424. in_str = false;
  2425. }
  2426. } else if (c2 === "/" && value[i2 + 1] === "*") {
  2427. in_comment = true;
  2428. } else if (c2 === '"' || c2 === "'") {
  2429. in_str = c2;
  2430. } else if (c2 === "(") {
  2431. in_apo++;
  2432. } else if (c2 === ")") {
  2433. in_apo--;
  2434. }
  2435. if (!in_comment && in_str === false && in_apo === 0) {
  2436. if (c2 === ":" && name_index === -1) {
  2437. name_index = i2;
  2438. } else if (c2 === ";" || i2 === len - 1) {
  2439. if (name_index !== -1) {
  2440. var name = to_css_name(value.substring(start_index, name_index).trim());
  2441. if (!reserved_names.includes(name)) {
  2442. if (c2 !== ";") {
  2443. i2++;
  2444. }
  2445. var property = value.substring(start_index, i2).trim();
  2446. new_style += " " + property + ";";
  2447. }
  2448. }
  2449. start_index = i2 + 1;
  2450. name_index = -1;
  2451. }
  2452. }
  2453. }
  2454. }
  2455. if (normal_styles) {
  2456. new_style += append_styles(normal_styles);
  2457. }
  2458. if (important_styles) {
  2459. new_style += append_styles(important_styles, true);
  2460. }
  2461. new_style = new_style.trim();
  2462. return new_style === "" ? null : new_style;
  2463. }
  2464. return value == null ? null : String(value);
  2465. }
  2466. function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
  2467. var prev = dom.__className;
  2468. if (prev !== value || prev === void 0) {
  2469. var next_class_name = to_class(value, hash, next_classes);
  2470. {
  2471. if (next_class_name == null) {
  2472. dom.removeAttribute("class");
  2473. } else if (is_html) {
  2474. dom.className = next_class_name;
  2475. } else {
  2476. dom.setAttribute("class", next_class_name);
  2477. }
  2478. }
  2479. dom.__className = value;
  2480. } else if (next_classes && prev_classes !== next_classes) {
  2481. for (var key in next_classes) {
  2482. var is_present = !!next_classes[key];
  2483. if (prev_classes == null || is_present !== !!prev_classes[key]) {
  2484. dom.classList.toggle(key, is_present);
  2485. }
  2486. }
  2487. }
  2488. return next_classes;
  2489. }
  2490. function update_styles(dom, prev = {}, next2, priority) {
  2491. for (var key in next2) {
  2492. var value = next2[key];
  2493. if (prev[key] !== value) {
  2494. if (next2[key] == null) {
  2495. dom.style.removeProperty(key);
  2496. } else {
  2497. dom.style.setProperty(key, value, priority);
  2498. }
  2499. }
  2500. }
  2501. }
  2502. function set_style(dom, value, prev_styles, next_styles) {
  2503. var prev = dom.__style;
  2504. if (prev !== value) {
  2505. var next_style_attr = to_style(value, next_styles);
  2506. {
  2507. if (next_style_attr == null) {
  2508. dom.removeAttribute("style");
  2509. } else {
  2510. dom.style.cssText = next_style_attr;
  2511. }
  2512. }
  2513. dom.__style = value;
  2514. } else if (next_styles) {
  2515. if (Array.isArray(next_styles)) {
  2516. update_styles(dom, prev_styles == null ? void 0 : prev_styles[0], next_styles[0]);
  2517. update_styles(dom, prev_styles == null ? void 0 : prev_styles[1], next_styles[1], "important");
  2518. } else {
  2519. update_styles(dom, prev_styles, next_styles);
  2520. }
  2521. }
  2522. return next_styles;
  2523. }
  2524. const CLASS = Symbol("class");
  2525. const STYLE = Symbol("style");
  2526. const IS_CUSTOM_ELEMENT = Symbol("is custom element");
  2527. const IS_HTML = Symbol("is html");
  2528. function set_selected(element, selected) {
  2529. if (selected) {
  2530. if (!element.hasAttribute("selected")) {
  2531. element.setAttribute("selected", "");
  2532. }
  2533. } else {
  2534. element.removeAttribute("selected");
  2535. }
  2536. }
  2537. function set_attribute(element, attribute, value, skip_warning) {
  2538. var attributes = get_attributes(element);
  2539. if (attributes[attribute] === (attributes[attribute] = value)) return;
  2540. if (attribute === "loading") {
  2541. element[LOADING_ATTR_SYMBOL] = value;
  2542. }
  2543. if (value == null) {
  2544. element.removeAttribute(attribute);
  2545. } else if (typeof value !== "string" && get_setters(element).includes(attribute)) {
  2546. element[attribute] = value;
  2547. } else {
  2548. element.setAttribute(attribute, value);
  2549. }
  2550. }
  2551. function set_attributes(element, prev, next2, css_hash, skip_warning = false) {
  2552. var attributes = get_attributes(element);
  2553. var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
  2554. var preserve_attribute_case = !attributes[IS_HTML];
  2555. var current = prev || {};
  2556. var is_option_element = element.tagName === "OPTION";
  2557. for (var key in prev) {
  2558. if (!(key in next2)) {
  2559. next2[key] = null;
  2560. }
  2561. }
  2562. if (next2.class) {
  2563. next2.class = clsx(next2.class);
  2564. } else if (css_hash || next2[CLASS]) {
  2565. next2.class = null;
  2566. }
  2567. if (next2[STYLE]) {
  2568. next2.style ?? (next2.style = null);
  2569. }
  2570. var setters = get_setters(element);
  2571. for (const key2 in next2) {
  2572. let value = next2[key2];
  2573. if (is_option_element && key2 === "value" && value == null) {
  2574. element.value = element.__value = "";
  2575. current[key2] = value;
  2576. continue;
  2577. }
  2578. if (key2 === "class") {
  2579. var is_html = element.namespaceURI === "http://www.w3.org/1999/xhtml";
  2580. set_class(element, is_html, value, css_hash, prev == null ? void 0 : prev[CLASS], next2[CLASS]);
  2581. current[key2] = value;
  2582. current[CLASS] = next2[CLASS];
  2583. continue;
  2584. }
  2585. if (key2 === "style") {
  2586. set_style(element, value, prev == null ? void 0 : prev[STYLE], next2[STYLE]);
  2587. current[key2] = value;
  2588. current[STYLE] = next2[STYLE];
  2589. continue;
  2590. }
  2591. var prev_value = current[key2];
  2592. if (value === prev_value) continue;
  2593. current[key2] = value;
  2594. var prefix = key2[0] + key2[1];
  2595. if (prefix === "$$") continue;
  2596. if (prefix === "on") {
  2597. const opts = {};
  2598. const event_handle_key = "$$" + key2;
  2599. let event_name = key2.slice(2);
  2600. var delegated = is_delegated(event_name);
  2601. if (is_capture_event(event_name)) {
  2602. event_name = event_name.slice(0, -7);
  2603. opts.capture = true;
  2604. }
  2605. if (!delegated && prev_value) {
  2606. if (value != null) continue;
  2607. element.removeEventListener(event_name, current[event_handle_key], opts);
  2608. current[event_handle_key] = null;
  2609. }
  2610. if (value != null) {
  2611. if (!delegated) {
  2612. let handle = function(evt) {
  2613. current[key2].call(this, evt);
  2614. };
  2615. current[event_handle_key] = create_event(event_name, element, handle, opts);
  2616. } else {
  2617. element[`__${event_name}`] = value;
  2618. delegate([event_name]);
  2619. }
  2620. } else if (delegated) {
  2621. element[`__${event_name}`] = void 0;
  2622. }
  2623. } else if (key2 === "style") {
  2624. set_attribute(element, key2, value);
  2625. } else if (key2 === "autofocus") {
  2626. autofocus(
  2627. /** @type {HTMLElement} */
  2628. element,
  2629. Boolean(value)
  2630. );
  2631. } else if (!is_custom_element && (key2 === "__value" || key2 === "value" && value != null)) {
  2632. element.value = element.__value = value;
  2633. } else if (key2 === "selected" && is_option_element) {
  2634. set_selected(
  2635. /** @type {HTMLOptionElement} */
  2636. element,
  2637. value
  2638. );
  2639. } else {
  2640. var name = key2;
  2641. if (!preserve_attribute_case) {
  2642. name = normalize_attribute(name);
  2643. }
  2644. var is_default = name === "defaultValue" || name === "defaultChecked";
  2645. if (value == null && !is_custom_element && !is_default) {
  2646. attributes[key2] = null;
  2647. if (name === "value" || name === "checked") {
  2648. let input = (
  2649. /** @type {HTMLInputElement} */
  2650. element
  2651. );
  2652. const use_default = prev === void 0;
  2653. if (name === "value") {
  2654. let previous = input.defaultValue;
  2655. input.removeAttribute(name);
  2656. input.defaultValue = previous;
  2657. input.value = input.__value = use_default ? previous : null;
  2658. } else {
  2659. let previous = input.defaultChecked;
  2660. input.removeAttribute(name);
  2661. input.defaultChecked = previous;
  2662. input.checked = use_default ? previous : false;
  2663. }
  2664. } else {
  2665. element.removeAttribute(key2);
  2666. }
  2667. } else if (is_default || setters.includes(name) && (is_custom_element || typeof value !== "string")) {
  2668. element[name] = value;
  2669. } else if (typeof value !== "function") {
  2670. set_attribute(element, name, value);
  2671. }
  2672. }
  2673. }
  2674. return current;
  2675. }
  2676. function get_attributes(element) {
  2677. return (
  2678. /** @type {Record<string | symbol, unknown>} **/
  2679. // @ts-expect-error
  2680. element.__attributes ?? (element.__attributes = {
  2681. [IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
  2682. [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
  2683. })
  2684. );
  2685. }
  2686. var setters_cache = /* @__PURE__ */ new Map();
  2687. function get_setters(element) {
  2688. var setters = setters_cache.get(element.nodeName);
  2689. if (setters) return setters;
  2690. setters_cache.set(element.nodeName, setters = []);
  2691. var descriptors;
  2692. var proto = element;
  2693. var element_proto = Element.prototype;
  2694. while (element_proto !== proto) {
  2695. descriptors = get_descriptors(proto);
  2696. for (var key in descriptors) {
  2697. if (descriptors[key].set) {
  2698. setters.push(key);
  2699. }
  2700. }
  2701. proto = get_prototype_of(proto);
  2702. }
  2703. return setters;
  2704. }
  2705. function is_bound_this(bound_value, element_or_component) {
  2706. return bound_value === element_or_component || (bound_value == null ? void 0 : bound_value[STATE_SYMBOL]) === element_or_component;
  2707. }
  2708. function bind_this(element_or_component = {}, update2, get_value, get_parts) {
  2709. effect(() => {
  2710. var old_parts;
  2711. var parts;
  2712. render_effect(() => {
  2713. old_parts = parts;
  2714. parts = [];
  2715. untrack(() => {
  2716. if (element_or_component !== get_value(...parts)) {
  2717. update2(element_or_component, ...parts);
  2718. if (old_parts && is_bound_this(get_value(...old_parts), element_or_component)) {
  2719. update2(null, ...old_parts);
  2720. }
  2721. }
  2722. });
  2723. });
  2724. return () => {
  2725. queue_micro_task(() => {
  2726. if (parts && is_bound_this(get_value(...parts), element_or_component)) {
  2727. update2(null, ...parts);
  2728. }
  2729. });
  2730. };
  2731. });
  2732. return element_or_component;
  2733. }
  2734. function init(immutable = false) {
  2735. const context = (
  2736. /** @type {ComponentContextLegacy} */
  2737. component_context
  2738. );
  2739. const callbacks = context.l.u;
  2740. if (!callbacks) return;
  2741. let props = () => deep_read_state(context.s);
  2742. if (immutable) {
  2743. let version = 0;
  2744. let prev = (
  2745. /** @type {Record<string, any>} */
  2746. {}
  2747. );
  2748. const d = /* @__PURE__ */ derived(() => {
  2749. let changed = false;
  2750. const props2 = context.s;
  2751. for (const key in props2) {
  2752. if (props2[key] !== prev[key]) {
  2753. prev[key] = props2[key];
  2754. changed = true;
  2755. }
  2756. }
  2757. if (changed) version++;
  2758. return version;
  2759. });
  2760. props = () => get$1(d);
  2761. }
  2762. if (callbacks.b.length) {
  2763. user_pre_effect(() => {
  2764. observe_all(context, props);
  2765. run_all(callbacks.b);
  2766. });
  2767. }
  2768. user_effect(() => {
  2769. const fns = untrack(() => callbacks.m.map(run));
  2770. return () => {
  2771. for (const fn of fns) {
  2772. if (typeof fn === "function") {
  2773. fn();
  2774. }
  2775. }
  2776. };
  2777. });
  2778. if (callbacks.a.length) {
  2779. user_effect(() => {
  2780. observe_all(context, props);
  2781. run_all(callbacks.a);
  2782. });
  2783. }
  2784. }
  2785. function observe_all(context, props) {
  2786. if (context.l.s) {
  2787. for (const signal of context.l.s) get$1(signal);
  2788. }
  2789. props();
  2790. }
  2791. function subscribe_to_store(store, run2, invalidate) {
  2792. if (store == null) {
  2793. run2(void 0);
  2794. return noop;
  2795. }
  2796. const unsub = untrack(
  2797. () => store.subscribe(
  2798. run2,
  2799. // @ts-expect-error
  2800. invalidate
  2801. )
  2802. );
  2803. return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
  2804. }
  2805. const subscriber_queue = [];
  2806. function writable(value, start = noop) {
  2807. let stop = null;
  2808. const subscribers = /* @__PURE__ */ new Set();
  2809. function set2(new_value) {
  2810. if (safe_not_equal(value, new_value)) {
  2811. value = new_value;
  2812. if (stop) {
  2813. const run_queue = !subscriber_queue.length;
  2814. for (const subscriber of subscribers) {
  2815. subscriber[1]();
  2816. subscriber_queue.push(subscriber, value);
  2817. }
  2818. if (run_queue) {
  2819. for (let i2 = 0; i2 < subscriber_queue.length; i2 += 2) {
  2820. subscriber_queue[i2][0](subscriber_queue[i2 + 1]);
  2821. }
  2822. subscriber_queue.length = 0;
  2823. }
  2824. }
  2825. }
  2826. }
  2827. function update2(fn) {
  2828. set2(fn(
  2829. /** @type {T} */
  2830. value
  2831. ));
  2832. }
  2833. function subscribe(run2, invalidate = noop) {
  2834. const subscriber = [run2, invalidate];
  2835. subscribers.add(subscriber);
  2836. if (subscribers.size === 1) {
  2837. stop = start(set2, update2) || noop;
  2838. }
  2839. run2(
  2840. /** @type {T} */
  2841. value
  2842. );
  2843. return () => {
  2844. subscribers.delete(subscriber);
  2845. if (subscribers.size === 0 && stop) {
  2846. stop();
  2847. stop = null;
  2848. }
  2849. };
  2850. }
  2851. return { set: set2, update: update2, subscribe };
  2852. }
  2853. function get(store) {
  2854. let value;
  2855. subscribe_to_store(store, (_) => value = _)();
  2856. return value;
  2857. }
  2858. let is_store_binding = false;
  2859. let IS_UNMOUNTED = Symbol();
  2860. function store_get(store, store_name, stores) {
  2861. const entry = stores[store_name] ?? (stores[store_name] = {
  2862. store: null,
  2863. source: /* @__PURE__ */ mutable_source(void 0),
  2864. unsubscribe: noop
  2865. });
  2866. if (entry.store !== store && !(IS_UNMOUNTED in stores)) {
  2867. entry.unsubscribe();
  2868. entry.store = store ?? null;
  2869. if (store == null) {
  2870. entry.source.v = void 0;
  2871. entry.unsubscribe = noop;
  2872. } else {
  2873. var is_synchronous_callback = true;
  2874. entry.unsubscribe = subscribe_to_store(store, (v2) => {
  2875. if (is_synchronous_callback) {
  2876. entry.source.v = v2;
  2877. } else {
  2878. set(entry.source, v2);
  2879. }
  2880. });
  2881. is_synchronous_callback = false;
  2882. }
  2883. }
  2884. if (store && IS_UNMOUNTED in stores) {
  2885. return get(store);
  2886. }
  2887. return get$1(entry.source);
  2888. }
  2889. function store_unsub(store, store_name, stores) {
  2890. let entry = stores[store_name];
  2891. if (entry && entry.store !== store) {
  2892. entry.unsubscribe();
  2893. entry.unsubscribe = noop;
  2894. }
  2895. return store;
  2896. }
  2897. function setup_stores() {
  2898. const stores = {};
  2899. function cleanup() {
  2900. teardown(() => {
  2901. for (var store_name in stores) {
  2902. const ref = stores[store_name];
  2903. ref.unsubscribe();
  2904. }
  2905. define_property(stores, IS_UNMOUNTED, {
  2906. enumerable: false,
  2907. value: true
  2908. });
  2909. });
  2910. }
  2911. return [stores, cleanup];
  2912. }
  2913. function capture_store_binding(fn) {
  2914. var previous_is_store_binding = is_store_binding;
  2915. try {
  2916. is_store_binding = false;
  2917. return [fn(), is_store_binding];
  2918. } finally {
  2919. is_store_binding = previous_is_store_binding;
  2920. }
  2921. }
  2922. const rest_props_handler = {
  2923. get(target, key) {
  2924. if (target.exclude.includes(key)) return;
  2925. return target.props[key];
  2926. },
  2927. set(target, key) {
  2928. return false;
  2929. },
  2930. getOwnPropertyDescriptor(target, key) {
  2931. if (target.exclude.includes(key)) return;
  2932. if (key in target.props) {
  2933. return {
  2934. enumerable: true,
  2935. configurable: true,
  2936. value: target.props[key]
  2937. };
  2938. }
  2939. },
  2940. has(target, key) {
  2941. if (target.exclude.includes(key)) return false;
  2942. return key in target.props;
  2943. },
  2944. ownKeys(target) {
  2945. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  2946. }
  2947. };
  2948. // @__NO_SIDE_EFFECTS__
  2949. function rest_props(props, exclude, name) {
  2950. return new Proxy(
  2951. { props, exclude },
  2952. rest_props_handler
  2953. );
  2954. }
  2955. const legacy_rest_props_handler = {
  2956. get(target, key) {
  2957. if (target.exclude.includes(key)) return;
  2958. get$1(target.version);
  2959. return key in target.special ? target.special[key]() : target.props[key];
  2960. },
  2961. set(target, key, value) {
  2962. if (!(key in target.special)) {
  2963. target.special[key] = prop(
  2964. {
  2965. get [key]() {
  2966. return target.props[key];
  2967. }
  2968. },
  2969. /** @type {string} */
  2970. key,
  2971. PROPS_IS_UPDATED
  2972. );
  2973. }
  2974. target.special[key](value);
  2975. update(target.version);
  2976. return true;
  2977. },
  2978. getOwnPropertyDescriptor(target, key) {
  2979. if (target.exclude.includes(key)) return;
  2980. if (key in target.props) {
  2981. return {
  2982. enumerable: true,
  2983. configurable: true,
  2984. value: target.props[key]
  2985. };
  2986. }
  2987. },
  2988. deleteProperty(target, key) {
  2989. if (target.exclude.includes(key)) return true;
  2990. target.exclude.push(key);
  2991. update(target.version);
  2992. return true;
  2993. },
  2994. has(target, key) {
  2995. if (target.exclude.includes(key)) return false;
  2996. return key in target.props;
  2997. },
  2998. ownKeys(target) {
  2999. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  3000. }
  3001. };
  3002. function legacy_rest_props(props, exclude) {
  3003. return new Proxy({ props, exclude, special: {}, version: source(0) }, legacy_rest_props_handler);
  3004. }
  3005. const spread_props_handler = {
  3006. get(target, key) {
  3007. let i2 = target.props.length;
  3008. while (i2--) {
  3009. let p = target.props[i2];
  3010. if (is_function(p)) p = p();
  3011. if (typeof p === "object" && p !== null && key in p) return p[key];
  3012. }
  3013. },
  3014. set(target, key, value) {
  3015. let i2 = target.props.length;
  3016. while (i2--) {
  3017. let p = target.props[i2];
  3018. if (is_function(p)) p = p();
  3019. const desc = get_descriptor(p, key);
  3020. if (desc && desc.set) {
  3021. desc.set(value);
  3022. return true;
  3023. }
  3024. }
  3025. return false;
  3026. },
  3027. getOwnPropertyDescriptor(target, key) {
  3028. let i2 = target.props.length;
  3029. while (i2--) {
  3030. let p = target.props[i2];
  3031. if (is_function(p)) p = p();
  3032. if (typeof p === "object" && p !== null && key in p) {
  3033. const descriptor = get_descriptor(p, key);
  3034. if (descriptor && !descriptor.configurable) {
  3035. descriptor.configurable = true;
  3036. }
  3037. return descriptor;
  3038. }
  3039. }
  3040. },
  3041. has(target, key) {
  3042. if (key === STATE_SYMBOL || key === LEGACY_PROPS) return false;
  3043. for (let p of target.props) {
  3044. if (is_function(p)) p = p();
  3045. if (p != null && key in p) return true;
  3046. }
  3047. return false;
  3048. },
  3049. ownKeys(target) {
  3050. const keys = [];
  3051. for (let p of target.props) {
  3052. if (is_function(p)) p = p();
  3053. for (const key in p) {
  3054. if (!keys.includes(key)) keys.push(key);
  3055. }
  3056. }
  3057. return keys;
  3058. }
  3059. };
  3060. function spread_props(...props) {
  3061. return new Proxy({ props }, spread_props_handler);
  3062. }
  3063. function has_destroyed_component_ctx(current_value) {
  3064. var _a2;
  3065. return ((_a2 = current_value.ctx) == null ? void 0 : _a2.d) ?? false;
  3066. }
  3067. function prop(props, key, flags, fallback) {
  3068. var _a2;
  3069. var immutable = (flags & PROPS_IS_IMMUTABLE) !== 0;
  3070. var runes = !legacy_mode_flag || (flags & PROPS_IS_RUNES) !== 0;
  3071. var bindable = (flags & PROPS_IS_BINDABLE) !== 0;
  3072. var lazy = (flags & PROPS_IS_LAZY_INITIAL) !== 0;
  3073. var is_store_sub = false;
  3074. var prop_value;
  3075. if (bindable) {
  3076. [prop_value, is_store_sub] = capture_store_binding(() => (
  3077. /** @type {V} */
  3078. props[key]
  3079. ));
  3080. } else {
  3081. prop_value = /** @type {V} */
  3082. props[key];
  3083. }
  3084. var is_entry_props = STATE_SYMBOL in props || LEGACY_PROPS in props;
  3085. var setter = bindable && (((_a2 = get_descriptor(props, key)) == null ? void 0 : _a2.set) ?? (is_entry_props && key in props && ((v2) => props[key] = v2))) || void 0;
  3086. var fallback_value = (
  3087. /** @type {V} */
  3088. fallback
  3089. );
  3090. var fallback_dirty = true;
  3091. var fallback_used = false;
  3092. var get_fallback = () => {
  3093. fallback_used = true;
  3094. if (fallback_dirty) {
  3095. fallback_dirty = false;
  3096. if (lazy) {
  3097. fallback_value = untrack(
  3098. /** @type {() => V} */
  3099. fallback
  3100. );
  3101. } else {
  3102. fallback_value = /** @type {V} */
  3103. fallback;
  3104. }
  3105. }
  3106. return fallback_value;
  3107. };
  3108. if (prop_value === void 0 && fallback !== void 0) {
  3109. if (setter && runes) {
  3110. props_invalid_value();
  3111. }
  3112. prop_value = get_fallback();
  3113. if (setter) setter(prop_value);
  3114. }
  3115. var getter;
  3116. if (runes) {
  3117. getter = () => {
  3118. var value = (
  3119. /** @type {V} */
  3120. props[key]
  3121. );
  3122. if (value === void 0) return get_fallback();
  3123. fallback_dirty = true;
  3124. fallback_used = false;
  3125. return value;
  3126. };
  3127. } else {
  3128. var derived_getter = (immutable ? derived : derived_safe_equal)(
  3129. () => (
  3130. /** @type {V} */
  3131. props[key]
  3132. )
  3133. );
  3134. derived_getter.f |= LEGACY_DERIVED_PROP;
  3135. getter = () => {
  3136. var value = get$1(derived_getter);
  3137. if (value !== void 0) fallback_value = /** @type {V} */
  3138. void 0;
  3139. return value === void 0 ? fallback_value : value;
  3140. };
  3141. }
  3142. if ((flags & PROPS_IS_UPDATED) === 0) {
  3143. return getter;
  3144. }
  3145. if (setter) {
  3146. var legacy_parent = props.$$legacy;
  3147. return function(value, mutation) {
  3148. if (arguments.length > 0) {
  3149. if (!runes || !mutation || legacy_parent || is_store_sub) {
  3150. setter(mutation ? getter() : value);
  3151. }
  3152. return value;
  3153. } else {
  3154. return getter();
  3155. }
  3156. };
  3157. }
  3158. var from_child = false;
  3159. var inner_current_value = /* @__PURE__ */ mutable_source(prop_value);
  3160. var current_value = /* @__PURE__ */ derived(() => {
  3161. var parent_value = getter();
  3162. var child_value = get$1(inner_current_value);
  3163. if (from_child) {
  3164. from_child = false;
  3165. return child_value;
  3166. }
  3167. return inner_current_value.v = parent_value;
  3168. });
  3169. if (bindable) {
  3170. get$1(current_value);
  3171. }
  3172. if (!immutable) current_value.equals = safe_equals;
  3173. return function(value, mutation) {
  3174. if (arguments.length > 0) {
  3175. const new_value = mutation ? get$1(current_value) : runes && bindable ? proxy(value) : value;
  3176. if (!current_value.equals(new_value)) {
  3177. from_child = true;
  3178. set(inner_current_value, new_value);
  3179. if (fallback_used && fallback_value !== void 0) {
  3180. fallback_value = new_value;
  3181. }
  3182. if (has_destroyed_component_ctx(current_value)) {
  3183. return value;
  3184. }
  3185. untrack(() => get$1(current_value));
  3186. }
  3187. return value;
  3188. }
  3189. if (has_destroyed_component_ctx(current_value)) {
  3190. return current_value.v;
  3191. }
  3192. return get$1(current_value);
  3193. };
  3194. }
  3195. function onMount(fn) {
  3196. if (component_context === null) {
  3197. lifecycle_outside_component();
  3198. }
  3199. if (legacy_mode_flag && component_context.l !== null) {
  3200. init_update_callbacks(component_context).m.push(fn);
  3201. } else {
  3202. user_effect(() => {
  3203. const cleanup = untrack(fn);
  3204. if (typeof cleanup === "function") return (
  3205. /** @type {() => void} */
  3206. cleanup
  3207. );
  3208. });
  3209. }
  3210. }
  3211. function onDestroy(fn) {
  3212. if (component_context === null) {
  3213. lifecycle_outside_component();
  3214. }
  3215. onMount(() => () => untrack(fn));
  3216. }
  3217. function init_update_callbacks(context) {
  3218. var l = (
  3219. /** @type {ComponentContextLegacy} */
  3220. context.l
  3221. );
  3222. return l.u ?? (l.u = { a: [], b: [], m: [] });
  3223. }
  3224. const PUBLIC_VERSION = "5";
  3225. if (typeof window !== "undefined") {
  3226. ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
  3227. }
  3228. enable_legacy_mode_flag();
  3229. var root_1$4 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd"></path></svg>`);
  3230. var root_3$1 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"></path></svg>`);
  3231. var root_5 = /* @__PURE__ */ ns_template(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" height="20" width="20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd"></path></svg>`);
  3232. var root_7 = /* @__PURE__ */ ns_template(`<svg viewBox="0 0 64 64" fill="currentColor" height="20" width="20" xmlns="http://www.w3.org/2000/svg"><path d="M32.427,7.987c2.183,0.124 4,1.165 5.096,3.281l17.936,36.208c1.739,3.66 -0.954,8.585 -5.373,8.656l-36.119,0c-4.022,-0.064 -7.322,-4.631 -5.352,-8.696l18.271,-36.207c0.342,-0.65 0.498,-0.838 0.793,-1.179c1.186,-1.375 2.483,-2.111 4.748,-2.063Zm-0.295,3.997c-0.687,0.034 -1.316,0.419 -1.659,1.017c-6.312,11.979 -12.397,24.081 -18.301,36.267c-0.546,1.225 0.391,2.797 1.762,2.863c12.06,0.195 24.125,0.195 36.185,0c1.325,-0.064 2.321,-1.584 1.769,-2.85c-5.793,-12.184 -11.765,-24.286 -17.966,-36.267c-0.366,-0.651 -0.903,-1.042 -1.79,-1.03Z"></path><path d="M33.631,40.581l-3.348,0l-0.368,-16.449l4.1,0l-0.384,16.449Zm-3.828,5.03c0,-0.609 0.197,-1.113 0.592,-1.514c0.396,-0.4 0.935,-0.601 1.618,-0.601c0.684,0 1.223,0.201 1.618,0.601c0.395,0.401 0.593,0.905 0.593,1.514c0,0.587 -0.193,1.078 -0.577,1.473c-0.385,0.395 -0.929,0.593 -1.634,0.593c-0.705,0 -1.249,-0.198 -1.634,-0.593c-0.384,-0.395 -0.576,-0.886 -0.576,-1.473Z"></path></svg>`);
  3233. function Icon($$anchor, $$props) {
  3234. let type = prop($$props, "type", 8, "success");
  3235. var fragment = comment();
  3236. var node = first_child(fragment);
  3237. {
  3238. var consequent = ($$anchor2) => {
  3239. var svg = root_1$4();
  3240. append($$anchor2, svg);
  3241. };
  3242. var alternate = ($$anchor2, $$elseif) => {
  3243. {
  3244. var consequent_1 = ($$anchor3) => {
  3245. var svg_1 = root_3$1();
  3246. append($$anchor3, svg_1);
  3247. };
  3248. var alternate_1 = ($$anchor3, $$elseif2) => {
  3249. {
  3250. var consequent_2 = ($$anchor4) => {
  3251. var svg_2 = root_5();
  3252. append($$anchor4, svg_2);
  3253. };
  3254. var alternate_2 = ($$anchor4, $$elseif3) => {
  3255. {
  3256. var consequent_3 = ($$anchor5) => {
  3257. var svg_3 = root_7();
  3258. append($$anchor5, svg_3);
  3259. };
  3260. var alternate_3 = ($$anchor5) => {
  3261. };
  3262. if_block(
  3263. $$anchor4,
  3264. ($$render) => {
  3265. if (type() === "warning") $$render(consequent_3);
  3266. else $$render(alternate_3, false);
  3267. },
  3268. $$elseif3
  3269. );
  3270. }
  3271. };
  3272. if_block(
  3273. $$anchor3,
  3274. ($$render) => {
  3275. if (type() === "info") $$render(consequent_2);
  3276. else $$render(alternate_2, false);
  3277. },
  3278. $$elseif2
  3279. );
  3280. }
  3281. };
  3282. if_block(
  3283. $$anchor2,
  3284. ($$render) => {
  3285. if (type() === "error") $$render(consequent_1);
  3286. else $$render(alternate_1, false);
  3287. },
  3288. $$elseif
  3289. );
  3290. }
  3291. };
  3292. if_block(node, ($$render) => {
  3293. if (type() === "success") $$render(consequent);
  3294. else $$render(alternate, false);
  3295. });
  3296. }
  3297. append($$anchor, fragment);
  3298. }
  3299. var root_1$3 = /* @__PURE__ */ template(`<div class="sonner-loading-bar"></div>`);
  3300. var root$5 = /* @__PURE__ */ template(`<div class="sonner-loading-wrapper"><div class="sonner-spinner"></div></div>`);
  3301. function Loader($$anchor, $$props) {
  3302. push($$props, false);
  3303. let visible = prop($$props, "visible", 8);
  3304. const bars = Array(12).fill(0);
  3305. init();
  3306. var div = root$5();
  3307. var div_1 = child(div);
  3308. each(div_1, 5, () => bars, index, ($$anchor2, _) => {
  3309. var div_2 = root_1$3();
  3310. append($$anchor2, div_2);
  3311. });
  3312. template_effect(() => set_attribute(div, "data-visible", visible()));
  3313. append($$anchor, div);
  3314. pop();
  3315. }
  3316. function cn(...classes) {
  3317. return classes.filter(Boolean).join(" ");
  3318. }
  3319. const isBrowser = typeof document !== "undefined";
  3320. function clientWritable(initialValue) {
  3321. const store = writable(initialValue);
  3322. function set2(value) {
  3323. if (isBrowser) {
  3324. store.set(value);
  3325. }
  3326. }
  3327. function update2(updater) {
  3328. if (isBrowser) {
  3329. store.update(updater);
  3330. }
  3331. }
  3332. return {
  3333. subscribe: store.subscribe,
  3334. set: set2,
  3335. update: update2
  3336. };
  3337. }
  3338. let toastsCounter = 0;
  3339. function createToastState() {
  3340. const toasts = clientWritable([]);
  3341. const heights = clientWritable([]);
  3342. function addToast(data) {
  3343. toasts.update((prev) => [data, ...prev]);
  3344. }
  3345. function create(data) {
  3346. var _a2;
  3347. const { message: message2, ...rest } = data;
  3348. const id = typeof (data == null ? void 0 : data.id) === "number" || data.id && ((_a2 = data.id) == null ? void 0 : _a2.length) > 0 ? data.id : toastsCounter++;
  3349. const dismissable = data.dismissable === void 0 ? true : data.dismissable;
  3350. const type = data.type === void 0 ? "default" : data.type;
  3351. const $toasts = get(toasts);
  3352. const alreadyExists = $toasts.find((toast2) => {
  3353. return toast2.id === id;
  3354. });
  3355. if (alreadyExists) {
  3356. toasts.update((prev) => prev.map((toast2) => {
  3357. if (toast2.id === id) {
  3358. return {
  3359. ...toast2,
  3360. ...data,
  3361. id,
  3362. title: message2,
  3363. dismissable,
  3364. type,
  3365. updated: true
  3366. };
  3367. }
  3368. return {
  3369. ...toast2,
  3370. updated: false
  3371. };
  3372. }));
  3373. } else {
  3374. addToast({ ...rest, id, title: message2, dismissable, type });
  3375. }
  3376. return id;
  3377. }
  3378. function dismiss(id) {
  3379. if (id === void 0) {
  3380. toasts.update((prev) => prev.map((toast2) => ({ ...toast2, dismiss: true })));
  3381. return;
  3382. }
  3383. toasts.update((prev) => prev.map((toast2) => toast2.id === id ? { ...toast2, dismiss: true } : toast2));
  3384. return id;
  3385. }
  3386. function remove2(id) {
  3387. if (id === void 0) {
  3388. toasts.set([]);
  3389. return;
  3390. }
  3391. toasts.update((prev) => prev.filter((toast2) => toast2.id !== id));
  3392. return id;
  3393. }
  3394. function message(message2, data) {
  3395. return create({ ...data, type: "default", message: message2 });
  3396. }
  3397. function error(message2, data) {
  3398. return create({ ...data, type: "error", message: message2 });
  3399. }
  3400. function success(message2, data) {
  3401. return create({ ...data, type: "success", message: message2 });
  3402. }
  3403. function info(message2, data) {
  3404. return create({ ...data, type: "info", message: message2 });
  3405. }
  3406. function warning(message2, data) {
  3407. return create({ ...data, type: "warning", message: message2 });
  3408. }
  3409. function loading(message2, data) {
  3410. return create({ ...data, type: "loading", message: message2 });
  3411. }
  3412. function promise(promise2, data) {
  3413. if (!data) {
  3414. return;
  3415. }
  3416. let id = void 0;
  3417. if (data.loading !== void 0) {
  3418. id = create({
  3419. ...data,
  3420. promise: promise2,
  3421. type: "loading",
  3422. message: data.loading
  3423. });
  3424. }
  3425. const p = promise2 instanceof Promise ? promise2 : promise2();
  3426. let shouldDismiss = id !== void 0;
  3427. p.then((response) => {
  3428. if (response && typeof response.ok === "boolean" && !response.ok) {
  3429. shouldDismiss = false;
  3430. const message2 = typeof data.error === "function" ? (
  3431. // @ts-expect-error: Incorrect response type
  3432. data.error(`HTTP error! status: ${response.status}`)
  3433. ) : data.error;
  3434. create({ id, type: "error", message: message2 });
  3435. } else if (data.success !== void 0) {
  3436. shouldDismiss = false;
  3437. const message2 = (
  3438. // @ts-expect-error: TODO: Better function checking
  3439. typeof data.success === "function" ? data.success(response) : data.success
  3440. );
  3441. create({ id, type: "success", message: message2 });
  3442. }
  3443. }).catch((error2) => {
  3444. if (data.error !== void 0) {
  3445. shouldDismiss = false;
  3446. const message2 = (
  3447. // @ts-expect-error: TODO: Better function checking
  3448. typeof data.error === "function" ? data.error(error2) : data.error
  3449. );
  3450. create({ id, type: "error", message: message2 });
  3451. }
  3452. }).finally(() => {
  3453. var _a2;
  3454. if (shouldDismiss) {
  3455. dismiss(id);
  3456. id = void 0;
  3457. }
  3458. (_a2 = data.finally) == null ? void 0 : _a2.call(data);
  3459. });
  3460. return id;
  3461. }
  3462. function custom(component2, data) {
  3463. const id = (data == null ? void 0 : data.id) || toastsCounter++;
  3464. create({ component: component2, id, ...data });
  3465. return id;
  3466. }
  3467. function removeHeight(id) {
  3468. heights.update((prev) => prev.filter((height) => height.toastId !== id));
  3469. }
  3470. function setHeight(data) {
  3471. const exists = get(heights).find((el) => el.toastId === data.toastId);
  3472. if (exists === void 0) {
  3473. heights.update((prev) => [data, ...prev]);
  3474. return;
  3475. }
  3476. heights.update((prev) => prev.map((el) => {
  3477. if (el.toastId === data.toastId) {
  3478. return data;
  3479. } else {
  3480. return el;
  3481. }
  3482. }));
  3483. }
  3484. function reset() {
  3485. toasts.set([]);
  3486. heights.set([]);
  3487. }
  3488. return {
  3489. // methods
  3490. create,
  3491. addToast,
  3492. dismiss,
  3493. remove: remove2,
  3494. message,
  3495. error,
  3496. success,
  3497. info,
  3498. warning,
  3499. loading,
  3500. promise,
  3501. custom,
  3502. removeHeight,
  3503. setHeight,
  3504. reset,
  3505. // stores
  3506. toasts,
  3507. heights
  3508. };
  3509. }
  3510. const toastState = createToastState();
  3511. function toastFunction(message, data) {
  3512. return toastState.create({
  3513. message,
  3514. ...data
  3515. });
  3516. }
  3517. const basicToast = toastFunction;
  3518. const toast = Object.assign(basicToast, {
  3519. success: toastState.success,
  3520. info: toastState.info,
  3521. warning: toastState.warning,
  3522. error: toastState.error,
  3523. custom: toastState.custom,
  3524. message: toastState.message,
  3525. promise: toastState.promise,
  3526. dismiss: toastState.dismiss,
  3527. loading: toastState.loading
  3528. });
  3529. const useEffect = (subscribe) => ({ subscribe });
  3530. var root_1$2 = /* @__PURE__ */ template(`<button aria-label="Close toast" data-close-button=""><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg></button>`);
  3531. var root_4 = /* @__PURE__ */ template(`<div data-icon=""><!> <!></div>`);
  3532. var root_15 = /* @__PURE__ */ template(`<div data-title=""><!></div>`);
  3533. var root_18 = /* @__PURE__ */ template(`<div data-description=""><!></div>`);
  3534. var root_21 = /* @__PURE__ */ template(`<button data-button="" data-cancel=""> </button>`);
  3535. var root_22 = /* @__PURE__ */ template(`<button data-button=""> </button>`);
  3536. var root_3 = /* @__PURE__ */ template(`<!> <div data-content=""><!> <!></div> <!> <!>`, 1);
  3537. var root$4 = /* @__PURE__ */ template(`<li aria-atomic="true" role="status" data-sonner-toast=""><!> <!></li>`);
  3538. function Toast($$anchor, $$props) {
  3539. const $$sanitized_props = legacy_rest_props($$props, [
  3540. "children",
  3541. "$$slots",
  3542. "$$events",
  3543. "$$legacy"
  3544. ]);
  3545. push($$props, false);
  3546. const [$$stores, $$cleanup] = setup_stores();
  3547. const $heights = () => store_get(heights, "$heights", $$stores);
  3548. const $effect = () => store_get(get$1(effect2), "$effect", $$stores);
  3549. const $toasts = () => store_get(toasts, "$toasts", $$stores);
  3550. const isFront = /* @__PURE__ */ mutable_source(void 0, true);
  3551. const isVisible = /* @__PURE__ */ mutable_source(void 0, true);
  3552. const toastTitle = /* @__PURE__ */ mutable_source(void 0, true);
  3553. const toastDescription = /* @__PURE__ */ mutable_source(void 0, true);
  3554. const toastType = /* @__PURE__ */ mutable_source(void 0, true);
  3555. const toastClass = /* @__PURE__ */ mutable_source(void 0, true);
  3556. const toastDescriptionClass = /* @__PURE__ */ mutable_source(void 0, true);
  3557. const heightIndex = /* @__PURE__ */ mutable_source(void 0, true);
  3558. const coords = /* @__PURE__ */ mutable_source(void 0, true);
  3559. const toastsHeightBefore = /* @__PURE__ */ mutable_source(void 0, true);
  3560. const disabled = /* @__PURE__ */ mutable_source(void 0, true);
  3561. const isPromiseLoadingOrInfiniteDuration = /* @__PURE__ */ mutable_source(void 0, true);
  3562. const TOAST_LIFETIME = 4e3;
  3563. const GAP = 14;
  3564. const SWIPE_TRESHOLD = 20;
  3565. const TIME_BEFORE_UNMOUNT = 200;
  3566. const SCALE_MULTIPLIER = 0.05;
  3567. const defaultClasses = {
  3568. toast: "",
  3569. title: "",
  3570. description: "",
  3571. loader: "",
  3572. closeButton: "",
  3573. cancelButton: "",
  3574. actionButton: "",
  3575. action: "",
  3576. warning: "",
  3577. error: "",
  3578. success: "",
  3579. default: "",
  3580. info: "",
  3581. loading: ""
  3582. };
  3583. const {
  3584. toasts,
  3585. heights,
  3586. removeHeight,
  3587. setHeight,
  3588. remove: remove2
  3589. } = toastState;
  3590. let toast2 = prop($$props, "toast", 9);
  3591. let index2 = prop($$props, "index", 9);
  3592. let expanded = prop($$props, "expanded", 9);
  3593. let invert = prop($$props, "invert", 13);
  3594. let position = prop($$props, "position", 9);
  3595. let visibleToasts = prop($$props, "visibleToasts", 9);
  3596. let expandByDefault = prop($$props, "expandByDefault", 9);
  3597. let closeButton = prop($$props, "closeButton", 9);
  3598. let interacting = prop($$props, "interacting", 9);
  3599. let cancelButtonStyle = prop($$props, "cancelButtonStyle", 9, "");
  3600. let actionButtonStyle = prop($$props, "actionButtonStyle", 9, "");
  3601. let duration = prop($$props, "duration", 9, 4e3);
  3602. let descriptionClass = prop($$props, "descriptionClass", 9, "");
  3603. let classes = prop($$props, "classes", 29, () => ({}));
  3604. let unstyled = prop($$props, "unstyled", 9, false);
  3605. let mounted = /* @__PURE__ */ mutable_source(false, true);
  3606. let removed = /* @__PURE__ */ mutable_source(false, true);
  3607. let swiping = /* @__PURE__ */ mutable_source(false, true);
  3608. let swipeOut = /* @__PURE__ */ mutable_source(false, true);
  3609. let offsetBeforeRemove = /* @__PURE__ */ mutable_source(0, true);
  3610. let initialHeight = /* @__PURE__ */ mutable_source(0, true);
  3611. let toastRef = /* @__PURE__ */ mutable_source(void 0, true);
  3612. let offset = /* @__PURE__ */ mutable_source(0, true);
  3613. let closeTimerStartTimeRef = 0;
  3614. let lastCloseTimerStartTimeRef = 0;
  3615. let pointerStartRef = null;
  3616. async function updateHeights() {
  3617. if (!get$1(mounted)) {
  3618. return;
  3619. }
  3620. await tick();
  3621. let scale;
  3622. if (expanded() || expandByDefault()) {
  3623. scale = 1;
  3624. } else {
  3625. scale = 1 - index2() * SCALE_MULTIPLIER;
  3626. }
  3627. get$1(toastRef).style.setProperty("height", "auto");
  3628. const offsetHeight = get$1(toastRef).offsetHeight;
  3629. const rectHeight = get$1(toastRef).getBoundingClientRect().height;
  3630. const scaledRectHeight = Math.round((rectHeight / scale + Number.EPSILON) * 100) / 100;
  3631. get$1(toastRef).style.removeProperty("height");
  3632. let finalHeight;
  3633. if (Math.abs(scaledRectHeight - offsetHeight) < 1) {
  3634. finalHeight = scaledRectHeight;
  3635. } else {
  3636. finalHeight = offsetHeight;
  3637. }
  3638. set(initialHeight, finalHeight);
  3639. setHeight({ toastId: toast2().id, height: finalHeight });
  3640. }
  3641. function deleteToast() {
  3642. set(removed, true);
  3643. set(offsetBeforeRemove, get$1(offset));
  3644. removeHeight(toast2().id);
  3645. setTimeout(
  3646. () => {
  3647. remove2(toast2().id);
  3648. },
  3649. TIME_BEFORE_UNMOUNT
  3650. );
  3651. }
  3652. let timeoutId = /* @__PURE__ */ mutable_source(void 0, true);
  3653. let remainingTime = /* @__PURE__ */ mutable_source(toast2().duration || duration() || TOAST_LIFETIME, true);
  3654. function pauseTimer() {
  3655. if (lastCloseTimerStartTimeRef < closeTimerStartTimeRef) {
  3656. const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef;
  3657. set(remainingTime, get$1(remainingTime) - elapsedTime);
  3658. }
  3659. lastCloseTimerStartTimeRef = (/* @__PURE__ */ new Date()).getTime();
  3660. }
  3661. function startTimer() {
  3662. closeTimerStartTimeRef = (/* @__PURE__ */ new Date()).getTime();
  3663. set(timeoutId, setTimeout(
  3664. () => {
  3665. var _a2, _b;
  3666. (_b = (_a2 = toast2()).onAutoClose) == null ? void 0 : _b.call(_a2, toast2());
  3667. deleteToast();
  3668. },
  3669. get$1(remainingTime)
  3670. ));
  3671. }
  3672. let effect2 = /* @__PURE__ */ mutable_source(void 0, true);
  3673. onMount(() => {
  3674. set(mounted, true);
  3675. const height = get$1(toastRef).getBoundingClientRect().height;
  3676. set(initialHeight, height);
  3677. setHeight({ toastId: toast2().id, height });
  3678. return () => removeHeight(toast2().id);
  3679. });
  3680. function onPointerDown(event2) {
  3681. if (get$1(disabled)) {
  3682. return;
  3683. }
  3684. set(offsetBeforeRemove, get$1(offset));
  3685. const target = event2.target;
  3686. target.setPointerCapture(event2.pointerId);
  3687. if (target.tagName === "BUTTON") {
  3688. return;
  3689. }
  3690. set(swiping, true);
  3691. pointerStartRef = { x: event2.clientX, y: event2.clientY };
  3692. }
  3693. function onPointerUp() {
  3694. var _a2, _b, _c;
  3695. if (get$1(swipeOut)) {
  3696. return;
  3697. }
  3698. pointerStartRef = null;
  3699. const swipeAmount = Number(((_a2 = get$1(toastRef)) == null ? void 0 : _a2.style.getPropertyValue("--swipe-amount").replace("px", "")) || 0);
  3700. if (Math.abs(swipeAmount) >= SWIPE_TRESHOLD) {
  3701. set(offsetBeforeRemove, get$1(offset));
  3702. (_c = (_b = toast2()).onDismiss) == null ? void 0 : _c.call(_b, toast2());
  3703. deleteToast();
  3704. set(swipeOut, true);
  3705. return;
  3706. }
  3707. get$1(toastRef).style.setProperty("--swipe-amount", "0px");
  3708. set(swiping, false);
  3709. }
  3710. function onPointerMove(event2) {
  3711. if (!pointerStartRef) {
  3712. return;
  3713. }
  3714. const yPosition = event2.clientY - pointerStartRef.y;
  3715. const xPosition = event2.clientX - pointerStartRef.x;
  3716. const clamp = get$1(coords)[0] === "top" ? Math.min : Math.max;
  3717. const clampedY = clamp(0, yPosition);
  3718. const swipeStartThreshold = event2.pointerType === "touch" ? 10 : 2;
  3719. const isAllowedToSwipe = Math.abs(clampedY) > swipeStartThreshold;
  3720. if (isAllowedToSwipe) {
  3721. get$1(toastRef).style.setProperty("--swipe-amount", `${yPosition}px`);
  3722. } else if (Math.abs(xPosition) > swipeStartThreshold) {
  3723. pointerStartRef = null;
  3724. }
  3725. }
  3726. legacy_pre_effect(() => deep_read_state(classes()), () => {
  3727. classes({ ...defaultClasses, ...classes() });
  3728. });
  3729. legacy_pre_effect(() => deep_read_state(index2()), () => {
  3730. set(isFront, index2() === 0);
  3731. });
  3732. legacy_pre_effect(
  3733. () => (deep_read_state(index2()), deep_read_state(visibleToasts())),
  3734. () => {
  3735. set(isVisible, index2() + 1 <= visibleToasts());
  3736. }
  3737. );
  3738. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3739. set(toastTitle, toast2().title);
  3740. });
  3741. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3742. set(toastDescription, toast2().description);
  3743. });
  3744. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3745. set(toastType, toast2().type);
  3746. });
  3747. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3748. set(toastClass, toast2().class || "");
  3749. });
  3750. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3751. set(toastDescriptionClass, toast2().descriptionClass || "");
  3752. });
  3753. legacy_pre_effect(
  3754. () => ($heights(), deep_read_state(toast2())),
  3755. () => {
  3756. set(heightIndex, $heights().findIndex((height) => height.toastId === toast2().id) || 0);
  3757. }
  3758. );
  3759. legacy_pre_effect(() => deep_read_state(position()), () => {
  3760. set(coords, position().split("-"));
  3761. });
  3762. legacy_pre_effect(() => ($heights(), get$1(heightIndex)), () => {
  3763. set(toastsHeightBefore, $heights().reduce(
  3764. (prev, curr, reducerIndex) => {
  3765. if (reducerIndex >= get$1(heightIndex)) return prev;
  3766. return prev + curr.height;
  3767. },
  3768. 0
  3769. ));
  3770. });
  3771. legacy_pre_effect(
  3772. () => (deep_read_state(invert()), deep_read_state(toast2())),
  3773. () => {
  3774. invert(toast2().invert || invert());
  3775. }
  3776. );
  3777. legacy_pre_effect(() => get$1(toastType), () => {
  3778. set(disabled, get$1(toastType) === "loading");
  3779. });
  3780. legacy_pre_effect(
  3781. () => (get$1(heightIndex), get$1(toastsHeightBefore)),
  3782. () => {
  3783. set(offset, Math.round(get$1(heightIndex) * GAP + get$1(toastsHeightBefore)));
  3784. }
  3785. );
  3786. legacy_pre_effect(
  3787. () => (get$1(toastTitle), get$1(toastDescription)),
  3788. () => {
  3789. get$1(toastTitle), get$1(toastDescription), updateHeights();
  3790. }
  3791. );
  3792. legacy_pre_effect(
  3793. () => (deep_read_state(toast2()), get$1(timeoutId), deep_read_state(duration())),
  3794. () => {
  3795. if (toast2().updated) {
  3796. clearTimeout(get$1(timeoutId));
  3797. set(remainingTime, toast2().duration || duration() || TOAST_LIFETIME);
  3798. startTimer();
  3799. }
  3800. }
  3801. );
  3802. legacy_pre_effect(
  3803. () => (deep_read_state(toast2()), get$1(toastType)),
  3804. () => {
  3805. set(isPromiseLoadingOrInfiniteDuration, toast2().promise && get$1(toastType) === "loading" || toast2().duration === Number.POSITIVE_INFINITY);
  3806. }
  3807. );
  3808. legacy_pre_effect(
  3809. () => (get$1(isPromiseLoadingOrInfiniteDuration), deep_read_state(expanded()), deep_read_state(interacting()), get$1(timeoutId)),
  3810. () => {
  3811. store_unsub(
  3812. set(effect2, useEffect(() => {
  3813. if (!get$1(isPromiseLoadingOrInfiniteDuration)) {
  3814. if (expanded() || interacting()) {
  3815. pauseTimer();
  3816. } else {
  3817. startTimer();
  3818. }
  3819. }
  3820. return () => clearTimeout(get$1(timeoutId));
  3821. })),
  3822. "$effect",
  3823. $$stores
  3824. );
  3825. }
  3826. );
  3827. legacy_pre_effect(() => $effect(), () => {
  3828. $effect();
  3829. });
  3830. legacy_pre_effect(() => deep_read_state(toast2()), () => {
  3831. if (toast2().delete) {
  3832. deleteToast();
  3833. }
  3834. });
  3835. legacy_pre_effect_reset();
  3836. init(true);
  3837. var li = root$4();
  3838. set_attribute(li, "tabindex", 0);
  3839. let styles;
  3840. var node = child(li);
  3841. {
  3842. var consequent = ($$anchor2) => {
  3843. var button = root_1$2();
  3844. template_effect(
  3845. ($0) => {
  3846. set_attribute(button, "data-disabled", get$1(disabled));
  3847. set_class(button, 1, $0);
  3848. },
  3849. [
  3850. () => {
  3851. var _a2, _b, _c;
  3852. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.closeButton, (_c = (_b = toast2()) == null ? void 0 : _b.classes) == null ? void 0 : _c.closeButton));
  3853. }
  3854. ],
  3855. derived_safe_equal
  3856. );
  3857. event("click", button, function(...$$args) {
  3858. var _a2;
  3859. (_a2 = get$1(disabled) ? void 0 : () => {
  3860. var _a3, _b;
  3861. deleteToast();
  3862. (_b = (_a3 = toast2()).onDismiss) == null ? void 0 : _b.call(_a3, toast2());
  3863. }) == null ? void 0 : _a2.apply(this, $$args);
  3864. });
  3865. append($$anchor2, button);
  3866. };
  3867. if_block(node, ($$render) => {
  3868. if (closeButton() && !toast2().component) $$render(consequent);
  3869. });
  3870. }
  3871. var node_1 = sibling(node, 2);
  3872. {
  3873. var consequent_1 = ($$anchor2) => {
  3874. var fragment = comment();
  3875. var node_2 = first_child(fragment);
  3876. component(node_2, () => toast2().component, ($$anchor3, $$component) => {
  3877. $$component($$anchor3, spread_props(() => toast2().componentProps, { $$events: { closeToast: deleteToast } }));
  3878. });
  3879. append($$anchor2, fragment);
  3880. };
  3881. var alternate = ($$anchor2) => {
  3882. var fragment_1 = root_3();
  3883. var node_3 = first_child(fragment_1);
  3884. {
  3885. var consequent_8 = ($$anchor3) => {
  3886. var div = root_4();
  3887. var node_4 = child(div);
  3888. {
  3889. var consequent_2 = ($$anchor4) => {
  3890. var fragment_2 = comment();
  3891. var node_5 = first_child(fragment_2);
  3892. slot(node_5, $$props, "loading-icon", {}, null);
  3893. append($$anchor4, fragment_2);
  3894. };
  3895. if_block(node_4, ($$render) => {
  3896. if ((toast2().promise || get$1(toastType) === "loading") && !toast2().icon) $$render(consequent_2);
  3897. });
  3898. }
  3899. var node_6 = sibling(node_4, 2);
  3900. {
  3901. var consequent_3 = ($$anchor4) => {
  3902. var fragment_3 = comment();
  3903. var node_7 = first_child(fragment_3);
  3904. component(node_7, () => toast2().icon, ($$anchor5, $$component) => {
  3905. $$component($$anchor5, {});
  3906. });
  3907. append($$anchor4, fragment_3);
  3908. };
  3909. var alternate_1 = ($$anchor4, $$elseif) => {
  3910. {
  3911. var consequent_4 = ($$anchor5) => {
  3912. var fragment_4 = comment();
  3913. var node_8 = first_child(fragment_4);
  3914. slot(node_8, $$props, "success-icon", {}, null);
  3915. append($$anchor5, fragment_4);
  3916. };
  3917. var alternate_2 = ($$anchor5, $$elseif2) => {
  3918. {
  3919. var consequent_5 = ($$anchor6) => {
  3920. var fragment_5 = comment();
  3921. var node_9 = first_child(fragment_5);
  3922. slot(node_9, $$props, "error-icon", {}, null);
  3923. append($$anchor6, fragment_5);
  3924. };
  3925. var alternate_3 = ($$anchor6, $$elseif3) => {
  3926. {
  3927. var consequent_6 = ($$anchor7) => {
  3928. var fragment_6 = comment();
  3929. var node_10 = first_child(fragment_6);
  3930. slot(node_10, $$props, "warning-icon", {}, null);
  3931. append($$anchor7, fragment_6);
  3932. };
  3933. var alternate_4 = ($$anchor7, $$elseif4) => {
  3934. {
  3935. var consequent_7 = ($$anchor8) => {
  3936. var fragment_7 = comment();
  3937. var node_11 = first_child(fragment_7);
  3938. slot(node_11, $$props, "info-icon", {}, null);
  3939. append($$anchor8, fragment_7);
  3940. };
  3941. if_block(
  3942. $$anchor7,
  3943. ($$render) => {
  3944. if (get$1(toastType) === "info") $$render(consequent_7);
  3945. },
  3946. $$elseif4
  3947. );
  3948. }
  3949. };
  3950. if_block(
  3951. $$anchor6,
  3952. ($$render) => {
  3953. if (get$1(toastType) === "warning") $$render(consequent_6);
  3954. else $$render(alternate_4, false);
  3955. },
  3956. $$elseif3
  3957. );
  3958. }
  3959. };
  3960. if_block(
  3961. $$anchor5,
  3962. ($$render) => {
  3963. if (get$1(toastType) === "error") $$render(consequent_5);
  3964. else $$render(alternate_3, false);
  3965. },
  3966. $$elseif2
  3967. );
  3968. }
  3969. };
  3970. if_block(
  3971. $$anchor4,
  3972. ($$render) => {
  3973. if (get$1(toastType) === "success") $$render(consequent_4);
  3974. else $$render(alternate_2, false);
  3975. },
  3976. $$elseif
  3977. );
  3978. }
  3979. };
  3980. if_block(node_6, ($$render) => {
  3981. if (toast2().icon) $$render(consequent_3);
  3982. else $$render(alternate_1, false);
  3983. });
  3984. }
  3985. append($$anchor3, div);
  3986. };
  3987. if_block(node_3, ($$render) => {
  3988. if (get$1(toastType) !== "default" || toast2().icon || toast2().promise) $$render(consequent_8);
  3989. });
  3990. }
  3991. var div_1 = sibling(node_3, 2);
  3992. var node_12 = child(div_1);
  3993. {
  3994. var consequent_10 = ($$anchor3) => {
  3995. var div_2 = root_15();
  3996. var node_13 = child(div_2);
  3997. {
  3998. var consequent_9 = ($$anchor4) => {
  3999. var fragment_8 = comment();
  4000. var node_14 = first_child(fragment_8);
  4001. component(node_14, () => toast2().title, ($$anchor5, $$component) => {
  4002. $$component($$anchor5, spread_props(() => toast2().componentProps));
  4003. });
  4004. append($$anchor4, fragment_8);
  4005. };
  4006. var alternate_5 = ($$anchor4) => {
  4007. var text$1 = text();
  4008. template_effect(() => set_text(text$1, toast2().title));
  4009. append($$anchor4, text$1);
  4010. };
  4011. if_block(node_13, ($$render) => {
  4012. if (typeof toast2().title !== "string") $$render(consequent_9);
  4013. else $$render(alternate_5, false);
  4014. });
  4015. }
  4016. template_effect(
  4017. ($0) => set_class(div_2, 1, $0),
  4018. [
  4019. () => {
  4020. var _a2, _b, _c;
  4021. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.title, (_c = (_b = toast2()) == null ? void 0 : _b.classes) == null ? void 0 : _c.title));
  4022. }
  4023. ],
  4024. derived_safe_equal
  4025. );
  4026. append($$anchor3, div_2);
  4027. };
  4028. if_block(node_12, ($$render) => {
  4029. if (toast2().title) $$render(consequent_10);
  4030. });
  4031. }
  4032. var node_15 = sibling(node_12, 2);
  4033. {
  4034. var consequent_12 = ($$anchor3) => {
  4035. var div_3 = root_18();
  4036. var node_16 = child(div_3);
  4037. {
  4038. var consequent_11 = ($$anchor4) => {
  4039. var fragment_10 = comment();
  4040. var node_17 = first_child(fragment_10);
  4041. component(node_17, () => toast2().description, ($$anchor5, $$component) => {
  4042. $$component($$anchor5, spread_props(() => toast2().componentProps));
  4043. });
  4044. append($$anchor4, fragment_10);
  4045. };
  4046. var alternate_6 = ($$anchor4) => {
  4047. var text_1 = text();
  4048. template_effect(() => set_text(text_1, toast2().description));
  4049. append($$anchor4, text_1);
  4050. };
  4051. if_block(node_16, ($$render) => {
  4052. if (typeof toast2().description !== "string") $$render(consequent_11);
  4053. else $$render(alternate_6, false);
  4054. });
  4055. }
  4056. template_effect(
  4057. ($0) => set_class(div_3, 1, $0),
  4058. [
  4059. () => {
  4060. var _a2, _b;
  4061. return clsx(cn(descriptionClass(), get$1(toastDescriptionClass), (_a2 = classes()) == null ? void 0 : _a2.description, (_b = toast2().classes) == null ? void 0 : _b.description));
  4062. }
  4063. ],
  4064. derived_safe_equal
  4065. );
  4066. append($$anchor3, div_3);
  4067. };
  4068. if_block(node_15, ($$render) => {
  4069. if (toast2().description) $$render(consequent_12);
  4070. });
  4071. }
  4072. var node_18 = sibling(div_1, 2);
  4073. {
  4074. var consequent_13 = ($$anchor3) => {
  4075. var button_1 = root_21();
  4076. var text_2 = child(button_1);
  4077. template_effect(
  4078. ($0) => {
  4079. set_style(button_1, cancelButtonStyle());
  4080. set_class(button_1, 1, $0);
  4081. set_text(text_2, toast2().cancel.label);
  4082. },
  4083. [
  4084. () => {
  4085. var _a2, _b, _c;
  4086. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.cancelButton, (_c = (_b = toast2()) == null ? void 0 : _b.classes) == null ? void 0 : _c.cancelButton));
  4087. }
  4088. ],
  4089. derived_safe_equal
  4090. );
  4091. event("click", button_1, () => {
  4092. var _a2;
  4093. deleteToast();
  4094. if ((_a2 = toast2().cancel) == null ? void 0 : _a2.onClick) {
  4095. toast2().cancel.onClick();
  4096. }
  4097. });
  4098. append($$anchor3, button_1);
  4099. };
  4100. if_block(node_18, ($$render) => {
  4101. if (toast2().cancel) $$render(consequent_13);
  4102. });
  4103. }
  4104. var node_19 = sibling(node_18, 2);
  4105. {
  4106. var consequent_14 = ($$anchor3) => {
  4107. var button_2 = root_22();
  4108. var text_3 = child(button_2);
  4109. template_effect(
  4110. ($0) => {
  4111. set_style(button_2, actionButtonStyle());
  4112. set_class(button_2, 1, $0);
  4113. set_text(text_3, toast2().action.label);
  4114. },
  4115. [
  4116. () => {
  4117. var _a2, _b, _c;
  4118. return clsx(cn((_a2 = classes()) == null ? void 0 : _a2.actionButton, (_c = (_b = toast2()) == null ? void 0 : _b.classes) == null ? void 0 : _c.actionButton));
  4119. }
  4120. ],
  4121. derived_safe_equal
  4122. );
  4123. event("click", button_2, (event2) => {
  4124. var _a2;
  4125. (_a2 = toast2().action) == null ? void 0 : _a2.onClick(event2);
  4126. if (event2.defaultPrevented) return;
  4127. deleteToast();
  4128. });
  4129. append($$anchor3, button_2);
  4130. };
  4131. if_block(node_19, ($$render) => {
  4132. if (toast2().action) $$render(consequent_14);
  4133. });
  4134. }
  4135. append($$anchor2, fragment_1);
  4136. };
  4137. if_block(node_1, ($$render) => {
  4138. if (toast2().component) $$render(consequent_1);
  4139. else $$render(alternate, false);
  4140. });
  4141. }
  4142. bind_this(li, ($$value) => set(toastRef, $$value), () => get$1(toastRef));
  4143. template_effect(
  4144. ($0, $1, $2) => {
  4145. var _a2;
  4146. set_attribute(li, "aria-live", toast2().important ? "assertive" : "polite");
  4147. set_class(li, 1, $0);
  4148. set_attribute(li, "data-styled", !(toast2().component || ((_a2 = toast2()) == null ? void 0 : _a2.unstyled) || unstyled()));
  4149. set_attribute(li, "data-mounted", get$1(mounted));
  4150. set_attribute(li, "data-promise", $1);
  4151. set_attribute(li, "data-removed", get$1(removed));
  4152. set_attribute(li, "data-visible", get$1(isVisible));
  4153. set_attribute(li, "data-y-position", get$1(coords)[0]);
  4154. set_attribute(li, "data-x-position", get$1(coords)[1]);
  4155. set_attribute(li, "data-index", index2());
  4156. set_attribute(li, "data-front", get$1(isFront));
  4157. set_attribute(li, "data-swiping", get$1(swiping));
  4158. set_attribute(li, "data-type", get$1(toastType));
  4159. set_attribute(li, "data-invert", invert());
  4160. set_attribute(li, "data-swipe-out", get$1(swipeOut));
  4161. set_attribute(li, "data-expanded", $2);
  4162. styles = set_style(li, `${$$sanitized_props.style} ${toast2().style}`, styles, {
  4163. "--index": index2(),
  4164. "--toasts-before": index2(),
  4165. "--z-index": $toasts().length - index2(),
  4166. "--offset": `${get$1(removed) ? get$1(offsetBeforeRemove) : get$1(offset)}px`,
  4167. "--initial-height": `${get$1(initialHeight)}px`
  4168. });
  4169. },
  4170. [
  4171. () => {
  4172. var _a2, _b, _c, _d, _e, _f;
  4173. return clsx(cn($$sanitized_props.class, get$1(toastClass), (_a2 = classes()) == null ? void 0 : _a2.toast, (_c = (_b = toast2()) == null ? void 0 : _b.classes) == null ? void 0 : _c.toast, (_d = classes()) == null ? void 0 : _d[get$1(toastType)], (_f = (_e = toast2()) == null ? void 0 : _e.classes) == null ? void 0 : _f[get$1(toastType)]));
  4174. },
  4175. () => Boolean(toast2().promise),
  4176. () => Boolean(expanded() || expandByDefault() && get$1(mounted))
  4177. ],
  4178. derived_safe_equal
  4179. );
  4180. event("pointerdown", li, onPointerDown);
  4181. event("pointerup", li, onPointerUp);
  4182. event("pointermove", li, onPointerMove);
  4183. append($$anchor, li);
  4184. pop();
  4185. $$cleanup();
  4186. }
  4187. var root_2 = /* @__PURE__ */ template(`<ol></ol>`);
  4188. var root_1$1 = /* @__PURE__ */ template(`<section class="svelte-1fo5d1m"></section>`);
  4189. function Toaster($$anchor, $$props) {
  4190. const $$sanitized_props = legacy_rest_props($$props, [
  4191. "children",
  4192. "$$slots",
  4193. "$$events",
  4194. "$$legacy"
  4195. ]);
  4196. const $$restProps = legacy_rest_props($$sanitized_props, [
  4197. "invert",
  4198. "theme",
  4199. "position",
  4200. "hotkey",
  4201. "containerAriaLabel",
  4202. "richColors",
  4203. "expand",
  4204. "duration",
  4205. "visibleToasts",
  4206. "closeButton",
  4207. "toastOptions",
  4208. "offset",
  4209. "dir"
  4210. ]);
  4211. push($$props, false);
  4212. const [$$stores, $$cleanup] = setup_stores();
  4213. const $toasts = () => store_get(toasts, "$toasts", $$stores);
  4214. const $heights = () => store_get(heights, "$heights", $$stores);
  4215. const possiblePositions = /* @__PURE__ */ mutable_source();
  4216. const hotkeyLabel = /* @__PURE__ */ mutable_source();
  4217. const VISIBLE_TOASTS_AMOUNT = 3;
  4218. const VIEWPORT_OFFSET = "32px";
  4219. const TOAST_WIDTH = 356;
  4220. const GAP = 14;
  4221. const DARK = "dark";
  4222. const LIGHT = "light";
  4223. function getInitialTheme(t) {
  4224. if (t !== "system") {
  4225. return t;
  4226. }
  4227. if (typeof window !== "undefined") {
  4228. if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
  4229. return DARK;
  4230. }
  4231. return LIGHT;
  4232. }
  4233. return LIGHT;
  4234. }
  4235. function getDocumentDirection() {
  4236. if (typeof window === "undefined") return "ltr";
  4237. if (typeof document === "undefined") return "ltr";
  4238. const dirAttribute = document.documentElement.getAttribute("dir");
  4239. if (dirAttribute === "auto" || !dirAttribute) {
  4240. return window.getComputedStyle(document.documentElement).direction;
  4241. }
  4242. return dirAttribute;
  4243. }
  4244. let invert = prop($$props, "invert", 8, false);
  4245. let theme = prop($$props, "theme", 8, "light");
  4246. let position = prop($$props, "position", 8, "bottom-right");
  4247. let hotkey = prop($$props, "hotkey", 24, () => ["altKey", "KeyT"]);
  4248. let containerAriaLabel = prop($$props, "containerAriaLabel", 8, "Notifications");
  4249. let richColors = prop($$props, "richColors", 8, false);
  4250. let expand = prop($$props, "expand", 8, false);
  4251. let duration = prop($$props, "duration", 8, 4e3);
  4252. let visibleToasts = prop($$props, "visibleToasts", 8, VISIBLE_TOASTS_AMOUNT);
  4253. let closeButton = prop($$props, "closeButton", 8, false);
  4254. let toastOptions = prop($$props, "toastOptions", 24, () => ({}));
  4255. let offset = prop($$props, "offset", 8, null);
  4256. let dir = prop($$props, "dir", 24, getDocumentDirection);
  4257. const { toasts, heights, reset } = toastState;
  4258. let expanded = /* @__PURE__ */ mutable_source(false);
  4259. let interacting = /* @__PURE__ */ mutable_source(false);
  4260. let actualTheme = /* @__PURE__ */ mutable_source(getInitialTheme(theme()));
  4261. let listRef = /* @__PURE__ */ mutable_source();
  4262. let lastFocusedElementRef = null;
  4263. let isFocusWithinRef = false;
  4264. onDestroy(() => {
  4265. if (get$1(listRef) && lastFocusedElementRef) {
  4266. lastFocusedElementRef.focus({ preventScroll: true });
  4267. lastFocusedElementRef = null;
  4268. isFocusWithinRef = false;
  4269. }
  4270. });
  4271. onMount(() => {
  4272. reset();
  4273. const handleKeydown = (event2) => {
  4274. var _a2, _b;
  4275. const isHotkeyPressed = hotkey().every((key) => (
  4276. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4277. event2[key] || event2.code === key
  4278. ));
  4279. if (isHotkeyPressed) {
  4280. set(expanded, true);
  4281. (_a2 = get$1(listRef)) == null ? void 0 : _a2.focus();
  4282. }
  4283. if (event2.code === "Escape" && (document.activeElement === get$1(listRef) || ((_b = get$1(listRef)) == null ? void 0 : _b.contains(document.activeElement)))) {
  4284. set(expanded, false);
  4285. }
  4286. };
  4287. document.addEventListener("keydown", handleKeydown);
  4288. return () => {
  4289. document.removeEventListener("keydown", handleKeydown);
  4290. };
  4291. });
  4292. function handleBlur(event2) {
  4293. if (isFocusWithinRef && !event2.currentTarget.contains(event2.relatedTarget)) {
  4294. isFocusWithinRef = false;
  4295. if (lastFocusedElementRef) {
  4296. lastFocusedElementRef.focus({ preventScroll: true });
  4297. lastFocusedElementRef = null;
  4298. }
  4299. }
  4300. }
  4301. function handleFocus(event2) {
  4302. if (!isFocusWithinRef) {
  4303. isFocusWithinRef = true;
  4304. lastFocusedElementRef = event2.relatedTarget;
  4305. }
  4306. }
  4307. legacy_pre_effect(
  4308. () => (deep_read_state(position()), $toasts()),
  4309. () => {
  4310. set(possiblePositions, Array.from(new Set([
  4311. position(),
  4312. ...$toasts().filter((toast2) => toast2.position).map((toast2) => toast2.position)
  4313. ].filter(Boolean))));
  4314. }
  4315. );
  4316. legacy_pre_effect(() => deep_read_state(hotkey()), () => {
  4317. set(hotkeyLabel, hotkey().join("+").replace(/Key/g, "").replace(/Digit/g, ""));
  4318. });
  4319. legacy_pre_effect(() => $toasts(), () => {
  4320. if ($toasts().length <= 1) {
  4321. set(expanded, false);
  4322. }
  4323. });
  4324. legacy_pre_effect(() => $toasts(), () => {
  4325. const toastsToDismiss = $toasts().filter((toast2) => toast2.dismiss && !toast2.delete);
  4326. if (toastsToDismiss.length > 0) {
  4327. const updatedToasts = $toasts().map((toast2) => {
  4328. const matchingToast = toastsToDismiss.find((dismissToast) => dismissToast.id === toast2.id);
  4329. if (matchingToast) {
  4330. return { ...toast2, delete: true };
  4331. }
  4332. return toast2;
  4333. });
  4334. toasts.set(updatedToasts);
  4335. }
  4336. });
  4337. legacy_pre_effect(() => deep_read_state(theme()), () => {
  4338. if (theme() !== "system") {
  4339. set(actualTheme, theme());
  4340. }
  4341. if (typeof window !== "undefined") {
  4342. if (theme() === "system") {
  4343. if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
  4344. set(actualTheme, DARK);
  4345. } else {
  4346. set(actualTheme, LIGHT);
  4347. }
  4348. }
  4349. const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
  4350. const changeHandler = ({ matches }) => {
  4351. set(actualTheme, matches ? DARK : LIGHT);
  4352. };
  4353. if ("addEventListener" in mediaQueryList) {
  4354. mediaQueryList.addEventListener("change", changeHandler);
  4355. } else {
  4356. mediaQueryList.addListener(changeHandler);
  4357. }
  4358. }
  4359. });
  4360. legacy_pre_effect_reset();
  4361. init();
  4362. var fragment = comment();
  4363. var node = first_child(fragment);
  4364. {
  4365. var consequent = ($$anchor2) => {
  4366. var section = root_1$1();
  4367. set_attribute(section, "tabindex", -1);
  4368. each(section, 5, () => get$1(possiblePositions), index, ($$anchor3, position2, index2, $$array) => {
  4369. var ol = root_2();
  4370. let attributes;
  4371. each(ol, 7, () => $toasts().filter((toast2) => !toast2.position && index2 === 0 || toast2.position === get$1(position2)), (toast2) => toast2.id, ($$anchor4, toast2, index3, $$array_1) => {
  4372. const expression = /* @__PURE__ */ derived_safe_equal(() => {
  4373. var _a2;
  4374. return ((_a2 = toastOptions()) == null ? void 0 : _a2.actionButtonStyle) || "";
  4375. });
  4376. const expression_1 = /* @__PURE__ */ derived_safe_equal(() => {
  4377. var _a2;
  4378. return ((_a2 = toastOptions()) == null ? void 0 : _a2.cancelButtonStyle) || "";
  4379. });
  4380. const expression_2 = /* @__PURE__ */ derived_safe_equal(() => {
  4381. var _a2;
  4382. return ((_a2 = toastOptions()) == null ? void 0 : _a2.class) || "";
  4383. });
  4384. const expression_3 = /* @__PURE__ */ derived_safe_equal(() => {
  4385. var _a2;
  4386. return ((_a2 = toastOptions()) == null ? void 0 : _a2.descriptionClass) || "";
  4387. });
  4388. const expression_4 = /* @__PURE__ */ derived_safe_equal(() => toastOptions().classes || {});
  4389. const expression_5 = /* @__PURE__ */ derived_safe_equal(() => {
  4390. var _a2;
  4391. return ((_a2 = toastOptions()) == null ? void 0 : _a2.duration) ?? duration();
  4392. });
  4393. const expression_6 = /* @__PURE__ */ derived_safe_equal(() => toastOptions().unstyled || false);
  4394. Toast($$anchor4, {
  4395. get index() {
  4396. return get$1(index3);
  4397. },
  4398. get toast() {
  4399. return get$1(toast2);
  4400. },
  4401. get invert() {
  4402. return invert();
  4403. },
  4404. get visibleToasts() {
  4405. return visibleToasts();
  4406. },
  4407. get closeButton() {
  4408. return closeButton();
  4409. },
  4410. get interacting() {
  4411. return get$1(interacting);
  4412. },
  4413. get position() {
  4414. return get$1(position2);
  4415. },
  4416. get expandByDefault() {
  4417. return expand();
  4418. },
  4419. get expanded() {
  4420. return get$1(expanded);
  4421. },
  4422. get actionButtonStyle() {
  4423. return get$1(expression);
  4424. },
  4425. get cancelButtonStyle() {
  4426. return get$1(expression_1);
  4427. },
  4428. get class() {
  4429. return get$1(expression_2);
  4430. },
  4431. get descriptionClass() {
  4432. return get$1(expression_3);
  4433. },
  4434. get classes() {
  4435. return get$1(expression_4);
  4436. },
  4437. get duration() {
  4438. return get$1(expression_5);
  4439. },
  4440. get unstyled() {
  4441. return get$1(expression_6);
  4442. },
  4443. $$slots: {
  4444. "loading-icon": ($$anchor5, $$slotProps) => {
  4445. var fragment_2 = comment();
  4446. var node_1 = first_child(fragment_2);
  4447. slot(node_1, $$props, "loading-icon", {}, ($$anchor6) => {
  4448. const expression_7 = /* @__PURE__ */ derived_safe_equal(() => get$1(toast2).type === "loading");
  4449. Loader($$anchor6, {
  4450. get visible() {
  4451. return get$1(expression_7);
  4452. }
  4453. });
  4454. });
  4455. append($$anchor5, fragment_2);
  4456. },
  4457. "success-icon": ($$anchor5, $$slotProps) => {
  4458. var fragment_4 = comment();
  4459. var node_2 = first_child(fragment_4);
  4460. slot(node_2, $$props, "success-icon", {}, ($$anchor6) => {
  4461. Icon($$anchor6, { type: "success" });
  4462. });
  4463. append($$anchor5, fragment_4);
  4464. },
  4465. "error-icon": ($$anchor5, $$slotProps) => {
  4466. var fragment_6 = comment();
  4467. var node_3 = first_child(fragment_6);
  4468. slot(node_3, $$props, "error-icon", {}, ($$anchor6) => {
  4469. Icon($$anchor6, { type: "error" });
  4470. });
  4471. append($$anchor5, fragment_6);
  4472. },
  4473. "warning-icon": ($$anchor5, $$slotProps) => {
  4474. var fragment_8 = comment();
  4475. var node_4 = first_child(fragment_8);
  4476. slot(node_4, $$props, "warning-icon", {}, ($$anchor6) => {
  4477. Icon($$anchor6, { type: "warning" });
  4478. });
  4479. append($$anchor5, fragment_8);
  4480. },
  4481. "info-icon": ($$anchor5, $$slotProps) => {
  4482. var fragment_10 = comment();
  4483. var node_5 = first_child(fragment_10);
  4484. slot(node_5, $$props, "info-icon", {}, ($$anchor6) => {
  4485. Icon($$anchor6, { type: "info" });
  4486. });
  4487. append($$anchor5, fragment_10);
  4488. }
  4489. }
  4490. });
  4491. });
  4492. bind_this(ol, ($$value) => set(listRef, $$value), () => get$1(listRef));
  4493. template_effect(
  4494. ($0, $1, $2) => {
  4495. var _a2;
  4496. attributes = set_attributes(
  4497. ol,
  4498. attributes,
  4499. {
  4500. tabIndex: -1,
  4501. class: $$sanitized_props.class,
  4502. "data-sonner-toaster": true,
  4503. "data-theme": get$1(actualTheme),
  4504. "data-rich-colors": richColors(),
  4505. dir: $0,
  4506. "data-y-position": $1,
  4507. "data-x-position": $2,
  4508. style: $$sanitized_props.style,
  4509. ...$$restProps,
  4510. [STYLE]: {
  4511. "--front-toast-height": `${(_a2 = $heights()[0]) == null ? void 0 : _a2.height}px`,
  4512. "--offset": typeof offset() === "number" ? `${offset()}px` : offset() || VIEWPORT_OFFSET,
  4513. "--width": `${TOAST_WIDTH}px`,
  4514. "--gap": `${GAP}px`
  4515. }
  4516. },
  4517. "svelte-1fo5d1m"
  4518. );
  4519. ol.dir = ol.dir;
  4520. },
  4521. [
  4522. () => dir() === "auto" ? getDocumentDirection() : dir(),
  4523. () => get$1(position2).split("-")[0],
  4524. () => get$1(position2).split("-")[1]
  4525. ],
  4526. derived_safe_equal
  4527. );
  4528. event("blur", ol, handleBlur);
  4529. event("focus", ol, handleFocus);
  4530. event("mouseenter", ol, () => set(expanded, true));
  4531. event("mousemove", ol, () => set(expanded, true));
  4532. event("mouseleave", ol, () => {
  4533. if (!get$1(interacting)) {
  4534. set(expanded, false);
  4535. }
  4536. });
  4537. event("pointerdown", ol, () => set(interacting, true));
  4538. event("pointerup", ol, () => set(interacting, false));
  4539. append($$anchor3, ol);
  4540. });
  4541. template_effect(() => set_attribute(section, "aria-label", `${containerAriaLabel()} ${get$1(hotkeyLabel)}`));
  4542. append($$anchor2, section);
  4543. };
  4544. if_block(node, ($$render) => {
  4545. if ($toasts().length > 0) $$render(consequent);
  4546. });
  4547. }
  4548. append($$anchor, fragment);
  4549. pop();
  4550. $$cleanup();
  4551. }
  4552. const CONFIG = {
  4553. APP_NAME: "LeetCode Toolkit"
  4554. };
  4555. const messageToastTypes = [
  4556. "success",
  4557. "info",
  4558. "warning",
  4559. "error",
  4560. "message",
  4561. "loading"
  4562. ];
  4563. function addPrefix(message) {
  4564. if (typeof message === "string") {
  4565. return `${CONFIG.APP_NAME}: ${message}`;
  4566. }
  4567. return message;
  4568. }
  4569. const prefixToast = new Proxy(toast, {
  4570. // Handle direct function calls: toast('message')
  4571. apply(target, thisArg, args) {
  4572. if (args.length > 0) {
  4573. args[0] = addPrefix(args[0]);
  4574. }
  4575. return Reflect.apply(target, thisArg, args);
  4576. },
  4577. get(target, prop2, receiver) {
  4578. const originalProp = Reflect.get(target, prop2, receiver);
  4579. if (typeof originalProp === "function" && messageToastTypes.includes(prop2.toString())) {
  4580. return function(...args) {
  4581. if (args.length > 0) {
  4582. args[0] = addPrefix(args[0]);
  4583. }
  4584. return originalProp.apply(this, args);
  4585. };
  4586. }
  4587. return originalProp;
  4588. }
  4589. });
  4590. class GlobalState {
  4591. constructor() {
  4592. __privateAdd(this, _site);
  4593. }
  4594. get site() {
  4595. if (!__privateGet(this, _site)) {
  4596. const hostname = window.location.hostname;
  4597. __privateSet(this, _site, hostname === "leetcode.cn" ? "cn" : "global");
  4598. }
  4599. return __privateGet(this, _site);
  4600. }
  4601. }
  4602. _site = new WeakMap();
  4603. const globalState = new GlobalState();
  4604. var _GM_getResourceText = /* @__PURE__ */ (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)();
  4605. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  4606. class TimeoutError extends Error {
  4607. constructor(item, timeout) {
  4608. super();
  4609. __publicField(this, "name", this.constructor.name);
  4610. this.message = `"${item}" not found within timeout (${timeout}ms)`;
  4611. }
  4612. }
  4613. function find(finderFn, {
  4614. subject = document,
  4615. observerOption = {
  4616. childList: true,
  4617. subtree: true
  4618. },
  4619. timeout = 5e3,
  4620. itemName = "Item"
  4621. }) {
  4622. return new Promise((resolve, reject) => {
  4623. const item = finderFn();
  4624. if (item) return resolve(item);
  4625. let timeoutId;
  4626. const observer = new MutationObserver(() => {
  4627. const item2 = finderFn();
  4628. if (item2) {
  4629. observer.disconnect();
  4630. clearTimeout(timeoutId);
  4631. return resolve(item2);
  4632. }
  4633. });
  4634. observer.observe(subject, observerOption);
  4635. if (timeout > 0) {
  4636. timeoutId = setTimeout(() => {
  4637. observer.disconnect();
  4638. prefixToast.error(
  4639. `${itemName} not found within timeout. Please refresh the page or disable the script.`
  4640. );
  4641. const error = new TimeoutError(itemName, timeout);
  4642. console.error(error);
  4643. return reject(error);
  4644. }, timeout);
  4645. }
  4646. });
  4647. }
  4648. async function findElement(selector, {
  4649. parent = document,
  4650. timeout = 500,
  4651. additionalRule
  4652. } = {}) {
  4653. const element = await find(
  4654. () => {
  4655. const el = parent.querySelector(selector);
  4656. if (additionalRule && el) {
  4657. return additionalRule(el) ? el : null;
  4658. } else {
  4659. return el;
  4660. }
  4661. },
  4662. {
  4663. subject: parent,
  4664. timeout,
  4665. itemName: `Element ${selector}`
  4666. }
  4667. );
  4668. return element;
  4669. }
  4670. const overrideOptions = {
  4671. selectionHighlight: true,
  4672. parameterHints: { enabled: true },
  4673. hover: { enabled: true },
  4674. quickSuggestions: true,
  4675. suggestOnTriggerCharacters: true,
  4676. "bracketPairColorization.enabled": true
  4677. };
  4678. function addIntellisense(editor) {
  4679. const originalUpdateOptions = editor.updateOptions.bind(editor);
  4680. editor.updateOptions = (options) => {
  4681. originalUpdateOptions({
  4682. ...options,
  4683. ...overrideOptions
  4684. });
  4685. };
  4686. }
  4687. async function findMonacoEditor() {
  4688. function getEditor() {
  4689. var _a2;
  4690. return ((_a2 = _unsafeWindow.monaco) == null ? void 0 : _a2.editor.getEditors()[0]) ?? null;
  4691. }
  4692. const editor = find(getEditor, {
  4693. subject: document.head,
  4694. observerOption: { childList: true },
  4695. itemName: "Monaco Editor"
  4696. });
  4697. return editor;
  4698. }
  4699. class ProblemPageState {
  4700. constructor() {
  4701. __publicField(this, "editor", null);
  4702. }
  4703. async patchMonacoEditor() {
  4704. this.editor = await findMonacoEditor();
  4705. this.enableFormatOnSave();
  4706. addIntellisense(this.editor);
  4707. }
  4708. enableFormatOnSave() {
  4709. document.addEventListener("keydown", async (e2) => {
  4710. var _a2, _b;
  4711. if (!(e2.ctrlKey && e2.key === "s")) return;
  4712. try {
  4713. await ((_b = (_a2 = this.editor) == null ? void 0 : _a2.getAction("editor.action.formatDocument")) == null ? void 0 : _b.run());
  4714. } catch (err) {
  4715. console.error(err);
  4716. if (err instanceof Error) {
  4717. toast.error("Failed to format code:" + err.message);
  4718. }
  4719. }
  4720. });
  4721. }
  4722. }
  4723. const problemState = new ProblemPageState();
  4724. function u$1(o2, n, a2) {
  4725. let t = (r2) => o2(r2, ...n);
  4726. return t;
  4727. }
  4728. function u(r2, n, o2) {
  4729. let a2 = r2.length - n.length;
  4730. if (a2 === 0) return r2(...n);
  4731. if (a2 === 1) return u$1(r2, n);
  4732. throw new Error("Wrong number of arguments");
  4733. }
  4734. var o$1 = [" ", `
  4735. `, "\v", "\f", "\r", " ", "…", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "\u2028", "\u2029", " ", " ", " ", "\uFEFF"], c = /* @__PURE__ */ new Set(["-", "_", ...o$1]), i = (r2) => {
  4736. let e2 = [], t = "", u2 = () => {
  4737. t.length > 0 && (e2.push(t), t = "");
  4738. };
  4739. for (let s of r2) {
  4740. if (c.has(s)) {
  4741. u2();
  4742. continue;
  4743. }
  4744. if (/[a-z]$/u.test(t) && /[A-Z]/u.test(s)) u2();
  4745. else if (/[A-Z][A-Z]$/u.test(t) && /[a-z]/u.test(s)) {
  4746. let n = t.slice(-1);
  4747. t = t.slice(0, -1), u2(), t = n;
  4748. } else /\d$/u.test(t) !== /\d/u.test(s) && u2();
  4749. t += s;
  4750. }
  4751. return u2(), e2;
  4752. };
  4753. function a(...e2) {
  4754. return u(o, e2);
  4755. }
  4756. var o = (e2) => i(e2).join("-").toLowerCase();
  4757. function e(o2) {
  4758. return o2 instanceof Promise;
  4759. }
  4760. const mouseClickEvents = ["mousedown", "mouseup", "click"];
  4761. function simulateMouseClickReact(element) {
  4762. mouseClickEvents.forEach(
  4763. (mouseEventType) => element.dispatchEvent(
  4764. new MouseEvent(mouseEventType, {
  4765. view: _unsafeWindow,
  4766. bubbles: true,
  4767. cancelable: true,
  4768. buttons: 1
  4769. })
  4770. )
  4771. );
  4772. }
  4773. const loaderIcon = ($$anchor) => {
  4774. var svg = root_1();
  4775. append($$anchor, svg);
  4776. };
  4777. var root_1 = /* @__PURE__ */ ns_template(`<svg class="animate-spin" xmlns="http://www.w3.org/2000/svg" width="1rem" height="1rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2v4m4.2 1.8l2.9-2.9M18 12h4m-5.8 4.2l2.9 2.9M12 18v4m-7.1-2.9l2.9-2.9M2 12h4M4.9 4.9l2.9 2.9"></path></svg>`);
  4778. var root$3 = /* @__PURE__ */ template(`<button><!> <!></button>`);
  4779. function Button($$anchor, $$props) {
  4780. push($$props, true);
  4781. let variant = prop($$props, "variant", 3, "purple"), type = prop($$props, "type", 3, "button"), restProps = /* @__PURE__ */ rest_props($$props, [
  4782. "$$slots",
  4783. "$$events",
  4784. "$$legacy",
  4785. "onclick",
  4786. "children",
  4787. "variant",
  4788. "type"
  4789. ]);
  4790. const variants = {
  4791. purple: "--bg: #6c5ce7; --shadow: #a29bfe",
  4792. green: "--bg: #1ba13e; --shadow: #42de6e",
  4793. orange: "--bg: #ffa116; --shadow: #fedd9b"
  4794. };
  4795. let loading = state(false);
  4796. async function handleOnClick(e$1) {
  4797. if (!$$props.onclick) return;
  4798. const returnValue = $$props.onclick(e$1);
  4799. if (e(returnValue)) {
  4800. set(loading, true);
  4801. await returnValue;
  4802. set(loading, false);
  4803. }
  4804. }
  4805. var button = root$3();
  4806. let attributes;
  4807. var node = child(button);
  4808. {
  4809. var consequent = ($$anchor2) => {
  4810. loaderIcon($$anchor2);
  4811. };
  4812. if_block(node, ($$render) => {
  4813. if (get$1(loading)) $$render(consequent);
  4814. });
  4815. }
  4816. var node_1 = sibling(node, 2);
  4817. snippet(node_1, () => $$props.children ?? noop);
  4818. template_effect(() => attributes = set_attributes(
  4819. button,
  4820. attributes,
  4821. {
  4822. type: type(),
  4823. style: variants[variant()],
  4824. disabled: get$1(loading),
  4825. onclick: handleOnClick,
  4826. ...restProps
  4827. },
  4828. "svelte-1dnnoz1"
  4829. ));
  4830. append($$anchor, button);
  4831. pop();
  4832. }
  4833. async function copy(text2, toastId) {
  4834. try {
  4835. await navigator.clipboard.writeText(text2);
  4836. prefixToast.success(
  4837. globalState.site === "cn" ? "复制到剪贴板!" : "Copied to clipboard!",
  4838. {
  4839. id: toastId
  4840. // update an already present toast, if given the id of that toast
  4841. }
  4842. );
  4843. } catch (err) {
  4844. if (err instanceof Error) {
  4845. const errorMessage = globalState.site === "cn" ? "复制失败" : "Failed to copy";
  4846. prefixToast.error(errorMessage + ": " + err.message, {
  4847. id: toastId
  4848. });
  4849. console.error(errorMessage + err);
  4850. } else throw err;
  4851. }
  4852. }
  4853. const getTitle = async () => {
  4854. const descriptionTabButton = (await findElement("#description_tab")).closest(".flexlayout__tab_button");
  4855. if (!(descriptionTabButton == null ? void 0 : descriptionTabButton.classList.contains(".flexlayout__tab_button--selected"))) {
  4856. simulateMouseClickReact(descriptionTabButton);
  4857. }
  4858. return (await findElement(".text-title-large")).textContent ?? "";
  4859. };
  4860. function Copy_title($$anchor, $$props) {
  4861. push($$props, false);
  4862. async function copyTitle() {
  4863. copy(await getTitle());
  4864. }
  4865. init();
  4866. Button($$anchor, {
  4867. onclick: copyTitle,
  4868. children: ($$anchor2, $$slotProps) => {
  4869. var text$1 = text();
  4870. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制标题" : "Copy Title"));
  4871. append($$anchor2, text$1);
  4872. },
  4873. $$slots: { default: true }
  4874. });
  4875. pop();
  4876. }
  4877. function extend(destination) {
  4878. for (var i2 = 1; i2 < arguments.length; i2++) {
  4879. var source2 = arguments[i2];
  4880. for (var key in source2) {
  4881. if (source2.hasOwnProperty(key)) destination[key] = source2[key];
  4882. }
  4883. }
  4884. return destination;
  4885. }
  4886. function repeat(character, count) {
  4887. return Array(count + 1).join(character);
  4888. }
  4889. function trimLeadingNewlines(string) {
  4890. return string.replace(/^\n*/, "");
  4891. }
  4892. function trimTrailingNewlines(string) {
  4893. var indexEnd = string.length;
  4894. while (indexEnd > 0 && string[indexEnd - 1] === "\n") indexEnd--;
  4895. return string.substring(0, indexEnd);
  4896. }
  4897. var blockElements = [
  4898. "ADDRESS",
  4899. "ARTICLE",
  4900. "ASIDE",
  4901. "AUDIO",
  4902. "BLOCKQUOTE",
  4903. "BODY",
  4904. "CANVAS",
  4905. "CENTER",
  4906. "DD",
  4907. "DIR",
  4908. "DIV",
  4909. "DL",
  4910. "DT",
  4911. "FIELDSET",
  4912. "FIGCAPTION",
  4913. "FIGURE",
  4914. "FOOTER",
  4915. "FORM",
  4916. "FRAMESET",
  4917. "H1",
  4918. "H2",
  4919. "H3",
  4920. "H4",
  4921. "H5",
  4922. "H6",
  4923. "HEADER",
  4924. "HGROUP",
  4925. "HR",
  4926. "HTML",
  4927. "ISINDEX",
  4928. "LI",
  4929. "MAIN",
  4930. "MENU",
  4931. "NAV",
  4932. "NOFRAMES",
  4933. "NOSCRIPT",
  4934. "OL",
  4935. "OUTPUT",
  4936. "P",
  4937. "PRE",
  4938. "SECTION",
  4939. "TABLE",
  4940. "TBODY",
  4941. "TD",
  4942. "TFOOT",
  4943. "TH",
  4944. "THEAD",
  4945. "TR",
  4946. "UL"
  4947. ];
  4948. function isBlock(node) {
  4949. return is(node, blockElements);
  4950. }
  4951. var voidElements = [
  4952. "AREA",
  4953. "BASE",
  4954. "BR",
  4955. "COL",
  4956. "COMMAND",
  4957. "EMBED",
  4958. "HR",
  4959. "IMG",
  4960. "INPUT",
  4961. "KEYGEN",
  4962. "LINK",
  4963. "META",
  4964. "PARAM",
  4965. "SOURCE",
  4966. "TRACK",
  4967. "WBR"
  4968. ];
  4969. function isVoid(node) {
  4970. return is(node, voidElements);
  4971. }
  4972. function hasVoid(node) {
  4973. return has(node, voidElements);
  4974. }
  4975. var meaningfulWhenBlankElements = [
  4976. "A",
  4977. "TABLE",
  4978. "THEAD",
  4979. "TBODY",
  4980. "TFOOT",
  4981. "TH",
  4982. "TD",
  4983. "IFRAME",
  4984. "SCRIPT",
  4985. "AUDIO",
  4986. "VIDEO"
  4987. ];
  4988. function isMeaningfulWhenBlank(node) {
  4989. return is(node, meaningfulWhenBlankElements);
  4990. }
  4991. function hasMeaningfulWhenBlank(node) {
  4992. return has(node, meaningfulWhenBlankElements);
  4993. }
  4994. function is(node, tagNames) {
  4995. return tagNames.indexOf(node.nodeName) >= 0;
  4996. }
  4997. function has(node, tagNames) {
  4998. return node.getElementsByTagName && tagNames.some(function(tagName) {
  4999. return node.getElementsByTagName(tagName).length;
  5000. });
  5001. }
  5002. var rules = {};
  5003. rules.paragraph = {
  5004. filter: "p",
  5005. replacement: function(content) {
  5006. return "\n\n" + content + "\n\n";
  5007. }
  5008. };
  5009. rules.lineBreak = {
  5010. filter: "br",
  5011. replacement: function(content, node, options) {
  5012. return options.br + "\n";
  5013. }
  5014. };
  5015. rules.heading = {
  5016. filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
  5017. replacement: function(content, node, options) {
  5018. var hLevel = Number(node.nodeName.charAt(1));
  5019. if (options.headingStyle === "setext" && hLevel < 3) {
  5020. var underline = repeat(hLevel === 1 ? "=" : "-", content.length);
  5021. return "\n\n" + content + "\n" + underline + "\n\n";
  5022. } else {
  5023. return "\n\n" + repeat("#", hLevel) + " " + content + "\n\n";
  5024. }
  5025. }
  5026. };
  5027. rules.blockquote = {
  5028. filter: "blockquote",
  5029. replacement: function(content) {
  5030. content = content.replace(/^\n+|\n+$/g, "");
  5031. content = content.replace(/^/gm, "> ");
  5032. return "\n\n" + content + "\n\n";
  5033. }
  5034. };
  5035. rules.list = {
  5036. filter: ["ul", "ol"],
  5037. replacement: function(content, node) {
  5038. var parent = node.parentNode;
  5039. if (parent.nodeName === "LI" && parent.lastElementChild === node) {
  5040. return "\n" + content;
  5041. } else {
  5042. return "\n\n" + content + "\n\n";
  5043. }
  5044. }
  5045. };
  5046. rules.listItem = {
  5047. filter: "li",
  5048. replacement: function(content, node, options) {
  5049. content = content.replace(/^\n+/, "").replace(/\n+$/, "\n").replace(/\n/gm, "\n ");
  5050. var prefix = options.bulletListMarker + " ";
  5051. var parent = node.parentNode;
  5052. if (parent.nodeName === "OL") {
  5053. var start = parent.getAttribute("start");
  5054. var index2 = Array.prototype.indexOf.call(parent.children, node);
  5055. prefix = (start ? Number(start) + index2 : index2 + 1) + ". ";
  5056. }
  5057. return prefix + content + (node.nextSibling && !/\n$/.test(content) ? "\n" : "");
  5058. }
  5059. };
  5060. rules.indentedCodeBlock = {
  5061. filter: function(node, options) {
  5062. return options.codeBlockStyle === "indented" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
  5063. },
  5064. replacement: function(content, node, options) {
  5065. return "\n\n " + node.firstChild.textContent.replace(/\n/g, "\n ") + "\n\n";
  5066. }
  5067. };
  5068. rules.fencedCodeBlock = {
  5069. filter: function(node, options) {
  5070. return options.codeBlockStyle === "fenced" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
  5071. },
  5072. replacement: function(content, node, options) {
  5073. var className = node.firstChild.getAttribute("class") || "";
  5074. var language = (className.match(/language-(\S+)/) || [null, ""])[1];
  5075. var code = node.firstChild.textContent;
  5076. var fenceChar = options.fence.charAt(0);
  5077. var fenceSize = 3;
  5078. var fenceInCodeRegex = new RegExp("^" + fenceChar + "{3,}", "gm");
  5079. var match;
  5080. while (match = fenceInCodeRegex.exec(code)) {
  5081. if (match[0].length >= fenceSize) {
  5082. fenceSize = match[0].length + 1;
  5083. }
  5084. }
  5085. var fence = repeat(fenceChar, fenceSize);
  5086. return "\n\n" + fence + language + "\n" + code.replace(/\n$/, "") + "\n" + fence + "\n\n";
  5087. }
  5088. };
  5089. rules.horizontalRule = {
  5090. filter: "hr",
  5091. replacement: function(content, node, options) {
  5092. return "\n\n" + options.hr + "\n\n";
  5093. }
  5094. };
  5095. rules.inlineLink = {
  5096. filter: function(node, options) {
  5097. return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
  5098. },
  5099. replacement: function(content, node) {
  5100. var href = node.getAttribute("href");
  5101. if (href) href = href.replace(/([()])/g, "\\$1");
  5102. var title = cleanAttribute(node.getAttribute("title"));
  5103. if (title) title = ' "' + title.replace(/"/g, '\\"') + '"';
  5104. return "[" + content + "](" + href + title + ")";
  5105. }
  5106. };
  5107. rules.referenceLink = {
  5108. filter: function(node, options) {
  5109. return options.linkStyle === "referenced" && node.nodeName === "A" && node.getAttribute("href");
  5110. },
  5111. replacement: function(content, node, options) {
  5112. var href = node.getAttribute("href");
  5113. var title = cleanAttribute(node.getAttribute("title"));
  5114. if (title) title = ' "' + title + '"';
  5115. var replacement;
  5116. var reference;
  5117. switch (options.linkReferenceStyle) {
  5118. case "collapsed":
  5119. replacement = "[" + content + "][]";
  5120. reference = "[" + content + "]: " + href + title;
  5121. break;
  5122. case "shortcut":
  5123. replacement = "[" + content + "]";
  5124. reference = "[" + content + "]: " + href + title;
  5125. break;
  5126. default:
  5127. var id = this.references.length + 1;
  5128. replacement = "[" + content + "][" + id + "]";
  5129. reference = "[" + id + "]: " + href + title;
  5130. }
  5131. this.references.push(reference);
  5132. return replacement;
  5133. },
  5134. references: [],
  5135. append: function(options) {
  5136. var references = "";
  5137. if (this.references.length) {
  5138. references = "\n\n" + this.references.join("\n") + "\n\n";
  5139. this.references = [];
  5140. }
  5141. return references;
  5142. }
  5143. };
  5144. rules.emphasis = {
  5145. filter: ["em", "i"],
  5146. replacement: function(content, node, options) {
  5147. if (!content.trim()) return "";
  5148. return options.emDelimiter + content + options.emDelimiter;
  5149. }
  5150. };
  5151. rules.strong = {
  5152. filter: ["strong", "b"],
  5153. replacement: function(content, node, options) {
  5154. if (!content.trim()) return "";
  5155. return options.strongDelimiter + content + options.strongDelimiter;
  5156. }
  5157. };
  5158. rules.code = {
  5159. filter: function(node) {
  5160. var hasSiblings = node.previousSibling || node.nextSibling;
  5161. var isCodeBlock = node.parentNode.nodeName === "PRE" && !hasSiblings;
  5162. return node.nodeName === "CODE" && !isCodeBlock;
  5163. },
  5164. replacement: function(content) {
  5165. if (!content) return "";
  5166. content = content.replace(/\r?\n|\r/g, " ");
  5167. var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? " " : "";
  5168. var delimiter = "`";
  5169. var matches = content.match(/`+/gm) || [];
  5170. while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + "`";
  5171. return delimiter + extraSpace + content + extraSpace + delimiter;
  5172. }
  5173. };
  5174. rules.image = {
  5175. filter: "img",
  5176. replacement: function(content, node) {
  5177. var alt = cleanAttribute(node.getAttribute("alt"));
  5178. var src = node.getAttribute("src") || "";
  5179. var title = cleanAttribute(node.getAttribute("title"));
  5180. var titlePart = title ? ' "' + title + '"' : "";
  5181. return src ? "![" + alt + "](" + src + titlePart + ")" : "";
  5182. }
  5183. };
  5184. function cleanAttribute(attribute) {
  5185. return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
  5186. }
  5187. function Rules(options) {
  5188. this.options = options;
  5189. this._keep = [];
  5190. this._remove = [];
  5191. this.blankRule = {
  5192. replacement: options.blankReplacement
  5193. };
  5194. this.keepReplacement = options.keepReplacement;
  5195. this.defaultRule = {
  5196. replacement: options.defaultReplacement
  5197. };
  5198. this.array = [];
  5199. for (var key in options.rules) this.array.push(options.rules[key]);
  5200. }
  5201. Rules.prototype = {
  5202. add: function(key, rule) {
  5203. this.array.unshift(rule);
  5204. },
  5205. keep: function(filter) {
  5206. this._keep.unshift({
  5207. filter,
  5208. replacement: this.keepReplacement
  5209. });
  5210. },
  5211. remove: function(filter) {
  5212. this._remove.unshift({
  5213. filter,
  5214. replacement: function() {
  5215. return "";
  5216. }
  5217. });
  5218. },
  5219. forNode: function(node) {
  5220. if (node.isBlank) return this.blankRule;
  5221. var rule;
  5222. if (rule = findRule(this.array, node, this.options)) return rule;
  5223. if (rule = findRule(this._keep, node, this.options)) return rule;
  5224. if (rule = findRule(this._remove, node, this.options)) return rule;
  5225. return this.defaultRule;
  5226. },
  5227. forEach: function(fn) {
  5228. for (var i2 = 0; i2 < this.array.length; i2++) fn(this.array[i2], i2);
  5229. }
  5230. };
  5231. function findRule(rules2, node, options) {
  5232. for (var i2 = 0; i2 < rules2.length; i2++) {
  5233. var rule = rules2[i2];
  5234. if (filterValue(rule, node, options)) return rule;
  5235. }
  5236. return void 0;
  5237. }
  5238. function filterValue(rule, node, options) {
  5239. var filter = rule.filter;
  5240. if (typeof filter === "string") {
  5241. if (filter === node.nodeName.toLowerCase()) return true;
  5242. } else if (Array.isArray(filter)) {
  5243. if (filter.indexOf(node.nodeName.toLowerCase()) > -1) return true;
  5244. } else if (typeof filter === "function") {
  5245. if (filter.call(rule, node, options)) return true;
  5246. } else {
  5247. throw new TypeError("`filter` needs to be a string, array, or function");
  5248. }
  5249. }
  5250. function collapseWhitespace(options) {
  5251. var element = options.element;
  5252. var isBlock2 = options.isBlock;
  5253. var isVoid2 = options.isVoid;
  5254. var isPre = options.isPre || function(node2) {
  5255. return node2.nodeName === "PRE";
  5256. };
  5257. if (!element.firstChild || isPre(element)) return;
  5258. var prevText = null;
  5259. var keepLeadingWs = false;
  5260. var prev = null;
  5261. var node = next(prev, element, isPre);
  5262. while (node !== element) {
  5263. if (node.nodeType === 3 || node.nodeType === 4) {
  5264. var text2 = node.data.replace(/[ \r\n\t]+/g, " ");
  5265. if ((!prevText || / $/.test(prevText.data)) && !keepLeadingWs && text2[0] === " ") {
  5266. text2 = text2.substr(1);
  5267. }
  5268. if (!text2) {
  5269. node = remove(node);
  5270. continue;
  5271. }
  5272. node.data = text2;
  5273. prevText = node;
  5274. } else if (node.nodeType === 1) {
  5275. if (isBlock2(node) || node.nodeName === "BR") {
  5276. if (prevText) {
  5277. prevText.data = prevText.data.replace(/ $/, "");
  5278. }
  5279. prevText = null;
  5280. keepLeadingWs = false;
  5281. } else if (isVoid2(node) || isPre(node)) {
  5282. prevText = null;
  5283. keepLeadingWs = true;
  5284. } else if (prevText) {
  5285. keepLeadingWs = false;
  5286. }
  5287. } else {
  5288. node = remove(node);
  5289. continue;
  5290. }
  5291. var nextNode = next(prev, node, isPre);
  5292. prev = node;
  5293. node = nextNode;
  5294. }
  5295. if (prevText) {
  5296. prevText.data = prevText.data.replace(/ $/, "");
  5297. if (!prevText.data) {
  5298. remove(prevText);
  5299. }
  5300. }
  5301. }
  5302. function remove(node) {
  5303. var next2 = node.nextSibling || node.parentNode;
  5304. node.parentNode.removeChild(node);
  5305. return next2;
  5306. }
  5307. function next(prev, current, isPre) {
  5308. if (prev && prev.parentNode === current || isPre(current)) {
  5309. return current.nextSibling || current.parentNode;
  5310. }
  5311. return current.firstChild || current.nextSibling || current.parentNode;
  5312. }
  5313. var root$2 = typeof window !== "undefined" ? window : {};
  5314. function canParseHTMLNatively() {
  5315. var Parser = root$2.DOMParser;
  5316. var canParse = false;
  5317. try {
  5318. if (new Parser().parseFromString("", "text/html")) {
  5319. canParse = true;
  5320. }
  5321. } catch (e2) {
  5322. }
  5323. return canParse;
  5324. }
  5325. function createHTMLParser() {
  5326. var Parser = function() {
  5327. };
  5328. {
  5329. if (shouldUseActiveX()) {
  5330. Parser.prototype.parseFromString = function(string) {
  5331. var doc = new window.ActiveXObject("htmlfile");
  5332. doc.designMode = "on";
  5333. doc.open();
  5334. doc.write(string);
  5335. doc.close();
  5336. return doc;
  5337. };
  5338. } else {
  5339. Parser.prototype.parseFromString = function(string) {
  5340. var doc = document.implementation.createHTMLDocument("");
  5341. doc.open();
  5342. doc.write(string);
  5343. doc.close();
  5344. return doc;
  5345. };
  5346. }
  5347. }
  5348. return Parser;
  5349. }
  5350. function shouldUseActiveX() {
  5351. var useActiveX = false;
  5352. try {
  5353. document.implementation.createHTMLDocument("").open();
  5354. } catch (e2) {
  5355. if (root$2.ActiveXObject) useActiveX = true;
  5356. }
  5357. return useActiveX;
  5358. }
  5359. var HTMLParser = canParseHTMLNatively() ? root$2.DOMParser : createHTMLParser();
  5360. function RootNode(input, options) {
  5361. var root2;
  5362. if (typeof input === "string") {
  5363. var doc = htmlParser().parseFromString(
  5364. // DOM parsers arrange elements in the <head> and <body>.
  5365. // Wrapping in a custom element ensures elements are reliably arranged in
  5366. // a single element.
  5367. '<x-turndown id="turndown-root">' + input + "</x-turndown>",
  5368. "text/html"
  5369. );
  5370. root2 = doc.getElementById("turndown-root");
  5371. } else {
  5372. root2 = input.cloneNode(true);
  5373. }
  5374. collapseWhitespace({
  5375. element: root2,
  5376. isBlock,
  5377. isVoid,
  5378. isPre: options.preformattedCode ? isPreOrCode : null
  5379. });
  5380. return root2;
  5381. }
  5382. var _htmlParser;
  5383. function htmlParser() {
  5384. _htmlParser = _htmlParser || new HTMLParser();
  5385. return _htmlParser;
  5386. }
  5387. function isPreOrCode(node) {
  5388. return node.nodeName === "PRE" || node.nodeName === "CODE";
  5389. }
  5390. function Node$1(node, options) {
  5391. node.isBlock = isBlock(node);
  5392. node.isCode = node.nodeName === "CODE" || node.parentNode.isCode;
  5393. node.isBlank = isBlank(node);
  5394. node.flankingWhitespace = flankingWhitespace(node, options);
  5395. return node;
  5396. }
  5397. function isBlank(node) {
  5398. return !isVoid(node) && !isMeaningfulWhenBlank(node) && /^\s*$/i.test(node.textContent) && !hasVoid(node) && !hasMeaningfulWhenBlank(node);
  5399. }
  5400. function flankingWhitespace(node, options) {
  5401. if (node.isBlock || options.preformattedCode && node.isCode) {
  5402. return { leading: "", trailing: "" };
  5403. }
  5404. var edges = edgeWhitespace(node.textContent);
  5405. if (edges.leadingAscii && isFlankedByWhitespace("left", node, options)) {
  5406. edges.leading = edges.leadingNonAscii;
  5407. }
  5408. if (edges.trailingAscii && isFlankedByWhitespace("right", node, options)) {
  5409. edges.trailing = edges.trailingNonAscii;
  5410. }
  5411. return { leading: edges.leading, trailing: edges.trailing };
  5412. }
  5413. function edgeWhitespace(string) {
  5414. var m = string.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);
  5415. return {
  5416. leading: m[1],
  5417. // whole string for whitespace-only strings
  5418. leadingAscii: m[2],
  5419. leadingNonAscii: m[3],
  5420. trailing: m[4],
  5421. // empty for whitespace-only strings
  5422. trailingNonAscii: m[5],
  5423. trailingAscii: m[6]
  5424. };
  5425. }
  5426. function isFlankedByWhitespace(side, node, options) {
  5427. var sibling2;
  5428. var regExp;
  5429. var isFlanked;
  5430. if (side === "left") {
  5431. sibling2 = node.previousSibling;
  5432. regExp = / $/;
  5433. } else {
  5434. sibling2 = node.nextSibling;
  5435. regExp = /^ /;
  5436. }
  5437. if (sibling2) {
  5438. if (sibling2.nodeType === 3) {
  5439. isFlanked = regExp.test(sibling2.nodeValue);
  5440. } else if (options.preformattedCode && sibling2.nodeName === "CODE") {
  5441. isFlanked = false;
  5442. } else if (sibling2.nodeType === 1 && !isBlock(sibling2)) {
  5443. isFlanked = regExp.test(sibling2.textContent);
  5444. }
  5445. }
  5446. return isFlanked;
  5447. }
  5448. var reduce = Array.prototype.reduce;
  5449. var escapes = [
  5450. [/\\/g, "\\\\"],
  5451. [/\*/g, "\\*"],
  5452. [/^-/g, "\\-"],
  5453. [/^\+ /g, "\\+ "],
  5454. [/^(=+)/g, "\\$1"],
  5455. [/^(#{1,6}) /g, "\\$1 "],
  5456. [/`/g, "\\`"],
  5457. [/^~~~/g, "\\~~~"],
  5458. [/\[/g, "\\["],
  5459. [/\]/g, "\\]"],
  5460. [/^>/g, "\\>"],
  5461. [/_/g, "\\_"],
  5462. [/^(\d+)\. /g, "$1\\. "]
  5463. ];
  5464. function TurndownService(options) {
  5465. if (!(this instanceof TurndownService)) return new TurndownService(options);
  5466. var defaults = {
  5467. rules,
  5468. headingStyle: "setext",
  5469. hr: "* * *",
  5470. bulletListMarker: "*",
  5471. codeBlockStyle: "indented",
  5472. fence: "```",
  5473. emDelimiter: "_",
  5474. strongDelimiter: "**",
  5475. linkStyle: "inlined",
  5476. linkReferenceStyle: "full",
  5477. br: " ",
  5478. preformattedCode: false,
  5479. blankReplacement: function(content, node) {
  5480. return node.isBlock ? "\n\n" : "";
  5481. },
  5482. keepReplacement: function(content, node) {
  5483. return node.isBlock ? "\n\n" + node.outerHTML + "\n\n" : node.outerHTML;
  5484. },
  5485. defaultReplacement: function(content, node) {
  5486. return node.isBlock ? "\n\n" + content + "\n\n" : content;
  5487. }
  5488. };
  5489. this.options = extend({}, defaults, options);
  5490. this.rules = new Rules(this.options);
  5491. }
  5492. TurndownService.prototype = {
  5493. /**
  5494. * The entry point for converting a string or DOM node to Markdown
  5495. * @public
  5496. * @param {String|HTMLElement} input The string or DOM node to convert
  5497. * @returns A Markdown representation of the input
  5498. * @type String
  5499. */
  5500. turndown: function(input) {
  5501. if (!canConvert(input)) {
  5502. throw new TypeError(
  5503. input + " is not a string, or an element/document/fragment node."
  5504. );
  5505. }
  5506. if (input === "") return "";
  5507. var output = process.call(this, new RootNode(input, this.options));
  5508. return postProcess.call(this, output);
  5509. },
  5510. /**
  5511. * Add one or more plugins
  5512. * @public
  5513. * @param {Function|Array} plugin The plugin or array of plugins to add
  5514. * @returns The Turndown instance for chaining
  5515. * @type Object
  5516. */
  5517. use: function(plugin) {
  5518. if (Array.isArray(plugin)) {
  5519. for (var i2 = 0; i2 < plugin.length; i2++) this.use(plugin[i2]);
  5520. } else if (typeof plugin === "function") {
  5521. plugin(this);
  5522. } else {
  5523. throw new TypeError("plugin must be a Function or an Array of Functions");
  5524. }
  5525. return this;
  5526. },
  5527. /**
  5528. * Adds a rule
  5529. * @public
  5530. * @param {String} key The unique key of the rule
  5531. * @param {Object} rule The rule
  5532. * @returns The Turndown instance for chaining
  5533. * @type Object
  5534. */
  5535. addRule: function(key, rule) {
  5536. this.rules.add(key, rule);
  5537. return this;
  5538. },
  5539. /**
  5540. * Keep a node (as HTML) that matches the filter
  5541. * @public
  5542. * @param {String|Array|Function} filter The unique key of the rule
  5543. * @returns The Turndown instance for chaining
  5544. * @type Object
  5545. */
  5546. keep: function(filter) {
  5547. this.rules.keep(filter);
  5548. return this;
  5549. },
  5550. /**
  5551. * Remove a node that matches the filter
  5552. * @public
  5553. * @param {String|Array|Function} filter The unique key of the rule
  5554. * @returns The Turndown instance for chaining
  5555. * @type Object
  5556. */
  5557. remove: function(filter) {
  5558. this.rules.remove(filter);
  5559. return this;
  5560. },
  5561. /**
  5562. * Escapes Markdown syntax
  5563. * @public
  5564. * @param {String} string The string to escape
  5565. * @returns A string with Markdown syntax escaped
  5566. * @type String
  5567. */
  5568. escape: function(string) {
  5569. return escapes.reduce(function(accumulator, escape) {
  5570. return accumulator.replace(escape[0], escape[1]);
  5571. }, string);
  5572. }
  5573. };
  5574. function process(parentNode) {
  5575. var self = this;
  5576. return reduce.call(parentNode.childNodes, function(output, node) {
  5577. node = new Node$1(node, self.options);
  5578. var replacement = "";
  5579. if (node.nodeType === 3) {
  5580. replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
  5581. } else if (node.nodeType === 1) {
  5582. replacement = replacementForNode.call(self, node);
  5583. }
  5584. return join(output, replacement);
  5585. }, "");
  5586. }
  5587. function postProcess(output) {
  5588. var self = this;
  5589. this.rules.forEach(function(rule) {
  5590. if (typeof rule.append === "function") {
  5591. output = join(output, rule.append(self.options));
  5592. }
  5593. });
  5594. return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
  5595. }
  5596. function replacementForNode(node) {
  5597. var rule = this.rules.forNode(node);
  5598. var content = process.call(this, node);
  5599. var whitespace2 = node.flankingWhitespace;
  5600. if (whitespace2.leading || whitespace2.trailing) content = content.trim();
  5601. return whitespace2.leading + rule.replacement(content, node, this.options) + whitespace2.trailing;
  5602. }
  5603. function join(output, replacement) {
  5604. var s1 = trimTrailingNewlines(output);
  5605. var s2 = trimLeadingNewlines(replacement);
  5606. var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
  5607. var separator = "\n\n".substring(0, nls);
  5608. return s1 + separator + s2;
  5609. }
  5610. function canConvert(input) {
  5611. return input != null && (typeof input === "string" || input.nodeType && (input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11));
  5612. }
  5613. var turndownPluginGfm_cjs = {};
  5614. var hasRequiredTurndownPluginGfm_cjs;
  5615. function requireTurndownPluginGfm_cjs() {
  5616. if (hasRequiredTurndownPluginGfm_cjs) return turndownPluginGfm_cjs;
  5617. hasRequiredTurndownPluginGfm_cjs = 1;
  5618. Object.defineProperty(turndownPluginGfm_cjs, "__esModule", { value: true });
  5619. var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
  5620. function highlightedCodeBlock(turndownService) {
  5621. turndownService.addRule("highlightedCodeBlock", {
  5622. filter: function(node) {
  5623. var firstChild = node.firstChild;
  5624. return node.nodeName === "DIV" && highlightRegExp.test(node.className) && firstChild && firstChild.nodeName === "PRE";
  5625. },
  5626. replacement: function(content, node, options) {
  5627. var className = node.className || "";
  5628. var language = (className.match(highlightRegExp) || [null, ""])[1];
  5629. return "\n\n" + options.fence + language + "\n" + node.firstChild.textContent + "\n" + options.fence + "\n\n";
  5630. }
  5631. });
  5632. }
  5633. function strikethrough(turndownService) {
  5634. turndownService.addRule("strikethrough", {
  5635. filter: ["del", "s", "strike"],
  5636. replacement: function(content) {
  5637. return "~~" + content + "~~";
  5638. }
  5639. });
  5640. }
  5641. var indexOf = Array.prototype.indexOf;
  5642. var every = Array.prototype.every;
  5643. var rules2 = {};
  5644. var alignMap = { left: ":---", right: "---:", center: ":---:" };
  5645. let isCodeBlock_ = null;
  5646. let options_ = null;
  5647. const tableShouldBeSkippedCache_ = /* @__PURE__ */ new WeakMap();
  5648. function getAlignment(node) {
  5649. return node ? (node.getAttribute("align") || node.style.textAlign || "").toLowerCase() : "";
  5650. }
  5651. function getBorder(alignment) {
  5652. return alignment ? alignMap[alignment] : "---";
  5653. }
  5654. function getColumnAlignment(table, columnIndex) {
  5655. var votes = {
  5656. left: 0,
  5657. right: 0,
  5658. center: 0,
  5659. "": 0
  5660. };
  5661. var align = "";
  5662. for (var i2 = 0; i2 < table.rows.length; ++i2) {
  5663. var row = table.rows[i2];
  5664. if (columnIndex < row.childNodes.length) {
  5665. var cellAlignment = getAlignment(row.childNodes[columnIndex]);
  5666. ++votes[cellAlignment];
  5667. if (votes[cellAlignment] > votes[align]) {
  5668. align = cellAlignment;
  5669. }
  5670. }
  5671. }
  5672. return align;
  5673. }
  5674. rules2.tableCell = {
  5675. filter: ["th", "td"],
  5676. replacement: function(content, node) {
  5677. if (tableShouldBeSkipped(nodeParentTable(node))) return content;
  5678. return cell(content, node);
  5679. }
  5680. };
  5681. rules2.tableRow = {
  5682. filter: "tr",
  5683. replacement: function(content, node) {
  5684. const parentTable = nodeParentTable(node);
  5685. if (tableShouldBeSkipped(parentTable)) return content;
  5686. var borderCells = "";
  5687. if (isHeadingRow(node)) {
  5688. const colCount = tableColCount(parentTable);
  5689. for (var i2 = 0; i2 < colCount; i2++) {
  5690. const childNode = i2 < node.childNodes.length ? node.childNodes[i2] : null;
  5691. var border = getBorder(getColumnAlignment(parentTable, i2));
  5692. borderCells += cell(border, childNode, i2);
  5693. }
  5694. }
  5695. return "\n" + content + (borderCells ? "\n" + borderCells : "");
  5696. }
  5697. };
  5698. rules2.table = {
  5699. filter: function(node, options) {
  5700. return node.nodeName === "TABLE";
  5701. },
  5702. replacement: function(content, node) {
  5703. if (tableShouldBeHtml(node, options_)) {
  5704. let html = node.outerHTML;
  5705. let divParent = nodeParentDiv(node);
  5706. if (divParent === null || !divParent.classList.contains("joplin-table-wrapper")) {
  5707. return `
  5708.  
  5709. <div class="joplin-table-wrapper">${html}</div>
  5710.  
  5711. `;
  5712. } else {
  5713. return html;
  5714. }
  5715. } else {
  5716. if (tableShouldBeSkipped(node)) return content;
  5717. content = content.replace(/\n+/g, "\n");
  5718. var secondLine = content.trim().split("\n");
  5719. if (secondLine.length >= 2) secondLine = secondLine[1];
  5720. var secondLineIsDivider = /\| :?---/.test(secondLine);
  5721. var columnCount = tableColCount(node);
  5722. var emptyHeader = "";
  5723. if (columnCount && !secondLineIsDivider) {
  5724. emptyHeader = "|" + " |".repeat(columnCount) + "\n|";
  5725. for (var columnIndex = 0; columnIndex < columnCount; ++columnIndex) {
  5726. emptyHeader += " " + getBorder(getColumnAlignment(node, columnIndex)) + " |";
  5727. }
  5728. }
  5729. const captionContent = node.caption ? node.caption.textContent || "" : "";
  5730. const caption = captionContent ? `${captionContent}
  5731.  
  5732. ` : "";
  5733. const tableContent = `${emptyHeader}${content}`.trimStart();
  5734. return `
  5735.  
  5736. ${caption}${tableContent}
  5737.  
  5738. `;
  5739. }
  5740. }
  5741. };
  5742. rules2.tableCaption = {
  5743. filter: ["caption"],
  5744. replacement: () => ""
  5745. };
  5746. rules2.tableColgroup = {
  5747. filter: ["colgroup", "col"],
  5748. replacement: () => ""
  5749. };
  5750. rules2.tableSection = {
  5751. filter: ["thead", "tbody", "tfoot"],
  5752. replacement: function(content) {
  5753. return content;
  5754. }
  5755. };
  5756. function isHeadingRow(tr) {
  5757. var parentNode = tr.parentNode;
  5758. return parentNode.nodeName === "THEAD" || parentNode.firstChild === tr && (parentNode.nodeName === "TABLE" || isFirstTbody(parentNode)) && every.call(tr.childNodes, function(n) {
  5759. return n.nodeName === "TH";
  5760. });
  5761. }
  5762. function isFirstTbody(element) {
  5763. var previousSibling = element.previousSibling;
  5764. return element.nodeName === "TBODY" && (!previousSibling || previousSibling.nodeName === "THEAD" && /^\s*$/i.test(previousSibling.textContent));
  5765. }
  5766. function cell(content, node = null, index2 = null) {
  5767. if (index2 === null) index2 = indexOf.call(node.parentNode.childNodes, node);
  5768. var prefix = " ";
  5769. if (index2 === 0) prefix = "| ";
  5770. let filteredContent = content.trim().replace(/\n\r/g, "<br>").replace(/\n/g, "<br>");
  5771. filteredContent = filteredContent.replace(/\|+/g, "\\|");
  5772. while (filteredContent.length < 3) filteredContent += " ";
  5773. if (node) filteredContent = handleColSpan(filteredContent, node, " ");
  5774. return prefix + filteredContent + " |";
  5775. }
  5776. function nodeContainsTable(node) {
  5777. if (!node.childNodes) return false;
  5778. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  5779. const child2 = node.childNodes[i2];
  5780. if (child2.nodeName === "TABLE") return true;
  5781. if (nodeContainsTable(child2)) return true;
  5782. }
  5783. return false;
  5784. }
  5785. const nodeContains = (node, types) => {
  5786. if (!node.childNodes) return false;
  5787. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  5788. const child2 = node.childNodes[i2];
  5789. if (types === "code" && isCodeBlock_ && isCodeBlock_(child2)) return true;
  5790. if (types.includes(child2.nodeName)) return true;
  5791. if (nodeContains(child2, types)) return true;
  5792. }
  5793. return false;
  5794. };
  5795. const tableShouldBeHtml = (tableNode, options) => {
  5796. const possibleTags = [
  5797. "UL",
  5798. "OL",
  5799. "H1",
  5800. "H2",
  5801. "H3",
  5802. "H4",
  5803. "H5",
  5804. "H6",
  5805. "HR",
  5806. "BLOCKQUOTE"
  5807. ];
  5808. if (options.preserveNestedTables) possibleTags.push("TABLE");
  5809. return nodeContains(tableNode, "code") || nodeContains(tableNode, possibleTags);
  5810. };
  5811. function tableShouldBeSkipped(tableNode) {
  5812. const cached = tableShouldBeSkippedCache_.get(tableNode);
  5813. if (cached !== void 0) return cached;
  5814. const result = tableShouldBeSkipped_(tableNode);
  5815. tableShouldBeSkippedCache_.set(tableNode, result);
  5816. return result;
  5817. }
  5818. function tableShouldBeSkipped_(tableNode) {
  5819. if (!tableNode) return true;
  5820. if (!tableNode.rows) return true;
  5821. if (tableNode.rows.length === 1 && tableNode.rows[0].childNodes.length <= 1) return true;
  5822. if (nodeContainsTable(tableNode)) return true;
  5823. return false;
  5824. }
  5825. function nodeParentDiv(node) {
  5826. let parent = node.parentNode;
  5827. while (parent.nodeName !== "DIV") {
  5828. parent = parent.parentNode;
  5829. if (!parent) return null;
  5830. }
  5831. return parent;
  5832. }
  5833. function nodeParentTable(node) {
  5834. let parent = node.parentNode;
  5835. while (parent.nodeName !== "TABLE") {
  5836. parent = parent.parentNode;
  5837. if (!parent) return null;
  5838. }
  5839. return parent;
  5840. }
  5841. function handleColSpan(content, node, emptyChar) {
  5842. const colspan = node.getAttribute("colspan") || 1;
  5843. for (let i2 = 1; i2 < colspan; i2++) {
  5844. content += " | " + emptyChar.repeat(3);
  5845. }
  5846. return content;
  5847. }
  5848. function tableColCount(node) {
  5849. let maxColCount = 0;
  5850. for (let i2 = 0; i2 < node.rows.length; i2++) {
  5851. const row = node.rows[i2];
  5852. const colCount = row.childNodes.length;
  5853. if (colCount > maxColCount) maxColCount = colCount;
  5854. }
  5855. return maxColCount;
  5856. }
  5857. function tables(turndownService) {
  5858. isCodeBlock_ = turndownService.isCodeBlock;
  5859. options_ = turndownService.options;
  5860. turndownService.keep(function(node) {
  5861. if (node.nodeName === "TABLE" && tableShouldBeHtml(node, turndownService.options)) return true;
  5862. return false;
  5863. });
  5864. for (var key in rules2) turndownService.addRule(key, rules2[key]);
  5865. }
  5866. function taskListItems(turndownService) {
  5867. turndownService.addRule("taskListItems", {
  5868. filter: function(node) {
  5869. return node.type === "checkbox" && node.parentNode.nodeName === "LI";
  5870. },
  5871. replacement: function(content, node) {
  5872. return (node.checked ? "[x]" : "[ ]") + " ";
  5873. }
  5874. });
  5875. }
  5876. function gfm(turndownService) {
  5877. turndownService.use([
  5878. highlightedCodeBlock,
  5879. strikethrough,
  5880. tables,
  5881. taskListItems
  5882. ]);
  5883. }
  5884. turndownPluginGfm_cjs.gfm = gfm;
  5885. turndownPluginGfm_cjs.highlightedCodeBlock = highlightedCodeBlock;
  5886. turndownPluginGfm_cjs.strikethrough = strikethrough;
  5887. turndownPluginGfm_cjs.tables = tables;
  5888. turndownPluginGfm_cjs.taskListItems = taskListItems;
  5889. return turndownPluginGfm_cjs;
  5890. }
  5891. var turndownPluginGfm_cjsExports = requireTurndownPluginGfm_cjs();
  5892. var M = "__monkeyWindow-" + (() => {
  5893. try {
  5894. return new URL((_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('__entry.js', document.baseURI).href)).origin;
  5895. } catch {
  5896. return location.origin;
  5897. }
  5898. })(), R = document[M] ?? window, v = R.GM, k = R.GM_xmlhttpRequest;
  5899. function x(p) {
  5900. var e2;
  5901. const t = new Headers(), s = p.replace(/\r?\n[\t ]+/g, " ");
  5902. for (const i2 of s.split(/\r?\n/)) {
  5903. const d = i2.split(":"), a2 = (e2 = d.shift()) == null ? void 0 : e2.trim();
  5904. if (a2) {
  5905. const c2 = d.join(":").trim();
  5906. try {
  5907. t.append(a2, c2);
  5908. } catch (r2) {
  5909. console.warn(`Response ${r2.message}`);
  5910. }
  5911. }
  5912. }
  5913. return t;
  5914. }
  5915. const H = async (p, t) => {
  5916. const s = k || v.xmlHttpRequest;
  5917. if (typeof s != "function")
  5918. throw new DOMException(
  5919. "GM_xmlhttpRequest or GM.xmlHttpRequest is not granted.",
  5920. "NotFoundError"
  5921. );
  5922. const e2 = new Request(p, t);
  5923. if (e2.signal.aborted)
  5924. throw new DOMException("Network request aborted.", "AbortError");
  5925. const i2 = await e2.arrayBuffer(), d = i2.byteLength ? new TextDecoder().decode(i2) : void 0, a2 = Object.fromEntries(e2.headers);
  5926. return new Headers(void 0).forEach((c2, r2) => {
  5927. a2[r2] = c2;
  5928. }), new Promise((c2, r2) => {
  5929. let l = false;
  5930. const b = new Promise((o2) => {
  5931. const { abort: w } = s({
  5932. method: e2.method.toUpperCase(),
  5933. url: e2.url || location.href,
  5934. headers: a2,
  5935. data: d,
  5936. redirect: e2.redirect,
  5937. binary: true,
  5938. nocache: e2.cache === "no-store",
  5939. revalidate: e2.cache === "reload",
  5940. timeout: 3e5,
  5941. responseType: s.RESPONSE_TYPE_STREAM ?? "blob",
  5942. overrideMimeType: e2.headers.get("Content-Type") ?? void 0,
  5943. anonymous: e2.credentials === "omit",
  5944. onload: ({ response: n }) => {
  5945. if (l) {
  5946. o2(null);
  5947. return;
  5948. }
  5949. o2(n);
  5950. },
  5951. async onreadystatechange({
  5952. readyState: n,
  5953. responseHeaders: m,
  5954. status: g,
  5955. statusText: q,
  5956. finalUrl: f,
  5957. response: E
  5958. }) {
  5959. if (n === XMLHttpRequest.DONE)
  5960. e2.signal.removeEventListener("abort", w);
  5961. else if (n !== XMLHttpRequest.HEADERS_RECEIVED)
  5962. return;
  5963. if (l) {
  5964. o2(null);
  5965. return;
  5966. }
  5967. const u2 = x(m), y = e2.url !== f, h = new Response(
  5968. E instanceof ReadableStream ? E : await b,
  5969. {
  5970. headers: u2,
  5971. status: g,
  5972. statusText: q
  5973. }
  5974. );
  5975. Object.defineProperties(h, {
  5976. url: {
  5977. value: f
  5978. },
  5979. type: {
  5980. value: "basic"
  5981. },
  5982. ...h.redirected !== y ? {
  5983. redirected: {
  5984. value: y
  5985. }
  5986. } : {},
  5987. // https://fetch.spec.whatwg.org/#forbidden-response-header-name
  5988. ...u2.has("set-cookie") || u2.has("set-cookie2") ? {
  5989. headers: {
  5990. value: u2
  5991. }
  5992. } : {}
  5993. }), c2(h), l = true;
  5994. },
  5995. onerror: ({ statusText: n, error: m }) => {
  5996. r2(
  5997. new TypeError(n || m || "Network request failed.")
  5998. ), o2(null);
  5999. },
  6000. ontimeout() {
  6001. r2(new TypeError("Network request timeout.")), o2(null);
  6002. },
  6003. onabort() {
  6004. r2(new DOMException("Network request aborted.", "AbortError")), o2(null);
  6005. }
  6006. });
  6007. e2.signal.addEventListener("abort", w);
  6008. });
  6009. });
  6010. };
  6011. function blobToDataURL(blob) {
  6012. return new Promise((resolve, reject) => {
  6013. const reader = new FileReader();
  6014. reader.onload = () => resolve(reader.result);
  6015. reader.onerror = (error) => reject(error);
  6016. reader.readAsDataURL(blob);
  6017. });
  6018. }
  6019. async function convertSrcToDataURL(src) {
  6020. if (src.startsWith("data:")) {
  6021. return src;
  6022. }
  6023. try {
  6024. const response = await H(src);
  6025. const blob = await response.blob();
  6026. const dataURL = await blobToDataURL(blob);
  6027. return dataURL;
  6028. } catch (err) {
  6029. console.error(`Failed to fetch image: ${src}`, err);
  6030. throw err;
  6031. }
  6032. }
  6033. const imageCache = /* @__PURE__ */ new Map();
  6034. async function prefetchImages(node) {
  6035. const images = Array.from(node.querySelectorAll("img"));
  6036. const fetchPromises = images.map(async ({ src }) => {
  6037. if (imageCache.has(src)) return;
  6038. const dataURL = await convertSrcToDataURL(src);
  6039. imageCache.set(src, dataURL);
  6040. });
  6041. await Promise.all(fetchPromises);
  6042. }
  6043. function createTurndownService() {
  6044. const turndown2 = new TurndownService({
  6045. emDelimiter: "*",
  6046. bulletListMarker: "-"
  6047. });
  6048. turndown2.addRule("pre", {
  6049. filter: ["pre"],
  6050. replacement: (_content, node) => {
  6051. var _a2;
  6052. return "\n```txt\n" + ((_a2 = node.textContent) == null ? void 0 : _a2.trim()) + "\n```\n";
  6053. }
  6054. });
  6055. turndown2.addRule("superscript", {
  6056. filter: ["sup"],
  6057. replacement: (content) => "^" + content
  6058. });
  6059. turndown2.addRule("paragraph", {
  6060. filter: ["p"],
  6061. replacement: (content) => "\n\n" + content + "\n\n"
  6062. });
  6063. turndown2.addRule("convert-img-src-to-base64", {
  6064. filter: ["img"],
  6065. replacement: (_content, node) => {
  6066. const { src, alt } = node;
  6067. const dataURL = imageCache.get(src);
  6068. if (dataURL) {
  6069. return `![${alt}](${dataURL})`;
  6070. }
  6071. return `![${alt}](${src})`;
  6072. }
  6073. });
  6074. turndown2.use(turndownPluginGfm_cjsExports.tables);
  6075. return turndown2;
  6076. }
  6077. async function htmlToMd(node, {
  6078. turndownService = createTurndownService(),
  6079. convertImage = true
  6080. } = {}) {
  6081. if (convertImage) await prefetchImages(node);
  6082. const md = turndownService.turndown(node);
  6083. if (convertImage) imageCache.clear();
  6084. return md;
  6085. }
  6086. const getDescription = async (convertImage = true) => {
  6087. const el = await findElement("div[data-track-load='description_content']");
  6088. return htmlToMd(el, { convertImage });
  6089. };
  6090. function Copy_description($$anchor, $$props) {
  6091. push($$props, false);
  6092. async function copyDescription() {
  6093. const toastId = prefixToast.loading("Scraping problem description...");
  6094. const desc = await getDescription(false);
  6095. copy(desc, toastId);
  6096. }
  6097. init();
  6098. Button($$anchor, {
  6099. variant: "green",
  6100. onclick: copyDescription,
  6101. children: ($$anchor2, $$slotProps) => {
  6102. var text$1 = text();
  6103. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制描述" : "Copy Description"));
  6104. append($$anchor2, text$1);
  6105. },
  6106. $$slots: { default: true }
  6107. });
  6108. pop();
  6109. }
  6110. function downloadFile(blob, filename, extension) {
  6111. const url2 = URL.createObjectURL(blob);
  6112. const a2 = document.createElement("a");
  6113. a2.href = url2;
  6114. a2.download = filename + "." + extension;
  6115. document.body.appendChild(a2);
  6116. a2.click();
  6117. document.body.removeChild(a2);
  6118. URL.revokeObjectURL(url2);
  6119. }
  6120. function createNotebook({
  6121. title,
  6122. description,
  6123. code,
  6124. language = "python",
  6125. url: url2
  6126. }) {
  6127. const notebook = {
  6128. metadata: {
  6129. language_info: {
  6130. name: language
  6131. }
  6132. },
  6133. nbformat: 5,
  6134. nbformat_minor: 10,
  6135. cells: []
  6136. };
  6137. const regex = /^(https:\/\/(leetcode\.com|leetcode\.cn)\/problems\/[a-zA-Z0-9_-]+)/;
  6138. const match = url2.match(regex);
  6139. const titleCell = createMarkdownCell(
  6140. `# [${title}](${match ? match[0] : url2})`
  6141. );
  6142. const descriptionPrefix = globalState.site === "cn" ? "题目描述" : "Description";
  6143. const descriptionCell = createMarkdownCell(
  6144. `## ${descriptionPrefix}
  6145.  
  6146. ` + description
  6147. );
  6148. const partitionCell = createMarkdownCell("---\n\n");
  6149. const solutionPrefix = globalState.site === "cn" ? "解答" : "Solution";
  6150. const solutionCell = createMarkdownCell(`## ${solutionPrefix}`);
  6151. const codeCell = createCodeCell(code);
  6152. notebook.cells.push(
  6153. titleCell,
  6154. descriptionCell,
  6155. partitionCell,
  6156. solutionCell,
  6157. codeCell
  6158. );
  6159. return notebook;
  6160. }
  6161. function createMarkdownCell(content) {
  6162. return {
  6163. cell_type: "markdown",
  6164. metadata: {},
  6165. source: content
  6166. };
  6167. }
  6168. function createCodeCell(content) {
  6169. return {
  6170. cell_type: "code",
  6171. metadata: {},
  6172. source: content,
  6173. execution_count: null,
  6174. outputs: []
  6175. };
  6176. }
  6177. function downloadNotebook(notebook, filename) {
  6178. const blob = new Blob([JSON.stringify(notebook)], {
  6179. type: "application/x-ipynb+json"
  6180. });
  6181. downloadFile(blob, filename, "ipynb");
  6182. }
  6183. function Download_as_jupyter($$anchor, $$props) {
  6184. push($$props, false);
  6185. async function saveAsJupyter() {
  6186. async function scrape() {
  6187. var _a2, _b, _c, _d;
  6188. const title = await getTitle();
  6189. const notebook = createNotebook({
  6190. title,
  6191. description: await getDescription(),
  6192. code: ((_b = (_a2 = problemState.editor) == null ? void 0 : _a2.getModel()) == null ? void 0 : _b.getValue()) ?? "",
  6193. language: ((_d = (_c = problemState.editor) == null ? void 0 : _c.getModel()) == null ? void 0 : _d.getLanguageId()) ?? "python",
  6194. url: window.location.href
  6195. });
  6196. return { notebook, title };
  6197. }
  6198. toast.promise(scrape, {
  6199. loading: "Scraping problem description and code...",
  6200. success: ({ notebook, title }) => {
  6201. downloadNotebook(notebook, title);
  6202. return "Start downloading jupyter notebook..";
  6203. },
  6204. error: "Something went wrong."
  6205. });
  6206. }
  6207. init();
  6208. Button($$anchor, {
  6209. variant: "orange",
  6210. onclick: saveAsJupyter,
  6211. children: ($$anchor2, $$slotProps) => {
  6212. var text$1 = text();
  6213. template_effect(() => set_text(text$1, globalState.site === "cn" ? "保存为 Jupyter Notebook (.ipynb)" : "Save as Jupyter Notebook (.ipynb)"));
  6214. append($$anchor2, text$1);
  6215. },
  6216. $$slots: { default: true }
  6217. });
  6218. pop();
  6219. }
  6220. var root$1 = /* @__PURE__ */ template(`<div class="svelte-1q3elx8"><!> <!> <!></div>`);
  6221. function DescriptionButttons($$anchor) {
  6222. var div = root$1();
  6223. var node = child(div);
  6224. Copy_title(node, {});
  6225. var node_1 = sibling(node, 2);
  6226. Copy_description(node_1, {});
  6227. var node_2 = sibling(node_1, 2);
  6228. Download_as_jupyter(node_2, {});
  6229. append($$anchor, div);
  6230. }
  6231. async function initDescriptionTab() {
  6232. var _a2;
  6233. const descriptionTab = await findElement(
  6234. ".flexlayout__tab:has([data-track-load='description_content'])",
  6235. {
  6236. timeout: 0,
  6237. additionalRule: (el) => el.style.display !== "none"
  6238. }
  6239. );
  6240. const titleContainer = await findElement("div:has(> .text-title-large)", {
  6241. parent: descriptionTab
  6242. });
  6243. const buttonsContainer = document.createElement("div");
  6244. buttonsContainer.setAttribute(
  6245. "id",
  6246. a(CONFIG.APP_NAME) + "-description"
  6247. );
  6248. buttonsContainer.style.cssText = "display: contents;";
  6249. (_a2 = titleContainer.parentElement) == null ? void 0 : _a2.before(buttonsContainer);
  6250. mount(DescriptionButttons, {
  6251. target: buttonsContainer
  6252. });
  6253. }
  6254. function Find_editorial_screenshot($$anchor, $$props) {
  6255. push($$props, false);
  6256. const editorialsMarkdown = _GM_getResourceText("editorials");
  6257. function extractScreenshotLink(problemTitle) {
  6258. const cleanTitle = problemTitle.trim();
  6259. const headingPattern = new RegExp(`####\\s+\\[${cleanTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\]\\((.*?)\\)`, "i");
  6260. const match = editorialsMarkdown.match(headingPattern);
  6261. return match ? match[1] : null;
  6262. }
  6263. async function goToEditorialScreenshot() {
  6264. const title = await getTitle();
  6265. const link2 = extractScreenshotLink(title);
  6266. if (link2) {
  6267. window.open(link2, "_blank");
  6268. } else {
  6269. toast.warning(`Editorial screenshot not found for problem: ${title}`);
  6270. }
  6271. }
  6272. init();
  6273. Button($$anchor, {
  6274. onclick: goToEditorialScreenshot,
  6275. children: ($$anchor2, $$slotProps) => {
  6276. var text$1 = text("Find Screenshot");
  6277. append($$anchor2, text$1);
  6278. },
  6279. $$slots: { default: true }
  6280. });
  6281. pop();
  6282. }
  6283. const turndown = createTurndownService();
  6284. turndown.addRule("remove-heading-link", {
  6285. filter: (node) => node.nodeName === "A" && node.getAttribute("aria-hidden") === "true",
  6286. replacement: () => ""
  6287. });
  6288. turndown.addRule("save-math-as-is", {
  6289. filter: (node) => node.nodeName === "SPAN" && node.matches(".math, .maths, .math-tex"),
  6290. replacement: (_content, node) => node.outerHTML
  6291. });
  6292. function waitForIframeToLoad(iframe) {
  6293. return new Promise((resolve) => {
  6294. var _a2, _b, _c, _d;
  6295. if (iframe.src !== "about:blank") {
  6296. const isSameOrigin = new URL(iframe.src).hostname === window.location.hostname;
  6297. if (!isSameOrigin || ((_b = (_a2 = iframe.contentWindow) == null ? void 0 : _a2.location) == null ? void 0 : _b.href) !== "about:blank" && ((_c = iframe.contentWindow) == null ? void 0 : _c.document.readyState) == "complete") {
  6298. resolve(void 0);
  6299. return;
  6300. }
  6301. }
  6302. console.log("wait for iframe to load...");
  6303. (_d = iframe.contentWindow) == null ? void 0 : _d.addEventListener("load", resolve, {
  6304. once: true
  6305. });
  6306. });
  6307. }
  6308. const playgroundCache = /* @__PURE__ */ new Map();
  6309. async function prefetchPlayground(editorialEl) {
  6310. const iframes = Array.from(editorialEl.querySelectorAll("iframe"));
  6311. const promises = iframes.map(async (iframe) => {
  6312. var _a2, _b;
  6313. await waitForIframeToLoad(iframe);
  6314. const { src, contentDocument } = iframe;
  6315. if (!src.includes("playground")) return;
  6316. console.log((_b = (_a2 = iframe.contentWindow) == null ? void 0 : _a2.location) == null ? void 0 : _b.href);
  6317. const langTab = await findElement("div.lang-btn-set", {
  6318. parent: contentDocument,
  6319. timeout: 1e3
  6320. });
  6321. const textarea = contentDocument == null ? void 0 : contentDocument.querySelector(
  6322. "textarea[name='lc-codemirror']"
  6323. );
  6324. let result = `<MixedCodeBlock>
  6325.  
  6326. `;
  6327. Array.from(
  6328. langTab.children
  6329. ).forEach((button) => {
  6330. var _a3;
  6331. let lang = (_a3 = button.textContent) == null ? void 0 : _a3.toLowerCase();
  6332. if (lang === "python3") lang = "python";
  6333. button.click();
  6334. const code = textarea == null ? void 0 : textarea.textContent;
  6335. result += `\`\`\`${lang}
  6336. ${code}
  6337. \`\`\`
  6338.  
  6339. `;
  6340. });
  6341. result += `</MixedCodeBlock>`;
  6342. playgroundCache.set(src, result);
  6343. });
  6344. await Promise.all(promises);
  6345. }
  6346. turndown.addRule("save-code-playground", {
  6347. filter: ["iframe"],
  6348. replacement: (_content, node) => {
  6349. const { src } = node;
  6350. if (!src.includes("playground")) return "";
  6351. return `[LeetCode Playground](${src})
  6352.  
  6353. ` + (playgroundCache.get(src) ?? "");
  6354. }
  6355. });
  6356. const slideCache = /* @__PURE__ */ new Map();
  6357. async function preFetchSlides(editorialEl) {
  6358. const slideImages = editorialEl.querySelectorAll("img[alt='Current']");
  6359. const promises = Array.from(slideImages).map(async (image) => {
  6360. var _a2, _b, _c;
  6361. const slideContainer = (_a2 = image.parentElement) == null ? void 0 : _a2.parentElement;
  6362. if (!slideContainer) {
  6363. throw new Error("Slide container not found");
  6364. }
  6365. const slideNumIndicator = slideContainer.children[2].children[1];
  6366. slideNumIndicator.setAttribute("data-skip-me-turndown", "true");
  6367. const slidesCountStr = (_c = (_b = slideNumIndicator.textContent) == null ? void 0 : _b.match(/\d+$/)) == null ? void 0 : _c[0];
  6368. if (!slidesCountStr) {
  6369. throw new Error("Slide count not found");
  6370. }
  6371. const nextSlideButton = slideContainer.querySelector("svg:nth-child(3)");
  6372. if (!nextSlideButton) {
  6373. throw new Error("Next slide button not found");
  6374. }
  6375. const firstSlideSrc = image.src;
  6376. slideCache.set(firstSlideSrc, []);
  6377. for (let i2 = 0; i2 < Number(slidesCountStr); i2++) {
  6378. simulateMouseClickReact(nextSlideButton);
  6379. const dataURL = await convertSrcToDataURL(image.src);
  6380. slideCache.get(firstSlideSrc).push(dataURL);
  6381. }
  6382. });
  6383. await Promise.all(promises);
  6384. }
  6385. turndown.addRule("save-slides", {
  6386. filter: (node) => node.tagName === "IMG" && node.alt === "Current",
  6387. replacement: (_content, node) => {
  6388. const { src } = node;
  6389. const dataURLs = slideCache.get(src);
  6390. if (!dataURLs) return "";
  6391. let res = `<Slides>
  6392.  
  6393. `;
  6394. dataURLs.forEach((dataURL, index2) => {
  6395. res += `![Slide ${index2 + 1}](${dataURL})
  6396. `;
  6397. });
  6398. res += `
  6399. </Slides>`;
  6400. return res;
  6401. }
  6402. });
  6403. turndown.remove(
  6404. (node) => node.getAttribute("data-skip-me-turndown") === "true"
  6405. );
  6406. async function scrapeEditorial(editorialEl) {
  6407. await prefetchPlayground(editorialEl);
  6408. await preFetchSlides(editorialEl);
  6409. const editorial = await htmlToMd(editorialEl, {
  6410. turndownService: turndown
  6411. });
  6412. playgroundCache.clear();
  6413. slideCache.clear();
  6414. return editorial;
  6415. }
  6416. async function downloadEditorial(editorialFinder, titleFinder) {
  6417. const toastId = prefixToast.loading("Scraping editorial...");
  6418. try {
  6419. const editorialEl = await editorialFinder();
  6420. const editorial = await scrapeEditorial(editorialEl);
  6421. const title = await titleFinder();
  6422. const blob = new Blob([`# ${title}
  6423.  
  6424. `, editorial], {
  6425. type: "text/markdown; charset=UTF-8"
  6426. });
  6427. downloadFile(blob, title, "md");
  6428. prefixToast.success("Editorial scraped. Downloading now...", {
  6429. id: toastId,
  6430. action: {
  6431. label: "Read it now",
  6432. onClick: () => {
  6433. window.open(
  6434. "https://leetcode-editorial-reader.vercel.app/",
  6435. "_blank"
  6436. );
  6437. }
  6438. }
  6439. });
  6440. } catch (err) {
  6441. console.error(err);
  6442. prefixToast.error(
  6443. "Something went wrong while scraping. See browser console for more detail.",
  6444. { id: toastId }
  6445. );
  6446. }
  6447. }
  6448. function Save_editorial($$anchor, $$props) {
  6449. push($$props, false);
  6450. async function findEditorial() {
  6451. const editorialEl = await findElement(".flexlayout__tab:has(#editorial-quick-navigation) div.WRmCx", { timeout: 2e3 });
  6452. return editorialEl;
  6453. }
  6454. init();
  6455. Button($$anchor, {
  6456. onclick: () => downloadEditorial(findEditorial, getTitle),
  6457. variant: "orange",
  6458. children: ($$anchor2, $$slotProps) => {
  6459. var text$1 = text("Save Editorial as Markdown");
  6460. append($$anchor2, text$1);
  6461. },
  6462. $$slots: { default: true }
  6463. });
  6464. pop();
  6465. }
  6466. var root = /* @__PURE__ */ template(`<div class="relative p-2 svelte-1ckqqtt"><!> <!></div>`);
  6467. function EditorialButtons($$anchor) {
  6468. var div = root();
  6469. var node = child(div);
  6470. Find_editorial_screenshot(node, {});
  6471. var node_1 = sibling(node, 2);
  6472. Save_editorial(node_1, {});
  6473. append($$anchor, div);
  6474. }
  6475. async function initEditorialTab() {
  6476. const editorialTab = await findElement(
  6477. ".flexlayout__tab:has(div.bg-blocker, #editorial-quick-navigation)",
  6478. {
  6479. timeout: 0,
  6480. additionalRule: (el) => el.style.display !== "none"
  6481. }
  6482. );
  6483. const buttonsContainer = document.createElement("div");
  6484. buttonsContainer.style.cssText = "display: contents;";
  6485. buttonsContainer.setAttribute(
  6486. "id",
  6487. a(CONFIG.APP_NAME) + "-editorial"
  6488. );
  6489. editorialTab.prepend(buttonsContainer);
  6490. mount(EditorialButtons, {
  6491. target: buttonsContainer
  6492. });
  6493. }
  6494. async function main$1() {
  6495. const initPromises = [];
  6496. initPromises.push(problemState.patchMonacoEditor());
  6497. initPromises.push(initDescriptionTab());
  6498. if (globalState.site === "global") {
  6499. initPromises.push(initEditorialTab());
  6500. }
  6501. await Promise.all(initPromises);
  6502. }
  6503. function getElementIndex(element) {
  6504. if (!element.parentNode) throw new Error("Element has no parent node");
  6505. return Array.from(element.parentNode.children).indexOf(element);
  6506. }
  6507. function Save_explore_article($$anchor, $$props) {
  6508. push($$props, false);
  6509. async function findExploreEditorial() {
  6510. return await findElement("div.block-markdown");
  6511. }
  6512. async function getExploreTitle() {
  6513. var _a2, _b;
  6514. const tocContainer = await findElement("div.list-group:not(.item-list-group)");
  6515. const titleContainer = tocContainer.querySelector(".list-group-item .selected");
  6516. if (!titleContainer) {
  6517. throw new Error("Title container not found");
  6518. }
  6519. const title = ((_b = (_a2 = titleContainer.querySelector(".title")) == null ? void 0 : _a2.textContent) == null ? void 0 : _b.trim()) ?? "";
  6520. const articleNumber = getElementIndex(titleContainer) + 1;
  6521. const chapterEl = titleContainer.closest("div.chapter-item");
  6522. if (!chapterEl) {
  6523. throw new Error("Chapter not found");
  6524. }
  6525. const chapterNumber = getElementIndex(chapterEl);
  6526. return `${chapterNumber}.${articleNumber} ${title}`;
  6527. }
  6528. init();
  6529. Button($$anchor, {
  6530. onclick: () => downloadEditorial(findExploreEditorial, getExploreTitle),
  6531. children: ($$anchor2, $$slotProps) => {
  6532. var text$1 = text("Save Article as Markdown");
  6533. append($$anchor2, text$1);
  6534. },
  6535. $$slots: { default: true }
  6536. });
  6537. pop();
  6538. }
  6539. async function main() {
  6540. const toolbar = await findElement("div.left-side", { timeout: 0 });
  6541. const container = document.createElement("div");
  6542. container.style.cssText = "display: contents;";
  6543. toolbar.append(container);
  6544. mount(Save_explore_article, {
  6545. target: container
  6546. });
  6547. }
  6548. mount(Toaster, {
  6549. target: document.body,
  6550. props: { richColors: true, position: "top-center" }
  6551. });
  6552. const url = window.location.href;
  6553. const problemPageRegex = /https?:\/\/leetcode\.com\/problems\/.*|https?:\/\/leetcode\.cn\/problems\/.*/;
  6554. const explorePageRegex = /https?:\/\/leetcode\.com\/explore\/learn\/card\/.*/;
  6555. if (problemPageRegex.test(url)) {
  6556. main$1();
  6557. } else if (explorePageRegex.test(url)) {
  6558. main();
  6559. }
  6560.  
  6561. })();