@demiurgejs/core 0.1.0 → 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 (96) hide show
  1. package/README.md +3 -0
  2. package/bin/demiurge.mjs +51 -0
  3. package/dist/browser/file-router.d.ts +5 -0
  4. package/dist/browser/file-router.d.ts.map +1 -1
  5. package/dist/chunks/request-metadata-DwEO1EAS.js +477 -0
  6. package/dist/chunks/request-metadata-DwEO1EAS.js.map +1 -0
  7. package/dist/chunks/static-files-DUjHw-4H.js +11 -0
  8. package/dist/chunks/static-files-DUjHw-4H.js.map +1 -0
  9. package/dist/chunks/{streaming-27pwhjGC.js → streaming-Ci6vf3BB.js} +117 -107
  10. package/dist/chunks/streaming-Ci6vf3BB.js.map +1 -0
  11. package/dist/chunks/{testing-BBnJ5WUR.js → testing-DBjVCN5v.js} +2384 -1941
  12. package/dist/chunks/testing-DBjVCN5v.js.map +1 -0
  13. package/dist/cli.d.ts +42 -0
  14. package/dist/cli.d.ts.map +1 -0
  15. package/dist/cli.js +164 -0
  16. package/dist/cli.js.map +1 -0
  17. package/dist/document/index.d.ts +2 -2
  18. package/dist/document/index.d.ts.map +1 -1
  19. package/dist/document/render.d.ts +2 -1
  20. package/dist/document/render.d.ts.map +1 -1
  21. package/dist/document/scripts.d.ts +22 -0
  22. package/dist/document/scripts.d.ts.map +1 -1
  23. package/dist/index.d.ts +7 -7
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +893 -1035
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal/testing.js +15 -14
  28. package/dist/internal/testing.js.map +1 -1
  29. package/dist/node/index.js +86 -85
  30. package/dist/node/index.js.map +1 -1
  31. package/dist/node/static.d.ts.map +1 -1
  32. package/dist/node/streaming.d.ts +2 -0
  33. package/dist/node/streaming.d.ts.map +1 -1
  34. package/dist/route/action.d.ts +11 -11
  35. package/dist/route/action.d.ts.map +1 -1
  36. package/dist/route/index.d.ts +2 -1
  37. package/dist/route/index.d.ts.map +1 -1
  38. package/dist/route/middleware.d.ts +7 -0
  39. package/dist/route/middleware.d.ts.map +1 -0
  40. package/dist/route/page.d.ts +2 -2
  41. package/dist/route/page.d.ts.map +1 -1
  42. package/dist/route/response.d.ts +19 -19
  43. package/dist/route/response.d.ts.map +1 -1
  44. package/dist/route/types.d.ts +55 -31
  45. package/dist/route/types.d.ts.map +1 -1
  46. package/dist/route/webhook.d.ts +1 -1
  47. package/dist/router/manifest.d.ts +4 -1
  48. package/dist/router/manifest.d.ts.map +1 -1
  49. package/dist/routing/generate.d.ts +2 -0
  50. package/dist/routing/generate.d.ts.map +1 -1
  51. package/dist/routing/index.d.ts +1 -1
  52. package/dist/routing/index.d.ts.map +1 -1
  53. package/dist/routing/types.d.ts +2 -0
  54. package/dist/routing/types.d.ts.map +1 -1
  55. package/dist/security/cors.d.ts.map +1 -1
  56. package/dist/security/index.d.ts +4 -2
  57. package/dist/security/index.d.ts.map +1 -1
  58. package/dist/security/policy.d.ts +31 -2
  59. package/dist/security/policy.d.ts.map +1 -1
  60. package/dist/security/types.d.ts +27 -13
  61. package/dist/security/types.d.ts.map +1 -1
  62. package/dist/security/verification.d.ts +8 -0
  63. package/dist/security/verification.d.ts.map +1 -0
  64. package/dist/server/errors.d.ts.map +1 -1
  65. package/dist/server/not-found.d.ts.map +1 -1
  66. package/dist/server/render-tree.d.ts +6 -1
  67. package/dist/server/render-tree.d.ts.map +1 -1
  68. package/dist/server/request-handler.d.ts +4 -1
  69. package/dist/server/request-handler.d.ts.map +1 -1
  70. package/dist/server/ssr.d.ts +1 -0
  71. package/dist/server/ssr.d.ts.map +1 -1
  72. package/dist/static/index.d.ts +15 -0
  73. package/dist/static/index.d.ts.map +1 -1
  74. package/dist/static/index.js +684 -123
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/preview.d.ts +8 -0
  77. package/dist/static/preview.d.ts.map +1 -0
  78. package/dist/static/vercel.d.ts +31 -0
  79. package/dist/static/vercel.d.ts.map +1 -0
  80. package/dist/static-files.d.ts +5 -0
  81. package/dist/static-files.d.ts.map +1 -0
  82. package/dist/vite/index.d.ts +3 -2
  83. package/dist/vite/index.d.ts.map +1 -1
  84. package/dist/vite/index.js +882 -288
  85. package/dist/vite/index.js.map +1 -1
  86. package/dist/vite/plugin.d.ts +13 -0
  87. package/dist/vite/plugin.d.ts.map +1 -1
  88. package/dist/vite/policy-verification.d.ts +10 -0
  89. package/dist/vite/policy-verification.d.ts.map +1 -0
  90. package/package.json +9 -1
  91. package/dist/chunks/index-BnX9Qxbm.js +0 -44
  92. package/dist/chunks/index-BnX9Qxbm.js.map +0 -1
  93. package/dist/chunks/ssr-O3d7Q73U.js +0 -273
  94. package/dist/chunks/ssr-O3d7Q73U.js.map +0 -1
  95. package/dist/chunks/streaming-27pwhjGC.js.map +0 -1
  96. package/dist/chunks/testing-BBnJ5WUR.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,33 +1,91 @@
1
1
  import { jsx as H } from "react/jsx-runtime";
2
- import { createContext as W, useState as I, useRef as k, useEffect as C, useMemo as _, createElement as f, useContext as V, Component as G } from "react";
3
- import { e as K, H as Y, f as Z } from "./chunks/ssr-O3d7Q73U.js";
4
- import { r as mr } from "./chunks/ssr-O3d7Q73U.js";
5
- import { e as Q, t as X, p as D, s as J, g as ee, c as L, l as te, i as O, j as re, N as z, k as ne, m as ae, n as ie, o as se, H as oe, q as ce, B as ue, u as le, v as fe, w as de, x as he, y as me, R as pe, z as A } from "./chunks/testing-BBnJ5WUR.js";
6
- import { A as gr, C as wr, D as yr, E as vr, F as br, G as Sr, I as Er, J as Rr, b as $r, K as xr, d as Ar, L as Tr, M as Ir, O as kr, P as Cr, Q as Dr, S as zr, T as Pr, U as Lr, V as Or, W as Nr, h as Ur, X as Mr, Y as Fr, Z as jr, _ as qr, $ as Br, a0 as Hr, a1 as Wr, a2 as _r, a3 as Vr, a4 as Gr, a5 as Kr, a6 as Yr, a7 as Zr, a8 as Qr, a9 as Xr, aa as Jr, ab as en, ac as tn, ad as rn, ae as nn, af as an, ag as sn, ah as on, ai as cn, aj as un, ak as ln, al as fn, am as dn, an as hn, ao as mn } from "./chunks/testing-BBnJ5WUR.js";
7
- import { a as gn, c as wn, d as yn } from "./chunks/index-BnX9Qxbm.js";
2
+ import { createContext as _, useState as I, useRef as T, useEffect as C, useMemo as V, createElement as f, useContext as W, Component as G } from "react";
3
+ import { g as K, H as Y, h as Z, i as Q } from "./chunks/request-metadata-DwEO1EAS.js";
4
+ import { j as Qt, k as Xt, l as Jt, d as er, m as tr, r as rr, n as nr } from "./chunks/request-metadata-DwEO1EAS.js";
5
+ import { p as z, k as X, l as J, t as ee, n as te, R as re, o as x, q as ne, j as O, u as ae, w as L, x as ie, N as D, y as oe, z as se, A as ce, B as ue, H as le, C as fe, D as de, E as me } from "./chunks/testing-DBjVCN5v.js";
6
+ import { F as ir, G as or, I as sr, J as cr, K as ur, L as lr, M as fr, O as dr, P as mr, a as hr, Q as gr, S as pr, d as wr, b as yr, T as vr, U as br, V as Er, W as Sr, X as Rr, Y as Ar, Z as $r, _ as xr, $ as kr, a0 as Ir, h as Tr, a1 as Cr, a2 as zr, a3 as Dr, a4 as Nr, a5 as Or, a6 as Lr, a7 as Mr, m as Pr, a8 as Ur, a9 as Fr, aa as jr, ab as Br, ac as qr, ad as Hr, ae as _r, af as Vr, ag as Wr, ah as Gr, ai as Kr, s as Yr, aj as Zr, ak as Qr, al as Xr, am as Jr, an as en, ao as tn, ap as rn, aq as nn, e as an, f as on, v as sn } from "./chunks/testing-DBjVCN5v.js";
8
7
  import "react-dom/server";
9
- function Nt(e) {
8
+ const he = "24h", ge = 1e4;
9
+ function vt(e = {}) {
10
+ const t = e.now ?? Date.now, r = e.defaultTtl ?? he, n = e.maximumEntries ?? ge;
11
+ if (!Number.isSafeInteger(n) || n <= 0)
12
+ throw new Error(
13
+ "Demiurge idempotency maximumEntries must be a positive integer."
14
+ );
15
+ const a = z(r);
16
+ if (!Number.isFinite(a))
17
+ throw new Error("Demiurge idempotency defaultTtl must be finite.");
18
+ const i = /* @__PURE__ */ new Map();
19
+ return {
20
+ async run(s) {
21
+ const o = X(s.key), u = t();
22
+ pe(i, u);
23
+ const d = i.get(o);
24
+ if (d && (d.pending || d.expiresAt > u))
25
+ return {
26
+ key: o,
27
+ replayed: !0,
28
+ value: await d.value
29
+ };
30
+ if (i.size >= n && we(i), i.size >= n)
31
+ throw new Error(
32
+ "Demiurge idempotency store is at capacity with in-flight mutations."
33
+ );
34
+ const p = Promise.resolve().then(s.fn), c = {
35
+ expiresAt: Number.POSITIVE_INFINITY,
36
+ pending: !0,
37
+ value: p
38
+ };
39
+ i.set(o, c);
40
+ try {
41
+ const l = await p;
42
+ return c.pending = !1, c.expiresAt = t() + z(s.ttl ?? r), {
43
+ key: o,
44
+ replayed: !1,
45
+ value: l
46
+ };
47
+ } catch (l) {
48
+ throw i.get(o) === c && i.delete(o), l;
49
+ }
50
+ }
51
+ };
52
+ }
53
+ function pe(e, t) {
54
+ for (const [r, n] of e)
55
+ !n.pending && n.expiresAt <= t && e.delete(r);
56
+ }
57
+ function we(e) {
58
+ for (const [t, r] of e)
59
+ if (!r.pending) {
60
+ e.delete(t);
61
+ return;
62
+ }
63
+ }
64
+ function bt(e, t) {
65
+ return e.run(t);
66
+ }
67
+ function Et(e) {
10
68
  return {
11
69
  entries: e
12
70
  };
13
71
  }
14
- function Ut(e) {
72
+ function St(e) {
15
73
  return [
16
74
  '<?xml version="1.0" encoding="UTF-8"?>',
17
75
  `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${e.entries.some((r) => r.alternates?.length) ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : ""}>`,
18
- ...e.entries.map(we),
76
+ ...e.entries.map(ve),
19
77
  "</urlset>",
20
78
  ""
21
79
  ].join(`
22
80
  `);
23
81
  }
24
- function Mt(e) {
82
+ function Rt(e) {
25
83
  return e;
26
84
  }
27
- function Ft(e) {
85
+ function At(e) {
28
86
  return e;
29
87
  }
30
- function jt(e) {
88
+ function $t(e) {
31
89
  const t = [];
32
90
  for (const r of e.rules ?? []) {
33
91
  for (const n of b(r.userAgent))
@@ -45,44 +103,44 @@ function jt(e) {
45
103
  `).replace(/\n+$/, "")}
46
104
  `;
47
105
  }
48
- function ge(e) {
49
- const t = e.width ?? 1200, r = e.height ?? 630, n = e.background ?? "#101820", a = e.foreground ?? "#ffffff", i = $(e.title, 120), o = e.subtitle ? $(e.subtitle, 160) : void 0, s = e.brand ? $(e.brand, 80) : void 0;
50
- return be(t, r), [
51
- `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${r}" viewBox="0 0 ${t} ${r}" role="img" aria-label="${p(i)}">`,
52
- ` <rect width="100%" height="100%" fill="${p(n)}" />`,
53
- s ? ` <text x="72" y="96" fill="${p(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="32" font-weight="700">${w(s)}</text>` : null,
54
- ` <text x="72" y="${o ? 300 : 340}" fill="${p(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="76" font-weight="800">${w(i)}</text>`,
55
- o ? ` <text x="72" y="392" fill="${p(a)}" fill-opacity="0.78" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="38" font-weight="500">${w(o)}</text>` : null,
106
+ function ye(e) {
107
+ const t = e.width ?? 1200, r = e.height ?? 630, n = e.background ?? "#101820", a = e.foreground ?? "#ffffff", i = A(e.title, 120), s = e.subtitle ? A(e.subtitle, 160) : void 0, o = e.brand ? A(e.brand, 80) : void 0;
108
+ return Se(t, r), [
109
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${r}" viewBox="0 0 ${t} ${r}" role="img" aria-label="${g(i)}">`,
110
+ ` <rect width="100%" height="100%" fill="${g(n)}" />`,
111
+ o ? ` <text x="72" y="96" fill="${g(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="32" font-weight="700">${w(o)}</text>` : null,
112
+ ` <text x="72" y="${s ? 300 : 340}" fill="${g(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="76" font-weight="800">${w(i)}</text>`,
113
+ s ? ` <text x="72" y="392" fill="${g(a)}" fill-opacity="0.78" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="38" font-weight="500">${w(s)}</text>` : null,
56
114
  "</svg>"
57
115
  ].filter((u) => !!u).join(`
58
116
  `);
59
117
  }
60
- function qt(e) {
61
- return new Response(ge(e), {
118
+ function xt(e) {
119
+ return new Response(ye(e), {
62
120
  headers: {
63
121
  "cache-control": "public, max-age=31536000, immutable",
64
122
  "content-type": "image/svg+xml; charset=utf-8"
65
123
  }
66
124
  });
67
125
  }
68
- function we(e) {
126
+ function ve(e) {
69
127
  return [
70
128
  " <url>",
71
129
  ` <loc>${w(e.url)}</loc>`,
72
- e.lastModified ? ` <lastmod>${w(ye(e.lastModified))}</lastmod>` : null,
130
+ e.lastModified ? ` <lastmod>${w(be(e.lastModified))}</lastmod>` : null,
73
131
  e.changeFrequency ? ` <changefreq>${e.changeFrequency}</changefreq>` : null,
74
- e.priority !== void 0 ? ` <priority>${ve(e.priority)}</priority>` : null,
132
+ e.priority !== void 0 ? ` <priority>${Ee(e.priority)}</priority>` : null,
75
133
  ...(e.alternates ?? []).map(
76
- (t) => ` <xhtml:link rel="alternate" hreflang="${p(t.hrefLang)}" href="${p(t.href)}" />`
134
+ (t) => ` <xhtml:link rel="alternate" hreflang="${g(t.hrefLang)}" href="${g(t.href)}" />`
77
135
  ),
78
136
  " </url>"
79
137
  ].filter((t) => !!t).join(`
80
138
  `);
81
139
  }
82
- function ye(e) {
140
+ function be(e) {
83
141
  return e instanceof Date ? e.toISOString() : e;
84
142
  }
85
- function ve(e) {
143
+ function Ee(e) {
86
144
  if (e < 0 || e > 1)
87
145
  throw new Error("Sitemap entry priority must be between 0 and 1.");
88
146
  return String(e);
@@ -93,25 +151,25 @@ function b(e) {
93
151
  function w(e) {
94
152
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
95
153
  }
96
- function p(e) {
154
+ function g(e) {
97
155
  return w(e).replaceAll('"', "&quot;").replaceAll("'", "&apos;");
98
156
  }
99
- function $(e, t) {
157
+ function A(e, t) {
100
158
  return e.length > t ? `${e.slice(0, t - 3)}...` : e;
101
159
  }
102
- function be(e, t) {
160
+ function Se(e, t) {
103
161
  if (!Number.isSafeInteger(e) || e <= 0)
104
162
  throw new Error("OG image width must be a positive integer.");
105
163
  if (!Number.isSafeInteger(t) || t <= 0)
106
164
  throw new Error("OG image height must be a positive integer.");
107
165
  }
108
- function Bt(e) {
109
- return Q(
166
+ function kt(e) {
167
+ return J(
110
168
  async (t) => {
111
169
  const r = e.input ? await e.input(t) : void 0, n = {
112
170
  ...t,
113
171
  input: r
114
- }, a = async () => await Se(
172
+ }, a = async () => await Re(
115
173
  await e.handler(n),
116
174
  t
117
175
  );
@@ -131,7 +189,7 @@ function Bt(e) {
131
189
  }
132
190
  );
133
191
  }
134
- const Ht = {
192
+ const It = {
135
193
  async formData({ request: e }) {
136
194
  return await e.formData();
137
195
  },
@@ -142,10 +200,10 @@ const Ht = {
142
200
  return await e.text();
143
201
  }
144
202
  };
145
- async function Se(e, t) {
146
- return e instanceof Response ? e : await X(e, t);
203
+ async function Re(e, t) {
204
+ return e instanceof Response ? e : await ee(e, t);
147
205
  }
148
- function Wt(e) {
206
+ function Tt(e) {
149
207
  return typeof e == "function" ? {
150
208
  kind: "page",
151
209
  render: { mode: "ssr" },
@@ -158,7 +216,10 @@ function Wt(e) {
158
216
  view: e.view
159
217
  };
160
218
  }
161
- const _t = {
219
+ function Ct(e) {
220
+ return e;
221
+ }
222
+ const zt = {
162
223
  hmac(e) {
163
224
  return {
164
225
  kind: "response",
@@ -166,7 +227,7 @@ const _t = {
166
227
  const r = new Uint8Array(await t.request.arrayBuffer()), n = t.request.headers.get(
167
228
  e.header ?? "x-webhook-signature"
168
229
  );
169
- return n ? await Ee(r, n, e) ? await e.handler({
230
+ return n ? await Ae(r, n, e) ? await e.handler({
170
231
  ...t,
171
232
  rawBody: r,
172
233
  text: () => new TextDecoder().decode(r)
@@ -182,15 +243,15 @@ const _t = {
182
243
  };
183
244
  }
184
245
  };
185
- async function Ee(e, t, r) {
186
- const n = r.algorithm ?? "SHA-256", a = r.encoding ?? "hex", i = Re(
246
+ async function Ae(e, t, r) {
247
+ const n = r.algorithm ?? "SHA-256", a = r.encoding ?? "hex", i = $e(
187
248
  t,
188
249
  n,
189
250
  r.prefix
190
- ), o = $e(i, a);
191
- if (!o)
251
+ ), s = xe(i, a);
252
+ if (!s)
192
253
  return !1;
193
- const s = await globalThis.crypto.subtle.importKey(
254
+ const o = await globalThis.crypto.subtle.importKey(
194
255
  "raw",
195
256
  new TextEncoder().encode(r.secret),
196
257
  {
@@ -202,16 +263,16 @@ async function Ee(e, t, r) {
202
263
  );
203
264
  return await globalThis.crypto.subtle.verify(
204
265
  "HMAC",
205
- s,
206
266
  o,
267
+ s,
207
268
  Uint8Array.from(e).buffer
208
269
  );
209
270
  }
210
- function Re(e, t, r) {
271
+ function $e(e, t, r) {
211
272
  const n = e.trim(), a = r === void 0 ? `${t.toLowerCase().replace("-", "")}=` : r;
212
273
  return a !== !1 && n.startsWith(a) ? n.slice(a.length).trim() : n;
213
274
  }
214
- function $e(e, t) {
275
+ function xe(e, t) {
215
276
  if (t === "hex")
216
277
  return /^(?:[0-9a-f]{2})+$/i.test(e) ? Uint8Array.from(
217
278
  e.match(/.{2}/g) ?? [],
@@ -228,1091 +289,888 @@ function $e(e, t) {
228
289
  return null;
229
290
  }
230
291
  }
231
- const xe = "24h", Ae = 1e4;
232
- function Vt(e = {}) {
233
- const t = e.now ?? Date.now, r = e.defaultTtl ?? xe, n = e.maximumEntries ?? Ae;
234
- if (!Number.isSafeInteger(n) || n <= 0)
235
- throw new Error(
236
- "Demiurge idempotency maximumEntries must be a positive integer."
237
- );
238
- const a = D(r);
239
- if (!Number.isFinite(a))
240
- throw new Error("Demiurge idempotency defaultTtl must be finite.");
241
- const i = /* @__PURE__ */ new Map();
242
- return {
243
- async run(o) {
244
- const s = J(o.key), u = t();
245
- Te(i, u);
246
- const d = i.get(s);
247
- if (d && (d.pending || d.expiresAt > u))
248
- return {
249
- key: s,
250
- replayed: !0,
251
- value: await d.value
252
- };
253
- if (i.size >= n && Ie(i), i.size >= n)
254
- throw new Error(
255
- "Demiurge idempotency store is at capacity with in-flight mutations."
256
- );
257
- const g = Promise.resolve().then(o.fn), c = {
258
- expiresAt: Number.POSITIVE_INFINITY,
259
- pending: !0,
260
- value: g
261
- };
262
- i.set(s, c);
263
- try {
264
- const l = await g;
265
- return c.pending = !1, c.expiresAt = t() + D(o.ttl ?? r), {
266
- key: s,
267
- replayed: !1,
268
- value: l
269
- };
270
- } catch (l) {
271
- throw i.get(s) === c && i.delete(s), l;
272
- }
273
- }
274
- };
275
- }
276
- function Te(e, t) {
277
- for (const [r, n] of e)
278
- !n.pending && n.expiresAt <= t && e.delete(r);
279
- }
280
- function Ie(e) {
281
- for (const [t, r] of e)
282
- if (!r.pending) {
283
- e.delete(t);
284
- return;
285
- }
292
+ class ke extends Error {
293
+ issues;
294
+ constructor(t) {
295
+ super(Oe(t)), this.name = "EnvValidationError", this.issues = t;
296
+ }
286
297
  }
287
- function Gt(e, t) {
288
- return e.run(t);
298
+ function Dt(e) {
299
+ return e;
289
300
  }
290
- function ke(e) {
291
- const t = L(e.routes), r = e.loadNavigationData ?? U;
292
- return function() {
293
- const [a, i] = I(() => S()), [o, s] = I(
294
- () => e.initialMatch ?? { status: "loading" }
295
- ), u = k(!!e.initialMatch), d = k(0);
296
- C(() => {
297
- function c() {
298
- i(S());
301
+ function Nt(e, t) {
302
+ const r = [], n = {};
303
+ for (const a of Object.keys(e)) {
304
+ const i = e[a], s = t[String(a)];
305
+ if (s === void 0 || s === "") {
306
+ if (i.optional) {
307
+ n[a] = void 0;
308
+ continue;
299
309
  }
300
- return window.addEventListener("popstate", c), () => window.removeEventListener("popstate", c);
301
- }, []), C(() => {
302
- let c = !1, l = !1;
303
- const h = ++d.current, R = new AbortController(), v = () => !c && h === d.current;
304
- if (u.current && De(e.initialMatch) === a.pathname)
305
- return u.current = !1, () => {
306
- c = !0;
307
- };
308
- s({ status: "loading" }), te(t, a.pathname).then((m) => {
309
- v() && !l && m && s({ loading: m, status: "loading" });
310
- }).catch(() => {
310
+ r.push({
311
+ code: "missing",
312
+ key: String(a),
313
+ message: `Environment variable ${String(a)} is required.`
311
314
  });
312
- const T = new Request(a.href, { signal: R.signal });
313
- return Promise.resolve(r(T)).then(
314
- (m) => O(
315
- t,
316
- a.pathname,
317
- T,
318
- m,
319
- void 0,
320
- { documentContributions: !1 }
321
- )
322
- ).then((m) => {
323
- l = !0, v() && s(m);
324
- }).catch(async (m) => {
325
- if (l = !0, !v() || R.signal.aborted)
326
- return;
327
- const B = await re(
328
- t,
329
- a.pathname
330
- );
331
- v() && s({
332
- Error: B,
333
- error: m,
334
- pathname: a.pathname,
335
- status: "error"
336
- });
337
- }), () => {
338
- c = !0, R.abort();
339
- };
340
- }, [a.pathname, a.search]);
341
- const g = _(
342
- () => ({
343
- navigation: e.navigation ?? "server",
344
- push(c) {
345
- const l = S();
346
- window.history.pushState(null, "", c);
347
- const h = S();
348
- i(h), l.pathname === h.pathname && l.search === h.search && l.hash !== h.hash && Oe(h.hash);
349
- }
350
- }),
351
- []
352
- );
353
- return f(M.Provider, {
354
- value: g,
355
- children: f(ze, {
356
- key: `${a.pathname}${a.search}`,
357
- Loading: e.loading,
358
- NotFound: e.notFound,
359
- match: o
360
- })
361
- });
362
- };
363
- }
364
- function Ce(e, t) {
365
- const r = t.getAttribute(Z);
366
- return e.status === "not-found" ? r === "not-found" : e.status === "ready" && r === null;
315
+ continue;
316
+ }
317
+ try {
318
+ n[a] = i.parse(String(a), s);
319
+ } catch (o) {
320
+ r.push({
321
+ code: "invalid",
322
+ key: String(a),
323
+ message: o instanceof Error ? o.message : `Environment variable ${String(a)} is invalid.`
324
+ });
325
+ }
326
+ }
327
+ if (r.length)
328
+ throw new ke(r);
329
+ return n;
367
330
  }
368
- function De(e) {
369
- if (e)
370
- return e.status === "ready" ? e.match.pathname : e.status === "loading" ? void 0 : e.pathname;
331
+ function Ie(e = {}) {
332
+ return y(e, !1, (t, r) => {
333
+ if (r === "true" || r === "1")
334
+ return !0;
335
+ if (r === "false" || r === "0")
336
+ return !1;
337
+ throw new Error(`Environment variable ${t} must be true, false, 1, or 0.`);
338
+ });
371
339
  }
372
- async function Kt(e) {
373
- const t = e.root ?? document.getElementById("root");
374
- if (!t)
340
+ function Te(e, t = {}) {
341
+ return y(t, !1, (r, n) => {
342
+ if (e.includes(n))
343
+ return n;
375
344
  throw new Error(
376
- "Demiurge expected a #root element in the framework document."
345
+ `Environment variable ${r} must be one of: ${e.join(", ")}.`
377
346
  );
378
- const r = L(e.routes), n = e.loadNavigationData ?? U, a = e.initialData ?? K(document), i = await O(
379
- r,
380
- window.location.pathname,
381
- new Request(window.location.href),
382
- a ?? await n(new Request(window.location.href)),
383
- void 0,
384
- { documentContributions: !1 }
385
- ), o = Ce(i, t), s = ke(
386
- o ? {
387
- ...e,
388
- initialMatch: i,
389
- loadNavigationData: n,
390
- navigation: a?.navigation ?? e.navigation
391
- } : {
392
- ...e,
393
- loadNavigationData: n,
394
- navigation: a?.navigation ?? e.navigation
395
- }
396
- ), { createRoot: u, hydrateRoot: d } = await import("react-dom/client");
397
- if (o && t.hasAttribute(Y)) {
398
- d(t, f(s));
399
- return;
400
- }
401
- t.replaceChildren(), u(t).render(f(s));
347
+ });
402
348
  }
403
- function Yt(e) {
404
- const t = Ue(), r = ee(e);
405
- return /* @__PURE__ */ H(
406
- "a",
407
- {
408
- className: e.className,
409
- href: r,
410
- onClick: (n) => {
411
- t.navigation === "server" && Ne(n) && (n.preventDefault(), t.push(r));
412
- },
413
- children: e.children
414
- }
349
+ function Ce(e = {}) {
350
+ return y(e, !1, (t, r) => {
351
+ if (!/^-?\d+$/.test(r))
352
+ throw new Error(`Environment variable ${t} must be an integer.`);
353
+ const n = Number(r);
354
+ if (!Number.isSafeInteger(n))
355
+ throw new Error(`Environment variable ${t} must be a safe integer.`);
356
+ if (e.min !== void 0 && n < e.min)
357
+ throw new Error(
358
+ `Environment variable ${t} must be greater than or equal to ${e.min}.`
359
+ );
360
+ if (e.max !== void 0 && n > e.max)
361
+ throw new Error(
362
+ `Environment variable ${t} must be less than or equal to ${e.max}.`
363
+ );
364
+ return n;
365
+ });
366
+ }
367
+ function ze(e = {}) {
368
+ return y(
369
+ e,
370
+ !0,
371
+ (t, r) => M(t, r, e)
415
372
  );
416
373
  }
417
- function ze({
418
- Loading: e,
419
- NotFound: t,
420
- match: r
421
- }) {
422
- if (r.status === "loading") {
423
- const c = r.loading ?? e;
424
- return c ? f(c) : null;
425
- }
426
- if (r.status === "not-found") {
427
- const c = r.notFound ?? t ?? ue;
428
- return r.layouts.reduceRight(
429
- (l, h) => f(h, {
430
- children: l,
431
- path: {},
432
- pathname: r.pathname
433
- }),
434
- f(c, { pathname: r.pathname })
435
- );
436
- }
437
- if (r.status === "error")
438
- return r.Error ? f(r.Error, {
439
- error: r.error,
440
- pathname: r.pathname,
441
- status: N(r.error)
442
- }) : null;
443
- const { data: n, error: a, page: i, layouts: o, path: s, pathname: u } = r.match, d = f(i, { data: n, path: s, pathname: u }), g = o.reduceRight(
444
- (c, l) => f(l, { path: s, pathname: u, children: c }),
445
- d
374
+ function De(e = {}) {
375
+ return y(
376
+ e,
377
+ !1,
378
+ (t, r) => M(t, r, e)
446
379
  );
447
- return f(Pe, {
448
- Error: a,
449
- children: g,
450
- pathname: u
451
- });
452
380
  }
453
- class Pe extends G {
454
- static getDerivedStateFromError(t) {
455
- return { error: t };
456
- }
457
- state = {};
458
- componentDidUpdate(t) {
459
- this.state.error !== void 0 && t.pathname !== this.props.pathname && this.setState({ error: void 0 });
460
- }
461
- render() {
462
- return this.state.error !== void 0 ? this.props.Error ? f(this.props.Error, {
463
- error: this.state.error,
464
- pathname: this.props.pathname,
465
- status: N(this.state.error)
466
- }) : null : this.props.children;
467
- }
468
- }
469
- function N(e) {
470
- return le(e) ? e.status : 500;
381
+ function Ne(e = {}) {
382
+ return y(e, !1, (t, r) => {
383
+ let n;
384
+ try {
385
+ n = new URL(r);
386
+ } catch {
387
+ throw new Error(`Environment variable ${t} must be a valid URL.`);
388
+ }
389
+ if (e.protocols?.length && !e.protocols.includes(n.protocol))
390
+ throw new Error(
391
+ `Environment variable ${t} must use one of these protocols: ${e.protocols.join(", ")}.`
392
+ );
393
+ return n;
394
+ });
471
395
  }
472
- function S() {
396
+ const Ot = {
397
+ boolean: Ie,
398
+ enum: Te,
399
+ integer: Ce,
400
+ secret: ze,
401
+ string: De,
402
+ url: Ne
403
+ };
404
+ function y(e, t, r) {
473
405
  return {
474
- hash: window.location.hash,
475
- href: window.location.href,
476
- pathname: window.location.pathname,
477
- search: window.location.search
406
+ optional: e.optional ?? !1,
407
+ parse: r,
408
+ sensitive: t
478
409
  };
479
410
  }
480
- async function U(e) {
481
- const t = new Headers(e.headers);
482
- t.set("accept", "application/json"), t.set(z, ne);
483
- const r = await fetch(new Request(e, {
484
- credentials: "same-origin",
485
- headers: t
486
- })), n = r.headers.get(z);
487
- if (n === ae) {
488
- const a = await r.json();
489
- if (a.hasData !== !0)
490
- throw new Error("Demiurge received malformed navigation route data.");
491
- return { data: a.data, hasData: !0 };
492
- }
493
- if (n === ie)
494
- return { hasData: !0 };
495
- if (n === se || !r.ok) {
496
- const a = await Le(r), i = oe.includes(
497
- r.status
498
- ) ? r.status : 500;
499
- throw ce(i, {
500
- detail: typeof a?.detail == "string" ? a.detail : void 0,
501
- title: typeof a?.title == "string" ? a.title : void 0
502
- });
503
- }
504
- throw new Error(
505
- "Demiurge expected a navigation data response from the application server."
506
- );
507
- }
508
- async function Le(e) {
509
- try {
510
- return await e.json();
511
- } catch {
512
- return;
513
- }
411
+ function M(e, t, r) {
412
+ if (r.minLength !== void 0 && t.length < r.minLength)
413
+ throw new Error(
414
+ `Environment variable ${e} must be at least ${r.minLength} characters.`
415
+ );
416
+ return t;
514
417
  }
515
418
  function Oe(e) {
516
- queueMicrotask(() => {
517
- if (!e) {
518
- window.scrollTo?.(0, 0);
519
- return;
520
- }
521
- let t;
419
+ return e.length === 1 ? e[0].message : `Environment validation failed with ${e.length} issues.`;
420
+ }
421
+ function Lt(e = {}) {
422
+ return async function(r) {
423
+ if (r.method.toUpperCase() !== "POST")
424
+ return new Response(null, {
425
+ headers: {
426
+ allow: "POST"
427
+ },
428
+ status: 405
429
+ });
430
+ const n = Me(r);
431
+ if (n)
432
+ return n;
433
+ const a = Pe(e, r);
434
+ if (a)
435
+ return a;
436
+ e.maxBodySize !== void 0 && (r = te({ maxBodySize: e.maxBodySize }, r));
437
+ let i;
522
438
  try {
523
- t = decodeURIComponent(e.slice(1));
524
- } catch {
525
- t = e.slice(1);
439
+ i = await r.json();
440
+ } catch (o) {
441
+ return o instanceof re ? new Response("Security report body too large.", { status: 413 }) : new Response("Invalid security report JSON.", {
442
+ status: 400
443
+ });
526
444
  }
527
- document.getElementById(t)?.scrollIntoView?.();
445
+ const s = Ue(i);
446
+ for (let o = 0; o < s.length; o += 1)
447
+ await e.onReport?.(s[o], {
448
+ index: o,
449
+ request: r
450
+ });
451
+ return new Response(null, {
452
+ status: 204
453
+ });
454
+ };
455
+ }
456
+ const Le = /* @__PURE__ */ new Set([
457
+ "application/csp-report",
458
+ "application/reports+json"
459
+ ]);
460
+ function Me(e) {
461
+ const t = e.headers.get("content-type");
462
+ if (!t)
463
+ return null;
464
+ const r = t.split(";", 1)[0]?.trim().toLowerCase();
465
+ return r && Le.has(r) ? null : new Response("Unsupported security report Content-Type.", {
466
+ status: 415
528
467
  });
529
468
  }
530
- function Ne(e) {
531
- return e.button === 0 && !e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey;
469
+ function Pe(e, t) {
470
+ if (e.maxBodySize === void 0)
471
+ return null;
472
+ const r = t.headers.get("content-length");
473
+ if (!r)
474
+ return null;
475
+ if (!/^\d+$/.test(r))
476
+ return new Response("Invalid Content-Length.", {
477
+ status: 400
478
+ });
479
+ const n = Number(r);
480
+ return Number.isSafeInteger(n) ? n > x(e.maxBodySize) ? new Response("Security report body too large.", {
481
+ status: 413
482
+ }) : null : new Response("Invalid Content-Length.", {
483
+ status: 400
484
+ });
532
485
  }
533
- const M = W({
534
- navigation: "document",
535
- push(e) {
536
- window.location.href = e;
486
+ function Ue(e) {
487
+ return Array.isArray(e) ? e : Fe(e) && "csp-report" in e ? [e["csp-report"]] : [e];
488
+ }
489
+ function Fe(e) {
490
+ return typeof e == "object" && e !== null;
491
+ }
492
+ function Mt(e, t) {
493
+ const r = {}, n = [];
494
+ let a = 0;
495
+ for (const [i, s] of Object.entries(t.files)) {
496
+ const o = e.getAll(i).filter(qe);
497
+ r[i] = o, s.required && o.length === 0 && n.push({
498
+ code: "file-missing",
499
+ field: i,
500
+ message: `Upload field ${i} requires at least one file.`
501
+ });
502
+ for (const u of o)
503
+ a += u.size, je(i, u, s, n);
537
504
  }
538
- });
539
- function Ue() {
540
- return V(M);
505
+ return t.maxTotalSize !== void 0 && a > x(t.maxTotalSize) && n.push({
506
+ code: "total-upload-too-large",
507
+ field: "*",
508
+ message: `Uploaded files exceed the maximum total size of ${t.maxTotalSize}.`
509
+ }), {
510
+ files: r,
511
+ issues: n,
512
+ ok: n.length === 0,
513
+ totalSize: a
514
+ };
541
515
  }
542
- const Me = "/_demiurge/image";
543
- function Zt(e) {
544
- return e;
516
+ function je(e, t, r, n) {
517
+ r.maxSize !== void 0 && t.size > x(r.maxSize) && n.push({
518
+ code: "file-too-large",
519
+ field: e,
520
+ message: `Upload field ${e} contains ${t.name || "a file"} larger than ${r.maxSize}.`
521
+ }), r.types?.length && !Be(t.type, r.types) && n.push({
522
+ code: "file-type-not-allowed",
523
+ field: e,
524
+ message: `Upload field ${e} contains ${t.name || "a file"} with disallowed type ${t.type || "unknown"}.`
525
+ });
526
+ }
527
+ function Be(e, t) {
528
+ return t.some((r) => r.endsWith("/*") ? e.startsWith(r.slice(0, -1)) : e === r);
545
529
  }
546
- function Qt(e, t = {}) {
547
- return F(e, t) !== null;
530
+ function qe(e) {
531
+ return e instanceof File;
548
532
  }
549
- function Xt(e, t = {}) {
550
- const r = F(e.src, t);
533
+ function He(e, t) {
534
+ const r = t.headers.get("origin");
551
535
  if (!r)
552
- throw new Error(`Image source "${e.src}" is not allowed by the image policy.`);
553
- x("width", e.width), x("height", e.height), He(e.quality);
554
- const n = e.format ?? "auto", i = We(e.width, e.widths).map((s) => {
555
- const u = Math.round(e.height / e.width * s);
556
536
  return {
557
- format: n,
558
- height: u,
559
- src: _e({
560
- format: n,
561
- optimizerPath: t.optimizerPath ?? Me,
562
- quality: e.quality,
563
- src: e.src,
564
- width: s
565
- }),
566
- width: s
537
+ allowed: !!e.allowMissingOrigin,
538
+ expected: e.origins,
539
+ origin: r,
540
+ reason: e.allowMissingOrigin ? void 0 : "missing-origin"
541
+ };
542
+ const n = P(r);
543
+ if (!n)
544
+ return {
545
+ allowed: !1,
546
+ expected: e.origins,
547
+ origin: r,
548
+ reason: "invalid-origin"
567
549
  };
568
- }), o = i[0];
550
+ const a = _e(e, n, t);
569
551
  return {
570
- alt: e.alt,
571
- decoding: "async",
572
- fetchPriority: e.priority ? "high" : void 0,
573
- height: e.height,
574
- loading: e.priority ? "eager" : "lazy",
575
- sizes: e.sizes,
576
- source: r,
577
- src: o.src,
578
- srcSet: i.map((s) => `${s.src} ${s.width}w`).join(", "),
579
- variants: i,
580
- width: e.width
552
+ allowed: a,
553
+ expected: e.origins,
554
+ origin: n,
555
+ reason: a ? void 0 : "origin-not-allowed"
581
556
  };
582
557
  }
583
- function F(e, t) {
584
- if (e.startsWith("/") && !e.startsWith("//"))
585
- return t.local === !1 ? null : { kind: "local", src: e };
586
- let r;
587
- try {
588
- r = new URL(e);
589
- } catch {
590
- return null;
591
- }
592
- return r.protocol !== "https:" && r.protocol !== "http:" ? null : Fe(r, t.remote ?? []) ? { kind: "remote", src: r.toString() } : null;
558
+ function Pt(e, t) {
559
+ return !e || He(e, t).allowed ? null : new Response("WebSocket origin not allowed.", {
560
+ status: 403
561
+ });
593
562
  }
594
- function Fe(e, t) {
595
- return t.some(
596
- (r) => typeof r == "string" ? je(e, r) : qe(e, r)
563
+ function _e(e, t, r) {
564
+ return e.origins === "same-origin" ? t === new URL(r.url).origin : e.origins.some(
565
+ (n) => Ve(n, t)
597
566
  );
598
567
  }
599
- function je(e, t) {
568
+ function Ve(e, t) {
569
+ return e === "null" ? t === "null" : P(e) === t;
570
+ }
571
+ function P(e) {
572
+ if (e === "null")
573
+ return e;
600
574
  try {
601
- return e.origin === new URL(t).origin;
575
+ if (e !== e.trim())
576
+ return null;
577
+ const t = e.indexOf("://");
578
+ if (t === -1)
579
+ return null;
580
+ const r = e.slice(t + 3);
581
+ if (!r || /[/?#]/.test(r))
582
+ return null;
583
+ const n = new URL(e);
584
+ return n.protocol !== "http:" && n.protocol !== "https:" || n.username || n.password ? null : n.origin;
602
585
  } catch {
603
- return !1;
586
+ return null;
604
587
  }
605
588
  }
606
- function qe(e, t) {
607
- return t.protocol && e.protocol !== t.protocol || e.hostname !== t.hostname || t.port !== void 0 && e.port !== t.port ? !1 : t.pathname ? Be(e.pathname, t.pathname) : !0;
608
- }
609
- function Be(e, t) {
610
- return t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t;
611
- }
612
- function x(e, t) {
613
- if (!Number.isInteger(t) || t <= 0)
614
- throw new Error(`Image ${e} must be a positive integer.`);
615
- }
616
- function He(e) {
617
- if (e !== void 0 && (!Number.isInteger(e) || e < 1 || e > 100))
618
- throw new Error("Image quality must be an integer between 1 and 100.");
619
- }
620
- function We(e, t) {
621
- const r = t ?? [e, e * 2], n = [...new Set(r)];
622
- for (const a of n)
623
- x("width", a);
624
- return n.sort((a, i) => a - i);
625
- }
626
- function _e({
627
- format: e,
628
- optimizerPath: t,
629
- quality: r,
630
- src: n,
631
- width: a
632
- }) {
633
- const i = new URLSearchParams({
634
- src: n,
635
- w: String(a)
636
- });
637
- return r !== void 0 && i.set("q", String(r)), e !== "auto" && i.set("f", e), `${t}?${i.toString()}`;
638
- }
639
- const Jt = {
640
- google(e) {
641
- return {
642
- display: e.display ?? "swap",
643
- family: e.family,
644
- kind: "font",
645
- source: "google",
646
- src: e.src,
647
- style: e.style ?? "normal",
648
- weight: e.weight ?? 400
649
- };
650
- },
651
- local(e) {
652
- if (!e.src.trim())
653
- throw new Error("Local font source must not be empty.");
654
- return {
655
- display: e.display ?? "swap",
656
- family: e.name,
657
- kind: "font",
658
- source: "local",
659
- src: e.src,
660
- style: e.style ?? "normal",
661
- weight: e.weight ?? 400
662
- };
663
- }
664
- };
665
- function er(e) {
666
- return [...e];
667
- }
668
- function tr(e) {
669
- return e.filter((t) => t.src).map((t) => ({
670
- as: "font",
671
- crossOrigin: "anonymous",
672
- href: t.src,
673
- kind: "link",
674
- rel: "preload",
675
- type: Ve(t.src)
676
- }));
677
- }
678
- function rr(e) {
679
- return e.filter((t) => t.source === "local" && t.src).map((t) => {
680
- const r = t.src;
681
- return [
682
- "@font-face {",
683
- ` font-family: "${P(t.family)}";`,
684
- ` src: url("${P(r)}") format("${Ge(r)}");`,
685
- ` font-style: ${t.style};`,
686
- ` font-weight: ${t.weight};`,
687
- ` font-display: ${t.display};`,
688
- "}"
689
- ].join(`
690
- `);
691
- }).join(`
692
- `);
693
- }
694
- function Ve(e) {
695
- return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "font/woff" : "font/woff2";
589
+ function We(e) {
590
+ const t = O(e.routes), r = e.loadNavigationData ?? F;
591
+ return function() {
592
+ const [a, i] = I(() => E()), [s, o] = I(
593
+ () => e.initialMatch ?? { status: "loading" }
594
+ ), u = T(!!e.initialMatch), d = T(0);
595
+ C(() => {
596
+ function c() {
597
+ i(E());
598
+ }
599
+ return window.addEventListener("popstate", c), () => window.removeEventListener("popstate", c);
600
+ }, []), C(() => {
601
+ let c = !1, l = !1;
602
+ const m = ++d.current, R = new AbortController(), v = () => !c && m === d.current;
603
+ if (u.current && Ke(e.initialMatch) === a.pathname)
604
+ return u.current = !1, () => {
605
+ c = !0;
606
+ };
607
+ o({ status: "loading" }), ae(t, a.pathname).then((h) => {
608
+ v() && !l && h && o({ loading: h, status: "loading" });
609
+ }).catch(() => {
610
+ });
611
+ const k = new Request(a.href, { signal: R.signal });
612
+ return Promise.resolve(r(k)).then(
613
+ (h) => L(
614
+ t,
615
+ a.pathname,
616
+ k,
617
+ h,
618
+ void 0,
619
+ { documentContributions: !1 }
620
+ )
621
+ ).then((h) => {
622
+ l = !0, v() && o(h);
623
+ }).catch(async (h) => {
624
+ if (l = !0, !v() || R.signal.aborted)
625
+ return;
626
+ const q = await ie(
627
+ t,
628
+ a.pathname
629
+ );
630
+ v() && o({
631
+ Error: q,
632
+ error: h,
633
+ pathname: a.pathname,
634
+ status: "error"
635
+ });
636
+ }), () => {
637
+ c = !0, R.abort();
638
+ };
639
+ }, [a.pathname, a.search]);
640
+ const p = V(
641
+ () => ({
642
+ navigation: e.navigation ?? "server",
643
+ push(c) {
644
+ const l = E();
645
+ window.history.pushState(null, "", c);
646
+ const m = E();
647
+ i(m), l.pathname === m.pathname && l.search === m.search && l.hash !== m.hash && Je(m.hash);
648
+ }
649
+ }),
650
+ []
651
+ );
652
+ return f(j.Provider, {
653
+ value: p,
654
+ children: f(Ze, {
655
+ key: `${a.pathname}${a.search}`,
656
+ Loading: e.loading,
657
+ NotFound: e.notFound,
658
+ match: s
659
+ })
660
+ });
661
+ };
696
662
  }
697
- function Ge(e) {
698
- return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "woff" : "woff2";
663
+ function Ge(e, t) {
664
+ const r = t.getAttribute(Z);
665
+ return e.status === "not-found" ? r === "not-found" : e.status === "ready" && r === null;
699
666
  }
700
- function P(e) {
701
- return e.replace(/[\\"]/g, "\\$&");
667
+ function Ke(e) {
668
+ if (e)
669
+ return e.status === "ready" ? e.match.pathname : e.status === "loading" ? void 0 : e.pathname;
702
670
  }
703
- const nr = {
704
- plausible(e) {
705
- const t = Ke(e.domain), r = Ye(e.endpoint ?? "https://plausible.io");
706
- return {
707
- connectSrc: r.origin,
708
- consent: e.consent ?? !1,
709
- domain: t,
710
- kind: "analytics",
711
- provider: "plausible",
712
- script: fe({
713
- dataApi: `${r.origin}/api/event`,
714
- dataDomain: t,
715
- purpose: "analytics",
716
- src: `${r.origin}/js/script.js`,
717
- strategy: e.strategy ?? "afterInteractive"
718
- })
719
- };
671
+ async function Ut(e) {
672
+ const t = e.root ?? document.getElementById("root");
673
+ if (!t)
674
+ throw new Error(
675
+ "Demiurge expected a #root element in the framework document."
676
+ );
677
+ const r = O(e.routes), n = e.loadNavigationData ?? F, a = e.initialData ?? K(document), i = await L(
678
+ r,
679
+ window.location.pathname,
680
+ new Request(window.location.href),
681
+ a ?? await n(new Request(window.location.href)),
682
+ void 0,
683
+ { documentContributions: !1 }
684
+ ), s = Ge(i, t), o = We(
685
+ s ? {
686
+ ...e,
687
+ initialMatch: i,
688
+ loadNavigationData: n,
689
+ navigation: a?.navigation ?? e.navigation
690
+ } : {
691
+ ...e,
692
+ loadNavigationData: n,
693
+ navigation: a?.navigation ?? e.navigation
694
+ }
695
+ ), { createRoot: u, hydrateRoot: d } = Ye(
696
+ await import("react-dom/client")
697
+ );
698
+ if (s && t.hasAttribute(Y)) {
699
+ d(t, f(o));
700
+ return;
720
701
  }
721
- };
722
- function Ke(e) {
723
- const t = e.trim();
724
- if (!t || t.includes("/") || t.includes(" "))
725
- throw new Error("Analytics domain must be a hostname without a path.");
726
- return t;
702
+ t.replaceChildren(), u(t).render(f(o));
727
703
  }
728
704
  function Ye(e) {
729
- let t;
730
- try {
731
- t = new URL(e);
732
- } catch {
733
- throw new Error("Analytics endpoint must be an absolute URL.");
734
- }
735
- if (t.protocol !== "https:")
736
- throw new Error("Analytics endpoint must use HTTPS.");
705
+ const t = typeof e.createRoot == "function" && typeof e.hydrateRoot == "function" ? e : e.default;
706
+ if (!t || typeof t.createRoot != "function" || typeof t.hydrateRoot != "function")
707
+ throw new Error(
708
+ "Demiurge could not load the React DOM client from the Vite module."
709
+ );
737
710
  return t;
738
711
  }
739
- function ar(e = {}) {
740
- return {
741
- async request(t) {
742
- await E({ kind: "request", signal: t }, e);
743
- },
744
- async serverStart(t = {}) {
745
- await E({ kind: "server-start", signal: t }, e);
746
- },
747
- async trace(t) {
748
- await E({ kind: "trace", signal: t }, e);
749
- },
750
- async reportWebVitals(t) {
751
- await E({ kind: "web-vital", signal: t }, e);
712
+ function Ft(e) {
713
+ const t = tt(), r = ne(e);
714
+ return /* @__PURE__ */ H(
715
+ "a",
716
+ {
717
+ className: e.className,
718
+ href: r,
719
+ onClick: (n) => {
720
+ t.navigation === "server" && et(n) && (n.preventDefault(), t.push(r));
721
+ },
722
+ children: e.children
752
723
  }
753
- };
754
- }
755
- async function E(e, t) {
756
- await t.onEvent?.(e), e.kind === "request" ? await t.request?.(e.signal) : e.kind === "server-start" ? await t.serverStart?.(e.signal) : e.kind === "trace" ? await t.trace?.(e.signal) : await t.webVitals?.(e.signal);
757
- }
758
- const Ze = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]);
759
- function ir(e = {}) {
760
- const t = [], r = e.document, n = r ? Je(r.policy, r.headers, t) : {};
761
- r && Qe(r.policy, t);
762
- const a = e.route ? ot(e.route, t) : void 0;
763
- return r?.scripts && (et(
764
- r.policy.csp,
765
- r.scripts,
766
- r.headers,
767
- t
768
- ), r.scriptDependencies && t.push(
769
- ...Xe(
770
- r.scripts,
771
- tt(r.scriptDependencies)
772
- )
773
- )), {
774
- findings: t,
775
- headers: n,
776
- route: a
777
- };
724
+ );
778
725
  }
779
- function Qe(e, t) {
780
- if (!e.trustedTypes || e.trustedTypes.mode !== "report-only")
781
- return;
782
- const r = e.csp || void 0, n = !!r?.reportUri?.length, a = e.headers?.reportingEndpoints, i = !!(r?.reportTo && a && a[r.reportTo]);
783
- !n && !i && t.push({
784
- code: "report-only-target-missing",
785
- message: "Trusted Types report-only mode has no deliverable target. Configure CSP reportTo with a matching Reporting-Endpoints member, reportUri for compatibility, or both.",
786
- severity: "warning"
726
+ function Ze({
727
+ Loading: e,
728
+ NotFound: t,
729
+ match: r
730
+ }) {
731
+ if (r.status === "loading") {
732
+ const c = r.loading ?? e;
733
+ return c ? f(c) : null;
734
+ }
735
+ if (r.status === "not-found") {
736
+ const c = r.notFound ?? t ?? de;
737
+ return r.layouts.reduceRight(
738
+ (l, m) => f(m, {
739
+ children: l,
740
+ path: {},
741
+ pathname: r.pathname
742
+ }),
743
+ f(c, { pathname: r.pathname })
744
+ );
745
+ }
746
+ if (r.status === "error")
747
+ return r.Error ? f(r.Error, {
748
+ error: r.error,
749
+ pathname: r.pathname,
750
+ status: U(r.error)
751
+ }) : null;
752
+ const { data: n, error: a, page: i, layouts: s, path: o, pathname: u } = r.match, d = f(i, { data: n, path: o, pathname: u }), p = s.reduceRight(
753
+ (c, l) => f(l, { path: o, pathname: u, children: c }),
754
+ d
755
+ );
756
+ return f(Qe, {
757
+ Error: a,
758
+ children: p,
759
+ pathname: u
787
760
  });
788
761
  }
789
- function Xe(e, t = {}) {
790
- const r = t.requirePurpose ?? !0, n = [];
791
- for (const a of e) {
792
- const i = lt(a);
793
- i && (r && !a.purpose && n.push({
794
- code: "script-purpose-missing",
795
- message: `Third-party script ${a.src} should declare a purpose for audits and consent flows.`,
796
- severity: "warning"
797
- }), t.requireIntegrity && !a.integrity && n.push({
798
- code: "script-integrity-missing",
799
- message: `Third-party script ${a.src} should declare an integrity hash or an explicit trust-boundary exception.`,
800
- severity: "warning"
801
- }), a.strategy === "beforeInteractive" && !t.allowBeforeInteractiveThirdParty && n.push({
802
- code: "script-third-party-before-interactive",
803
- message: `Third-party script ${a.src} runs before the app is interactive and should be justified by policy.`,
804
- severity: "warning"
805
- }), ft(i) && n.push({
806
- code: "script-gtm-wide-trust-boundary",
807
- message: "Google Tag Manager can load additional scripts at runtime and should be treated as a wide trust boundary.",
808
- severity: "warning"
809
- }));
762
+ class Qe extends G {
763
+ static getDerivedStateFromError(t) {
764
+ return { error: t };
810
765
  }
811
- return n;
812
- }
813
- function Je(e, t, r) {
814
- try {
815
- return Object.fromEntries(de(e, t));
816
- } catch (n) {
817
- return r.push({
818
- code: "security-header-render-failed",
819
- message: n instanceof Error ? n.message : "Security headers failed to render.",
820
- severity: "error"
821
- }), {};
766
+ state = {};
767
+ componentDidUpdate(t) {
768
+ this.state.error !== void 0 && t.pathname !== this.props.pathname && this.setState({ error: void 0 });
822
769
  }
823
- }
824
- function et(e, t, r, n) {
825
- if (!e)
826
- return;
827
- const a = rt(e);
828
- for (const i of t) {
829
- if (nt(a) && !i.nonce) {
830
- n.push({
831
- code: "csp-script-missing-nonce",
832
- message: `Document script ${i.src} needs a nonce for the effective script-src policy.`,
833
- severity: "error"
834
- });
835
- continue;
836
- }
837
- i.nonce && r?.nonce && i.nonce === r.nonce || at(a, i.src) || n.push({
838
- code: "csp-script-src-blocked",
839
- message: `Document script ${i.src} is not allowed by the effective script-src policy.`,
840
- severity: "error"
841
- });
770
+ render() {
771
+ return this.state.error !== void 0 ? this.props.Error ? f(this.props.Error, {
772
+ error: this.state.error,
773
+ pathname: this.props.pathname,
774
+ status: U(this.state.error)
775
+ }) : null : this.props.children;
842
776
  }
843
777
  }
844
- function tt(e) {
845
- return typeof e == "boolean" ? {} : e;
778
+ function U(e) {
779
+ return me(e) ? e.status : 500;
846
780
  }
847
- function rt(e) {
848
- return e.scriptSrc ?? e.defaultSrc ?? [];
849
- }
850
- function nt(e) {
851
- return e.some((t) => t.includes("'nonce-{nonce}'"));
852
- }
853
- function at(e, t) {
854
- return e.includes("*") ? !0 : e.includes("'none'") || e.some((r) => r.startsWith("'nonce-")) ? !1 : e.includes("'self'") && it(t) || t.startsWith("https:") && e.includes("https:") || t.startsWith("http:") && e.includes("http:") ? !0 : e.some((r) => st(r, t));
781
+ function E() {
782
+ return {
783
+ hash: window.location.hash,
784
+ href: window.location.href,
785
+ pathname: window.location.pathname,
786
+ search: window.location.search
787
+ };
855
788
  }
856
- function it(e) {
857
- return e.startsWith("/") && !e.startsWith("//");
789
+ async function F(e) {
790
+ const t = new Headers(e.headers);
791
+ t.set("accept", "application/json"), t.set(D, oe);
792
+ const r = await fetch(new Request(e, {
793
+ credentials: "same-origin",
794
+ headers: t
795
+ })), n = r.headers.get(D);
796
+ if (n === se) {
797
+ const a = await r.json();
798
+ if (a.hasData !== !0)
799
+ throw new Error("Demiurge received malformed navigation route data.");
800
+ return { data: a.data, hasData: !0 };
801
+ }
802
+ if (n === ce)
803
+ return { hasData: !0 };
804
+ if (n === ue || !r.ok) {
805
+ const a = await Xe(r), i = le.includes(
806
+ r.status
807
+ ) ? r.status : 500;
808
+ throw fe(i, {
809
+ detail: typeof a?.detail == "string" ? a.detail : void 0,
810
+ title: typeof a?.title == "string" ? a.title : void 0
811
+ });
812
+ }
813
+ throw new Error(
814
+ "Demiurge expected a navigation data response from the application server."
815
+ );
858
816
  }
859
- function st(e, t) {
860
- if (e.startsWith("'"))
861
- return !1;
817
+ async function Xe(e) {
862
818
  try {
863
- const r = new URL(e), n = new URL(t);
864
- return n.protocol === r.protocol && n.hostname === r.hostname && n.port === r.port && (r.pathname === "/" || n.pathname.startsWith(r.pathname));
819
+ return await e.json();
865
820
  } catch {
866
- return !1;
821
+ return;
867
822
  }
868
823
  }
869
- function ot(e, t) {
870
- return ct(e.cors, t), ut(e.method, e.security, t), {
871
- cors: e.cors,
872
- method: e.method,
873
- security: e.security
874
- };
875
- }
876
- function ct(e, t) {
877
- if (e)
878
- try {
879
- he(e);
880
- } catch (r) {
881
- t.push({
882
- code: "cors-invalid",
883
- message: r instanceof Error ? r.message : "CORS policy is invalid.",
884
- severity: "error"
885
- });
886
- }
887
- }
888
- function ut(e, t, r) {
889
- Ze.has(e) && (t?.csrf === !1 && r.push({
890
- code: "csrf-disabled",
891
- message: "CSRF protection is explicitly disabled for this unsafe route.",
892
- severity: "info"
893
- }), t?.rateLimit || r.push({
894
- code: "rate-limit-missing",
895
- message: "Unsafe routes should declare rate limiting.",
896
- severity: "warning"
897
- }), t?.request?.maxBodySize || r.push({
898
- code: "request-body-limit-missing",
899
- message: "Unsafe routes should declare a request body size limit.",
900
- severity: "warning"
901
- }));
902
- }
903
- function lt(e) {
904
- try {
905
- const t = new URL(e.src);
906
- if (t.protocol === "http:" || t.protocol === "https:")
907
- return t;
908
- } catch {
909
- return null;
910
- }
911
- return null;
912
- }
913
- function ft(e) {
914
- return e.hostname === "www.googletagmanager.com" && (e.pathname === "/gtm.js" || e.pathname === "/ns.html");
915
- }
916
- class dt extends Error {
917
- issues;
918
- constructor(t) {
919
- super(vt(t)), this.name = "EnvValidationError", this.issues = t;
920
- }
921
- }
922
- function sr(e) {
923
- return e;
924
- }
925
- function or(e, t) {
926
- const r = [], n = {};
927
- for (const a of Object.keys(e)) {
928
- const i = e[a], o = t[String(a)];
929
- if (o === void 0 || o === "") {
930
- if (i.optional) {
931
- n[a] = void 0;
932
- continue;
933
- }
934
- r.push({
935
- code: "missing",
936
- key: String(a),
937
- message: `Environment variable ${String(a)} is required.`
938
- });
939
- continue;
824
+ function Je(e) {
825
+ queueMicrotask(() => {
826
+ if (!e) {
827
+ window.scrollTo?.(0, 0);
828
+ return;
940
829
  }
830
+ let t;
941
831
  try {
942
- n[a] = i.parse(String(a), o);
943
- } catch (s) {
944
- r.push({
945
- code: "invalid",
946
- key: String(a),
947
- message: s instanceof Error ? s.message : `Environment variable ${String(a)} is invalid.`
948
- });
832
+ t = decodeURIComponent(e.slice(1));
833
+ } catch {
834
+ t = e.slice(1);
949
835
  }
950
- }
951
- if (r.length)
952
- throw new dt(r);
953
- return n;
954
- }
955
- function ht(e = {}) {
956
- return y(e, !1, (t, r) => {
957
- if (r === "true" || r === "1")
958
- return !0;
959
- if (r === "false" || r === "0")
960
- return !1;
961
- throw new Error(`Environment variable ${t} must be true, false, 1, or 0.`);
962
- });
963
- }
964
- function mt(e, t = {}) {
965
- return y(t, !1, (r, n) => {
966
- if (e.includes(n))
967
- return n;
968
- throw new Error(
969
- `Environment variable ${r} must be one of: ${e.join(", ")}.`
970
- );
836
+ document.getElementById(t)?.scrollIntoView?.();
971
837
  });
972
838
  }
973
- function pt(e = {}) {
974
- return y(e, !1, (t, r) => {
975
- if (!/^-?\d+$/.test(r))
976
- throw new Error(`Environment variable ${t} must be an integer.`);
977
- const n = Number(r);
978
- if (!Number.isSafeInteger(n))
979
- throw new Error(`Environment variable ${t} must be a safe integer.`);
980
- if (e.min !== void 0 && n < e.min)
981
- throw new Error(
982
- `Environment variable ${t} must be greater than or equal to ${e.min}.`
983
- );
984
- if (e.max !== void 0 && n > e.max)
985
- throw new Error(
986
- `Environment variable ${t} must be less than or equal to ${e.max}.`
987
- );
988
- return n;
989
- });
839
+ function et(e) {
840
+ return e.button === 0 && !e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey;
990
841
  }
991
- function gt(e = {}) {
992
- return y(
993
- e,
994
- !0,
995
- (t, r) => j(t, r, e)
996
- );
842
+ const j = _({
843
+ navigation: "document",
844
+ push(e) {
845
+ window.location.href = e;
846
+ }
847
+ });
848
+ function tt() {
849
+ return W(j);
997
850
  }
998
- function wt(e = {}) {
999
- return y(
1000
- e,
1001
- !1,
1002
- (t, r) => j(t, r, e)
1003
- );
851
+ const rt = "/_demiurge/image";
852
+ function jt(e) {
853
+ return e;
1004
854
  }
1005
- function yt(e = {}) {
1006
- return y(e, !1, (t, r) => {
1007
- let n;
1008
- try {
1009
- n = new URL(r);
1010
- } catch {
1011
- throw new Error(`Environment variable ${t} must be a valid URL.`);
1012
- }
1013
- if (e.protocols?.length && !e.protocols.includes(n.protocol))
1014
- throw new Error(
1015
- `Environment variable ${t} must use one of these protocols: ${e.protocols.join(", ")}.`
1016
- );
1017
- return n;
1018
- });
855
+ function Bt(e, t = {}) {
856
+ return B(e, t) !== null;
1019
857
  }
1020
- const cr = {
1021
- boolean: ht,
1022
- enum: mt,
1023
- integer: pt,
1024
- secret: gt,
1025
- string: wt,
1026
- url: yt
1027
- };
1028
- function y(e, t, r) {
858
+ function qt(e, t = {}) {
859
+ const r = B(e.src, t);
860
+ if (!r)
861
+ throw new Error(`Image source "${e.src}" is not allowed by the image policy.`);
862
+ $("width", e.width), $("height", e.height), st(e.quality);
863
+ const n = e.format ?? "auto", i = ct(e.width, e.widths).map((o) => {
864
+ const u = Math.round(e.height / e.width * o);
865
+ return {
866
+ format: n,
867
+ height: u,
868
+ src: ut({
869
+ format: n,
870
+ optimizerPath: t.optimizerPath ?? rt,
871
+ quality: e.quality,
872
+ src: e.src,
873
+ width: o
874
+ }),
875
+ width: o
876
+ };
877
+ }), s = i[0];
1029
878
  return {
1030
- optional: e.optional ?? !1,
1031
- parse: r,
1032
- sensitive: t
879
+ alt: e.alt,
880
+ decoding: "async",
881
+ fetchPriority: e.priority ? "high" : void 0,
882
+ height: e.height,
883
+ loading: e.priority ? "eager" : "lazy",
884
+ sizes: e.sizes,
885
+ source: r,
886
+ src: s.src,
887
+ srcSet: i.map((o) => `${o.src} ${o.width}w`).join(", "),
888
+ variants: i,
889
+ width: e.width
1033
890
  };
1034
891
  }
1035
- function j(e, t, r) {
1036
- if (r.minLength !== void 0 && t.length < r.minLength)
1037
- throw new Error(
1038
- `Environment variable ${e} must be at least ${r.minLength} characters.`
1039
- );
1040
- return t;
892
+ function B(e, t) {
893
+ if (e.startsWith("/") && !e.startsWith("//"))
894
+ return t.local === !1 ? null : { kind: "local", src: e };
895
+ let r;
896
+ try {
897
+ r = new URL(e);
898
+ } catch {
899
+ return null;
900
+ }
901
+ return r.protocol !== "https:" && r.protocol !== "http:" ? null : nt(r, t.remote ?? []) ? { kind: "remote", src: r.toString() } : null;
1041
902
  }
1042
- function vt(e) {
1043
- return e.length === 1 ? e[0].message : `Environment validation failed with ${e.length} issues.`;
903
+ function nt(e, t) {
904
+ return t.some(
905
+ (r) => typeof r == "string" ? at(e, r) : it(e, r)
906
+ );
1044
907
  }
1045
- function ur(e = {}) {
1046
- return async function(r) {
1047
- if (r.method.toUpperCase() !== "POST")
1048
- return new Response(null, {
1049
- headers: {
1050
- allow: "POST"
1051
- },
1052
- status: 405
1053
- });
1054
- const n = St(r);
1055
- if (n)
1056
- return n;
1057
- const a = Et(e, r);
1058
- if (a)
1059
- return a;
1060
- e.maxBodySize !== void 0 && (r = me({ maxBodySize: e.maxBodySize }, r));
1061
- let i;
1062
- try {
1063
- i = await r.json();
1064
- } catch (s) {
1065
- return s instanceof pe ? new Response("Security report body too large.", { status: 413 }) : new Response("Invalid security report JSON.", {
1066
- status: 400
1067
- });
1068
- }
1069
- const o = Rt(i);
1070
- for (let s = 0; s < o.length; s += 1)
1071
- await e.onReport?.(o[s], {
1072
- index: s,
1073
- request: r
1074
- });
1075
- return new Response(null, {
1076
- status: 204
1077
- });
1078
- };
908
+ function at(e, t) {
909
+ try {
910
+ return e.origin === new URL(t).origin;
911
+ } catch {
912
+ return !1;
913
+ }
1079
914
  }
1080
- const bt = /* @__PURE__ */ new Set([
1081
- "application/csp-report",
1082
- "application/reports+json"
1083
- ]);
1084
- function St(e) {
1085
- const t = e.headers.get("content-type");
1086
- if (!t)
1087
- return null;
1088
- const r = t.split(";", 1)[0]?.trim().toLowerCase();
1089
- return r && bt.has(r) ? null : new Response("Unsupported security report Content-Type.", {
1090
- status: 415
1091
- });
915
+ function it(e, t) {
916
+ return t.protocol && e.protocol !== t.protocol || e.hostname !== t.hostname || t.port !== void 0 && e.port !== t.port ? !1 : t.pathname ? ot(e.pathname, t.pathname) : !0;
1092
917
  }
1093
- function Et(e, t) {
1094
- if (e.maxBodySize === void 0)
1095
- return null;
1096
- const r = t.headers.get("content-length");
1097
- if (!r)
1098
- return null;
1099
- if (!/^\d+$/.test(r))
1100
- return new Response("Invalid Content-Length.", {
1101
- status: 400
1102
- });
1103
- const n = Number(r);
1104
- return Number.isSafeInteger(n) ? n > A(e.maxBodySize) ? new Response("Security report body too large.", {
1105
- status: 413
1106
- }) : null : new Response("Invalid Content-Length.", {
1107
- status: 400
1108
- });
918
+ function ot(e, t) {
919
+ return t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t;
1109
920
  }
1110
- function Rt(e) {
1111
- return Array.isArray(e) ? e : $t(e) && "csp-report" in e ? [e["csp-report"]] : [e];
921
+ function $(e, t) {
922
+ if (!Number.isInteger(t) || t <= 0)
923
+ throw new Error(`Image ${e} must be a positive integer.`);
1112
924
  }
1113
- function $t(e) {
1114
- return typeof e == "object" && e !== null;
925
+ function st(e) {
926
+ if (e !== void 0 && (!Number.isInteger(e) || e < 1 || e > 100))
927
+ throw new Error("Image quality must be an integer between 1 and 100.");
1115
928
  }
1116
- function lr(e, t) {
1117
- const r = {}, n = [];
1118
- let a = 0;
1119
- for (const [i, o] of Object.entries(t.files)) {
1120
- const s = e.getAll(i).filter(Tt);
1121
- r[i] = s, o.required && s.length === 0 && n.push({
1122
- code: "file-missing",
1123
- field: i,
1124
- message: `Upload field ${i} requires at least one file.`
1125
- });
1126
- for (const u of s)
1127
- a += u.size, xt(i, u, o, n);
1128
- }
1129
- return t.maxTotalSize !== void 0 && a > A(t.maxTotalSize) && n.push({
1130
- code: "total-upload-too-large",
1131
- field: "*",
1132
- message: `Uploaded files exceed the maximum total size of ${t.maxTotalSize}.`
1133
- }), {
1134
- files: r,
1135
- issues: n,
1136
- ok: n.length === 0,
1137
- totalSize: a
1138
- };
929
+ function ct(e, t) {
930
+ const r = t ?? [e, e * 2], n = [...new Set(r)];
931
+ for (const a of n)
932
+ $("width", a);
933
+ return n.sort((a, i) => a - i);
1139
934
  }
1140
- function xt(e, t, r, n) {
1141
- r.maxSize !== void 0 && t.size > A(r.maxSize) && n.push({
1142
- code: "file-too-large",
1143
- field: e,
1144
- message: `Upload field ${e} contains ${t.name || "a file"} larger than ${r.maxSize}.`
1145
- }), r.types?.length && !At(t.type, r.types) && n.push({
1146
- code: "file-type-not-allowed",
1147
- field: e,
1148
- message: `Upload field ${e} contains ${t.name || "a file"} with disallowed type ${t.type || "unknown"}.`
935
+ function ut({
936
+ format: e,
937
+ optimizerPath: t,
938
+ quality: r,
939
+ src: n,
940
+ width: a
941
+ }) {
942
+ const i = new URLSearchParams({
943
+ src: n,
944
+ w: String(a)
1149
945
  });
946
+ return r !== void 0 && i.set("q", String(r)), e !== "auto" && i.set("f", e), `${t}?${i.toString()}`;
1150
947
  }
1151
- function At(e, t) {
1152
- return t.some((r) => r.endsWith("/*") ? e.startsWith(r.slice(0, -1)) : e === r);
1153
- }
1154
- function Tt(e) {
1155
- return e instanceof File;
1156
- }
1157
- function It(e, t) {
1158
- const r = t.headers.get("origin");
1159
- if (!r)
948
+ const Ht = {
949
+ google(e) {
1160
950
  return {
1161
- allowed: !!e.allowMissingOrigin,
1162
- expected: e.origins,
1163
- origin: r,
1164
- reason: e.allowMissingOrigin ? void 0 : "missing-origin"
951
+ display: e.display ?? "swap",
952
+ family: e.family,
953
+ kind: "font",
954
+ source: "google",
955
+ src: e.src,
956
+ style: e.style ?? "normal",
957
+ weight: e.weight ?? 400
1165
958
  };
1166
- const n = q(r);
1167
- if (!n)
959
+ },
960
+ local(e) {
961
+ if (!e.src.trim())
962
+ throw new Error("Local font source must not be empty.");
1168
963
  return {
1169
- allowed: !1,
1170
- expected: e.origins,
1171
- origin: r,
1172
- reason: "invalid-origin"
964
+ display: e.display ?? "swap",
965
+ family: e.name,
966
+ kind: "font",
967
+ source: "local",
968
+ src: e.src,
969
+ style: e.style ?? "normal",
970
+ weight: e.weight ?? 400
1173
971
  };
1174
- const a = kt(e, n, t);
1175
- return {
1176
- allowed: a,
1177
- expected: e.origins,
1178
- origin: n,
1179
- reason: a ? void 0 : "origin-not-allowed"
1180
- };
972
+ }
973
+ };
974
+ function _t(e) {
975
+ return [...e];
1181
976
  }
1182
- function fr(e, t) {
1183
- return !e || It(e, t).allowed ? null : new Response("WebSocket origin not allowed.", {
1184
- status: 403
1185
- });
977
+ function Vt(e) {
978
+ return e.filter((t) => t.src).map((t) => ({
979
+ as: "font",
980
+ crossOrigin: "anonymous",
981
+ href: t.src,
982
+ kind: "link",
983
+ rel: "preload",
984
+ type: lt(t.src)
985
+ }));
1186
986
  }
1187
- function kt(e, t, r) {
1188
- return e.origins === "same-origin" ? t === new URL(r.url).origin : e.origins.some(
1189
- (n) => Ct(n, t)
1190
- );
987
+ function Wt(e) {
988
+ return e.filter((t) => t.source === "local" && t.src).map((t) => {
989
+ const r = t.src;
990
+ return [
991
+ "@font-face {",
992
+ ` font-family: "${N(t.family)}";`,
993
+ ` src: url("${N(r)}") format("${ft(r)}");`,
994
+ ` font-style: ${t.style};`,
995
+ ` font-weight: ${t.weight};`,
996
+ ` font-display: ${t.display};`,
997
+ "}"
998
+ ].join(`
999
+ `);
1000
+ }).join(`
1001
+ `);
1191
1002
  }
1192
- function Ct(e, t) {
1193
- return e === "null" ? t === "null" : q(e) === t;
1003
+ function lt(e) {
1004
+ return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "font/woff" : "font/woff2";
1194
1005
  }
1195
- function q(e) {
1196
- if (e === "null")
1197
- return e;
1006
+ function ft(e) {
1007
+ return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "woff" : "woff2";
1008
+ }
1009
+ function N(e) {
1010
+ return e.replace(/[\\"]/g, "\\$&");
1011
+ }
1012
+ const Gt = {
1013
+ plausible(e) {
1014
+ const t = dt(e.domain), r = mt(e.endpoint ?? "https://plausible.io");
1015
+ return {
1016
+ connectSrc: r.origin,
1017
+ consent: e.consent ?? !1,
1018
+ domain: t,
1019
+ kind: "analytics",
1020
+ provider: "plausible",
1021
+ script: Q({
1022
+ dataApi: `${r.origin}/api/event`,
1023
+ dataDomain: t,
1024
+ purpose: "analytics",
1025
+ src: `${r.origin}/js/script.js`,
1026
+ strategy: e.strategy ?? "afterInteractive"
1027
+ })
1028
+ };
1029
+ }
1030
+ };
1031
+ function dt(e) {
1032
+ const t = e.trim();
1033
+ if (!t || t.includes("/") || t.includes(" "))
1034
+ throw new Error("Analytics domain must be a hostname without a path.");
1035
+ return t;
1036
+ }
1037
+ function mt(e) {
1038
+ let t;
1198
1039
  try {
1199
- if (e !== e.trim())
1200
- return null;
1201
- const t = e.indexOf("://");
1202
- if (t === -1)
1203
- return null;
1204
- const r = e.slice(t + 3);
1205
- if (!r || /[/?#]/.test(r))
1206
- return null;
1207
- const n = new URL(e);
1208
- return n.protocol !== "http:" && n.protocol !== "https:" || n.username || n.password ? null : n.origin;
1040
+ t = new URL(e);
1209
1041
  } catch {
1210
- return null;
1042
+ throw new Error("Analytics endpoint must be an absolute URL.");
1211
1043
  }
1044
+ if (t.protocol !== "https:")
1045
+ throw new Error("Analytics endpoint must use HTTPS.");
1046
+ return t;
1047
+ }
1048
+ function Kt(e = {}) {
1049
+ return {
1050
+ async request(t) {
1051
+ await S({ kind: "request", signal: t }, e);
1052
+ },
1053
+ async serverStart(t = {}) {
1054
+ await S({ kind: "server-start", signal: t }, e);
1055
+ },
1056
+ async trace(t) {
1057
+ await S({ kind: "trace", signal: t }, e);
1058
+ },
1059
+ async reportWebVitals(t) {
1060
+ await S({ kind: "web-vital", signal: t }, e);
1061
+ }
1062
+ };
1063
+ }
1064
+ async function S(e, t) {
1065
+ await t.onEvent?.(e), e.kind === "request" ? await t.request?.(e.signal) : e.kind === "server-start" ? await t.serverStart?.(e.signal) : e.kind === "trace" ? await t.trace?.(e.signal) : await t.webVitals?.(e.signal);
1212
1066
  }
1213
1067
  export {
1214
- dt as EnvValidationError,
1215
- oe as HTTP_ERROR_STATUSES,
1216
- gr as HttpError,
1217
- Yt as Link,
1218
- Bt as action,
1219
- Ht as actionInput,
1220
- nr as analytics,
1221
- gn as assertAdapterCapabilities,
1222
- Xe as auditScriptDependencies,
1223
- wn as checkAdapterCapabilities,
1224
- It as checkWebSocketOrigin,
1225
- wr as createCache,
1226
- yr as createCorsHeaders,
1227
- vr as createCsrfCookie,
1228
- br as createCsrfToken,
1229
- ke as createFileRouter,
1230
- Sr as createInvalidation,
1231
- Er as createMemoryCache,
1232
- Rr as createMemoryCacheStore,
1233
- Vt as createMemoryIdempotencyStore,
1234
- $r as createMemoryRateLimitStore,
1235
- xr as createRequestHandler,
1236
- ir as createSecurityAudit,
1237
- de as createSecurityHeaders,
1238
- ur as createSecurityReportHandler,
1239
- Ar as cspHash,
1240
- yn as defineAdapter,
1241
- sr as defineEnvSchema,
1242
- er as defineFonts,
1243
- Zt as defineImages,
1244
- ar as defineInstrumentation,
1245
- Tr as defineLinks,
1246
- Ir as defineMetadata,
1247
- Ft as defineOgImage,
1248
- Mt as defineRobots,
1249
- kr as defineRoutePolicy,
1250
- Cr as defineScripts,
1251
- Dr as defineSecurityPolicy,
1252
- Nt as defineSitemap,
1253
- zr as defineTags,
1254
- Pr as enforceAllowedMethods,
1255
- Lr as enforceCsrfProtection,
1256
- Or as enforceRateLimit,
1257
- Nr as enforceRequestSecurity,
1258
- fr as enforceWebSocketOrigin,
1259
- cr as env,
1260
- Jt as font,
1261
- tr as fontPreloadLinks,
1262
- Ur as handleRequestWithManifest,
1263
- ee as href,
1264
- Mr as html,
1265
- ce as httpError,
1266
- Kt as hydrateFileRouter,
1267
- Qt as isAllowedImageSource,
1268
- le as isHttpError,
1269
- Fr as issueCsrfToken,
1270
- jr as json,
1271
- qr as jsonl,
1272
- Br as link,
1273
- Hr as mergeRoutePolicies,
1274
- Wr as mergeRouteSecurityPolicies,
1275
- _r as mergeSecurityPolicies,
1276
- Vr as meta,
1277
- Gr as modulePreload,
1278
- Kr as notFound,
1279
- Wt as page,
1280
- A as parseBodySize,
1281
- D as parseCacheDuration,
1282
- Yr as parseCookieHeader,
1283
- Zr as parseRateLimitWindow,
1284
- Xt as planImageTransform,
1285
- Qr as preconnect,
1286
- Xr as preload,
1287
- Jr as query,
1288
- en as redirect,
1289
- rr as renderFontFaceCss,
1290
- qt as renderOgImageResponse,
1291
- ge as renderOgImageSvg,
1292
- mr as renderPageResponse,
1293
- jt as renderRobots,
1294
- Ut as renderSitemap,
1295
- tn as resolveLinks,
1296
- rn as resolveMetadata,
1297
- nn as resolveScripts,
1298
- Q as response,
1299
- Gt as runIdempotentMutation,
1300
- fe as script,
1301
- an as security,
1302
- J as serializeCacheKey,
1303
- sn as serializeCacheNamespace,
1304
- on as serializeCacheTag,
1305
- cn as serverTiming,
1306
- un as sse,
1307
- ln as stream,
1308
- fn as structuredData,
1309
- dn as tag,
1310
- hn as text,
1311
- X as toResponse,
1312
- he as validateCorsPolicy,
1313
- or as validateEnv,
1314
- mn as validateRateLimitPolicy,
1315
- lr as validateUploads,
1316
- _t as webhook
1068
+ ke as EnvValidationError,
1069
+ le as HTTP_ERROR_STATUSES,
1070
+ ir as HttpError,
1071
+ Ft as Link,
1072
+ Qt as Script,
1073
+ kt as action,
1074
+ It as actionInput,
1075
+ Gt as analytics,
1076
+ Xt as assertAdapterCapabilities,
1077
+ or as auditScriptDependencies,
1078
+ Jt as checkAdapterCapabilities,
1079
+ He as checkWebSocketOrigin,
1080
+ sr as createCache,
1081
+ cr as createCorsHeaders,
1082
+ ur as createCsrfCookie,
1083
+ lr as createCsrfToken,
1084
+ We as createFileRouter,
1085
+ fr as createInvalidation,
1086
+ dr as createMemoryCache,
1087
+ mr as createMemoryCacheStore,
1088
+ vt as createMemoryIdempotencyStore,
1089
+ hr as createMemoryRateLimitStore,
1090
+ gr as createRequestHandler,
1091
+ pr as createSecurityAudit,
1092
+ wr as createSecurityHeaders,
1093
+ Lt as createSecurityReportHandler,
1094
+ yr as cspHash,
1095
+ vr as cspNonce,
1096
+ er as defineAdapter,
1097
+ Dt as defineEnvSchema,
1098
+ _t as defineFonts,
1099
+ jt as defineImages,
1100
+ Kt as defineInstrumentation,
1101
+ br as defineLinks,
1102
+ Er as defineMetadata,
1103
+ Ct as defineMiddleware,
1104
+ At as defineOgImage,
1105
+ Rt as defineRobots,
1106
+ Sr as defineRoutePolicy,
1107
+ tr as defineScripts,
1108
+ Rr as defineSecurityPolicy,
1109
+ Et as defineSitemap,
1110
+ Ar as defineTags,
1111
+ $r as enforceAllowedMethods,
1112
+ xr as enforceCsrfProtection,
1113
+ kr as enforceRateLimit,
1114
+ Ir as enforceRequestSecurity,
1115
+ Pt as enforceWebSocketOrigin,
1116
+ Ot as env,
1117
+ Ht as font,
1118
+ Vt as fontPreloadLinks,
1119
+ Tr as handleRequestWithManifest,
1120
+ ne as href,
1121
+ Cr as html,
1122
+ fe as httpError,
1123
+ Ut as hydrateFileRouter,
1124
+ Bt as isAllowedImageSource,
1125
+ me as isHttpError,
1126
+ zr as issueCsrfToken,
1127
+ Dr as json,
1128
+ Nr as jsonl,
1129
+ Or as link,
1130
+ Lr as mergeRoutePolicies,
1131
+ Mr as mergeRouteSecurityPolicies,
1132
+ Pr as mergeSecurityPolicies,
1133
+ Ur as meta,
1134
+ Fr as modulePreload,
1135
+ jr as notFound,
1136
+ Tt as page,
1137
+ x as parseBodySize,
1138
+ z as parseCacheDuration,
1139
+ Br as parseCookieHeader,
1140
+ qr as parseRateLimitWindow,
1141
+ qt as planImageTransform,
1142
+ Hr as preconnect,
1143
+ _r as preload,
1144
+ Vr as query,
1145
+ Wr as redirect,
1146
+ Wt as renderFontFaceCss,
1147
+ xt as renderOgImageResponse,
1148
+ ye as renderOgImageSvg,
1149
+ rr as renderPageResponse,
1150
+ $t as renderRobots,
1151
+ St as renderSitemap,
1152
+ Gr as resolveLinks,
1153
+ Kr as resolveMetadata,
1154
+ nr as resolveScripts,
1155
+ J as response,
1156
+ bt as runIdempotentMutation,
1157
+ Q as script,
1158
+ Yr as security,
1159
+ X as serializeCacheKey,
1160
+ Zr as serializeCacheNamespace,
1161
+ Qr as serializeCacheTag,
1162
+ Xr as serverTiming,
1163
+ Jr as sse,
1164
+ en as stream,
1165
+ tn as structuredData,
1166
+ rn as tag,
1167
+ nn as text,
1168
+ ee as toResponse,
1169
+ an as validateCorsPolicy,
1170
+ Nt as validateEnv,
1171
+ on as validateRateLimitPolicy,
1172
+ sn as validateRouteModules,
1173
+ Mt as validateUploads,
1174
+ zt as webhook
1317
1175
  };
1318
1176
  //# sourceMappingURL=index.js.map