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