mirror of
https://github.com/SoPat712/A2ZSoftware.git
synced 2025-08-21 10:18:46 -04:00
142 lines
3.7 KiB
JavaScript
142 lines
3.7 KiB
JavaScript
import "clsx";
|
|
const HYDRATION_START = "[";
|
|
const HYDRATION_END = "]";
|
|
const HYDRATION_ERROR = {};
|
|
const UNINITIALIZED = Symbol();
|
|
function lifecycle_outside_component(name) {
|
|
{
|
|
throw new Error(`https://svelte.dev/e/lifecycle_outside_component`);
|
|
}
|
|
}
|
|
const ATTR_REGEX = /[&"<]/g;
|
|
const CONTENT_REGEX = /[&<]/g;
|
|
function escape_html(value, is_attr) {
|
|
const str = String(value ?? "");
|
|
const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
|
|
pattern.lastIndex = 0;
|
|
let escaped = "";
|
|
let last = 0;
|
|
while (pattern.test(str)) {
|
|
const i = pattern.lastIndex - 1;
|
|
const ch = str[i];
|
|
escaped += str.substring(last, i) + (ch === "&" ? "&" : ch === '"' ? """ : "<");
|
|
last = i + 1;
|
|
}
|
|
return escaped + str.substring(last);
|
|
}
|
|
function to_class(value, hash, directives) {
|
|
var classname = value == null ? "" : "" + value;
|
|
return classname === "" ? null : classname;
|
|
}
|
|
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 props_id_generator(prefix) {
|
|
let uid = 1;
|
|
return () => `${prefix}s${uid++}`;
|
|
}
|
|
function render(component, options = {}) {
|
|
const uid = props_id_generator(options.idPrefix ? options.idPrefix + "-" : "");
|
|
const payload = {
|
|
out: "",
|
|
css: /* @__PURE__ */ new Set(),
|
|
head: { title: "", out: "", css: /* @__PURE__ */ new Set(), uid },
|
|
uid
|
|
};
|
|
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 head = payload.head.out + payload.head.title;
|
|
for (const { hash, code } of payload.css) {
|
|
head += `<style id="${hash}">${code}</style>`;
|
|
}
|
|
return {
|
|
head,
|
|
html: payload.out,
|
|
body: payload.out
|
|
};
|
|
}
|
|
function stringify(value) {
|
|
return true ? value : value == null ? "" : value + "";
|
|
}
|
|
function attr_class(value, hash, directives) {
|
|
var result = to_class(value);
|
|
return result ? ` class="${escape_html(result, true)}"` : "";
|
|
}
|
|
function ensure_array_like(array_like_or_iterator) {
|
|
if (array_like_or_iterator) {
|
|
return array_like_or_iterator.length !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
|
|
}
|
|
return [];
|
|
}
|
|
export {
|
|
HYDRATION_ERROR as H,
|
|
UNINITIALIZED as U,
|
|
HYDRATION_START as a,
|
|
HYDRATION_END as b,
|
|
pop as c,
|
|
ensure_array_like as d,
|
|
escape_html as e,
|
|
attr_class as f,
|
|
getContext as g,
|
|
stringify as h,
|
|
push as p,
|
|
render as r,
|
|
setContext as s
|
|
};
|