1132 lines
33 KiB
JavaScript
1132 lines
33 KiB
JavaScript
import { G as render, H as set, L as LEGACY_PROPS, I as get, J as flushSync, K as define_property, M as mutable_source, N as init_operations, O as get_first_child, P as COMMENT_NODE, Q as HYDRATION_START, R as get_next_sibling, S as HYDRATION_ERROR, T as hydration_failed, U as clear_text_content, V as component_root, W as create_text, X as array_from, Y as is_passive_event, Z as set_active_reaction, _ as set_active_effect, $ as active_reaction, a0 as active_effect, k as setContext, a1 as BOUNDARY_EFFECT, a2 as block, a3 as branch, a4 as queue_micro_task, a5 as Batch, a6 as pause_effect, a7 as move_effect, a8 as defer_effect, a9 as set_component_context, aa as handle_error, ab as component_context, ac as set_signal_status, ad as DIRTY, ae as schedule_effect, af as MAYBE_DIRTY, ag as internal_set, ah as destroy_effect, ai as invoke_error_boundary, aj as svelte_boundary_reset_onerror, ak as effect_tracking, al as render_effect, am as HYDRATION_END, an as HYDRATION_START_ELSE, ao as source, ap as untrack, aq as increment, ar as push$1, as as pop$1, at as EFFECT_TRANSPARENT, au as EFFECT_PRESERVED, av as without_reactive_context } from './index2-C1QMSCIx.js';
|
|
import 'clsx';
|
|
|
|
// eslint-disable-next-line n/prefer-global/process
|
|
const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
|
|
|
|
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
/** @import { RequestStore } from 'types' */
|
|
/** @import { AsyncLocalStorage } from 'node:async_hooks' */
|
|
|
|
|
|
/** @type {RequestStore | null} */
|
|
let sync_store = null;
|
|
|
|
/** @type {AsyncLocalStorage<RequestStore | null> | null} */
|
|
let als;
|
|
|
|
import('node:async_hooks')
|
|
.then((hooks) => (als = new hooks.AsyncLocalStorage()))
|
|
.catch(() => {
|
|
// can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
|
|
// this isn't behind `supports` because it's basically just StackBlitz (i.e.
|
|
// in-browser usage) that doesn't support it AFAICT
|
|
});
|
|
|
|
/**
|
|
* @template T
|
|
* @param {RequestStore | null} store
|
|
* @param {() => T} fn
|
|
*/
|
|
function with_request_store(store, fn) {
|
|
try {
|
|
sync_store = store;
|
|
return als ? als.run(store, fn) : fn();
|
|
} finally {
|
|
// Since AsyncLocalStorage is not working in webcontainers, we don't reset `sync_store`
|
|
// and handle only one request at a time in `src/runtime/server/index.js`.
|
|
if (!IN_WEBCONTAINER) {
|
|
sync_store = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
const text_encoder = new TextEncoder();
|
|
const text_decoder = new TextDecoder();
|
|
function get_relative_path(from, to) {
|
|
const from_parts = from.split(/[/\\]/);
|
|
const to_parts = to.split(/[/\\]/);
|
|
from_parts.pop();
|
|
while (from_parts[0] === to_parts[0]) {
|
|
from_parts.shift();
|
|
to_parts.shift();
|
|
}
|
|
let i = from_parts.length;
|
|
while (i--) from_parts[i] = "..";
|
|
return from_parts.concat(to_parts).join("/");
|
|
}
|
|
function base64_encode(bytes) {
|
|
if (globalThis.Buffer) {
|
|
return globalThis.Buffer.from(bytes).toString("base64");
|
|
}
|
|
let binary = "";
|
|
for (let i = 0; i < bytes.length; i++) {
|
|
binary += String.fromCharCode(bytes[i]);
|
|
}
|
|
return btoa(binary);
|
|
}
|
|
function base64_decode(encoded) {
|
|
if (globalThis.Buffer) {
|
|
const buffer = globalThis.Buffer.from(encoded, "base64");
|
|
return new Uint8Array(buffer);
|
|
}
|
|
const binary = atob(encoded);
|
|
const bytes = new Uint8Array(binary.length);
|
|
for (let i = 0; i < binary.length; i++) {
|
|
bytes[i] = binary.charCodeAt(i);
|
|
}
|
|
return bytes;
|
|
}
|
|
|
|
const internal = new URL("sveltekit-internal://");
|
|
function resolve(base, path) {
|
|
if (path[0] === "/" && path[1] === "/") return path;
|
|
let url = new URL(base, internal);
|
|
url = new URL(path, url);
|
|
return url.protocol === internal.protocol ? url.pathname + url.search + url.hash : url.href;
|
|
}
|
|
function normalize_path(path, trailing_slash) {
|
|
if (path === "/" || trailing_slash === "ignore") return path;
|
|
if (trailing_slash === "never") {
|
|
return path.endsWith("/") ? path.slice(0, -1) : path;
|
|
} else if (trailing_slash === "always" && !path.endsWith("/")) {
|
|
return path + "/";
|
|
}
|
|
return path;
|
|
}
|
|
function decode_pathname(pathname) {
|
|
return pathname.split("%25").map(decodeURI).join("%25");
|
|
}
|
|
function decode_params(params) {
|
|
for (const key in params) {
|
|
params[key] = decodeURIComponent(params[key]);
|
|
}
|
|
return params;
|
|
}
|
|
function make_trackable(url, callback, search_params_callback, allow_hash = false) {
|
|
const tracked = new URL(url);
|
|
Object.defineProperty(tracked, "searchParams", {
|
|
value: new Proxy(tracked.searchParams, {
|
|
get(obj, key) {
|
|
if (key === "get" || key === "getAll" || key === "has") {
|
|
return (param, ...rest) => {
|
|
search_params_callback(param);
|
|
return obj[key](param, ...rest);
|
|
};
|
|
}
|
|
callback();
|
|
const value = Reflect.get(obj, key);
|
|
return typeof value === "function" ? value.bind(obj) : value;
|
|
}
|
|
}),
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
const tracked_url_properties = ["href", "pathname", "search", "toString", "toJSON"];
|
|
if (allow_hash) tracked_url_properties.push("hash");
|
|
for (const property of tracked_url_properties) {
|
|
Object.defineProperty(tracked, property, {
|
|
get() {
|
|
callback();
|
|
return url[property];
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
}
|
|
{
|
|
tracked[Symbol.for("nodejs.util.inspect.custom")] = (depth, opts, inspect) => {
|
|
return inspect(url, opts);
|
|
};
|
|
tracked.searchParams[Symbol.for("nodejs.util.inspect.custom")] = (depth, opts, inspect) => {
|
|
return inspect(url.searchParams, opts);
|
|
};
|
|
}
|
|
if (!allow_hash) {
|
|
disable_hash(tracked);
|
|
}
|
|
return tracked;
|
|
}
|
|
function disable_hash(url) {
|
|
allow_nodejs_console_log(url);
|
|
Object.defineProperty(url, "hash", {
|
|
get() {
|
|
throw new Error(
|
|
"Cannot access event.url.hash. Consider using `page.url.hash` inside a component instead"
|
|
);
|
|
}
|
|
});
|
|
}
|
|
function disable_search(url) {
|
|
allow_nodejs_console_log(url);
|
|
for (const property of ["search", "searchParams"]) {
|
|
Object.defineProperty(url, property, {
|
|
get() {
|
|
throw new Error(`Cannot access url.${property} on a page with prerendering enabled`);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
function allow_nodejs_console_log(url) {
|
|
{
|
|
url[Symbol.for("nodejs.util.inspect.custom")] = (depth, opts, inspect) => {
|
|
return inspect(new URL(url), opts);
|
|
};
|
|
}
|
|
}
|
|
function validator(expected) {
|
|
function validate(module, file) {
|
|
if (!module) return;
|
|
for (const key in module) {
|
|
if (key[0] === "_" || expected.has(key)) continue;
|
|
const values = [...expected.values()];
|
|
const hint = hint_for_supported_files(key, file?.slice(file.lastIndexOf("."))) ?? `valid exports are ${values.join(", ")}, or anything with a '_' prefix`;
|
|
throw new Error(`Invalid export '${key}'${file ? ` in ${file}` : ""} (${hint})`);
|
|
}
|
|
}
|
|
return validate;
|
|
}
|
|
function hint_for_supported_files(key, ext = ".js") {
|
|
const supported_files = [];
|
|
if (valid_layout_exports.has(key)) {
|
|
supported_files.push(`+layout${ext}`);
|
|
}
|
|
if (valid_page_exports.has(key)) {
|
|
supported_files.push(`+page${ext}`);
|
|
}
|
|
if (valid_layout_server_exports.has(key)) {
|
|
supported_files.push(`+layout.server${ext}`);
|
|
}
|
|
if (valid_page_server_exports.has(key)) {
|
|
supported_files.push(`+page.server${ext}`);
|
|
}
|
|
if (valid_server_exports.has(key)) {
|
|
supported_files.push(`+server${ext}`);
|
|
}
|
|
if (supported_files.length > 0) {
|
|
return `'${key}' is a valid export in ${supported_files.slice(0, -1).join(", ")}${supported_files.length > 1 ? " or " : ""}${supported_files.at(-1)}`;
|
|
}
|
|
}
|
|
const valid_layout_exports = /* @__PURE__ */ new Set([
|
|
"load",
|
|
"prerender",
|
|
"csr",
|
|
"ssr",
|
|
"trailingSlash",
|
|
"config"
|
|
]);
|
|
const valid_page_exports = /* @__PURE__ */ new Set([...valid_layout_exports, "entries"]);
|
|
const valid_layout_server_exports = /* @__PURE__ */ new Set([...valid_layout_exports]);
|
|
const valid_page_server_exports = /* @__PURE__ */ new Set([...valid_layout_server_exports, "actions", "entries"]);
|
|
const valid_server_exports = /* @__PURE__ */ new Set([
|
|
"GET",
|
|
"POST",
|
|
"PATCH",
|
|
"PUT",
|
|
"DELETE",
|
|
"OPTIONS",
|
|
"HEAD",
|
|
"fallback",
|
|
"prerender",
|
|
"trailingSlash",
|
|
"config",
|
|
"entries"
|
|
]);
|
|
const validate_layout_exports = validator(valid_layout_exports);
|
|
const validate_page_exports = validator(valid_page_exports);
|
|
const validate_layout_server_exports = validator(valid_layout_server_exports);
|
|
const validate_page_server_exports = validator(valid_page_server_exports);
|
|
|
|
function hydration_mismatch(location) {
|
|
{
|
|
console.warn(`https://svelte.dev/e/hydration_mismatch`);
|
|
}
|
|
}
|
|
function svelte_boundary_reset_noop() {
|
|
{
|
|
console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`);
|
|
}
|
|
}
|
|
let hydrating = false;
|
|
function set_hydrating(value) {
|
|
hydrating = value;
|
|
}
|
|
let hydrate_node;
|
|
function set_hydrate_node(node) {
|
|
if (node === null) {
|
|
hydration_mismatch();
|
|
throw HYDRATION_ERROR;
|
|
}
|
|
return hydrate_node = node;
|
|
}
|
|
function hydrate_next() {
|
|
return set_hydrate_node(get_next_sibling(hydrate_node));
|
|
}
|
|
function next(count = 1) {
|
|
if (hydrating) {
|
|
var i = count;
|
|
var node = hydrate_node;
|
|
while (i--) {
|
|
node = /** @type {TemplateNode} */
|
|
get_next_sibling(node);
|
|
}
|
|
hydrate_node = node;
|
|
}
|
|
}
|
|
function skip_nodes(remove = true) {
|
|
var depth = 0;
|
|
var node = hydrate_node;
|
|
while (true) {
|
|
if (node.nodeType === COMMENT_NODE) {
|
|
var data = (
|
|
/** @type {Comment} */
|
|
node.data
|
|
);
|
|
if (data === HYDRATION_END) {
|
|
if (depth === 0) return node;
|
|
depth -= 1;
|
|
} else if (data === HYDRATION_START || data === HYDRATION_START_ELSE || // "[1", "[2", etc. for if blocks
|
|
data[0] === "[" && !isNaN(Number(data.slice(1)))) {
|
|
depth += 1;
|
|
}
|
|
}
|
|
var next2 = (
|
|
/** @type {TemplateNode} */
|
|
get_next_sibling(node)
|
|
);
|
|
if (remove) node.remove();
|
|
node = next2;
|
|
}
|
|
}
|
|
function createSubscriber(start) {
|
|
let subscribers = 0;
|
|
let version = source(0);
|
|
let stop;
|
|
return () => {
|
|
if (effect_tracking()) {
|
|
get(version);
|
|
render_effect(() => {
|
|
if (subscribers === 0) {
|
|
stop = untrack(() => start(() => increment(version)));
|
|
}
|
|
subscribers += 1;
|
|
return () => {
|
|
queue_micro_task(() => {
|
|
subscribers -= 1;
|
|
if (subscribers === 0) {
|
|
stop?.();
|
|
stop = void 0;
|
|
increment(version);
|
|
}
|
|
});
|
|
};
|
|
});
|
|
}
|
|
};
|
|
}
|
|
var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;
|
|
function boundary(node, props, children) {
|
|
new Boundary(node, props, children);
|
|
}
|
|
class Boundary {
|
|
/** @type {Boundary | null} */
|
|
parent;
|
|
is_pending = false;
|
|
/** @type {TemplateNode} */
|
|
#anchor;
|
|
/** @type {TemplateNode | null} */
|
|
#hydrate_open = hydrating ? hydrate_node : null;
|
|
/** @type {BoundaryProps} */
|
|
#props;
|
|
/** @type {((anchor: Node) => void)} */
|
|
#children;
|
|
/** @type {Effect} */
|
|
#effect;
|
|
/** @type {Effect | null} */
|
|
#main_effect = null;
|
|
/** @type {Effect | null} */
|
|
#pending_effect = null;
|
|
/** @type {Effect | null} */
|
|
#failed_effect = null;
|
|
/** @type {DocumentFragment | null} */
|
|
#offscreen_fragment = null;
|
|
#local_pending_count = 0;
|
|
#pending_count = 0;
|
|
#pending_count_update_queued = false;
|
|
/** @type {Set<Effect>} */
|
|
#dirty_effects = /* @__PURE__ */ new Set();
|
|
/** @type {Set<Effect>} */
|
|
#maybe_dirty_effects = /* @__PURE__ */ new Set();
|
|
/**
|
|
* A source containing the number of pending async deriveds/expressions.
|
|
* Only created if `$effect.pending()` is used inside the boundary,
|
|
* otherwise updating the source results in needless `Batch.ensure()`
|
|
* calls followed by no-op flushes
|
|
* @type {Source<number> | null}
|
|
*/
|
|
#effect_pending = null;
|
|
#effect_pending_subscriber = createSubscriber(() => {
|
|
this.#effect_pending = source(this.#local_pending_count);
|
|
return () => {
|
|
this.#effect_pending = null;
|
|
};
|
|
});
|
|
/**
|
|
* @param {TemplateNode} node
|
|
* @param {BoundaryProps} props
|
|
* @param {((anchor: Node) => void)} children
|
|
*/
|
|
constructor(node, props, children) {
|
|
this.#anchor = node;
|
|
this.#props = props;
|
|
this.#children = (anchor) => {
|
|
var effect = (
|
|
/** @type {Effect} */
|
|
active_effect
|
|
);
|
|
effect.b = this;
|
|
effect.f |= BOUNDARY_EFFECT;
|
|
children(anchor);
|
|
};
|
|
this.parent = /** @type {Effect} */
|
|
active_effect.b;
|
|
this.#effect = block(() => {
|
|
if (hydrating) {
|
|
const comment = (
|
|
/** @type {Comment} */
|
|
this.#hydrate_open
|
|
);
|
|
hydrate_next();
|
|
if (comment.data === HYDRATION_START_ELSE) {
|
|
this.#hydrate_pending_content();
|
|
} else {
|
|
this.#hydrate_resolved_content();
|
|
}
|
|
} else {
|
|
this.#render();
|
|
}
|
|
}, flags);
|
|
if (hydrating) {
|
|
this.#anchor = hydrate_node;
|
|
}
|
|
}
|
|
#hydrate_resolved_content() {
|
|
try {
|
|
this.#main_effect = branch(() => this.#children(this.#anchor));
|
|
} catch (error) {
|
|
this.error(error);
|
|
}
|
|
}
|
|
#hydrate_pending_content() {
|
|
const pending = this.#props.pending;
|
|
if (!pending) return;
|
|
this.is_pending = true;
|
|
this.#pending_effect = branch(() => pending(this.#anchor));
|
|
queue_micro_task(() => {
|
|
var fragment = this.#offscreen_fragment = document.createDocumentFragment();
|
|
var anchor = create_text();
|
|
fragment.append(anchor);
|
|
this.#main_effect = this.#run(() => {
|
|
Batch.ensure();
|
|
return branch(() => this.#children(anchor));
|
|
});
|
|
if (this.#pending_count === 0) {
|
|
this.#anchor.before(fragment);
|
|
this.#offscreen_fragment = null;
|
|
pause_effect(
|
|
/** @type {Effect} */
|
|
this.#pending_effect,
|
|
() => {
|
|
this.#pending_effect = null;
|
|
}
|
|
);
|
|
this.is_pending = false;
|
|
}
|
|
});
|
|
}
|
|
#render() {
|
|
try {
|
|
this.is_pending = this.has_pending_snippet();
|
|
this.#pending_count = 0;
|
|
this.#local_pending_count = 0;
|
|
this.#main_effect = branch(() => {
|
|
this.#children(this.#anchor);
|
|
});
|
|
if (this.#pending_count > 0) {
|
|
var fragment = this.#offscreen_fragment = document.createDocumentFragment();
|
|
move_effect(this.#main_effect, fragment);
|
|
const pending = (
|
|
/** @type {(anchor: Node) => void} */
|
|
this.#props.pending
|
|
);
|
|
this.#pending_effect = branch(() => pending(this.#anchor));
|
|
} else {
|
|
this.is_pending = false;
|
|
}
|
|
} catch (error) {
|
|
this.error(error);
|
|
}
|
|
}
|
|
/**
|
|
* Defer an effect inside a pending boundary until the boundary resolves
|
|
* @param {Effect} effect
|
|
*/
|
|
defer_effect(effect) {
|
|
defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);
|
|
}
|
|
/**
|
|
* Returns `false` if the effect exists inside a boundary whose pending snippet is shown
|
|
* @returns {boolean}
|
|
*/
|
|
is_rendered() {
|
|
return !this.is_pending && (!this.parent || this.parent.is_rendered());
|
|
}
|
|
has_pending_snippet() {
|
|
return !!this.#props.pending;
|
|
}
|
|
/**
|
|
* @template T
|
|
* @param {() => T} fn
|
|
*/
|
|
#run(fn) {
|
|
var previous_effect = active_effect;
|
|
var previous_reaction = active_reaction;
|
|
var previous_ctx = component_context;
|
|
set_active_effect(this.#effect);
|
|
set_active_reaction(this.#effect);
|
|
set_component_context(this.#effect.ctx);
|
|
try {
|
|
return fn();
|
|
} catch (e) {
|
|
handle_error(e);
|
|
return null;
|
|
} finally {
|
|
set_active_effect(previous_effect);
|
|
set_active_reaction(previous_reaction);
|
|
set_component_context(previous_ctx);
|
|
}
|
|
}
|
|
/**
|
|
* Updates the pending count associated with the currently visible pending snippet,
|
|
* if any, such that we can replace the snippet with content once work is done
|
|
* @param {1 | -1} d
|
|
*/
|
|
#update_pending_count(d) {
|
|
if (!this.has_pending_snippet()) {
|
|
if (this.parent) {
|
|
this.parent.#update_pending_count(d);
|
|
}
|
|
return;
|
|
}
|
|
this.#pending_count += d;
|
|
if (this.#pending_count === 0) {
|
|
this.is_pending = false;
|
|
for (const e of this.#dirty_effects) {
|
|
set_signal_status(e, DIRTY);
|
|
schedule_effect(e);
|
|
}
|
|
for (const e of this.#maybe_dirty_effects) {
|
|
set_signal_status(e, MAYBE_DIRTY);
|
|
schedule_effect(e);
|
|
}
|
|
this.#dirty_effects.clear();
|
|
this.#maybe_dirty_effects.clear();
|
|
if (this.#pending_effect) {
|
|
pause_effect(this.#pending_effect, () => {
|
|
this.#pending_effect = null;
|
|
});
|
|
}
|
|
if (this.#offscreen_fragment) {
|
|
this.#anchor.before(this.#offscreen_fragment);
|
|
this.#offscreen_fragment = null;
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Update the source that powers `$effect.pending()` inside this boundary,
|
|
* and controls when the current `pending` snippet (if any) is removed.
|
|
* Do not call from inside the class
|
|
* @param {1 | -1} d
|
|
*/
|
|
update_pending_count(d) {
|
|
this.#update_pending_count(d);
|
|
this.#local_pending_count += d;
|
|
if (!this.#effect_pending || this.#pending_count_update_queued) return;
|
|
this.#pending_count_update_queued = true;
|
|
queue_micro_task(() => {
|
|
this.#pending_count_update_queued = false;
|
|
if (this.#effect_pending) {
|
|
internal_set(this.#effect_pending, this.#local_pending_count);
|
|
}
|
|
});
|
|
}
|
|
get_effect_pending() {
|
|
this.#effect_pending_subscriber();
|
|
return get(
|
|
/** @type {Source<number>} */
|
|
this.#effect_pending
|
|
);
|
|
}
|
|
/** @param {unknown} error */
|
|
error(error) {
|
|
var onerror = this.#props.onerror;
|
|
let failed = this.#props.failed;
|
|
if (!onerror && !failed) {
|
|
throw error;
|
|
}
|
|
if (this.#main_effect) {
|
|
destroy_effect(this.#main_effect);
|
|
this.#main_effect = null;
|
|
}
|
|
if (this.#pending_effect) {
|
|
destroy_effect(this.#pending_effect);
|
|
this.#pending_effect = null;
|
|
}
|
|
if (this.#failed_effect) {
|
|
destroy_effect(this.#failed_effect);
|
|
this.#failed_effect = null;
|
|
}
|
|
if (hydrating) {
|
|
set_hydrate_node(
|
|
/** @type {TemplateNode} */
|
|
this.#hydrate_open
|
|
);
|
|
next();
|
|
set_hydrate_node(skip_nodes());
|
|
}
|
|
var did_reset = false;
|
|
var calling_on_error = false;
|
|
const reset = () => {
|
|
if (did_reset) {
|
|
svelte_boundary_reset_noop();
|
|
return;
|
|
}
|
|
did_reset = true;
|
|
if (calling_on_error) {
|
|
svelte_boundary_reset_onerror();
|
|
}
|
|
if (this.#failed_effect !== null) {
|
|
pause_effect(this.#failed_effect, () => {
|
|
this.#failed_effect = null;
|
|
});
|
|
}
|
|
this.#run(() => {
|
|
Batch.ensure();
|
|
this.#render();
|
|
});
|
|
};
|
|
queue_micro_task(() => {
|
|
try {
|
|
calling_on_error = true;
|
|
onerror?.(error, reset);
|
|
calling_on_error = false;
|
|
} catch (error2) {
|
|
invoke_error_boundary(error2, this.#effect && this.#effect.parent);
|
|
}
|
|
if (failed) {
|
|
this.#failed_effect = this.#run(() => {
|
|
Batch.ensure();
|
|
try {
|
|
return branch(() => {
|
|
var effect = (
|
|
/** @type {Effect} */
|
|
active_effect
|
|
);
|
|
effect.b = this;
|
|
effect.f |= BOUNDARY_EFFECT;
|
|
failed(
|
|
this.#anchor,
|
|
() => error,
|
|
() => reset
|
|
);
|
|
});
|
|
} catch (error2) {
|
|
invoke_error_boundary(
|
|
error2,
|
|
/** @type {Effect} */
|
|
this.#effect.parent
|
|
);
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
const event_symbol = Symbol("events");
|
|
const all_registered_events = /* @__PURE__ */ new Set();
|
|
const root_event_handles = /* @__PURE__ */ new Set();
|
|
function create_event(event_name, dom, handler, options = {}) {
|
|
function target_handler(event) {
|
|
if (!options.capture) {
|
|
handle_event_propagation.call(dom, event);
|
|
}
|
|
if (!event.cancelBubble) {
|
|
return without_reactive_context(() => {
|
|
return handler?.call(this, event);
|
|
});
|
|
}
|
|
}
|
|
if (event_name.startsWith("pointer") || event_name.startsWith("touch") || event_name === "wheel") {
|
|
queue_micro_task(() => {
|
|
dom.addEventListener(event_name, target_handler, options);
|
|
});
|
|
} else {
|
|
dom.addEventListener(event_name, target_handler, options);
|
|
}
|
|
return target_handler;
|
|
}
|
|
function on(element, type, handler, options = {}) {
|
|
var target_handler = create_event(type, element, handler, options);
|
|
return () => {
|
|
element.removeEventListener(type, target_handler, options);
|
|
};
|
|
}
|
|
let last_propagated_event = null;
|
|
function handle_event_propagation(event) {
|
|
var handler_element = this;
|
|
var owner_document = (
|
|
/** @type {Node} */
|
|
handler_element.ownerDocument
|
|
);
|
|
var event_name = event.type;
|
|
var path = event.composedPath?.() || [];
|
|
var current_target = (
|
|
/** @type {null | Element} */
|
|
path[0] || event.target
|
|
);
|
|
last_propagated_event = event;
|
|
var path_idx = 0;
|
|
var handled_at = last_propagated_event === event && event[event_symbol];
|
|
if (handled_at) {
|
|
var at_idx = path.indexOf(handled_at);
|
|
if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
|
|
window)) {
|
|
event[event_symbol] = handler_element;
|
|
return;
|
|
}
|
|
var handler_idx = path.indexOf(handler_element);
|
|
if (handler_idx === -1) {
|
|
return;
|
|
}
|
|
if (at_idx <= handler_idx) {
|
|
path_idx = at_idx;
|
|
}
|
|
}
|
|
current_target = /** @type {Element} */
|
|
path[path_idx] || event.target;
|
|
if (current_target === handler_element) return;
|
|
define_property(event, "currentTarget", {
|
|
configurable: true,
|
|
get() {
|
|
return current_target || owner_document;
|
|
}
|
|
});
|
|
var previous_reaction = active_reaction;
|
|
var previous_effect = active_effect;
|
|
set_active_reaction(null);
|
|
set_active_effect(null);
|
|
try {
|
|
var throw_error;
|
|
var other_errors = [];
|
|
while (current_target !== null) {
|
|
var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
|
|
current_target.host || null;
|
|
try {
|
|
var delegated = current_target[event_symbol]?.[event_name];
|
|
if (delegated != null && (!/** @type {any} */
|
|
current_target.disabled || // DOM could've been updated already by the time this is reached, so we check this as well
|
|
// -> the target could not have been disabled because it emits the event in the first place
|
|
event.target === current_target)) {
|
|
delegated.call(current_target, event);
|
|
}
|
|
} catch (error) {
|
|
if (throw_error) {
|
|
other_errors.push(error);
|
|
} else {
|
|
throw_error = error;
|
|
}
|
|
}
|
|
if (event.cancelBubble || parent_element === handler_element || parent_element === null) {
|
|
break;
|
|
}
|
|
current_target = parent_element;
|
|
}
|
|
if (throw_error) {
|
|
for (let error of other_errors) {
|
|
queueMicrotask(() => {
|
|
throw error;
|
|
});
|
|
}
|
|
throw throw_error;
|
|
}
|
|
} finally {
|
|
event[event_symbol] = handler_element;
|
|
delete event.currentTarget;
|
|
set_active_reaction(previous_reaction);
|
|
set_active_effect(previous_effect);
|
|
}
|
|
}
|
|
function assign_nodes(start, end) {
|
|
var effect = (
|
|
/** @type {Effect} */
|
|
active_effect
|
|
);
|
|
if (effect.nodes === null) {
|
|
effect.nodes = { start, end, a: null, t: null };
|
|
}
|
|
}
|
|
function mount(component, options) {
|
|
return _mount(component, options);
|
|
}
|
|
function hydrate(component, options) {
|
|
init_operations();
|
|
options.intro = options.intro ?? false;
|
|
const target = options.target;
|
|
const was_hydrating = hydrating;
|
|
const previous_hydrate_node = hydrate_node;
|
|
try {
|
|
var anchor = get_first_child(target);
|
|
while (anchor && (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */
|
|
anchor.data !== HYDRATION_START)) {
|
|
anchor = get_next_sibling(anchor);
|
|
}
|
|
if (!anchor) {
|
|
throw HYDRATION_ERROR;
|
|
}
|
|
set_hydrating(true);
|
|
set_hydrate_node(
|
|
/** @type {Comment} */
|
|
anchor
|
|
);
|
|
const instance = _mount(component, { ...options, anchor });
|
|
set_hydrating(false);
|
|
return (
|
|
/** @type {Exports} */
|
|
instance
|
|
);
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message.split("\n").some((line) => line.startsWith("https://svelte.dev/e/"))) {
|
|
throw error;
|
|
}
|
|
if (error !== HYDRATION_ERROR) {
|
|
console.warn("Failed to hydrate: ", error);
|
|
}
|
|
if (options.recover === false) {
|
|
hydration_failed();
|
|
}
|
|
init_operations();
|
|
clear_text_content(target);
|
|
set_hydrating(false);
|
|
return mount(component, options);
|
|
} finally {
|
|
set_hydrating(was_hydrating);
|
|
set_hydrate_node(previous_hydrate_node);
|
|
}
|
|
}
|
|
const listeners = /* @__PURE__ */ new Map();
|
|
function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
|
|
init_operations();
|
|
var component = void 0;
|
|
var unmount2 = component_root(() => {
|
|
var anchor_node = anchor ?? target.appendChild(create_text());
|
|
boundary(
|
|
/** @type {TemplateNode} */
|
|
anchor_node,
|
|
{
|
|
pending: () => {
|
|
}
|
|
},
|
|
(anchor_node2) => {
|
|
push$1({});
|
|
var ctx = (
|
|
/** @type {ComponentContext} */
|
|
component_context
|
|
);
|
|
if (context) ctx.c = context;
|
|
if (events) {
|
|
props.$$events = events;
|
|
}
|
|
if (hydrating) {
|
|
assign_nodes(
|
|
/** @type {TemplateNode} */
|
|
anchor_node2,
|
|
null
|
|
);
|
|
}
|
|
component = Component(anchor_node2, props) || {};
|
|
if (hydrating) {
|
|
active_effect.nodes.end = hydrate_node;
|
|
if (hydrate_node === null || hydrate_node.nodeType !== COMMENT_NODE || /** @type {Comment} */
|
|
hydrate_node.data !== HYDRATION_END) {
|
|
hydration_mismatch();
|
|
throw HYDRATION_ERROR;
|
|
}
|
|
}
|
|
pop$1();
|
|
}
|
|
);
|
|
var registered_events = /* @__PURE__ */ new Set();
|
|
var event_handle = (events2) => {
|
|
for (var i = 0; i < events2.length; i++) {
|
|
var event_name = events2[i];
|
|
if (registered_events.has(event_name)) continue;
|
|
registered_events.add(event_name);
|
|
var passive = is_passive_event(event_name);
|
|
for (const node of [target, document]) {
|
|
var counts = listeners.get(node);
|
|
if (counts === void 0) {
|
|
counts = /* @__PURE__ */ new Map();
|
|
listeners.set(node, counts);
|
|
}
|
|
var count = counts.get(event_name);
|
|
if (count === void 0) {
|
|
node.addEventListener(event_name, handle_event_propagation, { passive });
|
|
counts.set(event_name, 1);
|
|
} else {
|
|
counts.set(event_name, count + 1);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
event_handle(array_from(all_registered_events));
|
|
root_event_handles.add(event_handle);
|
|
return () => {
|
|
for (var event_name of registered_events) {
|
|
for (const node of [target, document]) {
|
|
var counts = (
|
|
/** @type {Map<string, number>} */
|
|
listeners.get(node)
|
|
);
|
|
var count = (
|
|
/** @type {number} */
|
|
counts.get(event_name)
|
|
);
|
|
if (--count == 0) {
|
|
node.removeEventListener(event_name, handle_event_propagation);
|
|
counts.delete(event_name);
|
|
if (counts.size === 0) {
|
|
listeners.delete(node);
|
|
}
|
|
} else {
|
|
counts.set(event_name, count);
|
|
}
|
|
}
|
|
}
|
|
root_event_handles.delete(event_handle);
|
|
if (anchor_node !== anchor) {
|
|
anchor_node.parentNode?.removeChild(anchor_node);
|
|
}
|
|
};
|
|
});
|
|
mounted_components.set(component, unmount2);
|
|
return component;
|
|
}
|
|
let mounted_components = /* @__PURE__ */ new WeakMap();
|
|
function unmount(component, options) {
|
|
const fn = mounted_components.get(component);
|
|
if (fn) {
|
|
mounted_components.delete(component);
|
|
return fn(options);
|
|
}
|
|
return Promise.resolve();
|
|
}
|
|
function asClassComponent$1(component) {
|
|
return class extends Svelte4Component {
|
|
/** @param {any} options */
|
|
constructor(options) {
|
|
super({
|
|
component,
|
|
...options
|
|
});
|
|
}
|
|
};
|
|
}
|
|
class Svelte4Component {
|
|
/** @type {any} */
|
|
#events;
|
|
/** @type {Record<string, any>} */
|
|
#instance;
|
|
/**
|
|
* @param {ComponentConstructorOptions & {
|
|
* component: any;
|
|
* }} options
|
|
*/
|
|
constructor(options) {
|
|
var sources = /* @__PURE__ */ new Map();
|
|
var add_source = (key, value) => {
|
|
var s = mutable_source(value, false, false);
|
|
sources.set(key, s);
|
|
return s;
|
|
};
|
|
const props = new Proxy(
|
|
{ ...options.props || {}, $$events: {} },
|
|
{
|
|
get(target, prop) {
|
|
return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
},
|
|
has(target, prop) {
|
|
if (prop === LEGACY_PROPS) return true;
|
|
get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
return Reflect.has(target, prop);
|
|
},
|
|
set(target, prop, value) {
|
|
set(sources.get(prop) ?? add_source(prop, value), value);
|
|
return Reflect.set(target, prop, value);
|
|
}
|
|
}
|
|
);
|
|
this.#instance = (options.hydrate ? hydrate : mount)(options.component, {
|
|
target: options.target,
|
|
anchor: options.anchor,
|
|
props,
|
|
context: options.context,
|
|
intro: options.intro ?? false,
|
|
recover: options.recover
|
|
});
|
|
if (!options?.props?.$$host || options.sync === false) {
|
|
flushSync();
|
|
}
|
|
this.#events = props.$$events;
|
|
for (const key of Object.keys(this.#instance)) {
|
|
if (key === "$set" || key === "$destroy" || key === "$on") continue;
|
|
define_property(this, key, {
|
|
get() {
|
|
return this.#instance[key];
|
|
},
|
|
/** @param {any} value */
|
|
set(value) {
|
|
this.#instance[key] = value;
|
|
},
|
|
enumerable: true
|
|
});
|
|
}
|
|
this.#instance.$set = /** @param {Record<string, any>} next */
|
|
(next2) => {
|
|
Object.assign(props, next2);
|
|
};
|
|
this.#instance.$destroy = () => {
|
|
unmount(this.#instance);
|
|
};
|
|
}
|
|
/** @param {Record<string, any>} props */
|
|
$set(props) {
|
|
this.#instance.$set(props);
|
|
}
|
|
/**
|
|
* @param {string} event
|
|
* @param {(...args: any[]) => any} callback
|
|
* @returns {any}
|
|
*/
|
|
$on(event, callback) {
|
|
this.#events[event] = this.#events[event] || [];
|
|
const cb = (...args) => callback.call(this, ...args);
|
|
this.#events[event].push(cb);
|
|
return () => {
|
|
this.#events[event] = this.#events[event].filter(
|
|
/** @param {any} fn */
|
|
(fn) => fn !== cb
|
|
);
|
|
};
|
|
}
|
|
$destroy() {
|
|
this.#instance.$destroy();
|
|
}
|
|
}
|
|
function asClassComponent(component) {
|
|
const component_constructor = asClassComponent$1(component);
|
|
const _render = (props, { context, csp } = {}) => {
|
|
const result = render(component, { props, context, csp });
|
|
const munged = Object.defineProperties(
|
|
/** @type {LegacyRenderResult & PromiseLike<LegacyRenderResult>} */
|
|
{},
|
|
{
|
|
css: {
|
|
value: { code: "", map: null }
|
|
},
|
|
head: {
|
|
get: () => result.head
|
|
},
|
|
html: {
|
|
get: () => result.body
|
|
},
|
|
then: {
|
|
/**
|
|
* this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
|
|
*
|
|
* @template TResult1
|
|
* @template [TResult2=never]
|
|
* @param { (value: LegacyRenderResult) => TResult1 } onfulfilled
|
|
* @param { (reason: unknown) => TResult2 } onrejected
|
|
*/
|
|
value: (onfulfilled, onrejected) => {
|
|
{
|
|
const user_result = onfulfilled({
|
|
css: munged.css,
|
|
head: munged.head,
|
|
html: munged.html
|
|
});
|
|
return Promise.resolve(user_result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
return munged;
|
|
};
|
|
component_constructor.render = _render;
|
|
return component_constructor;
|
|
}
|
|
function Root($$renderer, $$props) {
|
|
$$renderer.component(($$renderer2) => {
|
|
let {
|
|
stores,
|
|
page,
|
|
constructors,
|
|
components = [],
|
|
form,
|
|
data_0 = null,
|
|
data_1 = null
|
|
} = $$props;
|
|
{
|
|
setContext("__svelte__", stores);
|
|
}
|
|
{
|
|
stores.page.set(page);
|
|
}
|
|
const Pyramid_1 = constructors[1];
|
|
if (constructors[1]) {
|
|
$$renderer2.push("<!--[-->");
|
|
const Pyramid_0 = constructors[0];
|
|
$$renderer2.push("<!---->");
|
|
Pyramid_0?.($$renderer2, {
|
|
data: data_0,
|
|
form,
|
|
params: page.params,
|
|
children: ($$renderer3) => {
|
|
$$renderer3.push("<!---->");
|
|
Pyramid_1?.($$renderer3, { data: data_1, form, params: page.params });
|
|
$$renderer3.push(`<!---->`);
|
|
},
|
|
$$slots: { default: true }
|
|
});
|
|
$$renderer2.push(`<!---->`);
|
|
} else {
|
|
$$renderer2.push("<!--[!-->");
|
|
const Pyramid_0 = constructors[0];
|
|
$$renderer2.push("<!---->");
|
|
Pyramid_0?.($$renderer2, { data: data_0, form, params: page.params });
|
|
$$renderer2.push(`<!---->`);
|
|
}
|
|
$$renderer2.push(`<!--]--> `);
|
|
{
|
|
$$renderer2.push("<!--[!-->");
|
|
}
|
|
$$renderer2.push(`<!--]-->`);
|
|
});
|
|
}
|
|
const root = asClassComponent(Root);
|
|
|
|
export { disable_search as a, base64_decode as b, decode_params as c, decode_pathname as d, validate_layout_exports as e, validate_page_server_exports as f, validate_page_exports as g, text_encoder as h, resolve as i, get_relative_path as j, base64_encode as k, make_trackable as m, normalize_path as n, on as o, root as r, text_decoder as t, validate_layout_server_exports as v, with_request_store as w };
|
|
//# sourceMappingURL=root-DLMkITFa.js.map
|