@demiurgejs/core 0.1.1 → 0.2.0-beta.1

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 (88) hide show
  1. package/README.md +3 -0
  2. package/bin/demiurge.mjs +51 -0
  3. package/dist/chunks/request-metadata-DwEO1EAS.js +477 -0
  4. package/dist/chunks/request-metadata-DwEO1EAS.js.map +1 -0
  5. package/dist/chunks/{streaming-DN1DnbRE.js → streaming-Ci6vf3BB.js} +117 -107
  6. package/dist/chunks/streaming-Ci6vf3BB.js.map +1 -0
  7. package/dist/chunks/{testing-DR3eQAvY.js → testing-DBjVCN5v.js} +2384 -1942
  8. package/dist/chunks/testing-DBjVCN5v.js.map +1 -0
  9. package/dist/cli.d.ts +42 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +164 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/document/index.d.ts +2 -2
  14. package/dist/document/index.d.ts.map +1 -1
  15. package/dist/document/render.d.ts +1 -1
  16. package/dist/document/render.d.ts.map +1 -1
  17. package/dist/document/scripts.d.ts +22 -0
  18. package/dist/document/scripts.d.ts.map +1 -1
  19. package/dist/index.d.ts +7 -7
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +817 -969
  22. package/dist/index.js.map +1 -1
  23. package/dist/internal/testing.js +15 -14
  24. package/dist/internal/testing.js.map +1 -1
  25. package/dist/node/index.js +3 -3
  26. package/dist/node/streaming.d.ts +2 -0
  27. package/dist/node/streaming.d.ts.map +1 -1
  28. package/dist/route/action.d.ts +11 -11
  29. package/dist/route/action.d.ts.map +1 -1
  30. package/dist/route/index.d.ts +2 -1
  31. package/dist/route/index.d.ts.map +1 -1
  32. package/dist/route/middleware.d.ts +7 -0
  33. package/dist/route/middleware.d.ts.map +1 -0
  34. package/dist/route/page.d.ts +2 -2
  35. package/dist/route/page.d.ts.map +1 -1
  36. package/dist/route/response.d.ts +19 -19
  37. package/dist/route/response.d.ts.map +1 -1
  38. package/dist/route/types.d.ts +55 -31
  39. package/dist/route/types.d.ts.map +1 -1
  40. package/dist/route/webhook.d.ts +1 -1
  41. package/dist/router/manifest.d.ts +1 -0
  42. package/dist/router/manifest.d.ts.map +1 -1
  43. package/dist/routing/generate.d.ts +2 -0
  44. package/dist/routing/generate.d.ts.map +1 -1
  45. package/dist/routing/index.d.ts +1 -1
  46. package/dist/routing/index.d.ts.map +1 -1
  47. package/dist/routing/types.d.ts +2 -0
  48. package/dist/routing/types.d.ts.map +1 -1
  49. package/dist/security/cors.d.ts.map +1 -1
  50. package/dist/security/index.d.ts +4 -2
  51. package/dist/security/index.d.ts.map +1 -1
  52. package/dist/security/policy.d.ts +31 -2
  53. package/dist/security/policy.d.ts.map +1 -1
  54. package/dist/security/types.d.ts +27 -13
  55. package/dist/security/types.d.ts.map +1 -1
  56. package/dist/security/verification.d.ts +8 -0
  57. package/dist/security/verification.d.ts.map +1 -0
  58. package/dist/server/errors.d.ts.map +1 -1
  59. package/dist/server/not-found.d.ts.map +1 -1
  60. package/dist/server/render-tree.d.ts +6 -1
  61. package/dist/server/render-tree.d.ts.map +1 -1
  62. package/dist/server/request-handler.d.ts +4 -1
  63. package/dist/server/request-handler.d.ts.map +1 -1
  64. package/dist/server/ssr.d.ts +1 -0
  65. package/dist/server/ssr.d.ts.map +1 -1
  66. package/dist/static/index.d.ts +10 -0
  67. package/dist/static/index.d.ts.map +1 -1
  68. package/dist/static/index.js +579 -139
  69. package/dist/static/index.js.map +1 -1
  70. package/dist/static/preview.d.ts +8 -0
  71. package/dist/static/preview.d.ts.map +1 -0
  72. package/dist/static/vercel.d.ts +31 -0
  73. package/dist/static/vercel.d.ts.map +1 -0
  74. package/dist/vite/index.d.ts +3 -2
  75. package/dist/vite/index.d.ts.map +1 -1
  76. package/dist/vite/index.js +754 -326
  77. package/dist/vite/index.js.map +1 -1
  78. package/dist/vite/plugin.d.ts +13 -0
  79. package/dist/vite/plugin.d.ts.map +1 -1
  80. package/dist/vite/policy-verification.d.ts +10 -0
  81. package/dist/vite/policy-verification.d.ts.map +1 -0
  82. package/package.json +6 -1
  83. package/dist/chunks/index-BnX9Qxbm.js +0 -44
  84. package/dist/chunks/index-BnX9Qxbm.js.map +0 -1
  85. package/dist/chunks/ssr-BJejKlkZ.js +0 -275
  86. package/dist/chunks/ssr-BJejKlkZ.js.map +0 -1
  87. package/dist/chunks/streaming-DN1DnbRE.js.map +0 -1
  88. package/dist/chunks/testing-DR3eQAvY.js.map +0 -1
package/README.md CHANGED
@@ -52,6 +52,9 @@ Run `vite` for development or `vite build` for a browser build. There is no
52
52
  `index.html` to write: the framework renders the document and attaches CSP
53
53
  nonces to what it emits.
54
54
 
55
+ Run `demiurge build` for static production output. Run `demiurge preview` to
56
+ serve that output with the headers in its manifest.
57
+
55
58
  Production SSR uses a separate server build and a runtime adapter. The minimum
56
59
  working setup is in the
57
60
  [README quickstart](https://github.com/NorthShoreSoftwareLabs/demiurge#deploy),
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* global console, process */
4
+
5
+ import { resolve } from "node:path";
6
+ import {
7
+ buildStaticSite,
8
+ helpText,
9
+ parseCliArguments,
10
+ resolvePreviewOutputDirectory,
11
+ } from "../dist/cli.js";
12
+ import {
13
+ createStaticPreviewServer,
14
+ } from "../dist/static/index.js";
15
+
16
+ async function main() {
17
+ const options = parseCliArguments(process.argv.slice(2), process.env);
18
+
19
+ if (options.command === "help") {
20
+ console.log(helpText);
21
+ return;
22
+ }
23
+
24
+ if (options.command === "build") {
25
+ const { deploymentOutDir, manifest, outDir } = await buildStaticSite(options);
26
+ console.log(
27
+ `Demiurge generated ${manifest.entries.length} static artifacts in ${outDir}.`,
28
+ );
29
+ if (deploymentOutDir) {
30
+ console.log(`Demiurge generated provider output in ${deploymentOutDir}.`);
31
+ }
32
+ return;
33
+ }
34
+
35
+ const server = await createStaticPreviewServer({
36
+ ...options,
37
+ outDir: await resolvePreviewOutputDirectory(options.outDir),
38
+ });
39
+ const address = server.address();
40
+ const port = typeof address === "object" && address ? address.port : options.port;
41
+ console.log(`Demiurge serves ${resolve(options.outDir)} at http://${options.host}:${port}.`);
42
+
43
+ const close = () => server.close();
44
+ process.once("SIGINT", close);
45
+ process.once("SIGTERM", close);
46
+ }
47
+
48
+ main().catch((error) => {
49
+ console.error(`demiurge: ${error instanceof Error ? error.message : String(error)}`);
50
+ process.exitCode = 1;
51
+ });
@@ -0,0 +1,477 @@
1
+ import { renderToString as k } from "react-dom/server";
2
+ import { createContext as C, useContext as O, createElement as p } from "react";
3
+ const P = {
4
+ backgroundLifetime: !1,
5
+ crossOriginIsolationHeaders: !1,
6
+ nonceInjection: !1,
7
+ sharedCache: !1,
8
+ staticOutput: !1,
9
+ streaming: !1,
10
+ webSocket: !1,
11
+ webTransport: !1
12
+ };
13
+ function le(e) {
14
+ return {
15
+ capabilities: {
16
+ ...P,
17
+ ...e.capabilities
18
+ },
19
+ name: e.name
20
+ };
21
+ }
22
+ function _(e, t) {
23
+ const n = [...new Set(t)], r = n.filter(
24
+ (o) => !e.capabilities[o]
25
+ );
26
+ return {
27
+ adapter: e.name,
28
+ missing: r,
29
+ ok: r.length === 0,
30
+ required: n
31
+ };
32
+ }
33
+ function pe(e, t) {
34
+ const n = _(e, t);
35
+ if (!n.ok)
36
+ throw new Error(
37
+ `Adapter "${e.name}" does not support required capabilities: ${n.missing.join(", ")}.`
38
+ );
39
+ return n;
40
+ }
41
+ const R = "__demiurge_data", N = "data-demiurge-hydrate", T = "data-demiurge-fallback";
42
+ function M(e, t = {}) {
43
+ return j(
44
+ JSON.stringify({ data: e, hasData: !0, ...t })
45
+ );
46
+ }
47
+ function fe(e) {
48
+ const t = e.getElementById(R), n = t?.tagName === "TEMPLATE" ? t.content.textContent : t?.textContent;
49
+ if (n)
50
+ try {
51
+ return JSON.parse(n);
52
+ } catch (r) {
53
+ throw new Error(
54
+ "Demiurge could not parse the initial route data payload.",
55
+ { cause: r }
56
+ );
57
+ }
58
+ }
59
+ function j(e) {
60
+ return e.replace(/&/g, "\\u0026").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
61
+ }
62
+ const q = /* @__PURE__ */ new Set([
63
+ "afterInteractive",
64
+ "beforeInteractive",
65
+ "module"
66
+ ]), d = Symbol("demiurge.scriptPlacement"), D = C(
67
+ void 0
68
+ );
69
+ function B(e = {}) {
70
+ let t = !1;
71
+ const n = [...e.scripts ?? []], r = new Set(n.map((i) => i.src)), o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
72
+ return {
73
+ get dev() {
74
+ return e.dev ?? !1;
75
+ },
76
+ get headFlushed() {
77
+ return t;
78
+ },
79
+ flushHead() {
80
+ t = !0;
81
+ },
82
+ nonce: e.nonce,
83
+ register(i) {
84
+ if (r.has(i.src) || o.has(i.src))
85
+ return "skip";
86
+ if (o.add(i.src), !t)
87
+ return a.set(i.src, {
88
+ ...i,
89
+ [d]: "hoisted"
90
+ }), "hoist";
91
+ if (i.strategy === "beforeInteractive" && (e.dev ?? !1))
92
+ throw new Error(
93
+ `A render-discovered beforeInteractive script ${JSON.stringify(i.src)} was found after the document head flushed. Declare it in export const scripts.`
94
+ );
95
+ return "render";
96
+ },
97
+ scripts() {
98
+ return x([...n, ...a.values()]);
99
+ }
100
+ };
101
+ }
102
+ function me(e) {
103
+ const t = O(D), n = H(e);
104
+ if (!t) {
105
+ if (typeof document > "u")
106
+ throw new Error(
107
+ `The script ${JSON.stringify(n.src)} rendered outside a Demiurge document render context. A server render must wrap its component tree with the script render context.`
108
+ );
109
+ return G(n.src) ? null : b({
110
+ ...n,
111
+ [d]: "in-place"
112
+ }, U());
113
+ }
114
+ return t.register(n) !== "render" ? null : b({
115
+ ...n,
116
+ [d]: "in-place"
117
+ }, t.nonce);
118
+ }
119
+ function b(e, t) {
120
+ return p("script", {
121
+ async: e.async,
122
+ "data-api": e.dataApi,
123
+ "data-domain": e.dataDomain,
124
+ "data-demiurge-script-placement": e[d],
125
+ defer: e.defer,
126
+ id: e.id,
127
+ integrity: e.integrity,
128
+ nonce: e.nonce ?? t,
129
+ referrerPolicy: e.referrerPolicy,
130
+ src: e.src,
131
+ type: e.type ?? Y(e.strategy)
132
+ });
133
+ }
134
+ function G(e) {
135
+ if (typeof document > "u")
136
+ return !1;
137
+ const t = new URL(e, document.baseURI).href;
138
+ return [...document.scripts].some(
139
+ (n) => n.src === t && n.dataset.demiurgeScriptPlacement !== "in-place"
140
+ );
141
+ }
142
+ function U() {
143
+ if (!(typeof document > "u"))
144
+ return [...document.scripts].reverse().find((e) => e.nonce)?.nonce;
145
+ }
146
+ function ye(e) {
147
+ return e;
148
+ }
149
+ function H(e) {
150
+ const t = e.strategy ?? "afterInteractive";
151
+ if (!q.has(t))
152
+ throw new Error(
153
+ `Unsupported script strategy ${JSON.stringify(t)}. Demiurge 0.1 supports "beforeInteractive", "module", and "afterInteractive"; deferred, visibility-triggered, and worker loading require a future client script runtime.`
154
+ );
155
+ if (t === "module" && e.type && e.type !== "module")
156
+ throw new Error(
157
+ 'The "module" script strategy cannot be combined with type="text/javascript".'
158
+ );
159
+ return {
160
+ ...e,
161
+ kind: "script",
162
+ strategy: t
163
+ };
164
+ }
165
+ function J(e, t) {
166
+ return p(D.Provider, { value: e, children: t });
167
+ }
168
+ async function he(e, t) {
169
+ const n = [];
170
+ for (const r of e) {
171
+ if (!r)
172
+ continue;
173
+ const o = typeof r == "function" ? await r(t) : r;
174
+ n.push(...o);
175
+ }
176
+ return x(L(n));
177
+ }
178
+ function L(e) {
179
+ const t = /* @__PURE__ */ new Map();
180
+ for (const n of e)
181
+ t.set(v(n), {
182
+ ...t.get(v(n)),
183
+ ...n
184
+ });
185
+ return [...t.values()];
186
+ }
187
+ function v(e) {
188
+ return [
189
+ e.src,
190
+ e.type ?? "",
191
+ e.integrity ?? "",
192
+ e.strategy
193
+ ].join("\0");
194
+ }
195
+ function F(e, t) {
196
+ return w(e.strategy) - w(t.strategy) || e.src.localeCompare(t.src);
197
+ }
198
+ function x(e) {
199
+ return e.sort(F);
200
+ }
201
+ function Y(e) {
202
+ return e === "module" ? "module" : void 0;
203
+ }
204
+ function w(e) {
205
+ return e === "beforeInteractive" ? 0 : e === "module" ? 1 : 2;
206
+ }
207
+ const z = "data-demiurge-structured-data";
208
+ function K(e) {
209
+ if (e.body) {
210
+ const { html: t, ...n } = e.body, { prefix: r, suffix: o } = W({ ...e, body: n });
211
+ return `${r}${t}${o}`;
212
+ }
213
+ return Q(e);
214
+ }
215
+ function W({
216
+ body: e,
217
+ entrySrc: t,
218
+ lang: n = "en",
219
+ links: r = [],
220
+ metadata: o,
221
+ nonce: a,
222
+ scripts: i = [],
223
+ styles: m = [],
224
+ title: y = "Demiurge App"
225
+ }) {
226
+ const h = o?.title ?? y, l = [
227
+ ...i.filter(($) => $[d] !== "hoisted").map(($) => ` ${S($, a)}`),
228
+ Z(e.data, e.navigation),
229
+ ...t ? [E(t, a)] : []
230
+ ].join(`
231
+ `);
232
+ return {
233
+ prefix: `<!doctype html>
234
+ <html lang="${s(n)}">
235
+ <head>
236
+ ${I({ links: r, metadata: o, nonce: a, scripts: i, styles: m, title: h })}
237
+ </head>
238
+ <body>
239
+ ${X(e)}`,
240
+ suffix: `</div>
241
+ ${l}
242
+ </body>
243
+ </html>
244
+ `
245
+ };
246
+ }
247
+ function Q({
248
+ entrySrc: e,
249
+ lang: t = "en",
250
+ links: n = [],
251
+ metadata: r,
252
+ nonce: o,
253
+ scripts: a = [],
254
+ styles: i = [],
255
+ title: m = "Demiurge App"
256
+ }) {
257
+ const y = r?.title ?? m, h = [
258
+ V(),
259
+ ...a.filter((l) => l[d] !== "hoisted").map((l) => ` ${S(l, o)}`),
260
+ ...e ? [E(e, o)] : []
261
+ ].join(`
262
+ `);
263
+ return `<!doctype html>
264
+ <html lang="${s(t)}">
265
+ <head>
266
+ ${I({ links: n, metadata: r, nonce: o, scripts: a, styles: i, title: y })}
267
+ </head>
268
+ <body>
269
+ ${h}
270
+ </body>
271
+ </html>
272
+ `;
273
+ }
274
+ function V(e) {
275
+ return ' <div id="root"></div>';
276
+ }
277
+ function X(e) {
278
+ const t = e.fallback ? ` ${T}="${s(e.fallback)}"` : "";
279
+ return ` <div id="root" ${N}=""${t}>`;
280
+ }
281
+ function Z(e, t) {
282
+ return ` <template id="${R}">${M(e, { navigation: t })}</template>`;
283
+ }
284
+ function E(e, t) {
285
+ return ` <script type="module" src="${s(e)}"${c("nonce", t)}><\/script>`;
286
+ }
287
+ function I({
288
+ links: e,
289
+ metadata: t,
290
+ nonce: n,
291
+ scripts: r,
292
+ styles: o,
293
+ title: a
294
+ }) {
295
+ return [
296
+ u({
297
+ content: t?.charset ?? "UTF-8",
298
+ name: "charset"
299
+ }),
300
+ u({
301
+ content: t?.viewport ?? "width=device-width, initial-scale=1.0",
302
+ name: "viewport"
303
+ }),
304
+ ` <title>${s(a)}</title>`,
305
+ ...t?.description ? [
306
+ u({
307
+ content: t.description,
308
+ name: "description"
309
+ })
310
+ ] : [],
311
+ ...t?.canonical ? [
312
+ g({
313
+ href: t.canonical,
314
+ rel: "canonical"
315
+ })
316
+ ] : [],
317
+ ...ee(t),
318
+ ...te(t),
319
+ ...(t?.custom ?? []).map(ne),
320
+ ...(t?.structuredData ?? []).map(
321
+ (i) => re(i, n)
322
+ ),
323
+ ...o.map(
324
+ (i) => ` <link rel="stylesheet" href="${s(i)}" />`
325
+ ),
326
+ ...e.map(g),
327
+ ...r.filter((i) => i[d] === "hoisted").map((i) => ` ${S(i, n)}`)
328
+ ].join(`
329
+ `);
330
+ }
331
+ function ee(e) {
332
+ if (!e?.robots)
333
+ return [];
334
+ const t = [
335
+ e.robots.index === !1 ? "noindex" : "index",
336
+ e.robots.follow === !1 ? "nofollow" : "follow"
337
+ ];
338
+ return [
339
+ u({
340
+ content: t.join(", "),
341
+ name: "robots"
342
+ })
343
+ ];
344
+ }
345
+ function te(e) {
346
+ return e?.openGraph ? [
347
+ e.openGraph.title ? u({
348
+ content: e.openGraph.title,
349
+ property: "og:title"
350
+ }) : null,
351
+ e.openGraph.description ? u({
352
+ content: e.openGraph.description,
353
+ property: "og:description"
354
+ }) : null,
355
+ e.openGraph.image ? u({
356
+ content: e.openGraph.image,
357
+ property: "og:image"
358
+ }) : null
359
+ ].filter((t) => !!t) : [];
360
+ }
361
+ function ne(e) {
362
+ return e.kind === "link" ? g(e) : u(e);
363
+ }
364
+ function re(e, t) {
365
+ return ` <script type="application/ld+json"${t ? "" : ` ${z}`}${c("nonce", t)}>${oe(JSON.stringify(e.value))}<\/script>`;
366
+ }
367
+ function u(e) {
368
+ if (e.name === "charset")
369
+ return ` <meta charset="${s(e.content)}" />`;
370
+ const t = e.name ? ` name="${s(e.name)}"` : "", n = e.property ? ` property="${s(e.property)}"` : "";
371
+ return ` <meta${t}${n} content="${s(e.content)}" />`;
372
+ }
373
+ function g(e) {
374
+ return ` <link${c("rel", e.rel)}${c("href", e.href)}${c("as", e.as)}${c("type", e.type)}${c("crossorigin", e.crossOrigin)}${c("hreflang", e.hrefLang)} />`;
375
+ }
376
+ function S(e, t) {
377
+ return `<script${c("id", e.id)}${c("src", e.src)}${c("type", e.type ?? ie(e.strategy))}${c("nonce", e.nonce ?? t)}${c("integrity", e.integrity)}${c("referrerpolicy", e.referrerPolicy)}${c("data-api", e.dataApi)}${c("data-domain", e.dataDomain)}${c("data-demiurge-script-placement", e[d])}${A("async", e.async)}${A("defer", e.defer)}><\/script>`;
378
+ }
379
+ function ie(e) {
380
+ return e === "module" ? "module" : void 0;
381
+ }
382
+ function c(e, t) {
383
+ return t ? ` ${e}="${s(t)}"` : "";
384
+ }
385
+ function A(e, t) {
386
+ return t ? ` ${e}` : "";
387
+ }
388
+ function s(e) {
389
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
390
+ }
391
+ function oe(e) {
392
+ return e.replaceAll("<", "\\u003c").replaceAll(">", "\\u003e").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
393
+ }
394
+ function ce(e, t) {
395
+ const n = p(e.page, {
396
+ data: e.data,
397
+ path: e.path,
398
+ pathname: e.pathname
399
+ }), r = e.layouts.reduceRight(
400
+ (o, a) => p(a, {
401
+ children: o,
402
+ path: e.path,
403
+ pathname: e.pathname
404
+ }),
405
+ n
406
+ );
407
+ return t ? J(t, r) : r;
408
+ }
409
+ function ae(e, t = {}) {
410
+ return B({
411
+ dev: t.dev,
412
+ nonce: t.nonce,
413
+ scripts: e.scripts
414
+ });
415
+ }
416
+ function se(e, t = {}) {
417
+ const n = ae(e, t), r = k(ce(e, n));
418
+ return K({
419
+ body: {
420
+ data: e.data,
421
+ html: r,
422
+ navigation: e.render.mode === "static" ? "document" : t.navigation
423
+ },
424
+ entrySrc: t.clientEntry,
425
+ lang: t.lang,
426
+ links: e.links,
427
+ metadata: e.metadata,
428
+ nonce: t.nonce,
429
+ scripts: n.scripts(),
430
+ styles: t.styles,
431
+ title: t.title
432
+ });
433
+ }
434
+ function $e(e, t = {}) {
435
+ const n = se(e, t);
436
+ return new Response(n, {
437
+ headers: {
438
+ "content-type": "text/html; charset=utf-8"
439
+ }
440
+ });
441
+ }
442
+ const f = /* @__PURE__ */ new WeakMap();
443
+ function ge(e) {
444
+ return f.get(e);
445
+ }
446
+ function Se(e, t) {
447
+ f.set(e, t);
448
+ }
449
+ function be(e, t) {
450
+ const n = f.get(e);
451
+ n && f.set(t, n);
452
+ }
453
+ export {
454
+ N as H,
455
+ z as S,
456
+ ce as a,
457
+ W as b,
458
+ ae as c,
459
+ le as d,
460
+ K as e,
461
+ se as f,
462
+ fe as g,
463
+ T as h,
464
+ H as i,
465
+ me as j,
466
+ pe as k,
467
+ _ as l,
468
+ ye as m,
469
+ he as n,
470
+ B as o,
471
+ ge as p,
472
+ be as q,
473
+ $e as r,
474
+ Se as s,
475
+ J as w
476
+ };
477
+ //# sourceMappingURL=request-metadata-DwEO1EAS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-metadata-DwEO1EAS.js","sources":["../../src/adapter/index.ts","../../src/document/hydration.ts","../../src/document/scripts.ts","../../src/document/render.ts","../../src/server/render-tree.ts","../../src/server/ssr.ts","../../src/server/request-metadata.ts"],"sourcesContent":["export type AdapterCapability =\n | \"backgroundLifetime\"\n | \"crossOriginIsolationHeaders\"\n | \"nonceInjection\"\n | \"sharedCache\"\n | \"staticOutput\"\n | \"streaming\"\n | \"webSocket\"\n | \"webTransport\";\n\nexport type AdapterCapabilityMap = Record<AdapterCapability, boolean>;\n\nexport type Adapter = {\n capabilities: AdapterCapabilityMap;\n name: string;\n};\n\nexport type AdapterDefinition = {\n capabilities?: Partial<AdapterCapabilityMap>;\n name: string;\n};\n\nexport type AdapterCapabilityCheck = {\n adapter: string;\n missing: AdapterCapability[];\n ok: boolean;\n required: AdapterCapability[];\n};\n\nconst defaultCapabilities = {\n backgroundLifetime: false,\n crossOriginIsolationHeaders: false,\n nonceInjection: false,\n sharedCache: false,\n staticOutput: false,\n streaming: false,\n webSocket: false,\n webTransport: false,\n} satisfies AdapterCapabilityMap;\n\nexport function defineAdapter(definition: AdapterDefinition): Adapter {\n return {\n capabilities: {\n ...defaultCapabilities,\n ...definition.capabilities,\n },\n name: definition.name,\n };\n}\n\nexport function checkAdapterCapabilities(\n adapter: Adapter,\n required: readonly AdapterCapability[],\n): AdapterCapabilityCheck {\n const uniqueRequired = [...new Set(required)];\n const missing = uniqueRequired.filter(\n (capability) => !adapter.capabilities[capability],\n );\n\n return {\n adapter: adapter.name,\n missing,\n ok: missing.length === 0,\n required: uniqueRequired,\n };\n}\n\nexport function assertAdapterCapabilities(\n adapter: Adapter,\n required: readonly AdapterCapability[],\n) {\n const check = checkAdapterCapabilities(adapter, required);\n\n if (!check.ok) {\n throw new Error(\n `Adapter \"${adapter.name}\" does not support required capabilities: ${check.missing.join(\", \")}.`,\n );\n }\n\n return check;\n}\n","export type InitialRouteData = {\n data?: unknown;\n hasData: boolean;\n navigation?: \"document\";\n};\n\nexport const HYDRATION_DATA_ELEMENT_ID = \"__demiurge_data\";\nexport const HYDRATION_ROOT_ATTRIBUTE = \"data-demiurge-hydrate\";\n// Marks a server document as a fallback, not a page. The client hydrates markup\n// that it can reproduce. It replaces other markup. This attribute distinguishes\n// a server 404 from a page that does not match the client manifest.\nexport const HYDRATION_FALLBACK_ATTRIBUTE = \"data-demiurge-fallback\";\n\nexport function serializeInitialRouteData(\n data: unknown,\n options: { navigation?: \"document\" } = {},\n) {\n return escapeJsonScript(\n JSON.stringify({ data, hasData: true, ...options }),\n );\n}\n\nexport function readInitialRouteData(source: Document) {\n const element = source.getElementById(HYDRATION_DATA_ELEMENT_ID);\n const serialized = element?.tagName === \"TEMPLATE\"\n ? (element as HTMLTemplateElement).content.textContent\n : element?.textContent;\n\n if (!serialized) {\n return undefined;\n }\n\n try {\n return JSON.parse(serialized) as InitialRouteData;\n } catch (error) {\n throw new Error(\n \"Demiurge could not parse the initial route data payload.\",\n { cause: error },\n );\n }\n}\n\nfunction escapeJsonScript(value: string) {\n return value\n .replace(/&/g, \"\\\\u0026\")\n .replace(/</g, \"\\\\u003c\")\n .replace(/>/g, \"\\\\u003e\")\n .replace(/\\u2028/g, \"\\\\u2028\")\n .replace(/\\u2029/g, \"\\\\u2029\");\n}\n","import {\n createContext,\n createElement,\n useContext,\n type ReactNode,\n} from \"react\";\nimport type { HttpRouteContext, MaybePromise } from \"../route\";\n\nexport type ScriptStrategy =\n | \"afterInteractive\"\n | \"beforeInteractive\"\n | \"module\";\n\nconst SCRIPT_STRATEGIES = new Set<ScriptStrategy>([\n \"afterInteractive\",\n \"beforeInteractive\",\n \"module\",\n]);\n\nexport const scriptPlacement = Symbol(\"demiurge.scriptPlacement\");\n\nexport type ScriptTag = {\n async?: boolean;\n dataApi?: string;\n dataDomain?: string;\n defer?: boolean;\n id?: string;\n integrity?: string;\n kind: \"script\";\n nonce?: string;\n purpose?: string;\n referrerPolicy?: ReferrerPolicy;\n src: string;\n strategy: ScriptStrategy;\n type?: \"module\" | \"text/javascript\";\n [scriptPlacement]?: \"hoisted\" | \"in-place\";\n};\n\nexport type ScriptContribution =\n | readonly ScriptTag[]\n | ((context: HttpRouteContext) => MaybePromise<readonly ScriptTag[]>);\n\nexport type ScriptProps = Omit<\n ScriptTag,\n \"kind\" | \"nonce\" | \"strategy\" | typeof scriptPlacement\n> & {\n strategy?: ScriptStrategy;\n};\n\nexport type ScriptRenderContext = {\n dev: boolean;\n headFlushed: boolean;\n flushHead: () => void;\n nonce?: string;\n register: (scriptTag: ScriptTag) => \"hoist\" | \"render\" | \"skip\";\n scripts: () => ScriptTag[];\n};\n\nexport const ScriptContext = createContext<ScriptRenderContext | undefined>(\n undefined,\n);\n\nexport function createScriptRenderContext(options: {\n dev?: boolean;\n nonce?: string;\n scripts?: readonly ScriptTag[];\n} = {}): ScriptRenderContext {\n let headFlushed = false;\n const staticScripts = [...(options.scripts ?? [])];\n const staticSources = new Set(staticScripts.map((tag) => tag.src));\n const registeredSources = new Set<string>();\n const hoisted = new Map<string, ScriptTag>();\n\n return {\n get dev() {\n return options.dev ?? false;\n },\n get headFlushed() {\n return headFlushed;\n },\n flushHead() {\n headFlushed = true;\n },\n nonce: options.nonce,\n register(scriptTag) {\n if (staticSources.has(scriptTag.src) || registeredSources.has(scriptTag.src)) {\n return \"skip\";\n }\n\n registeredSources.add(scriptTag.src);\n\n if (!headFlushed) {\n hoisted.set(scriptTag.src, {\n ...scriptTag,\n [scriptPlacement]: \"hoisted\",\n });\n return \"hoist\";\n }\n\n if (scriptTag.strategy === \"beforeInteractive\" && (options.dev ?? false)) {\n throw new Error(\n `A render-discovered beforeInteractive script ${JSON.stringify(scriptTag.src)} was found after the document head flushed. Declare it in export const scripts.`,\n );\n }\n\n return \"render\";\n },\n scripts() {\n return sortScripts([...staticScripts, ...hoisted.values()]);\n },\n };\n}\n\nexport function Script(props: ScriptProps): ReactNode {\n const context = useContext(ScriptContext);\n const scriptTag = script(props);\n\n if (!context) {\n if (typeof document === \"undefined\") {\n throw new Error(\n `The script ${JSON.stringify(scriptTag.src)} rendered outside a Demiurge document render context. A server render must wrap its component tree with the script render context.`,\n );\n }\n\n if (hasExistingScript(scriptTag.src)) {\n return null;\n }\n\n return renderScriptElement({\n ...scriptTag,\n [scriptPlacement]: \"in-place\",\n }, documentNonce());\n }\n\n const placement = context.register(scriptTag);\n\n if (placement !== \"render\") {\n return null;\n }\n\n return renderScriptElement({\n ...scriptTag,\n [scriptPlacement]: \"in-place\",\n }, context.nonce);\n}\n\nfunction renderScriptElement(scriptTag: ScriptTag, nonce?: string) {\n return createElement(\"script\", {\n async: scriptTag.async,\n \"data-api\": scriptTag.dataApi,\n \"data-domain\": scriptTag.dataDomain,\n \"data-demiurge-script-placement\": scriptTag[scriptPlacement],\n defer: scriptTag.defer,\n id: scriptTag.id,\n integrity: scriptTag.integrity,\n nonce: scriptTag.nonce ?? nonce,\n referrerPolicy: scriptTag.referrerPolicy,\n src: scriptTag.src,\n type: scriptTag.type ?? scriptTypeForStrategy(scriptTag.strategy),\n });\n}\n\nfunction hasExistingScript(src: string) {\n if (typeof document === \"undefined\") {\n return false;\n }\n\n const expected = new URL(src, document.baseURI).href;\n\n return [...document.scripts].some((element) =>\n element.src === expected &&\n element.dataset.demiurgeScriptPlacement !== \"in-place\"\n );\n}\n\nfunction documentNonce() {\n if (typeof document === \"undefined\") {\n return undefined;\n }\n\n return [...document.scripts].reverse().find((element) => element.nonce)?.nonce;\n}\n\nexport function defineScripts(contribution: ScriptContribution) {\n return contribution;\n}\n\nexport function script(options: Omit<ScriptTag, \"kind\" | \"strategy\"> & {\n strategy?: ScriptStrategy;\n}): ScriptTag {\n const strategy = options.strategy ?? \"afterInteractive\";\n\n if (!SCRIPT_STRATEGIES.has(strategy)) {\n throw new Error(\n `Unsupported script strategy ${JSON.stringify(strategy)}. Demiurge 0.1 supports \"beforeInteractive\", \"module\", and \"afterInteractive\"; deferred, visibility-triggered, and worker loading require a future client script runtime.`,\n );\n }\n\n if (strategy === \"module\" && options.type && options.type !== \"module\") {\n throw new Error(\n 'The \"module\" script strategy cannot be combined with type=\"text/javascript\".',\n );\n }\n\n return {\n ...options,\n kind: \"script\",\n strategy,\n };\n}\n\nexport function withScriptContext(\n context: ScriptRenderContext,\n children: ReactNode,\n) {\n return createElement(ScriptContext.Provider, { value: context, children });\n}\n\nexport async function resolveScripts(\n contributions: Array<ScriptContribution | false | undefined>,\n context: HttpRouteContext,\n) {\n const scripts: ScriptTag[] = [];\n\n for (const contribution of contributions) {\n if (!contribution) {\n continue;\n }\n\n const resolved =\n typeof contribution === \"function\"\n ? await contribution(context)\n : contribution;\n\n scripts.push(...resolved);\n }\n\n return sortScripts(dedupeScripts(scripts));\n}\n\nfunction dedupeScripts(scripts: ScriptTag[]) {\n const deduped = new Map<string, ScriptTag>();\n\n for (const scriptTag of scripts) {\n deduped.set(scriptKey(scriptTag), {\n ...deduped.get(scriptKey(scriptTag)),\n ...scriptTag,\n });\n }\n\n return [...deduped.values()];\n}\n\nfunction scriptKey(scriptTag: ScriptTag) {\n return [\n scriptTag.src,\n scriptTag.type ?? \"\",\n scriptTag.integrity ?? \"\",\n scriptTag.strategy,\n ].join(\"\\0\");\n}\n\nfunction compareScripts(left: ScriptTag, right: ScriptTag) {\n return (\n scriptStrategyOrder(left.strategy) - scriptStrategyOrder(right.strategy) ||\n left.src.localeCompare(right.src)\n );\n}\n\nfunction sortScripts(scripts: ScriptTag[]) {\n return scripts.sort(compareScripts);\n}\n\nfunction scriptTypeForStrategy(strategy: ScriptTag[\"strategy\"]) {\n return strategy === \"module\" ? \"module\" : undefined;\n}\n\nfunction scriptStrategyOrder(strategy: ScriptStrategy) {\n if (strategy === \"beforeInteractive\") {\n return 0;\n }\n\n if (strategy === \"module\") {\n return 1;\n }\n\n return 2;\n}\n","import {\n HYDRATION_DATA_ELEMENT_ID,\n HYDRATION_FALLBACK_ATTRIBUTE,\n HYDRATION_ROOT_ATTRIBUTE,\n serializeInitialRouteData,\n} from \"./hydration\";\nimport type {\n DocumentMetadataTag,\n LinkTag,\n ResolvedMetadata,\n StructuredDataTag,\n} from \"./metadata\";\nimport { scriptPlacement, type ScriptTag } from \"./scripts\";\n\nexport const STRUCTURED_DATA_ATTRIBUTE = \"data-demiurge-structured-data\";\n\nexport type DocumentBody = {\n data: unknown;\n fallback?: \"not-found\";\n html: string;\n navigation?: \"document\";\n};\n\nexport type RenderDocumentOptions = {\n body?: DocumentBody;\n entrySrc?: string;\n lang?: string;\n links?: LinkTag[];\n metadata?: ResolvedMetadata;\n nonce?: string;\n scripts?: ScriptTag[];\n styles?: string[];\n title?: string;\n};\n\nexport type RenderDocumentShellOptions = Omit<RenderDocumentOptions, \"body\"> & {\n body: Omit<DocumentBody, \"html\">;\n};\n\nexport function renderDocument(options: RenderDocumentOptions) {\n if (options.body) {\n const { html, ...body } = options.body;\n const { prefix, suffix } = renderDocumentShell({ ...options, body });\n\n return `${prefix}${html}${suffix}`;\n }\n\n return renderDocumentWithoutBody(options);\n}\n\nexport function renderDocumentShell({\n body,\n entrySrc,\n lang = \"en\",\n links = [],\n metadata,\n nonce,\n scripts = [],\n styles = [],\n title = \"Demiurge App\",\n}: RenderDocumentShellOptions) {\n const documentTitle = metadata?.title ?? title;\n const trailingBodyContent = [\n ...scripts\n .filter((scriptTag) => scriptTag[scriptPlacement] !== \"hoisted\")\n .map((scriptTag) => ` ${renderScriptTag(scriptTag, nonce)}`),\n renderBootstrapData(body.data, body.navigation),\n ...(entrySrc ? [renderEntryScript(entrySrc, nonce)] : []),\n ].join(\"\\n\");\n\n return {\n prefix: `<!doctype html>\n<html lang=\"${escapeHtml(lang)}\">\n <head>\n${renderHeadTags({ links, metadata, nonce, scripts, styles, title: documentTitle })}\n </head>\n <body>\n${renderRootStart(body)}`,\n suffix: `</div>\n${trailingBodyContent}\n </body>\n</html>\n`,\n };\n}\n\nfunction renderDocumentWithoutBody({\n entrySrc,\n lang = \"en\",\n links = [],\n metadata,\n nonce,\n scripts = [],\n styles = [],\n title = \"Demiurge App\",\n}: RenderDocumentOptions) {\n const documentTitle = metadata?.title ?? title;\n const bodyContent = [\n renderRootElement(),\n ...scripts\n .filter((scriptTag) => scriptTag[scriptPlacement] !== \"hoisted\")\n .map((scriptTag) => ` ${renderScriptTag(scriptTag, nonce)}`),\n ...(entrySrc ? [renderEntryScript(entrySrc, nonce)] : []),\n ].join(\"\\n\");\n\n return `<!doctype html>\n<html lang=\"${escapeHtml(lang)}\">\n <head>\n${renderHeadTags({ links, metadata, nonce, scripts, styles, title: documentTitle })}\n </head>\n <body>\n${bodyContent}\n </body>\n</html>\n`;\n}\n\nfunction renderRootElement(body?: DocumentBody) {\n if (!body) {\n return ` <div id=\"root\"></div>`;\n }\n\n return `${renderRootStart(body)}${body.html}</div>`;\n}\n\nfunction renderRootStart(body: Omit<DocumentBody, \"html\">) {\n const fallback = body.fallback\n ? ` ${HYDRATION_FALLBACK_ATTRIBUTE}=\"${escapeHtml(body.fallback)}\"`\n : \"\";\n\n return ` <div id=\"root\" ${HYDRATION_ROOT_ATTRIBUTE}=\"\"${fallback}>`;\n}\n\nfunction renderBootstrapData(data: unknown, navigation?: \"document\") {\n return ` <template id=\"${HYDRATION_DATA_ELEMENT_ID}\">${serializeInitialRouteData(data, { navigation })}</template>`;\n}\n\nfunction renderEntryScript(entrySrc: string, nonce: string | undefined) {\n return ` <script type=\"module\" src=\"${escapeHtml(entrySrc)}\"${renderAttribute(\"nonce\", nonce)}></script>`;\n}\n\nfunction renderHeadTags({\n links,\n metadata,\n nonce,\n scripts,\n styles,\n title,\n}: {\n links: LinkTag[];\n metadata: ResolvedMetadata | undefined;\n nonce: string | undefined;\n scripts: ScriptTag[];\n styles: string[];\n title: string;\n}) {\n return [\n renderMetaTag({\n content: metadata?.charset ?? \"UTF-8\",\n kind: \"meta\",\n name: \"charset\",\n }),\n renderMetaTag({\n content: metadata?.viewport ?? \"width=device-width, initial-scale=1.0\",\n kind: \"meta\",\n name: \"viewport\",\n }),\n ` <title>${escapeHtml(title)}</title>`,\n ...(metadata?.description\n ? [\n renderMetaTag({\n content: metadata.description,\n kind: \"meta\",\n name: \"description\",\n }),\n ]\n : []),\n ...(metadata?.canonical\n ? [\n renderLinkTag({\n href: metadata.canonical,\n kind: \"link\",\n rel: \"canonical\",\n }),\n ]\n : []),\n ...renderRobotsTags(metadata),\n ...renderOpenGraphTags(metadata),\n ...(metadata?.custom ?? []).map(renderDocumentMetadataTag),\n ...(metadata?.structuredData ?? []).map((tag) =>\n renderStructuredDataTag(tag, nonce),\n ),\n ...styles.map(\n (href) => ` <link rel=\"stylesheet\" href=\"${escapeHtml(href)}\" />`,\n ),\n ...links.map(renderLinkTag),\n ...scripts\n .filter((scriptTag) => scriptTag[scriptPlacement] === \"hoisted\")\n .map((scriptTag) => ` ${renderScriptTag(scriptTag, nonce)}`),\n ].join(\"\\n\");\n}\n\nfunction renderRobotsTags(metadata: ResolvedMetadata | undefined) {\n if (!metadata?.robots) {\n return [];\n }\n\n const directives = [\n metadata.robots.index === false ? \"noindex\" : \"index\",\n metadata.robots.follow === false ? \"nofollow\" : \"follow\",\n ];\n\n return [\n renderMetaTag({\n content: directives.join(\", \"),\n kind: \"meta\",\n name: \"robots\",\n }),\n ];\n}\n\nfunction renderOpenGraphTags(metadata: ResolvedMetadata | undefined) {\n if (!metadata?.openGraph) {\n return [];\n }\n\n return [\n metadata.openGraph.title\n ? renderMetaTag({\n content: metadata.openGraph.title,\n kind: \"meta\",\n property: \"og:title\",\n })\n : null,\n metadata.openGraph.description\n ? renderMetaTag({\n content: metadata.openGraph.description,\n kind: \"meta\",\n property: \"og:description\",\n })\n : null,\n metadata.openGraph.image\n ? renderMetaTag({\n content: metadata.openGraph.image,\n kind: \"meta\",\n property: \"og:image\",\n })\n : null,\n ].filter((tag): tag is string => Boolean(tag));\n}\n\nfunction renderDocumentMetadataTag(tag: DocumentMetadataTag) {\n if (tag.kind === \"link\") {\n return renderLinkTag(tag);\n }\n\n return renderMetaTag(tag);\n}\n\nfunction renderStructuredDataTag(\n tag: StructuredDataTag,\n nonce: string | undefined,\n) {\n const ownership = nonce ? \"\" : ` ${STRUCTURED_DATA_ATTRIBUTE}`;\n\n return ` <script type=\"application/ld+json\"${ownership}${renderAttribute(\"nonce\", nonce)}>${escapeJsonScript(JSON.stringify(tag.value))}</script>`;\n}\n\nfunction renderMetaTag(tag: DocumentMetadataTag & { kind: \"meta\" }) {\n if (tag.name === \"charset\") {\n return ` <meta charset=\"${escapeHtml(tag.content)}\" />`;\n }\n\n const name = tag.name ? ` name=\"${escapeHtml(tag.name)}\"` : \"\";\n const property = tag.property ? ` property=\"${escapeHtml(tag.property)}\"` : \"\";\n\n return ` <meta${name}${property} content=\"${escapeHtml(tag.content)}\" />`;\n}\n\nfunction renderLinkTag(tag: LinkTag) {\n return ` <link${renderAttribute(\"rel\", tag.rel)}${renderAttribute(\"href\", tag.href)}${renderAttribute(\"as\", tag.as)}${renderAttribute(\"type\", tag.type)}${renderAttribute(\"crossorigin\", tag.crossOrigin)}${renderAttribute(\"hreflang\", tag.hrefLang)} />`;\n}\n\nfunction renderScriptTag(scriptTag: ScriptTag, nonce: string | undefined) {\n return `<script${renderAttribute(\"id\", scriptTag.id)}${renderAttribute(\"src\", scriptTag.src)}${renderAttribute(\"type\", scriptTag.type ?? scriptTypeForStrategy(scriptTag.strategy))}${renderAttribute(\"nonce\", scriptTag.nonce ?? nonce)}${renderAttribute(\"integrity\", scriptTag.integrity)}${renderAttribute(\"referrerpolicy\", scriptTag.referrerPolicy)}${renderAttribute(\"data-api\", scriptTag.dataApi)}${renderAttribute(\"data-domain\", scriptTag.dataDomain)}${renderAttribute(\"data-demiurge-script-placement\", scriptTag[scriptPlacement])}${renderBooleanAttribute(\"async\", scriptTag.async)}${renderBooleanAttribute(\"defer\", scriptTag.defer)}></script>`;\n}\n\nfunction scriptTypeForStrategy(strategy: ScriptTag[\"strategy\"]) {\n return strategy === \"module\" ? \"module\" : undefined;\n}\n\nfunction renderAttribute(name: string, value: string | undefined) {\n return value ? ` ${name}=\"${escapeHtml(value)}\"` : \"\";\n}\n\nfunction renderBooleanAttribute(name: string, value: boolean | undefined) {\n return value ? ` ${name}` : \"\";\n}\n\nfunction escapeHtml(value: string) {\n return value\n .replaceAll(\"&\", \"&amp;\")\n .replaceAll(\"<\", \"&lt;\")\n .replaceAll(\">\", \"&gt;\")\n .replaceAll('\"', \"&quot;\");\n}\n\nfunction escapeJsonScript(value: string) {\n return value\n .replaceAll(\"<\", \"\\\\u003c\")\n .replaceAll(\">\", \"\\\\u003e\")\n .replaceAll(\"
\", \"\\\\u2028\")\n .replaceAll(\"
\", \"\\\\u2029\");\n}\n","import { createElement, type ReactNode } from \"react\";\nimport {\n createScriptRenderContext,\n withScriptContext,\n type ScriptRenderContext,\n} from \"../document/scripts\";\nimport type { LoadedRouteMatch } from \"../router\";\n\nexport function createPageRenderTree(\n match: LoadedRouteMatch,\n scripts?: ScriptRenderContext,\n) {\n const page = createElement(match.page, {\n data: match.data,\n path: match.path,\n pathname: match.pathname,\n });\n\n const tree = match.layouts.reduceRight<ReactNode>(\n (children, Layout) =>\n createElement(Layout, {\n children,\n path: match.path,\n pathname: match.pathname,\n }),\n page,\n );\n\n return scripts ? withScriptContext(scripts, tree) : tree;\n}\n\nexport function createPageScriptContext(\n match: LoadedRouteMatch,\n options: { dev?: boolean; nonce?: string } = {},\n) {\n return createScriptRenderContext({\n dev: options.dev,\n nonce: options.nonce,\n scripts: match.scripts,\n });\n}\n","import { renderToString } from \"react-dom/server\";\nimport { renderDocument } from \"../document\";\nimport type { LoadedRouteMatch } from \"../router\";\nimport { createPageRenderTree, createPageScriptContext } from \"./render-tree\";\n\nexport type SsrOptions = {\n clientEntry?: string;\n lang?: string;\n navigation?: \"document\";\n styles?: string[];\n title?: string;\n};\n\nexport type SsrRenderOptions = SsrOptions & {\n dev?: boolean;\n nonce?: string;\n onStreamError?: (error: unknown) => void;\n signal?: AbortSignal;\n transformDocument?: (html: string) => string | Promise<string>;\n};\n\nexport function renderPageDocument(\n match: LoadedRouteMatch,\n options: SsrRenderOptions = {},\n) {\n const scripts = createPageScriptContext(match, options);\n const html = renderToString(createPageRenderTree(match, scripts));\n\n return renderDocument({\n body: {\n data: match.data,\n html,\n navigation: match.render.mode === \"static\"\n ? \"document\"\n : options.navigation,\n },\n entrySrc: options.clientEntry,\n lang: options.lang,\n links: match.links,\n metadata: match.metadata,\n nonce: options.nonce,\n scripts: scripts.scripts(),\n styles: options.styles,\n title: options.title,\n });\n}\n\nexport function renderPageResponse(\n match: LoadedRouteMatch,\n options: SsrRenderOptions = {},\n) {\n const html = renderPageDocument(match, options);\n\n return new Response(html, {\n headers: {\n \"content-type\": \"text/html; charset=utf-8\",\n },\n });\n}\n","export type RequestConnectionMetadata = {\n clientIp: string;\n};\n\nconst connectionMetadata = new WeakMap<Request, RequestConnectionMetadata>();\n\nexport function getRequestConnectionMetadata(request: Request) {\n return connectionMetadata.get(request);\n}\n\nexport function setRequestConnectionMetadata(\n request: Request,\n metadata: RequestConnectionMetadata,\n) {\n connectionMetadata.set(request, metadata);\n}\n\nexport function copyRequestConnectionMetadata(from: Request, to: Request) {\n const metadata = connectionMetadata.get(from);\n\n if (metadata) {\n connectionMetadata.set(to, metadata);\n }\n}\n"],"names":["defaultCapabilities","defineAdapter","definition","checkAdapterCapabilities","adapter","required","uniqueRequired","missing","capability","assertAdapterCapabilities","check","HYDRATION_DATA_ELEMENT_ID","HYDRATION_ROOT_ATTRIBUTE","HYDRATION_FALLBACK_ATTRIBUTE","serializeInitialRouteData","data","options","escapeJsonScript","readInitialRouteData","source","element","serialized","error","value","SCRIPT_STRATEGIES","scriptPlacement","ScriptContext","createContext","createScriptRenderContext","headFlushed","staticScripts","staticSources","tag","registeredSources","hoisted","scriptTag","sortScripts","Script","props","context","useContext","script","hasExistingScript","renderScriptElement","documentNonce","nonce","createElement","scriptTypeForStrategy","src","expected","defineScripts","contribution","strategy","withScriptContext","children","resolveScripts","contributions","scripts","resolved","dedupeScripts","deduped","scriptKey","compareScripts","left","right","scriptStrategyOrder","STRUCTURED_DATA_ATTRIBUTE","renderDocument","html","body","prefix","suffix","renderDocumentShell","renderDocumentWithoutBody","entrySrc","lang","links","metadata","styles","title","documentTitle","trailingBodyContent","renderScriptTag","renderBootstrapData","renderEntryScript","escapeHtml","renderHeadTags","renderRootStart","bodyContent","renderRootElement","fallback","navigation","renderAttribute","renderMetaTag","renderLinkTag","renderRobotsTags","renderOpenGraphTags","renderDocumentMetadataTag","renderStructuredDataTag","href","directives","name","property","renderBooleanAttribute","createPageRenderTree","match","page","tree","Layout","createPageScriptContext","renderPageDocument","renderToString","renderPageResponse","connectionMetadata","getRequestConnectionMetadata","request","setRequestConnectionMetadata","copyRequestConnectionMetadata","from","to"],"mappings":";;AA6BA,MAAMA,IAAsB;AAAA,EAC1B,oBAAoB;AAAA,EACpB,6BAA6B;AAAA,EAC7B,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,cAAc;AAChB;AAEO,SAASC,GAAcC,GAAwC;AACpE,SAAO;AAAA,IACL,cAAc;AAAA,MACZ,GAAGF;AAAA,MACH,GAAGE,EAAW;AAAA,IAAA;AAAA,IAEhB,MAAMA,EAAW;AAAA,EAAA;AAErB;AAEO,SAASC,EACdC,GACAC,GACwB;AACxB,QAAMC,IAAiB,CAAC,GAAG,IAAI,IAAID,CAAQ,CAAC,GACtCE,IAAUD,EAAe;AAAA,IAC7B,CAACE,MAAe,CAACJ,EAAQ,aAAaI,CAAU;AAAA,EAAA;AAGlD,SAAO;AAAA,IACL,SAASJ,EAAQ;AAAA,IACjB,SAAAG;AAAA,IACA,IAAIA,EAAQ,WAAW;AAAA,IACvB,UAAUD;AAAA,EAAA;AAEd;AAEO,SAASG,GACdL,GACAC,GACA;AACA,QAAMK,IAAQP,EAAyBC,GAASC,CAAQ;AAExD,MAAI,CAACK,EAAM;AACT,UAAM,IAAI;AA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