LeetCode Toolkit

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

Mint 2025.05.23.. Lásd a legutóbbi verzió

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