import { Jn as deferred, Kn as get_stack, Vn as STALE_REACTION, ar as noop, fr as invalid_snippet_arguments, hr as set_context_after_init, ir as is_promise, mr as missing_context, nr as is_array, pr as lifecycle_outside_component, tr as has_own_property } from "./runtime-DInTlc-h.js"; import { t as async_mode_flag } from "./flags-qfBdqUK7.js"; import { l as UNINITIALIZED, n as FILENAME } from "./constants-Dd0-6Ncu.js"; import { i as EMPTY_COMMENT, n as BLOCK_OPEN, o as is_tag_valid_with_ancestor, r as BLOCK_OPEN_ELSE, s as is_tag_valid_with_parent, t as BLOCK_CLOSE } from "./hydration-Bgwk4N_v.js"; import { _ as is_void, a as is_boolean_attribute, b as escape_html, f as is_raw_text_element, i as hash, t as REGEX_VALID_TAG_NAME } from "./utils-BWzPBw9Y.js"; import { a as attr, c as to_style, o as clsx, r as validate_store, s as to_class } from "./validate-EWwS2w2A.js"; import { t as subscribe_to_store } from "./utils-B9o6NEeQ.js"; // node_modules/svelte/src/internal/shared/context.js /** * @template T * @param {(key: object) => T} get_context * @param {(key: object, context: T) => T} set_context * @param {(key: object) => boolean} has_context * @returns {[() => T, (context: T) => T, () => boolean]} */ function create_context(get_context, set_context, has_context) { const key = {}; return [ () => { if (!has_context(key)) missing_context(); return get_context(key); }, (context) => set_context(key, context), () => has_context(key) ]; } /** * @typedef {{ p: Context | null, c: Map | null }} Context */ /** * @param {Context} context * @returns {Map | null} */ function get_parent_context(context) { let parent = context.p; while (parent !== null && parent.c === null) parent = parent.p; return parent?.c ?? null; } /** * @param {Context | null} context * @param {string} name * @returns {Map} */ function get_or_init_context_map(context, name) { if (context === null) lifecycle_outside_component(name); return context.c ??= new Map(get_parent_context(context) || void 0); } // node_modules/svelte/src/internal/server/errors.js /** * The node API `AsyncLocalStorage` is not available, but is required to use async server rendering. * @returns {never} */ function async_local_storage_unavailable() { const error = /* @__PURE__ */ new Error(`async_local_storage_unavailable\nThe node API \`AsyncLocalStorage\` is not available, but is required to use async server rendering.\nhttps://svelte.dev/e/async_local_storage_unavailable`); error.name = "Svelte error"; throw error; } /** * Encountered asynchronous work while rendering synchronously. * @returns {never} */ function await_invalid() { const error = /* @__PURE__ */ new Error(`await_invalid\nEncountered asynchronous work while rendering synchronously.\nhttps://svelte.dev/e/await_invalid`); error.name = "Svelte error"; throw error; } /** * `` is not a valid element name — the element will not be rendered * @param {string} tag * @returns {never} */ function dynamic_element_invalid_tag(tag) { const error = /* @__PURE__ */ new Error(`dynamic_element_invalid_tag\n\`\` is not a valid element name — the element will not be rendered\nhttps://svelte.dev/e/dynamic_element_invalid_tag`); error.name = "Svelte error"; throw error; } /** * The `html` property of server render results has been deprecated. Use `body` instead. * @returns {never} */ function html_deprecated() { const error = /* @__PURE__ */ new Error(`html_deprecated\nThe \`html\` property of server render results has been deprecated. Use \`body\` instead.\nhttps://svelte.dev/e/html_deprecated`); error.name = "Svelte error"; throw error; } /** * Attempted to set `hydratable` with key `%key%` twice with different values. * * %stack% * @param {string} key * @param {string} stack * @returns {never} */ function hydratable_clobbering(key, stack) { const error = /* @__PURE__ */ new Error(`hydratable_clobbering\nAttempted to set \`hydratable\` with key \`${key}\` twice with different values. ${stack}\nhttps://svelte.dev/e/hydratable_clobbering`); error.name = "Svelte error"; throw error; } /** * Failed to serialize `hydratable` data for key `%key%`. * * `hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/devalue) can, plus Promises. * * Cause: * %stack% * @param {string} key * @param {string} stack * @returns {never} */ function hydratable_serialization_failed(key, stack) { const error = /* @__PURE__ */ new Error(`hydratable_serialization_failed\nFailed to serialize \`hydratable\` data for key \`${key}\`. \`hydratable\` can serialize anything [\`uneval\` from \`devalue\`](https://npmjs.com/package/devalue) can, plus Promises. Cause: ${stack}\nhttps://svelte.dev/e/hydratable_serialization_failed`); error.name = "Svelte error"; throw error; } /** * `csp.nonce` was set while `csp.hash` was `true`. These options cannot be used simultaneously. * @returns {never} */ function invalid_csp() { const error = /* @__PURE__ */ new Error(`invalid_csp\n\`csp.nonce\` was set while \`csp.hash\` was \`true\`. These options cannot be used simultaneously.\nhttps://svelte.dev/e/invalid_csp`); error.name = "Svelte error"; throw error; } /** * The `idPrefix` option cannot include `--`. * @returns {never} */ function invalid_id_prefix() { const error = /* @__PURE__ */ new Error(`invalid_id_prefix\nThe \`idPrefix\` option cannot include \`--\`.\nhttps://svelte.dev/e/invalid_id_prefix`); error.name = "Svelte error"; throw error; } /** * `%name%(...)` is not available on the server * @param {string} name * @returns {never} */ function lifecycle_function_unavailable(name) { const error = /* @__PURE__ */ new Error(`lifecycle_function_unavailable\n\`${name}(...)\` is not available on the server\nhttps://svelte.dev/e/lifecycle_function_unavailable`); error.name = "Svelte error"; throw error; } /** * Could not resolve `render` context. * @returns {never} */ function server_context_required() { const error = /* @__PURE__ */ new Error(`server_context_required\nCould not resolve \`render\` context.\nhttps://svelte.dev/e/server_context_required`); error.name = "Svelte error"; throw error; } // node_modules/svelte/src/internal/server/context.js /** @import { SSRContext } from '#server' */ /** @type {SSRContext | null} */ var ssr_context = null; /** @param {SSRContext | null} v */ function set_ssr_context(v) { ssr_context = v; } /** * @template T * @returns {[() => T, (context: T) => T, () => boolean]} * @since 5.40.0 */ function createContext() { return create_context(getContext, setContext, hasContext); } /** * @template T * @param {any} key * @returns {T} */ function getContext(key) { return get_or_init_context_map(ssr_context, "getContext").get(key); } /** * @template T * @param {any} key * @param {T} context * @returns {T} */ function setContext(key, context) { const context_map = get_or_init_context_map(ssr_context, "setContext"); if (ssr_context.i) set_context_after_init(); context_map.set(key, context); return context; } /** * @param {any} key * @returns {boolean} */ function hasContext(key) { return get_or_init_context_map(ssr_context, "hasContext").has(key); } /** @returns {Map} */ function getAllContexts() { return get_or_init_context_map(ssr_context, "getAllContexts"); } /** * @param {Function} [fn] */ function push(fn) { ssr_context = { p: ssr_context, c: null, r: null, i: false }; ssr_context.function = fn; ssr_context.element = ssr_context.p?.element; } function pop() { ssr_context = ssr_context.p; } /** * Wraps an `await` expression in such a way that the component context that was * active before the expression evaluated can be reapplied afterwards — * `await a + b()` becomes `(await $.save(a))() + b()`, meaning `b()` will have access * to the context of its component. * @template T * @param {Promise} promise * @returns {Promise<() => T>} */ async function save(promise) { var previous_context = ssr_context; var value = await promise; return () => { ssr_context = previous_context; return value; }; } // node_modules/svelte/src/internal/server/render-context.js /** @import { AsyncLocalStorage } from 'node:async_hooks' */ /** @import { RenderContext } from '#server' */ /** @type {Promise | null} */ var current_render = null; /** @type {RenderContext | null} */ var context = null; /** @returns {RenderContext} */ function get_render_context() { const store = context ?? als?.getStore(); if (!store) server_context_required(); return store; } /** * @template T * @param {() => Promise} fn * @returns {Promise} */ 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; } } /** @type {AsyncLocalStorage | null} */ var als = null; /** @type {Promise | null} */ var als_import = null; /** * * @returns {Promise} */ 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; } var MAX_ARRAY_INDEX = 2 ** 32 - 1 - 1; // node_modules/devalue/src/utils.js /** @type {Record} */ var escaped = { "<": "\\u003C", "\\": "\\\\", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", " ": "\\t", "\u2028": "\\u2028", "\u2029": "\\u2029" }; var DevalueError = class 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; } }; /** @param {any} thing */ function is_primitive(thing) { return thing === null || typeof thing !== "object" && typeof thing !== "function"; } var object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0"); /** @param {any} thing */ 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; } /** @param {any} thing */ function get_type(thing) { return Object.prototype.toString.call(thing).slice(8, -1); } /** @param {any} thing */ function is_buffer(thing) { return typeof Buffer !== "undefined" && Buffer.isBuffer(thing); } /** @param {string} char */ 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")}` : ""; } } /** @param {string} str */ 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)}"`; } /** @param {Record} object */ function enumerable_symbols(object) { return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable); } var is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; /** @param {string} key */ function stringify_key(key) { return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]"; } /** @param {number} n */ 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; } /** @param {string} s */ 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); } /** * Returns the length of the leading run of valid array indices in `keys`. * @param {readonly string[]} keys */ function array_index_cut(keys) { for (var i = keys.length - 1; i >= 0; i--) if (is_valid_array_index_string(keys[i])) break; return i + 1; } /** * Finds the populated indices of an array. * @param {unknown[]} array */ function valid_array_indices(array) { const keys = Object.keys(array); keys.length = array_index_cut(keys); return keys; } // node_modules/devalue/src/uneval.js var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"; var MIN_STRING_LENGTH = 128; var unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g; var 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)$/; /** * Turn a value into the JavaScript that creates an equivalent value * @param {any} value * @param {(value: any, uneval: (value: any) => string) => string | void} [replacer] */ function uneval(value, replacer) { const counts = /* @__PURE__ */ new Map(); /** @type {string[]} */ const keys = []; const custom = /* @__PURE__ */ new Map(); /** @type {Map | undefined} */ let primitives; /** @param {any} thing */ function stringify_cached_primitive(thing) { if (typeof thing === "string" && thing.length >= MIN_STRING_LENGTH || typeof thing === "bigint") { primitives ??= /* @__PURE__ */ new Map(); let literal = primitives.get(thing); if (literal === void 0) { literal = stringify_primitive(thing); primitives.set(thing, literal); } return literal; } return stringify_primitive(thing); } /** @param {any} thing */ 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 str = replacer(thing, (value) => uneval(value, replacer)); if (typeof str === "string") { custom.set(thing, str); return; } } if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value); switch (get_type(thing)) { case "BigInt": case "String": walk(thing.valueOf()); return; case "Number": case "Boolean": case "Date": case "RegExp": case "URL": case "URLSearchParams": return; case "Array": for (const i of valid_array_indices(thing)) { keys.push(`[${i}]`); walk(thing[i]); keys.pop(); } break; case "Set": Array.from(thing).forEach(walk); break; case "Map": for (const [key, value] of thing) { keys.push(`.get(${is_primitive(key) ? stringify_cached_primitive(key) : "..."})`); walk(key); walk(value); 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": if (!is_buffer(thing)) 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); else if (typeof thing === "string" && thing.length >= MIN_STRING_LENGTH || typeof thing === "bigint") counts.set(thing, (counts.get(thing) || 0) + 1); } walk(value); const names = /* @__PURE__ */ new Map(); /** @type {Array<[any, number]>} */ const repeated = []; counts.forEach((count, thing) => { if (count > 1) repeated.push([thing, count]); }); repeated.sort((a, b) => b[1] - a[1]).forEach(([thing, count]) => { const name = get_name(names.size); if (is_primitive(thing)) { const length = stringify_cached_primitive(thing).length; if (length * count <= length + (count + 1) * name.length + 25) return; } names.set(thing, name); }); /** * @param {any} thing * @returns {string} */ 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(thing); const population = populated_keys.length; const d = String(thing.length).length; const array = stringify_sparse_array(thing.length); if (thing.length + 2 > array.length + 18 + population * (d + 2)) return `Object.assign(${array},{${populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(",")}})`; has_holes = true; } } const tail = thing.length === 0 || Object.hasOwn(thing, thing.length - 1) ? "" : ","; 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": { if (is_buffer(thing)) thing = new Uint8Array(thing); let str = `new ${type}`; if (!names.has(thing.buffer)) str += `([${stringify_typed_array_elements(type, thing.buffer)}])`; else str += `(${stringify(thing.buffer)})`; if (thing.byteLength !== thing.buffer.byteLength) { const start = thing.byteOffset / thing.BYTES_PER_ELEMENT; const end = start + thing.length; str += `.subarray(${start},${end})`; } return str; } case "DataView": { let str = `new DataView`; if (!names.has(thing.buffer)) str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`; else str += `(${stringify(thing.buffer)}`; if (thing.byteLength !== thing.buffer.byteLength) str += `,${thing.byteOffset},${thing.byteLength}`; return str + ")"; } case "ArrayBuffer": return `new Uint8Array([${new Uint8Array(thing).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 keys = Object.keys(thing); const obj = keys.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(","); if (Object.getPrototypeOf(thing) === null) return keys.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`; return `{${obj}}`; } } const str = stringify(value); if (names.size) { /** @type {string[]} */ const params = []; /** @type {string[]} */ const statements = []; /** @type {string[]} */ const values = []; /** @type {string[]} */ const reconstructions = []; names.forEach((name, thing) => { params.push(name); if (custom.has(thing)) { values.push(custom.get(thing)); return; } if (is_primitive(thing)) { values.push(stringify_cached_primitive(thing)); return; } const type = get_type(thing); switch (type) { case "Number": case "String": case "Boolean": case "BigInt": { const primitive = thing.valueOf(); if (names.has(primitive)) { values.push("{}"); reconstructions.push(`${name}=Object(${stringify(primitive)})`); } else values.push(`Object(${stringify(primitive)})`); 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": { const populated_keys = valid_array_indices(thing); values.push(thing.length > 32 + 2 * populated_keys.length ? stringify_sparse_array(thing.length) : `Array(${thing.length})`); for (const i of populated_keys) statements.push(`${name}[${i}]=${stringify(thing[i])}`); break; } case "Set": { values.push(`new Set`); const adds = Array.from(thing).map((v) => `.add(${stringify(v)})`); if (adds.length > 0) statements.push(name + adds.join("")); break; } case "Map": { values.push(`new Map`); const sets = Array.from(thing).map(([k, v]) => `.set(${stringify(k)}, ${stringify(v)})`); if (sets.length > 0) statements.push(name + sets.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": { if (is_buffer(thing)) thing = new Uint8Array(thing); let str = `new ${type}`; if (!names.has(thing.buffer)) str += `([${stringify_typed_array_elements(type, thing.buffer)}])`; else str += `(${stringify(thing.buffer)})`; if (thing.byteLength !== thing.buffer.byteLength) { const start = thing.byteOffset / thing.BYTES_PER_ELEMENT; const end = start + thing.length; str += `.subarray(${start},${end})`; } values.push(`{}`); reconstructions.push(`${name}=${str}`); break; } case "DataView": { let str = `new DataView`; if (!names.has(thing.buffer)) str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`; else str += `(${stringify(thing.buffer)}`; if (thing.byteLength !== thing.buffer.byteLength) str += `,${thing.byteOffset},${thing.byteLength}`; str += ")"; values.push(`{}`); reconstructions.push(`${name}=${str}`); break; } case "ArrayBuffer": values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`); break; case "Temporal.Duration": case "Temporal.Instant": case "Temporal.PlainDate": case "Temporal.PlainTime": case "Temporal.PlainDateTime": case "Temporal.PlainMonthDay": case "Temporal.PlainYearMonth": case "Temporal.ZonedDateTime": values.push(`${type}.from(${stringify_string(thing.toString())})`); 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}`); const body = [...reconstructions, ...statements].join(";"); if (params.length > 65534) return `(function(){var[${params.join(",")}]=arguments[0];${body}}([${values.join(",")}]))`; return `(function(${params.join(",")}){${body}}(${values.join(",")}))`; } else return str; } /** * Emit an array whose storage is not proportional to its declared length. * As in the default parse operations, touching and deleting the largest valid * index forces V8 into dictionary-elements mode before setting the length. * Merely starting with [] and assigning .length still eagerly allocates. * @param {number} length */ function stringify_sparse_array(length) { return `(function(a){a[${MAX_ARRAY_INDEX}]=0;delete a[${MAX_ARRAY_INDEX}];a.length=${length};return a}([]))`; } /** * Serialize the elements of `buffer`, read as `type`, as a comma-separated list. * The view is created from `type` rather than from the serialized value's own * constructor, which may be a subclass like Node's `Buffer` whose `toString` * decodes the bytes instead of listing them. * `BigInt64Array`/`BigUint64Array` elements are bigints and must be written * with an `n` suffix, otherwise the emitted `new BigInt64Array([...])` throws. * @param {string} type * @param {ArrayBufferLike} buffer */ function stringify_typed_array_elements(type, buffer) { const array = new globalThis[type](buffer); if (type === "BigInt64Array" || type === "BigUint64Array") return Array.from(array, (element) => `${element}n`).join(","); if (array instanceof Float32Array || array instanceof Float64Array || typeof Float16Array !== "undefined" && array instanceof Float16Array) return Array.from(array, (element) => Object.is(element, -0) ? "-0" : `${element}`).join(","); return array.toString(); } /** @param {number} num */ function get_name(num) { let name = ""; do { name = chars[num % 54] + name; num = ~~(num / 54) - 1; } while (num >= 0); return reserved.test(name) ? `${name}0` : name; } /** @param {string} c */ function escape_unsafe_char(c) { return escaped[c] || c; } /** @param {string} str */ function escape_unsafe_chars(str) { return str.replace(unsafe_chars, escape_unsafe_char); } /** @param {string} key */ function safe_key(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key)); } /** @param {string} key */ function safe_prop(key) { return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? `.${key}` : `[${escape_unsafe_chars(JSON.stringify(key))}]`; } /** @param {any} thing */ 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; } // node_modules/svelte/src/internal/server/warnings.js var bold = "font-weight: bold"; var normal = "font-weight: normal"; /** * A `hydratable` value with key `%key%` was created, but at least part of it was not used during the render. * * The `hydratable` was initialized in: * %stack% * @param {string} key * @param {string} stack */ function unresolved_hydratable(key, stack) { console.warn(`%c[svelte] unresolved_hydratable\n%cA \`hydratable\` value with key \`${key}\` was created, but at least part of it was not used during the render. The \`hydratable\` was initialized in: ${stack}\nhttps://svelte.dev/e/unresolved_hydratable`, bold, normal); } // node_modules/svelte/src/internal/server/blocks/html.js /** * @param {string} value */ function html(value) { var html = String(value ?? ""); return `` + html + ""; } // node_modules/svelte/src/internal/server/index.js var INVALID_ATTR_NAME_CHAR_REGEX = /[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u; /** * @param {Renderer} renderer * @param {string} tag * @param {() => void} attributes_fn * @param {() => void} children_fn * @returns {void} */ function element(renderer, tag, attributes_fn = noop, children_fn = noop) { renderer.push(""); if (tag) { if (!REGEX_VALID_TAG_NAME.test(tag)) dynamic_element_invalid_tag(tag); renderer.push(`<${tag}`); attributes_fn(); renderer.push(`>`); if (!is_void(tag)) { children_fn(); if (!is_raw_text_element(tag)) renderer.push(EMPTY_COMMENT); renderer.push(``); } } renderer.push(""); } /** * Only available on the server and when compiling with the `server` option. * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app. * @template {Record} Props * @param {Component | ComponentType>} component * @param {{ props?: Omit; context?: Map; idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} [options] * @returns {RenderOutput} */ function render(component, options = {}) { if (options.csp?.hash && options.csp.nonce) invalid_csp(); return Renderer.render(component, options); } /** * @param {string} hash * @param {Renderer} renderer * @param {(renderer: Renderer) => Promise | void} fn * @returns {void} */ function head(hash, renderer, fn) { renderer.head((renderer) => { renderer.push(``); renderer.child(fn); renderer.push(EMPTY_COMMENT); }); } /** * @param {Renderer} renderer * @param {boolean} is_html * @param {Record} props * @param {() => void} component * @param {boolean} dynamic * @returns {void} */ function css_props(renderer, is_html, props, component, dynamic = false) { const styles = style_object_to_string(props); if (is_html) renderer.push(``); else renderer.push(``); component(); if (!dynamic) renderer.push(""); if (is_html) renderer.push(""); else renderer.push(""); } /** * @param {Record} attrs * @param {string} [css_hash] * @param {Record} [classes] * @param {Record} [styles] * @param {number} [flags] * @returns {string} */ function attributes(attrs, css_hash, classes, styles, flags = 0) { if (styles) attrs.style = to_style(attrs.style, styles); if (attrs.class) attrs.class = clsx(attrs.class); if (css_hash || classes) attrs.class = to_class(attrs.class, css_hash, classes); let attr_str = ""; let name; const is_html = (flags & 1) === 0; const lowercase = (flags & 2) === 0; const is_input = (flags & 4) !== 0; const names = Object.keys(attrs); outer: for (let i = 0; i < names.length; i++) { name = names[i]; if (typeof attrs[name] === "function") continue; if (name[0] === "$" && name[1] === "$") continue; if (name === "" || INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue; var value = attrs[name]; var lower = name.toLowerCase(); if (lowercase) name = lower; if (lower.length > 2 && lower.startsWith("on")) continue; if (is_input) { if (name === "defaultvalue" || name === "defaultchecked") { name = name === "defaultvalue" ? "value" : "checked"; if (name in attrs) continue; for (let j = 0; j < names.length; j++) if (names[j].toLowerCase() === name) continue outer; } } attr_str += attr(name, value, is_html && is_boolean_attribute(name)); } return attr_str; } /** * @param {Record[]} props * @returns {Record} */ function spread_props(props) { /** @type {Record} */ const merged_props = {}; let key; for (let i = 0; i < props.length; i++) { const obj = props[i]; if (obj == null) continue; for (key of Object.keys(obj)) { const desc = Object.getOwnPropertyDescriptor(obj, key); if (desc) Object.defineProperty(merged_props, key, desc); else merged_props[key] = obj[key]; } } return merged_props; } /** * @param {unknown} value * @returns {string} */ function stringify(value) { return typeof value === "string" ? value : value == null ? "" : value + ""; } /** @param {Record} style_object */ function style_object_to_string(style_object) { return Object.keys(style_object).filter( /** @param {any} key */ (key) => style_object[key] != null && style_object[key] !== "" ).map( /** @param {any} key */ (key) => `${key}: ${escape_html(style_object[key], true)};` ).join(" "); } /** * @param {any} value * @param {string | undefined} [hash] * @param {Record} [directives] */ function attr_class(value, hash, directives) { var result = to_class(value, hash, directives); return result ? ` class="${escape_html(result, true)}"` : ""; } /** * @param {any} value * @param {Record|[Record,Record]} [directives] */ function attr_style(value, directives) { var result = to_style(value, directives); return result ? ` style="${escape_html(result, true)}"` : ""; } /** * @template V * @param {Record} store_values * @param {string} store_name * @param {Store | null | undefined} store * @returns {V} */ function store_get(store_values, store_name, store) { validate_store(store, store_name.slice(1)); if (store_name in store_values && store_values[store_name][0] === store) return store_values[store_name][2]; store_values[store_name]?.[1](); store_values[store_name] = [ store, null, void 0 ]; const unsub = subscribe_to_store( store, /** @param {any} v */ (v) => store_values[store_name][2] = v ); store_values[store_name][1] = unsub; return store_values[store_name][2]; } /** * Sets the new value of a store and returns that value. * @template V * @param {Store} store * @param {V} value * @returns {V} */ function store_set(store, value) { store.set(value); return value; } /** * Updates a store with a new value. * @template V * @param {Record} store_values * @param {string} store_name * @param {Store} store * @param {any} expression */ function store_mutate(store_values, store_name, store, expression) { store_set(store, store_get(store_values, store_name, store)); return expression; } /** * @param {Record} store_values * @param {string} store_name * @param {Store} store * @param {1 | -1} [d] * @returns {number} */ function update_store(store_values, store_name, store, d = 1) { let store_value = store_get(store_values, store_name, store); store.set(store_value + d); return store_value; } /** * @param {Record} store_values * @param {string} store_name * @param {Store} store * @param {1 | -1} [d] * @returns {number} */ function update_store_pre(store_values, store_name, store, d = 1) { const value = store_get(store_values, store_name, store) + d; store.set(value); return value; } /** @param {Record} store_values */ function unsubscribe_stores(store_values) { for (const store_name of Object.keys(store_values)) store_values[store_name][1](); } /** * @param {Renderer} renderer * @param {Record} $$props * @param {string} name * @param {Record} slot_props * @param {null | (() => void)} fallback_fn * @returns {void} */ function slot(renderer, $$props, name, slot_props, fallback_fn) { var slot_fn = $$props.$$slots?.[name]; if (slot_fn === true) slot_fn = $$props[name === "default" ? "children" : name]; if (slot_fn !== void 0) slot_fn(renderer, slot_props); else fallback_fn?.(); } /** * @param {Record} props * @param {string[]} rest * @returns {Record} */ function rest_props(props, rest) { /** @type {Record} */ const rest_props = {}; let key; for (key of Object.keys(props)) if (!rest.includes(key)) rest_props[key] = props[key]; return rest_props; } /** * @param {Record} props * @returns {Record} */ function sanitize_props(props) { const { children, $$slots, ...sanitized } = props; return sanitized; } /** * @param {Record} props * @returns {Record} */ function sanitize_slots(props) { /** @type {Record} */ const sanitized = {}; if (props.children) sanitized.default = true; for (const key of Object.keys(props.$$slots || {})) sanitized[key] = true; return sanitized; } /** * Legacy mode: If the prop has a fallback and is bound in the * parent component, propagate the fallback value upwards. * @param {Record} props_parent * @param {Record} props_now */ function bind_props(props_parent, props_now) { for (const key of Object.keys(props_now)) { const initial_value = props_parent[key]; const value = props_now[key]; if (initial_value === void 0 && value !== void 0 && Object.getOwnPropertyDescriptor(props_parent, key)?.set) props_parent[key] = value; } } /** * @template V * @param {Renderer} renderer * @param {Promise} promise * @param {null | (() => void)} pending_fn * @param {(value: V) => void} then_fn * @returns {void} */ function await_block(renderer, promise, pending_fn, then_fn) { if (is_promise(promise)) { renderer.push(BLOCK_OPEN); promise.then(null, noop); if (pending_fn !== null) pending_fn(); } else if (then_fn !== null) { renderer.push(BLOCK_OPEN_ELSE); then_fn(promise); } } /** @param {any} array_like_or_iterator */ function ensure_array_like(array_like_or_iterator) { if (array_like_or_iterator) return array_like_or_iterator.length !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator); return []; } /** * @template V * @param {() => V} get_value */ function once(get_value) { let value = UNINITIALIZED; return () => { if (value === UNINITIALIZED) value = get_value(); return value; }; } /** * Create an unique ID * @param {Renderer} renderer * @returns {string} */ function props_id(renderer) { const uid = renderer.global.uid(); renderer.push(""); return uid; } /** * @template T * @param {()=>T} fn * @returns {(new_value?: T) => (T | void)} */ function derived(fn) { const get_value = ssr_context === null ? fn : once(fn); /** @type {T | undefined} */ let updated_value; return function(new_value) { if (arguments.length === 0) return updated_value ?? get_value(); updated_value = new_value; return updated_value; }; } /** * @template {number | bigint} T * @param {(value?: T) => T} derived * @param {1 | -1} [d] * @returns {T} */ function update_derived(derived, d = 1) { const value = derived(); derived(value + (typeof value === "bigint" ? BigInt(d) : d)); return value; } /** * @template {number | bigint} T * @param {(value?: T) => T} derived * @param {1 | -1} [d] * @returns {T} */ function update_derived_pre(derived, d = 1) { const old_value = derived(); const value = old_value + (typeof old_value === "bigint" ? BigInt(d) : d); derived(value); return value; } /** * @template T * @param {()=>T} fn */ function async_derived(fn) { return Promise.resolve(fn()).then((value) => { return () => value; }); } // node_modules/svelte/src/internal/server/crypto.js var text_encoder; var crypto; /** @param {string} module_name */ var obfuscated_import = (module_name) => import( /* @vite-ignore */ module_name ); /** @param {string} data */ async function sha256(data) { text_encoder ??= new TextEncoder(); crypto ??= globalThis.crypto?.subtle?.digest ? globalThis.crypto : (await obfuscated_import("node:crypto")).webcrypto; return base64_encode(await crypto.subtle.digest("SHA-256", text_encoder.encode(data))); } /** * @param {Uint8Array} bytes * @returns {string} */ function base64_encode(bytes) { if (globalThis.Buffer) return globalThis.Buffer.from(bytes).toString("base64"); let binary = ""; for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]); return btoa(binary); } // node_modules/svelte/src/internal/server/renderer.js /** @import { Component } from 'svelte' */ /** @import { HydratableContext, SSRContext } from './types.js' */ /** @import { Csp, RenderOutput, SyncRenderOutput, Sha256Source } from '../../server/public.js' */ /** @import { MaybePromise } from '#shared' */ /** @typedef {'head' | 'body'} RendererType */ /** @typedef {{ [key in RendererType]: string }} AccumulatedContent */ /** * @typedef {string | Renderer} RendererItem */ var RenderResult = class { /** @type {() => AccumulatedContent} */ #render; /** @type {() => Promise} */ #render_async; /** @type {AccumulatedContent | undefined} */ #sync; /** @type {{ script: '' }} */ #hashes = { script: "" }; /** @type {Promise | undefined} */ #promise; /** * @param {() => AccumulatedContent} render * @param {() => Promise} render_async */ constructor(render, render_async) { this.#render = render; this.#render_async = render_async; } #get() { return this.#sync ??= this.#render(); } get html() { return this.#get().body; } get head() { return this.#get().head; } get body() { return this.#get().body; } get hashes() { return this.#hashes; } /** * This is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function. * * @template TResult1 * @template [TResult2=never] * @param {(value: SyncRenderOutput) => TResult1} onfulfilled * @param {(reason: unknown) => TResult2} onrejected */ then(onfulfilled, onrejected) { if (!async_mode_flag) { const result = this.#get(); const user_result = onfulfilled({ head: result.head, body: result.body, html: result.body, hashes: { script: [] } }); return Promise.resolve(user_result); } this.#promise ??= this.#render_async().then((result) => { Object.defineProperty(result, "html", { get: () => { html_deprecated(); } }); return result; }); return this.#promise.then((result) => onfulfilled(result), onrejected); } }; /** * Renderers are basically a tree of `string | Renderer`s, where each `Renderer` in the tree represents * work that may or may not have completed. A renderer can be {@link collect}ed to aggregate the * content from itself and all of its children, but this will throw if any of the children are * performing asynchronous work. To asynchronously collect a renderer, just `await` it. * * The `string` values within a renderer are always associated with the {@link type} of that renderer. To switch types, * call {@link child} with a different `type` argument. */ var Renderer = class Renderer { /** * The contents of the renderer. * @type {RendererItem[]} */ #out = []; /** * Any `onDestroy` callbacks registered during execution of this renderer. * @type {(() => void)[] | undefined} */ #on_destroy = void 0; /** * Whether this renderer is a component body. * @type {boolean} */ #is_component_body = false; /** * If set, this renderer is an error boundary. When async collection * of the children fails, the failed snippet is rendered instead. * @type {{ * failed: (renderer: Renderer, error: unknown, reset: () => void) => void; * transformError: (error: unknown) => unknown; * context: SSRContext | null; * } | null} */ #boundary = null; /** * The type of string content that this renderer is accumulating. * @type {RendererType} */ type; /** @type {Renderer | undefined} */ #parent; /** * Asynchronous work associated with this renderer * @type {Promise | undefined} */ promise = void 0; /** * State which is associated with the content tree as a whole. * It will be re-exposed, uncopied, on all children. * @type {SSRState} * @readonly */ global; /** * State that is local to the branch it is declared in. * It will be shallow-copied to all children. * * @type {{ select_value: any, multiple: boolean }} */ local; /** * @param {SSRState} global * @param {Renderer | undefined} [parent] */ constructor(global, parent) { this.#parent = parent; this.global = global; this.local = parent ? { ...parent.local } : { select_value: void 0, multiple: false }; this.type = parent ? parent.type : "body"; } /** * @param {(renderer: Renderer) => void} fn */ head(fn) { const head = new Renderer(this.global, this); head.type = "head"; this.#out.push(head); head.child(fn); } /** * @param {Array>} blockers * @param {(renderer: Renderer) => void} fn */ async_block(blockers, fn) { this.#out.push(BLOCK_OPEN); this.async(blockers, fn); this.#out.push(BLOCK_CLOSE); } /** * @param {Array>} blockers * @param {(renderer: Renderer) => void} fn */ async(blockers, fn) { let callback = fn; if (blockers.length > 0) { const context = ssr_context; callback = (renderer) => { return Promise.all(blockers).then(() => { const previous_context = ssr_context; try { set_ssr_context(context); return fn(renderer); } finally { set_ssr_context(previous_context); } }); }; } this.child(callback); } /** * @param {Array<() => void>} thunks */ run(thunks) { const context = ssr_context; let promise = Promise.resolve(thunks[0]()); const promises = [promise]; if (context !== null && thunks.length > 1) context.i = true; for (const fn of thunks.slice(1)) { promise = promise.then(() => { const previous_context = ssr_context; set_ssr_context(context); try { return fn(); } finally { set_ssr_context(previous_context); } }); promises.push(promise); } promise.catch(noop); this.promise = this.global.track(promise); return promises; } /** * @param {(renderer: Renderer) => MaybePromise} fn */ child_block(fn) { this.#out.push(BLOCK_OPEN); this.child(fn); this.#out.push(BLOCK_CLOSE); } /** * Create a child renderer. The child renderer inherits the state from the parent, * but has its own content. * @param {(renderer: Renderer) => MaybePromise} fn */ child(fn) { const child = new Renderer(this.global, this); this.#out.push(child); const parent = ssr_context; set_ssr_context({ ...ssr_context, p: parent, c: null, r: child, i: ssr_context?.i ?? false }); const result = fn(child); set_ssr_context(parent); if (result instanceof Promise) { result.catch(noop); result.finally(() => set_ssr_context(null)).catch(noop); if (child.global.mode === "sync") await_invalid(); child.promise = child.global.track(result); } return child; } /** * Render children inside an error boundary. If the children throw and the API-level * `transformError` transform handles the error (doesn't re-throw), the `failed` snippet is * rendered instead. Otherwise the error propagates. * * @param {{ failed?: (renderer: Renderer, error: unknown, reset: () => void) => void }} props * @param {(renderer: Renderer) => MaybePromise} children_fn */ boundary(props, children_fn) { const child = new Renderer(this.global, this); this.#out.push(child); const parent_context = ssr_context; if (props.failed) child.#boundary = { failed: props.failed, transformError: this.global.transformError, context: parent_context }; set_ssr_context({ ...ssr_context, p: parent_context, c: null, r: child, i: ssr_context?.i ?? false }); try { const result = children_fn(child); set_ssr_context(parent_context); if (result instanceof Promise) { if (child.global.mode === "sync") await_invalid(); result.catch(noop); child.promise = child.global.track(result); } } catch (error) { set_ssr_context(parent_context); const failed_snippet = props.failed; if (!failed_snippet) throw error; const result = this.global.transformError(error); child.#out.length = 0; child.#boundary = null; if (result instanceof Promise) { if (this.global.mode === "sync") await_invalid(); child.promise = child.global.track( /** @type {Promise} */ result.then((transformed) => { set_ssr_context(parent_context); child.#out.push(Renderer.#serialize_failed_boundary(transformed)); failed_snippet(child, transformed, noop); child.#out.push(BLOCK_CLOSE); }) ); child.promise.catch(noop); } else { child.#out.push(Renderer.#serialize_failed_boundary(result)); failed_snippet(child, result, noop); child.#out.push(BLOCK_CLOSE); } } } /** * Create a component renderer. The component renderer inherits the state from the parent, * but has its own content. It is treated as an ordering boundary for ondestroy callbacks. * @param {(renderer: Renderer) => MaybePromise} fn * @param {Function} [component_fn] * @returns {void} */ component(fn, component_fn) { push(component_fn); this.child((renderer) => { renderer.#is_component_body = true; return fn(renderer); }); pop(); } /** * @param {Record} attrs * @param {(renderer: Renderer) => void} fn * @param {string | undefined} [css_hash] * @param {Record | undefined} [classes] * @param {Record | undefined} [styles] * @param {number | undefined} [flags] * @param {boolean | undefined} [is_rich] * @returns {void} */ select(attrs, fn, css_hash, classes, styles, flags, is_rich) { const { value, defaultValue, ...select_attrs } = attrs; if (select_attrs.multiple === "") select_attrs.multiple = true; this.push(``); this.child((renderer) => { renderer.local.select_value = value === void 0 ? defaultValue : value; renderer.local.multiple = !!select_attrs.multiple; fn(renderer); }); this.push(`${is_rich ? "" : ""}`); } /** * @param {Record} attrs * @param {string | number | boolean | ((renderer: Renderer) => void)} body * @param {string | undefined} [css_hash] * @param {Record | undefined} [classes] * @param {Record | undefined} [styles] * @param {number | undefined} [flags] * @param {boolean | undefined} [is_rich] */ option(attrs, body, css_hash, classes, styles, flags, is_rich) { this.#out.push(` { if (has_own_property.call(attrs, "value")) value = attrs.value; var select_value = this.local.select_value; if (this.local.multiple && is_array(select_value) ? select_value.includes(value) : value === select_value) renderer.#out.push(" selected=\"\""); renderer.#out.push(`>${body}${is_rich ? "" : ""}`); if (head) renderer.head((child) => child.push(head)); }; if (typeof body === "function") this.child((renderer) => { const r = new Renderer(this.global, this); body(r); if (this.global.mode === "async") return r.#collect_content_async().then((content) => { close(renderer, content.body.replaceAll("", ""), content); }); else { const content = r.#collect_content(); close(renderer, content.body.replaceAll("", ""), content); } }); else close(this, body, { body: escape_html(body) }); } /** * @param {(renderer: Renderer) => void} fn */ title(fn) { const path = this.get_path(); /** @param {string} head */ const close = (head) => { this.global.set_title(head, path); }; this.child((renderer) => { const r = new Renderer(renderer.global, renderer); fn(r); if (renderer.global.mode === "async") return r.#collect_content_async().then((content) => { close(content.head); }); else { const content = r.#collect_content(); close(content.head); } }); } /** * @param {string | (() => Promise)} content */ push(content) { if (typeof content === "function") this.child(async (renderer) => renderer.push(await content())); else this.#out.push(content); } /** * @param {() => void} fn */ on_destroy(fn) { (this.#on_destroy ??= []).push(fn); } /** * @returns {number[]} */ get_path() { return this.#parent ? [...this.#parent.get_path(), this.#parent.#out.indexOf(this)] : []; } /** * @deprecated this is needed for legacy component bindings */ copy() { const copy = new Renderer(this.global, this.#parent); copy.type = this.type; copy.#out = this.#out.map((item) => item instanceof Renderer ? item.copy() : item); copy.promise = this.promise; return copy; } /** * @param {Renderer} other * @deprecated this is needed for legacy component bindings */ subsume(other) { if (this.global.mode !== other.global.mode) throw new Error("invariant: A renderer cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"); this.local = other.local; this.#out = other.#out.map((item, i) => { const current = this.#out[i]; if (current instanceof Renderer && item instanceof Renderer) { current.subsume(item); return current; } return item; }); this.promise = other.promise; this.type = other.type; } get length() { return this.#out.length; } /** * Creates the hydration comment that marks the start of a failed boundary. * The error is JSON-serialized and embedded inside an HTML comment for the client * to parse during hydration. The JSON is escaped to prevent `-->` or ``; } /** * Only available on the server and when compiling with the `server` option. * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app. * @template {Record} Props * @param {Component} component * @param {{ props?: Omit; context?: Map; idPrefix?: string; csp?: Csp }} [options] * @returns {RenderOutput} */ static render(component, options = {}) { return new RenderResult(() => Renderer.#render(component, options), () => init_render_context().then(() => with_render_context(() => Renderer.#render_async(component, options)))); } /** * Collect all of the `onDestroy` callbacks registered during rendering. In an async context, this is only safe to call * after awaiting `collect_async`. * * Child renderers are "porous" and don't affect execution order, but component body renderers * create ordering boundaries. Within a renderer, callbacks run in order until hitting a component boundary. * @returns {Iterable<() => void>} */ *#collect_on_destroy() { for (const component of this.#traverse_components()) yield* component.#collect_ondestroy(); } /** * Performs a depth-first search of renderers, yielding the deepest components first, then additional components as we backtrack up the tree. * @returns {Iterable} */ *#traverse_components() { for (const child of this.#out) if (typeof child !== "string") yield* child.#traverse_components(); if (this.#is_component_body) yield this; } /** * @returns {Iterable<() => void>} */ *#collect_ondestroy() { if (this.#on_destroy) for (const fn of this.#on_destroy) yield fn; for (const child of this.#out) if (child instanceof Renderer && !child.#is_component_body) yield* child.#collect_ondestroy(); } /** * Runs every `onDestroy` callback in this renderer tree. On a failed render, * cleanup errors are suppressed so they do not mask the render error. * @param {boolean} suppress_errors */ #run_on_destroy(suppress_errors) { let first_error; let has_error = false; for (const cleanup of this.#collect_on_destroy()) try { cleanup(); } catch (error) { if (!suppress_errors && !has_error) { first_error = error; has_error = true; } } if (has_error) throw first_error; } /** * @param {'sync' | 'async'} mode * @param {{ idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} options * @returns {Renderer} */ static #create(mode, options) { if (options.idPrefix?.includes("--")) invalid_id_prefix(); return new Renderer(new SSRState(mode, options.idPrefix ? options.idPrefix + "-" : "", options.csp, options.transformError)); } /** * Render a component. Throws if any of the children are performing asynchronous work. * * @template {Record} Props * @param {Component} component * @param {{ props?: Omit; context?: Map; idPrefix?: string }} options * @returns {AccumulatedContent} */ static #render(component, options) { var previous_context = ssr_context; const renderer = Renderer.#create("sync", options); /** @type {AccumulatedContent | undefined} */ let result; let render_error; let failed = false; try { try { Renderer.#open_render(renderer, component, options); result = Renderer.#close_render(renderer.#collect_content(), renderer); } catch (error) { render_error = error; failed = true; } renderer.#run_on_destroy(failed); if (failed) throw render_error; return result; } finally { renderer.global.abort(); set_ssr_context(previous_context); } } /** * Render a component. * * @template {Record} Props * @param {Component} component * @param {{ props?: Omit; context?: Map; idPrefix?: string; csp?: Csp }} options * @returns {Promise} */ static async #render_async(component, options) { const previous_context = ssr_context; const renderer = Renderer.#create("async", options); /** @type {(AccumulatedContent & { hashes: { script: Sha256Source[] } }) | undefined} */ let result; let render_error; let failed = false; try { try { Renderer.#open_render(renderer, component, options); const content = await renderer.#collect_content_async(); const hydratables = await renderer.#collect_hydratables(); if (hydratables !== null) content.head = hydratables + content.head; result = Renderer.#close_render(content, renderer); } catch (error) { render_error = error; failed = true; renderer.global.abort(); await renderer.global.settle(); } renderer.#run_on_destroy(failed); if (failed) throw render_error; return result; } finally { set_ssr_context(previous_context); renderer.global.abort(); } } /** * Collect all of the code from the `out` array and return it as a string, or a promise resolving to a string. * @param {AccumulatedContent} content * @returns {AccumulatedContent} */ #collect_content(content = { head: "", body: "" }) { for (const item of this.#out) if (typeof item === "string") content[this.type] += item; else if (item instanceof Renderer) item.#collect_content(content); return content; } /** * Collect all of the code from the `out` array and return it as a string. * @param {AccumulatedContent} content * @returns {Promise} */ async #collect_content_async(content = { head: "", body: "" }) { await this.promise; for (const item of this.#out) if (typeof item === "string") content[this.type] += item; else if (item instanceof Renderer) { if (item.#boundary) { /** @type {AccumulatedContent} */ const boundary_content = { head: "", body: "" }; try { await item.#collect_content_async(boundary_content); content.head += boundary_content.head; content.body += boundary_content.body; } catch (error) { const { context, failed, transformError } = item.#boundary; set_ssr_context(context); let promise = transformError(error); set_ssr_context(null); let transformed = await promise; set_ssr_context(context); const failed_renderer = new Renderer(item.global, item); failed_renderer.type = item.type; failed_renderer.#out.push(Renderer.#serialize_failed_boundary(transformed)); failed(failed_renderer, transformed, noop); failed_renderer.#out.push(BLOCK_CLOSE); await failed_renderer.#collect_content_async(content); } } else await item.#collect_content_async(content); } return content; } async #collect_hydratables() { const ctx = get_render_context().hydratable; for (const [_, key] of ctx.unresolved_promises) unresolved_hydratable(key, ctx.lookup.get(key)?.stack ?? ""); for (const comparison of ctx.comparisons) await comparison; return await this.#hydratable_block(ctx); } /** * @template {Record} Props * @param {Renderer} renderer * @param {import('svelte').Component} component * @param {{ props?: Omit; context?: Map; idPrefix?: string; csp?: Csp; transformError?: (error: unknown) => unknown }} options * @returns {void} */ static #open_render(renderer, component, options) { var previous_context = ssr_context; try { set_ssr_context({ p: null, c: options.context ?? null, r: renderer, i: false }); renderer.push(BLOCK_OPEN); component(renderer, options.props ?? {}); renderer.push(BLOCK_CLOSE); } finally { set_ssr_context(previous_context); } } /** * @param {AccumulatedContent} content * @param {Renderer} renderer * @returns {AccumulatedContent & { hashes: { script: Sha256Source[] } }} */ static #close_render(content, renderer) { let head = content.head + renderer.global.get_title(); let body = content.body; for (const { hash, code } of renderer.global.css) head += ``; return { head, body, hashes: { script: renderer.global.csp.script_hashes } }; } /** * @param {HydratableContext} ctx */ async #hydratable_block(ctx) { if (ctx.lookup.size === 0) return null; let entries = []; let has_promises = false; for (const [k, v] of ctx.lookup) { if (v.promises) { has_promises = true; for (const p of v.promises) await p; } entries.push(`[${uneval(k)},${v.serialized}]`); } let prelude = `const h = (window.__svelte ??= {}).h ??= new Map();`; if (has_promises) prelude = `const r = (v) => Promise.resolve(v); ${prelude}`; const body = ` { ${prelude} for (const [k, v] of [ ${entries.join(",\n ")} ]) { h.set(k, v); } } `; let csp_attr = ""; if (this.global.csp.nonce) csp_attr = ` nonce="${this.global.csp.nonce}"`; else if (this.global.csp.hash) { const hash = await sha256(body); this.global.csp.script_hashes.push(`sha256-${hash}`); } return `\n\t\t${body}<\/script>`; } }; var SSRState = class { /** @readonly @type {Csp & { script_hashes: Sha256Source[] }} */ csp; /** @readonly @type {'sync' | 'async'} */ mode; /** @readonly @type {() => string} */ uid; /** @readonly @type {Set<{ hash: string; code: string }>} */ css = /* @__PURE__ */ new Set(); /** @type {Set>} */ #pending = /* @__PURE__ */ new Set(); /** @type {AbortController | null} */ #controller = null; #aborted = false; /** * `transformError` passed to `render`. Called when an error boundary catches an error. * Throws by default if unset in `render`. * @type {(error: unknown) => unknown} */ transformError; /** @type {{ path: number[], value: string }} */ #title = { path: [], value: "" }; /** * @param {'sync' | 'async'} mode * @param {string} id_prefix * @param {Csp} csp * @param {((error: unknown) => unknown) | undefined} [transformError] */ constructor(mode, id_prefix = "", csp = { hash: false }, transformError) { this.mode = mode; this.csp = { ...csp, script_hashes: [] }; this.transformError = transformError ?? ((error) => { throw error; }); let uid = 1; this.uid = () => `${id_prefix}s${uid++}`; } /** * @template T * @param {Promise} promise * @returns {Promise} */ track(promise) { this.#pending.add(promise); promise.then(() => this.#pending.delete(promise), () => this.#pending.delete(promise)); return promise; } async settle() { while (this.#pending.size > 0) await Promise.allSettled([...this.#pending]); } abort() { if (this.#aborted) return; this.#aborted = true; this.#controller?.abort(STALE_REACTION); } get_abort_signal() { const controller = this.#controller ??= new AbortController(); if (this.#aborted) controller.abort(STALE_REACTION); return controller.signal; } get_title() { return this.#title.value; } /** * Performs a depth-first (lexicographic) comparison using the path. Rejects sets * from earlier than or equal to the current value. * @param {string} value * @param {number[]} path */ set_title(value, path) { const current = this.#title.path; let i = 0; let l = Math.min(path.length, current.length); while (i < l && path[i] === current[i]) i += 1; if (path[i] === void 0) return; if (current[i] === void 0 || path[i] > current[i]) { this.#title.path = path; this.#title.value = value; } } }; // node_modules/svelte/src/internal/server/dev.js /** @import { SSRContext } from '#server' */ /** * @typedef {{ * tag: string; * parent: undefined | Element; * filename: undefined | string; * line: number; * column: number; * }} Element */ /** * This is exported so that it can be cleared between tests * @type {Set} */ var seen; /** * @param {Renderer} renderer * @param {string} message */ function print_error(renderer, message) { message = `node_invalid_placement_ssr: ${message}\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a \`hydration_mismatch\` warning.`; if ((seen ??= /* @__PURE__ */ new Set()).has(message)) return; seen.add(message); console.error(message); renderer.head((r) => r.push(`