UNPKG

mongoku

Version:

[![CI](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml/badge.svg)](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)

1,664 lines (1,648 loc) 157 kB
import { a as async_mode_flag, t as tracing_mode_flag } from './async-DUoD1OpG.js'; // eslint-disable-next-line n/prefer-global/process const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer; /** @import { RequestEvent } from '@sveltejs/kit' */ /** @import { RequestStore } from 'types' */ /** @import { AsyncLocalStorage } from 'node:async_hooks' */ /** @type {RequestStore | null} */ let sync_store = null; /** @type {AsyncLocalStorage<RequestStore | null> | null} */ let als$1; import('node:async_hooks') .then((hooks) => (als$1 = new hooks.AsyncLocalStorage())) .catch(() => { // can't use AsyncLocalStorage, but can still call getRequestEvent synchronously. // this isn't behind `supports` because it's basically just StackBlitz (i.e. // in-browser usage) that doesn't support it AFAICT }); function get_request_store() { const result = try_get_request_store(); if (!result) { let message = 'Could not get the request store.'; if (als$1) { message += ' This is an internal error.'; } else { message += ' In environments without `AsyncLocalStorage`, the request store (used by e.g. remote functions) must be accessed synchronously, not after an `await`.' + ' If it was accessed synchronously then this is an internal error.'; } throw new Error(message); } return result; } function try_get_request_store() { return sync_store ?? als$1?.getStore() ?? null; } /** * @template T * @param {RequestStore | null} store * @param {() => T} fn */ function with_request_store(store, fn) { try { sync_store = store; return als$1 ? als$1.run(store, fn) : fn(); } finally { // Since AsyncLocalStorage is not working in webcontainers, we don't reset `sync_store` // and handle only one request at a time in `src/runtime/server/index.js`. if (!IN_WEBCONTAINER) { sync_store = null; } } } const DEV = false; const UNDEFINED = -1; const HOLE = -2; const NAN = -3; const POSITIVE_INFINITY = -4; const NEGATIVE_INFINITY = -5; const NEGATIVE_ZERO = -6; const SPARSE = -7; const MAX_ARRAY_LEN = 2 ** 32 - 1; const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1; const escaped = { "<": "\\u003C", "\\": "\\\\", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\u2028": "\\u2028", "\u2029": "\\u2029" }; class DevalueError extends Error { /** * @param {string} message * @param {string[]} keys * @param {any} [value] - The value that failed to be serialized * @param {any} [root] - The root value being serialized */ constructor(message, keys, value, root) { super(message); this.name = "DevalueError"; this.path = keys.join(""); this.value = value; this.root = root; } } function is_primitive(thing) { return thing === null || typeof thing !== "object" && typeof thing !== "function"; } const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0"); function is_plain_object(thing) { const proto = Object.getPrototypeOf(thing); return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names; } function get_type(thing) { return Object.prototype.toString.call(thing).slice(8, -1); } function get_escaped_char(char) { switch (char) { case '"': return '\\"'; case "<": return "\\u003C"; case "\\": return "\\\\"; case "\n": return "\\n"; case "\r": return "\\r"; case " ": return "\\t"; case "\b": return "\\b"; case "\f": return "\\f"; case "\u2028": return "\\u2028"; case "\u2029": return "\\u2029"; default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : ""; } } function stringify_string(str) { let result = ""; let last_pos = 0; const len = str.length; for (let i = 0; i < len; i += 1) { const char = str[i]; const replacement = get_escaped_char(char); if (replacement) { result += str.slice(last_pos, i) + replacement; last_pos = i + 1; } } return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`; } function enumerable_symbols(object) { return Object.getOwnPropertySymbols(object).filter( (symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable ); } const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; function stringify_key(key) { return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]"; } function is_valid_array_index(n) { if (!Number.isInteger(n)) return false; if (n < 0) return false; if (n > MAX_ARRAY_INDEX) return false; return true; } function is_valid_array_len(n) { if (!Number.isInteger(n)) return false; if (n < 0) return false; if (n > MAX_ARRAY_LEN) return false; return true; } function is_valid_array_index_string(s) { if (s.length === 0) return false; if (s.length > 1 && s.charCodeAt(0) === 48) return false; for (let i = 0; i < s.length; i++) { const c = s.charCodeAt(i); if (c < 48 || c > 57) return false; } return is_valid_array_index(+s); } function valid_array_indices(array) { const keys = Object.keys(array); for (var i = keys.length - 1; i >= 0; i--) { if (is_valid_array_index_string(keys[i])) { break; } } keys.length = i + 1; return keys; } const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"; const unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g; const reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/; function uneval(value, replacer) { const counts = /* @__PURE__ */ new Map(); const keys = []; const custom = /* @__PURE__ */ new Map(); function walk(thing) { if (!is_primitive(thing)) { if (counts.has(thing)) { counts.set(thing, counts.get(thing) + 1); return; } counts.set(thing, 1); if (replacer) { const str2 = replacer(thing, (value2) => uneval(value2, replacer)); if (typeof str2 === "string") { custom.set(thing, str2); return; } } if (typeof thing === "function") { throw new DevalueError(`Cannot stringify a function`, keys, thing, value); } const type = get_type(thing); switch (type) { case "Number": case "BigInt": case "String": case "Boolean": case "Date": case "RegExp": case "URL": case "URLSearchParams": return; case "Array": thing.forEach((value2, i) => { keys.push(`[${i}]`); walk(value2); keys.pop(); }); break; case "Set": Array.from(thing).forEach(walk); break; case "Map": for (const [key, value2] of thing) { keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`); walk(value2); keys.pop(); } break; case "Int8Array": case "Uint8Array": case "Uint8ClampedArray": case "Int16Array": case "Uint16Array": case "Float16Array": case "Int32Array": case "Uint32Array": case "Float32Array": case "Float64Array": case "BigInt64Array": case "BigUint64Array": case "DataView": walk(thing.buffer); return; case "ArrayBuffer": return; case "Temporal.Duration": case "Temporal.Instant": case "Temporal.PlainDate": case "Temporal.PlainTime": case "Temporal.PlainDateTime": case "Temporal.PlainMonthDay": case "Temporal.PlainYearMonth": case "Temporal.ZonedDateTime": return; default: if (!is_plain_object(thing)) { throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value); } if (enumerable_symbols(thing).length > 0) { throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value); } for (const key of Object.keys(thing)) { if (key === "__proto__") { throw new DevalueError( `Cannot stringify objects with __proto__ keys`, keys, thing, value ); } keys.push(stringify_key(key)); walk(thing[key]); keys.pop(); } } } else if (typeof thing === "symbol") { throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value); } } walk(value); const names = /* @__PURE__ */ new Map(); Array.from(counts).filter((entry) => entry[1] > 1).sort((a, b) => b[1] - a[1]).forEach((entry, i) => { names.set(entry[0], get_name(i)); }); function stringify(thing) { if (names.has(thing)) { return names.get(thing); } if (is_primitive(thing)) { return stringify_primitive(thing); } if (custom.has(thing)) { return custom.get(thing); } const type = get_type(thing); switch (type) { case "Number": case "String": case "Boolean": case "BigInt": return `Object(${stringify(thing.valueOf())})`; case "RegExp": const { source, flags } = thing; return flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`; case "Date": return `new Date(${thing.getTime()})`; case "URL": return `new URL(${stringify_string(thing.toString())})`; case "URLSearchParams": return `new URLSearchParams(${stringify_string(thing.toString())})`; case "Array": { let has_holes = false; let result = "["; for (let i = 0; i < thing.length; i += 1) { if (i > 0) result += ","; if (Object.hasOwn(thing, i)) { result += stringify(thing[i]); } else if (!has_holes) { const populated_keys = valid_array_indices( /** @type {any[]} */ thing ); const population = populated_keys.length; const d = String(thing.length).length; const hole_cost = thing.length + 2; const sparse_cost = 25 + d + population * (d + 2); if (hole_cost > sparse_cost) { const entries = populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(","); return `Object.assign(Array(${thing.length}),{${entries}})`; } has_holes = true; i -= 1; } } const tail = thing.length === 0 || thing.length - 1 in thing ? "" : ","; return result + tail + "]"; } case "Set": case "Map": return `new ${type}([${Array.from(thing).map(stringify).join(",")}])`; case "Int8Array": case "Uint8Array": case "Uint8ClampedArray": case "Int16Array": case "Uint16Array": case "Float16Array": case "Int32Array": case "Uint32Array": case "Float32Array": case "Float64Array": case "BigInt64Array": case "BigUint64Array": { let str2 = `new ${type}`; if (!names.has(thing.buffer)) { const array = new thing.constructor(thing.buffer); str2 += `([${array}])`; } else { str2 += `(${stringify(thing.buffer)})`; } if (thing.byteLength !== thing.buffer.byteLength) { const start = thing.byteOffset / thing.BYTES_PER_ELEMENT; const end = start + thing.length; str2 += `.subarray(${start},${end})`; } return str2; } case "DataView": { let str2 = `new DataView`; if (!names.has(thing.buffer)) { str2 += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`; } else { str2 += `(${stringify(thing.buffer)}`; } if (thing.byteLength !== thing.buffer.byteLength) { str2 += `,${thing.startOffset},${thing.byteLength}`; } return str2 + ")"; } case "ArrayBuffer": { const ui8 = new Uint8Array(thing); return `new Uint8Array([${ui8.toString()}]).buffer`; } case "Temporal.Duration": case "Temporal.Instant": case "Temporal.PlainDate": case "Temporal.PlainTime": case "Temporal.PlainDateTime": case "Temporal.PlainMonthDay": case "Temporal.PlainYearMonth": case "Temporal.ZonedDateTime": return `${type}.from(${stringify_string(thing.toString())})`; default: const keys2 = Object.keys(thing); const obj = keys2.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(","); const proto = Object.getPrototypeOf(thing); if (proto === null) { return keys2.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`; } return `{${obj}}`; } } const str = stringify(value); if (names.size) { const params = []; const statements = []; const values = []; names.forEach((name, thing) => { params.push(name); if (custom.has(thing)) { values.push( /** @type {string} */ custom.get(thing) ); return; } if (is_primitive(thing)) { values.push(stringify_primitive(thing)); return; } const type = get_type(thing); switch (type) { case "Number": case "String": case "Boolean": case "BigInt": values.push(`Object(${stringify(thing.valueOf())})`); break; case "RegExp": const { source, flags } = thing; const regexp = flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`; values.push(regexp); break; case "Date": values.push(`new Date(${thing.getTime()})`); break; case "URL": values.push(`new URL(${stringify_string(thing.toString())})`); break; case "URLSearchParams": values.push(`new URLSearchParams(${stringify_string(thing.toString())})`); break; case "Array": values.push(`Array(${thing.length})`); thing.forEach((v, i) => { statements.push(`${name}[${i}]=${stringify(v)}`); }); break; case "Set": values.push(`new Set`); statements.push( `${name}.${Array.from(thing).map((v) => `add(${stringify(v)})`).join(".")}` ); break; case "Map": values.push(`new Map`); statements.push( `${name}.${Array.from(thing).map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`).join(".")}` ); break; case "Int8Array": case "Uint8Array": case "Uint8ClampedArray": case "Int16Array": case "Uint16Array": case "Float16Array": case "Int32Array": case "Uint32Array": case "Float32Array": case "Float64Array": case "BigInt64Array": case "BigUint64Array": { let str2 = `new ${type}`; if (!names.has(thing.buffer)) { const array = new thing.constructor(thing.buffer); str2 += `([${array}])`; } else { str2 += `(${stringify(thing.buffer)})`; } if (thing.byteLength !== thing.buffer.byteLength) { const start = thing.byteOffset / thing.BYTES_PER_ELEMENT; const end = start + thing.length; str2 += `.subarray(${start},${end})`; } values.push(`{}`); statements.push(`${name}=${str2}`); break; } case "DataView": { let str2 = `new DataView`; if (!names.has(thing.buffer)) { str2 += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`; } else { str2 += `(${stringify(thing.buffer)}`; } if (thing.byteLength !== thing.buffer.byteLength) { str2 += `,${thing.byteOffset},${thing.byteLength}`; } str2 += ")"; values.push(`{}`); statements.push(`${name}=${str2}`); break; } case "ArrayBuffer": values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`); break; default: values.push(Object.getPrototypeOf(thing) === null ? "Object.create(null)" : "{}"); Object.keys(thing).forEach((key) => { statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`); }); } }); statements.push(`return ${str}`); return `(function(${params.join(",")}){${statements.join(";")}}(${values.join(",")}))`; } else { return str; } } function get_name(num) { let name = ""; do { name = chars[num % chars.length] + name; num = ~~(num / chars.length) - 1; } while (num >= 0); return reserved.test(name) ? `${name}0` : name; } function escape_unsafe_char(c) { return escaped[c] || c; } function escape_unsafe_chars(str) { return str.replace(unsafe_chars, escape_unsafe_char); } function safe_key(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key)); } function safe_prop(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? `.${key}` : `[${escape_unsafe_chars(JSON.stringify(key))}]`; } function stringify_primitive(thing) { const type = typeof thing; if (type === "string") return stringify_string(thing); if (thing === void 0) return "void 0"; if (thing === 0 && 1 / thing < 0) return "-0"; const str = String(thing); if (type === "number") return str.replace(/^(-)?0\./, "$1."); if (type === "bigint") return thing + "n"; return str; } function experimental_async_required(name) { { throw new Error(`https://svelte.dev/e/experimental_async_required`); } } function lifecycle_outside_component(name) { { throw new Error(`https://svelte.dev/e/lifecycle_outside_component`); } } function async_local_storage_unavailable() { const error = new Error(`async_local_storage_unavailable The node API \`AsyncLocalStorage\` is not available, but is required to use async server rendering. https://svelte.dev/e/async_local_storage_unavailable`); error.name = "Svelte error"; throw error; } function await_invalid() { const error = new Error(`await_invalid Encountered asynchronous work while rendering synchronously. https://svelte.dev/e/await_invalid`); error.name = "Svelte error"; throw error; } function html_deprecated() { const error = new Error(`html_deprecated The \`html\` property of server render results has been deprecated. Use \`body\` instead. https://svelte.dev/e/html_deprecated`); error.name = "Svelte error"; throw error; } function hydratable_serialization_failed(key, stack) { const error = new Error(`hydratable_serialization_failed Failed to serialize \`hydratable\` data for key \`${key}\`. \`hydratable\` can serialize anything [\`uneval\` from \`devalue\`](https://npmjs.com/package/uneval) can, plus Promises. Cause: ${stack} https://svelte.dev/e/hydratable_serialization_failed`); error.name = "Svelte error"; throw error; } function invalid_csp() { const error = new Error(`invalid_csp \`csp.nonce\` was set while \`csp.hash\` was \`true\`. These options cannot be used simultaneously. https://svelte.dev/e/invalid_csp`); error.name = "Svelte error"; throw error; } function invalid_id_prefix() { const error = new Error(`invalid_id_prefix The \`idPrefix\` option cannot include \`--\`. https://svelte.dev/e/invalid_id_prefix`); error.name = "Svelte error"; throw error; } function server_context_required() { const error = new Error(`server_context_required Could not resolve \`render\` context. https://svelte.dev/e/server_context_required`); error.name = "Svelte error"; throw error; } var is_array = Array.isArray; var index_of = Array.prototype.indexOf; var includes = Array.prototype.includes; var array_from = Array.from; var define_property = Object.defineProperty; var get_descriptor = Object.getOwnPropertyDescriptor; var object_prototype = Object.prototype; var array_prototype = Array.prototype; var get_prototype_of = Object.getPrototypeOf; var is_extensible = Object.isExtensible; var has_own_property = Object.prototype.hasOwnProperty; const noop = () => { }; function is_promise(value) { return typeof value?.then === "function"; } function run_all(arr) { for (var i = 0; i < arr.length; i++) { arr[i](); } } function deferred() { var resolve; var reject; var promise = new Promise((res, rej) => { resolve = res; reject = rej; }); return { promise, resolve, reject }; } let current_render = null; let context = null; function get_render_context() { const store = context ?? als?.getStore(); if (!store) { server_context_required(); } return store; } async function with_render_context(fn) { context = { hydratable: { lookup: /* @__PURE__ */ new Map(), comparisons: [], unresolved_promises: /* @__PURE__ */ new Map() } }; if (in_webcontainer()) { const { promise, resolve } = deferred(); const previous_render = current_render; current_render = promise; await previous_render; return fn().finally(resolve); } try { if (als === null) { async_local_storage_unavailable(); } return als.run(context, fn); } finally { context = null; } } let als = null; let als_import = null; function init_render_context() { als_import ??= import('node:async_hooks').then((hooks) => { als = new hooks.AsyncLocalStorage(); }).then(noop, noop); return als_import; } function in_webcontainer() { return !!globalThis.process?.versions?.webcontainer; } const internal = new URL("sveltekit-internal://"); function resolve(base, path) { if (path[0] === "/" && path[1] === "/") return path; let url = new URL(base, internal); url = new URL(path, url); return url.protocol === internal.protocol ? url.pathname + url.search + url.hash : url.href; } function normalize_path(path, trailing_slash) { if (path === "/" || trailing_slash === "ignore") return path; if (trailing_slash === "never") { return path.endsWith("/") ? path.slice(0, -1) : path; } else if (trailing_slash === "always" && !path.endsWith("/")) { return path + "/"; } return path; } function decode_pathname(pathname) { return pathname.split("%25").map(decodeURI).join("%25"); } function decode_params(params) { for (const key in params) { params[key] = decodeURIComponent(params[key]); } return params; } function make_trackable(url, callback, search_params_callback, allow_hash = false) { const tracked = new URL(url); Object.defineProperty(tracked, "searchParams", { value: new Proxy(tracked.searchParams, { get(obj, key) { if (key === "get" || key === "getAll" || key === "has") { return (param, ...rest) => { search_params_callback(param); return obj[key](param, ...rest); }; } callback(); const value = Reflect.get(obj, key); return typeof value === "function" ? value.bind(obj) : value; } }), enumerable: true, configurable: true }); const tracked_url_properties = ["href", "pathname", "search", "toString", "toJSON"]; if (allow_hash) tracked_url_properties.push("hash"); for (const property of tracked_url_properties) { Object.defineProperty(tracked, property, { get() { callback(); return url[property]; }, enumerable: true, configurable: true }); } { tracked[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = (_depth, opts, inspect) => { return inspect(url, opts); }; tracked.searchParams[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = (_depth, opts, inspect) => { return inspect(url.searchParams, opts); }; } if (!allow_hash) { disable_hash(tracked); } return tracked; } function disable_hash(url) { allow_nodejs_console_log(url); Object.defineProperty(url, "hash", { get() { throw new Error( "Cannot access event.url.hash. Consider using `page.url.hash` inside a component instead" ); } }); } function disable_search(url) { allow_nodejs_console_log(url); for (const property of ["search", "searchParams"]) { Object.defineProperty(url, property, { get() { throw new Error(`Cannot access url.${property} on a page with prerendering enabled`); } }); } } function allow_nodejs_console_log(url) { { url[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = (_depth, opts, inspect) => { return inspect(new URL(url), opts); }; } } var ssr_context = null; function set_ssr_context(v) { ssr_context = v; } function getContext(key) { const context_map = get_or_init_context_map(); const result = ( /** @type {T} */ context_map.get(key) ); return result; } function setContext(key, context) { get_or_init_context_map().set(key, context); return context; } function get_or_init_context_map(name) { if (ssr_context === null) { lifecycle_outside_component(); } return ssr_context.c ??= new Map(get_parent_context(ssr_context) || void 0); } function push$1(fn) { ssr_context = { p: ssr_context, c: null, r: null }; } function pop$1() { ssr_context = /** @type {SSRContext} */ ssr_context.p; } function get_parent_context(ssr_context2) { let parent = ssr_context2.p; while (parent !== null) { const context_map = parent.c; if (context_map !== null) { return context_map; } parent = parent.p; } return null; } const DERIVED = 1 << 1; const EFFECT = 1 << 2; const RENDER_EFFECT = 1 << 3; const MANAGED_EFFECT = 1 << 24; const BLOCK_EFFECT = 1 << 4; const BRANCH_EFFECT = 1 << 5; const ROOT_EFFECT = 1 << 6; const BOUNDARY_EFFECT = 1 << 7; const CONNECTED = 1 << 9; const CLEAN = 1 << 10; const DIRTY = 1 << 11; const MAYBE_DIRTY = 1 << 12; const INERT = 1 << 13; const DESTROYED = 1 << 14; const REACTION_RAN = 1 << 15; const DESTROYING = 1 << 25; const EFFECT_TRANSPARENT = 1 << 16; const EAGER_EFFECT = 1 << 17; const HEAD_EFFECT = 1 << 18; const EFFECT_PRESERVED = 1 << 19; const USER_EFFECT = 1 << 20; const WAS_MARKED = 1 << 16; const REACTION_IS_UPDATING = 1 << 21; const ASYNC = 1 << 22; const ERROR_VALUE = 1 << 23; const STATE_SYMBOL = /* @__PURE__ */ Symbol("$state"); const LEGACY_PROPS = /* @__PURE__ */ Symbol("legacy props"); const ATTRIBUTES_CACHE = /* @__PURE__ */ Symbol("attributes"); const CLASS_CACHE = /* @__PURE__ */ Symbol("class"); const STYLE_CACHE = /* @__PURE__ */ Symbol("style"); const TEXT_CACHE = /* @__PURE__ */ Symbol("text"); const STALE_REACTION = new class StaleReactionError extends Error { name = "StaleReactionError"; message = "The reaction that called `getAbortSignal()` was re-run or destroyed"; }(); const COMMENT_NODE = 8; let controller = null; function abort() { controller?.abort(STALE_REACTION); controller = null; } const HYDRATION_START = "["; const HYDRATION_START_ELSE = "[!"; const HYDRATION_START_FAILED = "[?"; const HYDRATION_END = "]"; const HYDRATION_ERROR = {}; const ELEMENT_IS_NAMESPACED = 1; const ELEMENT_PRESERVE_ATTRIBUTE_CASE = 1 << 1; const ELEMENT_IS_INPUT = 1 << 2; const UNINITIALIZED = /* @__PURE__ */ Symbol(); function unresolved_hydratable(key, stack) { { console.warn(`https://svelte.dev/e/unresolved_hydratable`); } } const BLOCK_OPEN = `<!--${HYDRATION_START}-->`; const BLOCK_OPEN_ELSE = `<!--${HYDRATION_START_ELSE}-->`; const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`; const EMPTY_COMMENT = `<!---->`; const ATTR_REGEX = /[&"<]/g; const CONTENT_REGEX = /[&<]/g; function escape_html(value, is_attr) { const str = String(value ?? ""); const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX; pattern.lastIndex = 0; let escaped = ""; let last = 0; while (pattern.test(str)) { const i = pattern.lastIndex - 1; const ch = str[i]; escaped += str.substring(last, i) + (ch === "&" ? "&amp;" : ch === '"' ? "&quot;" : "&lt;"); last = i + 1; } return escaped + str.substring(last); } function r(e) { var t, f, n = ""; if ("string" == typeof e || "number" == typeof e) n += e; else if ("object" == typeof e) if (Array.isArray(e)) { var o = e.length; for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f); } else for (f in e) e[f] && (n && (n += " "), n += f); return n; } function clsx$1() { for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t); return n; } const replacements = { translate: /* @__PURE__ */ new Map([ [true, "yes"], [false, "no"] ]) }; function attr(name, value, is_boolean = false) { if (name === "hidden" && value !== "until-found") { is_boolean = true; } if (value == null || !value && is_boolean) return ""; const normalized = has_own_property.call(replacements, name) && replacements[name].get(value) || value; const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`; return ` ${name}${assignment}`; } function clsx(value) { if (typeof value === "object") { return clsx$1(value); } else { return value ?? ""; } } const whitespace = [..." \n\r\f \v\uFEFF"]; function to_class(value, hash, directives) { var classname = value == null ? "" : "" + value; if (hash) { classname = classname ? classname + " " + hash : hash; } if (directives) { for (var key of Object.keys(directives)) { if (directives[key]) { classname = classname ? classname + " " + key : key; } else if (classname.length) { var len = key.length; var a = 0; while ((a = classname.indexOf(key, a)) >= 0) { var b = a + len; if ((a === 0 || whitespace.includes(classname[a - 1])) && (b === classname.length || whitespace.includes(classname[b]))) { classname = (a === 0 ? "" : classname.substring(0, a)) + classname.substring(b + 1); } else { a = b; } } } } } return classname === "" ? null : classname; } function append_styles(styles, important = false) { var separator = important ? " !important;" : ";"; var css = ""; for (var key of Object.keys(styles)) { var value = styles[key]; if (value != null && value !== "") { css += " " + key + ": " + value + separator; } } return css; } function to_css_name(name) { if (name[0] !== "-" || name[1] !== "-") { return name.toLowerCase(); } return name; } function to_style(value, styles) { if (styles) { var new_style = ""; var normal_styles; var important_styles; if (Array.isArray(styles)) { normal_styles = styles[0]; important_styles = styles[1]; } else { normal_styles = styles; } if (value) { value = String(value).replaceAll(/\s*\/\*.*?\*\/\s*/g, "").trim(); var in_str = false; var in_apo = 0; var in_comment = false; var reserved_names = []; if (normal_styles) { reserved_names.push(...Object.keys(normal_styles).map(to_css_name)); } if (important_styles) { reserved_names.push(...Object.keys(important_styles).map(to_css_name)); } var start_index = 0; var name_index = -1; const len = value.length; for (var i = 0; i < len; i++) { var c = value[i]; if (in_comment) { if (c === "/" && value[i - 1] === "*") { in_comment = false; } } else if (in_str) { if (in_str === c) { in_str = false; } } else if (c === "/" && value[i + 1] === "*") { in_comment = true; } else if (c === '"' || c === "'") { in_str = c; } else if (c === "(") { in_apo++; } else if (c === ")") { in_apo--; } if (!in_comment && in_str === false && in_apo === 0) { if (c === ":" && name_index === -1) { name_index = i; } else if (c === ";" || i === len - 1) { if (name_index !== -1) { var name = to_css_name(value.substring(start_index, name_index).trim()); if (!reserved_names.includes(name)) { if (c !== ";") { i++; } var property = value.substring(start_index, i).trim(); new_style += " " + property + ";"; } } start_index = i + 1; name_index = -1; } } } } if (normal_styles) { new_style += append_styles(normal_styles); } if (important_styles) { new_style += append_styles(important_styles, true); } new_style = new_style.trim(); return new_style === "" ? null : new_style; } return value == null ? null : String(value); } function effect_update_depth_exceeded() { { throw new Error(`https://svelte.dev/e/effect_update_depth_exceeded`); } } function hydration_failed() { { throw new Error(`https://svelte.dev/e/hydration_failed`); } } function state_descriptors_fixed() { { throw new Error(`https://svelte.dev/e/state_descriptors_fixed`); } } function state_prototype_fixed() { { throw new Error(`https://svelte.dev/e/state_prototype_fixed`); } } function state_unsafe_mutation() { { throw new Error(`https://svelte.dev/e/state_unsafe_mutation`); } } function svelte_boundary_reset_onerror() { { throw new Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`); } } function derived_inert() { { console.warn(`https://svelte.dev/e/derived_inert`); } } function hydration_mismatch(location) { { console.warn(`https://svelte.dev/e/hydration_mismatch`); } } function svelte_boundary_reset_noop() { { console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`); } } let hydrating = false; function set_hydrating(value) { hydrating = value; } let hydrate_node; function set_hydrate_node(node) { if (node === null) { hydration_mismatch(); throw HYDRATION_ERROR; } return hydrate_node = node; } function hydrate_next() { return set_hydrate_node(/* @__PURE__ */ get_next_sibling(hydrate_node)); } function next(count = 1) { if (hydrating) { var i = count; var node = hydrate_node; while (i--) { node = /** @type {TemplateNode} */ /* @__PURE__ */ get_next_sibling(node); } hydrate_node = node; } } function skip_nodes(remove = true) { var depth = 0; var node = hydrate_node; while (true) { if (node.nodeType === COMMENT_NODE) { var data = ( /** @type {Comment} */ node.data ); if (data === HYDRATION_END) { if (depth === 0) return node; depth -= 1; } else if (data === HYDRATION_START || data === HYDRATION_START_ELSE || // "[1", "[2", etc. for if blocks data[0] === "[" && !isNaN(Number(data.slice(1)))) { depth += 1; } } var next2 = ( /** @type {TemplateNode} */ /* @__PURE__ */ get_next_sibling(node) ); if (remove) node.remove(); node = next2; } } function equals(value) { return value === this.v; } function safe_not_equal(a, b) { return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function"; } function safe_equals(value) { return !safe_not_equal(value, this.v); } let component_context = null; function set_component_context(context) { component_context = context; } function push(props, runes = false, fn) { component_context = { p: component_context, i: false, c: null, e: null, s: props, x: null, r: ( /** @type {Effect} */ active_effect ), l: null }; } function pop(component) { var context = ( /** @type {ComponentContext} */ component_context ); var effects = context.e; if (effects !== null) { context.e = null; for (var fn of effects) { create_user_effect(fn); } } context.i = true; component_context = context.p; return ( /** @type {T} */ {} ); } function is_runes() { return true; } let micro_tasks = []; function run_micro_tasks() { var tasks = micro_tasks; micro_tasks = []; run_all(tasks); } function queue_micro_task(fn) { if (micro_tasks.length === 0 && !is_flushing_sync) { var tasks = micro_tasks; queueMicrotask(() => { if (tasks === micro_tasks) run_micro_tasks(); }); } micro_tasks.push(fn); } function flush_tasks() { while (micro_tasks.length > 0) { run_micro_tasks(); } } function handle_error(error) { var effect = active_effect; if (effect === null) { active_reaction.f |= ERROR_VALUE; return error; } if ((effect.f & REACTION_RAN) === 0 && (effect.f & EFFECT) === 0) { throw error; } invoke_error_boundary(error, effect); } function invoke_error_boundary(error, effect) { while (effect !== null) { if ((effect.f & BOUNDARY_EFFECT) !== 0) { if ((effect.f & REACTION_RAN) === 0) { throw error; } try { effect.b.error(error); return; } catch (e) { error = e; } } effect = effect.parent; } throw error; } const STATUS_MASK = -7169; function set_signal_status(signal, status) { signal.f = signal.f & STATUS_MASK | status; } function update_derived_status(derived2) { if ((derived2.f & CONNECTED) !== 0 || derived2.deps === null) { set_signal_status(derived2, CLEAN); } else { set_signal_status(derived2, MAYBE_DIRTY); } } function clear_marked(deps) { if (deps === null) return; for (const dep of deps) { if ((dep.f & DERIVED) === 0 || (dep.f & WAS_MARKED) === 0) { continue; } dep.f ^= WAS_MARKED; clear_marked( /** @type {Derived} */ dep.deps ); } } function defer_effect(effect, dirty_effects, maybe_dirty_effects) { if ((effect.f & DIRTY) !== 0) { dirty_effects.add(effect); } else if ((effect.f & MAYBE_DIRTY) !== 0) { maybe_dirty_effects.add(effect); } clear_marked(effect.deps); set_signal_status(effect, CLEAN); } let first_batch = null; let last_batch = null; let current_batch = null; let previous_batch = null; let batch_values = null; let last_scheduled_effect = null; let is_flushing_sync = false; let is_processing = false; let collected_effects = null; let legacy_updates = null; var flush_count = 0; let uid = 1; class Batch { id = uid++; /** True as soon as `#process` was called */ #started = false; linked = true; /** @type {Batch | null} */ #prev = null; /** @type {Batch | null} */ #next = null; /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */ async_deriveds = /* @__PURE__ */ new Map(); /** * The current values of any signals that are updated in this batch. * Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment) * They keys of this map are identical to `this.#previous` * @type {Map<Value, [any, boolean]>} */ current = /* @__PURE__ */ new Map(); /** * The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place. * They keys of this map are identical to `this.#current` * @type {Map<Value, any>} */ previous = /* @__PURE__ */ new Map(); /** * Async effects which this batch doesn't take into account anymore when calculating blockers, * as it has a value for it already. * @type {Set<Effect>} */ unblocked = /* @__PURE__ */ new Set(); /** * When the batch is committed (and the DOM is updated), we need to remove old branches * and append new ones by calling the functions added inside (if/each/key/etc) blocks * @type {Set<(batch: Batch) => void>} */ #commit_callbacks = /* @__PURE__ */ new Set(); /** * If a fork is discarded, we need to destroy any effects that are no longer needed * @type {Set<(batch: Batch) => void>} */ #discard_callbacks = /* @__PURE__ */ new Set(); /** * Callbacks that should run only when a fork is committed. * @type {Set<(batch: Batch) => void>} */ #fork_commit_callbacks = /* @__PURE__ */ new Set(); /** * The number of async effects that are currently in flight */ #pending = 0; /** * Async effects that are currently in flight, _not_ inside a pending boundary * @type {Map<Effect, number>} */ #blocking_pending = /* @__PURE__ */ new Map(); /** * A deferred that resolves when the batch is committed, used with `settled()` * TODO replace with Promise.withResolvers once supported widely enough * @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null} */ #deferred = null; /** * The root effects that need to be flushed * @type {Effect[]} */ #roots = []; /** * Effects created while this batch was active. * @type {Effect[]} */ #new_effects = []; /** * Deferred effects (which run after async work has completed) that are DIRTY * @type {Set<Effect>} */ #dirty_effects = /* @__PURE__ */ new Set(); /** * Deferred effects that are MAYBE_DIRTY * @type {Set<Effect>} */ #maybe_dirty_effects = /* @__PURE__ */ new Set(); /** * A map of branches that still exist, but will be destroyed when this batch * is committed — we skip over these during `process`. * The value contains child effects that were dirty/maybe_dirty before being reset, * so they can be rescheduled if the branch survives. * @type {Map<Effect, { d: Effect[], m: Effect[] }>} */ #skipped_branches = /* @__PURE__ */ new Map(); /** * Inverse of #skipped_branches which we need to tell prior batches to unskip them when committing * @type {Set<Effect>} */ #unskipped_branches = /* @__PURE__ */ new Set(); is_fork = false; #decrement_queued = false; #is_deferred() { if (this.is_fork) return true; for (const effect of this.#blocking_pending.keys()) { var e = effect; var skipped = false; while (e.parent !== null) { if (this.#skipped_branches.has(e)) { skipped = true; break; } e = e.parent; } if (!skipped) { return true; } } return false; } /** * Add an effect to the #skipped_branches map and reset its children * @param {Effect} effect */ skip_effect(effect) { if (!this.#skipped_branches.has(effect)) { this.#skipped_branches.set(effect, { d: [], m: [] }); } this.#unskipped_branches.delete(effect); } /** * Remove an effect from the #skipped_branches map and reschedule * any tracked dirty/maybe_dirty child effects * @param {Effect} effect * @param {(e: Effect) => void} callback */ unskip_effect(effect, callback = (e) => this.schedule(e)) { var tracked = this.#skipped_branches.get(effect); if (tracked) { this.#skipped_branches.delete(effect); for (var e of tracked.d) { set_signal_status(e, DIRTY); callback(e); } for (e of tracked.m) { set_signal_status(e, MAYBE_DIRTY); callback(e); } } this.#unskipped_branches.add(effect); } #process() { this.#started = true; if (flush_count++ > 1e3) { this.#unlink(); infinite_loop_guard(); } if (!this.#is_deferred()) { for (const e of this.#dirty_effects) { this.#maybe_dirty_effects.delete(e); set_signal_status(e, DIRTY); this.schedule(e); } for (const e of this.#maybe_dirty_effects) { set_signal_status(e, MAYBE_DIRTY); this.schedule(e); } } const roots = this.#roots; this.#roots = []; this.apply(); var effects = collected_effects = []; var render_effects = []; var updates = legacy_updates = []; for (const root2 of roots) { try { this.#traverse(root2, effects, render_effects); } catch (e) { reset_all(root2); throw e; } } current_batch = null; if (updates.length > 0) { var batch = Batch.ensure(); for (const e of updates) { batch.schedule(e); } } collected_effects = null; legacy_updates = null; if (this.#is_deferred()) { this.#defer_effects(render_effects); this.#defer_effects(effects); for (const [e, t] of this.#skipped_branches) { reset_branch(e, t); } if (updates.length > 0) { /** @type {unknown} */ current_batch.#process(); } return; } const earlier_batch = this.#find_earlier_batch(); if (earlier_batch) { earlier_batch.#merge(this); return; } this.#dirty_effects.clear(); this.#maybe_dirty_effects.clear(); for (const fn of this.#commit_callbacks) fn(this); this.#commit_callbacks.clear(); previous_batch = this; flush_queued_effects(render_effects); flush_queued_effects(effects); previous_batch = null; this.#deferred?.resolve(); var next_batch = ( /** @type {Batch | null} */ /** @type {unknown} */ current_batch ); if (this.linked && this.#pending === 0) { this.#unlink(); } if (async_mode_flag && !this.linked) { this.#commit(); current_batch = next_batch; } if (this.#roots.length > 0) { if (next_batch === null) { next_batch = this; this.#link(); } const batch2 = next_batch; batch2.#roots.push(...this.#roots.filter((r2) => !batch2.#roots.includes(r2))); } if (next_batch !== null) { next_batch.#process(); } } /** * Traverse the effect tree, executing effects or stashing * them for later execution as appropriate * @param {Effect} root * @param {Effect[]} effects * @param {Effect[]} render_effects */ #traverse(root2, effects, render_effects) { root2.f ^= CLEAN; var effect = root2.first; while (effect !== null) { var flags2 = effect.f; var is_branch = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) !== 0; var is_skippable_branch = is_branch && (flags2 & CLEAN) !== 0; var skip = is_skippable_branch || (flags2 & INERT) !== 0 || this.#skipped_branches.has(effect); if (!skip && effect.fn !== null) { if (is_branch) { effect.f ^= CLEAN; } else if ((flags2 & EFFECT) !== 0) { effects.push(effect); } else if (async_mode_flag && (flags2 & (RENDER_EFFECT | MANAGED_EFFECT)) !== 0) { render_effects.push(effect); } else if (is_dirty(effect)) { if ((flags2 & BLOCK_EFFECT) !== 0) this.#maybe_dirty_effects.add(effect); update_effect(effect); } var child = effect.first; if (child !== null) { effect = child; continue; } } while (effect !== null) { var next2 = effect.next; if (next2 !== null) { effect = next2; break; } effect = effect.parent; } } } #find_earlier_batch() { var batch = this.#prev; while (batch !== null) { if (!batch.is_fork) { for (const [value, [, is_derived]] of this.current) { if (batch.current.has(value) && !is_derived) { return batch; } } } batch = batch.#prev; } return null; } /** * @param {Batch} batch */ #merge(batch) { for (const [source2, value] of batch.current) { if (!this.previous.has(source2) && batch.previous.has(source2)) { this.previous.set(source2, batch.previous.get(source2)); } this.current.set(source2, value); } for (const [effect, deferred2] of batch.async_deriveds) { const d = this.async_deriveds.get(effect); if (d) deferred2.promise.then(d.resolve); } const mark = (value) => { var reactions = value.reactions; if (reactions === null) return; for (const reaction of reactions) { var flags2 = reaction.f; if ((flags2 & DERIVED) !== 0) { mark( /** @type {Derived} */ reaction ); } else { var effect = ( /** @type {Effect} */ reaction ); if (flags2 & (ASYNC | BLOCK_EFFECT) && !this.async_deriveds.has(effect)) { this.#maybe_dirty_effects.delete(effect); set_signal_status(effect, DIRTY); this.schedule(effect); } } } }; for (const source2 of this.current.keys()) { mark(source2); } this.oncommit(() => batch.discard()); batch.#unlink(); current_batch = this; this.#process(); } /** * @param {Effect[]} effects */ #defer_effects(effects) { for (var i = 0; i < effects.length; i += 1) { defer_effect(effects[i], this.#dirty_effects, this.#maybe_dirty_effects); } } /** * Associate a change to a given source with the current * batch, noting its previous and current values * @param {Value} source * @param {any} value * @param {boolean} [is_derived] */ capture(source2, value, is_derived = false) { if (source2.v !== UNINITIALIZED && !this.previous.has(source2)) { this.previous.set(source2, source2.v); } if ((source2.f & ERROR_VALUE) === 0) { this.current.set