LeetCode工具箱

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

  1. // ==UserScript==
  2. // @name LeetCode Toolkit
  3. // @name:zh-CN LeetCode工具箱
  4. // @namespace https://github.com/eclipher/leetcode-toolkit
  5. // @version 2.7.0
  6. // @author eclipher
  7. // @description Find & Save Editorial, Copy problem as Markdown or Download as Jupyter Notebook, Format on Save, Unlock IntelliSense, Display Problem Ratings and more.
  8. // @description:zh-CN 复制题目为 Markdown | 下载为 Jupyter Notebook | 保存时自动格式化 | 免费自动补全 | 显示题目评分
  9. // @license MIT
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  11. // @homepage https://github.com/eclipher/Userscripts/tree/main/userscripts/leetcode-toolkit
  12. // @include /https?:\/\/leetcode\.com\/problems\/.*/
  13. // @include /https?:\/\/leetcode\.cn\/problems\/.*/
  14. // @include /https?:\/\/leetcode\.com\/explore\/.*\/card\/.*/
  15. // @exclude *://leetcode.com/problems/*/post-solution/*
  16. // @exclude *://leetcode.cn/problems/*/post-solution/*
  17. // @require https://cdn.jsdelivr.net/npm/compressorjs@1.2.1
  18. // @require https://cdn.jsdelivr.net/npm/turndown@7.2.0/lib/turndown.browser.umd.js
  19. // @resource editorials https://raw.githubusercontent.com/akhilkammila/leetcode-screenshotter/refs/heads/main/ReadMe.md
  20. // @resource ratings https://raw.githubusercontent.com/zerotrac/leetcode_problem_rating/refs/heads/main/ratings.txt
  21. // @connect assets.leetcode.com
  22. // @connect *
  23. // @grant GM_addStyle
  24. // @grant GM_getResourceText
  25. // @grant GM_xmlhttpRequest
  26. // @grant unsafeWindow
  27. // @grant window.onurlchange
  28. // ==/UserScript==
  29.  
  30. (t=>{if(typeof GM_addStyle=="function"){GM_addStyle(t);return}const e=document.createElement("style");e.textContent=t,document.head.append(e)})(" .toast-container{inset:unset;border:none;background-color:transparent;overflow:clip;overflow-clip-margin:12px;display:flex;width:100%;max-width:360px;interpolate-size:allow-keywords;transition:.5s cubic-bezier(.215,.61,.355,1);transition-property:transform,translate;--space-to-screen: 20px}.toast-container.top{transform:translateY(var(--space-to-screen));flex-direction:column;--toast-initial-transform: translateY(-100%)}.toast-container.bottom{transform:translateY(calc(100vh - 100%));flex-direction:column-reverse;--toast-initial-transform: translateY(100%)}.toast-container.left{translate:calc(0% + var(--space-to-screen))}.toast-container.center{translate:calc(50vw - 50%)}.toast-container.right{translate:calc(100vw - 100% - var(--space-to-screen))}.toast{opacity:0;transition:all .5s cubic-bezier(.215,.61,.355,1);transform:var(--toast-initial-transform);height:0;overflow:hidden;margin-bottom:0;filter:blur(10px)}.toast.visible{opacity:1;transform:translateY(0);height:auto;filter:none;margin-bottom:12px}.toast[data-styled=true]{display:flex;align-items:center;gap:12px;background-color:#fff;border-radius:8px;box-shadow:0 4px 12px #00000026;border-left:4px solid var(--accent-color)}.toast[data-styled=true].visible{padding:16px}.toast[data-styled=true] .toast-icon{font-size:1.75rem;color:var(--accent-color)}.toast[data-styled=true] .toast-title{color:var(--accent-color);font-weight:600;font-size:1.125rem}.toast[data-styled=true] .toast-message{color:#333}.toast[data-styled=true] .toast-close{background:none;border:none;color:#999;cursor:pointer;font-size:1.25rem;padding:0;line-height:1}.toast-content{flex-grow:1}.toast.success{--accent-color: #4caf50}.toast.error{--accent-color: #f44336}.toast.info{--accent-color: #2196f3}.toast.warning{--accent-color: #ff9800}.toast.loading{--accent-color: #000000}.toast.loading>.toast-icon{animation:spin 1s linear infinite}@keyframes spin{to{transform:rotate(360deg)}}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%} ");
  31.  
  32. (function (TurndownService, Compressor) {
  33. 'use strict';
  34.  
  35. var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
  36. var __defProp = Object.defineProperty;
  37. var __typeError = (msg) => {
  38. throw TypeError(msg);
  39. };
  40. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  41. var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  42. var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
  43. var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
  44. 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);
  45. var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
  46. var _site, _a, _cells, _metadata, _nbformat, _nbformat_minor;
  47. class GlobalState {
  48. constructor() {
  49. __privateAdd(this, _site);
  50. }
  51. get site() {
  52. if (!__privateGet(this, _site)) {
  53. const hostname = window.location.hostname;
  54. __privateSet(this, _site, hostname === "leetcode.cn" ? "cn" : "global");
  55. }
  56. return __privateGet(this, _site);
  57. }
  58. }
  59. _site = new WeakMap();
  60. const globalState = new GlobalState();
  61. var _GM_getResourceText = /* @__PURE__ */ (() => typeof GM_getResourceText != "undefined" ? GM_getResourceText : void 0)();
  62. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  63. var _monkeyWindow = /* @__PURE__ */ (() => window)();
  64. class TimeoutError extends Error {
  65. constructor(item, timeout) {
  66. super();
  67. __publicField(this, "name", this.constructor.name);
  68. this.message = `"${item}" not found within timeout (${timeout}ms)`;
  69. }
  70. }
  71. function find(finderFn, {
  72. subject = document,
  73. observerOption = {
  74. childList: true,
  75. subtree: true
  76. },
  77. timeout = 5e3,
  78. itemName = "Item"
  79. }) {
  80. return new Promise((resolve, reject) => {
  81. const item = finderFn();
  82. if (item) return resolve(item);
  83. let timeoutId;
  84. const observer = new MutationObserver(() => {
  85. const item2 = finderFn();
  86. if (item2) {
  87. observer.disconnect();
  88. clearTimeout(timeoutId);
  89. return resolve(item2);
  90. }
  91. });
  92. observer.observe(subject, observerOption);
  93. if (timeout > 0) {
  94. timeoutId = setTimeout(() => {
  95. observer.disconnect();
  96. const error = new TimeoutError(itemName, timeout);
  97. console.error(error);
  98. return reject(error);
  99. }, timeout);
  100. }
  101. });
  102. }
  103. async function findElement(selector, {
  104. parent = document,
  105. timeout = 500,
  106. additionalRule
  107. } = {}) {
  108. const element = await find(
  109. () => {
  110. const el = parent.querySelector(selector);
  111. if (additionalRule && el) {
  112. return additionalRule(el) ? el : null;
  113. } else {
  114. return el;
  115. }
  116. },
  117. {
  118. subject: parent,
  119. timeout,
  120. itemName: `Element ${selector}`
  121. }
  122. );
  123. return element;
  124. }
  125. const overrideOptions = {
  126. selectionHighlight: true,
  127. parameterHints: { enabled: true },
  128. hover: { enabled: true },
  129. quickSuggestions: true,
  130. suggestOnTriggerCharacters: true,
  131. "bracketPairColorization.enabled": true
  132. };
  133. function addIntellisense(editor) {
  134. const originalUpdateOptions = editor.updateOptions.bind(editor);
  135. editor.updateOptions = (options) => {
  136. originalUpdateOptions({
  137. ...options,
  138. ...overrideOptions
  139. });
  140. };
  141. }
  142. async function findMonacoEditor() {
  143. function getEditor() {
  144. var _a2;
  145. return ((_a2 = _unsafeWindow.monaco) == null ? void 0 : _a2.editor.getEditors()[0]) ?? null;
  146. }
  147. const editor = find(getEditor, {
  148. subject: document.head,
  149. observerOption: { childList: true },
  150. itemName: "Monaco Editor"
  151. });
  152. return editor;
  153. }
  154. var C = Object.defineProperty;
  155. var x = (s) => {
  156. throw TypeError(s);
  157. };
  158. var B = (s, e2, t) => e2 in s ? C(s, e2, { enumerable: true, configurable: true, writable: true, value: t }) : s[e2] = t;
  159. var w = (s, e2, t) => B(s, typeof e2 != "symbol" ? e2 + "" : e2, t), m = (s, e2, t) => e2.has(s) || x("Cannot " + t);
  160. var l = (s, e2, t) => (m(s, e2, "read from private field"), t ? t.call(s) : e2.get(s)), p = (s, e2, t) => e2.has(s) ? x("Cannot add the same private member more than once") : e2 instanceof WeakSet ? e2.add(s) : e2.set(s, t), y$1 = (s, e2, t, i2) => (m(s, e2, "write to private field"), e2.set(s, t), t), n = (s, e2, t) => (m(s, e2, "access private method"), t);
  161. const M$1 = {
  162. success: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-check-icon lucide-circle-check"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',
  163. error: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-x-icon lucide-circle-x"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',
  164. info: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-info-icon lucide-info"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>',
  165. warning: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-alert-icon lucide-circle-alert"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>',
  166. loading: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-loader-circle-icon lucide-loader-circle"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
  167. close: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'
  168. };
  169. function f(s, e2) {
  170. return typeof s == "function" ? s(e2) : s;
  171. }
  172. var r$1, o$2, T, $, v$1, b, k$1, d;
  173. class L {
  174. constructor(e2) {
  175. p(this, o$2);
  176. w(this, "defaultOptions", {
  177. durationMs: 3e3,
  178. dismissible: true,
  179. position: "top-right"
  180. });
  181. p(this, r$1);
  182. w(this, "toastTimeoutMap", /* @__PURE__ */ new Map());
  183. w(this, "count", 0);
  184. this.defaultOptions = { ...this.defaultOptions, ...e2 }, y$1(this, r$1, n(this, o$2, $).call(this)), this.changePosition(this.defaultOptions.position);
  185. }
  186. changePosition(e2) {
  187. l(this, r$1).className = `toast-container ${e2.replace("-", " ")}`;
  188. }
  189. isEmpty() {
  190. return l(this, r$1).children.length === 0;
  191. }
  192. dismissAll() {
  193. this.toastTimeoutMap.forEach((e2, t) => this.dismiss(t)), this.toastTimeoutMap.clear(), l(this, r$1).innerHTML = "";
  194. }
  195. // Function to hide and remove a toast
  196. dismiss(e2) {
  197. const t = n(this, o$2, v$1).call(this, e2);
  198. if (!t) {
  199. console.error("No toast found to dismiss");
  200. return;
  201. }
  202. const i2 = this.toastTimeoutMap.get(e2);
  203. i2 && (clearTimeout(i2), this.toastTimeoutMap.delete(e2)), t.classList.remove("visible"), t.addEventListener("transitionend", () => t.remove(), {
  204. once: true
  205. });
  206. }
  207. // public-facing method with `message` as first argument
  208. toast(e2, t = {}) {
  209. return n(this, o$2, k$1).call(this, { ...t, message: e2 });
  210. }
  211. success(e2, t) {
  212. return n(this, o$2, d).call(this, "success", { ...t, message: e2 });
  213. }
  214. error(e2, t) {
  215. return n(this, o$2, d).call(this, "error", { ...t, message: e2 });
  216. }
  217. info(e2, t) {
  218. return n(this, o$2, d).call(this, "info", { ...t, message: e2 });
  219. }
  220. warning(e2, t) {
  221. return n(this, o$2, d).call(this, "warning", { ...t, message: e2 });
  222. }
  223. /** Render a toast of "loading" type. By default, this kind of toast will stay on screen forever and cannot be dismissed by user. You can either:
  224. * - Programmatically remove it via `toaster.remove()`.
  225. * - Or explicitly pass `dismissible` and `duration` to override the default option. */
  226. loading(e2, t) {
  227. return n(this, o$2, d).call(this, "loading", {
  228. durationMs: 1 / 0,
  229. dismissible: false,
  230. ...t,
  231. message: e2
  232. });
  233. }
  234. /**
  235. * A convenience method to handle promises with toast notifications.
  236. * @param promise - The promise to handle, or a function that returns a promise.
  237. * @param handlers - An object containing loading, success, and error messages, as well as an optional finally callback.
  238. * @param options - Additional options for the toast.
  239. * @returns The ID of the toast.
  240. */
  241. async promise(e2, t, i2 = {}) {
  242. var u2;
  243. const c2 = this.loading(t.loading, {
  244. durationMs: 1 / 0,
  245. // Keep the loading toast on screen indefinitely until resolved (in case user specifies `durationMs`)
  246. ...i2
  247. }), h = f(e2);
  248. try {
  249. const a2 = await h, g2 = f(t.success, a2);
  250. this.success(g2, { id: c2, ...i2 });
  251. } catch (a2) {
  252. const g2 = f(t.error, a2);
  253. this.error(g2, { id: c2, ...i2 });
  254. } finally {
  255. (u2 = t.finally) == null || u2.call(t);
  256. }
  257. return c2;
  258. }
  259. }
  260. r$1 = /* @__PURE__ */ new WeakMap(), o$2 = /* @__PURE__ */ new WeakSet(), T = function() {
  261. return this.count++, `toast-${this.count};`;
  262. }, $ = function() {
  263. const e2 = document.getElementById("toast-rack");
  264. if (e2)
  265. return console.warn(
  266. "Toaster container already exists. Using the existing one."
  267. ), e2;
  268. const t = document.createElement("div");
  269. return t.id = "toast-rack", t.popover = "manual", document.body.append(t), t.showPopover(), t;
  270. }, v$1 = function(e2) {
  271. return l(this, r$1).children.namedItem(e2);
  272. }, /**
  273. * Get or create a toast element by id.
  274. * If no id is given, or the toast with the given id does not exist, it will create a new one.
  275. * @param id - The id of the toast to get or create.
  276. * @returns The toast element with a defined id.
  277. */
  278. b = function(e2) {
  279. if (e2) {
  280. const i2 = n(this, o$2, v$1).call(this, e2);
  281. if (i2)
  282. return delete i2.dataset.isNew, i2;
  283. console.warn(`Toast with id ${e2} not found, creating a new one.`);
  284. }
  285. const t = document.createElement("article");
  286. return t.id = n(this, o$2, T).call(this), t.dataset.isNew = "true", t;
  287. }, // The main function to create and show a toast
  288. k$1 = function(e2) {
  289. var c2, h, u2, a2;
  290. const t = {
  291. ...this.defaultOptions,
  292. ...e2,
  293. message: e2.message || ""
  294. }, i2 = n(this, o$2, b).call(this, t.id);
  295. return i2.innerHTML = `
  296. ${t.type ? `<div class="toast-icon">${M$1[t.type]}</div>` : ""}
  297. <div class="toast-content">
  298. ${t.title ? `<p class="toast-title ${((c2 = t.classes) == null ? void 0 : c2.title) || ""}">${t.title}</p>` : ""}
  299. <p class="toast-message ${((h = t.classes) == null ? void 0 : h.message) || ""}">${t.message}</p>
  300. </div>
  301. ${t.dismissible ? `<button class="toast-close ${((u2 = t.classes) == null ? void 0 : u2.close) || ""}">${M$1.close}</button>` : ""}
  302. `, i2.className = `toast ${t.type || ""} ${((a2 = t.classes) == null ? void 0 : a2.toast) || ""} `, i2.style.cssText = t.style || "", i2.dataset.styled = t.unstyled ? "false" : "true", l(this, r$1).append(i2), i2.dataset.isNew ? setTimeout(() => i2.classList.add("visible"), 0) : i2.classList.add("visible"), t.durationMs !== 1 / 0 && (clearTimeout(this.toastTimeoutMap.get(i2.id)), this.toastTimeoutMap.set(
  303. i2.id,
  304. setTimeout(() => this.dismiss(i2.id), t.durationMs)
  305. )), t.dismissible && i2.querySelector(".toast-close").addEventListener(
  306. "click",
  307. () => this.dismiss(i2.id)
  308. ), i2.id;
  309. }, d = function(e2, t) {
  310. return n(this, o$2, k$1).call(this, {
  311. ...t,
  312. type: e2,
  313. title: t.title ?? this.defaultOptions.title ?? e2[0].toUpperCase() + e2.slice(1)
  314. });
  315. };
  316. const CONFIG = {
  317. APP_NAME: "LeetCode Toolkit",
  318. EDITORIAL_READER_URL: "https://leetcode-editorial-reader.vercel.app"
  319. };
  320. const toaster = new L({
  321. title: CONFIG.APP_NAME,
  322. position: "top-center"
  323. });
  324. class ProblemPageState {
  325. constructor() {
  326. __publicField(this, "editor", null);
  327. }
  328. async patchMonacoEditor() {
  329. this.editor = await findMonacoEditor();
  330. this.enableFormatOnSave();
  331. addIntellisense(this.editor);
  332. }
  333. enableFormatOnSave() {
  334. document.addEventListener("keydown", async (e2) => {
  335. var _a2, _b;
  336. if (!(e2.ctrlKey && e2.key === "s")) return;
  337. try {
  338. await ((_b = (_a2 = this.editor) == null ? void 0 : _a2.getAction("editor.action.formatDocument")) == null ? void 0 : _b.run());
  339. } catch (err) {
  340. console.error(err);
  341. if (err instanceof Error) {
  342. toaster.error("Failed to format code:" + err.message);
  343. }
  344. }
  345. });
  346. }
  347. }
  348. const problemState = new ProblemPageState();
  349. function u$1(o2, n2, a2) {
  350. let t = (r2) => o2(r2, ...n2);
  351. return t;
  352. }
  353. function u(r2, n2, o2) {
  354. let a2 = r2.length - n2.length;
  355. if (a2 === 0) return r2(...n2);
  356. if (a2 === 1) return u$1(r2, n2);
  357. throw new Error("Wrong number of arguments");
  358. }
  359. var o$1 = [" ", `
  360. `, "\v", "\f", "\r", " ", "…", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "\u2028", "\u2029", " ", " ", " ", "\uFEFF"], c = /* @__PURE__ */ new Set(["-", "_", ...o$1]), i = (r2) => {
  361. let e2 = [], t = "", u2 = () => {
  362. t.length > 0 && (e2.push(t), t = "");
  363. };
  364. for (let s of r2) {
  365. if (c.has(s)) {
  366. u2();
  367. continue;
  368. }
  369. if (/[a-z]$/u.test(t) && /[A-Z]/u.test(s)) u2();
  370. else if (/[A-Z][A-Z]$/u.test(t) && /[a-z]/u.test(s)) {
  371. let n2 = t.slice(-1);
  372. t = t.slice(0, -1), u2(), t = n2;
  373. } else /\d$/u.test(t) !== /\d/u.test(s) && u2();
  374. t += s;
  375. }
  376. return u2(), e2;
  377. };
  378. function a(...e2) {
  379. return u(o, e2);
  380. }
  381. var o = (e2) => i(e2).join("-").toLowerCase();
  382. function e(o2) {
  383. return o2 instanceof Promise;
  384. }
  385. const DEV = false;
  386. var is_array = Array.isArray;
  387. var index_of = Array.prototype.indexOf;
  388. var array_from = Array.from;
  389. var define_property = Object.defineProperty;
  390. var get_descriptor = Object.getOwnPropertyDescriptor;
  391. var get_descriptors = Object.getOwnPropertyDescriptors;
  392. var object_prototype = Object.prototype;
  393. var array_prototype = Array.prototype;
  394. var get_prototype_of = Object.getPrototypeOf;
  395. var is_extensible = Object.isExtensible;
  396. const noop = () => {
  397. };
  398. function run(fn) {
  399. return fn();
  400. }
  401. function run_all(arr) {
  402. for (var i2 = 0; i2 < arr.length; i2++) {
  403. arr[i2]();
  404. }
  405. }
  406. const DERIVED = 1 << 1;
  407. const EFFECT = 1 << 2;
  408. const RENDER_EFFECT = 1 << 3;
  409. const BLOCK_EFFECT = 1 << 4;
  410. const BRANCH_EFFECT = 1 << 5;
  411. const ROOT_EFFECT = 1 << 6;
  412. const BOUNDARY_EFFECT = 1 << 7;
  413. const UNOWNED = 1 << 8;
  414. const DISCONNECTED = 1 << 9;
  415. const CLEAN = 1 << 10;
  416. const DIRTY = 1 << 11;
  417. const MAYBE_DIRTY = 1 << 12;
  418. const INERT = 1 << 13;
  419. const DESTROYED = 1 << 14;
  420. const EFFECT_RAN = 1 << 15;
  421. const EFFECT_TRANSPARENT = 1 << 16;
  422. const INSPECT_EFFECT = 1 << 18;
  423. const HEAD_EFFECT = 1 << 19;
  424. const EFFECT_HAS_DERIVED = 1 << 20;
  425. const EFFECT_IS_UPDATING = 1 << 21;
  426. const STATE_SYMBOL = Symbol("$state");
  427. const LOADING_ATTR_SYMBOL = Symbol("");
  428. function equals(value) {
  429. return value === this.v;
  430. }
  431. function effect_in_teardown(rune) {
  432. {
  433. throw new Error(`https://svelte.dev/e/effect_in_teardown`);
  434. }
  435. }
  436. function effect_in_unowned_derived() {
  437. {
  438. throw new Error(`https://svelte.dev/e/effect_in_unowned_derived`);
  439. }
  440. }
  441. function effect_orphan(rune) {
  442. {
  443. throw new Error(`https://svelte.dev/e/effect_orphan`);
  444. }
  445. }
  446. function effect_update_depth_exceeded() {
  447. {
  448. throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);
  449. }
  450. }
  451. function state_descriptors_fixed() {
  452. {
  453. throw new Error(`https://svelte.dev/e/state_descriptors_fixed`);
  454. }
  455. }
  456. function state_prototype_fixed() {
  457. {
  458. throw new Error(`https://svelte.dev/e/state_prototype_fixed`);
  459. }
  460. }
  461. function state_unsafe_mutation() {
  462. {
  463. throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
  464. }
  465. }
  466. let legacy_mode_flag = false;
  467. let tracing_mode_flag = false;
  468. function enable_legacy_mode_flag() {
  469. legacy_mode_flag = true;
  470. }
  471. const TEMPLATE_FRAGMENT = 1;
  472. const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
  473. const UNINITIALIZED = Symbol();
  474. const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
  475. const ATTACHMENT_KEY = "@attach";
  476. let component_context = null;
  477. function set_component_context(context) {
  478. component_context = context;
  479. }
  480. function push(props, runes = false, fn) {
  481. var ctx = component_context = {
  482. p: component_context,
  483. c: null,
  484. d: false,
  485. e: null,
  486. m: false,
  487. s: props,
  488. x: null,
  489. l: null
  490. };
  491. if (legacy_mode_flag && !runes) {
  492. component_context.l = {
  493. s: null,
  494. u: null,
  495. r1: [],
  496. r2: source(false)
  497. };
  498. }
  499. teardown(() => {
  500. ctx.d = true;
  501. });
  502. }
  503. function pop(component) {
  504. const context_stack_item = component_context;
  505. if (context_stack_item !== null) {
  506. const component_effects = context_stack_item.e;
  507. if (component_effects !== null) {
  508. var previous_effect = active_effect;
  509. var previous_reaction = active_reaction;
  510. context_stack_item.e = null;
  511. try {
  512. for (var i2 = 0; i2 < component_effects.length; i2++) {
  513. var component_effect = component_effects[i2];
  514. set_active_effect(component_effect.effect);
  515. set_active_reaction(component_effect.reaction);
  516. effect(component_effect.fn);
  517. }
  518. } finally {
  519. set_active_effect(previous_effect);
  520. set_active_reaction(previous_reaction);
  521. }
  522. }
  523. component_context = context_stack_item.p;
  524. context_stack_item.m = true;
  525. }
  526. return (
  527. /** @type {T} */
  528. {}
  529. );
  530. }
  531. function is_runes() {
  532. return !legacy_mode_flag || component_context !== null && component_context.l === null;
  533. }
  534. function proxy(value) {
  535. if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
  536. return value;
  537. }
  538. const prototype = get_prototype_of(value);
  539. if (prototype !== object_prototype && prototype !== array_prototype) {
  540. return value;
  541. }
  542. var sources = /* @__PURE__ */ new Map();
  543. var is_proxied_array = is_array(value);
  544. var version = /* @__PURE__ */ state(0);
  545. var reaction = active_reaction;
  546. var with_parent = (fn) => {
  547. var previous_reaction = active_reaction;
  548. set_active_reaction(reaction);
  549. var result = fn();
  550. set_active_reaction(previous_reaction);
  551. return result;
  552. };
  553. if (is_proxied_array) {
  554. sources.set("length", /* @__PURE__ */ state(
  555. /** @type {any[]} */
  556. value.length
  557. ));
  558. }
  559. return new Proxy(
  560. /** @type {any} */
  561. value,
  562. {
  563. defineProperty(_, prop2, descriptor) {
  564. if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
  565. state_descriptors_fixed();
  566. }
  567. var s = sources.get(prop2);
  568. if (s === void 0) {
  569. s = with_parent(() => {
  570. var s2 = /* @__PURE__ */ state(descriptor.value);
  571. sources.set(prop2, s2);
  572. return s2;
  573. });
  574. } else {
  575. set(s, descriptor.value, true);
  576. }
  577. return true;
  578. },
  579. deleteProperty(target, prop2) {
  580. var s = sources.get(prop2);
  581. if (s === void 0) {
  582. if (prop2 in target) {
  583. const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
  584. sources.set(prop2, s2);
  585. update_version(version);
  586. }
  587. } else {
  588. if (is_proxied_array && typeof prop2 === "string") {
  589. var ls = (
  590. /** @type {Source<number>} */
  591. sources.get("length")
  592. );
  593. var n2 = Number(prop2);
  594. if (Number.isInteger(n2) && n2 < ls.v) {
  595. set(ls, n2);
  596. }
  597. }
  598. set(s, UNINITIALIZED);
  599. update_version(version);
  600. }
  601. return true;
  602. },
  603. get(target, prop2, receiver) {
  604. var _a2;
  605. if (prop2 === STATE_SYMBOL) {
  606. return value;
  607. }
  608. var s = sources.get(prop2);
  609. var exists = prop2 in target;
  610. if (s === void 0 && (!exists || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  611. s = with_parent(() => {
  612. var p2 = proxy(exists ? target[prop2] : UNINITIALIZED);
  613. var s2 = /* @__PURE__ */ state(p2);
  614. return s2;
  615. });
  616. sources.set(prop2, s);
  617. }
  618. if (s !== void 0) {
  619. var v2 = get(s);
  620. return v2 === UNINITIALIZED ? void 0 : v2;
  621. }
  622. return Reflect.get(target, prop2, receiver);
  623. },
  624. getOwnPropertyDescriptor(target, prop2) {
  625. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  626. if (descriptor && "value" in descriptor) {
  627. var s = sources.get(prop2);
  628. if (s) descriptor.value = get(s);
  629. } else if (descriptor === void 0) {
  630. var source2 = sources.get(prop2);
  631. var value2 = source2 == null ? void 0 : source2.v;
  632. if (source2 !== void 0 && value2 !== UNINITIALIZED) {
  633. return {
  634. enumerable: true,
  635. configurable: true,
  636. value: value2,
  637. writable: true
  638. };
  639. }
  640. }
  641. return descriptor;
  642. },
  643. has(target, prop2) {
  644. var _a2;
  645. if (prop2 === STATE_SYMBOL) {
  646. return true;
  647. }
  648. var s = sources.get(prop2);
  649. var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop2);
  650. if (s !== void 0 || active_effect !== null && (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable))) {
  651. if (s === void 0) {
  652. s = with_parent(() => {
  653. var p2 = has ? proxy(target[prop2]) : UNINITIALIZED;
  654. var s2 = /* @__PURE__ */ state(p2);
  655. return s2;
  656. });
  657. sources.set(prop2, s);
  658. }
  659. var value2 = get(s);
  660. if (value2 === UNINITIALIZED) {
  661. return false;
  662. }
  663. }
  664. return has;
  665. },
  666. set(target, prop2, value2, receiver) {
  667. var _a2;
  668. var s = sources.get(prop2);
  669. var has = prop2 in target;
  670. if (is_proxied_array && prop2 === "length") {
  671. for (var i2 = value2; i2 < /** @type {Source<number>} */
  672. s.v; i2 += 1) {
  673. var other_s = sources.get(i2 + "");
  674. if (other_s !== void 0) {
  675. set(other_s, UNINITIALIZED);
  676. } else if (i2 in target) {
  677. other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
  678. sources.set(i2 + "", other_s);
  679. }
  680. }
  681. }
  682. if (s === void 0) {
  683. if (!has || ((_a2 = get_descriptor(target, prop2)) == null ? void 0 : _a2.writable)) {
  684. s = with_parent(() => /* @__PURE__ */ state(void 0));
  685. set(s, proxy(value2));
  686. sources.set(prop2, s);
  687. }
  688. } else {
  689. has = s.v !== UNINITIALIZED;
  690. var p2 = with_parent(() => proxy(value2));
  691. set(s, p2);
  692. }
  693. var descriptor = Reflect.getOwnPropertyDescriptor(target, prop2);
  694. if (descriptor == null ? void 0 : descriptor.set) {
  695. descriptor.set.call(receiver, value2);
  696. }
  697. if (!has) {
  698. if (is_proxied_array && typeof prop2 === "string") {
  699. var ls = (
  700. /** @type {Source<number>} */
  701. sources.get("length")
  702. );
  703. var n2 = Number(prop2);
  704. if (Number.isInteger(n2) && n2 >= ls.v) {
  705. set(ls, n2 + 1);
  706. }
  707. }
  708. update_version(version);
  709. }
  710. return true;
  711. },
  712. ownKeys(target) {
  713. get(version);
  714. var own_keys = Reflect.ownKeys(target).filter((key2) => {
  715. var source3 = sources.get(key2);
  716. return source3 === void 0 || source3.v !== UNINITIALIZED;
  717. });
  718. for (var [key, source2] of sources) {
  719. if (source2.v !== UNINITIALIZED && !(key in target)) {
  720. own_keys.push(key);
  721. }
  722. }
  723. return own_keys;
  724. },
  725. setPrototypeOf() {
  726. state_prototype_fixed();
  727. }
  728. }
  729. );
  730. }
  731. function update_version(signal, d2 = 1) {
  732. set(signal, signal.v + d2);
  733. }
  734. function get_proxied_value(value) {
  735. try {
  736. if (value !== null && typeof value === "object" && STATE_SYMBOL in value) {
  737. return value[STATE_SYMBOL];
  738. }
  739. } catch {
  740. }
  741. return value;
  742. }
  743. function is(a2, b2) {
  744. return Object.is(get_proxied_value(a2), get_proxied_value(b2));
  745. }
  746. // @__NO_SIDE_EFFECTS__
  747. function derived(fn) {
  748. var flags = DERIVED | DIRTY;
  749. var parent_derived = active_reaction !== null && (active_reaction.f & DERIVED) !== 0 ? (
  750. /** @type {Derived} */
  751. active_reaction
  752. ) : null;
  753. if (active_effect === null || parent_derived !== null && (parent_derived.f & UNOWNED) !== 0) {
  754. flags |= UNOWNED;
  755. } else {
  756. active_effect.f |= EFFECT_HAS_DERIVED;
  757. }
  758. const signal = {
  759. ctx: component_context,
  760. deps: null,
  761. effects: null,
  762. equals,
  763. f: flags,
  764. fn,
  765. reactions: null,
  766. rv: 0,
  767. v: (
  768. /** @type {V} */
  769. null
  770. ),
  771. wv: 0,
  772. parent: parent_derived ?? active_effect
  773. };
  774. return signal;
  775. }
  776. function destroy_derived_effects(derived2) {
  777. var effects = derived2.effects;
  778. if (effects !== null) {
  779. derived2.effects = null;
  780. for (var i2 = 0; i2 < effects.length; i2 += 1) {
  781. destroy_effect(
  782. /** @type {Effect} */
  783. effects[i2]
  784. );
  785. }
  786. }
  787. }
  788. function get_derived_parent_effect(derived2) {
  789. var parent = derived2.parent;
  790. while (parent !== null) {
  791. if ((parent.f & DERIVED) === 0) {
  792. return (
  793. /** @type {Effect} */
  794. parent
  795. );
  796. }
  797. parent = parent.parent;
  798. }
  799. return null;
  800. }
  801. function execute_derived(derived2) {
  802. var value;
  803. var prev_active_effect = active_effect;
  804. set_active_effect(get_derived_parent_effect(derived2));
  805. {
  806. try {
  807. destroy_derived_effects(derived2);
  808. value = update_reaction(derived2);
  809. } finally {
  810. set_active_effect(prev_active_effect);
  811. }
  812. }
  813. return value;
  814. }
  815. function update_derived(derived2) {
  816. var value = execute_derived(derived2);
  817. if (!derived2.equals(value)) {
  818. derived2.v = value;
  819. derived2.wv = increment_write_version();
  820. }
  821. if (is_destroying_effect) return;
  822. var status = (skip_reaction || (derived2.f & UNOWNED) !== 0) && derived2.deps !== null ? MAYBE_DIRTY : CLEAN;
  823. set_signal_status(derived2, status);
  824. }
  825. const old_values = /* @__PURE__ */ new Map();
  826. function source(v2, stack) {
  827. var signal = {
  828. f: 0,
  829. // TODO ideally we could skip this altogether, but it causes type errors
  830. v: v2,
  831. reactions: null,
  832. equals,
  833. rv: 0,
  834. wv: 0
  835. };
  836. return signal;
  837. }
  838. // @__NO_SIDE_EFFECTS__
  839. function state(v2, stack) {
  840. const s = source(v2);
  841. push_reaction_value(s);
  842. return s;
  843. }
  844. function set(source2, value, should_proxy = false) {
  845. if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
  846. // to ensure we error if state is set inside an inspect effect
  847. (!untracking || (active_reaction.f & INSPECT_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | INSPECT_EFFECT)) !== 0 && !((reaction_sources == null ? void 0 : reaction_sources[1].includes(source2)) && reaction_sources[0] === active_reaction)) {
  848. state_unsafe_mutation();
  849. }
  850. let new_value = should_proxy ? proxy(value) : value;
  851. return internal_set(source2, new_value);
  852. }
  853. function internal_set(source2, value) {
  854. if (!source2.equals(value)) {
  855. var old_value = source2.v;
  856. if (is_destroying_effect) {
  857. old_values.set(source2, value);
  858. } else {
  859. old_values.set(source2, old_value);
  860. }
  861. source2.v = value;
  862. if ((source2.f & DERIVED) !== 0) {
  863. if ((source2.f & DIRTY) !== 0) {
  864. execute_derived(
  865. /** @type {Derived} */
  866. source2
  867. );
  868. }
  869. set_signal_status(source2, (source2.f & UNOWNED) === 0 ? CLEAN : MAYBE_DIRTY);
  870. }
  871. source2.wv = increment_write_version();
  872. mark_reactions(source2, DIRTY);
  873. if (is_runes() && active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
  874. if (untracked_writes === null) {
  875. set_untracked_writes([source2]);
  876. } else {
  877. untracked_writes.push(source2);
  878. }
  879. }
  880. }
  881. return value;
  882. }
  883. function mark_reactions(signal, status) {
  884. var reactions = signal.reactions;
  885. if (reactions === null) return;
  886. var runes = is_runes();
  887. var length = reactions.length;
  888. for (var i2 = 0; i2 < length; i2++) {
  889. var reaction = reactions[i2];
  890. var flags = reaction.f;
  891. if ((flags & DIRTY) !== 0) continue;
  892. if (!runes && reaction === active_effect) continue;
  893. set_signal_status(reaction, status);
  894. if ((flags & (CLEAN | UNOWNED)) !== 0) {
  895. if ((flags & DERIVED) !== 0) {
  896. mark_reactions(
  897. /** @type {Derived} */
  898. reaction,
  899. MAYBE_DIRTY
  900. );
  901. } else {
  902. schedule_effect(
  903. /** @type {Effect} */
  904. reaction
  905. );
  906. }
  907. }
  908. }
  909. }
  910. function select_multiple_invalid_value() {
  911. {
  912. console.warn(`https://svelte.dev/e/select_multiple_invalid_value`);
  913. }
  914. }
  915. var $window;
  916. var is_firefox;
  917. var first_child_getter;
  918. var next_sibling_getter;
  919. function init_operations() {
  920. if ($window !== void 0) {
  921. return;
  922. }
  923. $window = window;
  924. is_firefox = /Firefox/.test(navigator.userAgent);
  925. var element_prototype = Element.prototype;
  926. var node_prototype = Node.prototype;
  927. var text_prototype = Text.prototype;
  928. first_child_getter = get_descriptor(node_prototype, "firstChild").get;
  929. next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
  930. if (is_extensible(element_prototype)) {
  931. element_prototype.__click = void 0;
  932. element_prototype.__className = void 0;
  933. element_prototype.__attributes = null;
  934. element_prototype.__style = void 0;
  935. element_prototype.__e = void 0;
  936. }
  937. if (is_extensible(text_prototype)) {
  938. text_prototype.__t = void 0;
  939. }
  940. }
  941. function create_text(value = "") {
  942. return document.createTextNode(value);
  943. }
  944. // @__NO_SIDE_EFFECTS__
  945. function get_first_child(node) {
  946. return first_child_getter.call(node);
  947. }
  948. // @__NO_SIDE_EFFECTS__
  949. function get_next_sibling(node) {
  950. return next_sibling_getter.call(node);
  951. }
  952. function child(node, is_text) {
  953. {
  954. return /* @__PURE__ */ get_first_child(node);
  955. }
  956. }
  957. function first_child(fragment, is_text) {
  958. {
  959. var first = (
  960. /** @type {DocumentFragment} */
  961. /* @__PURE__ */ get_first_child(
  962. /** @type {Node} */
  963. fragment
  964. )
  965. );
  966. if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
  967. return first;
  968. }
  969. }
  970. function sibling(node, count = 1, is_text = false) {
  971. let next_sibling = node;
  972. while (count--) {
  973. next_sibling = /** @type {TemplateNode} */
  974. /* @__PURE__ */ get_next_sibling(next_sibling);
  975. }
  976. {
  977. return next_sibling;
  978. }
  979. }
  980. function validate_effect(rune) {
  981. if (active_effect === null && active_reaction === null) {
  982. effect_orphan();
  983. }
  984. if (active_reaction !== null && (active_reaction.f & UNOWNED) !== 0 && active_effect === null) {
  985. effect_in_unowned_derived();
  986. }
  987. if (is_destroying_effect) {
  988. effect_in_teardown();
  989. }
  990. }
  991. function push_effect(effect2, parent_effect) {
  992. var parent_last = parent_effect.last;
  993. if (parent_last === null) {
  994. parent_effect.last = parent_effect.first = effect2;
  995. } else {
  996. parent_last.next = effect2;
  997. effect2.prev = parent_last;
  998. parent_effect.last = effect2;
  999. }
  1000. }
  1001. function create_effect(type, fn, sync, push2 = true) {
  1002. var parent = active_effect;
  1003. var effect2 = {
  1004. ctx: component_context,
  1005. deps: null,
  1006. nodes_start: null,
  1007. nodes_end: null,
  1008. f: type | DIRTY,
  1009. first: null,
  1010. fn,
  1011. last: null,
  1012. next: null,
  1013. parent,
  1014. prev: null,
  1015. teardown: null,
  1016. transitions: null,
  1017. wv: 0
  1018. };
  1019. if (sync) {
  1020. try {
  1021. update_effect(effect2);
  1022. effect2.f |= EFFECT_RAN;
  1023. } catch (e2) {
  1024. destroy_effect(effect2);
  1025. throw e2;
  1026. }
  1027. } else if (fn !== null) {
  1028. schedule_effect(effect2);
  1029. }
  1030. var inert = sync && effect2.deps === null && effect2.first === null && effect2.nodes_start === null && effect2.teardown === null && (effect2.f & (EFFECT_HAS_DERIVED | BOUNDARY_EFFECT)) === 0;
  1031. if (!inert && push2) {
  1032. if (parent !== null) {
  1033. push_effect(effect2, parent);
  1034. }
  1035. if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
  1036. var derived2 = (
  1037. /** @type {Derived} */
  1038. active_reaction
  1039. );
  1040. (derived2.effects ?? (derived2.effects = [])).push(effect2);
  1041. }
  1042. }
  1043. return effect2;
  1044. }
  1045. function teardown(fn) {
  1046. const effect2 = create_effect(RENDER_EFFECT, null, false);
  1047. set_signal_status(effect2, CLEAN);
  1048. effect2.teardown = fn;
  1049. return effect2;
  1050. }
  1051. function user_effect(fn) {
  1052. validate_effect();
  1053. var defer = active_effect !== null && (active_effect.f & BRANCH_EFFECT) !== 0 && component_context !== null && !component_context.m;
  1054. if (defer) {
  1055. var context = (
  1056. /** @type {ComponentContext} */
  1057. component_context
  1058. );
  1059. (context.e ?? (context.e = [])).push({
  1060. fn,
  1061. effect: active_effect,
  1062. reaction: active_reaction
  1063. });
  1064. } else {
  1065. var signal = effect(fn);
  1066. return signal;
  1067. }
  1068. }
  1069. function user_pre_effect(fn) {
  1070. validate_effect();
  1071. return render_effect(fn);
  1072. }
  1073. function component_root(fn) {
  1074. const effect2 = create_effect(ROOT_EFFECT, fn, true);
  1075. return (options = {}) => {
  1076. return new Promise((fulfil) => {
  1077. if (options.outro) {
  1078. pause_effect(effect2, () => {
  1079. destroy_effect(effect2);
  1080. fulfil(void 0);
  1081. });
  1082. } else {
  1083. destroy_effect(effect2);
  1084. fulfil(void 0);
  1085. }
  1086. });
  1087. };
  1088. }
  1089. function effect(fn) {
  1090. return create_effect(EFFECT, fn, false);
  1091. }
  1092. function render_effect(fn) {
  1093. return create_effect(RENDER_EFFECT, fn, true);
  1094. }
  1095. function template_effect(fn, thunks = [], d2 = derived) {
  1096. const deriveds = thunks.map(d2);
  1097. return block(() => fn(...deriveds.map(get)));
  1098. }
  1099. function block(fn, flags = 0) {
  1100. return create_effect(RENDER_EFFECT | BLOCK_EFFECT | flags, fn, true);
  1101. }
  1102. function branch(fn, push2 = true) {
  1103. return create_effect(RENDER_EFFECT | BRANCH_EFFECT, fn, true, push2);
  1104. }
  1105. function execute_effect_teardown(effect2) {
  1106. var teardown2 = effect2.teardown;
  1107. if (teardown2 !== null) {
  1108. const previously_destroying_effect = is_destroying_effect;
  1109. const previous_reaction = active_reaction;
  1110. set_is_destroying_effect(true);
  1111. set_active_reaction(null);
  1112. try {
  1113. teardown2.call(null);
  1114. } finally {
  1115. set_is_destroying_effect(previously_destroying_effect);
  1116. set_active_reaction(previous_reaction);
  1117. }
  1118. }
  1119. }
  1120. function destroy_effect_children(signal, remove_dom = false) {
  1121. var effect2 = signal.first;
  1122. signal.first = signal.last = null;
  1123. while (effect2 !== null) {
  1124. var next = effect2.next;
  1125. if ((effect2.f & ROOT_EFFECT) !== 0) {
  1126. effect2.parent = null;
  1127. } else {
  1128. destroy_effect(effect2, remove_dom);
  1129. }
  1130. effect2 = next;
  1131. }
  1132. }
  1133. function destroy_block_effect_children(signal) {
  1134. var effect2 = signal.first;
  1135. while (effect2 !== null) {
  1136. var next = effect2.next;
  1137. if ((effect2.f & BRANCH_EFFECT) === 0) {
  1138. destroy_effect(effect2);
  1139. }
  1140. effect2 = next;
  1141. }
  1142. }
  1143. function destroy_effect(effect2, remove_dom = true) {
  1144. var removed = false;
  1145. if ((remove_dom || (effect2.f & HEAD_EFFECT) !== 0) && effect2.nodes_start !== null && effect2.nodes_end !== null) {
  1146. remove_effect_dom(
  1147. effect2.nodes_start,
  1148. /** @type {TemplateNode} */
  1149. effect2.nodes_end
  1150. );
  1151. removed = true;
  1152. }
  1153. destroy_effect_children(effect2, remove_dom && !removed);
  1154. remove_reactions(effect2, 0);
  1155. set_signal_status(effect2, DESTROYED);
  1156. var transitions = effect2.transitions;
  1157. if (transitions !== null) {
  1158. for (const transition of transitions) {
  1159. transition.stop();
  1160. }
  1161. }
  1162. execute_effect_teardown(effect2);
  1163. var parent = effect2.parent;
  1164. if (parent !== null && parent.first !== null) {
  1165. unlink_effect(effect2);
  1166. }
  1167. effect2.next = effect2.prev = effect2.teardown = effect2.ctx = effect2.deps = effect2.fn = effect2.nodes_start = effect2.nodes_end = null;
  1168. }
  1169. function remove_effect_dom(node, end) {
  1170. while (node !== null) {
  1171. var next = node === end ? null : (
  1172. /** @type {TemplateNode} */
  1173. /* @__PURE__ */ get_next_sibling(node)
  1174. );
  1175. node.remove();
  1176. node = next;
  1177. }
  1178. }
  1179. function unlink_effect(effect2) {
  1180. var parent = effect2.parent;
  1181. var prev = effect2.prev;
  1182. var next = effect2.next;
  1183. if (prev !== null) prev.next = next;
  1184. if (next !== null) next.prev = prev;
  1185. if (parent !== null) {
  1186. if (parent.first === effect2) parent.first = next;
  1187. if (parent.last === effect2) parent.last = prev;
  1188. }
  1189. }
  1190. function pause_effect(effect2, callback) {
  1191. var transitions = [];
  1192. pause_children(effect2, transitions, true);
  1193. run_out_transitions(transitions, () => {
  1194. destroy_effect(effect2);
  1195. if (callback) callback();
  1196. });
  1197. }
  1198. function run_out_transitions(transitions, fn) {
  1199. var remaining = transitions.length;
  1200. if (remaining > 0) {
  1201. var check = () => --remaining || fn();
  1202. for (var transition of transitions) {
  1203. transition.out(check);
  1204. }
  1205. } else {
  1206. fn();
  1207. }
  1208. }
  1209. function pause_children(effect2, transitions, local) {
  1210. if ((effect2.f & INERT) !== 0) return;
  1211. effect2.f ^= INERT;
  1212. if (effect2.transitions !== null) {
  1213. for (const transition of effect2.transitions) {
  1214. if (transition.is_global || local) {
  1215. transitions.push(transition);
  1216. }
  1217. }
  1218. }
  1219. var child2 = effect2.first;
  1220. while (child2 !== null) {
  1221. var sibling2 = child2.next;
  1222. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  1223. pause_children(child2, transitions, transparent ? local : false);
  1224. child2 = sibling2;
  1225. }
  1226. }
  1227. function resume_effect(effect2) {
  1228. resume_children(effect2, true);
  1229. }
  1230. function resume_children(effect2, local) {
  1231. if ((effect2.f & INERT) === 0) return;
  1232. effect2.f ^= INERT;
  1233. var child2 = effect2.first;
  1234. while (child2 !== null) {
  1235. var sibling2 = child2.next;
  1236. var transparent = (child2.f & EFFECT_TRANSPARENT) !== 0 || (child2.f & BRANCH_EFFECT) !== 0;
  1237. resume_children(child2, transparent ? local : false);
  1238. child2 = sibling2;
  1239. }
  1240. if (effect2.transitions !== null) {
  1241. for (const transition of effect2.transitions) {
  1242. if (transition.is_global || local) {
  1243. transition.in();
  1244. }
  1245. }
  1246. }
  1247. }
  1248. let micro_tasks = [];
  1249. function run_micro_tasks() {
  1250. var tasks = micro_tasks;
  1251. micro_tasks = [];
  1252. run_all(tasks);
  1253. }
  1254. function queue_micro_task(fn) {
  1255. if (micro_tasks.length === 0) {
  1256. queueMicrotask(run_micro_tasks);
  1257. }
  1258. micro_tasks.push(fn);
  1259. }
  1260. function handle_error(error) {
  1261. var effect2 = (
  1262. /** @type {Effect} */
  1263. active_effect
  1264. );
  1265. if ((effect2.f & EFFECT_RAN) === 0) {
  1266. if ((effect2.f & BOUNDARY_EFFECT) === 0) {
  1267. throw error;
  1268. }
  1269. effect2.fn(error);
  1270. } else {
  1271. invoke_error_boundary(error, effect2);
  1272. }
  1273. }
  1274. function invoke_error_boundary(error, effect2) {
  1275. while (effect2 !== null) {
  1276. if ((effect2.f & BOUNDARY_EFFECT) !== 0) {
  1277. try {
  1278. effect2.fn(error);
  1279. return;
  1280. } catch {
  1281. }
  1282. }
  1283. effect2 = effect2.parent;
  1284. }
  1285. throw error;
  1286. }
  1287. let is_flushing = false;
  1288. let last_scheduled_effect = null;
  1289. let is_updating_effect = false;
  1290. let is_destroying_effect = false;
  1291. function set_is_destroying_effect(value) {
  1292. is_destroying_effect = value;
  1293. }
  1294. let queued_root_effects = [];
  1295. let active_reaction = null;
  1296. let untracking = false;
  1297. function set_active_reaction(reaction) {
  1298. active_reaction = reaction;
  1299. }
  1300. let active_effect = null;
  1301. function set_active_effect(effect2) {
  1302. active_effect = effect2;
  1303. }
  1304. let reaction_sources = null;
  1305. function push_reaction_value(value) {
  1306. if (active_reaction !== null && active_reaction.f & EFFECT_IS_UPDATING) {
  1307. if (reaction_sources === null) {
  1308. reaction_sources = [active_reaction, [value]];
  1309. } else {
  1310. reaction_sources[1].push(value);
  1311. }
  1312. }
  1313. }
  1314. let new_deps = null;
  1315. let skipped_deps = 0;
  1316. let untracked_writes = null;
  1317. function set_untracked_writes(value) {
  1318. untracked_writes = value;
  1319. }
  1320. let write_version = 1;
  1321. let read_version = 0;
  1322. let skip_reaction = false;
  1323. function increment_write_version() {
  1324. return ++write_version;
  1325. }
  1326. function check_dirtiness(reaction) {
  1327. var _a2;
  1328. var flags = reaction.f;
  1329. if ((flags & DIRTY) !== 0) {
  1330. return true;
  1331. }
  1332. if ((flags & MAYBE_DIRTY) !== 0) {
  1333. var dependencies = reaction.deps;
  1334. var is_unowned = (flags & UNOWNED) !== 0;
  1335. if (dependencies !== null) {
  1336. var i2;
  1337. var dependency;
  1338. var is_disconnected = (flags & DISCONNECTED) !== 0;
  1339. var is_unowned_connected = is_unowned && active_effect !== null && !skip_reaction;
  1340. var length = dependencies.length;
  1341. if (is_disconnected || is_unowned_connected) {
  1342. var derived2 = (
  1343. /** @type {Derived} */
  1344. reaction
  1345. );
  1346. var parent = derived2.parent;
  1347. for (i2 = 0; i2 < length; i2++) {
  1348. dependency = dependencies[i2];
  1349. if (is_disconnected || !((_a2 = dependency == null ? void 0 : dependency.reactions) == null ? void 0 : _a2.includes(derived2))) {
  1350. (dependency.reactions ?? (dependency.reactions = [])).push(derived2);
  1351. }
  1352. }
  1353. if (is_disconnected) {
  1354. derived2.f ^= DISCONNECTED;
  1355. }
  1356. if (is_unowned_connected && parent !== null && (parent.f & UNOWNED) === 0) {
  1357. derived2.f ^= UNOWNED;
  1358. }
  1359. }
  1360. for (i2 = 0; i2 < length; i2++) {
  1361. dependency = dependencies[i2];
  1362. if (check_dirtiness(
  1363. /** @type {Derived} */
  1364. dependency
  1365. )) {
  1366. update_derived(
  1367. /** @type {Derived} */
  1368. dependency
  1369. );
  1370. }
  1371. if (dependency.wv > reaction.wv) {
  1372. return true;
  1373. }
  1374. }
  1375. }
  1376. if (!is_unowned || active_effect !== null && !skip_reaction) {
  1377. set_signal_status(reaction, CLEAN);
  1378. }
  1379. }
  1380. return false;
  1381. }
  1382. function schedule_possible_effect_self_invalidation(signal, effect2, root2 = true) {
  1383. var reactions = signal.reactions;
  1384. if (reactions === null) return;
  1385. for (var i2 = 0; i2 < reactions.length; i2++) {
  1386. var reaction = reactions[i2];
  1387. if ((reaction_sources == null ? void 0 : reaction_sources[1].includes(signal)) && reaction_sources[0] === active_reaction) continue;
  1388. if ((reaction.f & DERIVED) !== 0) {
  1389. schedule_possible_effect_self_invalidation(
  1390. /** @type {Derived} */
  1391. reaction,
  1392. effect2,
  1393. false
  1394. );
  1395. } else if (effect2 === reaction) {
  1396. if (root2) {
  1397. set_signal_status(reaction, DIRTY);
  1398. } else if ((reaction.f & CLEAN) !== 0) {
  1399. set_signal_status(reaction, MAYBE_DIRTY);
  1400. }
  1401. schedule_effect(
  1402. /** @type {Effect} */
  1403. reaction
  1404. );
  1405. }
  1406. }
  1407. }
  1408. function update_reaction(reaction) {
  1409. var _a2;
  1410. var previous_deps = new_deps;
  1411. var previous_skipped_deps = skipped_deps;
  1412. var previous_untracked_writes = untracked_writes;
  1413. var previous_reaction = active_reaction;
  1414. var previous_skip_reaction = skip_reaction;
  1415. var previous_reaction_sources = reaction_sources;
  1416. var previous_component_context = component_context;
  1417. var previous_untracking = untracking;
  1418. var flags = reaction.f;
  1419. new_deps = /** @type {null | Value[]} */
  1420. null;
  1421. skipped_deps = 0;
  1422. untracked_writes = null;
  1423. skip_reaction = (flags & UNOWNED) !== 0 && (untracking || !is_updating_effect || active_reaction === null);
  1424. active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
  1425. reaction_sources = null;
  1426. set_component_context(reaction.ctx);
  1427. untracking = false;
  1428. read_version++;
  1429. reaction.f |= EFFECT_IS_UPDATING;
  1430. try {
  1431. var result = (
  1432. /** @type {Function} */
  1433. (0, reaction.fn)()
  1434. );
  1435. var deps = reaction.deps;
  1436. if (new_deps !== null) {
  1437. var i2;
  1438. remove_reactions(reaction, skipped_deps);
  1439. if (deps !== null && skipped_deps > 0) {
  1440. deps.length = skipped_deps + new_deps.length;
  1441. for (i2 = 0; i2 < new_deps.length; i2++) {
  1442. deps[skipped_deps + i2] = new_deps[i2];
  1443. }
  1444. } else {
  1445. reaction.deps = deps = new_deps;
  1446. }
  1447. if (!skip_reaction) {
  1448. for (i2 = skipped_deps; i2 < deps.length; i2++) {
  1449. ((_a2 = deps[i2]).reactions ?? (_a2.reactions = [])).push(reaction);
  1450. }
  1451. }
  1452. } else if (deps !== null && skipped_deps < deps.length) {
  1453. remove_reactions(reaction, skipped_deps);
  1454. deps.length = skipped_deps;
  1455. }
  1456. if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
  1457. for (i2 = 0; i2 < /** @type {Source[]} */
  1458. untracked_writes.length; i2++) {
  1459. schedule_possible_effect_self_invalidation(
  1460. untracked_writes[i2],
  1461. /** @type {Effect} */
  1462. reaction
  1463. );
  1464. }
  1465. }
  1466. if (previous_reaction !== null && previous_reaction !== reaction) {
  1467. read_version++;
  1468. if (untracked_writes !== null) {
  1469. if (previous_untracked_writes === null) {
  1470. previous_untracked_writes = untracked_writes;
  1471. } else {
  1472. previous_untracked_writes.push(.../** @type {Source[]} */
  1473. untracked_writes);
  1474. }
  1475. }
  1476. }
  1477. return result;
  1478. } catch (error) {
  1479. handle_error(error);
  1480. } finally {
  1481. new_deps = previous_deps;
  1482. skipped_deps = previous_skipped_deps;
  1483. untracked_writes = previous_untracked_writes;
  1484. active_reaction = previous_reaction;
  1485. skip_reaction = previous_skip_reaction;
  1486. reaction_sources = previous_reaction_sources;
  1487. set_component_context(previous_component_context);
  1488. untracking = previous_untracking;
  1489. reaction.f ^= EFFECT_IS_UPDATING;
  1490. }
  1491. }
  1492. function remove_reaction(signal, dependency) {
  1493. let reactions = dependency.reactions;
  1494. if (reactions !== null) {
  1495. var index = index_of.call(reactions, signal);
  1496. if (index !== -1) {
  1497. var new_length = reactions.length - 1;
  1498. if (new_length === 0) {
  1499. reactions = dependency.reactions = null;
  1500. } else {
  1501. reactions[index] = reactions[new_length];
  1502. reactions.pop();
  1503. }
  1504. }
  1505. }
  1506. if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
  1507. // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
  1508. // allows us to skip the expensive work of disconnecting and immediately reconnecting it
  1509. (new_deps === null || !new_deps.includes(dependency))) {
  1510. set_signal_status(dependency, MAYBE_DIRTY);
  1511. if ((dependency.f & (UNOWNED | DISCONNECTED)) === 0) {
  1512. dependency.f ^= DISCONNECTED;
  1513. }
  1514. destroy_derived_effects(
  1515. /** @type {Derived} **/
  1516. dependency
  1517. );
  1518. remove_reactions(
  1519. /** @type {Derived} **/
  1520. dependency,
  1521. 0
  1522. );
  1523. }
  1524. }
  1525. function remove_reactions(signal, start_index) {
  1526. var dependencies = signal.deps;
  1527. if (dependencies === null) return;
  1528. for (var i2 = start_index; i2 < dependencies.length; i2++) {
  1529. remove_reaction(signal, dependencies[i2]);
  1530. }
  1531. }
  1532. function update_effect(effect2) {
  1533. var flags = effect2.f;
  1534. if ((flags & DESTROYED) !== 0) {
  1535. return;
  1536. }
  1537. set_signal_status(effect2, CLEAN);
  1538. var previous_effect = active_effect;
  1539. var was_updating_effect = is_updating_effect;
  1540. active_effect = effect2;
  1541. is_updating_effect = true;
  1542. try {
  1543. if ((flags & BLOCK_EFFECT) !== 0) {
  1544. destroy_block_effect_children(effect2);
  1545. } else {
  1546. destroy_effect_children(effect2);
  1547. }
  1548. execute_effect_teardown(effect2);
  1549. var teardown2 = update_reaction(effect2);
  1550. effect2.teardown = typeof teardown2 === "function" ? teardown2 : null;
  1551. effect2.wv = write_version;
  1552. var dep;
  1553. if (DEV && tracing_mode_flag && (effect2.f & DIRTY) !== 0 && effect2.deps !== null) ;
  1554. if (DEV) ;
  1555. } finally {
  1556. is_updating_effect = was_updating_effect;
  1557. active_effect = previous_effect;
  1558. }
  1559. }
  1560. function infinite_loop_guard() {
  1561. try {
  1562. effect_update_depth_exceeded();
  1563. } catch (error) {
  1564. if (last_scheduled_effect !== null) {
  1565. {
  1566. invoke_error_boundary(error, last_scheduled_effect);
  1567. }
  1568. } else {
  1569. throw error;
  1570. }
  1571. }
  1572. }
  1573. function flush_queued_root_effects() {
  1574. var was_updating_effect = is_updating_effect;
  1575. try {
  1576. var flush_count = 0;
  1577. is_updating_effect = true;
  1578. while (queued_root_effects.length > 0) {
  1579. if (flush_count++ > 1e3) {
  1580. infinite_loop_guard();
  1581. }
  1582. var root_effects = queued_root_effects;
  1583. var length = root_effects.length;
  1584. queued_root_effects = [];
  1585. for (var i2 = 0; i2 < length; i2++) {
  1586. var collected_effects = process_effects(root_effects[i2]);
  1587. flush_queued_effects(collected_effects);
  1588. }
  1589. old_values.clear();
  1590. }
  1591. } finally {
  1592. is_flushing = false;
  1593. is_updating_effect = was_updating_effect;
  1594. last_scheduled_effect = null;
  1595. }
  1596. }
  1597. function flush_queued_effects(effects) {
  1598. var length = effects.length;
  1599. if (length === 0) return;
  1600. for (var i2 = 0; i2 < length; i2++) {
  1601. var effect2 = effects[i2];
  1602. if ((effect2.f & (DESTROYED | INERT)) === 0) {
  1603. if (check_dirtiness(effect2)) {
  1604. update_effect(effect2);
  1605. if (effect2.deps === null && effect2.first === null && effect2.nodes_start === null) {
  1606. if (effect2.teardown === null) {
  1607. unlink_effect(effect2);
  1608. } else {
  1609. effect2.fn = null;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. function schedule_effect(signal) {
  1617. if (!is_flushing) {
  1618. is_flushing = true;
  1619. queueMicrotask(flush_queued_root_effects);
  1620. }
  1621. var effect2 = last_scheduled_effect = signal;
  1622. while (effect2.parent !== null) {
  1623. effect2 = effect2.parent;
  1624. var flags = effect2.f;
  1625. if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
  1626. if ((flags & CLEAN) === 0) return;
  1627. effect2.f ^= CLEAN;
  1628. }
  1629. }
  1630. queued_root_effects.push(effect2);
  1631. }
  1632. function process_effects(root2) {
  1633. var effects = [];
  1634. var effect2 = root2;
  1635. while (effect2 !== null) {
  1636. var flags = effect2.f;
  1637. var is_branch = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0;
  1638. var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
  1639. if (!is_skippable_branch && (flags & INERT) === 0) {
  1640. if ((flags & EFFECT) !== 0) {
  1641. effects.push(effect2);
  1642. } else if (is_branch) {
  1643. effect2.f ^= CLEAN;
  1644. } else {
  1645. if (check_dirtiness(effect2)) {
  1646. update_effect(effect2);
  1647. }
  1648. }
  1649. var child2 = effect2.first;
  1650. if (child2 !== null) {
  1651. effect2 = child2;
  1652. continue;
  1653. }
  1654. }
  1655. var parent = effect2.parent;
  1656. effect2 = effect2.next;
  1657. while (effect2 === null && parent !== null) {
  1658. effect2 = parent.next;
  1659. parent = parent.parent;
  1660. }
  1661. }
  1662. return effects;
  1663. }
  1664. function get(signal) {
  1665. var flags = signal.f;
  1666. var is_derived = (flags & DERIVED) !== 0;
  1667. if (active_reaction !== null && !untracking) {
  1668. if (!(reaction_sources == null ? void 0 : reaction_sources[1].includes(signal)) || reaction_sources[0] !== active_reaction) {
  1669. var deps = active_reaction.deps;
  1670. if (signal.rv < read_version) {
  1671. signal.rv = read_version;
  1672. if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
  1673. skipped_deps++;
  1674. } else if (new_deps === null) {
  1675. new_deps = [signal];
  1676. } else if (!skip_reaction || !new_deps.includes(signal)) {
  1677. new_deps.push(signal);
  1678. }
  1679. }
  1680. }
  1681. } else if (is_derived && /** @type {Derived} */
  1682. signal.deps === null && /** @type {Derived} */
  1683. signal.effects === null) {
  1684. var derived2 = (
  1685. /** @type {Derived} */
  1686. signal
  1687. );
  1688. var parent = derived2.parent;
  1689. if (parent !== null && (parent.f & UNOWNED) === 0) {
  1690. derived2.f ^= UNOWNED;
  1691. }
  1692. }
  1693. if (is_derived) {
  1694. derived2 = /** @type {Derived} */
  1695. signal;
  1696. if (check_dirtiness(derived2)) {
  1697. update_derived(derived2);
  1698. }
  1699. }
  1700. if (is_destroying_effect && old_values.has(signal)) {
  1701. return old_values.get(signal);
  1702. }
  1703. return signal.v;
  1704. }
  1705. function untrack(fn) {
  1706. var previous_untracking = untracking;
  1707. try {
  1708. untracking = true;
  1709. return fn();
  1710. } finally {
  1711. untracking = previous_untracking;
  1712. }
  1713. }
  1714. const STATUS_MASK = -7169;
  1715. function set_signal_status(signal, status) {
  1716. signal.f = signal.f & STATUS_MASK | status;
  1717. }
  1718. function deep_read_state(value) {
  1719. if (typeof value !== "object" || !value || value instanceof EventTarget) {
  1720. return;
  1721. }
  1722. if (STATE_SYMBOL in value) {
  1723. deep_read(value);
  1724. } else if (!Array.isArray(value)) {
  1725. for (let key in value) {
  1726. const prop2 = value[key];
  1727. if (typeof prop2 === "object" && prop2 && STATE_SYMBOL in prop2) {
  1728. deep_read(prop2);
  1729. }
  1730. }
  1731. }
  1732. }
  1733. function deep_read(value, visited = /* @__PURE__ */ new Set()) {
  1734. if (typeof value === "object" && value !== null && // We don't want to traverse DOM elements
  1735. !(value instanceof EventTarget) && !visited.has(value)) {
  1736. visited.add(value);
  1737. if (value instanceof Date) {
  1738. value.getTime();
  1739. }
  1740. for (let key in value) {
  1741. try {
  1742. deep_read(value[key], visited);
  1743. } catch (e2) {
  1744. }
  1745. }
  1746. const proto = get_prototype_of(value);
  1747. if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
  1748. const descriptors = get_descriptors(proto);
  1749. for (let key in descriptors) {
  1750. const get2 = descriptors[key].get;
  1751. if (get2) {
  1752. try {
  1753. get2.call(value);
  1754. } catch (e2) {
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. }
  1761. function is_capture_event(name) {
  1762. return name.endsWith("capture") && name !== "gotpointercapture" && name !== "lostpointercapture";
  1763. }
  1764. const DELEGATED_EVENTS = [
  1765. "beforeinput",
  1766. "click",
  1767. "change",
  1768. "dblclick",
  1769. "contextmenu",
  1770. "focusin",
  1771. "focusout",
  1772. "input",
  1773. "keydown",
  1774. "keyup",
  1775. "mousedown",
  1776. "mousemove",
  1777. "mouseout",
  1778. "mouseover",
  1779. "mouseup",
  1780. "pointerdown",
  1781. "pointermove",
  1782. "pointerout",
  1783. "pointerover",
  1784. "pointerup",
  1785. "touchend",
  1786. "touchmove",
  1787. "touchstart"
  1788. ];
  1789. function is_delegated(event_name) {
  1790. return DELEGATED_EVENTS.includes(event_name);
  1791. }
  1792. const ATTRIBUTE_ALIASES = {
  1793. // no `class: 'className'` because we handle that separately
  1794. formnovalidate: "formNoValidate",
  1795. ismap: "isMap",
  1796. nomodule: "noModule",
  1797. playsinline: "playsInline",
  1798. readonly: "readOnly",
  1799. defaultvalue: "defaultValue",
  1800. defaultchecked: "defaultChecked",
  1801. srcobject: "srcObject",
  1802. novalidate: "noValidate",
  1803. allowfullscreen: "allowFullscreen",
  1804. disablepictureinpicture: "disablePictureInPicture",
  1805. disableremoteplayback: "disableRemotePlayback"
  1806. };
  1807. function normalize_attribute(name) {
  1808. name = name.toLowerCase();
  1809. return ATTRIBUTE_ALIASES[name] ?? name;
  1810. }
  1811. const PASSIVE_EVENTS = ["touchstart", "touchmove"];
  1812. function is_passive_event(name) {
  1813. return PASSIVE_EVENTS.includes(name);
  1814. }
  1815. function autofocus(dom, value) {
  1816. if (value) {
  1817. const body = document.body;
  1818. dom.autofocus = true;
  1819. queue_micro_task(() => {
  1820. if (document.activeElement === body) {
  1821. dom.focus();
  1822. }
  1823. });
  1824. }
  1825. }
  1826. function without_reactive_context(fn) {
  1827. var previous_reaction = active_reaction;
  1828. var previous_effect = active_effect;
  1829. set_active_reaction(null);
  1830. set_active_effect(null);
  1831. try {
  1832. return fn();
  1833. } finally {
  1834. set_active_reaction(previous_reaction);
  1835. set_active_effect(previous_effect);
  1836. }
  1837. }
  1838. const all_registered_events = /* @__PURE__ */ new Set();
  1839. const root_event_handles = /* @__PURE__ */ new Set();
  1840. function create_event(event_name, dom, handler, options = {}) {
  1841. function target_handler(event) {
  1842. if (!options.capture) {
  1843. handle_event_propagation.call(dom, event);
  1844. }
  1845. if (!event.cancelBubble) {
  1846. return without_reactive_context(() => {
  1847. return handler == null ? void 0 : handler.call(this, event);
  1848. });
  1849. }
  1850. }
  1851. if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
  1852. queue_micro_task(() => {
  1853. dom.addEventListener(event_name, target_handler, options);
  1854. });
  1855. } else {
  1856. dom.addEventListener(event_name, target_handler, options);
  1857. }
  1858. return target_handler;
  1859. }
  1860. function delegate(events) {
  1861. for (var i2 = 0; i2 < events.length; i2++) {
  1862. all_registered_events.add(events[i2]);
  1863. }
  1864. for (var fn of root_event_handles) {
  1865. fn(events);
  1866. }
  1867. }
  1868. function handle_event_propagation(event) {
  1869. var _a2;
  1870. var handler_element = this;
  1871. var owner_document = (
  1872. /** @type {Node} */
  1873. handler_element.ownerDocument
  1874. );
  1875. var event_name = event.type;
  1876. var path = ((_a2 = event.composedPath) == null ? void 0 : _a2.call(event)) || [];
  1877. var current_target = (
  1878. /** @type {null | Element} */
  1879. path[0] || event.target
  1880. );
  1881. var path_idx = 0;
  1882. var handled_at = event.__root;
  1883. if (handled_at) {
  1884. var at_idx = path.indexOf(handled_at);
  1885. if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
  1886. window)) {
  1887. event.__root = handler_element;
  1888. return;
  1889. }
  1890. var handler_idx = path.indexOf(handler_element);
  1891. if (handler_idx === -1) {
  1892. return;
  1893. }
  1894. if (at_idx <= handler_idx) {
  1895. path_idx = at_idx;
  1896. }
  1897. }
  1898. current_target = /** @type {Element} */
  1899. path[path_idx] || event.target;
  1900. if (current_target === handler_element) return;
  1901. define_property(event, "currentTarget", {
  1902. configurable: true,
  1903. get() {
  1904. return current_target || owner_document;
  1905. }
  1906. });
  1907. var previous_reaction = active_reaction;
  1908. var previous_effect = active_effect;
  1909. set_active_reaction(null);
  1910. set_active_effect(null);
  1911. try {
  1912. var throw_error;
  1913. var other_errors = [];
  1914. while (current_target !== null) {
  1915. var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
  1916. current_target.host || null;
  1917. try {
  1918. var delegated = current_target["__" + event_name];
  1919. if (delegated != null && (!/** @type {any} */
  1920. current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
  1921. // -> the target could not have been disabled because it emits the event in the first place
  1922. event.target === current_target)) {
  1923. if (is_array(delegated)) {
  1924. var [fn, ...data] = delegated;
  1925. fn.apply(current_target, [event, ...data]);
  1926. } else {
  1927. delegated.call(current_target, event);
  1928. }
  1929. }
  1930. } catch (error) {
  1931. if (throw_error) {
  1932. other_errors.push(error);
  1933. } else {
  1934. throw_error = error;
  1935. }
  1936. }
  1937. if (event.cancelBubble || parent_element === handler_element || parent_element === null) {
  1938. break;
  1939. }
  1940. current_target = parent_element;
  1941. }
  1942. if (throw_error) {
  1943. for (let error of other_errors) {
  1944. queueMicrotask(() => {
  1945. throw error;
  1946. });
  1947. }
  1948. throw throw_error;
  1949. }
  1950. } finally {
  1951. event.__root = handler_element;
  1952. delete event.currentTarget;
  1953. set_active_reaction(previous_reaction);
  1954. set_active_effect(previous_effect);
  1955. }
  1956. }
  1957. function create_fragment_from_html(html) {
  1958. var elem = document.createElement("template");
  1959. elem.innerHTML = html.replaceAll("<!>", "<!---->");
  1960. return elem.content;
  1961. }
  1962. function assign_nodes(start, end) {
  1963. var effect2 = (
  1964. /** @type {Effect} */
  1965. active_effect
  1966. );
  1967. if (effect2.nodes_start === null) {
  1968. effect2.nodes_start = start;
  1969. effect2.nodes_end = end;
  1970. }
  1971. }
  1972. // @__NO_SIDE_EFFECTS__
  1973. function from_html(content, flags) {
  1974. var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
  1975. var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
  1976. var node;
  1977. var has_start = !content.startsWith("<!>");
  1978. return () => {
  1979. if (node === void 0) {
  1980. node = create_fragment_from_html(has_start ? content : "<!>" + content);
  1981. if (!is_fragment) node = /** @type {Node} */
  1982. /* @__PURE__ */ get_first_child(node);
  1983. }
  1984. var clone = (
  1985. /** @type {TemplateNode} */
  1986. use_import_node || is_firefox ? document.importNode(node, true) : node.cloneNode(true)
  1987. );
  1988. if (is_fragment) {
  1989. var start = (
  1990. /** @type {TemplateNode} */
  1991. /* @__PURE__ */ get_first_child(clone)
  1992. );
  1993. var end = (
  1994. /** @type {TemplateNode} */
  1995. clone.lastChild
  1996. );
  1997. assign_nodes(start, end);
  1998. } else {
  1999. assign_nodes(clone, clone);
  2000. }
  2001. return clone;
  2002. };
  2003. }
  2004. // @__NO_SIDE_EFFECTS__
  2005. function from_namespace(content, flags, ns = "svg") {
  2006. var has_start = !content.startsWith("<!>");
  2007. var wrapped = `<${ns}>${has_start ? content : "<!>" + content}</${ns}>`;
  2008. var node;
  2009. return () => {
  2010. if (!node) {
  2011. var fragment = (
  2012. /** @type {DocumentFragment} */
  2013. create_fragment_from_html(wrapped)
  2014. );
  2015. var root2 = (
  2016. /** @type {Element} */
  2017. /* @__PURE__ */ get_first_child(fragment)
  2018. );
  2019. {
  2020. node = /** @type {Element} */
  2021. /* @__PURE__ */ get_first_child(root2);
  2022. }
  2023. }
  2024. var clone = (
  2025. /** @type {TemplateNode} */
  2026. node.cloneNode(true)
  2027. );
  2028. {
  2029. assign_nodes(clone, clone);
  2030. }
  2031. return clone;
  2032. };
  2033. }
  2034. // @__NO_SIDE_EFFECTS__
  2035. function from_svg(content, flags) {
  2036. return /* @__PURE__ */ from_namespace(content, flags, "svg");
  2037. }
  2038. function text(value = "") {
  2039. {
  2040. var t = create_text(value + "");
  2041. assign_nodes(t, t);
  2042. return t;
  2043. }
  2044. }
  2045. function comment() {
  2046. var frag = document.createDocumentFragment();
  2047. var start = document.createComment("");
  2048. var anchor = create_text();
  2049. frag.append(start, anchor);
  2050. assign_nodes(start, anchor);
  2051. return frag;
  2052. }
  2053. function append(anchor, dom) {
  2054. if (anchor === null) {
  2055. return;
  2056. }
  2057. anchor.before(
  2058. /** @type {Node} */
  2059. dom
  2060. );
  2061. }
  2062. function set_text(text2, value) {
  2063. var str = value == null ? "" : typeof value === "object" ? value + "" : value;
  2064. if (str !== (text2.__t ?? (text2.__t = text2.nodeValue))) {
  2065. text2.__t = str;
  2066. text2.nodeValue = str + "";
  2067. }
  2068. }
  2069. function mount(component, options) {
  2070. return _mount(component, options);
  2071. }
  2072. const document_listeners = /* @__PURE__ */ new Map();
  2073. function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
  2074. init_operations();
  2075. var registered_events = /* @__PURE__ */ new Set();
  2076. var event_handle = (events2) => {
  2077. for (var i2 = 0; i2 < events2.length; i2++) {
  2078. var event_name = events2[i2];
  2079. if (registered_events.has(event_name)) continue;
  2080. registered_events.add(event_name);
  2081. var passive = is_passive_event(event_name);
  2082. target.addEventListener(event_name, handle_event_propagation, { passive });
  2083. var n2 = document_listeners.get(event_name);
  2084. if (n2 === void 0) {
  2085. document.addEventListener(event_name, handle_event_propagation, { passive });
  2086. document_listeners.set(event_name, 1);
  2087. } else {
  2088. document_listeners.set(event_name, n2 + 1);
  2089. }
  2090. }
  2091. };
  2092. event_handle(array_from(all_registered_events));
  2093. root_event_handles.add(event_handle);
  2094. var component = void 0;
  2095. var unmount = component_root(() => {
  2096. var anchor_node = anchor ?? target.appendChild(create_text());
  2097. branch(() => {
  2098. if (context) {
  2099. push({});
  2100. var ctx = (
  2101. /** @type {ComponentContext} */
  2102. component_context
  2103. );
  2104. ctx.c = context;
  2105. }
  2106. if (events) {
  2107. props.$$events = events;
  2108. }
  2109. component = Component(anchor_node, props) || {};
  2110. if (context) {
  2111. pop();
  2112. }
  2113. });
  2114. return () => {
  2115. var _a2;
  2116. for (var event_name of registered_events) {
  2117. target.removeEventListener(event_name, handle_event_propagation);
  2118. var n2 = (
  2119. /** @type {number} */
  2120. document_listeners.get(event_name)
  2121. );
  2122. if (--n2 === 0) {
  2123. document.removeEventListener(event_name, handle_event_propagation);
  2124. document_listeners.delete(event_name);
  2125. } else {
  2126. document_listeners.set(event_name, n2);
  2127. }
  2128. }
  2129. root_event_handles.delete(event_handle);
  2130. if (anchor_node !== anchor) {
  2131. (_a2 = anchor_node.parentNode) == null ? void 0 : _a2.removeChild(anchor_node);
  2132. }
  2133. };
  2134. });
  2135. mounted_components.set(component, unmount);
  2136. return component;
  2137. }
  2138. let mounted_components = /* @__PURE__ */ new WeakMap();
  2139. function if_block(node, fn, [root_index, hydrate_index] = [0, 0]) {
  2140. var anchor = node;
  2141. var consequent_effect = null;
  2142. var alternate_effect = null;
  2143. var condition = UNINITIALIZED;
  2144. var flags = root_index > 0 ? EFFECT_TRANSPARENT : 0;
  2145. var has_branch = false;
  2146. const set_branch = (fn2, flag = true) => {
  2147. has_branch = true;
  2148. update_branch(flag, fn2);
  2149. };
  2150. const update_branch = (new_condition, fn2) => {
  2151. if (condition === (condition = new_condition)) return;
  2152. if (condition) {
  2153. if (consequent_effect) {
  2154. resume_effect(consequent_effect);
  2155. } else if (fn2) {
  2156. consequent_effect = branch(() => fn2(anchor));
  2157. }
  2158. if (alternate_effect) {
  2159. pause_effect(alternate_effect, () => {
  2160. alternate_effect = null;
  2161. });
  2162. }
  2163. } else {
  2164. if (alternate_effect) {
  2165. resume_effect(alternate_effect);
  2166. } else if (fn2) {
  2167. alternate_effect = branch(() => fn2(anchor, [root_index + 1, hydrate_index]));
  2168. }
  2169. if (consequent_effect) {
  2170. pause_effect(consequent_effect, () => {
  2171. consequent_effect = null;
  2172. });
  2173. }
  2174. }
  2175. };
  2176. block(() => {
  2177. has_branch = false;
  2178. fn(set_branch);
  2179. if (!has_branch) {
  2180. update_branch(null, null);
  2181. }
  2182. }, flags);
  2183. }
  2184. function snippet(node, get_snippet, ...args) {
  2185. var anchor = node;
  2186. var snippet2 = noop;
  2187. var snippet_effect;
  2188. block(() => {
  2189. if (snippet2 === (snippet2 = get_snippet())) return;
  2190. if (snippet_effect) {
  2191. destroy_effect(snippet_effect);
  2192. snippet_effect = null;
  2193. }
  2194. snippet_effect = branch(() => (
  2195. /** @type {SnippetFn} */
  2196. snippet2(anchor, ...args)
  2197. ));
  2198. }, EFFECT_TRANSPARENT);
  2199. }
  2200. function attach(node, get_fn) {
  2201. var fn = void 0;
  2202. var e2;
  2203. block(() => {
  2204. if (fn !== (fn = get_fn())) {
  2205. if (e2) {
  2206. destroy_effect(e2);
  2207. e2 = null;
  2208. }
  2209. if (fn) {
  2210. e2 = branch(() => {
  2211. effect(() => (
  2212. /** @type {(node: Element) => void} */
  2213. fn(node)
  2214. ));
  2215. });
  2216. }
  2217. }
  2218. });
  2219. }
  2220. function r(e2) {
  2221. var t, f2, n2 = "";
  2222. if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
  2223. else if ("object" == typeof e2) if (Array.isArray(e2)) {
  2224. var o2 = e2.length;
  2225. for (t = 0; t < o2; t++) e2[t] && (f2 = r(e2[t])) && (n2 && (n2 += " "), n2 += f2);
  2226. } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
  2227. return n2;
  2228. }
  2229. function clsx$1() {
  2230. for (var e2, t, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t = r(e2)) && (n2 && (n2 += " "), n2 += t);
  2231. return n2;
  2232. }
  2233. function clsx(value) {
  2234. if (typeof value === "object") {
  2235. return clsx$1(value);
  2236. } else {
  2237. return value ?? "";
  2238. }
  2239. }
  2240. const whitespace = [..." \n\r\f \v\uFEFF"];
  2241. function to_class(value, hash, directives) {
  2242. var classname = value == null ? "" : "" + value;
  2243. if (hash) {
  2244. classname = classname ? classname + " " + hash : hash;
  2245. }
  2246. if (directives) {
  2247. for (var key in directives) {
  2248. if (directives[key]) {
  2249. classname = classname ? classname + " " + key : key;
  2250. } else if (classname.length) {
  2251. var len = key.length;
  2252. var a2 = 0;
  2253. while ((a2 = classname.indexOf(key, a2)) >= 0) {
  2254. var b2 = a2 + len;
  2255. if ((a2 === 0 || whitespace.includes(classname[a2 - 1])) && (b2 === classname.length || whitespace.includes(classname[b2]))) {
  2256. classname = (a2 === 0 ? "" : classname.substring(0, a2)) + classname.substring(b2 + 1);
  2257. } else {
  2258. a2 = b2;
  2259. }
  2260. }
  2261. }
  2262. }
  2263. }
  2264. return classname === "" ? null : classname;
  2265. }
  2266. function append_styles(styles, important = false) {
  2267. var separator = important ? " !important;" : ";";
  2268. var css = "";
  2269. for (var key in styles) {
  2270. var value = styles[key];
  2271. if (value != null && value !== "") {
  2272. css += " " + key + ": " + value + separator;
  2273. }
  2274. }
  2275. return css;
  2276. }
  2277. function to_css_name(name) {
  2278. if (name[0] !== "-" || name[1] !== "-") {
  2279. return name.toLowerCase();
  2280. }
  2281. return name;
  2282. }
  2283. function to_style(value, styles) {
  2284. if (styles) {
  2285. var new_style = "";
  2286. var normal_styles;
  2287. var important_styles;
  2288. if (Array.isArray(styles)) {
  2289. normal_styles = styles[0];
  2290. important_styles = styles[1];
  2291. } else {
  2292. normal_styles = styles;
  2293. }
  2294. if (value) {
  2295. value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim();
  2296. var in_str = false;
  2297. var in_apo = 0;
  2298. var in_comment = false;
  2299. var reserved_names = [];
  2300. if (normal_styles) {
  2301. reserved_names.push(...Object.keys(normal_styles).map(to_css_name));
  2302. }
  2303. if (important_styles) {
  2304. reserved_names.push(...Object.keys(important_styles).map(to_css_name));
  2305. }
  2306. var start_index = 0;
  2307. var name_index = -1;
  2308. const len = value.length;
  2309. for (var i2 = 0; i2 < len; i2++) {
  2310. var c2 = value[i2];
  2311. if (in_comment) {
  2312. if (c2 === "/" && value[i2 - 1] === "*") {
  2313. in_comment = false;
  2314. }
  2315. } else if (in_str) {
  2316. if (in_str === c2) {
  2317. in_str = false;
  2318. }
  2319. } else if (c2 === "/" && value[i2 + 1] === "*") {
  2320. in_comment = true;
  2321. } else if (c2 === '"' || c2 === "'") {
  2322. in_str = c2;
  2323. } else if (c2 === "(") {
  2324. in_apo++;
  2325. } else if (c2 === ")") {
  2326. in_apo--;
  2327. }
  2328. if (!in_comment && in_str === false && in_apo === 0) {
  2329. if (c2 === ":" && name_index === -1) {
  2330. name_index = i2;
  2331. } else if (c2 === ";" || i2 === len - 1) {
  2332. if (name_index !== -1) {
  2333. var name = to_css_name(value.substring(start_index, name_index).trim());
  2334. if (!reserved_names.includes(name)) {
  2335. if (c2 !== ";") {
  2336. i2++;
  2337. }
  2338. var property = value.substring(start_index, i2).trim();
  2339. new_style += " " + property + ";";
  2340. }
  2341. }
  2342. start_index = i2 + 1;
  2343. name_index = -1;
  2344. }
  2345. }
  2346. }
  2347. }
  2348. if (normal_styles) {
  2349. new_style += append_styles(normal_styles);
  2350. }
  2351. if (important_styles) {
  2352. new_style += append_styles(important_styles, true);
  2353. }
  2354. new_style = new_style.trim();
  2355. return new_style === "" ? null : new_style;
  2356. }
  2357. return value == null ? null : String(value);
  2358. }
  2359. function set_class(dom, is_html, value, hash, prev_classes, next_classes) {
  2360. var prev = dom.__className;
  2361. if (prev !== value || prev === void 0) {
  2362. var next_class_name = to_class(value, hash, next_classes);
  2363. {
  2364. if (next_class_name == null) {
  2365. dom.removeAttribute("class");
  2366. } else if (is_html) {
  2367. dom.className = next_class_name;
  2368. } else {
  2369. dom.setAttribute("class", next_class_name);
  2370. }
  2371. }
  2372. dom.__className = value;
  2373. } else if (next_classes && prev_classes !== next_classes) {
  2374. for (var key in next_classes) {
  2375. var is_present = !!next_classes[key];
  2376. if (prev_classes == null || is_present !== !!prev_classes[key]) {
  2377. dom.classList.toggle(key, is_present);
  2378. }
  2379. }
  2380. }
  2381. return next_classes;
  2382. }
  2383. function update_styles(dom, prev = {}, next, priority) {
  2384. for (var key in next) {
  2385. var value = next[key];
  2386. if (prev[key] !== value) {
  2387. if (next[key] == null) {
  2388. dom.style.removeProperty(key);
  2389. } else {
  2390. dom.style.setProperty(key, value, priority);
  2391. }
  2392. }
  2393. }
  2394. }
  2395. function set_style(dom, value, prev_styles, next_styles) {
  2396. var prev = dom.__style;
  2397. if (prev !== value) {
  2398. var next_style_attr = to_style(value, next_styles);
  2399. {
  2400. if (next_style_attr == null) {
  2401. dom.removeAttribute("style");
  2402. } else {
  2403. dom.style.cssText = next_style_attr;
  2404. }
  2405. }
  2406. dom.__style = value;
  2407. } else if (next_styles) {
  2408. if (Array.isArray(next_styles)) {
  2409. update_styles(dom, prev_styles == null ? void 0 : prev_styles[0], next_styles[0]);
  2410. update_styles(dom, prev_styles == null ? void 0 : prev_styles[1], next_styles[1], "important");
  2411. } else {
  2412. update_styles(dom, prev_styles, next_styles);
  2413. }
  2414. }
  2415. return next_styles;
  2416. }
  2417. function select_option(select, value, mounting) {
  2418. if (select.multiple) {
  2419. if (value == void 0) {
  2420. return;
  2421. }
  2422. if (!is_array(value)) {
  2423. return select_multiple_invalid_value();
  2424. }
  2425. for (var option of select.options) {
  2426. option.selected = value.includes(get_option_value(option));
  2427. }
  2428. return;
  2429. }
  2430. for (option of select.options) {
  2431. var option_value = get_option_value(option);
  2432. if (is(option_value, value)) {
  2433. option.selected = true;
  2434. return;
  2435. }
  2436. }
  2437. if (!mounting || value !== void 0) {
  2438. select.selectedIndex = -1;
  2439. }
  2440. }
  2441. function init_select(select, get_value) {
  2442. let mounting = true;
  2443. effect(() => {
  2444. if (get_value) {
  2445. select_option(select, untrack(get_value), mounting);
  2446. }
  2447. mounting = false;
  2448. var observer = new MutationObserver(() => {
  2449. var value = select.__value;
  2450. select_option(select, value);
  2451. });
  2452. observer.observe(select, {
  2453. // Listen to option element changes
  2454. childList: true,
  2455. subtree: true,
  2456. // because of <optgroup>
  2457. // Listen to option element value attribute changes
  2458. // (doesn't get notified of select value changes,
  2459. // because that property is not reflected as an attribute)
  2460. attributes: true,
  2461. attributeFilter: ["value"]
  2462. });
  2463. return () => {
  2464. observer.disconnect();
  2465. };
  2466. });
  2467. }
  2468. function get_option_value(option) {
  2469. if ("__value" in option) {
  2470. return option.__value;
  2471. } else {
  2472. return option.value;
  2473. }
  2474. }
  2475. const CLASS = Symbol("class");
  2476. const STYLE = Symbol("style");
  2477. const IS_CUSTOM_ELEMENT = Symbol("is custom element");
  2478. const IS_HTML = Symbol("is html");
  2479. function set_selected(element, selected) {
  2480. if (selected) {
  2481. if (!element.hasAttribute("selected")) {
  2482. element.setAttribute("selected", "");
  2483. }
  2484. } else {
  2485. element.removeAttribute("selected");
  2486. }
  2487. }
  2488. function set_attribute(element, attribute, value, skip_warning) {
  2489. var attributes = get_attributes(element);
  2490. if (attributes[attribute] === (attributes[attribute] = value)) return;
  2491. if (attribute === "loading") {
  2492. element[LOADING_ATTR_SYMBOL] = value;
  2493. }
  2494. if (value == null) {
  2495. element.removeAttribute(attribute);
  2496. } else if (typeof value !== "string" && get_setters(element).includes(attribute)) {
  2497. element[attribute] = value;
  2498. } else {
  2499. element.setAttribute(attribute, value);
  2500. }
  2501. }
  2502. function set_attributes(element, prev, next, css_hash, skip_warning = false) {
  2503. var attributes = get_attributes(element);
  2504. var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
  2505. var preserve_attribute_case = !attributes[IS_HTML];
  2506. var current = prev || {};
  2507. var is_option_element = element.tagName === "OPTION";
  2508. for (var key in prev) {
  2509. if (!(key in next)) {
  2510. next[key] = null;
  2511. }
  2512. }
  2513. if (next.class) {
  2514. next.class = clsx(next.class);
  2515. } else if (css_hash || next[CLASS]) {
  2516. next.class = null;
  2517. }
  2518. if (next[STYLE]) {
  2519. next.style ?? (next.style = null);
  2520. }
  2521. var setters = get_setters(element);
  2522. for (const key2 in next) {
  2523. let value = next[key2];
  2524. if (is_option_element && key2 === "value" && value == null) {
  2525. element.value = element.__value = "";
  2526. current[key2] = value;
  2527. continue;
  2528. }
  2529. if (key2 === "class") {
  2530. var is_html = element.namespaceURI === "http://www.w3.org/1999/xhtml";
  2531. set_class(element, is_html, value, css_hash, prev == null ? void 0 : prev[CLASS], next[CLASS]);
  2532. current[key2] = value;
  2533. current[CLASS] = next[CLASS];
  2534. continue;
  2535. }
  2536. if (key2 === "style") {
  2537. set_style(element, value, prev == null ? void 0 : prev[STYLE], next[STYLE]);
  2538. current[key2] = value;
  2539. current[STYLE] = next[STYLE];
  2540. continue;
  2541. }
  2542. var prev_value = current[key2];
  2543. if (value === prev_value && !(value === void 0 && element.hasAttribute(key2))) {
  2544. continue;
  2545. }
  2546. current[key2] = value;
  2547. var prefix = key2[0] + key2[1];
  2548. if (prefix === "$$") continue;
  2549. if (prefix === "on") {
  2550. const opts = {};
  2551. const event_handle_key = "$$" + key2;
  2552. let event_name = key2.slice(2);
  2553. var delegated = is_delegated(event_name);
  2554. if (is_capture_event(event_name)) {
  2555. event_name = event_name.slice(0, -7);
  2556. opts.capture = true;
  2557. }
  2558. if (!delegated && prev_value) {
  2559. if (value != null) continue;
  2560. element.removeEventListener(event_name, current[event_handle_key], opts);
  2561. current[event_handle_key] = null;
  2562. }
  2563. if (value != null) {
  2564. if (!delegated) {
  2565. let handle = function(evt) {
  2566. current[key2].call(this, evt);
  2567. };
  2568. current[event_handle_key] = create_event(event_name, element, handle, opts);
  2569. } else {
  2570. element[`__${event_name}`] = value;
  2571. delegate([event_name]);
  2572. }
  2573. } else if (delegated) {
  2574. element[`__${event_name}`] = void 0;
  2575. }
  2576. } else if (key2 === "style") {
  2577. set_attribute(element, key2, value);
  2578. } else if (key2 === "autofocus") {
  2579. autofocus(
  2580. /** @type {HTMLElement} */
  2581. element,
  2582. Boolean(value)
  2583. );
  2584. } else if (!is_custom_element && (key2 === "__value" || key2 === "value" && value != null)) {
  2585. element.value = element.__value = value;
  2586. } else if (key2 === "selected" && is_option_element) {
  2587. set_selected(
  2588. /** @type {HTMLOptionElement} */
  2589. element,
  2590. value
  2591. );
  2592. } else {
  2593. var name = key2;
  2594. if (!preserve_attribute_case) {
  2595. name = normalize_attribute(name);
  2596. }
  2597. var is_default = name === "defaultValue" || name === "defaultChecked";
  2598. if (value == null && !is_custom_element && !is_default) {
  2599. attributes[key2] = null;
  2600. if (name === "value" || name === "checked") {
  2601. let input = (
  2602. /** @type {HTMLInputElement} */
  2603. element
  2604. );
  2605. const use_default = prev === void 0;
  2606. if (name === "value") {
  2607. let previous = input.defaultValue;
  2608. input.removeAttribute(name);
  2609. input.defaultValue = previous;
  2610. input.value = input.__value = use_default ? previous : null;
  2611. } else {
  2612. let previous = input.defaultChecked;
  2613. input.removeAttribute(name);
  2614. input.defaultChecked = previous;
  2615. input.checked = use_default ? previous : false;
  2616. }
  2617. } else {
  2618. element.removeAttribute(key2);
  2619. }
  2620. } else if (is_default || setters.includes(name) && (is_custom_element || typeof value !== "string")) {
  2621. element[name] = value;
  2622. } else if (typeof value !== "function") {
  2623. set_attribute(element, name, value);
  2624. }
  2625. }
  2626. }
  2627. return current;
  2628. }
  2629. function attribute_effect(element, fn, thunks = [], css_hash, skip_warning = false, d2 = derived) {
  2630. const deriveds = thunks.map(d2);
  2631. var prev = void 0;
  2632. var effects = {};
  2633. var is_select = element.nodeName === "SELECT";
  2634. var inited = false;
  2635. block(() => {
  2636. var next = fn(...deriveds.map(get));
  2637. var current = set_attributes(element, prev, next, css_hash, skip_warning);
  2638. if (inited && is_select && "value" in next) {
  2639. select_option(
  2640. /** @type {HTMLSelectElement} */
  2641. element,
  2642. next.value,
  2643. false
  2644. );
  2645. }
  2646. for (let symbol of Object.getOwnPropertySymbols(effects)) {
  2647. if (!next[symbol]) destroy_effect(effects[symbol]);
  2648. }
  2649. for (let symbol of Object.getOwnPropertySymbols(next)) {
  2650. var n2 = next[symbol];
  2651. if (symbol.description === ATTACHMENT_KEY && (!prev || n2 !== prev[symbol])) {
  2652. if (effects[symbol]) destroy_effect(effects[symbol]);
  2653. effects[symbol] = branch(() => attach(element, () => n2));
  2654. }
  2655. current[symbol] = n2;
  2656. }
  2657. prev = current;
  2658. });
  2659. if (is_select) {
  2660. init_select(
  2661. /** @type {HTMLSelectElement} */
  2662. element,
  2663. () => (
  2664. /** @type {Record<string | symbol, any>} */
  2665. prev.value
  2666. )
  2667. );
  2668. }
  2669. inited = true;
  2670. }
  2671. function get_attributes(element) {
  2672. return (
  2673. /** @type {Record<string | symbol, unknown>} **/
  2674. // @ts-expect-error
  2675. element.__attributes ?? (element.__attributes = {
  2676. [IS_CUSTOM_ELEMENT]: element.nodeName.includes("-"),
  2677. [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
  2678. })
  2679. );
  2680. }
  2681. var setters_cache = /* @__PURE__ */ new Map();
  2682. function get_setters(element) {
  2683. var setters = setters_cache.get(element.nodeName);
  2684. if (setters) return setters;
  2685. setters_cache.set(element.nodeName, setters = []);
  2686. var descriptors;
  2687. var proto = element;
  2688. var element_proto = Element.prototype;
  2689. while (element_proto !== proto) {
  2690. descriptors = get_descriptors(proto);
  2691. for (var key in descriptors) {
  2692. if (descriptors[key].set) {
  2693. setters.push(key);
  2694. }
  2695. }
  2696. proto = get_prototype_of(proto);
  2697. }
  2698. return setters;
  2699. }
  2700. function init(immutable = false) {
  2701. const context = (
  2702. /** @type {ComponentContextLegacy} */
  2703. component_context
  2704. );
  2705. const callbacks = context.l.u;
  2706. if (!callbacks) return;
  2707. let props = () => deep_read_state(context.s);
  2708. if (immutable) {
  2709. let version = 0;
  2710. let prev = (
  2711. /** @type {Record<string, any>} */
  2712. {}
  2713. );
  2714. const d2 = /* @__PURE__ */ derived(() => {
  2715. let changed = false;
  2716. const props2 = context.s;
  2717. for (const key in props2) {
  2718. if (props2[key] !== prev[key]) {
  2719. prev[key] = props2[key];
  2720. changed = true;
  2721. }
  2722. }
  2723. if (changed) version++;
  2724. return version;
  2725. });
  2726. props = () => get(d2);
  2727. }
  2728. if (callbacks.b.length) {
  2729. user_pre_effect(() => {
  2730. observe_all(context, props);
  2731. run_all(callbacks.b);
  2732. });
  2733. }
  2734. user_effect(() => {
  2735. const fns = untrack(() => callbacks.m.map(run));
  2736. return () => {
  2737. for (const fn of fns) {
  2738. if (typeof fn === "function") {
  2739. fn();
  2740. }
  2741. }
  2742. };
  2743. });
  2744. if (callbacks.a.length) {
  2745. user_effect(() => {
  2746. observe_all(context, props);
  2747. run_all(callbacks.a);
  2748. });
  2749. }
  2750. }
  2751. function observe_all(context, props) {
  2752. if (context.l.s) {
  2753. for (const signal of context.l.s) get(signal);
  2754. }
  2755. props();
  2756. }
  2757. const rest_props_handler = {
  2758. get(target, key) {
  2759. if (target.exclude.includes(key)) return;
  2760. return target.props[key];
  2761. },
  2762. set(target, key) {
  2763. return false;
  2764. },
  2765. getOwnPropertyDescriptor(target, key) {
  2766. if (target.exclude.includes(key)) return;
  2767. if (key in target.props) {
  2768. return {
  2769. enumerable: true,
  2770. configurable: true,
  2771. value: target.props[key]
  2772. };
  2773. }
  2774. },
  2775. has(target, key) {
  2776. if (target.exclude.includes(key)) return false;
  2777. return key in target.props;
  2778. },
  2779. ownKeys(target) {
  2780. return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key));
  2781. }
  2782. };
  2783. // @__NO_SIDE_EFFECTS__
  2784. function rest_props(props, exclude, name) {
  2785. return new Proxy(
  2786. { props, exclude },
  2787. rest_props_handler
  2788. );
  2789. }
  2790. function prop(props, key, flags, fallback) {
  2791. var prop_value;
  2792. {
  2793. prop_value = /** @type {V} */
  2794. props[key];
  2795. }
  2796. var fallback_value = (
  2797. /** @type {V} */
  2798. fallback
  2799. );
  2800. var fallback_dirty = true;
  2801. var get_fallback = () => {
  2802. if (fallback_dirty) {
  2803. fallback_dirty = false;
  2804. {
  2805. fallback_value = /** @type {V} */
  2806. fallback;
  2807. }
  2808. }
  2809. return fallback_value;
  2810. };
  2811. if (prop_value === void 0 && fallback !== void 0) {
  2812. prop_value = get_fallback();
  2813. }
  2814. var getter;
  2815. {
  2816. getter = () => {
  2817. var value = (
  2818. /** @type {V} */
  2819. props[key]
  2820. );
  2821. if (value === void 0) return get_fallback();
  2822. fallback_dirty = true;
  2823. return value;
  2824. };
  2825. }
  2826. {
  2827. return getter;
  2828. }
  2829. }
  2830. const PUBLIC_VERSION = "5";
  2831. if (typeof window !== "undefined") {
  2832. ((_a = window.__svelte ?? (window.__svelte = {})).v ?? (_a.v = /* @__PURE__ */ new Set())).add(PUBLIC_VERSION);
  2833. }
  2834. enable_legacy_mode_flag();
  2835. var root = /* @__PURE__ */ from_html(`<div><!></div>`);
  2836. function ButtonGroup($$anchor, $$props) {
  2837. let props = /* @__PURE__ */ rest_props($$props, [
  2838. "$$slots",
  2839. "$$events",
  2840. "$$legacy",
  2841. "children"
  2842. ]);
  2843. var div = root();
  2844. attribute_effect(div, () => ({ ...props }), void 0, "svelte-4mbyk0");
  2845. var node = child(div);
  2846. snippet(node, () => $$props.children);
  2847. append($$anchor, div);
  2848. }
  2849. const mouseClickEvents = ["mousedown", "mouseup", "click"];
  2850. function simulateMouseClickReact(element) {
  2851. mouseClickEvents.forEach(
  2852. (mouseEventType) => element.dispatchEvent(
  2853. new MouseEvent(mouseEventType, {
  2854. view: _unsafeWindow,
  2855. bubbles: true,
  2856. cancelable: true,
  2857. buttons: 1
  2858. })
  2859. )
  2860. );
  2861. }
  2862. const loaderIcon = ($$anchor) => {
  2863. var svg = root_1$3();
  2864. append($$anchor, svg);
  2865. };
  2866. var root_1$3 = /* @__PURE__ */ from_svg(`<svg class="animate-spin" xmlns="http://www.w3.org/2000/svg" width="1rem" height="1rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2v4m4.2 1.8l2.9-2.9M18 12h4m-5.8 4.2l2.9 2.9M12 18v4m-7.1-2.9l2.9-2.9M2 12h4M4.9 4.9l2.9 2.9"></path></svg>`);
  2867. var root_2 = /* @__PURE__ */ from_html(`<a><!></a>`);
  2868. var root_3 = /* @__PURE__ */ from_html(`<button><!> <!></button>`);
  2869. function Button($$anchor, $$props) {
  2870. push($$props, true);
  2871. let variant = prop($$props, "variant", 3, "purple"), type = prop($$props, "type", 3, "button"), restProps = /* @__PURE__ */ rest_props($$props, [
  2872. "$$slots",
  2873. "$$events",
  2874. "$$legacy",
  2875. "onclick",
  2876. "children",
  2877. "variant",
  2878. "type",
  2879. "href"
  2880. ]);
  2881. const variants = {
  2882. purple: "--bg: #6c5ce7; --shadow: #a29bfe",
  2883. green: "--bg: #1ba13e; --shadow: #42de6e",
  2884. orange: "--bg: #ffa116; --shadow: #fedd9b"
  2885. };
  2886. let loading = /* @__PURE__ */ state(false);
  2887. async function handleOnClick(e$1) {
  2888. if (!$$props.onclick) return;
  2889. const returnValue = $$props.onclick(e$1);
  2890. if (e(returnValue)) {
  2891. set(loading, true);
  2892. await returnValue;
  2893. set(loading, false);
  2894. }
  2895. }
  2896. var fragment = comment();
  2897. var node = first_child(fragment);
  2898. {
  2899. var consequent = ($$anchor2) => {
  2900. var a2 = root_2();
  2901. attribute_effect(
  2902. a2,
  2903. () => ({
  2904. style: variants[variant()],
  2905. href: $$props.href,
  2906. target: "_blank",
  2907. ...restProps
  2908. }),
  2909. void 0,
  2910. "svelte-ll0ynk"
  2911. );
  2912. var node_1 = child(a2);
  2913. snippet(node_1, () => $$props.children ?? noop);
  2914. append($$anchor2, a2);
  2915. };
  2916. var alternate = ($$anchor2) => {
  2917. var button = root_3();
  2918. attribute_effect(
  2919. button,
  2920. () => ({
  2921. style: variants[variant()],
  2922. type: type(),
  2923. disabled: get(loading),
  2924. onclick: handleOnClick,
  2925. ...restProps
  2926. }),
  2927. void 0,
  2928. "svelte-ll0ynk"
  2929. );
  2930. var node_2 = child(button);
  2931. {
  2932. var consequent_1 = ($$anchor3) => {
  2933. loaderIcon($$anchor3);
  2934. };
  2935. if_block(node_2, ($$render) => {
  2936. if (get(loading)) $$render(consequent_1);
  2937. });
  2938. }
  2939. var node_3 = sibling(node_2, 2);
  2940. snippet(node_3, () => $$props.children ?? noop);
  2941. append($$anchor2, button);
  2942. };
  2943. if_block(node, ($$render) => {
  2944. if ($$props.href) $$render(consequent);
  2945. else $$render(alternate, false);
  2946. });
  2947. }
  2948. append($$anchor, fragment);
  2949. pop();
  2950. }
  2951. async function copyText(text2) {
  2952. try {
  2953. await navigator.clipboard.writeText(text2);
  2954. } catch (err) {
  2955. if (err instanceof Error) {
  2956. console.error(err);
  2957. }
  2958. throw err;
  2959. }
  2960. }
  2961. const getTitle = async () => {
  2962. const descriptionTabButton = (await findElement("#description_tab")).closest(".flexlayout__tab_button");
  2963. if (!(descriptionTabButton == null ? void 0 : descriptionTabButton.classList.contains(".flexlayout__tab_button--selected"))) {
  2964. simulateMouseClickReact(descriptionTabButton);
  2965. }
  2966. return (await findElement(".text-title-large")).textContent ?? "";
  2967. };
  2968. function Copy_title($$anchor, $$props) {
  2969. push($$props, false);
  2970. async function copyTitle() {
  2971. copyText(await getTitle());
  2972. toaster.success(globalState.site === "cn" ? "已复制题目标题到剪贴板" : "Problem title copied to clipboard");
  2973. }
  2974. init();
  2975. Button($$anchor, {
  2976. onclick: copyTitle,
  2977. children: ($$anchor2, $$slotProps) => {
  2978. var text$1 = text();
  2979. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制标题" : "Copy Title"));
  2980. append($$anchor2, text$1);
  2981. },
  2982. $$slots: { default: true }
  2983. });
  2984. pop();
  2985. }
  2986. var turndownPluginGfm_cjs = {};
  2987. var hasRequiredTurndownPluginGfm_cjs;
  2988. function requireTurndownPluginGfm_cjs() {
  2989. if (hasRequiredTurndownPluginGfm_cjs) return turndownPluginGfm_cjs;
  2990. hasRequiredTurndownPluginGfm_cjs = 1;
  2991. Object.defineProperty(turndownPluginGfm_cjs, "__esModule", { value: true });
  2992. var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
  2993. function highlightedCodeBlock(turndownService) {
  2994. turndownService.addRule("highlightedCodeBlock", {
  2995. filter: function(node) {
  2996. var firstChild = node.firstChild;
  2997. return node.nodeName === "DIV" && highlightRegExp.test(node.className) && firstChild && firstChild.nodeName === "PRE";
  2998. },
  2999. replacement: function(content, node, options) {
  3000. var className = node.className || "";
  3001. var language = (className.match(highlightRegExp) || [null, ""])[1];
  3002. return "\n\n" + options.fence + language + "\n" + node.firstChild.textContent + "\n" + options.fence + "\n\n";
  3003. }
  3004. });
  3005. }
  3006. function strikethrough(turndownService) {
  3007. turndownService.addRule("strikethrough", {
  3008. filter: ["del", "s", "strike"],
  3009. replacement: function(content) {
  3010. return "~~" + content + "~~";
  3011. }
  3012. });
  3013. }
  3014. var indexOf = Array.prototype.indexOf;
  3015. var every = Array.prototype.every;
  3016. var rules = {};
  3017. var alignMap = { left: ":---", right: "---:", center: ":---:" };
  3018. let isCodeBlock_ = null;
  3019. let options_ = null;
  3020. const tableShouldBeSkippedCache_ = /* @__PURE__ */ new WeakMap();
  3021. function getAlignment(node) {
  3022. return node ? (node.getAttribute("align") || node.style.textAlign || "").toLowerCase() : "";
  3023. }
  3024. function getBorder(alignment) {
  3025. return alignment ? alignMap[alignment] : "---";
  3026. }
  3027. function getColumnAlignment(table, columnIndex) {
  3028. var votes = {
  3029. left: 0,
  3030. right: 0,
  3031. center: 0,
  3032. "": 0
  3033. };
  3034. var align = "";
  3035. for (var i2 = 0; i2 < table.rows.length; ++i2) {
  3036. var row = table.rows[i2];
  3037. if (columnIndex < row.childNodes.length) {
  3038. var cellAlignment = getAlignment(row.childNodes[columnIndex]);
  3039. ++votes[cellAlignment];
  3040. if (votes[cellAlignment] > votes[align]) {
  3041. align = cellAlignment;
  3042. }
  3043. }
  3044. }
  3045. return align;
  3046. }
  3047. rules.tableCell = {
  3048. filter: ["th", "td"],
  3049. replacement: function(content, node) {
  3050. if (tableShouldBeSkipped(nodeParentTable(node))) return content;
  3051. return cell(content, node);
  3052. }
  3053. };
  3054. rules.tableRow = {
  3055. filter: "tr",
  3056. replacement: function(content, node) {
  3057. const parentTable = nodeParentTable(node);
  3058. if (tableShouldBeSkipped(parentTable)) return content;
  3059. var borderCells = "";
  3060. if (isHeadingRow(node)) {
  3061. const colCount = tableColCount(parentTable);
  3062. for (var i2 = 0; i2 < colCount; i2++) {
  3063. const childNode = i2 < node.childNodes.length ? node.childNodes[i2] : null;
  3064. var border = getBorder(getColumnAlignment(parentTable, i2));
  3065. borderCells += cell(border, childNode, i2);
  3066. }
  3067. }
  3068. return "\n" + content + (borderCells ? "\n" + borderCells : "");
  3069. }
  3070. };
  3071. rules.table = {
  3072. filter: function(node, options) {
  3073. return node.nodeName === "TABLE";
  3074. },
  3075. replacement: function(content, node) {
  3076. if (tableShouldBeHtml(node, options_)) {
  3077. let html = node.outerHTML;
  3078. let divParent = nodeParentDiv(node);
  3079. if (divParent === null || !divParent.classList.contains("joplin-table-wrapper")) {
  3080. return `
  3081.  
  3082. <div class="joplin-table-wrapper">${html}</div>
  3083.  
  3084. `;
  3085. } else {
  3086. return html;
  3087. }
  3088. } else {
  3089. if (tableShouldBeSkipped(node)) return content;
  3090. content = content.replace(/\n+/g, "\n");
  3091. var secondLine = content.trim().split("\n");
  3092. if (secondLine.length >= 2) secondLine = secondLine[1];
  3093. var secondLineIsDivider = /\| :?---/.test(secondLine);
  3094. var columnCount = tableColCount(node);
  3095. var emptyHeader = "";
  3096. if (columnCount && !secondLineIsDivider) {
  3097. emptyHeader = "|" + " |".repeat(columnCount) + "\n|";
  3098. for (var columnIndex = 0; columnIndex < columnCount; ++columnIndex) {
  3099. emptyHeader += " " + getBorder(getColumnAlignment(node, columnIndex)) + " |";
  3100. }
  3101. }
  3102. const captionContent = node.caption ? node.caption.textContent || "" : "";
  3103. const caption = captionContent ? `${captionContent}
  3104.  
  3105. ` : "";
  3106. const tableContent = `${emptyHeader}${content}`.trimStart();
  3107. return `
  3108.  
  3109. ${caption}${tableContent}
  3110.  
  3111. `;
  3112. }
  3113. }
  3114. };
  3115. rules.tableCaption = {
  3116. filter: ["caption"],
  3117. replacement: () => ""
  3118. };
  3119. rules.tableColgroup = {
  3120. filter: ["colgroup", "col"],
  3121. replacement: () => ""
  3122. };
  3123. rules.tableSection = {
  3124. filter: ["thead", "tbody", "tfoot"],
  3125. replacement: function(content) {
  3126. return content;
  3127. }
  3128. };
  3129. function isHeadingRow(tr) {
  3130. var parentNode = tr.parentNode;
  3131. return parentNode.nodeName === "THEAD" || parentNode.firstChild === tr && (parentNode.nodeName === "TABLE" || isFirstTbody(parentNode)) && every.call(tr.childNodes, function(n2) {
  3132. return n2.nodeName === "TH";
  3133. });
  3134. }
  3135. function isFirstTbody(element) {
  3136. var previousSibling = element.previousSibling;
  3137. return element.nodeName === "TBODY" && (!previousSibling || previousSibling.nodeName === "THEAD" && /^\s*$/i.test(previousSibling.textContent));
  3138. }
  3139. function cell(content, node = null, index = null) {
  3140. if (index === null) index = indexOf.call(node.parentNode.childNodes, node);
  3141. var prefix = " ";
  3142. if (index === 0) prefix = "| ";
  3143. let filteredContent = content.trim().replace(/\n\r/g, "<br>").replace(/\n/g, "<br>");
  3144. filteredContent = filteredContent.replace(/\|+/g, "\\|");
  3145. while (filteredContent.length < 3) filteredContent += " ";
  3146. if (node) filteredContent = handleColSpan(filteredContent, node, " ");
  3147. return prefix + filteredContent + " |";
  3148. }
  3149. function nodeContainsTable(node) {
  3150. if (!node.childNodes) return false;
  3151. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  3152. const child2 = node.childNodes[i2];
  3153. if (child2.nodeName === "TABLE") return true;
  3154. if (nodeContainsTable(child2)) return true;
  3155. }
  3156. return false;
  3157. }
  3158. const nodeContains = (node, types) => {
  3159. if (!node.childNodes) return false;
  3160. for (let i2 = 0; i2 < node.childNodes.length; i2++) {
  3161. const child2 = node.childNodes[i2];
  3162. if (types === "code" && isCodeBlock_ && isCodeBlock_(child2)) return true;
  3163. if (types.includes(child2.nodeName)) return true;
  3164. if (nodeContains(child2, types)) return true;
  3165. }
  3166. return false;
  3167. };
  3168. const tableShouldBeHtml = (tableNode, options) => {
  3169. const possibleTags = [
  3170. "UL",
  3171. "OL",
  3172. "H1",
  3173. "H2",
  3174. "H3",
  3175. "H4",
  3176. "H5",
  3177. "H6",
  3178. "HR",
  3179. "BLOCKQUOTE"
  3180. ];
  3181. if (options.preserveNestedTables) possibleTags.push("TABLE");
  3182. return nodeContains(tableNode, "code") || nodeContains(tableNode, possibleTags);
  3183. };
  3184. function tableShouldBeSkipped(tableNode) {
  3185. const cached = tableShouldBeSkippedCache_.get(tableNode);
  3186. if (cached !== void 0) return cached;
  3187. const result = tableShouldBeSkipped_(tableNode);
  3188. tableShouldBeSkippedCache_.set(tableNode, result);
  3189. return result;
  3190. }
  3191. function tableShouldBeSkipped_(tableNode) {
  3192. if (!tableNode) return true;
  3193. if (!tableNode.rows) return true;
  3194. if (tableNode.rows.length === 1 && tableNode.rows[0].childNodes.length <= 1) return true;
  3195. if (nodeContainsTable(tableNode)) return true;
  3196. return false;
  3197. }
  3198. function nodeParentDiv(node) {
  3199. let parent = node.parentNode;
  3200. while (parent.nodeName !== "DIV") {
  3201. parent = parent.parentNode;
  3202. if (!parent) return null;
  3203. }
  3204. return parent;
  3205. }
  3206. function nodeParentTable(node) {
  3207. let parent = node.parentNode;
  3208. while (parent.nodeName !== "TABLE") {
  3209. parent = parent.parentNode;
  3210. if (!parent) return null;
  3211. }
  3212. return parent;
  3213. }
  3214. function handleColSpan(content, node, emptyChar) {
  3215. const colspan = node.getAttribute("colspan") || 1;
  3216. for (let i2 = 1; i2 < colspan; i2++) {
  3217. content += " | " + emptyChar.repeat(3);
  3218. }
  3219. return content;
  3220. }
  3221. function tableColCount(node) {
  3222. let maxColCount = 0;
  3223. for (let i2 = 0; i2 < node.rows.length; i2++) {
  3224. const row = node.rows[i2];
  3225. const colCount = row.childNodes.length;
  3226. if (colCount > maxColCount) maxColCount = colCount;
  3227. }
  3228. return maxColCount;
  3229. }
  3230. function tables(turndownService) {
  3231. isCodeBlock_ = turndownService.isCodeBlock;
  3232. options_ = turndownService.options;
  3233. turndownService.keep(function(node) {
  3234. if (node.nodeName === "TABLE" && tableShouldBeHtml(node, turndownService.options)) return true;
  3235. return false;
  3236. });
  3237. for (var key in rules) turndownService.addRule(key, rules[key]);
  3238. }
  3239. function taskListItems(turndownService) {
  3240. turndownService.addRule("taskListItems", {
  3241. filter: function(node) {
  3242. return node.type === "checkbox" && node.parentNode.nodeName === "LI";
  3243. },
  3244. replacement: function(content, node) {
  3245. return (node.checked ? "[x]" : "[ ]") + " ";
  3246. }
  3247. });
  3248. }
  3249. function gfm(turndownService) {
  3250. turndownService.use([
  3251. highlightedCodeBlock,
  3252. strikethrough,
  3253. tables,
  3254. taskListItems
  3255. ]);
  3256. }
  3257. turndownPluginGfm_cjs.gfm = gfm;
  3258. turndownPluginGfm_cjs.highlightedCodeBlock = highlightedCodeBlock;
  3259. turndownPluginGfm_cjs.strikethrough = strikethrough;
  3260. turndownPluginGfm_cjs.tables = tables;
  3261. turndownPluginGfm_cjs.taskListItems = taskListItems;
  3262. return turndownPluginGfm_cjs;
  3263. }
  3264. var turndownPluginGfm_cjsExports = requireTurndownPluginGfm_cjs();
  3265. var M = "__monkeyWindow-" + (() => {
  3266. try {
  3267. return new URL((_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('__entry.js', document.baseURI).href)).origin;
  3268. } catch {
  3269. return location.origin;
  3270. }
  3271. })(), y = document[M] ?? window, g = y.GM, v = y.GM_xmlhttpRequest;
  3272. function k(l2) {
  3273. var e2;
  3274. const t = new Headers(), a2 = l2.replace(/\r?\n[\t ]+/g, " ");
  3275. for (const d2 of a2.split(/\r?\n/)) {
  3276. const i2 = d2.split(":"), o2 = (e2 = i2.shift()) == null ? void 0 : e2.trim();
  3277. if (o2) {
  3278. const r2 = i2.join(":").trim();
  3279. try {
  3280. t.append(o2, r2);
  3281. } catch (c2) {
  3282. console.warn(`Response ${c2.message}`);
  3283. }
  3284. }
  3285. }
  3286. return t;
  3287. }
  3288. const H = async (l2, t) => {
  3289. const a2 = v || g.xmlHttpRequest;
  3290. if (typeof a2 != "function")
  3291. throw new DOMException(
  3292. "GM_xmlhttpRequest or GM.xmlHttpRequest is not granted.",
  3293. "NotFoundError"
  3294. );
  3295. const e2 = new Request(l2, t);
  3296. if (e2.signal.aborted)
  3297. throw new DOMException("Network request aborted.", "AbortError");
  3298. const d2 = await e2.blob(), i2 = Object.fromEntries(e2.headers);
  3299. return new Headers(void 0).forEach((o2, r2) => {
  3300. i2[r2] = o2;
  3301. }), new Promise((o2, r2) => {
  3302. let c2 = false;
  3303. const R = new Promise((n2) => {
  3304. const { abort: h } = a2({
  3305. method: e2.method.toUpperCase(),
  3306. url: e2.url || location.href,
  3307. headers: i2,
  3308. data: d2.size ? d2 : void 0,
  3309. redirect: e2.redirect,
  3310. binary: true,
  3311. nocache: e2.cache === "no-store",
  3312. revalidate: e2.cache === "reload",
  3313. timeout: 3e5,
  3314. responseType: a2.RESPONSE_TYPE_STREAM ?? "blob",
  3315. overrideMimeType: e2.headers.get("Content-Type") ?? void 0,
  3316. anonymous: e2.credentials === "omit",
  3317. onload: ({ response: s }) => {
  3318. if (c2) {
  3319. n2(null);
  3320. return;
  3321. }
  3322. n2(s);
  3323. },
  3324. async onreadystatechange({
  3325. readyState: s,
  3326. responseHeaders: p2,
  3327. status: b2,
  3328. statusText: q,
  3329. finalUrl: w2,
  3330. response: E
  3331. }) {
  3332. if (s === XMLHttpRequest.DONE)
  3333. e2.signal.removeEventListener("abort", h);
  3334. else if (s !== XMLHttpRequest.HEADERS_RECEIVED)
  3335. return;
  3336. if (c2) {
  3337. n2(null);
  3338. return;
  3339. }
  3340. const u2 = k(p2), f2 = e2.url !== w2, m2 = new Response(
  3341. E instanceof ReadableStream ? E : await R,
  3342. {
  3343. headers: u2,
  3344. status: b2,
  3345. statusText: q
  3346. }
  3347. );
  3348. Object.defineProperties(m2, {
  3349. url: {
  3350. value: w2
  3351. },
  3352. type: {
  3353. value: "basic"
  3354. },
  3355. ...m2.redirected !== f2 ? {
  3356. redirected: {
  3357. value: f2
  3358. }
  3359. } : {},
  3360. // https://fetch.spec.whatwg.org/#forbidden-response-header-name
  3361. ...u2.has("set-cookie") || u2.has("set-cookie2") ? {
  3362. headers: {
  3363. value: u2
  3364. }
  3365. } : {}
  3366. }), o2(m2), c2 = true;
  3367. },
  3368. onerror: ({ statusText: s, error: p2 }) => {
  3369. r2(
  3370. new TypeError(s || p2 || "Network request failed.")
  3371. ), n2(null);
  3372. },
  3373. ontimeout() {
  3374. r2(new TypeError("Network request timeout.")), n2(null);
  3375. },
  3376. onabort() {
  3377. r2(new DOMException("Network request aborted.", "AbortError")), n2(null);
  3378. }
  3379. });
  3380. e2.signal.addEventListener("abort", h);
  3381. });
  3382. });
  3383. };
  3384. async function compressImage(image) {
  3385. return new Promise((resolve, reject) => {
  3386. new Compressor(image, {
  3387. success: resolve,
  3388. error: reject
  3389. });
  3390. });
  3391. }
  3392. function blobToDataURL(blob) {
  3393. return new Promise((resolve, reject) => {
  3394. const reader = new FileReader();
  3395. reader.onload = () => resolve(reader.result);
  3396. reader.onerror = (error) => reject(error);
  3397. reader.readAsDataURL(blob);
  3398. });
  3399. }
  3400. async function convertSrcToDataURL(src) {
  3401. if (src.startsWith("data:")) {
  3402. return src;
  3403. }
  3404. try {
  3405. const response = await H(src);
  3406. let blob = await response.blob();
  3407. const incompressableTypes = ["image/gif", "image/svg+xml"];
  3408. if (!incompressableTypes.includes(blob.type)) {
  3409. blob = await compressImage(blob);
  3410. }
  3411. const dataURL = await blobToDataURL(blob);
  3412. return dataURL;
  3413. } catch (err) {
  3414. console.error(`Failed to convert image: ${src}`, err);
  3415. throw err;
  3416. }
  3417. }
  3418. const imageCache = /* @__PURE__ */ new Map();
  3419. async function prefetchImages(node) {
  3420. const images = Array.from(node.querySelectorAll("img"));
  3421. const fetchPromises = images.map(async ({ src }) => {
  3422. if (imageCache.has(src)) return;
  3423. const dataURL = await convertSrcToDataURL(src);
  3424. imageCache.set(src, dataURL);
  3425. });
  3426. await Promise.all(fetchPromises);
  3427. }
  3428. function createTurndownService() {
  3429. const turndown2 = new TurndownService({
  3430. emDelimiter: "*",
  3431. bulletListMarker: "-"
  3432. });
  3433. turndown2.addRule("pre", {
  3434. filter: ["pre"],
  3435. replacement: (_content, node) => {
  3436. var _a2;
  3437. return "\n```txt\n" + ((_a2 = node.textContent) == null ? void 0 : _a2.trim()) + "\n```\n";
  3438. }
  3439. });
  3440. turndown2.addRule("superscript", {
  3441. filter: ["sup"],
  3442. replacement: (content) => "^" + content
  3443. });
  3444. turndown2.addRule("paragraph", {
  3445. filter: ["p"],
  3446. replacement: (content) => "\n\n" + content + "\n\n"
  3447. });
  3448. turndown2.addRule("convert-img-src-to-base64", {
  3449. filter: ["img"],
  3450. replacement: (_content, node) => {
  3451. const { src, alt } = node;
  3452. const dataURL = imageCache.get(src);
  3453. if (dataURL) {
  3454. return `![${alt}](${dataURL})`;
  3455. }
  3456. return `![${alt}](${src})`;
  3457. }
  3458. });
  3459. turndown2.use(turndownPluginGfm_cjsExports.tables);
  3460. return turndown2;
  3461. }
  3462. async function htmlToMd(node, {
  3463. turndownService = createTurndownService(),
  3464. convertImage = true
  3465. } = {}) {
  3466. if (convertImage) await prefetchImages(node);
  3467. const md = turndownService.turndown(node);
  3468. if (convertImage) imageCache.clear();
  3469. return md;
  3470. }
  3471. const getDescription = async (convertImage = true) => {
  3472. const el = await findElement("div[data-track-load='description_content']");
  3473. return htmlToMd(el, { convertImage });
  3474. };
  3475. function Copy_description($$anchor, $$props) {
  3476. push($$props, false);
  3477. async function copyDescription() {
  3478. const desc = await getDescription(false);
  3479. copyText(desc);
  3480. toaster.success(globalState.site === "cn" ? "已复制题目描述到剪贴板" : "Problem description copied to clipboard");
  3481. }
  3482. init();
  3483. Button($$anchor, {
  3484. variant: "green",
  3485. onclick: copyDescription,
  3486. children: ($$anchor2, $$slotProps) => {
  3487. var text$1 = text();
  3488. template_effect(() => set_text(text$1, globalState.site === "cn" ? "复制描述" : "Copy Description"));
  3489. append($$anchor2, text$1);
  3490. },
  3491. $$slots: { default: true }
  3492. });
  3493. pop();
  3494. }
  3495. function downloadFile(blob, filename, extension) {
  3496. const url2 = URL.createObjectURL(blob);
  3497. const a2 = document.createElement("a");
  3498. a2.href = url2;
  3499. a2.download = filename + "." + extension;
  3500. document.body.appendChild(a2);
  3501. a2.click();
  3502. document.body.removeChild(a2);
  3503. URL.revokeObjectURL(url2);
  3504. }
  3505. class NotebookBuilder {
  3506. constructor() {
  3507. __privateAdd(this, _cells, []);
  3508. __privateAdd(this, _metadata, {});
  3509. __privateAdd(this, _nbformat, 5);
  3510. __privateAdd(this, _nbformat_minor, 10);
  3511. }
  3512. addMarkdown(content) {
  3513. const md = {
  3514. cell_type: "markdown",
  3515. metadata: {},
  3516. source: content
  3517. };
  3518. __privateGet(this, _cells).push(md);
  3519. return this;
  3520. }
  3521. /** Add a level one heading. There should be only one title in a document. */
  3522. addTitle(title, url2) {
  3523. this.addMarkdown(`# [${title}](${url2})`);
  3524. return this;
  3525. }
  3526. addSection(heading, content) {
  3527. this.addMarkdown(`## ${heading}
  3528.  
  3529. ${content ?? ""}`);
  3530. return this;
  3531. }
  3532. /** Add a horizontal rule (`<hr>` in html) or line that visually separates content */
  3533. addHorizontalRule() {
  3534. this.addMarkdown("---\n\n");
  3535. return this;
  3536. }
  3537. addCode(content) {
  3538. const code = {
  3539. cell_type: "code",
  3540. metadata: {},
  3541. source: content,
  3542. execution_count: null,
  3543. outputs: []
  3544. };
  3545. __privateGet(this, _cells).push(code);
  3546. return this;
  3547. }
  3548. setLanguage(language) {
  3549. __privateGet(this, _metadata).language_info = {
  3550. name: language
  3551. };
  3552. return this;
  3553. }
  3554. build() {
  3555. return {
  3556. metadata: __privateGet(this, _metadata),
  3557. nbformat: __privateGet(this, _nbformat),
  3558. nbformat_minor: __privateGet(this, _nbformat_minor),
  3559. cells: __privateGet(this, _cells)
  3560. };
  3561. }
  3562. download(filename) {
  3563. const notebook = this.build();
  3564. const blob = new Blob([JSON.stringify(notebook)], {
  3565. type: "application/x-ipynb+json"
  3566. });
  3567. downloadFile(blob, filename, "ipynb");
  3568. }
  3569. }
  3570. _cells = new WeakMap();
  3571. _metadata = new WeakMap();
  3572. _nbformat = new WeakMap();
  3573. _nbformat_minor = new WeakMap();
  3574. function Download_as_jupyter($$anchor, $$props) {
  3575. push($$props, false);
  3576. async function saveAsJupyter() {
  3577. var _a2, _b, _c, _d;
  3578. const builder = new NotebookBuilder();
  3579. const title = await getTitle();
  3580. const url2 = window.location.href;
  3581. const urlRegex = /^(https:\/\/(leetcode\.com|leetcode\.cn)\/problems\/[a-zA-Z0-9_-]+)/;
  3582. const urlMatch = url2.match(urlRegex);
  3583. builder.addTitle(title, urlMatch ? urlMatch[0] : url2);
  3584. const description = await getDescription();
  3585. builder.addSection(globalState.site === "cn" ? "题目描述" : "Description", description);
  3586. builder.addHorizontalRule();
  3587. builder.addSection(globalState.site === "cn" ? "解答" : "Solution");
  3588. const code = (_b = (_a2 = problemState.editor) == null ? void 0 : _a2.getModel()) == null ? void 0 : _b.getValue();
  3589. if (!code) {
  3590. toaster.error("Fail to retrieve current code in the editor");
  3591. } else {
  3592. builder.addCode(code);
  3593. }
  3594. const language = ((_d = (_c = problemState.editor) == null ? void 0 : _c.getModel()) == null ? void 0 : _d.getLanguageId()) ?? "python";
  3595. builder.setLanguage(language);
  3596. builder.download(title);
  3597. }
  3598. init();
  3599. Button($$anchor, {
  3600. variant: "orange",
  3601. onclick: () => {
  3602. toaster.promise(saveAsJupyter(), {
  3603. loading: "Scraping problem description and code...",
  3604. success: "Start downloading jupyter notebook...",
  3605. error: "Something went wrong while scraping. See browser console for more detail."
  3606. });
  3607. },
  3608. children: ($$anchor2, $$slotProps) => {
  3609. var text$1 = text();
  3610. template_effect(() => set_text(text$1, globalState.site === "cn" ? "保存为 Jupyter Notebook" : "Save as Jupyter Notebook"));
  3611. append($$anchor2, text$1);
  3612. },
  3613. $$slots: { default: true }
  3614. });
  3615. pop();
  3616. }
  3617. var root_1$2 = /* @__PURE__ */ from_html(`<!> <!> <!>`, 1);
  3618. function DescriptionButttons($$anchor) {
  3619. ButtonGroup($$anchor, {
  3620. children: ($$anchor2, $$slotProps) => {
  3621. var fragment_1 = root_1$2();
  3622. var node = first_child(fragment_1);
  3623. Copy_title(node, {});
  3624. var node_1 = sibling(node, 2);
  3625. Copy_description(node_1, {});
  3626. var node_2 = sibling(node_1, 2);
  3627. Download_as_jupyter(node_2, {});
  3628. append($$anchor2, fragment_1);
  3629. },
  3630. $$slots: { default: true }
  3631. });
  3632. }
  3633. const ratingsTxt = _GM_getResourceText("ratings");
  3634. function getSlug(url2) {
  3635. const pathParts = url2.pathname.split("/");
  3636. if (pathParts.length < 3) return null;
  3637. return pathParts[2];
  3638. }
  3639. function getRating(slugToSearch) {
  3640. const lines = ratingsTxt.split("\n");
  3641. for (const line of lines) {
  3642. const parts = line.split(" ");
  3643. if (parts.length < 2) continue;
  3644. const slug = parts[4];
  3645. if (slug === slugToSearch) {
  3646. return Math.round(parseFloat(parts[0]));
  3647. }
  3648. }
  3649. return null;
  3650. }
  3651. async function getOrCreateRatingElement() {
  3652. const difficultyEl = await findElement(
  3653. "div[class*='text-difficulty']",
  3654. { timeout: 5e3 }
  3655. );
  3656. const id = a(CONFIG.APP_NAME) + "-rating";
  3657. const el = difficultyEl.querySelector(`#${id}`);
  3658. if (el) {
  3659. return el;
  3660. } else {
  3661. const span = document.createElement("span");
  3662. span.id = id;
  3663. difficultyEl.append(span);
  3664. return span;
  3665. }
  3666. }
  3667. async function appendRating() {
  3668. const slug = getSlug(window.location);
  3669. if (!slug) return;
  3670. const rating = getRating(slug);
  3671. if (rating) {
  3672. console.log("got a rating for slug", slug, ":", rating);
  3673. }
  3674. const el = await getOrCreateRatingElement();
  3675. el.textContent = (rating == null ? void 0 : rating.toString()) ?? "";
  3676. }
  3677. function initRatings() {
  3678. appendRating();
  3679. if (_monkeyWindow.onurlchange === null) {
  3680. _monkeyWindow.addEventListener("urlchange", () => {
  3681. appendRating();
  3682. });
  3683. }
  3684. }
  3685. async function initDescriptionTab() {
  3686. var _a2;
  3687. const descriptionTab = await findElement(
  3688. ".flexlayout__tab:has([data-track-load='description_content'])",
  3689. {
  3690. timeout: 0,
  3691. additionalRule: (el) => el.style.display !== "none"
  3692. }
  3693. );
  3694. const titleContainer = await findElement("div:has(> .text-title-large)", {
  3695. parent: descriptionTab
  3696. });
  3697. const buttonsContainer = document.createElement("div");
  3698. buttonsContainer.setAttribute(
  3699. "id",
  3700. a(CONFIG.APP_NAME) + "-description"
  3701. );
  3702. buttonsContainer.style.cssText = "display: contents;";
  3703. (_a2 = titleContainer.parentElement) == null ? void 0 : _a2.before(buttonsContainer);
  3704. mount(DescriptionButttons, {
  3705. target: buttonsContainer
  3706. });
  3707. initRatings();
  3708. }
  3709. function Find_editorial_screenshot($$anchor, $$props) {
  3710. push($$props, false);
  3711. const editorialsMarkdown = _GM_getResourceText("editorials");
  3712. function extractScreenshotLink(problemTitle) {
  3713. const cleanTitle = problemTitle.trim();
  3714. const headingPattern = new RegExp(`####\\s+\\[${cleanTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\]\\((.*?)\\)`, "i");
  3715. const match = editorialsMarkdown.match(headingPattern);
  3716. return match ? match[1] : null;
  3717. }
  3718. async function goToEditorialScreenshot() {
  3719. const title = await getTitle();
  3720. const link = extractScreenshotLink(title);
  3721. if (link) {
  3722. window.open(link, "_blank");
  3723. } else {
  3724. toaster.error(`Editorial screenshot not found for problem: ${title}`);
  3725. }
  3726. }
  3727. init();
  3728. Button($$anchor, {
  3729. onclick: goToEditorialScreenshot,
  3730. children: ($$anchor2, $$slotProps) => {
  3731. var text$1 = text("Find Screenshot");
  3732. append($$anchor2, text$1);
  3733. },
  3734. $$slots: { default: true }
  3735. });
  3736. pop();
  3737. }
  3738. const turndown = createTurndownService();
  3739. turndown.addRule("remove-heading-link", {
  3740. filter: (node) => node.nodeName === "A" && node.getAttribute("aria-hidden") === "true",
  3741. replacement: () => ""
  3742. });
  3743. turndown.addRule("save-math-as-is", {
  3744. filter: (node) => ["SPAN", "DIV"].includes(node.nodeName) && node.matches(".math, .maths, .math-tex"),
  3745. replacement: (_content, node) => node.outerHTML
  3746. });
  3747. function waitForIframeToLoad(iframe) {
  3748. return new Promise((resolve) => {
  3749. var _a2, _b, _c, _d;
  3750. if (iframe.src !== "about:blank") {
  3751. const isSameOrigin = new URL(iframe.src).hostname === window.location.hostname;
  3752. 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") {
  3753. resolve(void 0);
  3754. return;
  3755. }
  3756. }
  3757. console.log("wait for iframe to load...");
  3758. (_d = iframe.contentWindow) == null ? void 0 : _d.addEventListener("load", resolve, {
  3759. once: true
  3760. });
  3761. });
  3762. }
  3763. const playgroundCache = /* @__PURE__ */ new Map();
  3764. async function prefetchPlayground(editorialEl) {
  3765. const iframes = Array.from(editorialEl.querySelectorAll("iframe"));
  3766. const promises = iframes.map(async (iframe) => {
  3767. var _a2, _b;
  3768. await waitForIframeToLoad(iframe);
  3769. const { src, contentDocument } = iframe;
  3770. if (!src.includes("playground")) return;
  3771. console.log((_b = (_a2 = iframe.contentWindow) == null ? void 0 : _a2.location) == null ? void 0 : _b.href);
  3772. const langTab = await findElement("div.lang-btn-set", {
  3773. parent: contentDocument,
  3774. timeout: 1e3
  3775. });
  3776. const textarea = contentDocument == null ? void 0 : contentDocument.querySelector(
  3777. "textarea[name='lc-codemirror']"
  3778. );
  3779. let result = `<MixedCodeBlock>
  3780.  
  3781. `;
  3782. Array.from(
  3783. langTab.children
  3784. ).forEach((button) => {
  3785. var _a3;
  3786. let lang = (_a3 = button.textContent) == null ? void 0 : _a3.toLowerCase();
  3787. if (lang === "python3") lang = "python";
  3788. button.click();
  3789. const code = textarea == null ? void 0 : textarea.textContent;
  3790. result += `\`\`\`${lang}
  3791. ${code}
  3792. \`\`\`
  3793.  
  3794. `;
  3795. });
  3796. result += `</MixedCodeBlock>`;
  3797. playgroundCache.set(src, result);
  3798. });
  3799. await Promise.all(promises);
  3800. }
  3801. turndown.addRule("save-code-playground", {
  3802. filter: ["iframe"],
  3803. replacement: (_content, node) => {
  3804. const { src } = node;
  3805. if (!src.includes("playground")) return "";
  3806. return `[LeetCode Playground](${src})
  3807.  
  3808. ` + (playgroundCache.get(src) ?? "");
  3809. }
  3810. });
  3811. const slideCache = /* @__PURE__ */ new Map();
  3812. async function preFetchSlides(editorialEl) {
  3813. const slideImages = editorialEl.querySelectorAll("img[alt='Current']");
  3814. const promises = Array.from(slideImages).map(async (image) => {
  3815. var _a2, _b, _c;
  3816. const slideContainer = (_a2 = image.parentElement) == null ? void 0 : _a2.parentElement;
  3817. if (!slideContainer) {
  3818. throw new Error("Slide container not found");
  3819. }
  3820. const slideNumIndicator = slideContainer.children[2].children[1];
  3821. slideNumIndicator.setAttribute("data-skip-me-turndown", "true");
  3822. const slidesCountStr = (_c = (_b = slideNumIndicator.textContent) == null ? void 0 : _b.match(/\d+$/)) == null ? void 0 : _c[0];
  3823. if (!slidesCountStr) {
  3824. throw new Error("Slide count not found");
  3825. }
  3826. const nextSlideButton = slideContainer.querySelector("svg:nth-child(3)");
  3827. if (!nextSlideButton) {
  3828. throw new Error("Next slide button not found");
  3829. }
  3830. const firstSlideSrc = image.src;
  3831. slideCache.set(firstSlideSrc, []);
  3832. for (let i2 = 0; i2 < Number(slidesCountStr); i2++) {
  3833. simulateMouseClickReact(nextSlideButton);
  3834. const dataURL = await convertSrcToDataURL(image.src);
  3835. slideCache.get(firstSlideSrc).push(dataURL);
  3836. }
  3837. });
  3838. await Promise.all(promises);
  3839. }
  3840. turndown.addRule("save-slides", {
  3841. filter: (node) => node.tagName === "IMG" && node.alt === "Current",
  3842. replacement: (_content, node) => {
  3843. const { src } = node;
  3844. const dataURLs = slideCache.get(src);
  3845. if (!dataURLs) return "";
  3846. let res = `<Slides>
  3847.  
  3848. `;
  3849. dataURLs.forEach((dataURL, index) => {
  3850. res += `![Slide ${index + 1}](${dataURL})
  3851. `;
  3852. });
  3853. res += `
  3854. </Slides>`;
  3855. return res;
  3856. }
  3857. });
  3858. turndown.addRule("save-details-as-is", {
  3859. filter: ["details"],
  3860. replacement: (_content, node) => {
  3861. const { children } = node;
  3862. [...children].forEach((child2) => {
  3863. if (!child2.textContent) node.removeChild(child2);
  3864. });
  3865. return node.outerHTML;
  3866. }
  3867. });
  3868. turndown.remove(
  3869. (node) => node.getAttribute("data-skip-me-turndown") === "true"
  3870. );
  3871. async function scrapeEditorial(editorialEl) {
  3872. await prefetchPlayground(editorialEl);
  3873. await preFetchSlides(editorialEl);
  3874. const editorial = await htmlToMd(editorialEl, {
  3875. turndownService: turndown
  3876. });
  3877. playgroundCache.clear();
  3878. slideCache.clear();
  3879. return editorial;
  3880. }
  3881. async function downloadEditorial(editorialFinder, titleFinder) {
  3882. toaster.promise(
  3883. async () => {
  3884. const editorialEl = await editorialFinder();
  3885. const editorial = await scrapeEditorial(editorialEl);
  3886. const title = await titleFinder();
  3887. const blob = new Blob([`# ${title}
  3888.  
  3889. `, editorial], {
  3890. type: "text/markdown; charset=UTF-8"
  3891. });
  3892. downloadFile(blob, title, "md");
  3893. },
  3894. {
  3895. loading: "Scraping editorial...",
  3896. success: "Editorial scraped. Downloading...",
  3897. error: "Something went wrong while scraping. See browser console for more detail."
  3898. }
  3899. );
  3900. }
  3901. function Save_editorial($$anchor, $$props) {
  3902. push($$props, false);
  3903. async function findEditorial() {
  3904. const editorialEl = await findElement(".flexlayout__tab:has(#editorial-quick-navigation) div.WRmCx", { timeout: 2e3 });
  3905. return editorialEl;
  3906. }
  3907. init();
  3908. Button($$anchor, {
  3909. onclick: () => downloadEditorial(findEditorial, getTitle),
  3910. variant: "orange",
  3911. children: ($$anchor2, $$slotProps) => {
  3912. var text$1 = text("Save Editorial as Markdown");
  3913. append($$anchor2, text$1);
  3914. },
  3915. $$slots: { default: true }
  3916. });
  3917. pop();
  3918. }
  3919. function Read_saved_editorial($$anchor, $$props) {
  3920. push($$props, false);
  3921. init();
  3922. Button($$anchor, {
  3923. get href() {
  3924. return CONFIG.EDITORIAL_READER_URL;
  3925. },
  3926. variant: "green",
  3927. children: ($$anchor2, $$slotProps) => {
  3928. var text$1 = text("Read Saved Editorial");
  3929. append($$anchor2, text$1);
  3930. },
  3931. $$slots: { default: true }
  3932. });
  3933. pop();
  3934. }
  3935. var root_1$1 = /* @__PURE__ */ from_html(`<!> <!> <!>`, 1);
  3936. function EditorialButtons($$anchor) {
  3937. ButtonGroup($$anchor, {
  3938. style: "z-index: 10; position:relative; padding: 0.5rem",
  3939. children: ($$anchor2, $$slotProps) => {
  3940. var fragment_1 = root_1$1();
  3941. var node = first_child(fragment_1);
  3942. Find_editorial_screenshot(node, {});
  3943. var node_1 = sibling(node, 2);
  3944. Save_editorial(node_1, {});
  3945. var node_2 = sibling(node_1, 2);
  3946. Read_saved_editorial(node_2, {});
  3947. append($$anchor2, fragment_1);
  3948. },
  3949. $$slots: { default: true }
  3950. });
  3951. }
  3952. async function initEditorialTab() {
  3953. const editorialTab = await findElement(
  3954. ".flexlayout__tab:has(div.bg-blocker, #editorial-quick-navigation)",
  3955. {
  3956. timeout: 0,
  3957. additionalRule: (el) => el.style.display !== "none"
  3958. }
  3959. );
  3960. const buttonsContainer = document.createElement("div");
  3961. buttonsContainer.style.cssText = "display: contents;";
  3962. buttonsContainer.setAttribute(
  3963. "id",
  3964. a(CONFIG.APP_NAME) + "-editorial"
  3965. );
  3966. editorialTab.prepend(buttonsContainer);
  3967. mount(EditorialButtons, {
  3968. target: buttonsContainer
  3969. });
  3970. }
  3971. async function main$1() {
  3972. const initPromises = [];
  3973. initPromises.push(problemState.patchMonacoEditor());
  3974. initPromises.push(initDescriptionTab());
  3975. if (globalState.site === "global") {
  3976. initPromises.push(initEditorialTab());
  3977. }
  3978. await Promise.all(initPromises);
  3979. }
  3980. function getElementIndex(element) {
  3981. if (!element.parentNode) throw new Error("Element has no parent node");
  3982. return Array.from(element.parentNode.children).indexOf(element);
  3983. }
  3984. function Save_explore_article($$anchor, $$props) {
  3985. push($$props, false);
  3986. async function findExploreEditorial() {
  3987. return await findElement("div.block-markdown");
  3988. }
  3989. async function getExploreTitle() {
  3990. var _a2, _b;
  3991. const tocContainer = await findElement("div.list-group:not(.item-list-group)");
  3992. const titleContainer = tocContainer.querySelector(".list-group-item .selected");
  3993. if (!titleContainer) {
  3994. throw new Error("Title container not found");
  3995. }
  3996. const title = ((_b = (_a2 = titleContainer.querySelector(".title")) == null ? void 0 : _a2.textContent) == null ? void 0 : _b.trim()) ?? "";
  3997. const articleNumber = getElementIndex(titleContainer) + 1;
  3998. const chapterEl = titleContainer.closest("div.chapter-item");
  3999. if (!chapterEl) {
  4000. throw new Error("Chapter not found");
  4001. }
  4002. const chapterNumber = getElementIndex(chapterEl);
  4003. return `${chapterNumber}.${articleNumber} ${title}`;
  4004. }
  4005. init();
  4006. Button($$anchor, {
  4007. onclick: () => downloadEditorial(findExploreEditorial, getExploreTitle),
  4008. children: ($$anchor2, $$slotProps) => {
  4009. var text$1 = text("Save Article as Markdown");
  4010. append($$anchor2, text$1);
  4011. },
  4012. $$slots: { default: true }
  4013. });
  4014. pop();
  4015. }
  4016. var root_1 = /* @__PURE__ */ from_html(`<!> <!>`, 1);
  4017. function ExploreButtons($$anchor) {
  4018. ButtonGroup($$anchor, {
  4019. children: ($$anchor2, $$slotProps) => {
  4020. var fragment_1 = root_1();
  4021. var node = first_child(fragment_1);
  4022. Save_explore_article(node, {});
  4023. var node_1 = sibling(node, 2);
  4024. Read_saved_editorial(node_1, {});
  4025. append($$anchor2, fragment_1);
  4026. },
  4027. $$slots: { default: true }
  4028. });
  4029. }
  4030. async function main() {
  4031. const toolbar = await findElement("div.left-side", { timeout: 0 });
  4032. const container = document.createElement("div");
  4033. container.style.cssText = "display: contents;";
  4034. toolbar.append(container);
  4035. mount(ExploreButtons, {
  4036. target: container
  4037. });
  4038. }
  4039. const url = window.location.href;
  4040. const problemPageRegex = /https?:\/\/leetcode\.com\/problems\/.*|https?:\/\/leetcode\.cn\/problems\/.*/;
  4041. const explorePageRegex = /https?:\/\/leetcode\.com\/explore\/.*\/card\/.*/;
  4042. if (problemPageRegex.test(url)) {
  4043. main$1();
  4044. } else if (explorePageRegex.test(url)) {
  4045. main();
  4046. }
  4047.  
  4048. })(TurndownService, Compressor);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址