sibujs 1.2.0 → 1.4.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 (95) hide show
  1. package/README.md +29 -25
  2. package/dist/browser.cjs +804 -2
  3. package/dist/browser.d.cts +591 -1
  4. package/dist/browser.d.ts +591 -1
  5. package/dist/browser.js +50 -8
  6. package/dist/build.cjs +655 -237
  7. package/dist/build.js +15 -93
  8. package/dist/cdn.global.js +188 -7
  9. package/dist/chunk-2BYQDGN3.js +742 -0
  10. package/dist/chunk-32DY64NT.js +282 -0
  11. package/dist/chunk-3AIRKM3B.js +1263 -0
  12. package/dist/chunk-3X2YG6YM.js +505 -0
  13. package/dist/chunk-5X6PP2UK.js +28 -0
  14. package/dist/chunk-77L6NL3X.js +1097 -0
  15. package/dist/chunk-BGN5ZMP4.js +26 -0
  16. package/dist/chunk-BTU3TJDS.js +365 -0
  17. package/dist/chunk-CHF5OHIA.js +61 -0
  18. package/dist/chunk-CMBFNA7L.js +27 -0
  19. package/dist/chunk-CNZ35WI2.js +178 -0
  20. package/dist/chunk-DAHRH4ON.js +331 -0
  21. package/dist/chunk-EBGIRKQY.js +616 -0
  22. package/dist/chunk-EUZND3CB.js +27 -0
  23. package/dist/chunk-F3FA4F32.js +292 -0
  24. package/dist/chunk-JAKHTMQU.js +1000 -0
  25. package/dist/chunk-JCI5M6U6.js +956 -0
  26. package/dist/chunk-KQPDEVVS.js +398 -0
  27. package/dist/chunk-M4NLBH4I.js +725 -0
  28. package/dist/chunk-NEKUBFPT.js +60 -0
  29. package/dist/chunk-NYVAC6P5.js +37 -0
  30. package/dist/chunk-PTQJDMRT.js +146 -0
  31. package/dist/chunk-QWZG56ET.js +2744 -0
  32. package/dist/chunk-TSOKIX5Z.js +654 -0
  33. package/dist/chunk-UHNL42EF.js +2730 -0
  34. package/dist/chunk-VRW3FULF.js +725 -0
  35. package/dist/chunk-WZSPOOER.js +84 -0
  36. package/dist/chunk-YT6HQ6AM.js +14 -0
  37. package/dist/chunk-ZD6OAMTH.js +277 -0
  38. package/dist/chunk-ZWKZCBO6.js +317 -0
  39. package/dist/contracts-DDrwxvJ-.d.cts +245 -0
  40. package/dist/contracts-DDrwxvJ-.d.ts +245 -0
  41. package/dist/contracts-xo5ckdRP.d.cts +240 -0
  42. package/dist/contracts-xo5ckdRP.d.ts +240 -0
  43. package/dist/data.cjs +35 -2
  44. package/dist/data.d.cts +7 -0
  45. package/dist/data.d.ts +7 -0
  46. package/dist/data.js +9 -8
  47. package/dist/devtools.cjs +122 -0
  48. package/dist/devtools.d.cts +69 -461
  49. package/dist/devtools.d.ts +69 -461
  50. package/dist/devtools.js +127 -6
  51. package/dist/ecosystem.cjs +23 -6
  52. package/dist/ecosystem.d.cts +1 -1
  53. package/dist/ecosystem.d.ts +1 -1
  54. package/dist/ecosystem.js +10 -9
  55. package/dist/extras.cjs +1208 -88
  56. package/dist/extras.d.cts +6 -6
  57. package/dist/extras.d.ts +6 -6
  58. package/dist/extras.js +70 -33
  59. package/dist/index.cjs +663 -158
  60. package/dist/index.d.cts +398 -40
  61. package/dist/index.d.ts +398 -40
  62. package/dist/index.js +39 -21
  63. package/dist/introspect-BumjnBKr.d.cts +477 -0
  64. package/dist/introspect-CZrlcaYy.d.ts +477 -0
  65. package/dist/introspect-Cb0zgpi2.d.cts +477 -0
  66. package/dist/introspect-Y2xNXGSf.d.ts +477 -0
  67. package/dist/motion.js +4 -4
  68. package/dist/patterns.cjs +51 -24
  69. package/dist/patterns.d.cts +19 -57
  70. package/dist/patterns.d.ts +19 -57
  71. package/dist/patterns.js +8 -16
  72. package/dist/performance.js +4 -4
  73. package/dist/plugins.cjs +429 -82
  74. package/dist/plugins.d.cts +27 -4
  75. package/dist/plugins.d.ts +27 -4
  76. package/dist/plugins.js +156 -37
  77. package/dist/ssr-4PBXAOO3.js +40 -0
  78. package/dist/ssr-Do_SiVoL.d.cts +201 -0
  79. package/dist/ssr-Do_SiVoL.d.ts +201 -0
  80. package/dist/ssr.cjs +312 -60
  81. package/dist/ssr.d.cts +10 -1
  82. package/dist/ssr.d.ts +10 -1
  83. package/dist/ssr.js +13 -10
  84. package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
  85. package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
  86. package/dist/testing.cjs +233 -2
  87. package/dist/testing.d.cts +42 -1
  88. package/dist/testing.d.ts +42 -1
  89. package/dist/testing.js +129 -2
  90. package/dist/ui.cjs +374 -8
  91. package/dist/ui.d.cts +252 -2
  92. package/dist/ui.d.ts +252 -2
  93. package/dist/ui.js +329 -11
  94. package/dist/widgets.js +7 -7
  95. package/package.json +1 -1
@@ -0,0 +1,505 @@
1
+ import {
2
+ sanitizeUrl
3
+ } from "./chunk-CMBFNA7L.js";
4
+ import {
5
+ isDev
6
+ } from "./chunk-5X6PP2UK.js";
7
+
8
+ // src/platform/ssr.ts
9
+ var _isDev = isDev();
10
+ var SAFE_ATTR_NAME = /^[A-Za-z_:][-A-Za-z0-9_.:]*$/;
11
+ function isSafeAttrName(name) {
12
+ return SAFE_ATTR_NAME.test(name);
13
+ }
14
+ function isEventHandlerAttr(name) {
15
+ if (name.length < 3) return false;
16
+ const lower = name.toLowerCase();
17
+ return lower[0] === "o" && lower[1] === "n" && lower.charCodeAt(2) >= 97 && lower.charCodeAt(2) <= 122;
18
+ }
19
+ var URL_ATTRS = /* @__PURE__ */ new Set([
20
+ "href",
21
+ "src",
22
+ "action",
23
+ "formaction",
24
+ "cite",
25
+ "poster",
26
+ "background",
27
+ "srcset",
28
+ "ping",
29
+ "manifest",
30
+ "data",
31
+ "xlink:href"
32
+ ]);
33
+ function ssrErrorComment(err) {
34
+ if (_isDev) {
35
+ const msg = escapeHtml(err instanceof Error ? err.message : String(err));
36
+ return `<!--SSR error: ${safeCommentText(msg)}-->`;
37
+ }
38
+ return "<!--SSR error-->";
39
+ }
40
+ function safeCommentText(text) {
41
+ return text.replace(/-->/g, "--&gt;").replace(/--!>/g, "--!&gt;").replace(/<!--/g, "&lt;!--").replace(/--$/g, "--&#45;");
42
+ }
43
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
44
+ "area",
45
+ "base",
46
+ "br",
47
+ "col",
48
+ "embed",
49
+ "hr",
50
+ "img",
51
+ "input",
52
+ "link",
53
+ "meta",
54
+ "param",
55
+ "source",
56
+ "track",
57
+ "wbr"
58
+ ]);
59
+ function renderToString(element) {
60
+ if (element instanceof DocumentFragment) {
61
+ return Array.from(element.childNodes).map((child) => {
62
+ try {
63
+ return renderToString(child);
64
+ } catch (err) {
65
+ return ssrErrorComment(err);
66
+ }
67
+ }).join("");
68
+ }
69
+ if (element.nodeType === 3) {
70
+ return escapeHtml(element.textContent || "");
71
+ }
72
+ if (element.nodeType === 8) {
73
+ return `<!--${safeCommentText(element.textContent || "")}-->`;
74
+ }
75
+ if (!(element instanceof HTMLElement)) {
76
+ return escapeHtml(element.textContent || "");
77
+ }
78
+ const tag = element.tagName.toLowerCase();
79
+ if (tag === "script" || tag === "style") {
80
+ return _isDev ? `<!--ssr:${tag}-stripped-->` : "";
81
+ }
82
+ if (!/^[a-z][a-z0-9-]*$/i.test(tag)) {
83
+ return _isDev ? "<!--ssr:invalid-tag-->" : "";
84
+ }
85
+ let html = `<${tag}`;
86
+ for (const attr of Array.from(element.attributes)) {
87
+ const rawName = attr.name;
88
+ if (!isSafeAttrName(rawName)) continue;
89
+ if (isEventHandlerAttr(rawName)) continue;
90
+ const lowerName = rawName.toLowerCase();
91
+ let value = attr.value;
92
+ if (URL_ATTRS.has(lowerName)) {
93
+ value = sanitizeUrl(value);
94
+ if (!value) continue;
95
+ }
96
+ html += ` ${rawName}="${escapeAttr(value)}"`;
97
+ }
98
+ if (element.dataset && !element.dataset.sibuHydrate) {
99
+ html += ` data-sibu-ssr="true"`;
100
+ }
101
+ if (VOID_ELEMENTS.has(tag)) {
102
+ return `${html} />`;
103
+ }
104
+ html += ">";
105
+ for (const child of Array.from(element.childNodes)) {
106
+ try {
107
+ html += renderToString(child);
108
+ } catch (err) {
109
+ html += ssrErrorComment(err);
110
+ }
111
+ }
112
+ html += `</${tag}>`;
113
+ return html;
114
+ }
115
+ function hydrate(component, container, options = {}) {
116
+ const clientTree = component();
117
+ if (options.diagnostics) {
118
+ const mismatches = [];
119
+ collectMismatches(container.firstElementChild, clientTree, "", mismatches);
120
+ if (mismatches.length > 0) {
121
+ const first = mismatches[0];
122
+ if (options.onMismatch) {
123
+ options.onMismatch(first);
124
+ } else if (_isDev) {
125
+ console.warn(
126
+ `[Sibu hydration] ${first.message}
127
+ at ${first.path}
128
+ server: ${first.serverValue}
129
+ client: ${first.clientValue}`
130
+ );
131
+ }
132
+ }
133
+ }
134
+ hydrateNode(container.firstElementChild, clientTree);
135
+ container.setAttribute("data-sibu-hydrated", "true");
136
+ }
137
+ function hydrateNode(serverNode, clientNode) {
138
+ if (!serverNode) return;
139
+ const serverChildren = Array.from(serverNode.children);
140
+ const clientChildren = Array.from(clientNode.children);
141
+ for (let i = 0; i < Math.min(serverChildren.length, clientChildren.length); i++) {
142
+ hydrateNode(serverChildren[i], clientChildren[i]);
143
+ }
144
+ }
145
+ function collectMismatches(serverNode, clientNode, path, out, max = 5) {
146
+ if (out.length >= max) return;
147
+ const nodePath = path || clientNode?.tagName?.toLowerCase() || "(root)";
148
+ if (!serverNode && clientNode) {
149
+ out.push({
150
+ kind: "child-count",
151
+ path: nodePath,
152
+ serverValue: "(missing)",
153
+ clientValue: clientNode.tagName.toLowerCase(),
154
+ message: "Client rendered a node that the server did not emit."
155
+ });
156
+ return;
157
+ }
158
+ if (serverNode && !clientNode) {
159
+ out.push({
160
+ kind: "child-count",
161
+ path: nodePath,
162
+ serverValue: serverNode.tagName.toLowerCase(),
163
+ clientValue: "(missing)",
164
+ message: "Server rendered a node that the client did not produce."
165
+ });
166
+ return;
167
+ }
168
+ if (!serverNode || !clientNode) return;
169
+ if (serverNode.tagName !== clientNode.tagName) {
170
+ out.push({
171
+ kind: "tag",
172
+ path: nodePath,
173
+ serverValue: serverNode.tagName.toLowerCase(),
174
+ clientValue: clientNode.tagName.toLowerCase(),
175
+ message: "Element tag mismatch \u2014 server and client disagree on the element type."
176
+ });
177
+ return;
178
+ }
179
+ const skipAttrs = /* @__PURE__ */ new Set(["data-sibu-ssr", "data-sibu-hydrated", "data-sibu-island"]);
180
+ const serverAttrs = /* @__PURE__ */ new Map();
181
+ for (const a of Array.from(serverNode.attributes)) {
182
+ if (!skipAttrs.has(a.name)) serverAttrs.set(a.name, a.value);
183
+ }
184
+ const clientAttrs = /* @__PURE__ */ new Map();
185
+ for (const a of Array.from(clientNode.attributes)) {
186
+ if (!skipAttrs.has(a.name)) clientAttrs.set(a.name, a.value);
187
+ }
188
+ for (const [name, value] of serverAttrs) {
189
+ if (out.length >= max) return;
190
+ if (!clientAttrs.has(name)) {
191
+ out.push({
192
+ kind: "attribute",
193
+ path: `${nodePath}[${name}]`,
194
+ serverValue: value,
195
+ clientValue: "(missing)",
196
+ message: `Attribute "${name}" present on server but missing on client.`
197
+ });
198
+ } else if (clientAttrs.get(name) !== value) {
199
+ out.push({
200
+ kind: "attribute",
201
+ path: `${nodePath}[${name}]`,
202
+ serverValue: value,
203
+ clientValue: clientAttrs.get(name) ?? "",
204
+ message: `Attribute "${name}" differs between server and client.`
205
+ });
206
+ }
207
+ }
208
+ for (const [name, value] of clientAttrs) {
209
+ if (out.length >= max) return;
210
+ if (!serverAttrs.has(name)) {
211
+ out.push({
212
+ kind: "attribute",
213
+ path: `${nodePath}[${name}]`,
214
+ serverValue: "(missing)",
215
+ clientValue: value,
216
+ message: `Attribute "${name}" present on client but missing on server.`
217
+ });
218
+ }
219
+ }
220
+ const serverChildren = Array.from(serverNode.children);
221
+ const clientChildren = Array.from(clientNode.children);
222
+ const max2 = Math.max(serverChildren.length, clientChildren.length);
223
+ for (let i = 0; i < max2; i++) {
224
+ if (out.length >= max) return;
225
+ const childPath = `${nodePath} > ${clientChildren[i]?.tagName?.toLowerCase() ?? serverChildren[i]?.tagName?.toLowerCase() ?? "?"}:nth-child(${i + 1})`;
226
+ collectMismatches(serverChildren[i] ?? null, clientChildren[i] ?? null, childPath, out, max);
227
+ }
228
+ }
229
+ function trustHTML(html) {
230
+ return html;
231
+ }
232
+ function buildAttrString(attrs, { allowEventHandlers = false } = {}) {
233
+ if (!attrs) return "";
234
+ const out = [];
235
+ for (const rawKey of Object.keys(attrs)) {
236
+ if (!Object.hasOwn(attrs, rawKey)) continue;
237
+ if (!isSafeAttrName(rawKey)) continue;
238
+ if (!allowEventHandlers && isEventHandlerAttr(rawKey)) continue;
239
+ const lowerKey = rawKey.toLowerCase();
240
+ let value = String(attrs[rawKey]);
241
+ if (URL_ATTRS.has(lowerKey)) {
242
+ value = sanitizeUrl(value);
243
+ if (!value) continue;
244
+ }
245
+ out.push(`${rawKey}="${escapeAttr(value)}"`);
246
+ }
247
+ return out.join(" ");
248
+ }
249
+ function isDangerousMetaRefresh(metaProps) {
250
+ const httpEquiv = metaProps["http-equiv"];
251
+ if (typeof httpEquiv !== "string") return false;
252
+ if (httpEquiv.toLowerCase() !== "refresh") return false;
253
+ const content = metaProps.content;
254
+ if (typeof content !== "string") return false;
255
+ const normalized = content.replace(/[\x00-\x20\x7f-\x9f]+/g, "").toLowerCase();
256
+ return normalized.includes("url=javascript:") || normalized.includes("url=data:") || normalized.includes("url=vbscript:") || normalized.includes("url=blob:");
257
+ }
258
+ function renderToDocument(component, options = {}) {
259
+ let content;
260
+ try {
261
+ content = renderToString(component());
262
+ } catch (err) {
263
+ content = ssrErrorComment(err);
264
+ }
265
+ const metaTags = (options.meta || []).map((attrs) => {
266
+ if (isDangerousMetaRefresh(attrs)) return "";
267
+ const pairs = buildAttrString(attrs);
268
+ return pairs ? `<meta ${pairs} />` : "";
269
+ }).filter(Boolean).join("\n ");
270
+ const linkTags = (options.links || []).map((attrs) => {
271
+ const pairs = buildAttrString(attrs);
272
+ return pairs ? `<link ${pairs} />` : "";
273
+ }).filter(Boolean).join("\n ");
274
+ const scriptTags = (options.scripts || []).map((src) => {
275
+ const safe = sanitizeUrl(String(src));
276
+ if (!safe) return "";
277
+ return `<script src="${escapeAttr(safe)}"></script>`;
278
+ }).filter(Boolean).join("\n ");
279
+ const bodyAttrPairs = buildAttrString(options.bodyAttrs);
280
+ const bodyAttrs = bodyAttrPairs ? ` ${bodyAttrPairs}` : "";
281
+ return `<!DOCTYPE html>
282
+ <html>
283
+ <head>
284
+ <meta charset="UTF-8" />
285
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
286
+ ${options.title ? `<title>${escapeHtml(options.title)}</title>` : ""}
287
+ ${metaTags}
288
+ ${linkTags}
289
+ ${options.headExtra || ""}
290
+ </head>
291
+ <body${bodyAttrs}>
292
+ <div id="app">${content}</div>
293
+ ${scriptTags}
294
+ </body>
295
+ </html>`;
296
+ }
297
+ async function* renderToStream(element) {
298
+ if (element instanceof DocumentFragment) {
299
+ for (const child of Array.from(element.childNodes)) {
300
+ try {
301
+ yield* renderToStream(child);
302
+ } catch (err) {
303
+ yield ssrErrorComment(err);
304
+ }
305
+ }
306
+ return;
307
+ }
308
+ if (element.nodeType === 3) {
309
+ yield escapeHtml(element.textContent || "");
310
+ return;
311
+ }
312
+ if (element.nodeType === 8) {
313
+ yield `<!--${safeCommentText(element.textContent || "")}-->`;
314
+ return;
315
+ }
316
+ if (!(element instanceof HTMLElement)) {
317
+ yield escapeHtml(element.textContent || "");
318
+ return;
319
+ }
320
+ const tag = element.tagName.toLowerCase();
321
+ if (tag === "script" || tag === "style") {
322
+ if (_isDev) yield `<!--ssr:${tag}-stripped-->`;
323
+ return;
324
+ }
325
+ if (!/^[a-z][a-z0-9-]*$/i.test(tag)) {
326
+ if (_isDev) yield "<!--ssr:invalid-tag-->";
327
+ return;
328
+ }
329
+ let openTag = `<${tag}`;
330
+ for (const attr of Array.from(element.attributes)) {
331
+ const rawName = attr.name;
332
+ if (!isSafeAttrName(rawName)) continue;
333
+ if (isEventHandlerAttr(rawName)) continue;
334
+ const lowerName = rawName.toLowerCase();
335
+ let value = attr.value;
336
+ if (URL_ATTRS.has(lowerName)) {
337
+ value = sanitizeUrl(value);
338
+ if (!value) continue;
339
+ }
340
+ openTag += ` ${rawName}="${escapeAttr(value)}"`;
341
+ }
342
+ if (VOID_ELEMENTS.has(tag)) {
343
+ yield `${openTag} />`;
344
+ return;
345
+ }
346
+ yield `${openTag}>`;
347
+ for (const child of Array.from(element.childNodes)) {
348
+ try {
349
+ yield* renderToStream(child);
350
+ } catch (err) {
351
+ yield ssrErrorComment(err);
352
+ }
353
+ }
354
+ yield `</${tag}>`;
355
+ }
356
+ async function collectStream(stream) {
357
+ let result = "";
358
+ for await (const chunk of stream) {
359
+ result += chunk;
360
+ }
361
+ return result;
362
+ }
363
+ function renderToReadableStream(element) {
364
+ const generator = renderToStream(element);
365
+ return new ReadableStream({
366
+ async pull(controller) {
367
+ const { value, done } = await generator.next();
368
+ if (done) {
369
+ controller.close();
370
+ } else {
371
+ controller.enqueue(value);
372
+ }
373
+ },
374
+ cancel() {
375
+ generator.return(void 0);
376
+ }
377
+ });
378
+ }
379
+ function island(id, component) {
380
+ const el = component();
381
+ el.setAttribute("data-sibu-island", id);
382
+ return el;
383
+ }
384
+ function hydrateIslands(container, islands) {
385
+ const markers = container.querySelectorAll("[data-sibu-island]");
386
+ for (const marker of Array.from(markers)) {
387
+ const id = marker.getAttribute("data-sibu-island") ?? "";
388
+ if (!Object.hasOwn(islands, id)) continue;
389
+ const factory = islands[id];
390
+ if (typeof factory !== "function") continue;
391
+ const clientTree = factory();
392
+ hydrateNode(marker, clientTree);
393
+ marker.setAttribute("data-sibu-hydrated", "true");
394
+ }
395
+ container.setAttribute("data-sibu-hydrated", "partial");
396
+ }
397
+ function hydrateProgressively(container, islands, options) {
398
+ const markers = container.querySelectorAll("[data-sibu-island]");
399
+ const cleanups = [];
400
+ for (const marker of Array.from(markers)) {
401
+ const id = marker.getAttribute("data-sibu-island") ?? "";
402
+ if (!Object.hasOwn(islands, id)) continue;
403
+ const factory = islands[id];
404
+ if (typeof factory !== "function") continue;
405
+ const observer = new IntersectionObserver(
406
+ (entries) => {
407
+ for (const entry of entries) {
408
+ if (entry.isIntersecting) {
409
+ const clientTree = factory();
410
+ hydrateNode(marker, clientTree);
411
+ marker.setAttribute("data-sibu-hydrated", "true");
412
+ observer.disconnect();
413
+ break;
414
+ }
415
+ }
416
+ },
417
+ { rootMargin: "200px", ...options }
418
+ );
419
+ observer.observe(marker);
420
+ cleanups.push(() => observer.disconnect());
421
+ }
422
+ container.setAttribute("data-sibu-hydrated", "progressive");
423
+ return () => {
424
+ for (const cleanup of cleanups) cleanup();
425
+ };
426
+ }
427
+ var suspenseIdCounter = 0;
428
+ function resetSSRState() {
429
+ suspenseIdCounter = 0;
430
+ }
431
+ function ssrSuspense(props) {
432
+ const id = `sibu-sus-${suspenseIdCounter++}`;
433
+ const fallbackEl = props.fallback();
434
+ const wrapper = document.createElement("div");
435
+ wrapper.setAttribute("data-sibu-suspense-id", id);
436
+ wrapper.appendChild(fallbackEl);
437
+ const promise = props.content().then((resolvedEl) => ({
438
+ id,
439
+ html: renderToString(resolvedEl)
440
+ }));
441
+ return { element: wrapper, promise };
442
+ }
443
+ var SAFE_SUSPENSE_ID = /^[A-Za-z0-9_-]+$/;
444
+ function suspenseSwapScript(id, nonce) {
445
+ if (!SAFE_SUSPENSE_ID.test(id)) {
446
+ throw new Error(
447
+ `[SibuJS SSR] suspenseSwapScript: id must match [A-Za-z0-9_-]+ (got: ${JSON.stringify(id.slice(0, 32))})`
448
+ );
449
+ }
450
+ const nonceAttr = nonce ? ` nonce="${escapeAttr(nonce)}"` : "";
451
+ return `<script${nonceAttr}>(function(){var t=document.getElementById("sibu-resolved-${id}");var f=document.querySelector('[data-sibu-suspense-id="${id}"]');if(t&&f){while(t.firstChild)f.appendChild(t.firstChild);t.remove();f.removeAttribute("data-sibu-suspense-id");}})()</script>`;
452
+ }
453
+ async function* renderToSuspenseStream(element, pendingBoundaries = [], options) {
454
+ yield* renderToStream(element);
455
+ if (pendingBoundaries.length > 0) {
456
+ const resolved = await Promise.all(pendingBoundaries);
457
+ for (const { id, html } of resolved) {
458
+ if (!SAFE_SUSPENSE_ID.test(id)) continue;
459
+ yield `<div hidden id="sibu-resolved-${id}">${html}</div>`;
460
+ yield suspenseSwapScript(id, options?.nonce);
461
+ }
462
+ }
463
+ }
464
+ var SSR_DATA_ATTR = "__SIBU_SSR_DATA__";
465
+ function escapeScriptJson(json) {
466
+ return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
467
+ }
468
+ function serializeState(state, nonce) {
469
+ const json = escapeScriptJson(JSON.stringify(state));
470
+ const nonceAttr = nonce ? ` nonce="${escapeAttr(nonce)}"` : "";
471
+ return `<script${nonceAttr}>window.${SSR_DATA_ATTR}=${json}</script>`;
472
+ }
473
+ function deserializeState(validate) {
474
+ if (typeof window === "undefined") return void 0;
475
+ const raw = window[SSR_DATA_ATTR];
476
+ if (raw === void 0) return void 0;
477
+ if (validate && !validate(raw)) return void 0;
478
+ return raw;
479
+ }
480
+ function escapeHtml(str) {
481
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
482
+ }
483
+ function escapeAttr(str) {
484
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
485
+ }
486
+
487
+ export {
488
+ renderToString,
489
+ hydrate,
490
+ trustHTML,
491
+ renderToDocument,
492
+ renderToStream,
493
+ collectStream,
494
+ renderToReadableStream,
495
+ island,
496
+ hydrateIslands,
497
+ hydrateProgressively,
498
+ resetSSRState,
499
+ ssrSuspense,
500
+ suspenseSwapScript,
501
+ renderToSuspenseStream,
502
+ escapeScriptJson,
503
+ serializeState,
504
+ deserializeState
505
+ };
@@ -0,0 +1,28 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/core/dev.ts
8
+ function isDev() {
9
+ return typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : typeof __SIBU_DEV__ !== "undefined" ? __SIBU_DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
10
+ }
11
+ var _isDev = isDev();
12
+ function devAssert(condition, message) {
13
+ if (_isDev && !condition) {
14
+ throw new Error(`[Sibu] ${message}`);
15
+ }
16
+ }
17
+ function devWarn(message) {
18
+ if (_isDev) {
19
+ console.warn(`[Sibu] ${message}`);
20
+ }
21
+ }
22
+
23
+ export {
24
+ __export,
25
+ isDev,
26
+ devAssert,
27
+ devWarn
28
+ };