4489 lines
142 KiB
JavaScript
4489 lines
142 KiB
JavaScript
import "./esm-env-D8Yi5ac9.js";
|
|
import { d as hydration_mismatch, n as await_reactivity_loss, o as derived_inert, r as await_waterfall, v as state_proxy_equality_mismatch } from "./warnings-BCxPSjeg.js";
|
|
import { a as legacy_mode_flag, o as tracing_mode_flag, t as async_mode_flag } from "./flags-qfBdqUK7.js";
|
|
// node_modules/svelte/src/internal/shared/utils.js
|
|
var is_array = Array.isArray;
|
|
var index_of = Array.prototype.indexOf;
|
|
var includes = Array.prototype.includes;
|
|
var array_from = Array.from;
|
|
var object_keys = Object.keys;
|
|
var define_property = Object.defineProperty;
|
|
var get_descriptor = Object.getOwnPropertyDescriptor;
|
|
var get_descriptors = Object.getOwnPropertyDescriptors;
|
|
var object_prototype = Object.prototype;
|
|
var array_prototype = Array.prototype;
|
|
var get_prototype_of = Object.getPrototypeOf;
|
|
var is_extensible = Object.isExtensible;
|
|
var has_own_property = Object.prototype.hasOwnProperty;
|
|
/**
|
|
* @param {any} thing
|
|
* @returns {thing is Function}
|
|
*/
|
|
function is_function(thing) {
|
|
return typeof thing === "function";
|
|
}
|
|
var noop = () => {};
|
|
/**
|
|
* @template [T=any]
|
|
* @param {any} value
|
|
* @returns {value is PromiseLike<T>}
|
|
*/
|
|
function is_promise(value) {
|
|
return typeof value?.then === "function";
|
|
}
|
|
/** @param {Function} fn */
|
|
function run$1(fn) {
|
|
return fn();
|
|
}
|
|
/** @param {Array<() => void>} arr */
|
|
function run_all(arr) {
|
|
for (var i = 0; i < arr.length; i++) arr[i]();
|
|
}
|
|
/**
|
|
* TODO replace with Promise.withResolvers once supported widely enough
|
|
* @template [T=void]
|
|
*/
|
|
function deferred() {
|
|
/** @type {(value: T) => void} */
|
|
var resolve;
|
|
/** @type {(reason: any) => void} */
|
|
var reject;
|
|
return {
|
|
promise: new Promise((res, rej) => {
|
|
resolve = res;
|
|
reject = rej;
|
|
}),
|
|
resolve,
|
|
reject
|
|
};
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {V} value
|
|
* @param {V | (() => V)} fallback
|
|
* @param {boolean} [lazy]
|
|
* @returns {V}
|
|
*/
|
|
function fallback(value, fallback, lazy = false) {
|
|
return value === void 0 ? lazy ? fallback() : fallback : value;
|
|
}
|
|
/**
|
|
* When encountering a situation like `let [a, b, c] = $derived(blah())`,
|
|
* we need to stash an intermediate value that `a`, `b`, and `c` derive
|
|
* from, in case it's an iterable
|
|
* @template T
|
|
* @param {ArrayLike<T> | Iterable<T>} value
|
|
* @param {number} [n]
|
|
* @returns {Array<T>}
|
|
*/
|
|
function to_array(value, n) {
|
|
if (Array.isArray(value)) return value;
|
|
if (n === void 0 || !(Symbol.iterator in value)) return Array.from(value);
|
|
/** @type {T[]} */
|
|
const array = [];
|
|
for (const element of value) {
|
|
array.push(element);
|
|
if (array.length === n) break;
|
|
}
|
|
return array;
|
|
}
|
|
/**
|
|
* @param {Record<string | symbol, unknown>} obj
|
|
* @param {Array<string | symbol>} keys
|
|
* @returns {Record<string | symbol, unknown>}
|
|
*/
|
|
function exclude_from_object(obj, keys) {
|
|
/** @type {Record<string | symbol, unknown>} */
|
|
var result = {};
|
|
for (var key in obj) if (!keys.includes(key)) result[key] = obj[key];
|
|
for (var symbol of Object.getOwnPropertySymbols(obj)) if (Object.propertyIsEnumerable.call(obj, symbol) && !keys.includes(symbol)) result[symbol] = obj[symbol];
|
|
return result;
|
|
}
|
|
// node_modules/svelte/src/internal/client/constants.js
|
|
/**
|
|
* An effect that does not destroy its child effects when it reruns.
|
|
* Runs as part of render effects, i.e. not eagerly as part of tree traversal or effect flushing.
|
|
*/
|
|
var MANAGED_EFFECT = 1 << 24;
|
|
var CLEAN = 1024;
|
|
var DIRTY = 2048;
|
|
var MAYBE_DIRTY = 4096;
|
|
var INERT = 8192;
|
|
var DESTROYED = 16384;
|
|
/** Set once a reaction has run for the first time */
|
|
var REACTION_RAN = 32768;
|
|
/** Effect is in the process of getting destroyed. Can be observed in child teardown functions */
|
|
var DESTROYING = 1 << 25;
|
|
/**
|
|
* 'Transparent' effects do not create a transition boundary.
|
|
* This is on a block effect 99% of the time but may also be on a branch effect if its parent block effect was pruned
|
|
*/
|
|
var EFFECT_TRANSPARENT = 65536;
|
|
var EAGER_EFFECT = 1 << 17;
|
|
var HEAD_EFFECT = 1 << 18;
|
|
var EFFECT_PRESERVED = 1 << 19;
|
|
var USER_EFFECT = 1 << 20;
|
|
var EFFECT_OFFSCREEN = 1 << 25;
|
|
var REACTION_IS_UPDATING = 1 << 21;
|
|
var ASYNC = 1 << 22;
|
|
var ERROR_VALUE = 1 << 23;
|
|
var STATE_SYMBOL = Symbol("$state");
|
|
/** Marks component export objects, so that `proxy(...)` leaves them untouched */
|
|
var COMPONENT_SYMBOL = Symbol("component");
|
|
var LEGACY_PROPS = Symbol("legacy props");
|
|
var LOADING_ATTR_SYMBOL = Symbol("");
|
|
var PROXY_PATH_SYMBOL = Symbol("proxy path");
|
|
var ATTRIBUTES_CACHE = Symbol("attributes");
|
|
var CLASS_CACHE = Symbol("class");
|
|
var STYLE_CACHE = Symbol("style");
|
|
var TEXT_CACHE = Symbol("text");
|
|
var FORM_RESET_HANDLER = Symbol("form reset");
|
|
/** An anchor might change, via this symbol on the original anchor we can tell HMR about the updated anchor */
|
|
var HMR_ANCHOR = Symbol("hmr anchor");
|
|
/** allow users to ignore aborted signal errors if `reason.name === 'StaleReactionError` */
|
|
var STALE_REACTION = new class StaleReactionError extends Error {
|
|
name = "StaleReactionError";
|
|
message = "The reaction that called `getAbortSignal()` was re-run or destroyed";
|
|
}();
|
|
var IS_XHTML = !!globalThis.document?.contentType && /* @__PURE__ */ globalThis.document.contentType.includes("xml");
|
|
// node_modules/svelte/src/constants.js
|
|
var HYDRATION_ERROR = {};
|
|
var UNINITIALIZED = Symbol("uninitialized");
|
|
var FILENAME = Symbol("filename");
|
|
var HMR = Symbol("hmr");
|
|
var NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
|
|
var NAMESPACE_SVG = "http://www.w3.org/2000/svg";
|
|
var NAMESPACE_MATHML = "http://www.w3.org/1998/Math/MathML";
|
|
var ATTACHMENT_KEY = "@attach";
|
|
// node_modules/svelte/src/internal/client/dom/hydration.js
|
|
/** @import { TemplateNode } from '#client' */
|
|
/**
|
|
* Use this variable to guard everything related to hydration code so it can be treeshaken out
|
|
* if the user doesn't use the `hydrate` method and these code paths are therefore not needed.
|
|
*/
|
|
var hydrating = false;
|
|
/** @param {boolean} value */
|
|
function set_hydrating(value) {
|
|
hydrating = value;
|
|
}
|
|
/**
|
|
* The node that is currently being hydrated. This starts out as the first node inside the opening
|
|
* <!--[--> comment, and updates each time a component calls `$.child(...)` or `$.sibling(...)`.
|
|
* When entering a block (e.g. `{#if ...}`), `hydrate_node` is the block opening comment; by the
|
|
* time we leave the block it is the closing comment, which serves as the block's anchor.
|
|
* @type {TemplateNode}
|
|
*/
|
|
var hydrate_node;
|
|
/** @param {TemplateNode | null} 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));
|
|
}
|
|
/** @param {TemplateNode} node */
|
|
function reset(node) {
|
|
if (!hydrating) return;
|
|
if (/* @__PURE__ */ get_next_sibling(hydrate_node) !== null) {
|
|
hydration_mismatch();
|
|
throw HYDRATION_ERROR;
|
|
}
|
|
hydrate_node = node;
|
|
}
|
|
/**
|
|
* @param {HTMLTemplateElement} template
|
|
*/
|
|
function hydrate_template(template) {
|
|
if (hydrating) hydrate_node = template.content;
|
|
}
|
|
function next(count = 1) {
|
|
if (hydrating) {
|
|
var i = count;
|
|
var node = hydrate_node;
|
|
while (i--) node = /* @__PURE__ */ get_next_sibling(node);
|
|
hydrate_node = node;
|
|
}
|
|
}
|
|
/**
|
|
* Skips or removes (depending on {@link remove}) all nodes starting at `hydrate_node` up until the next hydration end comment
|
|
* @param {boolean} remove
|
|
*/
|
|
function skip_nodes(remove = true) {
|
|
var depth = 0;
|
|
var node = hydrate_node;
|
|
while (true) {
|
|
if (node.nodeType === 8) {
|
|
var data = node.data;
|
|
if (data === "]") {
|
|
if (depth === 0) return node;
|
|
depth -= 1;
|
|
} else if (data === "[" || data === "[!" || data[0] === "[" && !isNaN(Number(data.slice(1)))) depth += 1;
|
|
}
|
|
var next = /* @__PURE__ */ get_next_sibling(node);
|
|
if (remove) node.remove();
|
|
node = next;
|
|
}
|
|
}
|
|
/**
|
|
*
|
|
* @param {TemplateNode} node
|
|
*/
|
|
function read_hydration_instruction(node) {
|
|
if (!node || node.nodeType !== 8) {
|
|
hydration_mismatch();
|
|
throw HYDRATION_ERROR;
|
|
}
|
|
return node.data;
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/equality.js
|
|
/** @import { Equals } from '#client' */
|
|
/** @type {Equals} */
|
|
function equals$1(value) {
|
|
return value === this.v;
|
|
}
|
|
/**
|
|
* @param {unknown} a
|
|
* @param {unknown} b
|
|
* @returns {boolean}
|
|
*/
|
|
function safe_not_equal(a, b) {
|
|
return a != a ? b == b : a !== b || a !== null && typeof a === "object" || typeof a === "function";
|
|
}
|
|
/** @type {Equals} */
|
|
function safe_equals(value) {
|
|
return !safe_not_equal(value, this.v);
|
|
}
|
|
// node_modules/svelte/src/internal/shared/errors.js
|
|
/**
|
|
* Cannot use `%name%(...)` unless the `experimental.async` compiler option is `true`
|
|
* @param {string} name
|
|
* @returns {never}
|
|
*/
|
|
function experimental_async_required(name) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`experimental_async_required\nCannot use \`${name}(...)\` unless the \`experimental.async\` compiler option is \`true\`\nhttps://svelte.dev/e/experimental_async_required`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead
|
|
* @returns {never}
|
|
*/
|
|
function invalid_default_snippet() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`invalid_default_snippet\nCannot use \`{@render children(...)}\` if the parent component uses \`let:\` directives. Consider using a named snippet instead\nhttps://svelte.dev/e/invalid_default_snippet`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* A snippet function was passed invalid arguments. Snippets should only be instantiated via `{@render ...}`
|
|
* @returns {never}
|
|
*/
|
|
function invalid_snippet_arguments() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`invalid_snippet_arguments\nA snippet function was passed invalid arguments. Snippets should only be instantiated via \`{@render ...}\`\nhttps://svelte.dev/e/invalid_snippet_arguments`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* An invariant violation occurred, meaning Svelte's internal assumptions were flawed. This is a bug in Svelte, not your app — please open an issue at https://github.com/sveltejs/svelte, citing the following message: "%message%"
|
|
* @param {string} message
|
|
* @returns {never}
|
|
*/
|
|
function invariant_violation(message) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`invariant_violation\nAn invariant violation occurred, meaning Svelte's internal assumptions were flawed. This is a bug in Svelte, not your app — please open an issue at https://github.com/sveltejs/svelte, citing the following message: "${message}"\nhttps://svelte.dev/e/invariant_violation`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `%name%(...)` can only be used during component initialisation
|
|
* @param {string} name
|
|
* @returns {never}
|
|
*/
|
|
function lifecycle_outside_component(name) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`lifecycle_outside_component\n\`${name}(...)\` can only be used during component initialisation\nhttps://svelte.dev/e/lifecycle_outside_component`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Context was not set in the current component or any of its ancestors
|
|
* @returns {never}
|
|
*/
|
|
function missing_context() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`missing_context\nContext was not set in the current component or any of its ancestors\nhttps://svelte.dev/e/missing_context`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression
|
|
* @returns {never}
|
|
*/
|
|
function set_context_after_init() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`set_context_after_init\n\`setContext\` must be called when a component first initializes, not in a subsequent effect or after an \`await\` expression\nhttps://svelte.dev/e/set_context_after_init`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Attempted to render a snippet without a `{@render}` block. This would cause the snippet code to be stringified instead of its content being rendered to the DOM. To fix this, change `{snippet}` to `{@render snippet()}`.
|
|
* @returns {never}
|
|
*/
|
|
function snippet_without_render_tag() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`snippet_without_render_tag\nAttempted to render a snippet without a \`{@render}\` block. This would cause the snippet code to be stringified instead of its content being rendered to the DOM. To fix this, change \`{snippet}\` to \`{@render snippet()}\`.\nhttps://svelte.dev/e/snippet_without_render_tag`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `%name%` is not a store with a `subscribe` method
|
|
* @param {string} name
|
|
* @returns {never}
|
|
*/
|
|
function store_invalid_shape(name) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`store_invalid_shape\n\`${name}\` is not a store with a \`subscribe\` method\nhttps://svelte.dev/e/store_invalid_shape`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* The `this` prop on `<svelte:element>` must be a string, if defined
|
|
* @returns {never}
|
|
*/
|
|
function svelte_element_invalid_this_value() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`svelte_element_invalid_this_value\nThe \`this\` prop on \`<svelte:element>\` must be a string, if defined\nhttps://svelte.dev/e/svelte_element_invalid_this_value`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/errors.js
|
|
/**
|
|
* Cannot create a `$derived(...)` with an `await` expression outside of an effect tree
|
|
* @returns {never}
|
|
*/
|
|
function async_derived_orphan() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`async_derived_orphan\nCannot create a \`$derived(...)\` with an \`await\` expression outside of an effect tree\nhttps://svelte.dev/e/async_derived_orphan`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead
|
|
* @returns {never}
|
|
*/
|
|
function bind_invalid_checkbox_value() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`bind_invalid_checkbox_value\nUsing \`bind:value\` together with a checkbox input is not allowed. Use \`bind:checked\` instead\nhttps://svelte.dev/e/bind_invalid_checkbox_value`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Calling `%method%` on a component instance (of %component%) is no longer valid in Svelte 5
|
|
* @param {string} method
|
|
* @param {string} component
|
|
* @returns {never}
|
|
*/
|
|
function component_api_changed(method, component) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`component_api_changed\nCalling \`${method}\` on a component instance (of ${component}) is no longer valid in Svelte 5\nhttps://svelte.dev/e/component_api_changed`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.componentApi` compiler option to `4` to keep it working.
|
|
* @param {string} component
|
|
* @param {string} name
|
|
* @returns {never}
|
|
*/
|
|
function component_api_invalid_new(component, name) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`component_api_invalid_new\nAttempted to instantiate ${component} with \`new ${name}\`, which is no longer valid in Svelte 5. If this component is not under your control, set the \`compatibility.componentApi\` compiler option to \`4\` to keep it working.\nhttps://svelte.dev/e/component_api_invalid_new`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* A derived value cannot reference itself recursively
|
|
* @returns {never}
|
|
*/
|
|
function derived_references_self() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`derived_references_self\nA derived value cannot reference itself recursively\nhttps://svelte.dev/e/derived_references_self`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Keyed each block has duplicate key `%value%` at indexes %a% and %b%
|
|
* @param {string} a
|
|
* @param {string} b
|
|
* @param {string | undefined | null} [value]
|
|
* @returns {never}
|
|
*/
|
|
function each_key_duplicate(a, b, value) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`each_key_duplicate\n${value ? `Keyed each block has duplicate key \`${value}\` at indexes ${a} and ${b}` : `Keyed each block has duplicate key at indexes ${a} and ${b}`}\nhttps://svelte.dev/e/each_key_duplicate`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Keyed each block has key that is not idempotent — the key for item at index %index% was `%a%` but is now `%b%`. Keys must be the same each time for a given item
|
|
* @param {string} index
|
|
* @param {string} a
|
|
* @param {string} b
|
|
* @returns {never}
|
|
*/
|
|
function each_key_volatile(index, a, b) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`each_key_volatile\nKeyed each block has key that is not idempotent — the key for item at index ${index} was \`${a}\` but is now \`${b}\`. Keys must be the same each time for a given item\nhttps://svelte.dev/e/each_key_volatile`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `%rune%` cannot be used inside an effect cleanup function
|
|
* @param {string} rune
|
|
* @returns {never}
|
|
*/
|
|
function effect_in_teardown(rune) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`effect_in_teardown\n\`${rune}\` cannot be used inside an effect cleanup function\nhttps://svelte.dev/e/effect_in_teardown`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Effect cannot be created inside a `$derived` value that was not itself created inside an effect
|
|
* @returns {never}
|
|
*/
|
|
function effect_in_unowned_derived() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`effect_in_unowned_derived\nEffect cannot be created inside a \`$derived\` value that was not itself created inside an effect\nhttps://svelte.dev/e/effect_in_unowned_derived`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `%rune%` can only be used inside an effect (e.g. during component initialisation)
|
|
* @param {string} rune
|
|
* @returns {never}
|
|
*/
|
|
function effect_orphan(rune) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`effect_orphan\n\`${rune}\` can only be used inside an effect (e.g. during component initialisation)\nhttps://svelte.dev/e/effect_orphan`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `$effect.pending()` can only be called inside an effect or derived
|
|
* @returns {never}
|
|
*/
|
|
function effect_pending_outside_reaction() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`effect_pending_outside_reaction\n\`$effect.pending()\` can only be called inside an effect or derived\nhttps://svelte.dev/e/effect_pending_outside_reaction`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Maximum update depth exceeded. This typically indicates that an effect reads and writes the same piece of state
|
|
* @returns {never}
|
|
*/
|
|
function effect_update_depth_exceeded() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`effect_update_depth_exceeded\nMaximum update depth exceeded. This typically indicates that an effect reads and writes the same piece of state\nhttps://svelte.dev/e/effect_update_depth_exceeded`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Cannot commit a fork that was already discarded
|
|
* @returns {never}
|
|
*/
|
|
function fork_discarded() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`fork_discarded\nCannot commit a fork that was already discarded\nhttps://svelte.dev/e/fork_discarded`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Cannot create a fork inside an effect or when state changes are pending
|
|
* @returns {never}
|
|
*/
|
|
function fork_timing() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`fork_timing\nCannot create a fork inside an effect or when state changes are pending\nhttps://svelte.dev/e/fork_timing`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `getAbortSignal()` can only be called inside an effect or derived
|
|
* @returns {never}
|
|
*/
|
|
function get_abort_signal_outside_reaction() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`get_abort_signal_outside_reaction\n\`getAbortSignal()\` can only be called inside an effect or derived\nhttps://svelte.dev/e/get_abort_signal_outside_reaction`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Expected to find a hydratable with key `%key%` during hydration, but did not.
|
|
* @param {string} key
|
|
* @returns {never}
|
|
*/
|
|
function hydratable_missing_but_required(key) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`hydratable_missing_but_required\nExpected to find a hydratable with key \`${key}\` during hydration, but did not.\nhttps://svelte.dev/e/hydratable_missing_but_required`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Failed to hydrate the application
|
|
* @returns {never}
|
|
*/
|
|
function hydration_failed() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`hydration_failed\nFailed to hydrate the application\nhttps://svelte.dev/e/hydration_failed`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Could not `{@render}` snippet due to the expression being `null` or `undefined`. Consider using optional chaining `{@render snippet?.()}`
|
|
* @returns {never}
|
|
*/
|
|
function invalid_snippet() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`invalid_snippet\nCould not \`{@render}\` snippet due to the expression being \`null\` or \`undefined\`. Consider using optional chaining \`{@render snippet?.()}\`\nhttps://svelte.dev/e/invalid_snippet`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* `%name%(...)` cannot be used in runes mode
|
|
* @param {string} name
|
|
* @returns {never}
|
|
*/
|
|
function lifecycle_legacy_only(name) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`lifecycle_legacy_only\n\`${name}(...)\` cannot be used in runes mode\nhttps://svelte.dev/e/lifecycle_legacy_only`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value
|
|
* @param {string} key
|
|
* @returns {never}
|
|
*/
|
|
function props_invalid_value(key) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`props_invalid_value\nCannot do \`bind:${key}={undefined}\` when \`${key}\` has a fallback value\nhttps://svelte.dev/e/props_invalid_value`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Rest element properties of `$props()` such as `%property%` are readonly
|
|
* @param {string} property
|
|
* @returns {never}
|
|
*/
|
|
function props_rest_readonly(property) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`props_rest_readonly\nRest element properties of \`$props()\` such as \`${property}\` are readonly\nhttps://svelte.dev/e/props_rest_readonly`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files
|
|
* @param {string} rune
|
|
* @returns {never}
|
|
*/
|
|
function rune_outside_svelte(rune) {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`rune_outside_svelte\nThe \`${rune}\` rune is only available inside \`.svelte\` and \`.svelte.js/ts\` files\nhttps://svelte.dev/e/rune_outside_svelte`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
|
|
* @returns {never}
|
|
*/
|
|
function state_descriptors_fixed() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`state_descriptors_fixed\nProperty descriptors defined on \`$state\` objects must contain \`value\` and always be \`enumerable\`, \`configurable\` and \`writable\`.\nhttps://svelte.dev/e/state_descriptors_fixed`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Cannot set prototype of `$state` object
|
|
* @returns {never}
|
|
*/
|
|
function state_prototype_fixed() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`state_prototype_fixed\nCannot set prototype of \`$state\` object\nhttps://svelte.dev/e/state_prototype_fixed`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* Updating state inside `$derived(...)`, `$inspect(...)` or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
|
|
* @returns {never}
|
|
*/
|
|
function state_unsafe_mutation() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`state_unsafe_mutation\nUpdating state inside \`$derived(...)\`, \`$inspect(...)\` or a template expression is forbidden. If the value should not be reactive, declare it without \`$state\`\nhttps://svelte.dev/e/state_unsafe_mutation`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
/**
|
|
* A `<svelte:boundary>` `reset` function cannot be called while an error is still being handled
|
|
* @returns {never}
|
|
*/
|
|
function svelte_boundary_reset_onerror() {
|
|
{
|
|
const error = /* @__PURE__ */ new Error(`svelte_boundary_reset_onerror\nA \`<svelte:boundary>\` \`reset\` function cannot be called while an error is still being handled\nhttps://svelte.dev/e/svelte_boundary_reset_onerror`);
|
|
error.name = "Svelte error";
|
|
throw error;
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/shared/warnings.js
|
|
var bold = "font-weight: bold";
|
|
var normal = "font-weight: normal";
|
|
/**
|
|
* `<svelte:element this="%tag%">` is a void element — it cannot have content
|
|
* @param {string} tag
|
|
*/
|
|
function dynamic_void_element_content(tag) {
|
|
console.warn(`%c[svelte] dynamic_void_element_content\n%c\`<svelte:element this="${tag}">\` is a void element — it cannot have content\nhttps://svelte.dev/e/dynamic_void_element_content`, bold, normal);
|
|
}
|
|
/**
|
|
* The following properties cannot be cloned with `$state.snapshot` — the return value contains the originals:
|
|
*
|
|
* %properties%
|
|
* @param {string | undefined | null} [properties]
|
|
*/
|
|
function state_snapshot_uncloneable(properties) {
|
|
console.warn(`%c[svelte] state_snapshot_uncloneable\n%c${properties ? `The following properties cannot be cloned with \`$state.snapshot\` — the return value contains the originals:
|
|
|
|
${properties}` : "Value cannot be cloned with `$state.snapshot` — the original value was returned"}\nhttps://svelte.dev/e/state_snapshot_uncloneable`, bold, normal);
|
|
}
|
|
// node_modules/svelte/src/internal/shared/clone.js
|
|
/** @import { Snapshot } from './types' */
|
|
/**
|
|
* In dev, we keep track of which properties could not be cloned. In prod
|
|
* we don't bother, but we keep a dummy array around so that the
|
|
* signature stays the same
|
|
* @type {string[]}
|
|
*/
|
|
var empty = [];
|
|
/**
|
|
* @template T
|
|
* @param {T} value
|
|
* @param {boolean} [skip_warning]
|
|
* @param {boolean} [no_tojson]
|
|
* @returns {Snapshot<T>}
|
|
*/
|
|
function snapshot(value, skip_warning = false, no_tojson = false) {
|
|
if (!skip_warning) {
|
|
/** @type {string[]} */
|
|
const paths = [];
|
|
const copy = clone(value, /* @__PURE__ */ new Map(), "", paths, null, no_tojson);
|
|
if (paths.length === 1 && paths[0] === "") state_snapshot_uncloneable();
|
|
else if (paths.length > 0) {
|
|
const slice = paths.length > 10 ? paths.slice(0, 7) : paths.slice(0, 10);
|
|
const excess = paths.length - slice.length;
|
|
let uncloned = slice.map((path) => `- <value>${path}`).join("\n");
|
|
if (excess > 0) uncloned += `\n- ...and ${excess} more`;
|
|
state_snapshot_uncloneable(uncloned);
|
|
}
|
|
return copy;
|
|
}
|
|
return clone(value, /* @__PURE__ */ new Map(), "", empty, null, no_tojson);
|
|
}
|
|
/**
|
|
* @template T
|
|
* @param {T} value
|
|
* @param {Map<T, Snapshot<T>>} cloned
|
|
* @param {string} path
|
|
* @param {string[]} paths
|
|
* @param {null | T} [original] The original value, if `value` was produced from a `toJSON` call
|
|
* @param {boolean} [no_tojson]
|
|
* @returns {Snapshot<T>}
|
|
*/
|
|
function clone(value, cloned, path, paths, original = null, no_tojson = false) {
|
|
if (typeof value === "object" && value !== null) {
|
|
var unwrapped = cloned.get(value);
|
|
if (unwrapped !== void 0) return unwrapped;
|
|
if (value instanceof Map) return new Map(value);
|
|
if (value instanceof Set) return new Set(value);
|
|
if (is_array(value)) {
|
|
var copy = Array(value.length);
|
|
cloned.set(value, copy);
|
|
if (original !== null) cloned.set(original, copy);
|
|
for (var i = 0; i < value.length; i += 1) {
|
|
var element = value[i];
|
|
if (i in value) copy[i] = clone(element, cloned, `${path}[${i}]`, paths, null, no_tojson);
|
|
}
|
|
return copy;
|
|
}
|
|
if (get_prototype_of(value) === object_prototype) {
|
|
/** @type {Snapshot<any>} */
|
|
copy = {};
|
|
cloned.set(value, copy);
|
|
if (original !== null) cloned.set(original, copy);
|
|
for (var key of Object.keys(value)) copy[key] = clone(value[key], cloned, `${path}.${key}`, paths, null, no_tojson);
|
|
return copy;
|
|
}
|
|
if (value instanceof Date) {
|
|
value.getTime();
|
|
return structuredClone(value);
|
|
}
|
|
if (typeof value.toJSON === "function" && !no_tojson) return clone(
|
|
/** @type {T & { toJSON(): any } } */
|
|
value.toJSON(),
|
|
cloned,
|
|
`${path}.toJSON()`,
|
|
paths,
|
|
value
|
|
);
|
|
}
|
|
if (value instanceof EventTarget) return value;
|
|
try {
|
|
return structuredClone(value);
|
|
} catch (e) {
|
|
paths.push(path);
|
|
return value;
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/dev/tracing.js
|
|
/** @import { Derived, Reaction, Value } from '#client' */
|
|
/**
|
|
* @typedef {{
|
|
* traces: Error[];
|
|
* }} TraceEntry
|
|
*/
|
|
/** @type {{ reaction: Reaction | null, entries: Map<Value, TraceEntry> } | null} */
|
|
var tracing_expressions = null;
|
|
/**
|
|
* @param {Value} signal
|
|
* @param {TraceEntry} [entry]
|
|
*/
|
|
function log_entry(signal, entry) {
|
|
const value = signal.v;
|
|
if (value === UNINITIALIZED) return;
|
|
const type = get_type(signal);
|
|
const current_reaction = active_reaction;
|
|
const dirty = signal.wv > current_reaction.wv || current_reaction.wv === 0;
|
|
const style = dirty ? "color: CornflowerBlue; font-weight: bold" : "color: grey; font-weight: normal";
|
|
console.groupCollapsed(signal.label ? `%c${type}%c ${signal.label}` : `%c${type}%c`, style, dirty ? "font-weight: normal" : style, typeof value === "object" && value !== null && STATE_SYMBOL in value ? snapshot(value, true) : value);
|
|
if (type === "$derived") {
|
|
const deps = new Set(
|
|
/** @type {Derived} */
|
|
signal.deps
|
|
);
|
|
for (const dep of deps) log_entry(dep);
|
|
}
|
|
if (signal.created) console.log(signal.created);
|
|
if (dirty && signal.updated) {
|
|
for (const updated of signal.updated.values()) if (updated.error) console.log(updated.error);
|
|
}
|
|
if (entry) for (var trace of entry.traces) console.log(trace);
|
|
console.groupEnd();
|
|
}
|
|
/**
|
|
* @param {Value} signal
|
|
* @returns {'$state' | '$derived' | 'store'}
|
|
*/
|
|
function get_type(signal) {
|
|
if ((signal.f & 4194306) !== 0) return "$derived";
|
|
return signal.label?.startsWith("$") ? "store" : "$state";
|
|
}
|
|
/**
|
|
* @template T
|
|
* @param {() => string} label
|
|
* @param {() => T} fn
|
|
*/
|
|
function trace(label, fn) {
|
|
var previously_tracing_expressions = tracing_expressions;
|
|
try {
|
|
tracing_expressions = {
|
|
entries: /* @__PURE__ */ new Map(),
|
|
reaction: active_reaction
|
|
};
|
|
var start = performance.now();
|
|
var value = fn();
|
|
var time = (performance.now() - start).toFixed(2);
|
|
var prefix = untrack(label);
|
|
if (!effect_tracking()) console.log(`${prefix} %cran outside of an effect (${time}ms)`, "color: grey");
|
|
else if (tracing_expressions.entries.size === 0) console.log(`${prefix} %cno reactive dependencies (${time}ms)`, "color: grey");
|
|
else {
|
|
console.group(`${prefix} %c(${time}ms)`, "color: grey");
|
|
var entries = tracing_expressions.entries;
|
|
untrack(() => {
|
|
for (const [signal, traces] of entries) log_entry(signal, traces);
|
|
});
|
|
tracing_expressions = null;
|
|
console.groupEnd();
|
|
}
|
|
return value;
|
|
} finally {
|
|
tracing_expressions = previously_tracing_expressions;
|
|
}
|
|
}
|
|
/**
|
|
* @template {Value} T
|
|
* @param {T} source
|
|
* @param {string} label
|
|
* @returns {T}
|
|
*/
|
|
function tag(source, label) {
|
|
source.label = label;
|
|
tag_proxy(source.v, label);
|
|
return source;
|
|
}
|
|
/**
|
|
* @param {unknown} value
|
|
* @param {string} label
|
|
*/
|
|
function tag_proxy(value, label) {
|
|
value?.[PROXY_PATH_SYMBOL]?.(label);
|
|
return value;
|
|
}
|
|
/**
|
|
* @param {unknown} value
|
|
*/
|
|
function label(value) {
|
|
if (typeof value === "symbol") return `Symbol(${value.description})`;
|
|
if (typeof value === "function") return "<function>";
|
|
if (typeof value === "object" && value) return "<object>";
|
|
return String(value);
|
|
}
|
|
// node_modules/svelte/src/internal/shared/dev.js
|
|
/**
|
|
* @param {string} label
|
|
* @returns {Error & { stack: string } | null}
|
|
*/
|
|
function get_error(label) {
|
|
const error = /* @__PURE__ */ new Error();
|
|
const stack = get_stack();
|
|
if (stack.length === 0) return null;
|
|
stack.unshift("\n");
|
|
define_property(error, "stack", { value: stack.join("\n") });
|
|
define_property(error, "name", { value: label });
|
|
return error;
|
|
}
|
|
/**
|
|
* @returns {string[]}
|
|
*/
|
|
function get_stack() {
|
|
const limit = Error.stackTraceLimit;
|
|
Error.stackTraceLimit = Infinity;
|
|
const stack = (/* @__PURE__ */ new Error()).stack;
|
|
Error.stackTraceLimit = limit;
|
|
if (!stack) return [];
|
|
const lines = stack.split("\n");
|
|
const new_lines = [];
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const line = lines[i];
|
|
const posixified = line.replaceAll("\\", "/");
|
|
if (line.trim() === "Error") continue;
|
|
if (line.includes("validate_each_keys")) return [];
|
|
if (posixified.includes("svelte/src/internal") || posixified.includes("node_modules/.vite")) continue;
|
|
new_lines.push(line);
|
|
}
|
|
return new_lines;
|
|
}
|
|
/**
|
|
* @param {boolean} condition
|
|
* @param {string} message
|
|
*/
|
|
function invariant(condition, message) {
|
|
if (!condition) invariant_violation(message);
|
|
}
|
|
// node_modules/svelte/src/internal/shared/context.js
|
|
/**
|
|
* @template T
|
|
* @param {(key: object) => T} get_context
|
|
* @param {(key: object, context: T) => T} set_context
|
|
* @param {(key: object) => boolean} has_context
|
|
* @returns {[() => T, (context: T) => T, () => boolean]}
|
|
*/
|
|
function create_context(get_context, set_context, has_context) {
|
|
const key = {};
|
|
return [
|
|
() => {
|
|
if (!has_context(key)) missing_context();
|
|
return get_context(key);
|
|
},
|
|
(context) => set_context(key, context),
|
|
() => has_context(key)
|
|
];
|
|
}
|
|
/**
|
|
* @typedef {{ p: Context | null, c: Map<unknown, unknown> | null }} Context
|
|
*/
|
|
/**
|
|
* @param {Context} context
|
|
* @returns {Map<unknown, unknown> | null}
|
|
*/
|
|
function get_parent_context(context) {
|
|
let parent = context.p;
|
|
while (parent !== null && parent.c === null) parent = parent.p;
|
|
return parent?.c ?? null;
|
|
}
|
|
/**
|
|
* @param {Context | null} context
|
|
* @param {string} name
|
|
* @returns {Map<unknown, unknown>}
|
|
*/
|
|
function get_or_init_context_map(context, name) {
|
|
if (context === null) lifecycle_outside_component(name);
|
|
return context.c ??= new Map(get_parent_context(context) || void 0);
|
|
}
|
|
// node_modules/svelte/src/internal/client/context.js
|
|
/** @import { ComponentContext, DevStackEntry, Effect } from '#client' */
|
|
/** @type {ComponentContext | null} */
|
|
var component_context = null;
|
|
/** @param {ComponentContext | null} context */
|
|
function set_component_context(context) {
|
|
component_context = context;
|
|
}
|
|
/** @type {DevStackEntry | null} */
|
|
var dev_stack = null;
|
|
/** @param {DevStackEntry | null} stack */
|
|
function set_dev_stack(stack) {
|
|
dev_stack = stack;
|
|
}
|
|
/**
|
|
* Execute a callback with a new dev stack entry
|
|
* @param {() => any} callback - Function to execute
|
|
* @param {DevStackEntry['type']} type - Type of block/component
|
|
* @param {any} component - Component function
|
|
* @param {number} line - Line number
|
|
* @param {number} column - Column number
|
|
* @param {Record<string, any>} [additional] - Any additional properties to add to the dev stack entry
|
|
* @returns {any}
|
|
*/
|
|
function add_svelte_meta(callback, type, component, line, column, additional) {
|
|
const parent = dev_stack;
|
|
dev_stack = {
|
|
type,
|
|
file: component[FILENAME],
|
|
line,
|
|
column,
|
|
parent,
|
|
...additional
|
|
};
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
dev_stack = parent;
|
|
}
|
|
}
|
|
/**
|
|
* The current component function. Different from current component context:
|
|
* ```html
|
|
* <!-- App.svelte -->
|
|
* <Foo>
|
|
* <Bar /> <!-- context == Foo.svelte, function == App.svelte -->
|
|
* </Foo>
|
|
* ```
|
|
* @type {ComponentContext['function']}
|
|
*/
|
|
var dev_current_component_function = null;
|
|
/** @param {ComponentContext['function']} fn */
|
|
function set_dev_current_component_function(fn) {
|
|
dev_current_component_function = fn;
|
|
}
|
|
/**
|
|
* Returns a `[get, set, has]` triplet of functions for working with context in a type-safe way.
|
|
*
|
|
* `get` will throw an error if `set` has not yet been called in the current component or any of
|
|
* its ancestors.
|
|
*
|
|
* @template T
|
|
* @returns {[() => T, (context: T) => T, () => boolean]}
|
|
* @since 5.40.0
|
|
*/
|
|
function createContext() {
|
|
return create_context(getContext, setContext, hasContext);
|
|
}
|
|
/**
|
|
* Retrieves the context set with the specified `key` in the current component or any of its
|
|
* ancestors. If multiple components set the same key, the value from the closest one is returned.
|
|
* A `setContext` call in the current component is only visible to `getContext` calls that run after it.
|
|
* Must be called during component initialisation.
|
|
*
|
|
* [`createContext`](https://svelte.dev/docs/svelte/svelte#createContext) is a type-safe alternative.
|
|
*
|
|
* @template T
|
|
* @param {any} key
|
|
* @returns {T}
|
|
*/
|
|
function getContext(key) {
|
|
return get_or_init_context_map(component_context, "getContext").get(key);
|
|
}
|
|
/**
|
|
* Associates an arbitrary `context` object with the current component and the specified `key`
|
|
* and returns that object. The context is then available to the component itself and all of its
|
|
* descendants (including slotted content) with `getContext`.
|
|
*
|
|
* Like lifecycle functions, this must be called during component initialisation.
|
|
*
|
|
* [`createContext`](https://svelte.dev/docs/svelte/svelte#createContext) is a type-safe alternative.
|
|
*
|
|
* @template T
|
|
* @param {any} key
|
|
* @param {T} context
|
|
* @returns {T}
|
|
*/
|
|
function setContext(key, context) {
|
|
const context_map = get_or_init_context_map(component_context, "setContext");
|
|
if (async_mode_flag) {
|
|
var flags = active_effect.f;
|
|
if (!(!active_reaction && (flags & 32) !== 0 && !component_context.i)) set_context_after_init();
|
|
}
|
|
context_map.set(key, context);
|
|
return context;
|
|
}
|
|
/**
|
|
* Checks whether a given `key` has been set in the context of the current component or any of
|
|
* its ancestors. Must be called during component initialisation.
|
|
*
|
|
* @param {any} key
|
|
* @returns {boolean}
|
|
*/
|
|
function hasContext(key) {
|
|
return get_or_init_context_map(component_context, "hasContext").has(key);
|
|
}
|
|
/**
|
|
* Retrieves the whole context map that belongs to the current component, including entries
|
|
* inherited from its ancestors. Must be called during component initialisation. Useful, for
|
|
* example, if you programmatically create a component and want to pass the existing context to it.
|
|
*
|
|
* @template {Map<any, any>} [T=Map<any, any>]
|
|
* @returns {T}
|
|
*/
|
|
function getAllContexts() {
|
|
return get_or_init_context_map(component_context, "getAllContexts");
|
|
}
|
|
/**
|
|
* @param {Record<string, unknown>} props
|
|
* @param {any} runes
|
|
* @param {Function} [fn]
|
|
* @returns {void}
|
|
*/
|
|
function push(props, runes = false, fn) {
|
|
component_context = {
|
|
p: component_context,
|
|
i: false,
|
|
c: null,
|
|
e: null,
|
|
s: props,
|
|
x: null,
|
|
r: active_effect,
|
|
l: legacy_mode_flag && !runes ? {
|
|
s: null,
|
|
u: null,
|
|
$: []
|
|
} : null
|
|
};
|
|
component_context.function = fn;
|
|
dev_current_component_function = fn;
|
|
}
|
|
/**
|
|
* @template {Record<string, any>} T
|
|
* @param {T} [component]
|
|
* @returns {T}
|
|
*/
|
|
function pop(component) {
|
|
var context = component_context;
|
|
var effects = context.e;
|
|
if (effects !== null) {
|
|
context.e = null;
|
|
for (var fn of effects) create_user_effect(fn);
|
|
}
|
|
if (component !== void 0) context.x = component;
|
|
context.i = true;
|
|
component_context = context.p;
|
|
dev_current_component_function = component_context?.function ?? null;
|
|
return mark_as_component(component);
|
|
}
|
|
/**
|
|
* Add a symbol to the object (or create one if undefined) to mark it as a component so it isn't proxified.
|
|
* @param {any} component
|
|
*/
|
|
function mark_as_component(component = {}) {
|
|
define_property(component, COMPONENT_SYMBOL, { value: true });
|
|
return component;
|
|
}
|
|
/** @returns {boolean} */
|
|
function is_runes() {
|
|
return !legacy_mode_flag || component_context !== null && component_context.l === null;
|
|
}
|
|
// node_modules/svelte/src/internal/client/dom/task.js
|
|
/** @type {Array<() => void>} */
|
|
var micro_tasks = [];
|
|
function run_micro_tasks() {
|
|
var tasks = micro_tasks;
|
|
micro_tasks = [];
|
|
run_all(tasks);
|
|
}
|
|
/**
|
|
* @param {() => void} fn
|
|
*/
|
|
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);
|
|
}
|
|
/**
|
|
* Synchronously run any queued tasks.
|
|
*/
|
|
function flush_tasks() {
|
|
while (micro_tasks.length > 0) run_micro_tasks();
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/status.js
|
|
/** @import { Derived, Signal } from '#client' */
|
|
var STATUS_MASK = ~(DIRTY | MAYBE_DIRTY | CLEAN);
|
|
/**
|
|
* @param {Signal} signal
|
|
* @param {number} status
|
|
*/
|
|
function set_signal_status(signal, status) {
|
|
signal.f = signal.f & STATUS_MASK | status;
|
|
}
|
|
/**
|
|
* Set a derived's status to CLEAN or MAYBE_DIRTY based on its connection state.
|
|
* @param {Derived} derived
|
|
*/
|
|
function update_derived_status(derived) {
|
|
if ((derived.f & 512) !== 0 || derived.deps === null) set_signal_status(derived, CLEAN);
|
|
else set_signal_status(derived, MAYBE_DIRTY);
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/utils.js
|
|
/** @import { Effect } from '#client' */
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {Map<Effect, number>} dirty_reactions
|
|
*/
|
|
function defer_effect(effect, dirty_reactions) {
|
|
if ((effect.f & 2048) !== 0) dirty_reactions.set(effect, DIRTY);
|
|
else if ((effect.f & 4096) !== 0 && dirty_reactions.get(effect) !== 2048) dirty_reactions.set(effect, MAYBE_DIRTY);
|
|
set_signal_status(effect, CLEAN);
|
|
}
|
|
// node_modules/svelte/src/internal/client/dev/debug.js
|
|
/**
|
|
* Stringify a derived function, removing `$.track_reactivity_loss` and `$.get` etc
|
|
* @param {Function} fn
|
|
*/
|
|
function stringify_derived(fn) {
|
|
return `{${fn.toString().replace(/^async \(\) => /, "").replace(/^\(/, "").replace(/\$\.get\((.+?)\)/g, (_, name) => name).replace(/\$\.track_reactivity_loss\((.+?)\)\(\)/g, (_, name) => name).replace(/\)$/, "")}}`;
|
|
}
|
|
// node_modules/svelte/src/internal/client/dom/elements/misc.js
|
|
/**
|
|
* @param {HTMLElement} dom
|
|
* @param {boolean} value
|
|
* @returns {void}
|
|
*/
|
|
function autofocus(dom, value) {
|
|
if (value) {
|
|
const body = document.body;
|
|
dom.autofocus = true;
|
|
queue_micro_task(() => {
|
|
if (document.activeElement === body) dom.focus();
|
|
});
|
|
}
|
|
}
|
|
/**
|
|
* The child of a textarea actually corresponds to the defaultValue property, so we need
|
|
* to remove it upon hydration to avoid a bug when someone resets the form value.
|
|
* @param {HTMLTextAreaElement} dom
|
|
* @returns {void}
|
|
*/
|
|
function remove_textarea_child(dom) {
|
|
if (hydrating && /* @__PURE__ */ get_first_child(dom) !== null) clear_text_content(dom);
|
|
}
|
|
var listening_to_form_reset = false;
|
|
function add_form_reset_listener() {
|
|
if (!listening_to_form_reset) {
|
|
listening_to_form_reset = true;
|
|
document.addEventListener("reset", (evt) => {
|
|
Promise.resolve().then(() => {
|
|
if (!evt.defaultPrevented) for (const e of evt.target.elements)
|
|
/** @type {any} */ e[FORM_RESET_HANDLER]?.();
|
|
});
|
|
}, { capture: true });
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/dom/elements/bindings/shared.js
|
|
/**
|
|
* Fires the handler once immediately (unless corresponding arg is set to `false`),
|
|
* then listens to the given events until the render effect context is destroyed
|
|
* @param {EventTarget} target
|
|
* @param {Array<string>} events
|
|
* @param {(event?: Event) => void} handler
|
|
* @param {any} call_handler_immediately
|
|
*/
|
|
function listen(target, events, handler, call_handler_immediately = true) {
|
|
if (call_handler_immediately) handler();
|
|
for (var name of events) target.addEventListener(name, handler);
|
|
teardown(() => {
|
|
for (var name of events) target.removeEventListener(name, handler);
|
|
});
|
|
}
|
|
/**
|
|
* @template T
|
|
* @param {() => T} fn
|
|
*/
|
|
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);
|
|
}
|
|
}
|
|
/**
|
|
* Listen to the given event, and then instantiate a global form reset listener if not already done,
|
|
* to notify all bindings when the form is reset
|
|
* @param {HTMLElement} element
|
|
* @param {string} event
|
|
* @param {(is_reset?: true) => void} handler
|
|
* @param {(is_reset?: true) => void} [on_reset]
|
|
*/
|
|
function listen_to_event_and_reset_event(element, event, handler, on_reset = handler) {
|
|
element.addEventListener(event, () => without_reactive_context(handler));
|
|
const prev = element[FORM_RESET_HANDLER];
|
|
if (prev)
|
|
/** @type {any} */ element[FORM_RESET_HANDLER] = () => {
|
|
prev();
|
|
on_reset(true);
|
|
};
|
|
else
|
|
/** @type {any} */ element[FORM_RESET_HANDLER] = () => on_reset(true);
|
|
add_form_reset_listener();
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/async.js
|
|
/** @import { Blocker, Effect, Source, Value } from '#client' */
|
|
/**
|
|
* @param {Blocker[]} blockers
|
|
* @param {Array<() => any>} sync
|
|
* @param {Array<() => Promise<any>>} async
|
|
* @param {(values: Value[]) => any} fn
|
|
*/
|
|
function flatten(blockers, sync, async, fn) {
|
|
const d = is_runes() ? derived : derived_safe_equal;
|
|
var pending = blockers.filter((b) => !b.settled);
|
|
var deriveds = sync.map(d);
|
|
deriveds.forEach((d, i) => {
|
|
d.label = sync[i].toString().replace("() => ", "").replaceAll("$.eager(() => ", "$state.eager(").replace(/\$\.get\((.+?)\)/g, (_, id) => id);
|
|
});
|
|
if (async.length === 0 && pending.length === 0) {
|
|
fn(deriveds);
|
|
return;
|
|
}
|
|
var parent = active_effect;
|
|
var restore = capture();
|
|
var blocker_promise = pending.length === 1 ? pending[0].promise : pending.length > 1 ? Promise.all(pending.map((b) => b.promise)) : null;
|
|
/**
|
|
* @param {Source[]} async
|
|
*/
|
|
function finish(async) {
|
|
if ((parent.f & 16384) !== 0) return;
|
|
restore();
|
|
try {
|
|
fn([...deriveds, ...async]);
|
|
} catch (error) {
|
|
invoke_error_boundary(error, parent);
|
|
}
|
|
unset_context();
|
|
}
|
|
var decrement_pending = increment_pending();
|
|
if (async.length === 0) {
|
|
/** @type {Promise<any>} */ blocker_promise.then(() => finish([])).finally(decrement_pending);
|
|
return;
|
|
}
|
|
function run() {
|
|
Promise.all(async.map((expression) => /* @__PURE__ */ async_derived(expression))).then(finish).catch((error) => invoke_error_boundary(error, parent)).finally(decrement_pending);
|
|
}
|
|
if (blocker_promise) blocker_promise.then(() => {
|
|
if ((parent.f & 16384) !== 0) {
|
|
decrement_pending();
|
|
return;
|
|
}
|
|
restore();
|
|
run();
|
|
unset_context();
|
|
});
|
|
else run();
|
|
}
|
|
/**
|
|
* @param {Blocker[]} blockers
|
|
* @param {(values: Value[]) => any} fn
|
|
*/
|
|
function run_after_blockers(blockers, fn) {
|
|
flatten(blockers, [], [], fn);
|
|
}
|
|
/**
|
|
* Captures the current effect context so that we can restore it after
|
|
* some asynchronous work has happened (so that e.g. `await a + b`
|
|
* causes `b` to be registered as a dependency).
|
|
*/
|
|
function capture() {
|
|
var previous_effect = active_effect;
|
|
var previous_reaction = active_reaction;
|
|
var previous_component_context = component_context;
|
|
var previous_batch = current_batch;
|
|
var previous_dev_stack = dev_stack;
|
|
return function restore(activate_batch = true) {
|
|
set_active_effect(previous_effect);
|
|
set_active_reaction(previous_reaction);
|
|
set_component_context(previous_component_context);
|
|
if (activate_batch && (previous_effect.f & 16384) === 0) {
|
|
previous_batch?.activate();
|
|
previous_batch?.apply();
|
|
}
|
|
set_reactivity_loss_tracker(null);
|
|
set_dev_stack(previous_dev_stack);
|
|
};
|
|
}
|
|
/** `true` between a `save` thunk restoring a context and the end of that synchronous segment */
|
|
var restored = false;
|
|
/**
|
|
* Wraps an `await` expression in such a way that the effect context that was
|
|
* active before the expression evaluated can be reapplied afterwards —
|
|
* `await a + b` becomes `(await $.save(a))() + b`
|
|
* @template T
|
|
* @param {Promise<T>} promise
|
|
* @returns {Promise<() => T>}
|
|
*/
|
|
async function save(promise) {
|
|
var restore = capture();
|
|
unsave();
|
|
var value = await promise;
|
|
return () => {
|
|
restore();
|
|
restored = true;
|
|
return value;
|
|
};
|
|
}
|
|
/**
|
|
* Unset the context if a `save` thunk restored it in the current synchronous segment,
|
|
* so that a foreign microtask can never run inside a restored reaction context.
|
|
* Called at every suspension point, and at the end of async expression bodies —
|
|
* `async () => (await $.save(a))().b` becomes `async () => { try { return (await $.save(a))().b; } finally { $.unsave(); } }`
|
|
* @template T
|
|
* @param {T} [value]
|
|
* @returns {T}
|
|
*/
|
|
function unsave(value) {
|
|
if (restored) unset_context();
|
|
return value;
|
|
}
|
|
/**
|
|
* Reset `current_async_effect` after the `promise` resolves, so
|
|
* that we can emit `await_reactivity_loss` warnings
|
|
* @template T
|
|
* @param {Promise<T>} promise
|
|
* @returns {Promise<() => T>}
|
|
*/
|
|
async function track_reactivity_loss(promise) {
|
|
unsave();
|
|
var previous_reactivity_loss_tracker = reactivity_loss_tracker;
|
|
queueMicrotask(() => {
|
|
if (reactivity_loss_tracker === previous_reactivity_loss_tracker) set_reactivity_loss_tracker(null);
|
|
});
|
|
var value = await promise;
|
|
return () => {
|
|
set_reactivity_loss_tracker(previous_reactivity_loss_tracker);
|
|
queueMicrotask(() => {
|
|
if (reactivity_loss_tracker === previous_reactivity_loss_tracker) set_reactivity_loss_tracker(null);
|
|
});
|
|
return value;
|
|
};
|
|
}
|
|
/**
|
|
* Used in `for await` loops in DEV, so
|
|
* that we can emit `await_reactivity_loss` warnings
|
|
* after each `async_iterator` result resolves and
|
|
* after the `async_iterator` return resolves (if it runs)
|
|
* @template T
|
|
* @template TReturn
|
|
* @param {Iterable<T> | AsyncIterable<T>} iterable
|
|
* @returns {AsyncGenerator<T, TReturn | undefined>}
|
|
*/
|
|
async function* for_await_track_reactivity_loss(iterable) {
|
|
/** @type {AsyncIterator<T, TReturn>} */
|
|
const iterator = iterable[Symbol.asyncIterator]?.() ?? iterable[Symbol.iterator]?.();
|
|
if (iterator === void 0) throw new TypeError("value is not async iterable");
|
|
let invoke_return = true;
|
|
try {
|
|
while (true) {
|
|
const { done, value } = (await track_reactivity_loss(iterator.next()))();
|
|
if (done) {
|
|
invoke_return = false;
|
|
break;
|
|
}
|
|
var prev = reactivity_loss_tracker;
|
|
try {
|
|
yield value;
|
|
} catch (e) {
|
|
set_reactivity_loss_tracker(prev);
|
|
if (iterator.return !== void 0) (await track_reactivity_loss(iterator.return()))();
|
|
throw e;
|
|
}
|
|
set_reactivity_loss_tracker(prev);
|
|
}
|
|
} catch (error) {
|
|
invoke_return = false;
|
|
throw error;
|
|
} finally {
|
|
if (invoke_return && iterator.return !== void 0) return (await track_reactivity_loss(iterator.return()))().value;
|
|
}
|
|
}
|
|
function unset_context(deactivate_batch = true) {
|
|
restored = false;
|
|
set_active_effect(null);
|
|
set_active_reaction(null);
|
|
set_component_context(null);
|
|
if (deactivate_batch) current_batch?.deactivate();
|
|
set_reactivity_loss_tracker(null);
|
|
set_dev_stack(null);
|
|
}
|
|
/**
|
|
* @param {Array<() => void | Promise<void>>} thunks
|
|
*/
|
|
function run(thunks) {
|
|
const restore = capture();
|
|
const decrement_pending = increment_pending();
|
|
var active = active_effect;
|
|
/** @type {null | { error: any }} */
|
|
var errored = null;
|
|
/** @param {any} error */
|
|
const handle_error = (error) => {
|
|
errored = { error };
|
|
if (!aborted(active)) invoke_error_boundary(error, active);
|
|
};
|
|
var promise = Promise.resolve(thunks[0]()).catch(handle_error);
|
|
/** @type {Blocker} */
|
|
var blocker = {
|
|
promise,
|
|
settled: false
|
|
};
|
|
var blockers = [blocker];
|
|
promise.finally(() => {
|
|
blocker.settled = true;
|
|
unset_context();
|
|
});
|
|
for (const fn of thunks.slice(1)) {
|
|
promise = promise.then(() => {
|
|
restore();
|
|
try {
|
|
if (errored) throw errored.error;
|
|
if (aborted(active)) throw STALE_REACTION;
|
|
return fn();
|
|
} finally {
|
|
unset_context();
|
|
}
|
|
}).catch(handle_error);
|
|
const blocker = {
|
|
promise,
|
|
settled: false
|
|
};
|
|
blockers.push(blocker);
|
|
promise.finally(() => {
|
|
blocker.settled = true;
|
|
unset_context();
|
|
});
|
|
}
|
|
promise.then(() => Promise.resolve()).finally(decrement_pending);
|
|
return blockers;
|
|
}
|
|
/**
|
|
* @param {Blocker[]} blockers
|
|
*/
|
|
function wait(blockers) {
|
|
return Promise.all(blockers.map((b) => b.promise));
|
|
}
|
|
/**
|
|
* @returns {(skip?: boolean) => void}
|
|
*/
|
|
function increment_pending() {
|
|
var effect = active_effect;
|
|
var boundary = effect.b;
|
|
var batch = current_batch;
|
|
var blocking = !!boundary?.is_rendered();
|
|
boundary?.update_pending_count(1, batch);
|
|
batch.increment(blocking, effect);
|
|
return () => {
|
|
boundary?.update_pending_count(-1, batch);
|
|
batch.decrement(blocking, effect);
|
|
};
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/deriveds.js
|
|
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
|
|
/** @import { Batch } from './batch.js'; */
|
|
/** @import { Boundary } from '../dom/blocks/boundary.js'; */
|
|
/**
|
|
* This allows us to track 'reactivity loss' that occurs when signals
|
|
* are read after a non-context-restoring `await`. Dev-only
|
|
* @type {{ effect: Effect, effect_deps: Set<Value>, warned: boolean } | null}
|
|
*/
|
|
var reactivity_loss_tracker = null;
|
|
/** @param {{ effect: Effect, effect_deps: Set<Value>, warned: boolean } | null} v */
|
|
function set_reactivity_loss_tracker(v) {
|
|
reactivity_loss_tracker = v;
|
|
}
|
|
var recent_async_deriveds = /* @__PURE__ */ new Set();
|
|
/**
|
|
* @template V
|
|
* @param {() => V} fn
|
|
* @returns {Derived<V>}
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function derived(fn) {
|
|
var flags = 2 | DIRTY;
|
|
if (active_effect !== null) active_effect.f |= EFFECT_PRESERVED;
|
|
/** @type {Derived<V>} */
|
|
const signal = {
|
|
ctx: component_context,
|
|
deps: null,
|
|
effects: null,
|
|
equals: equals$1,
|
|
f: flags,
|
|
fn,
|
|
reactions: null,
|
|
rv: 0,
|
|
v: UNINITIALIZED,
|
|
wv: 0,
|
|
parent: active_effect,
|
|
ac: null
|
|
};
|
|
if (tracing_mode_flag) signal.created = get_error("created at");
|
|
return signal;
|
|
}
|
|
var OBSOLETE = Symbol("obsolete");
|
|
/**
|
|
* @template V
|
|
* @param {() => V | Promise<V>} fn
|
|
* @param {string} [label]
|
|
* @param {string} [location] If provided, print a warning if the value is not read immediately after update
|
|
* @returns {Promise<Source<V>>}
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function async_derived(fn, label, location) {
|
|
let parent = active_effect;
|
|
if (parent === null) async_derived_orphan();
|
|
var promise = void 0;
|
|
var signal = source(UNINITIALIZED);
|
|
signal.label = label ?? stringify_derived(fn);
|
|
var should_suspend = !active_reaction;
|
|
/** @type {Set<ReturnType<typeof deferred<V>>>} */
|
|
var deferreds = /* @__PURE__ */ new Set();
|
|
async_effect(() => {
|
|
var effect = active_effect;
|
|
reactivity_loss_tracker = {
|
|
effect,
|
|
effect_deps: /* @__PURE__ */ new Set(),
|
|
warned: false
|
|
};
|
|
/** @type {ReturnType<typeof deferred<V>>} */
|
|
var d = deferred();
|
|
promise = d.promise;
|
|
try {
|
|
Promise.resolve(fn()).then(d.resolve, (e) => {
|
|
if (e !== STALE_REACTION) d.reject(e);
|
|
}).finally(unset_context);
|
|
} catch (error) {
|
|
d.reject(error);
|
|
unset_context();
|
|
}
|
|
if (reactivity_loss_tracker) {
|
|
if (effect.deps !== null) for (let i = 0; i < skipped_deps; i += 1) reactivity_loss_tracker.effect_deps.add(effect.deps[i]);
|
|
if (new_deps !== null) for (let i = 0; i < new_deps.length; i += 1) reactivity_loss_tracker.effect_deps.add(new_deps[i]);
|
|
}
|
|
reactivity_loss_tracker = null;
|
|
var batch = current_batch;
|
|
if (should_suspend) {
|
|
if ((effect.f & 32768) !== 0) var decrement_pending = increment_pending();
|
|
if (parent.b?.is_rendered()) batch.async_deriveds.get(effect)?.reject(OBSOLETE);
|
|
else for (const d of deferreds.values()) d.reject(OBSOLETE);
|
|
deferreds.add(d);
|
|
batch.async_deriveds.set(effect, d);
|
|
}
|
|
/**
|
|
* @param {any} value
|
|
* @param {unknown} error
|
|
*/
|
|
const handler = (value, error = void 0) => {
|
|
reactivity_loss_tracker = null;
|
|
decrement_pending?.();
|
|
deferreds.delete(d);
|
|
if (error === OBSOLETE) return;
|
|
batch.activate();
|
|
if (error) {
|
|
signal.f |= ERROR_VALUE;
|
|
internal_set(signal, error);
|
|
} else {
|
|
if ((signal.f & 8388608) !== 0) signal.f ^= ERROR_VALUE;
|
|
if (location !== void 0 && !signal.equals(value)) {
|
|
recent_async_deriveds.add(signal);
|
|
setTimeout(() => {
|
|
if (recent_async_deriveds.has(signal) && (effect.f & 16384) === 0) {
|
|
await_waterfall(signal.label, location);
|
|
recent_async_deriveds.delete(signal);
|
|
}
|
|
});
|
|
}
|
|
internal_set(signal, value);
|
|
}
|
|
batch.deactivate();
|
|
};
|
|
d.promise.then(handler, (e) => handler(null, e || "unknown"));
|
|
});
|
|
teardown(() => {
|
|
for (const d of deferreds) d.reject(OBSOLETE);
|
|
});
|
|
signal.f |= ASYNC;
|
|
return new Promise((fulfil) => {
|
|
/** @param {Promise<V>} p */
|
|
function next(p) {
|
|
function go() {
|
|
if (p === promise) fulfil(signal);
|
|
else next(promise);
|
|
}
|
|
p.then(go, go);
|
|
}
|
|
next(promise);
|
|
});
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {() => V} fn
|
|
* @returns {Derived<V>}
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function user_derived(fn) {
|
|
const d = /* @__PURE__ */ derived(fn);
|
|
if (!async_mode_flag) push_reaction_value(d);
|
|
return d;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {() => V} fn
|
|
* @returns {Derived<V>}
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function derived_safe_equal(fn) {
|
|
const signal = /* @__PURE__ */ derived(fn);
|
|
signal.equals = safe_equals;
|
|
return signal;
|
|
}
|
|
/**
|
|
* @param {Derived} derived
|
|
* @returns {void}
|
|
*/
|
|
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(effects[i]);
|
|
}
|
|
}
|
|
/**
|
|
* The currently updating deriveds, used to detect infinite recursion
|
|
* in dev mode and provide a nicer error than 'too much recursion'
|
|
* @type {Derived[]}
|
|
*/
|
|
var stack = [];
|
|
/**
|
|
* @template T
|
|
* @param {Derived} derived
|
|
* @returns {T}
|
|
*/
|
|
function execute_derived(derived) {
|
|
var value;
|
|
var prev_active_effect = active_effect;
|
|
var parent = derived.parent;
|
|
if (!is_destroying_effect && parent !== null && derived.v !== UNINITIALIZED && (parent.f & 24576) !== 0) {
|
|
derived_inert();
|
|
return derived.v;
|
|
}
|
|
set_active_effect(parent);
|
|
{
|
|
let prev_eager_effects = eager_effects;
|
|
set_eager_effects(/* @__PURE__ */ new Set());
|
|
try {
|
|
if (includes.call(stack, derived)) derived_references_self();
|
|
stack.push(derived);
|
|
destroy_derived_effects(derived);
|
|
value = update_reaction(derived);
|
|
} finally {
|
|
set_active_effect(prev_active_effect);
|
|
set_eager_effects(prev_eager_effects);
|
|
stack.pop();
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
/**
|
|
* @param {Derived} derived
|
|
* @returns {void}
|
|
*/
|
|
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) {
|
|
if (current_batch !== null) {
|
|
current_batch.capture(derived, value, true);
|
|
previous_batch?.capture(derived, value, true);
|
|
} else 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);
|
|
}
|
|
/**
|
|
* @param {Derived} derived
|
|
*/
|
|
function freeze_derived_effects(derived) {
|
|
if (derived.effects === null) return;
|
|
for (const e of derived.effects) if (e.teardown || e.ac) {
|
|
e.teardown?.();
|
|
if (e.ac !== null) without_reactive_context(() => {
|
|
/** @type {AbortController} */ e.ac.abort(STALE_REACTION);
|
|
e.ac = null;
|
|
});
|
|
if (e.fn !== null) e.teardown = noop;
|
|
remove_reactions(e, 0);
|
|
destroy_effect_children(e);
|
|
}
|
|
}
|
|
/**
|
|
* @param {Derived} derived
|
|
*/
|
|
function unfreeze_derived_effects(derived) {
|
|
if (derived.effects === null) return;
|
|
for (const e of derived.effects) if (e.teardown && e.fn !== null) update_effect(e);
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/batch.js
|
|
/** @import { Fork } from 'svelte' */
|
|
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
|
|
/** @type {Batch | null} */
|
|
var first_batch = null;
|
|
/** @type {Batch | null} */
|
|
var last_batch = null;
|
|
/** @type {Batch | null} */
|
|
var current_batch = null;
|
|
/**
|
|
* This is needed to avoid overwriting inputs
|
|
* @type {Batch | null}
|
|
*/
|
|
var previous_batch = null;
|
|
/**
|
|
* When time travelling (i.e. working in one batch, while other batches
|
|
* still have ongoing work), we ignore the real values of affected
|
|
* signals in favour of their values within the batch
|
|
* @type {Map<Value, any> | null}
|
|
*/
|
|
var batch_values = null;
|
|
/** @type {Effect | null} */
|
|
var last_scheduled_effect = null;
|
|
var is_flushing_sync = false;
|
|
var is_processing = false;
|
|
/**
|
|
* During traversal, this is an array. Newly created effects are (if not immediately
|
|
* executed) pushed to this array, rather than going through the scheduling
|
|
* rigamarole that would cause another turn of the flush loop.
|
|
* @type {Effect[] | null}
|
|
*/
|
|
var collected_effects = null;
|
|
/**
|
|
* An array of effects that are marked during traversal as a result of a `set`
|
|
* (not `internal_set`) call. These will be added to the next batch and
|
|
* trigger another `batch.process()`
|
|
* @type {Effect[] | null}
|
|
* @deprecated when we get rid of legacy mode and stores, we can get rid of this
|
|
*/
|
|
var legacy_updates = null;
|
|
var flush_count = 0;
|
|
/** @type {Set<Value>} */
|
|
var source_stacks = /* @__PURE__ */ new Set();
|
|
var uid = 1;
|
|
var Batch = class Batch {
|
|
id = uid++;
|
|
/** True as soon as `#process` was called */
|
|
started = false;
|
|
linked = true;
|
|
/** @type {Batch | null} */
|
|
prev = null;
|
|
/** @type {Batch | null} */
|
|
next = null;
|
|
/** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
|
|
async_deriveds = /* @__PURE__ */ new Map();
|
|
/**
|
|
* The current values of any signals that are updated in this batch.
|
|
* Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
|
|
* The keys of this map are identical to `this.previous`
|
|
* @type {Map<Value, [any, boolean]>}
|
|
*/
|
|
current = /* @__PURE__ */ new Map();
|
|
/**
|
|
* The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
|
|
* The keys of this map are identical to `this.current`
|
|
* @type {Map<Value, 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<(batch: Batch) => void>}
|
|
*/
|
|
#commit_callbacks = /* @__PURE__ */ new Set();
|
|
/**
|
|
* If a fork is discarded, we need to destroy any effects that are no longer needed
|
|
* @type {Set<(batch: Batch) => void>}
|
|
*/
|
|
#discard_callbacks = /* @__PURE__ */ new Set();
|
|
/**
|
|
* The number of async effects that are currently in flight
|
|
*/
|
|
#pending = 0;
|
|
/**
|
|
* Async effects that are currently in flight, _not_ inside a pending boundary
|
|
* @type {Map<Effect, number>}
|
|
*/
|
|
#blocking_pending = /* @__PURE__ */ new Map();
|
|
/**
|
|
* A deferred that resolves when the batch is committed, used with `settled()`
|
|
* TODO replace with Promise.withResolvers once supported widely enough
|
|
* @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
|
|
*/
|
|
#deferred = null;
|
|
/**
|
|
* Effects that were scheduled in this batch but not yet 'resolved' into the
|
|
* root effects that need to be flushed. Resolving — the upwards traversal that
|
|
* marks the path to each effect on the shared effect tree (see #resolve) — is
|
|
* deferred until the batch is processed, so that the markers are created and
|
|
* consumed within a single traversal. Scheduling into other batches (which can
|
|
* happen concurrently, e.g. while a batch is committed) can therefore never
|
|
* observe (and be confused by) this batch's markers.
|
|
* May contain duplicates — deduplication happens during resolving
|
|
* @type {Effect[]}
|
|
*/
|
|
#scheduled = [];
|
|
/**
|
|
* Effects created while this batch was active.
|
|
* @type {Effect[]}
|
|
*/
|
|
#new_effects = [];
|
|
/**
|
|
* Deferred effects (which run after async work has completed) and their status (DIRTY or MAYBE_DIRTY)
|
|
* @type {Map<Effect, number>}
|
|
*/
|
|
#dirty_reactions = /* @__PURE__ */ new Map();
|
|
/**
|
|
* A map of branches that still exist, but will be destroyed when this batch
|
|
* is committed — we skip over these during `process`.
|
|
* The value contains child effects that were dirty/maybe_dirty before being reset,
|
|
* so they can be rescheduled if the branch survives.
|
|
* @type {Map<Effect, { d: Effect[], m: Effect[] }>}
|
|
*/
|
|
#skipped_branches = /* @__PURE__ */ new Map();
|
|
/**
|
|
* Inverse of #skipped_branches which we need to tell prior batches to unskip them when committing
|
|
* @type {Set<Effect>}
|
|
*/
|
|
#unskipped_branches = /* @__PURE__ */ new Set();
|
|
is_fork = false;
|
|
#decrement_queued = false;
|
|
constructor() {
|
|
if (last_batch === null) first_batch = last_batch = this;
|
|
else {
|
|
last_batch.next = this;
|
|
this.prev = last_batch;
|
|
}
|
|
last_batch = this;
|
|
}
|
|
#is_deferred() {
|
|
if (this.is_fork) return true;
|
|
for (const effect of this.#blocking_pending.keys()) if (!this.#is_skipped(effect)) return true;
|
|
return false;
|
|
}
|
|
/**
|
|
* Whether `effect` is inside a branch that this batch skips
|
|
* @param {Effect} effect
|
|
*/
|
|
#is_skipped(effect) {
|
|
for (var e = effect; e !== null; e = e.parent) if (this.#skipped_branches.has(e)) return true;
|
|
return false;
|
|
}
|
|
/**
|
|
* Add an effect to the #skipped_branches map and reset its children
|
|
* @param {Effect} effect
|
|
*/
|
|
skip_effect(effect) {
|
|
if (!this.#skipped_branches.has(effect)) this.#skipped_branches.set(effect, {
|
|
d: [],
|
|
m: []
|
|
});
|
|
this.#unskipped_branches.delete(effect);
|
|
}
|
|
/**
|
|
* Remove an effect from the #skipped_branches map and reschedule
|
|
* any tracked dirty/maybe_dirty child effects
|
|
* @param {Effect} effect
|
|
* @param {(e: Effect) => void} callback
|
|
*/
|
|
unskip_effect(effect, callback = (e) => this.schedule(e)) {
|
|
var tracked = this.#skipped_branches.get(effect);
|
|
if (tracked) {
|
|
this.#skipped_branches.delete(effect);
|
|
for (var e of tracked.d) {
|
|
set_signal_status(e, DIRTY);
|
|
callback(e);
|
|
}
|
|
for (e of tracked.m) {
|
|
set_signal_status(e, MAYBE_DIRTY);
|
|
callback(e);
|
|
}
|
|
}
|
|
this.#unskipped_branches.add(effect);
|
|
}
|
|
/**
|
|
* Convert the effects that were scheduled in this batch into the root effects
|
|
* that need to be traversed, marking the path to each effect (by clearing the
|
|
* `CLEAN` flag on ancestor branches) so that the traversal can find them.
|
|
* This happens right before traversal rather than at scheduling time, so that
|
|
* the markers left on the (shared) effect tree are created and consumed within
|
|
* a single traversal — scheduling into other batches can never observe them
|
|
* @returns {Effect[]}
|
|
*/
|
|
#resolve() {
|
|
/** @type {Effect[]} */
|
|
var roots = [];
|
|
for (const effect of this.#scheduled) {
|
|
if ((effect.f & 16384) !== 0 || (effect.f & 6144) === 0) continue;
|
|
var e = effect;
|
|
var covered = false;
|
|
while (e.parent !== null) {
|
|
e = e.parent;
|
|
var flags = e.f;
|
|
if ((flags & 96) !== 0) {
|
|
if ((flags & 1024) === 0) {
|
|
covered = true;
|
|
break;
|
|
}
|
|
e.f ^= CLEAN;
|
|
}
|
|
}
|
|
if (!covered) roots.push(e);
|
|
}
|
|
this.#scheduled = [];
|
|
return roots;
|
|
}
|
|
#process() {
|
|
this.started = true;
|
|
for (const value of this.current.keys()) source_stacks.add(value);
|
|
for (const [e, status] of this.#dirty_reactions) {
|
|
set_signal_status(e, status);
|
|
this.schedule(e);
|
|
}
|
|
this.apply();
|
|
/** @type {Effect[]} */
|
|
var effects = collected_effects = [];
|
|
/** @type {Effect[]} */
|
|
var render_effects = [];
|
|
/**
|
|
* @type {Effect[]}
|
|
* @deprecated when we get rid of legacy mode and stores, we can get rid of this
|
|
*/
|
|
var updates = legacy_updates = [];
|
|
while (this.#scheduled.length > 0) {
|
|
if (flush_count++ > 1e3) {
|
|
this.#unlink();
|
|
infinite_loop_guard();
|
|
}
|
|
for (const root of this.#resolve()) try {
|
|
this.#traverse(root, effects, render_effects);
|
|
} catch (e) {
|
|
reset_all(root);
|
|
if (!this.#is_deferred()) this.discard();
|
|
throw e;
|
|
}
|
|
}
|
|
current_batch = null;
|
|
if (updates.length > 0) {
|
|
var batch = Batch.ensure();
|
|
for (const e of updates) batch.schedule(e);
|
|
}
|
|
collected_effects = null;
|
|
legacy_updates = null;
|
|
if (this.#is_deferred()) {
|
|
this.#defer_effects(render_effects);
|
|
this.#defer_effects(effects);
|
|
for (const [e, t] of this.#skipped_branches) reset_branch(e, t);
|
|
if (updates.length > 0)
|
|
/** @type {Batch} */ current_batch.#process();
|
|
return;
|
|
}
|
|
const earlier_batch = this.#find_earlier_batch();
|
|
if (earlier_batch) {
|
|
this.#defer_effects(render_effects);
|
|
this.#defer_effects(effects);
|
|
earlier_batch.#merge(this);
|
|
return;
|
|
}
|
|
this.#dirty_reactions.clear();
|
|
for (const fn of this.#commit_callbacks) fn(this);
|
|
this.#commit_callbacks.clear();
|
|
previous_batch = this;
|
|
flush_queued_effects(render_effects);
|
|
flush_queued_effects(effects);
|
|
previous_batch = null;
|
|
this.#deferred?.resolve();
|
|
var next_batch = current_batch;
|
|
if (this.#pending === 0 && (this.#scheduled.length === 0 || next_batch !== null)) {
|
|
this.#unlink();
|
|
if (async_mode_flag) {
|
|
this.#commit();
|
|
current_batch = next_batch;
|
|
}
|
|
}
|
|
if (next_batch !== null) {
|
|
old_values.clear();
|
|
next_batch.#process();
|
|
}
|
|
}
|
|
/**
|
|
* Traverse the effect tree, executing effects or stashing
|
|
* them for later execution as appropriate
|
|
* @param {Effect} root
|
|
* @param {Effect[]} effects
|
|
* @param {Effect[]} render_effects
|
|
*/
|
|
#traverse(root, effects, render_effects) {
|
|
root.f ^= CLEAN;
|
|
var effect = root.first;
|
|
while (effect !== null) {
|
|
var flags = effect.f;
|
|
var is_branch = (flags & 96) !== 0;
|
|
if (!(is_branch && (flags & 1024) !== 0 || (flags & 8192) !== 0 || this.#skipped_branches.has(effect)) && effect.fn !== null) {
|
|
if (is_branch) effect.f ^= CLEAN;
|
|
else if ((flags & 4) !== 0) effects.push(effect);
|
|
else if (async_mode_flag && (flags & 16777224) !== 0) render_effects.push(effect);
|
|
else if (is_dirty(effect)) {
|
|
if ((flags & 16) !== 0) this.add_dirty_reaction(effect, MAYBE_DIRTY);
|
|
update_effect(effect);
|
|
}
|
|
var child = effect.first;
|
|
if (child !== null) {
|
|
effect = child;
|
|
continue;
|
|
}
|
|
}
|
|
while (effect !== null) {
|
|
var next = effect.next;
|
|
if (next !== null) {
|
|
effect = next;
|
|
break;
|
|
}
|
|
effect = effect.parent;
|
|
}
|
|
}
|
|
}
|
|
#find_earlier_batch() {
|
|
for (var batch = this.prev; batch !== null; batch = batch.prev) if (!batch.is_fork && this.#intersects(batch)) return batch;
|
|
return null;
|
|
}
|
|
/** @param {Batch} batch */
|
|
#intersects(batch) {
|
|
for (const [source, [, is_derived]] of this.current) {
|
|
if (is_derived) continue;
|
|
if (batch.current.has(source)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* @param {Batch} batch
|
|
*/
|
|
#merge(batch) {
|
|
for (const [source, value] of batch.current) {
|
|
if (!this.previous.has(source) && batch.previous.has(source)) this.previous.set(source, batch.previous.get(source));
|
|
this.current.set(source, value);
|
|
}
|
|
for (const [effect, deferred] of batch.async_deriveds) {
|
|
const d = this.async_deriveds.get(effect);
|
|
if (d) deferred.promise.then(d.resolve).catch(d.reject);
|
|
}
|
|
batch.async_deriveds.clear();
|
|
this.transfer_reactions(batch.#dirty_reactions);
|
|
/**
|
|
* mark all effects that depend on `batch.current`, except the
|
|
* async effects that we just resolved (TODO unless they depend
|
|
* on values in this batch that are NOT in the later batch?).
|
|
* Through this we also will populate the correct #skipped_branches,
|
|
* oncommit callbacks etc, so we don't need to merge them separately.
|
|
* @param {Value} value
|
|
*/
|
|
const mark = (value) => {
|
|
var reactions = value.reactions;
|
|
if (reactions === null) return;
|
|
if ((value.f & 2) !== 0 && (value.f & 6144) === 0) return;
|
|
for (const reaction of reactions) {
|
|
var flags = reaction.f;
|
|
if ((flags & 2) !== 0) mark(reaction);
|
|
else {
|
|
var effect = reaction;
|
|
if (flags & 4194320 && !this.async_deriveds.has(effect)) {
|
|
this.#dirty_reactions.delete(effect);
|
|
set_signal_status(effect, DIRTY);
|
|
this.schedule(effect);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
for (const source of this.current.keys()) mark(source);
|
|
this.oncommit(() => batch.discard());
|
|
batch.#unlink();
|
|
current_batch = this;
|
|
this.#process();
|
|
}
|
|
/**
|
|
* @param {Effect[]} effects
|
|
*/
|
|
#defer_effects(effects) {
|
|
for (var i = 0; i < effects.length; i += 1) defer_effect(effects[i], this.#dirty_reactions);
|
|
}
|
|
/**
|
|
* Associate a change to a given source with the current
|
|
* batch, noting its previous and current values
|
|
* @param {Value} source
|
|
* @param {any} value
|
|
* @param {boolean} [is_derived]
|
|
*/
|
|
capture(source, value, is_derived = false) {
|
|
if (source.v !== UNINITIALIZED && !this.previous.has(source)) this.previous.set(source, source.v);
|
|
if ((source.f & 8388608) === 0) {
|
|
this.current.set(source, [value, is_derived]);
|
|
batch_values?.set(source, value);
|
|
}
|
|
if (!this.is_fork) source.v = value;
|
|
}
|
|
activate() {
|
|
current_batch = this;
|
|
}
|
|
deactivate() {
|
|
current_batch = null;
|
|
batch_values = null;
|
|
}
|
|
flush() {
|
|
try {
|
|
source_stacks.clear();
|
|
is_processing = true;
|
|
current_batch = this;
|
|
this.#process();
|
|
} finally {
|
|
flush_count = 0;
|
|
last_scheduled_effect = null;
|
|
collected_effects = null;
|
|
legacy_updates = null;
|
|
is_processing = false;
|
|
current_batch = null;
|
|
batch_values = null;
|
|
old_values.clear();
|
|
for (const source of source_stacks) source.updated = null;
|
|
}
|
|
}
|
|
discard() {
|
|
for (const fn of this.#discard_callbacks) fn(this);
|
|
this.#discard_callbacks.clear();
|
|
for (const deferred of this.async_deriveds.values()) deferred.reject(OBSOLETE);
|
|
this.#unlink();
|
|
this.#deferred?.resolve();
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
*/
|
|
register_created_effect(effect) {
|
|
this.#new_effects.push(effect);
|
|
}
|
|
#commit() {
|
|
for (let batch = first_batch; batch !== null; batch = batch.next) {
|
|
var is_earlier = batch.id < this.id;
|
|
/** @type {Source[]} */
|
|
var sources = [];
|
|
for (const [source, [value, is_derived]] of this.current) {
|
|
if (batch.current.has(source)) {
|
|
var batch_value = batch.current.get(source)[0];
|
|
if (is_earlier && value !== batch_value) batch.current.set(source, [value, is_derived]);
|
|
else continue;
|
|
}
|
|
sources.push(source);
|
|
}
|
|
if (is_earlier) for (const [effect, deferred] of this.async_deriveds) {
|
|
const d = batch.async_deriveds.get(effect);
|
|
if (d) deferred.promise.then(d.resolve).catch(d.reject);
|
|
}
|
|
var current = [...batch.current.keys()].filter((source) => !batch.current.get(source)[1]);
|
|
if (!batch.started || current.length === 0) continue;
|
|
var others = current.filter((source) => !this.current.has(source));
|
|
if (others.length === 0) {
|
|
if (is_earlier) batch.discard();
|
|
} else if (sources.length > 0) {
|
|
if (!batch.#decrement_queued) invariant(batch.#scheduled.length === 0, "Batch has scheduled effects");
|
|
if (is_earlier) for (const unskipped of this.#unskipped_branches) batch.unskip_effect(unskipped, (e) => {
|
|
if ((e.f & 4194320) !== 0) batch.schedule(e);
|
|
else batch.#defer_effects([e]);
|
|
});
|
|
batch.activate();
|
|
/** @type {Set<Value>} */
|
|
var marked = /* @__PURE__ */ new Set();
|
|
/** @type {Map<Reaction, boolean>} */
|
|
var checked = /* @__PURE__ */ new Map();
|
|
for (var source of sources) mark_effects(source, others, marked, checked);
|
|
checked = /* @__PURE__ */ new Map();
|
|
var current_unequal = [...batch.current].filter(([c, v1]) => {
|
|
const v2 = this.current.get(c);
|
|
if (!v2) return true;
|
|
return v2[0] !== v1[0] || v2[1] !== v1[1];
|
|
}).map(([c]) => c);
|
|
if (current_unequal.length > 0) {
|
|
for (const effect of this.#new_effects) if ((effect.f & 155648) === 0 && depends_on(effect, current_unequal, checked)) {
|
|
if ((effect.f & 4194320) !== 0) {
|
|
set_signal_status(effect, DIRTY);
|
|
batch.schedule(effect);
|
|
} else batch.add_dirty_reaction(effect, DIRTY);
|
|
}
|
|
}
|
|
if (batch.#scheduled.length > 0 && !batch.#decrement_queued) {
|
|
batch.apply();
|
|
for (var root of batch.#resolve()) batch.#traverse(root, [], []);
|
|
}
|
|
batch.deactivate();
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @param {boolean} blocking
|
|
* @param {Effect} effect
|
|
*/
|
|
increment(blocking, effect) {
|
|
this.#pending += 1;
|
|
if (blocking) {
|
|
let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
|
|
this.#blocking_pending.set(effect, blocking_pending_count + 1);
|
|
}
|
|
}
|
|
/**
|
|
* @param {boolean} blocking
|
|
* @param {Effect} effect
|
|
*/
|
|
decrement(blocking, effect) {
|
|
this.#pending -= 1;
|
|
if (blocking) {
|
|
let blocking_pending_count = this.#blocking_pending.get(effect) ?? 0;
|
|
if (blocking_pending_count === 1) this.#blocking_pending.delete(effect);
|
|
else this.#blocking_pending.set(effect, blocking_pending_count - 1);
|
|
}
|
|
if (this.#decrement_queued) return;
|
|
this.#decrement_queued = true;
|
|
queue_micro_task(() => {
|
|
this.#decrement_queued = false;
|
|
if (this.linked) this.flush();
|
|
});
|
|
}
|
|
/**
|
|
* @param {Map<Effect, number>} dirty_reactions
|
|
*/
|
|
transfer_reactions(dirty_reactions) {
|
|
for (const [effect, status] of dirty_reactions) this.add_dirty_reaction(effect, status);
|
|
dirty_reactions.clear();
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {number} status
|
|
*/
|
|
add_dirty_reaction(effect, status) {
|
|
if (status === 2048 || this.#dirty_reactions.get(effect) !== 2048) this.#dirty_reactions.set(effect, status);
|
|
}
|
|
/** @param {(batch: Batch) => 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();
|
|
if (!is_processing && !is_flushing_sync) queue_micro_task(() => {
|
|
if (!batch.started) batch.flush();
|
|
});
|
|
}
|
|
return current_batch;
|
|
}
|
|
apply() {
|
|
if (!async_mode_flag || !this.is_fork && this.prev === null && this.next === null) {
|
|
batch_values = null;
|
|
return;
|
|
}
|
|
batch_values = /* @__PURE__ */ new Map();
|
|
for (const [source, [value]] of this.current) batch_values.set(source, value);
|
|
for (let batch = first_batch; batch !== null; batch = batch.next) {
|
|
if (batch === this || batch.is_fork) continue;
|
|
if (batch.id >= this.id || !batch.#intersects(this)) {
|
|
for (const [source, previous] of batch.previous) if (!batch_values.has(source)) batch_values.set(source, previous);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
*
|
|
* @param {Effect} effect
|
|
*/
|
|
schedule(effect) {
|
|
last_scheduled_effect = effect;
|
|
if (effect.b?.is_pending && (effect.f & 16777228) !== 0 && (effect.f & 32768) === 0) {
|
|
effect.b.defer_effect(effect);
|
|
return;
|
|
}
|
|
this.#scheduled.push(effect);
|
|
}
|
|
#unlink() {
|
|
if (!this.linked) return;
|
|
var prev = this.prev;
|
|
var next = this.next;
|
|
if (prev === null) first_batch = next;
|
|
else prev.next = next;
|
|
if (next === null) last_batch = prev;
|
|
else next.prev = prev;
|
|
this.linked = false;
|
|
}
|
|
};
|
|
/**
|
|
* Synchronously flush any pending updates.
|
|
* Returns void if no callback is provided, otherwise returns the result of calling the callback.
|
|
* @template [T=void]
|
|
* @param {(() => T) | undefined} [fn]
|
|
* @returns {T}
|
|
*/
|
|
function flushSync(fn) {
|
|
var was_flushing_sync = is_flushing_sync;
|
|
var prev_previous_batch = previous_batch;
|
|
previous_batch = null;
|
|
is_flushing_sync = true;
|
|
try {
|
|
var result;
|
|
if (fn) {
|
|
flushSync();
|
|
result = fn();
|
|
}
|
|
while (true) {
|
|
flush_tasks();
|
|
if (current_batch === null) return result;
|
|
current_batch.flush();
|
|
}
|
|
} finally {
|
|
is_flushing_sync = was_flushing_sync;
|
|
previous_batch = prev_previous_batch;
|
|
}
|
|
}
|
|
function infinite_loop_guard() {
|
|
var updates = /* @__PURE__ */ new Map();
|
|
for (const source of current_batch.current.keys()) for (const [stack, update] of source.updated ?? []) {
|
|
var entry = updates.get(stack);
|
|
if (!entry) {
|
|
entry = {
|
|
error: update.error,
|
|
count: 0
|
|
};
|
|
updates.set(stack, entry);
|
|
}
|
|
entry.count += update.count;
|
|
}
|
|
for (const update of updates.values()) if (update.error) console.error(update.error);
|
|
try {
|
|
effect_update_depth_exceeded();
|
|
} catch (error) {
|
|
define_property(error, "stack", { value: "" });
|
|
invoke_error_boundary(error, last_scheduled_effect);
|
|
}
|
|
}
|
|
/** @type {Set<Effect> | null} */
|
|
var eager_block_effects = null;
|
|
/**
|
|
* @param {Array<Effect>} effects
|
|
* @returns {void}
|
|
*/
|
|
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 & 24576) === 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 & 24576) !== 0) continue;
|
|
/** @type {Effect[]} */
|
|
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 e = ordered_effects[j];
|
|
if ((e.f & 24576) !== 0) continue;
|
|
update_effect(e);
|
|
}
|
|
}
|
|
eager_block_effects.clear();
|
|
}
|
|
}
|
|
}
|
|
eager_block_effects = null;
|
|
}
|
|
/**
|
|
* This is similar to `mark_reactions`, but it only marks async/block effects
|
|
* depending on `value` and at least one of the other `sources`, so that
|
|
* these effects can re-run after another batch has been committed
|
|
* @param {Value} value
|
|
* @param {Source[]} sources
|
|
* @param {Set<Value>} marked
|
|
* @param {Map<Reaction, boolean>} checked
|
|
*/
|
|
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 flags = reaction.f;
|
|
if ((flags & 2) !== 0) mark_effects(reaction, sources, marked, checked);
|
|
else if ((flags & 4194320) !== 0 && (flags & 2048) === 0 && depends_on(reaction, sources, checked)) {
|
|
set_signal_status(reaction, DIRTY);
|
|
schedule_effect(reaction);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* When committing a fork, we need to trigger eager effects so that
|
|
* any `$state.eager(...)` expressions update immediately. This
|
|
* function allows us to discover them
|
|
* @param {Value} value
|
|
* @param {Set<Effect>} effects
|
|
*/
|
|
function mark_eager_effects(value, effects) {
|
|
if (value.reactions === null) return;
|
|
for (const reaction of value.reactions) {
|
|
const flags = reaction.f;
|
|
if ((flags & 2) !== 0) mark_eager_effects(reaction, effects);
|
|
else if ((flags & 131072) !== 0) {
|
|
set_signal_status(reaction, DIRTY);
|
|
effects.add(reaction);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @param {Reaction} reaction
|
|
* @param {Source[]} sources
|
|
* @param {Map<Reaction, boolean>} checked
|
|
*/
|
|
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 & 2) !== 0 && depends_on(dep, sources, checked)) {
|
|
checked.set(dep, true);
|
|
return true;
|
|
}
|
|
}
|
|
checked.set(reaction, false);
|
|
return false;
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @returns {void}
|
|
*/
|
|
function schedule_effect(effect) {
|
|
/** @type {Batch} */ current_batch.schedule(effect);
|
|
}
|
|
/** @type {Source<number>[]} */
|
|
var eager_versions = [];
|
|
function eager_flush() {
|
|
flushSync(() => {
|
|
const eager = eager_versions;
|
|
eager_versions = [];
|
|
for (const version of eager) update(version);
|
|
});
|
|
}
|
|
/** @type {Map<Reaction, Source<number>>} */
|
|
var version_map = /* @__PURE__ */ new Map();
|
|
/**
|
|
* Implementation of `$state.eager(fn())`
|
|
* @template T
|
|
* @param {() => T} fn
|
|
* @returns {T}
|
|
*/
|
|
function eager(fn) {
|
|
var initial = true;
|
|
var value = void 0;
|
|
if (active_reaction === null) return fn();
|
|
let parent = active_reaction;
|
|
let version = version_map.get(parent) ?? source(0);
|
|
version_map.set(parent, version);
|
|
version.label ??= "$state.eager version";
|
|
teardown(() => {
|
|
if (parent.f & 33554432) version_map.delete(parent);
|
|
});
|
|
get(version);
|
|
eager_effect(() => {
|
|
if (initial) {
|
|
var previous_batch_values = batch_values;
|
|
try {
|
|
batch_values = null;
|
|
value = fn();
|
|
} finally {
|
|
batch_values = previous_batch_values;
|
|
}
|
|
return;
|
|
}
|
|
if (eager_versions.length === 0) queue_micro_task(eager_flush);
|
|
eager_versions.push(version);
|
|
});
|
|
initial = false;
|
|
return value;
|
|
}
|
|
/**
|
|
* Mark all the effects inside a skipped branch CLEAN, so that
|
|
* they can be correctly rescheduled later. Tracks dirty and maybe_dirty
|
|
* effects so they can be rescheduled if the branch survives.
|
|
* @param {Effect} effect
|
|
* @param {{ d: Effect[], m: Effect[] }} tracked
|
|
*/
|
|
function reset_branch(effect, tracked) {
|
|
if ((effect.f & 32) !== 0 && (effect.f & 1024) !== 0) return;
|
|
if ((effect.f & 2048) !== 0) tracked.d.push(effect);
|
|
else if ((effect.f & 4096) !== 0) tracked.m.push(effect);
|
|
set_signal_status(effect, CLEAN);
|
|
var e = effect.first;
|
|
while (e !== null) {
|
|
reset_branch(e, tracked);
|
|
e = e.next;
|
|
}
|
|
}
|
|
/**
|
|
* Mark an entire effect tree clean following an error
|
|
* @param {Effect} effect
|
|
*/
|
|
function reset_all(effect) {
|
|
set_signal_status(effect, CLEAN);
|
|
var e = effect.first;
|
|
while (e !== null) {
|
|
reset_all(e);
|
|
e = e.next;
|
|
}
|
|
}
|
|
/**
|
|
* Creates a 'fork', in which state changes are evaluated but not applied to the DOM.
|
|
* This is useful for speculatively loading data (for example) when you suspect that
|
|
* the user is about to take some action.
|
|
*
|
|
* Frameworks like SvelteKit can use this to preload data when the user touches or
|
|
* hovers over a link, making any subsequent navigation feel instantaneous.
|
|
*
|
|
* The `fn` parameter is a synchronous function that modifies some state. The
|
|
* state changes will be reverted after the fork is initialised, then reapplied
|
|
* if and when the fork is eventually committed.
|
|
*
|
|
* When it becomes clear that a fork will _not_ be committed (e.g. because the
|
|
* user navigated elsewhere), it must be discarded to avoid leaking memory.
|
|
*
|
|
* @param {() => void} fn
|
|
* @returns {Fork}
|
|
* @since 5.42
|
|
*/
|
|
function fork(fn) {
|
|
if (!async_mode_flag) experimental_async_required("fork");
|
|
if (current_batch !== null) fork_timing();
|
|
flushSync();
|
|
var batch = Batch.ensure();
|
|
batch.is_fork = true;
|
|
batch_values = /* @__PURE__ */ new Map();
|
|
var committed = false;
|
|
var settled = batch.settled();
|
|
fn();
|
|
flushSync();
|
|
return {
|
|
commit: async () => {
|
|
if (committed) {
|
|
await settled;
|
|
return;
|
|
}
|
|
if (!batch.linked) fork_discarded();
|
|
committed = true;
|
|
batch.is_fork = false;
|
|
for (var [source, [value]] of batch.current) {
|
|
source.v = value;
|
|
source.wv = increment_write_version();
|
|
}
|
|
flushSync(() => {
|
|
/** @type {Set<Effect>} */
|
|
var eager_effects = /* @__PURE__ */ new Set();
|
|
for (var source of batch.current.keys()) mark_eager_effects(source, eager_effects);
|
|
set_eager_effects(eager_effects);
|
|
flush_eager_effects();
|
|
});
|
|
batch.flush();
|
|
await settled;
|
|
},
|
|
discard: () => {
|
|
for (var source of batch.current.keys()) source.wv = increment_write_version();
|
|
if (!committed && batch.linked) batch.discard();
|
|
}
|
|
};
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/sources.js
|
|
/** @import { Derived, Effect, Source, Value } from '#client' */
|
|
/** @type {Set<Effect>} */
|
|
var eager_effects = /* @__PURE__ */ new Set();
|
|
/** @type {Map<Value, any>} */
|
|
var old_values = /* @__PURE__ */ new Map();
|
|
/**
|
|
* @param {Set<any>} v
|
|
*/
|
|
function set_eager_effects(v) {
|
|
eager_effects = v;
|
|
}
|
|
var eager_effects_deferred = false;
|
|
function set_eager_effects_deferred() {
|
|
eager_effects_deferred = true;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {V} v
|
|
* @param {Error | null} [stack]
|
|
* @returns {Source<V>}
|
|
*/
|
|
function source(v, stack) {
|
|
/** @type {Source<V>} */
|
|
var signal = {
|
|
f: 0,
|
|
v,
|
|
reactions: null,
|
|
equals: equals$1,
|
|
rv: 0,
|
|
wv: 0
|
|
};
|
|
if (tracing_mode_flag) {
|
|
signal.created = stack ?? get_error("created at");
|
|
signal.updated = null;
|
|
signal.set_during_effect = false;
|
|
signal.trace = null;
|
|
}
|
|
return signal;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {V} v
|
|
* @param {Error | null} [stack]
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function state(v, stack) {
|
|
const s = source(v, stack);
|
|
push_reaction_value(s);
|
|
return s;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {V} initial_value
|
|
* @param {boolean} [immutable]
|
|
* @returns {Source<V>}
|
|
*/
|
|
/*#__NO_SIDE_EFFECTS__*/
|
|
function mutable_source(initial_value, immutable = false, trackable = true) {
|
|
const s = source(initial_value);
|
|
if (!immutable) s.equals = safe_equals;
|
|
if (legacy_mode_flag && trackable && component_context !== null && component_context.l !== null) (component_context.l.s ??= []).push(s);
|
|
return s;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {Value<V>} source
|
|
* @param {V} value
|
|
*/
|
|
function mutate(source, value) {
|
|
set(source, untrack(() => get(source)));
|
|
return value;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {Value<V>} source
|
|
* @param {V} value
|
|
* @param {boolean} [should_proxy]
|
|
* @returns {V}
|
|
*/
|
|
function set(source, value, should_proxy = false) {
|
|
if (active_reaction !== null && (!untracking || (active_reaction.f & 131072) !== 0) && is_runes() && (active_reaction.f & 4325394) !== 0 && (current_sources === null || !current_sources.has(source))) state_unsafe_mutation();
|
|
let new_value = should_proxy ? proxy(value) : value;
|
|
tag_proxy(new_value, source.label);
|
|
return internal_set(source, new_value, legacy_updates);
|
|
}
|
|
/**
|
|
* A set of signals we have already seen while traversing in mark_reactions.
|
|
* Not always set to balance the common case of sources only having a couple
|
|
* of (transitive) dependencies (where always creating a Set would be bad for perf)
|
|
* with the edge case of extremely deep or wide dependency arrays with cycles.
|
|
* @type {Set<any> | null}
|
|
*/
|
|
var seen = null;
|
|
/** Number of transitive dependencies, see {@link seen} for more info */
|
|
var count_deps = 0;
|
|
/**
|
|
* @template V
|
|
* @param {Value<V>} source
|
|
* @param {V} value
|
|
* @param {Effect[] | null} [updated_during_traversal]
|
|
* @returns {V}
|
|
*/
|
|
function internal_set(source, value, updated_during_traversal = null) {
|
|
if (!source.equals(value)) {
|
|
if (is_destroying_effect) old_values.set(source, value);
|
|
else if (!old_values.has(source)) old_values.set(source, source.v);
|
|
var batch = Batch.ensure();
|
|
batch.capture(source, value);
|
|
if (tracing_mode_flag || active_effect !== null) {
|
|
source.updated ??= /* @__PURE__ */ new Map();
|
|
const count = (source.updated.get("")?.count ?? 0) + 1;
|
|
source.updated.set("", {
|
|
error: null,
|
|
count
|
|
});
|
|
if (tracing_mode_flag || count > 5) {
|
|
const error = get_error("updated at");
|
|
if (error !== null) {
|
|
let entry = source.updated.get(error.stack);
|
|
if (!entry) {
|
|
entry = {
|
|
error,
|
|
count: 0
|
|
};
|
|
source.updated.set(error.stack, entry);
|
|
}
|
|
entry.count++;
|
|
}
|
|
}
|
|
}
|
|
if (active_effect !== null) source.set_during_effect = true;
|
|
if ((source.f & 2) !== 0) {
|
|
const derived = source;
|
|
if ((source.f & 2048) !== 0) execute_derived(derived);
|
|
if (batch_values === null) update_derived_status(derived);
|
|
}
|
|
source.wv = increment_write_version();
|
|
seen = null;
|
|
count_deps = 0;
|
|
mark_reactions(source, DIRTY, updated_during_traversal);
|
|
seen = null;
|
|
if (is_runes() && active_effect !== null && (active_effect.f & 1024) !== 0 && (active_effect.f & 96) === 0) {
|
|
if (untracked_writes === null) set_untracked_writes([source]);
|
|
else untracked_writes.push(source);
|
|
}
|
|
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 & 1024) !== 0) set_signal_status(effect, MAYBE_DIRTY);
|
|
let dirty;
|
|
try {
|
|
dirty = is_dirty(effect);
|
|
} catch {
|
|
dirty = true;
|
|
}
|
|
if (dirty) update_effect(effect);
|
|
}
|
|
eager_effects.clear();
|
|
}
|
|
/**
|
|
* @template {number | bigint} T
|
|
* @param {Source<T>} source
|
|
* @param {1 | -1} [d]
|
|
* @returns {T}
|
|
*/
|
|
function update(source, d = 1) {
|
|
var value = get(source);
|
|
var result = d === 1 ? value++ : value--;
|
|
set(source, value);
|
|
return result;
|
|
}
|
|
/**
|
|
* @template {number | bigint} T
|
|
* @param {Source<T>} source
|
|
* @param {1 | -1} [d]
|
|
* @returns {T}
|
|
*/
|
|
function update_pre(source, d = 1) {
|
|
var value = get(source);
|
|
return set(source, d === 1 ? ++value : --value);
|
|
}
|
|
/**
|
|
* Silently (without using `get`) increment a source
|
|
* @param {Source<number>} source
|
|
*/
|
|
function increment(source) {
|
|
set(source, source.v + 1);
|
|
}
|
|
/**
|
|
* @param {Value} signal
|
|
* @param {number} status should be DIRTY or MAYBE_DIRTY
|
|
* @param {Effect[] | null} updated_during_traversal
|
|
* @returns {void}
|
|
*/
|
|
function mark_reactions(signal, status, updated_during_traversal) {
|
|
var reactions = signal.reactions;
|
|
if (reactions === null) return;
|
|
var runes = is_runes();
|
|
var length = reactions.length;
|
|
count_deps += length;
|
|
if (count_deps > 1e5 && seen === null) seen = /* @__PURE__ */ new Set();
|
|
if (seen !== null) {
|
|
if (seen.has(signal)) return;
|
|
seen.add(signal);
|
|
}
|
|
for (var i = 0; i < length; i++) {
|
|
var reaction = reactions[i];
|
|
var flags = reaction.f;
|
|
if (!runes && reaction === active_effect) continue;
|
|
var not_dirty = (flags & DIRTY) === 0;
|
|
if (not_dirty) set_signal_status(reaction, status);
|
|
if ((flags & 131072) !== 0) eager_effects.add(reaction);
|
|
else if ((flags & 2) !== 0) {
|
|
var derived = reaction;
|
|
batch_values?.delete(derived);
|
|
mark_reactions(derived, MAYBE_DIRTY, updated_during_traversal);
|
|
} else if (not_dirty) {
|
|
var effect = reaction;
|
|
if ((flags & 16) !== 0 && eager_block_effects !== null) eager_block_effects.add(effect);
|
|
if (updated_during_traversal !== null) updated_during_traversal.push(effect);
|
|
else schedule_effect(effect);
|
|
}
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/proxy.js
|
|
/** @import { Source } from '#client' */
|
|
var regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
/**
|
|
* @template T
|
|
* @param {T} value
|
|
* @returns {T}
|
|
*/
|
|
function proxy(value) {
|
|
if (typeof value !== "object" || value === null || STATE_SYMBOL in value || COMPONENT_SYMBOL in value) return value;
|
|
const prototype = get_prototype_of(value);
|
|
if (prototype !== object_prototype && prototype !== array_prototype) return value;
|
|
/** @type {Map<any, Source<any>>} */
|
|
var sources = /* @__PURE__ */ new Map();
|
|
var is_proxied_array = is_array(value);
|
|
var version = /* @__PURE__ */ state(0);
|
|
var stack = tracing_mode_flag ? get_error("created at") : null;
|
|
var parent_version = update_version;
|
|
/**
|
|
* Executes the proxy in the context of the reaction it was originally created in, if any
|
|
* @template T
|
|
* @param {() => T} fn
|
|
*/
|
|
var with_parent = (fn) => {
|
|
if (update_version === parent_version) return fn();
|
|
var reaction = active_reaction;
|
|
var version = update_version;
|
|
set_active_reaction(null);
|
|
set_update_version(parent_version);
|
|
var result = fn();
|
|
set_active_reaction(reaction);
|
|
set_update_version(version);
|
|
return result;
|
|
};
|
|
if (is_proxied_array) {
|
|
sources.set("length", /* @__PURE__ */ state(
|
|
/** @type {any[]} */
|
|
value.length,
|
|
stack
|
|
));
|
|
value = inspectable_array(value);
|
|
}
|
|
/** Used in dev for $inspect.trace() */
|
|
var path = "";
|
|
let updating = false;
|
|
/** @param {string} new_path */
|
|
function update_path(new_path) {
|
|
if (updating) return;
|
|
updating = true;
|
|
path = new_path;
|
|
tag(version, `${path} version`);
|
|
for (const [prop, source] of sources) tag(source, get_label(path, prop));
|
|
updating = false;
|
|
}
|
|
return new Proxy(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 s = /* @__PURE__ */ state(descriptor.value, stack);
|
|
sources.set(prop, s);
|
|
if (typeof prop === "string") tag(s, get_label(path, prop));
|
|
return s;
|
|
});
|
|
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 s = with_parent(() => /* @__PURE__ */ state(UNINITIALIZED, stack));
|
|
sources.set(prop, s);
|
|
increment(version);
|
|
tag(s, get_label(path, prop));
|
|
}
|
|
} else {
|
|
set(s, UNINITIALIZED);
|
|
increment(version);
|
|
}
|
|
return true;
|
|
},
|
|
get(target, prop, receiver) {
|
|
if (prop === STATE_SYMBOL) return value;
|
|
if (prop === PROXY_PATH_SYMBOL) return update_path;
|
|
var s = sources.get(prop);
|
|
var exists = prop in target;
|
|
if (s === void 0 && (!exists || get_descriptor(target, prop)?.writable)) {
|
|
s = with_parent(() => {
|
|
var s = /* @__PURE__ */ state(proxy(exists ? target[prop] : UNINITIALIZED), stack);
|
|
tag(s, get_label(path, prop));
|
|
return s;
|
|
});
|
|
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) {
|
|
this.has?.(target, prop);
|
|
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
var s = sources.get(prop);
|
|
if (s !== void 0) {
|
|
var value = get(s);
|
|
if (value === UNINITIALIZED) return;
|
|
if (descriptor && "value" in descriptor) descriptor.value = value;
|
|
else return {
|
|
enumerable: true,
|
|
configurable: true,
|
|
value,
|
|
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 || active_reaction !== null) && (!has || get_descriptor(target, prop)?.writable)) {
|
|
if (s === void 0) {
|
|
s = with_parent(() => {
|
|
var s = /* @__PURE__ */ state(has ? proxy(target[prop]) : UNINITIALIZED, stack);
|
|
tag(s, get_label(path, prop));
|
|
return s;
|
|
});
|
|
sources.set(prop, s);
|
|
}
|
|
if (get(s) === UNINITIALIZED) return false;
|
|
}
|
|
return has;
|
|
},
|
|
set(target, prop, value, receiver) {
|
|
var s = sources.get(prop);
|
|
var has = prop in target;
|
|
if (is_proxied_array && prop === "length") for (var i = value; i < 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, stack));
|
|
sources.set(i + "", other_s);
|
|
tag(other_s, get_label(path, i));
|
|
}
|
|
}
|
|
if (s === void 0) {
|
|
if (!has || get_descriptor(target, prop)?.writable) {
|
|
s = with_parent(() => /* @__PURE__ */ state(void 0, stack));
|
|
tag(s, get_label(path, prop));
|
|
set(s, proxy(value));
|
|
sources.set(prop, s);
|
|
}
|
|
} else {
|
|
has = s.v !== UNINITIALIZED;
|
|
var p = with_parent(() => proxy(value));
|
|
set(s, p);
|
|
}
|
|
var descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
if (descriptor?.set) descriptor.set.call(receiver, value);
|
|
if (!has) {
|
|
if (is_proxied_array && typeof prop === "string") {
|
|
var ls = 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((key) => {
|
|
var source = sources.get(key);
|
|
return source === void 0 || source.v !== UNINITIALIZED;
|
|
});
|
|
for (var [key, source] of sources) if (source.v !== UNINITIALIZED && !(key in target)) own_keys.push(key);
|
|
return own_keys;
|
|
},
|
|
setPrototypeOf() {
|
|
state_prototype_fixed();
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* @param {string} path
|
|
* @param {string | symbol} prop
|
|
*/
|
|
function get_label(path, prop) {
|
|
if (typeof prop === "symbol") return `${path}[Symbol(${prop.description ?? ""})]`;
|
|
if (regex_is_valid_identifier.test(prop)) return `${path}.${prop}`;
|
|
return /^\d+$/.test(prop) ? `${path}[${prop}]` : `${path}['${prop}']`;
|
|
}
|
|
/**
|
|
* @param {any} value
|
|
*/
|
|
function get_proxied_value(value) {
|
|
try {
|
|
if (value !== null && typeof value === "object" && STATE_SYMBOL in value) return value[STATE_SYMBOL];
|
|
} catch {}
|
|
return value;
|
|
}
|
|
/**
|
|
* @param {any} a
|
|
* @param {any} b
|
|
*/
|
|
function is(a, b) {
|
|
return Object.is(get_proxied_value(a), get_proxied_value(b));
|
|
}
|
|
var ARRAY_MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
"copyWithin",
|
|
"fill",
|
|
"pop",
|
|
"push",
|
|
"reverse",
|
|
"shift",
|
|
"sort",
|
|
"splice",
|
|
"unshift"
|
|
]);
|
|
/**
|
|
* Wrap array mutating methods so $inspect is triggered only once and
|
|
* to prevent logging an array in intermediate state (e.g. with an empty slot)
|
|
* @param {any[]} array
|
|
*/
|
|
function inspectable_array(array) {
|
|
return new Proxy(array, { get(target, prop, receiver) {
|
|
var value = Reflect.get(target, prop, receiver);
|
|
if (!ARRAY_MUTATING_METHODS.has(prop)) return value;
|
|
/**
|
|
* @this {any[]}
|
|
* @param {any[]} args
|
|
*/
|
|
return function(...args) {
|
|
set_eager_effects_deferred();
|
|
var result = value.apply(this, args);
|
|
flush_eager_effects();
|
|
return result;
|
|
};
|
|
} });
|
|
}
|
|
// node_modules/svelte/src/internal/client/dev/equality.js
|
|
function init_array_prototype_warnings() {
|
|
const array_prototype = Array.prototype;
|
|
const cleanup = Array.__svelte_cleanup;
|
|
if (cleanup) cleanup();
|
|
const { indexOf, lastIndexOf, includes } = array_prototype;
|
|
array_prototype.indexOf = function(item, from_index) {
|
|
const index = indexOf.call(this, item, from_index);
|
|
if (index === -1) {
|
|
for (let i = from_index ?? 0; i < this.length; i += 1) if (get_proxied_value(this[i]) === item) {
|
|
state_proxy_equality_mismatch("array.indexOf(...)");
|
|
break;
|
|
}
|
|
}
|
|
return index;
|
|
};
|
|
array_prototype.lastIndexOf = function(item, from_index) {
|
|
const index = lastIndexOf.call(this, item, from_index ?? this.length - 1);
|
|
if (index === -1) {
|
|
for (let i = 0; i <= (from_index ?? this.length - 1); i += 1) if (get_proxied_value(this[i]) === item) {
|
|
state_proxy_equality_mismatch("array.lastIndexOf(...)");
|
|
break;
|
|
}
|
|
}
|
|
return index;
|
|
};
|
|
array_prototype.includes = function(item, from_index) {
|
|
const has = includes.call(this, item, from_index);
|
|
if (!has) {
|
|
for (let i = 0; i < this.length; i += 1) if (get_proxied_value(this[i]) === item) {
|
|
state_proxy_equality_mismatch("array.includes(...)");
|
|
break;
|
|
}
|
|
}
|
|
return has;
|
|
};
|
|
Array.__svelte_cleanup = () => {
|
|
array_prototype.indexOf = indexOf;
|
|
array_prototype.lastIndexOf = lastIndexOf;
|
|
array_prototype.includes = includes;
|
|
};
|
|
}
|
|
/**
|
|
* @param {any} a
|
|
* @param {any} b
|
|
* @param {boolean} equal
|
|
* @returns {boolean}
|
|
*/
|
|
function strict_equals(a, b, equal = true) {
|
|
try {
|
|
if (a === b !== (get_proxied_value(a) === get_proxied_value(b))) state_proxy_equality_mismatch(equal ? "===" : "!==");
|
|
} catch {}
|
|
return a === b === equal;
|
|
}
|
|
/**
|
|
* @param {any} a
|
|
* @param {any} b
|
|
* @param {boolean} equal
|
|
* @returns {boolean}
|
|
*/
|
|
function equals(a, b, equal = true) {
|
|
if (a == b !== (get_proxied_value(a) == get_proxied_value(b))) state_proxy_equality_mismatch(equal ? "==" : "!=");
|
|
return a == b === equal;
|
|
}
|
|
// node_modules/svelte/src/internal/client/dom/operations.js
|
|
/** @import { Effect, TemplateNode } from '#client' */
|
|
/** @type {Window} */
|
|
var $window;
|
|
/** @type {Document} */
|
|
var $document;
|
|
/** @type {boolean} */
|
|
var is_firefox;
|
|
/** @type {() => Node | null} */
|
|
var first_child_getter;
|
|
/** @type {() => Node | null} */
|
|
var next_sibling_getter;
|
|
/**
|
|
* Initialize these lazily to avoid issues when using the runtime in a server context
|
|
* where these globals are not available while avoiding a separate server entry point
|
|
*/
|
|
function init_operations() {
|
|
if ($window !== void 0) return;
|
|
$window = window;
|
|
$document = document;
|
|
is_firefox = /Firefox/.test(navigator.userAgent);
|
|
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)) {
|
|
/** @type {any} */ element_prototype[CLASS_CACHE] = void 0;
|
|
/** @type {any} */ element_prototype[ATTRIBUTES_CACHE] = null;
|
|
/** @type {any} */ element_prototype[STYLE_CACHE] = void 0;
|
|
element_prototype.__e = void 0;
|
|
}
|
|
if (is_extensible(text_prototype))
|
|
/** @type {any} */ text_prototype[TEXT_CACHE] = void 0;
|
|
element_prototype.__svelte_meta = null;
|
|
init_array_prototype_warnings();
|
|
}
|
|
/**
|
|
* @param {string} value
|
|
* @returns {Text}
|
|
*/
|
|
function create_text(value = "") {
|
|
return document.createTextNode(value);
|
|
}
|
|
/**
|
|
* @template {Node} N
|
|
* @param {N} node
|
|
*/
|
|
/*@__NO_SIDE_EFFECTS__*/
|
|
function get_first_child(node) {
|
|
return first_child_getter.call(node);
|
|
}
|
|
/**
|
|
* @template {Node} N
|
|
* @param {N} node
|
|
*/
|
|
/*@__NO_SIDE_EFFECTS__*/
|
|
function get_next_sibling(node) {
|
|
return next_sibling_getter.call(node);
|
|
}
|
|
/**
|
|
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
* @template {Node} N
|
|
* @param {N} node
|
|
* @param {boolean} is_text
|
|
* @returns {TemplateNode | null}
|
|
*/
|
|
function child(node, is_text) {
|
|
if (!hydrating) return /* @__PURE__ */ get_first_child(node);
|
|
var child = /* @__PURE__ */ get_first_child(hydrate_node);
|
|
if (child === null) child = hydrate_node.appendChild(create_text());
|
|
else if (is_text && child.nodeType !== 3) {
|
|
var text = create_text();
|
|
child?.before(text);
|
|
set_hydrate_node(text);
|
|
return text;
|
|
}
|
|
if (is_text) merge_text_nodes(child);
|
|
set_hydrate_node(child);
|
|
return child;
|
|
}
|
|
/**
|
|
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
* @param {TemplateNode} node
|
|
* @param {boolean} [is_text]
|
|
* @returns {TemplateNode | null}
|
|
*/
|
|
function first_child(node, is_text = false) {
|
|
if (!hydrating) {
|
|
var first = /* @__PURE__ */ get_first_child(node);
|
|
if (first instanceof Comment && first.data === "") return /* @__PURE__ */ get_next_sibling(first);
|
|
return first;
|
|
}
|
|
if (is_text) {
|
|
if (hydrate_node?.nodeType !== 3) {
|
|
var text = create_text();
|
|
hydrate_node?.before(text);
|
|
set_hydrate_node(text);
|
|
return text;
|
|
}
|
|
merge_text_nodes(hydrate_node);
|
|
}
|
|
return hydrate_node;
|
|
}
|
|
/**
|
|
* `child`, for the very common case of an element with exactly one child. Resetting the
|
|
* hydration cursor is part of the same step, so the compiler doesn't have to emit a
|
|
* separate `reset` call for every `<p>{text}</p>` in an app.
|
|
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
* @param {TemplateNode} node
|
|
* @param {boolean} [is_text]
|
|
* @returns {TemplateNode | null}
|
|
*/
|
|
function only_child(node, is_text = false) {
|
|
if (!hydrating) return /* @__PURE__ */ get_first_child(node);
|
|
var first = child(node, is_text);
|
|
reset(node);
|
|
return first;
|
|
}
|
|
/**
|
|
* Don't mark this as side-effect-free, hydration needs to walk all nodes
|
|
* @param {TemplateNode} node
|
|
* @param {number} count
|
|
* @param {boolean} is_text
|
|
* @returns {TemplateNode | null}
|
|
*/
|
|
function sibling(node, count = 1, is_text = false) {
|
|
let next_sibling = hydrating ? hydrate_node : node;
|
|
var last_sibling;
|
|
while (count--) {
|
|
last_sibling = next_sibling;
|
|
next_sibling = /* @__PURE__ */ get_next_sibling(next_sibling);
|
|
}
|
|
if (!hydrating) return next_sibling;
|
|
if (is_text) {
|
|
if (next_sibling?.nodeType !== 3) {
|
|
var text = create_text();
|
|
if (next_sibling === null) last_sibling?.after(text);
|
|
else next_sibling.before(text);
|
|
set_hydrate_node(text);
|
|
return text;
|
|
}
|
|
merge_text_nodes(next_sibling);
|
|
}
|
|
set_hydrate_node(next_sibling);
|
|
return next_sibling;
|
|
}
|
|
/**
|
|
* @template {Node} N
|
|
* @param {N} node
|
|
* @returns {void}
|
|
*/
|
|
function clear_text_content(node) {
|
|
node.textContent = "";
|
|
}
|
|
/**
|
|
* Returns `true` if we're updating the current block, for example `condition` in
|
|
* an `{#if condition}` block just changed. In this case, the branch should be
|
|
* appended (or removed) at the same time as other updates within the
|
|
* current `<svelte:boundary>`
|
|
*/
|
|
function should_defer_append() {
|
|
if (!async_mode_flag) return false;
|
|
if (eager_block_effects !== null) return false;
|
|
return (active_effect.f & REACTION_RAN) !== 0;
|
|
}
|
|
/**
|
|
* Branching here is intentional and load-bearing for perf. `createElement(tag)`
|
|
* hits a fast path in Blink that `createElementNS(NAMESPACE_HTML, tag)` doesn't,
|
|
* and passing an explicit `undefined` as the trailing options arg measurably
|
|
* slows both APIs. Funnelling every case through a single `createElementNS(ns,
|
|
* tag, options)` call would be smaller but slower on the HTML path.
|
|
*
|
|
* @template {keyof HTMLElementTagNameMap | string} T
|
|
* @param {T} tag
|
|
* @param {string} [namespace]
|
|
* @param {string} [is]
|
|
* @returns {T extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[T] : Element}
|
|
*/
|
|
function create_element(tag, namespace, is) {
|
|
if (namespace == null || namespace === "http://www.w3.org/1999/xhtml") return is ? document.createElement(tag, { is }) : document.createElement(tag);
|
|
return is ? document.createElementNS(namespace, tag, { is }) : document.createElementNS(namespace, tag);
|
|
}
|
|
function create_fragment() {
|
|
return document.createDocumentFragment();
|
|
}
|
|
/**
|
|
* @param {string} data
|
|
* @returns
|
|
*/
|
|
function create_comment(data = "") {
|
|
return document.createComment(data);
|
|
}
|
|
/**
|
|
* @param {Element} element
|
|
* @param {string} key
|
|
* @param {string} value
|
|
* @returns
|
|
*/
|
|
function set_attribute(element, key, value = "") {
|
|
if (key.startsWith("xlink:")) {
|
|
element.setAttributeNS("http://www.w3.org/1999/xlink", key, value);
|
|
return;
|
|
}
|
|
return element.setAttribute(key, value);
|
|
}
|
|
/**
|
|
* Browsers split text nodes larger than 65536 bytes when parsing.
|
|
* For hydration to succeed, we need to stitch them back together
|
|
* @param {Text} text
|
|
*/
|
|
function merge_text_nodes(text) {
|
|
if (text.nodeValue.length < 65536) return;
|
|
let next = text.nextSibling;
|
|
while (next !== null && next.nodeType === 3) {
|
|
next.remove();
|
|
/** @type {string} */ text.nodeValue += next.nodeValue;
|
|
next = text.nextSibling;
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/error-handling.js
|
|
/** @import { Derived, Effect } from '#client' */
|
|
/** @import { Boundary } from './dom/blocks/boundary.js' */
|
|
var adjustments = /* @__PURE__ */ new WeakMap();
|
|
/**
|
|
* @param {unknown} error
|
|
*/
|
|
function handle_error(error) {
|
|
var effect = active_effect;
|
|
if (effect === null) {
|
|
/** @type {Derived} */ active_reaction.f |= ERROR_VALUE;
|
|
return error;
|
|
}
|
|
if (error instanceof Error && !adjustments.has(error)) adjustments.set(error, get_adjustments(error, effect));
|
|
if ((effect.f & 32768) === 0 && (effect.f & 4) === 0) {
|
|
if (!effect.parent && error instanceof Error) apply_adjustments(error);
|
|
throw error;
|
|
}
|
|
invoke_error_boundary(error, effect);
|
|
}
|
|
/**
|
|
* @param {unknown} error
|
|
* @param {Effect | null} effect
|
|
*/
|
|
function invoke_error_boundary(error, effect) {
|
|
if (error === HYDRATION_ERROR) throw error;
|
|
if (effect !== null && (effect.f & 16384) !== 0) return;
|
|
while (effect !== null) {
|
|
if ((effect.f & 128) !== 0 && (effect.f & 33570816) === 0) {
|
|
if ((effect.f & 32768) === 0) throw error;
|
|
try {
|
|
/** @type {Boundary} */ effect.b.error(error);
|
|
return;
|
|
} catch (e) {
|
|
error = e;
|
|
}
|
|
}
|
|
effect = effect.parent;
|
|
}
|
|
if (error instanceof Error) apply_adjustments(error);
|
|
throw error;
|
|
}
|
|
/**
|
|
* Add useful information to the error message/stack in development
|
|
* @param {Error} error
|
|
* @param {Effect} effect
|
|
*/
|
|
function get_adjustments(error, effect) {
|
|
const message_descriptor = get_descriptor(error, "message");
|
|
if (message_descriptor && !message_descriptor.configurable) return;
|
|
var indent = is_firefox ? " " : " ";
|
|
var component_stack = `\n${indent}in ${effect.fn?.name || "<unknown>"}`;
|
|
var context = effect.ctx;
|
|
while (context !== null) {
|
|
component_stack += `\n${indent}in ${context.function?.[FILENAME].split("/").pop()}`;
|
|
context = context.p;
|
|
}
|
|
return {
|
|
message: error.message + `\n${component_stack}\n`,
|
|
stack: error.stack?.split("\n").filter((line) => !line.includes("svelte/src/internal")).join("\n")
|
|
};
|
|
}
|
|
/**
|
|
* @param {Error} error
|
|
*/
|
|
function apply_adjustments(error) {
|
|
const adjusted = adjustments.get(error);
|
|
if (adjusted) {
|
|
define_property(error, "message", { value: adjusted.message });
|
|
define_property(error, "stack", { value: adjusted.stack });
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/reactivity/effects.js
|
|
/** @import { Blocker, ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
|
|
/**
|
|
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
|
|
*/
|
|
function validate_effect(rune) {
|
|
if (active_effect === null) {
|
|
if (active_reaction === null) effect_orphan(rune);
|
|
effect_in_unowned_derived();
|
|
}
|
|
if (is_destroying_effect) effect_in_teardown(rune);
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {Effect} parent_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;
|
|
}
|
|
}
|
|
/**
|
|
* @param {number} type
|
|
* @param {null | (() => void | (() => void))} fn
|
|
* @returns {Effect}
|
|
*/
|
|
function create_effect(type, fn) {
|
|
var parent = active_effect;
|
|
while (parent !== null && (parent.f & 131072) !== 0) parent = parent.parent;
|
|
if (parent !== null && (parent.f & 8192) !== 0) type |= INERT;
|
|
/** @type {Effect} */
|
|
var effect = {
|
|
ctx: component_context,
|
|
deps: null,
|
|
nodes: null,
|
|
f: type | DIRTY | 512,
|
|
first: null,
|
|
fn,
|
|
last: null,
|
|
next: null,
|
|
parent,
|
|
b: parent && parent.b,
|
|
prev: null,
|
|
teardown: null,
|
|
wv: 0,
|
|
ac: null
|
|
};
|
|
effect.component_function = dev_current_component_function;
|
|
current_batch?.register_created_effect(effect);
|
|
/** @type {Effect | null} */
|
|
var e = effect;
|
|
if ((type & 4) !== 0) {
|
|
if (collected_effects !== null) collected_effects.push(effect);
|
|
else Batch.ensure().schedule(effect);
|
|
} else if (fn !== null) {
|
|
try {
|
|
update_effect(effect);
|
|
} catch (e) {
|
|
destroy_effect(effect);
|
|
throw e;
|
|
}
|
|
if (e.deps === null && e.teardown === null && e.nodes === null && e.first === e.last && (e.f & 524288) === 0) {
|
|
e = e.first;
|
|
if ((type & 16) !== 0 && (type & 65536) !== 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 & 2) !== 0 && (type & 64) === 0) {
|
|
var derived = active_reaction;
|
|
(derived.effects ??= []).push(e);
|
|
}
|
|
}
|
|
return effect;
|
|
}
|
|
/**
|
|
* Internal representation of `$effect.tracking()`
|
|
* @returns {boolean}
|
|
*/
|
|
function effect_tracking() {
|
|
return active_reaction !== null && !untracking;
|
|
}
|
|
/**
|
|
* @param {() => void} fn
|
|
*/
|
|
function teardown(fn) {
|
|
const effect = create_effect(8, null);
|
|
set_signal_status(effect, CLEAN);
|
|
effect.teardown = fn;
|
|
return effect;
|
|
}
|
|
/**
|
|
* Internal representation of `$effect(...)`
|
|
* @param {() => void | (() => void)} fn
|
|
*/
|
|
function user_effect(fn) {
|
|
validate_effect("$effect");
|
|
define_property(fn, "name", { value: "$effect" });
|
|
var flags = active_effect.f;
|
|
if (!active_reaction && (flags & 32) !== 0 && component_context !== null && !component_context.i) {
|
|
var context = component_context;
|
|
(context.e ??= []).push(fn);
|
|
} else return create_user_effect(fn);
|
|
}
|
|
/**
|
|
* @param {() => void | (() => void)} fn
|
|
*/
|
|
function create_user_effect(fn) {
|
|
return create_effect(4 | USER_EFFECT, fn);
|
|
}
|
|
/**
|
|
* Internal representation of `$effect.pre(...)`
|
|
* @param {() => void | (() => void)} fn
|
|
* @returns {Effect}
|
|
*/
|
|
function user_pre_effect(fn) {
|
|
validate_effect("$effect.pre");
|
|
define_property(fn, "name", { value: "$effect.pre" });
|
|
return create_effect(8 | USER_EFFECT, fn);
|
|
}
|
|
/** @param {() => void | (() => void)} fn */
|
|
function eager_effect(fn) {
|
|
return create_effect(EAGER_EFFECT, fn);
|
|
}
|
|
/**
|
|
* Internal representation of `$effect.root(...)`
|
|
* @param {() => void | (() => void)} fn
|
|
* @returns {() => void}
|
|
*/
|
|
function effect_root(fn) {
|
|
Batch.ensure();
|
|
const effect = create_effect(64 | EFFECT_PRESERVED, fn);
|
|
return () => {
|
|
destroy_effect(effect);
|
|
};
|
|
}
|
|
/**
|
|
* An effect root whose children can transition out
|
|
* @param {() => void} fn
|
|
* @returns {(options?: { outro?: boolean }) => Promise<void>}
|
|
*/
|
|
function component_root(fn) {
|
|
Batch.ensure();
|
|
const effect = create_effect(64 | EFFECT_PRESERVED, fn);
|
|
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);
|
|
}
|
|
});
|
|
};
|
|
}
|
|
/**
|
|
* @param {() => void | (() => void)} fn
|
|
* @returns {Effect}
|
|
*/
|
|
function effect(fn) {
|
|
return create_effect(4, fn);
|
|
}
|
|
/**
|
|
* Internal representation of `$: ..`
|
|
* @param {() => any} deps
|
|
* @param {() => void | (() => void)} fn
|
|
*/
|
|
function legacy_pre_effect(deps, fn) {
|
|
var context = component_context;
|
|
/** @type {{ effect: null | Effect, ran: boolean, deps: () => any }} */
|
|
var token = {
|
|
effect: null,
|
|
ran: false,
|
|
deps
|
|
};
|
|
context.l.$.push(token);
|
|
token.effect = render_effect(() => {
|
|
deps();
|
|
if (token.ran) return;
|
|
token.ran = true;
|
|
var effect = active_effect;
|
|
try {
|
|
set_active_effect(effect.parent);
|
|
untrack(fn);
|
|
} finally {
|
|
set_active_effect(effect);
|
|
}
|
|
});
|
|
}
|
|
function legacy_pre_effect_reset() {
|
|
var context = component_context;
|
|
render_effect(() => {
|
|
for (var token of context.l.$) {
|
|
token.deps();
|
|
var effect = token.effect;
|
|
if ((effect.f & 1024) !== 0 && effect.deps !== null) set_signal_status(effect, MAYBE_DIRTY);
|
|
if (is_dirty(effect)) update_effect(effect);
|
|
token.ran = false;
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* @param {() => void | (() => void)} fn
|
|
* @returns {Effect}
|
|
*/
|
|
function async_effect(fn) {
|
|
return create_effect(ASYNC | EFFECT_PRESERVED, fn);
|
|
}
|
|
/**
|
|
* @param {() => void | (() => void)} fn
|
|
* @returns {Effect}
|
|
*/
|
|
function render_effect(fn, flags = 0) {
|
|
return create_effect(8 | flags, fn);
|
|
}
|
|
/**
|
|
* @param {(...expressions: any) => void | (() => void)} fn
|
|
* @param {Array<() => any>} sync
|
|
* @param {Array<() => Promise<any>>} async
|
|
* @param {Blocker[]} blockers
|
|
*/
|
|
function template_effect(fn, sync = [], async = [], blockers = []) {
|
|
flatten(blockers, sync, async, (values) => {
|
|
create_effect(8, () => {
|
|
fn(...values.map(get));
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* Like `template_effect`, but with an effect which is deferred until the batch commits
|
|
* @param {(...expressions: any) => void | (() => void)} fn
|
|
* @param {Array<() => any>} sync
|
|
* @param {Array<() => Promise<any>>} async
|
|
* @param {Blocker[]} blockers
|
|
*/
|
|
function deferred_template_effect(fn, sync = [], async = [], blockers = []) {
|
|
flatten(blockers, sync, async, (values) => {
|
|
create_effect(4, () => fn(...values.map(get)));
|
|
});
|
|
}
|
|
/**
|
|
* @param {(() => void)} fn
|
|
* @param {number} flags
|
|
*/
|
|
function block(fn, flags = 0) {
|
|
var effect = create_effect(16 | flags, fn);
|
|
effect.dev_stack = dev_stack;
|
|
return effect;
|
|
}
|
|
/**
|
|
* @param {(() => void)} fn
|
|
* @param {number} flags
|
|
*/
|
|
function managed(fn, flags = 0) {
|
|
var effect = create_effect(MANAGED_EFFECT | flags, fn);
|
|
effect.dev_stack = dev_stack;
|
|
return effect;
|
|
}
|
|
/**
|
|
* @param {(() => void)} fn
|
|
*/
|
|
function branch(fn) {
|
|
return create_effect(32 | EFFECT_PRESERVED, fn);
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
*/
|
|
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);
|
|
} catch (error) {
|
|
invoke_error_boundary(error, effect.parent);
|
|
} finally {
|
|
set_is_destroying_effect(previously_destroying_effect);
|
|
set_active_reaction(previous_reaction);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @param {Effect} signal
|
|
* @param {boolean} remove_dom
|
|
* @returns {void}
|
|
*/
|
|
function destroy_effect_children(signal, remove_dom = false) {
|
|
var effect = signal.first;
|
|
signal.first = signal.last = null;
|
|
while (effect !== null) {
|
|
const controller = effect.ac;
|
|
if (controller !== null) without_reactive_context(() => {
|
|
controller.abort(STALE_REACTION);
|
|
});
|
|
var next = effect.next;
|
|
if ((effect.f & 64) !== 0) effect.parent = null;
|
|
else destroy_effect(effect, remove_dom);
|
|
effect = next;
|
|
}
|
|
}
|
|
/**
|
|
* @param {Effect} signal
|
|
* @returns {void}
|
|
*/
|
|
function destroy_block_effect_children(signal) {
|
|
var effect = signal.first;
|
|
while (effect !== null) {
|
|
var next = effect.next;
|
|
if ((effect.f & 32) === 0) destroy_effect(effect);
|
|
effect = next;
|
|
}
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {boolean} [remove_dom]
|
|
* @returns {void}
|
|
*/
|
|
function destroy_effect(effect, remove_dom = true) {
|
|
var removed = false;
|
|
if ((remove_dom || (effect.f & 262144) !== 0) && effect.nodes !== null && effect.nodes.end !== null) {
|
|
remove_effect_dom(effect.nodes.start, effect.nodes.end);
|
|
removed = true;
|
|
}
|
|
effect.f |= DESTROYING;
|
|
destroy_effect_children(effect, remove_dom && !removed);
|
|
remove_reactions(effect, 0);
|
|
var transitions = effect.nodes && effect.nodes.t;
|
|
if (transitions !== null) for (const transition of transitions) transition.stop();
|
|
execute_effect_teardown(effect);
|
|
effect.f ^= DESTROYING;
|
|
effect.f |= DESTROYED;
|
|
var parent = effect.parent;
|
|
if (parent !== null && parent.first !== null) unlink_effect(effect);
|
|
effect.component_function = null;
|
|
effect.next = effect.prev = effect.teardown = effect.ctx = effect.deps = effect.fn = effect.nodes = effect.ac = effect.b = null;
|
|
}
|
|
/**
|
|
*
|
|
* @param {TemplateNode | null} node
|
|
* @param {TemplateNode} end
|
|
*/
|
|
function remove_effect_dom(node, end) {
|
|
while (node !== null) {
|
|
/** @type {TemplateNode | null} */
|
|
var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
|
|
node.remove();
|
|
node = next;
|
|
}
|
|
}
|
|
/**
|
|
* Detach an effect from the effect tree, freeing up memory and
|
|
* reducing the amount of work that happens on subsequent traversals
|
|
* @param {Effect} effect
|
|
*/
|
|
function unlink_effect(effect) {
|
|
var parent = effect.parent;
|
|
var prev = effect.prev;
|
|
var next = effect.next;
|
|
if (prev !== null) prev.next = next;
|
|
if (next !== null) next.prev = prev;
|
|
if (parent !== null) {
|
|
if (parent.first === effect) parent.first = next;
|
|
if (parent.last === effect) parent.last = prev;
|
|
}
|
|
}
|
|
/**
|
|
* When a block effect is removed, we don't immediately destroy it or yank it
|
|
* out of the DOM, because it might have transitions. Instead, we 'pause' it.
|
|
* It stays around (in memory, and in the DOM) until outro transitions have
|
|
* completed, and if the state change is reversed then we _resume_ it.
|
|
* A paused effect does not update, and the DOM subtree becomes inert.
|
|
* @param {Effect} effect
|
|
* @param {() => void} [callback]
|
|
* @param {boolean} [destroy]
|
|
*/
|
|
function pause_effect(effect, callback, destroy = true) {
|
|
/** @type {TransitionManager[]} */
|
|
var transitions = [];
|
|
effect.f |= 256;
|
|
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();
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {TransitionManager[]} transitions
|
|
* @param {boolean} local
|
|
*/
|
|
function pause_children(effect, transitions, local) {
|
|
if ((effect.f & 8192) !== 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;
|
|
if ((child.f & 64) === 0) {
|
|
var transparent = (child.f & 65536) !== 0 || (child.f & 32) !== 0 && (effect.f & 16) !== 0;
|
|
pause_children(child, transitions, transparent ? local : false);
|
|
}
|
|
child = sibling;
|
|
}
|
|
}
|
|
/**
|
|
* The opposite of `pause_effect`. We call this if (for example)
|
|
* `x` becomes falsy then truthy: `{#if x}...{/if}`
|
|
* @param {Effect} effect
|
|
*/
|
|
function resume_effect(effect) {
|
|
effect.f &= -257;
|
|
resume_children(effect, true);
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {boolean} local
|
|
*/
|
|
function resume_children(effect, local) {
|
|
if ((effect.f & 256) !== 0) return;
|
|
if ((effect.f & 8192) === 0) return;
|
|
effect.f ^= INERT;
|
|
if ((effect.f & 1024) === 0) {
|
|
set_signal_status(effect, DIRTY);
|
|
Batch.ensure().schedule(effect);
|
|
}
|
|
var child = effect.first;
|
|
while (child !== null) {
|
|
var sibling = child.next;
|
|
var transparent = (child.f & 65536) !== 0 || (child.f & 32) !== 0;
|
|
resume_children(child, transparent ? local : false);
|
|
child = sibling;
|
|
}
|
|
var t = effect.nodes && effect.nodes.t;
|
|
if (t !== null) {
|
|
for (const transition of t) if (transition.is_global || local) transition.in();
|
|
}
|
|
}
|
|
function aborted(effect = active_effect) {
|
|
return (effect.f & DESTROYED) !== 0;
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @param {DocumentFragment} fragment
|
|
*/
|
|
function move_effect(effect, fragment) {
|
|
if (!effect.nodes) return;
|
|
/** @type {TemplateNode | null} */
|
|
var node = effect.nodes.start;
|
|
var end = effect.nodes.end;
|
|
while (node !== null) {
|
|
/** @type {TemplateNode | null} */
|
|
var next = node === end ? null : /* @__PURE__ */ get_next_sibling(node);
|
|
fragment.append(node);
|
|
node = next;
|
|
}
|
|
}
|
|
// node_modules/svelte/src/internal/client/legacy.js
|
|
/** @import { Value } from '#client' */
|
|
/**
|
|
* @type {Set<Value> | null}
|
|
* @deprecated
|
|
*/
|
|
var captured_signals = null;
|
|
/**
|
|
* Capture an array of all the signals that are read when `fn` is called
|
|
* @template T
|
|
* @param {() => T} fn
|
|
*/
|
|
function capture_signals(fn) {
|
|
var previous_captured_signals = captured_signals;
|
|
try {
|
|
captured_signals = /* @__PURE__ */ new Set();
|
|
untrack(fn);
|
|
if (previous_captured_signals !== null) for (var signal of captured_signals) previous_captured_signals.add(signal);
|
|
return captured_signals;
|
|
} finally {
|
|
captured_signals = previous_captured_signals;
|
|
}
|
|
}
|
|
/**
|
|
* Invokes a function and captures all signals that are read during the invocation,
|
|
* then invalidates them.
|
|
* @param {() => any} fn
|
|
* @deprecated
|
|
*/
|
|
function invalidate_inner_signals(fn) {
|
|
for (var signal of capture_signals(fn)) internal_set(signal, signal.v);
|
|
}
|
|
// node_modules/svelte/src/internal/client/runtime.js
|
|
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
|
|
var is_destroying_effect = false;
|
|
/** @param {boolean} value */
|
|
function set_is_destroying_effect(value) {
|
|
is_destroying_effect = value;
|
|
}
|
|
/** @type {null | Reaction} */
|
|
var active_reaction = null;
|
|
var untracking = false;
|
|
/** @param {null | Reaction} reaction */
|
|
function set_active_reaction(reaction) {
|
|
active_reaction = reaction;
|
|
}
|
|
/** @type {null | Effect} */
|
|
var active_effect = null;
|
|
/** @param {null | Effect} effect */
|
|
function set_active_effect(effect) {
|
|
active_effect = effect;
|
|
}
|
|
/**
|
|
* When sources are created within a reaction, reading and writing
|
|
* them within that reaction should not cause a re-run
|
|
* @type {null | Set<Value>}
|
|
*/
|
|
var current_sources = null;
|
|
/** @param {Value} value */
|
|
function push_reaction_value(value) {
|
|
if (active_reaction !== null && (!async_mode_flag && (active_reaction.f & 2097152) !== 0 || (active_reaction.f & 2) !== 0)) (current_sources ??= /* @__PURE__ */ new Set()).add(value);
|
|
}
|
|
/**
|
|
* The dependencies of the reaction that is currently being executed. In many cases,
|
|
* the dependencies are unchanged between runs, and so this will be `null` unless
|
|
* and until a new dependency is accessed — we track this via `skipped_deps`
|
|
* @type {null | Value[]}
|
|
*/
|
|
var new_deps = null;
|
|
var skipped_deps = 0;
|
|
/**
|
|
* Tracks writes that the effect it's executed in doesn't listen to yet,
|
|
* so that the dependency can be added to the effect later on if it then reads it
|
|
* @type {null | Value[]}
|
|
*/
|
|
var untracked_writes = null;
|
|
/** @param {null | Value[]} value */
|
|
function set_untracked_writes(value) {
|
|
untracked_writes = value;
|
|
}
|
|
/**
|
|
* @type {number} Used by sources and deriveds for handling updates.
|
|
* Version starts from 1 so that unowned deriveds differentiate between a created effect and a run one for tracing
|
|
**/
|
|
var write_version = 1;
|
|
/** @type {number} Used to version each read of a source of derived to avoid duplicating dependencies inside a reaction */
|
|
var read_version = 0;
|
|
var update_version = read_version;
|
|
/** @param {number} value */
|
|
function set_update_version(value) {
|
|
update_version = value;
|
|
}
|
|
function increment_write_version() {
|
|
return ++write_version;
|
|
}
|
|
/**
|
|
* Determines whether a derived or effect is dirty.
|
|
* If it is MAYBE_DIRTY, will set the status to CLEAN
|
|
* @param {Reaction} reaction
|
|
* @returns {boolean}
|
|
*/
|
|
function is_dirty(reaction) {
|
|
var flags = reaction.f;
|
|
if ((flags & 2048) !== 0) return true;
|
|
if ((flags & 4096) !== 0) {
|
|
var dependencies = reaction.deps;
|
|
var length = dependencies.length;
|
|
for (var i = 0; i < length; i++) {
|
|
var dependency = dependencies[i];
|
|
if (is_dirty(dependency)) update_derived(dependency);
|
|
if (dependency.wv > reaction.wv) return true;
|
|
}
|
|
if ((flags & 512) !== 0 && batch_values === null) set_signal_status(reaction, CLEAN);
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* @param {Value} signal
|
|
* @param {Effect} effect
|
|
* @param {boolean} [root]
|
|
*/
|
|
function schedule_possible_effect_self_invalidation(signal, effect, root = true) {
|
|
var reactions = signal.reactions;
|
|
if (reactions === null) return;
|
|
if (!async_mode_flag && current_sources !== null && current_sources.has(signal)) return;
|
|
for (var i = 0; i < reactions.length; i++) {
|
|
var reaction = reactions[i];
|
|
if ((reaction.f & 2) !== 0) schedule_possible_effect_self_invalidation(reaction, effect, false);
|
|
else if (effect === reaction) {
|
|
if (root) set_signal_status(reaction, DIRTY);
|
|
else if ((reaction.f & 1024) !== 0) set_signal_status(reaction, MAYBE_DIRTY);
|
|
schedule_effect(reaction);
|
|
}
|
|
}
|
|
}
|
|
/** @param {Reaction} 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 flags = reaction.f;
|
|
new_deps = null;
|
|
skipped_deps = 0;
|
|
untracked_writes = null;
|
|
active_reaction = (flags & 96) === 0 ? reaction : null;
|
|
current_sources = null;
|
|
set_component_context(reaction.ctx);
|
|
untracking = false;
|
|
update_version = ++read_version;
|
|
if (reaction.ac !== null) {
|
|
without_reactive_context(() => {
|
|
/** @type {AbortController} */ reaction.ac.abort(STALE_REACTION);
|
|
});
|
|
reaction.ac = null;
|
|
}
|
|
try {
|
|
reaction.f |= REACTION_IS_UPDATING;
|
|
var fn = reaction.fn;
|
|
var result = fn();
|
|
reaction.f |= REACTION_RAN;
|
|
var deps = update_dependencies(reaction);
|
|
if (is_runes() && untracked_writes !== null && !untracking && deps !== null && (reaction.f & 6146) === 0) for (var i = 0; i < untracked_writes.length; i++) schedule_possible_effect_self_invalidation(untracked_writes[i], reaction);
|
|
if (previous_reaction !== null && previous_reaction !== reaction) {
|
|
read_version++;
|
|
if (previous_reaction.deps !== null) for (let i = 0; i < previous_skipped_deps; i += 1) previous_reaction.deps[i].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(...untracked_writes);
|
|
}
|
|
}
|
|
if ((reaction.f & 8388608) !== 0) reaction.f ^= ERROR_VALUE;
|
|
return result;
|
|
} catch (error) {
|
|
update_dependencies(reaction);
|
|
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;
|
|
}
|
|
}
|
|
/**
|
|
* @param {Reaction} reaction
|
|
*/
|
|
function update_dependencies(reaction) {
|
|
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 & 512) !== 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;
|
|
}
|
|
return deps;
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {Reaction} signal
|
|
* @param {Value<V>} dependency
|
|
* @returns {void}
|
|
*/
|
|
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 & 2) !== 0 && (new_deps === null || !includes.call(new_deps, dependency))) {
|
|
var derived = dependency;
|
|
if ((derived.f & 512) !== 0) derived.f ^= 512;
|
|
if (derived.v !== UNINITIALIZED) update_derived_status(derived);
|
|
if (derived.ac !== null) without_reactive_context(() => {
|
|
/** @type {AbortController} */ derived.ac.abort(STALE_REACTION);
|
|
derived.ac = null;
|
|
set_signal_status(derived, DIRTY);
|
|
});
|
|
freeze_derived_effects(derived);
|
|
remove_reactions(derived, 0);
|
|
}
|
|
}
|
|
/**
|
|
* @param {Reaction} signal
|
|
* @param {number} start_index
|
|
* @returns {void}
|
|
*/
|
|
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]);
|
|
}
|
|
/**
|
|
* @param {Effect} effect
|
|
* @returns {void}
|
|
*/
|
|
function update_effect(effect) {
|
|
var flags = effect.f;
|
|
if ((flags & 16384) !== 0) return;
|
|
set_signal_status(effect, CLEAN);
|
|
var previous_effect = active_effect;
|
|
active_effect = effect;
|
|
var previous_component_fn = dev_current_component_function;
|
|
set_dev_current_component_function(effect.component_function);
|
|
var previous_stack = dev_stack;
|
|
set_dev_stack(effect.dev_stack ?? dev_stack);
|
|
try {
|
|
if ((flags & 16777232) !== 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;
|
|
if (tracing_mode_flag && (effect.f & 2048) !== 0 && effect.deps !== null) {
|
|
for (var dep of effect.deps) if (dep.set_during_effect) {
|
|
dep.wv = increment_write_version();
|
|
dep.set_during_effect = false;
|
|
}
|
|
}
|
|
} finally {
|
|
active_effect = previous_effect;
|
|
set_dev_current_component_function(previous_component_fn);
|
|
set_dev_stack(previous_stack);
|
|
}
|
|
}
|
|
/**
|
|
* Returns a promise that resolves once any pending state changes have been applied.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async function tick() {
|
|
if (async_mode_flag) return new Promise((f) => {
|
|
requestAnimationFrame(() => f());
|
|
setTimeout(() => f());
|
|
});
|
|
await Promise.resolve();
|
|
flushSync();
|
|
}
|
|
/**
|
|
* Returns a promise that resolves once any state changes, and asynchronous work resulting from them,
|
|
* have resolved and the DOM has been updated
|
|
* @returns {Promise<void>}
|
|
* @since 5.36
|
|
*/
|
|
function settled() {
|
|
return Batch.ensure().settled();
|
|
}
|
|
/**
|
|
* @template V
|
|
* @param {Value<V>} signal
|
|
* @returns {V}
|
|
*/
|
|
function get(signal) {
|
|
var is_derived = (signal.f & 2) !== 0;
|
|
captured_signals?.add(signal);
|
|
if (active_reaction !== null && !untracking) {
|
|
if (!(active_effect !== null && (active_effect.f & 16384) !== 0) && (current_sources === null || !current_sources.has(signal))) {
|
|
var deps = active_reaction.deps;
|
|
if ((active_reaction.f & 2097152) !== 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 ??= [];
|
|
if (!includes.call(active_reaction.deps, signal)) 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 (!untracking && reactivity_loss_tracker && current_batch === null && previous_batch === null && !reactivity_loss_tracker.warned && (reactivity_loss_tracker.effect.f & 2097152) === 0 && !reactivity_loss_tracker.effect_deps.has(signal)) {
|
|
reactivity_loss_tracker.warned = true;
|
|
await_reactivity_loss(signal.label);
|
|
var trace = get_error("traced at");
|
|
if (trace) console.warn(trace);
|
|
}
|
|
recent_async_deriveds.delete(signal);
|
|
if (tracing_mode_flag && !untracking && tracing_expressions !== null && active_reaction !== null && tracing_expressions.reaction === active_reaction) {
|
|
if (signal.trace) signal.trace();
|
|
else {
|
|
trace = get_error("traced at");
|
|
if (trace) {
|
|
var entry = tracing_expressions.entries.get(signal);
|
|
if (entry === void 0) {
|
|
entry = { traces: [] };
|
|
tracing_expressions.entries.set(signal, entry);
|
|
}
|
|
var last = entry.traces[entry.traces.length - 1];
|
|
if (trace.stack !== last?.stack) entry.traces.push(trace);
|
|
}
|
|
}
|
|
}
|
|
if (is_destroying_effect && old_values.has(signal)) return old_values.get(signal);
|
|
if (is_derived) {
|
|
var derived = signal;
|
|
if (is_destroying_effect) {
|
|
var value = derived.v;
|
|
if ((derived.f & 1024) === 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 & 512) === 0 && !untracking && active_reaction !== null && (active_reaction.f & 512) !== 0;
|
|
var is_new = (derived.f & REACTION_RAN) === 0;
|
|
if (is_dirty(derived)) {
|
|
if (should_connect) derived.f |= 512;
|
|
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 & 8388608) !== 0) throw signal.v;
|
|
return signal.v;
|
|
}
|
|
/**
|
|
* (Re)connect a disconnected derived, so that it is notified
|
|
* of changes in `mark_reactions`
|
|
* @param {Derived} derived
|
|
*/
|
|
function reconnect(derived) {
|
|
derived.f |= 512;
|
|
if (derived.deps === null) return;
|
|
for (const dep of derived.deps) {
|
|
var reactions = dep.reactions;
|
|
if (reactions === null) dep.reactions = [derived];
|
|
else if (!includes.call(reactions, derived)) reactions.push(derived);
|
|
if ((dep.f & 2) !== 0 && (dep.f & 512) === 0) {
|
|
unfreeze_derived_effects(dep);
|
|
reconnect(dep);
|
|
}
|
|
}
|
|
}
|
|
/** @param {Derived} derived */
|
|
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 & 2) !== 0 && depends_on_old_values(dep)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* Like `get`, but checks for `undefined`. Used for `var` declarations because they can be accessed before being declared
|
|
* @template V
|
|
* @param {Value<V> | undefined} signal
|
|
* @returns {V | undefined}
|
|
*/
|
|
function safe_get(signal) {
|
|
return signal && get(signal);
|
|
}
|
|
/**
|
|
* When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect),
|
|
* any state read inside `fn` will not be treated as a dependency.
|
|
*
|
|
* ```ts
|
|
* $effect(() => {
|
|
* // this will run when `data` changes, but not when `time` changes
|
|
* save(data, {
|
|
* timestamp: untrack(() => time)
|
|
* });
|
|
* });
|
|
* ```
|
|
* @template T
|
|
* @param {() => T} fn
|
|
* @returns {T}
|
|
*/
|
|
function untrack(fn) {
|
|
var previous_untracking = untracking;
|
|
try {
|
|
untracking = true;
|
|
return fn();
|
|
} finally {
|
|
untracking = previous_untracking;
|
|
}
|
|
}
|
|
/**
|
|
* Possibly traverse an object and read all its properties so that they're all reactive in case this is `$state`.
|
|
* Does only check first level of an object for performance reasons (heuristic should be good for 99% of all cases).
|
|
* @param {any} value
|
|
* @returns {void}
|
|
*/
|
|
function deep_read_state(value) {
|
|
if (typeof value !== "object" || !value || value instanceof EventTarget) return;
|
|
if (STATE_SYMBOL in value) deep_read(value);
|
|
else if (!Array.isArray(value)) for (let key in value) {
|
|
const prop = value[key];
|
|
if (typeof prop === "object" && prop && STATE_SYMBOL in prop) deep_read(prop);
|
|
}
|
|
}
|
|
/**
|
|
* Deeply traverse an object and read all its properties
|
|
* so that they're all reactive in case this is `$state`
|
|
* @param {any} value
|
|
* @param {Set<any>} visited
|
|
* @returns {void}
|
|
*/
|
|
function deep_read(value, visited = /* @__PURE__ */ new Set()) {
|
|
if (typeof value === "object" && value !== null && !(value instanceof EventTarget) && !visited.has(value)) {
|
|
visited.add(value);
|
|
if (value instanceof Date) value.getTime();
|
|
for (let key in value) try {
|
|
deep_read(value[key], visited);
|
|
} catch (e) {}
|
|
const proto = get_prototype_of(value);
|
|
if (proto !== Object.prototype && proto !== Array.prototype && proto !== Map.prototype && proto !== Set.prototype && proto !== Date.prototype) {
|
|
const descriptors = get_descriptors(proto);
|
|
for (let key in descriptors) {
|
|
const get = descriptors[key].get;
|
|
if (get) try {
|
|
get.call(value);
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
export { only_child as $, NAMESPACE_SVG as $n, hasContext as $t, remove_effect_dom as A, invalid_default_snippet as An, is_array as Ar, run as At, $window as B, hydrating as Bn, add_form_reset_listener as Bt, effect_root as C, invalid_snippet as Cn, define_property as Cr, async_derived as Ct, managed as D, rune_outside_svelte as Dn, get_descriptors as Dr, capture as Dt, legacy_pre_effect_reset as E, props_rest_readonly as En, get_descriptor as Er, user_derived as Et, user_effect as F, svelte_element_invalid_this_value as Fn, run$1 as Fr, unset_context as Ft, create_fragment as G, set_hydrating as Gn, queue_micro_task as Gt, clear_text_content as H, read_hydration_instruction as Hn, remove_textarea_child as Ht, user_pre_effect as I, safe_not_equal as In, run_all as Ir, wait as It, get_first_child as J, FILENAME as Jn, createContext as Jt, create_text as K, skip_nodes as Kn, add_svelte_meta as Kt, validate_effect as L, hydrate_next as Ln, to_array as Lr, listen as Lt, resume_effect as M, lifecycle_outside_component as Mn, is_promise as Mr, save as Mt, teardown as N, snippet_without_render_tag as Nn, noop as Nr, track_reactivity_loss as Nt, move_effect as O, svelte_boundary_reset_onerror as On, get_prototype_of as Or, flatten as Ot, template_effect as P, store_invalid_shape as Pn, object_keys as Pr, unsave as Pt, merge_text_nodes as Q, NAMESPACE_MATHML as Qn, getContext as Qt, invoke_error_boundary as R, hydrate_node as Rn, listen_to_event_and_reset_event as Rt, effect as S, hydration_failed as Sn, deferred as Sr, previous_batch as St, legacy_pre_effect as T, props_invalid_value as Tn, fallback as Tr, derived_safe_equal as Tt, create_comment as U, reset as Un, defer_effect as Ut, child as V, next as Vn, autofocus as Vt, create_element as W, set_hydrate_node as Wn, set_signal_status as Wt, init_operations as X, HYDRATION_ERROR as Xn, dev_stack as Xt, get_next_sibling as Y, HMR as Yn, dev_current_component_function as Yt, is_firefox as Z, NAMESPACE_HTML as Zn, getAllContexts as Zt, branch as _, each_key_duplicate as _n, REACTION_RAN as _r, current_batch as _t, get as a, set_component_context as an, DIRTY as ar, is as at, destroy_effect as b, get_abort_signal_outside_reaction as bn, TEXT_CACHE as br, fork as bt, set_active_effect as c, label as cn, EFFECT_TRANSPARENT as cr, internal_set as ct, tick as d, trace as dn, HMR_ANCHOR as dr, set as dt, is_runes as en, UNINITIALIZED as er, set_attribute as et, untrack as f, snapshot as fn, INERT as fr, source as ft, block as g, component_api_invalid_new as gn, MAYBE_DIRTY as gr, Batch as gt, aborted as h, component_api_changed as hn, LOADING_ATTR_SYMBOL as hr, update_pre as ht, deep_read_state as i, setContext as in, DESTROYING as ir, strict_equals as it, render_effect as j, invalid_snippet_arguments as jn, is_function as jr, run_after_blockers as jt, pause_effect as k, experimental_async_required as kn, has_own_property as kr, for_await_track_reactivity_loss as kt, set_active_reaction as l, tag as ln, FORM_RESET_HANDLER as lr, mutable_source as lt, invalidate_inner_signals as m, bind_invalid_checkbox_value as mn, LEGACY_PROPS as mr, update as mt, active_reaction as n, pop as nn, CLASS_CACHE as nr, sibling as nt, is_destroying_effect as o, set_dev_current_component_function as on, EFFECT_OFFSCREEN as or, proxy as ot, update_version as p, dynamic_void_element_content as pn, IS_XHTML as pr, state as pt, first_child as q, ATTACHMENT_KEY as qn, component_context as qt, deep_read as r, push as rn, DESTROYED as rr, equals as rt, safe_get as s, get_error as sn, EFFECT_PRESERVED as sr, increment as st, active_effect as t, mark_as_component as tn, ATTRIBUTES_CACHE as tr, should_defer_append as tt, settled as u, tag_proxy as un, HEAD_EFFECT as ur, mutate as ut, component_root as v, each_key_volatile as vn, STATE_SYMBOL as vr, eager as vt, effect_tracking as w, lifecycle_legacy_only as wn, exclude_from_object as wr, derived as wt, eager_effect as x, hydratable_missing_but_required as xn, array_from as xr, is_flushing_sync as xt, deferred_template_effect as y, effect_pending_outside_reaction as yn, STYLE_CACHE as yr, flushSync as yt, $document as z, hydrate_template as zn, without_reactive_context as zt };
|