typerighter 0.4.4 → 0.30.3

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-gH0dpuch.js +2382 -0
  2. package/dist/brand-CG1fQshq.js +5 -0
  3. package/dist/cli-BFgBPypP.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 +2314 -593
  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-EKDV1L4U.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 +15 -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 +1 -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-BuA2cqMO.js +401 -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-CYozrIIG.js +1468 -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,1468 @@
1
+ import { C as e, F as t, G as n, H as r, L as i, N as a, P as o, V as s, W as c, _ as l, f as u, g as d, h as f, j as p, l as m, p as h, s as g, w as _ } from "./shared-BuA2cqMO.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 = g(e.title), n = g(e.description), r = e.siteTitle !== void 0 && e.title !== e.siteTitle ? `${t} - ${g(e.siteTitle)}` : t, i = e.canonicalUrl === void 0 ? "" : `\n <link rel="canonical" href="${g(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, a = b.resolve(n, t.outDir ?? "dist"), o = b.join(a, ".client"), s = b.join(a, ".server");
123
+ await D.rm(a, {
124
+ recursive: !0,
125
+ force: !0
126
+ });
127
+ let c = await e.getTdContext(), [l, d, f, p] = 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 = f.map((e) => ({
133
+ ...e,
134
+ header: {}
135
+ })), _ = u(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 }), u = 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: u,
169
+ logLevel: "silent",
170
+ build: {
171
+ ...t.viteConfig?.build,
172
+ outDir: o,
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(o, "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: u,
190
+ logLevel: "silent",
191
+ build: {
192
+ ...t.viteConfig?.build,
193
+ outDir: s,
194
+ ssr: C,
195
+ emptyOutDir: !0
196
+ }
197
+ }), m.done("SSR bundle");
198
+ let g = d.map((e) => {
199
+ let t = i(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(s, "ssr-entry.js"),
206
+ clientOutDir: o,
207
+ outDir: a,
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(a, "sitemap.xml"), y);
215
+ let x = b.join(o, "assets"), w = b.join(a, "assets");
216
+ await D.cp(x, w, { recursive: !0 }).catch(() => {}), await ve(b.join(n, l.rootDir), a);
217
+ let E = b.join(n, l.publicDir);
218
+ await D.cp(E, a, { recursive: !0 }).catch(() => {});
219
+ } finally {
220
+ await Promise.all([
221
+ D.rm(x, {
222
+ recursive: !0,
223
+ force: !0
224
+ }),
225
+ D.rm(o, {
226
+ recursive: !0,
227
+ force: !0
228
+ }),
229
+ D.rm(s, {
230
+ recursive: !0,
231
+ force: !0
232
+ })
233
+ ]);
234
+ }
235
+ r.log(`\nBuild complete. Output: ${a}`);
236
+ }
237
+ function _e(e) {
238
+ let t = `/${e.rootDir}/${r}`, n = JSON.parse(e.siteConfig), i = JSON.parse(e.siteData), a = i.contentTree ?? { entries: [] }, o = h(a.entries ?? [], n.title ?? ""), c = 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(s)};
252
+ const siteData = ${c};
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(e, t) {
287
+ let n = (await D.readdir(e, {
288
+ recursive: !0,
289
+ withFileTypes: !0
290
+ })).filter((e) => e.isFile() && !o(e.name)).map(async (n) => {
291
+ let r = b.join(n.parentPath, n.name), i = b.relative(e, r), a = b.join(t, i);
292
+ return D.mkdir(b.dirname(a), { recursive: !0 }).then(() => D.copyFile(r, a));
293
+ });
294
+ await Promise.all(n);
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>${g(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 = m(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(m(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 || (l(n) ? f(n, (await e.getConfig()).siteTitle) : d(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
+ slug: r.slug,
776
+ link: `#${r.slug}`,
777
+ children: []
778
+ };
779
+ for (; 0 < n.length && r.level <= n[n.length - 1].level;) n.pop();
780
+ 0 < n.length ? n[n.length - 1].children.push(e) : t.push(e), n.push(e);
781
+ }
782
+ return t;
783
+ }
784
+ function nt(e) {
785
+ return e.replaceAll("{{", "&#123;&#123;");
786
+ }
787
+ //#endregion
788
+ //#region src/node/lib/typedown-context.ts
789
+ var rt = class {
790
+ client;
791
+ constructor(e) {
792
+ this.client = e, this.registerNotificationHandlers(e);
793
+ }
794
+ cachedConfig;
795
+ cachedFiles;
796
+ cachedSchemas;
797
+ cachedSchemaMap = /* @__PURE__ */ new Map();
798
+ cachedFileMap = /* @__PURE__ */ new Map();
799
+ registerNotificationHandlers(e) {
800
+ e.onConfigChanged((e) => {
801
+ this.cachedConfig = e;
802
+ }), e.onContentChanged(({ content: e, affectedFiles: t = [] }) => {
803
+ this.cachedFileMap.delete(e);
804
+ for (let e of t) this.cachedFileMap.delete(e);
805
+ }), e.onContentCreated(() => {
806
+ this.cachedFiles = void 0;
807
+ }), e.onContentDeleted(({ content: e }) => {
808
+ this.cachedFiles = void 0, this.cachedFileMap.delete(e);
809
+ }), e.onSchemaChanged(({ schema: e }) => {
810
+ this.cachedSchemaMap.delete(e);
811
+ }), e.onSchemaCreated(() => {
812
+ this.cachedSchemas = void 0;
813
+ }), e.onSchemaDeleted(({ schema: e }) => {
814
+ this.cachedSchemas = void 0, this.cachedSchemaMap.delete(e);
815
+ });
816
+ }
817
+ get rpc() {
818
+ return this.client;
819
+ }
820
+ async getFile(e) {
821
+ let t = this.cachedFileMap.get(e);
822
+ if (t) return t;
823
+ let n = await W(() => this.rpc.requestFile(e));
824
+ return this.cachedFileMap.set(e, n), n;
825
+ }
826
+ async getFiles(e) {
827
+ let t = e.filter((e) => !this.cachedFileMap.has(e));
828
+ if (0 < t.length) {
829
+ let e = await W(() => this.rpc.requestFiles(t));
830
+ for (let [n, r] of t.entries()) this.cachedFileMap.set(r, e[n]);
831
+ }
832
+ return e.map((e) => this.cachedFileMap.get(e));
833
+ }
834
+ async listFiles() {
835
+ return this.cachedFiles ||= await W(() => this.rpc.listVault()), this.cachedFiles;
836
+ }
837
+ async listSidebar() {
838
+ return W(() => this.rpc.listSidebar());
839
+ }
840
+ async getConfig() {
841
+ return this.cachedConfig ||= await W(() => this.rpc.getConfig()), this.cachedConfig;
842
+ }
843
+ async getSchema(e) {
844
+ let t = this.cachedSchemaMap.get(e);
845
+ if (t) return t;
846
+ let n = await W(() => this.rpc.getSchema(e));
847
+ return this.cachedSchemaMap.set(e, n), n;
848
+ }
849
+ async listSchemas() {
850
+ return this.cachedSchemas ||= await W(() => this.rpc.listSchemas()), this.cachedSchemas;
851
+ }
852
+ async checkVault() {
853
+ return W(() => this.rpc.checkVault());
854
+ }
855
+ async formatFile(e) {
856
+ return W(() => this.rpc.formatFile(e));
857
+ }
858
+ };
859
+ function U(e) {
860
+ return e instanceof Error && "code" in e && e.code === ue;
861
+ }
862
+ async function W(e, t = 5) {
863
+ for (let n = 0; n < t; n++) try {
864
+ return await e();
865
+ } catch (e) {
866
+ if (!U(e) || n === t - 1) throw e;
867
+ await new Promise((e) => setTimeout(e, 50 * (n + 1)));
868
+ }
869
+ throw Error("unreachable");
870
+ }
871
+ //#endregion
872
+ //#region src/node/context.ts
873
+ var G = ["typedown.yaml", "typedown.yml"];
874
+ function K(e) {
875
+ let t = new R(ot(e));
876
+ function n() {
877
+ let e = E("warn");
878
+ return {
879
+ ...e,
880
+ info(e) {
881
+ t.writeToFile("VITE", e);
882
+ },
883
+ warn(n) {
884
+ e.warn(n), t.writeToFile("VITE:WARN", n);
885
+ },
886
+ error(n) {
887
+ e.error(n), t.writeToFile("VITE:ERROR", n);
888
+ }
889
+ };
890
+ }
891
+ let r, i, a, o = !1;
892
+ function s() {
893
+ t.log(""), u(), process.exit(0);
894
+ }
895
+ function c() {
896
+ u();
897
+ }
898
+ async function l() {
899
+ if (r) return r;
900
+ process.on("SIGINT", s), process.on("SIGTERM", s), i = new le({ root: e }), await new Promise((e, t) => {
901
+ i?.once("error", t), i?.listen(() => {
902
+ i?.removeListener("error", t), e();
903
+ });
904
+ });
905
+ let t = i.host, n = i.port;
906
+ if (t === void 0 || n === void 0) throw Error("RPC server started but host/port not available");
907
+ return a = await de.connectTcp(t, n), r = new rt(a), i.unref(), process.on("exit", c), r;
908
+ }
909
+ function u() {
910
+ 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);
911
+ }
912
+ return {
913
+ root: e,
914
+ logger: t,
915
+ getTdContext: l,
916
+ createViteLogger: n,
917
+ dispose: u
918
+ };
919
+ }
920
+ function it(e) {
921
+ let t = b.resolve(e);
922
+ for (;;) {
923
+ if (at(t)) return t;
924
+ let e = b.dirname(t);
925
+ if (e === t) break;
926
+ t = e;
927
+ }
928
+ return b.resolve(e);
929
+ }
930
+ function at(e) {
931
+ return G.some((t) => O.existsSync(b.join(e, t)));
932
+ }
933
+ function ot(e) {
934
+ try {
935
+ let t = b.join(e, ".typedown", ".local"), n = b.join(t, "logs");
936
+ O.mkdirSync(n, { recursive: !0 });
937
+ let r = b.join(t, ".gitignore");
938
+ O.existsSync(r) || O.writeFileSync(r, "*\n");
939
+ let i = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
940
+ return b.join(n, `${i}.log`);
941
+ } catch {
942
+ return;
943
+ }
944
+ }
945
+ //#endregion
946
+ //#region src/node/plugin/vite/constants.ts
947
+ var st = "@typedown/app", q = "\0@typedown/app", J = "@typedown/pages", ct = "\0" + J;
948
+ J + "";
949
+ var Y = "\0@typedown/pages?resource=", lt = "@typedown/site-data", ut = "\0@typedown/site-data", dt = "@typedown/search-index", ft = "\0@typedown/search-index";
950
+ //#endregion
951
+ //#region src/node/plugin/vite/virtual/utils.ts
952
+ function X(e, t) {
953
+ let n = e.moduleGraph.getModuleById(t);
954
+ if (!n) return;
955
+ e.moduleGraph.invalidateModule(n);
956
+ let r = pt(n.url);
957
+ for (let t of n.importers) e.hot.send({
958
+ type: "update",
959
+ updates: [{
960
+ type: "js-update",
961
+ path: pt(t.url),
962
+ acceptedPath: r,
963
+ timestamp: Date.now()
964
+ }]
965
+ });
966
+ }
967
+ function pt(e) {
968
+ return e.startsWith("\0") ? "/@id/__x00__" + e.slice(1) : e;
969
+ }
970
+ //#endregion
971
+ //#region src/node/plugin/vite/virtual/app.ts
972
+ var mt = class {
973
+ async load(e) {
974
+ let t = await e.getConfig();
975
+ return Z({
976
+ ...t,
977
+ rootDir: t.rootDir
978
+ });
979
+ }
980
+ invalidate(e) {
981
+ X(e, q);
982
+ }
983
+ };
984
+ function Z(e) {
985
+ let { rootDir: t = "." } = e, n = JSON.stringify({
986
+ title: e.siteTitle,
987
+ description: e.siteDescription,
988
+ basePath: e.basePath ?? "/",
989
+ repo: e.repo,
990
+ author: e.author,
991
+ license: e.license,
992
+ nav: e.nav
993
+ });
994
+ return `
995
+ import 'typerighter/style.css';
996
+ import 'typerighter/fonts.css';
997
+ import('typerighter/math.css');
998
+ import { createTypedownApp } from 'typerighter/client';
999
+ import { TdDirectoryIndex, TdGlossaryIndex } from 'typerighter/client/theme-default';
1000
+ import { isIndexUrl, getDirectoryFromPageUrl } from 'typerighter/shared';
1001
+ import { h } from 'vue';
1002
+ import theme from 'typerighter/client/theme-default';
1003
+ import { pages as initialPages } from '${J}';
1004
+ import initialSiteData from '${lt}';
1005
+ let pages = initialPages;
1006
+ const contentExts = ${JSON.stringify(s)};
1007
+
1008
+ function findPage(base) {
1009
+ for (const ext of contentExts) {
1010
+ const key = base + ext;
1011
+ if (pages[key]) return pages[key];
1012
+ }
1013
+ }
1014
+
1015
+ async function loadPageModule(pagePath) {
1016
+ const base = ('/${t}/' + pagePath).replace(/\\/+/g, '/').replace(/\\/$/, '');
1017
+ const loader = findPage(base);
1018
+ if (loader) return loader();
1019
+
1020
+ if (isIndexUrl(pagePath)) {
1021
+ const dirPath = getDirectoryFromPageUrl(pagePath);
1022
+ const dir = siteData.value.directoryListings[dirPath];
1023
+ if (dir) return {
1024
+ default: { name: 'DirectoryIndex', render() { return h(TdDirectoryIndex); } },
1025
+ pageData: { frontmatter: {}, headings: [], title: dir.title },
1026
+ };
1027
+ }
1028
+
1029
+ return undefined;
1030
+ }
1031
+
1032
+ const { app, searchIndex: searchIndexRef, siteData } = await createTypedownApp(loadPageModule, theme.Layout, ${n}, initialSiteData);
1033
+ app.mount('#app');
1034
+
1035
+ // Load search index in the background after the app is mounted
1036
+ import('${dt}').then((m) => { searchIndexRef.value = m.default; });
1037
+
1038
+ // Accept HMR so modules update without a full page reload
1039
+ if (import.meta.hot) {
1040
+ import.meta.hot.accept('${J}', (m) => {
1041
+ if (m) pages = m.pages;
1042
+ });
1043
+
1044
+ import.meta.hot.accept('${dt}', (m) => {
1045
+ if (m) searchIndexRef.value = m.default;
1046
+ });
1047
+
1048
+ import.meta.hot.accept('${lt}', (m) => {
1049
+ if (m) siteData.value = m.default;
1050
+ });
1051
+ }
1052
+ `;
1053
+ }
1054
+ //#endregion
1055
+ //#region src/node/plugin/vite/virtual/pages.ts
1056
+ var ht = class {
1057
+ async load(e) {
1058
+ let t = (await e.getConfig()).rootDir ?? ".";
1059
+ return `export const pages = import.meta.glob('${t === "." ? "/**/*.{td,md}" : `/${t}/**/*.{td,md}`}');`;
1060
+ }
1061
+ resolvePageData(e) {
1062
+ if (e.startsWith("@typedown/pages?resource=")) return "\0" + e;
1063
+ }
1064
+ isPageDataModule(e) {
1065
+ return e.startsWith(Y);
1066
+ }
1067
+ async loadPageData(e, t) {
1068
+ let n = decodeURIComponent(e.slice(Y.length)), r = await H(t, await t.getFile(n), n);
1069
+ return `export const pageData = ${JSON.stringify(r)}`;
1070
+ }
1071
+ invalidatePageData(e, t) {
1072
+ X(e, Y + encodeURIComponent(t));
1073
+ }
1074
+ invalidate(e) {
1075
+ X(e, ct);
1076
+ }
1077
+ }, gt = "\0@typedown/site-data", _t = {
1078
+ ready: !1,
1079
+ contentTree: { entries: [] },
1080
+ schemas: {},
1081
+ directoryListings: {}
1082
+ }, vt = class {
1083
+ data;
1084
+ scan(e) {
1085
+ let t = oe("**/*.td", {
1086
+ cwd: e,
1087
+ exclude: (e) => e.startsWith("_")
1088
+ }).map((e) => ({
1089
+ filepath: e,
1090
+ label: d(e),
1091
+ header: {}
1092
+ })), n = u(t);
1093
+ this.data = {
1094
+ contentTree: n,
1095
+ schemas: {},
1096
+ directoryListings: {}
1097
+ };
1098
+ }
1099
+ load(e) {
1100
+ let t = this.data ? {
1101
+ ready: !0,
1102
+ ...this.data
1103
+ } : _t;
1104
+ return `export default ${JSON.stringify(t)}`;
1105
+ }
1106
+ clear() {
1107
+ this.data = void 0;
1108
+ }
1109
+ fetch(e, t) {
1110
+ yt(e).then((e) => {
1111
+ this.data = e, t && this.invalidate(t);
1112
+ }).catch((e) => {
1113
+ console.error("[typedown] Failed to fetch site data:", e instanceof Error ? e.message : e);
1114
+ });
1115
+ }
1116
+ async fetchSync(e) {
1117
+ this.data = await yt(e);
1118
+ }
1119
+ invalidate(e) {
1120
+ X(e, gt);
1121
+ }
1122
+ };
1123
+ async function yt(e) {
1124
+ let [t, n, r] = await Promise.all([
1125
+ e.getConfig(),
1126
+ e.listSidebar(),
1127
+ e.listSchemas()
1128
+ ]), i = await Promise.all(r.map(async (t) => [t, (await e.getSchema(t)).properties])), a = Object.fromEntries(i), o = n.map((e) => ({
1129
+ ...e,
1130
+ header: {}
1131
+ })), s = u(o);
1132
+ return {
1133
+ contentTree: s,
1134
+ schemas: a,
1135
+ directoryListings: h(s.entries, t.siteTitle)
1136
+ };
1137
+ }
1138
+ //#endregion
1139
+ //#region src/node/lib/search-indexer/index.ts
1140
+ var bt = class {
1141
+ index;
1142
+ constructor() {
1143
+ this.index = new y({
1144
+ fields: c,
1145
+ storeFields: n
1146
+ });
1147
+ }
1148
+ addAll(e) {
1149
+ this.index.removeAll();
1150
+ for (let t of e) this.index.add(t);
1151
+ }
1152
+ addPage(e) {
1153
+ this.index.has(e.id) && this.index.discard(e.id), this.index.add(e);
1154
+ }
1155
+ discardPage(e) {
1156
+ this.index.has(e) && this.index.discard(e);
1157
+ }
1158
+ serialize() {
1159
+ return JSON.stringify(this.index);
1160
+ }
1161
+ };
1162
+ //#endregion
1163
+ //#region src/node/lib/search-indexer/scan.ts
1164
+ function xt(e, t) {
1165
+ let n = Tt(e), r = [];
1166
+ for (let t of n) {
1167
+ let n = wt(e, t);
1168
+ n && r.push(n);
1169
+ }
1170
+ t.addAll(r);
1171
+ }
1172
+ function St(t, n, r) {
1173
+ let i = wt(t, x(t, n));
1174
+ i ? r.addPage(i) : r.discardPage(e(n));
1175
+ }
1176
+ function Ct(e, t) {
1177
+ let n = d(e);
1178
+ if (!t.startsWith("---")) return {
1179
+ title: n,
1180
+ body: t
1181
+ };
1182
+ let r = t.indexOf("\n---", 3);
1183
+ if (r === -1) return {
1184
+ title: n,
1185
+ body: t
1186
+ };
1187
+ let i = t.slice(4, r), a = t.slice(r + 4).trim();
1188
+ return {
1189
+ title: (/^_label:\s*"(.+)"$/m.exec(i) ?? /^_label:\s*'(.+)'$/m.exec(i))?.[1]?.trim() || n,
1190
+ body: a
1191
+ };
1192
+ }
1193
+ function wt(t, n) {
1194
+ let r;
1195
+ try {
1196
+ r = se(n, "utf-8");
1197
+ } catch {
1198
+ return;
1199
+ }
1200
+ if (!r.trim()) return;
1201
+ let i = n.slice(t.length + 1), { title: a, body: o } = Ct(i, r);
1202
+ return {
1203
+ id: e(i),
1204
+ title: a,
1205
+ text: `${a}\n${o}`
1206
+ };
1207
+ }
1208
+ function Tt(e) {
1209
+ return oe("**/*.td", {
1210
+ cwd: e,
1211
+ exclude: (e) => e.startsWith("_")
1212
+ }).map((t) => x(e, t));
1213
+ }
1214
+ //#endregion
1215
+ //#region src/node/plugin/vite/virtual/search-index.ts
1216
+ var Et = "\0@typedown/search-index", Dt = class {
1217
+ indexer = new bt();
1218
+ load(e) {
1219
+ return `export default ${JSON.stringify(this.indexer.serialize())}`;
1220
+ }
1221
+ index(e) {
1222
+ xt(e, this.indexer);
1223
+ }
1224
+ reindex(e, t) {
1225
+ St(e, t, this.indexer);
1226
+ }
1227
+ invalidate(e) {
1228
+ X(e, Et);
1229
+ }
1230
+ }, Q = fe(import.meta.url);
1231
+ function Ot() {
1232
+ return [{
1233
+ find: "vue/server-renderer",
1234
+ replacement: Q.resolve("vue/server-renderer")
1235
+ }, {
1236
+ find: "vue",
1237
+ replacement: Q.resolve("vue/dist/vue.runtime.esm-bundler.js")
1238
+ }];
1239
+ }
1240
+ //#endregion
1241
+ //#region src/node/plugin/vite/middleware/vault-assets.ts
1242
+ var kt = {
1243
+ jpg: "image/jpeg",
1244
+ jpeg: "image/jpeg",
1245
+ png: "image/png",
1246
+ gif: "image/gif",
1247
+ webp: "image/webp",
1248
+ svg: "image/svg+xml",
1249
+ avif: "image/avif",
1250
+ ico: "image/x-icon",
1251
+ pdf: "application/pdf",
1252
+ zip: "application/zip",
1253
+ mp3: "audio/mpeg",
1254
+ mp4: "video/mp4",
1255
+ webm: "video/webm",
1256
+ woff2: "font/woff2",
1257
+ woff: "font/woff",
1258
+ ttf: "font/ttf"
1259
+ };
1260
+ function At(e, t) {
1261
+ return (n, r, i) => {
1262
+ if (!n.url || n.method !== "GET" || r.writableEnded) return i();
1263
+ let o = _(n.url);
1264
+ if (o.startsWith("/@") || o.startsWith("/node_modules")) return i();
1265
+ let s = o.replace(/^\//, ""), c = x(e.config.root, t.rootDirectory, s);
1266
+ if (ae(c)) try {
1267
+ let e = ce(c);
1268
+ if (e.isFile()) {
1269
+ let t = kt[a(c).slice(1).toLowerCase()] ?? "application/octet-stream";
1270
+ r.setHeader("Content-Type", t), r.setHeader("Content-Length", e.size), ie(c).pipe(r);
1271
+ return;
1272
+ }
1273
+ } catch {}
1274
+ i();
1275
+ };
1276
+ }
1277
+ //#endregion
1278
+ //#region src/node/plugin/vite/middleware/virtual-html.ts
1279
+ function jt(e, t, n) {
1280
+ return (r, i, a) => {
1281
+ if (!r.url) return a();
1282
+ let o = p(_(r.url)), s = p(n.basePath);
1283
+ if (o.startsWith("/@") || o.startsWith("/node_modules") || !o.startsWith(s)) return a();
1284
+ let c = o.slice(s.length);
1285
+ if (c.startsWith("/@") || c.startsWith("/node_modules") || o.includes(".") && !o.endsWith("/index.html")) return a();
1286
+ t.getConfig().then(async (t) => {
1287
+ let a = await e.transformIndexHtml(r.url ?? "", Mt(n, t));
1288
+ i.setHeader("Content-Type", "text/html"), i.end(a);
1289
+ }).catch(() => a());
1290
+ };
1291
+ }
1292
+ function Mt(e, t) {
1293
+ return e.devHtml === void 0 && (e.devHtml = k({
1294
+ title: t.siteTitle,
1295
+ description: t.siteDescription,
1296
+ base: "/",
1297
+ entryScript: st
1298
+ })), e.devHtml;
1299
+ }
1300
+ //#endregion
1301
+ //#region src/node/plugin/vite/index.ts
1302
+ function Nt(e = {}) {
1303
+ let n = e.context, r, i, a, s = new mt(), c = new ht(), l = new vt(), u = new Dt(), d = {
1304
+ devHtml: void 0,
1305
+ basePath: "/",
1306
+ rootDirectory: "vault"
1307
+ };
1308
+ function f() {
1309
+ if (n === void 0) throw Error("typedown plugin not initialized");
1310
+ return n.getTdContext();
1311
+ }
1312
+ return [
1313
+ {
1314
+ name: "vite-plugin-typedown",
1315
+ enforce: "pre",
1316
+ async config(t) {
1317
+ n ||= K(e.root ? x(t.root ?? process.cwd(), e.root) : it(t.root ?? process.cwd())), a = t.base ?? "/";
1318
+ let r = await (await f()).getConfig();
1319
+ return {
1320
+ base: t.base ?? r.basePath,
1321
+ publicDir: r.publicDir,
1322
+ server: {
1323
+ port: 8686,
1324
+ strictPort: !1
1325
+ },
1326
+ resolve: { alias: Ot() },
1327
+ ssr: { noExternal: ["typerighter"] }
1328
+ };
1329
+ },
1330
+ configResolved(e) {
1331
+ i = x(e.root, e.build.outDir);
1332
+ },
1333
+ async buildStart() {
1334
+ if (r) return;
1335
+ let e = await f(), t = await e.getConfig(), n = x(t.rootDir);
1336
+ u.index(n), await l.fetchSync(e);
1337
+ let i = await e.checkVault();
1338
+ if ($(i.diagnostics), 0 < i.errorCount) {
1339
+ let e = i.diagnostics.filter((e) => e.severity === "error").map((e) => ` ${e.filepath}:${e.line}:${e.column} - ${e.message} (${e.code})`);
1340
+ this.error(`Vault check failed with ${i.errorCount} error(s):\n${e.join("\n")}`);
1341
+ }
1342
+ },
1343
+ resolveId(e) {
1344
+ if (e === "/@typedown/app" || e === "@typedown/app") return q;
1345
+ if (e === "@typedown/pages") return ct;
1346
+ if (e.startsWith("@typedown/pages?resource=")) return c.resolvePageData(e);
1347
+ if (e === "@typedown/site-data") return ut;
1348
+ if (e === "@typedown/search-index") return ft;
1349
+ },
1350
+ async load(e) {
1351
+ if (c.isPageDataModule(e)) return c.loadPageData(e, await f());
1352
+ if (e !== "\0@typedown/search-index" && e !== "\0@typedown/site-data" && e !== "\0@typedown/pages" && e !== "\0@typedown/app") return;
1353
+ let t = await f();
1354
+ if (e === "\0@typedown/search-index") return u.load(t);
1355
+ if (e === "\0@typedown/site-data") return l.load(t);
1356
+ if (e === "\0@typedown/pages") return c.load(t);
1357
+ if (e === "\0@typedown/app") return s.load(t);
1358
+ },
1359
+ async configureServer(e) {
1360
+ r = e;
1361
+ let t = await f(), n = await t.getConfig(), i = x(n.rootDir);
1362
+ u.index(i), l.scan(i), l.fetch(t, r), e.httpServer?.once("listening", async () => {
1363
+ let e = await t.checkVault();
1364
+ 0 < e.diagnostics.length && (console.error(""), $(e.diagnostics));
1365
+ }), t.rpc.onConfigChanged(() => {
1366
+ r && (d.devHtml = void 0, l.clear(), s.invalidate(r), c.invalidate(r), Ft(r), l.fetch(t, r));
1367
+ }), t.rpc.onContentChanged(({ content: e, affectedFiles: n = [] }) => {
1368
+ r && (u.reindex(i, e), u.invalidate(r), t.getConfig().then((t) => {
1369
+ if (!r) return;
1370
+ let i = [e, ...n], a = [];
1371
+ for (let e of i) {
1372
+ let n = ee(x(r.config.root, t.rootDir, e)), i = r.moduleGraph.getModulesByFile(n);
1373
+ if (i?.size) {
1374
+ for (let e of i) r?.moduleGraph.invalidateModule(e), a.push(Lt(e));
1375
+ c.invalidatePageData(r, e);
1376
+ }
1377
+ }
1378
+ 0 < a.length && r.hot.send({
1379
+ type: "update",
1380
+ updates: a
1381
+ });
1382
+ }).catch(() => {}));
1383
+ });
1384
+ function a() {
1385
+ r && (u.index(i), u.invalidate(r), c.invalidate(r), l.clear(), l.fetch(t, r));
1386
+ }
1387
+ t.rpc.onContentCreated(a), t.rpc.onContentDeleted(a);
1388
+ function o() {
1389
+ r && (l.clear(), It(r), l.fetch(t, r));
1390
+ }
1391
+ t.rpc.onSchemaChanged(o), t.rpc.onSchemaCreated(o), t.rpc.onSchemaDeleted(o);
1392
+ let p = await t.getConfig();
1393
+ d.basePath = p.basePath, d.rootDirectory = p.rootDir, t.rpc.onConfigChanged((e) => {
1394
+ d.basePath = e.basePath, d.rootDirectory = e.rootDir, d.devHtml = void 0;
1395
+ }), e.middlewares.use(At(e, d)), e.middlewares.use(jt(e, t, d));
1396
+ },
1397
+ async transform(e, n) {
1398
+ let r = n.split("?")[0];
1399
+ if (!o(r)) return;
1400
+ if (t(r)) return {
1401
+ code: "<script>import { TdNotFound } from 'typerighter/client/theme-default'; export default TdNotFound; export const pageData = { frontmatter: {}, headings: [], title: '' };<\/script>",
1402
+ map: null
1403
+ };
1404
+ let i = await f(), a = (await i.getConfig()).rootDir, s = r.includes(a) ? r.slice(r.indexOf(a) + a.length + 1) : r;
1405
+ try {
1406
+ let { vueSrc: e } = await et(i, await i.getFile(s), s);
1407
+ return {
1408
+ code: e,
1409
+ map: null
1410
+ };
1411
+ } catch (e) {
1412
+ if (U(e)) return;
1413
+ let t = e instanceof Error ? e.message : String(e);
1414
+ this.error(`[typedown] Failed to transform ${s}: ${t}`);
1415
+ }
1416
+ },
1417
+ handleHotUpdate({ file: e }) {
1418
+ if (o(e)) return [];
1419
+ },
1420
+ async closeBundle() {
1421
+ if (!e.context && n) try {
1422
+ let e = (await (await n.getTdContext()).getConfig()).basePath, t = e.startsWith(a) ? e.slice(a.length) : e.replace(/^\//, "");
1423
+ await M(n, {
1424
+ outDir: x(i, t),
1425
+ base: e
1426
+ });
1427
+ } finally {
1428
+ n.dispose();
1429
+ }
1430
+ }
1431
+ },
1432
+ w({
1433
+ include: e.root ? RegExp(`${e.root.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/.*\\.(?:vue|td)$`) : /\.(?:vue|td)$/,
1434
+ template: { transformAssetUrls: !1 }
1435
+ }),
1436
+ ...C()
1437
+ ];
1438
+ }
1439
+ function Pt(e) {
1440
+ return [...e.moduleGraph.idToModuleMap.entries()].filter(([e]) => e.endsWith(".td")).map(([, e]) => e);
1441
+ }
1442
+ function Ft(e) {
1443
+ for (let t of Pt(e)) e.moduleGraph.invalidateModule(t);
1444
+ e.hot.send({ type: "full-reload" });
1445
+ }
1446
+ function It(e) {
1447
+ let t = Pt(e).map((t) => (e.moduleGraph.invalidateModule(t), Lt(t)));
1448
+ 0 < t.length && e.hot.send({
1449
+ type: "update",
1450
+ updates: t
1451
+ });
1452
+ }
1453
+ function Lt(e) {
1454
+ return {
1455
+ type: "js-update",
1456
+ path: e.url,
1457
+ acceptedPath: e.url,
1458
+ timestamp: Date.now()
1459
+ };
1460
+ }
1461
+ function $(e) {
1462
+ for (let t of e) {
1463
+ let e = `${t.filepath}:${t.line}:${t.column}`, n = t.severity === "error" ? S.red("error") : S.yellow("warn");
1464
+ console.error(` ${n} ${e} ${t.message} ${S.dim(`(${t.code})`)}`);
1465
+ }
1466
+ }
1467
+ //#endregion
1468
+ export { M as a, K as i, Z as n, G as r, Nt as t };