typerighter 0.43.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/{app-DjpuKzvd.js → app-Cs3OppHS.js} +1 -1
  2. package/dist/{cli-DKDYNRYe.js → cli-BcvGlMzh.js} +5 -5
  3. package/dist/cli.js +1 -1
  4. package/dist/client/theme-default.js +154 -154
  5. package/dist/client.js +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/{init-sdwwozr2.js → init-DCe3DWKz.js} +2 -2
  8. package/dist/{jsonld-Crj_9xpa.js → jsonld-DZsAYYxx.js} +2 -2
  9. package/dist/node/build/index.d.ts.map +1 -1
  10. package/dist/node/lib/codegen/app-entry.d.ts +1 -1
  11. package/dist/node/lib/codegen/app-entry.d.ts.map +1 -1
  12. package/dist/node/lib/codegen/index.d.ts +0 -1
  13. package/dist/node/lib/codegen/index.d.ts.map +1 -1
  14. package/dist/node/lib/codegen/theme.d.ts +1 -0
  15. package/dist/node/lib/codegen/theme.d.ts.map +1 -1
  16. package/dist/node/lib/codegen/theme.test.d.ts +2 -0
  17. package/dist/node/lib/codegen/theme.test.d.ts.map +1 -0
  18. package/dist/node/lib/components.d.ts +14 -0
  19. package/dist/node/lib/components.d.ts.map +1 -0
  20. package/dist/node/lib/{htmlTemplate.d.ts → html-template.d.ts} +1 -1
  21. package/dist/node/lib/html-template.d.ts.map +1 -0
  22. package/dist/node/plugin/vite/index.d.ts.map +1 -1
  23. package/dist/node/plugin/vite/subplugins/component-contract.d.ts +4 -0
  24. package/dist/node/plugin/vite/subplugins/component-contract.d.ts.map +1 -0
  25. package/dist/node/plugin/vite/virtual/app.d.ts.map +1 -1
  26. package/dist/prerenderWorker.js +2 -2
  27. package/dist/{renderMath-C2Z7HdfG.js → renderMath-BAZXLnOu.js} +1 -1
  28. package/dist/rolldown-runtime-CEFd7nDs.js +30 -0
  29. package/dist/shared/types/index.d.ts +1 -0
  30. package/dist/shared/types/index.d.ts.map +1 -1
  31. package/dist/shared/types/json-schema.d.ts +24 -0
  32. package/dist/shared/types/json-schema.d.ts.map +1 -0
  33. package/dist/{shared-QuBFygxT.js → shared-kjMIXu1H.js} +114 -102
  34. package/dist/shared.js +1 -1
  35. package/dist/vite-DrX11EH5.js +127331 -0
  36. package/dist/vite.js +1 -1
  37. package/package.json +3 -3
  38. package/dist/node/lib/codegen/components.d.ts +0 -7
  39. package/dist/node/lib/codegen/components.d.ts.map +0 -1
  40. package/dist/node/lib/htmlTemplate.d.ts.map +0 -1
  41. package/dist/rolldown-runtime-B0aSnxlc.js +0 -20
  42. package/dist/vite-Cj1Ofykq.js +0 -1531
@@ -1,1531 +0,0 @@
1
- import { D as e, E as t, F as n, G as r, H as i, J as a, L as o, P as s, Q as c, R as l, V as u, Y as d, Z as f, _ as p, b as m, c as h, d as g, g as _, h as v, i as y, p as b, v as x, w as S, y as C, z as w } from "./shared-QuBFygxT.js";
2
- import { a as T, i as E, n as D, o as O, r as k, s as ee, t as te } from "./jsonld-Crj_9xpa.js";
3
- import { t as ne } from "./temml-D47Z4xZ2.js";
4
- import { a as re, i as ie, n as ae, r as oe } from "./context-CSvoDxVt.js";
5
- import { t as se } from "./es-ClqUVRJn.js";
6
- import A, { resolve as j } from "node:path";
7
- import M from "picocolors";
8
- import ce from "@tailwindcss/vite";
9
- import le from "@vitejs/plugin-vue";
10
- import { build as ue, normalizePath as de } from "vite";
11
- import N, { readdir as fe } from "node:fs/promises";
12
- import { fileURLToPath as pe } from "node:url";
13
- import me from "node:os";
14
- import { Worker as he } from "node:worker_threads";
15
- import { createHighlighter as ge, guessEmbeddedLanguages as _e, isSpecialLang as ve } from "shiki";
16
- import { createReadStream as ye, existsSync as be, globSync as P, readFileSync as xe, statSync as Se } from "node:fs";
17
- import { createRequire as Ce } from "node:module";
18
- //#region src/node/lib/worker-pool/index.ts
19
- var we = class {
20
- workers = [];
21
- queue = [];
22
- destroyed = !1;
23
- startupError;
24
- constructor(e) {
25
- let t = e.concurrency ?? Math.max(1, Math.floor(me.cpus().length / 2));
26
- for (let n = 0; n < t; n++) {
27
- let t = new he(e.filename, { workerData: e.workerData }), n = { worker: t };
28
- this.workers.push(n), t.on("message", (e) => {
29
- let t = n.pending;
30
- n.pending = void 0, e.error === void 0 ? t?.resolve(e.result) : t?.reject(Error(e.error)), this.dispatch(n);
31
- }), t.on("error", (e) => {
32
- let t = n.pending;
33
- n.pending = void 0, t?.reject(e), this.destroyAll(e);
34
- });
35
- }
36
- }
37
- run(e) {
38
- return this.destroyed ? Promise.reject(this.startupError ?? /* @__PURE__ */ Error("Worker pool is destroyed")) : new Promise((t, n) => {
39
- let r = {
40
- task: e,
41
- resolve: t,
42
- reject: n
43
- }, i = this.workers.find((e) => e.pending === void 0);
44
- i ? (i.pending = r, i.worker.postMessage(r.task)) : this.queue.push(r);
45
- });
46
- }
47
- async destroy() {
48
- this.destroyed = !0, this.rejectAll(/* @__PURE__ */ Error("Worker pool is destroyed")), await Promise.all(this.workers.map((e) => e.worker.terminate()));
49
- }
50
- dispatch(e) {
51
- let t = this.queue.shift();
52
- t !== void 0 && (e.pending = t, e.worker.postMessage(t.task));
53
- }
54
- rejectAll(e) {
55
- for (let t of this.queue) t.reject(e);
56
- this.queue.length = 0;
57
- for (let t of this.workers) t.pending &&= (t.pending.reject(e), void 0);
58
- }
59
- destroyAll(e) {
60
- this.destroyed || (this.startupError = e instanceof Error ? e : Error(String(e)), this.destroyed = !0, this.rejectAll(e), Promise.all(this.workers.map((e) => e.worker.terminate())).catch(() => {}));
61
- }
62
- };
63
- //#endregion
64
- //#region src/node/build/seo/sitemap.ts
65
- function Te(e, t, n, r) {
66
- let i = n ?? "";
67
- return `<?xml version="1.0" encoding="UTF-8"?>
68
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
69
- ${e.map((e) => {
70
- let n = h(i + t + s(e)), a = r?.get(e);
71
- return ` <url><loc>${n}</loc>${a === void 0 ? "" : `<lastmod>${y(a)}</lastmod>`}</url>`;
72
- }).join("\n")}
73
- </urlset>
74
- `;
75
- }
76
- function Ee(e, t) {
77
- return `User-agent: *
78
- Allow: /
79
-
80
- Sitemap: ${e}${t}sitemap.xml
81
- `;
82
- }
83
- //#endregion
84
- //#region src/node/build/seo/feed.ts
85
- function De(e, t, n, r, i, a) {
86
- let o = [...e].filter((e) => e.fileMetadata.mtime > 0).sort((e, t) => t.fileMetadata.mtime - e.fileMetadata.mtime).slice(0, 50).map((e) => {
87
- let r = u(e.filepath), i = `${n}${t}${r}`, a = new Date(e.fileMetadata.mtime).toUTCString(), o = h(e.label ?? r), s = e.excerpt === void 0 ? "" : `<![CDATA[${e.excerpt}]]>`;
88
- return ` <item>
89
- <title>${o}</title>
90
- <link>${h(i)}</link>
91
- <guid>${h(i)}</guid>
92
- <pubDate>${a}</pubDate>
93
- <description>${s}</description>
94
- </item>`;
95
- }).join("\n");
96
- return `<?xml version="1.0" encoding="UTF-8"?>
97
- <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
98
- <channel>
99
- <title>${h(r)}</title>
100
- <link>${h(n + t)}</link>
101
- <description>${h(i)}</description>
102
- <language>${a}</language>
103
- <atom:link href="${h(n + t)}feed.xml" rel="self" type="application/rss+xml"/>
104
- ${o}
105
- </channel>
106
- </rss>
107
- `;
108
- }
109
- //#endregion
110
- //#region src/node/build/fonts.ts
111
- function Oe(e) {
112
- let t = A.basename(e);
113
- return t.endsWith(".woff2") && t.includes("-latin-") && !t.includes("-latin-ext-");
114
- }
115
- //#endregion
116
- //#region src/node/build/prerender.ts
117
- var ke = 64;
118
- async function Ae(e) {
119
- let { clientEntry: t, cssFiles: n, fontFiles: r } = await Ne(e.clientOutDir), i = [n.map((t) => ` <link rel="stylesheet" href="${e.base}${t}">`).join("\n"), r.map((t) => ` <link rel="preload" as="font" type="font/woff2" crossorigin href="${e.base}${t}">`).join("\n")].filter(Boolean).join("\n") || void 0;
120
- e.pagePaths.length >= ke ? await je(e, t, i) : await Me(e, t, i);
121
- }
122
- async function je(e, t, n) {
123
- let r = new we({
124
- filename: A.resolve(pe(import.meta.url), "../prerenderWorker.js"),
125
- workerData: {
126
- ssrEntryPath: e.ssrEntryPath,
127
- base: e.base,
128
- origin: e.origin,
129
- lang: e.lang,
130
- siteTitle: e.siteTitle,
131
- author: e.author,
132
- clientEntry: t,
133
- headExtra: n
134
- }
135
- }), i = 0, a = e.pagePaths.length;
136
- try {
137
- await Promise.all(e.pagePaths.map(async (t) => {
138
- let n = await r.run(t), o = A.join(e.outDir, n.fileName);
139
- await N.mkdir(A.dirname(o), { recursive: !0 }), await N.writeFile(o, n.html), i++, e.progress?.update(i, a);
140
- }));
141
- } finally {
142
- await r.destroy();
143
- }
144
- }
145
- async function Me(e, t, n) {
146
- let r = await (await import(e.ssrEntryPath)).createRenderer(), i = e.pagePaths.length, a = 0;
147
- for (let o of e.pagePaths) {
148
- let c = await r(o), l = O(c.pageData), u = T(c.pageData), d = k(c.pageData), f = e.base + s(o), p = [te({
149
- title: l,
150
- description: u,
151
- canonicalUrl: f,
152
- author: e.author,
153
- dateModified: d
154
- }), D(o, l)].filter((e) => e !== void 0), m = ee({
155
- title: l,
156
- description: u,
157
- siteTitle: e.siteTitle,
158
- author: e.author,
159
- base: e.base,
160
- origin: e.origin,
161
- lang: e.lang,
162
- entryScript: t,
163
- canonicalUrl: f,
164
- ogImagePath: E(c.pageData),
165
- jsonLdBlocks: p,
166
- headExtra: n,
167
- appContent: c.html
168
- }), h = o === "/" ? "index.html" : `${s(o)}.html`, g = A.join(e.outDir, h);
169
- await N.mkdir(A.dirname(g), { recursive: !0 }), await N.writeFile(g, m), a++, e.progress?.update(a, i);
170
- }
171
- }
172
- async function Ne(e) {
173
- let t = A.join(e, ".vite", "manifest.json"), n = await N.readFile(t, "utf-8"), r = JSON.parse(n), i = "", a = [], o = [];
174
- for (let e of Object.values(r)) e.isEntry ? (i = e.file, e.css && a.push(...e.css)) : Oe(e.file) && o.push(e.file);
175
- return {
176
- clientEntry: i,
177
- cssFiles: a,
178
- fontFiles: o
179
- };
180
- }
181
- //#endregion
182
- //#region src/node/lib/codegen/app-entry.ts
183
- function F(e, t) {
184
- let { rootDir: n = ".", userComponents: r = [] } = e, i = r.map((e) => `import ${e.name} from ${JSON.stringify(e.absolutePath)};`).join("\n"), o = r.map((e) => `app.component(${JSON.stringify(e.name)}, ${e.name});`).join("\n"), s = JSON.stringify({
185
- title: e.siteTitle,
186
- description: e.siteDescription,
187
- basePath: e.basePath ?? "/",
188
- origin: e.origin,
189
- lang: e.lang,
190
- repo: e.repo,
191
- author: e.author,
192
- license: e.license,
193
- rootDir: n,
194
- nav: e.nav
195
- });
196
- return `
197
- ${[i, "import 'typerighter/style.css';"].filter(Boolean).join("\n")}
198
- import 'typerighter/fonts.css';
199
- import('typerighter/math.css');
200
- import { createTypedownApp } from 'typerighter/client';
201
- import { TdDirectoryIndex, TdGlossaryIndex } from 'typerighter/client/theme-default';
202
- import { isIndexUrl, getDirectoryFromPageUrl, getParentUrl, path } from 'typerighter/shared';
203
- import { h } from 'vue';
204
- import theme from '${t.theme}';
205
- import { pages as initialPages } from '${t.pages}';
206
- import initialSiteData from '${t.siteData}';
207
- let pages = initialPages;
208
- const contentExts = ${JSON.stringify(a)};
209
-
210
- function findPage(base) {
211
- for (const ext of contentExts) {
212
- const key = base + ext;
213
- if (pages[key]) return pages[key];
214
- }
215
- }
216
-
217
- async function loadPageModule(pagePath) {
218
- const loader = findPage(path.join('/', '${n}', pagePath));
219
- if (loader) return loader();
220
-
221
- if (isIndexUrl(pagePath)) {
222
- const dirPath = getDirectoryFromPageUrl(pagePath);
223
- const dir = siteData.value.directoryListings[dirPath];
224
- if (dir) return {
225
- default: { name: 'DirectoryIndex', render() { return h(TdDirectoryIndex); } },
226
- pageData: { frontmatter: {}, headings: [], title: dir.title },
227
- };
228
- }
229
-
230
- return undefined;
231
- }
232
-
233
- const { app, router, searchIndex: searchIndexRef, siteData } = await createTypedownApp(loadPageModule, theme, ${s}, initialSiteData);
234
- ${o}
235
- app.mount('#app');
236
-
237
- // Load search index in the background after the app is mounted
238
- import('${t.searchIndex}').then((m) => { searchIndexRef.value = m.default; });
239
-
240
- // Accept HMR so modules update without a full page reload
241
- if (import.meta.hot) {
242
- import.meta.hot.accept('${t.pages}', (m) => {
243
- if (!m) return;
244
- const base = path.join('/', '${n}', router.route.path);
245
- const hadPage = !!findPage(base);
246
- pages = m.pages;
247
- const hasPage = !!findPage(base);
248
- // Current page was removed (deleted or renamed away)
249
- if (hadPage && !hasPage) router.go(getParentUrl(router.route.path));
250
- // A real page appeared where a directory index was shown
251
- if (!hadPage && hasPage) router.go(router.route.path);
252
- });
253
-
254
- import.meta.hot.accept('${t.searchIndex}', (m) => {
255
- if (m) searchIndexRef.value = m.default;
256
- });
257
-
258
- import.meta.hot.accept('${t.siteData}', (m) => {
259
- if (m) siteData.value = m.default;
260
- });
261
-
262
- // Update route.data directly when content changes - Vue SFC setup only re-runs on script block changes
263
- import.meta.hot.on('${t.pageDataEvent}', ({ filepath, pageData }) => {
264
- const eventBase = path.join('/', '${n}', path.stripExtension(filepath));
265
- const routeBase = path.join('/', '${n}', router.route.path);
266
- if (eventBase === routeBase) {
267
- router.route.data = pageData;
268
- }
269
- });
270
- }
271
- `;
272
- }
273
- //#endregion
274
- //#region src/node/lib/codegen/theme.ts
275
- var I = "typerighter/client/theme-default";
276
- function Pe(e, t) {
277
- if (e?.component) {
278
- let n = t ? A.resolve(t, e.component) : e.component;
279
- return [`import CustomLayout from ${JSON.stringify(n)};`, "export default { Layout: CustomLayout };"].join("\n");
280
- }
281
- let n = Object.entries(e?.slots ?? {});
282
- if (0 < n.length) {
283
- let e = n.map(([e, t]) => `${JSON.stringify(r(e))}: () => h(resolveComponent(${JSON.stringify(t)}))`).join(", ");
284
- return [
285
- `import DefaultTheme from ${JSON.stringify(I)};`,
286
- "import { h, resolveComponent } from 'vue';",
287
- `export default { Layout: { render() { return h(DefaultTheme.Layout, null, { ${e} }); } } };`
288
- ].join("\n");
289
- }
290
- return `export { default } from ${JSON.stringify(I)};`;
291
- }
292
- //#endregion
293
- //#region src/node/lib/codegen/components.ts
294
- async function Fe(e, t) {
295
- let n = [];
296
- for (let r of e) if (r.kind === "dir") {
297
- let e = A.resolve(t, r.path), i;
298
- try {
299
- i = await fe(e);
300
- } catch {
301
- continue;
302
- }
303
- for (let t of i) {
304
- if (!t.endsWith(".vue")) continue;
305
- let r = t.slice(0, -4);
306
- n.push({
307
- name: r,
308
- absolutePath: A.join(e, t)
309
- });
310
- }
311
- } else n.push({
312
- name: r.name,
313
- absolutePath: A.resolve(t, r.source)
314
- });
315
- return n;
316
- }
317
- //#endregion
318
- //#region src/node/lib/progress.ts
319
- var L = [
320
- "◐",
321
- "◓",
322
- "◑",
323
- "◒"
324
- ], R = class {
325
- logger;
326
- label;
327
- start;
328
- spinnerInterval;
329
- constructor(e, t) {
330
- if (this.logger = e, this.label = t, this.start = performance.now(), process.stdout.isTTY) {
331
- let e = 0;
332
- process.stdout.write(M.cyan(`${L[0]} ${t}`)), this.spinnerInterval = setInterval(() => {
333
- e = (e + 1) % L.length, process.stdout.write(`\r${M.cyan(`${L[e]} ${this.label}`)}`);
334
- }, 120).unref();
335
- } else this.logger.start(t);
336
- }
337
- update(e, t) {
338
- if (!process.stdout.isTTY) return;
339
- let n = Math.round(e / t * 100);
340
- this.stopSpinner(), process.stdout.write(`\r ${this.label} ${e}/${t} (${n}%)`);
341
- }
342
- done(e) {
343
- this.stopSpinner(), process.stdout.isTTY && process.stdout.write("\r\x1B[K");
344
- let t = Math.round(performance.now() - this.start);
345
- this.logger.success(`${e} (${Ie(t)})`);
346
- }
347
- stopSpinner() {
348
- this.spinnerInterval &&= (clearInterval(this.spinnerInterval), void 0);
349
- }
350
- };
351
- function Ie(e) {
352
- return e < 1e3 ? `${Math.round(e)}ms` : `${(e / 1e3).toFixed(1)}s`;
353
- }
354
- //#endregion
355
- //#region src/node/build/index.ts
356
- async function Le(e, t = {}) {
357
- let { root: n, logger: r } = e, i = A.resolve(n, t.outDir ?? "dist"), a = A.join(i, ".client"), o = A.join(i, ".server");
358
- await N.rm(i, {
359
- recursive: !0,
360
- force: !0
361
- });
362
- let s = await e.getTdContext(), [c, l, d] = await Promise.all([
363
- s.getConfig(),
364
- s.listFiles(),
365
- s.listSidebar()
366
- ]), f = c.origin ?? void 0, p = c.author ?? void 0, m = c.license ?? void 0, h = c.repo ?? void 0, g = t.base ?? c.basePath ?? "/", _ = g.endsWith("/") ? g : g + "/", y = d.map((e) => ({
367
- ...e,
368
- header: {}
369
- })), b = v(y), x = JSON.stringify({
370
- title: c.siteTitle,
371
- description: c.siteDescription,
372
- basePath: _,
373
- origin: f,
374
- lang: c.lang,
375
- rootDir: c.rootDir,
376
- repo: h,
377
- author: p,
378
- license: m,
379
- nav: c.nav
380
- }), S = JSON.stringify({
381
- ready: !0,
382
- contentTree: b
383
- }), C = A.join(n, "node_modules", ".typerighter");
384
- await N.mkdir(C, { recursive: !0 });
385
- let w = A.join(C, "client-entry.js"), T = A.join(C, "ssr-entry.js"), E = A.join(C, "theme.js"), D = await Fe(c.components, n), O = Pe(c.layout ?? void 0, n);
386
- await Promise.all([
387
- N.writeFile(w, F({
388
- rootDir: c.rootDir,
389
- basePath: _,
390
- origin: f,
391
- lang: c.lang,
392
- siteTitle: c.siteTitle,
393
- siteDescription: c.siteDescription,
394
- repo: h,
395
- author: p,
396
- license: m,
397
- nav: c.nav,
398
- userComponents: D
399
- }, {
400
- theme: X,
401
- pages: K,
402
- siteData: J,
403
- searchIndex: Y,
404
- pageDataEvent: Z
405
- })),
406
- N.writeFile(T, Re({
407
- rootDir: c.rootDir,
408
- siteConfig: x,
409
- siteData: S,
410
- userComponents: D
411
- })),
412
- N.writeFile(E, O)
413
- ]);
414
- try {
415
- let s = $t({ context: e }), m = e.createViteLogger(), h = new R(r, "Building client bundle...");
416
- await ue({
417
- ...t.viteConfig,
418
- root: n,
419
- base: _,
420
- plugins: s,
421
- customLogger: m,
422
- logLevel: "silent",
423
- build: {
424
- ...t.viteConfig?.build,
425
- outDir: a,
426
- manifest: !0,
427
- emptyOutDir: !0,
428
- rollupOptions: {
429
- ...t.viteConfig?.build?.rollupOptions,
430
- input: w
431
- }
432
- }
433
- });
434
- let g = await N.readdir(A.join(a, "assets")).catch(() => []);
435
- h.done(`Client bundle (${g.length} chunks)`);
436
- let v = new R(r, "Building SSR bundle...");
437
- await ue({
438
- ...t.viteConfig,
439
- root: n,
440
- base: _,
441
- plugins: s,
442
- customLogger: m,
443
- logLevel: "silent",
444
- build: {
445
- ...t.viteConfig?.build,
446
- outDir: o,
447
- ssr: T,
448
- emptyOutDir: !0
449
- }
450
- }), v.done("SSR bundle");
451
- let y = l.map((e) => {
452
- let t = u(e);
453
- return t === "index" ? "/" : `/${t}`;
454
- });
455
- y.push("/"), Be(b.entries, "", y);
456
- let x = new R(r, "Pre-rendering pages...");
457
- await Ae({
458
- ssrEntryPath: A.join(o, "ssr-entry.js"),
459
- clientOutDir: a,
460
- outDir: i,
461
- base: _,
462
- origin: f,
463
- lang: c.lang,
464
- pagePaths: y,
465
- siteTitle: c.siteTitle,
466
- author: p,
467
- progress: x
468
- }), x.done(`Pre-rendered ${y.length} pages`);
469
- let S = /* @__PURE__ */ new Map();
470
- for (let e of d) {
471
- let t = u(e.filepath), n = t === "index" ? "/" : `/${t}`;
472
- S.set(n, e.fileMetadata.mtime);
473
- }
474
- let C = Te(y, _, f, S), E = [N.writeFile(A.join(i, "sitemap.xml"), C)];
475
- f !== void 0 && (E.push(N.writeFile(A.join(i, "robots.txt"), Ee(f, _))), E.push(N.writeFile(A.join(i, "feed.xml"), De(d, _, f, c.siteTitle, c.siteDescription, c.lang)))), await Promise.all(E);
476
- let D = A.join(a, "assets"), O = A.join(i, "assets");
477
- await N.cp(D, O, { recursive: !0 }).catch(() => {}), await ze(A.join(n, c.rootDir), i);
478
- let k = A.join(n, c.publicDir);
479
- await N.cp(k, i, { recursive: !0 }).catch(() => {});
480
- } finally {
481
- await Promise.all([
482
- N.rm(C, {
483
- recursive: !0,
484
- force: !0
485
- }),
486
- N.rm(a, {
487
- recursive: !0,
488
- force: !0
489
- }),
490
- N.rm(o, {
491
- recursive: !0,
492
- force: !0
493
- })
494
- ]);
495
- }
496
- r.log(`\nBuild complete. Output: ${i}`);
497
- }
498
- function Re(e) {
499
- let t = `/${e.rootDir}/${d}`, n = JSON.parse(e.siteConfig), r = JSON.parse(e.siteData), i = r.contentTree ?? { entries: [] }, o = _(i.entries ?? [], n.title ?? ""), s = JSON.stringify({
500
- ...r,
501
- directoryListings: o
502
- }), c = e.userComponents ?? [], l = c.map((e) => `import ${e.name} from ${JSON.stringify(e.absolutePath)};`).join("\n"), u = c.map((e) => `app.component(${JSON.stringify(e.name)}, ${e.name});`).join("\n");
503
- return `
504
- ${[l, "import { createTypedownApp } from 'typerighter/client';"].filter(Boolean).join("\n")}
505
- import { TdDirectoryIndex, TdGlossaryIndex } from 'typerighter/client/theme-default';
506
- import { isIndexUrl, getDirectoryFromPageUrl } from 'typerighter/shared';
507
- import { renderToString } from 'vue/server-renderer';
508
- import { h } from 'vue';
509
- import theme from './theme.js';
510
-
511
- const pages = import.meta.glob('${t}', { eager: true });
512
- const contentExts = ${JSON.stringify(a)};
513
- const siteData = ${s};
514
-
515
- function findPage(base) {
516
- for (const ext of contentExts) {
517
- const key = base + ext;
518
- if (pages[key]) return pages[key];
519
- }
520
- }
521
-
522
- function loadPageModule(pagePath) {
523
- const base = ('/${e.rootDir}/' + pagePath).replace(/\\/+/g, '/').replace(/\\/$/, '');
524
- const page = findPage(base);
525
- if (page) return Promise.resolve(page);
526
-
527
- if (isIndexUrl(pagePath)) {
528
- const dirPath = getDirectoryFromPageUrl(pagePath);
529
- const dir = siteData.directoryListings[dirPath];
530
- if (dir) return Promise.resolve({
531
- default: { name: 'DirectoryIndex', render() { return h(TdDirectoryIndex); } },
532
- pageData: { frontmatter: {}, headings: [], title: dir.title },
533
- });
534
- }
535
-
536
- return Promise.resolve(undefined);
537
- }
538
-
539
- export async function createRenderer() {
540
- const { app, router } = await createTypedownApp(loadPageModule, theme, ${e.siteConfig}, siteData);
541
- ${u}
542
- return async function render(url) {
543
- await router.go(url, { replace: true });
544
- const html = await renderToString(app);
545
- return { html, pageData: router.route.data };
546
- };
547
- }
548
- `;
549
- }
550
- async function ze(e, t) {
551
- let n = (await N.readdir(e, {
552
- recursive: !0,
553
- withFileTypes: !0
554
- })).filter((e) => e.isFile() && !l(e.name)).map(async (n) => {
555
- let r = A.join(n.parentPath, n.name), i = A.relative(e, r), a = A.join(t, i);
556
- return N.mkdir(A.dirname(a), { recursive: !0 }).then(() => N.copyFile(r, a));
557
- });
558
- await Promise.all(n);
559
- }
560
- function Be(e, t, n) {
561
- for (let r of e) {
562
- if (r.kind !== "dir") continue;
563
- let e = `${t}/${r.node.name}`;
564
- p(r.node) || n.push(S(e)), Be(r.node.entries, e, n);
565
- }
566
- }
567
- //#endregion
568
- //#region ../../node_modules/.pnpm/@shikijs+transformers@4.4.3/node_modules/@shikijs/transformers/dist/index.mjs
569
- var Ve = /(\s+\/\/)/, He = /(?:\/\/|["'#]|;{1,2}|%{1,2}|--)(\s*)$/, Ue = /(?:\/\/|#|;{1,2}|%{1,2}|--)(\s*)$/, We = [
570
- [/^(<!--)(.+)(-->)$/, !1],
571
- [/^(\/\*)(.+)(\*\/)$/, !1],
572
- [/^(\/\/|["'#]|;{1,2}|%{1,2}|--)(.*)$/, !0],
573
- [/^(\*)(.+)$/, !0]
574
- ];
575
- function Ge(e, t, n) {
576
- let r = [];
577
- for (let i of e) {
578
- if (n === "v3") {
579
- let e = i.children.flatMap((e, t) => {
580
- if (e.type !== "element") return e;
581
- let n = e.children[0];
582
- if (n.type !== "text") return e;
583
- let r = t === i.children.length - 1;
584
- if (!z(n.value, r)) return e;
585
- let a = n.value.split(Ve);
586
- if (a.length <= 1) return e;
587
- let o = [a[0]];
588
- for (let e = 1; e < a.length; e += 2) o.push(a[e] + (a[e + 1] || ""));
589
- return o = o.filter(Boolean), o.length <= 1 ? e : o.map((t) => ({
590
- ...e,
591
- children: [{
592
- type: "text",
593
- value: t
594
- }]
595
- }));
596
- });
597
- e.length !== i.children.length && (i.children = e);
598
- }
599
- let e = i.children, a = e.length - 1;
600
- n === "v1" ? a = 0 : t && (a = e.length - 2);
601
- for (let n = Math.max(a, 0); n < e.length; n++) {
602
- let a = e[n];
603
- if (a.type !== "element") continue;
604
- let o = a.children.at(0);
605
- if (o?.type !== "text") continue;
606
- let s = n === e.length - 1, c = z(o.value, s), l;
607
- if (!c && n > 0 && o.value.trim().startsWith("[!code")) {
608
- let t = e[n - 1];
609
- if (t?.type === "element") {
610
- let n = t.children.at(0);
611
- if (n?.type === "text" && n.value.includes("//")) {
612
- let l = z(n.value + o.value, s);
613
- if (l) {
614
- c = l, r.push({
615
- info: l,
616
- line: i,
617
- token: t,
618
- isLineCommentOnly: e.length === 2 && t.children.length === 1 && a.children.length === 1,
619
- isJsxStyle: !1,
620
- additionalTokens: [a]
621
- });
622
- continue;
623
- }
624
- }
625
- }
626
- }
627
- if (c) {
628
- if (t && !s && n !== 0) {
629
- let t = Ke(e[n - 1], "{") && Ke(e[n + 1], "}");
630
- r.push({
631
- info: c,
632
- line: i,
633
- token: a,
634
- isLineCommentOnly: e.length === 3 && a.children.length === 1,
635
- isJsxStyle: t,
636
- additionalTokens: l
637
- });
638
- } else r.push({
639
- info: c,
640
- line: i,
641
- token: a,
642
- isLineCommentOnly: e.length === 1 && a.children.length === 1,
643
- isJsxStyle: !1,
644
- additionalTokens: l
645
- });
646
- }
647
- }
648
- }
649
- return r;
650
- }
651
- function Ke(e, t) {
652
- if (e.type !== "element") return !1;
653
- let n = e.children[0];
654
- return n.type === "text" && n.value.trim() === t;
655
- }
656
- function z(e, t) {
657
- let n = e.trimStart(), r = e.length - n.length;
658
- n = n.trimEnd();
659
- let i = e.length - n.length - r;
660
- for (let [e, a] of We) {
661
- if (a && !t) continue;
662
- let o = e.exec(n);
663
- if (o) return [
664
- " ".repeat(r) + o[1],
665
- o[2],
666
- o[3] ? o[3] + " ".repeat(i) : void 0
667
- ];
668
- }
669
- }
670
- function qe(e) {
671
- let t = e.match(He);
672
- return t && t[1].trim().length === 0 ? e.slice(0, t.index) : e;
673
- }
674
- function Je(e) {
675
- let t = e.match(Ue);
676
- return t && t[1].trim().length === 0 ? e.slice(0, t.index).trimEnd() : e;
677
- }
678
- function Ye(e, t, n, r) {
679
- return r ??= "v3", {
680
- name: e,
681
- code(e) {
682
- let i = e.children.filter((e) => e.type === "element"), a = [];
683
- e.data ??= {};
684
- let o = e.data;
685
- o._shiki_notation ??= Ge(i, ["jsx", "tsx"].includes(this.options.lang), r);
686
- let s = o._shiki_notation;
687
- for (let e of s) {
688
- if (e.info[1].length === 0) continue;
689
- let o = i.indexOf(e.line);
690
- e.isLineCommentOnly && r !== "v1" && o++;
691
- let s = !1;
692
- if (e.info[1] = e.info[1].replace(t, (...t) => n.call(this, t, e.line, e.token, i, o) ? (s = !0, "") : t[0]), !s) continue;
693
- r === "v1" ? e.info[1] = qe(e.info[1]) : r === "v3" && (e.info[1] = Je(e.info[1]));
694
- let c = e.info[1].trim().length === 0;
695
- if (c && (e.info[1] = ""), c && e.isLineCommentOnly) a.push(e.line);
696
- else if (c && e.isJsxStyle) e.line.children.splice(e.line.children.indexOf(e.token) - 1, 3);
697
- else if (c) {
698
- if (e.additionalTokens) for (let t = e.additionalTokens.length - 1; t >= 0; t--) {
699
- let n = e.additionalTokens[t], r = e.line.children.indexOf(n);
700
- r !== -1 && e.line.children.splice(r, 1);
701
- }
702
- e.line.children.splice(e.line.children.indexOf(e.token), 1);
703
- } else {
704
- let t = e.token.children[0];
705
- if (t.type === "text" && (t.value = e.info.join(""), e.additionalTokens)) for (let t of e.additionalTokens) {
706
- let e = t.children[0];
707
- e?.type === "text" && (e.value = "");
708
- }
709
- }
710
- }
711
- for (let t of a) {
712
- let n = e.children.indexOf(t), r = e.children[n + 1], i = 1;
713
- r?.type === "text" && r?.value === "\n" && (i = 2), e.children.splice(n, i);
714
- }
715
- }
716
- };
717
- }
718
- var Xe = /\{([\d,-]+)\}/;
719
- function Ze(e) {
720
- if (!e) return null;
721
- let t = e.match(Xe);
722
- return t ? t[1].split(",").flatMap((e) => {
723
- let t = e.split("-").map((e) => Number.parseInt(e, 10));
724
- return t.length === 1 ? [t[0]] : Array.from({ length: t[1] - t[0] + 1 }, (e, n) => t[0] + n);
725
- }) : null;
726
- }
727
- var Qe = Symbol("highlighted-lines");
728
- function $e(e = {}) {
729
- let { className: t = "highlighted", zeroIndexed: n = !1 } = e;
730
- return {
731
- name: "@shikijs/transformers:meta-highlight",
732
- line(e, r) {
733
- if (!this.options.meta?.__raw) return;
734
- let i = this.meta;
735
- i[Qe] ??= Ze(this.options.meta.__raw);
736
- let a = i[Qe] ?? [], o = n ? r - 1 : r;
737
- return a.includes(o) && this.addClassToHast(e, t), e;
738
- }
739
- };
740
- }
741
- var et = /[.*+?^${}()|[\]\\]/g;
742
- function tt(e) {
743
- return e.replace(et, "\\$&");
744
- }
745
- function B(e = {}, t = "@shikijs/transformers:notation-map") {
746
- let { classMap: n = {}, classActivePre: r = void 0, classActiveCode: i = void 0 } = e;
747
- return Ye(t, RegExp(`#?\\s*\\[!code (${Object.keys(n).map(tt).join("|")})(:\\d+)?\\]`, "gi"), function([e, t, a = ":1"], o, s, c, l) {
748
- let u = Number.parseInt(a.slice(1), 10);
749
- for (let e = l; e < Math.min(l + u, c.length); e++) this.addClassToHast(c[e], n[t]);
750
- return r && this.addClassToHast(this.pre, r), i && this.addClassToHast(this.code, i), !0;
751
- }, e.matchAlgorithm);
752
- }
753
- function nt(e = {}) {
754
- let { classLineAdd: t = "diff add", classLineRemove: n = "diff remove", classActivePre: r = "has-diff", classActiveCode: i } = e;
755
- return B({
756
- classMap: {
757
- "++": t,
758
- "--": n
759
- },
760
- classActivePre: r,
761
- classActiveCode: i,
762
- matchAlgorithm: e.matchAlgorithm
763
- }, "@shikijs/transformers:notation-diff");
764
- }
765
- function rt(e = {}) {
766
- let { classMap: t = {
767
- error: ["highlighted", "error"],
768
- warning: ["highlighted", "warning"],
769
- info: ["highlighted", "info"]
770
- }, classActivePre: n = "has-highlighted", classActiveCode: r } = e;
771
- return B({
772
- classMap: t,
773
- classActivePre: n,
774
- classActiveCode: r,
775
- matchAlgorithm: e.matchAlgorithm
776
- }, "@shikijs/transformers:notation-error-level");
777
- }
778
- function it(e = {}) {
779
- let { classActiveLine: t = "focused", classActivePre: n = "has-focused", classActiveCode: r } = e;
780
- return B({
781
- classMap: { focus: t },
782
- classActivePre: n,
783
- classActiveCode: r,
784
- matchAlgorithm: e.matchAlgorithm
785
- }, "@shikijs/transformers:notation-focus");
786
- }
787
- function at(e = {}) {
788
- let { classActiveLine: t = "highlighted", classActivePre: n = "has-highlighted", classActiveCode: r } = e;
789
- return B({
790
- classMap: {
791
- highlight: t,
792
- hl: t
793
- },
794
- classActivePre: n,
795
- classActiveCode: r,
796
- matchAlgorithm: e.matchAlgorithm
797
- }, "@shikijs/transformers:notation-highlight");
798
- }
799
- //#endregion
800
- //#region src/node/lib/render/highlight/language.ts
801
- var ot = [
802
- "shellscript",
803
- "shell",
804
- "bash",
805
- "sh",
806
- "zsh"
807
- ];
808
- function st(e) {
809
- return ot.includes(e);
810
- }
811
- var ct = /^[a-zA-Z0-9-_]+/;
812
- function lt(e) {
813
- return ct.exec(e)?.[0] || "";
814
- }
815
- //#endregion
816
- //#region src/node/lib/render/highlight/index.ts
817
- var ut = new FinalizationRegistry((e) => {
818
- e();
819
- }), V = {
820
- light: "github-light",
821
- dark: "github-dark"
822
- };
823
- async function dt() {
824
- let e = await ge({
825
- themes: [V.light, V.dark],
826
- langs: []
827
- }), t = [
828
- $e(),
829
- nt(),
830
- it({
831
- classActiveLine: "has-focus",
832
- classActivePre: "has-focused-lines"
833
- }),
834
- at(),
835
- rt(),
836
- ft(),
837
- {
838
- name: "typedown:add-dir",
839
- pre(e) {
840
- e.properties.dir = "ltr";
841
- }
842
- }
843
- ], n = new Set(e.getLoadedLanguages());
844
- async function r(r, i, a) {
845
- let o = lt(i);
846
- if (o) {
847
- let e = i;
848
- i = o.toLowerCase(), a = e.slice(i.length).replace(/(?<!=)\{/g, " {") + " " + a, a = a.trim().replace(/\s+/g, " ");
849
- }
850
- i ||= "txt";
851
- try {
852
- !ve(i) && !n.has(i) && (await e.loadLanguage(i), n.add(i));
853
- } catch {
854
- re.warn(`\nThe language '${i}' is not loaded, falling back to 'txt' for syntax highlighting.`), i = "txt";
855
- }
856
- r = r.trimEnd();
857
- let s = _e(r, i, e);
858
- return await e.loadLanguage(...s), e.codeToHtml(r, {
859
- lang: i,
860
- transformers: [...t, {
861
- name: "typedown:empty-line",
862
- code(e) {
863
- e.children.forEach((e) => {
864
- e.type === "element" && e.tagName === "span" && Array.isArray(e.properties.class) && e.properties.class.includes("line") && e.children.length === 0 && e.children.push({
865
- type: "element",
866
- tagName: "wbr",
867
- properties: {},
868
- children: []
869
- });
870
- });
871
- }
872
- }],
873
- meta: { __raw: a },
874
- themes: V,
875
- defaultColor: !1,
876
- colorReplacements: {
877
- "github-light": {
878
- "#959da5": "#6c676f",
879
- "#28a745": "#0e790b",
880
- "#b08800": "#846312",
881
- "#e36209": "#c13617",
882
- "#3192aa": "#05728b",
883
- "#d73a49": "#c62739",
884
- "#22863a": "#11782a",
885
- "#6a737d": "#62687b",
886
- "#1b7c83": "#06747a",
887
- "#0366d6": "#0663d0",
888
- "#cb2431": "#c82430"
889
- },
890
- "github-dark": {
891
- "#586069": "#5b93a3",
892
- "#6a737d": "#818e99",
893
- "#ea4a5a": "#ef5564",
894
- "#2188ff": "#268bf9"
895
- }
896
- }
897
- });
898
- }
899
- return ut.register(r, () => e.dispose()), r;
900
- }
901
- function ft() {
902
- return {
903
- name: "typedown:disable-shell-symbol-select",
904
- tokens(e) {
905
- if (st(this.options.lang)) for (let t of e) {
906
- if (t.length < 2) continue;
907
- let e = t[0].content.trim();
908
- (e === "$" || e === ">") && t[1].content[0] === " " && (t[0].content = e + " ", t[0].htmlStyle ??= {}, t[0].htmlStyle["user-select"] = "none", t[0].htmlStyle["-webkit-user-select"] = "none", t[1].content = t[1].content.slice(1));
909
- }
910
- }
911
- };
912
- }
913
- //#endregion
914
- //#region src/node/lib/render/postprocess.ts
915
- var H;
916
- async function pt(e) {
917
- return e = await gt(e), e = bt(e), e;
918
- }
919
- function mt() {
920
- return H ||= dt(), H;
921
- }
922
- var ht = /<pre class="td-code-placeholder"([^>]*)><code>([\s\S]*?)<\/code><\/pre>/g;
923
- function U(e, t) {
924
- return e.match(RegExp(`${t}="([^"]*)"`))?.[1];
925
- }
926
- async function gt(e) {
927
- let t = await mt(), n = [...e.matchAll(ht)];
928
- if (n.length === 0) return e;
929
- let r = await Promise.all(n.map(async (e) => {
930
- let n = e[1], r = U(n, "data-lang") ?? "", i = U(n, "data-meta") ?? "", a = U(n, "data-title"), o = U(n, "data-line-numbers"), s = g(e[2]);
931
- return _t(await t(s, r, i), r, {
932
- title: a,
933
- lineNumbers: o
934
- });
935
- })), i = e;
936
- for (let e = n.length - 1; 0 <= e; e--) {
937
- let t = n[e];
938
- i = i.slice(0, t.index) + r[e] + i.slice(t.index + t[0].length);
939
- }
940
- return i;
941
- }
942
- function _t(e, t, n) {
943
- t ||= "txt";
944
- let r = n.title ?? t.replace(/_/g, " "), i = ["language-" + t];
945
- n.title && i.push("has-title"), n.lineNumbers !== void 0 && i.push("line-numbers-mode");
946
- let a = `<div class="${i.join(" ")}"><button title="Copy code" data-copied="Copied" class="copy"></button><span class="lang">${h(r)}</span>` + e;
947
- if (n.lineNumbers !== void 0) {
948
- let e = parseInt(n.lineNumbers) || 1, t = a.slice(a.indexOf("<code>"), a.indexOf("</code>")).split("\n").length, r = [...Array(t)].map((t, n) => `<span class="line-number">${n + e}</span><br>`).join("");
949
- a += `<div class="line-numbers-wrapper" aria-hidden="true">${r}</div>`;
950
- }
951
- return a += "</div>", a;
952
- }
953
- var vt = /<span class="td-math-inline">([\s\S]*?)<\/span>/g, yt = /<div class="td-math-block">([\s\S]*?)<\/div>/g;
954
- function bt(e) {
955
- return e = e.replace(vt, (e, t) => W(t, !1)), e = e.replace(yt, (e, t) => W(t, !0)), e;
956
- }
957
- var xt = /`([^`]+)`|\$([^$]+)\$/g;
958
- function St(e) {
959
- let t = 0, n = "";
960
- for (let r of e.matchAll(xt)) {
961
- if (n += h(e.slice(t, r.index)), r[1] !== void 0) n += `<code>${h(r[1])}</code>`;
962
- else if (r[2] !== void 0) try {
963
- n += ne.renderToString(r[2], { throwOnError: !1 });
964
- } catch {
965
- n += h(r[0]);
966
- }
967
- t = r.index + r[0].length;
968
- }
969
- return n += h(e.slice(t)), n;
970
- }
971
- function W(e, t) {
972
- let n = t ? "div" : "span";
973
- try {
974
- return ne.renderToString(g(e), {
975
- throwOnError: !1,
976
- displayMode: t
977
- });
978
- } catch {
979
- return `<${n} class="td-math-error">${e}</${n}>`;
980
- }
981
- }
982
- //#endregion
983
- //#region src/node/lib/render/vue.ts
984
- async function G(e, t, n) {
985
- let r = t.title || t.label || (m(n) ? x(n, (await e.getConfig()).siteTitle) : C(n));
986
- return {
987
- schema: t.schema,
988
- schemaLabel: t.schemaLabel,
989
- label: t.label,
990
- icon: t.icon,
991
- frontmatter: t.header ?? {},
992
- headings: wt(t.headings),
993
- title: r,
994
- titleHtml: St(r),
995
- filepath: n,
996
- fileMetadata: t.fileMetadata,
997
- seoMetadata: t.seoMetadata
998
- };
999
- }
1000
- async function Ct(e, t, n) {
1001
- let r = await pt(t.content), i = await G(e, t, n), a = JSON.stringify(`@typedown/pages?resource=${encodeURIComponent(n)}`);
1002
- return {
1003
- vueSrc: [
1004
- "<script>",
1005
- `export { pageData } from ${a}`,
1006
- `export default { name: ${JSON.stringify(n)} }`,
1007
- "<\/script>",
1008
- "<script setup>",
1009
- "import { useRouter } from 'typerighter/client'",
1010
- `import { pageData } from ${a}`,
1011
- "useRouter().route.data = pageData",
1012
- "<\/script>",
1013
- `<template><div class="typedown-content">\n${Tt(r)}\n</div></template>`
1014
- ].join("\n"),
1015
- pageData: i
1016
- };
1017
- }
1018
- function wt(e) {
1019
- let t = [], n = [];
1020
- for (let r of e) {
1021
- let e = {
1022
- level: r.level,
1023
- title: r.title,
1024
- titleHtml: r.titleHtml ?? r.title,
1025
- slug: r.slug,
1026
- link: `#${r.slug}`,
1027
- children: []
1028
- };
1029
- for (; 0 < n.length && r.level <= n[n.length - 1].level;) n.pop();
1030
- 0 < n.length ? n[n.length - 1].children.push(e) : t.push(e), n.push(e);
1031
- }
1032
- return t;
1033
- }
1034
- function Tt(e) {
1035
- return e.replaceAll("{{", "&#123;&#123;").replaceAll("}}", "&#125;&#125;");
1036
- }
1037
- //#endregion
1038
- //#region src/node/plugin/vite/constants.ts
1039
- var Et = "@typedown/app", Dt = "\0@typedown/app", K = "@typedown/pages", Ot = "\0" + K;
1040
- K + "";
1041
- var q = "\0@typedown/pages?resource=", J = "@typedown/site-data", kt = "\0@typedown/site-data", Y = "@typedown/search-index", At = "\0@typedown/search-index", X = "@typedown/theme", jt = "\0@typedown/theme", Z = "typedown:page-data";
1042
- //#endregion
1043
- //#region src/node/plugin/vite/virtual/utils.ts
1044
- function Q(e, t) {
1045
- let n = e.moduleGraph.getModuleById(t);
1046
- if (n) {
1047
- e.moduleGraph.invalidateModule(n);
1048
- for (let t of n.importers) e.hot.send({
1049
- type: "update",
1050
- updates: [{
1051
- type: "js-update",
1052
- path: t.url,
1053
- acceptedPath: n.url,
1054
- timestamp: Date.now()
1055
- }]
1056
- });
1057
- }
1058
- }
1059
- //#endregion
1060
- //#region src/node/plugin/vite/virtual/app.ts
1061
- var Mt = class {
1062
- async load(e) {
1063
- let t = await (await e.getTdContext()).getConfig(), n = await Fe(t.components, e.root);
1064
- return F({
1065
- rootDir: t.rootDir,
1066
- basePath: t.basePath,
1067
- origin: t.origin ?? void 0,
1068
- lang: t.lang,
1069
- siteTitle: t.siteTitle,
1070
- siteDescription: t.siteDescription,
1071
- repo: t.repo ?? void 0,
1072
- author: t.author ?? void 0,
1073
- license: t.license ?? void 0,
1074
- nav: t.nav,
1075
- userComponents: n
1076
- }, {
1077
- theme: X,
1078
- pages: K,
1079
- siteData: J,
1080
- searchIndex: Y,
1081
- pageDataEvent: Z
1082
- });
1083
- }
1084
- invalidate(e) {
1085
- Q(e, Dt);
1086
- }
1087
- }, Nt = class {
1088
- async load(e) {
1089
- let t = (await e.getConfig()).rootDir ?? ".";
1090
- return `export const pages = import.meta.glob('${t === "." ? "/**/*.{td,md}" : `/${t}/**/*.{td,md}`}');`;
1091
- }
1092
- resolvePageData(e) {
1093
- if (e.startsWith("@typedown/pages?resource=")) return "\0" + e;
1094
- }
1095
- isPageDataModule(e) {
1096
- return e.startsWith(q);
1097
- }
1098
- async loadPageData(e, t) {
1099
- let n = decodeURIComponent(e.slice(q.length)), r = await G(t, await t.getFile(n), n);
1100
- return `export const pageData = ${JSON.stringify(r)}`;
1101
- }
1102
- invalidatePageData(e, t) {
1103
- Q(e, q + encodeURIComponent(t));
1104
- }
1105
- sendPageData(e, t, n) {
1106
- t.getFile(n).then(async (r) => {
1107
- let i = await G(t, r, n);
1108
- e.hot.send({
1109
- type: "custom",
1110
- event: Z,
1111
- data: {
1112
- filepath: n,
1113
- pageData: i
1114
- }
1115
- });
1116
- }).catch((e) => {
1117
- console.error("[typedown] Failed to send page data:", e instanceof Error ? e.message : e);
1118
- });
1119
- }
1120
- invalidate(e) {
1121
- Q(e, Ot);
1122
- }
1123
- }, Pt = class {
1124
- async load(e) {
1125
- return Pe((await (await e.getTdContext()).getConfig()).layout ?? void 0, e.root);
1126
- }
1127
- invalidate(e) {
1128
- Q(e, jt);
1129
- }
1130
- }, Ft = "\0@typedown/site-data", It = {
1131
- ready: !1,
1132
- contentTree: { entries: [] },
1133
- schemas: {},
1134
- directoryListings: {}
1135
- }, Lt = class {
1136
- data;
1137
- scan(e) {
1138
- let t = P("**/*.td", {
1139
- cwd: e,
1140
- exclude: (e) => e.startsWith("_")
1141
- }).map((e) => ({
1142
- filepath: e,
1143
- label: C(e),
1144
- header: {}
1145
- })), n = v(t);
1146
- this.data = {
1147
- contentTree: n,
1148
- schemas: {},
1149
- directoryListings: _(n.entries, "")
1150
- };
1151
- }
1152
- load(e) {
1153
- let t = this.data ? {
1154
- ready: !0,
1155
- ...this.data
1156
- } : It;
1157
- return `export default ${JSON.stringify(t)}`;
1158
- }
1159
- clear() {
1160
- this.data = void 0;
1161
- }
1162
- fetch = b((e, t) => {
1163
- Rt(e).then((e) => {
1164
- this.data = e, t && this.invalidate(t);
1165
- }).catch((e) => {
1166
- console.error("[typedown] Failed to fetch site data:", e instanceof Error ? e.message : e);
1167
- });
1168
- }, 200);
1169
- async fetchSync(e) {
1170
- this.data = await Rt(e);
1171
- }
1172
- invalidate(e) {
1173
- Q(e, Ft);
1174
- }
1175
- };
1176
- async function Rt(e) {
1177
- let [t, n, r] = await Promise.all([
1178
- e.getConfig(),
1179
- e.listSidebar(),
1180
- e.listSchemas()
1181
- ]), i = await Promise.all(r.map(async (t) => [t, (await e.getSchema(t)).properties])), a = Object.fromEntries(i), o = n.map((e) => ({
1182
- ...e,
1183
- header: {}
1184
- })), s = v(o);
1185
- return {
1186
- contentTree: s,
1187
- schemas: a,
1188
- directoryListings: _(s.entries, t.siteTitle)
1189
- };
1190
- }
1191
- //#endregion
1192
- //#region src/node/lib/search-indexer/index.ts
1193
- var zt = class {
1194
- index;
1195
- constructor() {
1196
- this.index = new se({
1197
- fields: f,
1198
- storeFields: c
1199
- });
1200
- }
1201
- addAll(e) {
1202
- this.index.removeAll();
1203
- for (let t of e) this.index.add(t);
1204
- }
1205
- addPage(e) {
1206
- this.index.has(e.id) && this.index.discard(e.id), this.index.add(e);
1207
- }
1208
- discardPage(e) {
1209
- this.index.has(e) && this.index.discard(e);
1210
- }
1211
- serialize() {
1212
- return JSON.stringify(this.index);
1213
- }
1214
- };
1215
- //#endregion
1216
- //#region src/node/lib/search-indexer/scan.ts
1217
- function Bt(e, t) {
1218
- let n = Wt(e), r = [];
1219
- for (let t of n) {
1220
- let n = Ut(e, t);
1221
- n && r.push(n);
1222
- }
1223
- t.addAll(r);
1224
- }
1225
- function Vt(e, n, r) {
1226
- let i = Ut(e, j(e, n));
1227
- i ? r.addPage(i) : r.discardPage(t(n));
1228
- }
1229
- function Ht(e, t) {
1230
- let n = C(e);
1231
- if (!t.startsWith("---")) return {
1232
- title: n,
1233
- body: t
1234
- };
1235
- let r = t.indexOf("\n---", 3);
1236
- if (r === -1) return {
1237
- title: n,
1238
- body: t
1239
- };
1240
- let i = t.slice(4, r), a = t.slice(r + 4).trim();
1241
- return {
1242
- title: (/^_label:\s*"(.+)"$/m.exec(i) ?? /^_label:\s*'(.+)'$/m.exec(i))?.[1]?.trim() || n,
1243
- body: a
1244
- };
1245
- }
1246
- function Ut(e, n) {
1247
- let r;
1248
- try {
1249
- r = xe(n, "utf-8");
1250
- } catch {
1251
- return;
1252
- }
1253
- if (!r.trim()) return;
1254
- let i = n.slice(e.length + 1), { title: a, body: o } = Ht(i, r);
1255
- return {
1256
- id: t(i),
1257
- title: a,
1258
- text: `${a}\n${o}`
1259
- };
1260
- }
1261
- function Wt(e) {
1262
- return P("**/*.td", {
1263
- cwd: e,
1264
- exclude: (e) => e.startsWith("_")
1265
- }).map((t) => j(e, t));
1266
- }
1267
- //#endregion
1268
- //#region src/node/plugin/vite/virtual/search-index.ts
1269
- var Gt = "\0@typedown/search-index", Kt = class {
1270
- indexer = new zt();
1271
- load(e) {
1272
- return `export default ${JSON.stringify(this.indexer.serialize())}`;
1273
- }
1274
- index(e) {
1275
- Bt(e, this.indexer);
1276
- }
1277
- reindex(e, t) {
1278
- Vt(e, t, this.indexer);
1279
- }
1280
- invalidate(e) {
1281
- Q(e, Gt);
1282
- }
1283
- }, qt = Ce(import.meta.url);
1284
- function Jt() {
1285
- return [{
1286
- find: "vue/server-renderer",
1287
- replacement: qt.resolve("vue/server-renderer")
1288
- }, {
1289
- find: "vue",
1290
- replacement: qt.resolve("vue/dist/vue.runtime.esm-bundler.js")
1291
- }];
1292
- }
1293
- //#endregion
1294
- //#region src/node/plugin/vite/middleware/vault-assets.ts
1295
- var Yt = {
1296
- jpg: "image/jpeg",
1297
- jpeg: "image/jpeg",
1298
- png: "image/png",
1299
- gif: "image/gif",
1300
- webp: "image/webp",
1301
- svg: "image/svg+xml",
1302
- avif: "image/avif",
1303
- ico: "image/x-icon",
1304
- pdf: "application/pdf",
1305
- zip: "application/zip",
1306
- mp3: "audio/mpeg",
1307
- mp4: "video/mp4",
1308
- webm: "video/webm",
1309
- woff2: "font/woff2",
1310
- woff: "font/woff",
1311
- ttf: "font/ttf"
1312
- };
1313
- function Xt(t, r) {
1314
- return (i, a, s) => {
1315
- if (!i.url || i.method !== "GET" || a.writableEnded) return s();
1316
- let c = e(i.url);
1317
- if (c.startsWith("/@") || c.startsWith("/node_modules")) return s();
1318
- let l = n(r.basePath), u = (l && c.startsWith(l) ? c.slice(l.length) : c).replace(/^\//, ""), d = j(t.config.root, r.rootDirectory, u);
1319
- if (be(d)) try {
1320
- let e = Se(d);
1321
- if (e.isFile()) {
1322
- let t = Yt[o(d).slice(1).toLowerCase()] ?? "application/octet-stream";
1323
- a.setHeader("Content-Type", t), a.setHeader("Content-Length", e.size), ye(d).pipe(a);
1324
- return;
1325
- }
1326
- } catch {}
1327
- s();
1328
- };
1329
- }
1330
- //#endregion
1331
- //#region src/node/plugin/vite/middleware/virtual-html.ts
1332
- function Zt(t, r, i) {
1333
- return (a, o, s) => {
1334
- if (!a.url) return s();
1335
- let c = n(e(a.url)), l = n(i.basePath);
1336
- if (c.startsWith("/@") || c.startsWith("/node_modules") || !c.startsWith(l)) return s();
1337
- let u = c.slice(l.length);
1338
- if (u.startsWith("/@") || u.startsWith("/node_modules") || c.includes(".") && !c.endsWith("/index.html")) return s();
1339
- r.getConfig().then(async (e) => {
1340
- let n = await t.transformIndexHtml(a.url ?? "", Qt(i, e));
1341
- o.setHeader("Content-Type", "text/html"), o.end(n);
1342
- }).catch(() => s());
1343
- };
1344
- }
1345
- function Qt(e, t) {
1346
- return e.devHtml === void 0 && (e.devHtml = ee({
1347
- title: t.siteTitle,
1348
- description: t.siteDescription,
1349
- base: "/",
1350
- entryScript: Et
1351
- })), e.devHtml;
1352
- }
1353
- //#endregion
1354
- //#region src/node/plugin/vite/index.ts
1355
- function $t(e = {}) {
1356
- let t = e.context, n, r, a, o = new Mt(), s = new Pt(), c = new Nt(), u = new Lt(), d = new Kt(), f = {
1357
- devHtml: void 0,
1358
- basePath: "/",
1359
- rootDirectory: "vault"
1360
- };
1361
- function p() {
1362
- if (t === void 0) throw Error("typedown plugin not initialized");
1363
- return t.getTdContext();
1364
- }
1365
- return [
1366
- {
1367
- name: "vite-plugin-typedown",
1368
- enforce: "pre",
1369
- async config(n) {
1370
- if (!t) {
1371
- let r = e.root ? j(n.root ?? process.cwd(), e.root) : oe(n.root ?? process.cwd());
1372
- t = ae(r);
1373
- }
1374
- a = n.base ?? "/";
1375
- let r = await (await p()).getConfig();
1376
- return {
1377
- base: n.base ?? r.basePath,
1378
- publicDir: r.publicDir,
1379
- server: {
1380
- port: n.server?.port ?? 8686,
1381
- strictPort: n.server?.strictPort ?? !1
1382
- },
1383
- resolve: { alias: Jt() },
1384
- ssr: { noExternal: ["typerighter"] }
1385
- };
1386
- },
1387
- configResolved(e) {
1388
- r = j(e.root, e.build.outDir);
1389
- },
1390
- async buildStart() {
1391
- if (n) return;
1392
- let e = await p(), t = await e.getConfig(), r = j(t.rootDir);
1393
- d.index(r), await u.fetchSync(e);
1394
- let i = await e.checkVault();
1395
- if (rn(i.diagnostics), 0 < i.errorCount) {
1396
- let e = i.diagnostics.filter((e) => e.severity === "error").map((e) => ` ${e.filepath}:${e.line}:${e.column} - ${e.message} (${e.code})`);
1397
- this.error(`Vault check failed with ${i.errorCount} error(s):\n${e.join("\n")}`);
1398
- }
1399
- },
1400
- resolveId(e) {
1401
- if (e === "/@typedown/app" || e === "@typedown/app") return Dt;
1402
- if (e === "@typedown/pages") return Ot;
1403
- if (e.startsWith("@typedown/pages?resource=")) return c.resolvePageData(e);
1404
- if (e === "@typedown/site-data") return kt;
1405
- if (e === "@typedown/search-index") return At;
1406
- if (e === "@typedown/theme") return jt;
1407
- },
1408
- async load(e) {
1409
- if (c.isPageDataModule(e)) return c.loadPageData(e, await p());
1410
- if (e !== "\0@typedown/search-index" && e !== "\0@typedown/site-data" && e !== "\0@typedown/pages" && e !== "\0@typedown/app" && e !== "\0@typedown/theme") return;
1411
- let n = await p();
1412
- if (e === "\0@typedown/search-index") return d.load(n);
1413
- if (e === "\0@typedown/site-data") return u.load(n);
1414
- if (e === "\0@typedown/pages") return c.load(n);
1415
- if (e === "\0@typedown/app") return o.load(t);
1416
- if (e === "\0@typedown/theme") return s.load(t);
1417
- },
1418
- async configureServer(e) {
1419
- n = e;
1420
- let t = await p(), r = await t.getConfig(), i = j(r.rootDir);
1421
- d.index(i), u.scan(i), u.fetch(t, n), e.httpServer?.once("listening", async () => {
1422
- let e = await t.checkVault();
1423
- 0 < e.diagnostics.length && (console.error(""), rn(e.diagnostics));
1424
- }), t.rpc.onConfigChanged(() => {
1425
- n && (f.devHtml = void 0, u.clear(), o.invalidate(n), s.invalidate(n), c.invalidate(n), $(n), u.fetch(t, n));
1426
- }), t.rpc.onComponentContractChanged(() => {
1427
- n && (o.invalidate(n), $(n));
1428
- });
1429
- function a(...e) {
1430
- n && t.getConfig().then((t) => {
1431
- if (!n) return;
1432
- let r = [];
1433
- for (let i of e) {
1434
- let e = de(j(n.config.root, t.rootDir, i)), a = n.moduleGraph.getModulesByFile(e);
1435
- if (a?.size) {
1436
- for (let e of a) n.moduleGraph.invalidateModule(e), r.push(nn(e));
1437
- c.invalidatePageData(n, i);
1438
- }
1439
- }
1440
- 0 < r.length && n.hot.send({
1441
- type: "update",
1442
- updates: r
1443
- });
1444
- }).catch(() => {});
1445
- }
1446
- t.rpc.onContentUpdated(({ filepath: e, affectedFiles: r = [] }) => {
1447
- n && (d.reindex(i, e), d.invalidate(n), c.invalidate(n), u.fetch(t, n), a(e, ...r), c.sendPageData(n, t, e));
1448
- }), t.rpc.onContentDeleted(({ filepath: e }) => {
1449
- n && (d.reindex(i, e), d.invalidate(n), c.invalidate(n), u.fetch(t, n), a(e));
1450
- });
1451
- function l() {
1452
- n && (u.clear(), tn(n), u.fetch(t, n));
1453
- }
1454
- t.rpc.onSchemaUpdated(l), t.rpc.onSchemaDeleted(l);
1455
- let m = await t.getConfig();
1456
- f.basePath = m.basePath, f.rootDirectory = m.rootDir, t.rpc.onConfigChanged((e) => {
1457
- f.basePath = e.basePath, f.rootDirectory = e.rootDir, f.devHtml = void 0;
1458
- }), e.middlewares.use(Xt(e, f)), e.middlewares.use(Zt(e, t, f));
1459
- },
1460
- async transform(e, t) {
1461
- let n = t.split("?")[0];
1462
- if (!l(n)) return;
1463
- if (w(n)) return {
1464
- code: "<script>import { TdNotFound } from 'typerighter/client/theme-default'; export default TdNotFound; export const pageData = { frontmatter: {}, headings: [], title: '' };<\/script>",
1465
- map: null
1466
- };
1467
- let r = await p(), a = await r.getConfig(), o = i(n, a.rootDir);
1468
- try {
1469
- let { vueSrc: e } = await Ct(r, await r.getFile(o), o);
1470
- return {
1471
- code: e,
1472
- map: null
1473
- };
1474
- } catch (e) {
1475
- if (ie(e)) return;
1476
- let t = e instanceof Error ? e.message : String(e);
1477
- this.error(`[typedown] Failed to transform ${o}: ${t}`);
1478
- }
1479
- },
1480
- handleHotUpdate({ file: e }) {
1481
- if (l(e)) return [];
1482
- },
1483
- async closeBundle() {
1484
- if (!e.context && t) try {
1485
- let e = (await (await t.getTdContext()).getConfig()).basePath, n = e.startsWith(a) ? e.slice(a.length) : e.replace(/^\//, "");
1486
- await Le(t, {
1487
- outDir: j(r, n),
1488
- base: e
1489
- });
1490
- } finally {
1491
- t.dispose();
1492
- }
1493
- }
1494
- },
1495
- le({
1496
- include: e.root ? RegExp(`${e.root.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/.*\\.(?:vue|td)$`) : /\.(?:vue|td)$/,
1497
- template: { transformAssetUrls: !1 }
1498
- }),
1499
- ...ce()
1500
- ];
1501
- }
1502
- function en(e) {
1503
- return [...e.moduleGraph.idToModuleMap.entries()].filter(([e]) => e.endsWith(".td")).map(([, e]) => e);
1504
- }
1505
- function $(e) {
1506
- for (let t of en(e)) e.moduleGraph.invalidateModule(t);
1507
- e.hot.send({ type: "full-reload" });
1508
- }
1509
- function tn(e) {
1510
- let t = en(e).map((t) => (e.moduleGraph.invalidateModule(t), nn(t)));
1511
- 0 < t.length && e.hot.send({
1512
- type: "update",
1513
- updates: t
1514
- });
1515
- }
1516
- function nn(e) {
1517
- return {
1518
- type: "js-update",
1519
- path: e.url,
1520
- acceptedPath: e.url,
1521
- timestamp: Date.now()
1522
- };
1523
- }
1524
- function rn(e) {
1525
- for (let t of e) {
1526
- let e = `${t.filepath}:${t.line}:${t.column}`, n = t.severity === "error" ? M.red("error") : M.yellow("warn");
1527
- console.error(` ${n} ${e} ${t.message} ${M.dim(`(${t.code})`)}`);
1528
- }
1529
- }
1530
- //#endregion
1531
- export { J as a, Y as i, K as n, X as o, Z as r, Le as s, $t as t };