typerighter 0.4.4 → 0.30.4

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