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

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 (156) 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-WoM8yZlR.js +35 -0
  8. package/dist/chunks/document-shell-WoM8yZlR.js.map +1 -0
  9. package/dist/chunks/image-codec-Di53WpcH.js +141 -0
  10. package/dist/chunks/image-codec-Di53WpcH.js.map +1 -0
  11. package/dist/chunks/images-Edar3eU1.js +339 -0
  12. package/dist/chunks/images-Edar3eU1.js.map +1 -0
  13. package/dist/chunks/request-metadata-DaIYq4Ea.js +677 -0
  14. package/dist/chunks/request-metadata-DaIYq4Ea.js.map +1 -0
  15. package/dist/chunks/streaming-D0fGAuiO.js +469 -0
  16. package/dist/chunks/streaming-D0fGAuiO.js.map +1 -0
  17. package/dist/chunks/{testing-DBjVCN5v.js → testing-CRflAw4X.js} +1300 -1139
  18. package/dist/chunks/testing-CRflAw4X.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/data/cache.d.ts +8 -0
  23. package/dist/data/cache.d.ts.map +1 -1
  24. package/dist/data/idempotency.d.ts.map +1 -1
  25. package/dist/data/index.d.ts +3 -1
  26. package/dist/data/index.d.ts.map +1 -1
  27. package/dist/data/testing.d.ts.map +1 -1
  28. package/dist/data/testing.js +94 -72
  29. package/dist/data/testing.js.map +1 -1
  30. package/dist/data/tiered.d.ts +7 -0
  31. package/dist/data/tiered.d.ts.map +1 -0
  32. package/dist/document/deferred-scripts.d.ts +11 -0
  33. package/dist/document/deferred-scripts.d.ts.map +1 -0
  34. package/dist/document/hydration.d.ts.map +1 -1
  35. package/dist/document/index.d.ts +4 -1
  36. package/dist/document/index.d.ts.map +1 -1
  37. package/dist/document/render.d.ts.map +1 -1
  38. package/dist/document/scripts.d.ts +12 -1
  39. package/dist/document/scripts.d.ts.map +1 -1
  40. package/dist/document/trusted-types.d.ts +10 -0
  41. package/dist/document/trusted-types.d.ts.map +1 -0
  42. package/dist/edge/assets.d.ts +14 -0
  43. package/dist/edge/assets.d.ts.map +1 -0
  44. package/dist/edge/index.d.ts +19 -0
  45. package/dist/edge/index.d.ts.map +1 -0
  46. package/dist/edge/index.js +286 -0
  47. package/dist/edge/index.js.map +1 -0
  48. package/dist/edge/stores.d.ts +8 -0
  49. package/dist/edge/stores.d.ts.map +1 -0
  50. package/dist/edge/streaming.d.ts +7 -0
  51. package/dist/edge/streaming.d.ts.map +1 -0
  52. package/dist/index.d.ts +7 -7
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +895 -556
  55. package/dist/index.js.map +1 -1
  56. package/dist/internal/testing.js +6 -6
  57. package/dist/kv/index.d.ts +5 -0
  58. package/dist/kv/index.d.ts.map +1 -0
  59. package/dist/kv/index.js +126 -0
  60. package/dist/kv/index.js.map +1 -0
  61. package/dist/kv/rate-limit-store.d.ts +8 -0
  62. package/dist/kv/rate-limit-store.d.ts.map +1 -0
  63. package/dist/kv/store.d.ts +28 -0
  64. package/dist/kv/store.d.ts.map +1 -0
  65. package/dist/node/font.d.ts +5 -0
  66. package/dist/node/font.d.ts.map +1 -0
  67. package/dist/node/http.d.ts.map +1 -1
  68. package/dist/node/image.d.ts +15 -0
  69. package/dist/node/image.d.ts.map +1 -0
  70. package/dist/node/index.d.ts +4 -0
  71. package/dist/node/index.d.ts.map +1 -1
  72. package/dist/node/index.js +25 -23
  73. package/dist/node/index.js.map +1 -1
  74. package/dist/node/static.d.ts.map +1 -1
  75. package/dist/node/streaming.d.ts.map +1 -1
  76. package/dist/platform/analytics.d.ts +58 -5
  77. package/dist/platform/analytics.d.ts.map +1 -1
  78. package/dist/platform/font-assets.d.ts +19 -0
  79. package/dist/platform/font-assets.d.ts.map +1 -0
  80. package/dist/platform/fonts.d.ts +14 -4
  81. package/dist/platform/fonts.d.ts.map +1 -1
  82. package/dist/platform/image-codec.d.ts +15 -0
  83. package/dist/platform/image-codec.d.ts.map +1 -0
  84. package/dist/platform/image-url.d.ts +17 -0
  85. package/dist/platform/image-url.d.ts.map +1 -0
  86. package/dist/platform/image.d.ts +8 -0
  87. package/dist/platform/image.d.ts.map +1 -0
  88. package/dist/platform/images.d.ts +15 -0
  89. package/dist/platform/images.d.ts.map +1 -1
  90. package/dist/platform/index.d.ts +13 -6
  91. package/dist/platform/index.d.ts.map +1 -1
  92. package/dist/platform/observability.d.ts +2 -1
  93. package/dist/platform/observability.d.ts.map +1 -1
  94. package/dist/platform/web-vitals-client.d.ts +32 -0
  95. package/dist/platform/web-vitals-client.d.ts.map +1 -0
  96. package/dist/platform/web-vitals.d.ts +78 -0
  97. package/dist/platform/web-vitals.d.ts.map +1 -0
  98. package/dist/redis/index.d.ts +5 -0
  99. package/dist/redis/index.d.ts.map +1 -0
  100. package/dist/redis/index.js +209 -0
  101. package/dist/redis/index.js.map +1 -0
  102. package/dist/redis/rate-limit-store.d.ts +8 -0
  103. package/dist/redis/rate-limit-store.d.ts.map +1 -0
  104. package/dist/redis/store.d.ts +8 -0
  105. package/dist/redis/store.d.ts.map +1 -0
  106. package/dist/route/action.d.ts.map +1 -1
  107. package/dist/route/middleware.d.ts.map +1 -1
  108. package/dist/route/response.d.ts.map +1 -1
  109. package/dist/router/index.d.ts +1 -1
  110. package/dist/router/index.d.ts.map +1 -1
  111. package/dist/router/manifest.d.ts +1 -0
  112. package/dist/router/manifest.d.ts.map +1 -1
  113. package/dist/security/cookies.d.ts +26 -0
  114. package/dist/security/cookies.d.ts.map +1 -0
  115. package/dist/security/env.d.ts.map +1 -1
  116. package/dist/security/fetch-metadata.d.ts +29 -0
  117. package/dist/security/fetch-metadata.d.ts.map +1 -0
  118. package/dist/security/index.d.ts +5 -1
  119. package/dist/security/index.d.ts.map +1 -1
  120. package/dist/security/policy.d.ts +2 -27
  121. package/dist/security/policy.d.ts.map +1 -1
  122. package/dist/security/rate-limit.d.ts +6 -3
  123. package/dist/security/rate-limit.d.ts.map +1 -1
  124. package/dist/security/request.d.ts.map +1 -1
  125. package/dist/security/types.d.ts +82 -6
  126. package/dist/security/types.d.ts.map +1 -1
  127. package/dist/security/verification.d.ts.map +1 -1
  128. package/dist/server/document-shell.d.ts +12 -0
  129. package/dist/server/document-shell.d.ts.map +1 -0
  130. package/dist/server/index.d.ts +1 -1
  131. package/dist/server/index.d.ts.map +1 -1
  132. package/dist/server/request-handler.d.ts +6 -2
  133. package/dist/server/request-handler.d.ts.map +1 -1
  134. package/dist/static/images.d.ts +13 -0
  135. package/dist/static/images.d.ts.map +1 -0
  136. package/dist/static/index.d.ts +8 -0
  137. package/dist/static/index.d.ts.map +1 -1
  138. package/dist/static/index.js +421 -313
  139. package/dist/static/index.js.map +1 -1
  140. package/dist/static/vercel.d.ts +3 -0
  141. package/dist/static/vercel.d.ts.map +1 -1
  142. package/dist/vite/index.d.ts +3 -0
  143. package/dist/vite/index.d.ts.map +1 -1
  144. package/dist/vite/index.js +1041 -652
  145. package/dist/vite/index.js.map +1 -1
  146. package/dist/vite/plugin.d.ts +9 -0
  147. package/dist/vite/plugin.d.ts.map +1 -1
  148. package/dist/vite/policy-verification.d.ts.map +1 -1
  149. package/dist/vite/route-audit.d.ts +50 -0
  150. package/dist/vite/route-audit.d.ts.map +1 -0
  151. package/package.json +34 -3
  152. package/dist/chunks/request-metadata-DwEO1EAS.js +0 -477
  153. package/dist/chunks/request-metadata-DwEO1EAS.js.map +0 -1
  154. package/dist/chunks/streaming-Ci6vf3BB.js +0 -353
  155. package/dist/chunks/streaming-Ci6vf3BB.js.map +0 -1
  156. package/dist/chunks/testing-DBjVCN5v.js.map +0 -1
@@ -1,14 +1,76 @@
1
- import { readFile as v, mkdir as E, mkdtemp as W, cp as k, writeFile as A, rm as $, rename as rt } from "node:fs/promises";
2
- import { resolve as h, relative as w, sep as g, extname as nt, dirname as N, join as m } from "node:path";
3
- import { d as it, S as F } from "../chunks/request-metadata-DwEO1EAS.js";
4
- import { v as ot, c as st, a as at, h as ct, r as ut, m as ft, b as D, d as lt } from "../chunks/testing-DBjVCN5v.js";
1
+ import { readFile as O, mkdir as T, mkdtemp as k, cp as D, writeFile as b, rm as A, rename as nt } from "node:fs/promises";
2
+ import { resolve as h, relative as w, sep as S, extname as it, dirname as C, join as y } from "node:path";
3
+ import { d as ot, S as P } from "../chunks/request-metadata-DaIYq4Ea.js";
4
+ import { v as st, a as at, b as ct, d as ut, h as lt, r as ft, m as dt, e as _, f as ht } from "../chunks/testing-CRflAw4X.js";
5
5
  import "react-dom/server";
6
6
  import "react";
7
7
  import "react/jsx-runtime";
8
- import { C as _, I as dt, R as ht } from "../chunks/static-files-DUjHw-4H.js";
9
- import { createServer as pt } from "node:http";
10
- import { normalizeRoutes as mt, getTransformedRoutes as wt } from "@vercel/routing-utils";
11
- const yt = "demiurge-static-manifest.json", gt = {
8
+ import { C as U, I as pt, R as mt } from "../chunks/static-files-DUjHw-4H.js";
9
+ import { t as wt, n as gt, r as yt } from "../chunks/image-codec-Di53WpcH.js";
10
+ import { e as V, g as St, p as Et, h as $t } from "../chunks/images-Edar3eU1.js";
11
+ import { createServer as vt } from "node:http";
12
+ import { normalizeRoutes as Ot, getTransformedRoutes as Rt } from "@vercel/routing-utils";
13
+ async function Tt(t) {
14
+ const e = h(t.outDir), r = t.policy ?? {}, n = r.optimizerPath ?? V, o = new Set(
15
+ t.documents.flatMap(
16
+ (a) => St(a, n)
17
+ )
18
+ ), s = [], c = /* @__PURE__ */ new Map();
19
+ for (const a of [...o].sort()) {
20
+ const i = Et(a, n);
21
+ if (!i)
22
+ throw new Error(
23
+ `Static output references image variant ${JSON.stringify(a)}, which does not describe a transform the build can emit.`
24
+ );
25
+ if (!$t(i.src, r))
26
+ throw new Error(
27
+ `Image source ${JSON.stringify(i.src)} is not allowed by the image policy.`
28
+ );
29
+ const u = Ft(e, i.src);
30
+ let f = c.get(u);
31
+ f || (f = await Nt(u, i.src), c.set(u, f));
32
+ const E = await wt(f, {
33
+ format: gt(i, null),
34
+ quality: i.quality,
35
+ width: i.width
36
+ });
37
+ s.push({ body: E.body, file: a.slice(1) });
38
+ }
39
+ return s;
40
+ }
41
+ function At(t, e = {}) {
42
+ const r = e.optimizerPath ?? V, n = new RegExp(`${r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\?`);
43
+ for (const o of t)
44
+ if (n.test(o))
45
+ throw new Error(
46
+ 'Static output references the request-time image optimizer, which a static build cannot serve. Set loader: "static" in the image policy, or deploy a runtime adapter.'
47
+ );
48
+ }
49
+ async function Nt(t, e) {
50
+ try {
51
+ return new Uint8Array(await O(t));
52
+ } catch (r) {
53
+ throw new Error(
54
+ `Demiurge could not read the source image ${JSON.stringify(e)} from the build output.`,
55
+ { cause: r }
56
+ );
57
+ }
58
+ }
59
+ function Ft(t, e) {
60
+ let r;
61
+ try {
62
+ r = decodeURIComponent(e);
63
+ } catch {
64
+ throw new Error(`Image source is not valid UTF-8: ${JSON.stringify(e)}.`);
65
+ }
66
+ const n = h(t, `.${r}`);
67
+ if (w(t, n).split(S).includes(".."))
68
+ throw new Error(
69
+ `Image source escaped the build output directory: ${JSON.stringify(e)}.`
70
+ );
71
+ return n;
72
+ }
73
+ const xt = "demiurge-static-manifest.json", bt = {
12
74
  ".avif": "image/avif",
13
75
  ".css": "text/css; charset=utf-8",
14
76
  ".gif": "image/gif",
@@ -27,131 +89,131 @@ const yt = "demiurge-static-manifest.json", gt = {
27
89
  ".woff": "font/woff",
28
90
  ".woff2": "font/woff2"
29
91
  };
30
- async function de(t) {
31
- const e = h(t.outDir), r = Et(
32
- await v(h(e, yt), "utf8")
92
+ async function Ne(t) {
93
+ const e = h(t.outDir), r = Pt(
94
+ await O(h(e, xt), "utf8")
33
95
  ), n = new Map(
34
- r.entries.map((o) => [o.pathname, o])
35
- ), i = new Map(
36
- r.entries.map((o) => [o.file, o])
37
- ), a = r.fileHeaderRules.map((o) => ({
38
- ...o,
39
- expression: new RegExp(o.pattern)
40
- })), c = pt(async (o, s) => {
96
+ r.entries.map((a) => [a.pathname, a])
97
+ ), o = new Map(
98
+ r.entries.map((a) => [a.file, a])
99
+ ), s = r.fileHeaderRules.map((a) => ({
100
+ ...a,
101
+ expression: new RegExp(a.pattern)
102
+ })), c = vt(async (a, i) => {
41
103
  try {
42
- if (o.method !== "GET" && o.method !== "HEAD") {
43
- s.writeHead(405, { allow: "GET, HEAD" }), s.end();
104
+ if (a.method !== "GET" && a.method !== "HEAD") {
105
+ i.writeHead(405, { allow: "GET, HEAD" }), i.end();
44
106
  return;
45
107
  }
46
- const f = new URL(o.url ?? "/", "http://demiurge.local");
47
- let l;
108
+ const u = new URL(a.url ?? "/", "http://demiurge.local");
109
+ let f;
48
110
  try {
49
- l = decodeURIComponent(f.pathname);
111
+ f = decodeURIComponent(u.pathname);
50
112
  } catch {
51
- s.writeHead(400, {
113
+ i.writeHead(400, {
52
114
  "content-type": "text/plain; charset=utf-8"
53
- }), s.end("The request path is not valid UTF-8.");
115
+ }), i.end("The request path is not valid UTF-8.");
54
116
  return;
55
117
  }
56
- const R = l.replace(/\/$/, "") || "/", y = n.get(R);
57
- if (y) {
58
- await T(e, y, o.method, s);
118
+ const E = f.replace(/\/$/, "") || "/", $ = n.get(E);
119
+ if ($) {
120
+ await F(e, $, a.method, i);
59
121
  return;
60
122
  }
61
- const u = St(e, l);
62
- if (u)
123
+ const p = Ct(e, f);
124
+ if (p)
63
125
  try {
64
- const p = w(e, u).split(g).join("/"), b = i.get(p);
65
- if (b) {
66
- await T(e, b, o.method, s);
126
+ const m = w(e, p).split(S).join("/"), l = o.get(m);
127
+ if (l) {
128
+ await F(e, l, a.method, i);
67
129
  return;
68
130
  }
69
- const X = await v(u), j = gt[nt(u).toLowerCase()];
70
- j && s.setHeader("content-type", j);
71
- const Y = l.split("/").at(-1) ?? "", tt = a.find(({ expression: et }) => et.test(Y));
72
- U(s, tt?.headers ?? {}), s.writeHead(200), s.end(o.method === "HEAD" ? void 0 : X);
131
+ const d = await O(p), v = bt[it(p).toLowerCase()];
132
+ v && i.setHeader("content-type", v);
133
+ const tt = f.split("/").at(-1) ?? "", et = s.find(({ expression: rt }) => rt.test(tt));
134
+ z(i, et?.headers ?? {}), i.writeHead(200), i.end(a.method === "HEAD" ? void 0 : d);
73
135
  return;
74
- } catch (p) {
75
- if (!Ot(p)) throw p;
136
+ } catch (m) {
137
+ if (!Ht(m)) throw m;
76
138
  }
77
- const d = n.get("*");
78
- if (!d) {
79
- s.writeHead(404), s.end();
139
+ const g = n.get("*");
140
+ if (!g) {
141
+ i.writeHead(404), i.end();
80
142
  return;
81
143
  }
82
- await T(e, d, o.method, s);
144
+ await F(e, g, a.method, i);
83
145
  } catch {
84
- s.writeHead(500, {
146
+ i.writeHead(500, {
85
147
  "content-type": "text/plain; charset=utf-8"
86
- }), s.end("Demiurge could not serve the static output.");
148
+ }), i.end("Demiurge could not serve the static output.");
87
149
  }
88
150
  });
89
- return await new Promise((o, s) => {
90
- const f = (l) => s(l);
91
- c.once("error", f), c.listen(
151
+ return await new Promise((a, i) => {
152
+ const u = (f) => i(f);
153
+ c.once("error", u), c.listen(
92
154
  t.port ?? 4173,
93
155
  t.host ?? "localhost",
94
156
  () => {
95
- c.off("error", f), o();
157
+ c.off("error", u), a();
96
158
  }
97
159
  );
98
160
  }), c;
99
161
  }
100
- async function T(t, e, r, n) {
101
- const i = B(t, e.file), a = await v(i);
102
- U(n, e.headers), n.writeHead(e.status), n.end(r === "HEAD" ? void 0 : a);
162
+ async function F(t, e, r, n) {
163
+ const o = q(t, e.file), s = await O(o);
164
+ z(n, e.headers), n.writeHead(e.status), n.end(r === "HEAD" ? void 0 : s);
103
165
  }
104
- function U(t, e) {
166
+ function z(t, e) {
105
167
  for (const [r, n] of Object.entries(e))
106
168
  t.setHeader(r, n);
107
169
  }
108
- function St(t, e) {
170
+ function Ct(t, e) {
109
171
  if (!e.endsWith("/"))
110
- return V(t, `.${e}`);
172
+ return B(t, `.${e}`);
111
173
  }
112
- function B(t, e) {
113
- const r = V(t, e);
174
+ function q(t, e) {
175
+ const r = B(t, e);
114
176
  if (!r)
115
177
  throw new Error(`Static preview file is outside the output directory: ${JSON.stringify(e)}.`);
116
178
  return r;
117
179
  }
118
- function V(t, e) {
180
+ function B(t, e) {
119
181
  if (!e || e.startsWith("/") || e.startsWith("\\") || e.split(/[\\/]/).includes(".."))
120
182
  return;
121
183
  const r = h(t, e), n = w(t, r);
122
- return n !== ".." && !n.startsWith(`..${g}`) ? r : void 0;
184
+ return n !== ".." && !n.startsWith(`..${S}`) ? r : void 0;
123
185
  }
124
- function Et(t) {
186
+ function Pt(t) {
125
187
  let e;
126
188
  try {
127
189
  e = JSON.parse(t);
128
190
  } catch {
129
191
  throw new Error("The static output manifest is not valid JSON.");
130
192
  }
131
- if (!O(e) || e.adapter !== "static" || e.version !== 1)
193
+ if (!N(e) || e.adapter !== "static" || e.version !== 1)
132
194
  throw new Error("The static output manifest has an unsupported format.");
133
195
  if (!Array.isArray(e.entries) || !Array.isArray(e.fileHeaderRules))
134
196
  throw new Error("The static output manifest does not contain header rules and entries.");
135
- const r = e.entries.map(vt), n = e.fileHeaderRules.map($t), i = /* @__PURE__ */ new Set();
136
- for (const a of r) {
137
- if (i.has(a.pathname))
138
- throw new Error(`The static output manifest repeats pathname ${JSON.stringify(a.pathname)}.`);
139
- i.add(a.pathname);
197
+ const r = e.entries.map(It), n = e.fileHeaderRules.map(jt), o = /* @__PURE__ */ new Set();
198
+ for (const s of r) {
199
+ if (o.has(s.pathname))
200
+ throw new Error(`The static output manifest repeats pathname ${JSON.stringify(s.pathname)}.`);
201
+ o.add(s.pathname);
140
202
  }
141
203
  return { adapter: "static", entries: r, fileHeaderRules: n, version: 1 };
142
204
  }
143
- function vt(t) {
144
- if (!O(t) || typeof t.file != "string" || typeof t.pathname != "string" || t.status !== 200 && t.status !== 404 || !q(t.headers))
205
+ function It(t) {
206
+ if (!N(t) || typeof t.file != "string" || typeof t.pathname != "string" || t.status !== 200 && t.status !== 404 || !G(t.headers))
145
207
  throw new Error("The static output manifest contains an invalid entry.");
146
- return B("/demiurge-manifest-root", t.file), {
208
+ return q("/demiurge-manifest-root", t.file), {
147
209
  file: t.file,
148
210
  headers: t.headers,
149
211
  pathname: t.pathname,
150
212
  status: t.status
151
213
  };
152
214
  }
153
- function $t(t) {
154
- if (!O(t) || typeof t.pattern != "string" || !q(t.headers))
215
+ function jt(t) {
216
+ if (!N(t) || typeof t.pattern != "string" || !G(t.headers))
155
217
  throw new Error("The static output manifest contains an invalid file header rule.");
156
218
  try {
157
219
  new RegExp(t.pattern);
@@ -160,125 +222,132 @@ function $t(t) {
160
222
  }
161
223
  return { headers: t.headers, pattern: t.pattern };
162
224
  }
163
- function O(t) {
225
+ function N(t) {
164
226
  return !!t && typeof t == "object" && !Array.isArray(t);
165
227
  }
166
- function q(t) {
167
- return O(t) && Object.values(t).every(
228
+ function G(t) {
229
+ return N(t) && Object.values(t).every(
168
230
  (e) => typeof e == "string"
169
231
  );
170
232
  }
171
- function Ot(t) {
233
+ function Ht(t) {
172
234
  return t instanceof Error && "code" in t && (t.code === "EISDIR" || t.code === "ENOENT");
173
235
  }
174
- const Rt = "demiurge-manifest.json", Tt = "demiurge-static-manifest.json";
175
- function he(t = {}) {
236
+ const Jt = "demiurge-manifest.json", Mt = "demiurge-static-manifest.json";
237
+ function Fe(t = {}) {
176
238
  return {
177
239
  adapter: "vercel",
178
240
  cache: t.cache?.map((e) => ({
179
241
  source: e.source,
180
242
  value: e.value
181
- })) ?? []
243
+ })) ?? [],
244
+ cors: t.cors
182
245
  };
183
246
  }
184
- async function pe(t) {
185
- Ft(t.deployment);
247
+ async function xe(t) {
248
+ Vt(t.deployment);
186
249
  const e = h(t.projectRoot), r = h(t.outDir), n = h(e, ".vercel/output");
187
- if (Ht(r, n))
250
+ if (zt(r, n))
188
251
  throw new Error(
189
252
  "The static output directory must not overlap the Vercel output directory."
190
253
  );
191
- const i = N(n);
192
- await E(i, { recursive: !0 });
193
- const a = await W(m(i, "output-demiurge-"));
254
+ const o = C(n);
255
+ await T(o, { recursive: !0 });
256
+ const s = await k(y(o, "output-demiurge-"));
194
257
  try {
195
- const c = m(a, "static");
196
- await k(r, c, {
197
- filter: (o) => {
198
- const s = w(r, o).split(g).join("/");
199
- return s !== Rt && s !== Tt;
258
+ const c = y(s, "static");
259
+ await D(r, c, {
260
+ filter: (a) => {
261
+ const i = w(r, a).split(S).join("/");
262
+ return i !== Jt && i !== Mt;
200
263
  },
201
264
  recursive: !0
202
- }), await A(
203
- m(a, "config.json"),
204
- `${JSON.stringify(xt(
265
+ }), await b(
266
+ y(s, "config.json"),
267
+ `${JSON.stringify(Lt(
205
268
  t.manifest,
206
269
  t.deployment
207
270
  ), null, 2)}
208
271
  `
209
- ), await $(n, { force: !0, recursive: !0 }), await rt(a, n);
272
+ ), await A(n, { force: !0, recursive: !0 }), await nt(s, n);
210
273
  } catch (c) {
211
- throw await $(a, { force: !0, recursive: !0 }), c;
274
+ throw await A(s, { force: !0, recursive: !0 }), c;
212
275
  }
213
276
  return n;
214
277
  }
215
- function xt(t, e) {
216
- const r = t.entries.find((o) => o.pathname === "*");
278
+ function Lt(t, e) {
279
+ const r = t.entries.find((i) => i.pathname === "*");
217
280
  if (!r)
218
281
  throw new Error("Vercel output requires a static fallback entry.");
219
- const n = jt(e.cache), i = [];
220
- for (const o of t.entries) {
221
- if (o.pathname === "*") continue;
222
- const s = `/${o.file}`;
223
- s !== o.pathname && i.push({
282
+ const n = _t(e.cache), s = [
283
+ {
284
+ continue: !0,
285
+ headers: { "access-control-allow-origin": Ut(e.cors, t.origin) },
286
+ src: "^/.*$"
287
+ }
288
+ ];
289
+ for (const i of t.entries) {
290
+ if (i.pathname === "*") continue;
291
+ const u = `/${i.file}`;
292
+ u !== i.pathname && s.push({
224
293
  continue: !0,
225
- dest: o.pathname,
226
- src: S(s)
294
+ dest: i.pathname,
295
+ src: R(u)
227
296
  });
228
297
  }
229
- for (const o of t.entries) {
230
- const s = H(o.headers);
231
- if (Object.keys(s).length === 0) continue;
232
- const f = o.pathname === "*" ? `/${o.file}` : o.pathname;
233
- i.push({
298
+ for (const i of t.entries) {
299
+ const u = I(i.headers);
300
+ if (Object.keys(u).length === 0) continue;
301
+ const f = i.pathname === "*" ? `/${i.file}` : i.pathname;
302
+ s.push({
234
303
  continue: !0,
235
- headers: s,
236
- src: S(f)
304
+ headers: u,
305
+ src: R(f)
237
306
  });
238
307
  }
239
- i.push(...n);
240
- for (const o of t.entries) {
241
- if (o.pathname === "*") {
242
- i.push({
243
- dest: `/${o.file}`,
244
- src: S(`/${o.file}`),
308
+ s.push(...n);
309
+ for (const i of t.entries) {
310
+ if (i.pathname === "*") {
311
+ s.push({
312
+ dest: `/${i.file}`,
313
+ src: R(`/${i.file}`),
245
314
  status: 404
246
315
  });
247
316
  continue;
248
317
  }
249
- i.push({
250
- dest: o.pathname === "/" ? `/${o.file}` : o.pathname,
251
- src: S(o.pathname)
318
+ s.push({
319
+ dest: i.pathname === "/" ? `/${i.file}` : i.pathname,
320
+ src: R(i.pathname)
252
321
  });
253
322
  }
254
- i.push({ handle: "hit" });
255
- for (const o of [...t.fileHeaderRules].reverse())
256
- i.push({
323
+ s.push({ handle: "hit" });
324
+ for (const i of [...t.fileHeaderRules].reverse())
325
+ s.push({
257
326
  continue: !0,
258
- headers: { ...o.headers },
259
- src: Nt(o.pattern)
327
+ headers: { ...i.headers },
328
+ src: kt(i.pattern)
260
329
  });
261
- i.push(...n.map((o) => ({ ...o }))), i.push({ handle: "error" });
262
- const a = H(r.headers);
263
- Object.keys(a).length > 0 && i.push({
330
+ s.push(...n.map((i) => ({ ...i }))), s.push({ handle: "error" });
331
+ const c = I(r.headers);
332
+ Object.keys(c).length > 0 && s.push({
264
333
  continue: !0,
265
- headers: a,
334
+ headers: c,
266
335
  src: "^/.*$"
267
- }), i.push(...n.map((o) => ({ ...o }))), i.push({ dest: `/${r.file}`, src: "^/.*$", status: 404 });
268
- const c = mt(i);
269
- if (c.error || !c.routes)
336
+ }), s.push(...n.map((i) => ({ ...i }))), s.push({ dest: `/${r.file}`, src: "^/.*$", status: 404 });
337
+ const a = Ot(s);
338
+ if (a.error || !a.routes)
270
339
  throw new Error(
271
- `Vercel rejected the generated routes: ${c.error?.message ?? "The route list is empty."}`
340
+ `Vercel rejected the generated routes: ${a.error?.message ?? "The route list is empty."}`
272
341
  );
273
342
  return {
274
343
  overrides: Object.fromEntries(
275
- t.entries.map((o) => [o.file, At(o)])
344
+ t.entries.map((i) => [i.file, Wt(i)])
276
345
  ),
277
- routes: c.routes,
346
+ routes: a.routes,
278
347
  version: 3
279
348
  };
280
349
  }
281
- function At(t) {
350
+ function Wt(t) {
282
351
  const e = {}, r = t.headers["content-type"];
283
352
  if (r && (e.contentType = r), t.pathname !== "*") {
284
353
  const n = t.file === "index.html" ? "/" : `/${t.file}`;
@@ -286,166 +355,196 @@ function At(t) {
286
355
  }
287
356
  return e;
288
357
  }
289
- function S(t) {
358
+ function R(t) {
290
359
  const e = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
291
360
  return t === "/" ? "^/$" : `^${e}/?$`;
292
361
  }
293
- function H(t) {
362
+ function I(t) {
294
363
  return Object.fromEntries(
295
364
  Object.entries(t).filter(([e]) => e.toLowerCase() !== "content-type")
296
365
  );
297
366
  }
298
- function Nt(t) {
299
- return t === ".*" ? "^/.*$" : t === _.source ? "^/(?:.*/)?[^/]*-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$" : `^/${bt(t)}$`;
367
+ function kt(t) {
368
+ return t === ".*" ? "^/.*$" : t === U.source ? "^/(?:.*/)?[^/]*-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$" : `^/${Dt(t)}$`;
300
369
  }
301
- function bt(t) {
370
+ function Dt(t) {
302
371
  const e = t.startsWith("^"), r = t.endsWith("$") && !t.endsWith("\\$"), n = t.slice(
303
372
  e ? 1 : 0,
304
373
  r ? -1 : void 0
305
374
  );
306
375
  return `${e ? "(?:.*/)?" : "(?:.*/)?[^/]*"}(?:${n})${r ? "" : "[^/]*"}`;
307
376
  }
308
- function jt(t) {
377
+ function _t(t) {
309
378
  const e = t.map((n) => ({
310
379
  headers: [{ key: "cache-control", value: n.value }],
311
380
  source: n.source
312
- })), r = wt({ headers: e });
381
+ })), r = Rt({ headers: e });
313
382
  if (r.error || !r.routes)
314
383
  throw new Error(
315
384
  `A Vercel static header rule is not valid: ${r.error?.message ?? "The route list is empty."}`
316
385
  );
317
386
  return r.routes;
318
387
  }
319
- function Ft(t) {
388
+ function Ut(t, e) {
389
+ if (t) {
390
+ if (st(t), t.origins === "*")
391
+ return "*";
392
+ if (t.origins.length === 1)
393
+ return t.origins[0];
394
+ throw new Error(
395
+ "A Vercel static CORS policy must declare the wildcard origin or exactly one origin. A static response cannot vary access-control-allow-origin by request."
396
+ );
397
+ }
398
+ if (!e)
399
+ throw new Error(
400
+ "Vercel static output requires a build origin to emit access-control-allow-origin. Pass --origin, set SITE_ORIGIN, or declare a Vercel CORS policy."
401
+ );
402
+ return e;
403
+ }
404
+ function Vt(t) {
320
405
  if (t.adapter !== "vercel" || !Array.isArray(t.cache))
321
406
  throw new Error("The Vercel static adapter configuration is not valid.");
322
407
  for (const e of t.cache)
323
408
  if (!e || typeof e != "object" || typeof e.source != "string" || !e.source || typeof e.value != "string" || !e.value)
324
409
  throw new Error("A Vercel static header rule is not valid.");
325
410
  }
326
- function Ht(t, e) {
411
+ function zt(t, e) {
327
412
  const r = w(t, e), n = w(e, t);
328
- return C(r) || C(n);
413
+ return j(r) || j(n);
329
414
  }
330
- function C(t) {
331
- return !t || t !== ".." && !t.startsWith(`..${g}`) && !t.startsWith("/");
415
+ function j(t) {
416
+ return !t || t !== ".." && !t.startsWith(`..${S}`) && !t.startsWith("/");
332
417
  }
333
- const G = "demiurge-static-manifest.json", Ct = it({
418
+ const K = "demiurge-static-manifest.json", qt = ot({
334
419
  name: "static",
335
420
  capabilities: {
336
421
  staticOutput: !0
337
422
  }
338
- }), Pt = 8;
339
- async function Jt(t) {
423
+ }), Bt = 8;
424
+ async function Gt(t) {
340
425
  const e = Object.entries(t), r = new Array(e.length);
341
426
  let n = 0;
342
- const i = Array.from(
343
- { length: Math.min(Pt, e.length) },
427
+ const o = Array.from(
428
+ { length: Math.min(Bt, e.length) },
344
429
  async () => {
345
430
  for (; n < e.length; ) {
346
- const a = n++, [c, o] = e[a];
431
+ const s = n++, [c, a] = e[s];
347
432
  try {
348
- r[a] = [c, await o()];
349
- } catch (s) {
433
+ r[s] = [c, await a()];
434
+ } catch (i) {
350
435
  throw new Error(
351
436
  `Demiurge could not load route module ${JSON.stringify(c)}.`,
352
- { cause: s }
437
+ { cause: i }
353
438
  );
354
439
  }
355
440
  }
356
441
  }
357
442
  );
358
- return await Promise.all(i), Object.fromEntries(r);
443
+ return await Promise.all(o), Object.fromEntries(r);
359
444
  }
360
- async function me(t) {
361
- const e = await Jt(t.routes), r = ot(e, {
362
- adapter: Ct
363
- }), n = Wt(t.origin), i = h(t.outDir), a = await Dt(r), c = await st(r, {
445
+ async function be(t) {
446
+ const e = await Gt(t.routes), r = at(e, {
447
+ adapter: qt
448
+ }), n = Xt(t.origin), o = h(t.outDir), s = await te(r), c = await ct(r, {
364
449
  includeResources: !0
365
450
  });
366
- kt(
451
+ Yt(
367
452
  r,
368
- c.filter((u) => a.get(u.file) === "document").length
453
+ c.filter((l) => s.get(l.file) === "document").length
369
454
  );
370
- const o = Bt(
371
- c.map((u) => ({
372
- kind: a.get(u.file) ?? "resource",
373
- pathname: u.pathname
455
+ const a = ne(
456
+ c.map((l) => ({
457
+ kind: s.get(l.file) ?? "resource",
458
+ pathname: l.pathname
374
459
  }))
375
- ), s = at(), f = [], l = { ...t.ssr, navigation: "document" };
376
- for (const u of o) {
377
- const d = J(n, u.pathname, u.kind), p = await ct(r, d, {
460
+ ), i = ut(), u = [], f = { ...t.ssr, navigation: "document" };
461
+ for (const l of a) {
462
+ const d = J(n, l.pathname, l.kind), v = await lt(r, d, {
378
463
  onError: t.onError,
379
- rateLimitStore: s,
380
- ssr: l
464
+ rateLimitStore: i,
465
+ ssr: f
381
466
  });
382
- f.push(
383
- u.kind === "document" ? await L(u, p, 200) : await Gt(u, p)
467
+ u.push(
468
+ l.kind === "document" ? await M(l, v, 200) : await se(l, v)
384
469
  );
385
470
  }
386
- const R = await ut(
471
+ const E = await ft(
387
472
  r,
388
473
  J(n, "/404", "document"),
389
474
  {
390
- ...l,
391
- onError: (u, d) => t.onError?.(u, { pathname: "/404", site: d })
475
+ ...f,
476
+ onError: (l, d) => t.onError?.(l, { pathname: "/404", site: d })
392
477
  }
393
478
  );
394
- f.push(
395
- await L(
479
+ u.push(
480
+ await M(
396
481
  {
397
482
  file: "404.html",
398
483
  pathname: "*"
399
484
  },
400
- R,
485
+ E,
401
486
  404
402
487
  )
403
- ), f.sort((u, d) => u.file.localeCompare(d.file));
404
- const y = {
488
+ );
489
+ const $ = u.map((l) => l.body);
490
+ At($, t.images);
491
+ const p = await Tt({
492
+ documents: $,
493
+ outDir: o,
494
+ policy: t.images
495
+ }), g = await yt({
496
+ fonts: t.fonts,
497
+ root: t.root ?? process.cwd()
498
+ });
499
+ u.sort((l, d) => l.file.localeCompare(d.file)), p.sort((l, d) => l.file.localeCompare(d.file)), g.sort((l, d) => l.file.localeCompare(d.file));
500
+ const m = {
405
501
  adapter: "static",
406
- entries: f.map(({ body: u, ...d }) => d),
407
- fileHeaderRules: await Lt(
502
+ entries: u.map(({ body: l, ...d }) => d),
503
+ fileHeaderRules: await Kt(
408
504
  r,
409
505
  t.staticFileHeaders ?? []
410
506
  ),
507
+ fontFiles: g.map((l) => l.file),
508
+ imageFiles: p.map((l) => l.file),
509
+ origin: n,
411
510
  version: 1
412
511
  };
413
- return await te(i, f, y), y;
512
+ return await he(o, u, [...p, ...g], m), m;
414
513
  }
415
- async function Lt(t, e) {
416
- const r = await Mt(t), n = P(r);
514
+ async function Kt(t, e) {
515
+ const r = await Zt(t), n = H(r);
417
516
  return [
418
- ...e.map((i) => (It(i.pattern), {
419
- headers: P(
420
- ft(r, { headers: i.headers })
517
+ ...e.map((o) => (Qt(o.pattern), {
518
+ headers: H(
519
+ dt(r, { headers: o.headers })
421
520
  ),
422
- pattern: i.pattern
521
+ pattern: o.pattern
423
522
  })),
424
523
  {
425
524
  headers: {
426
525
  ...n,
427
- "cache-control": dt
526
+ "cache-control": pt
428
527
  },
429
- pattern: _.source
528
+ pattern: U.source
430
529
  },
431
530
  {
432
531
  headers: {
433
532
  ...n,
434
- "cache-control": ht
533
+ "cache-control": mt
435
534
  },
436
535
  pattern: ".*"
437
536
  }
438
537
  ];
439
538
  }
440
- async function Mt(t) {
539
+ async function Zt(t) {
441
540
  return { headers: (await t.policies.find(
442
541
  (n) => n.fileSegments.length === 0
443
542
  )?.load())?.policy?.document?.headers };
444
543
  }
445
- function P(t) {
446
- return Object.fromEntries(lt(t, {}).entries());
544
+ function H(t) {
545
+ return Object.fromEntries(ht(t, {}).entries());
447
546
  }
448
- function It(t) {
547
+ function Qt(t) {
449
548
  try {
450
549
  new RegExp(t);
451
550
  } catch {
@@ -454,7 +553,7 @@ function It(t) {
454
553
  );
455
554
  }
456
555
  }
457
- function Wt(t) {
556
+ function Xt(t) {
458
557
  let e;
459
558
  try {
460
559
  e = new URL(t ?? "http://demiurge.local");
@@ -469,7 +568,7 @@ function Wt(t) {
469
568
  );
470
569
  return e.origin;
471
570
  }
472
- function kt(t, e) {
571
+ function Yt(t, e) {
473
572
  if (e === 0)
474
573
  throw new Error("Static output requires at least one page route.");
475
574
  if (!t.fallbacks.notFound.some(
@@ -479,13 +578,13 @@ function kt(t, e) {
479
578
  "Static output requires a root @not-found.tsx so 404.html is app-owned."
480
579
  );
481
580
  }
482
- async function Dt(t) {
581
+ async function te(t) {
483
582
  const e = /* @__PURE__ */ new Map();
484
583
  for (const r of t.routes) {
485
- const n = await r.load(), i = _t(n);
486
- if (i.length > 0)
584
+ const n = await r.load(), o = ee(n);
585
+ if (o.length > 0)
487
586
  throw new Error(
488
- `Static route ${JSON.stringify(r.file)} exports unsupported methods ${i.join(", ")}. Deploy a runtime adapter for request-time methods.`
587
+ `Static route ${JSON.stringify(r.file)} exports unsupported methods ${o.join(", ")}. Deploy a runtime adapter for request-time methods.`
489
588
  );
490
589
  if (!n.GET)
491
590
  throw new Error(
@@ -495,14 +594,14 @@ async function Dt(t) {
495
594
  e.set(r.file, "document");
496
595
  continue;
497
596
  }
498
- Ut(r.file, n.GET), e.set(r.file, "resource");
597
+ re(r.file, n.GET), e.set(r.file, "resource");
499
598
  }
500
599
  return e;
501
600
  }
502
- function _t(t) {
601
+ function ee(t) {
503
602
  return ["POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"].filter((e) => t[e] !== void 0);
504
603
  }
505
- function Ut(t, e) {
604
+ function re(t, e) {
506
605
  if ((e.kind === "text" || e.kind === "html" || e.kind === "json") && typeof e.value != "function")
507
606
  return;
508
607
  const r = "value" in e && typeof e.value == "function" ? `uses a request-dependent ${e.kind} value` : `uses the ${e.kind} response helper`;
@@ -510,23 +609,23 @@ function Ut(t, e) {
510
609
  `Static route ${JSON.stringify(t)} ${r} and cannot produce a fixed output file. Use a fixed text, html, or json value, or deploy a runtime adapter.`
511
610
  );
512
611
  }
513
- function Bt(t) {
612
+ function ne(t) {
514
613
  const e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
515
- return t.map(({ kind: n, pathname: i }) => {
516
- if (r.has(i))
517
- throw new Error(`Static output collected duplicate pathname ${JSON.stringify(i)}.`);
518
- r.add(i);
519
- const a = n === "document" ? z(i) : Vt(i), c = a.toLocaleLowerCase("en-US"), o = [...e.entries()].find(
520
- ([s]) => s === c || s.startsWith(`${c}/`) || c.startsWith(`${s}/`)
614
+ return t.map(({ kind: n, pathname: o }) => {
615
+ if (r.has(o))
616
+ throw new Error(`Static output collected duplicate pathname ${JSON.stringify(o)}.`);
617
+ r.add(o);
618
+ const s = n === "document" ? Z(o) : ie(o), c = s.toLocaleLowerCase("en-US"), a = [...e.entries()].find(
619
+ ([i]) => i === c || i.startsWith(`${c}/`) || c.startsWith(`${i}/`)
521
620
  );
522
- if (o)
621
+ if (a)
523
622
  throw new Error(
524
- `Static paths ${JSON.stringify(o[1])} and ${JSON.stringify(i)} map to the same portable output file or to a file and directory conflict.`
623
+ `Static paths ${JSON.stringify(a[1])} and ${JSON.stringify(o)} map to the same portable output file or to a file and directory conflict.`
525
624
  );
526
- return e.set(c, i), { file: a, kind: n, pathname: i };
625
+ return e.set(c, o), { file: s, kind: n, pathname: o };
527
626
  });
528
627
  }
529
- function z(t) {
628
+ function Z(t) {
530
629
  if (!t.startsWith("/") || t.includes("?") || t.includes("#"))
531
630
  throw new Error(`Static output received invalid pathname ${JSON.stringify(t)}.`);
532
631
  return t === "/" ? "index.html" : [...t.split("/").slice(1).map((r) => {
@@ -536,15 +635,15 @@ function z(t) {
536
635
  } catch {
537
636
  throw new Error(`Static output pathname is not valid UTF-8: ${JSON.stringify(t)}.`);
538
637
  }
539
- return qt(n, t), n;
638
+ return oe(n, t), n;
540
639
  }), "index.html"].join("/");
541
640
  }
542
- function Vt(t) {
641
+ function ie(t) {
543
642
  if (t === "/")
544
643
  throw new Error("A static resource route cannot own the root pathname.");
545
- return z(t).slice(0, -11);
644
+ return Z(t).slice(0, -11);
546
645
  }
547
- function qt(t, e) {
646
+ function oe(t, e) {
548
647
  const r = /[<>:"|?*]/.test(t) || [...t].some((n) => n.charCodeAt(0) <= 31) || /[. ]$/.test(t) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(t);
549
648
  if (!t || t === "." || t === ".." || t.includes("/") || t.includes("\\") || r)
550
649
  throw new Error(
@@ -556,7 +655,7 @@ function J(t, e, r) {
556
655
  headers: { accept: r === "document" ? "text/html" : "*/*" }
557
656
  });
558
657
  }
559
- async function L(t, e, r) {
658
+ async function M(t, e, r) {
560
659
  if (e.status !== r)
561
660
  throw new Error(
562
661
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected ${r}.`
@@ -570,19 +669,19 @@ async function L(t, e, r) {
570
669
  throw new Error(
571
670
  `Static output for ${JSON.stringify(t.pathname)} attempted to set a cookie. Build artifacts cannot contain per-user response state.`
572
671
  );
573
- const i = await zt(
672
+ const o = await ae(
574
673
  await e.text(),
575
674
  e.headers
576
675
  );
577
- return await Zt(t.pathname, i, e.headers), {
676
+ return await ue(t.pathname, o, e.headers), {
578
677
  file: t.file,
579
- headers: Z(e.headers),
580
- body: i,
678
+ headers: X(e.headers),
679
+ body: o,
581
680
  pathname: t.pathname,
582
681
  status: r
583
682
  };
584
683
  }
585
- async function Gt(t, e) {
684
+ async function se(t, e) {
586
685
  if (e.status !== 200)
587
686
  throw new Error(
588
687
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected 200.`
@@ -593,48 +692,48 @@ async function Gt(t, e) {
593
692
  );
594
693
  return {
595
694
  file: t.file,
596
- headers: Z(e.headers),
695
+ headers: X(e.headers),
597
696
  body: await e.text(),
598
697
  pathname: t.pathname,
599
698
  status: 200
600
699
  };
601
700
  }
602
- async function zt(t, e) {
701
+ async function ae(t, e) {
603
702
  const r = new RegExp(
604
- `(?:^|\\s)${F}(?:\\s|$)`
605
- ), n = K(t, "script").filter((a) => r.test(a.attributes));
703
+ `(?:^|\\s)${P}(?:\\s|$)`
704
+ ), n = Q(t, "script").filter((s) => r.test(s.attributes));
606
705
  if (n.length === 0)
607
706
  return t;
608
- const i = await Promise.all(
609
- n.map((a) => D(a.content))
707
+ const o = await Promise.all(
708
+ n.map((s) => _(s.content))
610
709
  );
611
- for (const a of [
710
+ for (const s of [
612
711
  "content-security-policy",
613
712
  "content-security-policy-report-only"
614
713
  ]) {
615
- const c = e.get(a);
616
- c && e.set(a, Kt(c, i));
714
+ const c = e.get(s);
715
+ c && e.set(s, ce(c, o));
617
716
  }
618
717
  return t.replace(
619
- new RegExp(`\\s${F}(?=\\s|>)`, "g"),
718
+ new RegExp(`\\s${P}(?=\\s|>)`, "g"),
620
719
  ""
621
720
  );
622
721
  }
623
- function Kt(t, e) {
624
- const r = t.split(";").map((s) => s.trim()).filter(Boolean), n = r.findIndex(
625
- (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
626
- ), i = r.find(
627
- (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
628
- ), a = n === -1 ? i : r[n];
629
- if (!a)
722
+ function ce(t, e) {
723
+ const r = t.split(";").map((i) => i.trim()).filter(Boolean), n = r.findIndex(
724
+ (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
725
+ ), o = r.find(
726
+ (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
727
+ ), s = n === -1 ? o : r[n];
728
+ if (!s)
630
729
  return t;
631
- const c = a.split(/\s+/).slice(1).filter((s) => s !== "'none'"), o = [
730
+ const c = s.split(/\s+/).slice(1).filter((i) => i !== "'none'"), a = [
632
731
  "script-src",
633
732
  .../* @__PURE__ */ new Set([...c, ...e])
634
733
  ].join(" ");
635
- return n === -1 ? r.push(o) : r[n] = o, r.join("; ");
734
+ return n === -1 ? r.push(a) : r[n] = a, r.join("; ");
636
735
  }
637
- async function Zt(t, e, r) {
736
+ async function ue(t, e, r) {
638
737
  const n = r.get("content-security-policy");
639
738
  if (!n)
640
739
  return;
@@ -642,39 +741,39 @@ async function Zt(t, e, r) {
642
741
  throw new Error(
643
742
  `Static output for ${JSON.stringify(t)} uses a nonce-backed CSP. Use security.static() with stable hashes or a runtime adapter that injects a fresh nonce.`
644
743
  );
645
- const i = Qt(n);
646
- await M(
744
+ const o = le(n);
745
+ await L(
647
746
  t,
648
747
  e,
649
748
  "script",
650
- x(i, "script-src", "default-src")
651
- ), await M(
749
+ x(o, "script-src", "default-src")
750
+ ), await L(
652
751
  t,
653
752
  e,
654
753
  "style",
655
754
  x(
656
- i,
755
+ o,
657
756
  "style-src-elem",
658
757
  "style-src",
659
758
  "default-src"
660
759
  )
661
760
  );
662
- const a = x(
663
- i,
761
+ const s = x(
762
+ o,
664
763
  "style-src-attr",
665
764
  "style-src",
666
765
  "default-src"
667
766
  );
668
- if (a && /\sstyle\s*=/i.test(e) && !a.includes("'unsafe-inline'"))
767
+ if (s && /\sstyle\s*=/i.test(e) && !s.includes("'unsafe-inline'"))
669
768
  throw new Error(
670
769
  `Static output for ${JSON.stringify(t)} contains an inline style attribute that its CSP does not allow. Move the style into a stylesheet or explicitly allow inline styles.`
671
770
  );
672
771
  }
673
- function Qt(t) {
772
+ function le(t) {
674
773
  const e = /* @__PURE__ */ new Map();
675
774
  for (const r of t.split(";")) {
676
- const [n, ...i] = r.trim().split(/\s+/);
677
- n && e.set(n.toLowerCase(), i);
775
+ const [n, ...o] = r.trim().split(/\s+/);
776
+ n && e.set(n.toLowerCase(), o);
678
777
  }
679
778
  return e;
680
779
  }
@@ -685,34 +784,34 @@ function x(t, ...e) {
685
784
  return n;
686
785
  }
687
786
  }
688
- async function M(t, e, r, n) {
787
+ async function L(t, e, r, n) {
689
788
  if (!(!n || n.includes("'unsafe-inline'")))
690
- for (const i of K(e, r)) {
789
+ for (const o of Q(e, r)) {
691
790
  if (r === "script") {
692
- const c = Xt(i.attributes, "src");
791
+ const c = fe(o.attributes, "src");
693
792
  if (c) {
694
- if (!Yt(n, c))
793
+ if (!de(n, c))
695
794
  throw new Error(
696
795
  `Static output for ${JSON.stringify(t)} contains script ${JSON.stringify(c)} that the effective script-src directive does not allow. Add its origin to security.needs.script or the route CSP policy.`
697
796
  );
698
797
  continue;
699
798
  }
700
799
  }
701
- if (!i.content)
800
+ if (!o.content)
702
801
  continue;
703
- const a = await D(i.content);
704
- if (!n.includes(a))
802
+ const s = await _(o.content);
803
+ if (!n.includes(s))
705
804
  throw new Error(
706
- `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${a}.`
805
+ `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${s}.`
707
806
  );
708
807
  }
709
808
  }
710
- function Xt(t, e) {
809
+ function fe(t, e) {
711
810
  return t.match(
712
811
  new RegExp(`(?:^|\\s)${e}\\s*=\\s*["']([^"']+)["']`, "i")
713
812
  )?.[1]?.replaceAll("&amp;", "&");
714
813
  }
715
- function Yt(t, e) {
814
+ function de(t, e) {
716
815
  if (!t)
717
816
  return !0;
718
817
  if (t.includes("'none'") || t.includes("'strict-dynamic'") && t.some(
@@ -730,88 +829,97 @@ function Yt(t, e) {
730
829
  return t.some((n) => {
731
830
  if (n.startsWith("'"))
732
831
  return !1;
733
- let i;
832
+ let o;
734
833
  try {
735
- i = new URL(n);
834
+ o = new URL(n);
736
835
  } catch {
737
836
  return !1;
738
837
  }
739
- const a = i.hostname.startsWith("*.") ? r.hostname.endsWith(i.hostname.slice(1)) && r.hostname !== i.hostname.slice(2) : r.hostname === i.hostname, c = i.pathname === "/" || i.pathname.endsWith("/") ? r.pathname.startsWith(i.pathname) : r.pathname === i.pathname;
740
- return r.protocol === i.protocol && a && r.port === i.port && c;
838
+ const s = o.hostname.startsWith("*.") ? r.hostname.endsWith(o.hostname.slice(1)) && r.hostname !== o.hostname.slice(2) : r.hostname === o.hostname, c = o.pathname === "/" || o.pathname.endsWith("/") ? r.pathname.startsWith(o.pathname) : r.pathname === o.pathname;
839
+ return r.protocol === o.protocol && s && r.port === o.port && c;
741
840
  });
742
841
  }
743
- function K(t, e) {
744
- const r = t.toLowerCase(), n = [], i = `<${e}`, a = `</${e}`;
842
+ function Q(t, e) {
843
+ const r = t.toLowerCase(), n = [], o = `<${e}`, s = `</${e}`;
745
844
  let c = 0;
746
845
  for (; c < t.length; ) {
747
- const o = r.indexOf(i, c);
748
- if (o === -1)
846
+ const a = r.indexOf(o, c);
847
+ if (a === -1)
749
848
  break;
750
- const s = r.indexOf(">", o + i.length), f = s === -1 ? -1 : r.indexOf(a, s + 1), l = f === -1 ? -1 : r.indexOf(">", f + a.length);
751
- if (s === -1 || f === -1 || l === -1)
849
+ const i = r.indexOf(">", a + o.length), u = i === -1 ? -1 : r.indexOf(s, i + 1), f = u === -1 ? -1 : r.indexOf(">", u + s.length);
850
+ if (i === -1 || u === -1 || f === -1)
752
851
  throw new Error(`Static output contains an unclosed <${e}> element.`);
753
852
  n.push({
754
- attributes: t.slice(o + i.length, s),
755
- content: t.slice(s + 1, f)
756
- }), c = l + 1;
853
+ attributes: t.slice(a + o.length, i),
854
+ content: t.slice(i + 1, u)
855
+ }), c = f + 1;
757
856
  }
758
857
  return n;
759
858
  }
760
- function Z(t) {
859
+ function X(t) {
761
860
  return Object.fromEntries(
762
861
  [...t.entries()].sort(([e], [r]) => e.localeCompare(r))
763
862
  );
764
863
  }
765
- async function te(t, e, r) {
766
- const n = N(t);
767
- await E(n, { recursive: !0 });
768
- const i = await W(m(n, ".demiurge-static-"));
864
+ async function he(t, e, r, n) {
865
+ const o = C(t);
866
+ await T(o, { recursive: !0 });
867
+ const s = await k(y(o, ".demiurge-static-"));
769
868
  try {
770
- for (const o of e) {
771
- const s = I(i, o.file);
772
- await E(N(s), { recursive: !0 }), await A(s, o.body);
869
+ for (const i of [...e, ...r]) {
870
+ const u = W(s, i.file);
871
+ await T(C(u), { recursive: !0 }), await b(u, i.body);
773
872
  }
774
- await A(
775
- m(i, G),
776
- `${JSON.stringify(r, null, 2)}
873
+ await b(
874
+ y(s, K),
875
+ `${JSON.stringify(n, null, 2)}
777
876
  `
778
877
  );
779
- const a = await ee(t);
780
- await E(t, { recursive: !0 }), await k(i, t, { recursive: !0, force: !0 });
781
- const c = new Set(e.map((o) => o.file));
782
- for (const o of a)
783
- c.has(o) || await $(I(t, o), { force: !0 });
878
+ const c = await pe(t);
879
+ await T(t, { recursive: !0 }), await D(s, t, { recursive: !0, force: !0 });
880
+ const a = new Set(
881
+ [...e, ...r].map((i) => i.file)
882
+ );
883
+ for (const i of c)
884
+ a.has(i) || await A(W(t, i), { force: !0 });
784
885
  } finally {
785
- await $(i, { force: !0, recursive: !0 });
886
+ await A(s, { force: !0, recursive: !0 });
786
887
  }
787
888
  }
788
- async function ee(t) {
889
+ async function pe(t) {
789
890
  try {
790
- const e = await v(m(t, G), "utf8"), r = JSON.parse(e);
791
- return r.adapter !== "static" || r.version !== 1 || !Array.isArray(r.entries) ? [] : r.entries.flatMap(
792
- (n) => typeof n.file == "string" && Q(n.file) ? [n.file] : []
891
+ const e = await O(y(t, K), "utf8"), r = JSON.parse(e);
892
+ if (r.adapter !== "static" || r.version !== 1 || !Array.isArray(r.entries))
893
+ return [];
894
+ const n = Array.isArray(r.fontFiles) ? r.fontFiles : [], o = Array.isArray(r.imageFiles) ? r.imageFiles : [];
895
+ return [
896
+ ...r.entries.map((s) => s.file),
897
+ ...n,
898
+ ...o
899
+ ].flatMap(
900
+ (s) => typeof s == "string" && Y(s) ? [s] : []
793
901
  );
794
902
  } catch {
795
903
  return [];
796
904
  }
797
905
  }
798
- function I(t, e) {
799
- if (!Q(e))
906
+ function W(t, e) {
907
+ if (!Y(e))
800
908
  throw new Error(`Static output file must stay inside the output directory: ${JSON.stringify(e)}.`);
801
909
  const r = h(t), n = h(r, e);
802
- if (w(r, n).split(g).includes(".."))
910
+ if (w(r, n).split(S).includes(".."))
803
911
  throw new Error(`Static output file escaped the output directory: ${JSON.stringify(e)}.`);
804
912
  return n;
805
913
  }
806
- function Q(t) {
914
+ function Y(t) {
807
915
  return !!t && !t.startsWith("/") && !t.startsWith("\\") && !t.split(/[\\/]/).includes("..");
808
916
  }
809
917
  export {
810
- de as createStaticPreviewServer,
811
- xt as createVercelOutputConfig,
812
- me as generateStaticOutput,
813
- pe as generateVercelStaticOutput,
814
- Ct as staticAdapter,
815
- he as vercelStatic
918
+ Ne as createStaticPreviewServer,
919
+ Lt as createVercelOutputConfig,
920
+ be as generateStaticOutput,
921
+ xe as generateVercelStaticOutput,
922
+ qt as staticAdapter,
923
+ Fe as vercelStatic
816
924
  };
817
925
  //# sourceMappingURL=index.js.map