@nimtech/nimpress 2.3.6 → 2.3.8

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.
@@ -0,0 +1,3851 @@
1
+ import { readdir as Me, readFile as it, writeFile as nt, copyFile as rs, cp as Ze, mkdir as Tt } from "node:fs/promises";
2
+ import { existsSync as dt, readFileSync as zt, statSync as ie, readdirSync as pe, createReadStream as is } from "node:fs";
3
+ import { request as as } from "node:http";
4
+ import { execFileSync as cs } from "node:child_process";
5
+ import { resolve as q, dirname as G, join as W, basename as Mt, relative as jt, extname as _e, isAbsolute as vt, sep as kt } from "node:path";
6
+ import { createHash as bn } from "node:crypto";
7
+ import Te from "gray-matter";
8
+ import ls from "markdown-it";
9
+ import Qe from "markdown-it-anchor";
10
+ import ps from "markdown-it-attrs";
11
+ import us from "markdown-it-container";
12
+ import fs from "markdown-it-deflist";
13
+ import ms from "markdown-it-footnote";
14
+ import ds from "markdown-it-task-lists";
15
+ import { z as f } from "zod";
16
+ import { parse as vn, stringify as hs } from "yaml";
17
+ import { createHighlighter as gs } from "shiki";
18
+ import { fileURLToPath as ys, pathToFileURL as tn } from "node:url";
19
+ import { exporter as bs } from "@dbml/core";
20
+ import { n as vs, r as Ut, e as ae, b as je, p as wn, c as Ne, d as Fe, g as ce, h as ws, k as Ie, o as $s, s as Ss, l as xs, q as ks, t as Ps, j as gt, m as js, a as Es } from "./typeMembers-CNvE92EX.js";
21
+ import { createRequire as Ds } from "node:module";
22
+ import { svelte as As } from "@sveltejs/vite-plugin-svelte";
23
+ import Cs from "@tailwindcss/vite";
24
+ import { loadConfigFromFile as Os } from "vite";
25
+ const en = {
26
+ out: "dist",
27
+ cache: "node_modules/.nimpress",
28
+ export: ".nimpress",
29
+ modules: "_components",
30
+ guarded: "_guarded"
31
+ }, Wt = {
32
+ title: "Nimpress",
33
+ base: "/",
34
+ contentDir: "docs",
35
+ assetsDir: "assets",
36
+ assetUrlBase: "/assets",
37
+ paths: en,
38
+ exclude: [],
39
+ defaultFrontmatter: {},
40
+ defaultFrontmatterExclude: [],
41
+ banner: {},
42
+ css: [],
43
+ vite: {},
44
+ modules: {
45
+ dir: "modules",
46
+ route: `/${en.modules}`,
47
+ systems: {}
48
+ }
49
+ }, Ms = f.object({
50
+ primary: f.string().optional(),
51
+ primaryHover: f.string().optional()
52
+ }).passthrough(), _s = f.object({
53
+ title: f.string(),
54
+ url: f.string().optional(),
55
+ description: f.string().optional(),
56
+ ogImage: f.string().optional(),
57
+ twitterSite: f.string().optional(),
58
+ locale: f.string().optional()
59
+ }).passthrough(), Ts = f.object({
60
+ text: f.string(),
61
+ link: f.string(),
62
+ gate: f.string().optional()
63
+ }), Ns = f.object({
64
+ title: f.string().optional(),
65
+ tagline: f.string().optional(),
66
+ company: f.string().optional(),
67
+ version: f.string().optional()
68
+ }).passthrough(), Fs = f.object({
69
+ name: f.string(),
70
+ framework: f.enum(["vue", "svelte"]),
71
+ source: f.string().optional(),
72
+ package: f.string().optional(),
73
+ version: f.string().optional(),
74
+ css: f.array(f.string()).optional(),
75
+ setup: f.string().optional(),
76
+ harness: f.string().optional(),
77
+ port: f.number().optional(),
78
+ visibility: f.enum(["visible", "dev-only"]).optional()
79
+ }), Is = f.object({
80
+ title: f.string().optional(),
81
+ logo: f.string().optional(),
82
+ github: f.string().optional(),
83
+ brand: Ms.optional(),
84
+ footer: f.string().optional(),
85
+ navRoutes: f.array(Ts).optional(),
86
+ auth: f.object({
87
+ issuer: f.string(),
88
+ clientId: f.string(),
89
+ scopes: f.string().optional(),
90
+ redirectPath: f.string().optional(),
91
+ headers: f.record(f.string()).optional(),
92
+ endpoints: f.object({
93
+ discovery: f.string().optional(),
94
+ authorization: f.string().optional(),
95
+ token: f.string().optional(),
96
+ userinfo: f.string().optional(),
97
+ endSession: f.string().optional(),
98
+ jwks: f.string().optional()
99
+ }).passthrough().optional(),
100
+ guard: f.custom((e) => e === void 0 || typeof e == "function").optional()
101
+ }).passthrough().optional(),
102
+ client: f.string().optional(),
103
+ subscribe: f.object({
104
+ endpoint: f.string().optional(),
105
+ appSlug: f.string().optional()
106
+ }).passthrough().optional(),
107
+ meta: f.object({
108
+ keywords: f.array(f.string()).optional(),
109
+ localeAlternates: f.array(f.string()).optional(),
110
+ organization: f.record(f.unknown()).optional(),
111
+ robots: f.object({
112
+ block: f.array(f.string()).optional(),
113
+ append: f.string().optional(),
114
+ custom: f.string().optional()
115
+ }).passthrough().optional(),
116
+ llms: f.object({
117
+ summary: f.string().optional(),
118
+ append: f.string().optional(),
119
+ full: f.boolean().optional()
120
+ }).passthrough().optional(),
121
+ og: f.object({
122
+ width: f.number().optional(),
123
+ height: f.number().optional()
124
+ }).passthrough().optional(),
125
+ webmanifest: f.record(f.unknown()).optional(),
126
+ humans: f.string().optional(),
127
+ security: f.object({
128
+ contact: f.string().optional(),
129
+ policy: f.string().optional(),
130
+ languages: f.string().optional(),
131
+ canonical: f.string().optional(),
132
+ expires: f.string().optional()
133
+ }).passthrough().optional()
134
+ }).passthrough().optional(),
135
+ site: _s.optional(),
136
+ base: f.string().optional(),
137
+ contentDir: f.string().optional(),
138
+ assetsDir: f.string().optional(),
139
+ assetUrlBase: f.string().optional(),
140
+ paths: f.object({
141
+ out: f.string().optional(),
142
+ cache: f.string().optional(),
143
+ export: f.string().optional(),
144
+ modules: f.string().optional(),
145
+ guarded: f.string().optional()
146
+ }).passthrough().optional(),
147
+ exclude: f.array(f.string()).optional(),
148
+ defaultFrontmatter: f.record(f.unknown()).optional(),
149
+ defaultFrontmatterExclude: f.array(f.string()).optional(),
150
+ banner: f.union([Ns, f.literal(!1)]).optional(),
151
+ css: f.union([f.string(), f.array(f.string())]).optional(),
152
+ vite: f.record(f.unknown()).optional(),
153
+ modules: f.array(Fs).optional()
154
+ }).passthrough();
155
+ function nn(e, t) {
156
+ const n = Is.safeParse(e);
157
+ return n.success ? n.data : (console.warn(`[nimpress] invalid config in ${t}: ${n.error.message}`), {});
158
+ }
159
+ const Bs = ["nimpress.config.ts", "nimpress.config.js", "nimpress.config.mjs", "nimpress.config.json"];
160
+ function sn(e) {
161
+ return typeof e == "object" && e !== null && !Array.isArray(e);
162
+ }
163
+ function Ee(e, t) {
164
+ if (!t) return e;
165
+ const n = { ...e };
166
+ for (const [s, o] of Object.entries(t)) {
167
+ if (o === void 0) continue;
168
+ const i = n[s];
169
+ sn(i) && sn(o) ? n[s] = Ee(i, o) : n[s] = o;
170
+ }
171
+ return n;
172
+ }
173
+ async function Rs(e) {
174
+ for (const t of Bs) {
175
+ const n = q(e, t);
176
+ if (!dt(n)) continue;
177
+ if (t.endsWith(".json")) {
178
+ const i = JSON.parse(zt(n, "utf-8"));
179
+ return { config: nn(i, n), file: n };
180
+ }
181
+ const o = (await Os({ command: "serve", mode: "development" }, n, e))?.config ?? {};
182
+ return { config: nn(o, n), file: n };
183
+ }
184
+ return null;
185
+ }
186
+ async function Ws(e, t) {
187
+ const n = await Rs(e), s = n?.config ? { ...n.config, modules: void 0 } : void 0, o = t ? { ...t, modules: void 0 } : void 0;
188
+ let i = Ee(Wt, s);
189
+ i = Ee(i, o), i.css = typeof i.css == "string" ? [i.css] : i.css ?? [], i.base = vs(i.base);
190
+ const c = t?.modules ?? n?.config?.modules;
191
+ return i.modules = {
192
+ dir: Wt.modules.dir,
193
+ route: `/${i.paths.modules}`,
194
+ systems: c ? Object.fromEntries(c.map((u) => [u.name, u])) : {}
195
+ }, { resolved: i, configFile: n?.file ?? null };
196
+ }
197
+ function Ls(e) {
198
+ return {
199
+ title: e.title,
200
+ logo: e.logo,
201
+ github: e.github,
202
+ brand: e.brand,
203
+ base: e.base,
204
+ contentRoot: e.contentDir,
205
+ navRoutes: e.navRoutes,
206
+ auth: e.auth,
207
+ subscribe: e.subscribe,
208
+ site: e.site,
209
+ footer: e.footer,
210
+ guardedBase: `/${e.paths.guarded}`
211
+ };
212
+ }
213
+ const et = "\x1B[0m", le = "\x1B[1m", oe = "\x1B[2m", $n = "\x1B[38;2;204;120;92m", Pt = "\x1B[38;2;229;174;156m", Ot = "\x1B[38;2;160;160;170m", Kt = [
214
+ " ███╗ ██╗ ██╗ ███╗ ███╗ ██████╗ ██████╗ ███████╗ ███████╗ ███████╗",
215
+ " ████╗ ██║ ██║ ████╗ ████║ ██╔══██╗ ██╔══██╗ ██╔════╝ ██╔════╝ ██╔════╝",
216
+ " ██╔██╗ ██║ ██║ ██╔████╔██║ ██████╔╝ ██████╔╝ █████╗ ███████╗ ███████╗",
217
+ " ██║╚██╗██║ ██║ ██║╚██╔╝██║ ██╔═══╝ ██╔══██╗ ██╔══╝ ╚════██║ ╚════██║",
218
+ " ██║ ╚████║ ██║ ██║ ╚═╝ ██║ ██║ ██║ ██║ ███████╗ ███████║ ███████║",
219
+ " ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝"
220
+ ], It = 60;
221
+ function Hs(e, t) {
222
+ const n = e.replace(/\x1b\[[0-9;]*m/g, ""), s = Math.max(0, t - n.length);
223
+ return e + " ".repeat(s);
224
+ }
225
+ function Us(e) {
226
+ const t = "╔" + "═".repeat(It + 2) + "╗", n = "╠" + "═".repeat(It + 2) + "╣", s = "╚" + "═".repeat(It + 2) + "╝", o = [t];
227
+ for (let i = 0; i < e.length; i++)
228
+ o.push("║ " + Hs(e[i], It) + " ║"), i < e.length - 1 && o.push(n);
229
+ return o.push(s), o;
230
+ }
231
+ function Js() {
232
+ try {
233
+ const e = G(ys(import.meta.url)), t = [
234
+ q(e, "package.json"),
235
+ q(e, "..", "package.json"),
236
+ q(e, "..", "..", "package.json")
237
+ ];
238
+ for (const n of t)
239
+ try {
240
+ const s = zt(n, "utf-8"), o = JSON.parse(s);
241
+ if (o?.name === "@nimtech/nimpress" && typeof o.version == "string") return o.version;
242
+ } catch {
243
+ }
244
+ } catch {
245
+ }
246
+ return "";
247
+ }
248
+ function qs(e = {}) {
249
+ const t = e.title ?? "Nimpress", n = e.tagline ?? "Docs framework on Svelte", s = e.company ?? `Samna® ${(/* @__PURE__ */ new Date()).getFullYear()}`, o = e.version ?? "dev", i = e.localUrl ?? "http://localhost:5173/", c = e.networkUrl ?? "use --host to expose", u = typeof e.duration == "number" ? `ready in ${e.duration} ms` : "ready", b = e.nimpressVersion ?? Js(), d = [];
250
+ d.push("");
251
+ for (const H of Kt) d.push($n + H + et);
252
+ d.push("");
253
+ const m = [
254
+ `${le}${t}${et}${Ot} · ${s}${et}`,
255
+ `${Ot}${n}${et}`,
256
+ `${Pt}Version${et} ${o} ${Pt}${u}${et}`
257
+ ];
258
+ b && m.push(`${Pt}Nimpress${et} ${b}`), m.push(`${Pt}➜${et} Local ${le}${i}${et}`), m.push(`${Pt}➜${et} Network ${oe}${c}${et}`);
259
+ const w = Us(m), k = Kt[0].length, P = Kt[0].length - Kt[0].trimStart().length, O = It + 4, E = " ".repeat(Math.max(0, Math.floor((k + P - O) / 2)));
260
+ for (const H of w) d.push(E + H);
261
+ return d.push(""), d.join(`
262
+ `);
263
+ }
264
+ function zs() {
265
+ try {
266
+ const e = zt(q(process.cwd(), "package.json"), "utf-8"), t = JSON.parse(e);
267
+ return { name: t.name, version: t.version };
268
+ } catch {
269
+ return {};
270
+ }
271
+ }
272
+ const Gs = 27, Vs = 14, Xs = 16, Ys = 20, Ks = 17, Zs = 14, Sn = 110, Qs = 60, to = 120, Lt = 40, eo = 200, no = 420, so = 24, oo = 7.6, ro = 6.6, xn = 7.4, io = 5.4, ao = 5.8, co = 6.2, lo = 34, po = 48, on = 8, uo = 260, fo = 18, mo = 6.2, ho = 30, rn = 24, an = 24;
273
+ class Be extends Error {
274
+ }
275
+ function go(e) {
276
+ const t = e?.diags;
277
+ return Array.isArray(t) && t.length ? t.map((n) => {
278
+ const s = n.location, o = s?.start?.line, i = s?.start?.column;
279
+ return `${o ? `line ${o}${i ? `, column ${i}` : ""}: ` : ""}${String(n.message ?? "invalid dbml")}`;
280
+ }).join(`
281
+ `) : e instanceof Error ? e.message : String(e);
282
+ }
283
+ function yo(e) {
284
+ try {
285
+ return JSON.parse(bs.export(e, "json"));
286
+ } catch (t) {
287
+ throw new Be(go(t));
288
+ }
289
+ }
290
+ function bo(e) {
291
+ return (e.type?.type_name ?? "").trim();
292
+ }
293
+ function vo(e) {
294
+ const t = e.dbdefault;
295
+ return !t || t.value === void 0 || t.value === null ? "" : String(t.value);
296
+ }
297
+ const wo = /\[([^\]]+)\]\(([^)\s]+)\)/;
298
+ function $o(e) {
299
+ const t = String(e ?? "").trim(), n = wo.exec(t);
300
+ return n ? {
301
+ note: t.replace(n[0], "").replace(/\s{2,}/g, " ").trim(),
302
+ label: n[1].trim(),
303
+ href: n[2].trim()
304
+ } : { note: t, label: "", href: "" };
305
+ }
306
+ function re(e, t, n) {
307
+ if (!e) return 0;
308
+ const s = Math.max(1, Math.floor(n / t));
309
+ return e.split(`
310
+ `).reduce((o, i) => o + Math.max(1, Math.ceil(i.trim().length / s)), 0);
311
+ }
312
+ function be(e) {
313
+ return e.reduce((t, n) => Math.max(t, n.length), 0);
314
+ }
315
+ function So(e, t) {
316
+ const n = be(t.map((b) => b.name)) * oo, s = be(t.map((b) => b.type)) * ro, o = be(t.map((b) => b.linkLabel)) * co, i = t.some((b) => b.pk || b.fk) ? lo : 0, c = Math.round(n + s + o + i + po), u = Math.round(e.length * xn + 32);
317
+ return Math.min(no, Math.max(eo, c, u));
318
+ }
319
+ function xo(e) {
320
+ const t = e.width - so, n = Math.max(1, re(e.name, xn, t)), s = re(e.note, io, t), o = Ys + n * Ks + s * Zs, i = Math.max(e.columns.length, 1) * Gs, c = e.indexes.reduce(
321
+ (b, d) => b + re(`${d.unique ? "unique" : "index"} ${d.columns.join(", ")}`, ao, t),
322
+ 0
323
+ ), u = e.indexes.length ? Xs + c * Vs : 0;
324
+ return Math.round(o + i + u + 2);
325
+ }
326
+ function ko(e) {
327
+ const t = e.width - rn, n = re(e.body, mo, t), s = e.title ? ho : 0;
328
+ return Math.round(rn + s + Math.max(1, n) * fo);
329
+ }
330
+ function Po(e, t, n) {
331
+ return e.x < t.x + t.width + n && t.x < e.x + e.width + n && e.y < t.y + t.height + n && t.y < e.y + e.height + n;
332
+ }
333
+ function jo(e, t) {
334
+ const n = [...e].sort((s, o) => s.y - o.y || s.x - o.x);
335
+ for (let s = 1; s < n.length; s++) {
336
+ let o = !0, i = 0;
337
+ for (; o && i < n.length; ) {
338
+ o = !1, i += 1;
339
+ for (let c = 0; c < s; c++)
340
+ Po(n[s], n[c], t) && (n[s].y = n[c].y + n[c].height + t, o = !0);
341
+ }
342
+ }
343
+ }
344
+ function Eo(e, t) {
345
+ const n = /* @__PURE__ */ new Map();
346
+ for (const u of e) n.set(u.id, /* @__PURE__ */ new Set());
347
+ for (const [u, b] of t)
348
+ u !== b && (n.get(u)?.add(b), n.get(b)?.add(u));
349
+ const s = new Map(e.map((u) => [u.id, u])), o = /* @__PURE__ */ new Set(), i = [], c = [...e].sort(
350
+ (u, b) => (n.get(b.id)?.size ?? 0) - (n.get(u.id)?.size ?? 0)
351
+ );
352
+ for (const u of c) {
353
+ if (o.has(u.id)) continue;
354
+ const b = [], d = [u.id];
355
+ for (o.add(u.id); d.length; ) {
356
+ const m = d.shift(), w = s.get(m);
357
+ w && b.push(w);
358
+ const k = [...n.get(m) ?? []].sort(
359
+ (P, O) => (n.get(O)?.size ?? 0) - (n.get(P)?.size ?? 0)
360
+ );
361
+ for (const P of k)
362
+ o.has(P) || (o.add(P), d.push(P));
363
+ }
364
+ i.push(b);
365
+ }
366
+ return i;
367
+ }
368
+ function Do(e, t) {
369
+ const n = new Set(e.map((d) => d.id)), s = /* @__PURE__ */ new Map();
370
+ for (const d of e) s.set(d.id, /* @__PURE__ */ new Set());
371
+ for (const [d, m] of t)
372
+ d === m || !n.has(d) || !n.has(m) || (s.get(d)?.add(m), s.get(m)?.add(d));
373
+ const o = /* @__PURE__ */ new Map(), i = e[0];
374
+ o.set(i.id, 0);
375
+ const c = [i.id];
376
+ for (; c.length; ) {
377
+ const d = c.shift();
378
+ for (const m of s.get(d) ?? [])
379
+ o.has(m) || (o.set(m, (o.get(d) ?? 0) + 1), c.push(m));
380
+ }
381
+ const u = /* @__PURE__ */ new Map();
382
+ for (const d of e) {
383
+ const m = o.get(d.id) ?? 0, w = u.get(m) ?? [];
384
+ w.push(d), u.set(m, w);
385
+ }
386
+ const b = [];
387
+ for (const d of [...u.keys()].sort((m, w) => m - w)) {
388
+ const m = u.get(d) ?? [];
389
+ for (let w = 0; w < m.length; w += on)
390
+ b.push(m.slice(w, w + on));
391
+ }
392
+ return b;
393
+ }
394
+ function Ao(e, t) {
395
+ const n = [];
396
+ let s = Lt;
397
+ for (const o of Eo(e, t)) {
398
+ let i = Lt, c = s;
399
+ for (const u of Do(o, t)) {
400
+ const b = Math.max(...u.map((m) => m.width));
401
+ let d = s;
402
+ for (const m of u)
403
+ m.x = i + Math.round((b - m.width) / 2), m.y = d, d += m.height + Qs, c = Math.max(c, m.y + m.height), n.push(m);
404
+ i += b + Sn;
405
+ }
406
+ s = c + to;
407
+ }
408
+ return n;
409
+ }
410
+ function Co(e) {
411
+ const t = yo(e), n = Object.values(t.database)[0], s = /* @__PURE__ */ new Map(), o = [];
412
+ for (const _ of Object.values(t.schemas).sort((A, L) => A.id - L.id))
413
+ for (const A of _.tableIds)
414
+ o.push(A), s.set(A, _.name);
415
+ const i = /* @__PURE__ */ new Set();
416
+ for (const _ of Object.values(t.indexes)) {
417
+ if (!_.pk) continue;
418
+ const A = t.tables[String(_.tableId)];
419
+ if (A)
420
+ for (const L of _.columnIds) {
421
+ const ot = t.indexColumns[String(L)];
422
+ if (!ot || ot.type !== "column") continue;
423
+ const lt = A.fieldIds.map((mt) => t.fields[String(mt)]).find((mt) => mt && mt.name === ot.value);
424
+ lt && i.add(lt.id);
425
+ }
426
+ }
427
+ const c = [], u = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
428
+ for (const _ of o) {
429
+ const A = t.tables[String(_)];
430
+ if (!A) continue;
431
+ const L = s.get(_) ?? "public", ot = L === "public" ? A.name : `${L}.${A.name}`, lt = `table-${_}`, mt = [];
432
+ A.fieldIds.forEach((pt) => {
433
+ const Q = t.fields[String(pt)];
434
+ if (!Q) return;
435
+ const $t = !!Q.pk || i.has(Q.id), at = $o(Q.note ?? "");
436
+ d.set(Q.id, mt.length), m.set(Q.id, lt), mt.push({
437
+ name: Q.name,
438
+ type: bo(Q),
439
+ note: at.note,
440
+ default: vo(Q),
441
+ pk: $t,
442
+ fk: !1,
443
+ unique: !!Q.unique,
444
+ notNull: $t || !!Q.not_null,
445
+ increment: !!Q.increment,
446
+ link: at.href,
447
+ linkLabel: at.label,
448
+ target: ""
449
+ });
450
+ });
451
+ const Et = [];
452
+ for (const pt of A.indexIds) {
453
+ const Q = t.indexes[String(pt)];
454
+ if (!Q || Q.pk) continue;
455
+ const $t = Q.columnIds.map((at) => t.indexColumns[String(at)]).filter((at) => at && at.type === "column").map((at) => at.value);
456
+ $t.length && Et.push({
457
+ name: Q.name ?? `${A.name}_index_${Q.id}`,
458
+ columns: $t,
459
+ unique: !!Q.unique
460
+ });
461
+ }
462
+ const wt = {
463
+ id: lt,
464
+ name: ot,
465
+ note: A.note ?? "",
466
+ color: A.headerColor ?? "",
467
+ columns: mt,
468
+ indexes: Et,
469
+ x: 0,
470
+ y: 0,
471
+ width: So(ot, mt),
472
+ height: 0
473
+ };
474
+ wt.height = xo(wt), c.push(wt), u.set(lt, wt), b.set(A.name, lt), b.set(ot, lt);
475
+ }
476
+ for (const _ of c)
477
+ for (const A of _.columns) {
478
+ if (!A.link) continue;
479
+ const L = A.link.replace(/^#/, ""), ot = b.get(L) ?? b.get(A.link);
480
+ !ot || ot === _.id || (A.target = ot, A.link = "");
481
+ }
482
+ const w = [];
483
+ for (const _ of Object.values(t.refs).sort((A, L) => A.id - L.id)) {
484
+ const A = _.endpointIds.map((Q) => t.endpoints[String(Q)]).filter(Boolean);
485
+ if (A.length !== 2) continue;
486
+ const L = A[1].relation === "1" ? 1 : A[0].relation === "1" ? 0 : 1, ot = A[L], lt = A[L === 0 ? 1 : 0], mt = ot.fieldIds[0], Et = lt.fieldIds[0];
487
+ if (mt === void 0 || Et === void 0) continue;
488
+ const wt = m.get(mt) ?? b.get(ot.tableName), pt = m.get(Et) ?? b.get(lt.tableName);
489
+ if (!(!wt || !pt)) {
490
+ for (const Q of lt.fieldIds) {
491
+ const $t = u.get(m.get(Q) ?? ""), at = d.get(Q);
492
+ if (!$t || at === void 0) continue;
493
+ const St = $t.columns[at];
494
+ St.fk = !0, !St.target && !St.link && (St.target = wt);
495
+ }
496
+ w.push({
497
+ id: `edge-${_.id}`,
498
+ parent: wt,
499
+ parentColumn: d.get(mt) ?? 0,
500
+ child: pt,
501
+ childColumn: d.get(Et) ?? 0,
502
+ many: lt.relation !== "1"
503
+ });
504
+ }
505
+ }
506
+ const k = Ao(
507
+ c,
508
+ w.map((_) => [_.parent, _.child])
509
+ ), P = k.length ? k : c, O = [], E = P.reduce((_, A) => Math.max(_, A.x + A.width), Lt);
510
+ let H = Lt;
511
+ const K = E + Lt + Sn;
512
+ for (const _ of Object.values(t.notes).sort((A, L) => A.id - L.id)) {
513
+ const A = String(_.content ?? "").trim();
514
+ if (!A) continue;
515
+ const L = {
516
+ id: `note-${_.id}`,
517
+ title: _.name ?? "",
518
+ body: A,
519
+ x: K,
520
+ y: H,
521
+ width: uo,
522
+ height: 0
523
+ };
524
+ L.height = ko(L), O.push(L), H += L.height + an;
525
+ }
526
+ jo([...P, ...O], an);
527
+ const st = [];
528
+ for (const _ of w) {
529
+ const A = u.get(_.parent), L = u.get(_.child);
530
+ if (!A || !L) continue;
531
+ const ot = A.x + A.width / 2 <= L.x + L.width / 2 ? "r" : "l", lt = ot === "r" ? "l" : "r";
532
+ st.push({
533
+ id: _.id,
534
+ source: A.id,
535
+ sourceHandle: `${ot}-${_.parentColumn}`,
536
+ target: L.id,
537
+ targetHandle: `${lt}-${_.childColumn}`,
538
+ many: _.many
539
+ });
540
+ }
541
+ return {
542
+ database: n?.name ?? "",
543
+ tables: P,
544
+ edges: st,
545
+ notes: O
546
+ };
547
+ }
548
+ function kn(e) {
549
+ return JSON.stringify(Co(e));
550
+ }
551
+ function Oo(e, t, n = "") {
552
+ const s = e.match(/<script[^>]*\bsetup\b[^>]*>([\s\S]*?)<\/script>/)?.[1] ?? "", o = e.match(/<template>([\s\S]*)<\/template>/)?.[1] ?? "", i = `${s}
553
+ ${n}`;
554
+ let c = null;
555
+ const u = /defineProps<\s*\{/.exec(s);
556
+ if (u)
557
+ c = Ut(s, u.index + u[0].length);
558
+ else {
559
+ const E = s.match(/defineProps<\s*([A-Za-z_$][\w$]*)\s*>/);
560
+ E && (c = ae(i, E[1]));
561
+ }
562
+ const b = /* @__PURE__ */ new Map(), d = s.match(/(?:const|let)\s*\{([\s\S]*?)\}\s*=\s*(?:withDefaults\s*\(\s*)?defineProps/);
563
+ if (d)
564
+ for (const E of je(d[1])) {
565
+ const H = E.match(/^([A-Za-z_$][\w$]*)\s*=\s*([\s\S]+)$/);
566
+ H && b.set(H[1], wn(H[2]));
567
+ }
568
+ const m = [];
569
+ if (c)
570
+ for (const E of Ne(c)) {
571
+ const H = Fe(
572
+ ce(E.name, E.type, E.optional, i, E.description),
573
+ E
574
+ );
575
+ b.has(E.name) && (H.default = b.get(E.name)), m.push(H);
576
+ }
577
+ for (const E of s.matchAll(/\bdefineModel(?:<([^>]*)>)?\(\s*(?:['"]([\w-]+)['"])?/g)) {
578
+ const H = E[2] ?? "modelValue";
579
+ if (m.some((_) => _.name === H)) continue;
580
+ const K = ce(H, E[1]?.trim() || "string", !0, i);
581
+ K.bindable = !0;
582
+ const st = s.slice(0, E.index).match(/\/\*\*((?:[^*]|\*(?!\/))*)\*\/\s*(?:const|let)\s+[\w$]+\s*=\s*$/);
583
+ if (st) {
584
+ const _ = ws(st[1].replace(/^\s*\*\s?/gm, "").trim());
585
+ _.description && (K.description = _.description), _.mock && !K.mock && (K.mock = _.mock);
586
+ }
587
+ m.push(K);
588
+ }
589
+ const w = [], k = /* @__PURE__ */ new Set();
590
+ for (const E of o.matchAll(/<slot\b([^>]*)>/g)) {
591
+ const H = E[1].match(/(?:^|[^:\w-])name=["']([^"']+)["']/)?.[1];
592
+ if (!H && /(?:^|\s)(?::|v-bind:)name=/.test(E[1])) continue;
593
+ const K = H ?? "default";
594
+ k.has(K) || (k.add(K), w.push({ name: K, kind: "slot", type: "slot" }));
595
+ }
596
+ const P = [], O = s.indexOf("defineEmits");
597
+ if (O >= 0) {
598
+ const E = s.slice(O), H = E.search(/[<(]/);
599
+ if (H >= 0) {
600
+ const K = E[H], st = K === "<" ? ">" : ")", _ = Ut(E, H + 1, K, st), A = /* @__PURE__ */ new Set();
601
+ for (const L of _.matchAll(/['"]([\w:.-]+)['"]\s*:\s*\[/g)) A.add(L[1]);
602
+ for (const L of _.matchAll(/\(\s*\w+\s*:\s*['"]([\w:.-]+)['"]/g)) A.add(L[1]);
603
+ for (const L of _.matchAll(/[,\[]\s*['"]([\w:.-]+)['"]\s*[,\]]/g)) A.add(L[1]);
604
+ for (const L of _.matchAll(/(?:^|[\n;{,])\s*([A-Za-z_$][\w$]*)\s*:\s*\[/g)) A.add(L[1]);
605
+ P.push(...A);
606
+ }
607
+ }
608
+ for (const E of m)
609
+ (E.bindable || P.includes(`update:${E.name}`)) && (E.bindable = !0, P.includes(`update:${E.name}`) || P.push(`update:${E.name}`));
610
+ return { component: t, props: m, slots: w, emits: P };
611
+ }
612
+ function Mo(e, t, n = "") {
613
+ const s = e.match(/<script[^>]*>([\s\S]*?)<\/script>/)?.[1] ?? "", o = `${s}
614
+ ${n}`, i = s.match(/(?:let|const)\s*\{([\s\S]*?)\}\s*(?::\s*([\s\S]*?))?=\s*\$props\(\)/), c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
615
+ if (i)
616
+ for (const P of je(i[1])) {
617
+ const O = P.match(/^([A-Za-z_$][\w$]*)\s*=\s*([\s\S]+)$/);
618
+ if (!O) continue;
619
+ const E = O[2].trim().match(/^\$bindable\(([\s\S]*)\)$/);
620
+ E && u.add(O[1]), c.set(O[1], wn(E ? E[1] : O[2]));
621
+ }
622
+ let b = null;
623
+ const d = i?.[2]?.trim();
624
+ if (d)
625
+ if (d.startsWith("{"))
626
+ b = Ut(d, 1);
627
+ else {
628
+ const P = d.match(/^([A-Za-z_$][\w$]*)/);
629
+ P && (b = ae(o, P[1]));
630
+ }
631
+ const m = [], w = [], k = [];
632
+ if (b)
633
+ for (const P of Ne(b)) {
634
+ if (/\bSnippet\b/.test(P.type)) {
635
+ w.push({ name: P.name, kind: "slot", type: P.type, required: !P.optional });
636
+ continue;
637
+ }
638
+ if (/^on[A-Z]/.test(P.name) && /=>/.test(P.type)) {
639
+ k.push(P.name);
640
+ continue;
641
+ }
642
+ const O = Fe(
643
+ ce(P.name, P.type, P.optional, o, P.description),
644
+ P
645
+ );
646
+ c.has(P.name) && (O.default = c.get(P.name)), u.has(P.name) && (O.bindable = !0), m.push(O);
647
+ }
648
+ else if (i) {
649
+ for (const P of je(i[1])) {
650
+ const O = P.match(/^([A-Za-z_$][\w$]*)/)?.[1];
651
+ if (!O || O === "children") continue;
652
+ const E = { name: O, kind: "json", type: "unknown" };
653
+ c.has(O) && (E.default = c.get(O)), u.has(O) && (E.bindable = !0), m.push(E);
654
+ }
655
+ /\bchildren\b/.test(i[1]) && w.push({ name: "children", kind: "slot", type: "Snippet" });
656
+ }
657
+ return { component: t, props: m, slots: w, emits: k };
658
+ }
659
+ function Pn(e, t = []) {
660
+ let n;
661
+ try {
662
+ n = pe(e, { withFileTypes: !0 });
663
+ } catch {
664
+ return t;
665
+ }
666
+ for (const s of n) {
667
+ const o = W(e, s.name);
668
+ if (s.isDirectory()) {
669
+ if (s.name === "node_modules") continue;
670
+ Pn(o, t);
671
+ } else s.isFile() && s.name.endsWith(".d.ts") && t.push(o);
672
+ }
673
+ return t;
674
+ }
675
+ function _o(e, t, n) {
676
+ const s = W(e, "node_modules", t);
677
+ if (!dt(s) || !ie(s).isDirectory()) return null;
678
+ const o = [
679
+ `${n}.vue.d.ts`,
680
+ `${n}.svelte.d.ts`,
681
+ `${n}.d.ts`,
682
+ `${n.toLowerCase()}/index.d.ts`
683
+ ], i = Pn(s);
684
+ for (const c of o) {
685
+ const u = i.find((b) => b.endsWith(`/${c}`));
686
+ if (u) return u;
687
+ }
688
+ return null;
689
+ }
690
+ function ti(e, t) {
691
+ const n = ae(e, `${t}Props`) ?? ae(e, "Props");
692
+ if (!n) return;
693
+ const s = [], o = [], i = [];
694
+ for (const c of Ne(n)) {
695
+ if (/\bSnippet\b/.test(c.type)) {
696
+ o.push({ name: c.name, kind: "slot", type: c.type, required: !c.optional });
697
+ continue;
698
+ }
699
+ if (/^on[A-Z]/.test(c.name) && /=>/.test(c.type)) {
700
+ i.push(c.name);
701
+ continue;
702
+ }
703
+ s.push(Fe(ce(c.name, c.type, c.optional, e, c.description), c));
704
+ }
705
+ return { component: t, props: s, slots: o, emits: i };
706
+ }
707
+ function ve(e, t) {
708
+ const n = e.search(new RegExp(`\\b${t}\\s*:`));
709
+ if (n < 0) return;
710
+ const s = e.indexOf("{", n);
711
+ if (s < 0) return;
712
+ const o = Ut(e, s + 1);
713
+ try {
714
+ return new Function(`return {${o}}`)();
715
+ } catch {
716
+ return;
717
+ }
718
+ }
719
+ function we(e, t) {
720
+ const n = e.search(new RegExp(`\\b${t}\\s*:`));
721
+ if (n < 0) return e;
722
+ const s = e.indexOf("{", n);
723
+ if (s < 0) return e;
724
+ const o = Ut(e, s + 1);
725
+ return e.slice(0, n) + e.slice(s + 1 + o.length + 1);
726
+ }
727
+ function To(e, t) {
728
+ const n = e.match(/^\s*\/\/\s*story:\s*(.+)$/m)?.[1]?.trim(), s = we(we(e, "props"), "slots"), o = ve(s, "sidebar"), i = we(s, "sidebar"), c = i.match(/\bname\s*:\s*['"]([^'"]+)['"]/)?.[1], u = i.match(/\bdescription\s*:\s*['"]([^'"]+)['"]/)?.[1], b = ve(e, "props"), d = ve(e, "slots");
729
+ return {
730
+ name: n ?? c ?? Mt(t).replace(/\.story\.tsx?$/, "").replace(/_/g, " "),
731
+ file: t,
732
+ description: u,
733
+ props: b,
734
+ slots: d,
735
+ sidebar: o
736
+ };
737
+ }
738
+ async function No(e) {
739
+ let t;
740
+ try {
741
+ t = await Me(e, { withFileTypes: !0 });
742
+ } catch {
743
+ return [];
744
+ }
745
+ const n = [];
746
+ for (const s of t) {
747
+ if (!s.isFile() || !s.name.match(/\.story\.tsx?$/)) continue;
748
+ let o;
749
+ try {
750
+ o = await it(W(e, s.name), "utf-8");
751
+ } catch {
752
+ continue;
753
+ }
754
+ n.push(To(o, s.name));
755
+ }
756
+ return n.sort((s, o) => s.name.localeCompare(o.name)), n;
757
+ }
758
+ function ue(e, t, n, s, o) {
759
+ const i = t.systems[n];
760
+ if (!i?.source) return null;
761
+ const c = q(e, i.source), u = i.framework === "vue" ? ".vue" : ".svelte", b = o ? [q(c, o)] : [W(c, s, s + u), W(c, s + u)];
762
+ for (const d of b) {
763
+ if (!o && !d.startsWith(c) || !dt(d)) continue;
764
+ const m = G(d);
765
+ return {
766
+ systemConfig: i,
767
+ componentFile: d,
768
+ componentDir: m,
769
+ claudeMdPath: W(m, "CLAUDE.md")
770
+ };
771
+ }
772
+ return null;
773
+ }
774
+ async function jn(e, t = []) {
775
+ let n;
776
+ try {
777
+ n = await Me(e, { withFileTypes: !0 });
778
+ } catch {
779
+ return t;
780
+ }
781
+ for (const s of n) {
782
+ const o = W(e, s.name);
783
+ if (s.isDirectory()) {
784
+ if (s.name.startsWith(".") || s.name === "node_modules") continue;
785
+ await jn(o, t);
786
+ } else s.isFile() && s.name.endsWith(".md") && t.push(o);
787
+ }
788
+ return t;
789
+ }
790
+ async function Re(e, t) {
791
+ const n = q(e, t), s = await jn(n), o = [];
792
+ for (const i of s) {
793
+ let c;
794
+ try {
795
+ c = await it(i, "utf-8");
796
+ } catch {
797
+ continue;
798
+ }
799
+ const { data: u } = Te(c);
800
+ if (u?.type !== "component") continue;
801
+ const b = u.data ?? {}, d = String(b.system ?? ""), m = String(b.component ?? "");
802
+ !d || !m || o.push({
803
+ pageFile: i,
804
+ system: d,
805
+ component: m,
806
+ file: typeof b.file == "string" ? b.file : void 0,
807
+ package: typeof b.package == "string" ? b.package : void 0,
808
+ version: typeof b.version == "string" ? b.version : void 0
809
+ });
810
+ }
811
+ return o;
812
+ }
813
+ function Gt(e) {
814
+ const t = W(e, "schema.yml");
815
+ if (dt(t)) return { path: t, form: "yml" };
816
+ const n = W(e, "schema.json");
817
+ return dt(n) ? { path: n, form: "json" } : null;
818
+ }
819
+ function Vt(e, t) {
820
+ return t === "yml" ? vn(e) : JSON.parse(e);
821
+ }
822
+ function Jt(e, t) {
823
+ return t === "yml" ? hs(e) : JSON.stringify(e, null, 2) + `
824
+ `;
825
+ }
826
+ async function We(e, t, n) {
827
+ try {
828
+ return await Xo(G(e), e, t, n);
829
+ } catch (s) {
830
+ console.warn(`nimpress modules: schema parse failed for ${n}: ${String(s)}`);
831
+ return;
832
+ }
833
+ }
834
+ const Fo = ["description", "default", "enum", "mock", "format", "minimum", "maximum", "title"], Io = ["type", "tsType", "bindable"];
835
+ function Ht(e, t) {
836
+ const n = { ...e }, s = n, o = t;
837
+ for (const i of Io)
838
+ o[i] !== void 0 && (s[i] = o[i]);
839
+ t.type !== void 0 && t.tsType === void 0 && delete n.tsType, t.required !== void 0 && (n.required = t.required);
840
+ for (const i of Fo)
841
+ s[i] === void 0 && o[i] !== void 0 && (s[i] = o[i]);
842
+ if (t.properties) {
843
+ const i = {};
844
+ for (const [c, u] of Object.entries(t.properties)) {
845
+ const b = e.properties?.[c];
846
+ i[c] = b ? Ht(b, u) : u;
847
+ }
848
+ for (const [c, u] of Object.entries(e.properties ?? {}))
849
+ c in i || (i[c] = u);
850
+ n.properties = i;
851
+ }
852
+ return t.items && (n.items = e.items ? Ht(e.items, t.items) : t.items), t.additionalProperties && (n.additionalProperties = e.additionalProperties ? Ht(e.additionalProperties, t.additionalProperties) : t.additionalProperties), n;
853
+ }
854
+ function Le(e, t) {
855
+ const n = t, s = { added: [], missing: [] }, o = {};
856
+ for (const [b, d] of Object.entries(n.properties ?? {})) {
857
+ const m = e.properties?.[b];
858
+ m ? o[b] = Ht(m, d) : (o[b] = d, s.added.push(b));
859
+ }
860
+ for (const [b, d] of Object.entries(e.properties ?? {}))
861
+ b in o || (o[b] = d, s.missing.push(`prop ${b}`));
862
+ const i = {};
863
+ for (const [b, d] of Object.entries(n.slots ?? {})) {
864
+ const m = e.slots?.[b];
865
+ i[b] = m ? Ht(m, d) : d;
866
+ }
867
+ for (const [b, d] of Object.entries(e.slots ?? {}))
868
+ b in i || (i[b] = d, s.missing.push(`slot ${b}`));
869
+ const c = [...n.emits ?? []];
870
+ for (const b of e.emits ?? [])
871
+ c.includes(b) || (c.push(b), s.missing.push(`emit ${b}`));
872
+ return { merged: { ...e, ...t, properties: o, slots: i, emits: c }, report: s };
873
+ }
874
+ const Bt = [], cn = /* @__PURE__ */ new Set();
875
+ function Bo(e) {
876
+ return `${e.component}|${e.kind}|${e.path}`;
877
+ }
878
+ function ln(e) {
879
+ for (const t of e) {
880
+ const n = Bo(t);
881
+ cn.has(n) || (cn.add(n), Bt.push(t));
882
+ }
883
+ }
884
+ const Ro = {
885
+ opaque: "author opaque members in the schema with enum or properties, or type them in the source",
886
+ undocumented: "describe them in the schema or above the type member in the source",
887
+ orphan: "remove the schema member or restore it in the source"
888
+ };
889
+ function Wo(e) {
890
+ const t = e.match(/^type (.+) is opaque$/);
891
+ return t ? `${Ot}type${et} ${t[1]} ${Ot}is opaque${et}` : `${Ot}${e}${et}`;
892
+ }
893
+ function Nt(e = process.cwd()) {
894
+ if (!Bt.length) return;
895
+ const t = /* @__PURE__ */ new Map();
896
+ for (const c of Bt) {
897
+ const u = t.get(c.component) ?? [];
898
+ u.push(c), t.set(c.component, u);
899
+ }
900
+ const n = Bt.length;
901
+ Bt.length = 0;
902
+ const s = n === 1 ? "schema warning" : "schema warnings", o = t.size === 1 ? "component" : "components", i = [""];
903
+ i.push(` ${Pt}${le}nimpress modules${et} ${Ot}${n} ${s} in ${t.size} ${o}${et}`), i.push("");
904
+ for (const [c, u] of t) {
905
+ const b = u.find((w) => w.sourceFile)?.sourceFile;
906
+ i.push(` ${$n}${le}${c}${et}${b ? ` ${oe}${jt(e, b)}${et}` : ""}`);
907
+ const d = Math.max(...u.map((w) => (w.line ? `L${w.line}` : "·").length)), m = Math.max(...u.map((w) => (w.path || "(component)").length));
908
+ for (const w of u) {
909
+ const k = (w.line ? `L${w.line}` : "·").padStart(d), P = (w.path || "(component)").padEnd(m);
910
+ i.push(` ${Ot}${k}${et} ${Pt}${P}${et} ${Wo(w.detail)}`);
911
+ }
912
+ for (const w of new Set(u.map((k) => k.kind)))
913
+ i.push(` ${Pt}→${et} ${oe}${Ro[w]}${et}`);
914
+ i.push(` ${Pt}→${et} ${oe}then run${et} nimpress modules update ${c}`), i.push("");
915
+ }
916
+ console.warn(i.join(`
917
+ `));
918
+ }
919
+ function pn(e, t) {
920
+ if (!e) return;
921
+ const n = t.split(".").filter((c) => c && c !== "[]").pop();
922
+ if (!n) return;
923
+ const s = e.split(`
924
+ `), o = new RegExp(`(^|[^\\w$])${n}\\s*[?:]`);
925
+ for (let c = 0; c < s.length; c++)
926
+ if (o.test(s[c])) return c + 1;
927
+ const i = new RegExp(`\\b${n}\\b`);
928
+ for (let c = 0; c < s.length; c++)
929
+ if (i.test(s[c])) return c + 1;
930
+ }
931
+ function un(e, t, n = {}) {
932
+ const s = [], o = Ie(e, t);
933
+ for (const i of o.props.filter((c) => !c.description))
934
+ s.push({ component: e, sourceFile: n.sourceFile, line: pn(n.sourceText, i.name), path: i.name, detail: "has no description", kind: "undocumented" });
935
+ for (const i of $s(o.props))
936
+ s.push({ component: e, sourceFile: n.sourceFile, line: pn(n.sourceText, i.path), path: i.path, detail: `type ${i.type} is opaque`, kind: "opaque" });
937
+ for (const i of n.report?.missing ?? [])
938
+ s.push({ component: e, sourceFile: n.sourceFile, path: i, detail: "has no counterpart in the component source", kind: "orphan" });
939
+ return s;
940
+ }
941
+ async function He(e, t, n, s) {
942
+ if (!n) return;
943
+ const o = Ss(t, n.props, n.slots, n.emits), i = s ? await it(s, "utf-8").catch(() => {
944
+ }) : void 0, c = Gt(e);
945
+ if (!c) {
946
+ const k = W(e, "schema.json");
947
+ await nt(k, Jt(o, "json")), console.log(`nimpress modules: ${t} schema seeded at ${k} — the file is yours to author from here`), ln(un(t, o, { sourceFile: s, sourceText: i }));
948
+ return;
949
+ }
950
+ const u = await it(c.path, "utf-8");
951
+ let b;
952
+ try {
953
+ b = Vt(u, c.form);
954
+ } catch (k) {
955
+ console.warn(`nimpress modules: ${t} ${Mt(c.path)} failed to parse, left untouched: ${String(k)}`);
956
+ return;
957
+ }
958
+ const { merged: d, report: m } = Le(b, o), w = Jt(d, c.form);
959
+ if (w !== u) {
960
+ await nt(c.path, w);
961
+ const k = m.added.length ? `, added ${m.added.join(", ")}` : "";
962
+ console.log(`nimpress modules: ${t} schema upserted at ${c.path}${k}`);
963
+ }
964
+ ln(un(t, d, { sourceFile: s, sourceText: i, report: m }));
965
+ }
966
+ const fn = /* @__PURE__ */ new Map();
967
+ async function Lo(e, t, n, s) {
968
+ let o;
969
+ try {
970
+ o = await it(n, "utf-8");
971
+ } catch {
972
+ return;
973
+ }
974
+ const i = bn("sha1").update(o).digest("hex");
975
+ if (fn.get(n) === i) return;
976
+ fn.set(n, i);
977
+ const c = await We(n, s, t);
978
+ c && await He(e, t, c, n);
979
+ }
980
+ async function ei(e, t) {
981
+ const n = Gt(e);
982
+ if (!n) {
983
+ await nt(W(e, "schema.json"), Jt(t, "json"));
984
+ return;
985
+ }
986
+ const s = await it(n.path, "utf-8"), o = Vt(s, n.form), { merged: i } = Le(t, o);
987
+ await nt(n.path, Jt(i, n.form));
988
+ }
989
+ function De(e) {
990
+ const t = _e(e);
991
+ return t === ".vue" ? "vue" : t === ".svelte" ? "svelte" : null;
992
+ }
993
+ function Ho(e, t, n) {
994
+ for (const [s, o] of Object.entries(t.modules.systems)) {
995
+ if (!o.source) continue;
996
+ const i = q(e, o.source);
997
+ if (n.startsWith(i + "/") || n.startsWith(i + "\\")) return s;
998
+ }
999
+ return null;
1000
+ }
1001
+ function Uo(e, t, n) {
1002
+ return e.find((s) => s.system === t && s.component === n);
1003
+ }
1004
+ async function Jo(e, t, n) {
1005
+ const s = await Re(e, t.contentDir), o = q(e, n);
1006
+ if ((n.includes("/") || n.includes("\\")) && dt(o)) {
1007
+ const d = De(o);
1008
+ if (!d)
1009
+ throw new Error(`[nimpress] modules: ${n} is not a .vue or .svelte component file`);
1010
+ const m = Mt(o, _e(o)), w = Ho(e, t, o);
1011
+ if (!w)
1012
+ throw new Error(`[nimpress] modules: ${n} sits under no configured system source`);
1013
+ const k = Uo(s, w, m);
1014
+ if (!k)
1015
+ throw new Error(
1016
+ `[nimpress] modules: no component page found for ${w}/${m}, run nimpress modules create ${w} ${m} first`
1017
+ );
1018
+ return { system: w, component: m, framework: d, componentFile: o, pageDir: G(k.pageFile) };
1019
+ }
1020
+ const i = s.filter((d) => d.component === n);
1021
+ if (!i.length)
1022
+ throw new Error(`[nimpress] modules: no component page found for ${n}`);
1023
+ if (i.length > 1) {
1024
+ const d = i.map((m) => `${m.system}/${m.component}`).join(", ");
1025
+ throw new Error(`[nimpress] modules: ${n} is ambiguous across ${d}, pass the component file path`);
1026
+ }
1027
+ const c = i[0], u = ue(e, t.modules, c.system, c.component, c.file);
1028
+ if (!u)
1029
+ throw new Error(
1030
+ `[nimpress] modules: no source file found for ${c.system}/${c.component}, the schema upsert needs the component source`
1031
+ );
1032
+ const b = De(u.componentFile) ?? u.systemConfig.framework;
1033
+ return {
1034
+ system: c.system,
1035
+ component: c.component,
1036
+ framework: b,
1037
+ componentFile: u.componentFile,
1038
+ pageDir: G(c.pageFile)
1039
+ };
1040
+ }
1041
+ async function qo(e, t, n) {
1042
+ const s = await Jo(e, t, n), o = await We(s.componentFile, s.framework, s.component);
1043
+ if (!o)
1044
+ throw new Error(`[nimpress] modules: schema parse produced nothing for ${s.component}`);
1045
+ await He(s.pageDir, s.component, o);
1046
+ const i = Gt(s.pageDir);
1047
+ return jt(e, i?.path ?? W(s.pageDir, "schema.json"));
1048
+ }
1049
+ async function ni(e, t, n = {}) {
1050
+ if (n.ref)
1051
+ return await qo(e, t, n.ref), 1;
1052
+ const s = await Re(e, t.contentDir);
1053
+ let o = 0;
1054
+ for (const i of s) {
1055
+ if (n.system && i.system !== n.system) continue;
1056
+ const c = ue(e, t.modules, i.system, i.component, i.file);
1057
+ if (!c) {
1058
+ console.warn(`nimpress modules: no source for ${i.system}/${i.component}, skipped`);
1059
+ continue;
1060
+ }
1061
+ const u = De(c.componentFile) ?? c.systemConfig.framework, b = await We(c.componentFile, u, i.component);
1062
+ b && (await He(G(i.pageFile), i.component, b), o++);
1063
+ }
1064
+ return o;
1065
+ }
1066
+ function zo(e) {
1067
+ let t = e;
1068
+ for (let n = 0; n < 8; n++) {
1069
+ if (t.endsWith("/src")) return t;
1070
+ const s = G(t);
1071
+ if (s === t) return null;
1072
+ t = s;
1073
+ }
1074
+ return null;
1075
+ }
1076
+ function mn(e, t) {
1077
+ return !e.endsWith(".vue") && !e.endsWith(".svelte") ? t : [...t.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g)].map((n) => n[1]).join(`
1078
+ `);
1079
+ }
1080
+ async function Go(e, t, n) {
1081
+ const s = zo(e), o = /* @__PURE__ */ new Set([q(t)]), i = [{ file: t, text: n, depth: 0 }];
1082
+ let c = "";
1083
+ for (; i.length; ) {
1084
+ const u = i.shift();
1085
+ if (!u || u.depth >= 3) continue;
1086
+ const b = mn(u.file, u.text);
1087
+ for (const d of b.matchAll(/from\s+['"]([^'"]+)['"]/g)) {
1088
+ const m = d[1];
1089
+ let w = null;
1090
+ if (m.startsWith(".") ? w = q(G(u.file), m) : m.startsWith("@/") && s && (w = q(s, m.slice(2))), !w || !vt(w)) continue;
1091
+ const P = [w, `${w}.ts`, `${w}.vue`, W(w, "index.ts")].find((H) => Vo(H));
1092
+ if (!P) continue;
1093
+ const O = q(P);
1094
+ if (o.has(O) || o.size > 50) continue;
1095
+ o.add(O);
1096
+ const E = await it(P, "utf-8");
1097
+ c += mn(P, E) + `
1098
+ `, i.push({ file: P, text: E, depth: u.depth + 1 });
1099
+ }
1100
+ }
1101
+ return c;
1102
+ }
1103
+ function Vo(e) {
1104
+ try {
1105
+ return ie(e).isFile();
1106
+ } catch {
1107
+ return !1;
1108
+ }
1109
+ }
1110
+ async function Xo(e, t, n, s) {
1111
+ const o = await it(t, "utf-8");
1112
+ let i = "";
1113
+ for (const u of pe(e))
1114
+ u.endsWith(".ts") && (u.endsWith(".stories.ts") || u.endsWith(".story.ts") || (i += await it(W(e, u), "utf-8"), i += `
1115
+ `));
1116
+ i += await Go(e, t, o);
1117
+ const c = n === "vue" ? Oo(o, s, i) : Mo(o, s, i);
1118
+ for (const u of c.props) {
1119
+ if (!u.format) {
1120
+ const b = xs(u);
1121
+ b && (u.format = b);
1122
+ }
1123
+ u.mock || (u.mock = ks(u.name, Ps(u)));
1124
+ }
1125
+ return c;
1126
+ }
1127
+ async function Yo(e) {
1128
+ const { cwd: t, modules: n, pageFile: s, data: o, editable: i } = e, c = String(o.system ?? ""), u = String(o.component ?? ""), b = typeof o.file == "string" ? o.file : void 0, d = await No(G(s)), m = ue(t, n, c, u, b), w = [];
1129
+ if (i && m) {
1130
+ const _ = m.componentFile.endsWith(".svelte") ? "svelte" : "vue";
1131
+ try {
1132
+ await Lo(G(s), u, m.componentFile, _);
1133
+ } catch (A) {
1134
+ console.warn(`nimpress modules: ${c}/${u} schema upsert failed: ${String(A)}`);
1135
+ }
1136
+ }
1137
+ let k;
1138
+ const P = Gt(G(s));
1139
+ if (P) {
1140
+ w.push(P.path);
1141
+ try {
1142
+ k = Vt(await it(P.path, "utf-8"), P.form);
1143
+ } catch (_) {
1144
+ console.warn(`nimpress modules: ${c}/${u} ${P.form} schema failed to parse: ${String(_)}`);
1145
+ }
1146
+ } else
1147
+ console.warn(
1148
+ `nimpress modules: ${c}/${u} has no schema file, controls stay empty, run nimpress modules update ${u}`
1149
+ );
1150
+ let O, E;
1151
+ if (m)
1152
+ w.push(m.componentFile), E = jt(t, m.claudeMdPath), dt(m.claudeMdPath) && (O = await it(m.claudeMdPath, "utf-8"), w.push(m.claudeMdPath));
1153
+ else {
1154
+ const _ = typeof o.package == "string" ? o.package : n.systems[c]?.package;
1155
+ if (_) {
1156
+ const A = _o(t, _, u);
1157
+ if (A) {
1158
+ const L = A.replace(/[^/]+$/, "CLAUDE.md");
1159
+ dt(L) && (O = await it(L, "utf-8"));
1160
+ }
1161
+ }
1162
+ }
1163
+ const H = o.schema && typeof o.schema == "object" && !Array.isArray(o.schema) ? o.schema : void 0;
1164
+ H && (k = k ? Le(H, k).merged : H);
1165
+ const K = k ? Ie(u, k) : void 0, st = n.route.replace(/\/$/, "");
1166
+ return {
1167
+ data: {
1168
+ system: c,
1169
+ component: u,
1170
+ package: typeof o.package == "string" ? o.package : void 0,
1171
+ version: typeof o.version == "string" ? o.version : void 0,
1172
+ claudeMd: O,
1173
+ claudeMdPath: E,
1174
+ editable: i && !!m,
1175
+ harnessPath: `${st}/${encodeURIComponent(c)}/${encodeURIComponent(u)}/`,
1176
+ schema: K,
1177
+ schemaPath: P ? jt(t, P.path) : void 0,
1178
+ stories: d
1179
+ },
1180
+ watchFiles: w
1181
+ };
1182
+ }
1183
+ function En(e, t) {
1184
+ return q(e, t.paths.out);
1185
+ }
1186
+ function Dn(e, t, ...n) {
1187
+ return q(e, t.paths.cache, ...n);
1188
+ }
1189
+ function si(e, t) {
1190
+ return W(e, t.paths.guarded);
1191
+ }
1192
+ function Ko(e) {
1193
+ const t = /* @__PURE__ */ new Map();
1194
+ for (const u of Object.values(e))
1195
+ u.type === "chunk" && t.set(u.fileName, u);
1196
+ const n = /* @__PURE__ */ new Map(), s = [], o = [], i = (u) => {
1197
+ const b = t.get(u);
1198
+ return b ? b.facadeModuleId ?? Object.keys(b.modules)[0] ?? u : u;
1199
+ }, c = (u) => {
1200
+ n.set(u, 1), s.push(u);
1201
+ for (const b of t.get(u)?.imports ?? []) {
1202
+ if (!t.has(b)) continue;
1203
+ const d = n.get(b);
1204
+ if (d === 1) {
1205
+ const m = s.slice(s.indexOf(b)).concat(b);
1206
+ o.push({ chunks: m, modules: m.map(i) });
1207
+ } else d || c(b);
1208
+ }
1209
+ s.pop(), n.set(u, 2);
1210
+ };
1211
+ for (const u of t.keys())
1212
+ n.get(u) || c(u);
1213
+ return o;
1214
+ }
1215
+ function An() {
1216
+ return {
1217
+ name: "nimpress:chunk-cycle-guard",
1218
+ apply: "build",
1219
+ generateBundle(e, t) {
1220
+ const n = Ko(t);
1221
+ if (!n.length) return;
1222
+ const s = n.map((o) => {
1223
+ const i = o.chunks.join(" -> "), c = o.modules.map((u) => ` ${u}`).join(`
1224
+ `);
1225
+ return ` ${i}
1226
+ ${c}`;
1227
+ }).join(`
1228
+ `);
1229
+ this.error(
1230
+ `[nimpress] circular chunk imports in the emitted bundle:
1231
+ ${s}
1232
+ A module shared across chunks statically imports a component that got its own chunk, and that component imports the shared side back. Evaluating either chunk first throws a ReferenceError on the deployed static site. Load components from registries and shared modules through dynamic imports, in vue via defineAsyncComponent.`
1233
+ );
1234
+ }
1235
+ };
1236
+ }
1237
+ function Ue(e, t) {
1238
+ if (!t) return e;
1239
+ const n = { ...e };
1240
+ for (const [s, o] of Object.entries(t)) {
1241
+ if (o === void 0) continue;
1242
+ const i = n[s], c = (u) => typeof u == "object" && u !== null && !Array.isArray(u);
1243
+ c(i) && c(o) ? n[s] = Ue(i, o) : n[s] = o;
1244
+ }
1245
+ return n;
1246
+ }
1247
+ function oi(e) {
1248
+ const { cwd: t, command: n, resolved: s, htmlInput: o } = e, i = {
1249
+ root: t,
1250
+ base: s.base,
1251
+ configFile: !1,
1252
+ publicDir: !1,
1253
+ appType: "custom",
1254
+ plugins: [
1255
+ As({ compilerOptions: { runes: !0, dev: n === "serve" } }),
1256
+ Cs(),
1257
+ Ar({ ...s, modules: Object.values(s.modules.systems) }),
1258
+ An()
1259
+ ],
1260
+ cacheDir: Dn(t, s, "site"),
1261
+ build: {
1262
+ outDir: En(t, s),
1263
+ emptyOutDir: !0,
1264
+ target: "es2022",
1265
+ ...o ? { rollupOptions: { input: o } } : {}
1266
+ }
1267
+ };
1268
+ return Ue(i, s.vite);
1269
+ }
1270
+ const Zo = 6161, Ae = "virtual:nimpress-harness/";
1271
+ function Ce(e, t) {
1272
+ const n = e.systems[t]?.port;
1273
+ if (n) return n;
1274
+ const s = Object.keys(e.systems).sort();
1275
+ return Zo + Math.max(0, s.indexOf(t));
1276
+ }
1277
+ function Cn(e, t) {
1278
+ return `${Ae}${e}/${t}/entry`;
1279
+ }
1280
+ function On() {
1281
+ return `const params = new URLSearchParams(location.search)
1282
+ function parseParam(name) {
1283
+ const raw = params.get(name)
1284
+ if (!raw) return undefined
1285
+ try { return JSON.parse(decodeURIComponent(escape(atob(raw)))) } catch { return undefined }
1286
+ }
1287
+ const state = {
1288
+ props: parseParam('props') ?? {},
1289
+ slots: parseParam('slots') ?? {},
1290
+ emits: parseParam('emits') ?? [],
1291
+ shadow: params.get('shadow') === '1',
1292
+ controlled: false
1293
+ }
1294
+ function applyTheme(mode) {
1295
+ if (mode !== 'light' && mode !== 'dark') return
1296
+ document.documentElement.classList.toggle('dark', mode === 'dark')
1297
+ document.documentElement.dataset.theme = mode
1298
+ const host = document.getElementById('host')
1299
+ if (host) host.style.colorScheme = mode
1300
+ }
1301
+ applyTheme(params.get('theme'))
1302
+ function safeArgs(args) {
1303
+ try { return JSON.parse(JSON.stringify(args)) } catch { return [] }
1304
+ }
1305
+ function evalOut(value) {
1306
+ if (value === undefined) return 'undefined'
1307
+ try { return JSON.parse(JSON.stringify(value)) } catch { return String(value) }
1308
+ }
1309
+ function runEval(code) {
1310
+ parent.postMessage({ type: 'nimpress:console', level: 'input', args: [code] }, '*')
1311
+ try {
1312
+ const result = (0, eval)(code)
1313
+ Promise.resolve(result).then(
1314
+ (value) => parent.postMessage({ type: 'nimpress:console', level: 'result', args: [evalOut(value)] }, '*'),
1315
+ (err) => parent.postMessage({ type: 'nimpress:console', level: 'error', args: [String(err)] }, '*')
1316
+ )
1317
+ } catch (err) {
1318
+ parent.postMessage({ type: 'nimpress:console', level: 'error', args: [String(err)] }, '*')
1319
+ }
1320
+ }
1321
+ function emitOut(name, args) {
1322
+ parent.postMessage({ type: 'nimpress:emit', name, args: safeArgs(args) }, '*')
1323
+ }
1324
+ for (const level of ['log', 'info', 'warn', 'error', 'debug']) {
1325
+ const original = console[level].bind(console)
1326
+ console[level] = (...args) => {
1327
+ original(...args)
1328
+ parent.postMessage({ type: 'nimpress:console', level, args: safeArgs(args) }, '*')
1329
+ }
1330
+ }
1331
+ window.addEventListener('error', (event) => {
1332
+ parent.postMessage({ type: 'nimpress:console', level: 'error', args: [String(event.message)] }, '*')
1333
+ })
1334
+ window.addEventListener('unhandledrejection', (event) => {
1335
+ parent.postMessage({ type: 'nimpress:console', level: 'error', args: ['unhandled rejection: ' + String(event.reason)] }, '*')
1336
+ })
1337
+ function emitEntries(emits) {
1338
+ if (Array.isArray(emits)) return emits.map((name) => [name, null])
1339
+ if (emits && typeof emits === 'object') return Object.entries(emits)
1340
+ return []
1341
+ }
1342
+ function bindEmit(name, source) {
1343
+ let user = null
1344
+ if (source) {
1345
+ try {
1346
+ user = new Function('return (' + source + ')')()
1347
+ } catch (err) {
1348
+ console.error('handler ' + name + ' failed to compile', err)
1349
+ }
1350
+ }
1351
+ return (...args) => {
1352
+ emitOut(name, args)
1353
+ if (user) {
1354
+ try {
1355
+ user(...args)
1356
+ } catch (err) {
1357
+ console.error('handler ' + name + ' threw', err)
1358
+ }
1359
+ }
1360
+ }
1361
+ }
1362
+ function materializeFns(props, path) {
1363
+ for (const [key, value] of Object.entries(props)) {
1364
+ const label = path ? path + '.' + key : key
1365
+ if (value && typeof value === 'object' && typeof value.__nimpressFn === 'string') {
1366
+ let fn
1367
+ try {
1368
+ fn = new Function('return (' + value.__nimpressFn + ')')()
1369
+ } catch (err) {
1370
+ console.error('nimpress fn ' + label + ' failed to compile', err)
1371
+ continue
1372
+ }
1373
+ props[key] = (...args) => {
1374
+ emitOut(label, args)
1375
+ return fn(...args)
1376
+ }
1377
+ } else if (value && typeof value === 'object') {
1378
+ materializeFns(value, label)
1379
+ }
1380
+ }
1381
+ return props
1382
+ }
1383
+ window.addEventListener('message', (event) => {
1384
+ const d = event.data
1385
+ if (!d) return
1386
+ if (d.type === 'nimpress:eval') {
1387
+ runEval(String(d.code ?? ''))
1388
+ return
1389
+ }
1390
+ if (d.type !== 'nimpress:props') return
1391
+ if (d.props !== undefined) {
1392
+ state.props = d.props
1393
+ state.controlled = true
1394
+ }
1395
+ if (d.slots !== undefined) state.slots = d.slots
1396
+ if (d.emits !== undefined) state.emits = d.emits
1397
+ if (d.theme !== undefined) applyTheme(d.theme)
1398
+ if (d.shadow !== undefined) state.shadow = !!d.shadow
1399
+ if (globalThis.__nimpressSync) globalThis.__nimpressSync()
1400
+ })
1401
+ window.addEventListener('wheel', (event) => {
1402
+ if (!event.ctrlKey && !event.metaKey) return
1403
+ event.preventDefault()
1404
+ parent.postMessage({ type: 'nimpress:zoom', delta: event.deltaY }, '*')
1405
+ }, { passive: false })
1406
+ let gestureBase = 1
1407
+ window.addEventListener('gesturestart', (event) => {
1408
+ event.preventDefault()
1409
+ gestureBase = event.scale ?? 1
1410
+ })
1411
+ window.addEventListener('gesturechange', (event) => {
1412
+ event.preventDefault()
1413
+ const scale = event.scale ?? 1
1414
+ parent.postMessage({ type: 'nimpress:zoomscale', scale: scale / gestureBase }, '*')
1415
+ gestureBase = scale
1416
+ })
1417
+ let panX = 0
1418
+ let panY = 0
1419
+ let panning = null
1420
+ function stageEl() {
1421
+ return document.getElementById('stage')
1422
+ }
1423
+ function applyPan() {
1424
+ const stage = stageEl()
1425
+ if (stage) stage.style.transform = panX || panY ? 'translate(' + panX + 'px, ' + panY + 'px)' : ''
1426
+ }
1427
+ window.addEventListener('pointerdown', (event) => {
1428
+ const pan = event.button === 1 || (event.button === 0 && (event.metaKey || event.ctrlKey))
1429
+ if (!pan) return
1430
+ event.preventDefault()
1431
+ panning = { x: event.clientX, y: event.clientY, tx: panX, ty: panY }
1432
+ document.documentElement.style.cursor = 'grabbing'
1433
+ })
1434
+ window.addEventListener('pointermove', (event) => {
1435
+ if (!panning) return
1436
+ panX = panning.tx + (event.clientX - panning.x)
1437
+ panY = panning.ty + (event.clientY - panning.y)
1438
+ applyPan()
1439
+ })
1440
+ window.addEventListener('pointerup', () => {
1441
+ if (!panning) return
1442
+ panning = null
1443
+ document.documentElement.style.cursor = ''
1444
+ })
1445
+ window.addEventListener('dblclick', (event) => {
1446
+ if (!(event.metaKey || event.ctrlKey)) return
1447
+ panX = 0
1448
+ panY = 0
1449
+ applyPan()
1450
+ })`;
1451
+ }
1452
+ function Mn(e) {
1453
+ const t = e.named ? `mod[${JSON.stringify(e.component)}]` : "mod.default ?? mod";
1454
+ return `let ComponentRef = null
1455
+ async function ensureComponent() {
1456
+ if (!ComponentRef) {
1457
+ const mod = await import(${JSON.stringify(e.importSpec)})
1458
+ ComponentRef = ${t}
1459
+ }
1460
+ return ComponentRef
1461
+ }`;
1462
+ }
1463
+ function _n(e) {
1464
+ return `const storyLoaders = {
1465
+ ${(e.storyFiles ?? []).map((n) => ` ${JSON.stringify(n.base)}: () => import(${JSON.stringify(n.path)})`).join(`,
1466
+ `)}
1467
+ }
1468
+ const activeLoader = storyLoaders[params.get('story') ?? '']
1469
+ const activeStoryDef = activeLoader ? (await activeLoader()).default : null`;
1470
+ }
1471
+ function Tn(e) {
1472
+ return e ? `import harnessSetup from ${JSON.stringify(e)}` : "const harnessSetup = null";
1473
+ }
1474
+ function Qo(e, t, n, s, o) {
1475
+ const i = t.map((u) => `import ${JSON.stringify(u)}`).join(`
1476
+ `), c = s ? `import HarnessOverride from ${JSON.stringify(s)}` : "const HarnessOverride = null";
1477
+ return `import { createApp, h } from 'vue'
1478
+ import { DefaultHarness, ComponentStory, createHarnessContext, HARNESS_KEY } from '@nimtech/nimpress/harness/vue'
1479
+ ${i}
1480
+ ${Tn(n)}
1481
+ ${c}
1482
+
1483
+ ${On()}
1484
+ ${_n(e)}
1485
+ ${Mn(e)}
1486
+
1487
+ const setupDef = typeof harnessSetup === 'function' ? await harnessSetup() : harnessSetup
1488
+ const Overlay = setupDef ? (setupDef.companion ?? null) : null
1489
+ const Harness = HarnessOverride ?? DefaultHarness
1490
+
1491
+ function installBaseline(app) {
1492
+ if (setupDef && typeof setupDef.install === 'function') {
1493
+ setupDef.install(app)
1494
+ }
1495
+ }
1496
+
1497
+ const ctx = createHarnessContext()
1498
+ ctx.overlay.value = Overlay
1499
+ const isRenderStory = activeStoryDef && typeof activeStoryDef.render === 'function'
1500
+
1501
+ const requiredDefaults = ${JSON.stringify(o)}
1502
+ const storyProps = activeStoryDef && activeStoryDef.props ? activeStoryDef.props : {}
1503
+ const storySlots = activeStoryDef && activeStoryDef.slots ? activeStoryDef.slots : {}
1504
+
1505
+ function cloneValue(value) {
1506
+ try { return structuredClone(value) } catch { return value }
1507
+ }
1508
+
1509
+ function buildProps() {
1510
+ const props = structuredClone(state.props)
1511
+ if (!state.controlled) {
1512
+ for (const [prop, value] of Object.entries(storyProps)) {
1513
+ if (props[prop] === undefined) props[prop] = cloneValue(value)
1514
+ }
1515
+ for (const [prop, value] of Object.entries(requiredDefaults)) {
1516
+ if (props[prop] === undefined) props[prop] = cloneValue(value)
1517
+ }
1518
+ }
1519
+ materializeFns(props)
1520
+ for (const [name, source] of emitEntries(state.emits)) {
1521
+ const key = 'on' + name.replace(/[:.-](\\w)/g, (_, c) => c.toUpperCase()).replace(/^\\w/, (c) => c.toUpperCase())
1522
+ props[key] = bindEmit(name, source)
1523
+ }
1524
+ return props
1525
+ }
1526
+
1527
+ function buildSlots() {
1528
+ const slots = {}
1529
+ const source = state.controlled ? state.slots : { ...storySlots, ...state.slots }
1530
+ for (const [name, html] of Object.entries(source)) {
1531
+ slots[name] = () => h('span', { innerHTML: String(html) })
1532
+ }
1533
+ return slots
1534
+ }
1535
+
1536
+ function sync() {
1537
+ ctx.shadow.value = state.shadow
1538
+ if (!isRenderStory) {
1539
+ ctx.props.value = buildProps()
1540
+ ctx.slots.value = buildSlots()
1541
+ }
1542
+ }
1543
+ globalThis.__nimpressSync = sync
1544
+
1545
+ try {
1546
+ ctx.component.value = isRenderStory ? activeStoryDef.render() : await ensureComponent()
1547
+ sync()
1548
+ const StoryHarness = activeStoryDef && activeStoryDef.harness ? activeStoryDef.harness : null
1549
+ const Root = {
1550
+ render() {
1551
+ const leaf = h(ComponentStory)
1552
+ const inner = StoryHarness ? h(StoryHarness, null, { default: () => leaf }) : leaf
1553
+ return h(Harness, null, { default: () => inner })
1554
+ }
1555
+ }
1556
+ const app = createApp(Root)
1557
+ app.provide(HARNESS_KEY, ctx)
1558
+ installBaseline(app)
1559
+ app.mount('#stage')
1560
+ } catch (err) {
1561
+ console.error(err)
1562
+ document.getElementById('host').innerText = String(err)
1563
+ parent.postMessage({ type: 'nimpress:error', message: String(err) }, '*')
1564
+ }
1565
+ parent.postMessage({ type: 'nimpress:ready' }, '*')
1566
+ `;
1567
+ }
1568
+ function tr(e, t, n, s, o) {
1569
+ const i = t.map((u) => `import ${JSON.stringify(u)}`).join(`
1570
+ `), c = s ? `import HarnessOverride from ${JSON.stringify(s)}` : "const HarnessOverride = null";
1571
+ return `import { mount, createRawSnippet } from 'svelte'
1572
+ import { DefaultHarness, HarnessRoot, createHarnessContext } from '@nimtech/nimpress/harness/svelte'
1573
+ ${i}
1574
+ ${Tn(n)}
1575
+ ${c}
1576
+
1577
+ ${On()}
1578
+ ${_n(e)}
1579
+ ${Mn(e)}
1580
+
1581
+ if (typeof harnessSetup === 'function') await harnessSetup()
1582
+
1583
+ const Harness = HarnessOverride ?? DefaultHarness
1584
+ const ctx = createHarnessContext()
1585
+ const isRenderStory = activeStoryDef && activeStoryDef.component
1586
+
1587
+ const requiredDefaults = ${JSON.stringify(o)}
1588
+ const storyProps = activeStoryDef && activeStoryDef.props ? activeStoryDef.props : {}
1589
+ const storySlots = activeStoryDef && activeStoryDef.slots ? activeStoryDef.slots : {}
1590
+
1591
+ function cloneValue(value) {
1592
+ try { return structuredClone(value) } catch { return value }
1593
+ }
1594
+
1595
+ function buildProps() {
1596
+ const props = structuredClone(state.props)
1597
+ if (!state.controlled) {
1598
+ for (const [prop, value] of Object.entries(storyProps)) {
1599
+ if (props[prop] === undefined) props[prop] = cloneValue(value)
1600
+ }
1601
+ for (const [prop, value] of Object.entries(requiredDefaults)) {
1602
+ if (props[prop] === undefined) props[prop] = cloneValue(value)
1603
+ }
1604
+ }
1605
+ materializeFns(props)
1606
+ for (const [name, source] of emitEntries(state.emits)) {
1607
+ props[name] = bindEmit(name, source)
1608
+ }
1609
+ const slotSource = state.controlled ? state.slots : { ...storySlots, ...state.slots }
1610
+ for (const [name, html] of Object.entries(slotSource)) {
1611
+ props[name] = createRawSnippet(() => ({ render: () => '<span>' + String(html) + '</span>' }))
1612
+ }
1613
+ return props
1614
+ }
1615
+
1616
+ function sync() {
1617
+ ctx.shadow = state.shadow
1618
+ ctx.props = buildProps()
1619
+ }
1620
+ globalThis.__nimpressSync = sync
1621
+
1622
+ try {
1623
+ ctx.component = isRenderStory ? activeStoryDef.component : await ensureComponent()
1624
+ sync()
1625
+ const StoryHarness = activeStoryDef && activeStoryDef.harness ? activeStoryDef.harness : null
1626
+ mount(HarnessRoot, { target: document.getElementById('stage'), props: { ctx, harness: Harness, storyHarness: StoryHarness } })
1627
+ } catch (err) {
1628
+ console.error(err)
1629
+ document.getElementById('host').innerText = String(err)
1630
+ parent.postMessage({ type: 'nimpress:error', message: String(err) }, '*')
1631
+ }
1632
+ parent.postMessage({ type: 'nimpress:ready' }, '*')
1633
+ `;
1634
+ }
1635
+ function er(e) {
1636
+ if (!e.schemaFile || !dt(e.schemaFile)) return {};
1637
+ let t;
1638
+ try {
1639
+ t = Vt(zt(e.schemaFile, "utf-8"), e.schemaFile.endsWith(".yml") ? "yml" : "json");
1640
+ } catch {
1641
+ return {};
1642
+ }
1643
+ const n = Ie(e.component, t), s = {};
1644
+ for (const o of n.props) {
1645
+ if (!o.required) continue;
1646
+ const i = o.default !== void 0 ? o.default : js(o, 0);
1647
+ i !== void 0 && (s[o.name] = i);
1648
+ }
1649
+ return s;
1650
+ }
1651
+ function nr(e, t, n, s, o) {
1652
+ const i = er(t);
1653
+ return e === "vue" ? Qo(t, n, s, o, i) : tr(t, n, s, o, i);
1654
+ }
1655
+ function dn(e, t, n) {
1656
+ const s = n.map((o) => ` <link rel="stylesheet" href="${o}" />`).join(`
1657
+ `);
1658
+ return `<!doctype html>
1659
+ <html lang="en">
1660
+ <head>
1661
+ <meta charset="utf-8" />
1662
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
1663
+ <meta name="robots" content="noindex" />
1664
+ <title>${e}</title>
1665
+ <style>
1666
+ * { box-sizing: border-box; }
1667
+ html, body { margin: 0; padding: 0; background: transparent !important; overflow: hidden; }
1668
+ html { color-scheme: light !important; }
1669
+ body { color: #18181b; }
1670
+ html.dark body { color: #e4e4e7; }
1671
+ #host { position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: 0; padding: 24px; overflow: auto; display: flex; }
1672
+ #stage { margin: auto; flex-shrink: 0; display: flex; align-items: center; justify-content: center; will-change: transform; }
1673
+ </style>
1674
+ ${s ? s + `
1675
+ ` : ""} </head>
1676
+ <body>
1677
+ <div id="host"><div id="stage"></div></div>
1678
+ <script type="module" src="${t}"><\/script>
1679
+ </body>
1680
+ </html>
1681
+ `;
1682
+ }
1683
+ async function sr(e, t) {
1684
+ if (t === "svelte") {
1685
+ const { svelte: u } = await import("@sveltejs/vite-plugin-svelte");
1686
+ return u();
1687
+ }
1688
+ const n = Ds(W(e, "package.json"));
1689
+ let s;
1690
+ try {
1691
+ s = n.resolve("@vitejs/plugin-vue");
1692
+ } catch {
1693
+ throw new Error("[nimpress] modules system with framework vue requires @vitejs/plugin-vue installed in the consumer");
1694
+ }
1695
+ const o = await import(tn(s).href), c = [(o.default ?? o)()];
1696
+ try {
1697
+ const u = n.resolve("@vitejs/plugin-vue-jsx"), b = await import(tn(u).href), d = b.default ?? b;
1698
+ c.push(d());
1699
+ } catch {
1700
+ }
1701
+ return c;
1702
+ }
1703
+ function or(e, t, n, s) {
1704
+ const o = t.systems[n];
1705
+ if (!o) return [];
1706
+ const i = [];
1707
+ for (const c of s) {
1708
+ if (c.system !== n) continue;
1709
+ const u = rr(c.pageFile), b = Gt(G(c.pageFile))?.path ?? W(G(c.pageFile), "schema.json"), d = o.source ? ue(e, t, n, c.component, c.file) : null;
1710
+ if (d) {
1711
+ i.push({ component: c.component, importSpec: d.componentFile, storyFiles: u, schemaFile: b });
1712
+ continue;
1713
+ }
1714
+ const m = c.package ?? o.package;
1715
+ if (m) {
1716
+ i.push({ component: c.component, importSpec: m, named: !0, storyFiles: u, schemaFile: b });
1717
+ continue;
1718
+ }
1719
+ console.warn(`[nimpress] modules: no source found for ${n}/${c.component}`);
1720
+ }
1721
+ return i;
1722
+ }
1723
+ function rr(e) {
1724
+ const t = G(e);
1725
+ let n;
1726
+ try {
1727
+ n = pe(t);
1728
+ } catch {
1729
+ return [];
1730
+ }
1731
+ return n.filter((s) => s.endsWith(".story.ts") || s.endsWith(".story.tsx")).sort().map((s) => ({
1732
+ base: s.endsWith(".story.tsx") ? Mt(s, ".story.tsx") : Mt(s, ".story.ts"),
1733
+ path: W(t, s)
1734
+ }));
1735
+ }
1736
+ function ir(e, t) {
1737
+ if (t.setup)
1738
+ return t.setup.startsWith(".") || vt(t.setup) ? q(e, t.setup) : t.setup;
1739
+ }
1740
+ function ar(e, t) {
1741
+ if (t.harness)
1742
+ return t.harness.startsWith(".") || vt(t.harness) ? q(e, t.harness) : t.harness;
1743
+ }
1744
+ function cr(e, t, n, s, o) {
1745
+ const i = (t.css ?? []).map(
1746
+ (k) => k.startsWith(".") || vt(k) ? q(e, k) : k
1747
+ ), c = ir(e, t), u = ar(e, t), b = new Map(s.map((k) => [k.component, k])), d = "\0" + Ae, m = (k) => {
1748
+ if (!k.startsWith(d)) return null;
1749
+ const P = k.slice(d.length).split("/");
1750
+ return P[0] === n && P[1] ? P[1] : null;
1751
+ }, w = (k) => nr(t.framework, k, i, c, u);
1752
+ return {
1753
+ name: "nimpress:harness",
1754
+ resolveId(k) {
1755
+ return k.startsWith(d) ? k : k.startsWith(Ae) ? "\0" + k : null;
1756
+ },
1757
+ load(k) {
1758
+ const P = m(k);
1759
+ if (!P) return null;
1760
+ const O = b.get(P);
1761
+ return O ? w(O) : null;
1762
+ },
1763
+ configureServer(k) {
1764
+ k.middlewares.use(async (P, O, E) => {
1765
+ const H = P.url;
1766
+ if (!H) return E();
1767
+ const K = H.split("?")[0];
1768
+ if (!K.startsWith(o)) return E();
1769
+ const st = K.slice(o.length).split("/").filter(Boolean), _ = st[0];
1770
+ if (!_ || !b.has(_)) return E();
1771
+ const A = st.slice(1).join("/");
1772
+ if (A === "" || A === "index.html") {
1773
+ const L = ` <script type="module" src="${o}@vite/client"><\/script>
1774
+ </head>`, ot = dn(_, "./entry.js", []).replace(" </head>", L);
1775
+ O.statusCode = 200, O.setHeader("Content-Type", "text/html"), O.end(ot);
1776
+ return;
1777
+ }
1778
+ if (A === "entry.js") {
1779
+ const L = await k.transformRequest(Cn(n, _));
1780
+ if (!L) return E();
1781
+ O.statusCode = 200, O.setHeader("Content-Type", "application/javascript"), O.end(L.code);
1782
+ return;
1783
+ }
1784
+ return E();
1785
+ });
1786
+ },
1787
+ generateBundle(k, P) {
1788
+ const O = (E, H, K) => {
1789
+ if (H.has(E)) return;
1790
+ H.add(E);
1791
+ const st = P[E];
1792
+ if (!st || st.type !== "chunk") return;
1793
+ const _ = st.viteMetadata;
1794
+ for (const A of _?.importedCss ?? []) K.add(A);
1795
+ for (const A of st.imports) O(A, H, K);
1796
+ };
1797
+ for (const E of Object.values(P)) {
1798
+ if (E.type !== "chunk" || !E.isEntry) continue;
1799
+ const H = b.get(E.name);
1800
+ if (!H) continue;
1801
+ const K = /* @__PURE__ */ new Set();
1802
+ O(E.fileName, /* @__PURE__ */ new Set(), K);
1803
+ const st = [...K].map((_) => o + _);
1804
+ this.emitFile({
1805
+ type: "asset",
1806
+ fileName: `${H.component}/index.html`,
1807
+ source: dn(H.component, o + E.fileName, st)
1808
+ });
1809
+ }
1810
+ }
1811
+ };
1812
+ }
1813
+ async function ri(e, t, n, s) {
1814
+ const o = t.modules, i = o.systems[n];
1815
+ if (!i) throw new Error(`[nimpress] unknown module system: ${n}`);
1816
+ const c = await Re(e, t.contentDir), u = or(e, o, n, c);
1817
+ u.length || console.warn(`[nimpress] modules: no component pages found for system ${n}`);
1818
+ const b = await sr(e, i.framework), d = i.source ? q(e, i.source) : e, m = o.route.replace(/\/$/, ""), w = `${m}/${n}/`, k = s === "build" ? gt(t.base, w) : w, P = u.filter((E) => vt(E.importSpec)).map((E) => E.importSpec).concat(u.flatMap((E) => (E.storyFiles ?? []).map((H) => H.path))), O = {
1819
+ root: e,
1820
+ configFile: !1,
1821
+ publicDir: !1,
1822
+ appType: "mpa",
1823
+ cacheDir: Dn(e, t, "modules", n),
1824
+ plugins: [cr(e, i, n, u, k), b, An()],
1825
+ resolve: i.framework === "vue" ? { alias: { vue: "vue/dist/vue.esm-bundler.js" } } : void 0,
1826
+ optimizeDeps: {
1827
+ entries: P,
1828
+ include: i.framework === "vue" ? ["vue"] : [],
1829
+ exclude: ["@nimtech/nimpress/harness/vue", "@nimtech/nimpress/harness/svelte"]
1830
+ },
1831
+ server: {
1832
+ host: "127.0.0.1",
1833
+ port: Ce(o, n),
1834
+ strictPort: !0,
1835
+ fs: { allow: [e, d] },
1836
+ hmr: {
1837
+ host: "127.0.0.1",
1838
+ clientPort: Ce(o, n)
1839
+ }
1840
+ },
1841
+ build: {
1842
+ outDir: W(En(e, t), m.replace(/^\//, ""), n),
1843
+ emptyOutDir: !0,
1844
+ target: "es2022",
1845
+ rollupOptions: {
1846
+ input: Object.fromEntries(u.map((E) => [E.component, Cn(n, E.component)]))
1847
+ }
1848
+ },
1849
+ base: k
1850
+ };
1851
+ return Ue(O, t.vite);
1852
+ }
1853
+ function lr(e, t = "virtual:nimpress/main") {
1854
+ return `<!doctype html>
1855
+ <html lang="en">
1856
+ <head>
1857
+ <meta charset="UTF-8" />
1858
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />${e.logo ? `
1859
+ <link rel="icon" href="${e.logo}" />` : ""}
1860
+ <title>${e.title}</title>
1861
+ <script>
1862
+ try {
1863
+ const k = 'nimpress-theme'
1864
+ const v = localStorage.getItem(k)
1865
+ const mode = v === 'light' || v === 'dark'
1866
+ ? v
1867
+ : (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
1868
+ if (mode === 'dark') document.documentElement.classList.add('dark')
1869
+ } catch {}
1870
+ <\/script>
1871
+ </head>
1872
+ <body>
1873
+ <div id="app"></div>
1874
+ <script type="module" src="${t}"><\/script>
1875
+ </body>
1876
+ </html>
1877
+ `;
1878
+ }
1879
+ const Zt = "virtual:nimpress/manifest", Qt = "virtual:nimpress/search", te = "virtual:nimpress/pages", ee = "virtual:nimpress/bodies", $e = "virtual:nimpress/config", Se = "virtual:nimpress/main", Ft = "virtual:nimpress/page-component/", _t = "virtual:nimpress/page-body/", xe = 20, pr = "https://github.com/nimling/nimpress";
1880
+ function ft(e) {
1881
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1882
+ }
1883
+ function ur(e) {
1884
+ return `<![CDATA[${e.replace(/\]\]>/g, "]]]]><![CDATA[>")}]]>`;
1885
+ }
1886
+ function hn(e) {
1887
+ return e === 0 ? "rss.xml" : `rss-${e + 1}.xml`;
1888
+ }
1889
+ const gn = [
1890
+ "Google-Extended",
1891
+ "Applebot-Extended",
1892
+ "OAI-SearchBot",
1893
+ "ChatGPT-User",
1894
+ "GPTBot",
1895
+ "Claude-SearchBot",
1896
+ "Claude-User",
1897
+ "ClaudeBot",
1898
+ "anthropic-ai",
1899
+ "PerplexityBot",
1900
+ "Perplexity-User",
1901
+ "MistralAI-User",
1902
+ "Amazonbot",
1903
+ "cohere-ai",
1904
+ "cohere-training-data-crawler",
1905
+ "CCBot",
1906
+ "Bytespider",
1907
+ "Diffbot",
1908
+ "img2dataset",
1909
+ "PetalBot",
1910
+ "YouBot",
1911
+ "Quora-Bot",
1912
+ "TikTokSpider",
1913
+ "Webzio-Extended",
1914
+ "AI2Bot",
1915
+ "Ai2Bot-Dolma",
1916
+ "omgili",
1917
+ "omgilibot",
1918
+ "aiHitBot",
1919
+ "Timpibot",
1920
+ "Kagibot",
1921
+ "ZoomBot",
1922
+ "AhrefsBot",
1923
+ "SemrushBot",
1924
+ "DotBot",
1925
+ "MJ12bot"
1926
+ ];
1927
+ function fr(e) {
1928
+ return `<script type="application/ld+json">${(typeof e == "string" ? e : JSON.stringify(e)).replace(/</g, "\\u003c")}<\/script>`;
1929
+ }
1930
+ const ke = (e) => e.visibility === "hidden", Dt = (e) => e.visibility === "hidden" || e.visibility === "dev-only", ne = (e) => e.visibility === "dev-only", mr = {
1931
+ milestone: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"/><line x1="4" x2="4" y1="22" y2="15"/></svg>',
1932
+ epic: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>',
1933
+ feature: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/><path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/></svg>',
1934
+ bug: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/></svg>'
1935
+ }, dr = f.object({
1936
+ title: f.string().optional(),
1937
+ description: f.string().optional(),
1938
+ type: f.string().optional(),
1939
+ image: f.string().optional(),
1940
+ imageAlt: f.string().optional(),
1941
+ url: f.string().optional(),
1942
+ siteName: f.string().optional(),
1943
+ locale: f.string().optional()
1944
+ }).passthrough(), hr = f.object({
1945
+ card: f.string().optional(),
1946
+ site: f.string().optional(),
1947
+ creator: f.string().optional(),
1948
+ title: f.string().optional(),
1949
+ description: f.string().optional(),
1950
+ image: f.string().optional(),
1951
+ imageAlt: f.string().optional()
1952
+ }).passthrough(), gr = f.object({
1953
+ description: f.string().optional(),
1954
+ canonical: f.string().optional(),
1955
+ robots: f.string().optional(),
1956
+ keywords: f.union([f.string(), f.array(f.string())]).optional(),
1957
+ author: f.string().optional(),
1958
+ themeColor: f.string().optional(),
1959
+ og: dr.optional(),
1960
+ twitter: hr.optional(),
1961
+ jsonLd: f.unknown().optional()
1962
+ }).passthrough(), Nn = f.object({
1963
+ title: f.string().optional(),
1964
+ slug: f.string().optional(),
1965
+ type: f.union([
1966
+ f.literal("doc"),
1967
+ f.literal("openapi"),
1968
+ f.literal("changelog"),
1969
+ f.literal("hero"),
1970
+ f.literal("roadmap"),
1971
+ f.literal("dbml"),
1972
+ f.literal("milestone"),
1973
+ f.literal("epic"),
1974
+ f.literal("feature"),
1975
+ f.literal("bug"),
1976
+ f.literal("component")
1977
+ ]).optional(),
1978
+ path: f.string().optional(),
1979
+ spec: f.string().optional(),
1980
+ gate: f.string().optional(),
1981
+ link: f.string().optional(),
1982
+ description: f.string().optional(),
1983
+ order: f.number().optional(),
1984
+ icon: f.string().optional(),
1985
+ sidebar: f.object({
1986
+ name: f.string().min(1),
1987
+ icon: f.string().optional(),
1988
+ style: f.string().optional(),
1989
+ path: f.string().optional()
1990
+ }).optional(),
1991
+ visibility: f.enum(["visible", "hidden", "dev-only"]).optional(),
1992
+ collapsed: f.boolean().optional(),
1993
+ lastUpdated: f.boolean().optional(),
1994
+ redirect: f.string().optional(),
1995
+ noToc: f.boolean().optional(),
1996
+ footer: f.string().optional(),
1997
+ background: f.string().optional(),
1998
+ tags: f.union([f.string(), f.array(f.string())]).optional(),
1999
+ rss: f.boolean().optional(),
2000
+ subscribe: f.boolean().optional(),
2001
+ meta: gr.optional(),
2002
+ data: f.record(f.unknown()).optional()
2003
+ }).passthrough();
2004
+ function Fn(e, t = "x") {
2005
+ const n = [], s = Nn.safeParse(e);
2006
+ if (!s.success) {
2007
+ for (const u of s.error.errors)
2008
+ n.push(`${u.path.join(".") || "frontmatter"}: ${u.message}`);
2009
+ return n;
2010
+ }
2011
+ const o = s.data, i = o.data ?? {};
2012
+ if (o.link)
2013
+ return !o.title && !o.sidebar?.name && n.push("a link page needs a title or a sidebar.name for its label"), /^[a-z][a-z0-9+.-]*:\/\/|^mailto:|^tel:/i.test(o.link) || n.push("link: must be an absolute url"), t.trim() !== "" && n.push("a link page carries no body, the entry opens link instead of a page"), n;
2014
+ if (e.type === void 0 && t.trim() === "")
2015
+ return o.sidebar?.name || n.push("a page without a type and without a body needs a sidebar.name to decorate its group"), n;
2016
+ if (o.title || n.push("title: Required"), o.type === "openapi" && !o.spec && n.push("type openapi requires a spec field"), o.type === "dbml" && !o.spec && n.push("type dbml requires a spec field"), o.type === "changelog") {
2017
+ (i.version === void 0 || String(i.version).trim() === "") && n.push("changelog requires data.version"), (i.release_date === void 0 || Number.isNaN(new Date(String(i.release_date)).getTime())) && n.push("changelog requires a valid data.release_date");
2018
+ const u = i.title === void 0 ? "" : String(i.title);
2019
+ u.trim() || n.push("changelog requires data.title"), u.length > 48 && n.push("changelog data.title exceeds 48 characters"), u.includes(",") && n.push("changelog data.title must not contain a comma"), i.description !== void 0 && String(i.description).length > 160 && n.push("changelog data.description exceeds 160 characters");
2020
+ }
2021
+ return (o.type === "milestone" || o.type === "epic" || o.type === "feature" || o.type === "bug") && (o.description || n.push(`type ${o.type} requires a description`), (i.date === void 0 || Number.isNaN(new Date(String(i.date)).getTime())) && n.push(`type ${o.type} requires a valid data.date`)), o.type === "component" && ((i.system === void 0 || String(i.system).trim() === "") && n.push("type component requires data.system"), (i.component === void 0 || String(i.component).trim() === "") && n.push("type component requires data.component")), n;
2022
+ }
2023
+ function yr(e, t) {
2024
+ const n = (b) => {
2025
+ const d = String(b ?? "").replace(/^v/i, "").replace(/\+.*$/, ""), m = d.indexOf("-");
2026
+ return {
2027
+ base: (m === -1 ? d : d.slice(0, m)).split("."),
2028
+ pre: m === -1 ? "" : d.slice(m + 1)
2029
+ };
2030
+ }, s = (b, d) => {
2031
+ const m = b.match(/\d+|\D+/g) ?? [], w = d.match(/\d+|\D+/g) ?? [];
2032
+ for (let k = 0; k < Math.max(m.length, w.length); k++) {
2033
+ const P = m[k], O = w[k];
2034
+ if (P === void 0) return -1;
2035
+ if (O === void 0) return 1;
2036
+ if (/^\d+$/.test(P) && /^\d+$/.test(O)) {
2037
+ const E = parseInt(P, 10) - parseInt(O, 10);
2038
+ if (E !== 0) return E;
2039
+ } else if (P !== O)
2040
+ return P < O ? -1 : 1;
2041
+ }
2042
+ return 0;
2043
+ }, o = n(e), i = n(t);
2044
+ for (let b = 0; b < Math.max(o.base.length, i.base.length); b++) {
2045
+ const d = parseInt(o.base[b] ?? "0", 10) || 0, m = parseInt(i.base[b] ?? "0", 10) || 0;
2046
+ if (d !== m) return d - m;
2047
+ }
2048
+ if (!o.pre && !i.pre) return 0;
2049
+ if (!o.pre) return 1;
2050
+ if (!i.pre) return -1;
2051
+ const c = o.pre.split("."), u = i.pre.split(".");
2052
+ for (let b = 0; b < Math.max(c.length, u.length); b++) {
2053
+ const d = c[b], m = u[b];
2054
+ if (d === void 0) return -1;
2055
+ if (m === void 0) return 1;
2056
+ const w = s(d, m);
2057
+ if (w !== 0) return w;
2058
+ }
2059
+ return 0;
2060
+ }
2061
+ function br(e, t) {
2062
+ const n = jt(e, t).split(kt).join("/");
2063
+ if (!(!n || n.startsWith("..") || vt(n)))
2064
+ return `/${n}`;
2065
+ }
2066
+ function vr(e, t) {
2067
+ const n = jt(e, t).split(kt).join("/");
2068
+ if (n.startsWith("..") || vt(n))
2069
+ throw new Error(
2070
+ `[nimpress] content file is outside contentDir.
2071
+ contentDir: ${e}
2072
+ file: ${t}
2073
+ Check the working directory you run vite from and the contentDir option.`
2074
+ );
2075
+ return n.replace(/\.md$/, "").replace(/\/index$/, "").replace(/^index$/, "");
2076
+ }
2077
+ function wr(e) {
2078
+ const t = e.lastIndexOf("/");
2079
+ return t >= 0 ? e.slice(0, t) : "";
2080
+ }
2081
+ function $r(e) {
2082
+ return e ? "/" + e : "/";
2083
+ }
2084
+ function yn(e) {
2085
+ if (!e) return "/";
2086
+ let t = e.startsWith("/") ? e : "/" + e;
2087
+ return t.length > 1 && t.endsWith("/") && (t = t.slice(0, -1)), t;
2088
+ }
2089
+ async function Je(e, t = []) {
2090
+ let n;
2091
+ try {
2092
+ n = await Me(e, { withFileTypes: !0 });
2093
+ } catch {
2094
+ return t;
2095
+ }
2096
+ for (const s of n) {
2097
+ const o = W(e, s.name);
2098
+ if (s.isDirectory()) {
2099
+ if (s.name.startsWith(".") || s.name === "node_modules") continue;
2100
+ await Je(o, t);
2101
+ } else s.isFile() && s.name.endsWith(".md") && t.push(o);
2102
+ }
2103
+ return t;
2104
+ }
2105
+ function In(e) {
2106
+ return e.toLowerCase().replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-");
2107
+ }
2108
+ function Pe(e) {
2109
+ return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
2110
+ }
2111
+ function Sr(e, t = { route: "/_components" }, n = "/") {
2112
+ const s = new ls({
2113
+ html: !0,
2114
+ linkify: !0,
2115
+ typographer: !1,
2116
+ highlight(d, m, w) {
2117
+ const k = {
2118
+ curl: "bash",
2119
+ sh: "bash",
2120
+ zsh: "bash",
2121
+ console: "bash",
2122
+ hurl: "http"
2123
+ }, O = ((w ? w.match(/\[([^\]]+)\]/) : null)?.[1].trim() || m || "text").trim(), E = k[m] ?? m, H = E && e.getLoadedLanguages().includes(E) ? E : "text";
2124
+ try {
2125
+ return e.codeToHtml(d, { lang: H, theme: "github-dark" }).replace("<pre ", `<pre data-lang="${s.utils.escapeHtml(O)}" `);
2126
+ } catch {
2127
+ return `<pre data-lang="${s.utils.escapeHtml(O)}"><code>${s.utils.escapeHtml(d)}</code></pre>`;
2128
+ }
2129
+ }
2130
+ }), o = (d, m, w, k, P) => P.renderToken(d, m, w), i = s.renderer.rules.link_open ?? o;
2131
+ s.renderer.rules.link_open = (d, m, w, k, P) => {
2132
+ const O = d[m].attrGet("href");
2133
+ return O && d[m].attrSet("href", gt(n, O)), i(d, m, w, k, P);
2134
+ };
2135
+ const c = s.renderer.rules.image ?? o;
2136
+ s.renderer.rules.image = (d, m, w, k, P) => {
2137
+ const O = d[m].attrGet("src");
2138
+ return O && d[m].attrSet("src", gt(n, O)), c(d, m, w, k, P);
2139
+ }, s.use(Qe, {
2140
+ slugify: In,
2141
+ permalink: Qe.permalink.headerLink({ safariReaderFix: !0 })
2142
+ }), s.use(ps), s.use(fs), s.use(ms), s.use(ds, { enabled: !0 });
2143
+ const u = (d, m) => {
2144
+ s.use(us, d, m);
2145
+ }, b = ["tip", "note", "warning", "info", "check"];
2146
+ for (const d of b)
2147
+ u(d, {
2148
+ render(m, w) {
2149
+ if (m[w].nesting === 1) {
2150
+ const k = m[w].info.trim().slice(d.length).trim() || d;
2151
+ return `<div class="np-callout np-callout-${d}"><div class="np-callout-body"><div class="np-callout-title">${s.utils.escapeHtml(k)}</div>`;
2152
+ }
2153
+ return "</div></div>";
2154
+ }
2155
+ });
2156
+ return u("cards", {
2157
+ render(d, m) {
2158
+ return d[m].nesting === 1 ? '<div class="np-cards-grid">' : "</div>";
2159
+ }
2160
+ }), u("details", {
2161
+ validate(d) {
2162
+ return /^details\b/.test(d.trim());
2163
+ },
2164
+ render(d, m) {
2165
+ if (d[m].nesting === 1) {
2166
+ const w = d[m].info.trim().match(/^details\s*(.*)$/), k = w && w[1] || "Details";
2167
+ return `<details class="np-details"><summary class="np-details-summary">${s.utils.escapeHtml(k)}</summary><div class="np-details-body">
2168
+ `;
2169
+ }
2170
+ return `</div></details>
2171
+ `;
2172
+ }
2173
+ }), u("code-group", {
2174
+ render(d, m) {
2175
+ return d[m].nesting === 1 ? '<div class="np-code-group">' : "</div>";
2176
+ }
2177
+ }), u("actions", {
2178
+ render(d, m) {
2179
+ if (d[m].nesting === 1) {
2180
+ const w = d[m].info.trim().slice(7).trim(), k = w ? Rt(w, d[m].info) : {}, P = typeof k?.align == "string" ? k.align : "start";
2181
+ return `<div class="np-actions" data-align="${s.utils.escapeHtml(P)}">`;
2182
+ }
2183
+ return "</div>";
2184
+ }
2185
+ }), u("features", {
2186
+ render(d, m) {
2187
+ if (d[m].nesting === 1) {
2188
+ const w = d[m].info.trim().slice(8).trim(), k = w ? Rt(w, d[m].info) : {}, P = typeof k?.columns == "number" ? k.columns : 0;
2189
+ return `<div class="np-features"${P > 0 ? ` data-columns="${P}"` : ""}>`;
2190
+ }
2191
+ return "</div>";
2192
+ }
2193
+ }), u("feature", {
2194
+ render(d, m) {
2195
+ if (d[m].nesting === 1) {
2196
+ const w = d[m].info.trim().slice(7).trim(), k = w ? Rt(w, d[m].info) : {};
2197
+ return `<div class="np-feature" data-config="${qt(JSON.stringify(k))}"><div class="np-feature-body">`;
2198
+ }
2199
+ return "</div></div>";
2200
+ }
2201
+ }), u("component", {
2202
+ render(d, m) {
2203
+ if (d[m].nesting === 1) {
2204
+ const w = d[m].info.trim().slice(9).trim(), k = w.startsWith("{") ? Rt(w, d[m].info) : w ? { component: w } : {};
2205
+ return `<div class="np-component-embed" data-embed="${qt(JSON.stringify({ ...t, ...k }))}"><div class="np-component-embed-body">`;
2206
+ }
2207
+ return "</div></div>";
2208
+ }
2209
+ }), s;
2210
+ }
2211
+ function Rt(e, t) {
2212
+ try {
2213
+ const n = JSON.parse(e);
2214
+ return n && typeof n == "object" && !Array.isArray(n) ? n : {};
2215
+ } catch {
2216
+ return console.warn(`[nimpress] invalid JSON in directive: ${t}`), {};
2217
+ }
2218
+ }
2219
+ function qt(e) {
2220
+ return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2221
+ }
2222
+ function xr(e) {
2223
+ return `<div class="np-mermaid" data-graph="${Buffer.from(e, "utf-8").toString("base64")}"></div>`;
2224
+ }
2225
+ function kr(e, t, n) {
2226
+ const s = t.startsWith("{") ? Rt(t, t) : {};
2227
+ let o = "", i = "";
2228
+ try {
2229
+ o = kn(e);
2230
+ } catch (d) {
2231
+ i = d instanceof Be ? d.message : String(d), console.warn(`[nimpress] invalid dbml in ${n}:
2232
+ ${i}`);
2233
+ }
2234
+ const c = Buffer.from(o, "utf-8").toString("base64"), u = typeof s.height == "string" ? s.height : "";
2235
+ return `<div class="np-dbml" ${[
2236
+ `data-schema="${c}"`,
2237
+ i ? `data-error="${qt(i)}"` : "",
2238
+ u ? `data-height="${qt(u)}"` : ""
2239
+ ].filter(Boolean).join(" ")}></div>`;
2240
+ }
2241
+ function Pr(e, t) {
2242
+ const n = e.split(`
2243
+ `), s = [];
2244
+ let o = 0;
2245
+ for (; o < n.length; ) {
2246
+ const i = /^(\s*)(`{3,}|~{3,})(.*)$/.exec(n[o]);
2247
+ if (!i) {
2248
+ s.push(n[o]), o += 1;
2249
+ continue;
2250
+ }
2251
+ const [, c, u, b] = i, d = new RegExp(`^\\s*\\${u[0]}{${u.length},}\\s*$`);
2252
+ let m = o + 1;
2253
+ for (; m < n.length && !d.test(n[m]); ) m += 1;
2254
+ const w = b.trim(), k = w.split(/\s+/)[0].toLowerCase(), P = n.slice(o + 1, m).join(`
2255
+ `);
2256
+ k === "mermaid" ? s.push(`${c}${xr(P && `${P}
2257
+ `)}`) : k === "dbml" ? s.push(`${c}${kr(P, w.slice(k.length).trim(), t)}`) : s.push(...n.slice(o, Math.min(m + 1, n.length))), o = m + 1;
2258
+ }
2259
+ return s.join(`
2260
+ `);
2261
+ }
2262
+ function jr(e) {
2263
+ if (!e) return "";
2264
+ const t = [], n = (o) => {
2265
+ if (o)
2266
+ for (const i of o)
2267
+ i.type === "text" || i.type === "code_inline" ? t.push(i.content ?? "") : i.children && n(i.children);
2268
+ };
2269
+ n(e.children);
2270
+ const s = t.join("").trim();
2271
+ return s || (e.content ?? "").trim();
2272
+ }
2273
+ function Er(e, t) {
2274
+ const n = e.parse(t, {}), s = [];
2275
+ let o = 0;
2276
+ const i = /* @__PURE__ */ new Map();
2277
+ for (let c = 0; c < n.length; c++) {
2278
+ const u = n[c];
2279
+ if (u.type === "heading_open") {
2280
+ const b = parseInt(u.tag.slice(1)), d = n[c + 1], m = jr(d) || `heading-${o++}`;
2281
+ let w = In(m);
2282
+ w || (w = `heading-${o++}`);
2283
+ const k = i.get(w);
2284
+ if (k !== void 0) {
2285
+ const P = k + 1;
2286
+ i.set(w, P), w = `${w}-${P}`;
2287
+ } else
2288
+ i.set(w, 0);
2289
+ s.push({ level: b, text: m, slug: w });
2290
+ }
2291
+ }
2292
+ return s;
2293
+ }
2294
+ function Dr(e) {
2295
+ return e.frontmatter.slug ?? e.frontmatter.title;
2296
+ }
2297
+ function se(e) {
2298
+ return e ? e.replace(/[-_]/g, " ").replace(/\b\w/g, (t) => t.toUpperCase()) : "";
2299
+ }
2300
+ function Oe(e) {
2301
+ e.sort((t, n) => {
2302
+ const s = t.order ?? Number.MAX_SAFE_INTEGER, o = n.order ?? Number.MAX_SAFE_INTEGER;
2303
+ return s !== o ? s - o : t.text.localeCompare(n.text);
2304
+ });
2305
+ for (const t of e)
2306
+ t.items && Oe(t.items);
2307
+ }
2308
+ function Ar(e) {
2309
+ let t = Wt, n = q(process.cwd(), Wt.contentDir), s = q(process.cwd(), Wt.assetsDir), o = /* @__PURE__ */ new Map(), i = null, c = q(process.cwd(), "dist"), u = !1, b = null;
2310
+ const d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Set();
2311
+ function O(r) {
2312
+ return bn("sha1").update(r).digest("hex");
2313
+ }
2314
+ async function E() {
2315
+ return i || (i = await gs({
2316
+ themes: ["github-dark"],
2317
+ langs: [
2318
+ "ts",
2319
+ "tsx",
2320
+ "js",
2321
+ "jsx",
2322
+ "json",
2323
+ "bash",
2324
+ "shell",
2325
+ "yaml",
2326
+ "go",
2327
+ "sql",
2328
+ "html",
2329
+ "css",
2330
+ "svelte",
2331
+ "vue",
2332
+ "md",
2333
+ "rust",
2334
+ "python",
2335
+ "http",
2336
+ "diff",
2337
+ "text"
2338
+ ]
2339
+ }), i);
2340
+ }
2341
+ function H(r, l) {
2342
+ return /\.ya?ml$/i.test(l) ? vn(r) : JSON.parse(r);
2343
+ }
2344
+ async function K(r, l) {
2345
+ try {
2346
+ const a = vt(l) ? l : q(G(r), l), g = await it(a, "utf-8"), $ = H(g, a);
2347
+ return await st($, G(a)), $;
2348
+ } catch (a) {
2349
+ return console.warn(`[nimpress] failed to load spec ${l} for ${r}:`, a), null;
2350
+ }
2351
+ }
2352
+ async function st(r, l) {
2353
+ if (!r || typeof r != "object") return;
2354
+ r.components || (r.components = {}), r.components.schemas || (r.components.schemas = {});
2355
+ const a = r.components.schemas, g = /* @__PURE__ */ new Map(), $ = async (y) => {
2356
+ const x = await it(y, "utf-8");
2357
+ return H(x, y);
2358
+ }, h = async (y) => {
2359
+ if (g.has(y)) return g.get(y);
2360
+ const v = (y.split("/").pop() ?? "").replace(/\.json$/, "");
2361
+ g.set(y, v);
2362
+ const j = await $(y);
2363
+ return await p(j, G(y)), a[v] = j, v;
2364
+ }, p = async (y, x) => {
2365
+ if (!y || typeof y != "object") return;
2366
+ if (Array.isArray(y)) {
2367
+ for (const j of y) await p(j, x);
2368
+ return;
2369
+ }
2370
+ const v = y.$ref;
2371
+ if (typeof v == "string" && !v.startsWith("#")) {
2372
+ const j = vt(v) ? v : q(x, v), M = G(j).split("/").pop() ?? "";
2373
+ if (M === "schemas") {
2374
+ const S = await h(j);
2375
+ y.$ref = `#/components/schemas/${S}`;
2376
+ return;
2377
+ }
2378
+ if (M === "operations") {
2379
+ const S = await $(j);
2380
+ await p(S, G(j)), delete y.$ref;
2381
+ for (const N of Object.keys(S)) y[N] = S[N];
2382
+ return;
2383
+ }
2384
+ return;
2385
+ }
2386
+ for (const j of Object.keys(y))
2387
+ await p(y[j], x);
2388
+ };
2389
+ for (const y of Object.keys(a)) {
2390
+ const x = a[y];
2391
+ if (x && typeof x == "object" && typeof x.$ref == "string" && !x.$ref.startsWith("#")) {
2392
+ const v = vt(x.$ref) ? x.$ref : q(l, x.$ref);
2393
+ g.set(v, y);
2394
+ const j = await $(v);
2395
+ await p(j, G(v)), a[y] = j;
2396
+ }
2397
+ }
2398
+ for (const y of Object.keys(r))
2399
+ y !== "components" && await p(r[y], l);
2400
+ }
2401
+ function _(r, l) {
2402
+ if (typeof l != "string" || !l.startsWith("#/")) return null;
2403
+ const a = l.slice(2).split("/").map(($) => $.replace(/~1/g, "/").replace(/~0/g, "~"));
2404
+ let g = r;
2405
+ for (const $ of a) {
2406
+ if (g == null) return null;
2407
+ g = g[$];
2408
+ }
2409
+ return g;
2410
+ }
2411
+ function A(r, l, a = 0) {
2412
+ if (a > 4 || !r || typeof r != "object" || typeof r.$ref != "string") return r;
2413
+ const g = _(l, r.$ref);
2414
+ return g == null ? r : A(g, l, a + 1);
2415
+ }
2416
+ function L(r, l) {
2417
+ if (!(typeof l != "string" || l === ""))
2418
+ try {
2419
+ return r.render(l);
2420
+ } catch {
2421
+ return;
2422
+ }
2423
+ }
2424
+ function ot(r, l) {
2425
+ if (!r) return null;
2426
+ const a = r, g = a.info ?? {}, $ = a.components?.securitySchemes ?? {}, h = ["get", "post", "put", "patch", "delete", "head", "options"], p = (S) => A(S, a)?.example, y = /* @__PURE__ */ new Map(), x = a.paths ?? {};
2427
+ for (const [S, N] of Object.entries(x)) {
2428
+ const I = A(N, a);
2429
+ if (!I || typeof I != "object") continue;
2430
+ const U = (I.parameters ?? []).map((C) => A(C, a));
2431
+ for (const C of h) {
2432
+ const F = I[C];
2433
+ if (!F) continue;
2434
+ const D = F.operationId ?? `${C}-${S.replace(/[^a-z0-9]+/gi, "-")}`, R = F.tags?.[0] ?? "default", z = (F.parameters ?? []).map((ht) => A(ht, a)), V = [...U, ...z], T = /* @__PURE__ */ new Set(), B = [];
2435
+ for (const ht of V) {
2436
+ const rt = ht;
2437
+ if (!rt || typeof rt != "object" || !rt.name || !rt.in) continue;
2438
+ const tt = `${rt.name}@${rt.in}`;
2439
+ T.has(tt) || (T.add(tt), B.push({
2440
+ name: rt.name,
2441
+ in: rt.in,
2442
+ required: rt.required,
2443
+ schema: rt.schema,
2444
+ description: rt.description,
2445
+ description_html: L(l, rt.description),
2446
+ example: rt.example ?? p(rt.schema)
2447
+ }));
2448
+ }
2449
+ const J = F.requestBody ? A(F.requestBody, a) : void 0, Z = J?.content?.["application/json"], X = Z?.example ?? (Z?.examples ? Object.values(Z.examples)[0]?.value : void 0) ?? p(Z?.schema), Y = {}, ct = {};
2450
+ for (const [ht, rt] of Object.entries(F.responses ?? {})) {
2451
+ const tt = A(rt, a);
2452
+ ct[ht] = tt;
2453
+ const bt = tt?.content?.["application/json"], Ct = bt?.example ?? (bt?.examples ? Object.values(bt.examples)[0]?.value : void 0) ?? p(bt?.schema);
2454
+ Ct !== void 0 && (Y[ht] = Ct);
2455
+ }
2456
+ const ut = {
2457
+ id: D,
2458
+ method: C.toUpperCase(),
2459
+ path: S,
2460
+ tag: R,
2461
+ summary: F.summary ?? D,
2462
+ summary_html: L(l, F.summary),
2463
+ description: F.description,
2464
+ description_html: L(l, F.description),
2465
+ parameters: B,
2466
+ requestBody: J,
2467
+ requestBodyHtml: L(l, J?.description),
2468
+ requestExample: X,
2469
+ responses: ct,
2470
+ responseExamples: Y,
2471
+ security: F.security ?? a.security,
2472
+ operationName: F.operationId
2473
+ };
2474
+ y.has(R) || y.set(R, []), y.get(R).push(ut);
2475
+ }
2476
+ }
2477
+ const v = [...y.entries()].map(([S, N]) => ({ name: S, operations: N })).sort((S, N) => S.name.localeCompare(N.name)), j = a.components?.schemas ?? {}, M = {};
2478
+ for (const [S, N] of Object.entries(j)) {
2479
+ const I = L(l, N?.description);
2480
+ M[S] = I ? { ...N, description_html: I } : N;
2481
+ }
2482
+ return {
2483
+ title: g.title ?? "API",
2484
+ version: g.version ?? "",
2485
+ description: g.description,
2486
+ description_html: L(l, g.description),
2487
+ servers: a.servers,
2488
+ securitySchemes: $,
2489
+ tags: v,
2490
+ schemas: M
2491
+ };
2492
+ }
2493
+ async function lt(r) {
2494
+ const l = await it(r, "utf-8"), { data: a, content: g } = Te(l), $ = Fn(a, g);
2495
+ if ($.length) {
2496
+ const tt = `${r}
2497
+ ${$.join(`
2498
+ `)}`;
2499
+ if (u) throw new Error(`[nimpress] invalid frontmatter in ${tt}`);
2500
+ console.warn(`[nimpress] invalid frontmatter in ${tt}`);
2501
+ }
2502
+ const h = Nn.safeParse(a), p = h.success ? h.data : { title: r }, y = vr(n, r), x = p.type ?? "doc", v = yn(p.path ?? $r(y)), j = typeof p.link == "string" && p.link.trim() !== "" ? p.link.trim() : void 0, M = !!j || a.type === void 0 && g.trim() === "", S = t.defaultFrontmatter ?? {};
2503
+ if (!(t.defaultFrontmatterExclude ?? []).some((tt) => {
2504
+ const bt = tt.startsWith("/") ? tt : "/" + tt;
2505
+ return v === bt || v.startsWith(bt + "/");
2506
+ }))
2507
+ for (const [tt, bt] of Object.entries(S)) {
2508
+ const Ct = tt;
2509
+ (p[Ct] === void 0 || p[Ct] === null || p[Ct] === "") && (p[Ct] = bt);
2510
+ }
2511
+ const U = await E(), C = Sr(U, Q(), t.base), F = Pr(g, r), D = Er(C, F), R = C.render(F);
2512
+ let z, V, T, B;
2513
+ if (x === "openapi")
2514
+ if (!p.spec)
2515
+ console.warn(`[nimpress] page ${r} has type openapi but no spec field`);
2516
+ else {
2517
+ B = vt(p.spec) ? p.spec : q(G(r), p.spec), V = Mt(B), T = br(n, B);
2518
+ const tt = await K(r, p.spec);
2519
+ z = tt ? ot(tt, C) ?? void 0 : void 0;
2520
+ }
2521
+ let J, Z, X, Y;
2522
+ if (x === "dbml")
2523
+ if (!p.spec)
2524
+ console.warn(`[nimpress] page ${r} has type dbml but no spec field`);
2525
+ else {
2526
+ B = vt(p.spec) ? p.spec : q(G(r), p.spec), X = Mt(B);
2527
+ try {
2528
+ Z = await it(B, "utf-8"), J = kn(Z);
2529
+ } catch (tt) {
2530
+ Y = tt instanceof Be ? tt.message : String(tt);
2531
+ const bt = `${r} -> ${p.spec}
2532
+ ${Y}`;
2533
+ if (u) throw new Error(`[nimpress] invalid dbml in ${bt}`);
2534
+ console.warn(`[nimpress] invalid dbml in ${bt}`);
2535
+ }
2536
+ }
2537
+ mt(r, B);
2538
+ let ct, ut = [];
2539
+ if (x === "component") {
2540
+ const tt = await Yo({
2541
+ cwd: process.cwd(),
2542
+ modules: t.modules,
2543
+ pageFile: r,
2544
+ data: p.data ?? {},
2545
+ editable: !u
2546
+ });
2547
+ ct = tt.data, ut = tt.watchFiles;
2548
+ }
2549
+ Et(r, ut);
2550
+ const ht = r.replace(/\.md$/, ".css");
2551
+ let rt;
2552
+ return ht !== r && dt(ht) && (rt = await it(ht, "utf-8")), {
2553
+ slug: y,
2554
+ filePath: r,
2555
+ effectivePath: v,
2556
+ type: x,
2557
+ sidebarOnly: M,
2558
+ linkTo: j,
2559
+ frontmatter: p,
2560
+ html: R,
2561
+ headings: D,
2562
+ rawText: g,
2563
+ pageCss: rt,
2564
+ openApiSpec: z,
2565
+ openApiFile: V,
2566
+ openApiUrl: T,
2567
+ componentData: ct,
2568
+ dbmlSchema: J,
2569
+ dbmlSource: Z,
2570
+ dbmlFile: X,
2571
+ dbmlError: Y
2572
+ };
2573
+ }
2574
+ function mt(r, l) {
2575
+ for (const [a, g] of m)
2576
+ g === r && m.delete(a);
2577
+ l && (m.set(l, r), b && !w.has(l) && (b.watcher.add(l), w.add(l)));
2578
+ }
2579
+ function Et(r, l) {
2580
+ for (const [a, g] of k)
2581
+ g === r && k.delete(a);
2582
+ for (const a of l)
2583
+ k.set(a, r), b && !P.has(a) && (b.watcher.add(a), P.add(a));
2584
+ }
2585
+ async function wt(r) {
2586
+ let l;
2587
+ try {
2588
+ l = await it(r, "utf-8");
2589
+ } catch {
2590
+ return null;
2591
+ }
2592
+ const a = O(l), g = d.get(r);
2593
+ if (g && g.hash === a) return g.processed;
2594
+ const $ = await lt(r);
2595
+ return $ ? (d.set(r, { hash: a, processed: $ }), $) : (d.delete(r), null);
2596
+ }
2597
+ function pt(r) {
2598
+ d.delete(r);
2599
+ }
2600
+ function Q() {
2601
+ const r = Object.keys(t.modules.systems);
2602
+ return {
2603
+ route: t.modules.route.replace(/\/$/, ""),
2604
+ system: r.length === 1 ? r[0] : void 0
2605
+ };
2606
+ }
2607
+ function $t(r) {
2608
+ const l = t.exclude ?? [];
2609
+ for (const a of l) {
2610
+ const g = a.replace(/\/$/, "");
2611
+ if (r === g || r.startsWith(g + "/")) return !0;
2612
+ }
2613
+ return !1;
2614
+ }
2615
+ async function at() {
2616
+ const r = await Je(n), l = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), p = [], y = new Set(r);
2617
+ for (const x of [...d.keys()])
2618
+ y.has(x) || d.delete(x);
2619
+ for (const x of r) {
2620
+ let v = null;
2621
+ try {
2622
+ v = await wt(x);
2623
+ } catch (M) {
2624
+ console.warn(`[nimpress] failed to process ${x}:`, M);
2625
+ continue;
2626
+ }
2627
+ if (!v || $t(v.slug)) continue;
2628
+ if (p.push(v), v.type === "changelog") {
2629
+ const S = `${wr(v.slug)}\0${v.frontmatter.title}`, N = g.get(S) ?? [];
2630
+ N.push(v), g.set(S, N);
2631
+ continue;
2632
+ }
2633
+ if (v.type === "roadmap") {
2634
+ const M = String(v.filePath);
2635
+ $.set(M, [v]);
2636
+ }
2637
+ if (v.type === "component") {
2638
+ const M = G(v.filePath), S = h.get(M);
2639
+ if (S)
2640
+ throw new Error(
2641
+ `[nimpress] one type component page per folder: ${M} holds ${S} and ${v.filePath}`
2642
+ );
2643
+ h.set(M, v.filePath);
2644
+ }
2645
+ const j = a.get(v.effectivePath);
2646
+ if (j)
2647
+ throw new Error(
2648
+ `[nimpress] duplicate path ${v.effectivePath}: ${j} and ${v.filePath}`
2649
+ );
2650
+ a.set(v.effectivePath, v.filePath), l.set(v.slug, v);
2651
+ }
2652
+ fe.clear();
2653
+ for (const [x, v] of g) {
2654
+ const j = x.split("\0", 1)[0], M = yn(j ? "/" + j : "/");
2655
+ if (a.has(M))
2656
+ throw new Error(
2657
+ `[nimpress] path ${M} is occupied by both a changelog collection and a regular page`
2658
+ );
2659
+ const S = v.filter((D) => !(u && Dt(D.frontmatter)));
2660
+ if (S.length === 0) continue;
2661
+ S.sort((D, R) => {
2662
+ const z = String(D.frontmatter.data?.version ?? ""), V = String(R.frontmatter.data?.version ?? "");
2663
+ return yr(V, z);
2664
+ });
2665
+ const N = S[0], I = `__changelog__${(j || "root").replace(/\//g, "__")}`, U = S.map((D) => {
2666
+ const R = D.frontmatter.data, z = String(R?.version ?? ""), V = String(R?.title ?? ""), T = R?.description !== void 0 ? String(R.description) : void 0, B = R?.release_date;
2667
+ let J;
2668
+ if (B != null && String(B).trim() !== "") {
2669
+ const X = B instanceof Date ? B.toISOString() : String(B), Y = new Date(X);
2670
+ if (Number.isNaN(Y.getTime()))
2671
+ throw new Error(
2672
+ `[nimpress] changelog entry ${D.filePath} has an invalid data.release_date (${X}). Use an RFC 3339 timestamp like 2026-06-10 or 2026-06-10T09:00:00Z.`
2673
+ );
2674
+ J = Y.toISOString();
2675
+ }
2676
+ const Z = z ? `v${z}` : "unreleased";
2677
+ return fe.set(`${I}#${Z}`, D.rawText), {
2678
+ version: z,
2679
+ slug: Z,
2680
+ title: V,
2681
+ description: T,
2682
+ releaseDate: J,
2683
+ hidden: ne(D.frontmatter),
2684
+ html: D.html,
2685
+ headings: D.headings,
2686
+ data: D.frontmatter.data
2687
+ };
2688
+ }), C = U.map((D) => ({
2689
+ level: 2,
2690
+ text: D.version ? `v${D.version}` : D.title || "unreleased",
2691
+ slug: D.slug
2692
+ })), F = {
2693
+ slug: I,
2694
+ filePath: N.filePath,
2695
+ effectivePath: M,
2696
+ type: "changelog",
2697
+ frontmatter: {
2698
+ ...N.frontmatter,
2699
+ path: M,
2700
+ type: "changelog",
2701
+ rss: S.some((D) => D.frontmatter.rss === !0) ? !0 : void 0,
2702
+ subscribe: S.some((D) => D.frontmatter.subscribe === !0) ? !0 : void 0
2703
+ },
2704
+ html: "",
2705
+ headings: C,
2706
+ rawText: S.map((D) => D.rawText).join(`
2707
+
2708
+ `),
2709
+ changelogEntries: U
2710
+ };
2711
+ a.set(M, F.filePath), l.set(F.slug, F);
2712
+ }
2713
+ Yn($, p), Rn(l), Bn(l), o = l;
2714
+ }
2715
+ const St = /* @__PURE__ */ new Map(), fe = /* @__PURE__ */ new Map();
2716
+ let me = JSON.stringify({ pages: [] }, null, 2) + `
2717
+ `;
2718
+ function Bn(r) {
2719
+ const l = [];
2720
+ for (const a of r.values()) {
2721
+ if (a.frontmatter.subscribe !== !0 || ke(a.frontmatter)) continue;
2722
+ const g = a.effectivePath === "/" ? "" : a.effectivePath, h = `${yt(a) ? `/${t.paths.guarded}/${Xt(a)}` : ""}${g}/${hn(0)}`;
2723
+ if (!St.has(h)) continue;
2724
+ const p = {
2725
+ path: a.effectivePath,
2726
+ title: a.frontmatter.title,
2727
+ name: a.effectivePath === "/" ? "index" : a.effectivePath.replace(/\//g, "-").replace(/^-/, ""),
2728
+ feed: h
2729
+ };
2730
+ a.type === "changelog" && (p.entries = (a.changelogEntries ?? []).filter((y) => !y.hidden).map((y) => ({
2731
+ slug: y.slug,
2732
+ version: y.version,
2733
+ date: y.releaseDate,
2734
+ title: y.title,
2735
+ description: y.description,
2736
+ body: fe.get(`${a.slug}#${y.slug}`) ?? ""
2737
+ }))), l.push(p);
2738
+ }
2739
+ l.sort((a, g) => a.path.localeCompare(g.path)), me = JSON.stringify({ pages: l }, null, 2) + `
2740
+ `;
2741
+ }
2742
+ function Rn(r) {
2743
+ St.clear();
2744
+ const l = t.site?.url?.replace(/\/$/, "");
2745
+ for (const a of r.values()) {
2746
+ if (a.type !== "changelog" || !(a.frontmatter.rss === !0 || a.frontmatter.subscribe === !0)) continue;
2747
+ if (!l) {
2748
+ console.warn(`[nimpress] changelog feed for ${a.effectivePath} needs site.url in the config, skipping`);
2749
+ continue;
2750
+ }
2751
+ const g = (a.changelogEntries ?? []).filter((D) => !D.hidden);
2752
+ if (g.length === 0) continue;
2753
+ const $ = a.effectivePath === "/" ? "" : a.effectivePath, h = `${l}${gt(t.base, $ || "/")}`, p = yt(a) ? `/${t.paths.guarded}/${Xt(a)}` : "", y = (D) => `${p}${$}/${hn(D)}`, x = g.map((D) => D.releaseDate ? new Date(D.releaseDate).getTime() : Number.NaN).filter((D) => !Number.isNaN(D)).sort((D, R) => R - D), v = [];
2754
+ for (let D = 0; D + 1 < x.length; D++) v.push(x[D] - x[D + 1]);
2755
+ const j = v.length ? Math.round(v.reduce((D, R) => D + R, 0) / v.length / 1e3) : void 0, M = j ? Math.min(43200, Math.max(60, Math.round(j / 60))) : 1440, S = j ? j <= 172800 ? "daily" : j <= 1209600 ? "weekly" : j <= 5184e3 ? "monthly" : "yearly" : "weekly", N = x.length ? new Date(x[0]).toUTCString() : void 0, I = ft(a.frontmatter.title), U = ft(
2756
+ a.frontmatter.description ?? t.site?.description ?? a.frontmatter.title
2757
+ ), C = t.site?.locale?.replace("_", "-").toLowerCase(), F = Math.max(1, Math.ceil(g.length / xe));
2758
+ for (let D = 0; D < F; D++) {
2759
+ const R = g.slice(D * xe, (D + 1) * xe), z = [
2760
+ `<atom:link href="${ft(`${l}${gt(t.base, y(D))}`)}" rel="self" type="application/rss+xml"/>`
2761
+ ];
2762
+ D > 0 && z.push(
2763
+ `<atom:link href="${ft(`${l}${gt(t.base, y(0))}`)}" rel="current" type="application/rss+xml"/>`
2764
+ ), D + 1 < F && z.push(
2765
+ `<atom:link href="${ft(`${l}${gt(t.base, y(D + 1))}`)}" rel="prev-archive" type="application/rss+xml"/>`
2766
+ ), D > 1 && z.push(
2767
+ `<atom:link href="${ft(`${l}${gt(t.base, y(D - 1))}`)}" rel="next-archive" type="application/rss+xml"/>`
2768
+ );
2769
+ const V = R.map((J) => {
2770
+ const Z = `${h}#${J.slug}`, X = [
2771
+ `<title>${ft(J.version ? `v${J.version} ${J.title}` : J.title)}</title>`,
2772
+ `<link>${ft(Z)}</link>`,
2773
+ `<guid isPermaLink="true">${ft(Z)}</guid>`
2774
+ ];
2775
+ return J.releaseDate && X.push(`<pubDate>${new Date(J.releaseDate).toUTCString()}</pubDate>`), J.description && X.push(`<description>${ft(J.description)}</description>`), J.html && X.push(`<content:encoded>${ur(J.html)}</content:encoded>`), ` <item>
2776
+ ${X.join(`
2777
+ `)}
2778
+ </item>`;
2779
+ }), T = [
2780
+ `<title>${I}</title>`,
2781
+ `<link>${ft(h)}</link>`,
2782
+ `<description>${U}</description>`,
2783
+ ...z
2784
+ ];
2785
+ C && T.push(`<language>${ft(C)}</language>`), N && T.push(`<lastBuildDate>${N}</lastBuildDate>`), T.push(`<ttl>${M}</ttl>`), T.push(`<sy:updatePeriod>${S}</sy:updatePeriod>`), T.push("<sy:updateFrequency>1</sy:updateFrequency>"), j !== void 0 && T.push(`<nimpress:releaseCadence>${j}</nimpress:releaseCadence>`), T.push(`<nimpress:latestVersion>${ft(g[0].version)}</nimpress:latestVersion>`), T.push(`<nimpress:releaseCount>${g.length}</nimpress:releaseCount>`), D > 0 && T.push("<fh:archive/>");
2786
+ const B = [
2787
+ '<?xml version="1.0" encoding="UTF-8"?>',
2788
+ `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:fh="http://purl.org/syndication/history/1.0" xmlns:nimpress="${pr}">`,
2789
+ " <channel>",
2790
+ ` ${T.join(`
2791
+ `)}`,
2792
+ V.join(`
2793
+ `),
2794
+ " </channel>",
2795
+ "</rss>"
2796
+ ].join(`
2797
+ `);
2798
+ St.set(y(D), B);
2799
+ }
2800
+ }
2801
+ }
2802
+ const de = /* @__PURE__ */ new Map();
2803
+ function yt(r) {
2804
+ return r.frontmatter.gate !== void 0;
2805
+ }
2806
+ function Wn(r) {
2807
+ const l = G(r.filePath);
2808
+ let a = [];
2809
+ try {
2810
+ a = pe(l);
2811
+ } catch {
2812
+ return [];
2813
+ }
2814
+ return a.filter((g) => W(l, g) !== r.filePath).map((g) => jt(process.cwd(), W(l, g)));
2815
+ }
2816
+ function Xt(r) {
2817
+ const l = t.auth?.guard;
2818
+ return typeof l == "function" ? l(r.frontmatter, jt(process.cwd(), r.filePath), Wn(r)) : r.frontmatter.gate ?? "default";
2819
+ }
2820
+ function Ln() {
2821
+ const r = [];
2822
+ for (const l of o.values())
2823
+ l.sidebarOnly || ke(l.frontmatter) || yt(l) || r.push(l);
2824
+ return r;
2825
+ }
2826
+ function xt(r) {
2827
+ const l = t.site?.url?.replace(/\/$/, "");
2828
+ if (l)
2829
+ return l + gt(t.base, r.startsWith("/") ? r : "/" + r);
2830
+ }
2831
+ function qe(r) {
2832
+ if (de.has(r)) return de.get(r);
2833
+ let l;
2834
+ try {
2835
+ l = cs("git", ["log", "-1", "--format=%cI", "--", r], {
2836
+ cwd: process.cwd(),
2837
+ encoding: "utf-8",
2838
+ stdio: ["ignore", "pipe", "ignore"]
2839
+ }).trim() || void 0;
2840
+ } catch {
2841
+ l = void 0;
2842
+ }
2843
+ return de.set(r, l), l;
2844
+ }
2845
+ function Hn(r) {
2846
+ return r === "changelog" || r === "roadmap" ? "CollectionPage" : r === "openapi" ? "APIReference" : r === "hero" ? "WebPage" : "TechArticle";
2847
+ }
2848
+ function Un(r) {
2849
+ const l = t.meta ?? {}, a = t.site, g = r.frontmatter, $ = g.meta ?? {}, h = $.og ?? {}, p = $.twitter ?? {}, y = g.title, x = a?.title && a.title !== y ? `${y} · ${a.title}` : y, v = $.description ?? g.description ?? a?.description, j = $.canonical ?? xt(r.effectivePath), M = (() => {
2850
+ if ($.keywords) return Array.isArray($.keywords) ? $.keywords : [$.keywords];
2851
+ const X = ge(g.tags);
2852
+ return X.length ? X : l.keywords ?? [];
2853
+ })(), S = $.robots ?? "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1", N = h.title ?? y, I = h.description ?? v, U = h.image ?? a?.ogImage, C = U ? xt(U) ?? U : void 0, F = h.type ?? (g.type === "hero" || r.effectivePath === "/" ? "website" : "article"), D = l.og?.width ?? 1200, R = l.og?.height ?? 600, z = p.card ?? (C ? "summary_large_image" : "summary"), V = p.site ?? a?.twitterSite, T = qt, B = [];
2854
+ if (B.push(`<title>${T(x)}</title>`), v && B.push(`<meta name="description" content="${T(v)}">`), M.length && B.push(`<meta name="keywords" content="${T(M.join(", "))}">`), B.push(`<meta name="robots" content="${T(S)}">`), B.push(`<meta name="googlebot" content="${T(S)}">`), j) {
2855
+ B.push(`<link rel="canonical" href="${T(j)}">`);
2856
+ const X = l.localeAlternates ?? [];
2857
+ for (const Y of X)
2858
+ B.push(`<link rel="alternate" hreflang="${T(Y)}" href="${T(j)}">`);
2859
+ X.length && B.push(`<link rel="alternate" hreflang="x-default" href="${T(j)}">`);
2860
+ }
2861
+ if (B.push(`<meta property="og:title" content="${T(N)}">`), I && B.push(`<meta property="og:description" content="${T(I)}">`), B.push(`<meta property="og:type" content="${T(F)}">`), j && B.push(`<meta property="og:url" content="${T(j)}">`), C && (B.push(`<meta property="og:image" content="${T(C)}">`), B.push(`<meta property="og:image:width" content="${D}">`), B.push(`<meta property="og:image:height" content="${R}">`), h.imageAlt && B.push(`<meta property="og:image:alt" content="${T(h.imageAlt)}">`)), a?.title && B.push(`<meta property="og:site_name" content="${T(a.title)}">`), a?.locale && B.push(`<meta property="og:locale" content="${T(a.locale)}">`), B.push(`<meta name="twitter:card" content="${T(z)}">`), V && B.push(`<meta name="twitter:site" content="${T(V)}">`), B.push(`<meta name="twitter:title" content="${T(p.title ?? N)}">`), (p.description ?? I) && B.push(`<meta name="twitter:description" content="${T(p.description ?? I ?? "")}">`), (p.image ?? C) && B.push(`<meta name="twitter:image" content="${T(p.image ?? C ?? "")}">`), v && B.push(`<meta name="dc.description" content="${T(v)}">`), B.push(`<meta name="dc.title" content="${T(x)}">`), a?.locale && B.push(`<meta name="dc.language" content="${T(a.locale)}">`), g.type === "changelog" && (g.rss === !0 || g.subscribe === !0)) {
2862
+ const X = r.effectivePath === "/" ? "/rss.xml" : `${r.effectivePath}/rss.xml`, Y = xt(X) ?? X;
2863
+ B.push(`<link rel="alternate" type="application/rss+xml" title="${T(y)}" href="${T(Y)}">`);
2864
+ }
2865
+ const J = t.site?.url?.replace(/\/$/, ""), Z = [];
2866
+ if (l.organization && Z.push({ "@context": "https://schema.org", ...l.organization }), J && a?.title && Z.push({
2867
+ "@context": "https://schema.org",
2868
+ "@type": "WebSite",
2869
+ "@id": `${J}${gt(t.base, "/")}#website`,
2870
+ name: a.title,
2871
+ url: `${J}${gt(t.base, "/")}`,
2872
+ description: a.description
2873
+ }), j && r.effectivePath !== "/") {
2874
+ const X = [
2875
+ { name: a?.title ?? "Home", item: J ? `${J}${gt(t.base, "/")}` : void 0 }
2876
+ ], Y = r.effectivePath.split("/").filter(Boolean);
2877
+ let ct = "";
2878
+ for (const ut of Y) {
2879
+ ct += "/" + ut;
2880
+ const ht = [...o.values()].find((rt) => rt.effectivePath === ct);
2881
+ X.push({ name: ht?.frontmatter.title ?? se(ut), item: xt(ct) });
2882
+ }
2883
+ Z.push({
2884
+ "@context": "https://schema.org",
2885
+ "@type": "BreadcrumbList",
2886
+ itemListElement: X.map((ut, ht) => ({
2887
+ "@type": "ListItem",
2888
+ position: ht + 1,
2889
+ name: ut.name,
2890
+ item: ut.item
2891
+ }))
2892
+ });
2893
+ }
2894
+ Z.push({
2895
+ "@context": "https://schema.org",
2896
+ "@type": Hn(r.type),
2897
+ name: x,
2898
+ headline: y,
2899
+ description: v,
2900
+ url: j,
2901
+ isPartOf: J ? `${J}${gt(t.base, "/")}#website` : void 0,
2902
+ dateModified: qe(r.filePath)
2903
+ }), $.jsonLd && Z.push($.jsonLd);
2904
+ for (const X of Z) B.push(fr(X));
2905
+ return `
2906
+ ${B.join(`
2907
+ `)}
2908
+ `;
2909
+ }
2910
+ function Jn() {
2911
+ const r = t.meta ?? {};
2912
+ if (r.robots?.custom) return r.robots.custom;
2913
+ const l = new Set(r.robots?.block ?? []), a = ["User-agent: *", "Allow: /", ""];
2914
+ for (const $ of gn)
2915
+ a.push(`User-agent: ${$}`), a.push(l.has($) ? "Disallow: /" : "Allow: /"), a.push("");
2916
+ for (const $ of l)
2917
+ gn.includes($) || (a.push(`User-agent: ${$}`), a.push("Disallow: /"), a.push(""));
2918
+ r.robots?.append && a.push(r.robots.append, "");
2919
+ const g = xt("/sitemap.xml");
2920
+ return g && a.push(`Sitemap: ${g}`), a.join(`
2921
+ `).replace(/\n{3,}/g, `
2922
+
2923
+ `).trim() + `
2924
+ `;
2925
+ }
2926
+ function qn(r) {
2927
+ const l = t.site?.url?.replace(/\/$/, "");
2928
+ if (!l) return;
2929
+ const a = t.meta?.localeAlternates ?? [];
2930
+ return [
2931
+ '<?xml version="1.0" encoding="UTF-8"?>',
2932
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">',
2933
+ r.map(($) => {
2934
+ const h = `${l}${gt(t.base, $.effectivePath === "/" ? "/" : $.effectivePath)}`, p = $.effectivePath.split("/").filter(Boolean).length, y = p === 0 ? "1.0" : p === 1 ? "0.8" : "0.6", x = p === 0 ? "weekly" : "monthly", v = qe($.filePath), j = [` <loc>${ft(h)}</loc>`];
2935
+ v && j.push(` <lastmod>${ft(v)}</lastmod>`), j.push(` <changefreq>${x}</changefreq>`), j.push(` <priority>${y}</priority>`);
2936
+ for (const M of a)
2937
+ j.push(` <xhtml:link rel="alternate" hreflang="${ft(M)}" href="${ft(h)}"/>`);
2938
+ return ` <url>
2939
+ ${j.join(`
2940
+ `)}
2941
+ </url>`;
2942
+ }).join(`
2943
+ `),
2944
+ "</urlset>",
2945
+ ""
2946
+ ].join(`
2947
+ `);
2948
+ }
2949
+ function zn(r) {
2950
+ const l = t.meta ?? {}, a = t.site, g = [`# ${a?.title ?? t.title}`, ""], $ = l.llms?.summary ?? a?.description;
2951
+ $ && g.push(`> ${$}`, "");
2952
+ const h = /* @__PURE__ */ new Map(), p = [];
2953
+ for (const M of r) {
2954
+ const S = M.effectivePath.split("/").filter(Boolean);
2955
+ if (S.length === 0) {
2956
+ p.push(M);
2957
+ continue;
2958
+ }
2959
+ const N = S[0], I = h.get(N) ?? [];
2960
+ I.push(M), h.set(N, I);
2961
+ }
2962
+ const y = (M) => {
2963
+ const S = xt(M.effectivePath) ?? M.effectivePath;
2964
+ return M.frontmatter.description ? `- [${M.frontmatter.title}](${S}): ${M.frontmatter.description}` : `- [${M.frontmatter.title}](${S})`;
2965
+ };
2966
+ for (const M of p) g.push(y(M));
2967
+ p.length && g.push("");
2968
+ for (const [M, S] of [...h.entries()].sort((N, I) => N[0].localeCompare(I[0]))) {
2969
+ const N = S.find((I) => I.effectivePath === `/${M}`);
2970
+ g.push(`## ${N?.frontmatter.title ?? se(M)}`, ""), S.sort((I, U) => I.effectivePath.localeCompare(U.effectivePath));
2971
+ for (const I of S) g.push(y(I));
2972
+ g.push("");
2973
+ }
2974
+ const x = new Set(t.meta?.keywords ?? []);
2975
+ for (const M of r) for (const S of ge(M.frontmatter.tags)) x.add(S);
2976
+ x.size && g.push("## Keywords", "", [...x].join(", "), "");
2977
+ const v = xt("/sitemap.xml"), j = xt("/robots.txt");
2978
+ return (v || j) && (g.push("## Optional", ""), v && g.push(`- [Sitemap](${v})`), j && g.push(`- [Robots](${j})`), g.push("")), l.llms?.append && g.push(l.llms.append, ""), g.join(`
2979
+ `).replace(/\n{3,}/g, `
2980
+
2981
+ `);
2982
+ }
2983
+ function Gn(r) {
2984
+ const a = [`# ${t.site?.title ?? t.title}`, ""];
2985
+ for (const g of r) {
2986
+ a.push(`## ${g.frontmatter.title}`, "");
2987
+ const $ = xt(g.effectivePath);
2988
+ $ && a.push(`URL: ${$}`, ""), a.push(g.rawText.trim(), "");
2989
+ }
2990
+ return a.join(`
2991
+ `).replace(/\n{3,}/g, `
2992
+
2993
+ `);
2994
+ }
2995
+ async function Vn() {
2996
+ const r = t.meta ?? {}, l = Ln().sort((h, p) => h.effectivePath.localeCompare(p.effectivePath)), a = W(c, "index.html"), g = await it(a, "utf-8");
2997
+ for (const h of l) {
2998
+ const p = Un(h), y = g.replace("</head>", `${p}</head>`), x = h.effectivePath === "/" ? a : W(c, h.effectivePath.replace(/^\//, ""), "index.html");
2999
+ await Tt(G(x), { recursive: !0 }), await nt(x, y);
3000
+ }
3001
+ await nt(W(c, "robots.txt"), Jn());
3002
+ const $ = qn(l);
3003
+ if ($ && await nt(W(c, "sitemap.xml"), $), await nt(W(c, "llms.txt"), zn(l)), r.llms?.full && await nt(W(c, "llms-full.txt"), Gn(l)), r.webmanifest && await nt(W(c, "site.webmanifest"), JSON.stringify(r.webmanifest, null, 2) + `
3004
+ `), r.humans && await nt(W(c, "humans.txt"), r.humans.trim() + `
3005
+ `), r.security) {
3006
+ const h = r.security, p = [];
3007
+ h.contact && p.push(`Contact: ${h.contact}`), h.policy && p.push(`Policy: ${h.policy}`), h.languages && p.push(`Preferred-Languages: ${h.languages}`), h.canonical && p.push(`Canonical: ${h.canonical}`), h.expires && p.push(`Expires: ${h.expires}`), p.length && (await Tt(W(c, ".well-known"), { recursive: !0 }), await nt(W(c, ".well-known", "security.txt"), p.join(`
3008
+ `) + `
3009
+ `));
3010
+ }
3011
+ }
3012
+ async function Xn() {
3013
+ const r = [...o.values()].filter((p) => !ke(p.frontmatter) && yt(p)), l = {}, a = /* @__PURE__ */ new Map();
3014
+ for (const p of r) {
3015
+ const y = Xt(p);
3016
+ l[p.effectivePath] = { gate: p.frontmatter.gate, bundle: y };
3017
+ const x = a.get(y) ?? [];
3018
+ x.push(p), a.set(y, x);
3019
+ }
3020
+ const g = `/${t.paths.guarded}/`;
3021
+ if (await nt(
3022
+ W(c, "access.json"),
3023
+ JSON.stringify({ prefix: g, routes: l }, null, 2) + `
3024
+ `
3025
+ ), r.length === 0) return;
3026
+ const $ = W(c, t.paths.guarded), h = {};
3027
+ for (const [p, y] of a) {
3028
+ const x = W($, p);
3029
+ await Tt(W(x, "body"), { recursive: !0 });
3030
+ const v = {}, j = y.map((S) => ({
3031
+ slug: S.slug,
3032
+ path: S.effectivePath,
3033
+ type: S.type,
3034
+ frontmatter: S.frontmatter,
3035
+ bundle: p
3036
+ })), M = [`${p}/manifest.json`, `${p}/search.json`];
3037
+ for (const S of y) {
3038
+ S.pageCss && (v[S.effectivePath] = S.pageCss);
3039
+ const N = {
3040
+ html: S.html,
3041
+ headings: S.headings,
3042
+ openApiSpec: S.openApiSpec,
3043
+ openApiFile: S.openApiFile,
3044
+ openApiUrl: S.openApiUrl,
3045
+ changelogEntries: S.changelogEntries,
3046
+ roadmapEntries: S.roadmapEntries,
3047
+ componentData: S.componentData,
3048
+ dbmlSchema: S.dbmlSchema,
3049
+ dbmlSource: S.dbmlSource,
3050
+ dbmlFile: S.dbmlFile,
3051
+ dbmlError: S.dbmlError
3052
+ }, I = W(x, "body", `${At(S.slug)}.json`);
3053
+ await Tt(G(I), { recursive: !0 }), await nt(I, JSON.stringify(N)), M.push(`${p}/body/${At(S.slug)}.json`);
3054
+ }
3055
+ await nt(
3056
+ W(x, "manifest.json"),
3057
+ JSON.stringify({ shells: j, styles: v, sidebar: Ve(!0) })
3058
+ ), await nt(W(x, "search.json"), JSON.stringify(Xe(!0, y))), h[p] = {
3059
+ pages: Object.fromEntries(y.map((S) => [S.effectivePath, S.frontmatter.gate ?? ""])),
3060
+ files: M
3061
+ };
3062
+ }
3063
+ await nt(
3064
+ W(c, "guard.map.json"),
3065
+ JSON.stringify({ prefix: g, routes: l, bundles: h }, null, 2) + `
3066
+ `
3067
+ );
3068
+ }
3069
+ function Yn(r, l) {
3070
+ if (r.size === 0) return;
3071
+ const a = l.filter(($) => Kn($.type)), g = /* @__PURE__ */ new Map();
3072
+ for (const $ of a) g.set($.filePath, $);
3073
+ for (const [, $] of r) {
3074
+ const h = $[0], p = G(h.filePath), y = h.frontmatter.data, x = y?.issues ?? y?.entries, v = [];
3075
+ if (typeof x == "string") v.push(x);
3076
+ else if (Array.isArray(x))
3077
+ for (const C of x) typeof C == "string" && v.push(C);
3078
+ const j = v.length ? v.map((C) => q(p, C)) : [p], M = a.filter((C) => {
3079
+ for (const F of j)
3080
+ if (C.filePath !== F && (C.filePath.startsWith(F + "/") || C.filePath.startsWith(F + "\\")))
3081
+ return !0;
3082
+ return !1;
3083
+ }), S = y?.changelog, N = [];
3084
+ if (typeof S == "string")
3085
+ N.push(q(p, S));
3086
+ else if (Array.isArray(S))
3087
+ for (const C of S) typeof C == "string" && N.push(q(p, C));
3088
+ const I = /* @__PURE__ */ new Map();
3089
+ for (const C of l) {
3090
+ if (C.type !== "changelog" || N.length && !N.some(
3091
+ (ut) => C.filePath === ut || C.filePath.startsWith(ut + "/") || C.filePath.startsWith(ut + "\\")
3092
+ ))
3093
+ continue;
3094
+ const F = C.frontmatter.data, D = F?.issue;
3095
+ if (!D) continue;
3096
+ const R = String(D).trim();
3097
+ if (!R) continue;
3098
+ const z = ze(C.filePath, R);
3099
+ if (!z) continue;
3100
+ const V = g.get(z);
3101
+ if (!V) continue;
3102
+ const T = String(F?.version ?? ""), B = Ge(F?.release_date), J = F?.status;
3103
+ let Z, X = !1;
3104
+ if (typeof J == "string") {
3105
+ const ct = J.trim().toLowerCase();
3106
+ if (["completes", "completed", "complete", "fixes", "closes", "resolves"].includes(ct))
3107
+ X = !0;
3108
+ else {
3109
+ const ut = Number(ct.replace(/%$/, ""));
3110
+ Number.isFinite(ut) && (Z = ut);
3111
+ }
3112
+ } else typeof J == "number" && (Z = J);
3113
+ const Y = I.get(V.filePath) ?? [];
3114
+ Y.push({
3115
+ version: T,
3116
+ title: String(F?.title ?? C.frontmatter.title),
3117
+ description: F?.description !== void 0 ? String(F.description) : void 0,
3118
+ releaseDate: B,
3119
+ progress: Z,
3120
+ completes: X,
3121
+ path: C.effectivePath,
3122
+ slug: T ? `v${T}` : "unreleased",
3123
+ entrySlug: `${C.effectivePath}#${T ? `v${T}` : "unreleased"}`
3124
+ }), I.set(V.filePath, Y);
3125
+ }
3126
+ const U = M.map((C) => {
3127
+ const F = C.frontmatter.data, D = C.type, R = Ge(F?.date ?? F?.target_date);
3128
+ let z;
3129
+ const V = F?.parent;
3130
+ if (typeof V == "string" && V.trim()) {
3131
+ const Y = ze(C.filePath, V.trim());
3132
+ Y && g.has(Y) && (z = g.get(Y).effectivePath);
3133
+ }
3134
+ const T = (I.get(C.filePath) ?? []).slice().sort(
3135
+ (Y, ct) => (Y.releaseDate ?? "").localeCompare(ct.releaseDate ?? "")
3136
+ ), B = T.some((Y) => Y.completes), J = String(F?.status ?? "").toLowerCase(), Z = J === "shipped" || J === "in_progress" || J === "planned" ? J : B ? "shipped" : T.length ? "in_progress" : "planned", X = T.reduce((Y, ct) => typeof ct.progress == "number" ? Math.max(Y ?? 0, ct.progress) : Y, void 0);
3137
+ return {
3138
+ kind: D,
3139
+ slug: C.slug,
3140
+ filePath: C.filePath,
3141
+ href: C.effectivePath,
3142
+ title: C.frontmatter.title,
3143
+ description: C.frontmatter.description,
3144
+ targetDate: R,
3145
+ parent: z,
3146
+ progress: X,
3147
+ status: Z,
3148
+ hidden: ne(C.frontmatter),
3149
+ html: C.html,
3150
+ headings: C.headings,
3151
+ data: C.frontmatter.data,
3152
+ changelog: T
3153
+ };
3154
+ });
3155
+ U.sort((C, F) => (C.targetDate ?? "").localeCompare(F.targetDate ?? "")), h.roadmapEntries = U, h.headings = U.map((C) => ({
3156
+ level: 2,
3157
+ text: C.title,
3158
+ slug: C.slug
3159
+ }));
3160
+ }
3161
+ }
3162
+ function Kn(r) {
3163
+ return r === "milestone" || r === "epic" || r === "feature" || r === "bug";
3164
+ }
3165
+ function ze(r, l) {
3166
+ const a = G(r), g = l.replace(/\\/g, "/").trim(), $ = g.endsWith(".md") ? g : `${g}.md`;
3167
+ return q(a, $);
3168
+ }
3169
+ function Ge(r) {
3170
+ if (r == null) return;
3171
+ if (r instanceof Date) return r.toISOString();
3172
+ const l = String(r).trim();
3173
+ if (!l) return;
3174
+ const a = new Date(l);
3175
+ if (!Number.isNaN(a.getTime()))
3176
+ return a.toISOString();
3177
+ }
3178
+ function he(r, l) {
3179
+ if (!r || !/\.svg$/i.test(r.trim())) return r;
3180
+ const a = r.trim(), g = a.startsWith("/") ? W(n, a) : q(G(l), a);
3181
+ try {
3182
+ return zt(g, "utf8").trim();
3183
+ } catch {
3184
+ console.warn(`[nimpress] sidebar icon ${a} referenced from ${l} is not readable`);
3185
+ return;
3186
+ }
3187
+ }
3188
+ function Ve(r = !1) {
3189
+ const l = { children: /* @__PURE__ */ new Map() }, a = /* @__PURE__ */ new Map();
3190
+ for (const h of o.values()) {
3191
+ if (u && (Dt(h.frontmatter) || !r && yt(h))) continue;
3192
+ const p = h.frontmatter.sidebar;
3193
+ if (h.effectivePath === "/" && !p?.name) continue;
3194
+ const y = h.effectivePath === "/" ? [p.path ?? p.name] : h.effectivePath.split("/").filter(Boolean), x = h.filePath.endsWith(`${kt}index.md`);
3195
+ if (p?.name && x) {
3196
+ const S = "/" + y.join("/");
3197
+ a.set(S, {
3198
+ label: p.name,
3199
+ icon: he(p.icon, h.filePath) ?? a.get(S)?.icon,
3200
+ style: p.style ?? a.get(S)?.style
3201
+ });
3202
+ }
3203
+ if (h.sidebarOnly && !h.linkTo) continue;
3204
+ const v = x ? void 0 : p?.path ?? p?.name;
3205
+ v && y[y.length - 2] !== v && (y.length >= 3 ? y.splice(y.length - 2, 1, v) : y.splice(y.length - 1, 0, v));
3206
+ let j = l, M = "";
3207
+ for (const S of y) {
3208
+ M = M + "/" + S;
3209
+ let N = j.children.get(S);
3210
+ N || (N = { segment: S, fullPath: M, children: /* @__PURE__ */ new Map() }, j.children.set(S, N)), j = N;
3211
+ }
3212
+ if (j.page = h, !x && p?.name) {
3213
+ const S = "/" + y.slice(0, -1).join("/");
3214
+ a.set(S, {
3215
+ label: p.name,
3216
+ icon: he(p.icon, h.filePath) ?? a.get(S)?.icon,
3217
+ style: p.style ?? a.get(S)?.style
3218
+ });
3219
+ }
3220
+ }
3221
+ function g(h) {
3222
+ const p = [];
3223
+ for (const v of h.children.values()) p.push(g(v));
3224
+ if (Oe(p), h.page) {
3225
+ const v = {
3226
+ text: Dr(h.page),
3227
+ link: h.page.linkTo ?? h.page.effectivePath,
3228
+ external: h.page.linkTo ? !0 : void 0,
3229
+ slug: h.page.slug,
3230
+ gate: h.page.frontmatter.gate,
3231
+ order: h.page.frontmatter.order,
3232
+ collapsed: h.page.frontmatter.collapsed,
3233
+ hidden: ne(h.page.frontmatter)
3234
+ }, j = a.get(h.fullPath);
3235
+ j?.label && (v.text = j.label), j?.icon && !v.icon && (v.icon = j.icon), j?.style && (v.style = j.style);
3236
+ const M = h.page.openApiSpec;
3237
+ if (h.page.type === "openapi" && M?.tags?.length) {
3238
+ const S = M.tags.map((N) => ({
3239
+ text: N.name,
3240
+ link: `${h.page.effectivePath}#tag/${N.name}`,
3241
+ slug: `${h.page.slug}__tag__${N.name}`
3242
+ }));
3243
+ v.items = [...S, ...p];
3244
+ } else if (h.page.type === "changelog" && h.page.changelogEntries?.length) {
3245
+ const S = h.page.changelogEntries.map((N, I) => ({
3246
+ text: N.version ? `v${N.version}` : N.title || "unreleased",
3247
+ link: `${h.page.effectivePath}#${N.slug}`,
3248
+ slug: `${h.page.slug}__${N.slug}`,
3249
+ hidden: N.hidden,
3250
+ order: I
3251
+ }));
3252
+ v.items = p.length ? [...S, ...p] : S;
3253
+ } else if (h.page.type === "roadmap" && h.page.roadmapEntries?.length) {
3254
+ const S = h.page.roadmapEntries.slice().sort(
3255
+ (R, z) => (R.targetDate ?? "").localeCompare(z.targetDate ?? "")
3256
+ ), N = new Map(S.map((R) => [R.href, R])), I = /* @__PURE__ */ new Map(), U = [];
3257
+ for (const R of S)
3258
+ if (R.parent && N.has(R.parent)) {
3259
+ const z = I.get(R.parent) ?? [];
3260
+ z.push(R), I.set(R.parent, z);
3261
+ } else
3262
+ U.push(R);
3263
+ const C = (R, z) => {
3264
+ const V = I.get(R.href) ?? [], T = {
3265
+ text: R.title,
3266
+ link: R.href,
3267
+ slug: R.slug,
3268
+ icon: mr[R.kind],
3269
+ hidden: R.hidden,
3270
+ order: z
3271
+ };
3272
+ return V.length && (T.items = V.map((B, J) => C(B, J))), T;
3273
+ }, F = U.map((R, z) => C(R, z)), D = p.filter((R) => !R.slug || !S.some((z) => z.slug === R.slug));
3274
+ v.items = D.length ? [...F, ...D] : F;
3275
+ } else if (h.page.type === "component") {
3276
+ const S = {
3277
+ text: "Overview",
3278
+ link: h.page.effectivePath,
3279
+ slug: `${h.page.slug}__doc`,
3280
+ order: -1
3281
+ }, N = (h.page.componentData?.stories ?? []).map((I, U) => ({
3282
+ text: I.sidebar?.name ?? I.name,
3283
+ link: `${h.page.effectivePath}/${Pe(I.name)}`,
3284
+ slug: `${h.page.slug}__story__${Pe(I.name)}`,
3285
+ icon: he(I.sidebar?.icon, h.page.filePath),
3286
+ style: I.sidebar?.style,
3287
+ order: U
3288
+ }));
3289
+ v.text = se(h.segment), v.items = [S, ...N, ...p], v.collapsed = !0;
3290
+ } else p.length && (v.items = p);
3291
+ return v.collapsed !== !1 && v.items?.some((S) => S.collapsed === !1) && (v.collapsed = !1), v;
3292
+ }
3293
+ const y = a.get(h.fullPath), x = {
3294
+ text: y?.label ?? se(h.segment),
3295
+ slug: h.fullPath.replace(/^\//, "")
3296
+ };
3297
+ if (y?.icon && (x.icon = y.icon), y?.style && (x.style = y.style), p.length) {
3298
+ x.items = p;
3299
+ let v = Number.MAX_SAFE_INTEGER;
3300
+ for (const j of p)
3301
+ j.order !== void 0 && j.order < v && (v = j.order);
3302
+ v !== Number.MAX_SAFE_INTEGER && (x.order = v);
3303
+ }
3304
+ return x.items?.some((v) => v.collapsed === !1) && (x.collapsed = !1), x;
3305
+ }
3306
+ const $ = [];
3307
+ for (const h of l.children.values()) $.push(g(h));
3308
+ return Oe($), $;
3309
+ }
3310
+ function Zn() {
3311
+ const r = {}, l = {};
3312
+ for (const [g, $] of o) {
3313
+ if (u && (Dt($.frontmatter) || yt($)) || $.sidebarOnly) continue;
3314
+ const h = {
3315
+ slug: g,
3316
+ path: $.effectivePath,
3317
+ type: $.type,
3318
+ title: $.frontmatter.title,
3319
+ gate: $.frontmatter.gate,
3320
+ bundle: yt($) ? Xt($) : void 0,
3321
+ description: $.frontmatter.description,
3322
+ order: $.frontmatter.order,
3323
+ hidden: ne($.frontmatter),
3324
+ redirect: $.frontmatter.redirect,
3325
+ meta: $.frontmatter.meta
3326
+ };
3327
+ if (r[g] = h, l[$.effectivePath] = g, $.type === "component")
3328
+ for (const p of $.componentData?.stories ?? [])
3329
+ l[`${$.effectivePath}/${Pe(p.name)}`] = g;
3330
+ }
3331
+ const a = {};
3332
+ for (const g of o.values())
3333
+ g.sidebarOnly || u && (Dt(g.frontmatter) || yt(g)) || g.pageCss && (a[g.effectivePath] = g.pageCss);
3334
+ return { pages: r, byPath: l, sidebar: Ve(), styles: a };
3335
+ }
3336
+ function Xe(r = !1, l) {
3337
+ const a = [], g = l ? l.map(($) => [$.slug, $]) : o;
3338
+ for (const [$, h] of g) {
3339
+ if (h.sidebarOnly) continue;
3340
+ if (r) {
3341
+ if (Dt(h.frontmatter) || !yt(h)) continue;
3342
+ } else if (u && (Dt(h.frontmatter) || yt(h))) continue;
3343
+ const p = h.rawText.replace(/```[\s\S]*?```/g, "").replace(/[#*`>_\[\]\(\)]/g, " "), y = h.type === "openapi" ? Qn(h.openApiSpec) : "", x = h.type === "roadmap" ? ts(h.roadmapEntries ?? []) : "", v = h.componentData ? [
3344
+ h.componentData.component,
3345
+ h.componentData.system,
3346
+ ...(h.componentData.stories ?? []).flatMap((S) => [S.name, S.file])
3347
+ ].filter(Boolean).join(" ") : "", j = h.dbmlSource ? h.dbmlSource.replace(/[{}\[\]'"`,]/g, " ") : "", M = [p, y, x, v, j].filter(Boolean).join(`
3348
+ `);
3349
+ a.push({
3350
+ slug: $,
3351
+ path: h.effectivePath,
3352
+ title: h.frontmatter.title,
3353
+ description: h.frontmatter.description,
3354
+ body: M,
3355
+ gate: h.frontmatter.gate,
3356
+ headings: h.headings.map((S) => S.text),
3357
+ tags: [
3358
+ ...ge(h.frontmatter.tags),
3359
+ ...h.componentData ? [h.componentData.component] : []
3360
+ ]
3361
+ });
3362
+ }
3363
+ return a;
3364
+ }
3365
+ function Ye(r) {
3366
+ return r ? r.replace(/<[^>]+>/g, " ").replace(/&[a-z]+;/gi, " ") : "";
3367
+ }
3368
+ function Qn(r) {
3369
+ if (!r || typeof r != "object") return "";
3370
+ const l = r, a = [], g = /* @__PURE__ */ new WeakSet(), $ = 12, h = (p, y) => {
3371
+ if (p == null || y > $) return;
3372
+ const x = typeof p;
3373
+ if (x === "string") {
3374
+ const v = p.trim();
3375
+ v && a.push(v);
3376
+ return;
3377
+ }
3378
+ if (x === "number" || x === "boolean") {
3379
+ a.push(String(p));
3380
+ return;
3381
+ }
3382
+ if (x === "object" && !g.has(p)) {
3383
+ if (g.add(p), Array.isArray(p)) {
3384
+ for (const v of p) h(v, y + 1);
3385
+ return;
3386
+ }
3387
+ for (const [v, j] of Object.entries(p)) {
3388
+ if (v === "description_html" || v === "summary_html" || v === "requestBodyHtml") {
3389
+ typeof j == "string" && a.push(Ye(j));
3390
+ continue;
3391
+ }
3392
+ a.push(v), h(j, y + 1);
3393
+ }
3394
+ }
3395
+ };
3396
+ l.title && a.push(l.title), l.description && a.push(l.description);
3397
+ for (const p of l.servers ?? [])
3398
+ p.url && a.push(p.url), p.description && a.push(p.description);
3399
+ for (const [p, y] of Object.entries(l.securitySchemes ?? {}))
3400
+ a.push(p), h(y, 0);
3401
+ for (const p of l.tags ?? []) {
3402
+ p.name && a.push(p.name), p.description && a.push(p.description);
3403
+ for (const y of p.operations ?? []) {
3404
+ const x = y;
3405
+ x.method && a.push(x.method.toLowerCase(), x.method.toUpperCase()), h(y, 0);
3406
+ }
3407
+ }
3408
+ for (const [p, y] of Object.entries(l.schemas ?? {}))
3409
+ a.push(p), h(y, 0);
3410
+ return a.join(`
3411
+ `);
3412
+ }
3413
+ function ts(r) {
3414
+ const l = [];
3415
+ for (const a of r) {
3416
+ l.push(a.slug, a.kind, a.title), a.description && l.push(a.description), a.targetDate && l.push(a.targetDate), a.html && l.push(Ye(a.html));
3417
+ for (const g of a.changelog)
3418
+ l.push(g.version, g.title), g.description && l.push(g.description), g.releaseDate && l.push(g.releaseDate);
3419
+ }
3420
+ return l.join(`
3421
+ `);
3422
+ }
3423
+ function ge(r) {
3424
+ if (!r) return [];
3425
+ const l = Array.isArray(r) ? r : String(r).split(","), a = [];
3426
+ for (const g of l) {
3427
+ const $ = String(g).trim();
3428
+ $ && a.push($);
3429
+ }
3430
+ return a;
3431
+ }
3432
+ function At(r) {
3433
+ return r === "" ? "__root__" : r;
3434
+ }
3435
+ function Ke(r) {
3436
+ return r === "__root__" ? "" : r;
3437
+ }
3438
+ function Yt(r) {
3439
+ for (const l of [Zt, Qt, te, ee]) {
3440
+ const a = r.moduleGraph.getModuleById("\0" + l);
3441
+ a && r.moduleGraph.invalidateModule(a);
3442
+ }
3443
+ }
3444
+ function ye(r) {
3445
+ for (const l of o.keys()) {
3446
+ const a = _t + At(l) + ".js", g = Ft + At(l) + ".svelte", $ = r.moduleGraph.getModuleById(a), h = r.moduleGraph.getModuleById(g);
3447
+ $ && r.moduleGraph.invalidateModule($), h && r.moduleGraph.invalidateModule(h);
3448
+ }
3449
+ }
3450
+ function es() {
3451
+ const r = [];
3452
+ for (const [l, a] of o) {
3453
+ if (a.sidebarOnly || u && (Dt(a.frontmatter) || yt(a))) continue;
3454
+ const g = `${Ft}${At(l)}.svelte`;
3455
+ r.push(` ${JSON.stringify(l)}: () => import(${JSON.stringify(g)})`);
3456
+ }
3457
+ return `export const pages = {
3458
+ ${r.join(`,
3459
+ `)}
3460
+ }
3461
+ export default pages
3462
+ `;
3463
+ }
3464
+ function ns() {
3465
+ const r = [];
3466
+ for (const [l, a] of o) {
3467
+ if (a.sidebarOnly || u && (Dt(a.frontmatter) || yt(a))) continue;
3468
+ const g = `${_t}${At(l)}.js`;
3469
+ r.push(` ${JSON.stringify(l)}: () => import(${JSON.stringify(g)})`);
3470
+ }
3471
+ return `export const bodies = {
3472
+ ${r.join(`,
3473
+ `)}
3474
+ }
3475
+ export default bodies
3476
+ `;
3477
+ }
3478
+ function ss(r) {
3479
+ const l = o.get(r);
3480
+ if (!l) return null;
3481
+ const a = {
3482
+ html: l.html,
3483
+ headings: l.headings,
3484
+ openApiSpec: l.openApiSpec,
3485
+ openApiFile: l.openApiFile,
3486
+ openApiUrl: l.openApiUrl,
3487
+ changelogEntries: l.changelogEntries,
3488
+ roadmapEntries: l.roadmapEntries,
3489
+ componentData: l.componentData,
3490
+ dbmlSchema: l.dbmlSchema,
3491
+ dbmlSource: l.dbmlSource,
3492
+ dbmlFile: l.dbmlFile,
3493
+ dbmlError: l.dbmlError
3494
+ };
3495
+ return `export default ${JSON.stringify(a)}
3496
+ `;
3497
+ }
3498
+ function os(r) {
3499
+ const l = o.get(r);
3500
+ if (!l) return null;
3501
+ const a = {
3502
+ slug: l.slug,
3503
+ path: l.effectivePath,
3504
+ type: l.type,
3505
+ frontmatter: l.frontmatter
3506
+ }, g = `${_t}${At(r)}.js`;
3507
+ return `<script lang="ts">
3508
+ import { Page, OpenApiRoot, ChangelogPage, HeroPage, RoadmapPage, ComponentPage, DbmlPage, setPageMeta, applyPageStyles } from '@nimtech/nimpress'
3509
+ import type { PageBody } from '@nimtech/nimpress'
3510
+ const shell = ${JSON.stringify(a).replace(/<\/script>/g, "<\\/script>")}
3511
+ setPageMeta(shell)
3512
+ applyPageStyles(shell.path)
3513
+ const bodyPromise: Promise<{ default: PageBody }> = import(${JSON.stringify(g)})
3514
+ <\/script>
3515
+
3516
+ {#if shell.type === 'hero'}
3517
+ <HeroPage page={shell} {bodyPromise} />
3518
+ {:else}
3519
+ {#await bodyPromise}
3520
+ <div class="np-page-loading" aria-busy="true"></div>
3521
+ {:then mod}
3522
+ {#if shell.type === 'openapi' && mod.default.openApiSpec}
3523
+ <OpenApiRoot spec={mod.default.openApiSpec} specFile={mod.default.openApiFile} specUrl={mod.default.openApiUrl} title={shell.frontmatter.title} frontmatter={shell.frontmatter} />
3524
+ {:else if shell.type === 'changelog'}
3525
+ <ChangelogPage page={{ ...shell, ...mod.default }} />
3526
+ {:else if shell.type === 'roadmap'}
3527
+ <RoadmapPage page={{ ...shell, ...mod.default }} />
3528
+ {:else if shell.type === 'component'}
3529
+ <ComponentPage page={{ ...shell, ...mod.default }} />
3530
+ {:else if shell.type === 'dbml'}
3531
+ <DbmlPage page={{ ...shell, ...mod.default }} />
3532
+ {:else}
3533
+ <Page page={{ ...shell, ...mod.default }} />
3534
+ {/if}
3535
+ {:catch err}
3536
+ <div class="np-page-error">Failed to load page body: {String(err)}</div>
3537
+ {/await}
3538
+ {/if}
3539
+ `;
3540
+ }
3541
+ return {
3542
+ name: "@nimtech/nimpress:markdown",
3543
+ async config() {
3544
+ return t = (await Ws(process.cwd(), e)).resolved, n = q(process.cwd(), t.contentDir), s = q(process.cwd(), t.assetsDir), {};
3545
+ },
3546
+ configResolved(r) {
3547
+ u = r.command === "build", c = q(r.root, r.build.outDir);
3548
+ },
3549
+ async buildStart() {
3550
+ await at(), u && Nt();
3551
+ },
3552
+ async closeBundle(r) {
3553
+ if (!u || r) return;
3554
+ const l = W(c, "index.html"), a = W(c, "404.html");
3555
+ if (await rs(l, a), await nt(W(c, ".nojekyll"), ""), dt(n) && await Ze(n, c, {
3556
+ recursive: !0,
3557
+ filter: (g) => {
3558
+ try {
3559
+ return ie(g).isDirectory() || !(g.endsWith(".md") || g.endsWith(".css"));
3560
+ } catch {
3561
+ return !1;
3562
+ }
3563
+ }
3564
+ }), dt(s)) {
3565
+ const g = W(c, t.assetUrlBase.replace(/^\//, ""));
3566
+ await Ze(s, g, { recursive: !0 });
3567
+ }
3568
+ for (const [g, $] of St) {
3569
+ const h = W(c, g.replace(/^\//, ""));
3570
+ await Tt(G(h), { recursive: !0 }), await nt(h, $);
3571
+ }
3572
+ await nt(W(c, "subscribe.map.json"), me), await Vn(), await Xn();
3573
+ },
3574
+ configureServer(r) {
3575
+ b = r, r.watcher.add(n), r.watcher.add(s);
3576
+ for (const p of w) r.watcher.add(p);
3577
+ for (const p of P) r.watcher.add(p);
3578
+ const l = async (p) => {
3579
+ if (!(!p.startsWith(n) || !(p.endsWith(".md") || p.endsWith(".css") || p.match(/\.story\.tsx?$/)))) {
3580
+ p.endsWith(".css") && pt(p.replace(/\.css$/, ".md")), p.match(/\.story\.tsx?$/) && pt(W(G(p), "index.md"));
3581
+ try {
3582
+ await at();
3583
+ } catch (x) {
3584
+ r.config.logger.error(String(x));
3585
+ return;
3586
+ }
3587
+ Yt(r), ye(r), Nt(), r.ws.send({ type: "full-reload" });
3588
+ }
3589
+ }, a = async (p) => {
3590
+ if (p.startsWith(n) && (p.endsWith(".md") || p.endsWith(".css") || p.match(/\.story\.tsx?$/))) {
3591
+ p.match(/\.story\.tsx?$/) ? pt(W(G(p), "index.md")) : pt(p.endsWith(".css") ? p.replace(/\.css$/, ".md") : p);
3592
+ try {
3593
+ await at();
3594
+ } catch (x) {
3595
+ r.config.logger.error(String(x));
3596
+ return;
3597
+ }
3598
+ Yt(r), ye(r), Nt(), r.ws.send({ type: "full-reload" });
3599
+ return;
3600
+ }
3601
+ if (m.has(p)) {
3602
+ const x = m.get(p);
3603
+ pt(x);
3604
+ }
3605
+ k.has(p) && pt(k.get(p));
3606
+ };
3607
+ if (r.watcher.on("add", l), r.watcher.on("unlink", a), t.banner !== !1) {
3608
+ const p = zs(), y = t.banner, x = Date.now();
3609
+ r.printUrls = function() {
3610
+ const v = r.resolvedUrls, j = v?.local?.[0] ?? `http://localhost:${r.config.server.port ?? 5173}/`, M = v?.network?.[0] ?? "use --host to expose", S = qs({
3611
+ title: y.title ?? t.title ?? p.name ?? "Nimpress",
3612
+ tagline: y.tagline,
3613
+ company: y.company,
3614
+ version: y.version ?? p.version,
3615
+ localUrl: j,
3616
+ networkUrl: M,
3617
+ duration: Date.now() - x
3618
+ });
3619
+ process.stdout.write("\x1Bc"), process.stdout.write(S + `
3620
+ `), Nt();
3621
+ };
3622
+ }
3623
+ const g = {
3624
+ ".png": "image/png",
3625
+ ".jpg": "image/jpeg",
3626
+ ".jpeg": "image/jpeg",
3627
+ ".gif": "image/gif",
3628
+ ".svg": "image/svg+xml",
3629
+ ".webp": "image/webp",
3630
+ ".ico": "image/x-icon",
3631
+ ".pdf": "application/pdf",
3632
+ ".json": "application/json",
3633
+ ".css": "text/css",
3634
+ ".js": "text/javascript",
3635
+ ".txt": "text/plain",
3636
+ ".woff": "font/woff",
3637
+ ".woff2": "font/woff2",
3638
+ ".mp4": "video/mp4"
3639
+ }, $ = t.assetUrlBase, h = (p, y, x) => {
3640
+ if (!y || y.endsWith(".md")) return !1;
3641
+ const v = W(p, decodeURIComponent(y));
3642
+ return !v.startsWith(p) || !dt(v) || !ie(v).isFile() ? !1 : (x.setHeader("Content-Type", g[_e(v).toLowerCase()] ?? "application/octet-stream"), is(v).pipe(x), !0);
3643
+ };
3644
+ return r.middlewares.use((p, y, x) => {
3645
+ const v = (p.url ?? "").split("?")[0], j = Es(t.base, v);
3646
+ if (j.startsWith("/@") || j.startsWith("/node_modules/")) return x();
3647
+ if (j === "/__nimpress/claude-md" && p.method === "PUT") {
3648
+ const I = [];
3649
+ p.on("data", (U) => I.push(U)), p.on("end", async () => {
3650
+ try {
3651
+ const U = JSON.parse(Buffer.concat(I).toString("utf-8")), C = String(U.path ?? ""), F = String(U.content ?? ""), D = q(process.cwd(), C);
3652
+ if (!Object.values(t.modules.systems).filter((V) => V.source).map((V) => q(process.cwd(), V.source)).some((V) => D.startsWith(V + kt)) || !D.endsWith(`${kt}CLAUDE.md`) || !dt(G(D))) {
3653
+ y.statusCode = 403, y.end("invalid claude-md target");
3654
+ return;
3655
+ }
3656
+ await nt(D, F), pt(k.get(D) ?? ""), y.statusCode = 204, y.end();
3657
+ } catch (U) {
3658
+ y.statusCode = 400, y.end(String(U));
3659
+ }
3660
+ });
3661
+ return;
3662
+ }
3663
+ if (j === "/__nimpress/schema-defaults" && p.method === "PUT") {
3664
+ const I = [];
3665
+ p.on("data", (U) => I.push(U)), p.on("end", async () => {
3666
+ try {
3667
+ const U = JSON.parse(Buffer.concat(I).toString("utf-8")), C = String(U.path ?? ""), F = q(process.cwd(), C), D = F.endsWith(`${kt}schema.json`) || F.endsWith(`${kt}schema.yml`);
3668
+ if (!F.startsWith(n + kt) || !D || !dt(F)) {
3669
+ y.statusCode = 403, y.end("invalid schema target");
3670
+ return;
3671
+ }
3672
+ const R = F.endsWith(".yml") ? "yml" : "json", z = Vt(await it(F, "utf-8"), R);
3673
+ for (const [V, T] of Object.entries(U.defaults ?? {})) {
3674
+ const B = z.properties?.[V];
3675
+ B && (B.default = T);
3676
+ }
3677
+ await nt(F, Jt(z, R)), pt(k.get(F) ?? ""), y.statusCode = 204, y.end();
3678
+ } catch (U) {
3679
+ y.statusCode = 400, y.end(String(U));
3680
+ }
3681
+ });
3682
+ return;
3683
+ }
3684
+ const M = St.get(j);
3685
+ if (M !== void 0) {
3686
+ y.setHeader("Content-Type", "application/rss+xml; charset=utf-8"), y.end(M);
3687
+ return;
3688
+ }
3689
+ if (j === "/subscribe.map.json") {
3690
+ y.setHeader("Content-Type", "application/json; charset=utf-8"), y.end(me);
3691
+ return;
3692
+ }
3693
+ const S = t.modules.route.replace(/\/$/, "");
3694
+ if (j === S || j.startsWith(S + "/")) {
3695
+ const I = j.slice(S.length).replace(/^\/+/, ""), U = decodeURIComponent(I.split("/")[0] ?? "");
3696
+ if (!t.modules.systems[U]) {
3697
+ y.statusCode = 404, y.end(`unknown module system: ${U}`);
3698
+ return;
3699
+ }
3700
+ const F = as(
3701
+ {
3702
+ host: "127.0.0.1",
3703
+ port: Ce(t.modules, U),
3704
+ path: `${j}${(p.url ?? "").includes("?") ? `?${(p.url ?? "").split("?").slice(1).join("?")}` : ""}`,
3705
+ method: p.method,
3706
+ headers: p.headers
3707
+ },
3708
+ (D) => {
3709
+ y.writeHead(D.statusCode ?? 502, D.headers), D.pipe(y);
3710
+ }
3711
+ );
3712
+ F.on("error", () => {
3713
+ y.statusCode = 503, y.setHeader("Content-Type", "text/html"), y.end(
3714
+ `<!doctype html><html><body style="font-family:monospace;padding:2rem"><p>module harness for <b>${U}</b> is not running.</p><p>start it with: <code>nimpress modules dev ${U}</code></p></body></html>`
3715
+ );
3716
+ }), p.pipe(F);
3717
+ return;
3718
+ }
3719
+ if ($ === "/" || j === $ || j.startsWith($ + "/")) {
3720
+ const I = $ === "/" ? j : j.slice($.length);
3721
+ if (h(s, I.replace(/^\/+/, ""), y)) return;
3722
+ }
3723
+ h(n, j.replace(/^\/+/, ""), y) || x();
3724
+ }), () => {
3725
+ r.middlewares.use(async (p, y, x) => {
3726
+ if (p.method !== "GET" && p.method !== "HEAD" || !(p.headers.accept ?? "").includes("text/html")) return x();
3727
+ try {
3728
+ const v = await r.transformIndexHtml(
3729
+ p.url ?? "/",
3730
+ lr(t, "/@id/__x00__virtual:nimpress/main")
3731
+ );
3732
+ y.statusCode = 200, y.setHeader("Content-Type", "text/html"), y.end(v);
3733
+ } catch (v) {
3734
+ x(v);
3735
+ }
3736
+ });
3737
+ };
3738
+ },
3739
+ async handleHotUpdate(r) {
3740
+ const l = r.file, a = l.endsWith(".md") && l.startsWith(n), g = l.endsWith(".css") && l.startsWith(n), $ = l.match(/\.story\.tsx?$/) && l.startsWith(n), h = m.get(l), p = k.get(l);
3741
+ if (g) {
3742
+ pt(l.replace(/\.css$/, ".md"));
3743
+ try {
3744
+ await at();
3745
+ } catch (x) {
3746
+ r.server.config.logger.error(String(x));
3747
+ return;
3748
+ }
3749
+ return Yt(r.server), r.server.ws.send({ type: "full-reload" }), [];
3750
+ }
3751
+ if (!a && !$ && !h && !p) return;
3752
+ const y = a ? l : $ ? W(G(l), "index.md") : h ?? p;
3753
+ pt(y);
3754
+ try {
3755
+ await at();
3756
+ } catch (x) {
3757
+ r.server.config.logger.error(String(x));
3758
+ return;
3759
+ }
3760
+ return Yt(r.server), ye(r.server), Nt(), r.server.ws.send({ type: "full-reload" }), [];
3761
+ },
3762
+ resolveId(r) {
3763
+ return r === Zt ? "\0" + Zt : r === Qt ? "\0" + Qt : r === te ? "\0" + te : r === ee ? "\0" + ee : r === $e ? "\0" + $e : r === Se ? "\0" + Se : r.startsWith(Ft) && r.endsWith(".svelte") || r.startsWith(_t) && r.endsWith(".js") ? r : null;
3764
+ },
3765
+ async load(r) {
3766
+ if (r === "\0" + Zt)
3767
+ return `export default ${JSON.stringify(Zn())}`;
3768
+ if (r === "\0" + $e)
3769
+ return `export default ${JSON.stringify(Ls(t))}`;
3770
+ if (r === "\0" + Se) {
3771
+ const l = t.css.map((h) => `import ${JSON.stringify(h.startsWith("/") ? h : "/" + h)}`).join(`
3772
+ `), a = t.client ? t.client.startsWith("/") ? t.client : "/" + t.client.replace(/^\.\//, "") : null, g = a ? `import { authFunctions, subscribeFunctions } from ${JSON.stringify(a)}` : "";
3773
+ return `import '@nimtech/nimpress/app.css'
3774
+ ${l}
3775
+ import { createNimpressApp } from '@nimtech/nimpress'
3776
+ import config from 'virtual:nimpress/config'
3777
+ import manifest from 'virtual:nimpress/manifest'
3778
+ import searchIndex from 'virtual:nimpress/search'
3779
+ import pages from 'virtual:nimpress/pages'
3780
+ ${g}
3781
+ const app = createNimpressApp({ ...config, manifest, searchIndex, pageLoader: pages${a ? ", authFunctions, subscribeFunctions" : ""} })
3782
+ const target = document.getElementById('app')
3783
+ if (!target) throw new Error('Mount target #app missing')
3784
+ app.mount(target)
3785
+ `;
3786
+ }
3787
+ if (r === "\0" + Qt)
3788
+ return `export default ${JSON.stringify(Xe())}`;
3789
+ if (r === "\0" + te)
3790
+ return es();
3791
+ if (r === "\0" + ee)
3792
+ return ns();
3793
+ if (r.startsWith(Ft) && r.endsWith(".svelte")) {
3794
+ const l = r.slice(Ft.length, -7);
3795
+ return os(Ke(l));
3796
+ }
3797
+ if (r.startsWith(_t) && r.endsWith(".js")) {
3798
+ const l = r.slice(_t.length, -3);
3799
+ return ss(Ke(l));
3800
+ }
3801
+ return null;
3802
+ }
3803
+ };
3804
+ }
3805
+ function ii(e) {
3806
+ return e;
3807
+ }
3808
+ async function ai(e, t) {
3809
+ const n = q(e, t), s = await Je(n), o = [];
3810
+ for (const i of s) {
3811
+ let c;
3812
+ try {
3813
+ c = await it(i, "utf-8");
3814
+ } catch {
3815
+ continue;
3816
+ }
3817
+ const { data: u, content: b } = Te(c);
3818
+ for (const d of Fn(u, b))
3819
+ o.push(`${jt(n, i).split(kt).join("/")}: ${d}`);
3820
+ }
3821
+ return o;
3822
+ }
3823
+ export {
3824
+ ii as A,
3825
+ No as a,
3826
+ We as b,
3827
+ Re as c,
3828
+ Wt as d,
3829
+ ln as e,
3830
+ un as f,
3831
+ Nt as g,
3832
+ oi as h,
3833
+ lr as i,
3834
+ ri as j,
3835
+ Ce as k,
3836
+ ai as l,
3837
+ Dn as m,
3838
+ si as n,
3839
+ ei as o,
3840
+ Vt as p,
3841
+ _o as q,
3842
+ ue as r,
3843
+ Gt as s,
3844
+ ti as t,
3845
+ ni as u,
3846
+ qo as v,
3847
+ He as w,
3848
+ Ws as x,
3849
+ yr as y,
3850
+ Ar as z
3851
+ };