okno 1.0.0-beta.49 → 1.0.0-beta.50

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 (129) hide show
  1. package/README.md +103 -0
  2. package/dist/DateInput-DFMuwukN.js +5 -0
  3. package/dist/Doc-DaOTQ68S.js +1 -0
  4. package/dist/DocNote-DCnGLaBv.js +1 -0
  5. package/dist/Files-CAo7CtDV.js +1 -0
  6. package/dist/Strings-DB4e139g.js +1 -0
  7. package/dist/UI-Bxucd1jf.js +3 -0
  8. package/dist/ViewModeToggle-CM5Q9dZC.js +6 -0
  9. package/dist/Windows-CglPvdAM.js +128 -0
  10. package/dist/astro/index.js +1 -1
  11. package/dist/boot.js +75 -59
  12. package/dist/cli/index.d.ts.map +1 -1
  13. package/dist/cli/init.d.ts.map +1 -1
  14. package/dist/cli/mcp.d.ts.map +1 -1
  15. package/dist/cli/merge.d.ts +8 -0
  16. package/dist/cli/merge.d.ts.map +1 -0
  17. package/dist/cli/upgrade.d.ts +6 -0
  18. package/dist/cli/upgrade.d.ts.map +1 -0
  19. package/dist/cli.js +19 -9
  20. package/dist/codegen/generate.d.ts.map +1 -1
  21. package/dist/codegen/icon-assets.d.ts +18 -0
  22. package/dist/codegen/icon-assets.d.ts.map +1 -1
  23. package/dist/codegen/modules.d.ts.map +1 -1
  24. package/dist/codegen/validate-content.d.ts.map +1 -1
  25. package/dist/contracts/bootstrap.d.ts +4 -0
  26. package/dist/contracts/bootstrap.d.ts.map +1 -1
  27. package/dist/contracts/fields.d.ts +10 -2
  28. package/dist/contracts/fields.d.ts.map +1 -1
  29. package/dist/contracts/routes.d.ts +185 -0
  30. package/dist/contracts/routes.d.ts.map +1 -0
  31. package/dist/core/block-key.d.ts +8 -0
  32. package/dist/core/block-key.d.ts.map +1 -0
  33. package/dist/core/content-path.d.ts +3 -0
  34. package/dist/core/content-path.d.ts.map +1 -1
  35. package/dist/core/content.d.ts.map +1 -1
  36. package/dist/core/file-model.d.ts +136 -0
  37. package/dist/core/file-model.d.ts.map +1 -0
  38. package/dist/core/files-path.d.ts +21 -0
  39. package/dist/core/files-path.d.ts.map +1 -0
  40. package/dist/core/format.d.ts +26 -0
  41. package/dist/core/format.d.ts.map +1 -0
  42. package/dist/core/icon-symbol.d.ts +3 -0
  43. package/dist/core/icon-symbol.d.ts.map +1 -0
  44. package/dist/core/index.d.ts +12 -1
  45. package/dist/core/index.d.ts.map +1 -1
  46. package/dist/core/locale-move.d.ts +20 -0
  47. package/dist/core/locale-move.d.ts.map +1 -0
  48. package/dist/core/media-kind.d.ts +21 -0
  49. package/dist/core/media-kind.d.ts.map +1 -0
  50. package/dist/core/merge-record.d.ts +22 -0
  51. package/dist/core/merge-record.d.ts.map +1 -0
  52. package/dist/core/operation.d.ts +95 -0
  53. package/dist/core/operation.d.ts.map +1 -0
  54. package/dist/core/operations.d.ts +118 -0
  55. package/dist/core/operations.d.ts.map +1 -0
  56. package/dist/core/schema-mutation.d.ts.map +1 -1
  57. package/dist/core/schema.d.ts +3 -1
  58. package/dist/core/schema.d.ts.map +1 -1
  59. package/dist/core/scope.d.ts +25 -0
  60. package/dist/core/scope.d.ts.map +1 -0
  61. package/dist/core/storage.d.ts +83 -0
  62. package/dist/core/storage.d.ts.map +1 -0
  63. package/dist/core/strings.d.ts +34 -0
  64. package/dist/core/strings.d.ts.map +1 -0
  65. package/dist/core/svg-icon.d.ts +5 -4
  66. package/dist/core/svg-icon.d.ts.map +1 -1
  67. package/dist/core/usage.d.ts.map +1 -1
  68. package/dist/dispatch-SVt9Qb86.js +1382 -0
  69. package/dist/editor/index.js +1 -57606
  70. package/dist/{acorn-oIjaFBVA.js → encode-BHFEUCZ7.js} +273 -196
  71. package/dist/engine/index.js +128 -3409
  72. package/dist/format-BciVkjz-.js +118 -0
  73. package/dist/icon-symbol-D82I2EAb.js +13 -0
  74. package/dist/index-B1PShnsc.js +1 -132
  75. package/dist/index-B2WzdTzI.js +30 -14187
  76. package/dist/index-ButdD9Pf.js +5 -1825
  77. package/dist/index-CC1_5J9E.js +20 -0
  78. package/dist/index-DKF0siIz.js +33 -5483
  79. package/dist/index-q-7MEoHz.js +1 -47
  80. package/dist/index.js +1 -1
  81. package/dist/init.js +85 -81
  82. package/dist/integrations/vite/dev-server.d.ts.map +1 -1
  83. package/dist/integrations/vite/local-engine.d.ts +1 -1
  84. package/dist/integrations/vite/plugin.d.ts +3 -1
  85. package/dist/integrations/vite/plugin.d.ts.map +1 -1
  86. package/dist/local/disk-keys.d.ts +3 -0
  87. package/dist/local/disk-keys.d.ts.map +1 -0
  88. package/dist/local/disk.d.ts +16 -4
  89. package/dist/local/disk.d.ts.map +1 -1
  90. package/dist/local/dispatch.d.ts +6 -0
  91. package/dist/local/dispatch.d.ts.map +1 -1
  92. package/dist/local/schema-mutation.d.ts +8 -19
  93. package/dist/local/schema-mutation.d.ts.map +1 -1
  94. package/dist/local/setup.d.ts +6 -0
  95. package/dist/local/setup.d.ts.map +1 -1
  96. package/dist/local/store.d.ts +3 -0
  97. package/dist/local/store.d.ts.map +1 -0
  98. package/dist/mcp.js +90 -94
  99. package/dist/merge-Bk1X-G3W.js +45 -0
  100. package/dist/merge-record-C2RFnApc.js +36 -0
  101. package/dist/next/index.js +1 -1
  102. package/dist/operations-P-kTynGZ.js +1460 -0
  103. package/dist/plugin-Ba73V2fC.js +559 -0
  104. package/dist/runtime/boot.d.ts.map +1 -1
  105. package/dist/runtime/preview-sync.d.ts +10 -0
  106. package/dist/runtime/preview-sync.d.ts.map +1 -1
  107. package/dist/runtime/slot-format.d.ts.map +1 -1
  108. package/dist/runtime/values.d.ts +34 -2
  109. package/dist/runtime/values.d.ts.map +1 -1
  110. package/dist/runtime/wrap.d.ts +1 -1
  111. package/dist/runtime/wrap.d.ts.map +1 -1
  112. package/dist/runtime/wrap.js +4319 -3979
  113. package/dist/storage-D9hPzpMn.js +136 -0
  114. package/dist/store-wlYjWeY4.js +311 -0
  115. package/dist/upgrade-BVtnTG2H.js +59 -0
  116. package/dist/usage-CCy0FnoB.js +3558 -0
  117. package/dist/vite/index.js +1 -1
  118. package/package.json +1 -1
  119. package/skills/connect-okno/SKILL.md +22 -5
  120. package/skills/connect-okno/references/content.md +47 -10
  121. package/src/runtime/boot.ts +54 -8
  122. package/src/runtime/preview-sync.ts +73 -9
  123. package/src/runtime/slot-format.ts +3 -1
  124. package/src/runtime/values.ts +221 -90
  125. package/src/runtime/wrap.ts +1 -0
  126. package/dist/dispatch-dWn8cIFI.js +0 -1550
  127. package/dist/plugin-BAurTuo8.js +0 -538
  128. package/dist/schema-mutation-DQ7d4rmd.js +0 -675
  129. package/dist/schema-mutation-DXOYPQHt.js +0 -103
@@ -0,0 +1,1382 @@
1
+ import { join as m, resolve as D, sep as Re, dirname as Ve, relative as Qe } from "node:path";
2
+ import { readdir as P, readFile as De } from "node:fs/promises";
3
+ import { w as ee, b as et, r as tt, a as ot, e as ve, s as nt, f as st, h as rt, g as at, d as le, i as ce, o as je, j as it, k as lt } from "./store-wlYjWeY4.js";
4
+ import { existsSync as b, readFileSync as w, lstatSync as ct, readdirSync as oe, realpathSync as ut, mkdirSync as We } from "node:fs";
5
+ import { fileURLToPath as ft } from "node:url";
6
+ import { p as F, d as dt } from "./encode-BHFEUCZ7.js";
7
+ import { a4 as pt, O as Ue, T as mt, X as xe, P as Je, N as ht, a5 as gt, ab as Ae, G as ne, M as Te, L as yt, ag as kt, ac as _t, af as $t, ai as bt, aj as Ot, c as wt, E as St } from "./operations-P-kTynGZ.js";
8
+ import { d as Y, p as vt, o as jt, I as Ee, V as Ie, A as Ne, e as ue, F as xt, f as At } from "./usage-CCy0FnoB.js";
9
+ import { execSync as Tt } from "node:child_process";
10
+ import { simpleGit as Q } from "simple-git";
11
+ import { c as Et, d as It, p as Nt } from "./storage-D9hPzpMn.js";
12
+ import { homedir as Ft } from "node:os";
13
+ function ze(e) {
14
+ const t = m(e, "schema.ts");
15
+ if (!b(t)) return [];
16
+ const o = F(w(t, "utf8"));
17
+ if (!o || typeof o != "object") return [];
18
+ const i = [], l = (a, r, c = 0, f) => {
19
+ if (!(!a || typeof a != "object" || !r || c > 64))
20
+ for (const [u, p] of Object.entries(r)) {
21
+ const d = p;
22
+ if (!d) continue;
23
+ const k = a[u];
24
+ for (const y of Array.isArray(k) ? k : [k])
25
+ if ((d.type === "icon" || d.type === "media") && y && typeof y == "object") {
26
+ const A = y.src ?? (Array.isArray(k) ? void 0 : f?.[u]?.src);
27
+ A && i.push({ src: A, type: d.type, field: u, ...typeof y.alt == "string" ? { alt: y.alt } : {} });
28
+ } else if (d.type === "group") l(y, d.fields, c + 1, Array.isArray(k) ? void 0 : f?.[u]);
29
+ else if (d.type === "block") {
30
+ const A = Array.isArray(k) ? void 0 : f?.[u], _ = Ae(y) ?? Ae(A) ?? d.block ?? (d.blocks?.length === 1 ? d.blocks[0] : void 0);
31
+ l(y, o.blocks?.[_]?.fields, c + 1, A);
32
+ }
33
+ }
34
+ }, s = (o.locales?.supported ?? []).map((a) => typeof a == "string" ? a : a?.id).filter(Boolean), n = (a, r, c, f = !1) => {
35
+ if (!b(a)) return;
36
+ const u = F(w(a, "utf8")), p = c && b(c) ? F(w(c, "utf8")) : void 0;
37
+ if (Array.isArray(u)) for (const d of u) l(d, r, 0, Array.isArray(p) ? p.find((k) => k?.slug === d?.slug) : void 0);
38
+ else if (f && u && typeof u == "object") for (const [d, k] of Object.entries(u)) l(k, r, 0, p?.[d]);
39
+ else l(u, r, 0, p);
40
+ };
41
+ for (const a of ["pages", "globals", "collections"]) for (const [r, c] of Object.entries(o[a] ?? {}))
42
+ for (const f of [void 0, ...s]) {
43
+ const u = f ? m(e, a, f) : m(e, a);
44
+ if (a !== "collections") n(m(u, `${r}.ts`), c?.fields, f ? m(e, a, `${r}.ts`) : void 0);
45
+ else {
46
+ n(m(u, `${r}.ts`), c?.fields, f ? m(e, a, `${r}.ts`) : void 0, !0);
47
+ const p = m(u, r);
48
+ if (b(p))
49
+ for (const d of oe(p, { withFileTypes: !0 })) d.isFile() && d.name.endsWith(".ts") && d.name !== "index.ts" && n(m(p, d.name), c?.fields, f ? m(e, a, r, d.name) : void 0);
50
+ }
51
+ }
52
+ return i;
53
+ }
54
+ const Fe = /* @__PURE__ */ new Set(), Ke = (e) => {
55
+ Fe.has(e) || (Fe.add(e), console.warn(e));
56
+ };
57
+ function Mt(e, t = Ke) {
58
+ const o = m(e, "files", ".okno-tree.json"), i = /* @__PURE__ */ Object.create(null);
59
+ if (b(o)) {
60
+ const s = JSON.parse(w(o, "utf8"));
61
+ if (!s || typeof s != "object" || Array.isArray(s) || ![1, 2].includes(s.version)) throw Error("[okno] Invalid Files metadata: unsupported manifest version.");
62
+ if (s.version === 2 && (!s.entities || typeof s.entities != "object" || Array.isArray(s.entities))) throw Error("[okno] Invalid Files metadata: expected an entities object.");
63
+ for (const [n, a] of Object.entries(s.version === 2 ? s.entities : {})) {
64
+ if (!a || typeof a != "object" || Array.isArray(a) || a.alt !== void 0 && typeof a.alt != "string") throw Error(`[okno] Invalid Files description metadata for ${n}.`);
65
+ typeof a.alt == "string" && (i[n] = a.alt);
66
+ }
67
+ }
68
+ const l = /* @__PURE__ */ new Map();
69
+ for (const s of ze(e)) {
70
+ if (typeof s.src != "string" || !s.src.startsWith("/okno/files/")) continue;
71
+ let n;
72
+ try {
73
+ n = "files/" + decodeURIComponent(s.src.slice(12));
74
+ } catch {
75
+ continue;
76
+ }
77
+ if (/[\\?#]/.test(n) || n.split("/").some((r) => !r || r === "." || r === "..") || Object.hasOwn(i, n)) continue;
78
+ const a = l.get(n) ?? /* @__PURE__ */ new Set();
79
+ s.alt !== void 0 && a.add(s.alt), l.set(n, a);
80
+ }
81
+ for (const [s, n] of [...l].sort(([a], [r]) => a.localeCompare(r)))
82
+ i[s] = "", [...n].some((a) => a !== "") && t(`[okno] ${n.size > 1 ? "Conflicting legacy descriptions" : "Legacy description candidate"} for ${s}: ${JSON.stringify([...n].sort())}. Set this file's description in Files; rendering uses a blank description until resolved. Source content was preserved.`);
83
+ return i;
84
+ }
85
+ function Lt(e) {
86
+ const t = m(e, "files", ".okno-tree.json"), o = /* @__PURE__ */ Object.create(null);
87
+ if (!b(t)) return o;
88
+ const i = se(e), l = JSON.parse(w(t, "utf8"))?.entities ?? {};
89
+ for (const [s, n] of Object.entries(l)) {
90
+ const a = n?.poster;
91
+ typeof a == "string" && i.has(a) && (o[s] = Ue(a));
92
+ }
93
+ return o;
94
+ }
95
+ function Ct(e) {
96
+ const t = m(e, "files", ".okno-tree.json"), o = /* @__PURE__ */ Object.create(null);
97
+ if (!b(t)) return o;
98
+ const i = se(e), l = JSON.parse(w(t, "utf8"))?.entities ?? {};
99
+ for (const [s, n] of Object.entries(l)) {
100
+ const a = n?.sources;
101
+ if (!Array.isArray(a)) continue;
102
+ const r = Y(s), c = a.flatMap((f) => {
103
+ if (typeof f?.format != "string" || typeof f.type != "string") return [];
104
+ const u = f.format === r ? s : mt(s, f.format);
105
+ return i.has(u) ? [{ src: Ue(u), type: f.type }] : [];
106
+ });
107
+ c.length > 1 && (o[s] = c);
108
+ }
109
+ return o;
110
+ }
111
+ function Be(e) {
112
+ const t = m(e, "files", ".okno-tree.json");
113
+ if (!b(t)) return {};
114
+ let o;
115
+ try {
116
+ o = JSON.parse(w(t, "utf8"))?.entities;
117
+ } catch {
118
+ return {};
119
+ }
120
+ return o && typeof o == "object" && !Array.isArray(o) ? pt(o) : {};
121
+ }
122
+ function se(e) {
123
+ const t = /* @__PURE__ */ new Set();
124
+ for (const i of Object.keys(Be(e))) t.add(ht(i));
125
+ const o = (i, l) => {
126
+ if (b(i))
127
+ for (const s of oe(i, { withFileTypes: !0 })) {
128
+ const n = l + s.name;
129
+ s.isDirectory() ? Je(n + "/") || o(m(i, s.name), n + "/") : s.isFile() && n !== "files/.okno-tree.json" && t.add(n);
130
+ }
131
+ };
132
+ return o(m(e, "files"), "files/"), t;
133
+ }
134
+ function Pt(e) {
135
+ const t = /* @__PURE__ */ new Set(), o = (l, s) => {
136
+ if (b(l))
137
+ for (const n of oe(l, { withFileTypes: !0 })) {
138
+ const a = s + n.name;
139
+ if (n.isDirectory()) o(m(l, n.name), a + "/");
140
+ else if (n.isFile() && gt(a))
141
+ try {
142
+ xe(F(w(m(l, n.name), "utf8")), t);
143
+ } catch {
144
+ }
145
+ }
146
+ };
147
+ for (const l of ["pages", "globals", "collections", "strings"]) o(m(e, l), l + "/");
148
+ if (b(m(e, "strings.ts")))
149
+ try {
150
+ xe(F(w(m(e, "strings.ts"), "utf8")), t);
151
+ } catch {
152
+ }
153
+ if (!t.size) return [];
154
+ const i = se(e);
155
+ return [...t].filter((l) => !i.has(l)).sort();
156
+ }
157
+ function Rt(e) {
158
+ const t = /* @__PURE__ */ new Map();
159
+ for (const s of ze(e)) if (s.type === "icon") {
160
+ if (typeof s.src != "string" || !s.src.startsWith("/okno/files/")) throw Error(`[okno] Icon ${s.field} must reference a local Files SVG.`);
161
+ t.has(s.src) || t.set(s.src, s.field);
162
+ }
163
+ const o = D(e, "files"), i = se(e), l = (s) => {
164
+ Ke(`[okno] Icon ${t.get(s)} references a missing file: ${s}. The field reads as empty until a file exists at that path.`);
165
+ };
166
+ return [...t.keys()].sort().flatMap((s) => {
167
+ let n;
168
+ try {
169
+ n = decodeURIComponent(s.slice(12));
170
+ } catch {
171
+ throw Error(`[okno] Invalid icon address: ${s}`);
172
+ }
173
+ if (n.includes("\\") || n.includes("?") || n.includes("#") || n.split("/").some((f) => !f || f === "." || f === "..")) throw Error(`[okno] Invalid icon address: ${s}`);
174
+ if (Je(`files/${n}`))
175
+ return l(s), [];
176
+ const a = D(o, n);
177
+ if (!a.startsWith(o + Re) || !a.toLowerCase().endsWith(".svg")) throw Error(`[okno] Icon must reference an SVG inside Files: ${s}`);
178
+ let r = o;
179
+ for (const f of n.split("/"))
180
+ if (r = m(r, f), ct(r, { throwIfNoEntry: !1 })?.isSymbolicLink()) throw Error(`[okno] Symbolic icon sources are not supported: ${s}`);
181
+ if (!i.has(`files/${n}`))
182
+ return l(s), [];
183
+ const c = vt(w(a, "utf8"));
184
+ if (!c.ok) throw Error(`[okno] Cannot prepare icon ${s}: ${c.error}`);
185
+ if (!c.prepared) throw Error(`[okno] Icon ${s} is not prepared. Select it in an Icon field or add id="icon" to the safe SVG root.`);
186
+ return [{ path: `okno/files/${n}`, address: s + "#icon" }];
187
+ });
188
+ }
189
+ function No(e, t = "") {
190
+ return { ...Be(e), ...Vt(e, t) };
191
+ }
192
+ function Vt(e, t = "") {
193
+ const o = Rt(e);
194
+ if (!o.length) return {};
195
+ if (t !== "" && (!t.startsWith("/") || t.startsWith("//") || /[\\?#]/.test(t))) throw Error("[okno] Icon fields require an absolute same-origin base path (for example /site/). Relative and external Vite bases are not supported.");
196
+ const i = t.replace(/\/$/, "");
197
+ return Object.fromEntries(o.map((l) => [l.address, i + "/" + l.path + "#icon"]));
198
+ }
199
+ const Wt = /* @__PURE__ */ new Set([".astro", ".svelte", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue"]), Ut = /* @__PURE__ */ new Set([
200
+ "node_modules",
201
+ ".astro",
202
+ ".svelte-kit",
203
+ ".next",
204
+ ".nuxt",
205
+ ".vite",
206
+ "dist",
207
+ "build",
208
+ ".git",
209
+ ".turbo"
210
+ ]);
211
+ async function fe(e, t) {
212
+ const o = new RegExp(`import\\s*\\{([^}]+)\\}\\s*from\\s*["']okno/${t}["']`, "g"), i = /* @__PURE__ */ new Set();
213
+ async function l(s) {
214
+ let n;
215
+ try {
216
+ n = await P(s, { withFileTypes: !0 });
217
+ } catch {
218
+ return;
219
+ }
220
+ for (const a of n) {
221
+ if (a.name.startsWith(".") && a.name !== "." || Ut.has(a.name)) continue;
222
+ const r = m(s, a.name);
223
+ if (a.isDirectory()) {
224
+ await l(r);
225
+ continue;
226
+ }
227
+ const c = a.name.lastIndexOf(".");
228
+ if (c === -1) continue;
229
+ const f = a.name.slice(c);
230
+ if (!Wt.has(f)) continue;
231
+ let u;
232
+ try {
233
+ u = await De(r, "utf-8");
234
+ } catch {
235
+ continue;
236
+ }
237
+ if (u.includes(`okno/${t}`))
238
+ for (const p of u.matchAll(o)) {
239
+ const d = p[1] ?? "";
240
+ for (const k of d.split(",")) {
241
+ const y = k.trim().split(/\s+as\s+/)[0]?.trim();
242
+ y && /^[A-Za-z_$][\w$]*$/.test(y) && i.add(y);
243
+ }
244
+ }
245
+ }
246
+ }
247
+ return await l(e), i;
248
+ }
249
+ const Jt = "__oknoSetImages({})", zt = '__oknoSetImages(import.meta.glob(["/okno/files/**/*.{png,jpg,jpeg,webp,avif,gif,svg,tiff}", "!/okno/files/.trash/**"], { eager: false }))';
250
+ function Kt(e = "raw") {
251
+ return e === "astro" ? zt : Jt;
252
+ }
253
+ const Me = Ve(ft(import.meta.url)), Bt = [
254
+ D(Me, "./runtime/wrap.js"),
255
+ // bundled at dist/ (Vite plugin chunk)
256
+ D(Me, "../runtime/wrap.js")
257
+ // bundled at dist/next/ (Next entry)
258
+ ];
259
+ function Fo() {
260
+ for (const e of Bt)
261
+ if (b(e)) return w(e, "utf-8");
262
+ return null;
263
+ }
264
+ function Mo() {
265
+ return [
266
+ 'export * as pages from "okno/pages"',
267
+ 'export * as globals from "okno/globals"',
268
+ 'export * as collections from "okno/collections"',
269
+ 'export { strings } from "okno/strings"'
270
+ ].join(`
271
+ `);
272
+ }
273
+ function z(e) {
274
+ const t = m(e, "schema.ts");
275
+ if (!b(t)) return null;
276
+ try {
277
+ const i = F(w(t, "utf-8"))?.locales?.supported;
278
+ if (!Array.isArray(i) || i.length === 0) return null;
279
+ const l = i.map((s) => typeof s == "string" ? s : s?.id).filter((s) => typeof s == "string");
280
+ return l.length ? new Set(l) : null;
281
+ } catch {
282
+ return null;
283
+ }
284
+ }
285
+ function X(e, t) {
286
+ return t ? t.has(e) : Zt.test(e);
287
+ }
288
+ function Gt(e) {
289
+ for (const t of [e, "en"])
290
+ try {
291
+ const o = new Intl.DisplayNames([t], { type: "language" }).of(e);
292
+ if (o && o !== e) return o;
293
+ } catch {
294
+ }
295
+ return e;
296
+ }
297
+ async function he(e) {
298
+ return b(e) ? (await P(e)).filter((o) => o.endsWith(".ts") && o !== "index.ts" && Ht(m(e, o))) : [];
299
+ }
300
+ function Ht(e) {
301
+ try {
302
+ return ne(w(e, "utf8"), e), !0;
303
+ } catch {
304
+ return !1;
305
+ }
306
+ }
307
+ function qt(e) {
308
+ const t = m(e, "schema.ts"), o = {}, i = [], l = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
309
+ if (!b(t)) return { names: i, orders: o, draftsOff: l, schedulingOff: s };
310
+ try {
311
+ const a = F(w(t, "utf-8"))?.collections ?? {};
312
+ for (const [r, c] of Object.entries(a))
313
+ i.push(r), Array.isArray(c?.order) && (o[r] = c.order.filter((f) => typeof f == "string")), c?.drafts === !1 && l.add(r), c?.scheduling === !1 && s.add(r);
314
+ } catch {
315
+ }
316
+ return { names: i, orders: o, draftsOff: l, schedulingOff: s };
317
+ }
318
+ const Zt = /^[a-z]{2,3}(-[a-z]{4})?(-([a-z]{2}|[0-9]{3}))?$/i, re = (e) => e.replace(/[^a-zA-Z0-9]/g, "_");
319
+ function ge(e) {
320
+ return e.replace(".ts", "").replace(/-/g, "_");
321
+ }
322
+ function ye(e) {
323
+ return e.replace(".ts", "").replace(/-/g, "_");
324
+ }
325
+ function te(e) {
326
+ return e.replace(".ts", "");
327
+ }
328
+ function U(e, t) {
329
+ if (t.some((o) => ye(o) === "locale"))
330
+ throw new Error(`[okno] ${e} content name "locale" is reserved for namespace localization in "okno/${e}". Rename this content entry before generating the module.`);
331
+ }
332
+ function Ge(e, t) {
333
+ let o;
334
+ try {
335
+ o = F(w(e, "utf8"));
336
+ } catch {
337
+ return !0;
338
+ }
339
+ if (!o || typeof o != "object") return !0;
340
+ const i = /* @__PURE__ */ new Set(), l = (s) => Object.values(s ?? {}).some((n) => !n || typeof n != "object" ? !1 : n.type === "reference" || n.fields && l(n.fields) ? !0 : [n.block, ...Array.isArray(n.blocks) ? n.blocks : []].filter((r) => typeof r == "string").some((r) => !i.has(r) && (i.add(r), l(o.blocks?.[r]?.fields))));
341
+ return Object.values(o[t] ?? {}).some((s) => l(s?.fields));
342
+ }
343
+ const He = (e) => e.replace(/\b(__oknoWrap|__oknoResolveEnums|__oknoLiftSlots|__oknoLocalize)\(/g, "/* @__PURE__ */ $1(");
344
+ function ke(e, t, o, i = "") {
345
+ return [
346
+ `import { __oknoWrap, __oknoLocaleNamespace, __oknoLocalize, __oknoResolveEnums, __oknoLiftSlots, __oknoSetImages, __oknoSetRoutes${o ? ", __oknoSetAssets" : ""}${i} } from "okno/runtime"`,
347
+ Kt(t),
348
+ ...o ? [o] : [],
349
+ `const __oknoFileAlts = ${JSON.stringify(Mt(e))}`,
350
+ `const __oknoFilePosters = ${JSON.stringify(Lt(e))}`,
351
+ `const __oknoFileSources = ${JSON.stringify(Ct(e))}`,
352
+ `const __oknoMissingFiles = new Map(${JSON.stringify(Pt(e).map((l) => [l, null]))})`
353
+ ];
354
+ }
355
+ function _e(e) {
356
+ return `export const locale = (__oknoLocaleCode) => __oknoLocaleNamespace({ ${[...e].join(", ")} }, __oknoLocaleCode)`;
357
+ }
358
+ function Lo(e) {
359
+ const t = m(e, "schema.ts");
360
+ let o = [], i = "";
361
+ if (b(t))
362
+ try {
363
+ const l = F(w(t, "utf-8")), s = l?.locales?.supported;
364
+ Array.isArray(s) && (o = s.map((n) => typeof n == "string" ? { id: n } : n).filter((n) => !!n && typeof n.id == "string").map((n) => ({
365
+ id: n.id,
366
+ name: n.name || Gt(n.id),
367
+ // Preserve an intentionally empty slug (= no URL prefix for the default).
368
+ slug: typeof n.slug == "string" ? n.slug : n.id.toLowerCase()
369
+ })), i = typeof l.locales.default == "string" ? l.locales.default : o[0]?.id ?? "");
370
+ } catch {
371
+ }
372
+ return [
373
+ `const __raw = ${JSON.stringify(o)}`,
374
+ `const __def = ${JSON.stringify(i)}`,
375
+ // Swap the locale prefix on a path (empty slug = no prefix). Best-effort,
376
+ // matches the editor's own resolver; fully translated paths = dev's own tags.
377
+ "function __swap(pathname, slug) {",
378
+ ' const norm = (pathname || "/").replace(/\\/+$/, "") || "/"',
379
+ ' const segs = norm.split("/").filter(Boolean)',
380
+ " const known = __raw.find((l) => l.slug && l.slug === segs[0])",
381
+ ' const rest = known ? "/" + segs.slice(1).join("/") : norm',
382
+ ' const r = rest === "" ? "/" : rest',
383
+ " if (!slug) return r",
384
+ ' return r === "/" ? "/" + slug : "/" + slug + r',
385
+ "}",
386
+ 'const __origin = (url) => (typeof url === "object" && url !== null ? url.origin : "")',
387
+ 'const __path = (url) => (typeof url === "object" && url !== null ? url.pathname : String(url || "/"))',
388
+ "/** The configured languages — an array of { id, name, slug, link(url) }.",
389
+ " * link(url) → this entry's hreflang <link> descriptor (spread onto a <link>;",
390
+ " * pass Astro.url for an absolute href). `locales.default` is the base entry. */",
391
+ "export const locales = __raw.map((l) => ({",
392
+ " ...l,",
393
+ ' link: (url) => ({ rel: "alternate", hreflang: l.id, href: __origin(url) + __swap(__path(url), l.slug) }),',
394
+ "}))",
395
+ // `.default` = the base-locale entry (same object reference as in the array).
396
+ "locales.default = locales.find((l) => l.id === __def) || locales[0]"
397
+ ].join(`
398
+ `);
399
+ }
400
+ async function Co(e) {
401
+ const t = m(e, "strings.ts");
402
+ if (!b(t))
403
+ return [
404
+ 'import { __oknoMakeStrings } from "okno/runtime"',
405
+ 'export const strings = __oknoMakeStrings({}, {}, "")'
406
+ ].join(`
407
+ `);
408
+ const o = m(e, "schema.ts"), i = b(o), l = [...z(e) ?? []], s = z(e), n = m(e, "strings"), a = [];
409
+ if (b(n)) {
410
+ const d = await P(n, { withFileTypes: !0 });
411
+ for (const k of d) {
412
+ if (!k.isFile() || !k.name.endsWith(".ts") || k.name === "index.ts") continue;
413
+ const y = k.name.replace(/\.ts$/, "");
414
+ X(y, s) && a.push(y);
415
+ }
416
+ }
417
+ const r = [
418
+ 'import { __oknoMakeStrings, __oknoLocalize, __oknoExpandStrings } from "okno/runtime"',
419
+ `import _strings_default from "${t}"`
420
+ ];
421
+ i && r.push(`import __schema from "${o}"`);
422
+ const c = i ? "__schema?.strings" : "{}", f = i ? "__schema?.locales?.default" : '""', u = JSON.stringify(l);
423
+ if (a.length === 0)
424
+ return r.push(`export const strings = __oknoMakeStrings(__oknoExpandStrings(_strings_default), ${c}, ${f}, ${u})`), r.join(`
425
+ `);
426
+ const p = [];
427
+ for (const d of a) {
428
+ const k = re(d);
429
+ r.push(`import _strings_${k} from "${m(n, d + ".ts")}"`), p.push(`"${d}": __oknoExpandStrings(_strings_${k})`);
430
+ }
431
+ return r.push("const _strings_base = __oknoExpandStrings(_strings_default)"), r.push(`const _strings_localized = __oknoLocalize(_strings_base, { ${p.join(", ")} })`), r.push(`export const strings = __oknoMakeStrings(_strings_localized, ${c}, ${f}, ${u})`), r.join(`
432
+ `);
433
+ }
434
+ async function Po(e, t = /* @__PURE__ */ new Set(), o = "raw", i) {
435
+ const l = m(e, "pages"), s = m(e, "schema.ts"), n = b(s), a = n && Ge(s, "pages");
436
+ n && U("pages", Object.keys(F(w(s, "utf8"))?.pages ?? {}));
437
+ const r = ke(e, o, i);
438
+ n && (a && r.push('import * as __collections from "okno/collections"'), r.push(`import __schema from "${s}"`), r.push("__oknoSetRoutes(__schema)"));
439
+ const c = JSON.stringify([...z(e) ?? []]), f = (d, k) => {
440
+ if (!n) return `_${d}`;
441
+ const y = `__schema?.pages?.["${k}"]?.fields`;
442
+ return `__oknoResolveEnums(_${d}, ${y}, ${c})`;
443
+ }, u = (d) => n ? `, undefined, { slots: __oknoLiftSlots(__schema?.pages?.["${d}"]?.fields), defaultLocale: __schema?.locales?.default, fields: __schema?.pages?.["${d}"]?.fields, schema: __schema, ${a ? "collections: __collections, " : ""}locales: ${c}, fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles }` : ", undefined, { fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles }", p = /* @__PURE__ */ new Set();
444
+ if (b(l)) {
445
+ const d = z(e), y = (await P(l, { withFileTypes: !0 })).filter((_) => _.isDirectory() && X(_.name, d)).map((_) => _.name), A = await he(l);
446
+ for (const _ of A) {
447
+ const O = ge(_), T = ye(_);
448
+ U("pages", [T]);
449
+ const g = te(_), h = m(l, _);
450
+ if (y.length === 0) {
451
+ r.push(`import _${O} from "${h}"`), r.push(`export const ${T} = __oknoWrap(${f(O, g)}, "${g}"${u(g)})`), p.add(T);
452
+ continue;
453
+ }
454
+ const $ = [`import _${O}_default from "${h}"`], j = [];
455
+ for (const S of y) {
456
+ const x = m(l, S, _);
457
+ if (b(x)) {
458
+ const v = re(S);
459
+ $.push(`import _${O}_${v} from "${x}"`), j.push(`"${S}": _${O}_${v}`);
460
+ }
461
+ }
462
+ r.push(...$), r.push(`const _${O} = __oknoLocalize(_${O}_default, { ${j.join(", ")} })`), r.push(`export const ${T} = __oknoWrap(${f(O, g)}, "${g}"${u(g)})`), p.add(T);
463
+ }
464
+ }
465
+ for (const d of t)
466
+ d === "locale" || p.has(d) || (r.push(`export const ${d} = __oknoWrap(null, "${d}"${u(d)})`), p.add(d));
467
+ return r.push(_e(p)), He(r.join(`
468
+ `));
469
+ }
470
+ async function Ro(e, t = /* @__PURE__ */ new Set(), o = !1, i = "raw", l) {
471
+ const s = m(e, "collections"), n = z(e), a = b(s) ? await P(s, { withFileTypes: !0 }) : [], { names: r, orders: c, draftsOff: f, schedulingOff: u } = qt(e), p = a.filter((g) => g.isDirectory() && X(g.name, n)).map((g) => g.name), d = a.filter((g) => g.isDirectory() && !p.includes(g.name)).map((g) => g.name);
472
+ U("collections", [...r, ...d]);
473
+ const k = [...new Set([...r, ...d, ...[...t].filter((g) => g !== "locale")].map((g) => g.replace(/_/g, "-")))], y = JSON.stringify([...n ?? []]);
474
+ for (const g of k) {
475
+ const h = await P(m(s, g), { withFileTypes: !0 }).catch(() => []);
476
+ for (const $ of h)
477
+ $.isDirectory() && X($.name, n) && console.warn(
478
+ `[okno] "collections/${g}/${$.name}/" looks like a misplaced locale folder. Collection locale overrides go at "collections/${$.name}/${g}/<slug>.ts" (locale right after "collections/"). This folder will NOT be localized.`
479
+ );
480
+ }
481
+ const A = m(e, "schema.ts"), _ = b(A), O = ke(e, i, l, ", __oknoVisible, __oknoNormalizeCollectionDraft, __oknoCollection");
482
+ _ && (O.push(`import __schema from "${A}"`), O.push("__oknoSetRoutes(__schema)"));
483
+ const T = [];
484
+ for (const g of k) {
485
+ const h = _ ? `__schema?.collections?.[${JSON.stringify(g)}]?.fields` : "undefined", $ = m(s, g), j = jt(await he($), te, c[g]), S = g.replace(/-/g, "_"), x = o && !f.has(g), v = o && !u.has(g), E = [];
486
+ for (const N of j) {
487
+ const I = `_${S}_${ge(N)}`, M = te(N), V = m($, N);
488
+ if (p.length === 0)
489
+ O.push(`import ${I}_stored from "${V}"`), O.push(`const ${I} = __oknoNormalizeCollectionDraft(${I}_stored, ${h})`);
490
+ else {
491
+ const L = [`import ${I}_default from "${V}"`], J = [];
492
+ for (const K of p) {
493
+ const H = m(s, K, g, N);
494
+ if (b(H)) {
495
+ const q = re(K);
496
+ L.push(`import ${I}_${q} from "${H}"`), J.push(`"${K}": __oknoNormalizeCollectionDraft(${I}_${q}, ${h})`);
497
+ }
498
+ }
499
+ O.push(...L), O.push(`const ${I} = __oknoLocalize(__oknoNormalizeCollectionDraft(${I}_default, ${h}), { ${J.join(", ")} })`);
500
+ }
501
+ E.push({ varName: I, itemName: M });
502
+ }
503
+ const R = [x ? "item?.draft !== true" : "", v ? "__oknoVisible(item)" : ""].filter(Boolean);
504
+ O.push(`const __oknoRaw_${S} = [${E.map((N) => N.varName).join(", ")}]${R.length ? `.filter(item => ${R.join(" && ")})` : ""}`), T.push({ name: g, safe: S, draftsOn: x, schedulingOn: v, items: E });
505
+ }
506
+ _ && O.push(`const __oknoNs = { ${T.map((g) => `${g.safe}: __oknoRaw_${g.safe}`).join(", ")} }`);
507
+ for (const g of T) {
508
+ const h = `__schema?.collections?.["${g.name}"]?.fields`, $ = (E) => _ ? `__oknoResolveEnums(${E.varName}, ${h}, ${y})` : E.varName;
509
+ let j = ", { fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles, collection: true }";
510
+ _ && (O.push(`const __oknoSlots_${g.safe} = __oknoLiftSlots(${h})`), j = `, { slots: __oknoSlots_${g.safe}, defaultLocale: __schema?.locales?.default, fields: ${h}, schema: __schema, collections: __oknoNs, locales: ${y}, fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles, collection: true }`);
511
+ const S = [];
512
+ g.draftsOn && S.push("e[0]?.draft !== true"), g.schedulingOn && S.push("__oknoVisible(e[0])");
513
+ const v = `__oknoCollection(${`[${g.items.map((E) => `[${E.varName}, ${$(E)}, ${JSON.stringify(E.itemName)}]`).join(", ")}]${S.length ? `.filter((e) => ${S.join(" && ")})` : ""}`}, (r, s, i) => __oknoWrap(r, "${g.name}." + s, "${g.name}." + i${j}), ${_ ? "__schema?.locales?.default" : "undefined"}, ${y})`;
514
+ O.push(`const __oknoCollection_${g.safe} = ${v}`), O.push(
515
+ `Object.defineProperty(__oknoCollection_${g.safe}, "new", { value: __oknoWrap({ slug: "new" }, "${g.name}.new", undefined${j}), enumerable: false })`
516
+ ), O.push(`export const ${g.safe} = __oknoCollection_${g.safe}`);
517
+ }
518
+ return O.push(_e(T.map((g) => g.safe))), O.join(`
519
+ `);
520
+ }
521
+ async function Vo(e, t = /* @__PURE__ */ new Set(), o = "raw", i) {
522
+ const l = m(e, "globals"), s = m(e, "schema.ts"), n = b(s), a = n && Ge(s, "globals");
523
+ n && U("globals", Object.keys(F(w(s, "utf8"))?.globals ?? {}));
524
+ const r = ke(e, o, i);
525
+ n && (a && r.push('import * as __collections from "okno/collections"'), r.push(`import __schema from "${s}"`), r.push("__oknoSetRoutes(__schema)"));
526
+ const c = JSON.stringify([...z(e) ?? []]), f = (d, k) => {
527
+ if (!n) return `_${d}`;
528
+ const y = `__schema?.globals?.["${k}"]?.fields`;
529
+ return `__oknoResolveEnums(_${d}, ${y}, ${c})`;
530
+ }, u = (d) => n ? `, undefined, { slots: __oknoLiftSlots(__schema?.globals?.["${d}"]?.fields), defaultLocale: __schema?.locales?.default, fields: __schema?.globals?.["${d}"]?.fields, schema: __schema, ${a ? "collections: __collections, " : ""}locales: ${c}, fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles }` : ", undefined, { fileAlts: __oknoFileAlts, filePosters: __oknoFilePosters, fileSources: __oknoFileSources, missingFiles: __oknoMissingFiles }", p = /* @__PURE__ */ new Set();
531
+ if (b(l)) {
532
+ const d = z(e), y = (await P(l, { withFileTypes: !0 })).filter((_) => _.isDirectory() && X(_.name, d)).map((_) => _.name), A = await he(l);
533
+ for (const _ of A) {
534
+ const O = ge(_), T = ye(_);
535
+ U("globals", [T]);
536
+ const g = te(_), h = m(l, _);
537
+ if (y.length === 0) {
538
+ r.push(`import _${O} from "${h}"`), r.push(`export const ${T} = __oknoWrap(${f(O, g)}, "${g}"${u(g)})`), p.add(T);
539
+ continue;
540
+ }
541
+ const $ = [`import _${O}_default from "${h}"`], j = [];
542
+ for (const S of y) {
543
+ const x = m(l, S, _);
544
+ if (b(x)) {
545
+ const v = re(S);
546
+ $.push(`import _${O}_${v} from "${x}"`), j.push(`"${S}": _${O}_${v}`);
547
+ }
548
+ }
549
+ r.push(...$), r.push(`const _${O} = __oknoLocalize(_${O}_default, { ${j.join(", ")} })`), r.push(`export const ${T} = __oknoWrap(${f(O, g)}, "${g}"${u(g)})`), p.add(T);
550
+ }
551
+ }
552
+ for (const d of t)
553
+ d === "locale" || p.has(d) || (r.push(`export const ${d} = __oknoWrap(null, "${d}"${u(d)})`), p.add(d));
554
+ return r.push(_e(p)), He(r.join(`
555
+ `));
556
+ }
557
+ const G = /* @__PURE__ */ new Set();
558
+ function Z(e) {
559
+ return b(e) ? oe(e, { withFileTypes: !0 }).filter((t) => t.isFile() && t.name.endsWith(".ts") && t.name !== "index.ts").map((t) => m(e, t.name)) : [];
560
+ }
561
+ const Xt = /^(<{7}|>{7}) /m;
562
+ function de(e, t) {
563
+ let o = "";
564
+ try {
565
+ o = w(e, "utf8");
566
+ const i = ne(o, e);
567
+ if (!i || typeof i != "object" || Array.isArray(i)) throw new Error("Content must export a record object");
568
+ return i;
569
+ } catch (i) {
570
+ const l = Xt.test(o) ? "it contains unresolved Git conflict markers (<<<<<<< / >>>>>>>). Keep one version, remove the markers and save" : i instanceof Error ? i.message : String(i), s = `[okno] Invalid content module ${e}: ${l}`;
571
+ if (t === "strict") throw new Error(s);
572
+ return G.has(s) || (G.add(s), console.warn(`${s}. Skipped until it is fixed.`)), null;
573
+ }
574
+ }
575
+ function Yt(e, t, o = "strict") {
576
+ if (!t) return;
577
+ const i = [], l = /* @__PURE__ */ new Map(), s = (t.locales?.supported ?? []).map((c) => typeof c == "string" ? c : c?.id).filter((c) => typeof c == "string" && c.length > 0);
578
+ for (const c of Object.keys(t.collections ?? {})) {
579
+ const f = /* @__PURE__ */ new Set();
580
+ for (const u of Z(m(e, "collections", c))) {
581
+ const d = de(u, o)?.slug;
582
+ typeof d == "string" && d && f.add(d);
583
+ }
584
+ l.set(c, f);
585
+ }
586
+ for (const c of ["pages", "globals", "collections"])
587
+ for (const f of Object.keys(t[c] ?? {})) {
588
+ const u = c === "collections" ? Z(m(e, c, f)) : Z(m(e, c)).filter((p) => p.endsWith(`/${f}.ts`));
589
+ for (const p of u) {
590
+ const d = de(p, o);
591
+ if (d)
592
+ for (const k of Te(t, [{ kind: c, name: f, value: d }], l)) i.push(k);
593
+ }
594
+ for (const p of s) {
595
+ const d = c === "collections" ? Z(m(e, c, p, f)) : Z(m(e, c, p)).filter((k) => k.endsWith(`/${f}.ts`));
596
+ for (const k of d) {
597
+ const y = de(k, o);
598
+ if (y)
599
+ for (const A of Te(t, [{ kind: c, name: f, locale: p, value: y }], l)) i.push(A);
600
+ }
601
+ }
602
+ }
603
+ const n = o === "development" ? i.filter((c) => c.fatal && c.code === "required_missing") : [], a = i.filter((c) => c.fatal && !(o === "development" && c.code === "required_missing")), r = i.filter((c) => !c.fatal);
604
+ if (n.length) {
605
+ const c = n.slice(0, 25).map((d) => ` - ${d.path}: ${d.message}`).join(`
606
+ `), f = n.length > 25 ? `
607
+ - …and ${n.length - 25} more` : "", u = `[okno] Incomplete content during development. Fill required fields before building:
608
+ ${c}${f}`, p = `${e}
609
+ ${u}`;
610
+ G.has(p) || (G.add(p), console.warn(u));
611
+ }
612
+ if (r.length) {
613
+ const c = r.slice(0, 5).map((d) => ` - ${d.path}: ${d.message}`).join(`
614
+ `), f = r.length > 5 ? `
615
+ - …and ${r.length - 5} more` : "", u = `[okno] ${r.length} legacy content value(s) do not match the current schema. They remain readable, but should be resaved:
616
+ ${c}${f}`, p = `${e}
617
+ ${u}`;
618
+ G.has(p) || (G.add(p), console.warn(u));
619
+ }
620
+ if (a.length) {
621
+ const c = a.slice(0, 25).map((u) => ` - ${u.path}: ${u.message}`).join(`
622
+ `), f = a.length > 25 ? `
623
+ - …and ${a.length - 25} more` : "";
624
+ throw new Error(`[okno] Content integrity errors:
625
+ ${c}${f}`);
626
+ }
627
+ }
628
+ const B = (e, t) => [...new Set(e.map((o) => t(`file${o}`)))].sort().map((o) => JSON.stringify(o)).join(" | "), $e = (e) => e === "number" || e === "count" ? "number" : "string | number", W = (e, t) => {
629
+ const o = (i) => [...i].map((l) => /^[A-Za-z0-9_]$/.test(l) ? l : `_x${l.codePointAt(0).toString(16)}_`).join("");
630
+ return `OknoSchema_${o(e)}_${o(t)}`;
631
+ }, be = /^[A-Za-z_$][\w$]*$/, Qt = (e, t) => be.test(t) ? `${e}.${t}` : `${e}[${JSON.stringify(t)}]`, Dt = (e) => {
632
+ const t = e.replace(/[-_]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").trim().toLowerCase();
633
+ return t.charAt(0).toUpperCase() + t.slice(1);
634
+ }, Le = (e, t, o = "") => typeof e == "number" && typeof t == "number" ? `${e}–${t}${o}` : typeof t == "number" ? `max ${t}${o}` : typeof e == "number" ? `min ${e}${o}` : "";
635
+ function qe(e, t, o, i, l) {
636
+ const s = t.type ?? "string";
637
+ if (s === "divider") return [];
638
+ const n = t.multiple === !0, a = s === "string" && !n ? Object.keys(t.slots ?? {}) : [], r = s === "enum" ? (t.options ?? []).map((y) => typeof y == "string" ? y : y?.name ?? y?.value).filter((y) => typeof y == "string") : [], c = Array.isArray(t.blocks) ? t.blocks : typeof t.block == "string" ? [t.block] : [], f = [
639
+ xt[s] ?? s,
640
+ s === "string" && t.html ? "HTML" : "",
641
+ s === "string" && t.multiline ? "multiline" : "",
642
+ s === "string" ? t.email ? "email" : t.url ? "URL" : t.phone ? "phone" : "" : "",
643
+ s === "string" ? Le(t.min, t.max, " chars") : "",
644
+ a.length ? `slots ${a.map((y) => `{${y}}`).join(" ")}` : "",
645
+ s === "number" && t.integer ? "integer" : "",
646
+ s === "number" ? Le(t.min, t.max) : "",
647
+ s === "date" && t.time ? "with time" : "",
648
+ r.length ? r.slice(0, 6).join(", ") + (r.length > 6 ? ", …" : "") : "",
649
+ s === "media" && t.accept?.length ? t.accept.join(", ") : "",
650
+ s === "reference" && t.collection ? `→ ${t.collection}` : "",
651
+ s === "block" && c.length ? `→ ${c.join(" | ")}` : "",
652
+ s === "slug" && t.from ? `from ${t.from}` : "",
653
+ t.required ? "required" : "",
654
+ n ? typeof t.maxItems == "number" ? `multiple, max ${t.maxItems}` : "multiple" : "",
655
+ t.localized ? "localized" : ""
656
+ ].filter(Boolean), u = [`**${t.label?.trim() || Dt(e)}** · ${f.join(" · ")}`];
657
+ t.help?.trim() && u.push(t.help.trim());
658
+ const p = i && s !== "group" && s !== "slug" ? At(o, e, t, i, void 0, l, !0) : "";
659
+ p && u.push("", "```" + (i === "astro" ? "astro" : "tsx"), ...p.split(`
660
+ `), "```");
661
+ const d = !t.required && !n, k = n ? "" : s === "string" && !a.length && !t.html ? "`.value` → raw string, for attributes and comparisons" : s === "number" ? "`.value` → raw number" : s === "boolean" ? "`.value` → raw boolean (the wrapper itself is always truthy)" : s === "color" ? "`.value` → raw CSS color" : s === "date" ? "`.value` → raw ISO string" : s === "enum" ? "`.value` → stored value · `.name` → label" : (s === "media" || s === "reference" || s === "icon") && d ? "`.exists` → whether it is set (wrappers are always truthy)" : "";
662
+ return k && u.push("", k), u.map((y) => y.replaceAll("*/", "*\\/"));
663
+ }
664
+ const Ze = (e, t) => e.length ? [`${t}/**`, ...e.map((o) => o ? `${t} * ${o}` : `${t} *`), `${t} */`] : [];
665
+ function eo(e, t) {
666
+ if (!e) return [];
667
+ const o = [], i = e.blocks ?? {}, l = (n, a, r) => {
668
+ if (!n) return "unknown";
669
+ if (n.type === "string" && !n.multiple && Object.keys(n.slots ?? {}).length)
670
+ return `OknoTextTemplate<{ ${Object.entries(n.slots).map(
671
+ ([u, p]) => `${JSON.stringify(u)}: ${$e(p)}`
672
+ ).join("; ")} }>`;
673
+ let c;
674
+ switch (n.type) {
675
+ case "number":
676
+ c = "number";
677
+ break;
678
+ case "boolean":
679
+ c = "boolean";
680
+ break;
681
+ case "date":
682
+ c = "OknoDateValue";
683
+ break;
684
+ case "icon":
685
+ c = "OknoIconValue<OknoSchemaIcon>";
686
+ break;
687
+ case "media": {
688
+ const f = (n.accept ?? []).filter((u) => typeof u == "string");
689
+ c = `OknoMediaValue<${f.length ? f.map((u) => JSON.stringify(u)).join(" | ") : "OknoMediaKind"}>`;
690
+ break;
691
+ }
692
+ case "link":
693
+ c = "OknoSchemaLink";
694
+ break;
695
+ case "enum": {
696
+ const f = (n.options ?? []).map((p) => typeof p == "string" ? p : p?.value).filter((p) => typeof p == "string");
697
+ c = `OknoOptionValue<${f.length ? f.map((p) => JSON.stringify(p)).join(" | ") : "string"}>`;
698
+ break;
699
+ }
700
+ case "reference":
701
+ c = typeof n.collection == "string" && e.collections?.[n.collection] ? W("collections", n.collection) : "Record<string, unknown>";
702
+ break;
703
+ case "group":
704
+ c = s(n.fields ?? {}, a, r + 1);
705
+ break;
706
+ case "block": {
707
+ const f = Array.isArray(n.blocks) ? n.blocks.filter((u) => typeof u == "string") : typeof n.block == "string" ? [n.block] : [];
708
+ if (f.length > 1 || Array.isArray(n.blocks))
709
+ c = f.length ? f.map(
710
+ (u) => e.blocks?.[u] ? `({ readonly block: ${JSON.stringify(u)} } & ${W("blocks", u)})` : `({ readonly block: ${JSON.stringify(u)} } & Record<string, unknown>)`
711
+ ).join(" | ") : "Record<string, unknown>";
712
+ else {
713
+ const u = f[0];
714
+ c = u && e.blocks?.[u] ? W("blocks", u) : "Record<string, unknown>";
715
+ }
716
+ break;
717
+ }
718
+ case "divider":
719
+ c = "never";
720
+ break;
721
+ default:
722
+ c = "string";
723
+ }
724
+ return n.multiple ? `(${c})[]` : c;
725
+ };
726
+ function s(n, a, r = 1) {
727
+ const c = " ".repeat(r), f = Object.entries(n).filter(([, u]) => u?.type !== "divider").flatMap(([u, p]) => [
728
+ ...Ze(p ? qe(u, p, a, t, i) : [], c),
729
+ `${c}${JSON.stringify(u)}: ${l(p, Qt(a, u), r)}`
730
+ ]);
731
+ return f.length ? `{
732
+ ${f.join(`
733
+ `)}
734
+ ${" ".repeat(r - 1)}}` : "{}";
735
+ }
736
+ for (const n of ["blocks", "collections", "pages", "globals"])
737
+ for (const [a, r] of Object.entries(e[n] ?? {})) {
738
+ const c = r.url, f = n !== "blocks" ? ` & { created: OknoStamp; updated: OknoStamp${n === "collections" ? "; draft?: boolean" : ""}${n === "collections" && typeof c == "string" && c.trim() ? "; href: string" : ""} }` : "", u = Object.fromEntries(Object.entries(r.fields ?? {}).filter(([d]) => n === "blocks" || !["created", "updated"].includes(d))), p = n === "collections" ? "item" : n === "blocks" ? be.test(a) ? a : "block" : a.replace(/-/g, "_");
739
+ o.push(`type ${W(n, a)} = ${s(u, p)}${f}`);
740
+ }
741
+ return o.push(""), o;
742
+ }
743
+ async function Wo(e, t, o = "strict", i) {
744
+ const l = await uo(e), s = new Map(l.map((h) => [h.name, h.first])), n = lo(e);
745
+ for (const h of ["pages", "globals", "collections"]) U(h, Object.keys(n?.[h] ?? {}));
746
+ Yt(e, n, o);
747
+ const a = [
748
+ "// Auto-generated by okno. Do not edit.",
749
+ "",
750
+ "/** A wrapped content value that can be spread onto elements and rendered as text. */",
751
+ "/** A `.locale()` argument: a language id, or a locale from `okno/locales` (its id is read). */",
752
+ "type OknoLocaleInput = string | { readonly id: string } | null | undefined",
753
+ "",
754
+ "type OknoValue<T = unknown> = {",
755
+ ' readonly "data-okno": string',
756
+ ' readonly "data-okno-locale"?: string',
757
+ ' readonly "data-okno-html"?: ""',
758
+ ' readonly "data-okno-slots"?: string',
759
+ " toString(): string",
760
+ // NB: NO `[Symbol.toPrimitive]` in the TYPE. Svelte 5's element-attribute type
761
+ // carries a symbol index signature for attachments (`[key: symbol]: Attachment`),
762
+ // and a `(hint: string) => string` toPrimitive isn't assignable to it — so a
763
+ // `{...field}` spread would fail type-check on every element. The runtime keeps
764
+ // Symbol.toPrimitive (see runtime/wrap.ts) so `{field}` / String(field) still
765
+ // coerce; `toString()` covers the static string-coercion the type needs.
766
+ " onedit(callback: (value: T) => void): () => void",
767
+ " /** Re-root reads at a locale; no-op when unset or on the default locale. Returns the SAME wrapped shape (not `this`, which would drop array element types). */",
768
+ " locale(code?: OknoLocaleInput): OknoWrapped<T>",
769
+ " /** `true` when this field/reference actually holds a value — every read is a truthy wrapper, so `entry.ref ? …` can't tell set from unset. */",
770
+ " readonly exists: boolean",
771
+ "}",
772
+ "",
773
+ "/** A slotted Text field is callable and carries its editing attributes before interpolation. */",
774
+ 'type OknoTextTemplate<P> = ((params: P) => OknoValue<string> & { readonly value: string }) & Pick<OknoValue<string>, "data-okno" | "data-okno-locale" | "data-okno-html" | "data-okno-slots">',
775
+ "",
776
+ "/** The explicit reorder handle — spread `.drag` on a semantic wrapper (`<li {...item.drag}>`, `<tr {...item.drag}>`) when the item's own element can't be the direct child of the reorder container. Emits the same `data-okno-item` boundary as the bare `{...item}` spread; the editor resolves the OUTERMOST element carrying it as the drag unit, so both a wrapper's `.drag` and an inner `{...item}` can coexist. Present on every array item (leaf AND block). */",
777
+ 'type OknoDrag = { readonly drag: { readonly "data-okno-item": string; readonly "data-okno-locale"?: string } }',
778
+ "/** The reorder hook carried directly on an array item's bare spread (`{...item}`), so a leaf multiple needs no separate `{...item.drag}` in the common case. */",
779
+ 'type OknoDragItem = { readonly "data-okno-item": string; readonly "data-okno-locale"?: string }',
780
+ "/** One array member. A LEAF (media/link/text) is spread bare — `{...item}` — so it carries `data-okno-item` for reorder AND still exposes `.drag` as an escape hatch (for a semantic wrapper). A BLOCK/reference member also spreads only hooks, not its child fields. Use `.drag` when its reorder placement differs from its content element. */",
781
+ "/** A leaf array member: the value plus its reorder hooks. */",
782
+ "type OknoItem<V> = V & OknoDragItem & OknoDrag",
783
+ "/** A list field: iterate its items; `.onedit` reports every list edit with the raw items. */",
784
+ "type OknoList<T, U> = OknoArrayItem<U>[] & { onedit(callback: (value: T) => void): () => void }",
785
+ "type OknoArrayItem<U> =",
786
+ " U extends OknoIcon | OknoDateValue ? OknoItem<U> :",
787
+ " U extends string | number | boolean",
788
+ " ? OknoItem<OknoWrapped<U>>",
789
+ " : U extends { src: string }",
790
+ " ? OknoItem<OknoWrapped<U>>",
791
+ " : U extends { url: string; text: string }",
792
+ " ? OknoItem<OknoWrapped<U>>",
793
+ " : OknoWrapped<U> & OknoDrag",
794
+ "",
795
+ "/** A media value's `.image` handle — props for the active framework image component: an Astro asset source or a Next/Nuxt/raw URL, plus alt/dimensions and the edit hook. Use `<img {...cover}>` for the universal raw path. `src` stays loose because its framework-specific type is intentionally different. */",
796
+ 'type OknoImage = { src: any; alt: string; width?: number; height?: number; readonly "data-okno": string; readonly "data-okno-locale"?: string }',
797
+ "",
798
+ 'type OknoIcon = { readonly alt: string; readonly svg: { viewBox: string; role?: "img"; readonly "aria-label"?: string; readonly "aria-hidden"?: boolean; readonly "data-okno": string; readonly "data-okno-locale"?: string; readonly "data-okno-item"?: string }; readonly symbol: string }',
799
+ 'type OknoIconValue<T extends { src: string; viewBox: string }> = OknoIcon & Omit<OknoValue<T>, "locale"> & { locale(code?: OknoLocaleInput): OknoIconValue<T>; toJSON(): T }',
800
+ "/** Option renders its stored token; name/value are raw strings. Only schema Option fields use this already-wrapped contract, preserving ordinary name/value objects. */",
801
+ 'type OknoOptionValue<V extends string = string> = Omit<OknoValue<{ name: string; value: V }>, "locale" | "onedit"> & { readonly name: string; readonly value: V | ""; onedit(callback: (value: V | "" | null | undefined) => void): () => void; locale(code?: OknoLocaleInput): OknoOptionValue<V>; toJSON(): { name: string; value: V } | null }',
802
+ "/** Schema Date fields preserve their raw ISO value while format() returns a spreadable localized presentation with the same edit/reorder identity. */",
803
+ 'interface OknoDateValue extends Omit<OknoValue<string>, "locale" | "onedit"> { readonly value: string; readonly "data-okno-date-format"?: string; format(locale?: string, options?: Intl.DateTimeFormatOptions): this; locale(code?: OknoLocaleInput): this; onedit(callback: (value: string | null | undefined) => void): () => void; toJSON(): string }',
804
+ "/** Canonical raw media shape. Framework-specific optimized data is exposed by the wrapped value's `.image` handle. */",
805
+ "type OknoSchemaMedia = { src: string; alt: string; width?: number; height?: number; focal?: { x: number; y: number } }",
806
+ "type OknoSchemaIcon = { src: string; viewBox: string }",
807
+ "type OknoSchemaLink = { text: string; url: string; external?: boolean }",
808
+ "",
809
+ "/** Text value: renders as text and spreads its edit hook; `.value` is the raw string. */",
810
+ "type OknoText = OknoValue<string> & { readonly value: string }",
811
+ "/** Number value: `.value` is the raw number. */",
812
+ "type OknoNumber = OknoValue<number> & { readonly value: number }",
813
+ "/** Toggle value: `.value` is the raw boolean (the wrapper itself is always truthy). */",
814
+ "type OknoBoolean = OknoValue<boolean> & { readonly value: boolean }",
815
+ "/** File kind of a media value, from its extension. */",
816
+ 'type OknoMediaKind = "image" | "video" | "audio" | "document"',
817
+ "/** File extension (no dot) per kind; any extension counts as a document. */",
818
+ `type OknoMediaFormats = { image: ${B(Ee, Y)}; video: ${B(Ie, Y)}; audio: ${B(Ne, Y)}; document: string }`,
819
+ "/** IANA media type per kind. */",
820
+ `type OknoMediaMimes = { image: ${B(Ee, ue)}; video: ${B(Ie, ue)}; audio: ${B(Ne, ue)}; document: string }`,
821
+ '/** Media value: spread raw attributes (`<img {...x} />` or `<video {...x} />`); `.image` feeds the framework image component; `poster` spreads a video\'s Files poster; `.sources` lists a video\'s formats for `<source>` children (then the spread has no `src`), [] when it has one; `.kind` says which element to render, `.format` is the extension ("mp4"), `.mime` the IANA type ("video/mp4"); each "" while unset. */',
822
+ 'type OknoMediaOf<T, K extends OknoMediaKind = OknoMediaKind> = Omit<T, "focal" | "alt"> & { readonly alt: string } & OknoValue<T> & { readonly image: OknoImage; readonly poster?: string; readonly sources: readonly { readonly src: string; readonly type: string }[]; readonly kind: K | ""; readonly format: OknoMediaFormats[K] | ""; readonly mime: OknoMediaMimes[K] | "" } & (T extends { focal: infer F } ? { readonly focal: OknoWrapped<F> } : {})',
823
+ "type OknoMedia = OknoMediaOf<OknoSchemaMedia>",
824
+ "/** Schema Media field value: `.kind`, `.format` and `.mime` narrowed to the kinds the field accepts. */",
825
+ "type OknoMediaValue<K extends OknoMediaKind = OknoMediaKind> = OknoMediaOf<OknoSchemaMedia, K>",
826
+ "/** Link value: spread onto `<a>` (href, target, rel); renders its text. */",
827
+ "type OknoLinkOf<T> = { href: string; target?: string; rel?: string } & OknoValue<T>",
828
+ "type OknoLink = OknoLinkOf<OknoSchemaLink>",
829
+ "type OknoExact<T, S> = [T] extends [S] ? [S] extends [T] ? true : false : false",
830
+ "/** Recursively wraps content types so values are spreadable/renderable. Media (`{src}`) and link (`{url,text}`) objects keep RAW attribute values so `<img {...media}>` / `<a {...link}>` type-check; media also exposes `.image`; other objects expose wrapped fields + the data-okno hook. Array items carry `data-okno-item` on the bare spread (leaf multiples) AND expose `.drag` (the explicit reorder handle, for block wrappers or a leaf's semantic wrapper). */",
831
+ "type OknoWrapped<T> = [T] extends [never] ? OknoWrap<T> : [T] extends [boolean] ? OknoBoolean : OknoWrap<T>",
832
+ "type OknoWrap<T> =",
833
+ " T extends (...args: any[]) => any ? T :",
834
+ " T extends OknoIcon ? T :",
835
+ " T extends OknoDateValue ? T :",
836
+ " T extends OknoOptionValue ? T :",
837
+ " T extends OknoMediaValue<any> ? T :",
838
+ " T extends string | number | boolean",
839
+ " ? OknoExact<T, string> extends true ? OknoText : OknoExact<T, number> extends true ? OknoNumber : OknoValue<T> & { readonly value: T }",
840
+ " : T extends ReadonlyArray<infer U>",
841
+ " ? OknoList<T, U>",
842
+ " : T extends { src: string }",
843
+ " ? OknoExact<T, OknoSchemaMedia> extends true ? OknoMedia : OknoMediaOf<T>",
844
+ " : T extends { url: string; text: string }",
845
+ " ? OknoExact<T, OknoSchemaLink> extends true ? OknoLink : OknoLinkOf<T>",
846
+ " : OknoExact<T, OknoStamp> extends true ? OknoStampValue",
847
+ " : T extends Record<string, unknown>",
848
+ ' ? { [K in keyof T]: K extends "href" | "slug" | "block" ? T[K] : K extends "draft" ? {} extends Pick<T, K> ? T[K] : OknoWrapped<T[K]> : OknoWrapped<T[K]> } & OknoValue<T> & (T extends { created: OknoStamp; updated: OknoStamp } ? OknoDrag : {})',
849
+ " : OknoValue<T>",
850
+ "",
851
+ "/** Content referenced in code but not yet scaffolded — shape unknown, so every field is a flat leaf. Nested access (`home.hero.title`) is a type error on purpose: okno fields are flat (dividers organize the editor, they don't nest data). Use a Block for nested shapes. */",
852
+ "type OknoUnscaffolded = OknoWrapped<Record<string, unknown>>",
853
+ "",
854
+ "/** Authorship + timestamp metadata Okno writes on every entry (page, collection item, global). Read-only — never edit or spread; it's the data your own `.sort()` uses. Each is wrapped, so render `{a.updated.date}` and compare `String(a.updated.date)`. */",
855
+ "type OknoStamp = { readonly date: string; readonly author: string }",
856
+ "type OknoStampValue = { readonly date: OknoText; readonly author: OknoText } & OknoValue<OknoStamp>",
857
+ "type OknoMeta = {",
858
+ " readonly created: OknoWrapped<OknoStamp>",
859
+ " readonly updated: OknoWrapped<OknoStamp>",
860
+ "}",
861
+ "",
862
+ "/** A collection's real records plus its permanent, non-enumerated creation record. Use `.new` only when mapping the collection's dynamic route; normal iteration contains stored records only. The array holds items in all languages plus items limited to the default language; `.locale(code)` holds items in all languages read in `code` plus items limited to `code`. */",
863
+ "type OknoCollection<T> = T[] & { readonly new: T; locale(code?: OknoLocaleInput): OknoCollection<T> }",
864
+ ""
865
+ ];
866
+ a.push(...eo(n, i)), a.push(...to(n, i));
867
+ const r = ([, h]) => h?.type === "reference" && typeof h.collection == "string" && s.has(h.collection), c = ([, h]) => h?.type === "enum", f = ([, h]) => h?.type === "string" && !h.multiple && h.slots && typeof h.slots == "object" && !Array.isArray(h.slots) && Object.keys(h.slots).length > 0, u = ([h, $]) => {
868
+ const j = Object.entries($.slots).map(([S, x]) => `${JSON.stringify(S)}: ${$e(x)}`).join("; ");
869
+ return `${h}: OknoTextTemplate<{ ${j} }>`;
870
+ }, p = ([h, $]) => {
871
+ const j = (Array.isArray($?.options) ? $.options : []).map((v) => typeof v == "string" ? v : v?.value).filter((v) => typeof v == "string"), x = `OknoOptionValue<${j.length ? j.map((v) => JSON.stringify(v)).join(" | ") : "string"}>`;
872
+ return `${h}: ${$.multiple ? `${x}[]` : x}`;
873
+ }, d = (h, $) => {
874
+ const j = `typeof import("${$}").default`, S = m(e, $), x = ne(w(b(S) ? S : `${S}.ts`, "utf8"), $), v = !!x && typeof x == "object" && !Array.isArray(x) && Object.hasOwn(x, "status") && !Object.hasOwn(yt(x, n?.collections?.[h]?.fields), "status");
875
+ return `Omit<${j}, "draft"${v ? ' | "status"' : ""}> & { draft?: boolean }`;
876
+ }, k = (h) => n?.collections?.[h] ? W("collections", h) : s.has(h) ? d(h, `./collections/${h}/${s.get(h)}`) : "Record<string, unknown>", y = (h) => {
877
+ const $ = n?.collections?.[h]?.url;
878
+ return typeof $ == "string" && $.trim() ? " & { href: string }" : "";
879
+ }, A = (h, $) => {
880
+ const j = k(h);
881
+ if (n?.collections?.[h]) return `${j}${y(h)}`;
882
+ const S = n?.collections?.[h]?.fields, x = S ? Object.entries(S) : [], v = x.filter(r), E = x.filter(c);
883
+ if (v.length === 0 && E.length === 0) return `${j}${y(h)}`;
884
+ const R = [...v, ...E].map(([M]) => `"${M}"`).join(" | "), N = new Set($).add(h), I = [
885
+ ...v.map(([M, V]) => {
886
+ const L = V.collection, J = $.has(L) ? k(L) : A(L, N);
887
+ return `${M}: ${V.multiple ? `(${J})[]` : J}`;
888
+ }),
889
+ ...E.map(p)
890
+ ].join("; ");
891
+ return `Omit<${j}, ${R}> & { ${I} }${y(h)}`;
892
+ }, _ = (h, $, j) => {
893
+ const S = !!n?.[h]?.[$], x = `typeof import("${j}").default`, v = S ? W(h, $) : h === "collections" ? d($, j) : x, E = n?.[h]?.[$]?.fields, R = E ? Object.entries(E) : [], N = R.filter(r), I = R.filter(c), M = R.filter(f), V = '"created" | "updated"', L = h === "collections" ? y($) : "", J = M.length ? ` & { ${M.map(u).join("; ")} }` : "";
894
+ if (S)
895
+ return `OknoWrapped<${v}>`;
896
+ if (N.length === 0 && I.length === 0 && M.length === 0)
897
+ return `OknoWrapped<Omit<${v}, ${V}>${L}> & OknoMeta`;
898
+ const K = h === "collections" ? /* @__PURE__ */ new Set([$]) : /* @__PURE__ */ new Set(), H = `${[...N, ...I, ...M].map(([ae]) => `"${ae}"`).join(" | ")} | ${V}`, q = [
899
+ ...N.map(([ae, we]) => {
900
+ const ie = we.collection, Se = K.has(ie) ? k(ie) : A(ie, K);
901
+ return `${ae}: ${we.multiple ? `(${Se})[]` : Se}`;
902
+ }),
903
+ ...I.map(p)
904
+ ].join("; ");
905
+ return `OknoWrapped<${q ? `Omit<${v}, ${H}> & { ${q} }` : `Omit<${v}, ${H}>`}${L}> & OknoMeta${J}`;
906
+ }, [O, T, g] = await Promise.all([
907
+ fe(t, "pages"),
908
+ fe(t, "globals"),
909
+ fe(t, "collections")
910
+ ]);
911
+ a.push(
912
+ ...Ce("okno/pages", "pages", await pe(m(e, "pages")), O, _)
913
+ ), a.push(...io(l, g, _, Object.keys(n?.collections ?? {}))), a.push(
914
+ ...Ce("okno/globals", "globals", await pe(m(e, "globals")), T, _)
915
+ ), a.push(...so(co(e), ao(n))), a.push(...oo()), a.push(...no()), ee(m(e, "modules.d.ts"), a.join(`
916
+ `));
917
+ }
918
+ function to(e, t) {
919
+ const o = [];
920
+ for (const [i, l] of Object.entries(e?.blocks ?? {})) {
921
+ const s = W("blocks", i), n = Object.entries(l.fields ?? {}).filter(([, a]) => a.type !== "divider").flatMap(([a, r]) => [
922
+ ...Ze(qe(a, r, be.test(i) ? i : "block", t, e?.blocks ?? {}), " "),
923
+ ` ${JSON.stringify(a)}: OknoWrapped<${s}>[${JSON.stringify(a)}]`
924
+ ]);
925
+ o.push(` interface ${s}_Wrapped extends OknoValue<${s}> {`, ...n, " }"), /^[A-Za-z_$][\w$]*$/.test(i) && !["default", "BlockTypes"].includes(i) && o.push(` export type { ${s}_Wrapped as ${i} }`);
926
+ }
927
+ o.push(" export interface BlockTypes {");
928
+ for (const i of Object.keys(e?.blocks ?? {}))
929
+ o.push(` ${JSON.stringify(i)}: ${W("blocks", i)}_Wrapped`);
930
+ return o.push(" }"), ['declare module "okno/blocks" {', ...o, "}", ""];
931
+ }
932
+ function Ce(e, t, o, i, l) {
933
+ const s = /* @__PURE__ */ new Set(), n = [];
934
+ U(t, o);
935
+ for (const a of o)
936
+ n.push(` export const ${a}: ${l(t, a, `./${t}/${a}`)}`), s.add(a);
937
+ for (const a of i)
938
+ a === "locale" || s.has(a) || (n.push(` export const ${a}: OknoUnscaffolded`), s.add(a));
939
+ return n.push(` export function locale(__oknoLocaleCode?: OknoLocaleInput): { ${[...s].map((a) => `${JSON.stringify(a)}: typeof ${a}`).join("; ")} }`), [`declare module "${e}" {`, ...n, "}", ""];
940
+ }
941
+ function oo() {
942
+ return [
943
+ 'declare module "okno/locales" {',
944
+ ' /** A configured language. `id` is the BCP-47 tag (e.g. "zh-Hant"), `name` the display label, `slug` the URL segment you map into routing. `link(url)` returns this page\'s hreflang <link> descriptor — spread onto a <link> (pass Astro.url for an absolute href). Okno owns no routing; you map these. */',
945
+ " export interface OknoLocale {",
946
+ " id: string",
947
+ " name: string",
948
+ " slug: string",
949
+ ' link(url: URL | string): { rel: "alternate"; hreflang: string; href: string }',
950
+ " }",
951
+ " /** The configured languages; `locales.default` is the base-locale entry. Empty (`.default` undefined) when no languages are configured. */",
952
+ " export const locales: OknoLocale[] & { default: OknoLocale }",
953
+ "}",
954
+ ""
955
+ ];
956
+ }
957
+ function no() {
958
+ return [
959
+ 'declare module "okno/content" {',
960
+ ' /** Unified content namespace — `import * as okno from "okno/content"` then `okno.pages.home`, `okno.globals.nav`, `okno.collections.articles`, `okno.strings.nav.home`. */',
961
+ ' export * as pages from "okno/pages"',
962
+ ' export * as globals from "okno/globals"',
963
+ ' export * as collections from "okno/collections"',
964
+ ' export { strings } from "okno/strings"',
965
+ "}",
966
+ ""
967
+ ];
968
+ }
969
+ function so(e, t) {
970
+ const o = e.length ? `${ro(e, t)}` : "any", i = e.length ? `
971
+ locale(code?: OknoLocaleInput): ${o}` : "";
972
+ return [
973
+ 'declare module "okno/strings" {',
974
+ " /** The UI-strings store. A plain leaf is string-like (spread `{...s.nav.home}` for the edit hook, render `{s.nav.home}` for the text); a SLOTTED leaf is a `(params) => …` function — call it, then spread/render the result (`{...s.cart.items({count})}`). `.locale(code)` re-roots the whole tree at a language. */",
975
+ ` export const strings: ${e.length ? `${o} & {${i}
976
+ }` : "any"}`,
977
+ "}",
978
+ ""
979
+ ];
980
+ }
981
+ function ro(e, t) {
982
+ const o = { children: /* @__PURE__ */ new Map() };
983
+ for (const s of e) {
984
+ let n = o;
985
+ for (const a of s.split(".")) {
986
+ let r = n.children.get(a);
987
+ r || (r = { children: /* @__PURE__ */ new Map() }, n.children.set(a, r)), n = r;
988
+ }
989
+ }
990
+ const i = (s) => {
991
+ const n = t[s];
992
+ return !n || Object.keys(n).length === 0 ? "OknoValue<string>" : `(p: { ${Object.entries(n).map(([r, c]) => `${JSON.stringify(r)}: ${$e(c)}`).join("; ")} }) => OknoValue<string>`;
993
+ }, l = (s, n) => s.children.size === 0 ? i(n) : `{ ${[...s.children.entries()].map(
994
+ ([r, c]) => `${JSON.stringify(r)}: ${l(c, n ? `${n}.${r}` : r)}`
995
+ ).join("; ")} }`;
996
+ return l(o, "");
997
+ }
998
+ function ao(e) {
999
+ const t = {}, o = e?.strings;
1000
+ if (!o || typeof o != "object" || Array.isArray(o)) return t;
1001
+ for (const [i, l] of Object.entries(o)) {
1002
+ const s = l?.slots;
1003
+ if (!s || typeof s != "object" || Array.isArray(s)) continue;
1004
+ const n = {};
1005
+ for (const [a, r] of Object.entries(s))
1006
+ (r === "text" || r === "number" || r === "count") && (n[a] = r);
1007
+ Object.keys(n).length && (t[i] = n);
1008
+ }
1009
+ return t;
1010
+ }
1011
+ function io(e, t, o, i) {
1012
+ const l = /* @__PURE__ */ new Set(), s = [];
1013
+ U("collections", [...i, ...e.map((a) => a.name)]);
1014
+ const n = new Map(e.map((a) => [a.name, a.first]));
1015
+ for (const a of /* @__PURE__ */ new Set([...i, ...n.keys()])) {
1016
+ const r = o("collections", a, `./collections/${a}/${n.get(a) ?? ""}`), c = a.replace(/-/g, "_");
1017
+ s.push(` export const ${c}: OknoCollection<${r} & OknoDrag>`), l.add(c);
1018
+ }
1019
+ for (const a of t)
1020
+ a === "locale" || l.has(a) || (s.push(` export const ${a}: OknoCollection<OknoUnscaffolded>`), l.add(a));
1021
+ return s.push(` export function locale(__oknoLocaleCode?: OknoLocaleInput): { ${[...l].map((a) => `${JSON.stringify(a)}: typeof ${a}`).join("; ")} }`), ['declare module "okno/collections" {', ...s, "}", ""];
1022
+ }
1023
+ function lo(e) {
1024
+ const t = m(e, "schema.ts");
1025
+ if (!b(t)) return null;
1026
+ try {
1027
+ const o = ne(w(t, "utf8"), t);
1028
+ if (!o || typeof o != "object" || Array.isArray(o)) throw new Error("Schema must export an object");
1029
+ for (const [i, l] of Object.entries(o.collections ?? {})) if (Object.hasOwn(l.fields ?? {}, "draft")) throw new Error(`Collection ${i}: draft is reserved publication metadata`);
1030
+ return o;
1031
+ } catch (o) {
1032
+ throw new Error(`[okno] Invalid schema module ${t}: ${o instanceof Error ? o.message : String(o)}`, { cause: o });
1033
+ }
1034
+ }
1035
+ function co(e) {
1036
+ const t = m(e, "strings.ts");
1037
+ if (!b(t)) return [];
1038
+ try {
1039
+ let o = w(t, "utf8");
1040
+ const i = o.indexOf("export default");
1041
+ if (i === -1) return [];
1042
+ o = o.slice(i + 14).replace(/\bas const\b/g, "").replace(/\bsatisfies\s+[A-Za-z0-9_.]+/g, "").trim(), o.endsWith(";") && (o = o.slice(0, -1).trim());
1043
+ const l = JSON.parse(o);
1044
+ return l && typeof l == "object" && !Array.isArray(l) ? Object.keys(l) : [];
1045
+ } catch {
1046
+ return [];
1047
+ }
1048
+ }
1049
+ async function uo(e) {
1050
+ const t = m(e, "collections");
1051
+ if (!b(t)) return [];
1052
+ const o = (await P(t, { withFileTypes: !0 })).filter((l) => l.isDirectory()), i = [];
1053
+ for (const l of o) {
1054
+ const s = await pe(m(t, l.name));
1055
+ s.length > 0 && i.push({ name: l.name, first: s[0] });
1056
+ }
1057
+ return i;
1058
+ }
1059
+ async function pe(e) {
1060
+ return b(e) ? (await P(e)).filter((o) => o.endsWith(".ts") && o !== "index.ts" && o !== "modules.d.ts").map((o) => o.replace(".ts", "")) : [];
1061
+ }
1062
+ function Oe(e) {
1063
+ try {
1064
+ return Tt(e, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
1065
+ } catch {
1066
+ return null;
1067
+ }
1068
+ }
1069
+ function fo() {
1070
+ const e = Oe("git rev-parse --abbrev-ref HEAD");
1071
+ if (e && e !== "HEAD") return e;
1072
+ const t = process.env;
1073
+ return t.CF_PAGES_BRANCH || // Cloudflare Pages
1074
+ t.VERCEL_GIT_COMMIT_REF || // Vercel
1075
+ t.BRANCH || // Netlify
1076
+ t.GITHUB_REF_NAME || // GitHub Actions
1077
+ "main";
1078
+ }
1079
+ function po(e) {
1080
+ try {
1081
+ const t = JSON.parse(w(m(process.cwd(), e, "project.json"), "utf-8"));
1082
+ return typeof t?.repoId == "number" ? t.repoId : null;
1083
+ } catch {
1084
+ return null;
1085
+ }
1086
+ }
1087
+ function Uo(e = "okno") {
1088
+ const t = Oe("git remote get-url origin");
1089
+ if (!t) return null;
1090
+ const o = t.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
1091
+ if (!o) return null;
1092
+ const i = po(e);
1093
+ return `${o[1]}/${o[2]}${i ? `#${i}` : ""}@${fo()}`;
1094
+ }
1095
+ function Jo() {
1096
+ const e = Oe("git rev-parse --show-toplevel");
1097
+ return e ? Qe(e, process.cwd()).split(Re).join("/") : "";
1098
+ }
1099
+ function Xe(e) {
1100
+ try {
1101
+ const t = w(m(e, ".revision"), "utf-8").trim();
1102
+ if (!/^\d+$/.test(t)) return 0;
1103
+ const o = Number(t);
1104
+ return Number.isSafeInteger(o) ? o : 0;
1105
+ } catch {
1106
+ return 0;
1107
+ }
1108
+ }
1109
+ function zo(e) {
1110
+ return b(e) ? `${JSON.stringify({ revision: Xe(e) })}
1111
+ ` : null;
1112
+ }
1113
+ const Ye = () => process.env.OKNO_KEYS_FILE || m(Ft(), ".okno", "disks.json");
1114
+ function Pe() {
1115
+ const e = Ye();
1116
+ if (!b(e)) return {};
1117
+ try {
1118
+ const t = JSON.parse(w(e, "utf8"));
1119
+ return t && typeof t == "object" && !Array.isArray(t) ? t : {};
1120
+ } catch {
1121
+ return {};
1122
+ }
1123
+ }
1124
+ function mo(e) {
1125
+ const t = (o) => `${ut(e)}#${o}`;
1126
+ return {
1127
+ async get(o) {
1128
+ const i = o.toUpperCase().replace(/-/g, "_"), l = process.env[`OKNO_DISK_${i}_ACCESS_KEY`], s = process.env[`OKNO_DISK_${i}_SECRET`];
1129
+ if (l && s) return { accessKeyId: l, secretAccessKey: s };
1130
+ const n = Pe()[t(o)];
1131
+ return n && typeof n.accessKeyId == "string" && typeof n.secretAccessKey == "string" ? n : null;
1132
+ },
1133
+ async set(o, i) {
1134
+ et(Ye(), JSON.stringify({ ...Pe(), [t(o)]: i }, null, 2) + `
1135
+ `);
1136
+ }
1137
+ };
1138
+ }
1139
+ const ho = `import type { Schema } from "okno"
1140
+
1141
+ export default {
1142
+ pages: {},
1143
+ collections: {},
1144
+ globals: {},
1145
+ blocks: {},
1146
+ } satisfies Schema
1147
+ `;
1148
+ class C extends Error {
1149
+ constructor(t, o, i, l) {
1150
+ super(t), this.code = o, this.status = i, this.retryable = l;
1151
+ }
1152
+ code;
1153
+ status;
1154
+ retryable;
1155
+ }
1156
+ function me(e) {
1157
+ let t;
1158
+ try {
1159
+ t = w(m(e, "schema.ts"), "utf8");
1160
+ } catch (o) {
1161
+ if (o.code === "ENOENT")
1162
+ return { hasInstallation: !0, initialized: !1, installUrl: null, missing: ["schema.ts"] };
1163
+ throw new C("Couldn't read okno/schema.ts. Check the file permissions and try again.", "schema_read_failed", 500, !0);
1164
+ }
1165
+ try {
1166
+ const o = t.match(/export\s+default\s+([\s\S]+)/)?.[1];
1167
+ if (!o) throw new Error("Missing export default");
1168
+ const i = o.trim().replace(/;$/, "").replace(/\s+satisfies\s+\w+\s*$/, "").replace(/\s+as\s+\w+\s*$/, ""), l = dt(`(${i})`, 0, { ecmaVersion: "latest" });
1169
+ if (l.type !== "ObjectExpression") throw new Error("Schema must be an object");
1170
+ const s = F(t);
1171
+ if (l.properties.length && !Object.keys(s).length) throw new Error("Schema must contain literal data");
1172
+ for (const n of ["pages", "collections", "globals", "blocks", "strings", "locales", "layout"]) {
1173
+ const a = s[n];
1174
+ if (a !== void 0 && (a === null || typeof a != "object" || Array.isArray(a))) throw new Error(`Invalid ${n}`);
1175
+ }
1176
+ } catch {
1177
+ throw new C("Couldn't read the schema. Fix okno/schema.ts before continuing.", "invalid_schema", 422, !1);
1178
+ }
1179
+ return { hasInstallation: !0, initialized: !0, installUrl: null };
1180
+ }
1181
+ function go(e, t) {
1182
+ if (t !== void 0) {
1183
+ if (typeof t != "string" || !t.trim()) throw new C("A verified project identity is required", "project_identity_required", 400, !1);
1184
+ const l = m(e, "project.json");
1185
+ let s = {};
1186
+ try {
1187
+ const n = JSON.parse(w(l, "utf8"));
1188
+ if (!n || typeof n != "object" || Array.isArray(n)) throw new Error("Invalid project config");
1189
+ s = n;
1190
+ } catch (n) {
1191
+ if (n.code !== "ENOENT") throw new C("Fix okno/project.json before continuing", "invalid_project_config", 409, !1);
1192
+ }
1193
+ if (s.projectId !== void 0 && (typeof s.projectId != "string" || !s.projectId.trim())) throw new C("Fix the project identity in okno/project.json before continuing", "invalid_project_config", 409, !1);
1194
+ if (s.projectId && s.projectId !== t) throw new C("This checkout belongs to another Okno project. Reconnect the matching repository before continuing.", "project_identity_mismatch", 409, !1);
1195
+ }
1196
+ const o = me(e);
1197
+ if (o.initialized) return { ...o, ok: !0, alreadyInitialized: !0 };
1198
+ const i = m(e, "schema.ts");
1199
+ try {
1200
+ We(e, { recursive: !0 }), ee(i, ho, { exclusive: !0 });
1201
+ } catch (l) {
1202
+ if (l.code !== "EEXIST")
1203
+ throw new C("Couldn't create okno/schema.ts. Check the folder permissions and try again.", "schema_write_failed", 500, !0);
1204
+ }
1205
+ return { ...me(e), ok: !0, alreadyInitialized: !1 };
1206
+ }
1207
+ async function yo(e, t) {
1208
+ const o = m(e, "project.json");
1209
+ let i = null;
1210
+ try {
1211
+ const l = Q({ baseDir: e, timeout: { block: 1e4 } }), s = `${(await l.revparse(["--show-prefix"])).trim()}project.json`;
1212
+ if ((await l.raw(["ls-files", "--", "project.json"])).trim()) return "skipped";
1213
+ try {
1214
+ i = w(o, "utf8");
1215
+ } catch (n) {
1216
+ if (n.code !== "ENOENT") throw n;
1217
+ }
1218
+ if (i !== null) {
1219
+ const { projectId: n, repoId: a, ...r } = JSON.parse(i);
1220
+ if (n !== t || Object.keys(r).length) return "skipped";
1221
+ }
1222
+ return await l.fetch(), await l.show([`@{u}:${s}`]), i !== null && tt(o), await l.pull(void 0, void 0, ["--ff-only"]), "pulled";
1223
+ } catch {
1224
+ if (i !== null)
1225
+ try {
1226
+ w(o);
1227
+ } catch {
1228
+ ot(o, i);
1229
+ }
1230
+ return "skipped";
1231
+ }
1232
+ }
1233
+ function ko(e) {
1234
+ if (e.method === "GET" || e.method === "HEAD" || !e.header) return !1;
1235
+ if (e.header("sec-fetch-site") === "cross-site") return !0;
1236
+ const t = e.header("origin");
1237
+ if (!t) return !1;
1238
+ let o;
1239
+ try {
1240
+ o = new URL(t).host;
1241
+ } catch {
1242
+ return !0;
1243
+ }
1244
+ return ![e.header("host"), ...(e.header("x-forwarded-host") ?? "").split(",")].map((l) => l?.trim()).filter(Boolean).includes(o);
1245
+ }
1246
+ async function Ko(e, t) {
1247
+ const { method: o, route: i } = t;
1248
+ if (ko(t)) return { status: 403, body: { error: "Cross-site requests can't change local content" } };
1249
+ const l = { files: [], modules: [] }, s = (r, c) => {
1250
+ const f = r.split("/")[0];
1251
+ f !== "pages" && f !== "collections" && f !== "globals" || (l.modules.push(f), l.files.push(c));
1252
+ }, n = () => l.modules.push("pages", "collections", "globals"), a = (r, c) => ({ status: r, body: c, invalidation: l });
1253
+ try {
1254
+ if (o === "POST" && (i.startsWith("schema/") || ["setup/init", "setup/scaffold-page", "strings/set-schema", "collections/set-order", "collections/set-drafts"].includes(i)) && !ve(e, "schema.ts")) return a(400, { error: "Symlink schema paths are not supported" });
1255
+ if (o === "GET" && i === "setup/status") return a(200, me(e));
1256
+ if (o === "GET" && i === "setup/permissions")
1257
+ try {
1258
+ return a(200, { permissions: w(m(e, "permissions.ts"), "utf8") });
1259
+ } catch (r) {
1260
+ if (r.code === "ENOENT") return a(200, { permissions: null });
1261
+ throw new C("Couldn’t read okno/permissions.ts. Check the file permissions and try again.", "permissions_read_failed", 500, !0);
1262
+ }
1263
+ if (o === "POST" && i === "setup/init") {
1264
+ const r = await t.json(), c = go(e, r?.projectId);
1265
+ return l.files.push(m(e, "schema.ts")), n(), a(200, r?.projectId ? { ...c, checkout: await yo(e, r.projectId) } : c);
1266
+ }
1267
+ if (o === "GET" && i === "content") return a(200, nt(e));
1268
+ if (o === "GET" && i === "content/index") return a(200, st(e));
1269
+ if (o === "POST" && i === "content/read") return a(200, { content: rt(e, (await t.json())?.paths) });
1270
+ if (o === "POST" && kt(i)) {
1271
+ const r = await t.json(), c = typeof r?.author == "string" && r.author ? r.author : at(e), f = await _t($t[i], r, le(e), { author: c, now: (/* @__PURE__ */ new Date()).toISOString() });
1272
+ for (const u of f.changed)
1273
+ u === "schema.ts" ? n() : u === "strings.ts" || u.startsWith("strings/") ? (l.modules.push("strings", "content"), l.files.push(m(e, u))) : s(u, m(e, u));
1274
+ return a(f.status, f.body);
1275
+ }
1276
+ if (o === "GET" && i === "publish-state")
1277
+ try {
1278
+ const r = Q(ce(e)), c = await r.status(), f = je(e), u = (y) => y.startsWith(f + "/"), p = c.files.map((y) => y.path).filter(u);
1279
+ let d = [];
1280
+ if (c.ahead > 0)
1281
+ try {
1282
+ d = (await r.raw(["diff", "--name-only", "@{u}...HEAD", "--", f])).split(`
1283
+ `).map((A) => A.trim()).filter(Boolean);
1284
+ } catch {
1285
+ }
1286
+ const k = Array.from(/* @__PURE__ */ new Set([...p, ...d]));
1287
+ return a(200, { pendingPublish: p.length > 0 || c.ahead > 0, changed: k });
1288
+ } catch {
1289
+ return a(200, { pendingPublish: !1 });
1290
+ }
1291
+ if (o === "POST" && i === "publish") {
1292
+ const r = Q(ce(e)), c = je(e), f = await r.status();
1293
+ let u = Xe(e);
1294
+ f.files.some((_) => _.path.startsWith(c + "/")) && (u += 1, ee(m(e, ".revision"), `${u}
1295
+ `)), await r.raw(["add", "-A", "--", c]);
1296
+ const p = await r.status(), d = p.staged.length > 0;
1297
+ let k = !1;
1298
+ d && (await r.commit("okno: publish content"), k = !0);
1299
+ let y = !1, A = null;
1300
+ try {
1301
+ if (k || p.ahead > 0) {
1302
+ try {
1303
+ await r.fetch();
1304
+ } catch {
1305
+ }
1306
+ if ((await r.status()).behind > 0)
1307
+ try {
1308
+ if (await r.raw(["pull", "--no-rebase", "--no-edit"]), (await r.status()).conflicted.length) throw new Error("conflict");
1309
+ } catch {
1310
+ throw await r.raw(["merge", "--abort"]).catch(() => {
1311
+ }), new Error("Couldn't merge remote changes. Pull and resolve them in Git, then publish again.");
1312
+ }
1313
+ await r.push(), y = !0;
1314
+ }
1315
+ } catch (_) {
1316
+ A = _ instanceof Error ? _.message.split(`
1317
+ `)[0] : String(_);
1318
+ }
1319
+ return A ? a(502, { error: `Git push failed: ${A}`, committed: k, revision: u }) : a(200, { ok: !0, alreadyUpToDate: !k && p.ahead === 0, committed: k, pushed: y, pushError: A, revision: u });
1320
+ }
1321
+ if (o === "GET" && i === "files") {
1322
+ const r = m(e, "files", ".okno-tree.json");
1323
+ return a(200, {
1324
+ files: it(e),
1325
+ manifest: b(r) ? w(r, "utf-8") : null
1326
+ });
1327
+ }
1328
+ if (o === "POST" && i === "files/blob") {
1329
+ const r = (d) => {
1330
+ try {
1331
+ return decodeURIComponent(d ?? "");
1332
+ } catch {
1333
+ return d ?? "";
1334
+ }
1335
+ }, c = bt(r(t.header("x-okno-filename")), r(t.header("x-okno-dir"))), f = lt(e, c);
1336
+ if (!f) return a(400, { error: "Invalid path" });
1337
+ const u = await Ot(await le(e).open(), c);
1338
+ if (u) return a(409, { error: u });
1339
+ const p = await t.binary();
1340
+ return p.length === 0 ? a(400, { error: "Empty body" }) : p.length > 25 * 1024 * 1024 ? a(413, { error: "Uploads are capped at 25 MB" }) : (We(Ve(f), { recursive: !0 }), ee(f, p), a(200, { ok: !0, persisted: !0, blobSha: "", path: c, filename: c.split("/").pop() }));
1341
+ }
1342
+ if (o === "POST" && i === "files/commit") return a(200, { ok: !0 });
1343
+ if (o === "POST" && (i === "files/disk-connect" || i === "files/disk-status" || i === "files/presign")) {
1344
+ const r = mo(e), c = { fetch, subtle: crypto.subtle, now: () => /* @__PURE__ */ new Date(), random: () => crypto.randomUUID().replace(/-/g, "") }, f = await t.json(), u = i === "files/disk-connect" ? await Et(f, r, c, t.header("origin") ?? null) : i === "files/disk-status" ? await It(f, r) : await Nt(f, r, c, await le(e).open());
1345
+ return a(u.status, u.body);
1346
+ }
1347
+ if (o === "POST" && i === "history") {
1348
+ const r = (await t.json())?.path;
1349
+ if (!wt(r)) return a(400, { error: "Invalid path" });
1350
+ const c = ve(e, r);
1351
+ if (!c) return a(400, { error: "Invalid path" });
1352
+ const f = Q(ce(e)), [u, p] = await Promise.all([f.log({ file: c, maxCount: 30 }), f.status(["--", c])]);
1353
+ return a(200, {
1354
+ pending: p.files.length > 0,
1355
+ commits: u.all.map((d) => ({ sha: d.hash, date: d.date, author: d.author_name, message: [d.message, d.body].filter(Boolean).join(`
1356
+ `) }))
1357
+ });
1358
+ }
1359
+ return null;
1360
+ } catch (r) {
1361
+ return r instanceof C ? { status: r.status, body: { error: r.message, step: i === "setup/init" ? "init" : i === "setup/permissions" ? "permissions" : "status", code: r.code, retryable: r.retryable, status: r.status } } : r instanceof St ? { status: r.status, body: { error: r.message, ...r.code ? { code: r.code } : {} } } : { status: 500, body: { error: r instanceof Error ? r.message : String(r) } };
1362
+ }
1363
+ }
1364
+ export {
1365
+ Ro as a,
1366
+ Po as b,
1367
+ ko as c,
1368
+ Ko as d,
1369
+ Vo as e,
1370
+ No as f,
1371
+ Fo as g,
1372
+ Lo as h,
1373
+ Co as i,
1374
+ Mo as j,
1375
+ zo as k,
1376
+ Wo as l,
1377
+ Jo as m,
1378
+ Uo as n,
1379
+ Vt as o,
1380
+ Be as r,
1381
+ fe as s
1382
+ };