okno 1.0.0-beta.20 → 1.0.0-beta.21

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.
@@ -1,75 +1,75 @@
1
- import { extname as Y, join as h, dirname as P, relative as N, sep as G, resolve as g } from "node:path";
2
- import { existsSync as O, readFileSync as U, mkdirSync as R, writeFileSync as T, cpSync as Q } from "node:fs";
3
- import { execSync as K } from "node:child_process";
4
- import { fileURLToPath as Z } from "node:url";
5
- import { i as x, g as q, s as v, b as tt, a as et, c as ot, e as nt, d as rt, f as it, h as M, j as $, k as st } from "./dispatch-DKZB5I61.js";
6
- import { simpleGit as H } from "simple-git";
1
+ import { extname as z, join as h, dirname as T, relative as N, sep as D, resolve as g } from "node:path";
2
+ import { existsSync as O, readFileSync as U, mkdirSync as M, writeFileSync as B, cpSync as Y } from "node:fs";
3
+ import { fileURLToPath as Q } from "node:url";
4
+ import { k as Z, g as x, s as E, b as q, a as tt, c as et, e as ot, d as nt, f as it, j as P, l as $, m as rt, h as st, i as at } from "./dispatch-CmTJLIKc.js";
5
+ import { simpleGit as R } from "simple-git";
6
+ import "node:child_process";
7
7
  import "./acorn-CZBJD705.js";
8
- function F(n, i, e) {
9
- n.statusCode = i, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
8
+ function F(n, r, e) {
9
+ n.statusCode = r, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
10
10
  }
11
- function at(n) {
12
- return new Promise((i) => {
11
+ function lt(n) {
12
+ return new Promise((r) => {
13
13
  let e = "";
14
14
  n.on("data", (t) => e += t), n.on("end", () => {
15
15
  try {
16
- i(e ? JSON.parse(e) : {});
16
+ r(e ? JSON.parse(e) : {});
17
17
  } catch {
18
- i({});
18
+ r({});
19
19
  }
20
- }), n.on("error", () => i({}));
20
+ }), n.on("error", () => r({}));
21
21
  });
22
22
  }
23
- function lt(n) {
24
- return new Promise((i, e) => {
23
+ function ct(n) {
24
+ return new Promise((r, e) => {
25
25
  const t = [];
26
- n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
26
+ n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
27
27
  });
28
28
  }
29
- function ct(n, i) {
30
- if (i) {
31
- for (const e of new Set(i.modules)) {
29
+ function ut(n, r) {
30
+ if (r) {
31
+ for (const e of new Set(r.modules)) {
32
32
  const t = n.moduleGraph.getModuleById("\0okno:" + e);
33
33
  t && n.moduleGraph.invalidateModule(t);
34
34
  }
35
- for (const e of new Set(i.files))
35
+ for (const e of new Set(r.files))
36
36
  n.moduleGraph.getModulesByFile(e)?.forEach((t) => n.moduleGraph.invalidateModule(t));
37
37
  }
38
38
  }
39
- function ut(n, i) {
39
+ function dt(n, r) {
40
40
  n.middlewares.use(async (e, t, c) => {
41
41
  if (!e.url?.startsWith("/__okno/api/")) return c();
42
42
  const y = e.url.slice(12).split("?")[0], o = {
43
43
  method: e.method || "GET",
44
44
  route: y,
45
- json: () => at(e),
46
- binary: () => lt(e),
47
- header: (r) => {
48
- const s = e.headers[r];
45
+ json: () => lt(e),
46
+ binary: () => ct(e),
47
+ header: (i) => {
48
+ const s = e.headers[i];
49
49
  return Array.isArray(s) ? s[0] : s;
50
50
  }
51
51
  };
52
52
  try {
53
- const r = await x(i, o);
54
- if (!r) return c();
55
- ct(n, r.invalidation), F(t, r.status, r.body);
56
- } catch (r) {
57
- F(t, 500, { error: r instanceof Error ? r.message : String(r) });
53
+ const i = await Z(r, o);
54
+ if (!i) return c();
55
+ ut(n, i.invalidation), F(t, i.status, i.body);
56
+ } catch (i) {
57
+ F(t, 500, { error: i instanceof Error ? i.message : String(i) });
58
58
  }
59
59
  });
60
60
  }
61
- function dt(n, i) {
61
+ function ft(n, r) {
62
62
  let e;
63
63
  try {
64
- e = decodeURIComponent(i);
64
+ e = decodeURIComponent(r);
65
65
  } catch {
66
66
  return null;
67
67
  }
68
68
  if (!e || e.includes("\0")) return null;
69
69
  const t = g(n, "files"), c = g(t, e);
70
- return c === t || !c.startsWith(t + G) ? null : c;
70
+ return c === t || !c.startsWith(t + D) ? null : c;
71
71
  }
72
- const B = "okno", ft = {
72
+ const H = "okno", pt = {
73
73
  ".webp": "image/webp",
74
74
  ".png": "image/png",
75
75
  ".jpg": "image/jpeg",
@@ -90,18 +90,18 @@ const B = "okno", ft = {
90
90
  ".ttf": "font/ttf",
91
91
  ".otf": "font/otf"
92
92
  };
93
- function pt(n, i) {
94
- ut(n, i), n.middlewares.use((e, t, c) => {
93
+ function gt(n, r) {
94
+ dt(n, r), n.middlewares.use((e, t, c) => {
95
95
  if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return c();
96
96
  const y = e.url.slice(12).split("?")[0];
97
97
  if (!y) return c();
98
- const o = dt(i, y);
98
+ const o = ft(r, y);
99
99
  if (!o)
100
100
  return t.statusCode = 403, t.end("Forbidden");
101
101
  if (!O(o))
102
102
  return t.statusCode = 404, t.end("Not found");
103
- const r = Y(o).toLowerCase();
104
- t.setHeader("Content-Type", ft[r] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
103
+ const i = z(o).toLowerCase();
104
+ t.setHeader("Content-Type", pt[i] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
105
105
  }), n.middlewares.use(async (e, t, c) => {
106
106
  if (!e.url?.startsWith("/__okno/")) return c();
107
107
  const y = e.url.slice(8);
@@ -110,51 +110,51 @@ function pt(n, i) {
110
110
  if (e.method === "GET" && y === "repo") {
111
111
  t.setHeader("Content-Type", "application/json");
112
112
  try {
113
- const o = H(n.config.root), r = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: f, repo: a } = gt(r);
113
+ const o = R(n.config.root), i = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: f, repo: a } = mt(i);
114
114
  return t.end(
115
- JSON.stringify({ ok: !0, owner: f, repo: a, branch: s || null, remote: r || null })
115
+ JSON.stringify({ ok: !0, owner: f, repo: a, branch: s || null, remote: i || null })
116
116
  );
117
117
  } catch (o) {
118
118
  return t.end(JSON.stringify({ ok: !1, error: String(o) }));
119
119
  }
120
120
  }
121
121
  if (e.method === "POST" && y.startsWith("mirror")) {
122
- const r = new URL(e.url, "http://localhost").searchParams.get("path");
123
- if (!r || r.includes("..") || !r.startsWith("files/"))
122
+ const i = new URL(e.url, "http://localhost").searchParams.get("path");
123
+ if (!i || i.includes("..") || !i.startsWith("files/"))
124
124
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
125
- const s = h(i, r);
125
+ const s = h(r, i);
126
126
  if (O(s))
127
127
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
128
- const f = await mt(e);
129
- return R(P(s), { recursive: !0 }), T(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: r, bytes: f.length }));
128
+ const f = await ht(e);
129
+ return M(T(s), { recursive: !0 }), B(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: i, bytes: f.length }));
130
130
  }
131
131
  if (e.method === "POST" && y === "sync") {
132
- const r = (await ht(e))?.path;
133
- if (r) {
134
- if (r.includes("..") || r.includes("\0"))
132
+ const i = (await yt(e))?.path;
133
+ if (i) {
134
+ if (i.includes("..") || i.includes("\0"))
135
135
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
136
- const u = h(i, r);
136
+ const u = h(r, i);
137
137
  try {
138
- const l = H(i);
139
- await l.fetch("origin", B);
140
- const m = (await l.revparse(["--show-toplevel"])).trim(), p = N(m, u).split(G).join("/"), w = await l.show([`origin/${B}:${p}`]);
141
- R(P(u), { recursive: !0 }), T(u, w);
138
+ const l = R(r);
139
+ await l.fetch("origin", H);
140
+ const m = (await l.revparse(["--show-toplevel"])).trim(), p = N(m, u).split(D).join("/"), w = await l.show([`origin/${H}:${p}`]);
141
+ M(T(u), { recursive: !0 }), B(u, w);
142
142
  } catch (l) {
143
143
  const m = l instanceof Error ? l.message : String(l);
144
144
  console.warn(
145
- `[okno] sync: could not materialize ${r} from origin/${B} — ${m.split(`
145
+ `[okno] sync: could not materialize ${i} from origin/${H} — ${m.split(`
146
146
  `)[0]}`
147
147
  );
148
148
  }
149
- return D(n, r, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: r }));
149
+ return A(n, i, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: i }));
150
150
  }
151
- const s = H(i), f = await s.revparse(["--show-toplevel"]), a = N(f.trim(), i);
151
+ const s = R(r), f = await s.revparse(["--show-toplevel"]), a = N(f.trim(), r);
152
152
  try {
153
153
  const u = await s.pull();
154
154
  for (const l of u.files)
155
155
  if (l.startsWith(`${a}/`)) {
156
- const m = l.slice(`${a}/`.length), p = h(i, m);
157
- D(n, m, p);
156
+ const m = l.slice(`${a}/`.length), p = h(r, m);
157
+ A(n, m, p);
158
158
  }
159
159
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: u.files }));
160
160
  } catch (u) {
@@ -169,55 +169,55 @@ function pt(n, i) {
169
169
  }
170
170
  });
171
171
  }
172
- function gt(n) {
172
+ function mt(n) {
173
173
  if (!n) return { owner: null, repo: null };
174
- const i = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
175
- return i ? { owner: i[1], repo: i[2] } : { owner: null, repo: null };
174
+ const r = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
175
+ return r ? { owner: r[1], repo: r[2] } : { owner: null, repo: null };
176
176
  }
177
- function mt(n) {
178
- return new Promise((i, e) => {
177
+ function ht(n) {
178
+ return new Promise((r, e) => {
179
179
  const t = [];
180
- n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
180
+ n.on("data", (c) => t.push(c)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
181
181
  });
182
182
  }
183
- function ht(n) {
184
- return new Promise((i) => {
183
+ function yt(n) {
184
+ return new Promise((r) => {
185
185
  let e = "";
186
186
  n.on("data", (t) => {
187
187
  e += t;
188
188
  }), n.on("end", () => {
189
189
  try {
190
- i(e ? JSON.parse(e) : null);
190
+ r(e ? JSON.parse(e) : null);
191
191
  } catch {
192
- i(null);
192
+ r(null);
193
193
  }
194
- }), n.on("error", () => i(null));
194
+ }), n.on("error", () => r(null));
195
195
  });
196
196
  }
197
- function D(n, i, e) {
197
+ function A(n, r, e) {
198
198
  const t = "\0okno:";
199
199
  let c;
200
- if (i.startsWith("pages/") ? c = t + "pages" : i.startsWith("collections/") ? c = t + "collections" : i.startsWith("globals/") && (c = t + "globals"), c) {
200
+ if (r.startsWith("pages/") ? c = t + "pages" : r.startsWith("collections/") ? c = t + "collections" : r.startsWith("globals/") && (c = t + "globals"), c) {
201
201
  const y = n.moduleGraph.getModuleById(c);
202
202
  y && n.moduleGraph.invalidateModule(y);
203
203
  const o = n.moduleGraph.getModulesByFile(e);
204
- o && o.forEach((r) => {
205
- n.moduleGraph.invalidateModule(r);
204
+ o && o.forEach((i) => {
205
+ n.moduleGraph.invalidateModule(i);
206
206
  });
207
207
  }
208
208
  }
209
- function yt(n, i) {
210
- const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = i.replace(/\\/g, "/");
209
+ function wt(n, r) {
210
+ const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = r.replace(/\\/g, "/");
211
211
  return e === t || e.startsWith(t + "/");
212
212
  }
213
- function wt(n, i) {
214
- for (const [e, t] of Object.entries(i)) {
213
+ function bt(n, r) {
214
+ for (const [e, t] of Object.entries(r)) {
215
215
  if (n === e) return t;
216
216
  if (n.startsWith(e + "/")) return t + n.slice(e.length);
217
217
  }
218
218
  return null;
219
219
  }
220
- const bt = "okno:", S = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), V = P(Z(import.meta.url)), St = JSON.parse(U(g(V, "../package.json"), "utf-8")).version, L = q(), b = g(V, "../editor"), I = g(b, "index.ts"), Ot = O(I), kt = {
220
+ const St = "okno:", _ = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), K = T(Q(import.meta.url)), Ot = JSON.parse(U(g(K, "../package.json"), "utf-8")).version, L = x(), b = g(K, "../editor"), I = g(b, "index.ts"), kt = O(I), vt = {
221
221
  "@modules": g(b, "modules"),
222
222
  "@lib": g(b, "lib"),
223
223
  "@logger": g(b, "lib/logger.svelte.ts"),
@@ -229,51 +229,18 @@ const bt = "okno:", S = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "colle
229
229
  "@pages": g(b, "pages"),
230
230
  "@controllers": g(b, "controllers")
231
231
  };
232
- function Et() {
233
- try {
234
- const n = (t) => K(t, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim(), e = n("git remote get-url origin").match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
235
- return e ? `${e[1]}/${e[2]}@${vt(n)}` : null;
236
- } catch {
237
- return null;
238
- }
239
- }
240
- function vt(n) {
241
- let i = "";
242
- try {
243
- i = n("git rev-parse --abbrev-ref HEAD");
244
- } catch {
245
- }
246
- if (i && i !== "HEAD") return i;
247
- const e = process.env;
248
- return e.CF_PAGES_BRANCH || // Cloudflare Pages
249
- e.VERCEL_GIT_COMMIT_REF || // Vercel
250
- e.BRANCH || // Netlify
251
- e.GITHUB_REF_NAME || // GitHub Actions
252
- "main";
253
- }
254
- function Nt() {
255
- try {
256
- const n = K("git rev-parse --show-toplevel", {
257
- encoding: "utf-8",
258
- stdio: ["ignore", "pipe", "ignore"]
259
- }).trim();
260
- return N(n, process.cwd()).split(G).join("/");
261
- } catch {
262
- return "";
263
- }
264
- }
265
- function It(n = {}) {
266
- const i = n.dir ?? "okno";
232
+ function Tt(n = {}) {
233
+ const r = n.dir ?? "okno";
267
234
  let e, t, c = !1, y = !1;
268
235
  return n.isEditor, {
269
236
  name: "okno",
270
237
  enforce: "pre",
271
- config(o, r) {
272
- const s = r.command === "serve";
273
- return y = r.command === "build", c = s && Ot, {
238
+ config(o, i) {
239
+ const s = i.command === "serve";
240
+ return y = i.command === "build", c = s && kt, {
274
241
  define: {
275
242
  __OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
276
- __OKNO_VERSION__: JSON.stringify(St),
243
+ __OKNO_VERSION__: JSON.stringify(Ot),
277
244
  // True when the consumer is running `vite dev` / `astro dev` /
278
245
  // `sveltekit dev` — anything that serves locally. Replaced at
279
246
  // consumer build time so the prebuilt editor bundle can honor
@@ -287,12 +254,12 @@ function It(n = {}) {
287
254
  // auto-targets its repo with no picker. null outside a git
288
255
  // checkout → editor falls back to the picker. Dev ignores it
289
256
  // (runtime /__okno/repo derivation is more current).
290
- __OKNO_REPO__: JSON.stringify(Et()),
257
+ __OKNO_REPO__: JSON.stringify(at()),
291
258
  // Monorepo root path: the build dir relative to the git root (e.g.
292
259
  // "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
293
260
  // hosted backend reads/writes content under `<root>/okno` instead of
294
261
  // the repo-root `okno` — one repo, many okno projects keyed (repo, path).
295
- __OKNO_ROOT__: JSON.stringify(Nt())
262
+ __OKNO_ROOT__: JSON.stringify(st())
296
263
  },
297
264
  // Source mode (monorepo dev only): skip prebundling so saves to
298
265
  // `package/editor/**` propagate via HMR instead of needing
@@ -314,7 +281,7 @@ function It(n = {}) {
314
281
  // the backend mirrored saves to disk, causing spurious full
315
282
  // reloads. In production-mode the backend never touches local
316
283
  // FS so blocking those is pure harm — pulls go unseen.)
317
- ignored: [`**/${i}/files/**`, `**/${i}/.okno-tree.json`]
284
+ ignored: [`**/${r}/files/**`, `**/${r}/.okno-tree.json`]
318
285
  },
319
286
  // Source mode: the editor loads via a dynamic `import("okno/editor")`
320
287
  // from a separate package over `@fs`, so Vite's startup dep scan
@@ -330,15 +297,15 @@ function It(n = {}) {
330
297
  };
331
298
  },
332
299
  configResolved(o) {
333
- e = o.root, t = g(e, i);
300
+ e = o.root, t = g(e, r);
334
301
  },
335
302
  async buildStart() {
336
303
  if (O(t)) {
337
- if (await M(t, e), y) {
304
+ if (await P(t, e), y) {
338
305
  const o = h(t, "files");
339
306
  if (O(o)) {
340
- const r = O(h(e, "static")) ? h(e, "static") : h(e, "public"), s = h(r, "okno", "files");
341
- g(s) !== g(o) && (R(s, { recursive: !0 }), Q(o, s, {
307
+ const i = O(h(e, "static")) ? h(e, "static") : h(e, "public"), s = h(i, "okno", "files");
308
+ g(s) !== g(o) && (M(s, { recursive: !0 }), Y(o, s, {
342
309
  recursive: !0,
343
310
  filter: (f) => !f.endsWith(".okno-tree.json")
344
311
  }));
@@ -346,30 +313,30 @@ function It(n = {}) {
346
313
  }
347
314
  if (n.demo) {
348
315
  const o = h(e, "public");
349
- O(o) || R(o, { recursive: !0 }), T(
316
+ O(o) || M(o, { recursive: !0 }), B(
350
317
  h(o, "okno-demo.json"),
351
- JSON.stringify(st(t))
318
+ JSON.stringify(rt(t))
352
319
  );
353
320
  }
354
321
  }
355
322
  },
356
323
  configureServer(o) {
357
- pt(o, t);
358
- const r = (f) => {
324
+ gt(o, t);
325
+ const i = (f) => {
359
326
  const a = N(t, f);
360
327
  if (a.startsWith("..") || !a.endsWith(".ts")) return;
361
328
  const u = a.split(/[\\/]/)[0];
362
329
  if (u !== "pages" && u !== "collections" && u !== "globals") return;
363
- const l = o.moduleGraph.getModuleById(S + u);
330
+ const l = o.moduleGraph.getModuleById(_ + u);
364
331
  l && o.moduleGraph.invalidateModule(l), o.moduleGraph.getModulesByFile(f)?.forEach((m) => o.moduleGraph.invalidateModule(m)), !$(f) && o.ws.send({ type: "full-reload" });
365
332
  };
366
- o.watcher.on("add", r), o.watcher.on("unlink", r), o.middlewares.use("/__okno/imports", async (f, a, u) => {
333
+ o.watcher.on("add", i), o.watcher.on("unlink", i), o.middlewares.use("/__okno/imports", async (f, a, u) => {
367
334
  if (f.method !== "GET") return u();
368
335
  try {
369
336
  const [l, m, p] = await Promise.all([
370
- v(e, "pages"),
371
- v(e, "globals"),
372
- v(e, "collections")
337
+ E(e, "pages"),
338
+ E(e, "globals"),
339
+ E(e, "collections")
373
340
  ]);
374
341
  a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
375
342
  pages: Array.from(l),
@@ -395,31 +362,31 @@ function It(n = {}) {
395
362
  }), o.middlewares.use((f, a, u) => {
396
363
  const l = "<script>window.__oknoDev=true<\/script>", m = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", p = `${l}${m}<script type="module" src="${s}"><\/script>`, w = [];
397
364
  let k = null;
398
- const X = a.write.bind(a), j = a.end.bind(a), z = a.setHeader.bind(a), W = () => {
365
+ const V = a.write.bind(a), j = a.end.bind(a), X = a.setHeader.bind(a), G = () => {
399
366
  const d = a.getHeader("content-type");
400
367
  return typeof d == "string" && d.includes("text/html");
401
- }, J = (d, _) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, _ || "utf-8") : Buffer.from(String(d));
402
- a.write = (d, _, ...C) => (k === null && (k = W()), k ? (d && w.push(J(d, typeof _ == "string" ? _ : void 0)), !0) : X(d, _, ...C)), a.end = (d, _, ...C) => {
403
- if (k === null && (k = W()), !k) return j(d, _, ...C);
404
- d && w.push(J(d, typeof _ == "string" ? _ : void 0));
405
- let E = Buffer.concat(w).toString("utf-8");
406
- E.includes(p) || (E = E.includes("</body>") ? E.replace("</body>", `${p}</body>`) : E + p);
407
- const A = Buffer.from(E, "utf-8");
368
+ }, W = (d, S) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, S || "utf-8") : Buffer.from(String(d));
369
+ a.write = (d, S, ...C) => (k === null && (k = G()), k ? (d && w.push(W(d, typeof S == "string" ? S : void 0)), !0) : V(d, S, ...C)), a.end = (d, S, ...C) => {
370
+ if (k === null && (k = G()), !k) return j(d, S, ...C);
371
+ d && w.push(W(d, typeof S == "string" ? S : void 0));
372
+ let v = Buffer.concat(w).toString("utf-8");
373
+ v.includes(p) || (v = v.includes("</body>") ? v.replace("</body>", `${p}</body>`) : v + p);
374
+ const J = Buffer.from(v, "utf-8");
408
375
  if (!a.headersSent)
409
376
  try {
410
- z("content-length", String(A.length));
377
+ X("content-length", String(J.length));
411
378
  } catch {
412
379
  }
413
- return j(A, ...C);
380
+ return j(J, ...C);
414
381
  }, u();
415
382
  });
416
383
  },
417
384
  async handleHotUpdate(o) {
418
- const r = h(t, "schema.ts"), s = h(t, "users.json"), f = h(t, "permissions.ts"), a = h(t, "modules.d.ts");
419
- if (o.file === r) {
420
- await M(t, e);
385
+ const i = h(t, "schema.ts"), s = h(t, "users.json"), f = h(t, "permissions.ts"), a = h(t, "modules.d.ts");
386
+ if (o.file === i) {
387
+ await P(t, e);
421
388
  for (const p of ["pages", "collections", "globals", "locales", "content", "strings"]) {
422
- const w = o.server.moduleGraph.getModuleById(S + p);
389
+ const w = o.server.moduleGraph.getModuleById(_ + p);
423
390
  w && o.server.moduleGraph.invalidateModule(w);
424
391
  }
425
392
  return [];
@@ -428,9 +395,9 @@ function It(n = {}) {
428
395
  return [];
429
396
  const u = h(t, "strings.ts"), l = N(h(t, "strings"), o.file);
430
397
  if (o.file === u || !l.startsWith("..") && l.endsWith(".ts")) {
431
- await M(t, e);
398
+ await P(t, e);
432
399
  for (const p of ["strings", "content"]) {
433
- const w = o.server.moduleGraph.getModuleById(S + p);
400
+ const w = o.server.moduleGraph.getModuleById(_ + p);
434
401
  w && o.server.moduleGraph.invalidateModule(w);
435
402
  }
436
403
  }
@@ -438,57 +405,57 @@ function It(n = {}) {
438
405
  if (!m.startsWith("..") && m.endsWith(".ts")) {
439
406
  const p = m.split(/[\\/]/)[0];
440
407
  if ((p === "pages" || p === "collections" || p === "globals") && $(o.file)) {
441
- const w = o.server.moduleGraph.getModuleById(S + p);
408
+ const w = o.server.moduleGraph.getModuleById(_ + p);
442
409
  return w && o.server.moduleGraph.invalidateModule(w), [];
443
410
  }
444
411
  }
445
412
  },
446
- async resolveId(o, r) {
447
- if (o.startsWith(bt))
413
+ async resolveId(o, i) {
414
+ if (o.startsWith(St))
448
415
  return "\0" + o;
449
416
  if (o.startsWith("okno/")) {
450
417
  const s = o.slice(5);
451
- if (_t.has(s)) return S + s;
418
+ if (_t.has(s)) return _ + s;
452
419
  }
453
420
  if (c && o === "okno/editor")
454
421
  return I;
455
- if (c && r && yt(r, b)) {
456
- const s = wt(o, kt);
422
+ if (c && i && wt(i, b)) {
423
+ const s = bt(o, vt);
457
424
  if (s)
458
- return (await this.resolve(s, r, { skipSelf: !0 }))?.id;
425
+ return (await this.resolve(s, i, { skipSelf: !0 }))?.id;
459
426
  }
460
427
  },
461
428
  async load(o) {
462
- if (!o.startsWith(S)) return;
463
- const r = o.slice(S.length);
464
- if (r === "runtime") {
429
+ if (!o.startsWith(_)) return;
430
+ const i = o.slice(_.length);
431
+ if (i === "runtime") {
465
432
  if (!L)
466
433
  throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
467
434
  return L;
468
435
  }
469
- if (r === "bootstrap")
436
+ if (i === "bootstrap")
470
437
  return 'import("okno/editor")';
471
- if (r === "pages") {
472
- const s = await v(e, "pages");
473
- return await tt(t, s);
438
+ if (i === "pages") {
439
+ const s = await E(e, "pages");
440
+ return await q(t, s);
474
441
  }
475
- if (r === "collections") {
476
- const s = await v(e, "collections");
477
- return await et(t, s, y);
442
+ if (i === "collections") {
443
+ const s = await E(e, "collections");
444
+ return await tt(t, s, y);
478
445
  }
479
- if (r === "globals") {
480
- const s = await v(e, "globals");
481
- return await ot(t, s);
446
+ if (i === "globals") {
447
+ const s = await E(e, "globals");
448
+ return await et(t, s);
482
449
  }
483
- if (r === "locales")
484
- return nt(t);
485
- if (r === "strings")
486
- return await rt(t);
487
- if (r === "content")
450
+ if (i === "locales")
451
+ return ot(t);
452
+ if (i === "strings")
453
+ return await nt(t);
454
+ if (i === "content")
488
455
  return it();
489
456
  }
490
457
  };
491
458
  }
492
459
  export {
493
- It as o
460
+ Tt as o
494
461
  };
@@ -1,4 +1,4 @@
1
- import { o as a } from "../plugin-jvqdZWC0.js";
1
+ import { o as a } from "../plugin-DcdYJY8n.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAoHpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAsZpD"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA8DpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAsZpD"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "okno",
3
3
  "description": "Git-backed CMS with live editing for any Vite framework",
4
4
  "author": "Gabriel Uhlíř",
5
- "version": "1.0.0-beta.20",
5
+ "version": "1.0.0-beta.21",
6
6
  "homepage": "https://okno.build",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/editor/index.d.ts",
29
29
  "default": "./dist/editor/index.js"
30
30
  },
31
+ "./engine": {
32
+ "types": "./dist/engine/index.d.ts",
33
+ "default": "./dist/engine/index.js"
34
+ },
31
35
  "./boot": {
32
36
  "types": "./dist/boot.d.ts",
33
37
  "default": "./dist/boot.js"