sibujs 1.2.0 → 1.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/README.md +29 -25
- package/dist/browser.cjs +804 -2
- package/dist/browser.d.cts +591 -1
- package/dist/browser.d.ts +591 -1
- package/dist/browser.js +50 -8
- package/dist/build.cjs +654 -144
- package/dist/build.js +14 -12
- package/dist/cdn.global.js +188 -7
- package/dist/chunk-2BYQDGN3.js +742 -0
- package/dist/chunk-32DY64NT.js +282 -0
- package/dist/chunk-3AIRKM3B.js +1263 -0
- package/dist/chunk-3X2YG6YM.js +505 -0
- package/dist/chunk-5X6PP2UK.js +28 -0
- package/dist/chunk-77L6NL3X.js +1097 -0
- package/dist/chunk-BGN5ZMP4.js +26 -0
- package/dist/chunk-BTU3TJDS.js +365 -0
- package/dist/chunk-CHF5OHIA.js +61 -0
- package/dist/chunk-CMBFNA7L.js +27 -0
- package/dist/chunk-DAHRH4ON.js +331 -0
- package/dist/chunk-EBGIRKQY.js +616 -0
- package/dist/chunk-EUZND3CB.js +27 -0
- package/dist/chunk-F3FA4F32.js +292 -0
- package/dist/chunk-JAKHTMQU.js +1000 -0
- package/dist/chunk-JCI5M6U6.js +956 -0
- package/dist/chunk-KQPDEVVS.js +398 -0
- package/dist/chunk-NEKUBFPT.js +60 -0
- package/dist/chunk-NYVAC6P5.js +37 -0
- package/dist/chunk-PTQJDMRT.js +146 -0
- package/dist/chunk-QWZG56ET.js +2744 -0
- package/dist/chunk-TSOKIX5Z.js +654 -0
- package/dist/chunk-VRW3FULF.js +725 -0
- package/dist/chunk-WZSPOOER.js +84 -0
- package/dist/chunk-YT6HQ6AM.js +14 -0
- package/dist/chunk-ZD6OAMTH.js +277 -0
- package/dist/contracts-DDrwxvJ-.d.cts +245 -0
- package/dist/contracts-DDrwxvJ-.d.ts +245 -0
- package/dist/data.cjs +35 -2
- package/dist/data.d.cts +7 -0
- package/dist/data.d.ts +7 -0
- package/dist/data.js +9 -8
- package/dist/devtools.cjs +122 -0
- package/dist/devtools.d.cts +69 -461
- package/dist/devtools.d.ts +69 -461
- package/dist/devtools.js +127 -6
- package/dist/ecosystem.cjs +23 -6
- package/dist/ecosystem.d.cts +1 -1
- package/dist/ecosystem.d.ts +1 -1
- package/dist/ecosystem.js +10 -9
- package/dist/extras.cjs +1207 -65
- package/dist/extras.d.cts +5 -5
- package/dist/extras.d.ts +5 -5
- package/dist/extras.js +69 -24
- package/dist/index.cjs +663 -144
- package/dist/index.d.cts +397 -17
- package/dist/index.d.ts +397 -17
- package/dist/index.js +39 -17
- package/dist/introspect-BumjnBKr.d.cts +477 -0
- package/dist/introspect-CZrlcaYy.d.ts +477 -0
- package/dist/introspect-Cb0zgpi2.d.cts +477 -0
- package/dist/introspect-Y2xNXGSf.d.ts +477 -0
- package/dist/motion.js +4 -4
- package/dist/patterns.cjs +51 -2
- package/dist/patterns.d.cts +18 -8
- package/dist/patterns.d.ts +18 -8
- package/dist/patterns.js +7 -7
- package/dist/performance.js +4 -4
- package/dist/plugins.cjs +428 -81
- package/dist/plugins.d.cts +27 -4
- package/dist/plugins.d.ts +27 -4
- package/dist/plugins.js +156 -37
- package/dist/ssr-4PBXAOO3.js +40 -0
- package/dist/ssr-Do_SiVoL.d.cts +201 -0
- package/dist/ssr-Do_SiVoL.d.ts +201 -0
- package/dist/ssr.cjs +312 -60
- package/dist/ssr.d.cts +10 -1
- package/dist/ssr.d.ts +10 -1
- package/dist/ssr.js +13 -10
- package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
- package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
- package/dist/testing.cjs +233 -2
- package/dist/testing.d.cts +42 -1
- package/dist/testing.d.ts +42 -1
- package/dist/testing.js +129 -2
- package/dist/ui.cjs +374 -3
- package/dist/ui.d.cts +252 -2
- package/dist/ui.d.ts +252 -2
- package/dist/ui.js +328 -8
- package/dist/widgets.js +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an HTMLElement tree to an HTML string for server-side rendering.
|
|
3
|
+
*
|
|
4
|
+
* Security: attribute names are validated, `on*` handlers are dropped,
|
|
5
|
+
* URL-bearing attributes are routed through `sanitizeUrl`, and attribute
|
|
6
|
+
* values are escaped against both `"` and `'`. `<script>` and `<style>`
|
|
7
|
+
* tags are stripped from the serialized output.
|
|
8
|
+
*/
|
|
9
|
+
declare function renderToString(element: HTMLElement | DocumentFragment | Node): string;
|
|
10
|
+
interface HydrateOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Enable dev-mode hydration diagnostics. When true, the walker
|
|
13
|
+
* compares the server-rendered tree against the client tree and
|
|
14
|
+
* logs the first tag mismatch, attribute difference, or child count
|
|
15
|
+
* mismatch to the console. Disabled by default.
|
|
16
|
+
*/
|
|
17
|
+
diagnostics?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Called for each detected mismatch instead of the default console
|
|
20
|
+
* warning. Useful for routing diagnostics to a telemetry system.
|
|
21
|
+
*/
|
|
22
|
+
onMismatch?: (report: HydrationMismatch) => void;
|
|
23
|
+
}
|
|
24
|
+
interface HydrationMismatch {
|
|
25
|
+
kind: "tag" | "attribute" | "child-count" | "text";
|
|
26
|
+
path: string;
|
|
27
|
+
serverValue: string;
|
|
28
|
+
clientValue: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Hydrates a server-rendered DOM tree by attaching event listeners
|
|
33
|
+
* and activating reactive bindings.
|
|
34
|
+
*
|
|
35
|
+
* When `options.diagnostics` is true, the walker reports the first
|
|
36
|
+
* server/client mismatch it finds. This is a dev-mode tool — pass
|
|
37
|
+
* `diagnostics: false` (or omit it) in production.
|
|
38
|
+
*/
|
|
39
|
+
declare function hydrate(component: () => HTMLElement, container: HTMLElement, options?: HydrateOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Branded type for raw HTML that has been explicitly marked as trusted.
|
|
42
|
+
* Use `trustHTML()` to create a value of this type. This prevents
|
|
43
|
+
* accidental injection of unsanitized user input into `headExtra`.
|
|
44
|
+
*/
|
|
45
|
+
type TrustedHTML = string & {
|
|
46
|
+
readonly __brand: "TrustedHTML";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Mark an HTML string as trusted for use in contexts that accept raw HTML
|
|
50
|
+
* (e.g. `renderToDocument({ headExtra })`). Only call this on
|
|
51
|
+
* developer-controlled strings — never on user input.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const extra = trustHTML('<link rel="preconnect" href="https://fonts.googleapis.com">');
|
|
56
|
+
* renderToDocument(App, { headExtra: extra });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function trustHTML(html: string): TrustedHTML;
|
|
60
|
+
/**
|
|
61
|
+
* Renders a component to a full HTML document string.
|
|
62
|
+
*
|
|
63
|
+
* `headExtra` requires a `TrustedHTML` value created via `trustHTML()`.
|
|
64
|
+
* This prevents accidental injection of unsanitized user input.
|
|
65
|
+
*
|
|
66
|
+
* Security: meta/link/bodyAttrs keys are validated against
|
|
67
|
+
* `SAFE_ATTR_NAME` (rejecting crafted keys that would break out of the
|
|
68
|
+
* attribute context). URL attributes in meta/link/scripts/bodyAttrs pass
|
|
69
|
+
* through `sanitizeUrl`. The page `title` is HTML-escaped.
|
|
70
|
+
*/
|
|
71
|
+
declare function renderToDocument(component: () => HTMLElement, options?: {
|
|
72
|
+
title?: string;
|
|
73
|
+
meta?: Record<string, string>[];
|
|
74
|
+
links?: Record<string, string>[];
|
|
75
|
+
scripts?: string[];
|
|
76
|
+
bodyAttrs?: Record<string, string>;
|
|
77
|
+
/**
|
|
78
|
+
* Raw HTML injected into `<head>`. Must be wrapped in `trustHTML()`
|
|
79
|
+
* to confirm the content is developer-controlled.
|
|
80
|
+
*/
|
|
81
|
+
headExtra?: TrustedHTML;
|
|
82
|
+
}): string;
|
|
83
|
+
/**
|
|
84
|
+
* Renders a component tree to an async iterable of HTML chunks.
|
|
85
|
+
* Enables progressive server-side rendering — the consumer can write
|
|
86
|
+
* each chunk to a response stream as it becomes available.
|
|
87
|
+
*
|
|
88
|
+
* Same security posture as `renderToString`.
|
|
89
|
+
*/
|
|
90
|
+
declare function renderToStream(element: HTMLElement | DocumentFragment | Node): AsyncGenerator<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Collects the full output of renderToStream into a string.
|
|
93
|
+
*/
|
|
94
|
+
declare function collectStream(stream: AsyncGenerator<string> | AsyncIterable<string>): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Renders a component tree to a Web ReadableStream<string>.
|
|
97
|
+
* Compatible with Node 18+, Deno, and edge runtimes.
|
|
98
|
+
* Uses pull-based backpressure — chunks are produced on demand.
|
|
99
|
+
*/
|
|
100
|
+
declare function renderToReadableStream(element: HTMLElement | DocumentFragment | Node): ReadableStream<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Marks an element as a hydration island. During partial hydration
|
|
103
|
+
* only elements marked with `data-sibu-island` will be hydrated.
|
|
104
|
+
*/
|
|
105
|
+
declare function island(id: string, component: () => HTMLElement): HTMLElement;
|
|
106
|
+
/**
|
|
107
|
+
* Hydrate only elements marked as islands (`data-sibu-island`).
|
|
108
|
+
* Non-island content keeps its server-rendered HTML untouched.
|
|
109
|
+
*
|
|
110
|
+
* Security: uses `hasOwnProperty.call` to guard against prototype-pollution
|
|
111
|
+
* lookups (e.g. an island id of `__proto__` must not resolve to `Object.prototype`).
|
|
112
|
+
*/
|
|
113
|
+
declare function hydrateIslands(container: HTMLElement, islands: Record<string, () => HTMLElement>): void;
|
|
114
|
+
/**
|
|
115
|
+
* Progressively hydrate islands only when they enter the viewport.
|
|
116
|
+
* Uses IntersectionObserver to defer hydration of off-screen islands,
|
|
117
|
+
* reducing initial JavaScript execution cost.
|
|
118
|
+
*
|
|
119
|
+
* Returns a cleanup function that disconnects all observers.
|
|
120
|
+
*/
|
|
121
|
+
declare function hydrateProgressively(container: HTMLElement, islands: Record<string, () => HTMLElement>, options?: IntersectionObserverInit): () => void;
|
|
122
|
+
/**
|
|
123
|
+
* Reset SSR state between requests. Call at the start of each SSR render
|
|
124
|
+
* to prevent ID drift in long-lived server processes.
|
|
125
|
+
*/
|
|
126
|
+
declare function resetSSRState(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Create a suspense boundary for SSR streaming.
|
|
129
|
+
* Renders fallback HTML inline and returns a promise for the resolved content.
|
|
130
|
+
*
|
|
131
|
+
* The returned element contains the fallback UI with a `data-sibu-suspense-id`
|
|
132
|
+
* marker. The promise resolves to `{ id, html }` once async content is ready.
|
|
133
|
+
*/
|
|
134
|
+
declare function ssrSuspense(props: {
|
|
135
|
+
fallback: () => HTMLElement;
|
|
136
|
+
content: () => Promise<HTMLElement>;
|
|
137
|
+
}): {
|
|
138
|
+
element: HTMLElement;
|
|
139
|
+
promise: Promise<{
|
|
140
|
+
id: string;
|
|
141
|
+
html: string;
|
|
142
|
+
}>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Generate an inline script that swaps a suspense fallback with resolved content.
|
|
146
|
+
*
|
|
147
|
+
* Security: the `id` is validated against a strict allowlist. Values that
|
|
148
|
+
* do not match throw, so an attacker-controlled id cannot inject context
|
|
149
|
+
* breakers into the selector or the JS string. `ssrSuspense()`'s internal
|
|
150
|
+
* generator always produces allowlist-safe ids.
|
|
151
|
+
*/
|
|
152
|
+
declare function suspenseSwapScript(id: string, nonce?: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Renders a component tree with suspense boundaries as a stream.
|
|
155
|
+
* Yields the main tree HTML first (including fallback content for suspended
|
|
156
|
+
* boundaries), then flushes resolved content with inline swap scripts.
|
|
157
|
+
*
|
|
158
|
+
* Supports an optional `nonce` that is propagated to the resolved-content
|
|
159
|
+
* swap scripts so the stream works with strict CSP.
|
|
160
|
+
*/
|
|
161
|
+
declare function renderToSuspenseStream(element: HTMLElement | DocumentFragment | Node, pendingBoundaries?: Promise<{
|
|
162
|
+
id: string;
|
|
163
|
+
html: string;
|
|
164
|
+
}>[], options?: {
|
|
165
|
+
nonce?: string;
|
|
166
|
+
}): AsyncGenerator<string>;
|
|
167
|
+
/**
|
|
168
|
+
* Escape a JSON string for safe embedding inside a `<script>` tag. This
|
|
169
|
+
* goes beyond the usual `</script>` concern:
|
|
170
|
+
*
|
|
171
|
+
* - `<`, `>`, `&` are unicode-escaped so nothing inside a string literal
|
|
172
|
+
* can close the script tag or start a new one.
|
|
173
|
+
* - `U+2028` (LINE SEPARATOR) and `U+2029` (PARAGRAPH SEPARATOR) are
|
|
174
|
+
* unicode-escaped. Before ES2019 these were illegal inside a JS string
|
|
175
|
+
* literal, so including them verbatim would cause a SyntaxError on
|
|
176
|
+
* older engines and could break out of string context.
|
|
177
|
+
*/
|
|
178
|
+
declare function escapeScriptJson(json: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Serialize application state into an HTML script tag for SSR.
|
|
181
|
+
* The serialized data is embedded in the document and picked up
|
|
182
|
+
* on the client with `deserializeState()`.
|
|
183
|
+
*
|
|
184
|
+
* Security: the serialized JSON is escaped against `<`/`>`/`&` so nothing
|
|
185
|
+
* can close the `<script>` tag, plus `U+2028` / `U+2029` which otherwise
|
|
186
|
+
* break out of string literals on pre-ES2019 engines. Supports a `nonce`
|
|
187
|
+
* attribute so the script is compatible with strict CSP.
|
|
188
|
+
*/
|
|
189
|
+
declare function serializeState(state: Record<string, unknown>, nonce?: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* Retrieve state that was embedded by `serializeState()` during SSR.
|
|
192
|
+
*
|
|
193
|
+
* When a `validate` function is provided, it acts as a type guard —
|
|
194
|
+
* only data that passes validation is returned. This prevents
|
|
195
|
+
* tampered SSR payloads from being trusted by the client.
|
|
196
|
+
*
|
|
197
|
+
* @param validate Optional type guard to verify data integrity
|
|
198
|
+
*/
|
|
199
|
+
declare function deserializeState<T = Record<string, unknown>>(validate?: (data: unknown) => data is T): T | undefined;
|
|
200
|
+
|
|
201
|
+
export { type HydrateOptions as H, type TrustedHTML as T, type HydrationMismatch as a, hydrateIslands as b, collectStream as c, deserializeState as d, escapeScriptJson as e, hydrateProgressively as f, renderToReadableStream as g, hydrate as h, island as i, renderToStream as j, renderToString as k, renderToSuspenseStream as l, resetSSRState as m, ssrSuspense as n, suspenseSwapScript as o, renderToDocument as r, serializeState as s, trustHTML as t };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an HTMLElement tree to an HTML string for server-side rendering.
|
|
3
|
+
*
|
|
4
|
+
* Security: attribute names are validated, `on*` handlers are dropped,
|
|
5
|
+
* URL-bearing attributes are routed through `sanitizeUrl`, and attribute
|
|
6
|
+
* values are escaped against both `"` and `'`. `<script>` and `<style>`
|
|
7
|
+
* tags are stripped from the serialized output.
|
|
8
|
+
*/
|
|
9
|
+
declare function renderToString(element: HTMLElement | DocumentFragment | Node): string;
|
|
10
|
+
interface HydrateOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Enable dev-mode hydration diagnostics. When true, the walker
|
|
13
|
+
* compares the server-rendered tree against the client tree and
|
|
14
|
+
* logs the first tag mismatch, attribute difference, or child count
|
|
15
|
+
* mismatch to the console. Disabled by default.
|
|
16
|
+
*/
|
|
17
|
+
diagnostics?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Called for each detected mismatch instead of the default console
|
|
20
|
+
* warning. Useful for routing diagnostics to a telemetry system.
|
|
21
|
+
*/
|
|
22
|
+
onMismatch?: (report: HydrationMismatch) => void;
|
|
23
|
+
}
|
|
24
|
+
interface HydrationMismatch {
|
|
25
|
+
kind: "tag" | "attribute" | "child-count" | "text";
|
|
26
|
+
path: string;
|
|
27
|
+
serverValue: string;
|
|
28
|
+
clientValue: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Hydrates a server-rendered DOM tree by attaching event listeners
|
|
33
|
+
* and activating reactive bindings.
|
|
34
|
+
*
|
|
35
|
+
* When `options.diagnostics` is true, the walker reports the first
|
|
36
|
+
* server/client mismatch it finds. This is a dev-mode tool — pass
|
|
37
|
+
* `diagnostics: false` (or omit it) in production.
|
|
38
|
+
*/
|
|
39
|
+
declare function hydrate(component: () => HTMLElement, container: HTMLElement, options?: HydrateOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Branded type for raw HTML that has been explicitly marked as trusted.
|
|
42
|
+
* Use `trustHTML()` to create a value of this type. This prevents
|
|
43
|
+
* accidental injection of unsanitized user input into `headExtra`.
|
|
44
|
+
*/
|
|
45
|
+
type TrustedHTML = string & {
|
|
46
|
+
readonly __brand: "TrustedHTML";
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Mark an HTML string as trusted for use in contexts that accept raw HTML
|
|
50
|
+
* (e.g. `renderToDocument({ headExtra })`). Only call this on
|
|
51
|
+
* developer-controlled strings — never on user input.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const extra = trustHTML('<link rel="preconnect" href="https://fonts.googleapis.com">');
|
|
56
|
+
* renderToDocument(App, { headExtra: extra });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function trustHTML(html: string): TrustedHTML;
|
|
60
|
+
/**
|
|
61
|
+
* Renders a component to a full HTML document string.
|
|
62
|
+
*
|
|
63
|
+
* `headExtra` requires a `TrustedHTML` value created via `trustHTML()`.
|
|
64
|
+
* This prevents accidental injection of unsanitized user input.
|
|
65
|
+
*
|
|
66
|
+
* Security: meta/link/bodyAttrs keys are validated against
|
|
67
|
+
* `SAFE_ATTR_NAME` (rejecting crafted keys that would break out of the
|
|
68
|
+
* attribute context). URL attributes in meta/link/scripts/bodyAttrs pass
|
|
69
|
+
* through `sanitizeUrl`. The page `title` is HTML-escaped.
|
|
70
|
+
*/
|
|
71
|
+
declare function renderToDocument(component: () => HTMLElement, options?: {
|
|
72
|
+
title?: string;
|
|
73
|
+
meta?: Record<string, string>[];
|
|
74
|
+
links?: Record<string, string>[];
|
|
75
|
+
scripts?: string[];
|
|
76
|
+
bodyAttrs?: Record<string, string>;
|
|
77
|
+
/**
|
|
78
|
+
* Raw HTML injected into `<head>`. Must be wrapped in `trustHTML()`
|
|
79
|
+
* to confirm the content is developer-controlled.
|
|
80
|
+
*/
|
|
81
|
+
headExtra?: TrustedHTML;
|
|
82
|
+
}): string;
|
|
83
|
+
/**
|
|
84
|
+
* Renders a component tree to an async iterable of HTML chunks.
|
|
85
|
+
* Enables progressive server-side rendering — the consumer can write
|
|
86
|
+
* each chunk to a response stream as it becomes available.
|
|
87
|
+
*
|
|
88
|
+
* Same security posture as `renderToString`.
|
|
89
|
+
*/
|
|
90
|
+
declare function renderToStream(element: HTMLElement | DocumentFragment | Node): AsyncGenerator<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Collects the full output of renderToStream into a string.
|
|
93
|
+
*/
|
|
94
|
+
declare function collectStream(stream: AsyncGenerator<string> | AsyncIterable<string>): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Renders a component tree to a Web ReadableStream<string>.
|
|
97
|
+
* Compatible with Node 18+, Deno, and edge runtimes.
|
|
98
|
+
* Uses pull-based backpressure — chunks are produced on demand.
|
|
99
|
+
*/
|
|
100
|
+
declare function renderToReadableStream(element: HTMLElement | DocumentFragment | Node): ReadableStream<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Marks an element as a hydration island. During partial hydration
|
|
103
|
+
* only elements marked with `data-sibu-island` will be hydrated.
|
|
104
|
+
*/
|
|
105
|
+
declare function island(id: string, component: () => HTMLElement): HTMLElement;
|
|
106
|
+
/**
|
|
107
|
+
* Hydrate only elements marked as islands (`data-sibu-island`).
|
|
108
|
+
* Non-island content keeps its server-rendered HTML untouched.
|
|
109
|
+
*
|
|
110
|
+
* Security: uses `hasOwnProperty.call` to guard against prototype-pollution
|
|
111
|
+
* lookups (e.g. an island id of `__proto__` must not resolve to `Object.prototype`).
|
|
112
|
+
*/
|
|
113
|
+
declare function hydrateIslands(container: HTMLElement, islands: Record<string, () => HTMLElement>): void;
|
|
114
|
+
/**
|
|
115
|
+
* Progressively hydrate islands only when they enter the viewport.
|
|
116
|
+
* Uses IntersectionObserver to defer hydration of off-screen islands,
|
|
117
|
+
* reducing initial JavaScript execution cost.
|
|
118
|
+
*
|
|
119
|
+
* Returns a cleanup function that disconnects all observers.
|
|
120
|
+
*/
|
|
121
|
+
declare function hydrateProgressively(container: HTMLElement, islands: Record<string, () => HTMLElement>, options?: IntersectionObserverInit): () => void;
|
|
122
|
+
/**
|
|
123
|
+
* Reset SSR state between requests. Call at the start of each SSR render
|
|
124
|
+
* to prevent ID drift in long-lived server processes.
|
|
125
|
+
*/
|
|
126
|
+
declare function resetSSRState(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Create a suspense boundary for SSR streaming.
|
|
129
|
+
* Renders fallback HTML inline and returns a promise for the resolved content.
|
|
130
|
+
*
|
|
131
|
+
* The returned element contains the fallback UI with a `data-sibu-suspense-id`
|
|
132
|
+
* marker. The promise resolves to `{ id, html }` once async content is ready.
|
|
133
|
+
*/
|
|
134
|
+
declare function ssrSuspense(props: {
|
|
135
|
+
fallback: () => HTMLElement;
|
|
136
|
+
content: () => Promise<HTMLElement>;
|
|
137
|
+
}): {
|
|
138
|
+
element: HTMLElement;
|
|
139
|
+
promise: Promise<{
|
|
140
|
+
id: string;
|
|
141
|
+
html: string;
|
|
142
|
+
}>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Generate an inline script that swaps a suspense fallback with resolved content.
|
|
146
|
+
*
|
|
147
|
+
* Security: the `id` is validated against a strict allowlist. Values that
|
|
148
|
+
* do not match throw, so an attacker-controlled id cannot inject context
|
|
149
|
+
* breakers into the selector or the JS string. `ssrSuspense()`'s internal
|
|
150
|
+
* generator always produces allowlist-safe ids.
|
|
151
|
+
*/
|
|
152
|
+
declare function suspenseSwapScript(id: string, nonce?: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Renders a component tree with suspense boundaries as a stream.
|
|
155
|
+
* Yields the main tree HTML first (including fallback content for suspended
|
|
156
|
+
* boundaries), then flushes resolved content with inline swap scripts.
|
|
157
|
+
*
|
|
158
|
+
* Supports an optional `nonce` that is propagated to the resolved-content
|
|
159
|
+
* swap scripts so the stream works with strict CSP.
|
|
160
|
+
*/
|
|
161
|
+
declare function renderToSuspenseStream(element: HTMLElement | DocumentFragment | Node, pendingBoundaries?: Promise<{
|
|
162
|
+
id: string;
|
|
163
|
+
html: string;
|
|
164
|
+
}>[], options?: {
|
|
165
|
+
nonce?: string;
|
|
166
|
+
}): AsyncGenerator<string>;
|
|
167
|
+
/**
|
|
168
|
+
* Escape a JSON string for safe embedding inside a `<script>` tag. This
|
|
169
|
+
* goes beyond the usual `</script>` concern:
|
|
170
|
+
*
|
|
171
|
+
* - `<`, `>`, `&` are unicode-escaped so nothing inside a string literal
|
|
172
|
+
* can close the script tag or start a new one.
|
|
173
|
+
* - `U+2028` (LINE SEPARATOR) and `U+2029` (PARAGRAPH SEPARATOR) are
|
|
174
|
+
* unicode-escaped. Before ES2019 these were illegal inside a JS string
|
|
175
|
+
* literal, so including them verbatim would cause a SyntaxError on
|
|
176
|
+
* older engines and could break out of string context.
|
|
177
|
+
*/
|
|
178
|
+
declare function escapeScriptJson(json: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Serialize application state into an HTML script tag for SSR.
|
|
181
|
+
* The serialized data is embedded in the document and picked up
|
|
182
|
+
* on the client with `deserializeState()`.
|
|
183
|
+
*
|
|
184
|
+
* Security: the serialized JSON is escaped against `<`/`>`/`&` so nothing
|
|
185
|
+
* can close the `<script>` tag, plus `U+2028` / `U+2029` which otherwise
|
|
186
|
+
* break out of string literals on pre-ES2019 engines. Supports a `nonce`
|
|
187
|
+
* attribute so the script is compatible with strict CSP.
|
|
188
|
+
*/
|
|
189
|
+
declare function serializeState(state: Record<string, unknown>, nonce?: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* Retrieve state that was embedded by `serializeState()` during SSR.
|
|
192
|
+
*
|
|
193
|
+
* When a `validate` function is provided, it acts as a type guard —
|
|
194
|
+
* only data that passes validation is returned. This prevents
|
|
195
|
+
* tampered SSR payloads from being trusted by the client.
|
|
196
|
+
*
|
|
197
|
+
* @param validate Optional type guard to verify data integrity
|
|
198
|
+
*/
|
|
199
|
+
declare function deserializeState<T = Record<string, unknown>>(validate?: (data: unknown) => data is T): T | undefined;
|
|
200
|
+
|
|
201
|
+
export { type HydrateOptions as H, type TrustedHTML as T, type HydrationMismatch as a, hydrateIslands as b, collectStream as c, deserializeState as d, escapeScriptJson as e, hydrateProgressively as f, renderToReadableStream as g, hydrate as h, island as i, renderToStream as j, renderToString as k, renderToSuspenseStream as l, resetSSRState as m, ssrSuspense as n, suspenseSwapScript as o, renderToDocument as r, serializeState as s, trustHTML as t };
|