@jasonshimmy/custom-elements-runtime 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{css-utils-Cg4o1MqY.js → css-utils-CC43BbEy.js} +20 -21
- package/dist/css-utils-CC43BbEy.js.map +1 -0
- package/dist/{css-utils-RqkyBWft.cjs → css-utils-mgjmH8qX.cjs} +5 -4
- package/dist/css-utils-mgjmH8qX.cjs.map +1 -0
- package/dist/custom-elements-runtime.cjs.js +4 -3
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.colors.cjs.js +3 -2
- package/dist/custom-elements-runtime.colors.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.colors.es.js +3 -2
- package/dist/custom-elements-runtime.colors.es.js.map +1 -1
- package/dist/custom-elements-runtime.directive-enhancements.cjs.js +3 -2
- package/dist/custom-elements-runtime.directive-enhancements.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.directive-enhancements.es.js +86 -100
- package/dist/custom-elements-runtime.directive-enhancements.es.js.map +1 -1
- package/dist/custom-elements-runtime.directives.cjs.js +3 -2
- package/dist/custom-elements-runtime.directives.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.directives.es.js +40 -43
- package/dist/custom-elements-runtime.directives.es.js.map +1 -1
- package/dist/custom-elements-runtime.dom-jit-css.cjs.js +7 -6
- package/dist/custom-elements-runtime.dom-jit-css.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.dom-jit-css.es.js +58 -76
- package/dist/custom-elements-runtime.dom-jit-css.es.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +162 -186
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.event-bus.cjs.js +3 -2
- package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.event-bus.es.js +48 -103
- package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
- package/dist/custom-elements-runtime.jit-css.cjs.js +3 -2
- package/dist/custom-elements-runtime.jit-css.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.jit-css.es.js +29 -30
- package/dist/custom-elements-runtime.jit-css.es.js.map +1 -1
- package/dist/custom-elements-runtime.router.cjs.js +20 -19
- package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.router.es.js +579 -582
- package/dist/custom-elements-runtime.router.es.js.map +1 -1
- package/dist/custom-elements-runtime.ssr-middleware.cjs.js +5 -4
- package/dist/custom-elements-runtime.ssr-middleware.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.ssr-middleware.es.js +44 -37
- package/dist/custom-elements-runtime.ssr-middleware.es.js.map +1 -1
- package/dist/custom-elements-runtime.ssr.cjs.js +1 -4
- package/dist/custom-elements-runtime.ssr.es.js +11 -176
- package/dist/custom-elements-runtime.store.cjs.js +3 -2
- package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.store.es.js +17 -11
- package/dist/custom-elements-runtime.store.es.js.map +1 -1
- package/dist/custom-elements-runtime.transitions.cjs.js +3 -2
- package/dist/custom-elements-runtime.transitions.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.transitions.es.js +55 -120
- package/dist/custom-elements-runtime.transitions.es.js.map +1 -1
- package/dist/custom-elements-runtime.vite-plugin.cjs.js +3 -2
- package/dist/custom-elements-runtime.vite-plugin.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.vite-plugin.es.js +54 -75
- package/dist/custom-elements-runtime.vite-plugin.es.js.map +1 -1
- package/dist/hooks-_3xP4G2N.js +1189 -0
- package/dist/hooks-_3xP4G2N.js.map +1 -0
- package/dist/hooks-fYQgZk2g.cjs +7 -0
- package/dist/hooks-fYQgZk2g.cjs.map +1 -0
- package/dist/logger-BYIN7ysT.cjs +3 -0
- package/dist/logger-BYIN7ysT.cjs.map +1 -0
- package/dist/logger-L25axmB-.js +41 -0
- package/dist/logger-L25axmB-.js.map +1 -0
- package/dist/namespace-helpers-Bf7rm9JV.cjs +3 -0
- package/dist/namespace-helpers-Bf7rm9JV.cjs.map +1 -0
- package/dist/namespace-helpers-BucDdgz_.js +61 -0
- package/dist/namespace-helpers-BucDdgz_.js.map +1 -0
- package/dist/reset.css +1 -1
- package/dist/ssr-B3lxl1vr.js +165 -0
- package/dist/ssr-B3lxl1vr.js.map +1 -0
- package/dist/ssr-DtD9e5iA.cjs +5 -0
- package/dist/ssr-DtD9e5iA.cjs.map +1 -0
- package/dist/style-Bjn8zDiZ.cjs +56 -0
- package/dist/style-Bjn8zDiZ.cjs.map +1 -0
- package/dist/{style-BmyOIMcU.js → style-DuDoj_xK.js} +724 -876
- package/dist/style-DuDoj_xK.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/template-compiler-BB4JJdqk.cjs +23 -0
- package/dist/template-compiler-BB4JJdqk.cjs.map +1 -0
- package/dist/template-compiler-Cs5axmn4.js +3236 -0
- package/dist/template-compiler-Cs5axmn4.js.map +1 -0
- package/dist/variables.css +1 -1
- package/package.json +7 -7
- package/dist/css-utils-Cg4o1MqY.js.map +0 -1
- package/dist/css-utils-RqkyBWft.cjs.map +0 -1
- package/dist/custom-elements-runtime.ssr.cjs.js.map +0 -1
- package/dist/custom-elements-runtime.ssr.es.js.map +0 -1
- package/dist/hooks-BH-CpUun.js +0 -1474
- package/dist/hooks-BH-CpUun.js.map +0 -1
- package/dist/hooks-NOFG9QRQ.cjs +0 -6
- package/dist/hooks-NOFG9QRQ.cjs.map +0 -1
- package/dist/logger-BvkEbVM4.js +0 -48
- package/dist/logger-BvkEbVM4.js.map +0 -1
- package/dist/logger-CSALKaYm.cjs +0 -2
- package/dist/logger-CSALKaYm.cjs.map +0 -1
- package/dist/namespace-helpers-D4wC2-qA.js +0 -61
- package/dist/namespace-helpers-D4wC2-qA.js.map +0 -1
- package/dist/namespace-helpers-ckeEOxpR.cjs +0 -2
- package/dist/namespace-helpers-ckeEOxpR.cjs.map +0 -1
- package/dist/style-BmyOIMcU.js.map +0 -1
- package/dist/style-D40DsIqJ.cjs +0 -55
- package/dist/style-D40DsIqJ.cjs.map +0 -1
- package/dist/template-compiler-CDvhsHia.cjs +0 -22
- package/dist/template-compiler-CDvhsHia.cjs.map +0 -1
- package/dist/template-compiler-DiE69FLO.js +0 -3724
- package/dist/template-compiler-DiE69FLO.js.map +0 -1
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
if (!
|
|
1
|
+
import { n as v, t as C } from "./ssr-B3lxl1vr.js";
|
|
2
|
+
function b(t, r, i) {
|
|
3
|
+
if (!i) return t;
|
|
4
4
|
if (t.trimStart().toLowerCase().startsWith("<html") || t.includes("</html>")) {
|
|
5
|
-
const
|
|
6
|
-
return
|
|
5
|
+
const c = r ?? "", o = t.startsWith("<!DOCTYPE") ? t : `<!DOCTYPE html>${t}`;
|
|
6
|
+
return c && o.includes("</head>") ? o.replace("</head>", `${c}</head>`) : o;
|
|
7
7
|
}
|
|
8
|
-
return `<!DOCTYPE html><html><head>${
|
|
8
|
+
return `<!DOCTYPE html><html><head>${r ?? ""}</head><body>${t}</body></html>`;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
10
|
+
function H(t, r) {
|
|
11
|
+
const i = {
|
|
12
12
|
dsd: !0,
|
|
13
|
-
...
|
|
14
|
-
}, { head:
|
|
15
|
-
return async (
|
|
13
|
+
...r?.render
|
|
14
|
+
}, { head: c, document: o = !0 } = r ?? {};
|
|
15
|
+
return async (f, n) => {
|
|
16
16
|
try {
|
|
17
|
-
const e = typeof t == "function" ? await t(
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const e = typeof t == "function" ? await t(f) : t, d = e !== null && typeof e == "object" && "vnode" in e, m = d ? e.vnode : e, p = d ? e.router : void 0, s = d ? e.head : void 0, { htmlWithStyles: h } = v(m, {
|
|
18
|
+
...i,
|
|
19
|
+
router: p
|
|
20
|
+
}), a = b(h, [c, s].filter(Boolean).join(`
|
|
21
|
+
`) || void 0, o);
|
|
22
|
+
n.setHeader("Content-Type", "text/html; charset=utf-8"), n.end(a);
|
|
20
23
|
} catch (e) {
|
|
21
24
|
try {
|
|
22
25
|
n.setHeader("Content-Type", "text/plain; charset=utf-8"), n.end("Internal Server Error");
|
|
@@ -26,34 +29,37 @@ function R(t, o) {
|
|
|
26
29
|
}
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
32
|
+
function E(t, r) {
|
|
33
|
+
const i = {
|
|
31
34
|
dsd: !0,
|
|
32
|
-
...
|
|
33
|
-
}, { head:
|
|
34
|
-
return async (
|
|
35
|
+
...r?.render
|
|
36
|
+
}, { head: c, document: o = !0 } = r ?? {};
|
|
37
|
+
return async (f, n) => {
|
|
35
38
|
try {
|
|
36
|
-
const e = typeof t == "function" ? await t(
|
|
39
|
+
const e = typeof t == "function" ? await t(f) : t, d = e !== null && typeof e == "object" && "vnode" in e, m = d ? e.vnode : e, p = d ? e.router : void 0, s = [c, d ? e.head : void 0].filter(Boolean).join(`
|
|
37
40
|
`) || void 0;
|
|
38
41
|
n.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
39
|
-
const
|
|
42
|
+
const h = C(m, {
|
|
43
|
+
...i,
|
|
44
|
+
router: p
|
|
45
|
+
}).getReader();
|
|
40
46
|
if (n.write) {
|
|
41
|
-
n.setHeader("Transfer-Encoding", "chunked"),
|
|
42
|
-
let
|
|
43
|
-
for (; !
|
|
44
|
-
const { value:
|
|
45
|
-
|
|
47
|
+
n.setHeader("Transfer-Encoding", "chunked"), o && n.write(`<!DOCTYPE html><html><head>${s ?? ""}</head><body>`);
|
|
48
|
+
let a = !1;
|
|
49
|
+
for (; !a; ) {
|
|
50
|
+
const { value: u, done: l } = await h.read();
|
|
51
|
+
u && n.write(u), a = l;
|
|
46
52
|
}
|
|
47
|
-
|
|
53
|
+
o ? n.end("</body></html>") : n.end();
|
|
48
54
|
} else {
|
|
49
|
-
const
|
|
50
|
-
let
|
|
51
|
-
for (; !
|
|
52
|
-
const { value:
|
|
53
|
-
|
|
55
|
+
const a = [];
|
|
56
|
+
let u = !1;
|
|
57
|
+
for (; !u; ) {
|
|
58
|
+
const { value: w, done: T } = await h.read();
|
|
59
|
+
w && a.push(w), u = T;
|
|
54
60
|
}
|
|
55
|
-
const
|
|
56
|
-
n.end(
|
|
61
|
+
const l = a.join(""), y = o ? `<!DOCTYPE html><html><head>${s ?? ""}</head><body>${l}</body></html>` : l;
|
|
62
|
+
n.end(y);
|
|
57
63
|
}
|
|
58
64
|
} catch (e) {
|
|
59
65
|
try {
|
|
@@ -65,7 +71,8 @@ function S(t, o) {
|
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
export {
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
H as createSSRHandler,
|
|
75
|
+
E as createStreamingSSRHandler
|
|
70
76
|
};
|
|
71
|
-
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=custom-elements-runtime.ssr-middleware.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.ssr-middleware.es.js","sources":["../src/lib/ssr-middleware.ts"],"sourcesContent":["/**\n * SSR middleware helpers for Express, Fastify, Hono, and other Node.js HTTP frameworks.\n *\n * Provides two handler factories that wrap the SSR rendering pipeline and\n * emit a complete HTML document response. Both accept a static VNode **or**\n * a per-request factory function so route-specific data can be threaded into\n * the render tree.\n *\n * @example Express — static VNode\n * ```ts\n * import express from 'express';\n * import { createSSRHandler } from '@jasonshimmy/custom-elements-runtime/ssr-middleware';\n * import { html } from '@jasonshimmy/custom-elements-runtime';\n *\n * const app = express();\n * app.get('/', createSSRHandler(html`<my-app />`, {\n * render: { dsd: true, jit: { extendedColors: true } },\n * }));\n * ```\n *\n * @example Express — per-request factory\n * ```ts\n * app.get('*', createSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true }, head: '<link rel=\"stylesheet\" href=\"/app.css\">' },\n * ));\n * ```\n *\n * @example Streaming variant\n * ```ts\n * app.get('*', createStreamingSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * ));\n * ```\n */\n\nimport { renderToStringWithJITCSS, renderToStream } from './ssr';\nimport type { VNode } from './runtime/types';\nimport type { RenderOptions } from './runtime/vdom-ssr';\nimport type { DSDRenderOptions } from './runtime/vdom-ssr-dsd';\nimport type { JITCSSOptions } from './runtime/style';\n\n/**\n * What a per-request factory may return.\n *\n * - Plain `VNode` — backward-compatible; no per-request router threading.\n * - `{ vnode, router? }` — the router instance is threaded through the render\n * context, making concurrent SSR requests safe (each render reads from its\n * own router, not the module-level `activeRouterProxy` singleton).\n * - `{ vnode, router?, head? }` — `head` is an HTML string injected into the\n * document `<head>` for this specific request (e.g. serialized loader data).\n * It is merged with the static `head` option passed to the handler factory.\n */\nexport type VnodeFactoryResult = VNode | { vnode: VNode; router?: unknown; head?: string };\n\n// ---------------------------------------------------------------------------\n// Minimal framework-agnostic HTTP types\n// ---------------------------------------------------------------------------\n\n/**\n * Minimal request interface compatible with Express, Fastify, Hono, and the\n * raw Node.js `IncomingMessage`. Extend or replace with your framework's\n * request type via the generic parameter on `createSSRHandler`.\n */\nexport interface MinimalRequest {\n url?: string;\n method?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Minimal response interface compatible with Express, Fastify, Hono, and the\n * raw Node.js `ServerResponse`. `write` is optional — handlers fall back to\n * buffering when it is absent.\n */\nexport interface MinimalResponse {\n setHeader(name: string, value: string): void;\n write?(chunk: string): boolean | void;\n end(data?: string): void;\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for {@link createSSRHandler} and {@link createStreamingSSRHandler}.\n */\nexport interface SSRMiddlewareOptions {\n /**\n * Render options forwarded to `renderToStringWithJITCSS`.\n * Defaults to `{ dsd: true }` so DSD output is on by default.\n */\n render?: RenderOptions & DSDRenderOptions & { jit?: JITCSSOptions };\n /**\n * Additional HTML inserted at the end of the `<head>` tag.\n * Use this to inject `<link>`, `<script>`, `<meta>`, or `<title>` tags.\n */\n head?: string;\n /**\n * When `true` (default), the response is wrapped in a complete\n * `<!DOCTYPE html>` document shell. Set to `false` if you want to\n * assemble the document yourself and only need the rendered fragment.\n */\n document?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction wrapInDocument(\n htmlWithStyles: string,\n head: string | undefined,\n wrapDocument: boolean,\n): string {\n if (!wrapDocument) return htmlWithStyles;\n\n // If the rendered HTML already contains a root <html> tag, inject extra\n // head tags and prepend the DOCTYPE — do not double-wrap.\n if (\n htmlWithStyles.trimStart().toLowerCase().startsWith('<html') ||\n htmlWithStyles.includes('</html>')\n ) {\n const extra = head ?? '';\n const withDoctype = htmlWithStyles.startsWith('<!DOCTYPE')\n ? htmlWithStyles\n : `<!DOCTYPE html>${htmlWithStyles}`;\n if (extra) {\n return withDoctype.includes('</head>')\n ? withDoctype.replace('</head>', `${extra}</head>`)\n : withDoctype;\n }\n return withDoctype;\n }\n\n // Minimal shell\n const headContent = head ?? '';\n return `<!DOCTYPE html><html><head>${headContent}</head><body>${htmlWithStyles}</body></html>`;\n}\n\n// ---------------------------------------------------------------------------\n// Handler factories\n// ---------------------------------------------------------------------------\n\n/**\n * Create a request handler that SSR-renders a VNode tree and sends the full\n * HTML document as the response.\n *\n * Compatible with Express, Fastify, Hono, and any framework that uses an\n * `(req, res)` handler signature. The generic `Req` parameter lets you use\n * your framework's typed request object.\n *\n * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)\n * factory function that receives the request and returns the VNode to render.\n * @param options - Render and document-shell options.\n *\n * @example\n * ```ts\n * app.get('*', createSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true, jit: { extendedColors: true } } },\n * ));\n * ```\n */\nexport function createSSRHandler<Req extends MinimalRequest = MinimalRequest>(\n vnodeOrFactory:\n | VnodeFactoryResult\n | ((req: Req) => VnodeFactoryResult | Promise<VnodeFactoryResult>),\n options?: SSRMiddlewareOptions,\n): (req: Req, res: MinimalResponse) => Promise<void> {\n const renderOptions: RenderOptions &\n DSDRenderOptions & { jit?: JITCSSOptions } = {\n dsd: true,\n ...options?.render,\n };\n const { head, document: wrapDocument = true } = options ?? {};\n\n return async (req, res) => {\n try {\n const rawResult =\n typeof vnodeOrFactory === 'function'\n ? await vnodeOrFactory(req)\n : vnodeOrFactory;\n\n const isBundle =\n rawResult !== null &&\n typeof rawResult === 'object' &&\n 'vnode' in (rawResult as object);\n const vnode = isBundle\n ? (rawResult as { vnode: VNode }).vnode\n : (rawResult as VNode);\n const router = isBundle\n ? (rawResult as { vnode: VNode; router?: unknown }).router\n : undefined;\n const perRequestHead = isBundle\n ? (rawResult as { head?: string }).head\n : undefined;\n\n const { htmlWithStyles } = renderToStringWithJITCSS(vnode, { ...renderOptions, router });\n\n const mergedHead = [head, perRequestHead].filter(Boolean).join('\\n') || undefined;\n const body = wrapInDocument(htmlWithStyles, mergedHead, wrapDocument);\n\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.end(body);\n } catch (err) {\n // Ensure the response is always closed to prevent the request hanging.\n // Re-throw so the framework's error handler can set the proper status code.\n try {\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\n res.end('Internal Server Error');\n } catch {\n // ignore secondary errors during error response\n }\n throw err;\n }\n };\n}\n\n/**\n * Create a request handler that SSR-renders a VNode tree and streams the HTML\n * response using chunked transfer encoding.\n *\n * Each chunk produced by the underlying {@link renderToStream} call is written\n * to the response as it becomes available, minimising Time-to-First-Byte.\n * The document shell preamble (`<!DOCTYPE html>…<body>`) is sent in the first\n * write so the browser can begin parsing immediately.\n *\n * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)\n * factory function that receives the request and returns the VNode to render.\n * @param options - Render and document-shell options.\n *\n * @example\n * ```ts\n * app.get('*', createStreamingSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true } },\n * ));\n * ```\n */\nexport function createStreamingSSRHandler<\n Req extends MinimalRequest = MinimalRequest,\n>(\n vnodeOrFactory:\n | VnodeFactoryResult\n | ((req: Req) => VnodeFactoryResult | Promise<VnodeFactoryResult>),\n options?: SSRMiddlewareOptions,\n): (req: Req, res: MinimalResponse) => Promise<void> {\n const renderOptions: RenderOptions &\n DSDRenderOptions & { jit?: JITCSSOptions } = {\n dsd: true,\n ...options?.render,\n };\n const { head, document: wrapDocument = true } = options ?? {};\n\n return async (req, res) => {\n try {\n const rawResult =\n typeof vnodeOrFactory === 'function'\n ? await vnodeOrFactory(req)\n : vnodeOrFactory;\n\n const isBundle =\n rawResult !== null &&\n typeof rawResult === 'object' &&\n 'vnode' in (rawResult as object);\n const vnode = isBundle\n ? (rawResult as { vnode: VNode }).vnode\n : (rawResult as VNode);\n const router = isBundle\n ? (rawResult as { vnode: VNode; router?: unknown }).router\n : undefined;\n const perRequestHead = isBundle\n ? (rawResult as { head?: string }).head\n : undefined;\n\n const mergedHead = [head, perRequestHead].filter(Boolean).join('\\n') || undefined;\n\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n\n const stream = renderToStream(vnode, { ...renderOptions, router });\n const reader = stream.getReader();\n\n if (res.write) {\n // Streaming path: pipe chunks directly to the response as they arrive.\n res.setHeader('Transfer-Encoding', 'chunked');\n if (wrapDocument) {\n res.write(`<!DOCTYPE html><html><head>${mergedHead ?? ''}</head><body>`);\n }\n let done = false;\n while (!done) {\n const { value, done: d } = await reader.read();\n if (value) res.write(value);\n done = d;\n }\n if (wrapDocument) {\n res.end('</body></html>');\n } else {\n res.end();\n }\n } else {\n // Buffered fallback: framework does not expose write(); collect and send as one response.\n const chunks: string[] = [];\n let done = false;\n while (!done) {\n const { value, done: d } = await reader.read();\n if (value) chunks.push(value);\n done = d;\n }\n const content = chunks.join('');\n const body = wrapDocument\n ? `<!DOCTYPE html><html><head>${mergedHead ?? ''}</head><body>${content}</body></html>`\n : content;\n res.end(body);\n }\n } catch (err) {\n // Ensure the response is always closed to prevent the request hanging.\n // Re-throw so the framework's error handler can set the proper status code.\n try {\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\n res.end('Internal Server Error');\n } catch {\n // ignore secondary errors during error response\n }\n throw err;\n }\n };\n}\n"],"names":["wrapInDocument","htmlWithStyles","head","wrapDocument","extra","withDoctype","createSSRHandler","vnodeOrFactory","options","renderOptions","req","res","rawResult","isBundle","vnode","router","perRequestHead","renderToStringWithJITCSS","mergedHead","body","err","createStreamingSSRHandler","reader","renderToStream","done","value","d","chunks","content"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.ssr-middleware.es.js","names":[],"sources":["../src/lib/ssr-middleware.ts"],"sourcesContent":["/**\n * SSR middleware helpers for Express, Fastify, Hono, and other Node.js HTTP frameworks.\n *\n * Provides two handler factories that wrap the SSR rendering pipeline and\n * emit a complete HTML document response. Both accept a static VNode **or**\n * a per-request factory function so route-specific data can be threaded into\n * the render tree.\n *\n * @example Express — static VNode\n * ```ts\n * import express from 'express';\n * import { createSSRHandler } from '@jasonshimmy/custom-elements-runtime/ssr-middleware';\n * import { html } from '@jasonshimmy/custom-elements-runtime';\n *\n * const app = express();\n * app.get('/', createSSRHandler(html`<my-app />`, {\n * render: { dsd: true, jit: { extendedColors: true } },\n * }));\n * ```\n *\n * @example Express — per-request factory\n * ```ts\n * app.get('*', createSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true }, head: '<link rel=\"stylesheet\" href=\"/app.css\">' },\n * ));\n * ```\n *\n * @example Streaming variant\n * ```ts\n * app.get('*', createStreamingSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * ));\n * ```\n */\n\nimport { renderToStringWithJITCSS, renderToStream } from './ssr';\nimport type { VNode } from './runtime/types';\nimport type { RenderOptions } from './runtime/vdom-ssr';\nimport type { DSDRenderOptions } from './runtime/vdom-ssr-dsd';\nimport type { JITCSSOptions } from './runtime/style';\n\n/**\n * What a per-request factory may return.\n *\n * - Plain `VNode` — backward-compatible; no per-request router threading.\n * - `{ vnode, router? }` — the router instance is threaded through the render\n * context, making concurrent SSR requests safe (each render reads from its\n * own router, not the module-level `activeRouterProxy` singleton).\n * - `{ vnode, router?, head? }` — `head` is an HTML string injected into the\n * document `<head>` for this specific request (e.g. serialized loader data).\n * It is merged with the static `head` option passed to the handler factory.\n */\nexport type VnodeFactoryResult = VNode | { vnode: VNode; router?: unknown; head?: string };\n\n// ---------------------------------------------------------------------------\n// Minimal framework-agnostic HTTP types\n// ---------------------------------------------------------------------------\n\n/**\n * Minimal request interface compatible with Express, Fastify, Hono, and the\n * raw Node.js `IncomingMessage`. Extend or replace with your framework's\n * request type via the generic parameter on `createSSRHandler`.\n */\nexport interface MinimalRequest {\n url?: string;\n method?: string;\n headers?: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Minimal response interface compatible with Express, Fastify, Hono, and the\n * raw Node.js `ServerResponse`. `write` is optional — handlers fall back to\n * buffering when it is absent.\n */\nexport interface MinimalResponse {\n setHeader(name: string, value: string): void;\n write?(chunk: string): boolean | void;\n end(data?: string): void;\n}\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for {@link createSSRHandler} and {@link createStreamingSSRHandler}.\n */\nexport interface SSRMiddlewareOptions {\n /**\n * Render options forwarded to `renderToStringWithJITCSS`.\n * Defaults to `{ dsd: true }` so DSD output is on by default.\n */\n render?: RenderOptions & DSDRenderOptions & { jit?: JITCSSOptions };\n /**\n * Additional HTML inserted at the end of the `<head>` tag.\n * Use this to inject `<link>`, `<script>`, `<meta>`, or `<title>` tags.\n */\n head?: string;\n /**\n * When `true` (default), the response is wrapped in a complete\n * `<!DOCTYPE html>` document shell. Set to `false` if you want to\n * assemble the document yourself and only need the rendered fragment.\n */\n document?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction wrapInDocument(\n htmlWithStyles: string,\n head: string | undefined,\n wrapDocument: boolean,\n): string {\n if (!wrapDocument) return htmlWithStyles;\n\n // If the rendered HTML already contains a root <html> tag, inject extra\n // head tags and prepend the DOCTYPE — do not double-wrap.\n if (\n htmlWithStyles.trimStart().toLowerCase().startsWith('<html') ||\n htmlWithStyles.includes('</html>')\n ) {\n const extra = head ?? '';\n const withDoctype = htmlWithStyles.startsWith('<!DOCTYPE')\n ? htmlWithStyles\n : `<!DOCTYPE html>${htmlWithStyles}`;\n if (extra) {\n return withDoctype.includes('</head>')\n ? withDoctype.replace('</head>', `${extra}</head>`)\n : withDoctype;\n }\n return withDoctype;\n }\n\n // Minimal shell\n const headContent = head ?? '';\n return `<!DOCTYPE html><html><head>${headContent}</head><body>${htmlWithStyles}</body></html>`;\n}\n\n// ---------------------------------------------------------------------------\n// Handler factories\n// ---------------------------------------------------------------------------\n\n/**\n * Create a request handler that SSR-renders a VNode tree and sends the full\n * HTML document as the response.\n *\n * Compatible with Express, Fastify, Hono, and any framework that uses an\n * `(req, res)` handler signature. The generic `Req` parameter lets you use\n * your framework's typed request object.\n *\n * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)\n * factory function that receives the request and returns the VNode to render.\n * @param options - Render and document-shell options.\n *\n * @example\n * ```ts\n * app.get('*', createSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true, jit: { extendedColors: true } } },\n * ));\n * ```\n */\nexport function createSSRHandler<Req extends MinimalRequest = MinimalRequest>(\n vnodeOrFactory:\n | VnodeFactoryResult\n | ((req: Req) => VnodeFactoryResult | Promise<VnodeFactoryResult>),\n options?: SSRMiddlewareOptions,\n): (req: Req, res: MinimalResponse) => Promise<void> {\n const renderOptions: RenderOptions &\n DSDRenderOptions & { jit?: JITCSSOptions } = {\n dsd: true,\n ...options?.render,\n };\n const { head, document: wrapDocument = true } = options ?? {};\n\n return async (req, res) => {\n try {\n const rawResult =\n typeof vnodeOrFactory === 'function'\n ? await vnodeOrFactory(req)\n : vnodeOrFactory;\n\n const isBundle =\n rawResult !== null &&\n typeof rawResult === 'object' &&\n 'vnode' in (rawResult as object);\n const vnode = isBundle\n ? (rawResult as { vnode: VNode }).vnode\n : (rawResult as VNode);\n const router = isBundle\n ? (rawResult as { vnode: VNode; router?: unknown }).router\n : undefined;\n const perRequestHead = isBundle\n ? (rawResult as { head?: string }).head\n : undefined;\n\n const { htmlWithStyles } = renderToStringWithJITCSS(vnode, { ...renderOptions, router });\n\n const mergedHead = [head, perRequestHead].filter(Boolean).join('\\n') || undefined;\n const body = wrapInDocument(htmlWithStyles, mergedHead, wrapDocument);\n\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.end(body);\n } catch (err) {\n // Ensure the response is always closed to prevent the request hanging.\n // Re-throw so the framework's error handler can set the proper status code.\n try {\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\n res.end('Internal Server Error');\n } catch {\n // ignore secondary errors during error response\n }\n throw err;\n }\n };\n}\n\n/**\n * Create a request handler that SSR-renders a VNode tree and streams the HTML\n * response using chunked transfer encoding.\n *\n * Each chunk produced by the underlying {@link renderToStream} call is written\n * to the response as it becomes available, minimising Time-to-First-Byte.\n * The document shell preamble (`<!DOCTYPE html>…<body>`) is sent in the first\n * write so the browser can begin parsing immediately.\n *\n * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)\n * factory function that receives the request and returns the VNode to render.\n * @param options - Render and document-shell options.\n *\n * @example\n * ```ts\n * app.get('*', createStreamingSSRHandler(\n * (req) => html`<my-app url=\"${req.url}\" />`,\n * { render: { dsd: true } },\n * ));\n * ```\n */\nexport function createStreamingSSRHandler<\n Req extends MinimalRequest = MinimalRequest,\n>(\n vnodeOrFactory:\n | VnodeFactoryResult\n | ((req: Req) => VnodeFactoryResult | Promise<VnodeFactoryResult>),\n options?: SSRMiddlewareOptions,\n): (req: Req, res: MinimalResponse) => Promise<void> {\n const renderOptions: RenderOptions &\n DSDRenderOptions & { jit?: JITCSSOptions } = {\n dsd: true,\n ...options?.render,\n };\n const { head, document: wrapDocument = true } = options ?? {};\n\n return async (req, res) => {\n try {\n const rawResult =\n typeof vnodeOrFactory === 'function'\n ? await vnodeOrFactory(req)\n : vnodeOrFactory;\n\n const isBundle =\n rawResult !== null &&\n typeof rawResult === 'object' &&\n 'vnode' in (rawResult as object);\n const vnode = isBundle\n ? (rawResult as { vnode: VNode }).vnode\n : (rawResult as VNode);\n const router = isBundle\n ? (rawResult as { vnode: VNode; router?: unknown }).router\n : undefined;\n const perRequestHead = isBundle\n ? (rawResult as { head?: string }).head\n : undefined;\n\n const mergedHead = [head, perRequestHead].filter(Boolean).join('\\n') || undefined;\n\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n\n const stream = renderToStream(vnode, { ...renderOptions, router });\n const reader = stream.getReader();\n\n if (res.write) {\n // Streaming path: pipe chunks directly to the response as they arrive.\n res.setHeader('Transfer-Encoding', 'chunked');\n if (wrapDocument) {\n res.write(`<!DOCTYPE html><html><head>${mergedHead ?? ''}</head><body>`);\n }\n let done = false;\n while (!done) {\n const { value, done: d } = await reader.read();\n if (value) res.write(value);\n done = d;\n }\n if (wrapDocument) {\n res.end('</body></html>');\n } else {\n res.end();\n }\n } else {\n // Buffered fallback: framework does not expose write(); collect and send as one response.\n const chunks: string[] = [];\n let done = false;\n while (!done) {\n const { value, done: d } = await reader.read();\n if (value) chunks.push(value);\n done = d;\n }\n const content = chunks.join('');\n const body = wrapDocument\n ? `<!DOCTYPE html><html><head>${mergedHead ?? ''}</head><body>${content}</body></html>`\n : content;\n res.end(body);\n }\n } catch (err) {\n // Ensure the response is always closed to prevent the request hanging.\n // Re-throw so the framework's error handler can set the proper status code.\n try {\n res.setHeader('Content-Type', 'text/plain; charset=utf-8');\n res.end('Internal Server Error');\n } catch {\n // ignore secondary errors during error response\n }\n throw err;\n }\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`));return s?`<style>${s}</style>`:""}let p=null,E=0;function H(t){p=t,E=0}function I(){p=null}function y(t,r){if(!r.dsd)return f(t,r);if(typeof t=="string")return o.escapeHTML(t);const e=t.tag;if(e==="#text"||e==="#anchor"||e==="#raw")return f(t,r);if(_(e))return N(t,r);const n=t.props?.attrs?{...t.props.attrs}:{},s=A(n,e,r);if(j.has(e))return`<${e}${s}>`;const i=T(t.children,r);return`<${e}${s}>${i}</${e}>`}function N(t,r){const e=t.tag,n=m.registry.get(e),s=t.props?.attrs??{},i=P(s);if(!n){const h=T(t.children,r);return`<${e}${i}><template shadowrootmode="open"></template>${h}</${e}>`}const a=n.hydrate,u=a&&a!=="load"?` data-cer-hydrate="${a}"`:"",{shadowVNode:l,useStyleCSS:d,asyncPromise:S}=o.runComponentSSRRender(n,s,e,r.router);if(S&&p===null&&R.devWarn(`[SSR] Component "${e}" has an async render function. In standard SSR the shadow DOM will be empty. Use renderToStream() for incremental async component streaming.`),S&&p!==null){const h=`cer-stream-${E++}`,w=T(t.children,r);return p.push({id:h,tag:e,attrsString:i,hydrateAttr:u,useStyleCSS:d,lightDOM:w,opts:r,promise:S,router:r.router}),`<${e} id="${h}"${i}${u}><template shadowrootmode="open"></template>${w}</${e}>`}let c="";l!=null&&(Array.isArray(l)?c=l.map(h=>y(h,r)).join(""):c=y(l,r));const $=D(d,c),O=T(t.children,r);return`<${e}${i}${u}><template shadowrootmode="open">${$}${c}</template>${O}</${e}>`}function T(t,r){return t?typeof t=="string"?o.escapeHTML(t):Array.isArray(t)?t.filter(e=>e!=null).map(e=>y(e,r)).join(""):y(t,r):""}function L(t,r){const e={dsd:!0,...r},n=y(t,e);return e.dsdPolyfill!==!1?n.includes("</body>")?n.replace("</body>",`${g}</body>`):n+g:n}function M(t,r){const{jit:e,dsd:n,dsdPolyfill:s,...i}=r??{};e&&b.enableJITCSS(e),o.beginSSRGlobalStyleCollection();let a,u;try{n?a=L(t,{...i,dsd:!0,dsdPolyfill:!1}):a=f(t,i)}finally{u=o.endSSRGlobalStyleCollection()}const l=b.jitCSS(a),d=u.join(`
|
|
3
|
-
`),S=[];l&&S.push(`<style id="cer-ssr-jit">${l}</style>`),d.trim()&&S.push(`<style id="cer-ssr-global">${d}</style>`);let c=a;if(S.length){const $=S.join("");c=a.includes("</head>")?a.replace("</head>",`${$}</head>`):`${$}${a}`}return n&&s!==!1&&(c=c.includes("</body>")?c.replace("</body>",`${g}</body>`):c+g),{html:a,css:l,globalStyles:d,htmlWithStyles:c}}function q(t,r){return M(t,{...r,dsd:!0})}function k(t,r){return new ReadableStream({async start(e){const n=[];H(n);try{const{htmlWithStyles:s}=M(t,r);e.enqueue(s)}catch(s){e.error(s);return}finally{I()}for(const s of n)try{const i=await s.promise,a=Array.isArray(i)?i.map(d=>y(d,s.opts)).join(""):y(i,s.opts),l=`${D(s.useStyleCSS,a)}${a}`;e.enqueue(`<script>(function(){var e=document.getElementById(${JSON.stringify(s.id)});if(!e)return;var s=e.shadowRoot;if(!s&&e.attachShadow)try{s=e.attachShadow({mode:'open'});}catch(_){};if(s)s.innerHTML=${JSON.stringify(l)};e.removeAttribute('id');})();<\/script>`)}catch{}e.close()}})}exports.clearRegisteredEntityMap=o.clearRegisteredEntityMap;exports.loadEntityMap=o.loadEntityMap;exports.registerEntityMap=o.registerEntityMap;exports.DSD_POLYFILL_SCRIPT=g;exports.renderToStream=k;exports.renderToString=f;exports.renderToStringDSD=L;exports.renderToStringWithJITCSS=M;exports.renderToStringWithJITCSSDSD=q;
|
|
4
|
-
//# sourceMappingURL=custom-elements-runtime.ssr.cjs.js.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./hooks-fYQgZk2g.cjs"),r=require("./ssr-DtD9e5iA.cjs");exports.DSD_POLYFILL_SCRIPT=r.DSD_POLYFILL_SCRIPT;exports.clearRegisteredEntityMap=e.clearRegisteredEntityMap;exports.loadEntityMap=e.loadEntityMap;exports.registerEntityMap=e.registerEntityMap;exports.renderToStream=r.renderToStream;exports.renderToString=r.renderToString;exports.renderToStringDSD=r.renderToStringDSD;exports.renderToStringWithJITCSS=r.renderToStringWithJITCSS;exports.renderToStringWithJITCSSDSD=r.renderToStringWithJITCSSDSD;
|
|
@@ -1,178 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { S as P, T as w, a as j } from "./namespace-helpers-D4wC2-qA.js";
|
|
4
|
-
import { j as C, e as _ } from "./style-BmyOIMcU.js";
|
|
5
|
-
import { m as x, b as I } from "./css-utils-Cg4o1MqY.js";
|
|
6
|
-
import { a as k } from "./logger-BvkEbVM4.js";
|
|
7
|
-
const T = /* @__PURE__ */ new Set([
|
|
8
|
-
"area",
|
|
9
|
-
"base",
|
|
10
|
-
"br",
|
|
11
|
-
"col",
|
|
12
|
-
"embed",
|
|
13
|
-
"hr",
|
|
14
|
-
"img",
|
|
15
|
-
"input",
|
|
16
|
-
"link",
|
|
17
|
-
"meta",
|
|
18
|
-
"param",
|
|
19
|
-
"source",
|
|
20
|
-
"track",
|
|
21
|
-
"wbr"
|
|
22
|
-
]);
|
|
23
|
-
function A(t, e, r) {
|
|
24
|
-
const n = r.injectSvgNamespace ?? !0, s = r.injectKnownNamespaces ?? n, i = { ...t };
|
|
25
|
-
return n && e === "svg" && !("xmlns" in i) ? i.xmlns = P : s && e in w && !("xmlns" in i) && (i.xmlns = w[e]), Object.entries(i).map(([a, c]) => ` ${a}="${f(String(c))}"`).join("");
|
|
26
|
-
}
|
|
27
|
-
function W(t) {
|
|
28
|
-
return Object.entries(t).map(([e, r]) => ` ${e}="${f(String(r))}"`).join("");
|
|
29
|
-
}
|
|
30
|
-
function y(t, e) {
|
|
31
|
-
if (typeof t == "string") return f(t);
|
|
32
|
-
if (t.tag === "#text")
|
|
33
|
-
return typeof t.children == "string" ? f(t.children) : "";
|
|
34
|
-
if (t.tag === "#anchor")
|
|
35
|
-
return (Array.isArray(t.children) ? t.children.filter((a) => a != null) : []).map((a) => y(a, e)).join("");
|
|
36
|
-
if (t.tag === "#raw")
|
|
37
|
-
return typeof t.children == "string" ? t.children : "";
|
|
38
|
-
const r = t.props?.attrs ? { ...t.props.attrs } : {}, n = A(r, t.tag, e ?? {});
|
|
39
|
-
if (T.has(t.tag))
|
|
40
|
-
return `<${t.tag}${n}>`;
|
|
41
|
-
const s = Array.isArray(t.children) ? t.children.filter((i) => i != null).map((i) => y(i, e)).join("") : typeof t.children == "string" ? f(t.children) : t.children ? y(t.children, e) : "";
|
|
42
|
-
return `<${t.tag}${n}>${s}</${t.tag}>`;
|
|
43
|
-
}
|
|
44
|
-
const $ = "<script>(function(){if(HTMLTemplateElement.prototype.hasOwnProperty('shadowRootMode'))return;document.querySelectorAll('template[shadowrootmode]').forEach(function(t){var m=t.getAttribute('shadowrootmode');var s=t.parentElement.attachShadow({mode:m});s.appendChild(t.content);t.remove();});})()<\/script>";
|
|
45
|
-
function B(t) {
|
|
46
|
-
return t.includes("-") && j.has(t);
|
|
47
|
-
}
|
|
48
|
-
function D(t, e) {
|
|
49
|
-
const r = [I];
|
|
50
|
-
t.trim() && r.push(t);
|
|
51
|
-
const n = C(e);
|
|
52
|
-
n.trim() && r.push(n);
|
|
53
|
-
const s = x(r.join(`
|
|
54
|
-
`));
|
|
55
|
-
return s ? `<style>${s}</style>` : "";
|
|
56
|
-
}
|
|
57
|
-
let S = null, M = 0;
|
|
58
|
-
function H(t) {
|
|
59
|
-
S = t, M = 0;
|
|
60
|
-
}
|
|
61
|
-
function J() {
|
|
62
|
-
S = null;
|
|
63
|
-
}
|
|
64
|
-
function m(t, e) {
|
|
65
|
-
if (!e.dsd)
|
|
66
|
-
return y(t, e);
|
|
67
|
-
if (typeof t == "string")
|
|
68
|
-
return f(t);
|
|
69
|
-
const r = t.tag;
|
|
70
|
-
if (r === "#text" || r === "#anchor" || r === "#raw")
|
|
71
|
-
return y(t, e);
|
|
72
|
-
if (B(r))
|
|
73
|
-
return V(t, e);
|
|
74
|
-
const n = t.props?.attrs ? { ...t.props.attrs } : {}, s = A(n, r, e);
|
|
75
|
-
if (T.has(r))
|
|
76
|
-
return `<${r}${s}>`;
|
|
77
|
-
const i = g(t.children, e);
|
|
78
|
-
return `<${r}${s}>${i}</${r}>`;
|
|
79
|
-
}
|
|
80
|
-
function V(t, e) {
|
|
81
|
-
const r = t.tag, n = j.get(r), s = t.props?.attrs ?? {}, i = W(s);
|
|
82
|
-
if (!n) {
|
|
83
|
-
const h = g(t.children, e);
|
|
84
|
-
return `<${r}${i}><template shadowrootmode="open"></template>${h}</${r}>`;
|
|
85
|
-
}
|
|
86
|
-
const a = n.hydrate, c = a && a !== "load" ? ` data-cer-hydrate="${a}"` : "", { shadowVNode: o, useStyleCSS: u, asyncPromise: d } = R(n, s, r, e.router);
|
|
87
|
-
if (d && S === null && k(
|
|
88
|
-
`[SSR] Component "${r}" has an async render function. In standard SSR the shadow DOM will be empty. Use renderToStream() for incremental async component streaming.`
|
|
89
|
-
), d && S !== null) {
|
|
90
|
-
const h = `cer-stream-${M++}`, b = g(t.children, e);
|
|
91
|
-
return S.push({
|
|
92
|
-
id: h,
|
|
93
|
-
tag: r,
|
|
94
|
-
attrsString: i,
|
|
95
|
-
hydrateAttr: c,
|
|
96
|
-
useStyleCSS: u,
|
|
97
|
-
lightDOM: b,
|
|
98
|
-
opts: e,
|
|
99
|
-
promise: d,
|
|
100
|
-
router: e.router
|
|
101
|
-
}), `<${r} id="${h}"${i}${c}><template shadowrootmode="open"></template>${b}</${r}>`;
|
|
102
|
-
}
|
|
103
|
-
let l = "";
|
|
104
|
-
o != null && (Array.isArray(o) ? l = o.map((h) => m(h, e)).join("") : l = m(o, e));
|
|
105
|
-
const p = D(u, l), E = g(t.children, e);
|
|
106
|
-
return `<${r}${i}${c}><template shadowrootmode="open">${p}${l}</template>${E}</${r}>`;
|
|
107
|
-
}
|
|
108
|
-
function g(t, e) {
|
|
109
|
-
return t ? typeof t == "string" ? f(t) : Array.isArray(t) ? t.filter((r) => r != null).map((r) => m(r, e)).join("") : m(t, e) : "";
|
|
110
|
-
}
|
|
111
|
-
function G(t, e) {
|
|
112
|
-
const r = { dsd: !0, ...e }, n = m(t, r);
|
|
113
|
-
return r.dsdPolyfill !== !1 ? n.includes("</body>") ? n.replace("</body>", `${$}</body>`) : n + $ : n;
|
|
114
|
-
}
|
|
115
|
-
function O(t, e) {
|
|
116
|
-
const { jit: r, dsd: n, dsdPolyfill: s, ...i } = e ?? {};
|
|
117
|
-
r && _(r), L();
|
|
118
|
-
let a, c;
|
|
119
|
-
try {
|
|
120
|
-
n ? a = G(t, {
|
|
121
|
-
...i,
|
|
122
|
-
dsd: !0,
|
|
123
|
-
dsdPolyfill: !1
|
|
124
|
-
}) : a = y(t, i);
|
|
125
|
-
} finally {
|
|
126
|
-
c = N();
|
|
127
|
-
}
|
|
128
|
-
const o = C(a), u = c.join(`
|
|
129
|
-
`), d = [];
|
|
130
|
-
o && d.push(`<style id="cer-ssr-jit">${o}</style>`), u.trim() && d.push(`<style id="cer-ssr-global">${u}</style>`);
|
|
131
|
-
let l = a;
|
|
132
|
-
if (d.length) {
|
|
133
|
-
const p = d.join("");
|
|
134
|
-
l = a.includes("</head>") ? a.replace("</head>", `${p}</head>`) : `${p}${a}`;
|
|
135
|
-
}
|
|
136
|
-
return n && s !== !1 && (l = l.includes("</body>") ? l.replace("</body>", `${$}</body>`) : l + $), { html: a, css: o, globalStyles: u, htmlWithStyles: l };
|
|
137
|
-
}
|
|
138
|
-
function X(t, e) {
|
|
139
|
-
return O(t, { ...e, dsd: !0 });
|
|
140
|
-
}
|
|
141
|
-
function z(t, e) {
|
|
142
|
-
return new ReadableStream({
|
|
143
|
-
async start(r) {
|
|
144
|
-
const n = [];
|
|
145
|
-
H(n);
|
|
146
|
-
try {
|
|
147
|
-
const { htmlWithStyles: s } = O(t, e);
|
|
148
|
-
r.enqueue(s);
|
|
149
|
-
} catch (s) {
|
|
150
|
-
r.error(s);
|
|
151
|
-
return;
|
|
152
|
-
} finally {
|
|
153
|
-
J();
|
|
154
|
-
}
|
|
155
|
-
for (const s of n)
|
|
156
|
-
try {
|
|
157
|
-
const i = await s.promise, a = Array.isArray(i) ? i.map((u) => m(u, s.opts)).join("") : m(i, s.opts), o = `${D(s.useStyleCSS, a)}${a}`;
|
|
158
|
-
r.enqueue(
|
|
159
|
-
`<script>(function(){var e=document.getElementById(${JSON.stringify(s.id)});if(!e)return;var s=e.shadowRoot;if(!s&&e.attachShadow)try{s=e.attachShadow({mode:'open'});}catch(_){};if(s)s.innerHTML=${JSON.stringify(o)};e.removeAttribute('id');})();<\/script>`
|
|
160
|
-
);
|
|
161
|
-
} catch {
|
|
162
|
-
}
|
|
163
|
-
r.close();
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
1
|
+
import { A as t, C as e, k as a } from "./hooks-_3xP4G2N.js";
|
|
2
|
+
import { a as n, i as S, n as o, o as s, r as T, t as d } from "./ssr-B3lxl1vr.js";
|
|
167
3
|
export {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
4
|
+
S as DSD_POLYFILL_SCRIPT,
|
|
5
|
+
e as clearRegisteredEntityMap,
|
|
6
|
+
a as loadEntityMap,
|
|
7
|
+
t as registerEntityMap,
|
|
8
|
+
d as renderToStream,
|
|
9
|
+
s as renderToString,
|
|
10
|
+
n as renderToStringDSD,
|
|
11
|
+
o as renderToStringWithJITCSS,
|
|
12
|
+
T as renderToStringWithJITCSSDSD
|
|
177
13
|
};
|
|
178
|
-
//# sourceMappingURL=custom-elements-runtime.ssr.es.js.map
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./logger-BYIN7ysT.cjs");var f=50;function d(i){let t={...i};const n=[];function o(e){return n.push(e),n.length>=f&&a.devWarn(`[store] ${n.length} active subscriptions detected. This may indicate orphaned listeners from components that were destroyed without calling their unsubscribe function. Check that every subscribe() call is paired with the returned unsubscribe in a disconnect/cleanup handler.`),e(t),()=>{const r=n.indexOf(e);r!==-1&&n.splice(r,1)}}function c(){return t}function s(e){const r=typeof e=="function"?e(t):e;t={...t,...r},u()}function u(){const e=n.slice();for(const r of e)r(t)}return{subscribe:o,getState:c,setState:s}}exports.createStore=d;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=custom-elements-runtime.store.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.store.cjs.js","sources":["../src/lib/store.ts"],"sourcesContent":["type Listener<T> = (state: T) => void;\n\nimport { devWarn } from './runtime/logger';\n\nconst STORE_LISTENER_WARN_THRESHOLD = 50;\n\nexport interface Store<T extends object> {\n /**\n * Subscribe to store updates.\n * Returns an unsubscribe function to remove the listener.\n */\n subscribe(listener: Listener<T>): () => void;\n getState(): T;\n setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;\n}\n\nexport function createStore<T extends object>(initial: T): Store<T> {\n let state = { ...initial } as T; // no Proxy needed if we update via setState\n const listeners: Listener<T>[] = [];\n\n function subscribe(listener: Listener<T>) {\n listeners.push(listener);\n if (listeners.length >= STORE_LISTENER_WARN_THRESHOLD) {\n devWarn(\n `[store] ${listeners.length} active subscriptions detected. ` +\n 'This may indicate orphaned listeners from components that were destroyed ' +\n 'without calling their unsubscribe function. Check that every subscribe() ' +\n 'call is paired with the returned unsubscribe in a disconnect/cleanup handler.',\n );\n }\n listener(state); // initial push\n\n // Return unsubscribe function\n return () => {\n const idx = listeners.indexOf(listener);\n if (idx !== -1) listeners.splice(idx, 1);\n };\n }\n\n function getState(): T {\n return state;\n }\n\n function setState(partial: Partial<T> | ((prev: T) => Partial<T>)) {\n const next = typeof partial === 'function' ? partial(state) : partial;\n\n state = { ...state, ...next };\n notify();\n }\n\n function notify() {\n // Snapshot the listeners array before iterating so that a listener calling\n // setState() (re-entrant notify) cannot corrupt the current iteration.\n const snapshot = listeners.slice();\n for (const fn of snapshot) fn(state);\n }\n\n return { subscribe, getState, setState };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.store.cjs.js","names":[],"sources":["../src/lib/store.ts"],"sourcesContent":["type Listener<T> = (state: T) => void;\n\nimport { devWarn } from './runtime/logger';\n\nconst STORE_LISTENER_WARN_THRESHOLD = 50;\n\nexport interface Store<T extends object> {\n /**\n * Subscribe to store updates.\n * Returns an unsubscribe function to remove the listener.\n */\n subscribe(listener: Listener<T>): () => void;\n getState(): T;\n setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;\n}\n\nexport function createStore<T extends object>(initial: T): Store<T> {\n let state = { ...initial } as T; // no Proxy needed if we update via setState\n const listeners: Listener<T>[] = [];\n\n function subscribe(listener: Listener<T>) {\n listeners.push(listener);\n if (listeners.length >= STORE_LISTENER_WARN_THRESHOLD) {\n devWarn(\n `[store] ${listeners.length} active subscriptions detected. ` +\n 'This may indicate orphaned listeners from components that were destroyed ' +\n 'without calling their unsubscribe function. Check that every subscribe() ' +\n 'call is paired with the returned unsubscribe in a disconnect/cleanup handler.',\n );\n }\n listener(state); // initial push\n\n // Return unsubscribe function\n return () => {\n const idx = listeners.indexOf(listener);\n if (idx !== -1) listeners.splice(idx, 1);\n };\n }\n\n function getState(): T {\n return state;\n }\n\n function setState(partial: Partial<T> | ((prev: T) => Partial<T>)) {\n const next = typeof partial === 'function' ? partial(state) : partial;\n\n state = { ...state, ...next };\n notify();\n }\n\n function notify() {\n // Snapshot the listeners array before iterating so that a listener calling\n // setState() (re-entrant notify) cannot corrupt the current iteration.\n const snapshot = listeners.slice();\n for (const fn of snapshot) fn(state);\n }\n\n return { subscribe, getState, setState };\n}\n"],"mappings":"4GAIA,IAAM,EAAgC,GAYtC,SAAgB,EAA8B,EAAsB,CAClE,IAAI,EAAQ,CAAE,GAAG,CAAA,EACjB,MAAM,EAA2B,CAAA,EAEjC,SAAS,EAAU,EAAuB,CACxC,OAAA,EAAU,KAAK,CAAA,EACX,EAAU,QAAU,GACtB,EAAA,QACE,WAAW,EAAU,MAAA,iQAAO,EAMhC,EAAS,CAAA,EAGT,IAAa,CACX,MAAM,EAAM,EAAU,QAAQ,CAAA,EAC1B,IAAQ,IAAI,EAAU,OAAO,EAAK,CAAA,GAI1C,SAAS,GAAc,CACrB,OAAO,EAGT,SAAS,EAAS,EAAiD,CACjE,MAAM,EAAO,OAAO,GAAY,WAAa,EAAQ,CAAA,EAAS,EAE9D,EAAQ,CAAE,GAAG,EAAO,GAAG,GACvB,EAAA,EAGF,SAAS,GAAS,CAGhB,MAAM,EAAW,EAAU,MAAA,EAC3B,UAAW,KAAM,EAAU,EAAG,CAAA,EAGhC,MAAO,CAAE,UAAA,EAAW,SAAA,EAAU,SAAA"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function d(
|
|
4
|
-
let e = { ...
|
|
1
|
+
import { r as f } from "./logger-L25axmB-.js";
|
|
2
|
+
var a = 50;
|
|
3
|
+
function d(i) {
|
|
4
|
+
let e = { ...i };
|
|
5
5
|
const n = [];
|
|
6
|
-
function
|
|
7
|
-
return n.push(t), n.length >= a && f(
|
|
8
|
-
`[store] ${n.length} active subscriptions detected. This may indicate orphaned listeners from components that were destroyed without calling their unsubscribe function. Check that every subscribe() call is paired with the returned unsubscribe in a disconnect/cleanup handler.`
|
|
9
|
-
), t(e), () => {
|
|
6
|
+
function c(t) {
|
|
7
|
+
return n.push(t), n.length >= a && f(`[store] ${n.length} active subscriptions detected. This may indicate orphaned listeners from components that were destroyed without calling their unsubscribe function. Check that every subscribe() call is paired with the returned unsubscribe in a disconnect/cleanup handler.`), t(e), () => {
|
|
10
8
|
const s = n.indexOf(t);
|
|
11
9
|
s !== -1 && n.splice(s, 1);
|
|
12
10
|
};
|
|
@@ -16,15 +14,23 @@ function d(c) {
|
|
|
16
14
|
}
|
|
17
15
|
function r(t) {
|
|
18
16
|
const s = typeof t == "function" ? t(e) : t;
|
|
19
|
-
e = {
|
|
17
|
+
e = {
|
|
18
|
+
...e,
|
|
19
|
+
...s
|
|
20
|
+
}, u();
|
|
20
21
|
}
|
|
21
22
|
function u() {
|
|
22
23
|
const t = n.slice();
|
|
23
24
|
for (const s of t) s(e);
|
|
24
25
|
}
|
|
25
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
subscribe: c,
|
|
28
|
+
getState: o,
|
|
29
|
+
setState: r
|
|
30
|
+
};
|
|
26
31
|
}
|
|
27
32
|
export {
|
|
28
33
|
d as createStore
|
|
29
34
|
};
|
|
30
|
-
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=custom-elements-runtime.store.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.store.es.js","sources":["../src/lib/store.ts"],"sourcesContent":["type Listener<T> = (state: T) => void;\n\nimport { devWarn } from './runtime/logger';\n\nconst STORE_LISTENER_WARN_THRESHOLD = 50;\n\nexport interface Store<T extends object> {\n /**\n * Subscribe to store updates.\n * Returns an unsubscribe function to remove the listener.\n */\n subscribe(listener: Listener<T>): () => void;\n getState(): T;\n setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;\n}\n\nexport function createStore<T extends object>(initial: T): Store<T> {\n let state = { ...initial } as T; // no Proxy needed if we update via setState\n const listeners: Listener<T>[] = [];\n\n function subscribe(listener: Listener<T>) {\n listeners.push(listener);\n if (listeners.length >= STORE_LISTENER_WARN_THRESHOLD) {\n devWarn(\n `[store] ${listeners.length} active subscriptions detected. ` +\n 'This may indicate orphaned listeners from components that were destroyed ' +\n 'without calling their unsubscribe function. Check that every subscribe() ' +\n 'call is paired with the returned unsubscribe in a disconnect/cleanup handler.',\n );\n }\n listener(state); // initial push\n\n // Return unsubscribe function\n return () => {\n const idx = listeners.indexOf(listener);\n if (idx !== -1) listeners.splice(idx, 1);\n };\n }\n\n function getState(): T {\n return state;\n }\n\n function setState(partial: Partial<T> | ((prev: T) => Partial<T>)) {\n const next = typeof partial === 'function' ? partial(state) : partial;\n\n state = { ...state, ...next };\n notify();\n }\n\n function notify() {\n // Snapshot the listeners array before iterating so that a listener calling\n // setState() (re-entrant notify) cannot corrupt the current iteration.\n const snapshot = listeners.slice();\n for (const fn of snapshot) fn(state);\n }\n\n return { subscribe, getState, setState };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.store.es.js","names":[],"sources":["../src/lib/store.ts"],"sourcesContent":["type Listener<T> = (state: T) => void;\n\nimport { devWarn } from './runtime/logger';\n\nconst STORE_LISTENER_WARN_THRESHOLD = 50;\n\nexport interface Store<T extends object> {\n /**\n * Subscribe to store updates.\n * Returns an unsubscribe function to remove the listener.\n */\n subscribe(listener: Listener<T>): () => void;\n getState(): T;\n setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;\n}\n\nexport function createStore<T extends object>(initial: T): Store<T> {\n let state = { ...initial } as T; // no Proxy needed if we update via setState\n const listeners: Listener<T>[] = [];\n\n function subscribe(listener: Listener<T>) {\n listeners.push(listener);\n if (listeners.length >= STORE_LISTENER_WARN_THRESHOLD) {\n devWarn(\n `[store] ${listeners.length} active subscriptions detected. ` +\n 'This may indicate orphaned listeners from components that were destroyed ' +\n 'without calling their unsubscribe function. Check that every subscribe() ' +\n 'call is paired with the returned unsubscribe in a disconnect/cleanup handler.',\n );\n }\n listener(state); // initial push\n\n // Return unsubscribe function\n return () => {\n const idx = listeners.indexOf(listener);\n if (idx !== -1) listeners.splice(idx, 1);\n };\n }\n\n function getState(): T {\n return state;\n }\n\n function setState(partial: Partial<T> | ((prev: T) => Partial<T>)) {\n const next = typeof partial === 'function' ? partial(state) : partial;\n\n state = { ...state, ...next };\n notify();\n }\n\n function notify() {\n // Snapshot the listeners array before iterating so that a listener calling\n // setState() (re-entrant notify) cannot corrupt the current iteration.\n const snapshot = listeners.slice();\n for (const fn of snapshot) fn(state);\n }\n\n return { subscribe, getState, setState };\n}\n"],"mappings":";AAIA,IAAM,IAAgC;AAYtC,SAAgB,EAA8B,GAAsB;AAClE,MAAI,IAAQ,EAAE,GAAG,EAAA;AACjB,QAAM,IAA2B,CAAA;AAEjC,WAAS,EAAU,GAAuB;AACxC,WAAA,EAAU,KAAK,CAAA,GACX,EAAU,UAAU,KACtB,EACE,WAAW,EAAU,MAAA,iQAAO,GAMhC,EAAS,CAAA,GAGT,MAAa;AACX,YAAM,IAAM,EAAU,QAAQ,CAAA;AAC9B,MAAI,MAAQ,MAAI,EAAU,OAAO,GAAK,CAAA;AAAA;;AAI1C,WAAS,IAAc;AACrB,WAAO;AAAA;AAGT,WAAS,EAAS,GAAiD;AACjE,UAAM,IAAO,OAAO,KAAY,aAAa,EAAQ,CAAA,IAAS;AAE9D,IAAA,IAAQ;AAAA,MAAE,GAAG;AAAA,MAAO,GAAG;AAAA,OACvB,EAAA;AAAA;AAGF,WAAS,IAAS;AAGhB,UAAM,IAAW,EAAU,MAAA;AAC3B,eAAW,KAAM,EAAU,CAAA,EAAG,CAAA;AAAA;AAGhC,SAAO;AAAA,IAAE,WAAA;AAAA,IAAW,UAAA;AAAA,IAAU,UAAA;AAAA"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("./css-utils-mgjmH8qX.cjs"),O=require("./custom-elements-runtime.directives.cjs.js");var p={fade:{enterFrom:"opacity-0",enterActive:"transition-opacity duration-300 ease-out",enterTo:"opacity-100",leaveFrom:"opacity-100",leaveActive:"transition-opacity duration-200 ease-in",leaveTo:"opacity-0"},"slide-right":{enterFrom:"translate-x-[100%] opacity-0",enterActive:"transition-all duration-300 ease-out",enterTo:"translate-x-[0%] opacity-100",leaveFrom:"translate-x-[0%] opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"translate-x-[100%] opacity-0"},"slide-left":{enterFrom:"translate-x-[-100%] opacity-0",enterActive:"transition-all duration-300 ease-out",enterTo:"translate-x-[0%] opacity-100",leaveFrom:"translate-x-[0%] opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"translate-x-[-100%] opacity-0"},"slide-up":{enterFrom:"translate-y-[100%] opacity-0",enterActive:"transition-all duration-300 ease-out",enterTo:"translate-y-[0%] opacity-100",leaveFrom:"translate-y-[0%] opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"translate-y-[100%] opacity-0"},"slide-down":{enterFrom:"translate-y-[-100%] opacity-0",enterActive:"transition-all duration-300 ease-out",enterTo:"translate-y-[0%] opacity-100",leaveFrom:"translate-y-[0%] opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"translate-y-[-100%] opacity-0"},scale:{enterFrom:"scale-95 opacity-0",enterActive:"transition-all duration-200 ease-out",enterTo:"scale-100 opacity-100",leaveFrom:"scale-100 opacity-100",leaveActive:"transition-all duration-150 ease-in",leaveTo:"scale-95 opacity-0"},"scale-down":{enterFrom:"scale-105 opacity-0",enterActive:"transition-all duration-200 ease-out",enterTo:"scale-100 opacity-100",leaveFrom:"scale-100 opacity-100",leaveActive:"transition-all duration-150 ease-in",leaveTo:"scale-105 opacity-0"},bounce:{enterFrom:"scale-0 opacity-0",enterActive:"transition-all duration-500 ease-out",enterTo:"scale-100 opacity-100",leaveFrom:"scale-100 opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"scale-0 opacity-0"},zoom:{enterFrom:"scale-0 opacity-0",enterActive:"transition-all duration-300 ease-out",enterTo:"scale-100 opacity-100",leaveFrom:"scale-100 opacity-100",leaveActive:"transition-all duration-200 ease-in",leaveTo:"scale-0 opacity-0"},flip:{enterFrom:"rotate-[90deg] opacity-0",enterActive:"transition-all duration-400 ease-out",enterTo:"rotate-[0deg] opacity-100",leaveFrom:"rotate-[0deg] opacity-100",leaveActive:"transition-all duration-300 ease-in",leaveTo:"rotate-[90deg] opacity-0"}};function N(t,i){const{preset:e,show:d,mode:s="default",duration:k,appear:E=!1,css:b=!0,name:x,enterFrom:f,enterActive:m,enterTo:u,leaveFrom:r,leaveActive:l,leaveTo:c,onBeforeEnter:T,onEnter:A,onAfterEnter:h,onEnterCancelled:F,onBeforeLeave:L,onLeave:j,onAfterLeave:_,onLeaveCancelled:w}=t;let a;e&&p[e]?(a={...p[e]},f&&(a.enterFrom=f),m&&(a.enterActive=m),u&&(a.enterTo=u),r&&(a.leaveFrom=r),l&&(a.leaveActive=l),c&&(a.leaveTo=c)):a={enterFrom:f,enterActive:m,enterTo:u,leaveFrom:r,leaveActive:l,leaveTo:c};const B=d&&typeof i=="function"?i():i,S=x||(e?`transition-${e}`:"transition"),g=O.anchorBlock(d?B:[],S);return g._transition={name:S,classes:a,mode:s,duration:k,appear:E,css:b,state:d?"visible":"hidden",hooks:{onBeforeEnter:T,onEnter:A,onAfterEnter:h,onEnterCancelled:F,onBeforeLeave:L,onLeave:j,onAfterLeave:_,onLeaveCancelled:w}},g}function R(t,i){const{tag:e="div",moveClass:d="transition-transform duration-300",preset:s,show:k=!0,mode:E="default",duration:b,appear:x=!1,css:f=!0,name:m,class:u,style:r,enterFrom:l,enterActive:c,enterTo:T,leaveFrom:A,leaveActive:h,leaveTo:F,onBeforeEnter:L,onEnter:j,onAfterEnter:_,onEnterCancelled:w,onBeforeLeave:a,onLeave:B,onAfterLeave:S,onLeaveCancelled:g}=t;let n;s&&p[s]?(n={...p[s]},l&&(n.enterFrom=l),c&&(n.enterActive=c),T&&(n.enterTo=T),A&&(n.leaveFrom=A),h&&(n.leaveActive=h),F&&(n.leaveTo=F)):n={enterFrom:l,enterActive:c,enterTo:T,leaveFrom:A,leaveActive:h,leaveTo:F};const $=m||(s?`transition-group-${s}`:"transition-group"),C=[];for(const o of k?i:[])if(o&&typeof o=="object"&&o.tag==="#anchor"){const P=Array.isArray(o.children)?o.children:[];for(const y of P)if(y&&typeof y=="object"){const G={...y,key:o.key||y.key,props:{...y.props,_anchorKey:o.key}};C.push(G)}else C.push(y)}else C.push(o);const q=(()=>{if(r)return typeof r=="string"?r:Object.entries(r).map(([o,P])=>`${o}: ${P}`).join("; ")})();return{tag:e,children:C,key:$,props:{attrs:{...u?{class:u}:{},...q?{style:q}:{}},_transitionGroup:{name:$,classes:n,moveClass:d,mode:E,duration:b,appear:x,css:f,hooks:{onBeforeEnter:L,onEnter:j,onAfterEnter:_,onEnterCancelled:w,onBeforeLeave:a,onLeave:B,onAfterLeave:S,onLeaveCancelled:g}}}}}function z(t){return{...t}}var v=null;function I(){if(!v){if(typeof CSSStyleSheet>"u")return v={cssRules:[],replaceSync:()=>{},toString:()=>""},v;const t=[];Object.values(p).forEach(e=>{e.enterFrom&&t.push(e.enterFrom),e.enterActive&&t.push(e.enterActive),e.enterTo&&t.push(e.enterTo),e.leaveFrom&&t.push(e.leaveFrom),e.leaveActive&&t.push(e.leaveActive),e.leaveTo&&t.push(e.leaveTo)});const i=K.processJITCSS(`<div class="${t.join(" ")}"></div>`);try{v=new CSSStyleSheet,v.replaceSync(i)}catch{v={cssRules:[],replaceSync:()=>{},toString:()=>i||""}}}return v}exports.Transition=N;exports.TransitionGroup=R;exports.createTransitionPreset=z;exports.getTransitionStyleSheet=I;exports.transitionPresets=p;
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=custom-elements-runtime.transitions.cjs.js.map
|