Add ModeTemplate with Svelte 5 frontend and components
- Create reusable components: auth, api-client, shared-types - ModeTemplate with Hono backend and SvelteKit frontend - Auth store refactored to class-based Svelte 5 pattern - SSR-safe hydrate() pattern for localStorage access - Frontend builds successfully with Svelte 5 runes
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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);
|
||||
}
|
||||
var ssr_context = null;
|
||||
function set_ssr_context(v) {
|
||||
ssr_context = v;
|
||||
}
|
||||
function getContext(key) {
|
||||
const context_map = get_or_init_context_map();
|
||||
const result = (
|
||||
/** @type {T} */
|
||||
context_map.get(key)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
function setContext(key, context) {
|
||||
get_or_init_context_map().set(key, context);
|
||||
return context;
|
||||
}
|
||||
function get_or_init_context_map(name) {
|
||||
if (ssr_context === null) {
|
||||
lifecycle_outside_component();
|
||||
}
|
||||
return ssr_context.c ??= new Map(get_parent_context(ssr_context) || void 0);
|
||||
}
|
||||
function push(fn) {
|
||||
ssr_context = { p: ssr_context, c: null, r: null };
|
||||
}
|
||||
function pop() {
|
||||
ssr_context = /** @type {SSRContext} */
|
||||
ssr_context.p;
|
||||
}
|
||||
function get_parent_context(ssr_context2) {
|
||||
let parent = ssr_context2.p;
|
||||
while (parent !== null) {
|
||||
const context_map = parent.c;
|
||||
if (context_map !== null) {
|
||||
return context_map;
|
||||
}
|
||||
parent = parent.p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export {
|
||||
set_ssr_context as a,
|
||||
ssr_context as b,
|
||||
pop as c,
|
||||
escape_html as e,
|
||||
getContext as g,
|
||||
push as p,
|
||||
setContext as s
|
||||
};
|
||||
Reference in New Issue
Block a user