110 lines
2.8 KiB
JavaScript
110 lines
2.8 KiB
JavaScript
import "clsx";
|
|
const HYDRATION_START = "[";
|
|
const HYDRATION_END = "]";
|
|
const HYDRATION_ERROR = {};
|
|
function lifecycle_outside_component(name) {
|
|
{
|
|
throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
|
|
}
|
|
}
|
|
var current_component = null;
|
|
function getContext(key) {
|
|
const context_map = get_or_init_context_map();
|
|
const result = (
|
|
/** @type {T} */
|
|
context_map.get(key)
|
|
);
|
|
return result;
|
|
}
|
|
function setContext(key, context) {
|
|
get_or_init_context_map().set(key, context);
|
|
return context;
|
|
}
|
|
function get_or_init_context_map(name) {
|
|
if (current_component === null) {
|
|
lifecycle_outside_component();
|
|
}
|
|
return current_component.c ??= new Map(get_parent_context(current_component) || void 0);
|
|
}
|
|
function push(fn) {
|
|
current_component = { p: current_component, c: null, d: null };
|
|
}
|
|
function pop() {
|
|
var component = (
|
|
/** @type {Component} */
|
|
current_component
|
|
);
|
|
var ondestroy = component.d;
|
|
if (ondestroy) {
|
|
on_destroy.push(...ondestroy);
|
|
}
|
|
current_component = component.p;
|
|
}
|
|
function get_parent_context(component_context) {
|
|
let parent = component_context.p;
|
|
while (parent !== null) {
|
|
const context_map = parent.c;
|
|
if (context_map !== null) {
|
|
return context_map;
|
|
}
|
|
parent = parent.p;
|
|
}
|
|
return null;
|
|
}
|
|
const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
|
|
const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;
|
|
let on_destroy = [];
|
|
function render(component, options = {}) {
|
|
const payload = { out: "", css: /* @__PURE__ */ new Set(), head: { title: "", out: "" } };
|
|
const prev_on_destroy = on_destroy;
|
|
on_destroy = [];
|
|
payload.out += BLOCK_OPEN;
|
|
if (options.context) {
|
|
push();
|
|
current_component.c = options.context;
|
|
}
|
|
component(payload, options.props ?? {}, {}, {});
|
|
if (options.context) {
|
|
pop();
|
|
}
|
|
payload.out += BLOCK_CLOSE;
|
|
for (const cleanup of on_destroy) cleanup();
|
|
on_destroy = prev_on_destroy;
|
|
let head2 = payload.head.out + payload.head.title;
|
|
for (const { hash, code } of payload.css) {
|
|
head2 += `<style id="${hash}">${code}</style>`;
|
|
}
|
|
return {
|
|
head: head2,
|
|
html: payload.out,
|
|
body: payload.out
|
|
};
|
|
}
|
|
function head(payload, fn) {
|
|
const head_payload = payload.head;
|
|
head_payload.out += BLOCK_OPEN;
|
|
fn(head_payload);
|
|
head_payload.out += BLOCK_CLOSE;
|
|
}
|
|
function bind_props(props_parent, props_now) {
|
|
for (const key in props_now) {
|
|
const initial_value = props_parent[key];
|
|
const value = props_now[key];
|
|
if (initial_value === void 0 && value !== void 0 && Object.getOwnPropertyDescriptor(props_parent, key)?.set) {
|
|
props_parent[key] = value;
|
|
}
|
|
}
|
|
}
|
|
export {
|
|
HYDRATION_ERROR as H,
|
|
HYDRATION_START as a,
|
|
HYDRATION_END as b,
|
|
pop as c,
|
|
bind_props as d,
|
|
getContext as g,
|
|
head as h,
|
|
push as p,
|
|
render as r,
|
|
setContext as s
|
|
};
|