LeetCode Toolkit

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

  1. // ==UserScript==
  2. // @name LeetCode Toolkit
  3. // @name:zh-CN LeetCode工具箱
  4. // @namespace https://github.com/eclipher/leetcode-toolkit
  5. // @version 2.6.2
  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/Userscripts/tree/main/userscripts/leetcode-toolkit
  12. // @include /https?:\/\/leetcode\.com\/problems\/.*/
  13. // @include /https?:\/\/leetcode\.cn\/problems\/.*/
  14. // @include /https?:\/\/leetcode\.com\/explore\/.*\/card\/.*/
  15. // @exclude *://leetcode.com/problems/*/post-solution/*
  16. // @exclude *://leetcode.cn/problems/*/post-solution/*
  17. // @require https://cdn.jsdelivr.net/npm/compressorjs@1.2.1
  18. // @require https://cdn.jsdelivr.net/npm/turndown@7.2.0/lib/turndown.browser.umd.js
  19. // @resource editorials https://raw.githubusercontent.com/akhilkammila/leetcode-screenshotter/refs/heads/main/ReadMe.md
  20. // @connect assets.leetcode.com
  21. // @connect *
  22. // @grant GM_addStyle
  23. // @grant GM_getResourceText
  24. // @grant GM_xmlhttpRequest
  25. // @grant unsafeWindow
  26. // ==/UserScript==
  27.  
  28. (e=>{if(typeof GM_addStyle=="function"){GM_addStyle(e);return}const t=document.createElement("style");t.textContent=e,document.head.append(t)})(' div.svelte-11kvm4p{width:20px;opacity:0;height:20px;border-radius:10px;background:var(--primary, #61d345);position:relative;transform:rotate(45deg);animation:svelte-11kvm4p-circleAnimation .3s cubic-bezier(.175,.885,.32,1.275) forwards;animation-delay:.1s}div.svelte-11kvm4p:after{content:"";box-sizing:border-box;animation:svelte-11kvm4p-checkmarkAnimation .2s ease-out forwards;opacity:0;animation-delay:.2s;position:absolute;border-right:2px solid;border-bottom:2px solid;border-color:var(--secondary, #fff);bottom:6px;left:6px;height:10px;width:6px}@keyframes svelte-11kvm4p-circleAnimation{0%{transform:scale(0) rotate(45deg);opacity:0}to{transform:scale(1) rotate(45deg);opacity:1}}@keyframes svelte-11kvm4p-checkmarkAnimation{0%{height:0;width:0;opacity:0}40%{height:0;width:6px;opacity:1}to{opacity:1;height:10px}}div.svelte-1ee93ns{width:20px;opacity:0;height:20px;border-radius:10px;background:var(--primary, #ff4b4b);position:relative;transform:rotate(45deg);animation:svelte-1ee93ns-circleAnimation .3s cubic-bezier(.175,.885,.32,1.275) forwards;animation-delay:.1s}div.svelte-1ee93ns:after,div.svelte-1ee93ns:before{content:"";animation:svelte-1ee93ns-firstLineAnimation .15s ease-out forwards;animation-delay:.15s;position:absolute;border-radius:3px;opacity:0;background:var(--secondary, #fff);bottom:9px;left:4px;height:2px;width:12px}div.svelte-1ee93ns:before{animation:svelte-1ee93ns-secondLineAnimation .15s ease-out forwards;animation-delay:.18s;transform:rotate(90deg)}@keyframes svelte-1ee93ns-circleAnimation{0%{transform:scale(0) rotate(45deg);opacity:0}to{transform:scale(1) rotate(45deg);opacity:1}}@keyframes svelte-1ee93ns-firstLineAnimation{0%{transform:scale(0);opacity:0}to{transform:scale(1);opacity:1}}@keyframes svelte-1ee93ns-secondLineAnimation{0%{transform:scale(0) rotate(90deg);opacity:0}to{transform:scale(1) rotate(90deg);opacity:1}}div.svelte-1j7dflg{width:12px;height:12px;box-sizing:border-box;border:2px solid;border-radius:100%;border-color:var(--secondary, #e0e0e0);border-right-color:var(--primary, #616161);animation:svelte-1j7dflg-rotate 1s linear infinite}@keyframes svelte-1j7dflg-rotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.indicator.svelte-1kgeier{position:relative;display:flex;justify-content:center;align-items:center;min-width:20px;min-height:20px}.status.svelte-1kgeier{position:absolute}.animated.svelte-1kgeier{position:relative;transform:scale(.6);opacity:.4;min-width:20px;animation:svelte-1kgeier-enter .3s .12s cubic-bezier(.175,.885,.32,1.275) forwards}@keyframes svelte-1kgeier-enter{0%{transform:scale(.6);opacity:.4}to{transform:scale(1);opacity:1}}.message.svelte-1nauejd{display:flex;justify-content:center;margin:4px 10px;color:inherit;flex:1 1 auto;white-space:pre-line}@keyframes svelte-1c9srrs-enterAnimation{0%{transform:translate3d(0,calc(var(--factor) * -200%),0) scale(.6);opacity:.5}to{transform:translateZ(0) scale(1);opacity:1}}@keyframes svelte-1c9srrs-exitAnimation{0%{transform:translateZ(-1px) scale(1);opacity:1}to{transform:translate3d(0,calc(var(--factor) * -150%),-1px) scale(.6);opacity:0}}@keyframes svelte-1c9srrs-fadeInAnimation{0%{opacity:0}to{opacity:1}}@keyframes svelte-1c9srrs-fadeOutAnimation{0%{opacity:1}to{opacity:0}}.base.svelte-1c9srrs{display:flex;align-items:center;background:#fff;color:#363636;line-height:1.3;will-change:transform;box-shadow:0 3px 10px #0000001a,0 3px 3px #0000000d;max-width:350px;pointer-events:auto;padding:8px 10px;border-radius:8px}.transparent.svelte-1c9srrs{opacity:0}.enter.svelte-1c9srrs{animation:svelte-1c9srrs-enterAnimation .35s cubic-bezier(.21,1.02,.73,1) forwards}.exit.svelte-1c9srrs{animation:svelte-1c9srrs-exitAnimation .4s cubic-bezier(.06,.71,.55,1) forwards}.fadeIn.svelte-1c9srrs{animation:svelte-1c9srrs-fadeInAnimation .35s cubic-bezier(.21,1.02,.73,1) forwards}.fadeOut.svelte-1c9srrs{animation:svelte-1c9srrs-fadeOutAnimation .4s cubic-bezier(.06,.71,.55,1) forwards}.wrapper.svelte-v01oml{left:0;right:0;display:flex;position:absolute;transform:translateY(calc(var(--offset, 16px) * var(--factor) * 1px))}.transition.svelte-v01oml{transition:all .23s cubic-bezier(.21,1.02,.73,1)}.active.svelte-v01oml{z-index:9999}.active.svelte-v01oml>*{pointer-events:auto}.toaster.svelte-1phplh9{--default-offset: 16px;position:fixed;z-index:9999;top:var(--default-offset);left:var(--default-offset);right:var(--default-offset);bottom:var(--default-offset);pointer-events:none}div.svelte-4mbyk0{display:inline-flex;flex-wrap:wrap;gap:.4rem}button.svelte-ll0ynk,a.svelte-ll0ynk{color:#fff;background-color:var(--bg, #6c5ce7);box-shadow:0 3px 0 0 var(--shadow, #a29bfe);padding:5px 20px;font-size:.8rem;font-weight:500;border-radius:5px;transition:all ease .1s;display:inline-flex;align-items:center;gap:.25rem;-webkit-user-select:none;user-select:none}button.svelte-ll0ynk:active,a.svelte-ll0ynk:active{transform:translateY(3px);box-shadow:0 0 0 0 var(--shadow, #a29bfe)}button.svelte-ll0ynk:disabled,a.svelte-ll0ynk:disabled{pointer-events:none;opacity:50%} ');
  29.  
  30. (function (TurndownService, Compressor) {
  31. 'use strict';
  32.  
  33. var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
  34. var __defProp = Object.defineProperty;
  35. var __typeError = (msg) => {
  36. throw TypeError(msg);
  37. };
  38. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  39. var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  40. var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
  41. var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
  42. 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);
  43. var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
  44. var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
  45. var _listeners, _observer, _options, _ResizeObserverSingleton_instances, getObserver_fn, _a, _site;
  46. const DEV = false;
  47. var is_array = Array.isArray;
  48. var index_of = Array.prototype.indexOf;
  49. var array_from = Array.from;
  50. var define_property = Object.defineProperty;
  51. var get_descriptor = Object.getOwnPropertyDescriptor;
  52. var get_descriptors = Object.getOwnPropertyDescriptors;
  53. var object_prototype = Object.prototype;
  54. var array_prototype = Array.prototype;
  55. var get_prototype_of = Object.getPrototypeOf;
  56. var is_extensible = Object.isExtensible;
  57. function is_function(thing) {
  58. return typeof thing === "function";
  59. }
  60. const noop = () => {
  61. };
  62. function run(fn) {
  63. return fn();
  64. }
  65. function run_all(arr) {
  66. for (var i2 = 0; i2 < arr.length; i2++) {
  67. arr[i2]();
  68. }
  69. }
  70. const DERIVED = 1 << 1;
  71. const EFFECT = 1 << 2;
  72. const RENDER_EFFECT = 1 << 3;
  73. const BLOCK_EFFECT = 1 << 4;
  74. const BRANCH_EFFECT = 1 << 5;
  75. const ROOT_EFFECT = 1 << 6;
  76. const BOUNDARY_EFFECT = 1 << 7;
  77. const UNOWNED = 1 << 8;
  78. const DISCONNECTED = 1 << 9;
  79. const CLEAN = 1 << 10;
  80. const DIRTY = 1 << 11;
  81. const MAYBE_DIRTY = 1 << 12;
  82. const INERT = 1 << 13;
  83. const DESTROYED = 1 << 14;
  84. const EFFECT_RAN = 1 << 15;
  85. const EFFECT_TRANSPARENT = 1 << 16;
  86. const HEAD_EFFECT = 1 << 19;
  87. const EFFECT_HAS_DERIVED = 1 << 20;
  88. const EFFECT_IS_UPDATING = 1 << 21;
  89. const STATE_SYMBOL = Symbol("$state");
  90. const LEGACY_PROPS = Symbol("legacy props");
  91. const LOADING_ATTR_SYMBOL = Symbol("");
  92. function equals(value) {
  93. return value === this.v;
  94. }
  95. function safe_not_equal(a2, b) {
  96. return a2 != a2 ? b == b : a2 !== b || a2 !== null && typeof a2 === "object" || typeof a2 === "function";
  97. }
  98. function safe_equals(value) {
  99. return !safe_not_equal(value, this.v);
  100. }
  101. function effect_in_teardown(rune) {
  102. {
  103. throw new Error(`https://svelte.dev/e/effect_in_teardown`);
  104. }
  105. }
  106. function effect_in_unowned_derived() {
  107. {
  108. throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
  109. }
  110. }
  111. function effect_orphan(rune) {
  112. {
  113. throw new Error(`https://svelte.dev/e/effect_orphan`);
  114. }
  115. }
  116. function effect_update_depth_exceeded() {
  117. {
  118. throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
  119. }
  120. }
  121. function state_descriptors_fixed() {
  122. {
  123. throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
  124. }
  125. }
  126. function state_prototype_fixed() {
  127. {
  128. throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
  129. }
  130. }
  131. function state_unsafe_mutation() {
  132. {
  133. throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
  134. }
  135. }
  136. let legacy_mode_flag = false;
  137. let tracing_mode_flag = false;
  138. function enable_legacy_mode_flag() {
  139. legacy_mode_flag = true;
  140. }
  141. const EACH_ITEM_REACTIVE = 1;
  142. const EACH_INDEX_REACTIVE = 1 << 1;
  143. const EACH_ITEM_IMMUTABLE = 1 << 4;
  144. const TEMPLATE_FRAGMENT = 1;
  145. const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
  146. const UNINITIALIZED = Symbol();
  147. const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
  148. const ATTACHMENT_KEY = "@attach";
  149. function lifecycle_outside_component(name) {
  150. {
  151. throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
  152. }
  153. }
  154. let component_context = null;
  155. function set_component_context(context) {
  156. component_context = context;
  157. }
  158. function push(props, runes = false, fn) {
  159. var ctx = component_context = {
  160. p: component_context,
  161. c: null,
  162. d: false,
  163. e: null,
  164. m: false,
  165. s: props,
  166. x: null,
  167. l: null
  168. };
  169. if (legacy_mode_flag && !runes) {
  170. component_context.l = {
  171. s: null,
  172. u: null,
  173. r1: [],
  174. r2: source(false)
  175. };
  176. }
  177. teardown(() => {
  178. ctx.d = true;
  179. });
  180. }
  181. function pop(component2) {
  182. const context_stack_item = component_context;
  183. if (context_stack_item !== null) {
  184. const component_effects = context_stack_item.e;
  185. if (component_effects !== null) {
  186. var previous_effect = active_effect;
  187. var previous_reaction = active_reaction;
  188. context_stack_item.e = null;
  189. try {
  190. for (var i2 = 0; i2 < component_effects.length; i2++) {
  191. var component_effect = component_effects[i2];
  192. set_active_effect(component_effect.effect);
  193. set_active_reaction(component_effect.reaction);
  194. effect(component_effect.fn);
  195. }
  196. } finally {
  197. set_active_effect(previous_effect);
  198. set_active_reaction(previous_reaction);
  199. }
  200. }
  201. component_context = context_stack_item.p;
  202. context_stack_item.m = true;
  203. }
  204. return (
  205. /** @type {T} */
  206. {}
  207. );
  208. }
  209. function is_runes() {
  210. return !legacy_mode_flag || component_context !== null && component_context.l === null;
  211. }
  212. function proxy(value) {
  213. if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
  214. return value;
  215. }
  216. const prototype = get_prototype_of(value);
  217. if (prototype !== object_prototype && prototype !== array_prototype) {
  218. return value;
  219. }
  220. var sources = /* @__PURE__ */ new Map();
  221. var is_proxied_array = is_array(value);
  222. var version = /* @__PURE__ */ state(0);
  223. var reaction = active_reaction;
  224. var with_parent = (fn) => {
  225. var previous_reaction = active_reaction;
  226. set_active_reaction(reaction);
  227. var result = fn();
  228. set_active_reaction(previous_reaction);
  229. return result;
  230. };
  231. if (is_proxied_array) {
  232. sources.set("length", /* @__PURE__ */ state(
  233. /** @type {any[]} */
  234. value.length
  235. ));
  236. }
  237. return new Proxy(
  238. /** @type {any} */
  239. value,
  240. {
  241. defineProperty(_, prop2, descriptor) {
  242. if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
  243. state_descriptors_fixed();
  244. }
  245. var s = sources.get(prop2);
  246. if (s === void 0) {
  247. s = with_parent(() => /* @__PURE__ */ state(descriptor.value));
  248. sources.set(prop2, s);
  249. } else {
  250. set(
  251. s,
  252. with_parent(() => proxy(descriptor.value))
  253. );
  254. }
  255. return true;
  256. },
  257. deleteProperty(target, prop2) {
  258. var s = sources.get(prop2);
  259. if (s === void 0) {
  260. if (prop2 in target) {
  261. sources.set(
  262. prop2,
  263. with_parent(() => /* @__PURE__ */ state(UNINITIALIZED))
  264. );
  265. update_version(version);
  266. }
  267. } else {
  268. if (is_proxied_array && typeof prop2 === "string") {
  269. var ls = (
  270. /** @type {Source<number>} */
  271. sources.get("length")
  272. );
  273. var n = Number(prop2);
  274. if (Number.isInteger(n) && n < ls.v) {
  275. set(ls, n);
  276. }
  277. }
  278. set(s, UNINITIALIZED);
  279. update_version(version);
  280. }
  281. return true;
  282. },
  283. get(target, prop2, receiver) {
  284. var _a2;
  285. if (prop2 === STATE_SYMBOL) {
  286. return value;
  287. }
  288. var s = sources.get(prop2);
  289. var exists = prop2 in target;
  290. if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  291. s = with_parent(() => /* @__PURE__ */ state(proxy(exists ? target[prop2] : UNINITIALIZED)));
  292. sources.set(prop2, s);
  293. }
  294. if (s !== void 0) {
  295. var v2 = get$1(s);
  296. return v2 === UNINITIALIZED ? void 0 : v2;
  297. }
  298. return Reflect.get(target, prop2, receiver);
  299. },
  300. getOwnPropertyDescriptor(target, prop2) {
  301. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  302. if (descriptor && "value" in descriptor) {
  303. var s = sources.get(prop2);
  304. if (s) descriptor.value = get$1(s);
  305. } else if (descriptor === void 0) {
  306. var source2 = sources.get(prop2);
  307. var value2 = source2 == null ? void 0 : source2.v;
  308. if (source2 !== void 0 && value2 !== UNINITIALIZED) {
  309. return {
  310. enumerable: true,
  311. configurable: true,
  312. value: value2,
  313. writable: true
  314. };
  315. }
  316. }
  317. return descriptor;
  318. },
  319. has(target, prop2) {
  320. var _a2;
  321. if (prop2 === STATE_SYMBOL) {
  322. return true;
  323. }
  324. var s = sources.get(prop2);
  325. var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop2);
  326. if (s !== void 0 || active_effect !== null && (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  327. if (s === void 0) {
  328. s = with_parent(() => /* @__PURE__ */ state(has ? proxy(target[prop2]) : UNINITIALIZED));
  329. sources.set(prop2, s);
  330. }
  331. var value2 = get$1(s);
  332. if (value2 === UNINITIALIZED) {
  333. return false;
  334. }
  335. }
  336. return has;
  337. },
  338. set(target, prop2, value2, receiver) {
  339. var _a2;
  340. var s = sources.get(prop2);
  341. var has = prop2 in target;
  342. if (is_proxied_array && prop2 === "length") {
  343. for (var i2 = value2; i2 < /** @type {Source<number>} */
  344. s.v; i2 += 1) {
  345. var other_s = sources.get(i2 + "");
  346. if (other_s !== void 0) {
  347. set(other_s, UNINITIALIZED);
  348. } else if (i2 in target) {
  349. other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
  350. sources.set(i2 + "", other_s);
  351. }
  352. }
  353. }
  354. if (s === void 0) {
  355. if (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable)) {
  356. s = with_parent(() => /* @__PURE__ */ state(void 0));
  357. set(
  358. s,
  359. with_parent(() => proxy(value2))
  360. );
  361. sources.set(prop2, s);
  362. }
  363. } else {
  364. has = s.v !== UNINITIALIZED;
  365. set(
  366. s,
  367. with_parent(() => proxy(value2))
  368. );
  369. }
  370. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  371. if (descriptor == null ? void 0 : descriptor.set) {
  372. descriptor.set.call(receiver, value2);
  373. }
  374. if (!has) {
  375. if (is_proxied_array && typeof prop2 === "string") {
  376. var ls = (
  377. /** @type {Source<number>} */
  378. sources.get("length")
  379. );
  380. var n = Number(prop2);
  381. if (Number.isInteger(n) && n >= ls.v) {
  382. set(ls, n + 1);
  383. }
  384. }
  385. update_version(version);
  386. }
  387. return true;
  388. },
  389. ownKeys(target) {
  390. get$1(version);
  391. var own_keys = Reflect.ownKeys(target).filter((key2) => {
  392. var source3 = sources.get(key2);
  393. return source3 === void 0 || source3.v !== UNINITIALIZED;
  394. });
  395. for (var [key, source2] of sources) {
  396. if (source2.v !== UNINITIALIZED && !(key in target)) {
  397. own_keys.push(key);
  398. }
  399. }
  400. return own_keys;
  401. },
  402. setPrototypeOf() {
  403. state_prototype_fixed();
  404. }
  405. }
  406. );
  407. }
  408. function update_version(signal, d = 1) {
  409. set(signal, signal.v + d);
  410. }
  411. function get_proxied_value(value) {
  412. try {
  413. if (value !== null && typeof value === "object" && STATE_SYMBOL in value) {
  414. return value[STATE_SYMBOL];
  415. }
  416. } catch {
  417. }
  418. return value;
  419. }
  420. function is(a2, b) {
  421. return Object.is(get_proxied_value(a2), get_proxied_value(b));
  422. }
  423. // @__NO_SIDE_EFFECTS__
  424. function derived$1(fn) {
  425. var flags = DERIVED | DIRTY;
  426. var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
  427. /** @type {Derived} */
  428. active_reaction
  429. ) : null;
  430. if (active_effect === null || parent_derived !== null && (parent_derived.f & UNOWNED) !== 0) {
  431. flags |= UNOWNED;
  432. } else {
  433. active_effect.f |= EFFECT_HAS_DERIVED;
  434. }
  435. const signal = {
  436. ctx: component_context,
  437. deps: null,
  438. effects: null,
  439. equals,
  440. f: flags,
  441. fn,
  442. reactions: null,
  443. rv: 0,
  444. v: (
  445. /** @type {V} */
  446. null
  447. ),
  448. wv: 0,
  449. parent: parent_derived ?? active_effect
  450. };
  451. return signal;
  452. }
  453. // @__NO_SIDE_EFFECTS__
  454. function user_derived(fn) {
  455. const d = /* @__PURE__ */ derived$1(fn);
  456. push_reaction_value(d);
  457. return d;
  458. }
  459. // @__NO_SIDE_EFFECTS__
  460. function derived_safe_equal(fn) {
  461. const signal = /* @__PURE__ */ derived$1(fn);
  462. signal.equals = safe_equals;
  463. return signal;
  464. }
  465. function destroy_derived_effects(derived2) {
  466. var effects = derived2.effects;
  467. if (effects !== null) {
  468. derived2.effects = null;
  469. for (var i2 = 0; i2 < effects.length; i2 += 1) {
  470. destroy_effect(
  471. /** @type {Effect} */
  472. effects[i2]
  473. );
  474. }
  475. }
  476. }
  477. function get_derived_parent_effect(derived2) {
  478. var parent = derived2.parent;
  479. while (parent !== null) {
  480. if ((parent.f & DERIVED) === 0) {
  481. return (
  482. /** @type {Effect} */
  483. parent
  484. );
  485. }
  486. parent = parent.parent;
  487. }
  488. return null;
  489. }
  490. function execute_derived(derived2) {
  491. var value;
  492. var prev_active_effect = active_effect;
  493. set_active_effect(get_derived_parent_effect(derived2));
  494. {
  495. try {
  496. destroy_derived_effects(derived2);
  497. value = update_reaction(derived2);
  498. } finally {
  499. set_active_effect(prev_active_effect);
  500. }
  501. }
  502. return value;
  503. }
  504. function update_derived(derived2) {
  505. var value = execute_derived(derived2);
  506. if (!derived2.equals(value)) {
  507. derived2.v = value;
  508. derived2.wv = increment_write_version();
  509. }
  510. if (is_destroying_effect) return;
  511. var status = (skip_reaction || (derived2.f & UNOWNED) !== 0) && derived2.deps !== null ? MAYBE_DIRTY : CLEAN;
  512. set_signal_status(derived2, status);
  513. }
  514. const old_values = /* @__PURE__ */ new Map();
  515. function source(v2, stack) {
  516. var signal = {
  517. f: 0,
  518. // TODO ideally we could skip this altogether, but it causes type errors
  519. v: v2,
  520. reactions: null,
  521. equals,
  522. rv: 0,
  523. wv: 0
  524. };
  525. return signal;
  526. }
  527. // @__NO_SIDE_EFFECTS__
  528. function state(v2, stack) {
  529. const s = source(v2);
  530. push_reaction_value(s);
  531. return s;
  532. }
  533. // @__NO_SIDE_EFFECTS__
  534. function mutable_source(initial_value, immutable = false) {
  535. var _a2;
  536. const s = source(initial_value);
  537. if (!immutable) {
  538. s.equals = safe_equals;
  539. }
  540. if (legacy_mode_flag && component_context !== null && component_context.l !== null) {
  541. ((_a2 = component_context.l).s ?? (_a2.s = [])).push(s);
  542. }
  543. return s;
  544. }
  545. function set(source2, value, should_proxy = false) {
  546. if (active_reaction !== null && !untracking && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 && !(reaction_sources == null ? void 0 : reaction_sources.includes(source2))) {
  547. state_unsafe_mutation();
  548. }
  549. let new_value = should_proxy ? proxy(value) : value;
  550. return internal_set(source2, new_value);
  551. }
  552. function internal_set(source2, value) {
  553. if (!source2.equals(value)) {
  554. var old_value = source2.v;
  555. if (is_destroying_effect) {
  556. old_values.set(source2, value);
  557. } else {
  558. old_values.set(source2, old_value);
  559. }
  560. source2.v = value;
  561. if ((source2.f & DERIVED) !== 0) {
  562. if ((source2.f & DIRTY) !== 0) {
  563. execute_derived(
  564. /** @type {Derived} */
  565. source2
  566. );
  567. }
  568. set_signal_status(source2, (source2.f & UNOWNED) === 0 ? CLEAN : MAYBE_DIRTY);
  569. }
  570. source2.wv = increment_write_version();
  571. mark_reactions(source2, DIRTY);
  572. if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
  573. if (untracked_writes === null) {
  574. set_untracked_writes([source2]);
  575. } else {
  576. untracked_writes.push(source2);
  577. }
  578. }
  579. }
  580. return value;
  581. }
  582. function mark_reactions(signal, status) {
  583. var reactions = signal.reactions;
  584. if (reactions === null) return;
  585. var runes = is_runes();
  586. var length = reactions.length;
  587. for (var i2 = 0; i2 < length; i2++) {
  588. var reaction = reactions[i2];
  589. var flags = reaction.f;
  590. if ((flags & DIRTY) !== 0) continue;
  591. if (!runes && reaction === active_effect) continue;
  592. set_signal_status(reaction, status);
  593. if ((flags & (CLEAN | UNOWNED)) !== 0) {
  594. if ((flags & DERIVED) !== 0) {
  595. mark_reactions(
  596. /** @type {Derived} */
  597. reaction,
  598. MAYBE_DIRTY
  599. );
  600. } else {
  601. schedule_effect(
  602. /** @type {Effect} */
  603. reaction
  604. );
  605. }
  606. }
  607. }
  608. }
  609. function select_multiple_invalid_value() {
  610. {
  611. console.warn(`https://svelte.dev/e/select_multiple_invalid_value`);
  612. }
  613. }
  614. let hydrating = false;
  615. var $window;
  616. var is_firefox;
  617. var first_child_getter;
  618. var next_sibling_getter;
  619. function init_operations() {
  620. if ($window !== void 0) {
  621. return;
  622. }
  623. $window = window;
  624. is_firefox = /Firefox/.test(navigator.userAgent);
  625. var element_prototype = Element.prototype;
  626. var node_prototype = Node.prototype;
  627. var text_prototype = Text.prototype;
  628. first_child_getter = get_descriptor(node_prototype, "firstChild").get;
  629. next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
  630. if (is_extensible(element_prototype)) {
  631. element_prototype.__click = void 0;
  632. element_prototype.__className = void 0;
  633. element_prototype.__attributes = null;
  634. element_prototype.__style = void 0;
  635. element_prototype.__e = void 0;
  636. }
  637. if (is_extensible(text_prototype)) {
  638. text_prototype.__t = void 0;
  639. }
  640. }
  641. function create_text(value = "") {
  642. return document.createTextNode(value);
  643. }
  644. // @__NO_SIDE_EFFECTS__
  645. function get_first_child(node) {
  646. return first_child_getter.call(node);
  647. }
  648. // @__NO_SIDE_EFFECTS__
  649. function get_next_sibling(node) {
  650. return next_sibling_getter.call(node);
  651. }
  652. function child(node, is_text) {
  653. {
  654. return /* @__PURE__ */ get_first_child(node);
  655. }
  656. }
  657. function first_child(fragment, is_text) {
  658. {
  659. var first = (
  660. /** @type {DocumentFragment} */
  661. /* @__PURE__ */ get_first_child(
  662. /** @type {Node} */
  663. fragment
  664. )
  665. );
  666. if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
  667. return first;
  668. }
  669. }
  670. function sibling(node, count = 1, is_text = false) {
  671. let next_sibling = node;
  672. while (count--) {
  673. next_sibling = /** @type {TemplateNode} */
  674. /* @__PURE__ */ get_next_sibling(next_sibling);
  675. }
  676. {
  677. return next_sibling;
  678. }
  679. }
  680. function clear_text_content(node) {
  681. node.textContent = "";
  682. }
  683. function validate_effect(rune) {
  684. if (active_effect === null && active_reaction === null) {
  685. effect_orphan();
  686. }
  687. if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) {
  688. effect_in_unowned_derived();
  689. }
  690. if (is_destroying_effect) {
  691. effect_in_teardown();
  692. }
  693. }
  694. function push_effect(effect2, parent_effect) {
  695. var parent_last = parent_effect.last;
  696. if (parent_last === null) {
  697. parent_effect.last = parent_effect.first = effect2;
  698. } else {
  699. parent_last.next = effect2;
  700. effect2.prev = parent_last;
  701. parent_effect.last = effect2;
  702. }
  703. }
  704. function create_effect(type, fn, sync, push2 = true) {
  705. var parent = active_effect;
  706. var effect2 = {
  707. ctx: component_context,
  708. deps: null,
  709. nodes_start: null,
  710. nodes_end: null,
  711. f: type | DIRTY,
  712. first: null,
  713. fn,
  714. last: null,
  715. next: null,
  716. parent,
  717. prev: null,
  718. teardown: null,
  719. transitions: null,
  720. wv: 0
  721. };
  722. if (sync) {
  723. try {
  724. update_effect(effect2);
  725. effect2.f |= EFFECT_RAN;
  726. } catch (e2) {
  727. destroy_effect(effect2);
  728. throw e2;
  729. }
  730. } else if (fn !== null) {
  731. schedule_effect(effect2);
  732. }
  733. var inert = sync && effect2.deps === null && effect2.first === null && effect2.nodes_start === null && effect2.teardown === null && (effect2.f & (EFFECT_HAS_DERIVED | BOUNDARY_EFFECT)) === 0;
  734. if (!inert && push2) {
  735. if (parent !== null) {
  736. push_effect(effect2, parent);
  737. }
  738. if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
  739. var derived2 = (
  740. /** @type {Derived} */
  741. active_reaction
  742. );
  743. (derived2.effects ?? (derived2.effects = [])).push(effect2);
  744. }
  745. }
  746. return effect2;
  747. }
  748. function teardown(fn) {
  749. const effect2 = create_effect(RENDER_EFFECT, null, false);
  750. set_signal_status(effect2, CLEAN);
  751. effect2.teardown = fn;
  752. return effect2;
  753. }
  754. function user_effect(fn) {
  755. validate_effect();
  756. var defer = active_effect !== null && (active_effect.f & BRANCH_EFFECT) !== 0 && component_context !== null && !component_context.m;
  757. if (defer) {
  758. var context = (
  759. /** @type {ComponentContext} */
  760. component_context
  761. );
  762. (context.e ?? (context.e = [])).push({
  763. fn,
  764. effect: active_effect,
  765. reaction: active_reaction
  766. });
  767. } else {
  768. var signal = effect(fn);
  769. return signal;
  770. }
  771. }
  772. function user_pre_effect(fn) {
  773. validate_effect();
  774. return render_effect(fn);
  775. }
  776. function component_root(fn) {
  777. const effect2 = create_effect(ROOT_EFFECT, fn, true);
  778. return (options = {}) => {
  779. return new Promise((fulfil) => {
  780. if (options.outro) {
  781. pause_effect(effect2, () => {
  782. destroy_effect(effect2);
  783. fulfil(void 0);
  784. });
  785. } else {
  786. destroy_effect(effect2);
  787. fulfil(void 0);
  788. }
  789. });
  790. };
  791. }
  792. function effect(fn) {
  793. return create_effect(EFFECT, fn, false);
  794. }
  795. function render_effect(fn) {
  796. return create_effect(RENDER_EFFECT, fn, true);
  797. }
  798. function template_effect(fn, thunks = [], d = derived$1) {
  799. const deriveds = thunks.map(d);
  800. const effect2 = () => fn(...deriveds.map(get$1));
  801. return block(effect2);
  802. }
  803. function block(fn, flags = 0) {
  804. return create_effect(RENDER_EFFECT | BLOCK_EFFECT | flags, fn, true);
  805. }
  806. function branch(fn, push2 = true) {
  807. return create_effect(RENDER_EFFECT | BRANCH_EFFECT, fn, true, push2);
  808. }
  809. function execute_effect_teardown(effect2) {
  810. var teardown2 = effect2.teardown;
  811. if (teardown2 !== null) {
  812. const previously_destroying_effect = is_destroying_effect;
  813. const previous_reaction = active_reaction;
  814. set_is_destroying_effect(true);
  815. set_active_reaction(null);
  816. try {
  817. teardown2.call(null);
  818. } finally {
  819. set_is_destroying_effect(previously_destroying_effect);
  820. set_active_reaction(previous_reaction);
  821. }
  822. }
  823. }
  824. function destroy_effect_children(signal, remove_dom = false) {
  825. var effect2 = signal.first;
  826. signal.first = signal.last = null;
  827. while (effect2 !== null) {
  828. var next = effect2.next;
  829. if ((effect2.f & ROOT_EFFECT) !== 0) {
  830. effect2.parent = null;
  831. } else {
  832. destroy_effect(effect2, remove_dom);
  833. }
  834. effect2 = next;
  835. }
  836. }
  837. function destroy_block_effect_children(signal) {
  838. var effect2 = signal.first;
  839. while (effect2 !== null) {
  840. var next = effect2.next;
  841. if ((effect2.f & BRANCH_EFFECT) === 0) {
  842. destroy_effect(effect2);
  843. }
  844. effect2 = next;
  845. }
  846. }
  847. function destroy_effect(effect2, remove_dom = true) {
  848. var removed = false;
  849. if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes_start !== null) {
  850. remove_effect_dom(
  851. effect2.nodes_start,
  852. /** @type {TemplateNode} */
  853. effect2.nodes_end
  854. );
  855. removed = true;
  856. }
  857. destroy_effect_children(effect2, remove_dom && !removed);
  858. remove_reactions(effect2, 0);
  859. set_signal_status(effect2, DESTROYED);
  860. var transitions = effect2.transitions;
  861. if (transitions !== null) {
  862. for (const transition of transitions) {
  863. transition.stop();
  864. }
  865. }
  866. execute_effect_teardown(effect2);
  867. var parent = effect2.parent;
  868. if (parent !== null && parent.first !== null) {
  869. unlink_effect(effect2);
  870. }
  871. effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes_start = effect2.nodes_end = null;
  872. }
  873. function remove_effect_dom(node, end) {
  874. while (node !== null) {
  875. var next = node === end ? null : (
  876. /** @type {TemplateNode} */
  877. /* @__PURE__ */ get_next_sibling(node)
  878. );
  879. node.remove();
  880. node = next;
  881. }
  882. }
  883. function unlink_effect(effect2) {
  884. var parent = effect2.parent;
  885. var prev = effect2.prev;
  886. var next = effect2.next;
  887. if (prev !== null) prev.next = next;
  888. if (next !== null) next.prev = prev;
  889. if (parent !== null) {
  890. if (parent.first === effect2) parent.first = next;
  891. if (parent.last === effect2) parent.last = prev;
  892. }
  893. }
  894. function pause_effect(effect2, callback) {
  895. var transitions = [];
  896. pause_children(effect2, transitions, true);
  897. run_out_transitions(transitions, () => {
  898. destroy_effect(effect2);
  899. if (callback) callback();
  900. });
  901. }
  902. function run_out_transitions(transitions, fn) {
  903. var remaining = transitions.length;
  904. if (remaining > 0) {
  905. var check = () => --remaining || fn();
  906. for (var transition of transitions) {
  907. transition.out(check);
  908. }
  909. } else {
  910. fn();
  911. }
  912. }
  913. function pause_children(effect2, transitions, local) {
  914. if ((effect2.f & INERT) !== 0) return;
  915. effect2.f ^= INERT;
  916. if (effect2.transitions !== null) {
  917. for (const transition of effect2.transitions) {
  918. if (transition.is_global || local) {
  919. transitions.push(transition);
  920. }
  921. }
  922. }
  923. var child2 = effect2.first;
  924. while (child2 !== null) {
  925. var sibling2 = child2.next;
  926. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  927. pause_children(child2, transitions, transparent ? local : false);
  928. child2 = sibling2;
  929. }
  930. }
  931. function resume_effect(effect2) {
  932. resume_children(effect2, true);
  933. }
  934. function resume_children(effect2, local) {
  935. if ((effect2.f & INERT) === 0) return;
  936. effect2.f ^= INERT;
  937. if ((effect2.f & CLEAN) === 0) {
  938. effect2.f ^= CLEAN;
  939. }
  940. if (check_dirtiness(effect2)) {
  941. set_signal_status(effect2, DIRTY);
  942. schedule_effect(effect2);
  943. }
  944. var child2 = effect2.first;
  945. while (child2 !== null) {
  946. var sibling2 = child2.next;
  947. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  948. resume_children(child2, transparent ? local : false);
  949. child2 = sibling2;
  950. }
  951. if (effect2.transitions !== null) {
  952. for (const transition of effect2.transitions) {
  953. if (transition.is_global || local) {
  954. transition.in();
  955. }
  956. }
  957. }
  958. }
  959. let micro_tasks = [];
  960. function run_micro_tasks() {
  961. var tasks = micro_tasks;
  962. micro_tasks = [];
  963. run_all(tasks);
  964. }
  965. function queue_micro_task(fn) {
  966. if (micro_tasks.length === 0) {
  967. queueMicrotask(run_micro_tasks);
  968. }
  969. micro_tasks.push(fn);
  970. }
  971. let is_throwing_error = false;
  972. let is_flushing = false;
  973. let last_scheduled_effect = null;
  974. let is_updating_effect = false;
  975. let is_destroying_effect = false;
  976. function set_is_destroying_effect(value) {
  977. is_destroying_effect = value;
  978. }
  979. let queued_root_effects = [];
  980. let active_reaction = null;
  981. let untracking = false;
  982. function set_active_reaction(reaction) {
  983. active_reaction = reaction;
  984. }
  985. let active_effect = null;
  986. function set_active_effect(effect2) {
  987. active_effect = effect2;
  988. }
  989. let reaction_sources = null;
  990. function push_reaction_value(value) {
  991. if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
  992. if (reaction_sources === null) {
  993. reaction_sources = [value];
  994. } else {
  995. reaction_sources.push(value);
  996. }
  997. }
  998. }
  999. let new_deps = null;
  1000. let skipped_deps = 0;
  1001. let untracked_writes = null;
  1002. function set_untracked_writes(value) {
  1003. untracked_writes = value;
  1004. }
  1005. let write_version = 1;
  1006. let read_version = 0;
  1007. let skip_reaction = false;
  1008. function increment_write_version() {
  1009. return ++write_version;
  1010. }
  1011. function check_dirtiness(reaction) {
  1012. var _a2;
  1013. var flags = reaction.f;
  1014. if ((flags & DIRTY) !== 0) {
  1015. return true;
  1016. }
  1017. if ((flags & MAYBE_DIRTY) !== 0) {
  1018. var dependencies = reaction.deps;
  1019. var is_unowned = (flags & UNOWNED) !== 0;
  1020. if (dependencies !== null) {
  1021. var i2;
  1022. var dependency;
  1023. var is_disconnected = (flags & DISCONNECTED) !== 0;
  1024. var is_unowned_connected = is_unowned && active_effect !== null && !skip_reaction;
  1025. var length = dependencies.length;
  1026. if (is_disconnected || is_unowned_connected) {
  1027. var derived2 = (
  1028. /** @type {Derived} */
  1029. reaction
  1030. );
  1031. var parent = derived2.parent;
  1032. for (i2 = 0; i2 < length; i2++) {
  1033. dependency = dependencies[i2];
  1034. if (is_disconnected || !((_a2 = dependency == null ? void 0 : dependency.reactions) == null ? void 0 : _a2.includes(derived2))) {
  1035. (dependency.reactions ?? (dependency.reactions = [])).push(derived2);
  1036. }
  1037. }
  1038. if (is_disconnected) {
  1039. derived2.f ^= DISCONNECTED;
  1040. }
  1041. if (is_unowned_connected && parent !== null && (parent.f & UNOWNED) === 0) {
  1042. derived2.f ^= UNOWNED;
  1043. }
  1044. }
  1045. for (i2 = 0; i2 < length; i2++) {
  1046. dependency = dependencies[i2];
  1047. if (check_dirtiness(
  1048. /** @type {Derived} */
  1049. dependency
  1050. )) {
  1051. update_derived(
  1052. /** @type {Derived} */
  1053. dependency
  1054. );
  1055. }
  1056. if (dependency.wv > reaction.wv) {
  1057. return true;
  1058. }
  1059. }
  1060. }
  1061. if (!is_unowned || active_effect !== null && !skip_reaction) {
  1062. set_signal_status(reaction, CLEAN);
  1063. }
  1064. }
  1065. return false;
  1066. }
  1067. function propagate_error(error, effect2) {
  1068. var current = effect2;
  1069. while (current !== null) {
  1070. if ((current.f & BOUNDARY_EFFECT) !== 0) {
  1071. try {
  1072. current.fn(error);
  1073. return;
  1074. } catch {
  1075. current.f ^= BOUNDARY_EFFECT;
  1076. }
  1077. }
  1078. current = current.parent;
  1079. }
  1080. is_throwing_error = false;
  1081. throw error;
  1082. }
  1083. function should_rethrow_error(effect2) {
  1084. return (effect2.f & DESTROYED) === 0 && (effect2.parent === null || (effect2.parent.f & BOUNDARY_EFFECT) === 0);
  1085. }
  1086. function handle_error(error, effect2, previous_effect, component_context2) {
  1087. if (is_throwing_error) {
  1088. if (previous_effect === null) {
  1089. is_throwing_error = false;
  1090. }
  1091. if (should_rethrow_error(effect2)) {
  1092. throw error;
  1093. }
  1094. return;
  1095. }
  1096. if (previous_effect !== null) {
  1097. is_throwing_error = true;
  1098. }
  1099. propagate_error(error, effect2);
  1100. if (should_rethrow_error(effect2)) {
  1101. throw error;
  1102. }
  1103. }
  1104. function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
  1105. var reactions = signal.reactions;
  1106. if (reactions === null) return;
  1107. for (var i2 = 0; i2 < reactions.length; i2++) {
  1108. var reaction = reactions[i2];
  1109. if (reaction_sources == null ? void 0 : reaction_sources.includes(signal)) continue;
  1110. if ((reaction.f & DERIVED) !== 0) {
  1111. schedule_possible_effect_self_invalidation(
  1112. /** @type {Derived} */
  1113. reaction,
  1114. effect2,
  1115. false
  1116. );
  1117. } else if (effect2 === reaction) {
  1118. if (root2) {
  1119. set_signal_status(reaction, DIRTY);
  1120. } else if ((reaction.f & CLEAN) !== 0) {
  1121. set_signal_status(reaction, MAYBE_DIRTY);
  1122. }
  1123. schedule_effect(
  1124. /** @type {Effect} */
  1125. reaction
  1126. );
  1127. }
  1128. }
  1129. }
  1130. function update_reaction(reaction) {
  1131. var _a2;
  1132. var previous_deps = new_deps;
  1133. var previous_skipped_deps = skipped_deps;
  1134. var previous_untracked_writes = untracked_writes;
  1135. var previous_reaction = active_reaction;
  1136. var previous_skip_reaction = skip_reaction;
  1137. var previous_reaction_sources = reaction_sources;
  1138. var previous_component_context = component_context;
  1139. var previous_untracking = untracking;
  1140. var flags = reaction.f;
  1141. new_deps = /** @type {null | Value[]} */
  1142. null;
  1143. skipped_deps = 0;
  1144. untracked_writes = null;
  1145. skip_reaction = (flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
  1146. active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
  1147. reaction_sources = null;
  1148. set_component_context(reaction.ctx);
  1149. untracking = false;
  1150. read_version++;
  1151. reaction.f |= EFFECT_IS_UPDATING;
  1152. try {
  1153. var result = (
  1154. /** @type {Function} */
  1155. (0, reaction.fn)()
  1156. );
  1157. var deps = reaction.deps;
  1158. if (new_deps !== null) {
  1159. var i2;
  1160. remove_reactions(reaction, skipped_deps);
  1161. if (deps !== null && skipped_deps > 0) {
  1162. deps.length = skipped_deps + new_deps.length;
  1163. for (i2 = 0; i2 < new_deps.length; i2++) {
  1164. deps[skipped_deps + i2] = new_deps[i2];
  1165. }
  1166. } else {
  1167. reaction.deps = deps = new_deps;
  1168. }
  1169. if (!skip_reaction) {
  1170. for (i2 = skipped_deps; i2 < deps.length; i2++) {
  1171. ((_a2 = deps[i2]).reactions ?? (_a2.reactions = [])).push(reaction);
  1172. }
  1173. }
  1174. } else if (deps !== null && skipped_deps < deps.length) {
  1175. remove_reactions(reaction, skipped_deps);
  1176. deps.length = skipped_deps;
  1177. }
  1178. if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
  1179. for (i2 = 0; i2 < /** @type {Source[]} */
  1180. untracked_writes.length; i2++) {
  1181. schedule_possible_effect_self_invalidation(
  1182. untracked_writes[i2],
  1183. /** @type {Effect} */
  1184. reaction
  1185. );
  1186. }
  1187. }
  1188. if (previous_reaction !== null && previous_reaction !== reaction) {
  1189. read_version++;
  1190. if (untracked_writes !== null) {
  1191. if (previous_untracked_writes === null) {
  1192. previous_untracked_writes = untracked_writes;
  1193. } else {
  1194. previous_untracked_writes.push(.../** @type {Source[]} */
  1195. untracked_writes);
  1196. }
  1197. }
  1198. }
  1199. return result;
  1200. } finally {
  1201. new_deps = previous_deps;
  1202. skipped_deps = previous_skipped_deps;
  1203. untracked_writes = previous_untracked_writes;
  1204. active_reaction = previous_reaction;
  1205. skip_reaction = previous_skip_reaction;
  1206. reaction_sources = previous_reaction_sources;
  1207. set_component_context(previous_component_context);
  1208. untracking = previous_untracking;
  1209. reaction.f ^= EFFECT_IS_UPDATING;
  1210. }
  1211. }
  1212. function remove_reaction(signal, dependency) {
  1213. let reactions = dependency.reactions;
  1214. if (reactions !== null) {
  1215. var index = index_of.call(reactions, signal);
  1216. if (index !== -1) {
  1217. var new_length = reactions.length - 1;
  1218. if (new_length === 0) {
  1219. reactions = dependency.reactions = null;
  1220. } else {
  1221. reactions[index] = reactions[new_length];
  1222. reactions.pop();
  1223. }
  1224. }
  1225. }
  1226. if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
  1227. // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
  1228. // allows us to skip the expensive work of disconnecting and immediately reconnecting it
  1229. (new_deps === null || !new_deps.includes(dependency))) {
  1230. set_signal_status(dependency, MAYBE_DIRTY);
  1231. if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) {
  1232. dependency.f ^= DISCONNECTED;
  1233. }
  1234. destroy_derived_effects(
  1235. /** @type {Derived} **/
  1236. dependency
  1237. );
  1238. remove_reactions(
  1239. /** @type {Derived} **/
  1240. dependency,
  1241. 0
  1242. );
  1243. }
  1244. }
  1245. function remove_reactions(signal, start_index) {
  1246. var dependencies = signal.deps;
  1247. if (dependencies === null) return;
  1248. for (var i2 = start_index; i2 < dependencies.length; i2++) {
  1249. remove_reaction(signal, dependencies[i2]);
  1250. }
  1251. }
  1252. function update_effect(effect2) {
  1253. var flags = effect2.f;
  1254. if ((flags & DESTROYED) !== 0) {
  1255. return;
  1256. }
  1257. set_signal_status(effect2, CLEAN);
  1258. var previous_effect = active_effect;
  1259. var previous_component_context = component_context;
  1260. var was_updating_effect = is_updating_effect;
  1261. active_effect = effect2;
  1262. is_updating_effect = true;
  1263. try {
  1264. if ((flags & BLOCK_EFFECT) !== 0) {
  1265. destroy_block_effect_children(effect2);
  1266. } else {
  1267. destroy_effect_children(effect2);
  1268. }
  1269. execute_effect_teardown(effect2);
  1270. var teardown2 = update_reaction(effect2);
  1271. effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
  1272. effect2.wv = write_version;
  1273. var deps = effect2.deps;
  1274. var dep;
  1275. if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && deps !== null) ;
  1276. if (DEV) ;
  1277. } catch (error) {
  1278. handle_error(error, effect2, previous_effect, previous_component_context || effect2.ctx);
  1279. } finally {
  1280. is_updating_effect = was_updating_effect;
  1281. active_effect = previous_effect;
  1282. }
  1283. }
  1284. function infinite_loop_guard() {
  1285. try {
  1286. effect_update_depth_exceeded();
  1287. } catch (error) {
  1288. if (last_scheduled_effect !== null) {
  1289. {
  1290. handle_error(error, last_scheduled_effect, null);
  1291. }
  1292. } else {
  1293. throw error;
  1294. }
  1295. }
  1296. }
  1297. function flush_queued_root_effects() {
  1298. var was_updating_effect = is_updating_effect;
  1299. try {
  1300. var flush_count = 0;
  1301. is_updating_effect = true;
  1302. while (queued_root_effects.length > 0) {
  1303. if (flush_count++ > 1e3) {
  1304. infinite_loop_guard();
  1305. }
  1306. var root_effects = queued_root_effects;
  1307. var length = root_effects.length;
  1308. queued_root_effects = [];
  1309. for (var i2 = 0; i2 < length; i2++) {
  1310. var collected_effects = process_effects(root_effects[i2]);
  1311. flush_queued_effects(collected_effects);
  1312. }
  1313. old_values.clear();
  1314. }
  1315. } finally {
  1316. is_flushing = false;
  1317. is_updating_effect = was_updating_effect;
  1318. last_scheduled_effect = null;
  1319. }
  1320. }
  1321. function flush_queued_effects(effects) {
  1322. var length = effects.length;
  1323. if (length === 0) return;
  1324. for (var i2 = 0; i2 < length; i2++) {
  1325. var effect2 = effects[i2];
  1326. if ((effect2.f & (DESTROYED | INERT)) === 0) {
  1327. try {
  1328. if (check_dirtiness(effect2)) {
  1329. update_effect(effect2);
  1330. if (effect2.deps === null && effect2.first === null && effect2.nodes_start === null) {
  1331. if (effect2.teardown === null) {
  1332. unlink_effect(effect2);
  1333. } else {
  1334. effect2.fn = null;
  1335. }
  1336. }
  1337. }
  1338. } catch (error) {
  1339. handle_error(error, effect2, null, effect2.ctx);
  1340. }
  1341. }
  1342. }
  1343. }
  1344. function schedule_effect(signal) {
  1345. if (!is_flushing) {
  1346. is_flushing = true;
  1347. queueMicrotask(flush_queued_root_effects);
  1348. }
  1349. var effect2 = last_scheduled_effect = signal;
  1350. while (effect2.parent !== null) {
  1351. effect2 = effect2.parent;
  1352. var flags = effect2.f;
  1353. if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
  1354. if ((flags & CLEAN) === 0) return;
  1355. effect2.f ^= CLEAN;
  1356. }
  1357. }
  1358. queued_root_effects.push(effect2);
  1359. }
  1360. function process_effects(root2) {
  1361. var effects = [];
  1362. var effect2 = root2;
  1363. while (effect2 !== null) {
  1364. var flags = effect2.f;
  1365. var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
  1366. var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
  1367. if (!is_skippable_branch && (flags & INERT) === 0) {
  1368. if ((flags & EFFECT) !== 0) {
  1369. effects.push(effect2);
  1370. } else if (is_branch) {
  1371. effect2.f ^= CLEAN;
  1372. } else {
  1373. try {
  1374. if (check_dirtiness(effect2)) {
  1375. update_effect(effect2);
  1376. }
  1377. } catch (error) {
  1378. handle_error(error, effect2, null, effect2.ctx);
  1379. }
  1380. }
  1381. var child2 = effect2.first;
  1382. if (child2 !== null) {
  1383. effect2 = child2;
  1384. continue;
  1385. }
  1386. }
  1387. var parent = effect2.parent;
  1388. effect2 = effect2.next;
  1389. while (effect2 === null && parent !== null) {
  1390. effect2 = parent.next;
  1391. parent = parent.parent;
  1392. }
  1393. }
  1394. return effects;
  1395. }
  1396. function get$1(signal) {
  1397. var flags = signal.f;
  1398. var is_derived = (flags & DERIVED) !== 0;
  1399. if (active_reaction !== null && !untracking) {
  1400. if (!(reaction_sources == null ? void 0 : reaction_sources.includes(signal))) {
  1401. var deps = active_reaction.deps;
  1402. if (signal.rv < read_version) {
  1403. signal.rv = read_version;
  1404. if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
  1405. skipped_deps++;
  1406. } else if (new_deps === null) {
  1407. new_deps = [signal];
  1408. } else if (!skip_reaction || !new_deps.includes(signal)) {
  1409. new_deps.push(signal);
  1410. }
  1411. }
  1412. }
  1413. } else if (is_derived && /** @type {Derived} */
  1414. signal.deps === null && /** @type {Derived} */
  1415. signal.effects === null) {
  1416. var derived2 = (
  1417. /** @type {Derived} */
  1418. signal
  1419. );
  1420. var parent = derived2.parent;
  1421. if (parent !== null && (parent.f & UNOWNED) === 0) {
  1422. derived2.f ^= UNOWNED;
  1423. }
  1424. }
  1425. if (is_derived) {
  1426. derived2 = /** @type {Derived} */
  1427. signal;
  1428. if (check_dirtiness(derived2)) {
  1429. update_derived(derived2);
  1430. }
  1431. }
  1432. if (is_destroying_effect && old_values.has(signal)) {
  1433. return old_values.get(signal);
  1434. }
  1435. return signal.v;
  1436. }
  1437. function untrack(fn) {
  1438. var previous_untracking = untracking;
  1439. try {
  1440. untracking = true;
  1441. return fn();
  1442. } finally {
  1443. untracking = previous_untracking;
  1444. }
  1445. }
  1446. const STATUS_MASK = -7169;
  1447. function set_signal_status(signal, status) {
  1448. signal.f = signal.f & STATUS_MASK | status;
  1449. }
  1450. function deep_read_state(value) {
  1451. if (typeof value !== "object" || !value || value instanceof EventTarget) {
  1452. return;
  1453. }
  1454. if (STATE_SYMBOL in value) {
  1455. deep_read(value);
  1456. } else if (!Array.isArray(value)) {
  1457. for (let key in value) {
  1458. const prop2 = value[key];
  1459. if (typeof prop2 === "object" && prop2 && STATE_SYMBOL in prop2) {
  1460. deep_read(prop2);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. function deep_read(value, visited = /* @__PURE__ */ new Set()) {
  1466. if (typeof value === "object" && value !== null && // We don't want to traverse DOM elements
  1467. !(value instanceof EventTarget) && !visited.has(value)) {
  1468. visited.add(value);
  1469. if (value instanceof Date) {
  1470. value.getTime();
  1471. }
  1472. for (let key in value) {
  1473. try {
  1474. deep_read(value[key], visited);
  1475. } catch (e2) {
  1476. }
  1477. }
  1478. const proto = get_prototype_of(value);
  1479. if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
  1480. const descriptors = get_descriptors(proto);
  1481. for (let key in descriptors) {
  1482. const get2 = descriptors[key].get;
  1483. if (get2) {
  1484. try {
  1485. get2.call(value);
  1486. } catch (e2) {
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. }
  1493. function is_capture_event(name) {
  1494. return name.endsWith("capture") && name !== "gotpointercapture" && name !== "lostpointercapture";
  1495. }
  1496. const DELEGATED_EVENTS = [
  1497. "beforeinput",
  1498. "click",
  1499. "change",
  1500. "dblclick",
  1501. "contextmenu",
  1502. "focusin",
  1503. "focusout",
  1504. "input",
  1505. "keydown",
  1506. "keyup",
  1507. "mousedown",
  1508. "mousemove",
  1509. "mouseout",
  1510. "mouseover",
  1511. "mouseup",
  1512. "pointerdown",
  1513. "pointermove",
  1514. "pointerout",
  1515. "pointerover",
  1516. "pointerup",
  1517. "touchend",
  1518. "touchmove",
  1519. "touchstart"
  1520. ];
  1521. function is_delegated(event_name) {
  1522. return DELEGATED_EVENTS.includes(event_name);
  1523. }
  1524. const ATTRIBUTE_ALIASES = {
  1525. // no `class: 'className'` because we handle that separately
  1526. formnovalidate: "formNoValidate",
  1527. ismap: "isMap",
  1528. nomodule: "noModule",
  1529. playsinline: "playsInline",
  1530. readonly: "readOnly",
  1531. defaultvalue: "defaultValue",
  1532. defaultchecked: "defaultChecked",
  1533. srcobject: "srcObject",
  1534. novalidate: "noValidate",
  1535. allowfullscreen: "allowFullscreen",
  1536. disablepictureinpicture: "disablePictureInPicture",
  1537. disableremoteplayback: "disableRemotePlayback"
  1538. };
  1539. function normalize_attribute(name) {
  1540. name = name.toLowerCase();
  1541. return ATTRIBUTE_ALIASES[name] ?? name;
  1542. }
  1543. const PASSIVE_EVENTS = ["touchstart", "touchmove"];
  1544. function is_passive_event(name) {
  1545. return PASSIVE_EVENTS.includes(name);
  1546. }
  1547. function autofocus(dom, value) {
  1548. if (value) {
  1549. const body = document.body;
  1550. dom.autofocus = true;
  1551. queue_micro_task(() => {
  1552. if (document.activeElement === body) {
  1553. dom.focus();
  1554. }
  1555. });
  1556. }
  1557. }
  1558. function without_reactive_context(fn) {
  1559. var previous_reaction = active_reaction;
  1560. var previous_effect = active_effect;
  1561. set_active_reaction(null);
  1562. set_active_effect(null);
  1563. try {
  1564. return fn();
  1565. } finally {
  1566. set_active_reaction(previous_reaction);
  1567. set_active_effect(previous_effect);
  1568. }
  1569. }
  1570. const all_registered_events = /* @__PURE__ */ new Set();
  1571. const root_event_handles = /* @__PURE__ */ new Set();
  1572. function create_event(event_name, dom, handler, options = {}) {
  1573. function target_handler(event2) {
  1574. if (!options.capture) {
  1575. handle_event_propagation.call(dom, event2);
  1576. }
  1577. if (!event2.cancelBubble) {
  1578. return without_reactive_context(() => {
  1579. return handler == null ? void 0 : handler.call(this, event2);
  1580. });
  1581. }
  1582. }
  1583. if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
  1584. queue_micro_task(() => {
  1585. dom.addEventListener(event_name, target_handler, options);
  1586. });
  1587. } else {
  1588. dom.addEventListener(event_name, target_handler, options);
  1589. }
  1590. return target_handler;
  1591. }
  1592. function event(event_name, dom, handler, capture, passive) {
  1593. var options = { capture, passive };
  1594. var target_handler = create_event(event_name, dom, handler, options);
  1595. if (dom === document.body || // @ts-ignore
  1596. dom === window || // @ts-ignore
  1597. dom === document || // Firefox has quirky behavior, it can happen that we still get "canplay" events when the element is already removed
  1598. dom instanceof HTMLMediaElement) {
  1599. teardown(() => {
  1600. dom.removeEventListener(event_name, target_handler, options);
  1601. });
  1602. }
  1603. }
  1604. function delegate(events) {
  1605. for (var i2 = 0; i2 < events.length; i2++) {
  1606. all_registered_events.add(events[i2]);
  1607. }
  1608. for (var fn of root_event_handles) {
  1609. fn(events);
  1610. }
  1611. }
  1612. function handle_event_propagation(event2) {
  1613. var _a2;
  1614. var handler_element = this;
  1615. var owner_document = (
  1616. /** @type {Node} */
  1617. handler_element.ownerDocument
  1618. );
  1619. var event_name = event2.type;
  1620. var path = ((_a2 = event2.composedPath) == null ? void 0 : _a2.call(event2)) || [];
  1621. var current_target = (
  1622. /** @type {null | Element} */
  1623. path[0] || event2.target
  1624. );
  1625. var path_idx = 0;
  1626. var handled_at = event2.__root;
  1627. if (handled_at) {
  1628. var at_idx = path.indexOf(handled_at);
  1629. if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
  1630. window)) {
  1631. event2.__root = handler_element;
  1632. return;
  1633. }
  1634. var handler_idx = path.indexOf(handler_element);
  1635. if (handler_idx === -1) {
  1636. return;
  1637. }
  1638. if (at_idx <= handler_idx) {
  1639. path_idx = at_idx;
  1640. }
  1641. }
  1642. current_target = /** @type {Element} */
  1643. path[path_idx] || event2.target;
  1644. if (current_target === handler_element) return;
  1645. define_property(event2, "currentTarget", {
  1646. configurable: true,
  1647. get() {
  1648. return current_target || owner_document;
  1649. }
  1650. });
  1651. var previous_reaction = active_reaction;
  1652. var previous_effect = active_effect;
  1653. set_active_reaction(null);
  1654. set_active_effect(null);
  1655. try {
  1656. var throw_error;
  1657. var other_errors = [];
  1658. while (current_target !== null) {
  1659. var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
  1660. current_target.host || null;
  1661. try {
  1662. var delegated = current_target["__" + event_name];
  1663. if (delegated != null && (!/** @type {any} */
  1664. current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
  1665. // -> the target could not have been disabled because it emits the event in the first place
  1666. event2.target === current_target)) {
  1667. if (is_array(delegated)) {
  1668. var [fn, ...data] = delegated;
  1669. fn.apply(current_target, [event2, ...data]);
  1670. } else {
  1671. delegated.call(current_target, event2);
  1672. }
  1673. }
  1674. } catch (error) {
  1675. if (throw_error) {
  1676. other_errors.push(error);
  1677. } else {
  1678. throw_error = error;
  1679. }
  1680. }
  1681. if (event2.cancelBubble || parent_element === handler_element || parent_element === null) {
  1682. break;
  1683. }
  1684. current_target = parent_element;
  1685. }
  1686. if (throw_error) {
  1687. for (let error of other_errors) {
  1688. queueMicrotask(() => {
  1689. throw error;
  1690. });
  1691. }
  1692. throw throw_error;
  1693. }
  1694. } finally {
  1695. event2.__root = handler_element;
  1696. delete event2.currentTarget;
  1697. set_active_reaction(previous_reaction);
  1698. set_active_effect(previous_effect);
  1699. }
  1700. }
  1701. function create_fragment_from_html(html) {
  1702. var elem = document.createElement("template");
  1703. elem.innerHTML = html.replaceAll("<!>", "<!---->");
  1704. return elem.content;
  1705. }
  1706. function assign_nodes(start, end) {
  1707. var effect2 = (
  1708. /** @type {Effect} */
  1709. active_effect
  1710. );
  1711. if (effect2.nodes_start === null) {
  1712. effect2.nodes_start = start;
  1713. effect2.nodes_end = end;
  1714. }
  1715. }
  1716. // @__NO_SIDE_EFFECTS__
  1717. function from_html(content, flags) {
  1718. var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
  1719. var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
  1720. var node;
  1721. var has_start = !content.startsWith("<!>");
  1722. return () => {
  1723. if (node === void 0) {
  1724. node = create_fragment_from_html(has_start ? content : "<!>" + content);
  1725. if (!is_fragment) node = /** @type {Node} */
  1726. /* @__PURE__ */ get_first_child(node);
  1727. }
  1728. var clone = (
  1729. /** @type {TemplateNode} */
  1730. use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
  1731. );
  1732. if (is_fragment) {
  1733. var start = (
  1734. /** @type {TemplateNode} */
  1735. /* @__PURE__ */ get_first_child(clone)
  1736. );
  1737. var end = (
  1738. /** @type {TemplateNode} */
  1739. clone.lastChild
  1740. );
  1741. assign_nodes(start, end);
  1742. } else {
  1743. assign_nodes(clone, clone);
  1744. }
  1745. return clone;
  1746. };
  1747. }
  1748. // @__NO_SIDE_EFFECTS__
  1749. function from_namespace(content, flags, ns = "svg") {
  1750. var has_start = !content.startsWith("<!>");
  1751. var wrapped = `<${ns}>${has_start ? content : "<!>" + content}</${ns}>`;
  1752. var node;
  1753. return () => {
  1754. if (!node) {
  1755. var fragment = (
  1756. /** @type {DocumentFragment} */
  1757. create_fragment_from_html(wrapped)
  1758. );
  1759. var root2 = (
  1760. /** @type {Element} */
  1761. /* @__PURE__ */ get_first_child(fragment)
  1762. );
  1763. {
  1764. node = /** @type {Element} */
  1765. /* @__PURE__ */ get_first_child(root2);
  1766. }
  1767. }
  1768. var clone = (
  1769. /** @type {TemplateNode} */
  1770. node.cloneNode(true)
  1771. );
  1772. {
  1773. assign_nodes(clone, clone);
  1774. }
  1775. return clone;
  1776. };
  1777. }
  1778. // @__NO_SIDE_EFFECTS__
  1779. function from_svg(content, flags) {
  1780. return /* @__PURE__ */ from_namespace(content, flags, "svg");
  1781. }
  1782. function text(value = "") {
  1783. {
  1784. var t = create_text(value + "");
  1785. assign_nodes(t, t);
  1786. return t;
  1787. }
  1788. }
  1789. function comment() {
  1790. var frag = document.createDocumentFragment();
  1791. var start = document.createComment("");
  1792. var anchor = create_text();
  1793. frag.append(start, anchor);
  1794. assign_nodes(start, anchor);
  1795. return frag;
  1796. }
  1797. function append(anchor, dom) {
  1798. if (anchor === null) {
  1799. return;
  1800. }
  1801. anchor.before(
  1802. /** @type {Node} */
  1803. dom
  1804. );
  1805. }
  1806. function set_text(text2, value) {
  1807. var str = value == null ? "" : typeof value === "object" ? value + "" : value;
  1808. if (str !== (text2.__t ?? (text2.__t = text2.nodeValue))) {
  1809. text2.__t = str;
  1810. text2.nodeValue = str + "";
  1811. }
  1812. }
  1813. function mount(component2, options) {
  1814. return _mount(component2, options);
  1815. }
  1816. const document_listeners = /* @__PURE__ */ new Map();
  1817. function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
  1818. init_operations();
  1819. var registered_events = /* @__PURE__ */ new Set();
  1820. var event_handle = (events2) => {
  1821. for (var i2 = 0; i2 < events2.length; i2++) {
  1822. var event_name = events2[i2];
  1823. if (registered_events.has(event_name)) continue;
  1824. registered_events.add(event_name);
  1825. var passive = is_passive_event(event_name);
  1826. target.addEventListener(event_name, handle_event_propagation, { passive });
  1827. var n = document_listeners.get(event_name);
  1828. if (n === void 0) {
  1829. document.addEventListener(event_name, handle_event_propagation, { passive });
  1830. document_listeners.set(event_name, 1);
  1831. } else {
  1832. document_listeners.set(event_name, n + 1);
  1833. }
  1834. }
  1835. };
  1836. event_handle(array_from(all_registered_events));
  1837. root_event_handles.add(event_handle);
  1838. var component2 = void 0;
  1839. var unmount = component_root(() => {
  1840. var anchor_node = anchor ?? target.appendChild(create_text());
  1841. branch(() => {
  1842. if (context) {
  1843. push({});
  1844. var ctx = (
  1845. /** @type {ComponentContext} */
  1846. component_context
  1847. );
  1848. ctx.c = context;
  1849. }
  1850. if (events) {
  1851. props.$$events = events;
  1852. }
  1853. component2 = Component(anchor_node, props) || {};
  1854. if (context) {
  1855. pop();
  1856. }
  1857. });
  1858. return () => {
  1859. var _a2;
  1860. for (var event_name of registered_events) {
  1861. target.removeEventListener(event_name, handle_event_propagation);
  1862. var n = (
  1863. /** @type {number} */
  1864. document_listeners.get(event_name)
  1865. );
  1866. if (--n === 0) {
  1867. document.removeEventListener(event_name, handle_event_propagation);
  1868. document_listeners.delete(event_name);
  1869. } else {
  1870. document_listeners.set(event_name, n);
  1871. }
  1872. }
  1873. root_event_handles.delete(event_handle);
  1874. if (anchor_node !== anchor) {
  1875. (_a2 = anchor_node.parentNode) == null ? void 0 : _a2.removeChild(anchor_node);
  1876. }
  1877. };
  1878. });
  1879. mounted_components.set(component2, unmount);
  1880. return component2;
  1881. }
  1882. let mounted_components = /* @__PURE__ */ new WeakMap();
  1883. function if_block(node, fn, [root_index, hydrate_index] = [0, 0]) {
  1884. var anchor = node;
  1885. var consequent_effect = null;
  1886. var alternate_effect = null;
  1887. var condition = UNINITIALIZED;
  1888. var flags = root_index > 0 ? EFFECT_TRANSPARENT : 0;
  1889. var has_branch = false;
  1890. const set_branch = (fn2, flag = true) => {
  1891. has_branch = true;
  1892. update_branch(flag, fn2);
  1893. };
  1894. const update_branch = (new_condition, fn2) => {
  1895. if (condition === (condition = new_condition)) return;
  1896. if (condition) {
  1897. if (consequent_effect) {
  1898. resume_effect(consequent_effect);
  1899. } else if (fn2) {
  1900. consequent_effect = branch(() => fn2(anchor));
  1901. }
  1902. if (alternate_effect) {
  1903. pause_effect(alternate_effect, () => {
  1904. alternate_effect = null;
  1905. });
  1906. }
  1907. } else {
  1908. if (alternate_effect) {
  1909. resume_effect(alternate_effect);
  1910. } else if (fn2) {
  1911. alternate_effect = branch(() => fn2(anchor, [root_index + 1, hydrate_index]));
  1912. }
  1913. if (consequent_effect) {
  1914. pause_effect(consequent_effect, () => {
  1915. consequent_effect = null;
  1916. });
  1917. }
  1918. }
  1919. };
  1920. block(() => {
  1921. has_branch = false;
  1922. fn(set_branch);
  1923. if (!has_branch) {
  1924. update_branch(null, null);
  1925. }
  1926. }, flags);
  1927. }
  1928. function pause_effects(state2, items, controlled_anchor, items_map) {
  1929. var transitions = [];
  1930. var length = items.length;
  1931. for (var i2 = 0; i2 < length; i2++) {
  1932. pause_children(items[i2].e, transitions, true);
  1933. }
  1934. var is_controlled = length > 0 && transitions.length === 0 && controlled_anchor !== null;
  1935. if (is_controlled) {
  1936. var parent_node = (
  1937. /** @type {Element} */
  1938. /** @type {Element} */
  1939. controlled_anchor.parentNode
  1940. );
  1941. clear_text_content(parent_node);
  1942. parent_node.append(
  1943. /** @type {Element} */
  1944. controlled_anchor
  1945. );
  1946. items_map.clear();
  1947. link(state2, items[0].prev, items[length - 1].next);
  1948. }
  1949. run_out_transitions(transitions, () => {
  1950. for (var i3 = 0; i3 < length; i3++) {
  1951. var item = items[i3];
  1952. if (!is_controlled) {
  1953. items_map.delete(item.k);
  1954. link(state2, item.prev, item.next);
  1955. }
  1956. destroy_effect(item.e, !is_controlled);
  1957. }
  1958. });
  1959. }
  1960. function each(node, flags, get_collection, get_key, render_fn, fallback_fn = null) {
  1961. var anchor = node;
  1962. var state2 = { flags, items: /* @__PURE__ */ new Map(), first: null };
  1963. {
  1964. var parent_node = (
  1965. /** @type {Element} */
  1966. node
  1967. );
  1968. anchor = parent_node.appendChild(create_text());
  1969. }
  1970. var fallback = null;
  1971. var was_empty = false;
  1972. var each_array = /* @__PURE__ */ derived_safe_equal(() => {
  1973. var collection = get_collection();
  1974. return is_array(collection) ? collection : collection == null ? [] : array_from(collection);
  1975. });
  1976. block(() => {
  1977. var array = get$1(each_array);
  1978. var length = array.length;
  1979. if (was_empty && length === 0) {
  1980. return;
  1981. }
  1982. was_empty = length === 0;
  1983. {
  1984. reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection);
  1985. }
  1986. if (fallback_fn !== null) {
  1987. if (length === 0) {
  1988. if (fallback) {
  1989. resume_effect(fallback);
  1990. } else {
  1991. fallback = branch(() => fallback_fn(anchor));
  1992. }
  1993. } else if (fallback !== null) {
  1994. pause_effect(fallback, () => {
  1995. fallback = null;
  1996. });
  1997. }
  1998. }
  1999. get$1(each_array);
  2000. });
  2001. }
  2002. function reconcile(array, state2, anchor, render_fn, flags, get_key, get_collection) {
  2003. var length = array.length;
  2004. var items = state2.items;
  2005. var first = state2.first;
  2006. var current = first;
  2007. var seen;
  2008. var prev = null;
  2009. var matched = [];
  2010. var stashed = [];
  2011. var value;
  2012. var key;
  2013. var item;
  2014. var i2;
  2015. for (i2 = 0; i2 < length; i2 += 1) {
  2016. value = array[i2];
  2017. key = get_key(value, i2);
  2018. item = items.get(key);
  2019. if (item === void 0) {
  2020. var child_anchor = current ? (
  2021. /** @type {TemplateNode} */
  2022. current.e.nodes_start
  2023. ) : anchor;
  2024. prev = create_item(
  2025. child_anchor,
  2026. state2,
  2027. prev,
  2028. prev === null ? state2.first : prev.next,
  2029. value,
  2030. key,
  2031. i2,
  2032. render_fn,
  2033. flags,
  2034. get_collection
  2035. );
  2036. items.set(key, prev);
  2037. matched = [];
  2038. stashed = [];
  2039. current = prev.next;
  2040. continue;
  2041. }
  2042. {
  2043. update_item(item, value, i2);
  2044. }
  2045. if ((item.e.f & INERT) !== 0) {
  2046. resume_effect(item.e);
  2047. }
  2048. if (item !== current) {
  2049. if (seen !== void 0 && seen.has(item)) {
  2050. if (matched.length < stashed.length) {
  2051. var start = stashed[0];
  2052. var j;
  2053. prev = start.prev;
  2054. var a2 = matched[0];
  2055. var b = matched[matched.length - 1];
  2056. for (j = 0; j < matched.length; j += 1) {
  2057. move(matched[j], start, anchor);
  2058. }
  2059. for (j = 0; j < stashed.length; j += 1) {
  2060. seen.delete(stashed[j]);
  2061. }
  2062. link(state2, a2.prev, b.next);
  2063. link(state2, prev, a2);
  2064. link(state2, b, start);
  2065. current = start;
  2066. prev = b;
  2067. i2 -= 1;
  2068. matched = [];
  2069. stashed = [];
  2070. } else {
  2071. seen.delete(item);
  2072. move(item, current, anchor);
  2073. link(state2, item.prev, item.next);
  2074. link(state2, item, prev === null ? state2.first : prev.next);
  2075. link(state2, prev, item);
  2076. prev = item;
  2077. }
  2078. continue;
  2079. }
  2080. matched = [];
  2081. stashed = [];
  2082. while (current !== null && current.k !== key) {
  2083. if ((current.e.f & INERT) === 0) {
  2084. (seen ?? (seen = /* @__PURE__ */ new Set())).add(current);
  2085. }
  2086. stashed.push(current);
  2087. current = current.next;
  2088. }
  2089. if (current === null) {
  2090. continue;
  2091. }
  2092. item = current;
  2093. }
  2094. matched.push(item);
  2095. prev = item;
  2096. current = item.next;
  2097. }
  2098. if (current !== null || seen !== void 0) {
  2099. var to_destroy = seen === void 0 ? [] : array_from(seen);
  2100. while (current !== null) {
  2101. if ((current.e.f & INERT) === 0) {
  2102. to_destroy.push(current);
  2103. }
  2104. current = current.next;
  2105. }
  2106. var destroy_length = to_destroy.length;
  2107. if (destroy_length > 0) {
  2108. var controlled_anchor = length === 0 ? anchor : null;
  2109. pause_effects(state2, to_destroy, controlled_anchor, items);
  2110. }
  2111. }
  2112. active_effect.first = state2.first && state2.first.e;
  2113. active_effect.last = prev && prev.e;
  2114. }
  2115. function update_item(item, value, index, type) {
  2116. {
  2117. internal_set(item.v, value);
  2118. }
  2119. {
  2120. item.i = index;
  2121. }
  2122. }
  2123. function create_item(anchor, state2, prev, next, value, key, index, render_fn, flags, get_collection) {
  2124. var reactive = (flags & EACH_ITEM_REACTIVE) !== 0;
  2125. var mutable = (flags & EACH_ITEM_IMMUTABLE) === 0;
  2126. var v2 = reactive ? mutable ? /* @__PURE__ */ mutable_source(value) : source(value) : value;
  2127. var i2 = (flags & EACH_INDEX_REACTIVE) === 0 ? index : source(index);
  2128. var item = {
  2129. i: i2,
  2130. v: v2,
  2131. k: key,
  2132. a: null,
  2133. // @ts-expect-error
  2134. e: null,
  2135. prev,
  2136. next
  2137. };
  2138. try {
  2139. item.e = branch(() => render_fn(anchor, v2, i2, get_collection), hydrating);
  2140. item.e.prev = prev && prev.e;
  2141. item.e.next = next && next.e;
  2142. if (prev === null) {
  2143. state2.first = item;
  2144. } else {
  2145. prev.next = item;
  2146. prev.e.next = item.e;
  2147. }
  2148. if (next !== null) {
  2149. next.prev = item;
  2150. next.e.prev = item.e;
  2151. }
  2152. return item;
  2153. } finally {
  2154. }
  2155. }
  2156. function move(item, next, anchor) {
  2157. var end = item.next ? (
  2158. /** @type {TemplateNode} */
  2159. item.next.e.nodes_start
  2160. ) : anchor;
  2161. var dest = next ? (
  2162. /** @type {TemplateNode} */
  2163. next.e.nodes_start
  2164. ) : anchor;
  2165. var node = (
  2166. /** @type {TemplateNode} */
  2167. item.e.nodes_start
  2168. );
  2169. while (node !== end) {
  2170. var next_node = (
  2171. /** @type {TemplateNode} */
  2172. /* @__PURE__ */ get_next_sibling(node)
  2173. );
  2174. dest.before(node);
  2175. node = next_node;
  2176. }
  2177. }
  2178. function link(state2, prev, next) {
  2179. if (prev === null) {
  2180. state2.first = next;
  2181. } else {
  2182. prev.next = next;
  2183. prev.e.next = next && next.e;
  2184. }
  2185. if (next !== null) {
  2186. next.prev = prev;
  2187. next.e.prev = prev && prev.e;
  2188. }
  2189. }
  2190. function snippet(node, get_snippet, ...args) {
  2191. var anchor = node;
  2192. var snippet2 = noop;
  2193. var snippet_effect;
  2194. block(() => {
  2195. if (snippet2 === (snippet2 = get_snippet())) return;
  2196. if (snippet_effect) {
  2197. destroy_effect(snippet_effect);
  2198. snippet_effect = null;
  2199. }
  2200. snippet_effect = branch(() => (
  2201. /** @type {SnippetFn} */
  2202. snippet2(anchor, ...args)
  2203. ));
  2204. }, EFFECT_TRANSPARENT);
  2205. }
  2206. function component(node, get_component, render_fn) {
  2207. var anchor = node;
  2208. var component2;
  2209. var effect2;
  2210. block(() => {
  2211. if (component2 === (component2 = get_component())) return;
  2212. if (effect2) {
  2213. pause_effect(effect2);
  2214. effect2 = null;
  2215. }
  2216. if (component2) {
  2217. effect2 = branch(() => render_fn(anchor, component2));
  2218. }
  2219. }, EFFECT_TRANSPARENT);
  2220. }
  2221. function attach(node, get_fn) {
  2222. var fn = void 0;
  2223. var e2;
  2224. block(() => {
  2225. if (fn !== (fn = get_fn())) {
  2226. if (e2) {
  2227. destroy_effect(e2);
  2228. e2 = null;
  2229. }
  2230. if (fn) {
  2231. e2 = branch(() => {
  2232. effect(() => (
  2233. /** @type {(node: Element) => void} */
  2234. fn(node)
  2235. ));
  2236. });
  2237. }
  2238. }
  2239. });
  2240. }
  2241. function r(e2) {
  2242. var t, f, n = "";
  2243. if ("string" == typeof e2 || "number" == typeof e2) n += e2;
  2244. else if ("object" == typeof e2) if (Array.isArray(e2)) {
  2245. var o2 = e2.length;
  2246. for (t = 0; t < o2; t++) e2[t] && (f = r(e2[t])) && (n && (n += " "), n += f);
  2247. } else for (f in e2) e2[f] && (n && (n += " "), n += f);
  2248. return n;
  2249. }
  2250. function clsx$1() {
  2251. for (var e2, t, f = 0, n = "", o2 = arguments.length; f < o2; f++) (e2 = arguments[f]) && (t = r(e2)) && (n && (n += " "), n += t);
  2252. return n;
  2253. }
  2254. function clsx(value) {
  2255. if (typeof value === "object") {
  2256. return clsx$1(value);
  2257. } else {
  2258. return value ?? "";
  2259. }
  2260. }
  2261. const whitespace = [..." \n\r\f \v\uFEFF"];
  2262. function to_class(value, hash, directives) {
  2263. var classname = value == null ? "" : "" + value;
  2264. if (hash) {
  2265. classname = classname ? classname + " " + hash : hash;
  2266. }
  2267. if (directives) {
  2268. for (var key in directives) {
  2269. if (directives[key]) {
  2270. classname = classname ? classname + " " + key : key;
  2271. } else if (classname.length) {
  2272. var len = key.length;
  2273. var a2 = 0;
  2274. while ((a2 = classname.indexOf(key, a2)) >= 0) {
  2275. var b = a2 + len;
  2276. if ((a2 === 0 || whitespace.includes(classname[a2 - 1])) && (b === classname.length || whitespace.includes(classname[b]))) {
  2277. classname = (a2 === 0 ? "" : classname.substring(0, a2)) + classname.substring(b + 1);
  2278. } else {
  2279. a2 = b;
  2280. }
  2281. }
  2282. }
  2283. }
  2284. }
  2285. return classname === "" ? null : classname;
  2286. }
  2287. function append_styles(styles, important = false) {
  2288. var separator = important ? " !important;" : ";";
  2289. var css = "";
  2290. for (var key in styles) {
  2291. var value = styles[key];
  2292. if (value != null && value !== "") {
  2293. css += " " + key + ": " + value + separator;
  2294. }
  2295. }
  2296. return css;
  2297. }
  2298. function to_css_name(name) {
  2299. if (name[0] !== "-" || name[1] !== "-") {
  2300. return name.toLowerCase();
  2301. }
  2302. return name;
  2303. }
  2304. function to_style(value, styles) {
  2305. if (styles) {
  2306. var new_style = "";
  2307. var normal_styles;
  2308. var important_styles;
  2309. if (Array.isArray(styles)) {
  2310. normal_styles = styles[0];
  2311. important_styles = styles[1];
  2312. } else {
  2313. normal_styles = styles;
  2314. }
  2315. if (value) {
  2316. value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
  2317. var in_str = false;
  2318. var in_apo = 0;
  2319. var in_comment = false;
  2320. var reserved_names = [];
  2321. if (normal_styles) {
  2322. reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
  2323. }
  2324. if (important_styles) {
  2325. reserved_names.push(...Object.keys(important_styles).map(to_css_name));
  2326. }
  2327. var start_index = 0;
  2328. var name_index = -1;
  2329. const len = value.length;
  2330. for (var i2 = 0; i2 < len; i2++) {
  2331. var c2 = value[i2];
  2332. if (in_comment) {
  2333. if (c2 === "/" && value[i2 - 1] === "*") {
  2334. in_comment = false;
  2335. }
  2336. } else if (in_str) {
  2337. if (in_str === c2) {
  2338. in_str = false;
  2339. }
  2340. } else if (c2 === "/" && value[i2 + 1] === "*") {
  2341. in_comment = true;
  2342. } else if (c2 === '"' || c2 === "'") {
  2343. in_str = c2;
  2344. } else if (c2 === "(") {
  2345. in_apo++;
  2346. } else if (c2 === ")") {
  2347. in_apo--;
  2348. }
  2349. if (!in_comment && in_str === false && in_apo === 0) {
  2350. if (c2 === ":" && name_index === -1) {
  2351. name_index = i2;
  2352. } else if (c2 === ";" || i2 === len - 1) {
  2353. if (name_index !== -1) {
  2354. var name = to_css_name(value.substring(start_index, name_index).trim());
  2355. if (!reserved_names.includes(name)) {
  2356. if (c2 !== ";") {
  2357. i2++;
  2358. }
  2359. var property = value.substring(start_index, i2).trim();
  2360. new_style += " " + property + ";";
  2361. }
  2362. }
  2363. start_index = i2 + 1;
  2364. name_index = -1;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. if (normal_styles) {
  2370. new_style += append_styles(normal_styles);
  2371. }
  2372. if (important_styles) {
  2373. new_style += append_styles(important_styles, true);
  2374. }
  2375. new_style = new_style.trim();
  2376. return new_style === "" ? null : new_style;
  2377. }
  2378. return value == null ? null : String(value);
  2379. }
  2380. function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
  2381. var prev = dom.__className;
  2382. if (prev !== value || prev === void 0) {
  2383. var next_class_name = to_class(value, hash, next_classes);
  2384. {
  2385. if (next_class_name == null) {
  2386. dom.removeAttribute("class");
  2387. } else if (is_html) {
  2388. dom.className = next_class_name;
  2389. } else {
  2390. dom.setAttribute("class", next_class_name);
  2391. }
  2392. }
  2393. dom.__className = value;
  2394. } else if (next_classes && prev_classes !== next_classes) {
  2395. for (var key in next_classes) {
  2396. var is_present = !!next_classes[key];
  2397. if (prev_classes == null || is_present !== !!prev_classes[key]) {
  2398. dom.classList.toggle(key, is_present);
  2399. }
  2400. }
  2401. }
  2402. return next_classes;
  2403. }
  2404. function update_styles(dom, prev = {}, next, priority) {
  2405. for (var key in next) {
  2406. var value = next[key];
  2407. if (prev[key] !== value) {
  2408. if (next[key] == null) {
  2409. dom.style.removeProperty(key);
  2410. } else {
  2411. dom.style.setProperty(key, value, priority);
  2412. }
  2413. }
  2414. }
  2415. }
  2416. function set_style(dom, value, prev_styles, next_styles) {
  2417. var prev = dom.__style;
  2418. if (prev !== value) {
  2419. var next_style_attr = to_style(value, next_styles);
  2420. {
  2421. if (next_style_attr == null) {
  2422. dom.removeAttribute("style");
  2423. } else {
  2424. dom.style.cssText = next_style_attr;
  2425. }
  2426. }
  2427. dom.__style = value;
  2428. } else if (next_styles) {
  2429. if (Array.isArray(next_styles)) {
  2430. update_styles(dom, prev_styles == null ? void 0 : prev_styles[0], next_styles[0]);
  2431. update_styles(dom, prev_styles == null ? void 0 : prev_styles[1], next_styles[1], "important");
  2432. } else {
  2433. update_styles(dom, prev_styles, next_styles);
  2434. }
  2435. }
  2436. return next_styles;
  2437. }
  2438. function select_option(select, value, mounting) {
  2439. if (select.multiple) {
  2440. if (value == void 0) {
  2441. return;
  2442. }
  2443. if (!is_array(value)) {
  2444. return select_multiple_invalid_value();
  2445. }
  2446. for (var option of select.options) {
  2447. option.selected = value.includes(get_option_value(option));
  2448. }
  2449. return;
  2450. }
  2451. for (option of select.options) {
  2452. var option_value = get_option_value(option);
  2453. if (is(option_value, value)) {
  2454. option.selected = true;
  2455. return;
  2456. }
  2457. }
  2458. if (!mounting || value !== void 0) {
  2459. select.selectedIndex = -1;
  2460. }
  2461. }
  2462. function init_select(select, get_value) {
  2463. let mounting = true;
  2464. effect(() => {
  2465. if (get_value) {
  2466. select_option(select, untrack(get_value), mounting);
  2467. }
  2468. mounting = false;
  2469. var observer = new MutationObserver(() => {
  2470. var value = select.__value;
  2471. select_option(select, value);
  2472. });
  2473. observer.observe(select, {
  2474. // Listen to option element changes
  2475. childList: true,
  2476. subtree: true,
  2477. // because of <optgroup>
  2478. // Listen to option element value attribute changes
  2479. // (doesn't get notified of select value changes,
  2480. // because that property is not reflected as an attribute)
  2481. attributes: true,
  2482. attributeFilter: ["value"]
  2483. });
  2484. return () => {
  2485. observer.disconnect();
  2486. };
  2487. });
  2488. }
  2489. function get_option_value(option) {
  2490. if ("__value" in option) {
  2491. return option.__value;
  2492. } else {
  2493. return option.value;
  2494. }
  2495. }
  2496. const CLASS = Symbol("class");
  2497. const STYLE = Symbol("style");
  2498. const IS_CUSTOM_ELEMENT = Symbol("is custom element");
  2499. const IS_HTML = Symbol("is html");
  2500. function set_selected(element, selected) {
  2501. if (selected) {
  2502. if (!element.hasAttribute("selected")) {
  2503. element.setAttribute("selected", "");
  2504. }
  2505. } else {
  2506. element.removeAttribute("selected");
  2507. }
  2508. }
  2509. function set_attribute(element, attribute, value, skip_warning) {
  2510. var attributes = get_attributes(element);
  2511. if (attributes[attribute] === (attributes[attribute] = value)) return;
  2512. if (attribute === "loading") {
  2513. element[LOADING_ATTR_SYMBOL] = value;
  2514. }
  2515. if (value == null) {
  2516. element.removeAttribute(attribute);
  2517. } else if (typeof value !== "string" && get_setters(element).includes(attribute)) {
  2518. element[attribute] = value;
  2519. } else {
  2520. element.setAttribute(attribute, value);
  2521. }
  2522. }
  2523. function set_attributes(element, prev, next, css_hash, skip_warning = false) {
  2524. var attributes = get_attributes(element);
  2525. var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
  2526. var preserve_attribute_case = !attributes[IS_HTML];
  2527. var current = prev || {};
  2528. var is_option_element = element.tagName === "OPTION";
  2529. for (var key in prev) {
  2530. if (!(key in next)) {
  2531. next[key] = null;
  2532. }
  2533. }
  2534. if (next.class) {
  2535. next.class = clsx(next.class);
  2536. } else if (css_hash || next[CLASS]) {
  2537. next.class = null;
  2538. }
  2539. if (next[STYLE]) {
  2540. next.style ?? (next.style = null);
  2541. }
  2542. var setters = get_setters(element);
  2543. for (const key2 in next) {
  2544. let value = next[key2];
  2545. if (is_option_element && key2 === "value" && value == null) {
  2546. element.value = element.__value = "";
  2547. current[key2] = value;
  2548. continue;
  2549. }
  2550. if (key2 === "class") {
  2551. var is_html = element.namespaceURI === "http://www.w3.org/1999/xhtml";
  2552. set_class(element, is_html, value, css_hash, prev == null ? void 0 : prev[CLASS], next[CLASS]);
  2553. current[key2] = value;
  2554. current[CLASS] = next[CLASS];
  2555. continue;
  2556. }
  2557. if (key2 === "style") {
  2558. set_style(element, value, prev == null ? void 0 : prev[STYLE], next[STYLE]);
  2559. current[key2] = value;
  2560. current[STYLE] = next[STYLE];
  2561. continue;
  2562. }
  2563. var prev_value = current[key2];
  2564. if (value === prev_value) continue;
  2565. current[key2] = value;
  2566. var prefix = key2[0] + key2[1];
  2567. if (prefix === "$$") continue;
  2568. if (prefix === "on") {
  2569. const opts = {};
  2570. const event_handle_key = "$$" + key2;
  2571. let event_name = key2.slice(2);
  2572. var delegated = is_delegated(event_name);
  2573. if (is_capture_event(event_name)) {
  2574. event_name = event_name.slice(0, -7);
  2575. opts.capture = true;
  2576. }
  2577. if (!delegated && prev_value) {
  2578. if (value != null) continue;
  2579. element.removeEventListener(event_name, current[event_handle_key], opts);
  2580. current[event_handle_key] = null;
  2581. }
  2582. if (value != null) {
  2583. if (!delegated) {
  2584. let handle = function(evt) {
  2585. current[key2].call(this, evt);
  2586. };
  2587. current[event_handle_key] = create_event(event_name, element, handle, opts);
  2588. } else {
  2589. element[`__${event_name}`] = value;
  2590. delegate([event_name]);
  2591. }
  2592. } else if (delegated) {
  2593. element[`__${event_name}`] = void 0;
  2594. }
  2595. } else if (key2 === "style") {
  2596. set_attribute(element, key2, value);
  2597. } else if (key2 === "autofocus") {
  2598. autofocus(
  2599. /** @type {HTMLElement} */
  2600. element,
  2601. Boolean(value)
  2602. );
  2603. } else if (!is_custom_element && (key2 === "__value" || key2 === "value" && value != null)) {
  2604. element.value = element.__value = value;
  2605. } else if (key2 === "selected" && is_option_element) {
  2606. set_selected(
  2607. /** @type {HTMLOptionElement} */
  2608. element,
  2609. value
  2610. );
  2611. } else {
  2612. var name = key2;
  2613. if (!preserve_attribute_case) {
  2614. name = normalize_attribute(name);
  2615. }
  2616. var is_default = name === "defaultValue" || name === "defaultChecked";
  2617. if (value == null && !is_custom_element && !is_default) {
  2618. attributes[key2] = null;
  2619. if (name === "value" || name === "checked") {
  2620. let input = (
  2621. /** @type {HTMLInputElement} */
  2622. element
  2623. );
  2624. const use_default = prev === void 0;
  2625. if (name === "value") {
  2626. let previous = input.defaultValue;
  2627. input.removeAttribute(name);
  2628. input.defaultValue = previous;
  2629. input.value = input.__value = use_default ? previous : null;
  2630. } else {
  2631. let previous = input.defaultChecked;
  2632. input.removeAttribute(name);
  2633. input.defaultChecked = previous;
  2634. input.checked = use_default ? previous : false;
  2635. }
  2636. } else {
  2637. element.removeAttribute(key2);
  2638. }
  2639. } else if (is_default || setters.includes(name) && (is_custom_element || typeof value !== "string")) {
  2640. element[name] = value;
  2641. } else if (typeof value !== "function") {
  2642. set_attribute(element, name, value);
  2643. }
  2644. }
  2645. }
  2646. return current;
  2647. }
  2648. function attribute_effect(element, fn, thunks = [], css_hash, skip_warning = false, d = derived$1) {
  2649. const deriveds = thunks.map(d);
  2650. var prev = void 0;
  2651. var effects = {};
  2652. var is_select = element.nodeName === "SELECT";
  2653. var inited = false;
  2654. block(() => {
  2655. var next = fn(...deriveds.map(get$1));
  2656. set_attributes(element, prev, next, css_hash, skip_warning);
  2657. if (inited && is_select) {
  2658. select_option(
  2659. /** @type {HTMLSelectElement} */
  2660. element,
  2661. next.value,
  2662. false
  2663. );
  2664. }
  2665. for (let symbol of Object.getOwnPropertySymbols(effects)) {
  2666. if (!next[symbol]) destroy_effect(effects[symbol]);
  2667. }
  2668. for (let symbol of Object.getOwnPropertySymbols(next)) {
  2669. var n = next[symbol];
  2670. if (symbol.description === ATTACHMENT_KEY && (!prev || n !== prev[symbol])) {
  2671. if (effects[symbol]) destroy_effect(effects[symbol]);
  2672. effects[symbol] = branch(() => attach(element, () => n));
  2673. }
  2674. }
  2675. prev = next;
  2676. });
  2677. if (is_select) {
  2678. init_select(
  2679. /** @type {HTMLSelectElement} */
  2680. element,
  2681. () => (
  2682. /** @type {Record<string | symbol, any>} */
  2683. prev.value
  2684. )
  2685. );
  2686. }
  2687. inited = true;
  2688. }
  2689. function get_attributes(element) {
  2690. return (
  2691. /** @type {Record<string | symbol, unknown>} **/
  2692. // @ts-expect-error
  2693. element.__attributes ?? (element.__attributes = {
  2694. [IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
  2695. [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
  2696. })
  2697. );
  2698. }
  2699. var setters_cache = /* @__PURE__ */ new Map();
  2700. function get_setters(element) {
  2701. var setters = setters_cache.get(element.nodeName);
  2702. if (setters) return setters;
  2703. setters_cache.set(element.nodeName, setters = []);
  2704. var descriptors;
  2705. var proto = element;
  2706. var element_proto = Element.prototype;
  2707. while (element_proto !== proto) {
  2708. descriptors = get_descriptors(proto);
  2709. for (var key in descriptors) {
  2710. if (descriptors[key].set) {
  2711. setters.push(key);
  2712. }
  2713. }
  2714. proto = get_prototype_of(proto);
  2715. }
  2716. return setters;
  2717. }
  2718. const _ResizeObserverSingleton = class _ResizeObserverSingleton {
  2719. /** @param {ResizeObserverOptions} options */
  2720. constructor(options) {
  2721. __privateAdd(this, _ResizeObserverSingleton_instances);
  2722. /** */
  2723. __privateAdd(this, _listeners, /* @__PURE__ */ new WeakMap());
  2724. /** @type {ResizeObserver | undefined} */
  2725. __privateAdd(this, _observer);
  2726. /** @type {ResizeObserverOptions} */
  2727. __privateAdd(this, _options);
  2728. __privateSet(this, _options, options);
  2729. }
  2730. /**
  2731. * @param {Element} element
  2732. * @param {(entry: ResizeObserverEntry) => any} listener
  2733. */
  2734. observe(element, listener) {
  2735. var listeners = __privateGet(this, _listeners).get(element) || /* @__PURE__ */ new Set();
  2736. listeners.add(listener);
  2737. __privateGet(this, _listeners).set(element, listeners);
  2738. __privateMethod(this, _ResizeObserverSingleton_instances, getObserver_fn).call(this).observe(element, __privateGet(this, _options));
  2739. return () => {
  2740. var listeners2 = __privateGet(this, _listeners).get(element);
  2741. listeners2.delete(listener);
  2742. if (listeners2.size === 0) {
  2743. __privateGet(this, _listeners).delete(element);
  2744. __privateGet(this, _observer).unobserve(element);
  2745. }
  2746. };
  2747. }
  2748. };
  2749. _listeners = new WeakMap();
  2750. _observer = new WeakMap();
  2751. _options = new WeakMap();
  2752. _ResizeObserverSingleton_instances = new WeakSet();
  2753. getObserver_fn = function() {
  2754. return __privateGet(this, _observer) ?? __privateSet(this, _observer, new ResizeObserver(
  2755. /** @param {any} entries */
  2756. (entries) => {
  2757. for (var entry of entries) {
  2758. _ResizeObserverSingleton.entries.set(entry.target, entry);
  2759. for (var listener of __privateGet(this, _listeners).get(entry.target) || []) {
  2760. listener(entry);
  2761. }
  2762. }
  2763. }
  2764. ));
  2765. };
  2766. /** @static */
  2767. __publicField(_ResizeObserverSingleton, "entries", /* @__PURE__ */ new WeakMap());
  2768. let ResizeObserverSingleton = _ResizeObserverSingleton;
  2769. var resize_observer_border_box = /* @__PURE__ */ new ResizeObserverSingleton({
  2770. box: "border-box"
  2771. });
  2772. function bind_element_size(element, type, set2) {
  2773. var unsub = resize_observer_border_box.observe(element, () => set2(element[type]));
  2774. effect(() => {
  2775. untrack(() => set2(element[type]));
  2776. return unsub;
  2777. });
  2778. }
  2779. function init(immutable = false) {
  2780. const context = (
  2781. /** @type {ComponentContextLegacy} */
  2782. component_context
  2783. );
  2784. const callbacks = context.l.u;
  2785. if (!callbacks) return;
  2786. let props = () => deep_read_state(context.s);
  2787. if (immutable) {
  2788. let version = 0;
  2789. let prev = (
  2790. /** @type {Record<string, any>} */
  2791. {}
  2792. );
  2793. const d = /* @__PURE__ */ derived$1(() => {
  2794. let changed = false;
  2795. const props2 = context.s;
  2796. for (const key in props2) {
  2797. if (props2[key] !== prev[key]) {
  2798. prev[key] = props2[key];
  2799. changed = true;
  2800. }
  2801. }
  2802. if (changed) version++;
  2803. return version;
  2804. });
  2805. props = () => get$1(d);
  2806. }
  2807. if (callbacks.b.length) {
  2808. user_pre_effect(() => {
  2809. observe_all(context, props);
  2810. run_all(callbacks.b);
  2811. });
  2812. }
  2813. user_effect(() => {
  2814. const fns = untrack(() => callbacks.m.map(run));
  2815. return () => {
  2816. for (const fn of fns) {
  2817. if (typeof fn === "function") {
  2818. fn();
  2819. }
  2820. }
  2821. };
  2822. });
  2823. if (callbacks.a.length) {
  2824. user_effect(() => {
  2825. observe_all(context, props);
  2826. run_all(callbacks.a);
  2827. });
  2828. }
  2829. }
  2830. function observe_all(context, props) {
  2831. if (context.l.s) {
  2832. for (const signal of context.l.s) get$1(signal);
  2833. }
  2834. props();
  2835. }
  2836. function subscribe_to_store(store, run2, invalidate) {
  2837. if (store == null) {
  2838. run2(void 0);
  2839. if (invalidate) invalidate(void 0);
  2840. return noop;
  2841. }
  2842. const unsub = untrack(
  2843. () => store.subscribe(
  2844. run2,
  2845. // @ts-expect-error
  2846. invalidate
  2847. )
  2848. );
  2849. return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
  2850. }
  2851. const subscriber_queue = [];
  2852. function readable(value, start) {
  2853. return {
  2854. subscribe: writable(value, start).subscribe
  2855. };
  2856. }
  2857. function writable(value, start = noop) {
  2858. let stop = null;
  2859. const subscribers = /* @__PURE__ */ new Set();
  2860. function set2(new_value) {
  2861. if (safe_not_equal(value, new_value)) {
  2862. value = new_value;
  2863. if (stop) {
  2864. const run_queue = !subscriber_queue.length;
  2865. for (const subscriber of subscribers) {
  2866. subscriber[1]();
  2867. subscriber_queue.push(subscriber, value);
  2868. }
  2869. if (run_queue) {
  2870. for (let i2 = 0; i2 < subscriber_queue.length; i2 += 2) {
  2871. subscriber_queue[i2][0](subscriber_queue[i2 + 1]);
  2872. }
  2873. subscriber_queue.length = 0;
  2874. }
  2875. }
  2876. }
  2877. }
  2878. function update2(fn) {
  2879. set2(fn(
  2880. /** @type {T} */
  2881. value
  2882. ));
  2883. }
  2884. function subscribe(run2, invalidate = noop) {
  2885. const subscriber = [run2, invalidate];
  2886. subscribers.add(subscriber);
  2887. if (subscribers.size === 1) {
  2888. stop = start(set2, update2) || noop;
  2889. }
  2890. run2(
  2891. /** @type {T} */
  2892. value
  2893. );
  2894. return () => {
  2895. subscribers.delete(subscriber);
  2896. if (subscribers.size === 0 && stop) {
  2897. stop();
  2898. stop = null;
  2899. }
  2900. };
  2901. }
  2902. return { set: set2, update: update2, subscribe };
  2903. }
  2904. function derived(stores, fn, initial_value) {
  2905. const single = !Array.isArray(stores);
  2906. const stores_array = single ? [stores] : stores;
  2907. if (!stores_array.every(Boolean)) {
  2908. throw new Error("derived() expects stores as input, got a falsy value");
  2909. }
  2910. const auto = fn.length < 2;
  2911. return readable(initial_value, (set2, update2) => {
  2912. let started = false;
  2913. const values = [];
  2914. let pending = 0;
  2915. let cleanup = noop;
  2916. const sync = () => {
  2917. if (pending) {
  2918. return;
  2919. }
  2920. cleanup();
  2921. const result = fn(single ? values[0] : values, set2, update2);
  2922. if (auto) {
  2923. set2(result);
  2924. } else {
  2925. cleanup = typeof result === "function" ? result : noop;
  2926. }
  2927. };
  2928. const unsubscribers = stores_array.map(
  2929. (store, i2) => subscribe_to_store(
  2930. store,
  2931. (value) => {
  2932. values[i2] = value;
  2933. pending &= ~(1 << i2);
  2934. if (started) {
  2935. sync();
  2936. }
  2937. },
  2938. () => {
  2939. pending |= 1 << i2;
  2940. }
  2941. )
  2942. );
  2943. started = true;
  2944. sync();
  2945. return function stop() {
  2946. run_all(unsubscribers);
  2947. cleanup();
  2948. started = false;
  2949. };
  2950. });
  2951. }
  2952. function get(store) {
  2953. let value;
  2954. subscribe_to_store(store, (_) => value = _)();
  2955. return value;
  2956. }
  2957. let IS_UNMOUNTED = Symbol();
  2958. function store_get(store, store_name, stores) {
  2959. const entry = stores[store_name] ?? (stores[store_name] = {
  2960. store: null,
  2961. source: /* @__PURE__ */ mutable_source(void 0),
  2962. unsubscribe: noop
  2963. });
  2964. if (entry.store !== store && !(IS_UNMOUNTED in stores)) {
  2965. entry.unsubscribe();
  2966. entry.store = store ?? null;
  2967. if (store == null) {
  2968. entry.source.v = void 0;
  2969. entry.unsubscribe = noop;
  2970. } else {
  2971. var is_synchronous_callback = true;
  2972. entry.unsubscribe = subscribe_to_store(store, (v2) => {
  2973. if (is_synchronous_callback) {
  2974. entry.source.v = v2;
  2975. } else {
  2976. set(entry.source, v2);
  2977. }
  2978. });
  2979. is_synchronous_callback = false;
  2980. }
  2981. }
  2982. if (store && IS_UNMOUNTED in stores) {
  2983. return get(store);
  2984. }
  2985. return get$1(entry.source);
  2986. }
  2987. function setup_stores() {
  2988. const stores = {};
  2989. function cleanup() {
  2990. teardown(() => {
  2991. for (var store_name in stores) {
  2992. const ref = stores[store_name];
  2993. ref.unsubscribe();
  2994. }
  2995. define_property(stores, IS_UNMOUNTED, {
  2996. enumerable: false,
  2997. value: true
  2998. });
  2999. });
  3000. }
  3001. return [stores, cleanup];
  3002. }
  3003. const rest_props_handler = {
  3004. get(target, key) {
  3005. if (target.exclude.includes(key)) return;
  3006. return target.props[key];
  3007. },
  3008. set(target, key) {
  3009. return false;
  3010. },
  3011. getOwnPropertyDescriptor(target, key) {
  3012. if (target.exclude.includes(key)) return;
  3013. if (key in target.props) {
  3014. return {
  3015. enumerable: true,
  3016. configurable: true,
  3017. value: target.props[key]
  3018. };
  3019. }
  3020. },
  3021. has(target, key) {
  3022. if (target.exclude.includes(key)) return false;
  3023. return key in target.props;
  3024. },
  3025. ownKeys(target) {
  3026. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  3027. }
  3028. };
  3029. // @__NO_SIDE_EFFECTS__
  3030. function rest_props(props, exclude, name) {
  3031. return new Proxy(
  3032. { props, exclude },
  3033. rest_props_handler
  3034. );
  3035. }
  3036. const spread_props_handler = {
  3037. get(target, key) {
  3038. let i2 = target.props.length;
  3039. while (i2--) {
  3040. let p = target.props[i2];
  3041. if (is_function(p)) p = p();
  3042. if (typeof p === "object" && p !== null && key in p) return p[key];
  3043. }
  3044. },
  3045. set(target, key, value) {
  3046. let i2 = target.props.length;
  3047. while (i2--) {
  3048. let p = target.props[i2];
  3049. if (is_function(p)) p = p();
  3050. const desc = get_descriptor(p, key);
  3051. if (desc && desc.set) {
  3052. desc.set(value);
  3053. return true;
  3054. }
  3055. }
  3056. return false;
  3057. },
  3058. getOwnPropertyDescriptor(target, key) {
  3059. let i2 = target.props.length;
  3060. while (i2--) {
  3061. let p = target.props[i2];
  3062. if (is_function(p)) p = p();
  3063. if (typeof p === "object" && p !== null && key in p) {
  3064. const descriptor = get_descriptor(p, key);
  3065. if (descriptor && !descriptor.configurable) {
  3066. descriptor.configurable = true;
  3067. }
  3068. return descriptor;
  3069. }
  3070. }
  3071. },
  3072. has(target, key) {
  3073. if (key === STATE_SYMBOL || key === LEGACY_PROPS) return false;
  3074. for (let p of target.props) {
  3075. if (is_function(p)) p = p();
  3076. if (p != null && key in p) return true;
  3077. }
  3078. return false;
  3079. },
  3080. ownKeys(target) {
  3081. const keys = [];
  3082. for (let p of target.props) {
  3083. if (is_function(p)) p = p();
  3084. if (!p) continue;
  3085. for (const key in p) {
  3086. if (!keys.includes(key)) keys.push(key);
  3087. }
  3088. for (const key of Object.getOwnPropertySymbols(p)) {
  3089. if (!keys.includes(key)) keys.push(key);
  3090. }
  3091. }
  3092. return keys;
  3093. }
  3094. };
  3095. function spread_props(...props) {
  3096. return new Proxy({ props }, spread_props_handler);
  3097. }
  3098. function prop(props, key, flags, fallback) {
  3099. var prop_value;
  3100. {
  3101. prop_value = /** @type {V} */
  3102. props[key];
  3103. }
  3104. var fallback_value = (
  3105. /** @type {V} */
  3106. fallback
  3107. );
  3108. var fallback_dirty = true;
  3109. var get_fallback = () => {
  3110. if (fallback_dirty) {
  3111. fallback_dirty = false;
  3112. {
  3113. fallback_value = /** @type {V} */
  3114. fallback;
  3115. }
  3116. }
  3117. return fallback_value;
  3118. };
  3119. if (prop_value === void 0 && fallback !== void 0) {
  3120. prop_value = get_fallback();
  3121. }
  3122. var getter;
  3123. {
  3124. getter = () => {
  3125. var value = (
  3126. /** @type {V} */
  3127. props[key]
  3128. );
  3129. if (value === void 0) return get_fallback();
  3130. fallback_dirty = true;
  3131. return value;
  3132. };
  3133. }
  3134. {
  3135. return getter;
  3136. }
  3137. }
  3138. function onMount(fn) {
  3139. if (component_context === null) {
  3140. lifecycle_outside_component();
  3141. }
  3142. if (legacy_mode_flag && component_context.l !== null) {
  3143. init_update_callbacks(component_context).m.push(fn);
  3144. } else {
  3145. user_effect(() => {
  3146. const cleanup = untrack(fn);
  3147. if (typeof cleanup === "function") return (
  3148. /** @type {() => void} */
  3149. cleanup
  3150. );
  3151. });
  3152. }
  3153. }
  3154. function onDestroy(fn) {
  3155. if (component_context === null) {
  3156. lifecycle_outside_component();
  3157. }
  3158. onMount(() => () => untrack(fn));
  3159. }
  3160. function init_update_callbacks(context) {
  3161. var l = (
  3162. /** @type {ComponentContextLegacy} */
  3163. context.l
  3164. );
  3165. return l.u ?? (l.u = { a: [], b: [], m: [] });
  3166. }
  3167. function writableDerived(origins, derive, reflect, initial) {
  3168. var childDerivedSetter, originValues, blockNextDerive = false;
  3169. var reflectOldValues = reflect.length >= 2;
  3170. var wrappedDerive = (got, set2, update3) => {
  3171. childDerivedSetter = set2;
  3172. if (reflectOldValues) {
  3173. originValues = got;
  3174. }
  3175. if (!blockNextDerive) {
  3176. let returned = derive(got, set2, update3);
  3177. if (derive.length < 2) {
  3178. set2(returned);
  3179. } else {
  3180. return returned;
  3181. }
  3182. }
  3183. blockNextDerive = false;
  3184. };
  3185. var childDerived = derived(origins, wrappedDerive, initial);
  3186. var singleOrigin = !Array.isArray(origins);
  3187. function doReflect(reflecting) {
  3188. var setWith = reflect(reflecting, originValues);
  3189. if (singleOrigin) {
  3190. blockNextDerive = true;
  3191. origins.set(setWith);
  3192. } else {
  3193. setWith.forEach((value, i2) => {
  3194. blockNextDerive = true;
  3195. origins[i2].set(value);
  3196. });
  3197. }
  3198. blockNextDerive = false;
  3199. }
  3200. var tryingSet = false;
  3201. function update2(fn) {
  3202. var isUpdated, mutatedBySubscriptions, oldValue, newValue;
  3203. if (tryingSet) {
  3204. newValue = fn(get(childDerived));
  3205. childDerivedSetter(newValue);
  3206. return;
  3207. }
  3208. var unsubscribe = childDerived.subscribe((value) => {
  3209. if (!tryingSet) {
  3210. oldValue = value;
  3211. } else if (!isUpdated) {
  3212. isUpdated = true;
  3213. } else {
  3214. mutatedBySubscriptions = true;
  3215. }
  3216. });
  3217. newValue = fn(oldValue);
  3218. tryingSet = true;
  3219. childDerivedSetter(newValue);
  3220. unsubscribe();
  3221. tryingSet = false;
  3222. if (mutatedBySubscriptions) {
  3223. newValue = get(childDerived);
  3224. }
  3225. if (isUpdated) {
  3226. doReflect(newValue);
  3227. }
  3228. }
  3229. return {
  3230. subscribe: childDerived.subscribe,
  3231. set(value) {
  3232. update2(() => value);
  3233. },
  3234. update: update2
  3235. };
  3236. }
  3237. const TOAST_LIMIT = 20;
  3238. const toasts = writable([]);
  3239. const pausedAt = writable(null);
  3240. const toastTimeouts = /* @__PURE__ */ new Map();
  3241. const addToRemoveQueue = (toastId) => {
  3242. if (toastTimeouts.has(toastId)) {
  3243. return;
  3244. }
  3245. const timeout = setTimeout(() => {
  3246. toastTimeouts.delete(toastId);
  3247. remove(toastId);
  3248. }, 1e3);
  3249. toastTimeouts.set(toastId, timeout);
  3250. };
  3251. const clearFromRemoveQueue = (toastId) => {
  3252. const timeout = toastTimeouts.get(toastId);
  3253. if (timeout) {
  3254. clearTimeout(timeout);
  3255. }
  3256. };
  3257. function update(toast2, clearTimeout2 = true) {
  3258. if (clearTimeout2 && toast2.id) {
  3259. clearFromRemoveQueue(toast2.id);
  3260. }
  3261. toasts.update(($toasts) => $toasts.map((t) => t.id === toast2.id ? { ...t, ...toast2 } : t));
  3262. }
  3263. function add(toast2) {
  3264. toasts.update(($toasts) => [toast2, ...$toasts].slice(0, TOAST_LIMIT));
  3265. }
  3266. function upsert(toast2) {
  3267. if (get(toasts).find((t) => t.id === toast2.id)) {
  3268. update(toast2);
  3269. } else {
  3270. add(toast2);
  3271. }
  3272. }
  3273. function dismiss(toastId) {
  3274. toasts.update(($toasts) => {
  3275. if (toastId) {
  3276. addToRemoveQueue(toastId);
  3277. } else {
  3278. $toasts.forEach((toast2) => {
  3279. addToRemoveQueue(toast2.id);
  3280. });
  3281. }
  3282. return $toasts.map((t) => t.id === toastId || toastId === void 0 ? { ...t, visible: false } : t);
  3283. });
  3284. }
  3285. function remove(toastId) {
  3286. toasts.update(($toasts) => {
  3287. if (toastId === void 0) {
  3288. return [];
  3289. }
  3290. return $toasts.filter((t) => t.id !== toastId);
  3291. });
  3292. }
  3293. function startPause(time) {
  3294. pausedAt.set(time);
  3295. }
  3296. function endPause(time) {
  3297. let diff;
  3298. pausedAt.update(($pausedAt) => {
  3299. diff = time - ($pausedAt || 0);
  3300. return null;
  3301. });
  3302. toasts.update(($toasts) => $toasts.map((t) => ({
  3303. ...t,
  3304. pauseDuration: t.pauseDuration + diff
  3305. })));
  3306. }
  3307. const defaultTimeouts = {
  3308. blank: 4e3,
  3309. error: 4e3,
  3310. success: 2e3,
  3311. loading: Infinity,
  3312. custom: 4e3
  3313. };
  3314. function useToasterStore(toastOptions = {}) {
  3315. const mergedToasts = writableDerived(toasts, ($toasts) => $toasts.map((t) => {
  3316. var _a2, _b;
  3317. return {
  3318. ...toastOptions,
  3319. ...toastOptions[t.type],
  3320. ...t,
  3321. duration: t.duration || ((_a2 = toastOptions[t.type]) == null ? void 0 : _a2.duration) || (toastOptions == null ? void 0 : toastOptions.duration) || defaultTimeouts[t.type],
  3322. style: [toastOptions.style, (_b = toastOptions[t.type]) == null ? void 0 : _b.style, t.style].join(";")
  3323. };
  3324. }), ($toasts) => $toasts);
  3325. return {
  3326. toasts: mergedToasts,
  3327. pausedAt
  3328. };
  3329. }
  3330. const isFunction = (valOrFunction) => typeof valOrFunction === "function";
  3331. const resolveValue = (valOrFunction, arg) => isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction;
  3332. const genId = /* @__PURE__ */ (() => {
  3333. let count = 0;
  3334. return () => {
  3335. count += 1;
  3336. return count.toString();
  3337. };
  3338. })();
  3339. const prefersReducedMotion = /* @__PURE__ */ (() => {
  3340. let shouldReduceMotion;
  3341. return () => {
  3342. if (shouldReduceMotion === void 0 && typeof window !== "undefined") {
  3343. const mediaQuery = matchMedia("(prefers-reduced-motion: reduce)");
  3344. shouldReduceMotion = !mediaQuery || mediaQuery.matches;
  3345. }
  3346. return shouldReduceMotion;
  3347. };
  3348. })();
  3349. const createToast = (message, type = "blank", opts) => ({
  3350. createdAt: Date.now(),
  3351. visible: true,
  3352. type,
  3353. ariaProps: {
  3354. role: "status",
  3355. "aria-live": "polite"
  3356. },
  3357. message,
  3358. pauseDuration: 0,
  3359. icon: opts == null ? void 0 : opts.icon,
  3360. duration: opts == null ? void 0 : opts.duration,
  3361. iconTheme: opts == null ? void 0 : opts.iconTheme,
  3362. position: opts == null ? void 0 : opts.position,
  3363. props: opts == null ? void 0 : opts.props,
  3364. id: (opts == null ? void 0 : opts.id) || genId()
  3365. });
  3366. const createHandler = (type) => (message, options) => {
  3367. const toast2 = createToast(message, type, options);
  3368. upsert(toast2);
  3369. return toast2.id;
  3370. };
  3371. const toast$1 = (message, opts) => createHandler("blank")(message, opts);
  3372. toast$1.error = createHandler("error");
  3373. toast$1.success = createHandler("success");
  3374. toast$1.loading = createHandler("loading");
  3375. toast$1.custom = createHandler("custom");
  3376. toast$1.dismiss = (toastId) => {
  3377. dismiss(toastId);
  3378. };
  3379. toast$1.remove = (toastId) => remove(toastId);
  3380. toast$1.promise = (promise, msgs, opts) => {
  3381. const id = toast$1.loading(msgs.loading, { ...opts, ...opts == null ? void 0 : opts.loading });
  3382. promise.then((p) => {
  3383. toast$1.success(resolveValue(msgs.success, p), {
  3384. id,
  3385. ...opts,
  3386. ...opts == null ? void 0 : opts.success
  3387. });
  3388. return p;
  3389. }).catch((e2) => {
  3390. toast$1.error(resolveValue(msgs.error, e2), {
  3391. id,
  3392. ...opts,
  3393. ...opts == null ? void 0 : opts.error
  3394. });
  3395. });
  3396. return promise;
  3397. };
  3398. function calculateOffset(toast2, $toasts, opts) {
  3399. const { reverseOrder, gutter = 8, defaultPosition } = opts || {};
  3400. const relevantToasts = $toasts.filter((t) => (t.position || defaultPosition) === (toast2.position || defaultPosition) && t.height);
  3401. const toastIndex = relevantToasts.findIndex((t) => t.id === toast2.id);
  3402. const toastsBefore = relevantToasts.filter((toast3, i2) => i2 < toastIndex && toast3.visible).length;
  3403. const offset = relevantToasts.filter((t) => t.visible).slice(...reverseOrder ? [toastsBefore + 1] : [0, toastsBefore]).reduce((acc, t) => acc + (t.height || 0) + gutter, 0);
  3404. return offset;
  3405. }
  3406. const handlers = {
  3407. startPause() {
  3408. startPause(Date.now());
  3409. },
  3410. endPause() {
  3411. endPause(Date.now());
  3412. },
  3413. updateHeight: (toastId, height) => {
  3414. update({ id: toastId, height }, false);
  3415. },
  3416. calculateOffset
  3417. };
  3418. function useToaster(toastOptions) {
  3419. const { toasts: toasts2, pausedAt: pausedAt2 } = useToasterStore(toastOptions);
  3420. const timeouts = /* @__PURE__ */ new Map();
  3421. let _pausedAt;
  3422. const unsubscribes = [
  3423. pausedAt2.subscribe(($pausedAt) => {
  3424. if ($pausedAt) {
  3425. for (const [, timeoutId] of timeouts) {
  3426. clearTimeout(timeoutId);
  3427. }
  3428. timeouts.clear();
  3429. }
  3430. _pausedAt = $pausedAt;
  3431. }),
  3432. toasts2.subscribe(($toasts) => {
  3433. if (_pausedAt) {
  3434. return;
  3435. }
  3436. const now = Date.now();
  3437. for (const t of $toasts) {
  3438. if (timeouts.has(t.id)) {
  3439. continue;
  3440. }
  3441. if (t.duration === Infinity) {
  3442. continue;
  3443. }
  3444. const durationLeft = (t.duration || 0) + t.pauseDuration - (now - t.createdAt);
  3445. if (durationLeft < 0) {
  3446. if (t.visible) {
  3447. toast$1.dismiss(t.id);
  3448. }
  3449. return null;
  3450. }
  3451. timeouts.set(t.id, setTimeout(() => toast$1.dismiss(t.id), durationLeft));
  3452. }
  3453. })
  3454. ];
  3455. onDestroy(() => {
  3456. for (const unsubscribe of unsubscribes) {
  3457. unsubscribe();
  3458. }
  3459. });
  3460. return { toasts: toasts2, handlers };
  3461. }
  3462. const PUBLIC_VERSION = "5";
  3463. if (typeof window !== "undefined") {
  3464. ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
  3465. }
  3466. var root$7 = /* @__PURE__ */ from_html(`<div class="svelte-11kvm4p"></div>`);
  3467. function CheckmarkIcon($$anchor, $$props) {
  3468. let primary = prop($$props, "primary", 3, "#61d345"), secondary = prop($$props, "secondary", 3, "#fff");
  3469. var div = root$7();
  3470. let styles;
  3471. template_effect(() => styles = set_style(div, "", styles, {
  3472. "--primary": primary(),
  3473. "--secondary": secondary()
  3474. }));
  3475. append($$anchor, div);
  3476. }
  3477. var root$6 = /* @__PURE__ */ from_html(`<div class="svelte-1ee93ns"></div>`);
  3478. function ErrorIcon($$anchor, $$props) {
  3479. let primary = prop($$props, "primary", 3, "#ff4b4b"), secondary = prop($$props, "secondary", 3, "#fff");
  3480. var div = root$6();
  3481. let styles;
  3482. template_effect(() => styles = set_style(div, "", styles, {
  3483. "--primary": primary(),
  3484. "--secondary": secondary()
  3485. }));
  3486. append($$anchor, div);
  3487. }
  3488. var root$5 = /* @__PURE__ */ from_html(`<div class="svelte-1j7dflg"></div>`);
  3489. function LoaderIcon($$anchor, $$props) {
  3490. let primary = prop($$props, "primary", 3, "#616161"), secondary = prop($$props, "secondary", 3, "#e0e0e0");
  3491. var div = root$5();
  3492. let styles;
  3493. template_effect(() => styles = set_style(div, "", styles, {
  3494. "--primary": primary(),
  3495. "--secondary": secondary()
  3496. }));
  3497. append($$anchor, div);
  3498. }
  3499. var root_1$4 = /* @__PURE__ */ from_html(`<div class="animated svelte-1kgeier"> </div>`);
  3500. var root_6$1 = /* @__PURE__ */ from_html(`<div class="status svelte-1kgeier"><!></div>`);
  3501. var root_5 = /* @__PURE__ */ from_html(`<div class="indicator svelte-1kgeier"><!> <!></div>`);
  3502. function ToastIcon($$anchor, $$props) {
  3503. let type = /* @__PURE__ */ user_derived(() => $$props.toast.type), icon = /* @__PURE__ */ user_derived(() => $$props.toast.icon), iconTheme = /* @__PURE__ */ user_derived(() => $$props.toast.iconTheme);
  3504. var fragment = comment();
  3505. var node = first_child(fragment);
  3506. {
  3507. var consequent = ($$anchor2) => {
  3508. var div = root_1$4();
  3509. var text2 = child(div);
  3510. template_effect(() => set_text(text2, get$1(icon)));
  3511. append($$anchor2, div);
  3512. };
  3513. var alternate = ($$anchor2, $$elseif) => {
  3514. {
  3515. var consequent_1 = ($$anchor3) => {
  3516. var fragment_1 = comment();
  3517. const IconComponent = /* @__PURE__ */ user_derived(() => get$1(icon));
  3518. var node_1 = first_child(fragment_1);
  3519. component(node_1, () => get$1(IconComponent), ($$anchor4, $$component) => {
  3520. $$component($$anchor4, {});
  3521. });
  3522. append($$anchor3, fragment_1);
  3523. };
  3524. var alternate_1 = ($$anchor3, $$elseif2) => {
  3525. {
  3526. var consequent_4 = ($$anchor4) => {
  3527. var div_1 = root_5();
  3528. var node_2 = child(div_1);
  3529. LoaderIcon(node_2, spread_props(() => get$1(iconTheme)));
  3530. var node_3 = sibling(node_2, 2);
  3531. {
  3532. var consequent_3 = ($$anchor5) => {
  3533. var div_2 = root_6$1();
  3534. var node_4 = child(div_2);
  3535. {
  3536. var consequent_2 = ($$anchor6) => {
  3537. ErrorIcon($$anchor6, spread_props(() => get$1(iconTheme)));
  3538. };
  3539. var alternate_2 = ($$anchor6) => {
  3540. CheckmarkIcon($$anchor6, spread_props(() => get$1(iconTheme)));
  3541. };
  3542. if_block(node_4, ($$render) => {
  3543. if (get$1(type) === "error") $$render(consequent_2);
  3544. else $$render(alternate_2, false);
  3545. });
  3546. }
  3547. append($$anchor5, div_2);
  3548. };
  3549. if_block(node_3, ($$render) => {
  3550. if (get$1(type) !== "loading") $$render(consequent_3);
  3551. });
  3552. }
  3553. append($$anchor4, div_1);
  3554. };
  3555. if_block(
  3556. $$anchor3,
  3557. ($$render) => {
  3558. if (get$1(type) !== "blank") $$render(consequent_4);
  3559. },
  3560. $$elseif2
  3561. );
  3562. }
  3563. };
  3564. if_block(
  3565. $$anchor2,
  3566. ($$render) => {
  3567. if (typeof get$1(icon) !== "undefined") $$render(consequent_1);
  3568. else $$render(alternate_1, false);
  3569. },
  3570. $$elseif
  3571. );
  3572. }
  3573. };
  3574. if_block(node, ($$render) => {
  3575. if (typeof get$1(icon) === "string") $$render(consequent);
  3576. else $$render(alternate, false);
  3577. });
  3578. }
  3579. append($$anchor, fragment);
  3580. }
  3581. var root$4 = /* @__PURE__ */ from_html(`<div><!></div>`);
  3582. function ToastMessage($$anchor, $$props) {
  3583. push($$props, true);
  3584. var div = root$4();
  3585. attribute_effect(div, () => ({ class: "message", ...$$props.toast.ariaProps }), void 0, "svelte-1nauejd");
  3586. var node = child(div);
  3587. {
  3588. var consequent = ($$anchor2) => {
  3589. var text$1 = text();
  3590. template_effect(() => set_text(text$1, $$props.toast.message));
  3591. append($$anchor2, text$1);
  3592. };
  3593. var alternate = ($$anchor2) => {
  3594. var fragment_1 = comment();
  3595. const Message = /* @__PURE__ */ user_derived(() => $$props.toast.message);
  3596. var node_1 = first_child(fragment_1);
  3597. component(node_1, () => get$1(Message), ($$anchor3, $$component) => {
  3598. $$component($$anchor3, spread_props(
  3599. {
  3600. get toast() {
  3601. return $$props.toast;
  3602. }
  3603. },
  3604. () => $$props.toast.props
  3605. ));
  3606. });
  3607. append($$anchor2, fragment_1);
  3608. };
  3609. if_block(node, ($$render) => {
  3610. if (typeof $$props.toast.message === "string") $$render(consequent);
  3611. else $$render(alternate, false);
  3612. });
  3613. }
  3614. append($$anchor, div);
  3615. pop();
  3616. }
  3617. var root_6 = /* @__PURE__ */ from_html(`<!> <!>`, 1);
  3618. var root$3 = /* @__PURE__ */ from_html(`<div><!></div>`);
  3619. function ToastBar($$anchor, $$props) {
  3620. push($$props, true);
  3621. let position = prop($$props, "position", 3, void 0), style = prop($$props, "style", 3, ""), Component = prop($$props, "Component", 3, void 0);
  3622. let factor = /* @__PURE__ */ user_derived(() => {
  3623. const top = ($$props.toast.position || position() || "top-center").includes("top");
  3624. return top ? 1 : -1;
  3625. });
  3626. let animation = /* @__PURE__ */ user_derived(() => {
  3627. const [enter, exit] = prefersReducedMotion() ? ["fadeIn", "fadeOut"] : ["enter", "exit"];
  3628. return $$props.toast.visible ? enter : exit;
  3629. });
  3630. var div = root$3();
  3631. let styles;
  3632. var node = child(div);
  3633. {
  3634. var consequent = ($$anchor2) => {
  3635. var fragment = comment();
  3636. var node_1 = first_child(fragment);
  3637. component(node_1, Component, ($$anchor3, $$component) => {
  3638. {
  3639. const icon = ($$anchor4) => {
  3640. ToastIcon($$anchor4, {
  3641. get toast() {
  3642. return $$props.toast;
  3643. }
  3644. });
  3645. };
  3646. const message = ($$anchor4) => {
  3647. ToastMessage($$anchor4, {
  3648. get toast() {
  3649. return $$props.toast;
  3650. }
  3651. });
  3652. };
  3653. $$component($$anchor3, {
  3654. icon,
  3655. message,
  3656. $$slots: { icon: true, message: true }
  3657. });
  3658. }
  3659. });
  3660. append($$anchor2, fragment);
  3661. };
  3662. var alternate = ($$anchor2, $$elseif) => {
  3663. {
  3664. var consequent_1 = ($$anchor3) => {
  3665. var fragment_3 = comment();
  3666. var node_2 = first_child(fragment_3);
  3667. snippet(node_2, () => $$props.children, () => ({
  3668. ToastIcon,
  3669. ToastMessage,
  3670. toast: $$props.toast
  3671. }));
  3672. append($$anchor3, fragment_3);
  3673. };
  3674. var alternate_1 = ($$anchor3) => {
  3675. var fragment_4 = root_6();
  3676. var node_3 = first_child(fragment_4);
  3677. ToastIcon(node_3, {
  3678. get toast() {
  3679. return $$props.toast;
  3680. }
  3681. });
  3682. var node_4 = sibling(node_3, 2);
  3683. ToastMessage(node_4, {
  3684. get toast() {
  3685. return $$props.toast;
  3686. }
  3687. });
  3688. append($$anchor3, fragment_4);
  3689. };
  3690. if_block(
  3691. $$anchor2,
  3692. ($$render) => {
  3693. if ($$props.children) $$render(consequent_1);
  3694. else $$render(alternate_1, false);
  3695. },
  3696. $$elseif
  3697. );
  3698. }
  3699. };
  3700. if_block(node, ($$render) => {
  3701. if (Component()) $$render(consequent);
  3702. else $$render(alternate, false);
  3703. });
  3704. }
  3705. template_effect(() => {
  3706. set_class(div, 1, `base ${($$props.toast.height ? get$1(animation) : "transparent") ?? ""} ${($$props.toast.className || "") ?? ""}`, "svelte-1c9srrs");
  3707. styles = set_style(div, `${style() ?? ""}; ${$$props.toast.style ?? ""}`, styles, { "--factor": get$1(factor) });
  3708. });
  3709. append($$anchor, div);
  3710. pop();
  3711. }
  3712. var root$2 = /* @__PURE__ */ from_html(`<div><!></div>`);
  3713. function ToastWrapper($$anchor, $$props) {
  3714. push($$props, true);
  3715. let clientHeight = /* @__PURE__ */ state(void 0);
  3716. onMount(() => {
  3717. if (get$1(clientHeight) === void 0) return;
  3718. $$props.setHeight(get$1(clientHeight));
  3719. });
  3720. let top = /* @__PURE__ */ user_derived(() => {
  3721. var _a2;
  3722. return ((_a2 = $$props.toast.position) == null ? void 0 : _a2.includes("top")) ? 0 : null;
  3723. });
  3724. let bottom = /* @__PURE__ */ user_derived(() => {
  3725. var _a2;
  3726. return ((_a2 = $$props.toast.position) == null ? void 0 : _a2.includes("bottom")) ? 0 : null;
  3727. });
  3728. let factor = /* @__PURE__ */ user_derived(() => {
  3729. var _a2;
  3730. return ((_a2 = $$props.toast.position) == null ? void 0 : _a2.includes("top")) ? 1 : -1;
  3731. });
  3732. let justifyContent = /* @__PURE__ */ user_derived(() => {
  3733. var _a2, _b, _c;
  3734. return ((_a2 = $$props.toast.position) == null ? void 0 : _a2.includes("center")) && "center" || (((_b = $$props.toast.position) == null ? void 0 : _b.includes("right")) || ((_c = $$props.toast.position) == null ? void 0 : _c.includes("end"))) && "flex-end" || null;
  3735. });
  3736. var div = root$2();
  3737. let classes;
  3738. let styles;
  3739. var node = child(div);
  3740. {
  3741. var consequent = ($$anchor2) => {
  3742. ToastMessage($$anchor2, {
  3743. get toast() {
  3744. return $$props.toast;
  3745. }
  3746. });
  3747. };
  3748. var alternate = ($$anchor2, $$elseif) => {
  3749. {
  3750. var consequent_1 = ($$anchor3) => {
  3751. var fragment_1 = comment();
  3752. var node_1 = first_child(fragment_1);
  3753. snippet(node_1, () => $$props.children, () => ({ toast: $$props.toast }));
  3754. append($$anchor3, fragment_1);
  3755. };
  3756. var alternate_1 = ($$anchor3) => {
  3757. ToastBar($$anchor3, {
  3758. get toast() {
  3759. return $$props.toast;
  3760. },
  3761. get position() {
  3762. return $$props.toast.position;
  3763. }
  3764. });
  3765. };
  3766. if_block(
  3767. $$anchor2,
  3768. ($$render) => {
  3769. if ($$props.children) $$render(consequent_1);
  3770. else $$render(alternate_1, false);
  3771. },
  3772. $$elseif
  3773. );
  3774. }
  3775. };
  3776. if_block(node, ($$render) => {
  3777. if ($$props.toast.type === "custom") $$render(consequent);
  3778. else $$render(alternate, false);
  3779. });
  3780. }
  3781. template_effect(
  3782. ($0) => {
  3783. classes = set_class(div, 1, "wrapper svelte-v01oml", null, classes, $0);
  3784. styles = set_style(div, "", styles, {
  3785. "--factor": get$1(factor),
  3786. "--offset": $$props.toast.offset,
  3787. top: get$1(top),
  3788. bottom: get$1(bottom),
  3789. "justify-content": get$1(justifyContent)
  3790. });
  3791. },
  3792. [
  3793. () => ({
  3794. active: $$props.toast.visible,
  3795. transition: !prefersReducedMotion()
  3796. })
  3797. ]
  3798. );
  3799. bind_element_size(div, "clientHeight", ($$value) => set(clientHeight, $$value));
  3800. append($$anchor, div);
  3801. pop();
  3802. }
  3803. var root$1 = /* @__PURE__ */ from_html(`<div role="alert"></div>`);
  3804. function Toaster($$anchor, $$props) {
  3805. push($$props, true);
  3806. const [$$stores, $$cleanup] = setup_stores();
  3807. const $toasts = () => store_get(toasts2, "$toasts", $$stores);
  3808. let reverseOrder = prop($$props, "reverseOrder", 3, false), position = prop($$props, "position", 3, "top-center"), toastOptions = prop($$props, "toastOptions", 3, void 0), gutter = prop($$props, "gutter", 3, 8), containerStyle = prop($$props, "containerStyle", 3, void 0), containerClassName = prop($$props, "containerClassName", 3, void 0);
  3809. const { toasts: toasts2, handlers: handlers2 } = useToaster(toastOptions());
  3810. let _toasts = /* @__PURE__ */ user_derived(() => $toasts().map((toast2) => ({
  3811. ...toast2,
  3812. position: toast2.position || position(),
  3813. offset: handlers2.calculateOffset(toast2, $toasts(), {
  3814. reverseOrder: reverseOrder(),
  3815. gutter: gutter(),
  3816. defaultPosition: position()
  3817. })
  3818. })));
  3819. var div = root$1();
  3820. each(div, 21, () => get$1(_toasts), (toast2) => toast2.id, ($$anchor2, toast2) => {
  3821. ToastWrapper($$anchor2, {
  3822. get toast() {
  3823. return get$1(toast2);
  3824. },
  3825. setHeight: (height) => handlers2.updateHeight(get$1(toast2).id, height)
  3826. });
  3827. });
  3828. template_effect(() => {
  3829. set_class(div, 1, `toaster ${(containerClassName() || "") ?? ""}`, "svelte-1phplh9");
  3830. set_style(div, containerStyle());
  3831. });
  3832. event("mouseenter", div, function(...$$args) {
  3833. var _a2;
  3834. (_a2 = handlers2.startPause) == null ? void 0 : _a2.apply(this, $$args);
  3835. });
  3836. event("mouseleave", div, function(...$$args) {
  3837. var _a2;
  3838. (_a2 = handlers2.endPause) == null ? void 0 : _a2.apply(this, $$args);
  3839. });
  3840. append($$anchor, div);
  3841. pop();
  3842. $$cleanup();
  3843. }
  3844. const messageToastTypes = ["error", "success", "loading", "info"];
  3845. function createToastWithPrefix(prefix) {
  3846. function addPrefix(message) {
  3847. if (typeof message === "string") {
  3848. return `${prefix}${message}`;
  3849. }
  3850. return message;
  3851. }
  3852. return new Proxy(toast$1, {
  3853. // Handle direct function calls: toast('message')
  3854. apply(target, thisArg, args) {
  3855. if (args.length > 0) {
  3856. args[0] = addPrefix(args[0]);
  3857. }
  3858. return Reflect.apply(target, thisArg, args);
  3859. },
  3860. get(target, prop2, receiver) {
  3861. const originalProp = Reflect.get(target, prop2, receiver);
  3862. if (typeof originalProp === "function" && messageToastTypes.includes(prop2.toString())) {
  3863. return (...args) => {
  3864. if (args.length > 0 && typeof args[0] === "string") {
  3865. args[0] = addPrefix(args[0]);
  3866. }
  3867. return originalProp.apply(this, args);
  3868. };
  3869. }
  3870. if (prop2 === "promise") {
  3871. return (...args) => {
  3872. const [promise, data] = args;
  3873. if (!data) return originalProp;
  3874. const prefixedData = {
  3875. ...data,
  3876. loading: typeof data.loading === "string" ? addPrefix(data.loading) : data.loading,
  3877. success: typeof data.success === "string" ? addPrefix(data.success) : data.success,
  3878. error: typeof data.error === "string" ? addPrefix(data.error) : data.error
  3879. };
  3880. return originalProp.call(this, promise, prefixedData);
  3881. };
  3882. }
  3883. return originalProp;
  3884. }
  3885. });
  3886. }
  3887. const CONFIG = {
  3888. APP_NAME: "LeetCode Toolkit",
  3889. EDITORIAL_READER_URL: "https://leetcode-editorial-reader.vercel.app"
  3890. };
  3891. const toast = createToastWithPrefix(CONFIG.APP_NAME + ": ");
  3892. class GlobalState {
  3893. constructor() {
  3894. __privateAdd(this, _site);
  3895. }
  3896. get site() {
  3897. if (!__privateGet(this, _site)) {
  3898. const hostname = window.location.hostname;
  3899. __privateSet(this, _site, hostname === "leetcode.cn" ? "cn" : "global");
  3900. }
  3901. return __privateGet(this, _site);
  3902. }
  3903. }
  3904. _site = new WeakMap();
  3905. const globalState = new GlobalState();
  3906. var _GM_getResourceText = /* @__PURE__ */ (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)();
  3907. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  3908. class TimeoutError extends Error {
  3909. constructor(item, timeout) {
  3910. super();
  3911. __publicField(this, "name", this.constructor.name);
  3912. this.message = `"${item}" not found within timeout (${timeout}ms)`;
  3913. }
  3914. }
  3915. function find(finderFn, {
  3916. subject = document,
  3917. observerOption = {
  3918. childList: true,
  3919. subtree: true
  3920. },
  3921. timeout = 5e3,
  3922. itemName = "Item"
  3923. }) {
  3924. return new Promise((resolve, reject) => {
  3925. const item = finderFn();
  3926. if (item) return resolve(item);
  3927. let timeoutId;
  3928. const observer = new MutationObserver(() => {
  3929. const item2 = finderFn();
  3930. if (item2) {
  3931. observer.disconnect();
  3932. clearTimeout(timeoutId);
  3933. return resolve(item2);
  3934. }
  3935. });
  3936. observer.observe(subject, observerOption);
  3937. if (timeout > 0) {
  3938. timeoutId = setTimeout(() => {
  3939. observer.disconnect();
  3940. const error = new TimeoutError(itemName, timeout);
  3941. console.error(error);
  3942. return reject(error);
  3943. }, timeout);
  3944. }
  3945. });
  3946. }
  3947. async function findElement(selector, {
  3948. parent = document,
  3949. timeout = 500,
  3950. additionalRule
  3951. } = {}) {
  3952. const element = await find(
  3953. () => {
  3954. const el = parent.querySelector(selector);
  3955. if (additionalRule && el) {
  3956. return additionalRule(el) ? el : null;
  3957. } else {
  3958. return el;
  3959. }
  3960. },
  3961. {
  3962. subject: parent,
  3963. timeout,
  3964. itemName: `Element ${selector}`
  3965. }
  3966. );
  3967. return element;
  3968. }
  3969. const overrideOptions = {
  3970. selectionHighlight: true,
  3971. parameterHints: { enabled: true },
  3972. hover: { enabled: true },
  3973. quickSuggestions: true,
  3974. suggestOnTriggerCharacters: true,
  3975. "bracketPairColorization.enabled": true
  3976. };
  3977. function addIntellisense(editor) {
  3978. const originalUpdateOptions = editor.updateOptions.bind(editor);
  3979. editor.updateOptions = (options) => {
  3980. originalUpdateOptions({
  3981. ...options,
  3982. ...overrideOptions
  3983. });
  3984. };
  3985. }
  3986. async function findMonacoEditor() {
  3987. function getEditor() {
  3988. var _a2;
  3989. return ((_a2 = _unsafeWindow.monaco) == null ? void 0 : _a2.editor.getEditors()[0]) ?? null;
  3990. }
  3991. const editor = find(getEditor, {
  3992. subject: document.head,
  3993. observerOption: { childList: true },
  3994. itemName: "Monaco Editor"
  3995. });
  3996. return editor;
  3997. }
  3998. class ProblemPageState {
  3999. constructor() {
  4000. __publicField(this, "editor", null);
  4001. }
  4002. async patchMonacoEditor() {
  4003. this.editor = await findMonacoEditor();
  4004. this.enableFormatOnSave();
  4005. addIntellisense(this.editor);
  4006. }
  4007. enableFormatOnSave() {
  4008. document.addEventListener("keydown", async (e2) => {
  4009. var _a2, _b;
  4010. if (!(e2.ctrlKey && e2.key === "s")) return;
  4011. try {
  4012. await ((_b = (_a2 = this.editor) == null ? void 0 : _a2.getAction("editor.action.formatDocument")) == null ? void 0 : _b.run());
  4013. } catch (err) {
  4014. console.error(err);
  4015. if (err instanceof Error) {
  4016. toast.error("Failed to format code:" + err.message);
  4017. }
  4018. }
  4019. });
  4020. }
  4021. }
  4022. const problemState = new ProblemPageState();
  4023. function u$1(o2, n, a2) {
  4024. let t = (r2) => o2(r2, ...n);
  4025. return t;
  4026. }
  4027. function u(r2, n, o2) {
  4028. let a2 = r2.length - n.length;
  4029. if (a2 === 0) return r2(...n);
  4030. if (a2 === 1) return u$1(r2, n);
  4031. throw new Error("Wrong number of arguments");
  4032. }
  4033. var o$1 = [" ", `
  4034. `, "\v", "\f", "\r", " ", "…", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "\u2028", "\u2029", " ", " ", " ", "\uFEFF"], c = /* @__PURE__ */ new Set(["-", "_", ...o$1]), i = (r2) => {
  4035. let e2 = [], t = "", u2 = () => {
  4036. t.length > 0 && (e2.push(t), t = "");
  4037. };
  4038. for (let s of r2) {
  4039. if (c.has(s)) {
  4040. u2();
  4041. continue;
  4042. }
  4043. if (/[a-z]$/u.test(t) && /[A-Z]/u.test(s)) u2();
  4044. else if (/[A-Z][A-Z]$/u.test(t) && /[a-z]/u.test(s)) {
  4045. let n = t.slice(-1);
  4046. t = t.slice(0, -1), u2(), t = n;
  4047. } else /\d$/u.test(t) !== /\d/u.test(s) && u2();
  4048. t += s;
  4049. }
  4050. return u2(), e2;
  4051. };
  4052. function a(...e2) {
  4053. return u(o, e2);
  4054. }
  4055. var o = (e2) => i(e2).join("-").toLowerCase();
  4056. function e(o2) {
  4057. return o2 instanceof Promise;
  4058. }
  4059. enable_legacy_mode_flag();
  4060. var root = /* @__PURE__ */ from_html(`<div><!></div>`);
  4061. function ButtonGroup($$anchor, $$props) {
  4062. let props = /* @__PURE__ */ rest_props($$props, [
  4063. "$$slots",
  4064. "$$events",
  4065. "$$legacy",
  4066. "children"
  4067. ]);
  4068. var div = root();
  4069. attribute_effect(div, () => ({ ...props }), void 0, "svelte-4mbyk0");
  4070. var node = child(div);
  4071. snippet(node, () => $$props.children);
  4072. append($$anchor, div);
  4073. }
  4074. const mouseClickEvents = ["mousedown", "mouseup", "click"];
  4075. function simulateMouseClickReact(element) {
  4076. mouseClickEvents.forEach(
  4077. (mouseEventType) => element.dispatchEvent(
  4078. new MouseEvent(mouseEventType, {
  4079. view: _unsafeWindow,
  4080. bubbles: true,
  4081. cancelable: true,
  4082. buttons: 1
  4083. })
  4084. )
  4085. );
  4086. }
  4087. const loaderIcon = ($$anchor) => {
  4088. var svg = root_1$3();
  4089. append($$anchor, svg);
  4090. };
  4091. var root_1$3 = /* @__PURE__ */ from_svg(`<svg class="animate-spin" xmlns="http://www.w3.org/2000/svg" width="1rem" height="1rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2v4m4.2 1.8l2.9-2.9M18 12h4m-5.8 4.2l2.9 2.9M12 18v4m-7.1-2.9l2.9-2.9M2 12h4M4.9 4.9l2.9 2.9"></path></svg>`);
  4092. var root_2 = /* @__PURE__ */ from_html(`<a><!></a>`);
  4093. var root_3 = /* @__PURE__ */ from_html(`<button><!> <!></button>`);
  4094. function Button($$anchor, $$props) {
  4095. push($$props, true);
  4096. let variant = prop($$props, "variant", 3, "purple"), type = prop($$props, "type", 3, "button"), restProps = /* @__PURE__ */ rest_props($$props, [
  4097. "$$slots",
  4098. "$$events",
  4099. "$$legacy",
  4100. "onclick",
  4101. "children",
  4102. "variant",
  4103. "type",
  4104. "href"
  4105. ]);
  4106. const variants = {
  4107. purple: "--bg: #6c5ce7; --shadow: #a29bfe",
  4108. green: "--bg: #1ba13e; --shadow: #42de6e",
  4109. orange: "--bg: #ffa116; --shadow: #fedd9b"
  4110. };
  4111. let loading = /* @__PURE__ */ state(false);
  4112. async function handleOnClick(e$1) {
  4113. if (!$$props.onclick) return;
  4114. const returnValue = $$props.onclick(e$1);
  4115. if (e(returnValue)) {
  4116. set(loading, true);
  4117. await returnValue;
  4118. set(loading, false);
  4119. }
  4120. }
  4121. var fragment = comment();
  4122. var node = first_child(fragment);
  4123. {
  4124. var consequent = ($$anchor2) => {
  4125. var a2 = root_2();
  4126. attribute_effect(
  4127. a2,
  4128. () => ({
  4129. style: variants[variant()],
  4130. href: $$props.href,
  4131. target: "_blank",
  4132. ...restProps
  4133. }),
  4134. void 0,
  4135. "svelte-ll0ynk"
  4136. );
  4137. var node_1 = child(a2);
  4138. snippet(node_1, () => $$props.children ?? noop);
  4139. append($$anchor2, a2);
  4140. };
  4141. var alternate = ($$anchor2) => {
  4142. var button = root_3();
  4143. attribute_effect(
  4144. button,
  4145. () => ({
  4146. style: variants[variant()],
  4147. type: type(),
  4148. disabled: get$1(loading),
  4149. onclick: handleOnClick,
  4150. ...restProps
  4151. }),
  4152. void 0,
  4153. "svelte-ll0ynk"
  4154. );
  4155. var node_2 = child(button);
  4156. {
  4157. var consequent_1 = ($$anchor3) => {
  4158. loaderIcon($$anchor3);
  4159. };
  4160. if_block(node_2, ($$render) => {
  4161. if (get$1(loading)) $$render(consequent_1);
  4162. });
  4163. }
  4164. var node_3 = sibling(node_2, 2);
  4165. snippet(node_3, () => $$props.children ?? noop);
  4166. append($$anchor2, button);
  4167. };
  4168. if_block(node, ($$render) => {
  4169. if ($$props.href) $$render(consequent);
  4170. else $$render(alternate, false);
  4171. });
  4172. }
  4173. append($$anchor, fragment);
  4174. pop();
  4175. }
  4176. async function copyText(text2) {
  4177. try {
  4178. await navigator.clipboard.writeText(text2);
  4179. } catch (err) {
  4180. if (err instanceof Error) {
  4181. console.error(err);
  4182. }
  4183. throw err;
  4184. }
  4185. }
  4186. const getTitle = async () => {
  4187. const descriptionTabButton = (await findElement("#description_tab")).closest(".flexlayout__tab_button");
  4188. if (!(descriptionTabButton == null ? void 0 : descriptionTabButton.classList.contains(".flexlayout__tab_button--selected"))) {
  4189. simulateMouseClickReact(descriptionTabButton);
  4190. }
  4191. return (await findElement(".text-title-large")).textContent ?? "";
  4192. };
  4193. function Copy_title($$anchor, $$props) {
  4194. push($$props, false);
  4195. async function copyTitle() {
  4196. copyText(await getTitle());
  4197. }
  4198. init();
  4199. Button($$anchor, {
  4200. onclick: copyTitle,
  4201. children: ($$anchor2, $$slotProps) => {
  4202. var text$1 = text();
  4203. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制标题" : "Copy Title"));
  4204. append($$anchor2, text$1);
  4205. },
  4206. $$slots: { default: true }
  4207. });
  4208. pop();
  4209. }
  4210. var turndownPluginGfm_cjs = {};
  4211. var hasRequiredTurndownPluginGfm_cjs;
  4212. function requireTurndownPluginGfm_cjs() {
  4213. if (hasRequiredTurndownPluginGfm_cjs) return turndownPluginGfm_cjs;
  4214. hasRequiredTurndownPluginGfm_cjs = 1;
  4215. Object.defineProperty(turndownPluginGfm_cjs, "__esModule", { value: true });
  4216. var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
  4217. function highlightedCodeBlock(turndownService) {
  4218. turndownService.addRule("highlightedCodeBlock", {
  4219. filter: function(node) {
  4220. var firstChild = node.firstChild;
  4221. return node.nodeName === "DIV" && highlightRegExp.test(node.className) && firstChild && firstChild.nodeName === "PRE";
  4222. },
  4223. replacement: function(content, node, options) {
  4224. var className = node.className || "";
  4225. var language = (className.match(highlightRegExp) || [null, ""])[1];
  4226. return "\n\n" + options.fence + language + "\n" + node.firstChild.textContent + "\n" + options.fence + "\n\n";
  4227. }
  4228. });
  4229. }
  4230. function strikethrough(turndownService) {
  4231. turndownService.addRule("strikethrough", {
  4232. filter: ["del", "s", "strike"],
  4233. replacement: function(content) {
  4234. return "~~" + content + "~~";
  4235. }
  4236. });
  4237. }
  4238. var indexOf = Array.prototype.indexOf;
  4239. var every = Array.prototype.every;
  4240. var rules = {};
  4241. var alignMap = { left: ":---", right: "---:", center: ":---:" };
  4242. let isCodeBlock_ = null;
  4243. let options_ = null;
  4244. const tableShouldBeSkippedCache_ = /* @__PURE__ */ new WeakMap();
  4245. function getAlignment(node) {
  4246. return node ? (node.getAttribute("align") || node.style.textAlign || "").toLowerCase() : "";
  4247. }
  4248. function getBorder(alignment) {
  4249. return alignment ? alignMap[alignment] : "---";
  4250. }
  4251. function getColumnAlignment(table, columnIndex) {
  4252. var votes = {
  4253. left: 0,
  4254. right: 0,
  4255. center: 0,
  4256. "": 0
  4257. };
  4258. var align = "";
  4259. for (var i2 = 0; i2 < table.rows.length; ++i2) {
  4260. var row = table.rows[i2];
  4261. if (columnIndex < row.childNodes.length) {
  4262. var cellAlignment = getAlignment(row.childNodes[columnIndex]);
  4263. ++votes[cellAlignment];
  4264. if (votes[cellAlignment] > votes[align]) {
  4265. align = cellAlignment;
  4266. }
  4267. }
  4268. }
  4269. return align;
  4270. }
  4271. rules.tableCell = {
  4272. filter: ["th", "td"],
  4273. replacement: function(content, node) {
  4274. if (tableShouldBeSkipped(nodeParentTable(node))) return content;
  4275. return cell(content, node);
  4276. }
  4277. };
  4278. rules.tableRow = {
  4279. filter: "tr",
  4280. replacement: function(content, node) {
  4281. const parentTable = nodeParentTable(node);
  4282. if (tableShouldBeSkipped(parentTable)) return content;
  4283. var borderCells = "";
  4284. if (isHeadingRow(node)) {
  4285. const colCount = tableColCount(parentTable);
  4286. for (var i2 = 0; i2 < colCount; i2++) {
  4287. const childNode = i2 < node.childNodes.length ? node.childNodes[i2] : null;
  4288. var border = getBorder(getColumnAlignment(parentTable, i2));
  4289. borderCells += cell(border, childNode, i2);
  4290. }
  4291. }
  4292. return "\n" + content + (borderCells ? "\n" + borderCells : "");
  4293. }
  4294. };
  4295. rules.table = {
  4296. filter: function(node, options) {
  4297. return node.nodeName === "TABLE";
  4298. },
  4299. replacement: function(content, node) {
  4300. if (tableShouldBeHtml(node, options_)) {
  4301. let html = node.outerHTML;
  4302. let divParent = nodeParentDiv(node);
  4303. if (divParent === null || !divParent.classList.contains("joplin-table-wrapper")) {
  4304. return `
  4305.  
  4306. <div class="joplin-table-wrapper">${html}</div>
  4307.  
  4308. `;
  4309. } else {
  4310. return html;
  4311. }
  4312. } else {
  4313. if (tableShouldBeSkipped(node)) return content;
  4314. content = content.replace(/\n+/g, "\n");
  4315. var secondLine = content.trim().split("\n");
  4316. if (secondLine.length >= 2) secondLine = secondLine[1];
  4317. var secondLineIsDivider = /\| :?---/.test(secondLine);
  4318. var columnCount = tableColCount(node);
  4319. var emptyHeader = "";
  4320. if (columnCount && !secondLineIsDivider) {
  4321. emptyHeader = "|" + " |".repeat(columnCount) + "\n|";
  4322. for (var columnIndex = 0; columnIndex < columnCount; ++columnIndex) {
  4323. emptyHeader += " " + getBorder(getColumnAlignment(node, columnIndex)) + " |";
  4324. }
  4325. }
  4326. const captionContent = node.caption ? node.caption.textContent || "" : "";
  4327. const caption = captionContent ? `${captionContent}
  4328.  
  4329. ` : "";
  4330. const tableContent = `${emptyHeader}${content}`.trimStart();
  4331. return `
  4332.  
  4333. ${caption}${tableContent}
  4334.  
  4335. `;
  4336. }
  4337. }
  4338. };
  4339. rules.tableCaption = {
  4340. filter: ["caption"],
  4341. replacement: () => ""
  4342. };
  4343. rules.tableColgroup = {
  4344. filter: ["colgroup", "col"],
  4345. replacement: () => ""
  4346. };
  4347. rules.tableSection = {
  4348. filter: ["thead", "tbody", "tfoot"],
  4349. replacement: function(content) {
  4350. return content;
  4351. }
  4352. };
  4353. function isHeadingRow(tr) {
  4354. var parentNode = tr.parentNode;
  4355. return parentNode.nodeName === "THEAD" || parentNode.firstChild === tr && (parentNode.nodeName === "TABLE" || isFirstTbody(parentNode)) && every.call(tr.childNodes, function(n) {
  4356. return n.nodeName === "TH";
  4357. });
  4358. }
  4359. function isFirstTbody(element) {
  4360. var previousSibling = element.previousSibling;
  4361. return element.nodeName === "TBODY" && (!previousSibling || previousSibling.nodeName === "THEAD" && /^\s*$/i.test(previousSibling.textContent));
  4362. }
  4363. function cell(content, node = null, index = null) {
  4364. if (index === null) index = indexOf.call(node.parentNode.childNodes, node);
  4365. var prefix = " ";
  4366. if (index === 0) prefix = "| ";
  4367. let filteredContent = content.trim().replace(/\n\r/g, "<br>").replace(/\n/g, "<br>");
  4368. filteredContent = filteredContent.replace(/\|+/g, "\\|");
  4369. while (filteredContent.length < 3) filteredContent += " ";
  4370. if (node) filteredContent = handleColSpan(filteredContent, node, " ");
  4371. return prefix + filteredContent + " |";
  4372. }
  4373. function nodeContainsTable(node) {
  4374. if (!node.childNodes) return false;
  4375. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  4376. const child2 = node.childNodes[i2];
  4377. if (child2.nodeName === "TABLE") return true;
  4378. if (nodeContainsTable(child2)) return true;
  4379. }
  4380. return false;
  4381. }
  4382. const nodeContains = (node, types) => {
  4383. if (!node.childNodes) return false;
  4384. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  4385. const child2 = node.childNodes[i2];
  4386. if (types === "code" && isCodeBlock_ && isCodeBlock_(child2)) return true;
  4387. if (types.includes(child2.nodeName)) return true;
  4388. if (nodeContains(child2, types)) return true;
  4389. }
  4390. return false;
  4391. };
  4392. const tableShouldBeHtml = (tableNode, options) => {
  4393. const possibleTags = [
  4394. "UL",
  4395. "OL",
  4396. "H1",
  4397. "H2",
  4398. "H3",
  4399. "H4",
  4400. "H5",
  4401. "H6",
  4402. "HR",
  4403. "BLOCKQUOTE"
  4404. ];
  4405. if (options.preserveNestedTables) possibleTags.push("TABLE");
  4406. return nodeContains(tableNode, "code") || nodeContains(tableNode, possibleTags);
  4407. };
  4408. function tableShouldBeSkipped(tableNode) {
  4409. const cached = tableShouldBeSkippedCache_.get(tableNode);
  4410. if (cached !== void 0) return cached;
  4411. const result = tableShouldBeSkipped_(tableNode);
  4412. tableShouldBeSkippedCache_.set(tableNode, result);
  4413. return result;
  4414. }
  4415. function tableShouldBeSkipped_(tableNode) {
  4416. if (!tableNode) return true;
  4417. if (!tableNode.rows) return true;
  4418. if (tableNode.rows.length === 1 && tableNode.rows[0].childNodes.length <= 1) return true;
  4419. if (nodeContainsTable(tableNode)) return true;
  4420. return false;
  4421. }
  4422. function nodeParentDiv(node) {
  4423. let parent = node.parentNode;
  4424. while (parent.nodeName !== "DIV") {
  4425. parent = parent.parentNode;
  4426. if (!parent) return null;
  4427. }
  4428. return parent;
  4429. }
  4430. function nodeParentTable(node) {
  4431. let parent = node.parentNode;
  4432. while (parent.nodeName !== "TABLE") {
  4433. parent = parent.parentNode;
  4434. if (!parent) return null;
  4435. }
  4436. return parent;
  4437. }
  4438. function handleColSpan(content, node, emptyChar) {
  4439. const colspan = node.getAttribute("colspan") || 1;
  4440. for (let i2 = 1; i2 < colspan; i2++) {
  4441. content += " | " + emptyChar.repeat(3);
  4442. }
  4443. return content;
  4444. }
  4445. function tableColCount(node) {
  4446. let maxColCount = 0;
  4447. for (let i2 = 0; i2 < node.rows.length; i2++) {
  4448. const row = node.rows[i2];
  4449. const colCount = row.childNodes.length;
  4450. if (colCount > maxColCount) maxColCount = colCount;
  4451. }
  4452. return maxColCount;
  4453. }
  4454. function tables(turndownService) {
  4455. isCodeBlock_ = turndownService.isCodeBlock;
  4456. options_ = turndownService.options;
  4457. turndownService.keep(function(node) {
  4458. if (node.nodeName === "TABLE" && tableShouldBeHtml(node, turndownService.options)) return true;
  4459. return false;
  4460. });
  4461. for (var key in rules) turndownService.addRule(key, rules[key]);
  4462. }
  4463. function taskListItems(turndownService) {
  4464. turndownService.addRule("taskListItems", {
  4465. filter: function(node) {
  4466. return node.type === "checkbox" && node.parentNode.nodeName === "LI";
  4467. },
  4468. replacement: function(content, node) {
  4469. return (node.checked ? "[x]" : "[ ]") + " ";
  4470. }
  4471. });
  4472. }
  4473. function gfm(turndownService) {
  4474. turndownService.use([
  4475. highlightedCodeBlock,
  4476. strikethrough,
  4477. tables,
  4478. taskListItems
  4479. ]);
  4480. }
  4481. turndownPluginGfm_cjs.gfm = gfm;
  4482. turndownPluginGfm_cjs.highlightedCodeBlock = highlightedCodeBlock;
  4483. turndownPluginGfm_cjs.strikethrough = strikethrough;
  4484. turndownPluginGfm_cjs.tables = tables;
  4485. turndownPluginGfm_cjs.taskListItems = taskListItems;
  4486. return turndownPluginGfm_cjs;
  4487. }
  4488. var turndownPluginGfm_cjsExports = requireTurndownPluginGfm_cjs();
  4489. var M = "__monkeyWindow-" + (() => {
  4490. try {
  4491. return new URL((_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('__entry.js', document.baseURI).href)).origin;
  4492. } catch {
  4493. return location.origin;
  4494. }
  4495. })(), y = document[M] ?? window, g = y.GM, v = y.GM_xmlhttpRequest;
  4496. function k(l) {
  4497. var e2;
  4498. const t = new Headers(), a2 = l.replace(/\r?\n[\t ]+/g, " ");
  4499. for (const d of a2.split(/\r?\n/)) {
  4500. const i2 = d.split(":"), o2 = (e2 = i2.shift()) == null ? void 0 : e2.trim();
  4501. if (o2) {
  4502. const r2 = i2.join(":").trim();
  4503. try {
  4504. t.append(o2, r2);
  4505. } catch (c2) {
  4506. console.warn(`Response ${c2.message}`);
  4507. }
  4508. }
  4509. }
  4510. return t;
  4511. }
  4512. const H = async (l, t) => {
  4513. const a2 = v || g.xmlHttpRequest;
  4514. if (typeof a2 != "function")
  4515. throw new DOMException(
  4516. "GM_xmlhttpRequest or GM.xmlHttpRequest is not granted.",
  4517. "NotFoundError"
  4518. );
  4519. const e2 = new Request(l, t);
  4520. if (e2.signal.aborted)
  4521. throw new DOMException("Network request aborted.", "AbortError");
  4522. const d = await e2.blob(), i2 = Object.fromEntries(e2.headers);
  4523. return new Headers(void 0).forEach((o2, r2) => {
  4524. i2[r2] = o2;
  4525. }), new Promise((o2, r2) => {
  4526. let c2 = false;
  4527. const R = new Promise((n) => {
  4528. const { abort: h } = a2({
  4529. method: e2.method.toUpperCase(),
  4530. url: e2.url || location.href,
  4531. headers: i2,
  4532. data: d.size ? d : void 0,
  4533. redirect: e2.redirect,
  4534. binary: true,
  4535. nocache: e2.cache === "no-store",
  4536. revalidate: e2.cache === "reload",
  4537. timeout: 3e5,
  4538. responseType: a2.RESPONSE_TYPE_STREAM ?? "blob",
  4539. overrideMimeType: e2.headers.get("Content-Type") ?? void 0,
  4540. anonymous: e2.credentials === "omit",
  4541. onload: ({ response: s }) => {
  4542. if (c2) {
  4543. n(null);
  4544. return;
  4545. }
  4546. n(s);
  4547. },
  4548. async onreadystatechange({
  4549. readyState: s,
  4550. responseHeaders: p,
  4551. status: b,
  4552. statusText: q,
  4553. finalUrl: w,
  4554. response: E
  4555. }) {
  4556. if (s === XMLHttpRequest.DONE)
  4557. e2.signal.removeEventListener("abort", h);
  4558. else if (s !== XMLHttpRequest.HEADERS_RECEIVED)
  4559. return;
  4560. if (c2) {
  4561. n(null);
  4562. return;
  4563. }
  4564. const u2 = k(p), f = e2.url !== w, m = new Response(
  4565. E instanceof ReadableStream ? E : await R,
  4566. {
  4567. headers: u2,
  4568. status: b,
  4569. statusText: q
  4570. }
  4571. );
  4572. Object.defineProperties(m, {
  4573. url: {
  4574. value: w
  4575. },
  4576. type: {
  4577. value: "basic"
  4578. },
  4579. ...m.redirected !== f ? {
  4580. redirected: {
  4581. value: f
  4582. }
  4583. } : {},
  4584. // https://fetch.spec.whatwg.org/#forbidden-response-header-name
  4585. ...u2.has("set-cookie") || u2.has("set-cookie2") ? {
  4586. headers: {
  4587. value: u2
  4588. }
  4589. } : {}
  4590. }), o2(m), c2 = true;
  4591. },
  4592. onerror: ({ statusText: s, error: p }) => {
  4593. r2(
  4594. new TypeError(s || p || "Network request failed.")
  4595. ), n(null);
  4596. },
  4597. ontimeout() {
  4598. r2(new TypeError("Network request timeout.")), n(null);
  4599. },
  4600. onabort() {
  4601. r2(new DOMException("Network request aborted.", "AbortError")), n(null);
  4602. }
  4603. });
  4604. e2.signal.addEventListener("abort", h);
  4605. });
  4606. });
  4607. };
  4608. async function compressImage(image) {
  4609. return new Promise((resolve, reject) => {
  4610. new Compressor(image, {
  4611. success: resolve,
  4612. error: reject
  4613. });
  4614. });
  4615. }
  4616. function blobToDataURL(blob) {
  4617. return new Promise((resolve, reject) => {
  4618. const reader = new FileReader();
  4619. reader.onload = () => resolve(reader.result);
  4620. reader.onerror = (error) => reject(error);
  4621. reader.readAsDataURL(blob);
  4622. });
  4623. }
  4624. async function convertSrcToDataURL(src) {
  4625. if (src.startsWith("data:")) {
  4626. return src;
  4627. }
  4628. try {
  4629. const response = await H(src);
  4630. let blob = await response.blob();
  4631. const incompressableTypes = ["image/gif", "image/svg+xml"];
  4632. if (!incompressableTypes.includes(blob.type)) {
  4633. blob = await compressImage(blob);
  4634. }
  4635. const dataURL = await blobToDataURL(blob);
  4636. return dataURL;
  4637. } catch (err) {
  4638. console.error(`Failed to convert image: ${src}`, err);
  4639. throw err;
  4640. }
  4641. }
  4642. const imageCache = /* @__PURE__ */ new Map();
  4643. async function prefetchImages(node) {
  4644. const images = Array.from(node.querySelectorAll("img"));
  4645. const fetchPromises = images.map(async ({ src }) => {
  4646. if (imageCache.has(src)) return;
  4647. const dataURL = await convertSrcToDataURL(src);
  4648. imageCache.set(src, dataURL);
  4649. });
  4650. await Promise.all(fetchPromises);
  4651. }
  4652. function createTurndownService() {
  4653. const turndown2 = new TurndownService({
  4654. emDelimiter: "*",
  4655. bulletListMarker: "-"
  4656. });
  4657. turndown2.addRule("pre", {
  4658. filter: ["pre"],
  4659. replacement: (_content, node) => {
  4660. var _a2;
  4661. return "\n```txt\n" + ((_a2 = node.textContent) == null ? void 0 : _a2.trim()) + "\n```\n";
  4662. }
  4663. });
  4664. turndown2.addRule("superscript", {
  4665. filter: ["sup"],
  4666. replacement: (content) => "^" + content
  4667. });
  4668. turndown2.addRule("paragraph", {
  4669. filter: ["p"],
  4670. replacement: (content) => "\n\n" + content + "\n\n"
  4671. });
  4672. turndown2.addRule("convert-img-src-to-base64", {
  4673. filter: ["img"],
  4674. replacement: (_content, node) => {
  4675. const { src, alt } = node;
  4676. const dataURL = imageCache.get(src);
  4677. if (dataURL) {
  4678. return `![${alt}](${dataURL})`;
  4679. }
  4680. return `![${alt}](${src})`;
  4681. }
  4682. });
  4683. turndown2.use(turndownPluginGfm_cjsExports.tables);
  4684. return turndown2;
  4685. }
  4686. async function htmlToMd(node, {
  4687. turndownService = createTurndownService(),
  4688. convertImage = true
  4689. } = {}) {
  4690. if (convertImage) await prefetchImages(node);
  4691. const md = turndownService.turndown(node);
  4692. if (convertImage) imageCache.clear();
  4693. return md;
  4694. }
  4695. const getDescription = async (convertImage = true) => {
  4696. const el = await findElement("div[data-track-load='description_content']");
  4697. return htmlToMd(el, { convertImage });
  4698. };
  4699. function Copy_description($$anchor, $$props) {
  4700. push($$props, false);
  4701. async function copyDescription() {
  4702. const desc = await getDescription(false);
  4703. copyText(desc);
  4704. }
  4705. init();
  4706. Button($$anchor, {
  4707. variant: "green",
  4708. onclick: copyDescription,
  4709. children: ($$anchor2, $$slotProps) => {
  4710. var text$1 = text();
  4711. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制描述" : "Copy Description"));
  4712. append($$anchor2, text$1);
  4713. },
  4714. $$slots: { default: true }
  4715. });
  4716. pop();
  4717. }
  4718. function downloadFile(blob, filename, extension) {
  4719. const url2 = URL.createObjectURL(blob);
  4720. const a2 = document.createElement("a");
  4721. a2.href = url2;
  4722. a2.download = filename + "." + extension;
  4723. document.body.appendChild(a2);
  4724. a2.click();
  4725. document.body.removeChild(a2);
  4726. URL.revokeObjectURL(url2);
  4727. }
  4728. function createNotebook({
  4729. title,
  4730. description,
  4731. code,
  4732. language = "python",
  4733. url: url2
  4734. }) {
  4735. const notebook = {
  4736. metadata: {
  4737. language_info: {
  4738. name: language
  4739. }
  4740. },
  4741. nbformat: 5,
  4742. nbformat_minor: 10,
  4743. cells: []
  4744. };
  4745. const regex = /^(https:\/\/(leetcode\.com|leetcode\.cn)\/problems\/[a-zA-Z0-9_-]+)/;
  4746. const match = url2.match(regex);
  4747. const titleCell = createMarkdownCell(
  4748. `# [${title}](${match ? match[0] : url2})`
  4749. );
  4750. const descriptionPrefix = globalState.site === "cn" ? "题目描述" : "Description";
  4751. const descriptionCell = createMarkdownCell(
  4752. `## ${descriptionPrefix}
  4753.  
  4754. ` + description
  4755. );
  4756. const partitionCell = createMarkdownCell("---\n\n");
  4757. const solutionPrefix = globalState.site === "cn" ? "解答" : "Solution";
  4758. const solutionCell = createMarkdownCell(`## ${solutionPrefix}`);
  4759. const codeCell = createCodeCell(code);
  4760. notebook.cells.push(
  4761. titleCell,
  4762. descriptionCell,
  4763. partitionCell,
  4764. solutionCell,
  4765. codeCell
  4766. );
  4767. return notebook;
  4768. }
  4769. function createMarkdownCell(content) {
  4770. return {
  4771. cell_type: "markdown",
  4772. metadata: {},
  4773. source: content
  4774. };
  4775. }
  4776. function createCodeCell(content) {
  4777. return {
  4778. cell_type: "code",
  4779. metadata: {},
  4780. source: content,
  4781. execution_count: null,
  4782. outputs: []
  4783. };
  4784. }
  4785. function downloadNotebook(notebook, filename) {
  4786. const blob = new Blob([JSON.stringify(notebook)], {
  4787. type: "application/x-ipynb+json"
  4788. });
  4789. downloadFile(blob, filename, "ipynb");
  4790. }
  4791. function Download_as_jupyter($$anchor, $$props) {
  4792. push($$props, false);
  4793. async function saveAsJupyter() {
  4794. var _a2, _b, _c, _d;
  4795. const title = await getTitle();
  4796. const notebook = createNotebook({
  4797. title,
  4798. description: await getDescription(),
  4799. code: ((_b = (_a2 = problemState.editor) == null ? void 0 : _a2.getModel()) == null ? void 0 : _b.getValue()) ?? "",
  4800. language: ((_d = (_c = problemState.editor) == null ? void 0 : _c.getModel()) == null ? void 0 : _d.getLanguageId()) ?? "python",
  4801. url: window.location.href
  4802. });
  4803. downloadNotebook(notebook, title);
  4804. }
  4805. init();
  4806. Button($$anchor, {
  4807. variant: "orange",
  4808. onclick: () => {
  4809. toast.promise(saveAsJupyter(), {
  4810. loading: "Scraping problem description and code...",
  4811. success: "Start downloading jupyter notebook...",
  4812. error: "Something went wrong while scraping. See browser console for more detail."
  4813. });
  4814. },
  4815. children: ($$anchor2, $$slotProps) => {
  4816. var text$1 = text();
  4817. template_effect(() => set_text(text$1, globalState.site === "cn" ? "保存为 Jupyter Notebook (.ipynb)" : "Save as Jupyter Notebook (.ipynb)"));
  4818. append($$anchor2, text$1);
  4819. },
  4820. $$slots: { default: true }
  4821. });
  4822. pop();
  4823. }
  4824. var root_1$2 = /* @__PURE__ */ from_html(`<!> <!> <!>`, 1);
  4825. function DescriptionButttons($$anchor) {
  4826. ButtonGroup($$anchor, {
  4827. children: ($$anchor2, $$slotProps) => {
  4828. var fragment_1 = root_1$2();
  4829. var node = first_child(fragment_1);
  4830. Copy_title(node, {});
  4831. var node_1 = sibling(node, 2);
  4832. Copy_description(node_1, {});
  4833. var node_2 = sibling(node_1, 2);
  4834. Download_as_jupyter(node_2, {});
  4835. append($$anchor2, fragment_1);
  4836. },
  4837. $$slots: { default: true }
  4838. });
  4839. }
  4840. async function initDescriptionTab() {
  4841. var _a2;
  4842. const descriptionTab = await findElement(
  4843. ".flexlayout__tab:has([data-track-load='description_content'])",
  4844. {
  4845. timeout: 0,
  4846. additionalRule: (el) => el.style.display !== "none"
  4847. }
  4848. );
  4849. const titleContainer = await findElement("div:has(> .text-title-large)", {
  4850. parent: descriptionTab
  4851. });
  4852. const buttonsContainer = document.createElement("div");
  4853. buttonsContainer.setAttribute(
  4854. "id",
  4855. a(CONFIG.APP_NAME) + "-description"
  4856. );
  4857. buttonsContainer.style.cssText = "display: contents;";
  4858. (_a2 = titleContainer.parentElement) == null ? void 0 : _a2.before(buttonsContainer);
  4859. mount(DescriptionButttons, {
  4860. target: buttonsContainer
  4861. });
  4862. }
  4863. function Find_editorial_screenshot($$anchor, $$props) {
  4864. push($$props, false);
  4865. const editorialsMarkdown = _GM_getResourceText("editorials");
  4866. function extractScreenshotLink(problemTitle) {
  4867. const cleanTitle = problemTitle.trim();
  4868. const headingPattern = new RegExp(`####\\s+\\[${cleanTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\]\\((.*?)\\)`, "i");
  4869. const match = editorialsMarkdown.match(headingPattern);
  4870. return match ? match[1] : null;
  4871. }
  4872. async function goToEditorialScreenshot() {
  4873. const title = await getTitle();
  4874. const link2 = extractScreenshotLink(title);
  4875. if (link2) {
  4876. window.open(link2, "_blank");
  4877. } else {
  4878. toast.error(`Editorial screenshot not found for problem: ${title}`);
  4879. }
  4880. }
  4881. init();
  4882. Button($$anchor, {
  4883. onclick: goToEditorialScreenshot,
  4884. children: ($$anchor2, $$slotProps) => {
  4885. var text$1 = text("Find Screenshot");
  4886. append($$anchor2, text$1);
  4887. },
  4888. $$slots: { default: true }
  4889. });
  4890. pop();
  4891. }
  4892. const turndown = createTurndownService();
  4893. turndown.addRule("remove-heading-link", {
  4894. filter: (node) => node.nodeName === "A" && node.getAttribute("aria-hidden") === "true",
  4895. replacement: () => ""
  4896. });
  4897. turndown.addRule("save-math-as-is", {
  4898. filter: (node) => ["SPAN", "DIV"].includes(node.nodeName) && node.matches(".math, .maths, .math-tex"),
  4899. replacement: (_content, node) => node.outerHTML
  4900. });
  4901. function waitForIframeToLoad(iframe) {
  4902. return new Promise((resolve) => {
  4903. var _a2, _b, _c, _d;
  4904. if (iframe.src !== "about:blank") {
  4905. const isSameOrigin = new URL(iframe.src).hostname === window.location.hostname;
  4906. 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") {
  4907. resolve(void 0);
  4908. return;
  4909. }
  4910. }
  4911. console.log("wait for iframe to load...");
  4912. (_d = iframe.contentWindow) == null ? void 0 : _d.addEventListener("load", resolve, {
  4913. once: true
  4914. });
  4915. });
  4916. }
  4917. const playgroundCache = /* @__PURE__ */ new Map();
  4918. async function prefetchPlayground(editorialEl) {
  4919. const iframes = Array.from(editorialEl.querySelectorAll("iframe"));
  4920. const promises = iframes.map(async (iframe) => {
  4921. var _a2, _b;
  4922. await waitForIframeToLoad(iframe);
  4923. const { src, contentDocument } = iframe;
  4924. if (!src.includes("playground")) return;
  4925. console.log((_b = (_a2 = iframe.contentWindow) == null ? void 0 : _a2.location) == null ? void 0 : _b.href);
  4926. const langTab = await findElement("div.lang-btn-set", {
  4927. parent: contentDocument,
  4928. timeout: 1e3
  4929. });
  4930. const textarea = contentDocument == null ? void 0 : contentDocument.querySelector(
  4931. "textarea[name='lc-codemirror']"
  4932. );
  4933. let result = `<MixedCodeBlock>
  4934.  
  4935. `;
  4936. Array.from(
  4937. langTab.children
  4938. ).forEach((button) => {
  4939. var _a3;
  4940. let lang = (_a3 = button.textContent) == null ? void 0 : _a3.toLowerCase();
  4941. if (lang === "python3") lang = "python";
  4942. button.click();
  4943. const code = textarea == null ? void 0 : textarea.textContent;
  4944. result += `\`\`\`${lang}
  4945. ${code}
  4946. \`\`\`
  4947.  
  4948. `;
  4949. });
  4950. result += `</MixedCodeBlock>`;
  4951. playgroundCache.set(src, result);
  4952. });
  4953. await Promise.all(promises);
  4954. }
  4955. turndown.addRule("save-code-playground", {
  4956. filter: ["iframe"],
  4957. replacement: (_content, node) => {
  4958. const { src } = node;
  4959. if (!src.includes("playground")) return "";
  4960. return `[LeetCode Playground](${src})
  4961.  
  4962. ` + (playgroundCache.get(src) ?? "");
  4963. }
  4964. });
  4965. const slideCache = /* @__PURE__ */ new Map();
  4966. async function preFetchSlides(editorialEl) {
  4967. const slideImages = editorialEl.querySelectorAll("img[alt='Current']");
  4968. const promises = Array.from(slideImages).map(async (image) => {
  4969. var _a2, _b, _c;
  4970. const slideContainer = (_a2 = image.parentElement) == null ? void 0 : _a2.parentElement;
  4971. if (!slideContainer) {
  4972. throw new Error("Slide container not found");
  4973. }
  4974. const slideNumIndicator = slideContainer.children[2].children[1];
  4975. slideNumIndicator.setAttribute("data-skip-me-turndown", "true");
  4976. const slidesCountStr = (_c = (_b = slideNumIndicator.textContent) == null ? void 0 : _b.match(/\d+$/)) == null ? void 0 : _c[0];
  4977. if (!slidesCountStr) {
  4978. throw new Error("Slide count not found");
  4979. }
  4980. const nextSlideButton = slideContainer.querySelector("svg:nth-child(3)");
  4981. if (!nextSlideButton) {
  4982. throw new Error("Next slide button not found");
  4983. }
  4984. const firstSlideSrc = image.src;
  4985. slideCache.set(firstSlideSrc, []);
  4986. for (let i2 = 0; i2 < Number(slidesCountStr); i2++) {
  4987. simulateMouseClickReact(nextSlideButton);
  4988. const dataURL = await convertSrcToDataURL(image.src);
  4989. slideCache.get(firstSlideSrc).push(dataURL);
  4990. }
  4991. });
  4992. await Promise.all(promises);
  4993. }
  4994. turndown.addRule("save-slides", {
  4995. filter: (node) => node.tagName === "IMG" && node.alt === "Current",
  4996. replacement: (_content, node) => {
  4997. const { src } = node;
  4998. const dataURLs = slideCache.get(src);
  4999. if (!dataURLs) return "";
  5000. let res = `<Slides>
  5001.  
  5002. `;
  5003. dataURLs.forEach((dataURL, index) => {
  5004. res += `![Slide ${index + 1}](${dataURL})
  5005. `;
  5006. });
  5007. res += `
  5008. </Slides>`;
  5009. return res;
  5010. }
  5011. });
  5012. turndown.addRule("save-details-as-is", {
  5013. filter: ["details"],
  5014. replacement: (_content, node) => {
  5015. const { children } = node;
  5016. [...children].forEach((child2) => {
  5017. if (!child2.textContent) node.removeChild(child2);
  5018. });
  5019. return node.outerHTML;
  5020. }
  5021. });
  5022. turndown.remove(
  5023. (node) => node.getAttribute("data-skip-me-turndown") === "true"
  5024. );
  5025. async function scrapeEditorial(editorialEl) {
  5026. await prefetchPlayground(editorialEl);
  5027. await preFetchSlides(editorialEl);
  5028. const editorial = await htmlToMd(editorialEl, {
  5029. turndownService: turndown
  5030. });
  5031. playgroundCache.clear();
  5032. slideCache.clear();
  5033. return editorial;
  5034. }
  5035. async function downloadEditorial(editorialFinder, titleFinder) {
  5036. toast.promise(
  5037. (async () => {
  5038. const editorialEl = await editorialFinder();
  5039. const editorial = await scrapeEditorial(editorialEl);
  5040. const title = await titleFinder();
  5041. const blob = new Blob([`# ${title}
  5042.  
  5043. `, editorial], {
  5044. type: "text/markdown; charset=UTF-8"
  5045. });
  5046. downloadFile(blob, title, "md");
  5047. })(),
  5048. // svelte-french-toast.promise() doesn't support `()=> Promise` as argument, have to use IIFE here
  5049. {
  5050. loading: "Scraping editorial...",
  5051. success: "Editorial scraped. Downloading...",
  5052. error: "Something went wrong while scraping. See browser console for more detail."
  5053. }
  5054. );
  5055. }
  5056. function Save_editorial($$anchor, $$props) {
  5057. push($$props, false);
  5058. async function findEditorial() {
  5059. const editorialEl = await findElement(".flexlayout__tab:has(#editorial-quick-navigation) div.WRmCx", { timeout: 2e3 });
  5060. return editorialEl;
  5061. }
  5062. init();
  5063. Button($$anchor, {
  5064. onclick: () => downloadEditorial(findEditorial, getTitle),
  5065. variant: "orange",
  5066. children: ($$anchor2, $$slotProps) => {
  5067. var text$1 = text("Save Editorial as Markdown");
  5068. append($$anchor2, text$1);
  5069. },
  5070. $$slots: { default: true }
  5071. });
  5072. pop();
  5073. }
  5074. function Read_saved_editorial($$anchor, $$props) {
  5075. push($$props, false);
  5076. init();
  5077. Button($$anchor, {
  5078. get href() {
  5079. return CONFIG.EDITORIAL_READER_URL;
  5080. },
  5081. variant: "green",
  5082. children: ($$anchor2, $$slotProps) => {
  5083. var text$1 = text("Read Saved Editorial");
  5084. append($$anchor2, text$1);
  5085. },
  5086. $$slots: { default: true }
  5087. });
  5088. pop();
  5089. }
  5090. var root_1$1 = /* @__PURE__ */ from_html(`<!> <!> <!>`, 1);
  5091. function EditorialButtons($$anchor) {
  5092. ButtonGroup($$anchor, {
  5093. style: "z-index: 10; position:relative; padding: 0.5rem",
  5094. children: ($$anchor2, $$slotProps) => {
  5095. var fragment_1 = root_1$1();
  5096. var node = first_child(fragment_1);
  5097. Find_editorial_screenshot(node, {});
  5098. var node_1 = sibling(node, 2);
  5099. Save_editorial(node_1, {});
  5100. var node_2 = sibling(node_1, 2);
  5101. Read_saved_editorial(node_2, {});
  5102. append($$anchor2, fragment_1);
  5103. },
  5104. $$slots: { default: true }
  5105. });
  5106. }
  5107. async function initEditorialTab() {
  5108. const editorialTab = await findElement(
  5109. ".flexlayout__tab:has(div.bg-blocker, #editorial-quick-navigation)",
  5110. {
  5111. timeout: 0,
  5112. additionalRule: (el) => el.style.display !== "none"
  5113. }
  5114. );
  5115. const buttonsContainer = document.createElement("div");
  5116. buttonsContainer.style.cssText = "display: contents;";
  5117. buttonsContainer.setAttribute(
  5118. "id",
  5119. a(CONFIG.APP_NAME) + "-editorial"
  5120. );
  5121. editorialTab.prepend(buttonsContainer);
  5122. mount(EditorialButtons, {
  5123. target: buttonsContainer
  5124. });
  5125. }
  5126. async function main$1() {
  5127. const initPromises = [];
  5128. initPromises.push(problemState.patchMonacoEditor());
  5129. initPromises.push(initDescriptionTab());
  5130. if (globalState.site === "global") {
  5131. initPromises.push(initEditorialTab());
  5132. }
  5133. await Promise.all(initPromises);
  5134. }
  5135. function getElementIndex(element) {
  5136. if (!element.parentNode) throw new Error("Element has no parent node");
  5137. return Array.from(element.parentNode.children).indexOf(element);
  5138. }
  5139. function Save_explore_article($$anchor, $$props) {
  5140. push($$props, false);
  5141. async function findExploreEditorial() {
  5142. return await findElement("div.block-markdown");
  5143. }
  5144. async function getExploreTitle() {
  5145. var _a2, _b;
  5146. const tocContainer = await findElement("div.list-group:not(.item-list-group)");
  5147. const titleContainer = tocContainer.querySelector(".list-group-item .selected");
  5148. if (!titleContainer) {
  5149. throw new Error("Title container not found");
  5150. }
  5151. const title = ((_b = (_a2 = titleContainer.querySelector(".title")) == null ? void 0 : _a2.textContent) == null ? void 0 : _b.trim()) ?? "";
  5152. const articleNumber = getElementIndex(titleContainer) + 1;
  5153. const chapterEl = titleContainer.closest("div.chapter-item");
  5154. if (!chapterEl) {
  5155. throw new Error("Chapter not found");
  5156. }
  5157. const chapterNumber = getElementIndex(chapterEl);
  5158. return `${chapterNumber}.${articleNumber} ${title}`;
  5159. }
  5160. init();
  5161. Button($$anchor, {
  5162. onclick: () => downloadEditorial(findExploreEditorial, getExploreTitle),
  5163. children: ($$anchor2, $$slotProps) => {
  5164. var text$1 = text("Save Article as Markdown");
  5165. append($$anchor2, text$1);
  5166. },
  5167. $$slots: { default: true }
  5168. });
  5169. pop();
  5170. }
  5171. var root_1 = /* @__PURE__ */ from_html(`<!> <!>`, 1);
  5172. function ExploreButtons($$anchor) {
  5173. ButtonGroup($$anchor, {
  5174. children: ($$anchor2, $$slotProps) => {
  5175. var fragment_1 = root_1();
  5176. var node = first_child(fragment_1);
  5177. Save_explore_article(node, {});
  5178. var node_1 = sibling(node, 2);
  5179. Read_saved_editorial(node_1, {});
  5180. append($$anchor2, fragment_1);
  5181. },
  5182. $$slots: { default: true }
  5183. });
  5184. }
  5185. async function main() {
  5186. const toolbar = await findElement("div.left-side", { timeout: 0 });
  5187. const container = document.createElement("div");
  5188. container.style.cssText = "display: contents;";
  5189. toolbar.append(container);
  5190. mount(ExploreButtons, {
  5191. target: container
  5192. });
  5193. }
  5194. mount(Toaster, {
  5195. target: document.body,
  5196. props: { position: "top-center" }
  5197. });
  5198. const url = window.location.href;
  5199. const problemPageRegex = /https?:\/\/leetcode\.com\/problems\/.*|https?:\/\/leetcode\.cn\/problems\/.*/;
  5200. const explorePageRegex = /https?:\/\/leetcode\.com\/explore\/.*\/card\/.*/;
  5201. if (problemPageRegex.test(url)) {
  5202. main$1();
  5203. } else if (explorePageRegex.test(url)) {
  5204. main();
  5205. }
  5206.  
  5207. })(TurndownService, Compressor);