LeetCode工具箱

复制题目为 Markdown | 下载为 Jupyter Notebook | 保存时自动格式化 | 免费自动补全

目前为 2025-05-01 提交的版本。查看 最新版本

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