@jasonshimmy/custom-elements-runtime 2.8.2 → 3.1.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.
Files changed (99) hide show
  1. package/README.md +223 -73
  2. package/dist/css-utils-Cg4o1MqY.js +643 -0
  3. package/dist/css-utils-Cg4o1MqY.js.map +1 -0
  4. package/dist/css-utils-RqkyBWft.cjs +576 -0
  5. package/dist/css-utils-RqkyBWft.cjs.map +1 -0
  6. package/dist/custom-elements-runtime.cjs.js +3 -3
  7. package/dist/custom-elements-runtime.cjs.js.map +1 -1
  8. package/dist/custom-elements-runtime.dom-jit-css.cjs.js +7 -0
  9. package/dist/custom-elements-runtime.dom-jit-css.cjs.js.map +1 -0
  10. package/dist/custom-elements-runtime.dom-jit-css.es.js +136 -0
  11. package/dist/custom-elements-runtime.dom-jit-css.es.js.map +1 -0
  12. package/dist/custom-elements-runtime.es.js +105 -97
  13. package/dist/custom-elements-runtime.es.js.map +1 -1
  14. package/dist/custom-elements-runtime.event-bus.cjs.js +1 -1
  15. package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
  16. package/dist/custom-elements-runtime.event-bus.es.js +62 -46
  17. package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
  18. package/dist/custom-elements-runtime.jit-css.cjs.js +2 -0
  19. package/dist/custom-elements-runtime.jit-css.cjs.js.map +1 -0
  20. package/dist/custom-elements-runtime.jit-css.es.js +37 -0
  21. package/dist/custom-elements-runtime.jit-css.es.js.map +1 -0
  22. package/dist/custom-elements-runtime.router.cjs.js +20 -20
  23. package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
  24. package/dist/custom-elements-runtime.router.es.js +472 -458
  25. package/dist/custom-elements-runtime.router.es.js.map +1 -1
  26. package/dist/custom-elements-runtime.ssr-middleware.cjs.js +2 -0
  27. package/dist/custom-elements-runtime.ssr-middleware.cjs.js.map +1 -0
  28. package/dist/custom-elements-runtime.ssr-middleware.es.js +63 -0
  29. package/dist/custom-elements-runtime.ssr-middleware.es.js.map +1 -0
  30. package/dist/custom-elements-runtime.ssr.cjs.js +3 -1
  31. package/dist/custom-elements-runtime.ssr.cjs.js.map +1 -1
  32. package/dist/custom-elements-runtime.ssr.es.js +137 -24
  33. package/dist/custom-elements-runtime.ssr.es.js.map +1 -1
  34. package/dist/custom-elements-runtime.store.cjs.js +1 -1
  35. package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
  36. package/dist/custom-elements-runtime.store.es.js +21 -16
  37. package/dist/custom-elements-runtime.store.es.js.map +1 -1
  38. package/dist/custom-elements-runtime.transitions.cjs.js +1 -1
  39. package/dist/custom-elements-runtime.transitions.cjs.js.map +1 -1
  40. package/dist/custom-elements-runtime.transitions.es.js +279 -7
  41. package/dist/custom-elements-runtime.transitions.es.js.map +1 -1
  42. package/dist/custom-elements-runtime.vite-plugin.cjs.js +2 -0
  43. package/dist/custom-elements-runtime.vite-plugin.cjs.js.map +1 -0
  44. package/dist/custom-elements-runtime.vite-plugin.es.js +105 -0
  45. package/dist/custom-elements-runtime.vite-plugin.es.js.map +1 -0
  46. package/dist/dom-jit-css.d.ts +66 -0
  47. package/dist/event-bus.d.ts +3 -1
  48. package/dist/hooks-B50HhrHh.cjs +6 -0
  49. package/dist/hooks-B50HhrHh.cjs.map +1 -0
  50. package/dist/hooks-Cze3o-F7.js +1462 -0
  51. package/dist/hooks-Cze3o-F7.js.map +1 -0
  52. package/dist/index.d.ts +6 -3
  53. package/dist/jit-css.d.ts +30 -0
  54. package/dist/namespace-helpers-D4wC2-qA.js +61 -0
  55. package/dist/namespace-helpers-D4wC2-qA.js.map +1 -0
  56. package/dist/namespace-helpers-ckeEOxpR.cjs +2 -0
  57. package/dist/namespace-helpers-ckeEOxpR.cjs.map +1 -0
  58. package/dist/router/matcher.d.ts +14 -0
  59. package/dist/router/types.d.ts +4 -2
  60. package/dist/runtime/component/factory.d.ts +16 -2
  61. package/dist/runtime/css-utils.d.ts +33 -0
  62. package/dist/runtime/discovery-state.d.ts +3 -0
  63. package/dist/runtime/hooks.d.ts +78 -0
  64. package/dist/runtime/hydration.d.ts +33 -0
  65. package/dist/runtime/jit-hooks.d.ts +28 -0
  66. package/dist/runtime/render-bridge.d.ts +37 -0
  67. package/dist/runtime/scheduler.d.ts +3 -4
  68. package/dist/runtime/secure-expression-evaluator.d.ts +0 -1
  69. package/dist/runtime/ssr-context.d.ts +45 -0
  70. package/dist/runtime/style.d.ts +84 -26
  71. package/dist/runtime/template-compiler/lru-cache.d.ts +0 -3
  72. package/dist/runtime/types.d.ts +18 -0
  73. package/dist/runtime/vdom-helpers.d.ts +0 -1
  74. package/dist/runtime/vdom-ssr-dsd.d.ts +58 -0
  75. package/dist/ssr-middleware.d.ts +125 -0
  76. package/dist/ssr.d.ts +120 -16
  77. package/dist/{transitions-DMJXs_tY.js → style-BmyOIMcU.js} +904 -1344
  78. package/dist/style-BmyOIMcU.js.map +1 -0
  79. package/dist/style-D40DsIqJ.cjs +55 -0
  80. package/dist/style-D40DsIqJ.cjs.map +1 -0
  81. package/dist/style.css +1 -1
  82. package/dist/template-compiler-Cshhqxyd.cjs +23 -0
  83. package/dist/template-compiler-Cshhqxyd.cjs.map +1 -0
  84. package/dist/template-compiler-DtpNsqE-.js +3744 -0
  85. package/dist/template-compiler-DtpNsqE-.js.map +1 -0
  86. package/dist/variables.css +1 -1
  87. package/dist/vite-plugin.d.ts +142 -0
  88. package/package.json +60 -6
  89. package/dist/namespace-helpers-Ctd_h7j2.cjs +0 -5
  90. package/dist/namespace-helpers-Ctd_h7j2.cjs.map +0 -1
  91. package/dist/namespace-helpers-DhLBqt-7.js +0 -1009
  92. package/dist/namespace-helpers-DhLBqt-7.js.map +0 -1
  93. package/dist/template-compiler-Bvx02nAT.js +0 -4020
  94. package/dist/template-compiler-Bvx02nAT.js.map +0 -1
  95. package/dist/template-compiler-bj-MFC_Y.cjs +0 -23
  96. package/dist/template-compiler-bj-MFC_Y.cjs.map +0 -1
  97. package/dist/transitions-DMJXs_tY.js.map +0 -1
  98. package/dist/transitions-f4KfN29T.cjs +0 -330
  99. package/dist/transitions-f4KfN29T.cjs.map +0 -1
@@ -0,0 +1,125 @@
1
+ /**
2
+ * SSR middleware helpers for Express, Fastify, Hono, and other Node.js HTTP frameworks.
3
+ *
4
+ * Provides two handler factories that wrap the SSR rendering pipeline and
5
+ * emit a complete HTML document response. Both accept a static VNode **or**
6
+ * a per-request factory function so route-specific data can be threaded into
7
+ * the render tree.
8
+ *
9
+ * @example Express — static VNode
10
+ * ```ts
11
+ * import express from 'express';
12
+ * import { createSSRHandler } from '@jasonshimmy/custom-elements-runtime/ssr-middleware';
13
+ * import { html } from '@jasonshimmy/custom-elements-runtime';
14
+ *
15
+ * const app = express();
16
+ * app.get('/', createSSRHandler(html`<my-app />`, {
17
+ * render: { dsd: true, jit: { extendedColors: true } },
18
+ * }));
19
+ * ```
20
+ *
21
+ * @example Express — per-request factory
22
+ * ```ts
23
+ * app.get('*', createSSRHandler(
24
+ * (req) => html`<my-app url="${req.url}" />`,
25
+ * { render: { dsd: true }, head: '<link rel="stylesheet" href="/app.css">' },
26
+ * ));
27
+ * ```
28
+ *
29
+ * @example Streaming variant
30
+ * ```ts
31
+ * app.get('*', createStreamingSSRHandler(
32
+ * (req) => html`<my-app url="${req.url}" />`,
33
+ * ));
34
+ * ```
35
+ */
36
+ import type { VNode } from './runtime/types';
37
+ import type { RenderOptions } from './runtime/vdom-ssr';
38
+ import type { DSDRenderOptions } from './runtime/vdom-ssr-dsd';
39
+ import type { JITCSSOptions } from './runtime/style';
40
+ /**
41
+ * Minimal request interface compatible with Express, Fastify, Hono, and the
42
+ * raw Node.js `IncomingMessage`. Extend or replace with your framework's
43
+ * request type via the generic parameter on `createSSRHandler`.
44
+ */
45
+ export interface MinimalRequest {
46
+ url?: string;
47
+ method?: string;
48
+ headers?: Record<string, string | string[] | undefined>;
49
+ }
50
+ /**
51
+ * Minimal response interface compatible with Express, Fastify, Hono, and the
52
+ * raw Node.js `ServerResponse`. `write` is optional — handlers fall back to
53
+ * buffering when it is absent.
54
+ */
55
+ export interface MinimalResponse {
56
+ setHeader(name: string, value: string): void;
57
+ write?(chunk: string): boolean | void;
58
+ end(data?: string): void;
59
+ }
60
+ /**
61
+ * Options for {@link createSSRHandler} and {@link createStreamingSSRHandler}.
62
+ */
63
+ export interface SSRMiddlewareOptions {
64
+ /**
65
+ * Render options forwarded to `renderToStringWithJITCSS`.
66
+ * Defaults to `{ dsd: true }` so DSD output is on by default.
67
+ */
68
+ render?: RenderOptions & DSDRenderOptions & {
69
+ jit?: JITCSSOptions;
70
+ };
71
+ /**
72
+ * Additional HTML inserted at the end of the `<head>` tag.
73
+ * Use this to inject `<link>`, `<script>`, `<meta>`, or `<title>` tags.
74
+ */
75
+ head?: string;
76
+ /**
77
+ * When `true` (default), the response is wrapped in a complete
78
+ * `<!DOCTYPE html>` document shell. Set to `false` if you want to
79
+ * assemble the document yourself and only need the rendered fragment.
80
+ */
81
+ document?: boolean;
82
+ }
83
+ /**
84
+ * Create a request handler that SSR-renders a VNode tree and sends the full
85
+ * HTML document as the response.
86
+ *
87
+ * Compatible with Express, Fastify, Hono, and any framework that uses an
88
+ * `(req, res)` handler signature. The generic `Req` parameter lets you use
89
+ * your framework's typed request object.
90
+ *
91
+ * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)
92
+ * factory function that receives the request and returns the VNode to render.
93
+ * @param options - Render and document-shell options.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * app.get('*', createSSRHandler(
98
+ * (req) => html`<my-app url="${req.url}" />`,
99
+ * { render: { dsd: true, jit: { extendedColors: true } } },
100
+ * ));
101
+ * ```
102
+ */
103
+ export declare function createSSRHandler<Req extends MinimalRequest = MinimalRequest>(vnodeOrFactory: VNode | ((req: Req) => VNode | Promise<VNode>), options?: SSRMiddlewareOptions): (req: Req, res: MinimalResponse) => Promise<void>;
104
+ /**
105
+ * Create a request handler that SSR-renders a VNode tree and streams the HTML
106
+ * response using chunked transfer encoding.
107
+ *
108
+ * Each chunk produced by the underlying {@link renderToStream} call is written
109
+ * to the response as it becomes available, minimising Time-to-First-Byte.
110
+ * The document shell preamble (`<!DOCTYPE html>…<body>`) is sent in the first
111
+ * write so the browser can begin parsing immediately.
112
+ *
113
+ * @param vnodeOrFactory - A static {@link VNode} **or** a (possibly async)
114
+ * factory function that receives the request and returns the VNode to render.
115
+ * @param options - Render and document-shell options.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * app.get('*', createStreamingSSRHandler(
120
+ * (req) => html`<my-app url="${req.url}" />`,
121
+ * { render: { dsd: true } },
122
+ * ));
123
+ * ```
124
+ */
125
+ export declare function createStreamingSSRHandler<Req extends MinimalRequest = MinimalRequest>(vnodeOrFactory: VNode | ((req: Req) => VNode | Promise<VNode>), options?: SSRMiddlewareOptions): (req: Req, res: MinimalResponse) => Promise<void>;
package/dist/ssr.d.ts CHANGED
@@ -1,28 +1,132 @@
1
1
  /**
2
- * SSR entrypointsmall re-export so consumers can import SSR-only helpers
3
- * without pulling them into the main client runtime bundle.
2
+ * SSR entry point import from `@jasonshimmy/custom-elements-runtime/ssr`.
4
3
  *
5
- * renderToString accepts an optional second argument to control SSR behavior:
4
+ * Provides four rendering modes:
6
5
  *
7
- * renderToString(vnode, { injectSvgNamespace?: boolean })
6
+ * 1. **renderToString** — baseline HTML serialisation (no shadow DOM content).
7
+ * Backwards-compatible with the original API.
8
8
  *
9
- * - injectSvgNamespace (default: true): when true, the SSR renderer will
10
- * inject the standard SVG namespace attribute (xmlns="http://www.w3.org/2000/svg")
11
- * onto `<svg>` elements that do not already provide an explicit `xmlns`.
12
- * This matches the client runtime behavior (createElementNS) and avoids
13
- * hydration/namespace mismatches. Set to `false` to opt out and keep SSR
14
- * output minimal.
9
+ * 2. **renderToStringWithJITCSS** HTML + pre-generated JIT CSS injected into
10
+ * `<head>` to prevent FOUC. Supports `dsd: true` for DSD output.
15
11
  *
16
- * Examples
12
+ * 3. **renderToStringWithJITCSSDSD** — convenience alias for DSD mode.
13
+ * Full Declarative Shadow DOM output with per-shadow-root CSS layer stack
14
+ * (baseReset + useStyle() + JIT CSS). Enables true hydration, zero FOUC.
17
15
  *
18
- * // Default (injects xmlns for <svg> if missing)
19
- * import { renderToString } from '@jasonshimmy/custom-elements-runtime/ssr';
20
- * const html = renderToString(vnodeTree);
16
+ * 4. **renderToStream** ReadableStream variant for streaming SSR.
21
17
  *
22
- * // Opt-out
23
- * const htmlNoNs = renderToString(vnodeTree, { injectSvgNamespace: false });
18
+ * Entity map utilities are also exported for full HTML5 named-entity support.
19
+ *
20
+ * @example DSD usage (recommended)
21
+ * ```ts
22
+ * import { renderToStringWithJITCSSDSD } from '@jasonshimmy/custom-elements-runtime/ssr';
23
+ *
24
+ * const { htmlWithStyles } = renderToStringWithJITCSSDSD(appVNode, {
25
+ * jit: { extendedColors: true },
26
+ * });
27
+ * res.send(`<!DOCTYPE html><html><head>${head}</head><body>${htmlWithStyles}</body></html>`);
28
+ * ```
24
29
  */
25
30
  export { renderToString } from './runtime/vdom-ssr';
26
31
  export type { VNode } from './runtime/types';
27
32
  export type { RenderOptions } from './runtime/vdom-ssr';
28
33
  export { registerEntityMap, loadEntityMap, clearRegisteredEntityMap, } from './runtime/helpers';
34
+ export { renderToStringDSD, DSD_POLYFILL_SCRIPT, } from './runtime/vdom-ssr-dsd';
35
+ export type { DSDRenderOptions } from './runtime/vdom-ssr-dsd';
36
+ import { type JITCSSOptions } from './runtime/style';
37
+ import type { VNode } from './runtime/types';
38
+ import type { RenderOptions } from './runtime/vdom-ssr';
39
+ import type { DSDRenderOptions } from './runtime/vdom-ssr-dsd';
40
+ /**
41
+ * Result of `renderToStringWithJITCSS()` and `renderToStringWithJITCSSDSD()`.
42
+ */
43
+ export interface SSRJITResult {
44
+ /** The rendered HTML string (styles not yet injected). */
45
+ html: string;
46
+ /**
47
+ * Global JIT CSS extracted from the rendered HTML.
48
+ * For DSD renders, each shadow root embeds its own scoped styles; this field
49
+ * holds any residual light-DOM utility CSS.
50
+ */
51
+ css: string;
52
+ /**
53
+ * CSS captured from `useGlobalStyle()` calls during this render pass
54
+ * (e.g. `@font-face`, `:root` custom properties).
55
+ * Inject in a `<style id="cer-ssr-global">` in `<head>`.
56
+ */
57
+ globalStyles: string;
58
+ /**
59
+ * Convenience: `html` with both `<style>` tags injected before `</head>`.
60
+ * If no `</head>` is found, the styles are prepended.
61
+ */
62
+ htmlWithStyles: string;
63
+ }
64
+ /**
65
+ * Server-side render a VNode tree and simultaneously pre-generate JIT CSS.
66
+ *
67
+ * Pass `dsd: true` to enable Declarative Shadow DOM output with full per-shadow-
68
+ * root CSS layer extraction (recommended for new apps).
69
+ *
70
+ * @example Standard (no DSD)
71
+ * ```ts
72
+ * const { htmlWithStyles } = renderToStringWithJITCSS(appVNode);
73
+ * ```
74
+ *
75
+ * @example With DSD
76
+ * ```ts
77
+ * const { htmlWithStyles } = renderToStringWithJITCSS(appVNode, {
78
+ * dsd: true,
79
+ * jit: { extendedColors: true },
80
+ * });
81
+ * ```
82
+ */
83
+ export declare function renderToStringWithJITCSS(vnode: VNode, options?: RenderOptions & DSDRenderOptions & {
84
+ jit?: JITCSSOptions;
85
+ }): SSRJITResult;
86
+ /**
87
+ * Convenience alias: `renderToStringWithJITCSS(vnode, { dsd: true, ...options })`.
88
+ *
89
+ * Renders with Declarative Shadow DOM output, full per-shadow-root CSS layer
90
+ * extraction, and the DSD browser polyfill. This is the recommended function
91
+ * for all new server-rendered applications.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { renderToStringWithJITCSSDSD } from '@jasonshimmy/custom-elements-runtime/ssr';
96
+ *
97
+ * const { htmlWithStyles } = renderToStringWithJITCSSDSD(appVNode, {
98
+ * jit: { extendedColors: true },
99
+ * });
100
+ * ```
101
+ */
102
+ export declare function renderToStringWithJITCSSDSD(vnode: VNode, options?: Omit<RenderOptions & DSDRenderOptions & {
103
+ jit?: JITCSSOptions;
104
+ }, 'dsd'>): SSRJITResult;
105
+ /**
106
+ * Render a VNode tree to a `ReadableStream<string>`.
107
+ *
108
+ * The current implementation flushes the complete rendered output as a single
109
+ * chunk, providing the streaming API surface for framework adapters. True
110
+ * incremental streaming (flush shell immediately, resolve async components
111
+ * progressively) is planned for a future release.
112
+ *
113
+ * @example Node.js
114
+ * ```ts
115
+ * import { renderToStream } from '@jasonshimmy/custom-elements-runtime/ssr';
116
+ *
117
+ * app.get('/', (req, res) => {
118
+ * const stream = renderToStream(appVNode, { dsd: true });
119
+ * const reader = stream.getReader();
120
+ * const pump = () =>
121
+ * reader.read().then(({ value, done }) => {
122
+ * if (done) { res.end(); return; }
123
+ * res.write(value);
124
+ * pump();
125
+ * });
126
+ * pump();
127
+ * });
128
+ * ```
129
+ */
130
+ export declare function renderToStream(vnode: VNode, options?: RenderOptions & DSDRenderOptions & {
131
+ jit?: JITCSSOptions;
132
+ }): ReadableStream<string>;