@demiurgejs/core 0.2.0-beta.1 → 0.2.0-beta.2

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 (107) hide show
  1. package/README.md +2 -0
  2. package/dist/adapter/testing.d.ts +33 -0
  3. package/dist/adapter/testing.d.ts.map +1 -0
  4. package/dist/adapter/testing.js +251 -0
  5. package/dist/adapter/testing.js.map +1 -0
  6. package/dist/browser/file-router.d.ts.map +1 -1
  7. package/dist/chunks/document-shell-D1xo6cEA.js +35 -0
  8. package/dist/chunks/document-shell-D1xo6cEA.js.map +1 -0
  9. package/dist/chunks/image-codec-BGTx_t5K.js +141 -0
  10. package/dist/chunks/image-codec-BGTx_t5K.js.map +1 -0
  11. package/dist/chunks/images-B9MqcjSA.js +339 -0
  12. package/dist/chunks/images-B9MqcjSA.js.map +1 -0
  13. package/dist/chunks/request-metadata-D5NrT8ks.js +642 -0
  14. package/dist/chunks/request-metadata-D5NrT8ks.js.map +1 -0
  15. package/dist/chunks/streaming-BQ1bykDo.js +469 -0
  16. package/dist/chunks/streaming-BQ1bykDo.js.map +1 -0
  17. package/dist/chunks/{testing-DBjVCN5v.js → testing-B_iMFYz_.js} +768 -761
  18. package/dist/chunks/testing-B_iMFYz_.js.map +1 -0
  19. package/dist/cli.d.ts.map +1 -1
  20. package/dist/cli.js +63 -54
  21. package/dist/cli.js.map +1 -1
  22. package/dist/document/deferred-scripts.d.ts +11 -0
  23. package/dist/document/deferred-scripts.d.ts.map +1 -0
  24. package/dist/document/index.d.ts +3 -1
  25. package/dist/document/index.d.ts.map +1 -1
  26. package/dist/document/render.d.ts.map +1 -1
  27. package/dist/document/scripts.d.ts +12 -1
  28. package/dist/document/scripts.d.ts.map +1 -1
  29. package/dist/edge/assets.d.ts +14 -0
  30. package/dist/edge/assets.d.ts.map +1 -0
  31. package/dist/edge/index.d.ts +19 -0
  32. package/dist/edge/index.d.ts.map +1 -0
  33. package/dist/edge/index.js +286 -0
  34. package/dist/edge/index.js.map +1 -0
  35. package/dist/edge/stores.d.ts +8 -0
  36. package/dist/edge/stores.d.ts.map +1 -0
  37. package/dist/edge/streaming.d.ts +7 -0
  38. package/dist/edge/streaming.d.ts.map +1 -0
  39. package/dist/index.d.ts +5 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +423 -420
  42. package/dist/index.js.map +1 -1
  43. package/dist/internal/testing.js +9 -9
  44. package/dist/kv/index.d.ts +3 -0
  45. package/dist/kv/index.d.ts.map +1 -0
  46. package/dist/kv/index.js +103 -0
  47. package/dist/kv/index.js.map +1 -0
  48. package/dist/kv/store.d.ts +28 -0
  49. package/dist/kv/store.d.ts.map +1 -0
  50. package/dist/node/font.d.ts +5 -0
  51. package/dist/node/font.d.ts.map +1 -0
  52. package/dist/node/image.d.ts +15 -0
  53. package/dist/node/image.d.ts.map +1 -0
  54. package/dist/node/index.d.ts +4 -0
  55. package/dist/node/index.d.ts.map +1 -1
  56. package/dist/node/index.js +25 -23
  57. package/dist/node/index.js.map +1 -1
  58. package/dist/node/streaming.d.ts.map +1 -1
  59. package/dist/platform/analytics.d.ts +58 -5
  60. package/dist/platform/analytics.d.ts.map +1 -1
  61. package/dist/platform/font-assets.d.ts +19 -0
  62. package/dist/platform/font-assets.d.ts.map +1 -0
  63. package/dist/platform/fonts.d.ts +14 -4
  64. package/dist/platform/fonts.d.ts.map +1 -1
  65. package/dist/platform/image-codec.d.ts +15 -0
  66. package/dist/platform/image-codec.d.ts.map +1 -0
  67. package/dist/platform/image-url.d.ts +17 -0
  68. package/dist/platform/image-url.d.ts.map +1 -0
  69. package/dist/platform/image.d.ts +8 -0
  70. package/dist/platform/image.d.ts.map +1 -0
  71. package/dist/platform/images.d.ts +15 -0
  72. package/dist/platform/images.d.ts.map +1 -1
  73. package/dist/platform/index.d.ts +8 -5
  74. package/dist/platform/index.d.ts.map +1 -1
  75. package/dist/redis/index.d.ts +3 -0
  76. package/dist/redis/index.d.ts.map +1 -0
  77. package/dist/redis/index.js +171 -0
  78. package/dist/redis/index.js.map +1 -0
  79. package/dist/redis/store.d.ts +8 -0
  80. package/dist/redis/store.d.ts.map +1 -0
  81. package/dist/security/index.d.ts +1 -1
  82. package/dist/security/index.d.ts.map +1 -1
  83. package/dist/security/policy.d.ts +2 -27
  84. package/dist/security/policy.d.ts.map +1 -1
  85. package/dist/security/types.d.ts +10 -3
  86. package/dist/security/types.d.ts.map +1 -1
  87. package/dist/security/verification.d.ts.map +1 -1
  88. package/dist/server/document-shell.d.ts +12 -0
  89. package/dist/server/document-shell.d.ts.map +1 -0
  90. package/dist/static/images.d.ts +13 -0
  91. package/dist/static/images.d.ts.map +1 -0
  92. package/dist/static/index.d.ts +8 -0
  93. package/dist/static/index.d.ts.map +1 -1
  94. package/dist/static/index.js +421 -313
  95. package/dist/static/index.js.map +1 -1
  96. package/dist/static/vercel.d.ts +3 -0
  97. package/dist/static/vercel.d.ts.map +1 -1
  98. package/dist/vite/index.js +412 -387
  99. package/dist/vite/index.js.map +1 -1
  100. package/dist/vite/plugin.d.ts +7 -0
  101. package/dist/vite/plugin.d.ts.map +1 -1
  102. package/package.json +34 -3
  103. package/dist/chunks/request-metadata-DwEO1EAS.js +0 -477
  104. package/dist/chunks/request-metadata-DwEO1EAS.js.map +0 -1
  105. package/dist/chunks/streaming-Ci6vf3BB.js +0 -353
  106. package/dist/chunks/streaming-Ci6vf3BB.js.map +0 -1
  107. package/dist/chunks/testing-DBjVCN5v.js.map +0 -1
@@ -1,78 +1,79 @@
1
- import { existsSync as J } from "node:fs";
2
- import { mkdir as xt, writeFile as Rt, readdir as dt, readFile as pt } from "node:fs/promises";
3
- import { dirname as B, resolve as h, relative as x, sep as $, join as $t } from "node:path";
4
- import St from "magic-string";
5
- import { transformWithEsbuild as Et, parseAst as U } from "vite";
6
- import { e as Nt, f as Dt } from "../chunks/request-metadata-DwEO1EAS.js";
7
- import { e as Pt, d as Ot, f as Mt, s as _, g as W, r as It, i as Ct, h as _t, j as jt } from "../chunks/testing-DBjVCN5v.js";
1
+ import { existsSync as G } from "node:fs";
2
+ import { mkdir as Et, writeFile as Dt, readdir as ht, readFile as gt } from "node:fs/promises";
3
+ import { dirname as q, resolve as w, relative as R, sep as S, join as Nt } from "node:path";
4
+ import Pt from "magic-string";
5
+ import { transformWithEsbuild as Ot, parseAst as Y } from "vite";
6
+ import { e as Mt, f as It } from "../chunks/request-metadata-D5NrT8ks.js";
7
+ import { v as _t, f as Ct, g as jt, s as F, i as B, r as Ft, j as Tt, h as At, k as Vt } from "../chunks/testing-B_iMFYz_.js";
8
8
  import "react";
9
9
  import "react-dom/server";
10
10
  import "react/jsx-runtime";
11
- import { t as q, U as Y, w as z, b as K, c as Ft } from "../chunks/streaming-Ci6vf3BB.js";
12
- const R = "@demiurgejs/core";
13
- async function Tt(t) {
14
- const e = await At(t.routesDir), n = e.map((i) => Lt(t, i)).filter((i) => !!i), o = e.map((i) => Vt(t.routesDir, i, n)).filter((i) => !!i).sort((i, s) => i.pattern.localeCompare(s.pattern)), r = kt(o, n);
15
- return await xt(B(t.outputFile), { recursive: !0 }), await Rt(t.outputFile, r), {
11
+ import { c as Lt, t as X, U as Z, w as tt, b as T, d as kt, e as Wt } from "../chunks/streaming-BQ1bykDo.js";
12
+ import { p as Ht } from "../chunks/images-B9MqcjSA.js";
13
+ const $ = "@demiurgejs/core";
14
+ async function Jt(t) {
15
+ const e = await Bt(t.routesDir), n = e.map((i) => zt(t, i)).filter((i) => !!i), o = e.map((i) => Ut(t.routesDir, i, n)).filter((i) => !!i).sort((i, s) => i.pattern.localeCompare(s.pattern)), r = qt(o, n);
16
+ return await Et(q(t.outputFile), { recursive: !0 }), await Dt(t.outputFile, r), {
16
17
  routes: o,
17
18
  source: r
18
19
  };
19
20
  }
20
- async function At(t) {
21
- return (await dt(t, {
21
+ async function Bt(t) {
22
+ return (await ht(t, {
22
23
  recursive: !0,
23
24
  withFileTypes: !0
24
- })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => h(n.parentPath, n.name));
25
+ })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => w(n.parentPath, n.name));
25
26
  }
26
- function Vt(t, e, n) {
27
- const r = x(t, e).split($).join("/").replace(/\.tsx?$/, "").split("/");
27
+ function Ut(t, e, n) {
28
+ const r = R(t, e).split(S).join("/").replace(/\.tsx?$/, "").split("/");
28
29
  if (r.at(-1)?.startsWith("@"))
29
30
  return null;
30
- const s = r.flatMap((c) => Q(c) ? [] : c === "index" ? [] : c.startsWith("[...") && c.endsWith("]") ? [c] : c.startsWith("[") && c.endsWith("]") ? [c] : [c]), a = r.flatMap((c) => Q(c) ? [] : c.startsWith("[...") && c.endsWith("]") ? [c.slice(4, -1)] : c.startsWith("[") && c.endsWith("]") ? [c.slice(1, -1)] : []);
31
+ const s = r.flatMap((c) => et(c) ? [] : c === "index" ? [] : c.startsWith("[...") && c.endsWith("]") ? [c] : c.startsWith("[") && c.endsWith("]") ? [c] : [c]), a = r.flatMap((c) => et(c) ? [] : c.startsWith("[...") && c.endsWith("]") ? [c.slice(4, -1)] : c.startsWith("[") && c.endsWith("]") ? [c.slice(1, -1)] : []);
31
32
  return {
32
- contextMiddleware: n.filter((c) => Wt(c.fileSegments, r)).map((c) => n.indexOf(c)),
33
+ contextMiddleware: n.filter((c) => Gt(c.fileSegments, r)).map((c) => n.indexOf(c)),
33
34
  fileSegments: r,
34
35
  pathVars: a,
35
36
  pattern: `/${s.join("/")}`.replace(/\/$/, "") || "/"
36
37
  };
37
38
  }
38
- function Lt(t, e) {
39
- const o = x(t.routesDir, e).split($).join("/").replace(/\.tsx?$/, "").split("/");
39
+ function zt(t, e) {
40
+ const o = R(t.routesDir, e).split(S).join("/").replace(/\.tsx?$/, "").split("/");
40
41
  if (o.at(-1) !== "@middleware")
41
42
  return null;
42
- let r = x(B(t.outputFile), e).split($).join("/").replace(/\.tsx?$/, "");
43
+ let r = R(q(t.outputFile), e).split(S).join("/").replace(/\.tsx?$/, "");
43
44
  return r.startsWith(".") || (r = `./${r}`), { file: e, fileSegments: o.slice(0, -1), importPath: r };
44
45
  }
45
- function Wt(t, e) {
46
+ function Gt(t, e) {
46
47
  return t.every(
47
48
  (n, o) => e[o] === n
48
49
  );
49
50
  }
50
- function Q(t) {
51
+ function et(t) {
51
52
  return t.startsWith("(") && t.endsWith(")");
52
53
  }
53
- function kt(t, e) {
54
+ function qt(t, e) {
54
55
  return `// Generated by Demiurge. Do not edit by hand.
55
- import "${R}";
56
- import type { MiddlewareContextOf, PathValue } from "${R}";
57
- ${e.map(Ht).join(`
56
+ import "${$}";
57
+ import type { MiddlewareContextOf, PathValue } from "${$}";
58
+ ${e.map(Yt).join(`
58
59
  `)}
59
60
 
60
- ${e.map((n, o) => Jt(o)).join(`
61
+ ${e.map((n, o) => Kt(o)).join(`
61
62
  `)}
62
63
 
63
- declare module "${R}" {
64
+ declare module "${$}" {
64
65
  interface RoutePathVars {
65
- ${t.map(Bt).join(`
66
+ ${t.map(Qt).join(`
66
67
  `)}
67
68
  }
68
69
 
69
70
  interface RouteConcretePaths {
70
- ${t.map(Ut).join(`
71
+ ${t.map(Xt).join(`
71
72
  `)}
72
73
  }
73
74
 
74
75
  interface RouteRequestContexts {
75
- ${t.map(Gt).join(`
76
+ ${t.map(Zt).join(`
76
77
  `)}
77
78
  }
78
79
  }
@@ -80,32 +81,32 @@ ${t.map(Gt).join(`
80
81
  export {};
81
82
  `;
82
83
  }
83
- function Ht(t, e) {
84
+ function Yt(t, e) {
84
85
  return `type __DemiurgeMiddleware${e} = typeof import(${JSON.stringify(t.importPath)}) extends { middleware?: infer T } ? T : never;`;
85
86
  }
86
- function Jt(t) {
87
+ function Kt(t) {
87
88
  return `type __DemiurgeMiddlewareContext${t} = MiddlewareContextOf<__DemiurgeMiddleware${t}>;`;
88
89
  }
89
- function Bt(t) {
90
+ function Qt(t) {
90
91
  if (t.pathVars.length === 0)
91
92
  return ` ${JSON.stringify(t.pattern)}: {};`;
92
93
  const e = t.pathVars.map((n) => `${n}: PathValue`).join("; ");
93
94
  return ` ${JSON.stringify(t.pattern)}: { ${e} };`;
94
95
  }
95
- function Ut(t) {
96
- return ` ${JSON.stringify(t.pattern)}: ${qt(t.pattern)};`;
96
+ function Xt(t) {
97
+ return ` ${JSON.stringify(t.pattern)}: ${te(t.pattern)};`;
97
98
  }
98
- function Gt(t) {
99
+ function Zt(t) {
99
100
  const e = t.contextMiddleware.map((o) => `__DemiurgeMiddlewareContext${o}`), n = e.length > 0 ? e.join(" & ") : "Record<never, never>";
100
101
  return ` ${JSON.stringify(t.pattern)}: ${n};`;
101
102
  }
102
- function qt(t) {
103
- return t.includes("[") ? `\`${t.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : Yt(n)).join("")}\`` : JSON.stringify(t);
103
+ function te(t) {
104
+ return t.includes("[") ? `\`${t.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : ee(n)).join("")}\`` : JSON.stringify(t);
104
105
  }
105
- function Yt(t) {
106
+ function ee(t) {
106
107
  return t.replace(/[`$\\]/g, "\\$&");
107
108
  }
108
- const zt = [
109
+ const re = [
109
110
  "GET",
110
111
  "POST",
111
112
  "PUT",
@@ -113,7 +114,7 @@ const zt = [
113
114
  "DELETE",
114
115
  "OPTIONS",
115
116
  "HEAD"
116
- ], Kt = /* @__PURE__ */ new Set([
117
+ ], ne = /* @__PURE__ */ new Set([
117
118
  "action",
118
119
  "html",
119
120
  "json",
@@ -125,140 +126,140 @@ const zt = [
125
126
  "stream",
126
127
  "text"
127
128
  ]);
128
- async function Qt(t) {
129
- const e = await pt(t, "utf8");
130
- return await Xt(e, t);
129
+ async function oe(t) {
130
+ const e = await gt(t, "utf8");
131
+ return await ie(e, t);
131
132
  }
132
- async function Xt(t, e) {
133
- const n = e.endsWith(".tsx") ? "tsx" : "ts", o = await Et(t, e, {
133
+ async function ie(t, e) {
134
+ const n = e.endsWith(".tsx") ? "tsx" : "ts", o = await Ot(t, e, {
134
135
  format: "esm",
135
136
  loader: n,
136
137
  target: "esnext"
137
- }), r = Zt(o.code);
138
- return oe(r, e);
138
+ }), r = se(o.code);
139
+ return fe(r, e);
139
140
  }
140
- function Zt(t) {
141
- const e = U(t), n = se(e), o = ae(e), r = te(e), i = ee(e), s = {}, a = /* @__PURE__ */ new Set();
141
+ function se(t) {
142
+ const e = Y(t), n = pe(e), o = me(e), r = ae(e), i = ce(e), s = {}, a = /* @__PURE__ */ new Set();
142
143
  let c;
143
- for (const [u, l] of i) {
144
- const f = r.get(l);
144
+ for (const [u, f] of i) {
145
+ const g = r.get(f);
145
146
  if (u === "policy") {
146
- f && (c = mt(f, n, o));
147
+ g && (c = wt(g, n, o));
147
148
  continue;
148
149
  }
149
- if (!ce(u) || (a.add(u), !f)) continue;
150
- const g = re(f, n, o);
151
- g && (s[u] = g);
150
+ if (!ye(u) || (a.add(u), !g)) continue;
151
+ const l = ue(g, n, o);
152
+ l && (s[u] = l);
152
153
  }
153
154
  return { capabilities: s, declaredMethods: a, policy: c };
154
155
  }
155
- function te(t) {
156
+ function ae(t) {
156
157
  const e = /* @__PURE__ */ new Map();
157
158
  for (const n of d(t.body)) {
158
- const o = n.type === "ExportNamedDeclaration" ? y(n.declaration) : n;
159
+ const o = n.type === "ExportNamedDeclaration" ? h(n.declaration) : n;
159
160
  if (o?.type === "VariableDeclaration")
160
161
  for (const r of d(o.declarations)) {
161
- const i = E(r.id), s = y(r.init);
162
+ const i = D(r.id), s = h(r.init);
162
163
  i && s && e.set(i, s);
163
164
  }
164
165
  }
165
166
  return e;
166
167
  }
167
- function ee(t) {
168
+ function ce(t) {
168
169
  const e = /* @__PURE__ */ new Map();
169
170
  for (const n of d(t.body)) {
170
171
  if (n.type !== "ExportNamedDeclaration") continue;
171
- const o = y(n.declaration);
172
+ const o = h(n.declaration);
172
173
  if (o?.type === "VariableDeclaration")
173
174
  for (const r of d(o.declarations)) {
174
- const i = E(r.id);
175
+ const i = D(r.id);
175
176
  i && e.set(i, i);
176
177
  }
177
178
  for (const r of d(n.specifiers)) {
178
- const i = S(r.exported), s = S(r.local);
179
+ const i = E(r.exported), s = E(r.local);
179
180
  i && s && e.set(i, s);
180
181
  }
181
182
  }
182
183
  return e;
183
184
  }
184
- function re(t, e, n) {
185
+ function ue(t, e, n) {
185
186
  if (t.type !== "CallExpression") return;
186
- const o = E(t.callee), r = o ? e.get(o) : void 0;
187
- if (!r || !Kt.has(r)) return;
187
+ const o = D(t.callee), r = o ? e.get(o) : void 0;
188
+ if (!r || !ne.has(r)) return;
188
189
  const i = d(t.arguments), s = r === "action" ? i[0] : i[1];
189
190
  if (!s) return {};
190
- const a = X(s, "cors", n), c = X(
191
+ const a = rt(s, "cors", n), c = rt(
191
192
  s,
192
193
  "security",
193
194
  n
194
195
  );
195
196
  return {
196
- cors: D(a) ? a : void 0,
197
- security: D(c) ? c : void 0
197
+ cors: P(a) ? a : void 0,
198
+ security: P(c) ? c : void 0
198
199
  };
199
200
  }
200
- function X(t, e, n) {
201
+ function rt(t, e, n) {
201
202
  if (t.type === "Identifier") {
202
203
  const r = n.get(String(t.name));
203
- return D(r) ? r[e] : p;
204
+ return P(r) ? r[e] : m;
204
205
  }
205
- if (t.type !== "ObjectExpression") return p;
206
+ if (t.type !== "ObjectExpression") return m;
206
207
  let o;
207
208
  for (const r of d(t.properties)) {
208
- if (r.type !== "Property" || r.computed) return p;
209
- S(r.key) === e && (o = v(y(r.value), n));
209
+ if (r.type !== "Property" || r.computed) return m;
210
+ E(r.key) === e && (o = b(h(r.value), n));
210
211
  }
211
212
  return o;
212
213
  }
213
- function mt(t, e, n) {
214
+ function wt(t, e, n) {
214
215
  if (t.type === "CallExpression") {
215
- const r = E(t.callee);
216
+ const r = D(t.callee);
216
217
  if (r && e.get(r) === "defineRoutePolicy") {
217
218
  const i = d(t.arguments)[0];
218
- return i ? mt(i, e, n) : void 0;
219
+ return i ? wt(i, e, n) : void 0;
219
220
  }
220
221
  }
221
222
  if (t.type !== "ObjectExpression") {
222
- const r = v(t, n);
223
- return D(r) ? r : void 0;
223
+ const r = b(t, n);
224
+ return P(r) ? r : void 0;
224
225
  }
225
226
  const o = {};
226
227
  for (const r of d(t.properties)) {
227
228
  if (r.type !== "Property" || r.computed) return;
228
- const i = S(r.key), s = y(r.value);
229
+ const i = E(r.key), s = h(r.value);
229
230
  if (!i || !s) return;
230
231
  if (i === "document") {
231
- const c = ne(s, e, n);
232
+ const c = le(s, e, n);
232
233
  if (!c) return;
233
234
  o.document = c;
234
235
  continue;
235
236
  }
236
- const a = v(s, n);
237
- if (a === p) return;
237
+ const a = b(s, n);
238
+ if (a === m) return;
238
239
  o[i] = a;
239
240
  }
240
241
  return o;
241
242
  }
242
- function ne(t, e, n) {
243
+ function le(t, e, n) {
243
244
  if (t.type !== "CallExpression") {
244
- const a = v(t, n);
245
- return D(a) ? a : void 0;
245
+ const a = b(t, n);
246
+ return P(a) ? a : void 0;
246
247
  }
247
- const o = y(t.callee);
248
+ const o = h(t.callee);
248
249
  if (o?.type !== "MemberExpression") return;
249
- const r = E(o.object), i = S(o.property);
250
+ const r = D(o.object), i = E(o.property);
250
251
  if (!r || e.get(r) !== "security" || !i)
251
252
  return;
252
- const s = v(d(t.arguments)[0], n);
253
- if (!(s !== p && s !== void 0 && !D(s))) {
254
- if (i === "api") return _.api(s);
253
+ const s = b(d(t.arguments)[0], n);
254
+ if (!(s !== m && s !== void 0 && !P(s))) {
255
+ if (i === "api") return F.api(s);
255
256
  if (i === "crossOriginIsolated")
256
- return _.crossOriginIsolated(s);
257
- if (i === "static") return _.static(s);
258
- if (i === "strict") return _.strict(s);
257
+ return F.crossOriginIsolated(s);
258
+ if (i === "static") return F.static(s);
259
+ if (i === "strict") return F.strict(s);
259
260
  }
260
261
  }
261
- function oe(t, e) {
262
+ function fe(t, e) {
262
263
  const n = [], o = new Set(t.declaredMethods);
263
264
  o.has("GET") && o.add("HEAD"), o.add("OPTIONS");
264
265
  for (const [r, i] of Object.entries(
@@ -266,40 +267,40 @@ function oe(t, e) {
266
267
  )) {
267
268
  if (i.cors) {
268
269
  try {
269
- Pt(i.cors);
270
+ _t(i.cors);
270
271
  } catch (s) {
271
- n.push(F(
272
+ n.push(V(
272
273
  "cors-invalid",
273
274
  e,
274
- k(s, "The CORS policy is invalid."),
275
+ U(s, "The CORS policy is invalid."),
275
276
  r
276
277
  ));
277
278
  }
278
279
  for (const s of i.cors.methods ?? [])
279
- o.has(s) || n.push(F(
280
+ o.has(s) || n.push(V(
280
281
  "cors-method-unavailable",
281
282
  e,
282
283
  `CORS method ${s} is not available from this route.`,
283
284
  r
284
285
  ));
285
286
  }
286
- Z(i.security, e, r, n);
287
+ nt(i.security, e, r, n);
287
288
  }
288
- if (Z(t.policy?.security, e, void 0, n), t.policy?.document)
289
+ if (nt(t.policy?.security, e, void 0, n), t.policy?.document)
289
290
  try {
290
- Ot(ie(t.policy.document), {
291
+ Ct(de(t.policy.document), {
291
292
  nonce: "build-verification-nonce"
292
293
  });
293
294
  } catch (r) {
294
- n.push(F(
295
+ n.push(V(
295
296
  "security-header-render-failed",
296
297
  e,
297
- k(r, "The security headers are invalid.")
298
+ U(r, "The security headers are invalid.")
298
299
  ));
299
300
  }
300
301
  return n;
301
302
  }
302
- function ie(t) {
303
+ function de(t) {
303
304
  const e = t.headers?.reportingEndpoints, n = !!(e && Object.keys(e).length), o = t.csp === !1 ? void 0 : t.csp?.reportTo;
304
305
  return n || !o ? t : {
305
306
  ...t,
@@ -307,64 +308,64 @@ function ie(t) {
307
308
  headers: e ? { ...t.headers, reportingEndpoints: void 0 } : t.headers
308
309
  };
309
310
  }
310
- function Z(t, e, n, o) {
311
+ function nt(t, e, n, o) {
311
312
  if (t?.rateLimit)
312
313
  try {
313
- Mt(t.rateLimit);
314
+ jt(t.rateLimit);
314
315
  } catch (r) {
315
- o.push(F(
316
+ o.push(V(
316
317
  "rate-limit-invalid",
317
318
  e,
318
- k(r, "The rate limit policy is invalid."),
319
+ U(r, "The rate limit policy is invalid."),
319
320
  n
320
321
  ));
321
322
  }
322
323
  }
323
- function F(t, e, n, o) {
324
+ function V(t, e, n, o) {
324
325
  return { code: t, exportName: o, file: e, message: n, severity: "error" };
325
326
  }
326
- function se(t) {
327
+ function pe(t) {
327
328
  const e = /* @__PURE__ */ new Map();
328
329
  for (const n of d(t.body))
329
- if (!(n.type !== "ImportDeclaration" || y(n.source)?.value !== "@demiurgejs/core"))
330
+ if (!(n.type !== "ImportDeclaration" || h(n.source)?.value !== "@demiurgejs/core"))
330
331
  for (const o of d(n.specifiers)) {
331
332
  if (o.type !== "ImportSpecifier") continue;
332
- const r = E(o.local), i = S(o.imported);
333
+ const r = D(o.local), i = E(o.imported);
333
334
  r && i && e.set(r, i);
334
335
  }
335
336
  return e;
336
337
  }
337
- function ae(t) {
338
+ function me(t) {
338
339
  const e = /* @__PURE__ */ new Map();
339
340
  for (const n of d(t.body)) {
340
- const o = n.type === "ExportNamedDeclaration" ? y(n.declaration) : n;
341
+ const o = n.type === "ExportNamedDeclaration" ? h(n.declaration) : n;
341
342
  if (o?.type === "VariableDeclaration")
342
343
  for (const r of d(o.declarations)) {
343
- const i = E(r.id), s = y(r.init);
344
+ const i = D(r.id), s = h(r.init);
344
345
  if (!i || !s) continue;
345
- const a = v(s, e);
346
- a !== p && e.set(i, a);
346
+ const a = b(s, e);
347
+ a !== m && e.set(i, a);
347
348
  }
348
349
  }
349
350
  return e;
350
351
  }
351
- const p = Symbol("unresolved");
352
- function v(t, e) {
352
+ const m = Symbol("unresolved");
353
+ function b(t, e) {
353
354
  if (t) {
354
355
  if (t.type === "Literal") return t.value;
355
356
  if (t.type === "Identifier")
356
- return t.name === "undefined" ? void 0 : e.has(String(t.name)) ? e.get(String(t.name)) : p;
357
+ return t.name === "undefined" ? void 0 : e.has(String(t.name)) ? e.get(String(t.name)) : m;
357
358
  if (t.type === "TemplateLiteral")
358
- return d(t.expressions).length ? p : d(t.quasis).map((n) => y(n.value)?.cooked ?? "").join("");
359
+ return d(t.expressions).length ? m : d(t.quasis).map((n) => h(n.value)?.cooked ?? "").join("");
359
360
  if (t.type === "UnaryExpression") {
360
- const n = v(y(t.argument), e);
361
- return typeof n != "number" ? p : t.operator === "-" ? -n : t.operator === "+" ? n : p;
361
+ const n = b(h(t.argument), e);
362
+ return typeof n != "number" ? m : t.operator === "-" ? -n : t.operator === "+" ? n : m;
362
363
  }
363
364
  if (t.type === "ArrayExpression") {
364
365
  const n = [];
365
366
  for (const o of d(t.elements)) {
366
- const r = v(o, e);
367
- if (r === p) return p;
367
+ const r = b(o, e);
368
+ if (r === m) return m;
368
369
  n.push(r);
369
370
  }
370
371
  return n;
@@ -372,77 +373,79 @@ function v(t, e) {
372
373
  if (t.type === "ObjectExpression") {
373
374
  const n = {};
374
375
  for (const o of d(t.properties)) {
375
- if (o.type !== "Property" || o.computed) return p;
376
- const r = S(o.key), i = v(y(o.value), e);
377
- if (!r || i === p) return p;
376
+ if (o.type !== "Property" || o.computed) return m;
377
+ const r = E(o.key), i = b(h(o.value), e);
378
+ if (!r || i === m) return m;
378
379
  n[r] = i;
379
380
  }
380
381
  return n;
381
382
  }
382
- return p;
383
+ return m;
383
384
  }
384
385
  }
385
- function ce(t) {
386
- return zt.includes(t);
386
+ function ye(t) {
387
+ return re.includes(t);
387
388
  }
388
- function k(t, e) {
389
+ function U(t, e) {
389
390
  return t instanceof Error ? t.message : e;
390
391
  }
391
- function D(t) {
392
+ function P(t) {
392
393
  return !!t && typeof t == "object" && !Array.isArray(t);
393
394
  }
394
- function y(t) {
395
+ function h(t) {
395
396
  return t && typeof t == "object" && "type" in t ? t : void 0;
396
397
  }
397
398
  function d(t) {
398
- return Array.isArray(t) ? t.map(y).filter((e) => !!e) : [];
399
+ return Array.isArray(t) ? t.map(h).filter((e) => !!e) : [];
399
400
  }
400
- function E(t) {
401
- const e = y(t);
401
+ function D(t) {
402
+ const e = h(t);
402
403
  return e?.type === "Identifier" ? String(e.name) : void 0;
403
404
  }
404
- function S(t) {
405
- const e = y(t);
405
+ function E(t) {
406
+ const e = h(t);
406
407
  return e?.type === "Identifier" || e?.type === "Literal" ? String(e.name ?? e.value) : void 0;
407
408
  }
408
- const V = "virtual:demiurge/client-entry", H = `/@id/${V}`, L = `\0${V}`, yt = "virtual:demiurge/server-entry", tt = `\0${yt}`, et = ".demiurge/route-manifest.d.ts";
409
- function rr(t = {}) {
409
+ const W = "virtual:demiurge/client-entry", z = `/@id/${W}`, J = `\0${W}`, vt = "virtual:demiurge/server-entry", ot = `\0${vt}`, it = ".demiurge/route-manifest.d.ts";
410
+ function fr(t = {}) {
410
411
  let e = process.cwd(), n = !1;
411
- const o = `demiurge-${W()}`;
412
+ const o = `demiurge-${B()}`;
412
413
  return {
413
414
  api: {
414
415
  demiurge: !0,
416
+ fonts: t.fonts,
417
+ images: t.images,
415
418
  staticDeployment: t.static?.deployment,
416
419
  staticFileHeaders: t.static?.headers
417
420
  },
418
421
  enforce: "post",
419
422
  name: "demiurge",
420
423
  config(r, i) {
421
- return ge(r, i, o);
424
+ return Se(r, i, o);
422
425
  },
423
426
  configResolved(r) {
424
427
  e = r.root, n = r.command === "build";
425
428
  },
426
429
  resolveId(r) {
427
- return r === V ? L : r === yt ? tt : null;
430
+ return r === W ? J : r === vt ? ot : null;
428
431
  },
429
432
  load(r) {
430
- return r === L ? we(e, t) : r === tt ? ve(e, t) : null;
433
+ return r === J ? Ee(e, t) : r === ot ? De(e, t) : null;
431
434
  },
432
435
  transform: {
433
436
  order: "post",
434
437
  handler(r, i, s) {
435
- if (!de(e, t, i))
438
+ if (!ve(e, t, i))
436
439
  return null;
437
440
  if (s?.ssr)
438
- return n ? null : ue(r, i);
439
- const a = le(r);
441
+ return n ? null : he(r, i);
442
+ const a = ge(r);
440
443
  return a === r ? null : { code: a, map: null };
441
444
  }
442
445
  },
443
446
  generateBundle(r, i) {
444
447
  const s = Object.values(i).find(
445
- (u) => u.type === "chunk" && u.isEntry && u.facadeModuleId === L
448
+ (u) => u.type === "chunk" && u.isEntry && u.facadeModuleId === J
446
449
  );
447
450
  if (!s)
448
451
  return;
@@ -451,7 +454,7 @@ function rr(t = {}) {
451
454
  ).map((u) => `/${u.fileName}`), c = `/${s.fileName}`;
452
455
  this.emitFile({
453
456
  fileName: "index.html",
454
- source: Ae({
457
+ source: Ue({
455
458
  entrySrc: c,
456
459
  lang: t.document?.lang,
457
460
  styles: a,
@@ -466,18 +469,18 @@ function rr(t = {}) {
466
469
  },
467
470
  async buildStart() {
468
471
  if (n) {
469
- await Ie(e, t);
470
- const r = await ft(e, t);
472
+ await Le(e, t);
473
+ const r = await yt(e, t);
471
474
  if (r.length)
472
- throw new Error(Je(r));
475
+ throw new Error(Qe(r));
473
476
  }
474
- t.typedRoutes && await M(e, t);
477
+ t.typedRoutes && await _(e, t);
475
478
  },
476
479
  configureServer(r) {
477
480
  const i = async () => {
478
- const l = await ft(r.config.root, t);
479
- for (const f of l)
480
- r.config.logger.warn(bt(f));
481
+ const l = await yt(r.config.root, t);
482
+ for (const p of l)
483
+ r.config.logger.warn(St(p));
481
484
  };
482
485
  let s, a = Promise.resolve();
483
486
  const c = () => {
@@ -486,125 +489,139 @@ function rr(t = {}) {
486
489
  }, u = () => {
487
490
  s && clearTimeout(s), s = setTimeout(() => {
488
491
  s = void 0, c();
489
- }, ke), s.unref?.();
492
+ }, Ye), s.unref?.();
490
493
  };
491
494
  if (r.httpServer?.once("close", () => {
492
495
  s && (clearTimeout(s), s = void 0);
493
496
  }), c(), t.typedRoutes) {
494
- const l = h(
497
+ const l = w(
495
498
  r.config.root,
496
499
  t.routesDir ?? "src/routes"
497
500
  );
498
- M(r.config.root, t), r.watcher.add(l), r.watcher.on("add", (f) => {
499
- j(l, f) && (M(r.config.root, t), u());
500
- }), r.watcher.on("change", (f) => {
501
- j(l, f) && (M(r.config.root, t), u());
502
- }), r.watcher.on("unlink", (f) => {
503
- j(l, f) && (M(r.config.root, t), u());
501
+ _(r.config.root, t), r.watcher.add(l), r.watcher.on("add", (p) => {
502
+ A(l, p) && (_(r.config.root, t), u());
503
+ }), r.watcher.on("change", (p) => {
504
+ A(l, p) && (_(r.config.root, t), u());
505
+ }), r.watcher.on("unlink", (p) => {
506
+ A(l, p) && (_(r.config.root, t), u());
504
507
  });
505
508
  } else {
506
- const l = h(
509
+ const l = w(
507
510
  r.config.root,
508
511
  t.routesDir ?? "src/routes"
509
512
  );
510
513
  r.watcher.add(l);
511
- for (const f of ["add", "change", "unlink"])
512
- r.watcher.on(f, (g) => {
513
- j(l, g) && u();
514
+ for (const p of ["add", "change", "unlink"])
515
+ r.watcher.on(p, (N) => {
516
+ A(l, N) && u();
514
517
  });
515
518
  }
516
- return r.middlewares.use(async (l, f, g) => {
519
+ const f = Ie(r, t), g = Lt({
520
+ fonts: t.fonts,
521
+ root: r.config.root
522
+ });
523
+ return r.middlewares.use(async (l, p, N) => {
517
524
  try {
518
- let w;
525
+ let v;
519
526
  try {
520
- w = q(l, {
527
+ v = X(l, {
521
528
  // Vite performs its own configured host allowlist check before
522
529
  // Demiurge's middleware runs. Production Node listeners require
523
530
  // an explicit application allowlist instead.
524
531
  allowedHosts: [l.headers.host ?? "localhost"]
525
532
  });
526
- } catch (O) {
527
- if (O instanceof Y) {
528
- z(f);
533
+ } catch (Q) {
534
+ if (Q instanceof Z) {
535
+ tt(p);
529
536
  return;
530
537
  }
531
- throw O;
538
+ throw Q;
539
+ }
540
+ const O = await g(v);
541
+ if (O) {
542
+ await T(p, O);
543
+ return;
544
+ }
545
+ const M = await f(v);
546
+ if (M) {
547
+ await T(p, M);
548
+ return;
532
549
  }
533
- const I = h(
550
+ const C = w(
534
551
  r.config.root,
535
552
  t.routesDir ?? "src/routes"
536
- ), C = await ct(r, l, I), P = nt(
553
+ ), j = await dt(r, l, C), I = at(
537
554
  r,
538
555
  o
539
- ), N = await Le(
540
- C,
541
- w,
542
- Se(t, P.transform)
556
+ ), H = await Ge(
557
+ j,
558
+ v,
559
+ _e(t, I.transform)
543
560
  );
544
- if (N === "next") {
545
- g();
561
+ if (H === "next") {
562
+ N();
546
563
  return;
547
564
  }
548
- it(N, P.nonce), await K(f, N);
549
- } catch (w) {
550
- g(w);
565
+ ut(H, I.nonce), await T(p, H);
566
+ } catch (v) {
567
+ N(v);
551
568
  }
552
569
  }), () => {
553
- r.middlewares.use(async (l, f, g) => {
570
+ r.middlewares.use(async (l, p, N) => {
554
571
  try {
555
- let w;
572
+ let v;
556
573
  try {
557
- w = q(l, {
574
+ v = X(l, {
558
575
  allowedHosts: [l.headers.host ?? "localhost"]
559
576
  });
560
- } catch (O) {
561
- if (O instanceof Y) {
562
- z(f);
577
+ } catch (I) {
578
+ if (I instanceof Z) {
579
+ tt(p);
563
580
  return;
564
581
  }
565
- throw O;
582
+ throw I;
566
583
  }
567
- const I = h(
584
+ const O = w(
568
585
  r.config.root,
569
586
  t.routesDir ?? "src/routes"
570
- ), C = await ct(r, l, I);
571
- Me(C, I);
572
- const P = nt(
587
+ ), M = await dt(r, l, O);
588
+ Ve(M, O);
589
+ const C = at(
573
590
  r,
574
591
  o
575
- ), N = await It(
576
- C,
577
- w,
578
- Oe(t, P.transform)
592
+ ), j = await Ft(
593
+ M,
594
+ v,
595
+ Ae(t, C.transform)
579
596
  );
580
- it(
581
- N,
582
- P.nonce
583
- ), await K(f, N);
584
- } catch (w) {
585
- g(w);
597
+ ut(
598
+ j,
599
+ C.nonce
600
+ ), await T(p, j);
601
+ } catch (v) {
602
+ N(v);
586
603
  }
587
604
  });
588
605
  };
589
606
  }
590
607
  };
591
608
  }
592
- function ue(t, e) {
609
+ function he(t, e) {
593
610
  if (!t.includes("import.meta"))
594
611
  return null;
595
- const n = U(t), o = b(n.body).find(
596
- (u) => u.type === "ImportDeclaration" && b(u.specifiers).some(
597
- (l) => m(l.local)?.type === "Identifier" && m(l.local)?.name === "meta"
612
+ const n = Y(t), o = x(n.body).find(
613
+ (u) => u.type === "ImportDeclaration" && x(u.specifiers).some(
614
+ (f) => y(f.local)?.type === "Identifier" && y(f.local)?.name === "meta"
598
615
  )
599
- ), r = o && b(o.specifiers).find(
600
- (u) => m(u.local)?.type === "Identifier" && m(u.local)?.name === "meta"
601
- ), i = r && m(r.local);
616
+ ), r = o && x(o.specifiers).find(
617
+ (u) => y(u.local)?.type === "Identifier" && y(u.local)?.name === "meta"
618
+ ), i = r && y(r.local);
602
619
  if (!o || !r || !i)
603
620
  return null;
604
621
  let s = "__demiurge_imported_meta__";
605
622
  for (; new RegExp(`\\b${s}\\b`).test(t); )
606
623
  s += "_";
607
- const a = new St(t), c = m(r.imported);
624
+ const a = new Pt(t), c = y(r.imported);
608
625
  return a.overwrite(
609
626
  i.start,
610
627
  i.end,
@@ -619,138 +636,138 @@ const meta = ${s};`), {
619
636
  })
620
637
  };
621
638
  }
622
- function le(t) {
623
- const e = U(t), n = [], o = fe(e), r = [];
624
- T(e, (a) => {
625
- if (a.type === "ImportDeclaration" && me(a)) {
639
+ function ge(t) {
640
+ const e = Y(t), n = [], o = we(e), r = [];
641
+ L(e, (a) => {
642
+ if (a.type === "ImportDeclaration" && xe(a)) {
626
643
  r.push(a);
627
644
  return;
628
645
  }
629
- if (a.type !== "CallExpression" || !pe(a.callee))
646
+ if (a.type !== "CallExpression" || !be(a.callee))
630
647
  return;
631
- const c = b(a.arguments)[0];
648
+ const c = x(a.arguments)[0];
632
649
  if (c?.type === "ObjectExpression")
633
- for (const u of b(c.properties))
634
- u.type === "Property" && A(u.key) === "data" && n.push({ end: u.end, start: u.start });
650
+ for (const u of x(c.properties))
651
+ u.type === "Property" && k(u.key) === "data" && n.push({ end: u.end, start: u.start });
635
652
  });
636
653
  const i = [...n, ...o];
637
654
  if (i.length === 0)
638
655
  return t;
639
656
  const s = [...i];
640
657
  for (const a of r) {
641
- const c = b(a.specifiers).map((f) => m(f.local)).filter((f) => f?.type === "Identifier").map((f) => String(f.name)), u = ye(t, [
658
+ const c = x(a.specifiers).map((g) => y(g.local)).filter((g) => g?.type === "Identifier").map((g) => String(g.name)), u = Re(t, [
642
659
  ...i,
643
660
  { end: a.end, start: a.start }
644
- ]), l = c.find(
645
- (f) => new RegExp(`\\b${ht(f)}\\b`).test(u)
661
+ ]), f = c.find(
662
+ (g) => new RegExp(`\\b${bt(g)}\\b`).test(u)
646
663
  );
647
- if (l)
664
+ if (f)
648
665
  throw new Error(
649
- `Server-only import ${JSON.stringify(l)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
666
+ `Server-only import ${JSON.stringify(f)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
650
667
  );
651
668
  s.push({ end: a.end, start: a.start });
652
669
  }
653
- return he(
670
+ return $e(
654
671
  t,
655
672
  s,
656
673
  (a) => n.includes(a) ? "data: undefined" : o.includes(a) ? "undefined" : ""
657
674
  );
658
675
  }
659
- const rt = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
660
- function fe(t) {
676
+ const st = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
677
+ function we(t) {
661
678
  const e = /* @__PURE__ */ new Set();
662
- for (const o of b(t.body)) {
679
+ for (const o of x(t.body)) {
663
680
  if (o.type !== "ExportNamedDeclaration") continue;
664
- const r = m(o.declaration);
681
+ const r = y(o.declaration);
665
682
  if (r?.type === "VariableDeclaration")
666
- for (const i of b(r.declarations)) {
667
- const s = m(i.id);
668
- s?.type === "Identifier" && rt.has(String(s.name)) && e.add(String(s.name));
683
+ for (const i of x(r.declarations)) {
684
+ const s = y(i.id);
685
+ s?.type === "Identifier" && st.has(String(s.name)) && e.add(String(s.name));
669
686
  }
670
- for (const i of b(o.specifiers)) {
671
- const s = A(i.exported), a = A(i.local);
672
- s && a && rt.has(s) && e.add(a);
687
+ for (const i of x(o.specifiers)) {
688
+ const s = k(i.exported), a = k(i.local);
689
+ s && a && st.has(s) && e.add(a);
673
690
  }
674
691
  }
675
692
  const n = [];
676
- return T(t, (o) => {
693
+ return L(t, (o) => {
677
694
  if (o.type !== "VariableDeclarator") return;
678
- const r = m(o.id), i = m(o.init);
695
+ const r = y(o.id), i = y(o.init);
679
696
  r?.type === "Identifier" && e.has(String(r.name)) && i && n.push({ end: i.end, start: i.start });
680
697
  }), n;
681
698
  }
682
- function de(t, e, n) {
683
- const o = n.split("?", 1)[0] ?? n, r = h(t, e.routesDir ?? "src/routes"), i = x(r, o);
684
- return i !== "" && i !== ".." && !i.startsWith(`..${$}`);
699
+ function ve(t, e, n) {
700
+ const o = n.split("?", 1)[0] ?? n, r = w(t, e.routesDir ?? "src/routes"), i = R(r, o);
701
+ return i !== "" && i !== ".." && !i.startsWith(`..${S}`);
685
702
  }
686
- function T(t, e) {
703
+ function L(t, e) {
687
704
  if (!t || typeof t != "object") return;
688
705
  if (Array.isArray(t)) {
689
- for (const o of t) T(o, e);
706
+ for (const o of t) L(o, e);
690
707
  return;
691
708
  }
692
709
  const n = t;
693
710
  if (typeof n.type == "string") {
694
711
  e(n);
695
712
  for (const [o, r] of Object.entries(n))
696
- (/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(o) || T(r, e);
713
+ (/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(o) || L(r, e);
697
714
  }
698
715
  }
699
- function m(t) {
716
+ function y(t) {
700
717
  return t && typeof t == "object" && "type" in t ? t : void 0;
701
718
  }
702
- function b(t) {
703
- return Array.isArray(t) ? t.map(m).filter((e) => !!e) : [];
719
+ function x(t) {
720
+ return Array.isArray(t) ? t.map(y).filter((e) => !!e) : [];
704
721
  }
705
- function pe(t) {
706
- const e = m(t);
707
- return e?.type === "Identifier" ? e.name === "page" : e?.type === "MemberExpression" && A(e.property) === "page";
722
+ function be(t) {
723
+ const e = y(t);
724
+ return e?.type === "Identifier" ? e.name === "page" : e?.type === "MemberExpression" && k(e.property) === "page";
708
725
  }
709
- function A(t) {
710
- const e = m(t);
726
+ function k(t) {
727
+ const e = y(t);
711
728
  return e?.type === "Identifier" || e?.type === "Literal" ? String(e.name ?? e.value) : void 0;
712
729
  }
713
- function me(t) {
714
- const e = m(t.source)?.value;
730
+ function xe(t) {
731
+ const e = y(t.source)?.value;
715
732
  return typeof e == "string" && /(?:^|[/.-])server(?:[/.-]|$)/.test(e);
716
733
  }
717
- function ye(t, e) {
734
+ function Re(t, e) {
718
735
  const n = [...t];
719
736
  for (const { end: o, start: r } of e)
720
737
  n.fill(" ", r, o);
721
738
  return n.join("");
722
739
  }
723
- function he(t, e, n) {
740
+ function $e(t, e, n) {
724
741
  return [...e].sort((o, r) => r.start - o.start).reduce(
725
742
  (o, r) => `${o.slice(0, r.start)}${n(r)}${o.slice(r.end)}`,
726
743
  t
727
744
  );
728
745
  }
729
- function ht(t) {
746
+ function bt(t) {
730
747
  return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
731
748
  }
732
- function ge(t, e, n) {
749
+ function Se(t, e, n) {
733
750
  return {
734
751
  appType: "custom",
735
752
  build: {
736
753
  assetsInlineLimit: t.build?.assetsInlineLimit ?? 0,
737
754
  ...e.isSsrBuild && t.build?.target === void 0 && t.ssr?.target !== "webworker" ? { target: "node22.13" } : {},
738
755
  rollupOptions: {
739
- input: t.build?.rollupOptions?.input ?? V
756
+ input: t.build?.rollupOptions?.input ?? W
740
757
  }
741
758
  },
742
759
  ...e.command === "serve" ? {
743
760
  html: { cspNonce: n },
744
- ssr: { external: [R] }
761
+ ssr: { external: [$] }
745
762
  } : {}
746
763
  };
747
764
  }
748
- function we(t, e = {}) {
749
- const n = e.routesDir ?? "src/routes", o = $e(t, e);
750
- return `import { hydrateFileRouter } from "${R}";
765
+ function Ee(t, e = {}) {
766
+ const n = e.routesDir ?? "src/routes", o = Me(t, e);
767
+ return `import { hydrateFileRouter } from "${$}";
751
768
  ${o}
752
769
 
753
- ${gt(n, {
770
+ ${xt(n, {
754
771
  exportRoutes: !1,
755
772
  includeServerOnly: !1
756
773
  })}
@@ -758,11 +775,11 @@ ${gt(n, {
758
775
  void hydrateFileRouter({ routes });
759
776
  `;
760
777
  }
761
- function ve(t, e = {}) {
778
+ function De(t, e = {}) {
762
779
  const n = e.routesDir ?? "src/routes";
763
- return `import { createRequestHandler } from "${R}";
780
+ return `import { createRequestHandler } from "${$}";
764
781
 
765
- ${gt(n, {
782
+ ${xt(n, {
766
783
  exportRoutes: !0,
767
784
  includeServerOnly: !0,
768
785
  eagerModules: !0
@@ -785,12 +802,12 @@ export function createHandler(options = {}) {
785
802
  }
786
803
  `;
787
804
  }
788
- function gt(t, {
805
+ function xt(t, {
789
806
  exportRoutes: e,
790
807
  eagerModules: n = !1,
791
808
  includeServerOnly: o
792
809
  }) {
793
- const r = xe(t, o), i = Re(t);
810
+ const r = Pe(t, o), i = Oe(t);
794
811
  return n ? `const eagerRouteModules = import.meta.glob(${JSON.stringify(r)}, { eager: true });
795
812
  const routePrefix = ${JSON.stringify(i)};
796
813
  export const routeModules = Object.fromEntries(
@@ -813,41 +830,49 @@ ${e ? "export " : ""}const routes = Object.fromEntries(
813
830
  ]),
814
831
  );`;
815
832
  }
816
- const be = ["@middleware.ts", "@policy.ts"];
817
- function xe(t, e) {
833
+ const Ne = ["@middleware.ts", "@policy.ts"];
834
+ function Pe(t, e) {
818
835
  const n = `/${t.replace(/^\/|\/$/g, "")}`, o = [`${n}/**/*.{ts,tsx}`];
819
836
  return e || o.push(
820
- ...be.flatMap((r) => [
837
+ ...Ne.flatMap((r) => [
821
838
  `!${n}/${r}`,
822
839
  `!${n}/**/${r}`
823
840
  ])
824
841
  ), o;
825
842
  }
826
- function Re(t) {
843
+ function Oe(t) {
827
844
  return `/${t.replace(/^\/|\/$/g, "")}/`;
828
845
  }
829
- function $e(t, e) {
846
+ function Me(t, e) {
830
847
  if (e.styles === !1)
831
848
  return "";
832
- const n = e.styles ?? "src/styles.css", o = h(t, n);
833
- return J(o) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
834
- }
835
- function Se(t, e) {
849
+ const n = e.styles ?? "src/styles.css", o = w(t, n);
850
+ return G(o) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
851
+ }
852
+ function Ie(t, e) {
853
+ const n = t.config.publicDir, o = e.images?.optimizerPath ?? "/_demiurge/image";
854
+ return n ? kt({
855
+ policy: e.images,
856
+ resolveVariant: (r) => Ht(r, o),
857
+ root: n
858
+ }) : async () => null;
859
+ }
860
+ function _e(t, e) {
836
861
  return {
837
862
  dev: !0,
838
- ssr: vt(t),
863
+ ssr: $t(t),
839
864
  transformDocument: e,
840
865
  renderPage: async (n, o) => {
841
866
  if (n.render.mode === "streaming")
842
- return await Ft(n, {
867
+ return await Wt(n, {
843
868
  ...o,
844
- clientEntry: H,
869
+ clientEntry: z,
845
870
  transformDocument: e
846
871
  });
847
872
  const r = await e(
848
- Dt(n, {
873
+ It(n, {
849
874
  ...o,
850
- clientEntry: H
875
+ clientEntry: z
851
876
  })
852
877
  );
853
878
  return new Response(r, {
@@ -856,21 +881,21 @@ function Se(t, e) {
856
881
  }
857
882
  };
858
883
  }
859
- function nt(t, e) {
860
- const n = W(), o = W();
884
+ function at(t, e) {
885
+ const n = B(), o = B();
861
886
  return {
862
887
  nonce: n,
863
888
  transform: async (r) => {
864
- const i = Ee(r, o), s = await t.transformIndexHtml("/", i);
865
- return ot(
866
- ot(s, o),
889
+ const i = Ce(r, o), s = await t.transformIndexHtml("/", i);
890
+ return ct(
891
+ ct(s, o),
867
892
  e,
868
893
  n
869
894
  );
870
895
  }
871
896
  };
872
897
  }
873
- function Ee(t, e) {
898
+ function Ce(t, e) {
874
899
  const n = t.toLowerCase();
875
900
  let o = 0, r = "";
876
901
  for (; o < t.length; ) {
@@ -878,8 +903,8 @@ function Ee(t, e) {
878
903
  if (i === -1)
879
904
  return r + t.slice(o);
880
905
  if (r += t.slice(o, i), n.startsWith("<!--", i)) {
881
- const u = n.indexOf("-->", i + 4), l = u === -1 ? t.length : u + 3;
882
- r += t.slice(i, l), o = l;
906
+ const u = n.indexOf("-->", i + 4), f = u === -1 ? t.length : u + 3;
907
+ r += t.slice(i, f), o = f;
883
908
  continue;
884
909
  }
885
910
  const s = n.slice(i).match(/^<\s*(script|style|link)\b/)?.[1];
@@ -887,11 +912,11 @@ function Ee(t, e) {
887
912
  r += "<", o = i + 1;
888
913
  continue;
889
914
  }
890
- const a = Ne(t, i);
915
+ const a = je(t, i);
891
916
  if (a === -1)
892
917
  return r + t.slice(i);
893
918
  const c = t.slice(i, a + 1);
894
- if (r += /(?:^|\s)nonce(?:\s|=|>)/i.test(c) ? c : De(c, e), o = a + 1, s === "script" || s === "style") {
919
+ if (r += /(?:^|\s)nonce(?:\s|=|>)/i.test(c) ? c : Fe(c, e), o = a + 1, s === "script" || s === "style") {
895
920
  const u = n.indexOf(`</${s}`, o);
896
921
  if (u === -1)
897
922
  return r + t.slice(o);
@@ -900,7 +925,7 @@ function Ee(t, e) {
900
925
  }
901
926
  return r;
902
927
  }
903
- function Ne(t, e) {
928
+ function je(t, e) {
904
929
  let n;
905
930
  for (let o = e + 1; o < t.length; o++) {
906
931
  const r = t[o];
@@ -915,13 +940,13 @@ function Ne(t, e) {
915
940
  }
916
941
  return -1;
917
942
  }
918
- function De(t, e) {
943
+ function Fe(t, e) {
919
944
  const n = /\/\s*>$/.test(t) ? t.lastIndexOf("/") : t.length - 1;
920
945
  return `${t.slice(0, n)} nonce="${e}"${t.slice(n)}`;
921
946
  }
922
- function ot(t, e, n) {
947
+ function ct(t, e, n) {
923
948
  const o = new RegExp(
924
- `(\\snonce\\s*=\\s*)(["'])${ht(e)}\\2`,
949
+ `(\\snonce\\s*=\\s*)(["'])${bt(e)}\\2`,
925
950
  "g"
926
951
  );
927
952
  return t.replace(
@@ -929,19 +954,19 @@ function ot(t, e, n) {
929
954
  n ? `$1"${n}"` : ""
930
955
  );
931
956
  }
932
- function it(t, e) {
957
+ function ut(t, e) {
933
958
  const n = t.headers.get("content-type"), o = t.headers.get("content-security-policy");
934
959
  if (!n?.toLowerCase().startsWith("text/html") || !o)
935
960
  return;
936
- const r = `'nonce-${e}'`, i = st(
961
+ const r = `'nonce-${e}'`, i = lt(
937
962
  o,
938
963
  ["script-src-elem", "script-src"],
939
964
  "script-src",
940
965
  r
941
- ), s = Pe(
966
+ ), s = Te(
942
967
  i,
943
968
  ["style-src-elem", "style-src"]
944
- ) ? i : st(
969
+ ) ? i : lt(
945
970
  i,
946
971
  ["style-src-elem", "style-src"],
947
972
  "style-src",
@@ -949,27 +974,27 @@ function it(t, e) {
949
974
  );
950
975
  t.headers.set("content-security-policy", s), t.headers.set("cache-control", "private, no-store");
951
976
  }
952
- function st(t, e, n, o) {
953
- const r = t.split(";").map((l) => l.trim()), i = wt(r, e), s = r.find(
954
- (l) => l.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
977
+ function lt(t, e, n, o) {
978
+ const r = t.split(";").map((f) => f.trim()), i = Rt(r, e), s = r.find(
979
+ (f) => f.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
955
980
  );
956
981
  if (i === -1 && !s) return t;
957
982
  const [a, ...c] = (i === -1 ? s : r[i]).split(/\s+/), u = [
958
983
  i === -1 ? n : a,
959
984
  .../* @__PURE__ */ new Set([
960
- ...c.filter((l) => l !== "'none'"),
985
+ ...c.filter((f) => f !== "'none'"),
961
986
  o
962
987
  ])
963
988
  ].join(" ");
964
989
  return i === -1 ? r.push(u) : r[i] = u, r.join("; ");
965
990
  }
966
- function Pe(t, e) {
967
- const n = t.split(";").map((s) => s.trim()), o = wt(n, e), i = (o === -1 ? n.find(
991
+ function Te(t, e) {
992
+ const n = t.split(";").map((s) => s.trim()), o = Rt(n, e), i = (o === -1 ? n.find(
968
993
  (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
969
994
  ) : n[o])?.split(/\s+/).slice(1) ?? [];
970
995
  return i.includes("'unsafe-inline'") && !i.some((s) => /^'(?:nonce-|sha(?:256|384|512)-)/i.test(s));
971
996
  }
972
- function wt(t, e) {
997
+ function Rt(t, e) {
973
998
  for (const n of e) {
974
999
  const o = t.findIndex(
975
1000
  (r) => r.split(/\s+/, 1)[0]?.toLowerCase() === n
@@ -978,65 +1003,65 @@ function wt(t, e) {
978
1003
  }
979
1004
  return -1;
980
1005
  }
981
- const at = Symbol.for("demiurge.devManifest");
982
- async function ct(t, e, n) {
983
- const o = e, r = o[at];
1006
+ const ft = Symbol.for("demiurge.devManifest");
1007
+ async function dt(t, e, n) {
1008
+ const o = e, r = o[ft];
984
1009
  if (r)
985
1010
  return r;
986
- const i = jt(
987
- await Ve(t, n)
1011
+ const i = Vt(
1012
+ await ze(t, n)
988
1013
  );
989
- return o[at] = i, i;
1014
+ return o[ft] = i, i;
990
1015
  }
991
- function vt(t) {
1016
+ function $t(t) {
992
1017
  return {
993
- clientEntry: H,
1018
+ clientEntry: z,
994
1019
  lang: t.document?.lang,
995
1020
  title: t.document?.title
996
1021
  };
997
1022
  }
998
- function Oe(t, e) {
1023
+ function Ae(t, e) {
999
1024
  return {
1000
- ...vt(t),
1025
+ ...$t(t),
1001
1026
  dev: !0,
1002
1027
  transformDocument: e
1003
1028
  };
1004
1029
  }
1005
- const ut = /* @__PURE__ */ new Set();
1006
- function Me(t, e) {
1007
- ut.has(e) || t.fallbacks.notFound.some(
1030
+ const pt = /* @__PURE__ */ new Set();
1031
+ function Ve(t, e) {
1032
+ pt.has(e) || t.fallbacks.notFound.some(
1008
1033
  (n) => n.fileSegments.length === 0
1009
- ) || (ut.add(e), console.warn(Te($t(e, "@not-found.tsx"))));
1034
+ ) || (pt.add(e), console.warn(Be(Nt(e, "@not-found.tsx"))));
1010
1035
  }
1011
- async function Ie(t, e = {}) {
1012
- const n = e.routesDir ?? "src/routes", o = h(t, n);
1013
- if (!J(o))
1036
+ async function Le(t, e = {}) {
1037
+ const n = e.routesDir ?? "src/routes", o = w(t, n);
1038
+ if (!G(o))
1014
1039
  return;
1015
- const r = await G(o);
1040
+ const r = await K(o);
1016
1041
  if (r.map(
1017
- (a) => x(o, a).split($).join("/")
1042
+ (a) => R(o, a).split(S).join("/")
1018
1043
  ).some((a) => /^@not-found\.tsx?$/.test(a)))
1019
1044
  return;
1020
- const s = await Ce(r);
1045
+ const s = await ke(r);
1021
1046
  if (s)
1022
1047
  throw new Error(
1023
- Fe(
1048
+ Je(
1024
1049
  n,
1025
- x(o, s).split($).join("/")
1050
+ R(o, s).split(S).join("/")
1026
1051
  )
1027
1052
  );
1028
1053
  }
1029
- async function Ce(t) {
1054
+ async function ke(t) {
1030
1055
  for (const e of t)
1031
- if (!x(B(e), e).startsWith("@") && je(await pt(e, "utf8")))
1056
+ if (!R(q(e), e).startsWith("@") && He(await gt(e, "utf8")))
1032
1057
  return e;
1033
1058
  }
1034
- const _e = R.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), lt = new RegExp(
1035
- `import\\s*\\{([^}]*)\\}\\s*from\\s*["']${_e}["']`,
1059
+ const We = $.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), mt = new RegExp(
1060
+ `import\\s*\\{([^}]*)\\}\\s*from\\s*["']${We}["']`,
1036
1061
  "g"
1037
1062
  );
1038
- function je(t) {
1039
- const e = [...t.matchAll(lt)].flatMap(
1063
+ function He(t) {
1064
+ const e = [...t.matchAll(mt)].flatMap(
1040
1065
  (o) => o[1].split(",").flatMap((r) => {
1041
1066
  const [i, s] = r.trim().split(/\s+as\s+/);
1042
1067
  return i.replace(/^type\s+/, "") === "page" ? [s ?? i] : [];
@@ -1044,10 +1069,10 @@ function je(t) {
1044
1069
  );
1045
1070
  if (e.length === 0)
1046
1071
  return !1;
1047
- const n = t.replace(lt, "");
1072
+ const n = t.replace(mt, "");
1048
1073
  return e.some((o) => new RegExp(`\\b${o}\\s*\\(`).test(n));
1049
1074
  }
1050
- function Fe(t, e) {
1075
+ function Je(t, e) {
1051
1076
  return `Demiurge will not build an app with page routes and no ${t}/@not-found.tsx.
1052
1077
 
1053
1078
  "${e}" declares a page, so a browser can reach a path this app does not serve. Decide what that looks like rather than shipping the framework built-in.
@@ -1060,7 +1085,7 @@ Create ${t}/@not-found.tsx:
1060
1085
 
1061
1086
  It renders inside the layouts above the requested path. Opt out with "export const layout = false".`;
1062
1087
  }
1063
- function Te(t) {
1088
+ function Be(t) {
1064
1089
  return `Demiurge is serving its built-in 404 because ${t} does not exist.
1065
1090
 
1066
1091
  Create it before building for production:
@@ -1070,7 +1095,7 @@ Create it before building for production:
1070
1095
  }
1071
1096
  `;
1072
1097
  }
1073
- function Ae({
1098
+ function Ue({
1074
1099
  entrySrc: t,
1075
1100
  lang: e,
1076
1101
  links: n,
@@ -1080,7 +1105,7 @@ function Ae({
1080
1105
  styles: s,
1081
1106
  title: a
1082
1107
  }) {
1083
- return Nt({
1108
+ return Mt({
1084
1109
  entrySrc: t,
1085
1110
  lang: e,
1086
1111
  links: n,
@@ -1091,36 +1116,36 @@ function Ae({
1091
1116
  title: a
1092
1117
  });
1093
1118
  }
1094
- async function M(t, e) {
1095
- const n = h(t, e.routesDir ?? "src/routes"), o = h(
1119
+ async function _(t, e) {
1120
+ const n = w(t, e.routesDir ?? "src/routes"), o = w(
1096
1121
  t,
1097
- typeof e.typedRoutes == "object" ? e.typedRoutes.outputFile ?? et : et
1122
+ typeof e.typedRoutes == "object" ? e.typedRoutes.outputFile ?? it : it
1098
1123
  );
1099
- await Tt({ outputFile: o, routesDir: n });
1124
+ await Jt({ outputFile: o, routesDir: n });
1100
1125
  }
1101
- function j(t, e) {
1126
+ function A(t, e) {
1102
1127
  return e.startsWith(t) && /\.tsx?$/.test(e);
1103
1128
  }
1104
- async function Ve(t, e) {
1105
- const n = await G(e), o = {};
1129
+ async function ze(t, e) {
1130
+ const n = await K(e), o = {};
1106
1131
  for (const r of n) {
1107
- const i = Be(e, r);
1132
+ const i = Xe(e, r);
1108
1133
  o[i] = async () => await t.ssrLoadModule(r);
1109
1134
  }
1110
1135
  return o;
1111
1136
  }
1112
- async function Le(t, e, n = {}) {
1137
+ async function Ge(t, e, n = {}) {
1113
1138
  const o = new URL(e.url);
1114
- return Ct(t.routes, o.pathname) ? await _t(t, e, n) : "next";
1139
+ return Tt(t.routes, o.pathname) ? await At(t, e, n) : "next";
1115
1140
  }
1116
- async function G(t) {
1117
- return (await dt(t, {
1141
+ async function K(t) {
1142
+ return (await ht(t, {
1118
1143
  recursive: !0,
1119
1144
  withFileTypes: !0
1120
- })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => h(n.parentPath, n.name));
1145
+ })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => w(n.parentPath, n.name));
1121
1146
  }
1122
- const We = 8, ke = 50;
1123
- async function He(t, e, n) {
1147
+ const qe = 8, Ye = 50;
1148
+ async function Ke(t, e, n) {
1124
1149
  const o = new Array(t.length);
1125
1150
  let r = 0;
1126
1151
  const i = Array.from(
@@ -1134,41 +1159,41 @@ async function He(t, e, n) {
1134
1159
  );
1135
1160
  return await Promise.all(i), o;
1136
1161
  }
1137
- async function ft(t, e = {}) {
1138
- const n = h(t, e.routesDir ?? "src/routes");
1139
- return J(n) ? (await He(
1140
- await G(n),
1141
- We,
1142
- Qt
1162
+ async function yt(t, e = {}) {
1163
+ const n = w(t, e.routesDir ?? "src/routes");
1164
+ return G(n) ? (await Ke(
1165
+ await K(n),
1166
+ qe,
1167
+ oe
1143
1168
  )).flat().sort(
1144
1169
  (r, i) => r.file.localeCompare(i.file) || (r.exportName ?? "").localeCompare(i.exportName ?? "") || r.code.localeCompare(i.code)
1145
1170
  ) : [];
1146
1171
  }
1147
- function Je(t) {
1172
+ function Qe(t) {
1148
1173
  return [
1149
1174
  "Demiurge found invalid static route policy:",
1150
- ...t.map(bt)
1175
+ ...t.map(St)
1151
1176
  ].join(`
1152
1177
  `);
1153
1178
  }
1154
- function bt(t) {
1179
+ function St(t) {
1155
1180
  return `${t.exportName ? `${t.file} export ${t.exportName}` : t.file}: [${t.code}] ${t.message}`;
1156
1181
  }
1157
- function Be(t, e) {
1158
- return `./routes/${x(t, e).split($).join("/")}`;
1182
+ function Xe(t, e) {
1183
+ return `./routes/${R(t, e).split(S).join("/")}`;
1159
1184
  }
1160
1185
  export {
1161
- rr as demiurge,
1162
- Ie as unstable_assertRootNotFoundRoute,
1163
- we as unstable_createClientEntrySource,
1164
- Ve as unstable_createDevRouteImporters,
1165
- Ae as unstable_createDocumentHtml,
1166
- ve as unstable_createServerEntrySource,
1167
- je as unstable_declaresPageRoute,
1168
- Je as unstable_formatStaticPolicyFindings,
1169
- Le as unstable_handleDevRequest,
1170
- le as unstable_stripClientPageData,
1171
- ft as unstable_verifyRoutePolicies,
1172
- Xt as unstable_verifyRoutePolicySource
1186
+ fr as demiurge,
1187
+ Le as unstable_assertRootNotFoundRoute,
1188
+ Ee as unstable_createClientEntrySource,
1189
+ ze as unstable_createDevRouteImporters,
1190
+ Ue as unstable_createDocumentHtml,
1191
+ De as unstable_createServerEntrySource,
1192
+ He as unstable_declaresPageRoute,
1193
+ Qe as unstable_formatStaticPolicyFindings,
1194
+ Ge as unstable_handleDevRequest,
1195
+ ge as unstable_stripClientPageData,
1196
+ yt as unstable_verifyRoutePolicies,
1197
+ ie as unstable_verifyRoutePolicySource
1173
1198
  };
1174
1199
  //# sourceMappingURL=index.js.map