- Delete old Vite+Svelte frontend - Initialize new SvelteKit project with TypeScript - Configure Tailwind CSS v4 + DaisyUI - Implement JWT authentication with auto-refresh - Create login page with form validation (Zod) - Add protected route guards - Update Docker configuration for single-stage build - Add E2E tests with Playwright (6/11 passing) - Fix Svelte 5 reactivity with $state() runes Known issues: - 5 E2E tests failing (timing/async issues) - Token refresh implementation needs debugging - Validation error display timing
4587 lines
127 KiB
JavaScript
4587 lines
127 KiB
JavaScript
const browser = false;
|
||
|
||
// 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
|
||
});
|
||
|
||
/**
|
||
* @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;
|
||
}
|
||
}
|
||
}
|
||
|
||
/** @type {Record<string, string>} */
|
||
const escaped = {
|
||
'<': '\\u003C',
|
||
'\\': '\\\\',
|
||
'\b': '\\b',
|
||
'\f': '\\f',
|
||
'\n': '\\n',
|
||
'\r': '\\r',
|
||
'\t': '\\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;
|
||
}
|
||
}
|
||
|
||
/** @param {any} thing */
|
||
function is_primitive(thing) {
|
||
return Object(thing) !== thing;
|
||
}
|
||
|
||
const 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 {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 '\t':
|
||
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<string | symbol, any>} object */
|
||
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]*$/;
|
||
|
||
/** @param {string} key */
|
||
function stringify_key(key) {
|
||
return is_identifier.test(key) ? '.' + key : '[' + JSON.stringify(key) + ']';
|
||
}
|
||
|
||
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)$/;
|
||
|
||
/**
|
||
* 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 = new Map();
|
||
|
||
/** @type {string[]} */
|
||
const keys = [];
|
||
|
||
const custom = new Map();
|
||
|
||
/** @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);
|
||
}
|
||
|
||
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':
|
||
/** @type {any[]} */ (thing).forEach((value, i) => {
|
||
keys.push(`[${i}]`);
|
||
walk(value);
|
||
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_primitive(key) : '...'})`
|
||
);
|
||
walk(value);
|
||
keys.pop();
|
||
}
|
||
break;
|
||
|
||
case 'Int8Array':
|
||
case 'Uint8Array':
|
||
case 'Uint8ClampedArray':
|
||
case 'Int16Array':
|
||
case 'Uint16Array':
|
||
case 'Int32Array':
|
||
case 'Uint32Array':
|
||
case 'Float32Array':
|
||
case 'Float64Array':
|
||
case 'BigInt64Array':
|
||
case 'BigUint64Array':
|
||
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 in thing) {
|
||
keys.push(stringify_key(key));
|
||
walk(thing[key]);
|
||
keys.pop();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
walk(value);
|
||
|
||
const names = 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));
|
||
});
|
||
|
||
/**
|
||
* @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':
|
||
return `Object(${stringify(thing.valueOf())})`;
|
||
|
||
case 'RegExp':
|
||
return `new RegExp(${stringify_string(thing.source)}, "${
|
||
thing.flags
|
||
}")`;
|
||
|
||
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':
|
||
const members = /** @type {any[]} */ (thing).map((v, i) =>
|
||
i in thing ? stringify(v) : ''
|
||
);
|
||
const tail = thing.length === 0 || thing.length - 1 in thing ? '' : ',';
|
||
return `[${members.join(',')}${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 'Int32Array':
|
||
case 'Uint32Array':
|
||
case 'Float32Array':
|
||
case 'Float64Array':
|
||
case 'BigInt64Array':
|
||
case 'BigUint64Array': {
|
||
let str = `new ${type}`;
|
||
|
||
if (counts.get(thing.buffer) === 1) {
|
||
const array = new thing.constructor(thing.buffer);
|
||
str += `([${array}])`;
|
||
} else {
|
||
str += `([${stringify(thing.buffer)}])`;
|
||
}
|
||
|
||
const a = thing.byteOffset;
|
||
const b = a + thing.byteLength;
|
||
|
||
// handle subarrays
|
||
if (a > 0 || b !== thing.buffer.byteLength) {
|
||
const m = +/(\d+)/.exec(type)[1] / 8;
|
||
str += `.subarray(${a / m},${b / m})`;
|
||
}
|
||
|
||
return str;
|
||
}
|
||
|
||
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 keys = Object.keys(thing);
|
||
const obj = keys
|
||
.map((key) => `${safe_key(key)}:${stringify(thing[key])}`)
|
||
.join(',');
|
||
const proto = Object.getPrototypeOf(thing);
|
||
if (proto === 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 = [];
|
||
|
||
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':
|
||
values.push(`Object(${stringify(thing.valueOf())})`);
|
||
break;
|
||
|
||
case 'RegExp':
|
||
values.push(thing.toString());
|
||
break;
|
||
|
||
case 'Date':
|
||
values.push(`new Date(${thing.getTime()})`);
|
||
break;
|
||
|
||
case 'Array':
|
||
values.push(`Array(${thing.length})`);
|
||
/** @type {any[]} */ (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 'ArrayBuffer':
|
||
values.push(
|
||
`new Uint8Array([${new Uint8Array(thing).join(',')}]).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;
|
||
}
|
||
}
|
||
|
||
/** @param {number} num */
|
||
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;
|
||
}
|
||
|
||
/** @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) {
|
||
if (typeof thing === '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 (typeof thing === 'number') return str.replace(/^(-)?0\./, '$1.');
|
||
if (typeof thing === 'bigint') return thing + 'n';
|
||
return str;
|
||
}
|
||
|
||
const text_encoder$1 = new TextEncoder();
|
||
const text_decoder = new TextDecoder();
|
||
function get_relative_path(from, to) {
|
||
const from_parts = from.split(/[/\\]/);
|
||
const to_parts = to.split(/[/\\]/);
|
||
from_parts.pop();
|
||
while (from_parts[0] === to_parts[0]) {
|
||
from_parts.shift();
|
||
to_parts.shift();
|
||
}
|
||
let i = from_parts.length;
|
||
while (i--) from_parts[i] = "..";
|
||
return from_parts.concat(to_parts).join("/");
|
||
}
|
||
function base64_encode$1(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);
|
||
}
|
||
function base64_decode(encoded) {
|
||
if (globalThis.Buffer) {
|
||
const buffer = globalThis.Buffer.from(encoded, "base64");
|
||
return new Uint8Array(buffer);
|
||
}
|
||
const binary = atob(encoded);
|
||
const bytes = new Uint8Array(binary.length);
|
||
for (let i = 0; i < binary.length; i++) {
|
||
bytes[i] = binary.charCodeAt(i);
|
||
}
|
||
return bytes;
|
||
}
|
||
|
||
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}
|
||
|
||
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;
|
||
const noop = () => {
|
||
};
|
||
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 };
|
||
}
|
||
function fallback(value, fallback2, lazy = false) {
|
||
return value === void 0 ? lazy ? (
|
||
/** @type {() => V} */
|
||
fallback2()
|
||
) : (
|
||
/** @type {V} */
|
||
fallback2
|
||
) : value;
|
||
}
|
||
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);
|
||
}
|
||
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 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 = Symbol("$state");
|
||
const LEGACY_PROPS = Symbol("legacy props");
|
||
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;
|
||
function lifecycle_outside_component(name) {
|
||
{
|
||
throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
|
||
}
|
||
}
|
||
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`);
|
||
}
|
||
}
|
||
const HYDRATION_START = "[";
|
||
const HYDRATION_START_ELSE = "[!";
|
||
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 = Symbol();
|
||
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;
|
||
}
|
||
}
|
||
let tracing_mode_flag = false;
|
||
let component_context = null;
|
||
function set_component_context(context) {
|
||
component_context = context;
|
||
}
|
||
function push$1(props, runes = false, fn) {
|
||
component_context = {
|
||
p: component_context,
|
||
i: false,
|
||
c: null,
|
||
e: null,
|
||
s: props,
|
||
x: null,
|
||
l: null
|
||
};
|
||
}
|
||
function pop$1(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(derived) {
|
||
if ((derived.f & CONNECTED) !== 0 || derived.deps === null) {
|
||
set_signal_status(derived, CLEAN);
|
||
} else {
|
||
set_signal_status(derived, 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);
|
||
}
|
||
const batches = /* @__PURE__ */ new Set();
|
||
let current_batch = null;
|
||
let batch_values = null;
|
||
let queued_root_effects = [];
|
||
let last_scheduled_effect = null;
|
||
let is_flushing = false;
|
||
let is_flushing_sync = false;
|
||
class Batch {
|
||
committed = false;
|
||
/**
|
||
* The current values of any sources that are updated in this batch
|
||
* They keys of this map are identical to `this.#previous`
|
||
* @type {Map<Source, any>}
|
||
*/
|
||
current = /* @__PURE__ */ new Map();
|
||
/**
|
||
* The values of any sources that are updated in this batch _before_ those updates took place.
|
||
* They keys of this map are identical to `this.#current`
|
||
* @type {Map<Source, any>}
|
||
*/
|
||
previous = /* @__PURE__ */ new Map();
|
||
/**
|
||
* 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<() => 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();
|
||
/**
|
||
* The number of async effects that are currently in flight
|
||
*/
|
||
#pending = 0;
|
||
/**
|
||
* The number of async effects that are currently in flight, _not_ inside a pending boundary
|
||
*/
|
||
#blocking_pending = 0;
|
||
/**
|
||
* 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;
|
||
/**
|
||
* 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();
|
||
is_fork = false;
|
||
#decrement_queued = false;
|
||
is_deferred() {
|
||
return this.is_fork || this.#blocking_pending > 0;
|
||
}
|
||
/**
|
||
* 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: [] });
|
||
}
|
||
}
|
||
/**
|
||
* Remove an effect from the #skipped_branches map and reschedule
|
||
* any tracked dirty/maybe_dirty child effects
|
||
* @param {Effect} effect
|
||
*/
|
||
unskip_effect(effect) {
|
||
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);
|
||
schedule_effect(e);
|
||
}
|
||
for (e of tracked.m) {
|
||
set_signal_status(e, MAYBE_DIRTY);
|
||
schedule_effect(e);
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
*
|
||
* @param {Effect[]} root_effects
|
||
*/
|
||
process(root_effects) {
|
||
queued_root_effects = [];
|
||
this.apply();
|
||
var effects = [];
|
||
var render_effects = [];
|
||
for (const root2 of root_effects) {
|
||
this.#traverse_effect_tree(root2, effects, render_effects);
|
||
}
|
||
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);
|
||
}
|
||
} else {
|
||
for (const fn of this.#commit_callbacks) fn();
|
||
this.#commit_callbacks.clear();
|
||
if (this.#pending === 0) {
|
||
this.#commit();
|
||
}
|
||
current_batch = null;
|
||
flush_queued_effects(render_effects);
|
||
flush_queued_effects(effects);
|
||
this.#deferred?.resolve();
|
||
}
|
||
batch_values = null;
|
||
}
|
||
/**
|
||
* 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_effect_tree(root2, effects, render_effects) {
|
||
root2.f ^= CLEAN;
|
||
var effect = root2.first;
|
||
var pending_boundary = null;
|
||
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 (pending_boundary !== null && (flags2 & (EFFECT | RENDER_EFFECT | MANAGED_EFFECT)) !== 0) {
|
||
pending_boundary.b.defer_effect(effect);
|
||
} else if ((flags2 & EFFECT) !== 0) {
|
||
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) {
|
||
if (effect === pending_boundary) {
|
||
pending_boundary = null;
|
||
}
|
||
var next2 = effect.next;
|
||
if (next2 !== null) {
|
||
effect = next2;
|
||
break;
|
||
}
|
||
effect = effect.parent;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* @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 {Source} source
|
||
* @param {any} value
|
||
*/
|
||
capture(source2, value) {
|
||
if (value !== UNINITIALIZED && !this.previous.has(source2)) {
|
||
this.previous.set(source2, value);
|
||
}
|
||
if ((source2.f & ERROR_VALUE) === 0) {
|
||
this.current.set(source2, source2.v);
|
||
batch_values?.set(source2, source2.v);
|
||
}
|
||
}
|
||
activate() {
|
||
current_batch = this;
|
||
this.apply();
|
||
}
|
||
deactivate() {
|
||
if (current_batch !== this) return;
|
||
current_batch = null;
|
||
batch_values = null;
|
||
}
|
||
flush() {
|
||
this.activate();
|
||
if (queued_root_effects.length > 0) {
|
||
flush_effects();
|
||
if (current_batch !== null && current_batch !== this) {
|
||
return;
|
||
}
|
||
} else if (this.#pending === 0) {
|
||
this.process([]);
|
||
}
|
||
this.deactivate();
|
||
}
|
||
discard() {
|
||
for (const fn of this.#discard_callbacks) fn(this);
|
||
this.#discard_callbacks.clear();
|
||
}
|
||
#commit() {
|
||
if (batches.size > 1) {
|
||
this.previous.clear();
|
||
var previous_batch_values = batch_values;
|
||
var is_earlier = true;
|
||
for (const batch of batches) {
|
||
if (batch === this) {
|
||
is_earlier = false;
|
||
continue;
|
||
}
|
||
const sources = [];
|
||
for (const [source2, value] of this.current) {
|
||
if (batch.current.has(source2)) {
|
||
if (is_earlier && value !== batch.current.get(source2)) {
|
||
batch.current.set(source2, value);
|
||
} else {
|
||
continue;
|
||
}
|
||
}
|
||
sources.push(source2);
|
||
}
|
||
if (sources.length === 0) {
|
||
continue;
|
||
}
|
||
const others = [...batch.current.keys()].filter((s) => !this.current.has(s));
|
||
if (others.length > 0) {
|
||
var prev_queued_root_effects = queued_root_effects;
|
||
queued_root_effects = [];
|
||
const marked = /* @__PURE__ */ new Set();
|
||
const checked = /* @__PURE__ */ new Map();
|
||
for (const source2 of sources) {
|
||
mark_effects(source2, others, marked, checked);
|
||
}
|
||
if (queued_root_effects.length > 0) {
|
||
current_batch = batch;
|
||
batch.apply();
|
||
for (const root2 of queued_root_effects) {
|
||
batch.#traverse_effect_tree(root2, [], []);
|
||
}
|
||
batch.deactivate();
|
||
}
|
||
queued_root_effects = prev_queued_root_effects;
|
||
}
|
||
}
|
||
current_batch = null;
|
||
batch_values = previous_batch_values;
|
||
}
|
||
this.committed = true;
|
||
batches.delete(this);
|
||
}
|
||
/**
|
||
*
|
||
* @param {boolean} blocking
|
||
*/
|
||
increment(blocking) {
|
||
this.#pending += 1;
|
||
if (blocking) this.#blocking_pending += 1;
|
||
}
|
||
/**
|
||
*
|
||
* @param {boolean} blocking
|
||
*/
|
||
decrement(blocking) {
|
||
this.#pending -= 1;
|
||
if (blocking) this.#blocking_pending -= 1;
|
||
if (this.#decrement_queued) return;
|
||
this.#decrement_queued = true;
|
||
queue_micro_task(() => {
|
||
this.#decrement_queued = false;
|
||
if (!this.is_deferred()) {
|
||
this.revive();
|
||
} else if (queued_root_effects.length > 0) {
|
||
this.flush();
|
||
}
|
||
});
|
||
}
|
||
revive() {
|
||
for (const e of this.#dirty_effects) {
|
||
this.#maybe_dirty_effects.delete(e);
|
||
set_signal_status(e, DIRTY);
|
||
schedule_effect(e);
|
||
}
|
||
for (const e of this.#maybe_dirty_effects) {
|
||
set_signal_status(e, MAYBE_DIRTY);
|
||
schedule_effect(e);
|
||
}
|
||
this.flush();
|
||
}
|
||
/** @param {() => void} fn */
|
||
oncommit(fn) {
|
||
this.#commit_callbacks.add(fn);
|
||
}
|
||
/** @param {(batch: Batch) => void} fn */
|
||
ondiscard(fn) {
|
||
this.#discard_callbacks.add(fn);
|
||
}
|
||
settled() {
|
||
return (this.#deferred ??= deferred()).promise;
|
||
}
|
||
static ensure() {
|
||
if (current_batch === null) {
|
||
const batch = current_batch = new Batch();
|
||
batches.add(current_batch);
|
||
if (!is_flushing_sync) {
|
||
queue_micro_task(() => {
|
||
if (current_batch !== batch) {
|
||
return;
|
||
}
|
||
batch.flush();
|
||
});
|
||
}
|
||
}
|
||
return current_batch;
|
||
}
|
||
apply() {
|
||
return;
|
||
}
|
||
}
|
||
function flushSync(fn) {
|
||
var was_flushing_sync = is_flushing_sync;
|
||
is_flushing_sync = true;
|
||
try {
|
||
var result;
|
||
if (fn) ;
|
||
while (true) {
|
||
flush_tasks();
|
||
if (queued_root_effects.length === 0) {
|
||
current_batch?.flush();
|
||
if (queued_root_effects.length === 0) {
|
||
last_scheduled_effect = null;
|
||
return (
|
||
/** @type {T} */
|
||
result
|
||
);
|
||
}
|
||
}
|
||
flush_effects();
|
||
}
|
||
} finally {
|
||
is_flushing_sync = was_flushing_sync;
|
||
}
|
||
}
|
||
function flush_effects() {
|
||
is_flushing = true;
|
||
try {
|
||
var flush_count = 0;
|
||
while (queued_root_effects.length > 0) {
|
||
var batch = Batch.ensure();
|
||
if (flush_count++ > 1e3) {
|
||
var updates, entry;
|
||
if (browser) ;
|
||
infinite_loop_guard();
|
||
}
|
||
batch.process(queued_root_effects);
|
||
old_values.clear();
|
||
if (browser) ;
|
||
}
|
||
} finally {
|
||
queued_root_effects = [];
|
||
is_flushing = false;
|
||
last_scheduled_effect = null;
|
||
}
|
||
}
|
||
function infinite_loop_guard() {
|
||
try {
|
||
effect_update_depth_exceeded();
|
||
} catch (error) {
|
||
invoke_error_boundary(error, last_scheduled_effect);
|
||
}
|
||
}
|
||
let eager_block_effects = null;
|
||
function flush_queued_effects(effects) {
|
||
var length = effects.length;
|
||
if (length === 0) return;
|
||
var i = 0;
|
||
while (i < length) {
|
||
var effect = effects[i++];
|
||
if ((effect.f & (DESTROYED | INERT)) === 0 && is_dirty(effect)) {
|
||
eager_block_effects = /* @__PURE__ */ new Set();
|
||
update_effect(effect);
|
||
if (effect.deps === null && effect.first === null && effect.nodes === null && effect.teardown === null && effect.ac === null) {
|
||
unlink_effect(effect);
|
||
}
|
||
if (eager_block_effects?.size > 0) {
|
||
old_values.clear();
|
||
for (const e of eager_block_effects) {
|
||
if ((e.f & (DESTROYED | INERT)) !== 0) continue;
|
||
const ordered_effects = [e];
|
||
let ancestor = e.parent;
|
||
while (ancestor !== null) {
|
||
if (eager_block_effects.has(ancestor)) {
|
||
eager_block_effects.delete(ancestor);
|
||
ordered_effects.push(ancestor);
|
||
}
|
||
ancestor = ancestor.parent;
|
||
}
|
||
for (let j = ordered_effects.length - 1; j >= 0; j--) {
|
||
const e2 = ordered_effects[j];
|
||
if ((e2.f & (DESTROYED | INERT)) !== 0) continue;
|
||
update_effect(e2);
|
||
}
|
||
}
|
||
eager_block_effects.clear();
|
||
}
|
||
}
|
||
}
|
||
eager_block_effects = null;
|
||
}
|
||
function mark_effects(value, sources, marked, checked) {
|
||
if (marked.has(value)) return;
|
||
marked.add(value);
|
||
if (value.reactions !== null) {
|
||
for (const reaction of value.reactions) {
|
||
const flags2 = reaction.f;
|
||
if ((flags2 & DERIVED) !== 0) {
|
||
mark_effects(
|
||
/** @type {Derived} */
|
||
reaction,
|
||
sources,
|
||
marked,
|
||
checked
|
||
);
|
||
} else if ((flags2 & (ASYNC | BLOCK_EFFECT)) !== 0 && (flags2 & DIRTY) === 0 && depends_on(reaction, sources, checked)) {
|
||
set_signal_status(reaction, DIRTY);
|
||
schedule_effect(
|
||
/** @type {Effect} */
|
||
reaction
|
||
);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function depends_on(reaction, sources, checked) {
|
||
const depends = checked.get(reaction);
|
||
if (depends !== void 0) return depends;
|
||
if (reaction.deps !== null) {
|
||
for (const dep of reaction.deps) {
|
||
if (includes.call(sources, dep)) {
|
||
return true;
|
||
}
|
||
if ((dep.f & DERIVED) !== 0 && depends_on(
|
||
/** @type {Derived} */
|
||
dep,
|
||
sources,
|
||
checked
|
||
)) {
|
||
checked.set(
|
||
/** @type {Derived} */
|
||
dep,
|
||
true
|
||
);
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
checked.set(reaction, false);
|
||
return false;
|
||
}
|
||
function schedule_effect(signal) {
|
||
var effect = last_scheduled_effect = signal;
|
||
while (effect.parent !== null) {
|
||
effect = effect.parent;
|
||
var flags2 = effect.f;
|
||
if (is_flushing && effect === active_effect && (flags2 & BLOCK_EFFECT) !== 0 && (flags2 & HEAD_EFFECT) === 0) {
|
||
return;
|
||
}
|
||
if ((flags2 & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
|
||
if ((flags2 & CLEAN) === 0) return;
|
||
effect.f ^= CLEAN;
|
||
}
|
||
}
|
||
queued_root_effects.push(effect);
|
||
}
|
||
function reset_branch(effect, tracked) {
|
||
if ((effect.f & BRANCH_EFFECT) !== 0 && (effect.f & CLEAN) !== 0) {
|
||
return;
|
||
}
|
||
if ((effect.f & DIRTY) !== 0) {
|
||
tracked.d.push(effect);
|
||
} else if ((effect.f & MAYBE_DIRTY) !== 0) {
|
||
tracked.m.push(effect);
|
||
}
|
||
set_signal_status(effect, CLEAN);
|
||
var e = effect.first;
|
||
while (e !== null) {
|
||
reset_branch(e, tracked);
|
||
e = e.next;
|
||
}
|
||
}
|
||
function createSubscriber(start) {
|
||
let subscribers = 0;
|
||
let version = source(0);
|
||
let stop;
|
||
return () => {
|
||
if (effect_tracking()) {
|
||
get(version);
|
||
render_effect(() => {
|
||
if (subscribers === 0) {
|
||
stop = untrack(() => start(() => increment(version)));
|
||
}
|
||
subscribers += 1;
|
||
return () => {
|
||
queue_micro_task(() => {
|
||
subscribers -= 1;
|
||
if (subscribers === 0) {
|
||
stop?.();
|
||
stop = void 0;
|
||
increment(version);
|
||
}
|
||
});
|
||
};
|
||
});
|
||
}
|
||
};
|
||
}
|
||
var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
|
||
function boundary(node, props, children) {
|
||
new Boundary(node, props, children);
|
||
}
|
||
class Boundary {
|
||
/** @type {Boundary | null} */
|
||
parent;
|
||
is_pending = false;
|
||
/** @type {TemplateNode} */
|
||
#anchor;
|
||
/** @type {TemplateNode | null} */
|
||
#hydrate_open = hydrating ? hydrate_node : null;
|
||
/** @type {BoundaryProps} */
|
||
#props;
|
||
/** @type {((anchor: Node) => void)} */
|
||
#children;
|
||
/** @type {Effect} */
|
||
#effect;
|
||
/** @type {Effect | null} */
|
||
#main_effect = null;
|
||
/** @type {Effect | null} */
|
||
#pending_effect = null;
|
||
/** @type {Effect | null} */
|
||
#failed_effect = null;
|
||
/** @type {DocumentFragment | null} */
|
||
#offscreen_fragment = null;
|
||
#local_pending_count = 0;
|
||
#pending_count = 0;
|
||
#pending_count_update_queued = false;
|
||
/** @type {Set<Effect>} */
|
||
#dirty_effects = /* @__PURE__ */ new Set();
|
||
/** @type {Set<Effect>} */
|
||
#maybe_dirty_effects = /* @__PURE__ */ new Set();
|
||
/**
|
||
* A source containing the number of pending async deriveds/expressions.
|
||
* Only created if `$effect.pending()` is used inside the boundary,
|
||
* otherwise updating the source results in needless `Batch.ensure()`
|
||
* calls followed by no-op flushes
|
||
* @type {Source<number> | null}
|
||
*/
|
||
#effect_pending = null;
|
||
#effect_pending_subscriber = createSubscriber(() => {
|
||
this.#effect_pending = source(this.#local_pending_count);
|
||
return () => {
|
||
this.#effect_pending = null;
|
||
};
|
||
});
|
||
/**
|
||
* @param {TemplateNode} node
|
||
* @param {BoundaryProps} props
|
||
* @param {((anchor: Node) => void)} children
|
||
*/
|
||
constructor(node, props, children) {
|
||
this.#anchor = node;
|
||
this.#props = props;
|
||
this.#children = (anchor) => {
|
||
var effect = (
|
||
/** @type {Effect} */
|
||
active_effect
|
||
);
|
||
effect.b = this;
|
||
effect.f |= BOUNDARY_EFFECT;
|
||
children(anchor);
|
||
};
|
||
this.parent = /** @type {Effect} */
|
||
active_effect.b;
|
||
this.#effect = block(() => {
|
||
if (hydrating) {
|
||
const comment = (
|
||
/** @type {Comment} */
|
||
this.#hydrate_open
|
||
);
|
||
hydrate_next();
|
||
if (comment.data === HYDRATION_START_ELSE) {
|
||
this.#hydrate_pending_content();
|
||
} else {
|
||
this.#hydrate_resolved_content();
|
||
}
|
||
} else {
|
||
this.#render();
|
||
}
|
||
}, flags);
|
||
if (hydrating) {
|
||
this.#anchor = hydrate_node;
|
||
}
|
||
}
|
||
#hydrate_resolved_content() {
|
||
try {
|
||
this.#main_effect = branch(() => this.#children(this.#anchor));
|
||
} catch (error) {
|
||
this.error(error);
|
||
}
|
||
}
|
||
#hydrate_pending_content() {
|
||
const pending = this.#props.pending;
|
||
if (!pending) return;
|
||
this.is_pending = true;
|
||
this.#pending_effect = branch(() => pending(this.#anchor));
|
||
queue_micro_task(() => {
|
||
var fragment = this.#offscreen_fragment = document.createDocumentFragment();
|
||
var anchor = create_text();
|
||
fragment.append(anchor);
|
||
this.#main_effect = this.#run(() => {
|
||
Batch.ensure();
|
||
return branch(() => this.#children(anchor));
|
||
});
|
||
if (this.#pending_count === 0) {
|
||
this.#anchor.before(fragment);
|
||
this.#offscreen_fragment = null;
|
||
pause_effect(
|
||
/** @type {Effect} */
|
||
this.#pending_effect,
|
||
() => {
|
||
this.#pending_effect = null;
|
||
}
|
||
);
|
||
this.is_pending = false;
|
||
}
|
||
});
|
||
}
|
||
#render() {
|
||
try {
|
||
this.is_pending = this.has_pending_snippet();
|
||
this.#pending_count = 0;
|
||
this.#local_pending_count = 0;
|
||
this.#main_effect = branch(() => {
|
||
this.#children(this.#anchor);
|
||
});
|
||
if (this.#pending_count > 0) {
|
||
var fragment = this.#offscreen_fragment = document.createDocumentFragment();
|
||
move_effect(this.#main_effect, fragment);
|
||
const pending = (
|
||
/** @type {(anchor: Node) => void} */
|
||
this.#props.pending
|
||
);
|
||
this.#pending_effect = branch(() => pending(this.#anchor));
|
||
} else {
|
||
this.is_pending = false;
|
||
}
|
||
} catch (error) {
|
||
this.error(error);
|
||
}
|
||
}
|
||
/**
|
||
* Defer an effect inside a pending boundary until the boundary resolves
|
||
* @param {Effect} effect
|
||
*/
|
||
defer_effect(effect) {
|
||
defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);
|
||
}
|
||
/**
|
||
* Returns `false` if the effect exists inside a boundary whose pending snippet is shown
|
||
* @returns {boolean}
|
||
*/
|
||
is_rendered() {
|
||
return !this.is_pending && (!this.parent || this.parent.is_rendered());
|
||
}
|
||
has_pending_snippet() {
|
||
return !!this.#props.pending;
|
||
}
|
||
/**
|
||
* @template T
|
||
* @param {() => T} fn
|
||
*/
|
||
#run(fn) {
|
||
var previous_effect = active_effect;
|
||
var previous_reaction = active_reaction;
|
||
var previous_ctx = component_context;
|
||
set_active_effect(this.#effect);
|
||
set_active_reaction(this.#effect);
|
||
set_component_context(this.#effect.ctx);
|
||
try {
|
||
return fn();
|
||
} catch (e) {
|
||
handle_error(e);
|
||
return null;
|
||
} finally {
|
||
set_active_effect(previous_effect);
|
||
set_active_reaction(previous_reaction);
|
||
set_component_context(previous_ctx);
|
||
}
|
||
}
|
||
/**
|
||
* Updates the pending count associated with the currently visible pending snippet,
|
||
* if any, such that we can replace the snippet with content once work is done
|
||
* @param {1 | -1} d
|
||
*/
|
||
#update_pending_count(d) {
|
||
if (!this.has_pending_snippet()) {
|
||
if (this.parent) {
|
||
this.parent.#update_pending_count(d);
|
||
}
|
||
return;
|
||
}
|
||
this.#pending_count += d;
|
||
if (this.#pending_count === 0) {
|
||
this.is_pending = false;
|
||
for (const e of this.#dirty_effects) {
|
||
set_signal_status(e, DIRTY);
|
||
schedule_effect(e);
|
||
}
|
||
for (const e of this.#maybe_dirty_effects) {
|
||
set_signal_status(e, MAYBE_DIRTY);
|
||
schedule_effect(e);
|
||
}
|
||
this.#dirty_effects.clear();
|
||
this.#maybe_dirty_effects.clear();
|
||
if (this.#pending_effect) {
|
||
pause_effect(this.#pending_effect, () => {
|
||
this.#pending_effect = null;
|
||
});
|
||
}
|
||
if (this.#offscreen_fragment) {
|
||
this.#anchor.before(this.#offscreen_fragment);
|
||
this.#offscreen_fragment = null;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Update the source that powers `$effect.pending()` inside this boundary,
|
||
* and controls when the current `pending` snippet (if any) is removed.
|
||
* Do not call from inside the class
|
||
* @param {1 | -1} d
|
||
*/
|
||
update_pending_count(d) {
|
||
this.#update_pending_count(d);
|
||
this.#local_pending_count += d;
|
||
if (!this.#effect_pending || this.#pending_count_update_queued) return;
|
||
this.#pending_count_update_queued = true;
|
||
queue_micro_task(() => {
|
||
this.#pending_count_update_queued = false;
|
||
if (this.#effect_pending) {
|
||
internal_set(this.#effect_pending, this.#local_pending_count);
|
||
}
|
||
});
|
||
}
|
||
get_effect_pending() {
|
||
this.#effect_pending_subscriber();
|
||
return get(
|
||
/** @type {Source<number>} */
|
||
this.#effect_pending
|
||
);
|
||
}
|
||
/** @param {unknown} error */
|
||
error(error) {
|
||
var onerror = this.#props.onerror;
|
||
let failed = this.#props.failed;
|
||
if (!onerror && !failed) {
|
||
throw error;
|
||
}
|
||
if (this.#main_effect) {
|
||
destroy_effect(this.#main_effect);
|
||
this.#main_effect = null;
|
||
}
|
||
if (this.#pending_effect) {
|
||
destroy_effect(this.#pending_effect);
|
||
this.#pending_effect = null;
|
||
}
|
||
if (this.#failed_effect) {
|
||
destroy_effect(this.#failed_effect);
|
||
this.#failed_effect = null;
|
||
}
|
||
if (hydrating) {
|
||
set_hydrate_node(
|
||
/** @type {TemplateNode} */
|
||
this.#hydrate_open
|
||
);
|
||
next();
|
||
set_hydrate_node(skip_nodes());
|
||
}
|
||
var did_reset = false;
|
||
var calling_on_error = false;
|
||
const reset = () => {
|
||
if (did_reset) {
|
||
svelte_boundary_reset_noop();
|
||
return;
|
||
}
|
||
did_reset = true;
|
||
if (calling_on_error) {
|
||
svelte_boundary_reset_onerror();
|
||
}
|
||
if (this.#failed_effect !== null) {
|
||
pause_effect(this.#failed_effect, () => {
|
||
this.#failed_effect = null;
|
||
});
|
||
}
|
||
this.#run(() => {
|
||
Batch.ensure();
|
||
this.#render();
|
||
});
|
||
};
|
||
queue_micro_task(() => {
|
||
try {
|
||
calling_on_error = true;
|
||
onerror?.(error, reset);
|
||
calling_on_error = false;
|
||
} catch (error2) {
|
||
invoke_error_boundary(error2, this.#effect && this.#effect.parent);
|
||
}
|
||
if (failed) {
|
||
this.#failed_effect = this.#run(() => {
|
||
Batch.ensure();
|
||
try {
|
||
return branch(() => {
|
||
var effect = (
|
||
/** @type {Effect} */
|
||
active_effect
|
||
);
|
||
effect.b = this;
|
||
effect.f |= BOUNDARY_EFFECT;
|
||
failed(
|
||
this.#anchor,
|
||
() => error,
|
||
() => reset
|
||
);
|
||
});
|
||
} catch (error2) {
|
||
invoke_error_boundary(
|
||
error2,
|
||
/** @type {Effect} */
|
||
this.#effect.parent
|
||
);
|
||
return null;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
function destroy_derived_effects(derived) {
|
||
var effects = derived.effects;
|
||
if (effects !== null) {
|
||
derived.effects = null;
|
||
for (var i = 0; i < effects.length; i += 1) {
|
||
destroy_effect(
|
||
/** @type {Effect} */
|
||
effects[i]
|
||
);
|
||
}
|
||
}
|
||
}
|
||
function get_derived_parent_effect(derived) {
|
||
var parent = derived.parent;
|
||
while (parent !== null) {
|
||
if ((parent.f & DERIVED) === 0) {
|
||
return (parent.f & DESTROYED) === 0 ? (
|
||
/** @type {Effect} */
|
||
parent
|
||
) : null;
|
||
}
|
||
parent = parent.parent;
|
||
}
|
||
return null;
|
||
}
|
||
function execute_derived(derived) {
|
||
var value;
|
||
var prev_active_effect = active_effect;
|
||
set_active_effect(get_derived_parent_effect(derived));
|
||
{
|
||
try {
|
||
derived.f &= ~WAS_MARKED;
|
||
destroy_derived_effects(derived);
|
||
value = update_reaction(derived);
|
||
} finally {
|
||
set_active_effect(prev_active_effect);
|
||
}
|
||
}
|
||
return value;
|
||
}
|
||
function update_derived(derived) {
|
||
var value = execute_derived(derived);
|
||
if (!derived.equals(value)) {
|
||
derived.wv = increment_write_version();
|
||
if (!current_batch?.is_fork || derived.deps === null) {
|
||
derived.v = value;
|
||
if (derived.deps === null) {
|
||
set_signal_status(derived, CLEAN);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
if (is_destroying_effect) {
|
||
return;
|
||
}
|
||
if (batch_values !== null) {
|
||
if (effect_tracking() || current_batch?.is_fork) {
|
||
batch_values.set(derived, value);
|
||
}
|
||
} else {
|
||
update_derived_status(derived);
|
||
}
|
||
}
|
||
function freeze_derived_effects(derived) {
|
||
if (derived.effects === null) return;
|
||
for (const e of derived.effects) {
|
||
if (e.teardown || e.ac) {
|
||
e.teardown?.();
|
||
e.ac?.abort(STALE_REACTION);
|
||
e.teardown = noop;
|
||
e.ac = null;
|
||
remove_reactions(e, 0);
|
||
destroy_effect_children(e);
|
||
}
|
||
}
|
||
}
|
||
function unfreeze_derived_effects(derived) {
|
||
if (derived.effects === null) return;
|
||
for (const e of derived.effects) {
|
||
if (e.teardown) {
|
||
update_effect(e);
|
||
}
|
||
}
|
||
}
|
||
let eager_effects = /* @__PURE__ */ new Set();
|
||
const old_values = /* @__PURE__ */ new Map();
|
||
let eager_effects_deferred = false;
|
||
function source(v, stack) {
|
||
var signal = {
|
||
f: 0,
|
||
// TODO ideally we could skip this altogether, but it causes type errors
|
||
v,
|
||
reactions: null,
|
||
equals,
|
||
rv: 0,
|
||
wv: 0
|
||
};
|
||
return signal;
|
||
}
|
||
// @__NO_SIDE_EFFECTS__
|
||
function state(v, stack) {
|
||
const s = source(v);
|
||
push_reaction_value(s);
|
||
return s;
|
||
}
|
||
// @__NO_SIDE_EFFECTS__
|
||
function mutable_source(initial_value, immutable = false, trackable = true) {
|
||
const s = source(initial_value);
|
||
if (!immutable) {
|
||
s.equals = safe_equals;
|
||
}
|
||
return s;
|
||
}
|
||
function set(source2, value, should_proxy = false) {
|
||
if (active_reaction !== null && // since we are untracking the function inside `$inspect.with` we need to add this check
|
||
// to ensure we error if state is set inside an inspect effect
|
||
(!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 && (current_sources === null || !includes.call(current_sources, source2))) {
|
||
state_unsafe_mutation();
|
||
}
|
||
let new_value = should_proxy ? proxy(value) : value;
|
||
return internal_set(source2, new_value);
|
||
}
|
||
function internal_set(source2, value) {
|
||
if (!source2.equals(value)) {
|
||
var old_value = source2.v;
|
||
if (is_destroying_effect) {
|
||
old_values.set(source2, value);
|
||
} else {
|
||
old_values.set(source2, old_value);
|
||
}
|
||
source2.v = value;
|
||
var batch = Batch.ensure();
|
||
batch.capture(source2, old_value);
|
||
if ((source2.f & DERIVED) !== 0) {
|
||
const derived = (
|
||
/** @type {Derived} */
|
||
source2
|
||
);
|
||
if ((source2.f & DIRTY) !== 0) {
|
||
execute_derived(derived);
|
||
}
|
||
update_derived_status(derived);
|
||
}
|
||
source2.wv = increment_write_version();
|
||
mark_reactions(source2, DIRTY);
|
||
if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & (BRANCH_EFFECT | ROOT_EFFECT)) === 0) {
|
||
if (untracked_writes === null) {
|
||
set_untracked_writes([source2]);
|
||
} else {
|
||
untracked_writes.push(source2);
|
||
}
|
||
}
|
||
if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
|
||
flush_eager_effects();
|
||
}
|
||
}
|
||
return value;
|
||
}
|
||
function flush_eager_effects() {
|
||
eager_effects_deferred = false;
|
||
for (const effect of eager_effects) {
|
||
if ((effect.f & CLEAN) !== 0) {
|
||
set_signal_status(effect, MAYBE_DIRTY);
|
||
}
|
||
if (is_dirty(effect)) {
|
||
update_effect(effect);
|
||
}
|
||
}
|
||
eager_effects.clear();
|
||
}
|
||
function increment(source2) {
|
||
set(source2, source2.v + 1);
|
||
}
|
||
function mark_reactions(signal, status) {
|
||
var reactions = signal.reactions;
|
||
if (reactions === null) return;
|
||
var length = reactions.length;
|
||
for (var i = 0; i < length; i++) {
|
||
var reaction = reactions[i];
|
||
var flags2 = reaction.f;
|
||
var not_dirty = (flags2 & DIRTY) === 0;
|
||
if (not_dirty) {
|
||
set_signal_status(reaction, status);
|
||
}
|
||
if ((flags2 & DERIVED) !== 0) {
|
||
var derived = (
|
||
/** @type {Derived} */
|
||
reaction
|
||
);
|
||
batch_values?.delete(derived);
|
||
if ((flags2 & WAS_MARKED) === 0) {
|
||
if (flags2 & CONNECTED) {
|
||
reaction.f |= WAS_MARKED;
|
||
}
|
||
mark_reactions(derived, MAYBE_DIRTY);
|
||
}
|
||
} else if (not_dirty) {
|
||
if ((flags2 & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
|
||
eager_block_effects.add(
|
||
/** @type {Effect} */
|
||
reaction
|
||
);
|
||
}
|
||
schedule_effect(
|
||
/** @type {Effect} */
|
||
reaction
|
||
);
|
||
}
|
||
}
|
||
}
|
||
function proxy(value) {
|
||
if (typeof value !== "object" || value === null || STATE_SYMBOL in value) {
|
||
return value;
|
||
}
|
||
const prototype = get_prototype_of(value);
|
||
if (prototype !== object_prototype && prototype !== array_prototype) {
|
||
return value;
|
||
}
|
||
var sources = /* @__PURE__ */ new Map();
|
||
var is_proxied_array = is_array(value);
|
||
var version = /* @__PURE__ */ state(0);
|
||
var parent_version = update_version;
|
||
var with_parent = (fn) => {
|
||
if (update_version === parent_version) {
|
||
return fn();
|
||
}
|
||
var reaction = active_reaction;
|
||
var version2 = update_version;
|
||
set_active_reaction(null);
|
||
set_update_version(parent_version);
|
||
var result = fn();
|
||
set_active_reaction(reaction);
|
||
set_update_version(version2);
|
||
return result;
|
||
};
|
||
if (is_proxied_array) {
|
||
sources.set("length", /* @__PURE__ */ state(
|
||
/** @type {any[]} */
|
||
value.length
|
||
));
|
||
}
|
||
return new Proxy(
|
||
/** @type {any} */
|
||
value,
|
||
{
|
||
defineProperty(_, prop, descriptor) {
|
||
if (!("value" in descriptor) || descriptor.configurable === false || descriptor.enumerable === false || descriptor.writable === false) {
|
||
state_descriptors_fixed();
|
||
}
|
||
var s = sources.get(prop);
|
||
if (s === void 0) {
|
||
with_parent(() => {
|
||
var s2 = /* @__PURE__ */ state(descriptor.value);
|
||
sources.set(prop, s2);
|
||
return s2;
|
||
});
|
||
} else {
|
||
set(s, descriptor.value, true);
|
||
}
|
||
return true;
|
||
},
|
||
deleteProperty(target, prop) {
|
||
var s = sources.get(prop);
|
||
if (s === void 0) {
|
||
if (prop in target) {
|
||
const s2 = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
|
||
sources.set(prop, s2);
|
||
increment(version);
|
||
}
|
||
} else {
|
||
set(s, UNINITIALIZED);
|
||
increment(version);
|
||
}
|
||
return true;
|
||
},
|
||
get(target, prop, receiver) {
|
||
if (prop === STATE_SYMBOL) {
|
||
return value;
|
||
}
|
||
var s = sources.get(prop);
|
||
var exists = prop in target;
|
||
if (s === void 0 && (!exists || get_descriptor(target, prop)?.writable)) {
|
||
s = with_parent(() => {
|
||
var p = proxy(exists ? target[prop] : UNINITIALIZED);
|
||
var s2 = /* @__PURE__ */ state(p);
|
||
return s2;
|
||
});
|
||
sources.set(prop, s);
|
||
}
|
||
if (s !== void 0) {
|
||
var v = get(s);
|
||
return v === UNINITIALIZED ? void 0 : v;
|
||
}
|
||
return Reflect.get(target, prop, receiver);
|
||
},
|
||
getOwnPropertyDescriptor(target, prop) {
|
||
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
||
if (descriptor && "value" in descriptor) {
|
||
var s = sources.get(prop);
|
||
if (s) descriptor.value = get(s);
|
||
} else if (descriptor === void 0) {
|
||
var source2 = sources.get(prop);
|
||
var value2 = source2?.v;
|
||
if (source2 !== void 0 && value2 !== UNINITIALIZED) {
|
||
return {
|
||
enumerable: true,
|
||
configurable: true,
|
||
value: value2,
|
||
writable: true
|
||
};
|
||
}
|
||
}
|
||
return descriptor;
|
||
},
|
||
has(target, prop) {
|
||
if (prop === STATE_SYMBOL) {
|
||
return true;
|
||
}
|
||
var s = sources.get(prop);
|
||
var has = s !== void 0 && s.v !== UNINITIALIZED || Reflect.has(target, prop);
|
||
if (s !== void 0 || active_effect !== null && (!has || get_descriptor(target, prop)?.writable)) {
|
||
if (s === void 0) {
|
||
s = with_parent(() => {
|
||
var p = has ? proxy(target[prop]) : UNINITIALIZED;
|
||
var s2 = /* @__PURE__ */ state(p);
|
||
return s2;
|
||
});
|
||
sources.set(prop, s);
|
||
}
|
||
var value2 = get(s);
|
||
if (value2 === UNINITIALIZED) {
|
||
return false;
|
||
}
|
||
}
|
||
return has;
|
||
},
|
||
set(target, prop, value2, receiver) {
|
||
var s = sources.get(prop);
|
||
var has = prop in target;
|
||
if (is_proxied_array && prop === "length") {
|
||
for (var i = value2; i < /** @type {Source<number>} */
|
||
s.v; i += 1) {
|
||
var other_s = sources.get(i + "");
|
||
if (other_s !== void 0) {
|
||
set(other_s, UNINITIALIZED);
|
||
} else if (i in target) {
|
||
other_s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED));
|
||
sources.set(i + "", other_s);
|
||
}
|
||
}
|
||
}
|
||
if (s === void 0) {
|
||
if (!has || get_descriptor(target, prop)?.writable) {
|
||
s = with_parent(() => /* @__PURE__ */ state(void 0));
|
||
set(s, proxy(value2));
|
||
sources.set(prop, s);
|
||
}
|
||
} else {
|
||
has = s.v !== UNINITIALIZED;
|
||
var p = with_parent(() => proxy(value2));
|
||
set(s, p);
|
||
}
|
||
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
||
if (descriptor?.set) {
|
||
descriptor.set.call(receiver, value2);
|
||
}
|
||
if (!has) {
|
||
if (is_proxied_array && typeof prop === "string") {
|
||
var ls = (
|
||
/** @type {Source<number>} */
|
||
sources.get("length")
|
||
);
|
||
var n = Number(prop);
|
||
if (Number.isInteger(n) && n >= ls.v) {
|
||
set(ls, n + 1);
|
||
}
|
||
}
|
||
increment(version);
|
||
}
|
||
return true;
|
||
},
|
||
ownKeys(target) {
|
||
get(version);
|
||
var own_keys = Reflect.ownKeys(target).filter((key2) => {
|
||
var source3 = sources.get(key2);
|
||
return source3 === void 0 || source3.v !== UNINITIALIZED;
|
||
});
|
||
for (var [key, source2] of sources) {
|
||
if (source2.v !== UNINITIALIZED && !(key in target)) {
|
||
own_keys.push(key);
|
||
}
|
||
}
|
||
return own_keys;
|
||
},
|
||
setPrototypeOf() {
|
||
state_prototype_fixed();
|
||
}
|
||
}
|
||
);
|
||
}
|
||
var $window;
|
||
var first_child_getter;
|
||
var next_sibling_getter;
|
||
function init_operations() {
|
||
if ($window !== void 0) {
|
||
return;
|
||
}
|
||
$window = window;
|
||
var element_prototype = Element.prototype;
|
||
var node_prototype = Node.prototype;
|
||
var text_prototype = Text.prototype;
|
||
first_child_getter = get_descriptor(node_prototype, "firstChild").get;
|
||
next_sibling_getter = get_descriptor(node_prototype, "nextSibling").get;
|
||
if (is_extensible(element_prototype)) {
|
||
element_prototype.__click = void 0;
|
||
element_prototype.__className = void 0;
|
||
element_prototype.__attributes = null;
|
||
element_prototype.__style = void 0;
|
||
element_prototype.__e = void 0;
|
||
}
|
||
if (is_extensible(text_prototype)) {
|
||
text_prototype.__t = void 0;
|
||
}
|
||
}
|
||
function create_text(value = "") {
|
||
return document.createTextNode(value);
|
||
}
|
||
// @__NO_SIDE_EFFECTS__
|
||
function get_first_child(node) {
|
||
return (
|
||
/** @type {TemplateNode | null} */
|
||
first_child_getter.call(node)
|
||
);
|
||
}
|
||
// @__NO_SIDE_EFFECTS__
|
||
function get_next_sibling(node) {
|
||
return (
|
||
/** @type {TemplateNode | null} */
|
||
next_sibling_getter.call(node)
|
||
);
|
||
}
|
||
function clear_text_content(node) {
|
||
node.textContent = "";
|
||
}
|
||
function without_reactive_context(fn) {
|
||
var previous_reaction = active_reaction;
|
||
var previous_effect = active_effect;
|
||
set_active_reaction(null);
|
||
set_active_effect(null);
|
||
try {
|
||
return fn();
|
||
} finally {
|
||
set_active_reaction(previous_reaction);
|
||
set_active_effect(previous_effect);
|
||
}
|
||
}
|
||
function push_effect(effect, parent_effect) {
|
||
var parent_last = parent_effect.last;
|
||
if (parent_last === null) {
|
||
parent_effect.last = parent_effect.first = effect;
|
||
} else {
|
||
parent_last.next = effect;
|
||
effect.prev = parent_last;
|
||
parent_effect.last = effect;
|
||
}
|
||
}
|
||
function create_effect(type, fn, sync) {
|
||
var parent = active_effect;
|
||
if (parent !== null && (parent.f & INERT) !== 0) {
|
||
type |= INERT;
|
||
}
|
||
var effect = {
|
||
ctx: component_context,
|
||
deps: null,
|
||
nodes: null,
|
||
f: type | DIRTY | CONNECTED,
|
||
first: null,
|
||
fn,
|
||
last: null,
|
||
next: null,
|
||
parent,
|
||
b: parent && parent.b,
|
||
prev: null,
|
||
teardown: null,
|
||
wv: 0,
|
||
ac: null
|
||
};
|
||
if (sync) {
|
||
try {
|
||
update_effect(effect);
|
||
} catch (e2) {
|
||
destroy_effect(effect);
|
||
throw e2;
|
||
}
|
||
} else if (fn !== null) {
|
||
schedule_effect(effect);
|
||
}
|
||
var e = effect;
|
||
if (sync && e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && // either `null`, or a singular child
|
||
(e.f & EFFECT_PRESERVED) === 0) {
|
||
e = e.first;
|
||
if ((type & BLOCK_EFFECT) !== 0 && (type & EFFECT_TRANSPARENT) !== 0 && e !== null) {
|
||
e.f |= EFFECT_TRANSPARENT;
|
||
}
|
||
}
|
||
if (e !== null) {
|
||
e.parent = parent;
|
||
if (parent !== null) {
|
||
push_effect(e, parent);
|
||
}
|
||
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0 && (type & ROOT_EFFECT) === 0) {
|
||
var derived = (
|
||
/** @type {Derived} */
|
||
active_reaction
|
||
);
|
||
(derived.effects ??= []).push(e);
|
||
}
|
||
}
|
||
return effect;
|
||
}
|
||
function effect_tracking() {
|
||
return active_reaction !== null && !untracking;
|
||
}
|
||
function create_user_effect(fn) {
|
||
return create_effect(EFFECT | USER_EFFECT, fn, false);
|
||
}
|
||
function component_root(fn) {
|
||
Batch.ensure();
|
||
const effect = create_effect(ROOT_EFFECT | EFFECT_PRESERVED, fn, true);
|
||
return (options = {}) => {
|
||
return new Promise((fulfil) => {
|
||
if (options.outro) {
|
||
pause_effect(effect, () => {
|
||
destroy_effect(effect);
|
||
fulfil(void 0);
|
||
});
|
||
} else {
|
||
destroy_effect(effect);
|
||
fulfil(void 0);
|
||
}
|
||
});
|
||
};
|
||
}
|
||
function render_effect(fn, flags2 = 0) {
|
||
return create_effect(RENDER_EFFECT | flags2, fn, true);
|
||
}
|
||
function block(fn, flags2 = 0) {
|
||
var effect = create_effect(BLOCK_EFFECT | flags2, fn, true);
|
||
return effect;
|
||
}
|
||
function branch(fn) {
|
||
return create_effect(BRANCH_EFFECT | EFFECT_PRESERVED, fn, true);
|
||
}
|
||
function execute_effect_teardown(effect) {
|
||
var teardown = effect.teardown;
|
||
if (teardown !== null) {
|
||
const previously_destroying_effect = is_destroying_effect;
|
||
const previous_reaction = active_reaction;
|
||
set_is_destroying_effect(true);
|
||
set_active_reaction(null);
|
||
try {
|
||
teardown.call(null);
|
||
} finally {
|
||
set_is_destroying_effect(previously_destroying_effect);
|
||
set_active_reaction(previous_reaction);
|
||
}
|
||
}
|
||
}
|
||
function destroy_effect_children(signal, remove_dom = false) {
|
||
var effect = signal.first;
|
||
signal.first = signal.last = null;
|
||
while (effect !== null) {
|
||
const controller2 = effect.ac;
|
||
if (controller2 !== null) {
|
||
without_reactive_context(() => {
|
||
controller2.abort(STALE_REACTION);
|
||
});
|
||
}
|
||
var next2 = effect.next;
|
||
if ((effect.f & ROOT_EFFECT) !== 0) {
|
||
effect.parent = null;
|
||
} else {
|
||
destroy_effect(effect, remove_dom);
|
||
}
|
||
effect = next2;
|
||
}
|
||
}
|
||
function destroy_block_effect_children(signal) {
|
||
var effect = signal.first;
|
||
while (effect !== null) {
|
||
var next2 = effect.next;
|
||
if ((effect.f & BRANCH_EFFECT) === 0) {
|
||
destroy_effect(effect);
|
||
}
|
||
effect = next2;
|
||
}
|
||
}
|
||
function destroy_effect(effect, remove_dom = true) {
|
||
var removed = false;
|
||
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null && effect.nodes.end !== null) {
|
||
remove_effect_dom(
|
||
effect.nodes.start,
|
||
/** @type {TemplateNode} */
|
||
effect.nodes.end
|
||
);
|
||
removed = true;
|
||
}
|
||
destroy_effect_children(effect, remove_dom && !removed);
|
||
remove_reactions(effect, 0);
|
||
set_signal_status(effect, DESTROYED);
|
||
var transitions = effect.nodes && effect.nodes.t;
|
||
if (transitions !== null) {
|
||
for (const transition of transitions) {
|
||
transition.stop();
|
||
}
|
||
}
|
||
execute_effect_teardown(effect);
|
||
var parent = effect.parent;
|
||
if (parent !== null && parent.first !== null) {
|
||
unlink_effect(effect);
|
||
}
|
||
effect.next = effect.prev = effect.teardown = effect.ctx = effect.deps = effect.fn = effect.nodes = effect.ac = null;
|
||
}
|
||
function remove_effect_dom(node, end) {
|
||
while (node !== null) {
|
||
var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
|
||
node.remove();
|
||
node = next2;
|
||
}
|
||
}
|
||
function unlink_effect(effect) {
|
||
var parent = effect.parent;
|
||
var prev = effect.prev;
|
||
var next2 = effect.next;
|
||
if (prev !== null) prev.next = next2;
|
||
if (next2 !== null) next2.prev = prev;
|
||
if (parent !== null) {
|
||
if (parent.first === effect) parent.first = next2;
|
||
if (parent.last === effect) parent.last = prev;
|
||
}
|
||
}
|
||
function pause_effect(effect, callback, destroy = true) {
|
||
var transitions = [];
|
||
pause_children(effect, transitions, true);
|
||
var fn = () => {
|
||
if (destroy) destroy_effect(effect);
|
||
if (callback) callback();
|
||
};
|
||
var remaining = transitions.length;
|
||
if (remaining > 0) {
|
||
var check = () => --remaining || fn();
|
||
for (var transition of transitions) {
|
||
transition.out(check);
|
||
}
|
||
} else {
|
||
fn();
|
||
}
|
||
}
|
||
function pause_children(effect, transitions, local) {
|
||
if ((effect.f & INERT) !== 0) return;
|
||
effect.f ^= INERT;
|
||
var t = effect.nodes && effect.nodes.t;
|
||
if (t !== null) {
|
||
for (const transition of t) {
|
||
if (transition.is_global || local) {
|
||
transitions.push(transition);
|
||
}
|
||
}
|
||
}
|
||
var child = effect.first;
|
||
while (child !== null) {
|
||
var sibling = child.next;
|
||
var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || // If this is a branch effect without a block effect parent,
|
||
// it means the parent block effect was pruned. In that case,
|
||
// transparency information was transferred to the branch effect.
|
||
(child.f & BRANCH_EFFECT) !== 0 && (effect.f & BLOCK_EFFECT) !== 0;
|
||
pause_children(child, transitions, transparent ? local : false);
|
||
child = sibling;
|
||
}
|
||
}
|
||
function move_effect(effect, fragment) {
|
||
if (!effect.nodes) return;
|
||
var node = effect.nodes.start;
|
||
var end = effect.nodes.end;
|
||
while (node !== null) {
|
||
var next2 = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
|
||
fragment.append(node);
|
||
node = next2;
|
||
}
|
||
}
|
||
let is_updating_effect = false;
|
||
let is_destroying_effect = false;
|
||
function set_is_destroying_effect(value) {
|
||
is_destroying_effect = value;
|
||
}
|
||
let active_reaction = null;
|
||
let untracking = false;
|
||
function set_active_reaction(reaction) {
|
||
active_reaction = reaction;
|
||
}
|
||
let active_effect = null;
|
||
function set_active_effect(effect) {
|
||
active_effect = effect;
|
||
}
|
||
let current_sources = null;
|
||
function push_reaction_value(value) {
|
||
if (active_reaction !== null && true) {
|
||
if (current_sources === null) {
|
||
current_sources = [value];
|
||
} else {
|
||
current_sources.push(value);
|
||
}
|
||
}
|
||
}
|
||
let new_deps = null;
|
||
let skipped_deps = 0;
|
||
let untracked_writes = null;
|
||
function set_untracked_writes(value) {
|
||
untracked_writes = value;
|
||
}
|
||
let write_version = 1;
|
||
let read_version = 0;
|
||
let update_version = read_version;
|
||
function set_update_version(value) {
|
||
update_version = value;
|
||
}
|
||
function increment_write_version() {
|
||
return ++write_version;
|
||
}
|
||
function is_dirty(reaction) {
|
||
var flags2 = reaction.f;
|
||
if ((flags2 & DIRTY) !== 0) {
|
||
return true;
|
||
}
|
||
if (flags2 & DERIVED) {
|
||
reaction.f &= ~WAS_MARKED;
|
||
}
|
||
if ((flags2 & MAYBE_DIRTY) !== 0) {
|
||
var dependencies = (
|
||
/** @type {Value[]} */
|
||
reaction.deps
|
||
);
|
||
var length = dependencies.length;
|
||
for (var i = 0; i < length; i++) {
|
||
var dependency = dependencies[i];
|
||
if (is_dirty(
|
||
/** @type {Derived} */
|
||
dependency
|
||
)) {
|
||
update_derived(
|
||
/** @type {Derived} */
|
||
dependency
|
||
);
|
||
}
|
||
if (dependency.wv > reaction.wv) {
|
||
return true;
|
||
}
|
||
}
|
||
if ((flags2 & CONNECTED) !== 0 && // During time traveling we don't want to reset the status so that
|
||
// traversal of the graph in the other batches still happens
|
||
batch_values === null) {
|
||
set_signal_status(reaction, CLEAN);
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
function schedule_possible_effect_self_invalidation(signal, effect, root2 = true) {
|
||
var reactions = signal.reactions;
|
||
if (reactions === null) return;
|
||
if (current_sources !== null && includes.call(current_sources, signal)) {
|
||
return;
|
||
}
|
||
for (var i = 0; i < reactions.length; i++) {
|
||
var reaction = reactions[i];
|
||
if ((reaction.f & DERIVED) !== 0) {
|
||
schedule_possible_effect_self_invalidation(
|
||
/** @type {Derived} */
|
||
reaction,
|
||
effect,
|
||
false
|
||
);
|
||
} else if (effect === reaction) {
|
||
if (root2) {
|
||
set_signal_status(reaction, DIRTY);
|
||
} else if ((reaction.f & CLEAN) !== 0) {
|
||
set_signal_status(reaction, MAYBE_DIRTY);
|
||
}
|
||
schedule_effect(
|
||
/** @type {Effect} */
|
||
reaction
|
||
);
|
||
}
|
||
}
|
||
}
|
||
function update_reaction(reaction) {
|
||
var previous_deps = new_deps;
|
||
var previous_skipped_deps = skipped_deps;
|
||
var previous_untracked_writes = untracked_writes;
|
||
var previous_reaction = active_reaction;
|
||
var previous_sources = current_sources;
|
||
var previous_component_context = component_context;
|
||
var previous_untracking = untracking;
|
||
var previous_update_version = update_version;
|
||
var flags2 = reaction.f;
|
||
new_deps = /** @type {null | Value[]} */
|
||
null;
|
||
skipped_deps = 0;
|
||
untracked_writes = null;
|
||
active_reaction = (flags2 & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;
|
||
current_sources = null;
|
||
set_component_context(reaction.ctx);
|
||
untracking = false;
|
||
update_version = ++read_version;
|
||
if (reaction.ac !== null) {
|
||
without_reactive_context(() => {
|
||
reaction.ac.abort(STALE_REACTION);
|
||
});
|
||
reaction.ac = null;
|
||
}
|
||
try {
|
||
reaction.f |= REACTION_IS_UPDATING;
|
||
var fn = (
|
||
/** @type {Function} */
|
||
reaction.fn
|
||
);
|
||
var result = fn();
|
||
reaction.f |= REACTION_RAN;
|
||
var deps = reaction.deps;
|
||
var is_fork = current_batch?.is_fork;
|
||
if (new_deps !== null) {
|
||
var i;
|
||
if (!is_fork) {
|
||
remove_reactions(reaction, skipped_deps);
|
||
}
|
||
if (deps !== null && skipped_deps > 0) {
|
||
deps.length = skipped_deps + new_deps.length;
|
||
for (i = 0; i < new_deps.length; i++) {
|
||
deps[skipped_deps + i] = new_deps[i];
|
||
}
|
||
} else {
|
||
reaction.deps = deps = new_deps;
|
||
}
|
||
if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {
|
||
for (i = skipped_deps; i < deps.length; i++) {
|
||
(deps[i].reactions ??= []).push(reaction);
|
||
}
|
||
}
|
||
} else if (!is_fork && deps !== null && skipped_deps < deps.length) {
|
||
remove_reactions(reaction, skipped_deps);
|
||
deps.length = skipped_deps;
|
||
}
|
||
if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0) {
|
||
for (i = 0; i < /** @type {Source[]} */
|
||
untracked_writes.length; i++) {
|
||
schedule_possible_effect_self_invalidation(
|
||
untracked_writes[i],
|
||
/** @type {Effect} */
|
||
reaction
|
||
);
|
||
}
|
||
}
|
||
if (previous_reaction !== null && previous_reaction !== reaction) {
|
||
read_version++;
|
||
if (previous_reaction.deps !== null) {
|
||
for (let i2 = 0; i2 < previous_skipped_deps; i2 += 1) {
|
||
previous_reaction.deps[i2].rv = read_version;
|
||
}
|
||
}
|
||
if (previous_deps !== null) {
|
||
for (const dep of previous_deps) {
|
||
dep.rv = read_version;
|
||
}
|
||
}
|
||
if (untracked_writes !== null) {
|
||
if (previous_untracked_writes === null) {
|
||
previous_untracked_writes = untracked_writes;
|
||
} else {
|
||
previous_untracked_writes.push(.../** @type {Source[]} */
|
||
untracked_writes);
|
||
}
|
||
}
|
||
}
|
||
if ((reaction.f & ERROR_VALUE) !== 0) {
|
||
reaction.f ^= ERROR_VALUE;
|
||
}
|
||
return result;
|
||
} catch (error) {
|
||
return handle_error(error);
|
||
} finally {
|
||
reaction.f ^= REACTION_IS_UPDATING;
|
||
new_deps = previous_deps;
|
||
skipped_deps = previous_skipped_deps;
|
||
untracked_writes = previous_untracked_writes;
|
||
active_reaction = previous_reaction;
|
||
current_sources = previous_sources;
|
||
set_component_context(previous_component_context);
|
||
untracking = previous_untracking;
|
||
update_version = previous_update_version;
|
||
}
|
||
}
|
||
function remove_reaction(signal, dependency) {
|
||
let reactions = dependency.reactions;
|
||
if (reactions !== null) {
|
||
var index = index_of.call(reactions, signal);
|
||
if (index !== -1) {
|
||
var new_length = reactions.length - 1;
|
||
if (new_length === 0) {
|
||
reactions = dependency.reactions = null;
|
||
} else {
|
||
reactions[index] = reactions[new_length];
|
||
reactions.pop();
|
||
}
|
||
}
|
||
}
|
||
if (reactions === null && (dependency.f & DERIVED) !== 0 && // Destroying a child effect while updating a parent effect can cause a dependency to appear
|
||
// to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
|
||
// allows us to skip the expensive work of disconnecting and immediately reconnecting it
|
||
(new_deps === null || !includes.call(new_deps, dependency))) {
|
||
var derived = (
|
||
/** @type {Derived} */
|
||
dependency
|
||
);
|
||
if ((derived.f & CONNECTED) !== 0) {
|
||
derived.f ^= CONNECTED;
|
||
derived.f &= ~WAS_MARKED;
|
||
}
|
||
update_derived_status(derived);
|
||
freeze_derived_effects(derived);
|
||
remove_reactions(derived, 0);
|
||
}
|
||
}
|
||
function remove_reactions(signal, start_index) {
|
||
var dependencies = signal.deps;
|
||
if (dependencies === null) return;
|
||
for (var i = start_index; i < dependencies.length; i++) {
|
||
remove_reaction(signal, dependencies[i]);
|
||
}
|
||
}
|
||
function update_effect(effect) {
|
||
var flags2 = effect.f;
|
||
if ((flags2 & DESTROYED) !== 0) {
|
||
return;
|
||
}
|
||
set_signal_status(effect, CLEAN);
|
||
var previous_effect = active_effect;
|
||
var was_updating_effect = is_updating_effect;
|
||
active_effect = effect;
|
||
is_updating_effect = true;
|
||
try {
|
||
if ((flags2 & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {
|
||
destroy_block_effect_children(effect);
|
||
} else {
|
||
destroy_effect_children(effect);
|
||
}
|
||
execute_effect_teardown(effect);
|
||
var teardown = update_reaction(effect);
|
||
effect.teardown = typeof teardown === "function" ? teardown : null;
|
||
effect.wv = write_version;
|
||
var dep;
|
||
if (browser && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) ;
|
||
} finally {
|
||
is_updating_effect = was_updating_effect;
|
||
active_effect = previous_effect;
|
||
}
|
||
}
|
||
function get(signal) {
|
||
var flags2 = signal.f;
|
||
var is_derived = (flags2 & DERIVED) !== 0;
|
||
if (active_reaction !== null && !untracking) {
|
||
var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
|
||
if (!destroyed && (current_sources === null || !includes.call(current_sources, signal))) {
|
||
var deps = active_reaction.deps;
|
||
if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
|
||
if (signal.rv < read_version) {
|
||
signal.rv = read_version;
|
||
if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {
|
||
skipped_deps++;
|
||
} else if (new_deps === null) {
|
||
new_deps = [signal];
|
||
} else {
|
||
new_deps.push(signal);
|
||
}
|
||
}
|
||
} else {
|
||
(active_reaction.deps ??= []).push(signal);
|
||
var reactions = signal.reactions;
|
||
if (reactions === null) {
|
||
signal.reactions = [active_reaction];
|
||
} else if (!includes.call(reactions, active_reaction)) {
|
||
reactions.push(active_reaction);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (is_destroying_effect && old_values.has(signal)) {
|
||
return old_values.get(signal);
|
||
}
|
||
if (is_derived) {
|
||
var derived = (
|
||
/** @type {Derived} */
|
||
signal
|
||
);
|
||
if (is_destroying_effect) {
|
||
var value = derived.v;
|
||
if ((derived.f & CLEAN) === 0 && derived.reactions !== null || depends_on_old_values(derived)) {
|
||
value = execute_derived(derived);
|
||
}
|
||
old_values.set(derived, value);
|
||
return value;
|
||
}
|
||
var should_connect = (derived.f & CONNECTED) === 0 && !untracking && active_reaction !== null && (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);
|
||
var is_new = (derived.f & REACTION_RAN) === 0;
|
||
if (is_dirty(derived)) {
|
||
if (should_connect) {
|
||
derived.f |= CONNECTED;
|
||
}
|
||
update_derived(derived);
|
||
}
|
||
if (should_connect && !is_new) {
|
||
unfreeze_derived_effects(derived);
|
||
reconnect(derived);
|
||
}
|
||
}
|
||
if (batch_values?.has(signal)) {
|
||
return batch_values.get(signal);
|
||
}
|
||
if ((signal.f & ERROR_VALUE) !== 0) {
|
||
throw signal.v;
|
||
}
|
||
return signal.v;
|
||
}
|
||
function reconnect(derived) {
|
||
derived.f |= CONNECTED;
|
||
if (derived.deps === null) return;
|
||
for (const dep of derived.deps) {
|
||
(dep.reactions ??= []).push(derived);
|
||
if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
|
||
unfreeze_derived_effects(
|
||
/** @type {Derived} */
|
||
dep
|
||
);
|
||
reconnect(
|
||
/** @type {Derived} */
|
||
dep
|
||
);
|
||
}
|
||
}
|
||
}
|
||
function depends_on_old_values(derived) {
|
||
if (derived.v === UNINITIALIZED) return true;
|
||
if (derived.deps === null) return false;
|
||
for (const dep of derived.deps) {
|
||
if (old_values.has(dep)) {
|
||
return true;
|
||
}
|
||
if ((dep.f & DERIVED) !== 0 && depends_on_old_values(
|
||
/** @type {Derived} */
|
||
dep
|
||
)) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
function untrack(fn) {
|
||
var previous_untracking = untracking;
|
||
try {
|
||
untracking = true;
|
||
return fn();
|
||
} finally {
|
||
untracking = previous_untracking;
|
||
}
|
||
}
|
||
const DOM_BOOLEAN_ATTRIBUTES = [
|
||
"allowfullscreen",
|
||
"async",
|
||
"autofocus",
|
||
"autoplay",
|
||
"checked",
|
||
"controls",
|
||
"default",
|
||
"disabled",
|
||
"formnovalidate",
|
||
"indeterminate",
|
||
"inert",
|
||
"ismap",
|
||
"loop",
|
||
"multiple",
|
||
"muted",
|
||
"nomodule",
|
||
"novalidate",
|
||
"open",
|
||
"playsinline",
|
||
"readonly",
|
||
"required",
|
||
"reversed",
|
||
"seamless",
|
||
"selected",
|
||
"webkitdirectory",
|
||
"defer",
|
||
"disablepictureinpicture",
|
||
"disableremoteplayback"
|
||
];
|
||
function is_boolean_attribute(name) {
|
||
return DOM_BOOLEAN_ATTRIBUTES.includes(name);
|
||
}
|
||
const PASSIVE_EVENTS = ["touchstart", "touchmove"];
|
||
function is_passive_event(name) {
|
||
return PASSIVE_EVENTS.includes(name);
|
||
}
|
||
const event_symbol = Symbol("events");
|
||
const all_registered_events = /* @__PURE__ */ new Set();
|
||
const root_event_handles = /* @__PURE__ */ new Set();
|
||
let last_propagated_event = null;
|
||
function handle_event_propagation(event) {
|
||
var handler_element = this;
|
||
var owner_document = (
|
||
/** @type {Node} */
|
||
handler_element.ownerDocument
|
||
);
|
||
var event_name = event.type;
|
||
var path = event.composedPath?.() || [];
|
||
var current_target = (
|
||
/** @type {null | Element} */
|
||
path[0] || event.target
|
||
);
|
||
last_propagated_event = event;
|
||
var path_idx = 0;
|
||
var handled_at = last_propagated_event === event && event[event_symbol];
|
||
if (handled_at) {
|
||
var at_idx = path.indexOf(handled_at);
|
||
if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
|
||
window)) {
|
||
event[event_symbol] = handler_element;
|
||
return;
|
||
}
|
||
var handler_idx = path.indexOf(handler_element);
|
||
if (handler_idx === -1) {
|
||
return;
|
||
}
|
||
if (at_idx <= handler_idx) {
|
||
path_idx = at_idx;
|
||
}
|
||
}
|
||
current_target = /** @type {Element} */
|
||
path[path_idx] || event.target;
|
||
if (current_target === handler_element) return;
|
||
define_property(event, "currentTarget", {
|
||
configurable: true,
|
||
get() {
|
||
return current_target || owner_document;
|
||
}
|
||
});
|
||
var previous_reaction = active_reaction;
|
||
var previous_effect = active_effect;
|
||
set_active_reaction(null);
|
||
set_active_effect(null);
|
||
try {
|
||
var throw_error;
|
||
var other_errors = [];
|
||
while (current_target !== null) {
|
||
var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
|
||
current_target.host || null;
|
||
try {
|
||
var delegated = current_target[event_symbol]?.[event_name];
|
||
if (delegated != null && (!/** @type {any} */
|
||
current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
|
||
// -> the target could not have been disabled because it emits the event in the first place
|
||
event.target === current_target)) {
|
||
delegated.call(current_target, event);
|
||
}
|
||
} catch (error) {
|
||
if (throw_error) {
|
||
other_errors.push(error);
|
||
} else {
|
||
throw_error = error;
|
||
}
|
||
}
|
||
if (event.cancelBubble || parent_element === handler_element || parent_element === null) {
|
||
break;
|
||
}
|
||
current_target = parent_element;
|
||
}
|
||
if (throw_error) {
|
||
for (let error of other_errors) {
|
||
queueMicrotask(() => {
|
||
throw error;
|
||
});
|
||
}
|
||
throw throw_error;
|
||
}
|
||
} finally {
|
||
event[event_symbol] = handler_element;
|
||
delete event.currentTarget;
|
||
set_active_reaction(previous_reaction);
|
||
set_active_effect(previous_effect);
|
||
}
|
||
}
|
||
function assign_nodes(start, end) {
|
||
var effect = (
|
||
/** @type {Effect} */
|
||
active_effect
|
||
);
|
||
if (effect.nodes === null) {
|
||
effect.nodes = { start, end, a: null, t: null };
|
||
}
|
||
}
|
||
function mount(component, options) {
|
||
return _mount(component, options);
|
||
}
|
||
function hydrate(component, options) {
|
||
init_operations();
|
||
options.intro = options.intro ?? false;
|
||
const target = options.target;
|
||
const was_hydrating = hydrating;
|
||
const previous_hydrate_node = hydrate_node;
|
||
try {
|
||
var anchor = /* @__PURE__ */ get_first_child(target);
|
||
while (anchor && (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */
|
||
anchor.data !== HYDRATION_START)) {
|
||
anchor = /* @__PURE__ */ get_next_sibling(anchor);
|
||
}
|
||
if (!anchor) {
|
||
throw HYDRATION_ERROR;
|
||
}
|
||
set_hydrating(true);
|
||
set_hydrate_node(
|
||
/** @type {Comment} */
|
||
anchor
|
||
);
|
||
const instance = _mount(component, { ...options, anchor });
|
||
set_hydrating(false);
|
||
return (
|
||
/** @type {Exports} */
|
||
instance
|
||
);
|
||
} catch (error) {
|
||
if (error instanceof Error && error.message.split("\n").some((line) => line.startsWith("https://svelte.dev/e/"))) {
|
||
throw error;
|
||
}
|
||
if (error !== HYDRATION_ERROR) {
|
||
console.warn("Failed to hydrate: ", error);
|
||
}
|
||
if (options.recover === false) {
|
||
hydration_failed();
|
||
}
|
||
init_operations();
|
||
clear_text_content(target);
|
||
set_hydrating(false);
|
||
return mount(component, options);
|
||
} finally {
|
||
set_hydrating(was_hydrating);
|
||
set_hydrate_node(previous_hydrate_node);
|
||
}
|
||
}
|
||
const listeners = /* @__PURE__ */ new Map();
|
||
function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
|
||
init_operations();
|
||
var component = void 0;
|
||
var unmount2 = component_root(() => {
|
||
var anchor_node = anchor ?? target.appendChild(create_text());
|
||
boundary(
|
||
/** @type {TemplateNode} */
|
||
anchor_node,
|
||
{
|
||
pending: () => {
|
||
}
|
||
},
|
||
(anchor_node2) => {
|
||
push$1({});
|
||
var ctx = (
|
||
/** @type {ComponentContext} */
|
||
component_context
|
||
);
|
||
if (context) ctx.c = context;
|
||
if (events) {
|
||
props.$$events = events;
|
||
}
|
||
if (hydrating) {
|
||
assign_nodes(
|
||
/** @type {TemplateNode} */
|
||
anchor_node2,
|
||
null
|
||
);
|
||
}
|
||
component = Component(anchor_node2, props) || {};
|
||
if (hydrating) {
|
||
active_effect.nodes.end = hydrate_node;
|
||
if (hydrate_node === null || hydrate_node.nodeType !== COMMENT_NODE || /** @type {Comment} */
|
||
hydrate_node.data !== HYDRATION_END) {
|
||
hydration_mismatch();
|
||
throw HYDRATION_ERROR;
|
||
}
|
||
}
|
||
pop$1();
|
||
}
|
||
);
|
||
var registered_events = /* @__PURE__ */ new Set();
|
||
var event_handle = (events2) => {
|
||
for (var i = 0; i < events2.length; i++) {
|
||
var event_name = events2[i];
|
||
if (registered_events.has(event_name)) continue;
|
||
registered_events.add(event_name);
|
||
var passive = is_passive_event(event_name);
|
||
for (const node of [target, document]) {
|
||
var counts = listeners.get(node);
|
||
if (counts === void 0) {
|
||
counts = /* @__PURE__ */ new Map();
|
||
listeners.set(node, counts);
|
||
}
|
||
var count = counts.get(event_name);
|
||
if (count === void 0) {
|
||
node.addEventListener(event_name, handle_event_propagation, { passive });
|
||
counts.set(event_name, 1);
|
||
} else {
|
||
counts.set(event_name, count + 1);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
event_handle(array_from(all_registered_events));
|
||
root_event_handles.add(event_handle);
|
||
return () => {
|
||
for (var event_name of registered_events) {
|
||
for (const node of [target, document]) {
|
||
var counts = (
|
||
/** @type {Map<string, number>} */
|
||
listeners.get(node)
|
||
);
|
||
var count = (
|
||
/** @type {number} */
|
||
counts.get(event_name)
|
||
);
|
||
if (--count == 0) {
|
||
node.removeEventListener(event_name, handle_event_propagation);
|
||
counts.delete(event_name);
|
||
if (counts.size === 0) {
|
||
listeners.delete(node);
|
||
}
|
||
} else {
|
||
counts.set(event_name, count);
|
||
}
|
||
}
|
||
}
|
||
root_event_handles.delete(event_handle);
|
||
if (anchor_node !== anchor) {
|
||
anchor_node.parentNode?.removeChild(anchor_node);
|
||
}
|
||
};
|
||
});
|
||
mounted_components.set(component, unmount2);
|
||
return component;
|
||
}
|
||
let mounted_components = /* @__PURE__ */ new WeakMap();
|
||
function unmount(component, options) {
|
||
const fn = mounted_components.get(component);
|
||
if (fn) {
|
||
mounted_components.delete(component);
|
||
return fn(options);
|
||
}
|
||
return Promise.resolve();
|
||
}
|
||
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 === "&" ? "&" : ch === '"' ? """ : "<");
|
||
last = i + 1;
|
||
}
|
||
return escaped + str.substring(last);
|
||
}
|
||
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 = name in replacements && 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 in 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 in 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 asClassComponent$1(component) {
|
||
return class extends Svelte4Component {
|
||
/** @param {any} options */
|
||
constructor(options) {
|
||
super({
|
||
component,
|
||
...options
|
||
});
|
||
}
|
||
};
|
||
}
|
||
class Svelte4Component {
|
||
/** @type {any} */
|
||
#events;
|
||
/** @type {Record<string, any>} */
|
||
#instance;
|
||
/**
|
||
* @param {ComponentConstructorOptions & {
|
||
* component: any;
|
||
* }} options
|
||
*/
|
||
constructor(options) {
|
||
var sources = /* @__PURE__ */ new Map();
|
||
var add_source = (key, value) => {
|
||
var s = /* @__PURE__ */ mutable_source(value, false, false);
|
||
sources.set(key, s);
|
||
return s;
|
||
};
|
||
const props = new Proxy(
|
||
{ ...options.props || {}, $$events: {} },
|
||
{
|
||
get(target, prop) {
|
||
return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
||
},
|
||
has(target, prop) {
|
||
if (prop === LEGACY_PROPS) return true;
|
||
get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
||
return Reflect.has(target, prop);
|
||
},
|
||
set(target, prop, value) {
|
||
set(sources.get(prop) ?? add_source(prop, value), value);
|
||
return Reflect.set(target, prop, value);
|
||
}
|
||
}
|
||
);
|
||
this.#instance = (options.hydrate ? hydrate : mount)(options.component, {
|
||
target: options.target,
|
||
anchor: options.anchor,
|
||
props,
|
||
context: options.context,
|
||
intro: options.intro ?? false,
|
||
recover: options.recover
|
||
});
|
||
if (!options?.props?.$$host || options.sync === false) {
|
||
flushSync();
|
||
}
|
||
this.#events = props.$$events;
|
||
for (const key of Object.keys(this.#instance)) {
|
||
if (key === "$set" || key === "$destroy" || key === "$on") continue;
|
||
define_property(this, key, {
|
||
get() {
|
||
return this.#instance[key];
|
||
},
|
||
/** @param {any} value */
|
||
set(value) {
|
||
this.#instance[key] = value;
|
||
},
|
||
enumerable: true
|
||
});
|
||
}
|
||
this.#instance.$set = /** @param {Record<string, any>} next */
|
||
(next2) => {
|
||
Object.assign(props, next2);
|
||
};
|
||
this.#instance.$destroy = () => {
|
||
unmount(this.#instance);
|
||
};
|
||
}
|
||
/** @param {Record<string, any>} props */
|
||
$set(props) {
|
||
this.#instance.$set(props);
|
||
}
|
||
/**
|
||
* @param {string} event
|
||
* @param {(...args: any[]) => any} callback
|
||
* @returns {any}
|
||
*/
|
||
$on(event, callback) {
|
||
this.#events[event] = this.#events[event] || [];
|
||
const cb = (...args) => callback.call(this, ...args);
|
||
this.#events[event].push(cb);
|
||
return () => {
|
||
this.#events[event] = this.#events[event].filter(
|
||
/** @param {any} fn */
|
||
(fn) => fn !== cb
|
||
);
|
||
};
|
||
}
|
||
$destroy() {
|
||
this.#instance.$destroy();
|
||
}
|
||
}
|
||
function subscribe_to_store(store, run, invalidate) {
|
||
if (store == null) {
|
||
run(void 0);
|
||
if (invalidate) invalidate(void 0);
|
||
return noop;
|
||
}
|
||
const unsub = untrack(
|
||
() => store.subscribe(
|
||
run,
|
||
// @ts-expect-error
|
||
invalidate
|
||
)
|
||
);
|
||
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
|
||
}
|
||
const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
|
||
const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;
|
||
const EMPTY_COMMENT = `<!---->`;
|
||
let controller = null;
|
||
function abort() {
|
||
controller?.abort(STALE_REACTION);
|
||
controller = null;
|
||
}
|
||
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 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 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 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(fn) {
|
||
ssr_context = { p: ssr_context, c: null, r: null };
|
||
}
|
||
function pop() {
|
||
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;
|
||
}
|
||
function unresolved_hydratable(key, stack) {
|
||
{
|
||
console.warn(`https://svelte.dev/e/unresolved_hydratable`);
|
||
}
|
||
}
|
||
function get_render_context() {
|
||
const store = als?.getStore();
|
||
{
|
||
server_context_required();
|
||
}
|
||
return store;
|
||
}
|
||
let als = null;
|
||
let text_encoder;
|
||
let crypto;
|
||
async function sha256(data) {
|
||
text_encoder ??= new TextEncoder();
|
||
crypto ??= globalThis.crypto?.subtle?.digest ? globalThis.crypto : (
|
||
// @ts-ignore - we don't install node types in the prod build
|
||
// don't use 'node:crypto' because static analysers will think we rely on node when we don't
|
||
(await import(
|
||
/* @vite-ignore */
|
||
'node:crypto'
|
||
)).webcrypto
|
||
);
|
||
const hash_buffer = await crypto.subtle.digest("SHA-256", text_encoder.encode(data));
|
||
return base64_encode(hash_buffer);
|
||
}
|
||
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);
|
||
}
|
||
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;
|
||
/**
|
||
* 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<void> | 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: string | undefined }}
|
||
*/
|
||
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 };
|
||
this.type = parent ? parent.type : "body";
|
||
}
|
||
/**
|
||
* @param {(renderer: Renderer) => void} fn
|
||
*/
|
||
head(fn) {
|
||
const head2 = new Renderer(this.global, this);
|
||
head2.type = "head";
|
||
this.#out.push(head2);
|
||
head2.child(fn);
|
||
}
|
||
/**
|
||
* @param {Array<Promise<void>>} 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<Promise<void>>} 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];
|
||
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 = promise;
|
||
return promises;
|
||
}
|
||
/**
|
||
* @param {(renderer: Renderer) => MaybePromise<void>} 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<void>} 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
|
||
});
|
||
const result = fn(child);
|
||
set_ssr_context(parent);
|
||
if (result instanceof Promise) {
|
||
if (child.global.mode === "sync") {
|
||
await_invalid();
|
||
}
|
||
result.catch(() => {
|
||
});
|
||
child.promise = result;
|
||
}
|
||
return child;
|
||
}
|
||
/**
|
||
* 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<void>} fn
|
||
* @param {Function} [component_fn]
|
||
* @returns {void}
|
||
*/
|
||
component(fn, component_fn) {
|
||
push();
|
||
const child = this.child(fn);
|
||
child.#is_component_body = true;
|
||
pop();
|
||
}
|
||
/**
|
||
* @param {Record<string, any>} attrs
|
||
* @param {(renderer: Renderer) => void} fn
|
||
* @param {string | undefined} [css_hash]
|
||
* @param {Record<string, boolean> | undefined} [classes]
|
||
* @param {Record<string, string> | undefined} [styles]
|
||
* @param {number | undefined} [flags]
|
||
* @param {boolean | undefined} [is_rich]
|
||
* @returns {void}
|
||
*/
|
||
select(attrs, fn, css_hash, classes, styles, flags2, is_rich) {
|
||
const { value, ...select_attrs } = attrs;
|
||
this.push(`<select${attributes(select_attrs, css_hash, classes, styles, flags2)}>`);
|
||
this.child((renderer) => {
|
||
renderer.local.select_value = value;
|
||
fn(renderer);
|
||
});
|
||
this.push(`${is_rich ? "<!>" : ""}</select>`);
|
||
}
|
||
/**
|
||
* @param {Record<string, any>} attrs
|
||
* @param {string | number | boolean | ((renderer: Renderer) => void)} body
|
||
* @param {string | undefined} [css_hash]
|
||
* @param {Record<string, boolean> | undefined} [classes]
|
||
* @param {Record<string, string> | undefined} [styles]
|
||
* @param {number | undefined} [flags]
|
||
* @param {boolean | undefined} [is_rich]
|
||
*/
|
||
option(attrs, body, css_hash, classes, styles, flags2, is_rich) {
|
||
this.#out.push(`<option${attributes(attrs, css_hash, classes, styles, flags2)}`);
|
||
const close = (renderer, value, { head: head2, body: body2 }) => {
|
||
if ("value" in attrs) {
|
||
value = attrs.value;
|
||
}
|
||
if (value === this.local.select_value) {
|
||
renderer.#out.push(' selected=""');
|
||
}
|
||
renderer.#out.push(`>${body2}${is_rich ? "<!>" : ""}</option>`);
|
||
if (head2) {
|
||
renderer.head((child) => child.push(head2));
|
||
}
|
||
};
|
||
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 });
|
||
}
|
||
}
|
||
/**
|
||
* @param {(renderer: Renderer) => void} fn
|
||
*/
|
||
title(fn) {
|
||
const path = this.get_path();
|
||
const close = (head2) => {
|
||
this.global.set_title(head2, 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<string>)} 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.#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) => {
|
||
if (item instanceof Renderer) {
|
||
item.subsume(item);
|
||
}
|
||
return item;
|
||
});
|
||
this.promise = other.promise;
|
||
this.type = other.type;
|
||
}
|
||
get length() {
|
||
return this.#out.length;
|
||
}
|
||
/**
|
||
* 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<string, any>} Props
|
||
* @param {Component<Props>} component
|
||
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} [options]
|
||
* @returns {RenderOutput}
|
||
*/
|
||
static render(component, options = {}) {
|
||
let sync;
|
||
const result = (
|
||
/** @type {RenderOutput} */
|
||
{}
|
||
);
|
||
Object.defineProperties(result, {
|
||
html: {
|
||
get: () => {
|
||
return (sync ??= Renderer.#render(component, options)).body;
|
||
}
|
||
},
|
||
head: {
|
||
get: () => {
|
||
return (sync ??= Renderer.#render(component, options)).head;
|
||
}
|
||
},
|
||
body: {
|
||
get: () => {
|
||
return (sync ??= Renderer.#render(component, options)).body;
|
||
}
|
||
},
|
||
hashes: {
|
||
value: {
|
||
script: ""
|
||
}
|
||
},
|
||
then: {
|
||
value: (
|
||
/**
|
||
* 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
|
||
*/
|
||
(onfulfilled, onrejected) => {
|
||
{
|
||
const result2 = sync ??= Renderer.#render(component, options);
|
||
const user_result = onfulfilled({
|
||
head: result2.head,
|
||
body: result2.body,
|
||
html: result2.body,
|
||
hashes: { script: [] }
|
||
});
|
||
return Promise.resolve(user_result);
|
||
}
|
||
}
|
||
)
|
||
}
|
||
});
|
||
return result;
|
||
}
|
||
/**
|
||
* 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<Renderer>}
|
||
*/
|
||
*#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();
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Render a component. Throws if any of the children are performing asynchronous work.
|
||
*
|
||
* @template {Record<string, any>} Props
|
||
* @param {Component<Props>} component
|
||
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string }} options
|
||
* @returns {AccumulatedContent}
|
||
*/
|
||
static #render(component, options) {
|
||
var previous_context = ssr_context;
|
||
try {
|
||
const renderer = Renderer.#open_render("sync", component, options);
|
||
const content = renderer.#collect_content();
|
||
return Renderer.#close_render(content, renderer);
|
||
} finally {
|
||
abort();
|
||
set_ssr_context(previous_context);
|
||
}
|
||
}
|
||
/**
|
||
* Render a component.
|
||
*
|
||
* @template {Record<string, any>} Props
|
||
* @param {Component<Props>} component
|
||
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} options
|
||
* @returns {Promise<AccumulatedContent & { hashes: { script: Sha256Source[] } }>}
|
||
*/
|
||
static async #render_async(component, options) {
|
||
const previous_context = ssr_context;
|
||
try {
|
||
const renderer = Renderer.#open_render("async", component, options);
|
||
const content = await renderer.#collect_content_async();
|
||
const hydratables = await renderer.#collect_hydratables();
|
||
if (hydratables !== null) {
|
||
content.head = hydratables + content.head;
|
||
}
|
||
return Renderer.#close_render(content, renderer);
|
||
} finally {
|
||
set_ssr_context(previous_context);
|
||
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<AccumulatedContent>}
|
||
*/
|
||
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) {
|
||
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 ?? "<missing stack trace>");
|
||
}
|
||
for (const comparison of ctx.comparisons) {
|
||
await comparison;
|
||
}
|
||
return await this.#hydratable_block(ctx);
|
||
}
|
||
/**
|
||
* @template {Record<string, any>} Props
|
||
* @param {'sync' | 'async'} mode
|
||
* @param {import('svelte').Component<Props>} component
|
||
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>; idPrefix?: string; csp?: Csp }} options
|
||
* @returns {Renderer}
|
||
*/
|
||
static #open_render(mode, component, options) {
|
||
const renderer = new Renderer(
|
||
new SSRState(mode, options.idPrefix ? options.idPrefix + "-" : "", options.csp)
|
||
);
|
||
renderer.push(BLOCK_OPEN);
|
||
push();
|
||
if (options.context) ssr_context.c = options.context;
|
||
ssr_context.r = renderer;
|
||
component(renderer, options.props ?? {});
|
||
pop();
|
||
renderer.push(BLOCK_CLOSE);
|
||
return renderer;
|
||
}
|
||
/**
|
||
* @param {AccumulatedContent} content
|
||
* @param {Renderer} renderer
|
||
* @returns {AccumulatedContent & { hashes: { script: Sha256Source[] } }}
|
||
*/
|
||
static #close_render(content, renderer) {
|
||
for (const cleanup of renderer.#collect_on_destroy()) {
|
||
cleanup();
|
||
}
|
||
let head2 = content.head + renderer.global.get_title();
|
||
let body = content.body;
|
||
for (const { hash, code } of renderer.global.css) {
|
||
head2 += `<style id="${hash}">${code}</style>`;
|
||
}
|
||
return {
|
||
head: head2,
|
||
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 `
|
||
<script${csp_attr}>${body}<\/script>`;
|
||
}
|
||
}
|
||
class SSRState {
|
||
/** @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 {{ path: number[], value: string }} */
|
||
#title = { path: [], value: "" };
|
||
/**
|
||
* @param {'sync' | 'async'} mode
|
||
* @param {string} id_prefix
|
||
* @param {Csp} csp
|
||
*/
|
||
constructor(mode, id_prefix = "", csp = { hash: false }) {
|
||
this.mode = mode;
|
||
this.csp = { ...csp, script_hashes: [] };
|
||
let uid = 1;
|
||
this.uid = () => `${id_prefix}s${uid++}`;
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
const 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;
|
||
function render(component, options = {}) {
|
||
if (options.csp?.hash && options.csp.nonce) {
|
||
invalid_csp();
|
||
}
|
||
return Renderer.render(
|
||
/** @type {Component<Props>} */
|
||
component,
|
||
options
|
||
);
|
||
}
|
||
function head(hash, renderer, fn) {
|
||
renderer.head((renderer2) => {
|
||
renderer2.push(`<!--${hash}-->`);
|
||
renderer2.child(fn);
|
||
renderer2.push(EMPTY_COMMENT);
|
||
});
|
||
}
|
||
function attributes(attrs, css_hash, classes, styles, flags2 = 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 = (flags2 & ELEMENT_IS_NAMESPACED) === 0;
|
||
const lowercase = (flags2 & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0;
|
||
const is_input = (flags2 & ELEMENT_IS_INPUT) !== 0;
|
||
for (name in attrs) {
|
||
if (typeof attrs[name] === "function") continue;
|
||
if (name[0] === "$" && name[1] === "$") continue;
|
||
if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
|
||
var value = attrs[name];
|
||
if (lowercase) {
|
||
name = name.toLowerCase();
|
||
}
|
||
if (is_input) {
|
||
if (name === "defaultvalue" || name === "defaultchecked") {
|
||
name = name === "defaultvalue" ? "value" : "checked";
|
||
if (attrs[name]) continue;
|
||
}
|
||
}
|
||
attr_str += attr(name, value, is_html && is_boolean_attribute(name));
|
||
}
|
||
return attr_str;
|
||
}
|
||
function attr_class(value, hash, directives) {
|
||
var result = to_class(value, hash, directives);
|
||
return result ? ` class="${escape_html(result, true)}"` : "";
|
||
}
|
||
function store_get(store_values, store_name, store) {
|
||
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];
|
||
}
|
||
function unsubscribe_stores(store_values) {
|
||
for (const store_name in store_values) {
|
||
store_values[store_name][1]();
|
||
}
|
||
}
|
||
function slot(renderer, $$props, name, slot_props, fallback_fn) {
|
||
var slot_fn = $$props.$$slots?.[name];
|
||
if (slot_fn === true) {
|
||
slot_fn = $$props["children"];
|
||
}
|
||
if (slot_fn !== void 0) {
|
||
slot_fn(renderer, slot_props);
|
||
}
|
||
}
|
||
function bind_props(props_parent, props_now) {
|
||
for (const key in 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;
|
||
}
|
||
}
|
||
}
|
||
function asClassComponent(component) {
|
||
const component_constructor = asClassComponent$1(component);
|
||
const _render = (props, { context, csp } = {}) => {
|
||
const result = render(component, { props, context, csp });
|
||
const munged = Object.defineProperties(
|
||
/** @type {LegacyRenderResult & PromiseLike<LegacyRenderResult>} */
|
||
{},
|
||
{
|
||
css: {
|
||
value: { code: "", map: null }
|
||
},
|
||
head: {
|
||
get: () => result.head
|
||
},
|
||
html: {
|
||
get: () => result.body
|
||
},
|
||
then: {
|
||
/**
|
||
* 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: LegacyRenderResult) => TResult1 } onfulfilled
|
||
* @param { (reason: unknown) => TResult2 } onrejected
|
||
*/
|
||
value: (onfulfilled, onrejected) => {
|
||
{
|
||
const user_result = onfulfilled({
|
||
css: munged.css,
|
||
head: munged.head,
|
||
html: munged.html
|
||
});
|
||
return Promise.resolve(user_result);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
);
|
||
return munged;
|
||
};
|
||
component_constructor.render = _render;
|
||
return component_constructor;
|
||
}
|
||
function Root($$renderer, $$props) {
|
||
$$renderer.component(($$renderer2) => {
|
||
let {
|
||
stores,
|
||
page,
|
||
constructors,
|
||
components = [],
|
||
form,
|
||
data_0 = null,
|
||
data_1 = null,
|
||
data_2 = null
|
||
} = $$props;
|
||
{
|
||
setContext("__svelte__", stores);
|
||
}
|
||
{
|
||
stores.page.set(page);
|
||
}
|
||
const Pyramid_2 = constructors[2];
|
||
if (constructors[1]) {
|
||
$$renderer2.push("<!--[-->");
|
||
const Pyramid_0 = constructors[0];
|
||
$$renderer2.push("<!---->");
|
||
Pyramid_0?.($$renderer2, {
|
||
data: data_0,
|
||
form,
|
||
params: page.params,
|
||
children: ($$renderer3) => {
|
||
if (constructors[2]) {
|
||
$$renderer3.push("<!--[-->");
|
||
const Pyramid_1 = constructors[1];
|
||
$$renderer3.push("<!---->");
|
||
Pyramid_1?.($$renderer3, {
|
||
data: data_1,
|
||
form,
|
||
params: page.params,
|
||
children: ($$renderer4) => {
|
||
$$renderer4.push("<!---->");
|
||
Pyramid_2?.($$renderer4, { data: data_2, form, params: page.params });
|
||
$$renderer4.push(`<!---->`);
|
||
},
|
||
$$slots: { default: true }
|
||
});
|
||
$$renderer3.push(`<!---->`);
|
||
} else {
|
||
$$renderer3.push("<!--[!-->");
|
||
const Pyramid_1 = constructors[1];
|
||
$$renderer3.push("<!---->");
|
||
Pyramid_1?.($$renderer3, { data: data_1, form, params: page.params });
|
||
$$renderer3.push(`<!---->`);
|
||
}
|
||
$$renderer3.push(`<!--]-->`);
|
||
},
|
||
$$slots: { default: true }
|
||
});
|
||
$$renderer2.push(`<!---->`);
|
||
} else {
|
||
$$renderer2.push("<!--[!-->");
|
||
const Pyramid_0 = constructors[0];
|
||
$$renderer2.push("<!---->");
|
||
Pyramid_0?.($$renderer2, { data: data_0, form, params: page.params });
|
||
$$renderer2.push(`<!---->`);
|
||
}
|
||
$$renderer2.push(`<!--]--> `);
|
||
{
|
||
$$renderer2.push("<!--[!-->");
|
||
}
|
||
$$renderer2.push(`<!--]-->`);
|
||
});
|
||
}
|
||
const root = asClassComponent(Root);
|
||
|
||
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[Symbol.for("nodejs.util.inspect.custom")] = (depth, opts, inspect) => {
|
||
return inspect(url, opts);
|
||
};
|
||
tracked.searchParams[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[Symbol.for("nodejs.util.inspect.custom")] = (depth, opts, inspect) => {
|
||
return inspect(new URL(url), opts);
|
||
};
|
||
}
|
||
}
|
||
const subscriber_queue = [];
|
||
function readable(value, start) {
|
||
return {
|
||
subscribe: writable(value, start).subscribe
|
||
};
|
||
}
|
||
function writable(value, start = noop) {
|
||
let stop = null;
|
||
const subscribers = /* @__PURE__ */ new Set();
|
||
function set(new_value) {
|
||
if (safe_not_equal(value, new_value)) {
|
||
value = new_value;
|
||
if (stop) {
|
||
const run_queue = !subscriber_queue.length;
|
||
for (const subscriber of subscribers) {
|
||
subscriber[1]();
|
||
subscriber_queue.push(subscriber, value);
|
||
}
|
||
if (run_queue) {
|
||
for (let i = 0; i < subscriber_queue.length; i += 2) {
|
||
subscriber_queue[i][0](subscriber_queue[i + 1]);
|
||
}
|
||
subscriber_queue.length = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function update(fn) {
|
||
set(fn(
|
||
/** @type {T} */
|
||
value
|
||
));
|
||
}
|
||
function subscribe(run, invalidate = noop) {
|
||
const subscriber = [run, invalidate];
|
||
subscribers.add(subscriber);
|
||
if (subscribers.size === 1) {
|
||
stop = start(set, update) || noop;
|
||
}
|
||
run(
|
||
/** @type {T} */
|
||
value
|
||
);
|
||
return () => {
|
||
subscribers.delete(subscriber);
|
||
if (subscribers.size === 0 && stop) {
|
||
stop();
|
||
stop = null;
|
||
}
|
||
};
|
||
}
|
||
return { set, update, subscribe };
|
||
}
|
||
function derived(stores, fn, initial_value) {
|
||
const single = !Array.isArray(stores);
|
||
const stores_array = single ? [stores] : stores;
|
||
if (!stores_array.every(Boolean)) {
|
||
throw new Error("derived() expects stores as input, got a falsy value");
|
||
}
|
||
const auto = fn.length < 2;
|
||
return readable(initial_value, (set, update) => {
|
||
let started = false;
|
||
const values = [];
|
||
let pending = 0;
|
||
let cleanup = noop;
|
||
const sync = () => {
|
||
if (pending) {
|
||
return;
|
||
}
|
||
cleanup();
|
||
const result = fn(single ? values[0] : values, set, update);
|
||
if (auto) {
|
||
set(result);
|
||
} else {
|
||
cleanup = typeof result === "function" ? result : noop;
|
||
}
|
||
};
|
||
const unsubscribers = stores_array.map(
|
||
(store, i) => subscribe_to_store(
|
||
store,
|
||
(value) => {
|
||
values[i] = value;
|
||
pending &= ~(1 << i);
|
||
if (started) {
|
||
sync();
|
||
}
|
||
},
|
||
() => {
|
||
pending |= 1 << i;
|
||
}
|
||
)
|
||
);
|
||
started = true;
|
||
sync();
|
||
return function stop() {
|
||
run_all(unsubscribers);
|
||
cleanup();
|
||
started = false;
|
||
};
|
||
});
|
||
}
|
||
function validator(expected) {
|
||
function validate(module, file) {
|
||
if (!module) return;
|
||
for (const key in module) {
|
||
if (key[0] === "_" || expected.has(key)) continue;
|
||
const values = [...expected.values()];
|
||
const hint = hint_for_supported_files(key, file?.slice(file.lastIndexOf("."))) ?? `valid exports are ${values.join(", ")}, or anything with a '_' prefix`;
|
||
throw new Error(`Invalid export '${key}'${file ? ` in ${file}` : ""} (${hint})`);
|
||
}
|
||
}
|
||
return validate;
|
||
}
|
||
function hint_for_supported_files(key, ext = ".js") {
|
||
const supported_files = [];
|
||
if (valid_layout_exports.has(key)) {
|
||
supported_files.push(`+layout${ext}`);
|
||
}
|
||
if (valid_page_exports.has(key)) {
|
||
supported_files.push(`+page${ext}`);
|
||
}
|
||
if (valid_layout_server_exports.has(key)) {
|
||
supported_files.push(`+layout.server${ext}`);
|
||
}
|
||
if (valid_page_server_exports.has(key)) {
|
||
supported_files.push(`+page.server${ext}`);
|
||
}
|
||
if (valid_server_exports.has(key)) {
|
||
supported_files.push(`+server${ext}`);
|
||
}
|
||
if (supported_files.length > 0) {
|
||
return `'${key}' is a valid export in ${supported_files.slice(0, -1).join(", ")}${supported_files.length > 1 ? " or " : ""}${supported_files.at(-1)}`;
|
||
}
|
||
}
|
||
const valid_layout_exports = /* @__PURE__ */ new Set([
|
||
"load",
|
||
"prerender",
|
||
"csr",
|
||
"ssr",
|
||
"trailingSlash",
|
||
"config"
|
||
]);
|
||
const valid_page_exports = /* @__PURE__ */ new Set([...valid_layout_exports, "entries"]);
|
||
const valid_layout_server_exports = /* @__PURE__ */ new Set([...valid_layout_exports]);
|
||
const valid_page_server_exports = /* @__PURE__ */ new Set([...valid_layout_server_exports, "actions", "entries"]);
|
||
const valid_server_exports = /* @__PURE__ */ new Set([
|
||
"GET",
|
||
"POST",
|
||
"PATCH",
|
||
"PUT",
|
||
"DELETE",
|
||
"OPTIONS",
|
||
"HEAD",
|
||
"fallback",
|
||
"prerender",
|
||
"trailingSlash",
|
||
"config",
|
||
"entries"
|
||
]);
|
||
const validate_layout_exports = validator(valid_layout_exports);
|
||
const validate_page_exports = validator(valid_page_exports);
|
||
const validate_layout_server_exports = validator(valid_layout_server_exports);
|
||
const validate_page_server_exports = validator(valid_page_server_exports);
|
||
|
||
export { readable as A, slot as B, store_get as C, DevalueError as D, escape_html as E, unsubscribe_stores as F, getContext as G, head as H, fallback as I, attr_class as J, attr as K, bind_props as L, derived as M, noop as N, is_plain_object as a, stringify_string as b, base64_decode as c, decode_pathname as d, enumerable_symbols as e, browser as f, get_type as g, disable_search as h, is_primitive as i, decode_params as j, validate_layout_exports as k, validate_page_server_exports as l, validate_page_exports as m, normalize_path as n, text_encoder$1 as o, resolve as p, make_trackable as q, root as r, stringify_key as s, text_decoder as t, uneval as u, validate_layout_server_exports as v, with_request_store as w, get_relative_path as x, base64_encode$1 as y, writable as z };
|
||
//# sourceMappingURL=exports-yY1xCm4l.js.map
|