@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.
@@ -1,3815 +0,0 @@
1
- import { readdir as Oe, readFile as rt, writeFile as nt, copyFile as rs, cp as Ze, mkdir as _t } from "node:fs/promises";
2
- import { existsSync as mt, readFileSync as qt, statSync as re, readdirSync as le, 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 V, join as W, basename as Ot, relative as jt, extname as Me, isAbsolute as vt, sep as kt } from "node:path";
6
- import { createHash as vn } from "node:crypto";
7
- import _e 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 bn, 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 vs } from "@dbml/core";
20
- import { n as bs, r as Ht, e as ie, b as Pe, p as wn, c as Te, d as Ne, g as ae, h as ws, k as Fe, o as $s, s as Ss, l as xs, q as ks, t as Ps, j as dt, 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
- }, Rt = {
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 je(e, t) {
164
- if (!t) return e;
165
- const n = { ...e };
166
- for (const [s, r] of Object.entries(t)) {
167
- if (r === void 0) continue;
168
- const i = n[s];
169
- sn(i) && sn(r) ? n[s] = je(i, r) : n[s] = r;
170
- }
171
- return n;
172
- }
173
- async function Rs(e) {
174
- for (const t of Bs) {
175
- const n = q(e, t);
176
- if (!mt(n)) continue;
177
- if (t.endsWith(".json")) {
178
- const i = JSON.parse(qt(n, "utf-8"));
179
- return { config: nn(i, n), file: n };
180
- }
181
- const r = (await Os({ command: "serve", mode: "development" }, n, e))?.config ?? {};
182
- return { config: nn(r, 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, r = t ? { ...t, modules: void 0 } : void 0;
188
- let i = je(Rt, s);
189
- i = je(i, r), i.css = typeof i.css == "string" ? [i.css] : i.css ?? [], i.base = bs(i.base);
190
- const c = t?.modules ?? n?.config?.modules;
191
- return i.modules = {
192
- dir: Rt.modules.dir,
193
- route: `/${i.paths.modules}`,
194
- systems: c ? Object.fromEntries(c.map((p) => [p.name, p])) : {}
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", ce = "\x1B[1m", se = "\x1B[2m", $n = "\x1B[38;2;204;120;92m", Pt = "\x1B[38;2;229;174;156m", Ct = "\x1B[38;2;160;160;170m", Yt = [
214
- " ███╗ ██╗ ██╗ ███╗ ███╗ ██████╗ ██████╗ ███████╗ ███████╗ ███████╗",
215
- " ████╗ ██║ ██║ ████╗ ████║ ██╔══██╗ ██╔══██╗ ██╔════╝ ██╔════╝ ██╔════╝",
216
- " ██╔██╗ ██║ ██║ ██╔████╔██║ ██████╔╝ ██████╔╝ █████╗ ███████╗ ███████╗",
217
- " ██║╚██╗██║ ██║ ██║╚██╔╝██║ ██╔═══╝ ██╔══██╗ ██╔══╝ ╚════██║ ╚════██║",
218
- " ██║ ╚████║ ██║ ██║ ╚═╝ ██║ ██║ ██║ ██║ ███████╗ ███████║ ███████║",
219
- " ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚══════╝"
220
- ], Ft = 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(Ft + 2) + "╗", n = "╠" + "═".repeat(Ft + 2) + "╣", s = "╚" + "═".repeat(Ft + 2) + "╝", r = [t];
227
- for (let i = 0; i < e.length; i++)
228
- r.push("║ " + Hs(e[i], Ft) + " ║"), i < e.length - 1 && r.push(n);
229
- return r.push(s), r;
230
- }
231
- function Js() {
232
- try {
233
- const e = V(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 = qt(n, "utf-8"), r = JSON.parse(s);
241
- if (r?.name === "@nimtech/nimpress" && typeof r.version == "string") return r.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()}`, r = e.version ?? "dev", i = e.localUrl ?? "http://localhost:5173/", c = e.networkUrl ?? "use --host to expose", p = typeof e.duration == "number" ? `ready in ${e.duration} ms` : "ready", v = e.nimpressVersion ?? Js(), d = [];
250
- d.push("");
251
- for (const H of Yt) d.push($n + H + et);
252
- d.push("");
253
- const m = [
254
- `${ce}${t}${et}${Ct} · ${s}${et}`,
255
- `${Ct}${n}${et}`,
256
- `${Pt}Version${et} ${r} ${Pt}${p}${et}`
257
- ];
258
- v && m.push(`${Pt}Nimpress${et} ${v}`), m.push(`${Pt}➜${et} Local ${ce}${i}${et}`), m.push(`${Pt}➜${et} Network ${se}${c}${et}`);
259
- const S = Us(m), k = Yt[0].length, j = Yt[0].length - Yt[0].trimStart().length, T = Ft + 4, D = " ".repeat(Math.max(0, Math.floor((k + j - T) / 2)));
260
- for (const H of S) d.push(D + H);
261
- return d.push(""), d.join(`
262
- `);
263
- }
264
- function zs() {
265
- try {
266
- const e = qt(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, Wt = 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 Ie 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, r = s?.start?.line, i = s?.start?.column;
279
- return `${r ? `line ${r}${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(vs.export(e, "json"));
286
- } catch (t) {
287
- throw new Ie(go(t));
288
- }
289
- }
290
- function vo(e) {
291
- return (e.type?.type_name ?? "").trim();
292
- }
293
- function bo(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 oe(e, t, n) {
307
- if (!e) return 0;
308
- const s = Math.max(1, Math.floor(n / t));
309
- return e.split(`
310
- `).reduce((r, i) => r + Math.max(1, Math.ceil(i.trim().length / s)), 0);
311
- }
312
- function ye(e) {
313
- return e.reduce((t, n) => Math.max(t, n.length), 0);
314
- }
315
- function So(e, t) {
316
- const n = ye(t.map((v) => v.name)) * oo, s = ye(t.map((v) => v.type)) * ro, r = ye(t.map((v) => v.linkLabel)) * co, i = t.some((v) => v.pk || v.fk) ? lo : 0, c = Math.round(n + s + r + i + po), p = Math.round(e.length * xn + 32);
317
- return Math.min(no, Math.max(eo, c, p));
318
- }
319
- function xo(e) {
320
- const t = e.width - so, n = Math.max(1, oe(e.name, xn, t)), s = oe(e.note, io, t), r = Ys + n * Ks + s * Zs, i = Math.max(e.columns.length, 1) * Gs, c = e.indexes.reduce(
321
- (v, d) => v + oe(`${d.unique ? "unique" : "index"} ${d.columns.join(", ")}`, ao, t),
322
- 0
323
- ), p = e.indexes.length ? Xs + c * Vs : 0;
324
- return Math.round(r + i + p + 2);
325
- }
326
- function ko(e) {
327
- const t = e.width - rn, n = oe(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, r) => s.y - r.y || s.x - r.x);
335
- for (let s = 1; s < n.length; s++) {
336
- let r = !0, i = 0;
337
- for (; r && i < n.length; ) {
338
- r = !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, r = !0);
341
- }
342
- }
343
- }
344
- function Eo(e, t) {
345
- const n = /* @__PURE__ */ new Map();
346
- for (const p of e) n.set(p.id, /* @__PURE__ */ new Set());
347
- for (const [p, v] of t)
348
- p !== v && (n.get(p)?.add(v), n.get(v)?.add(p));
349
- const s = new Map(e.map((p) => [p.id, p])), r = /* @__PURE__ */ new Set(), i = [], c = [...e].sort(
350
- (p, v) => (n.get(v.id)?.size ?? 0) - (n.get(p.id)?.size ?? 0)
351
- );
352
- for (const p of c) {
353
- if (r.has(p.id)) continue;
354
- const v = [], d = [p.id];
355
- for (r.add(p.id); d.length; ) {
356
- const m = d.shift(), S = s.get(m);
357
- S && v.push(S);
358
- const k = [...n.get(m) ?? []].sort(
359
- (j, T) => (n.get(T)?.size ?? 0) - (n.get(j)?.size ?? 0)
360
- );
361
- for (const j of k)
362
- r.has(j) || (r.add(j), d.push(j));
363
- }
364
- i.push(v);
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 r = /* @__PURE__ */ new Map(), i = e[0];
374
- r.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
- r.has(m) || (r.set(m, (r.get(d) ?? 0) + 1), c.push(m));
380
- }
381
- const p = /* @__PURE__ */ new Map();
382
- for (const d of e) {
383
- const m = r.get(d.id) ?? 0, S = p.get(m) ?? [];
384
- S.push(d), p.set(m, S);
385
- }
386
- const v = [];
387
- for (const d of [...p.keys()].sort((m, S) => m - S)) {
388
- const m = p.get(d) ?? [];
389
- for (let S = 0; S < m.length; S += on)
390
- v.push(m.slice(S, S + on));
391
- }
392
- return v;
393
- }
394
- function Ao(e, t) {
395
- const n = [];
396
- let s = Wt;
397
- for (const r of Eo(e, t)) {
398
- let i = Wt, c = s;
399
- for (const p of Do(r, t)) {
400
- const v = Math.max(...p.map((m) => m.width));
401
- let d = s;
402
- for (const m of p)
403
- m.x = i + Math.round((v - m.width) / 2), m.y = d, d += m.height + Qs, c = Math.max(c, m.y + m.height), n.push(m);
404
- i += v + 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(), r = [];
412
- for (const _ of Object.values(t.schemas).sort((A, L) => A.id - L.id))
413
- for (const A of _.tableIds)
414
- r.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((ft) => t.fields[String(ft)]).find((ft) => ft && ft.name === ot.value);
424
- lt && i.add(lt.id);
425
- }
426
- }
427
- const c = [], p = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
428
- for (const _ of r) {
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-${_}`, ft = [];
432
- A.fieldIds.forEach((pt) => {
433
- const Q = t.fields[String(pt)];
434
- if (!Q) return;
435
- const wt = !!Q.pk || i.has(Q.id), it = $o(Q.note ?? "");
436
- d.set(Q.id, ft.length), m.set(Q.id, lt), ft.push({
437
- name: Q.name,
438
- type: vo(Q),
439
- note: it.note,
440
- default: bo(Q),
441
- pk: wt,
442
- fk: !1,
443
- unique: !!Q.unique,
444
- notNull: wt || !!Q.not_null,
445
- increment: !!Q.increment,
446
- link: it.href,
447
- linkLabel: it.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 wt = Q.columnIds.map((it) => t.indexColumns[String(it)]).filter((it) => it && it.type === "column").map((it) => it.value);
456
- wt.length && Et.push({
457
- name: Q.name ?? `${A.name}_index_${Q.id}`,
458
- columns: wt,
459
- unique: !!Q.unique
460
- });
461
- }
462
- const bt = {
463
- id: lt,
464
- name: ot,
465
- note: A.note ?? "",
466
- color: A.headerColor ?? "",
467
- columns: ft,
468
- indexes: Et,
469
- x: 0,
470
- y: 0,
471
- width: So(ot, ft),
472
- height: 0
473
- };
474
- bt.height = xo(bt), c.push(bt), p.set(lt, bt), v.set(A.name, lt), v.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 = v.get(L) ?? v.get(A.link);
480
- !ot || ot === _.id || (A.target = ot, A.link = "");
481
- }
482
- const S = [];
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], ft = ot.fieldIds[0], Et = lt.fieldIds[0];
487
- if (ft === void 0 || Et === void 0) continue;
488
- const bt = m.get(ft) ?? v.get(ot.tableName), pt = m.get(Et) ?? v.get(lt.tableName);
489
- if (!(!bt || !pt)) {
490
- for (const Q of lt.fieldIds) {
491
- const wt = p.get(m.get(Q) ?? ""), it = d.get(Q);
492
- if (!wt || it === void 0) continue;
493
- const $t = wt.columns[it];
494
- $t.fk = !0, !$t.target && !$t.link && ($t.target = bt);
495
- }
496
- S.push({
497
- id: `edge-${_.id}`,
498
- parent: bt,
499
- parentColumn: d.get(ft) ?? 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
- S.map((_) => [_.parent, _.child])
509
- ), j = k.length ? k : c, T = [], D = j.reduce((_, A) => Math.max(_, A.x + A.width), Wt);
510
- let H = Wt;
511
- const K = D + Wt + 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), T.push(L), H += L.height + an;
525
- }
526
- jo([...j, ...T], an);
527
- const st = [];
528
- for (const _ of S) {
529
- const A = p.get(_.parent), L = p.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: j,
544
- edges: st,
545
- notes: T
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] ?? "", r = e.match(/<template>([\s\S]*)<\/template>/)?.[1] ?? "", i = `${s}
553
- ${n}`;
554
- let c = null;
555
- const p = /defineProps<\s*\{/.exec(s);
556
- if (p)
557
- c = Ht(s, p.index + p[0].length);
558
- else {
559
- const D = s.match(/defineProps<\s*([A-Za-z_$][\w$]*)\s*>/);
560
- D && (c = ie(i, D[1]));
561
- }
562
- const v = /* @__PURE__ */ new Map(), d = s.match(/(?:const|let)\s*\{([\s\S]*?)\}\s*=\s*(?:withDefaults\s*\(\s*)?defineProps/);
563
- if (d)
564
- for (const D of Pe(d[1])) {
565
- const H = D.match(/^([A-Za-z_$][\w$]*)\s*=\s*([\s\S]+)$/);
566
- H && v.set(H[1], wn(H[2]));
567
- }
568
- const m = [];
569
- if (c)
570
- for (const D of Te(c)) {
571
- const H = Ne(
572
- ae(D.name, D.type, D.optional, i, D.description),
573
- D
574
- );
575
- v.has(D.name) && (H.default = v.get(D.name)), m.push(H);
576
- }
577
- for (const D of s.matchAll(/\bdefineModel(?:<([^>]*)>)?\(\s*(?:['"]([\w-]+)['"])?/g)) {
578
- const H = D[2] ?? "modelValue";
579
- if (m.some((_) => _.name === H)) continue;
580
- const K = ae(H, D[1]?.trim() || "string", !0, i);
581
- K.bindable = !0;
582
- const st = s.slice(0, D.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 S = [], k = /* @__PURE__ */ new Set();
590
- for (const D of r.matchAll(/<slot\b([^>]*)>/g)) {
591
- const H = D[1].match(/(?:^|[^:\w-])name=["']([^"']+)["']/)?.[1];
592
- if (!H && /(?:^|\s)(?::|v-bind:)name=/.test(D[1])) continue;
593
- const K = H ?? "default";
594
- k.has(K) || (k.add(K), S.push({ name: K, kind: "slot", type: "slot" }));
595
- }
596
- const j = [], T = s.indexOf("defineEmits");
597
- if (T >= 0) {
598
- const D = s.slice(T), H = D.search(/[<(]/);
599
- if (H >= 0) {
600
- const K = D[H], st = K === "<" ? ">" : ")", _ = Ht(D, 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
- j.push(...A);
606
- }
607
- }
608
- for (const D of m)
609
- (D.bindable || j.includes(`update:${D.name}`)) && (D.bindable = !0, j.includes(`update:${D.name}`) || j.push(`update:${D.name}`));
610
- return { component: t, props: m, slots: S, emits: j };
611
- }
612
- function Mo(e, t, n = "") {
613
- const s = e.match(/<script[^>]*>([\s\S]*?)<\/script>/)?.[1] ?? "", r = `${s}
614
- ${n}`, i = s.match(/(?:let|const)\s*\{([\s\S]*?)\}\s*(?::\s*([\s\S]*?))?=\s*\$props\(\)/), c = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Set();
615
- if (i)
616
- for (const j of Pe(i[1])) {
617
- const T = j.match(/^([A-Za-z_$][\w$]*)\s*=\s*([\s\S]+)$/);
618
- if (!T) continue;
619
- const D = T[2].trim().match(/^\$bindable\(([\s\S]*)\)$/);
620
- D && p.add(T[1]), c.set(T[1], wn(D ? D[1] : T[2]));
621
- }
622
- let v = null;
623
- const d = i?.[2]?.trim();
624
- if (d)
625
- if (d.startsWith("{"))
626
- v = Ht(d, 1);
627
- else {
628
- const j = d.match(/^([A-Za-z_$][\w$]*)/);
629
- j && (v = ie(r, j[1]));
630
- }
631
- const m = [], S = [], k = [];
632
- if (v)
633
- for (const j of Te(v)) {
634
- if (/\bSnippet\b/.test(j.type)) {
635
- S.push({ name: j.name, kind: "slot", type: j.type, required: !j.optional });
636
- continue;
637
- }
638
- if (/^on[A-Z]/.test(j.name) && /=>/.test(j.type)) {
639
- k.push(j.name);
640
- continue;
641
- }
642
- const T = Ne(
643
- ae(j.name, j.type, j.optional, r, j.description),
644
- j
645
- );
646
- c.has(j.name) && (T.default = c.get(j.name)), p.has(j.name) && (T.bindable = !0), m.push(T);
647
- }
648
- else if (i) {
649
- for (const j of Pe(i[1])) {
650
- const T = j.match(/^([A-Za-z_$][\w$]*)/)?.[1];
651
- if (!T || T === "children") continue;
652
- const D = { name: T, kind: "json", type: "unknown" };
653
- c.has(T) && (D.default = c.get(T)), p.has(T) && (D.bindable = !0), m.push(D);
654
- }
655
- /\bchildren\b/.test(i[1]) && S.push({ name: "children", kind: "slot", type: "Snippet" });
656
- }
657
- return { component: t, props: m, slots: S, emits: k };
658
- }
659
- function Pn(e, t = []) {
660
- let n;
661
- try {
662
- n = le(e, { withFileTypes: !0 });
663
- } catch {
664
- return t;
665
- }
666
- for (const s of n) {
667
- const r = W(e, s.name);
668
- if (s.isDirectory()) {
669
- if (s.name === "node_modules") continue;
670
- Pn(r, t);
671
- } else s.isFile() && s.name.endsWith(".d.ts") && t.push(r);
672
- }
673
- return t;
674
- }
675
- function _o(e, t, n) {
676
- const s = W(e, "node_modules", t);
677
- if (!mt(s) || !re(s).isDirectory()) return null;
678
- const r = [
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 r) {
685
- const p = i.find((v) => v.endsWith(`/${c}`));
686
- if (p) return p;
687
- }
688
- return null;
689
- }
690
- function ti(e, t) {
691
- const n = ie(e, `${t}Props`) ?? ie(e, "Props");
692
- if (!n) return;
693
- const s = [], r = [], i = [];
694
- for (const c of Te(n)) {
695
- if (/\bSnippet\b/.test(c.type)) {
696
- r.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(Ne(ae(c.name, c.type, c.optional, e, c.description), c));
704
- }
705
- return { component: t, props: s, slots: r, 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 r = Ht(e, s + 1);
713
- try {
714
- return new Function(`return {${r}}`)();
715
- } catch {
716
- return;
717
- }
718
- }
719
- function be(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 r = Ht(e, s + 1);
725
- return e.slice(0, n) + e.slice(s + 1 + r.length + 1);
726
- }
727
- function To(e, t) {
728
- const n = e.match(/^\s*\/\/\s*story:\s*(.+)$/m)?.[1]?.trim(), s = be(be(e, "props"), "slots"), r = ve(s, "sidebar"), i = be(s, "sidebar"), c = i.match(/\bname\s*:\s*['"]([^'"]+)['"]/)?.[1], p = i.match(/\bdescription\s*:\s*['"]([^'"]+)['"]/)?.[1], v = ve(e, "props"), d = ve(e, "slots");
729
- return {
730
- name: n ?? c ?? Ot(t).replace(/\.story\.tsx?$/, "").replace(/_/g, " "),
731
- file: t,
732
- description: p,
733
- props: v,
734
- slots: d,
735
- sidebar: r
736
- };
737
- }
738
- async function No(e) {
739
- let t;
740
- try {
741
- t = await Oe(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 r;
749
- try {
750
- r = await rt(W(e, s.name), "utf-8");
751
- } catch {
752
- continue;
753
- }
754
- n.push(To(r, s.name));
755
- }
756
- return n.sort((s, r) => s.name.localeCompare(r.name)), n;
757
- }
758
- function pe(e, t, n, s, r) {
759
- const i = t.systems[n];
760
- if (!i?.source) return null;
761
- const c = q(e, i.source), p = i.framework === "vue" ? ".vue" : ".svelte", v = r ? [q(c, r)] : [W(c, s, s + p), W(c, s + p)];
762
- for (const d of v) {
763
- if (!r && !d.startsWith(c) || !mt(d)) continue;
764
- const m = V(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 Oe(e, { withFileTypes: !0 });
778
- } catch {
779
- return t;
780
- }
781
- for (const s of n) {
782
- const r = W(e, s.name);
783
- if (s.isDirectory()) {
784
- if (s.name.startsWith(".") || s.name === "node_modules") continue;
785
- await jn(r, t);
786
- } else s.isFile() && s.name.endsWith(".md") && t.push(r);
787
- }
788
- return t;
789
- }
790
- async function Be(e, t) {
791
- const n = q(e, t), s = await jn(n), r = [];
792
- for (const i of s) {
793
- let c;
794
- try {
795
- c = await rt(i, "utf-8");
796
- } catch {
797
- continue;
798
- }
799
- const { data: p } = _e(c);
800
- if (p?.type !== "component") continue;
801
- const v = p.data ?? {}, d = String(v.system ?? ""), m = String(v.component ?? "");
802
- !d || !m || r.push({
803
- pageFile: i,
804
- system: d,
805
- component: m,
806
- file: typeof v.file == "string" ? v.file : void 0,
807
- package: typeof v.package == "string" ? v.package : void 0,
808
- version: typeof v.version == "string" ? v.version : void 0
809
- });
810
- }
811
- return r;
812
- }
813
- function zt(e) {
814
- const t = W(e, "schema.yml");
815
- if (mt(t)) return { path: t, form: "yml" };
816
- const n = W(e, "schema.json");
817
- return mt(n) ? { path: n, form: "json" } : null;
818
- }
819
- function Gt(e, t) {
820
- return t === "yml" ? bn(e) : JSON.parse(e);
821
- }
822
- function Ut(e, t) {
823
- return t === "yml" ? hs(e) : JSON.stringify(e, null, 2) + `
824
- `;
825
- }
826
- async function Re(e, t, n) {
827
- try {
828
- return await Xo(V(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 Lt(e, t) {
836
- const n = { ...e }, s = n, r = t;
837
- for (const i of Io)
838
- r[i] !== void 0 && (s[i] = r[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 && r[i] !== void 0 && (s[i] = r[i]);
842
- if (t.properties) {
843
- const i = {};
844
- for (const [c, p] of Object.entries(t.properties)) {
845
- const v = e.properties?.[c];
846
- i[c] = v ? Lt(v, p) : p;
847
- }
848
- for (const [c, p] of Object.entries(e.properties ?? {}))
849
- c in i || (i[c] = p);
850
- n.properties = i;
851
- }
852
- return t.items && (n.items = e.items ? Lt(e.items, t.items) : t.items), t.additionalProperties && (n.additionalProperties = e.additionalProperties ? Lt(e.additionalProperties, t.additionalProperties) : t.additionalProperties), n;
853
- }
854
- function We(e, t) {
855
- const n = t, s = { added: [], missing: [] }, r = {};
856
- for (const [v, d] of Object.entries(n.properties ?? {})) {
857
- const m = e.properties?.[v];
858
- m ? r[v] = Lt(m, d) : (r[v] = d, s.added.push(v));
859
- }
860
- for (const [v, d] of Object.entries(e.properties ?? {}))
861
- v in r || (r[v] = d, s.missing.push(`prop ${v}`));
862
- const i = {};
863
- for (const [v, d] of Object.entries(n.slots ?? {})) {
864
- const m = e.slots?.[v];
865
- i[v] = m ? Lt(m, d) : d;
866
- }
867
- for (const [v, d] of Object.entries(e.slots ?? {}))
868
- v in i || (i[v] = d, s.missing.push(`slot ${v}`));
869
- const c = [...n.emits ?? []];
870
- for (const v of e.emits ?? [])
871
- c.includes(v) || (c.push(v), s.missing.push(`emit ${v}`));
872
- return { merged: { ...e, ...t, properties: r, slots: i, emits: c }, report: s };
873
- }
874
- const It = [], 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), It.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 ? `${Ct}type${et} ${t[1]} ${Ct}is opaque${et}` : `${Ct}${e}${et}`;
892
- }
893
- function Tt(e = process.cwd()) {
894
- if (!It.length) return;
895
- const t = /* @__PURE__ */ new Map();
896
- for (const c of It) {
897
- const p = t.get(c.component) ?? [];
898
- p.push(c), t.set(c.component, p);
899
- }
900
- const n = It.length;
901
- It.length = 0;
902
- const s = n === 1 ? "schema warning" : "schema warnings", r = t.size === 1 ? "component" : "components", i = [""];
903
- i.push(` ${Pt}${ce}nimpress modules${et} ${Ct}${n} ${s} in ${t.size} ${r}${et}`), i.push("");
904
- for (const [c, p] of t) {
905
- const v = p.find((S) => S.sourceFile)?.sourceFile;
906
- i.push(` ${$n}${ce}${c}${et}${v ? ` ${se}${jt(e, v)}${et}` : ""}`);
907
- const d = Math.max(...p.map((S) => (S.line ? `L${S.line}` : "·").length)), m = Math.max(...p.map((S) => (S.path || "(component)").length));
908
- for (const S of p) {
909
- const k = (S.line ? `L${S.line}` : "·").padStart(d), j = (S.path || "(component)").padEnd(m);
910
- i.push(` ${Ct}${k}${et} ${Pt}${j}${et} ${Wo(S.detail)}`);
911
- }
912
- for (const S of new Set(p.map((k) => k.kind)))
913
- i.push(` ${Pt}→${et} ${se}${Ro[S]}${et}`);
914
- i.push(` ${Pt}→${et} ${se}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
- `), r = new RegExp(`(^|[^\\w$])${n}\\s*[?:]`);
925
- for (let c = 0; c < s.length; c++)
926
- if (r.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 = [], r = Fe(e, t);
933
- for (const i of r.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(r.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 Le(e, t, n, s) {
942
- if (!n) return;
943
- const r = Ss(t, n.props, n.slots, n.emits), i = s ? await rt(s, "utf-8").catch(() => {
944
- }) : void 0, c = zt(e);
945
- if (!c) {
946
- const k = W(e, "schema.json");
947
- await nt(k, Ut(r, "json")), console.log(`nimpress modules: ${t} schema seeded at ${k} — the file is yours to author from here`), ln(un(t, r, { sourceFile: s, sourceText: i }));
948
- return;
949
- }
950
- const p = await rt(c.path, "utf-8");
951
- let v;
952
- try {
953
- v = Gt(p, c.form);
954
- } catch (k) {
955
- console.warn(`nimpress modules: ${t} ${Ot(c.path)} failed to parse, left untouched: ${String(k)}`);
956
- return;
957
- }
958
- const { merged: d, report: m } = We(v, r), S = Ut(d, c.form);
959
- if (S !== p) {
960
- await nt(c.path, S);
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 r;
969
- try {
970
- r = await rt(n, "utf-8");
971
- } catch {
972
- return;
973
- }
974
- const i = vn("sha1").update(r).digest("hex");
975
- if (fn.get(n) === i) return;
976
- fn.set(n, i);
977
- const c = await Re(n, s, t);
978
- c && await Le(e, t, c, n);
979
- }
980
- async function ei(e, t) {
981
- const n = zt(e);
982
- if (!n) {
983
- await nt(W(e, "schema.json"), Ut(t, "json"));
984
- return;
985
- }
986
- const s = await rt(n.path, "utf-8"), r = Gt(s, n.form), { merged: i } = We(t, r);
987
- await nt(n.path, Ut(i, n.form));
988
- }
989
- function Ee(e) {
990
- const t = Me(e);
991
- return t === ".vue" ? "vue" : t === ".svelte" ? "svelte" : null;
992
- }
993
- function Ho(e, t, n) {
994
- for (const [s, r] of Object.entries(t.modules.systems)) {
995
- if (!r.source) continue;
996
- const i = q(e, r.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 Be(e, t.contentDir), r = q(e, n);
1006
- if ((n.includes("/") || n.includes("\\")) && mt(r)) {
1007
- const d = Ee(r);
1008
- if (!d)
1009
- throw new Error(`[nimpress] modules: ${n} is not a .vue or .svelte component file`);
1010
- const m = Ot(r, Me(r)), S = Ho(e, t, r);
1011
- if (!S)
1012
- throw new Error(`[nimpress] modules: ${n} sits under no configured system source`);
1013
- const k = Uo(s, S, m);
1014
- if (!k)
1015
- throw new Error(
1016
- `[nimpress] modules: no component page found for ${S}/${m}, run nimpress modules create ${S} ${m} first`
1017
- );
1018
- return { system: S, component: m, framework: d, componentFile: r, pageDir: V(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], p = pe(e, t.modules, c.system, c.component, c.file);
1028
- if (!p)
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 v = Ee(p.componentFile) ?? p.systemConfig.framework;
1033
- return {
1034
- system: c.system,
1035
- component: c.component,
1036
- framework: v,
1037
- componentFile: p.componentFile,
1038
- pageDir: V(c.pageFile)
1039
- };
1040
- }
1041
- async function qo(e, t, n) {
1042
- const s = await Jo(e, t, n), r = await Re(s.componentFile, s.framework, s.component);
1043
- if (!r)
1044
- throw new Error(`[nimpress] modules: schema parse produced nothing for ${s.component}`);
1045
- await Le(s.pageDir, s.component, r);
1046
- const i = zt(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 Be(e, t.contentDir);
1053
- let r = 0;
1054
- for (const i of s) {
1055
- if (n.system && i.system !== n.system) continue;
1056
- const c = pe(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 p = Ee(c.componentFile) ?? c.systemConfig.framework, v = await Re(c.componentFile, p, i.component);
1062
- v && (await Le(V(i.pageFile), i.component, v), r++);
1063
- }
1064
- return r;
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 = V(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), r = /* @__PURE__ */ new Set([q(t)]), i = [{ file: t, text: n, depth: 0 }];
1082
- let c = "";
1083
- for (; i.length; ) {
1084
- const p = i.shift();
1085
- if (!p || p.depth >= 3) continue;
1086
- const v = mn(p.file, p.text);
1087
- for (const d of v.matchAll(/from\s+['"]([^'"]+)['"]/g)) {
1088
- const m = d[1];
1089
- let S = null;
1090
- if (m.startsWith(".") ? S = q(V(p.file), m) : m.startsWith("@/") && s && (S = q(s, m.slice(2))), !S || !vt(S)) continue;
1091
- const j = [S, `${S}.ts`, `${S}.vue`, W(S, "index.ts")].find((H) => Vo(H));
1092
- if (!j) continue;
1093
- const T = q(j);
1094
- if (r.has(T) || r.size > 50) continue;
1095
- r.add(T);
1096
- const D = await rt(j, "utf-8");
1097
- c += mn(j, D) + `
1098
- `, i.push({ file: j, text: D, depth: p.depth + 1 });
1099
- }
1100
- }
1101
- return c;
1102
- }
1103
- function Vo(e) {
1104
- try {
1105
- return re(e).isFile();
1106
- } catch {
1107
- return !1;
1108
- }
1109
- }
1110
- async function Xo(e, t, n, s) {
1111
- const r = await rt(t, "utf-8");
1112
- let i = "";
1113
- for (const p of le(e))
1114
- p.endsWith(".ts") && (p.endsWith(".stories.ts") || p.endsWith(".story.ts") || (i += await rt(W(e, p), "utf-8"), i += `
1115
- `));
1116
- i += await Go(e, t, r);
1117
- const c = n === "vue" ? Oo(r, s, i) : Mo(r, s, i);
1118
- for (const p of c.props) {
1119
- if (!p.format) {
1120
- const v = xs(p);
1121
- v && (p.format = v);
1122
- }
1123
- p.mock || (p.mock = ks(p.name, Ps(p)));
1124
- }
1125
- return c;
1126
- }
1127
- async function Yo(e) {
1128
- const { cwd: t, modules: n, pageFile: s, data: r, editable: i } = e, c = String(r.system ?? ""), p = String(r.component ?? ""), v = typeof r.file == "string" ? r.file : void 0, d = await No(V(s)), m = pe(t, n, c, p, v), S = [];
1129
- if (i && m) {
1130
- const _ = m.componentFile.endsWith(".svelte") ? "svelte" : "vue";
1131
- try {
1132
- await Lo(V(s), p, m.componentFile, _);
1133
- } catch (A) {
1134
- console.warn(`nimpress modules: ${c}/${p} schema upsert failed: ${String(A)}`);
1135
- }
1136
- }
1137
- let k;
1138
- const j = zt(V(s));
1139
- if (j) {
1140
- S.push(j.path);
1141
- try {
1142
- k = Gt(await rt(j.path, "utf-8"), j.form);
1143
- } catch (_) {
1144
- console.warn(`nimpress modules: ${c}/${p} ${j.form} schema failed to parse: ${String(_)}`);
1145
- }
1146
- } else
1147
- console.warn(
1148
- `nimpress modules: ${c}/${p} has no schema file, controls stay empty, run nimpress modules update ${p}`
1149
- );
1150
- let T, D;
1151
- if (m)
1152
- S.push(m.componentFile), D = jt(t, m.claudeMdPath), mt(m.claudeMdPath) && (T = await rt(m.claudeMdPath, "utf-8"), S.push(m.claudeMdPath));
1153
- else {
1154
- const _ = typeof r.package == "string" ? r.package : n.systems[c]?.package;
1155
- if (_) {
1156
- const A = _o(t, _, p);
1157
- if (A) {
1158
- const L = A.replace(/[^/]+$/, "CLAUDE.md");
1159
- mt(L) && (T = await rt(L, "utf-8"));
1160
- }
1161
- }
1162
- }
1163
- const H = r.schema && typeof r.schema == "object" && !Array.isArray(r.schema) ? r.schema : void 0;
1164
- H && (k = k ? We(H, k).merged : H);
1165
- const K = k ? Fe(p, k) : void 0, st = n.route.replace(/\/$/, "");
1166
- return {
1167
- data: {
1168
- system: c,
1169
- component: p,
1170
- package: typeof r.package == "string" ? r.package : void 0,
1171
- version: typeof r.version == "string" ? r.version : void 0,
1172
- claudeMd: T,
1173
- claudeMdPath: D,
1174
- editable: i && !!m,
1175
- harnessPath: `${st}/${encodeURIComponent(c)}/${encodeURIComponent(p)}/`,
1176
- schema: K,
1177
- schemaPath: j ? jt(t, j.path) : void 0,
1178
- stories: d
1179
- },
1180
- watchFiles: S
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 p of Object.values(e))
1195
- p.type === "chunk" && t.set(p.fileName, p);
1196
- const n = /* @__PURE__ */ new Map(), s = [], r = [], i = (p) => {
1197
- const v = t.get(p);
1198
- return v ? v.facadeModuleId ?? Object.keys(v.modules)[0] ?? p : p;
1199
- }, c = (p) => {
1200
- n.set(p, 1), s.push(p);
1201
- for (const v of t.get(p)?.imports ?? []) {
1202
- if (!t.has(v)) continue;
1203
- const d = n.get(v);
1204
- if (d === 1) {
1205
- const m = s.slice(s.indexOf(v)).concat(v);
1206
- r.push({ chunks: m, modules: m.map(i) });
1207
- } else d || c(v);
1208
- }
1209
- s.pop(), n.set(p, 2);
1210
- };
1211
- for (const p of t.keys())
1212
- n.get(p) || c(p);
1213
- return r;
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((r) => {
1223
- const i = r.chunks.join(" -> "), c = r.modules.map((p) => ` ${p}`).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 He(e, t) {
1238
- if (!t) return e;
1239
- const n = { ...e };
1240
- for (const [s, r] of Object.entries(t)) {
1241
- if (r === void 0) continue;
1242
- const i = n[s], c = (p) => typeof p == "object" && p !== null && !Array.isArray(p);
1243
- c(i) && c(r) ? n[s] = He(i, r) : n[s] = r;
1244
- }
1245
- return n;
1246
- }
1247
- function oi(e) {
1248
- const { cwd: t, command: n, resolved: s, htmlInput: r } = 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
- ...r ? { rollupOptions: { input: r } } : {}
1266
- }
1267
- };
1268
- return He(i, s.vite);
1269
- }
1270
- const Zo = 6161, De = "virtual:nimpress-harness/";
1271
- function Ae(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 `${De}${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, r) {
1475
- const i = t.map((p) => `import ${JSON.stringify(p)}`).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(r)}
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, r) {
1569
- const i = t.map((p) => `import ${JSON.stringify(p)}`).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(r)}
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 || !mt(e.schemaFile)) return {};
1637
- let t;
1638
- try {
1639
- t = Gt(qt(e.schemaFile, "utf-8"), e.schemaFile.endsWith(".yml") ? "yml" : "json");
1640
- } catch {
1641
- return {};
1642
- }
1643
- const n = Fe(e.component, t), s = {};
1644
- for (const r of n.props) {
1645
- if (!r.required) continue;
1646
- const i = r.default !== void 0 ? r.default : js(r, 0);
1647
- i !== void 0 && (s[r.name] = i);
1648
- }
1649
- return s;
1650
- }
1651
- function nr(e, t, n, s, r) {
1652
- const i = er(t);
1653
- return e === "vue" ? Qo(t, n, s, r, i) : tr(t, n, s, r, i);
1654
- }
1655
- function dn(e, t, n) {
1656
- const s = n.map((r) => ` <link rel="stylesheet" href="${r}" />`).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: p } = await import("@sveltejs/vite-plugin-svelte");
1686
- return p();
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 r = await import(tn(s).href), c = [(r.default ?? r)()];
1696
- try {
1697
- const p = n.resolve("@vitejs/plugin-vue-jsx"), v = await import(tn(p).href), d = v.default ?? v;
1698
- c.push(d());
1699
- } catch {
1700
- }
1701
- return c;
1702
- }
1703
- function or(e, t, n, s) {
1704
- const r = t.systems[n];
1705
- if (!r) return [];
1706
- const i = [];
1707
- for (const c of s) {
1708
- if (c.system !== n) continue;
1709
- const p = rr(c.pageFile), v = zt(V(c.pageFile))?.path ?? W(V(c.pageFile), "schema.json"), d = r.source ? pe(e, t, n, c.component, c.file) : null;
1710
- if (d) {
1711
- i.push({ component: c.component, importSpec: d.componentFile, storyFiles: p, schemaFile: v });
1712
- continue;
1713
- }
1714
- const m = c.package ?? r.package;
1715
- if (m) {
1716
- i.push({ component: c.component, importSpec: m, named: !0, storyFiles: p, schemaFile: v });
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 = V(e);
1725
- let n;
1726
- try {
1727
- n = le(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") ? Ot(s, ".story.tsx") : Ot(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, r) {
1745
- const i = (t.css ?? []).map(
1746
- (k) => k.startsWith(".") || vt(k) ? q(e, k) : k
1747
- ), c = ir(e, t), p = ar(e, t), v = new Map(s.map((k) => [k.component, k])), d = "\0" + De, m = (k) => {
1748
- if (!k.startsWith(d)) return null;
1749
- const j = k.slice(d.length).split("/");
1750
- return j[0] === n && j[1] ? j[1] : null;
1751
- }, S = (k) => nr(t.framework, k, i, c, p);
1752
- return {
1753
- name: "nimpress:harness",
1754
- resolveId(k) {
1755
- return k.startsWith(d) ? k : k.startsWith(De) ? "\0" + k : null;
1756
- },
1757
- load(k) {
1758
- const j = m(k);
1759
- if (!j) return null;
1760
- const T = v.get(j);
1761
- return T ? S(T) : null;
1762
- },
1763
- configureServer(k) {
1764
- k.middlewares.use(async (j, T, D) => {
1765
- const H = j.url;
1766
- if (!H) return D();
1767
- const K = H.split("?")[0];
1768
- if (!K.startsWith(r)) return D();
1769
- const st = K.slice(r.length).split("/").filter(Boolean), _ = st[0];
1770
- if (!_ || !v.has(_)) return D();
1771
- const A = st.slice(1).join("/");
1772
- if (A === "" || A === "index.html") {
1773
- const L = ` <script type="module" src="${r}@vite/client"><\/script>
1774
- </head>`, ot = dn(_, "./entry.js", []).replace(" </head>", L);
1775
- T.statusCode = 200, T.setHeader("Content-Type", "text/html"), T.end(ot);
1776
- return;
1777
- }
1778
- if (A === "entry.js") {
1779
- const L = await k.transformRequest(Cn(n, _));
1780
- if (!L) return D();
1781
- T.statusCode = 200, T.setHeader("Content-Type", "application/javascript"), T.end(L.code);
1782
- return;
1783
- }
1784
- return D();
1785
- });
1786
- },
1787
- generateBundle(k, j) {
1788
- const T = (D, H, K) => {
1789
- if (H.has(D)) return;
1790
- H.add(D);
1791
- const st = j[D];
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) T(A, H, K);
1796
- };
1797
- for (const D of Object.values(j)) {
1798
- if (D.type !== "chunk" || !D.isEntry) continue;
1799
- const H = v.get(D.name);
1800
- if (!H) continue;
1801
- const K = /* @__PURE__ */ new Set();
1802
- T(D.fileName, /* @__PURE__ */ new Set(), K);
1803
- const st = [...K].map((_) => r + _);
1804
- this.emitFile({
1805
- type: "asset",
1806
- fileName: `${H.component}/index.html`,
1807
- source: dn(H.component, r + D.fileName, st)
1808
- });
1809
- }
1810
- }
1811
- };
1812
- }
1813
- async function ri(e, t, n, s) {
1814
- const r = t.modules, i = r.systems[n];
1815
- if (!i) throw new Error(`[nimpress] unknown module system: ${n}`);
1816
- const c = await Be(e, t.contentDir), p = or(e, r, n, c);
1817
- p.length || console.warn(`[nimpress] modules: no component pages found for system ${n}`);
1818
- const v = await sr(e, i.framework), d = i.source ? q(e, i.source) : e, m = r.route.replace(/\/$/, ""), S = `${m}/${n}/`, k = s === "build" ? dt(t.base, S) : S, j = p.filter((D) => vt(D.importSpec)).map((D) => D.importSpec).concat(p.flatMap((D) => (D.storyFiles ?? []).map((H) => H.path))), T = {
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, p, k), v, An()],
1825
- resolve: i.framework === "vue" ? { alias: { vue: "vue/dist/vue.esm-bundler.js" } } : void 0,
1826
- optimizeDeps: {
1827
- entries: j,
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: Ae(r, n),
1834
- strictPort: !0,
1835
- fs: { allow: [e, d] },
1836
- hmr: {
1837
- host: "127.0.0.1",
1838
- clientPort: Ae(r, 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(p.map((D) => [D.component, Cn(n, D.component)]))
1847
- }
1848
- },
1849
- base: k
1850
- };
1851
- return He(T, 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 Kt = "virtual:nimpress/manifest", Zt = "virtual:nimpress/search", Qt = "virtual:nimpress/pages", te = "virtual:nimpress/bodies", we = "virtual:nimpress/config", $e = "virtual:nimpress/main", Nt = "virtual:nimpress/page-component/", Mt = "virtual:nimpress/page-body/", Se = 20, pr = "https://github.com/nimling/nimpress";
1880
- function ut(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 xe = (e) => e.visibility === "hidden", Dt = (e) => e.visibility === "hidden" || e.visibility === "dev-only", ee = (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
- description: f.string().optional(),
1982
- order: f.number().optional(),
1983
- icon: f.string().optional(),
1984
- sidebar: f.object({
1985
- name: f.string().min(1),
1986
- icon: f.string().optional(),
1987
- style: f.string().optional(),
1988
- path: f.string().optional()
1989
- }).optional(),
1990
- visibility: f.enum(["visible", "hidden", "dev-only"]).optional(),
1991
- collapsed: f.boolean().optional(),
1992
- lastUpdated: f.boolean().optional(),
1993
- redirect: f.string().optional(),
1994
- noToc: f.boolean().optional(),
1995
- footer: f.string().optional(),
1996
- background: f.string().optional(),
1997
- tags: f.union([f.string(), f.array(f.string())]).optional(),
1998
- rss: f.boolean().optional(),
1999
- subscribe: f.boolean().optional(),
2000
- meta: gr.optional(),
2001
- data: f.record(f.unknown()).optional()
2002
- }).passthrough();
2003
- function Fn(e, t = "x") {
2004
- const n = [], s = Nn.safeParse(e);
2005
- if (!s.success) {
2006
- for (const p of s.error.errors)
2007
- n.push(`${p.path.join(".") || "frontmatter"}: ${p.message}`);
2008
- return n;
2009
- }
2010
- const r = s.data, i = r.data ?? {};
2011
- if (e.type === void 0 && t.trim() === "")
2012
- return r.sidebar?.name || n.push("a page without a type and without a body needs a sidebar.name to decorate its group"), n;
2013
- if (r.title || n.push("title: Required"), r.type === "openapi" && !r.spec && n.push("type openapi requires a spec field"), r.type === "dbml" && !r.spec && n.push("type dbml requires a spec field"), r.type === "changelog") {
2014
- (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");
2015
- const p = i.title === void 0 ? "" : String(i.title);
2016
- p.trim() || n.push("changelog requires data.title"), p.length > 48 && n.push("changelog data.title exceeds 48 characters"), p.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");
2017
- }
2018
- return (r.type === "milestone" || r.type === "epic" || r.type === "feature" || r.type === "bug") && (r.description || n.push(`type ${r.type} requires a description`), (i.date === void 0 || Number.isNaN(new Date(String(i.date)).getTime())) && n.push(`type ${r.type} requires a valid data.date`)), r.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;
2019
- }
2020
- function yr(e, t) {
2021
- const n = String(e ?? "").replace(/^v/i, "").split(/[.\-+]/), s = String(t ?? "").replace(/^v/i, "").split(/[.\-+]/), r = Math.max(n.length, s.length);
2022
- for (let i = 0; i < r; i++) {
2023
- const c = parseInt(n[i] ?? "0", 10) || 0, p = parseInt(s[i] ?? "0", 10) || 0;
2024
- if (c !== p) return c - p;
2025
- }
2026
- return 0;
2027
- }
2028
- function vr(e, t) {
2029
- const n = jt(e, t).split(kt).join("/");
2030
- if (!(!n || n.startsWith("..") || vt(n)))
2031
- return `/${n}`;
2032
- }
2033
- function br(e, t) {
2034
- const n = jt(e, t).split(kt).join("/");
2035
- if (n.startsWith("..") || vt(n))
2036
- throw new Error(
2037
- `[nimpress] content file is outside contentDir.
2038
- contentDir: ${e}
2039
- file: ${t}
2040
- Check the working directory you run vite from and the contentDir option.`
2041
- );
2042
- return n.replace(/\.md$/, "").replace(/\/index$/, "").replace(/^index$/, "");
2043
- }
2044
- function wr(e) {
2045
- const t = e.lastIndexOf("/");
2046
- return t >= 0 ? e.slice(0, t) : "";
2047
- }
2048
- function $r(e) {
2049
- return e ? "/" + e : "/";
2050
- }
2051
- function yn(e) {
2052
- if (!e) return "/";
2053
- let t = e.startsWith("/") ? e : "/" + e;
2054
- return t.length > 1 && t.endsWith("/") && (t = t.slice(0, -1)), t;
2055
- }
2056
- async function Ue(e, t = []) {
2057
- let n;
2058
- try {
2059
- n = await Oe(e, { withFileTypes: !0 });
2060
- } catch {
2061
- return t;
2062
- }
2063
- for (const s of n) {
2064
- const r = W(e, s.name);
2065
- if (s.isDirectory()) {
2066
- if (s.name.startsWith(".") || s.name === "node_modules") continue;
2067
- await Ue(r, t);
2068
- } else s.isFile() && s.name.endsWith(".md") && t.push(r);
2069
- }
2070
- return t;
2071
- }
2072
- function In(e) {
2073
- return e.toLowerCase().replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-");
2074
- }
2075
- function ke(e) {
2076
- return e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
2077
- }
2078
- function Sr(e, t = { route: "/_components" }, n = "/") {
2079
- const s = new ls({
2080
- html: !0,
2081
- linkify: !0,
2082
- typographer: !1,
2083
- highlight(d, m, S) {
2084
- const k = {
2085
- curl: "bash",
2086
- sh: "bash",
2087
- zsh: "bash",
2088
- console: "bash",
2089
- hurl: "http"
2090
- }, T = ((S ? S.match(/\[([^\]]+)\]/) : null)?.[1].trim() || m || "text").trim(), D = k[m] ?? m, H = D && e.getLoadedLanguages().includes(D) ? D : "text";
2091
- try {
2092
- return e.codeToHtml(d, { lang: H, theme: "github-dark" }).replace("<pre ", `<pre data-lang="${s.utils.escapeHtml(T)}" `);
2093
- } catch {
2094
- return `<pre data-lang="${s.utils.escapeHtml(T)}"><code>${s.utils.escapeHtml(d)}</code></pre>`;
2095
- }
2096
- }
2097
- }), r = (d, m, S, k, j) => j.renderToken(d, m, S), i = s.renderer.rules.link_open ?? r;
2098
- s.renderer.rules.link_open = (d, m, S, k, j) => {
2099
- const T = d[m].attrGet("href");
2100
- return T && d[m].attrSet("href", dt(n, T)), i(d, m, S, k, j);
2101
- };
2102
- const c = s.renderer.rules.image ?? r;
2103
- s.renderer.rules.image = (d, m, S, k, j) => {
2104
- const T = d[m].attrGet("src");
2105
- return T && d[m].attrSet("src", dt(n, T)), c(d, m, S, k, j);
2106
- }, s.use(Qe, {
2107
- slugify: In,
2108
- permalink: Qe.permalink.headerLink({ safariReaderFix: !0 })
2109
- }), s.use(ps), s.use(fs), s.use(ms), s.use(ds, { enabled: !0 });
2110
- const p = (d, m) => {
2111
- s.use(us, d, m);
2112
- }, v = ["tip", "note", "warning", "info", "check"];
2113
- for (const d of v)
2114
- p(d, {
2115
- render(m, S) {
2116
- if (m[S].nesting === 1) {
2117
- const k = m[S].info.trim().slice(d.length).trim() || d;
2118
- return `<div class="np-callout np-callout-${d}"><div class="np-callout-body"><div class="np-callout-title">${s.utils.escapeHtml(k)}</div>`;
2119
- }
2120
- return "</div></div>";
2121
- }
2122
- });
2123
- return p("cards", {
2124
- render(d, m) {
2125
- return d[m].nesting === 1 ? '<div class="np-cards-grid">' : "</div>";
2126
- }
2127
- }), p("details", {
2128
- validate(d) {
2129
- return /^details\b/.test(d.trim());
2130
- },
2131
- render(d, m) {
2132
- if (d[m].nesting === 1) {
2133
- const S = d[m].info.trim().match(/^details\s*(.*)$/), k = S && S[1] || "Details";
2134
- return `<details class="np-details"><summary class="np-details-summary">${s.utils.escapeHtml(k)}</summary><div class="np-details-body">
2135
- `;
2136
- }
2137
- return `</div></details>
2138
- `;
2139
- }
2140
- }), p("code-group", {
2141
- render(d, m) {
2142
- return d[m].nesting === 1 ? '<div class="np-code-group">' : "</div>";
2143
- }
2144
- }), p("actions", {
2145
- render(d, m) {
2146
- if (d[m].nesting === 1) {
2147
- const S = d[m].info.trim().slice(7).trim(), k = S ? Bt(S, d[m].info) : {}, j = typeof k?.align == "string" ? k.align : "start";
2148
- return `<div class="np-actions" data-align="${s.utils.escapeHtml(j)}">`;
2149
- }
2150
- return "</div>";
2151
- }
2152
- }), p("features", {
2153
- render(d, m) {
2154
- if (d[m].nesting === 1) {
2155
- const S = d[m].info.trim().slice(8).trim(), k = S ? Bt(S, d[m].info) : {}, j = typeof k?.columns == "number" ? k.columns : 0;
2156
- return `<div class="np-features"${j > 0 ? ` data-columns="${j}"` : ""}>`;
2157
- }
2158
- return "</div>";
2159
- }
2160
- }), p("feature", {
2161
- render(d, m) {
2162
- if (d[m].nesting === 1) {
2163
- const S = d[m].info.trim().slice(7).trim(), k = S ? Bt(S, d[m].info) : {};
2164
- return `<div class="np-feature" data-config="${Jt(JSON.stringify(k))}"><div class="np-feature-body">`;
2165
- }
2166
- return "</div></div>";
2167
- }
2168
- }), p("component", {
2169
- render(d, m) {
2170
- if (d[m].nesting === 1) {
2171
- const S = d[m].info.trim().slice(9).trim(), k = S.startsWith("{") ? Bt(S, d[m].info) : S ? { component: S } : {};
2172
- return `<div class="np-component-embed" data-embed="${Jt(JSON.stringify({ ...t, ...k }))}"><div class="np-component-embed-body">`;
2173
- }
2174
- return "</div></div>";
2175
- }
2176
- }), s;
2177
- }
2178
- function Bt(e, t) {
2179
- try {
2180
- const n = JSON.parse(e);
2181
- return n && typeof n == "object" && !Array.isArray(n) ? n : {};
2182
- } catch {
2183
- return console.warn(`[nimpress] invalid JSON in directive: ${t}`), {};
2184
- }
2185
- }
2186
- function Jt(e) {
2187
- return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2188
- }
2189
- function xr(e) {
2190
- return `<div class="np-mermaid" data-graph="${Buffer.from(e, "utf-8").toString("base64")}"></div>`;
2191
- }
2192
- function kr(e, t, n) {
2193
- const s = t.startsWith("{") ? Bt(t, t) : {};
2194
- let r = "", i = "";
2195
- try {
2196
- r = kn(e);
2197
- } catch (d) {
2198
- i = d instanceof Ie ? d.message : String(d), console.warn(`[nimpress] invalid dbml in ${n}:
2199
- ${i}`);
2200
- }
2201
- const c = Buffer.from(r, "utf-8").toString("base64"), p = typeof s.height == "string" ? s.height : "";
2202
- return `<div class="np-dbml" ${[
2203
- `data-schema="${c}"`,
2204
- i ? `data-error="${Jt(i)}"` : "",
2205
- p ? `data-height="${Jt(p)}"` : ""
2206
- ].filter(Boolean).join(" ")}></div>`;
2207
- }
2208
- function Pr(e, t) {
2209
- const n = e.split(`
2210
- `), s = [];
2211
- let r = 0;
2212
- for (; r < n.length; ) {
2213
- const i = /^(\s*)(`{3,}|~{3,})(.*)$/.exec(n[r]);
2214
- if (!i) {
2215
- s.push(n[r]), r += 1;
2216
- continue;
2217
- }
2218
- const [, c, p, v] = i, d = new RegExp(`^\\s*\\${p[0]}{${p.length},}\\s*$`);
2219
- let m = r + 1;
2220
- for (; m < n.length && !d.test(n[m]); ) m += 1;
2221
- const S = v.trim(), k = S.split(/\s+/)[0].toLowerCase(), j = n.slice(r + 1, m).join(`
2222
- `);
2223
- k === "mermaid" ? s.push(`${c}${xr(j && `${j}
2224
- `)}`) : k === "dbml" ? s.push(`${c}${kr(j, S.slice(k.length).trim(), t)}`) : s.push(...n.slice(r, Math.min(m + 1, n.length))), r = m + 1;
2225
- }
2226
- return s.join(`
2227
- `);
2228
- }
2229
- function jr(e) {
2230
- if (!e) return "";
2231
- const t = [], n = (r) => {
2232
- if (r)
2233
- for (const i of r)
2234
- i.type === "text" || i.type === "code_inline" ? t.push(i.content ?? "") : i.children && n(i.children);
2235
- };
2236
- n(e.children);
2237
- const s = t.join("").trim();
2238
- return s || (e.content ?? "").trim();
2239
- }
2240
- function Er(e, t) {
2241
- const n = e.parse(t, {}), s = [];
2242
- let r = 0;
2243
- const i = /* @__PURE__ */ new Map();
2244
- for (let c = 0; c < n.length; c++) {
2245
- const p = n[c];
2246
- if (p.type === "heading_open") {
2247
- const v = parseInt(p.tag.slice(1)), d = n[c + 1], m = jr(d) || `heading-${r++}`;
2248
- let S = In(m);
2249
- S || (S = `heading-${r++}`);
2250
- const k = i.get(S);
2251
- if (k !== void 0) {
2252
- const j = k + 1;
2253
- i.set(S, j), S = `${S}-${j}`;
2254
- } else
2255
- i.set(S, 0);
2256
- s.push({ level: v, text: m, slug: S });
2257
- }
2258
- }
2259
- return s;
2260
- }
2261
- function Dr(e) {
2262
- return e.frontmatter.slug ?? e.frontmatter.title;
2263
- }
2264
- function ne(e) {
2265
- return e ? e.replace(/[-_]/g, " ").replace(/\b\w/g, (t) => t.toUpperCase()) : "";
2266
- }
2267
- function Ce(e) {
2268
- e.sort((t, n) => {
2269
- const s = t.order ?? Number.MAX_SAFE_INTEGER, r = n.order ?? Number.MAX_SAFE_INTEGER;
2270
- return s !== r ? s - r : t.text.localeCompare(n.text);
2271
- });
2272
- for (const t of e)
2273
- t.items && Ce(t.items);
2274
- }
2275
- function Ar(e) {
2276
- let t = Rt, n = q(process.cwd(), Rt.contentDir), s = q(process.cwd(), Rt.assetsDir), r = /* @__PURE__ */ new Map(), i = null, c = q(process.cwd(), "dist"), p = !1, v = null;
2277
- const d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Set();
2278
- function T(o) {
2279
- return vn("sha1").update(o).digest("hex");
2280
- }
2281
- async function D() {
2282
- return i || (i = await gs({
2283
- themes: ["github-dark"],
2284
- langs: [
2285
- "ts",
2286
- "tsx",
2287
- "js",
2288
- "jsx",
2289
- "json",
2290
- "bash",
2291
- "shell",
2292
- "yaml",
2293
- "go",
2294
- "sql",
2295
- "html",
2296
- "css",
2297
- "svelte",
2298
- "vue",
2299
- "md",
2300
- "rust",
2301
- "python",
2302
- "http",
2303
- "diff",
2304
- "text"
2305
- ]
2306
- }), i);
2307
- }
2308
- function H(o, l) {
2309
- return /\.ya?ml$/i.test(l) ? bn(o) : JSON.parse(o);
2310
- }
2311
- async function K(o, l) {
2312
- try {
2313
- const a = vt(l) ? l : q(V(o), l), h = await rt(a, "utf-8"), w = H(h, a);
2314
- return await st(w, V(a)), w;
2315
- } catch (a) {
2316
- return console.warn(`[nimpress] failed to load spec ${l} for ${o}:`, a), null;
2317
- }
2318
- }
2319
- async function st(o, l) {
2320
- if (!o || typeof o != "object") return;
2321
- o.components || (o.components = {}), o.components.schemas || (o.components.schemas = {});
2322
- const a = o.components.schemas, h = /* @__PURE__ */ new Map(), w = async (g) => {
2323
- const x = await rt(g, "utf-8");
2324
- return H(x, g);
2325
- }, y = async (g) => {
2326
- if (h.has(g)) return h.get(g);
2327
- const b = (g.split("/").pop() ?? "").replace(/\.json$/, "");
2328
- h.set(g, b);
2329
- const P = await w(g);
2330
- return await u(P, V(g)), a[b] = P, b;
2331
- }, u = async (g, x) => {
2332
- if (!g || typeof g != "object") return;
2333
- if (Array.isArray(g)) {
2334
- for (const P of g) await u(P, x);
2335
- return;
2336
- }
2337
- const b = g.$ref;
2338
- if (typeof b == "string" && !b.startsWith("#")) {
2339
- const P = vt(b) ? b : q(x, b), M = V(P).split("/").pop() ?? "";
2340
- if (M === "schemas") {
2341
- const $ = await y(P);
2342
- g.$ref = `#/components/schemas/${$}`;
2343
- return;
2344
- }
2345
- if (M === "operations") {
2346
- const $ = await w(P);
2347
- await u($, V(P)), delete g.$ref;
2348
- for (const N of Object.keys($)) g[N] = $[N];
2349
- return;
2350
- }
2351
- return;
2352
- }
2353
- for (const P of Object.keys(g))
2354
- await u(g[P], x);
2355
- };
2356
- for (const g of Object.keys(a)) {
2357
- const x = a[g];
2358
- if (x && typeof x == "object" && typeof x.$ref == "string" && !x.$ref.startsWith("#")) {
2359
- const b = vt(x.$ref) ? x.$ref : q(l, x.$ref);
2360
- h.set(b, g);
2361
- const P = await w(b);
2362
- await u(P, V(b)), a[g] = P;
2363
- }
2364
- }
2365
- for (const g of Object.keys(o))
2366
- g !== "components" && await u(o[g], l);
2367
- }
2368
- function _(o, l) {
2369
- if (typeof l != "string" || !l.startsWith("#/")) return null;
2370
- const a = l.slice(2).split("/").map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~"));
2371
- let h = o;
2372
- for (const w of a) {
2373
- if (h == null) return null;
2374
- h = h[w];
2375
- }
2376
- return h;
2377
- }
2378
- function A(o, l, a = 0) {
2379
- if (a > 4 || !o || typeof o != "object" || typeof o.$ref != "string") return o;
2380
- const h = _(l, o.$ref);
2381
- return h == null ? o : A(h, l, a + 1);
2382
- }
2383
- function L(o, l) {
2384
- if (!(typeof l != "string" || l === ""))
2385
- try {
2386
- return o.render(l);
2387
- } catch {
2388
- return;
2389
- }
2390
- }
2391
- function ot(o, l) {
2392
- if (!o) return null;
2393
- const a = o, h = a.info ?? {}, w = a.components?.securitySchemes ?? {}, y = ["get", "post", "put", "patch", "delete", "head", "options"], u = ($) => A($, a)?.example, g = /* @__PURE__ */ new Map(), x = a.paths ?? {};
2394
- for (const [$, N] of Object.entries(x)) {
2395
- const F = A(N, a);
2396
- if (!F || typeof F != "object") continue;
2397
- const U = (F.parameters ?? []).map((C) => A(C, a));
2398
- for (const C of y) {
2399
- const I = F[C];
2400
- if (!I) continue;
2401
- const E = I.operationId ?? `${C}-${$.replace(/[^a-z0-9]+/gi, "-")}`, B = I.tags?.[0] ?? "default", z = (I.parameters ?? []).map((ht) => A(ht, a)), X = [...U, ...z], O = /* @__PURE__ */ new Set(), R = [];
2402
- for (const ht of X) {
2403
- const G = ht;
2404
- if (!G || typeof G != "object" || !G.name || !G.in) continue;
2405
- const gt = `${G.name}@${G.in}`;
2406
- O.has(gt) || (O.add(gt), R.push({
2407
- name: G.name,
2408
- in: G.in,
2409
- required: G.required,
2410
- schema: G.schema,
2411
- description: G.description,
2412
- description_html: L(l, G.description),
2413
- example: G.example ?? u(G.schema)
2414
- }));
2415
- }
2416
- const J = I.requestBody ? A(I.requestBody, a) : void 0, tt = J?.content?.["application/json"], Y = tt?.example ?? (tt?.examples ? Object.values(tt.examples)[0]?.value : void 0) ?? u(tt?.schema), Z = {}, at = {};
2417
- for (const [ht, G] of Object.entries(I.responses ?? {})) {
2418
- const gt = A(G, a);
2419
- at[ht] = gt;
2420
- const xt = gt?.content?.["application/json"], Ke = xt?.example ?? (xt?.examples ? Object.values(xt.examples)[0]?.value : void 0) ?? u(xt?.schema);
2421
- Ke !== void 0 && (Z[ht] = Ke);
2422
- }
2423
- const ct = {
2424
- id: E,
2425
- method: C.toUpperCase(),
2426
- path: $,
2427
- tag: B,
2428
- summary: I.summary ?? E,
2429
- summary_html: L(l, I.summary),
2430
- description: I.description,
2431
- description_html: L(l, I.description),
2432
- parameters: R,
2433
- requestBody: J,
2434
- requestBodyHtml: L(l, J?.description),
2435
- requestExample: Y,
2436
- responses: at,
2437
- responseExamples: Z,
2438
- security: I.security ?? a.security,
2439
- operationName: I.operationId
2440
- };
2441
- g.has(B) || g.set(B, []), g.get(B).push(ct);
2442
- }
2443
- }
2444
- const b = [...g.entries()].map(([$, N]) => ({ name: $, operations: N })).sort(($, N) => $.name.localeCompare(N.name)), P = a.components?.schemas ?? {}, M = {};
2445
- for (const [$, N] of Object.entries(P)) {
2446
- const F = L(l, N?.description);
2447
- M[$] = F ? { ...N, description_html: F } : N;
2448
- }
2449
- return {
2450
- title: h.title ?? "API",
2451
- version: h.version ?? "",
2452
- description: h.description,
2453
- description_html: L(l, h.description),
2454
- servers: a.servers,
2455
- securitySchemes: w,
2456
- tags: b,
2457
- schemas: M
2458
- };
2459
- }
2460
- async function lt(o) {
2461
- const l = await rt(o, "utf-8"), { data: a, content: h } = _e(l), w = Fn(a, h);
2462
- if (w.length) {
2463
- const G = `${o}
2464
- ${w.join(`
2465
- `)}`;
2466
- if (p) throw new Error(`[nimpress] invalid frontmatter in ${G}`);
2467
- console.warn(`[nimpress] invalid frontmatter in ${G}`);
2468
- }
2469
- const y = Nn.safeParse(a), u = y.success ? y.data : { title: o }, g = br(n, o), x = u.type ?? "doc", b = yn(u.path ?? $r(g)), P = a.type === void 0 && h.trim() === "", M = t.defaultFrontmatter ?? {};
2470
- if (!(t.defaultFrontmatterExclude ?? []).some((G) => {
2471
- const gt = G.startsWith("/") ? G : "/" + G;
2472
- return b === gt || b.startsWith(gt + "/");
2473
- }))
2474
- for (const [G, gt] of Object.entries(M)) {
2475
- const xt = G;
2476
- (u[xt] === void 0 || u[xt] === null || u[xt] === "") && (u[xt] = gt);
2477
- }
2478
- const F = await D(), U = Sr(F, Q(), t.base), C = Pr(h, o), I = Er(U, C), E = U.render(C);
2479
- let B, z, X, O;
2480
- if (x === "openapi")
2481
- if (!u.spec)
2482
- console.warn(`[nimpress] page ${o} has type openapi but no spec field`);
2483
- else {
2484
- O = vt(u.spec) ? u.spec : q(V(o), u.spec), z = Ot(O), X = vr(n, O);
2485
- const G = await K(o, u.spec);
2486
- B = G ? ot(G, U) ?? void 0 : void 0;
2487
- }
2488
- let R, J, tt, Y;
2489
- if (x === "dbml")
2490
- if (!u.spec)
2491
- console.warn(`[nimpress] page ${o} has type dbml but no spec field`);
2492
- else {
2493
- O = vt(u.spec) ? u.spec : q(V(o), u.spec), tt = Ot(O);
2494
- try {
2495
- J = await rt(O, "utf-8"), R = kn(J);
2496
- } catch (G) {
2497
- Y = G instanceof Ie ? G.message : String(G);
2498
- const gt = `${o} -> ${u.spec}
2499
- ${Y}`;
2500
- if (p) throw new Error(`[nimpress] invalid dbml in ${gt}`);
2501
- console.warn(`[nimpress] invalid dbml in ${gt}`);
2502
- }
2503
- }
2504
- ft(o, O);
2505
- let Z, at = [];
2506
- if (x === "component") {
2507
- const G = await Yo({
2508
- cwd: process.cwd(),
2509
- modules: t.modules,
2510
- pageFile: o,
2511
- data: u.data ?? {},
2512
- editable: !p
2513
- });
2514
- Z = G.data, at = G.watchFiles;
2515
- }
2516
- Et(o, at);
2517
- const ct = o.replace(/\.md$/, ".css");
2518
- let ht;
2519
- return ct !== o && mt(ct) && (ht = await rt(ct, "utf-8")), {
2520
- slug: g,
2521
- filePath: o,
2522
- effectivePath: b,
2523
- type: x,
2524
- sidebarOnly: P,
2525
- frontmatter: u,
2526
- html: E,
2527
- headings: I,
2528
- rawText: h,
2529
- pageCss: ht,
2530
- openApiSpec: B,
2531
- openApiFile: z,
2532
- openApiUrl: X,
2533
- componentData: Z,
2534
- dbmlSchema: R,
2535
- dbmlSource: J,
2536
- dbmlFile: tt,
2537
- dbmlError: Y
2538
- };
2539
- }
2540
- function ft(o, l) {
2541
- for (const [a, h] of m)
2542
- h === o && m.delete(a);
2543
- l && (m.set(l, o), v && !S.has(l) && (v.watcher.add(l), S.add(l)));
2544
- }
2545
- function Et(o, l) {
2546
- for (const [a, h] of k)
2547
- h === o && k.delete(a);
2548
- for (const a of l)
2549
- k.set(a, o), v && !j.has(a) && (v.watcher.add(a), j.add(a));
2550
- }
2551
- async function bt(o) {
2552
- let l;
2553
- try {
2554
- l = await rt(o, "utf-8");
2555
- } catch {
2556
- return null;
2557
- }
2558
- const a = T(l), h = d.get(o);
2559
- if (h && h.hash === a) return h.processed;
2560
- const w = await lt(o);
2561
- return w ? (d.set(o, { hash: a, processed: w }), w) : (d.delete(o), null);
2562
- }
2563
- function pt(o) {
2564
- d.delete(o);
2565
- }
2566
- function Q() {
2567
- const o = Object.keys(t.modules.systems);
2568
- return {
2569
- route: t.modules.route.replace(/\/$/, ""),
2570
- system: o.length === 1 ? o[0] : void 0
2571
- };
2572
- }
2573
- function wt(o) {
2574
- const l = t.exclude ?? [];
2575
- for (const a of l) {
2576
- const h = a.replace(/\/$/, "");
2577
- if (o === h || o.startsWith(h + "/")) return !0;
2578
- }
2579
- return !1;
2580
- }
2581
- async function it() {
2582
- const o = await Ue(n), l = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), u = [], g = new Set(o);
2583
- for (const x of [...d.keys()])
2584
- g.has(x) || d.delete(x);
2585
- for (const x of o) {
2586
- let b = null;
2587
- try {
2588
- b = await bt(x);
2589
- } catch (M) {
2590
- console.warn(`[nimpress] failed to process ${x}:`, M);
2591
- continue;
2592
- }
2593
- if (!b || wt(b.slug)) continue;
2594
- if (u.push(b), b.type === "changelog") {
2595
- const $ = `${wr(b.slug)}\0${b.frontmatter.title}`, N = h.get($) ?? [];
2596
- N.push(b), h.set($, N);
2597
- continue;
2598
- }
2599
- if (b.type === "roadmap") {
2600
- const M = String(b.filePath);
2601
- w.set(M, [b]);
2602
- }
2603
- if (b.type === "component") {
2604
- const M = V(b.filePath), $ = y.get(M);
2605
- if ($)
2606
- throw new Error(
2607
- `[nimpress] one type component page per folder: ${M} holds ${$} and ${b.filePath}`
2608
- );
2609
- y.set(M, b.filePath);
2610
- }
2611
- const P = a.get(b.effectivePath);
2612
- if (P)
2613
- throw new Error(
2614
- `[nimpress] duplicate path ${b.effectivePath}: ${P} and ${b.filePath}`
2615
- );
2616
- a.set(b.effectivePath, b.filePath), l.set(b.slug, b);
2617
- }
2618
- ue.clear();
2619
- for (const [x, b] of h) {
2620
- const P = x.split("\0", 1)[0], M = yn(P ? "/" + P : "/");
2621
- if (a.has(M))
2622
- throw new Error(
2623
- `[nimpress] path ${M} is occupied by both a changelog collection and a regular page`
2624
- );
2625
- const $ = b.filter((E) => !(p && Dt(E.frontmatter)));
2626
- if ($.length === 0) continue;
2627
- $.sort((E, B) => {
2628
- const z = String(E.frontmatter.data?.version ?? ""), X = String(B.frontmatter.data?.version ?? "");
2629
- return yr(X, z);
2630
- });
2631
- const N = $[0], F = `__changelog__${(P || "root").replace(/\//g, "__")}`, U = $.map((E) => {
2632
- const B = E.frontmatter.data, z = String(B?.version ?? ""), X = String(B?.title ?? ""), O = B?.description !== void 0 ? String(B.description) : void 0, R = B?.release_date;
2633
- let J;
2634
- if (R != null && String(R).trim() !== "") {
2635
- const Y = R instanceof Date ? R.toISOString() : String(R), Z = new Date(Y);
2636
- if (Number.isNaN(Z.getTime()))
2637
- throw new Error(
2638
- `[nimpress] changelog entry ${E.filePath} has an invalid data.release_date (${Y}). Use an RFC 3339 timestamp like 2026-06-10 or 2026-06-10T09:00:00Z.`
2639
- );
2640
- J = Z.toISOString();
2641
- }
2642
- const tt = z ? `v${z}` : "unreleased";
2643
- return ue.set(`${F}#${tt}`, E.rawText), {
2644
- version: z,
2645
- slug: tt,
2646
- title: X,
2647
- description: O,
2648
- releaseDate: J,
2649
- hidden: ee(E.frontmatter),
2650
- html: E.html,
2651
- headings: E.headings,
2652
- data: E.frontmatter.data
2653
- };
2654
- }), C = U.map((E) => ({
2655
- level: 2,
2656
- text: E.version ? `v${E.version}` : E.title || "unreleased",
2657
- slug: E.slug
2658
- })), I = {
2659
- slug: F,
2660
- filePath: N.filePath,
2661
- effectivePath: M,
2662
- type: "changelog",
2663
- frontmatter: {
2664
- ...N.frontmatter,
2665
- path: M,
2666
- type: "changelog",
2667
- rss: $.some((E) => E.frontmatter.rss === !0) ? !0 : void 0,
2668
- subscribe: $.some((E) => E.frontmatter.subscribe === !0) ? !0 : void 0
2669
- },
2670
- html: "",
2671
- headings: C,
2672
- rawText: $.map((E) => E.rawText).join(`
2673
-
2674
- `),
2675
- changelogEntries: U
2676
- };
2677
- a.set(M, I.filePath), l.set(I.slug, I);
2678
- }
2679
- Yn(w, u), Rn(l), Bn(l), r = l;
2680
- }
2681
- const $t = /* @__PURE__ */ new Map(), ue = /* @__PURE__ */ new Map();
2682
- let fe = JSON.stringify({ pages: [] }, null, 2) + `
2683
- `;
2684
- function Bn(o) {
2685
- const l = [];
2686
- for (const a of o.values()) {
2687
- if (a.frontmatter.subscribe !== !0 || xe(a.frontmatter)) continue;
2688
- const h = a.effectivePath === "/" ? "" : a.effectivePath, y = `${yt(a) ? `/${t.paths.guarded}/${Vt(a)}` : ""}${h}/${hn(0)}`;
2689
- if (!$t.has(y)) continue;
2690
- const u = {
2691
- path: a.effectivePath,
2692
- title: a.frontmatter.title,
2693
- name: a.effectivePath === "/" ? "index" : a.effectivePath.replace(/\//g, "-").replace(/^-/, ""),
2694
- feed: y
2695
- };
2696
- a.type === "changelog" && (u.entries = (a.changelogEntries ?? []).filter((g) => !g.hidden).map((g) => ({
2697
- slug: g.slug,
2698
- version: g.version,
2699
- date: g.releaseDate,
2700
- title: g.title,
2701
- description: g.description,
2702
- body: ue.get(`${a.slug}#${g.slug}`) ?? ""
2703
- }))), l.push(u);
2704
- }
2705
- l.sort((a, h) => a.path.localeCompare(h.path)), fe = JSON.stringify({ pages: l }, null, 2) + `
2706
- `;
2707
- }
2708
- function Rn(o) {
2709
- $t.clear();
2710
- const l = t.site?.url?.replace(/\/$/, "");
2711
- for (const a of o.values()) {
2712
- if (a.type !== "changelog" || !(a.frontmatter.rss === !0 || a.frontmatter.subscribe === !0)) continue;
2713
- if (!l) {
2714
- console.warn(`[nimpress] changelog feed for ${a.effectivePath} needs site.url in the config, skipping`);
2715
- continue;
2716
- }
2717
- const h = (a.changelogEntries ?? []).filter((E) => !E.hidden);
2718
- if (h.length === 0) continue;
2719
- const w = a.effectivePath === "/" ? "" : a.effectivePath, y = `${l}${dt(t.base, w || "/")}`, u = yt(a) ? `/${t.paths.guarded}/${Vt(a)}` : "", g = (E) => `${u}${w}/${hn(E)}`, x = h.map((E) => E.releaseDate ? new Date(E.releaseDate).getTime() : Number.NaN).filter((E) => !Number.isNaN(E)).sort((E, B) => B - E), b = [];
2720
- for (let E = 0; E + 1 < x.length; E++) b.push(x[E] - x[E + 1]);
2721
- const P = b.length ? Math.round(b.reduce((E, B) => E + B, 0) / b.length / 1e3) : void 0, M = P ? Math.min(43200, Math.max(60, Math.round(P / 60))) : 1440, $ = P ? P <= 172800 ? "daily" : P <= 1209600 ? "weekly" : P <= 5184e3 ? "monthly" : "yearly" : "weekly", N = x.length ? new Date(x[0]).toUTCString() : void 0, F = ut(a.frontmatter.title), U = ut(
2722
- a.frontmatter.description ?? t.site?.description ?? a.frontmatter.title
2723
- ), C = t.site?.locale?.replace("_", "-").toLowerCase(), I = Math.max(1, Math.ceil(h.length / Se));
2724
- for (let E = 0; E < I; E++) {
2725
- const B = h.slice(E * Se, (E + 1) * Se), z = [
2726
- `<atom:link href="${ut(`${l}${dt(t.base, g(E))}`)}" rel="self" type="application/rss+xml"/>`
2727
- ];
2728
- E > 0 && z.push(
2729
- `<atom:link href="${ut(`${l}${dt(t.base, g(0))}`)}" rel="current" type="application/rss+xml"/>`
2730
- ), E + 1 < I && z.push(
2731
- `<atom:link href="${ut(`${l}${dt(t.base, g(E + 1))}`)}" rel="prev-archive" type="application/rss+xml"/>`
2732
- ), E > 1 && z.push(
2733
- `<atom:link href="${ut(`${l}${dt(t.base, g(E - 1))}`)}" rel="next-archive" type="application/rss+xml"/>`
2734
- );
2735
- const X = B.map((J) => {
2736
- const tt = `${y}#${J.slug}`, Y = [
2737
- `<title>${ut(J.version ? `v${J.version} ${J.title}` : J.title)}</title>`,
2738
- `<link>${ut(tt)}</link>`,
2739
- `<guid isPermaLink="true">${ut(tt)}</guid>`
2740
- ];
2741
- return J.releaseDate && Y.push(`<pubDate>${new Date(J.releaseDate).toUTCString()}</pubDate>`), J.description && Y.push(`<description>${ut(J.description)}</description>`), J.html && Y.push(`<content:encoded>${ur(J.html)}</content:encoded>`), ` <item>
2742
- ${Y.join(`
2743
- `)}
2744
- </item>`;
2745
- }), O = [
2746
- `<title>${F}</title>`,
2747
- `<link>${ut(y)}</link>`,
2748
- `<description>${U}</description>`,
2749
- ...z
2750
- ];
2751
- C && O.push(`<language>${ut(C)}</language>`), N && O.push(`<lastBuildDate>${N}</lastBuildDate>`), O.push(`<ttl>${M}</ttl>`), O.push(`<sy:updatePeriod>${$}</sy:updatePeriod>`), O.push("<sy:updateFrequency>1</sy:updateFrequency>"), P !== void 0 && O.push(`<nimpress:releaseCadence>${P}</nimpress:releaseCadence>`), O.push(`<nimpress:latestVersion>${ut(h[0].version)}</nimpress:latestVersion>`), O.push(`<nimpress:releaseCount>${h.length}</nimpress:releaseCount>`), E > 0 && O.push("<fh:archive/>");
2752
- const R = [
2753
- '<?xml version="1.0" encoding="UTF-8"?>',
2754
- `<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}">`,
2755
- " <channel>",
2756
- ` ${O.join(`
2757
- `)}`,
2758
- X.join(`
2759
- `),
2760
- " </channel>",
2761
- "</rss>"
2762
- ].join(`
2763
- `);
2764
- $t.set(g(E), R);
2765
- }
2766
- }
2767
- }
2768
- const me = /* @__PURE__ */ new Map();
2769
- function yt(o) {
2770
- return o.frontmatter.gate !== void 0;
2771
- }
2772
- function Wn(o) {
2773
- const l = V(o.filePath);
2774
- let a = [];
2775
- try {
2776
- a = le(l);
2777
- } catch {
2778
- return [];
2779
- }
2780
- return a.filter((h) => W(l, h) !== o.filePath).map((h) => jt(process.cwd(), W(l, h)));
2781
- }
2782
- function Vt(o) {
2783
- const l = t.auth?.guard;
2784
- return typeof l == "function" ? l(o.frontmatter, jt(process.cwd(), o.filePath), Wn(o)) : o.frontmatter.gate ?? "default";
2785
- }
2786
- function Ln() {
2787
- const o = [];
2788
- for (const l of r.values())
2789
- l.sidebarOnly || xe(l.frontmatter) || yt(l) || o.push(l);
2790
- return o;
2791
- }
2792
- function St(o) {
2793
- const l = t.site?.url?.replace(/\/$/, "");
2794
- if (l)
2795
- return l + dt(t.base, o.startsWith("/") ? o : "/" + o);
2796
- }
2797
- function Je(o) {
2798
- if (me.has(o)) return me.get(o);
2799
- let l;
2800
- try {
2801
- l = cs("git", ["log", "-1", "--format=%cI", "--", o], {
2802
- cwd: process.cwd(),
2803
- encoding: "utf-8",
2804
- stdio: ["ignore", "pipe", "ignore"]
2805
- }).trim() || void 0;
2806
- } catch {
2807
- l = void 0;
2808
- }
2809
- return me.set(o, l), l;
2810
- }
2811
- function Hn(o) {
2812
- return o === "changelog" || o === "roadmap" ? "CollectionPage" : o === "openapi" ? "APIReference" : o === "hero" ? "WebPage" : "TechArticle";
2813
- }
2814
- function Un(o) {
2815
- const l = t.meta ?? {}, a = t.site, h = o.frontmatter, w = h.meta ?? {}, y = w.og ?? {}, u = w.twitter ?? {}, g = h.title, x = a?.title && a.title !== g ? `${g} · ${a.title}` : g, b = w.description ?? h.description ?? a?.description, P = w.canonical ?? St(o.effectivePath), M = (() => {
2816
- if (w.keywords) return Array.isArray(w.keywords) ? w.keywords : [w.keywords];
2817
- const Y = he(h.tags);
2818
- return Y.length ? Y : l.keywords ?? [];
2819
- })(), $ = w.robots ?? "index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1", N = y.title ?? g, F = y.description ?? b, U = y.image ?? a?.ogImage, C = U ? St(U) ?? U : void 0, I = y.type ?? (h.type === "hero" || o.effectivePath === "/" ? "website" : "article"), E = l.og?.width ?? 1200, B = l.og?.height ?? 600, z = u.card ?? (C ? "summary_large_image" : "summary"), X = u.site ?? a?.twitterSite, O = Jt, R = [];
2820
- if (R.push(`<title>${O(x)}</title>`), b && R.push(`<meta name="description" content="${O(b)}">`), M.length && R.push(`<meta name="keywords" content="${O(M.join(", "))}">`), R.push(`<meta name="robots" content="${O($)}">`), R.push(`<meta name="googlebot" content="${O($)}">`), P) {
2821
- R.push(`<link rel="canonical" href="${O(P)}">`);
2822
- const Y = l.localeAlternates ?? [];
2823
- for (const Z of Y)
2824
- R.push(`<link rel="alternate" hreflang="${O(Z)}" href="${O(P)}">`);
2825
- Y.length && R.push(`<link rel="alternate" hreflang="x-default" href="${O(P)}">`);
2826
- }
2827
- if (R.push(`<meta property="og:title" content="${O(N)}">`), F && R.push(`<meta property="og:description" content="${O(F)}">`), R.push(`<meta property="og:type" content="${O(I)}">`), P && R.push(`<meta property="og:url" content="${O(P)}">`), C && (R.push(`<meta property="og:image" content="${O(C)}">`), R.push(`<meta property="og:image:width" content="${E}">`), R.push(`<meta property="og:image:height" content="${B}">`), y.imageAlt && R.push(`<meta property="og:image:alt" content="${O(y.imageAlt)}">`)), a?.title && R.push(`<meta property="og:site_name" content="${O(a.title)}">`), a?.locale && R.push(`<meta property="og:locale" content="${O(a.locale)}">`), R.push(`<meta name="twitter:card" content="${O(z)}">`), X && R.push(`<meta name="twitter:site" content="${O(X)}">`), R.push(`<meta name="twitter:title" content="${O(u.title ?? N)}">`), (u.description ?? F) && R.push(`<meta name="twitter:description" content="${O(u.description ?? F ?? "")}">`), (u.image ?? C) && R.push(`<meta name="twitter:image" content="${O(u.image ?? C ?? "")}">`), b && R.push(`<meta name="dc.description" content="${O(b)}">`), R.push(`<meta name="dc.title" content="${O(x)}">`), a?.locale && R.push(`<meta name="dc.language" content="${O(a.locale)}">`), h.type === "changelog" && (h.rss === !0 || h.subscribe === !0)) {
2828
- const Y = o.effectivePath === "/" ? "/rss.xml" : `${o.effectivePath}/rss.xml`, Z = St(Y) ?? Y;
2829
- R.push(`<link rel="alternate" type="application/rss+xml" title="${O(g)}" href="${O(Z)}">`);
2830
- }
2831
- const J = t.site?.url?.replace(/\/$/, ""), tt = [];
2832
- if (l.organization && tt.push({ "@context": "https://schema.org", ...l.organization }), J && a?.title && tt.push({
2833
- "@context": "https://schema.org",
2834
- "@type": "WebSite",
2835
- "@id": `${J}${dt(t.base, "/")}#website`,
2836
- name: a.title,
2837
- url: `${J}${dt(t.base, "/")}`,
2838
- description: a.description
2839
- }), P && o.effectivePath !== "/") {
2840
- const Y = [
2841
- { name: a?.title ?? "Home", item: J ? `${J}${dt(t.base, "/")}` : void 0 }
2842
- ], Z = o.effectivePath.split("/").filter(Boolean);
2843
- let at = "";
2844
- for (const ct of Z) {
2845
- at += "/" + ct;
2846
- const ht = [...r.values()].find((G) => G.effectivePath === at);
2847
- Y.push({ name: ht?.frontmatter.title ?? ne(ct), item: St(at) });
2848
- }
2849
- tt.push({
2850
- "@context": "https://schema.org",
2851
- "@type": "BreadcrumbList",
2852
- itemListElement: Y.map((ct, ht) => ({
2853
- "@type": "ListItem",
2854
- position: ht + 1,
2855
- name: ct.name,
2856
- item: ct.item
2857
- }))
2858
- });
2859
- }
2860
- tt.push({
2861
- "@context": "https://schema.org",
2862
- "@type": Hn(o.type),
2863
- name: x,
2864
- headline: g,
2865
- description: b,
2866
- url: P,
2867
- isPartOf: J ? `${J}${dt(t.base, "/")}#website` : void 0,
2868
- dateModified: Je(o.filePath)
2869
- }), w.jsonLd && tt.push(w.jsonLd);
2870
- for (const Y of tt) R.push(fr(Y));
2871
- return `
2872
- ${R.join(`
2873
- `)}
2874
- `;
2875
- }
2876
- function Jn() {
2877
- const o = t.meta ?? {};
2878
- if (o.robots?.custom) return o.robots.custom;
2879
- const l = new Set(o.robots?.block ?? []), a = ["User-agent: *", "Allow: /", ""];
2880
- for (const w of gn)
2881
- a.push(`User-agent: ${w}`), a.push(l.has(w) ? "Disallow: /" : "Allow: /"), a.push("");
2882
- for (const w of l)
2883
- gn.includes(w) || (a.push(`User-agent: ${w}`), a.push("Disallow: /"), a.push(""));
2884
- o.robots?.append && a.push(o.robots.append, "");
2885
- const h = St("/sitemap.xml");
2886
- return h && a.push(`Sitemap: ${h}`), a.join(`
2887
- `).replace(/\n{3,}/g, `
2888
-
2889
- `).trim() + `
2890
- `;
2891
- }
2892
- function qn(o) {
2893
- const l = t.site?.url?.replace(/\/$/, "");
2894
- if (!l) return;
2895
- const a = t.meta?.localeAlternates ?? [];
2896
- return [
2897
- '<?xml version="1.0" encoding="UTF-8"?>',
2898
- '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">',
2899
- o.map((w) => {
2900
- const y = `${l}${dt(t.base, w.effectivePath === "/" ? "/" : w.effectivePath)}`, u = w.effectivePath.split("/").filter(Boolean).length, g = u === 0 ? "1.0" : u === 1 ? "0.8" : "0.6", x = u === 0 ? "weekly" : "monthly", b = Je(w.filePath), P = [` <loc>${ut(y)}</loc>`];
2901
- b && P.push(` <lastmod>${ut(b)}</lastmod>`), P.push(` <changefreq>${x}</changefreq>`), P.push(` <priority>${g}</priority>`);
2902
- for (const M of a)
2903
- P.push(` <xhtml:link rel="alternate" hreflang="${ut(M)}" href="${ut(y)}"/>`);
2904
- return ` <url>
2905
- ${P.join(`
2906
- `)}
2907
- </url>`;
2908
- }).join(`
2909
- `),
2910
- "</urlset>",
2911
- ""
2912
- ].join(`
2913
- `);
2914
- }
2915
- function zn(o) {
2916
- const l = t.meta ?? {}, a = t.site, h = [`# ${a?.title ?? t.title}`, ""], w = l.llms?.summary ?? a?.description;
2917
- w && h.push(`> ${w}`, "");
2918
- const y = /* @__PURE__ */ new Map(), u = [];
2919
- for (const M of o) {
2920
- const $ = M.effectivePath.split("/").filter(Boolean);
2921
- if ($.length === 0) {
2922
- u.push(M);
2923
- continue;
2924
- }
2925
- const N = $[0], F = y.get(N) ?? [];
2926
- F.push(M), y.set(N, F);
2927
- }
2928
- const g = (M) => {
2929
- const $ = St(M.effectivePath) ?? M.effectivePath;
2930
- return M.frontmatter.description ? `- [${M.frontmatter.title}](${$}): ${M.frontmatter.description}` : `- [${M.frontmatter.title}](${$})`;
2931
- };
2932
- for (const M of u) h.push(g(M));
2933
- u.length && h.push("");
2934
- for (const [M, $] of [...y.entries()].sort((N, F) => N[0].localeCompare(F[0]))) {
2935
- const N = $.find((F) => F.effectivePath === `/${M}`);
2936
- h.push(`## ${N?.frontmatter.title ?? ne(M)}`, ""), $.sort((F, U) => F.effectivePath.localeCompare(U.effectivePath));
2937
- for (const F of $) h.push(g(F));
2938
- h.push("");
2939
- }
2940
- const x = new Set(t.meta?.keywords ?? []);
2941
- for (const M of o) for (const $ of he(M.frontmatter.tags)) x.add($);
2942
- x.size && h.push("## Keywords", "", [...x].join(", "), "");
2943
- const b = St("/sitemap.xml"), P = St("/robots.txt");
2944
- return (b || P) && (h.push("## Optional", ""), b && h.push(`- [Sitemap](${b})`), P && h.push(`- [Robots](${P})`), h.push("")), l.llms?.append && h.push(l.llms.append, ""), h.join(`
2945
- `).replace(/\n{3,}/g, `
2946
-
2947
- `);
2948
- }
2949
- function Gn(o) {
2950
- const a = [`# ${t.site?.title ?? t.title}`, ""];
2951
- for (const h of o) {
2952
- a.push(`## ${h.frontmatter.title}`, "");
2953
- const w = St(h.effectivePath);
2954
- w && a.push(`URL: ${w}`, ""), a.push(h.rawText.trim(), "");
2955
- }
2956
- return a.join(`
2957
- `).replace(/\n{3,}/g, `
2958
-
2959
- `);
2960
- }
2961
- async function Vn() {
2962
- const o = t.meta ?? {}, l = Ln().sort((y, u) => y.effectivePath.localeCompare(u.effectivePath)), a = W(c, "index.html"), h = await rt(a, "utf-8");
2963
- for (const y of l) {
2964
- const u = Un(y), g = h.replace("</head>", `${u}</head>`), x = y.effectivePath === "/" ? a : W(c, y.effectivePath.replace(/^\//, ""), "index.html");
2965
- await _t(V(x), { recursive: !0 }), await nt(x, g);
2966
- }
2967
- await nt(W(c, "robots.txt"), Jn());
2968
- const w = qn(l);
2969
- if (w && await nt(W(c, "sitemap.xml"), w), await nt(W(c, "llms.txt"), zn(l)), o.llms?.full && await nt(W(c, "llms-full.txt"), Gn(l)), o.webmanifest && await nt(W(c, "site.webmanifest"), JSON.stringify(o.webmanifest, null, 2) + `
2970
- `), o.humans && await nt(W(c, "humans.txt"), o.humans.trim() + `
2971
- `), o.security) {
2972
- const y = o.security, u = [];
2973
- y.contact && u.push(`Contact: ${y.contact}`), y.policy && u.push(`Policy: ${y.policy}`), y.languages && u.push(`Preferred-Languages: ${y.languages}`), y.canonical && u.push(`Canonical: ${y.canonical}`), y.expires && u.push(`Expires: ${y.expires}`), u.length && (await _t(W(c, ".well-known"), { recursive: !0 }), await nt(W(c, ".well-known", "security.txt"), u.join(`
2974
- `) + `
2975
- `));
2976
- }
2977
- }
2978
- async function Xn() {
2979
- const o = [...r.values()].filter((u) => !xe(u.frontmatter) && yt(u)), l = {}, a = /* @__PURE__ */ new Map();
2980
- for (const u of o) {
2981
- const g = Vt(u);
2982
- l[u.effectivePath] = { gate: u.frontmatter.gate, bundle: g };
2983
- const x = a.get(g) ?? [];
2984
- x.push(u), a.set(g, x);
2985
- }
2986
- const h = `/${t.paths.guarded}/`;
2987
- if (await nt(
2988
- W(c, "access.json"),
2989
- JSON.stringify({ prefix: h, routes: l }, null, 2) + `
2990
- `
2991
- ), o.length === 0) return;
2992
- const w = W(c, t.paths.guarded), y = {};
2993
- for (const [u, g] of a) {
2994
- const x = W(w, u);
2995
- await _t(W(x, "body"), { recursive: !0 });
2996
- const b = {}, P = g.map(($) => ({
2997
- slug: $.slug,
2998
- path: $.effectivePath,
2999
- type: $.type,
3000
- frontmatter: $.frontmatter,
3001
- bundle: u
3002
- })), M = [`${u}/manifest.json`, `${u}/search.json`];
3003
- for (const $ of g) {
3004
- $.pageCss && (b[$.effectivePath] = $.pageCss);
3005
- const N = {
3006
- html: $.html,
3007
- headings: $.headings,
3008
- openApiSpec: $.openApiSpec,
3009
- openApiFile: $.openApiFile,
3010
- openApiUrl: $.openApiUrl,
3011
- changelogEntries: $.changelogEntries,
3012
- roadmapEntries: $.roadmapEntries,
3013
- componentData: $.componentData,
3014
- dbmlSchema: $.dbmlSchema,
3015
- dbmlSource: $.dbmlSource,
3016
- dbmlFile: $.dbmlFile,
3017
- dbmlError: $.dbmlError
3018
- }, F = W(x, "body", `${At($.slug)}.json`);
3019
- await _t(V(F), { recursive: !0 }), await nt(F, JSON.stringify(N)), M.push(`${u}/body/${At($.slug)}.json`);
3020
- }
3021
- await nt(
3022
- W(x, "manifest.json"),
3023
- JSON.stringify({ shells: P, styles: b, sidebar: Ge(!0) })
3024
- ), await nt(W(x, "search.json"), JSON.stringify(Ve(!0, g))), y[u] = {
3025
- pages: Object.fromEntries(g.map(($) => [$.effectivePath, $.frontmatter.gate ?? ""])),
3026
- files: M
3027
- };
3028
- }
3029
- await nt(
3030
- W(c, "guard.map.json"),
3031
- JSON.stringify({ prefix: h, routes: l, bundles: y }, null, 2) + `
3032
- `
3033
- );
3034
- }
3035
- function Yn(o, l) {
3036
- if (o.size === 0) return;
3037
- const a = l.filter((w) => Kn(w.type)), h = /* @__PURE__ */ new Map();
3038
- for (const w of a) h.set(w.filePath, w);
3039
- for (const [, w] of o) {
3040
- const y = w[0], u = V(y.filePath), g = y.frontmatter.data, x = g?.issues ?? g?.entries, b = [];
3041
- if (typeof x == "string") b.push(x);
3042
- else if (Array.isArray(x))
3043
- for (const C of x) typeof C == "string" && b.push(C);
3044
- const P = b.length ? b.map((C) => q(u, C)) : [u], M = a.filter((C) => {
3045
- for (const I of P)
3046
- if (C.filePath !== I && (C.filePath.startsWith(I + "/") || C.filePath.startsWith(I + "\\")))
3047
- return !0;
3048
- return !1;
3049
- }), $ = g?.changelog, N = [];
3050
- if (typeof $ == "string")
3051
- N.push(q(u, $));
3052
- else if (Array.isArray($))
3053
- for (const C of $) typeof C == "string" && N.push(q(u, C));
3054
- const F = /* @__PURE__ */ new Map();
3055
- for (const C of l) {
3056
- if (C.type !== "changelog" || N.length && !N.some(
3057
- (ct) => C.filePath === ct || C.filePath.startsWith(ct + "/") || C.filePath.startsWith(ct + "\\")
3058
- ))
3059
- continue;
3060
- const I = C.frontmatter.data, E = I?.issue;
3061
- if (!E) continue;
3062
- const B = String(E).trim();
3063
- if (!B) continue;
3064
- const z = qe(C.filePath, B);
3065
- if (!z) continue;
3066
- const X = h.get(z);
3067
- if (!X) continue;
3068
- const O = String(I?.version ?? ""), R = ze(I?.release_date), J = I?.status;
3069
- let tt, Y = !1;
3070
- if (typeof J == "string") {
3071
- const at = J.trim().toLowerCase();
3072
- if (["completes", "completed", "complete", "fixes", "closes", "resolves"].includes(at))
3073
- Y = !0;
3074
- else {
3075
- const ct = Number(at.replace(/%$/, ""));
3076
- Number.isFinite(ct) && (tt = ct);
3077
- }
3078
- } else typeof J == "number" && (tt = J);
3079
- const Z = F.get(X.filePath) ?? [];
3080
- Z.push({
3081
- version: O,
3082
- title: String(I?.title ?? C.frontmatter.title),
3083
- description: I?.description !== void 0 ? String(I.description) : void 0,
3084
- releaseDate: R,
3085
- progress: tt,
3086
- completes: Y,
3087
- path: C.effectivePath,
3088
- slug: O ? `v${O}` : "unreleased",
3089
- entrySlug: `${C.effectivePath}#${O ? `v${O}` : "unreleased"}`
3090
- }), F.set(X.filePath, Z);
3091
- }
3092
- const U = M.map((C) => {
3093
- const I = C.frontmatter.data, E = C.type, B = ze(I?.date ?? I?.target_date);
3094
- let z;
3095
- const X = I?.parent;
3096
- if (typeof X == "string" && X.trim()) {
3097
- const Z = qe(C.filePath, X.trim());
3098
- Z && h.has(Z) && (z = h.get(Z).effectivePath);
3099
- }
3100
- const O = (F.get(C.filePath) ?? []).slice().sort(
3101
- (Z, at) => (Z.releaseDate ?? "").localeCompare(at.releaseDate ?? "")
3102
- ), R = O.some((Z) => Z.completes), J = String(I?.status ?? "").toLowerCase(), tt = J === "shipped" || J === "in_progress" || J === "planned" ? J : R ? "shipped" : O.length ? "in_progress" : "planned", Y = O.reduce((Z, at) => typeof at.progress == "number" ? Math.max(Z ?? 0, at.progress) : Z, void 0);
3103
- return {
3104
- kind: E,
3105
- slug: C.slug,
3106
- filePath: C.filePath,
3107
- href: C.effectivePath,
3108
- title: C.frontmatter.title,
3109
- description: C.frontmatter.description,
3110
- targetDate: B,
3111
- parent: z,
3112
- progress: Y,
3113
- status: tt,
3114
- hidden: ee(C.frontmatter),
3115
- html: C.html,
3116
- headings: C.headings,
3117
- data: C.frontmatter.data,
3118
- changelog: O
3119
- };
3120
- });
3121
- U.sort((C, I) => (C.targetDate ?? "").localeCompare(I.targetDate ?? "")), y.roadmapEntries = U, y.headings = U.map((C) => ({
3122
- level: 2,
3123
- text: C.title,
3124
- slug: C.slug
3125
- }));
3126
- }
3127
- }
3128
- function Kn(o) {
3129
- return o === "milestone" || o === "epic" || o === "feature" || o === "bug";
3130
- }
3131
- function qe(o, l) {
3132
- const a = V(o), h = l.replace(/\\/g, "/").trim(), w = h.endsWith(".md") ? h : `${h}.md`;
3133
- return q(a, w);
3134
- }
3135
- function ze(o) {
3136
- if (o == null) return;
3137
- if (o instanceof Date) return o.toISOString();
3138
- const l = String(o).trim();
3139
- if (!l) return;
3140
- const a = new Date(l);
3141
- if (!Number.isNaN(a.getTime()))
3142
- return a.toISOString();
3143
- }
3144
- function de(o, l) {
3145
- if (!o || !/\.svg$/i.test(o.trim())) return o;
3146
- const a = o.trim(), h = a.startsWith("/") ? W(n, a) : q(V(l), a);
3147
- try {
3148
- return qt(h, "utf8").trim();
3149
- } catch {
3150
- console.warn(`[nimpress] sidebar icon ${a} referenced from ${l} is not readable`);
3151
- return;
3152
- }
3153
- }
3154
- function Ge(o = !1) {
3155
- const l = { children: /* @__PURE__ */ new Map() }, a = /* @__PURE__ */ new Map();
3156
- for (const y of r.values()) {
3157
- if (p && (Dt(y.frontmatter) || !o && yt(y))) continue;
3158
- const u = y.frontmatter.sidebar;
3159
- if (y.effectivePath === "/" && !u?.name) continue;
3160
- const g = y.effectivePath === "/" ? [u.path ?? u.name] : y.effectivePath.split("/").filter(Boolean), x = y.filePath.endsWith(`${kt}index.md`);
3161
- if (u?.name && x) {
3162
- const $ = "/" + g.join("/");
3163
- a.set($, {
3164
- label: u.name,
3165
- icon: de(u.icon, y.filePath) ?? a.get($)?.icon,
3166
- style: u.style ?? a.get($)?.style
3167
- });
3168
- }
3169
- if (y.sidebarOnly) continue;
3170
- const b = x ? void 0 : u?.path ?? u?.name;
3171
- b && g[g.length - 2] !== b && (g.length >= 3 ? g.splice(g.length - 2, 1, b) : g.splice(g.length - 1, 0, b));
3172
- let P = l, M = "";
3173
- for (const $ of g) {
3174
- M = M + "/" + $;
3175
- let N = P.children.get($);
3176
- N || (N = { segment: $, fullPath: M, children: /* @__PURE__ */ new Map() }, P.children.set($, N)), P = N;
3177
- }
3178
- if (P.page = y, !x && u?.name) {
3179
- const $ = "/" + g.slice(0, -1).join("/");
3180
- a.set($, {
3181
- label: u.name,
3182
- icon: de(u.icon, y.filePath) ?? a.get($)?.icon,
3183
- style: u.style ?? a.get($)?.style
3184
- });
3185
- }
3186
- }
3187
- function h(y) {
3188
- const u = [];
3189
- for (const b of y.children.values()) u.push(h(b));
3190
- if (Ce(u), y.page) {
3191
- const b = {
3192
- text: Dr(y.page),
3193
- link: y.page.effectivePath,
3194
- slug: y.page.slug,
3195
- gate: y.page.frontmatter.gate,
3196
- order: y.page.frontmatter.order,
3197
- collapsed: y.page.frontmatter.collapsed,
3198
- hidden: ee(y.page.frontmatter)
3199
- }, P = a.get(y.fullPath);
3200
- P?.label && (b.text = P.label), P?.icon && !b.icon && (b.icon = P.icon), P?.style && (b.style = P.style);
3201
- const M = y.page.openApiSpec;
3202
- if (y.page.type === "openapi" && M?.tags?.length) {
3203
- const $ = M.tags.map((N) => ({
3204
- text: N.name,
3205
- link: `${y.page.effectivePath}#tag/${N.name}`,
3206
- slug: `${y.page.slug}__tag__${N.name}`
3207
- }));
3208
- b.items = [...$, ...u];
3209
- } else if (y.page.type === "changelog" && y.page.changelogEntries?.length) {
3210
- const $ = y.page.changelogEntries.map((N, F) => ({
3211
- text: N.version ? `v${N.version}` : N.title || "unreleased",
3212
- link: `${y.page.effectivePath}#${N.slug}`,
3213
- slug: `${y.page.slug}__${N.slug}`,
3214
- hidden: N.hidden,
3215
- order: F
3216
- }));
3217
- b.items = u.length ? [...$, ...u] : $;
3218
- } else if (y.page.type === "roadmap" && y.page.roadmapEntries?.length) {
3219
- const $ = y.page.roadmapEntries.slice().sort(
3220
- (B, z) => (B.targetDate ?? "").localeCompare(z.targetDate ?? "")
3221
- ), N = new Map($.map((B) => [B.href, B])), F = /* @__PURE__ */ new Map(), U = [];
3222
- for (const B of $)
3223
- if (B.parent && N.has(B.parent)) {
3224
- const z = F.get(B.parent) ?? [];
3225
- z.push(B), F.set(B.parent, z);
3226
- } else
3227
- U.push(B);
3228
- const C = (B, z) => {
3229
- const X = F.get(B.href) ?? [], O = {
3230
- text: B.title,
3231
- link: B.href,
3232
- slug: B.slug,
3233
- icon: mr[B.kind],
3234
- hidden: B.hidden,
3235
- order: z
3236
- };
3237
- return X.length && (O.items = X.map((R, J) => C(R, J))), O;
3238
- }, I = U.map((B, z) => C(B, z)), E = u.filter((B) => !B.slug || !$.some((z) => z.slug === B.slug));
3239
- b.items = E.length ? [...I, ...E] : I;
3240
- } else if (y.page.type === "component") {
3241
- const $ = {
3242
- text: "Overview",
3243
- link: y.page.effectivePath,
3244
- slug: `${y.page.slug}__doc`,
3245
- order: -1
3246
- }, N = (y.page.componentData?.stories ?? []).map((F, U) => ({
3247
- text: F.sidebar?.name ?? F.name,
3248
- link: `${y.page.effectivePath}/${ke(F.name)}`,
3249
- slug: `${y.page.slug}__story__${ke(F.name)}`,
3250
- icon: de(F.sidebar?.icon, y.page.filePath),
3251
- style: F.sidebar?.style,
3252
- order: U
3253
- }));
3254
- b.text = ne(y.segment), b.items = [$, ...N, ...u], b.collapsed = !0;
3255
- } else u.length && (b.items = u);
3256
- return b.collapsed !== !1 && b.items?.some(($) => $.collapsed === !1) && (b.collapsed = !1), b;
3257
- }
3258
- const g = a.get(y.fullPath), x = {
3259
- text: g?.label ?? ne(y.segment),
3260
- slug: y.fullPath.replace(/^\//, "")
3261
- };
3262
- if (g?.icon && (x.icon = g.icon), g?.style && (x.style = g.style), u.length) {
3263
- x.items = u;
3264
- let b = Number.MAX_SAFE_INTEGER;
3265
- for (const P of u)
3266
- P.order !== void 0 && P.order < b && (b = P.order);
3267
- b !== Number.MAX_SAFE_INTEGER && (x.order = b);
3268
- }
3269
- return x.items?.some((b) => b.collapsed === !1) && (x.collapsed = !1), x;
3270
- }
3271
- const w = [];
3272
- for (const y of l.children.values()) w.push(h(y));
3273
- return Ce(w), w;
3274
- }
3275
- function Zn() {
3276
- const o = {}, l = {};
3277
- for (const [h, w] of r) {
3278
- if (p && (Dt(w.frontmatter) || yt(w)) || w.sidebarOnly) continue;
3279
- const y = {
3280
- slug: h,
3281
- path: w.effectivePath,
3282
- type: w.type,
3283
- title: w.frontmatter.title,
3284
- gate: w.frontmatter.gate,
3285
- bundle: yt(w) ? Vt(w) : void 0,
3286
- description: w.frontmatter.description,
3287
- order: w.frontmatter.order,
3288
- hidden: ee(w.frontmatter),
3289
- redirect: w.frontmatter.redirect,
3290
- meta: w.frontmatter.meta
3291
- };
3292
- if (o[h] = y, l[w.effectivePath] = h, w.type === "component")
3293
- for (const u of w.componentData?.stories ?? [])
3294
- l[`${w.effectivePath}/${ke(u.name)}`] = h;
3295
- }
3296
- const a = {};
3297
- for (const h of r.values())
3298
- h.sidebarOnly || p && (Dt(h.frontmatter) || yt(h)) || h.pageCss && (a[h.effectivePath] = h.pageCss);
3299
- return { pages: o, byPath: l, sidebar: Ge(), styles: a };
3300
- }
3301
- function Ve(o = !1, l) {
3302
- const a = [], h = l ? l.map((w) => [w.slug, w]) : r;
3303
- for (const [w, y] of h) {
3304
- if (y.sidebarOnly) continue;
3305
- if (o) {
3306
- if (Dt(y.frontmatter) || !yt(y)) continue;
3307
- } else if (p && (Dt(y.frontmatter) || yt(y))) continue;
3308
- const u = y.rawText.replace(/```[\s\S]*?```/g, "").replace(/[#*`>_\[\]\(\)]/g, " "), g = y.type === "openapi" ? Qn(y.openApiSpec) : "", x = y.type === "roadmap" ? ts(y.roadmapEntries ?? []) : "", b = y.componentData ? [
3309
- y.componentData.component,
3310
- y.componentData.system,
3311
- ...(y.componentData.stories ?? []).flatMap(($) => [$.name, $.file])
3312
- ].filter(Boolean).join(" ") : "", P = y.dbmlSource ? y.dbmlSource.replace(/[{}\[\]'"`,]/g, " ") : "", M = [u, g, x, b, P].filter(Boolean).join(`
3313
- `);
3314
- a.push({
3315
- slug: w,
3316
- path: y.effectivePath,
3317
- title: y.frontmatter.title,
3318
- description: y.frontmatter.description,
3319
- body: M,
3320
- gate: y.frontmatter.gate,
3321
- headings: y.headings.map(($) => $.text),
3322
- tags: [
3323
- ...he(y.frontmatter.tags),
3324
- ...y.componentData ? [y.componentData.component] : []
3325
- ]
3326
- });
3327
- }
3328
- return a;
3329
- }
3330
- function Xe(o) {
3331
- return o ? o.replace(/<[^>]+>/g, " ").replace(/&[a-z]+;/gi, " ") : "";
3332
- }
3333
- function Qn(o) {
3334
- if (!o || typeof o != "object") return "";
3335
- const l = o, a = [], h = /* @__PURE__ */ new WeakSet(), w = 12, y = (u, g) => {
3336
- if (u == null || g > w) return;
3337
- const x = typeof u;
3338
- if (x === "string") {
3339
- const b = u.trim();
3340
- b && a.push(b);
3341
- return;
3342
- }
3343
- if (x === "number" || x === "boolean") {
3344
- a.push(String(u));
3345
- return;
3346
- }
3347
- if (x === "object" && !h.has(u)) {
3348
- if (h.add(u), Array.isArray(u)) {
3349
- for (const b of u) y(b, g + 1);
3350
- return;
3351
- }
3352
- for (const [b, P] of Object.entries(u)) {
3353
- if (b === "description_html" || b === "summary_html" || b === "requestBodyHtml") {
3354
- typeof P == "string" && a.push(Xe(P));
3355
- continue;
3356
- }
3357
- a.push(b), y(P, g + 1);
3358
- }
3359
- }
3360
- };
3361
- l.title && a.push(l.title), l.description && a.push(l.description);
3362
- for (const u of l.servers ?? [])
3363
- u.url && a.push(u.url), u.description && a.push(u.description);
3364
- for (const [u, g] of Object.entries(l.securitySchemes ?? {}))
3365
- a.push(u), y(g, 0);
3366
- for (const u of l.tags ?? []) {
3367
- u.name && a.push(u.name), u.description && a.push(u.description);
3368
- for (const g of u.operations ?? []) {
3369
- const x = g;
3370
- x.method && a.push(x.method.toLowerCase(), x.method.toUpperCase()), y(g, 0);
3371
- }
3372
- }
3373
- for (const [u, g] of Object.entries(l.schemas ?? {}))
3374
- a.push(u), y(g, 0);
3375
- return a.join(`
3376
- `);
3377
- }
3378
- function ts(o) {
3379
- const l = [];
3380
- for (const a of o) {
3381
- l.push(a.slug, a.kind, a.title), a.description && l.push(a.description), a.targetDate && l.push(a.targetDate), a.html && l.push(Xe(a.html));
3382
- for (const h of a.changelog)
3383
- l.push(h.version, h.title), h.description && l.push(h.description), h.releaseDate && l.push(h.releaseDate);
3384
- }
3385
- return l.join(`
3386
- `);
3387
- }
3388
- function he(o) {
3389
- if (!o) return [];
3390
- const l = Array.isArray(o) ? o : String(o).split(","), a = [];
3391
- for (const h of l) {
3392
- const w = String(h).trim();
3393
- w && a.push(w);
3394
- }
3395
- return a;
3396
- }
3397
- function At(o) {
3398
- return o === "" ? "__root__" : o;
3399
- }
3400
- function Ye(o) {
3401
- return o === "__root__" ? "" : o;
3402
- }
3403
- function Xt(o) {
3404
- for (const l of [Kt, Zt, Qt, te]) {
3405
- const a = o.moduleGraph.getModuleById("\0" + l);
3406
- a && o.moduleGraph.invalidateModule(a);
3407
- }
3408
- }
3409
- function ge(o) {
3410
- for (const l of r.keys()) {
3411
- const a = Mt + At(l) + ".js", h = Nt + At(l) + ".svelte", w = o.moduleGraph.getModuleById(a), y = o.moduleGraph.getModuleById(h);
3412
- w && o.moduleGraph.invalidateModule(w), y && o.moduleGraph.invalidateModule(y);
3413
- }
3414
- }
3415
- function es() {
3416
- const o = [];
3417
- for (const [l, a] of r) {
3418
- if (a.sidebarOnly || p && (Dt(a.frontmatter) || yt(a))) continue;
3419
- const h = `${Nt}${At(l)}.svelte`;
3420
- o.push(` ${JSON.stringify(l)}: () => import(${JSON.stringify(h)})`);
3421
- }
3422
- return `export const pages = {
3423
- ${o.join(`,
3424
- `)}
3425
- }
3426
- export default pages
3427
- `;
3428
- }
3429
- function ns() {
3430
- const o = [];
3431
- for (const [l, a] of r) {
3432
- if (a.sidebarOnly || p && (Dt(a.frontmatter) || yt(a))) continue;
3433
- const h = `${Mt}${At(l)}.js`;
3434
- o.push(` ${JSON.stringify(l)}: () => import(${JSON.stringify(h)})`);
3435
- }
3436
- return `export const bodies = {
3437
- ${o.join(`,
3438
- `)}
3439
- }
3440
- export default bodies
3441
- `;
3442
- }
3443
- function ss(o) {
3444
- const l = r.get(o);
3445
- if (!l) return null;
3446
- const a = {
3447
- html: l.html,
3448
- headings: l.headings,
3449
- openApiSpec: l.openApiSpec,
3450
- openApiFile: l.openApiFile,
3451
- openApiUrl: l.openApiUrl,
3452
- changelogEntries: l.changelogEntries,
3453
- roadmapEntries: l.roadmapEntries,
3454
- componentData: l.componentData,
3455
- dbmlSchema: l.dbmlSchema,
3456
- dbmlSource: l.dbmlSource,
3457
- dbmlFile: l.dbmlFile,
3458
- dbmlError: l.dbmlError
3459
- };
3460
- return `export default ${JSON.stringify(a)}
3461
- `;
3462
- }
3463
- function os(o) {
3464
- const l = r.get(o);
3465
- if (!l) return null;
3466
- const a = {
3467
- slug: l.slug,
3468
- path: l.effectivePath,
3469
- type: l.type,
3470
- frontmatter: l.frontmatter
3471
- }, h = `${Mt}${At(o)}.js`;
3472
- return `<script lang="ts">
3473
- import { Page, OpenApiRoot, ChangelogPage, HeroPage, RoadmapPage, ComponentPage, DbmlPage, setPageMeta, applyPageStyles } from '@nimtech/nimpress'
3474
- import type { PageBody } from '@nimtech/nimpress'
3475
- const shell = ${JSON.stringify(a).replace(/<\/script>/g, "<\\/script>")}
3476
- setPageMeta(shell)
3477
- applyPageStyles(shell.path)
3478
- const bodyPromise: Promise<{ default: PageBody }> = import(${JSON.stringify(h)})
3479
- <\/script>
3480
-
3481
- {#if shell.type === 'hero'}
3482
- <HeroPage page={shell} {bodyPromise} />
3483
- {:else}
3484
- {#await bodyPromise}
3485
- <div class="np-page-loading" aria-busy="true"></div>
3486
- {:then mod}
3487
- {#if shell.type === 'openapi' && mod.default.openApiSpec}
3488
- <OpenApiRoot spec={mod.default.openApiSpec} specFile={mod.default.openApiFile} specUrl={mod.default.openApiUrl} title={shell.frontmatter.title} frontmatter={shell.frontmatter} />
3489
- {:else if shell.type === 'changelog'}
3490
- <ChangelogPage page={{ ...shell, ...mod.default }} />
3491
- {:else if shell.type === 'roadmap'}
3492
- <RoadmapPage page={{ ...shell, ...mod.default }} />
3493
- {:else if shell.type === 'component'}
3494
- <ComponentPage page={{ ...shell, ...mod.default }} />
3495
- {:else if shell.type === 'dbml'}
3496
- <DbmlPage page={{ ...shell, ...mod.default }} />
3497
- {:else}
3498
- <Page page={{ ...shell, ...mod.default }} />
3499
- {/if}
3500
- {:catch err}
3501
- <div class="np-page-error">Failed to load page body: {String(err)}</div>
3502
- {/await}
3503
- {/if}
3504
- `;
3505
- }
3506
- return {
3507
- name: "@nimtech/nimpress:markdown",
3508
- async config() {
3509
- return t = (await Ws(process.cwd(), e)).resolved, n = q(process.cwd(), t.contentDir), s = q(process.cwd(), t.assetsDir), {};
3510
- },
3511
- configResolved(o) {
3512
- p = o.command === "build", c = q(o.root, o.build.outDir);
3513
- },
3514
- async buildStart() {
3515
- await it(), p && Tt();
3516
- },
3517
- async closeBundle(o) {
3518
- if (!p || o) return;
3519
- const l = W(c, "index.html"), a = W(c, "404.html");
3520
- if (await rs(l, a), await nt(W(c, ".nojekyll"), ""), mt(n) && await Ze(n, c, {
3521
- recursive: !0,
3522
- filter: (h) => {
3523
- try {
3524
- return re(h).isDirectory() || !(h.endsWith(".md") || h.endsWith(".css"));
3525
- } catch {
3526
- return !1;
3527
- }
3528
- }
3529
- }), mt(s)) {
3530
- const h = W(c, t.assetUrlBase.replace(/^\//, ""));
3531
- await Ze(s, h, { recursive: !0 });
3532
- }
3533
- for (const [h, w] of $t) {
3534
- const y = W(c, h.replace(/^\//, ""));
3535
- await _t(V(y), { recursive: !0 }), await nt(y, w);
3536
- }
3537
- await nt(W(c, "subscribe.map.json"), fe), await Vn(), await Xn();
3538
- },
3539
- configureServer(o) {
3540
- v = o, o.watcher.add(n), o.watcher.add(s);
3541
- for (const u of S) o.watcher.add(u);
3542
- for (const u of j) o.watcher.add(u);
3543
- const l = async (u) => {
3544
- if (!(!u.startsWith(n) || !(u.endsWith(".md") || u.endsWith(".css") || u.match(/\.story\.tsx?$/)))) {
3545
- u.endsWith(".css") && pt(u.replace(/\.css$/, ".md")), u.match(/\.story\.tsx?$/) && pt(W(V(u), "index.md"));
3546
- try {
3547
- await it();
3548
- } catch (x) {
3549
- o.config.logger.error(String(x));
3550
- return;
3551
- }
3552
- Xt(o), ge(o), Tt(), o.ws.send({ type: "full-reload" });
3553
- }
3554
- }, a = async (u) => {
3555
- if (u.startsWith(n) && (u.endsWith(".md") || u.endsWith(".css") || u.match(/\.story\.tsx?$/))) {
3556
- u.match(/\.story\.tsx?$/) ? pt(W(V(u), "index.md")) : pt(u.endsWith(".css") ? u.replace(/\.css$/, ".md") : u);
3557
- try {
3558
- await it();
3559
- } catch (x) {
3560
- o.config.logger.error(String(x));
3561
- return;
3562
- }
3563
- Xt(o), ge(o), Tt(), o.ws.send({ type: "full-reload" });
3564
- return;
3565
- }
3566
- if (m.has(u)) {
3567
- const x = m.get(u);
3568
- pt(x);
3569
- }
3570
- k.has(u) && pt(k.get(u));
3571
- };
3572
- if (o.watcher.on("add", l), o.watcher.on("unlink", a), t.banner !== !1) {
3573
- const u = zs(), g = t.banner, x = Date.now();
3574
- o.printUrls = function() {
3575
- const b = o.resolvedUrls, P = b?.local?.[0] ?? `http://localhost:${o.config.server.port ?? 5173}/`, M = b?.network?.[0] ?? "use --host to expose", $ = qs({
3576
- title: g.title ?? t.title ?? u.name ?? "Nimpress",
3577
- tagline: g.tagline,
3578
- company: g.company,
3579
- version: g.version ?? u.version,
3580
- localUrl: P,
3581
- networkUrl: M,
3582
- duration: Date.now() - x
3583
- });
3584
- process.stdout.write("\x1Bc"), process.stdout.write($ + `
3585
- `), Tt();
3586
- };
3587
- }
3588
- const h = {
3589
- ".png": "image/png",
3590
- ".jpg": "image/jpeg",
3591
- ".jpeg": "image/jpeg",
3592
- ".gif": "image/gif",
3593
- ".svg": "image/svg+xml",
3594
- ".webp": "image/webp",
3595
- ".ico": "image/x-icon",
3596
- ".pdf": "application/pdf",
3597
- ".json": "application/json",
3598
- ".css": "text/css",
3599
- ".js": "text/javascript",
3600
- ".txt": "text/plain",
3601
- ".woff": "font/woff",
3602
- ".woff2": "font/woff2",
3603
- ".mp4": "video/mp4"
3604
- }, w = t.assetUrlBase, y = (u, g, x) => {
3605
- if (!g || g.endsWith(".md")) return !1;
3606
- const b = W(u, decodeURIComponent(g));
3607
- return !b.startsWith(u) || !mt(b) || !re(b).isFile() ? !1 : (x.setHeader("Content-Type", h[Me(b).toLowerCase()] ?? "application/octet-stream"), is(b).pipe(x), !0);
3608
- };
3609
- return o.middlewares.use((u, g, x) => {
3610
- const b = (u.url ?? "").split("?")[0], P = Es(t.base, b);
3611
- if (P.startsWith("/@") || P.startsWith("/node_modules/")) return x();
3612
- if (P === "/__nimpress/claude-md" && u.method === "PUT") {
3613
- const F = [];
3614
- u.on("data", (U) => F.push(U)), u.on("end", async () => {
3615
- try {
3616
- const U = JSON.parse(Buffer.concat(F).toString("utf-8")), C = String(U.path ?? ""), I = String(U.content ?? ""), E = q(process.cwd(), C);
3617
- if (!Object.values(t.modules.systems).filter((X) => X.source).map((X) => q(process.cwd(), X.source)).some((X) => E.startsWith(X + kt)) || !E.endsWith(`${kt}CLAUDE.md`) || !mt(V(E))) {
3618
- g.statusCode = 403, g.end("invalid claude-md target");
3619
- return;
3620
- }
3621
- await nt(E, I), pt(k.get(E) ?? ""), g.statusCode = 204, g.end();
3622
- } catch (U) {
3623
- g.statusCode = 400, g.end(String(U));
3624
- }
3625
- });
3626
- return;
3627
- }
3628
- if (P === "/__nimpress/schema-defaults" && u.method === "PUT") {
3629
- const F = [];
3630
- u.on("data", (U) => F.push(U)), u.on("end", async () => {
3631
- try {
3632
- const U = JSON.parse(Buffer.concat(F).toString("utf-8")), C = String(U.path ?? ""), I = q(process.cwd(), C), E = I.endsWith(`${kt}schema.json`) || I.endsWith(`${kt}schema.yml`);
3633
- if (!I.startsWith(n + kt) || !E || !mt(I)) {
3634
- g.statusCode = 403, g.end("invalid schema target");
3635
- return;
3636
- }
3637
- const B = I.endsWith(".yml") ? "yml" : "json", z = Gt(await rt(I, "utf-8"), B);
3638
- for (const [X, O] of Object.entries(U.defaults ?? {})) {
3639
- const R = z.properties?.[X];
3640
- R && (R.default = O);
3641
- }
3642
- await nt(I, Ut(z, B)), pt(k.get(I) ?? ""), g.statusCode = 204, g.end();
3643
- } catch (U) {
3644
- g.statusCode = 400, g.end(String(U));
3645
- }
3646
- });
3647
- return;
3648
- }
3649
- const M = $t.get(P);
3650
- if (M !== void 0) {
3651
- g.setHeader("Content-Type", "application/rss+xml; charset=utf-8"), g.end(M);
3652
- return;
3653
- }
3654
- if (P === "/subscribe.map.json") {
3655
- g.setHeader("Content-Type", "application/json; charset=utf-8"), g.end(fe);
3656
- return;
3657
- }
3658
- const $ = t.modules.route.replace(/\/$/, "");
3659
- if (P === $ || P.startsWith($ + "/")) {
3660
- const F = P.slice($.length).replace(/^\/+/, ""), U = decodeURIComponent(F.split("/")[0] ?? "");
3661
- if (!t.modules.systems[U]) {
3662
- g.statusCode = 404, g.end(`unknown module system: ${U}`);
3663
- return;
3664
- }
3665
- const I = as(
3666
- {
3667
- host: "127.0.0.1",
3668
- port: Ae(t.modules, U),
3669
- path: `${P}${(u.url ?? "").includes("?") ? `?${(u.url ?? "").split("?").slice(1).join("?")}` : ""}`,
3670
- method: u.method,
3671
- headers: u.headers
3672
- },
3673
- (E) => {
3674
- g.writeHead(E.statusCode ?? 502, E.headers), E.pipe(g);
3675
- }
3676
- );
3677
- I.on("error", () => {
3678
- g.statusCode = 503, g.setHeader("Content-Type", "text/html"), g.end(
3679
- `<!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>`
3680
- );
3681
- }), u.pipe(I);
3682
- return;
3683
- }
3684
- if (w === "/" || P === w || P.startsWith(w + "/")) {
3685
- const F = w === "/" ? P : P.slice(w.length);
3686
- if (y(s, F.replace(/^\/+/, ""), g)) return;
3687
- }
3688
- y(n, P.replace(/^\/+/, ""), g) || x();
3689
- }), () => {
3690
- o.middlewares.use(async (u, g, x) => {
3691
- if (u.method !== "GET" && u.method !== "HEAD" || !(u.headers.accept ?? "").includes("text/html")) return x();
3692
- try {
3693
- const b = await o.transformIndexHtml(
3694
- u.url ?? "/",
3695
- lr(t, "/@id/__x00__virtual:nimpress/main")
3696
- );
3697
- g.statusCode = 200, g.setHeader("Content-Type", "text/html"), g.end(b);
3698
- } catch (b) {
3699
- x(b);
3700
- }
3701
- });
3702
- };
3703
- },
3704
- async handleHotUpdate(o) {
3705
- const l = o.file, a = l.endsWith(".md") && l.startsWith(n), h = l.endsWith(".css") && l.startsWith(n), w = l.match(/\.story\.tsx?$/) && l.startsWith(n), y = m.get(l), u = k.get(l);
3706
- if (h) {
3707
- pt(l.replace(/\.css$/, ".md"));
3708
- try {
3709
- await it();
3710
- } catch (x) {
3711
- o.server.config.logger.error(String(x));
3712
- return;
3713
- }
3714
- return Xt(o.server), o.server.ws.send({ type: "full-reload" }), [];
3715
- }
3716
- if (!a && !w && !y && !u) return;
3717
- const g = a ? l : w ? W(V(l), "index.md") : y ?? u;
3718
- pt(g);
3719
- try {
3720
- await it();
3721
- } catch (x) {
3722
- o.server.config.logger.error(String(x));
3723
- return;
3724
- }
3725
- return Xt(o.server), ge(o.server), Tt(), o.server.ws.send({ type: "full-reload" }), [];
3726
- },
3727
- resolveId(o) {
3728
- return o === Kt ? "\0" + Kt : o === Zt ? "\0" + Zt : o === Qt ? "\0" + Qt : o === te ? "\0" + te : o === we ? "\0" + we : o === $e ? "\0" + $e : o.startsWith(Nt) && o.endsWith(".svelte") || o.startsWith(Mt) && o.endsWith(".js") ? o : null;
3729
- },
3730
- async load(o) {
3731
- if (o === "\0" + Kt)
3732
- return `export default ${JSON.stringify(Zn())}`;
3733
- if (o === "\0" + we)
3734
- return `export default ${JSON.stringify(Ls(t))}`;
3735
- if (o === "\0" + $e) {
3736
- const l = t.css.map((y) => `import ${JSON.stringify(y.startsWith("/") ? y : "/" + y)}`).join(`
3737
- `), a = t.client ? t.client.startsWith("/") ? t.client : "/" + t.client.replace(/^\.\//, "") : null, h = a ? `import { authFunctions, subscribeFunctions } from ${JSON.stringify(a)}` : "";
3738
- return `import '@nimtech/nimpress/app.css'
3739
- ${l}
3740
- import { createNimpressApp } from '@nimtech/nimpress'
3741
- import config from 'virtual:nimpress/config'
3742
- import manifest from 'virtual:nimpress/manifest'
3743
- import searchIndex from 'virtual:nimpress/search'
3744
- import pages from 'virtual:nimpress/pages'
3745
- ${h}
3746
- const app = createNimpressApp({ ...config, manifest, searchIndex, pageLoader: pages${a ? ", authFunctions, subscribeFunctions" : ""} })
3747
- const target = document.getElementById('app')
3748
- if (!target) throw new Error('Mount target #app missing')
3749
- app.mount(target)
3750
- `;
3751
- }
3752
- if (o === "\0" + Zt)
3753
- return `export default ${JSON.stringify(Ve())}`;
3754
- if (o === "\0" + Qt)
3755
- return es();
3756
- if (o === "\0" + te)
3757
- return ns();
3758
- if (o.startsWith(Nt) && o.endsWith(".svelte")) {
3759
- const l = o.slice(Nt.length, -7);
3760
- return os(Ye(l));
3761
- }
3762
- if (o.startsWith(Mt) && o.endsWith(".js")) {
3763
- const l = o.slice(Mt.length, -3);
3764
- return ss(Ye(l));
3765
- }
3766
- return null;
3767
- }
3768
- };
3769
- }
3770
- function ii(e) {
3771
- return e;
3772
- }
3773
- async function ai(e, t) {
3774
- const n = q(e, t), s = await Ue(n), r = [];
3775
- for (const i of s) {
3776
- let c;
3777
- try {
3778
- c = await rt(i, "utf-8");
3779
- } catch {
3780
- continue;
3781
- }
3782
- const { data: p, content: v } = _e(c);
3783
- for (const d of Fn(p, v))
3784
- r.push(`${jt(n, i).split(kt).join("/")}: ${d}`);
3785
- }
3786
- return r;
3787
- }
3788
- export {
3789
- No as a,
3790
- Re as b,
3791
- Be as c,
3792
- Rt as d,
3793
- ln as e,
3794
- un as f,
3795
- Tt as g,
3796
- oi as h,
3797
- lr as i,
3798
- ri as j,
3799
- Ae as k,
3800
- ai as l,
3801
- Dn as m,
3802
- si as n,
3803
- ei as o,
3804
- Gt as p,
3805
- _o as q,
3806
- pe as r,
3807
- zt as s,
3808
- ti as t,
3809
- ni as u,
3810
- qo as v,
3811
- Le as w,
3812
- Ws as x,
3813
- Ar as y,
3814
- ii as z
3815
- };