typerighter 0.7.0 → 0.9.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.

Potentially problematic release.


This version of typerighter might be problematic. Click here for more details.

Files changed (37) hide show
  1. package/dist/app-C-qfoH4a.js +373 -0
  2. package/dist/brand-CG1fQshq.js +5 -0
  3. package/dist/{cli-CDd4TNg1.js → cli-mg9QpUrf.js} +159 -132
  4. package/dist/cli.js +1 -1
  5. package/dist/client/app/index.d.ts +12 -3
  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 +541 -417
  10. package/dist/client.js +1 -1
  11. package/dist/es-CG8rP6j5.js +22524 -0
  12. package/dist/index.js +2 -2
  13. package/dist/{init-Bfnl0t1B.js → init-BSgCv7vy.js} +664 -654
  14. package/dist/node/build/index.d.ts.map +1 -1
  15. package/dist/node/build/prerender.d.ts +2 -0
  16. package/dist/node/build/prerender.d.ts.map +1 -1
  17. package/dist/node/plugin/vite/index.d.ts.map +1 -1
  18. package/dist/shared/utils/field.d.ts +2 -0
  19. package/dist/shared/utils/field.d.ts.map +1 -0
  20. package/dist/shared/utils/index.d.ts +1 -0
  21. package/dist/shared/utils/index.d.ts.map +1 -1
  22. package/dist/shared/utils/url.d.ts +5 -0
  23. package/dist/shared/utils/url.d.ts.map +1 -1
  24. package/dist/shared-BIdsxcZ2.js +265 -0
  25. package/dist/shared.js +2 -0
  26. package/dist/typerighter.css +1 -1
  27. package/dist/vite-8CV23ALg.js +10704 -0
  28. package/dist/vite.js +1 -1
  29. package/package.json +7 -3
  30. package/dist/app-Bf0aLzaG.js +0 -370
  31. package/dist/brand-BfamszbH.js +0 -12
  32. package/dist/client/app/composables/useUrl.d.ts +0 -6
  33. package/dist/client/app/composables/useUrl.d.ts.map +0 -1
  34. package/dist/constants-DJbUAb1-.js +0 -32189
  35. package/dist/es-ClqUVRJn.js +0 -705
  36. package/dist/shared-CpPZZ8IH.js +0 -196
  37. package/dist/vite-DnP-_NzR.js +0 -326
@@ -1,196 +0,0 @@
1
- //#region src/shared/constants.ts
2
- var e = "index", t = [".td", ".md"], n = "**/*.{td,md}", r = [
3
- "title",
4
- "titles",
5
- "text"
6
- ], i = ["title", "titles"], a = /^[a-z]+:/i;
7
- //#endregion
8
- //#region src/shared/utils/format.ts
9
- function o(e) {
10
- let t = e.match(/^(\d+)[-_](.+)$/);
11
- return t ? {
12
- order: Number(t[1]),
13
- rest: t[2]
14
- } : {
15
- order: Infinity,
16
- rest: e
17
- };
18
- }
19
- function s(e) {
20
- let { rest: t } = o(e), n = t.replace(/[-_]/g, " ").split(" ");
21
- return 0 < n.length && (n[0] = n[0].charAt(0).toUpperCase() + n[0].slice(1)), n.join(" ");
22
- }
23
- //#endregion
24
- //#region src/shared/utils/path.ts
25
- function c(e, t) {
26
- let n = h(e).split("/").pop() ?? "";
27
- return t !== void 0 && n.endsWith(t) ? n.slice(0, -t.length) : n;
28
- }
29
- function l(e) {
30
- let t = h(e).split("/");
31
- return t.pop(), t.join("/");
32
- }
33
- function u(e) {
34
- let t = c(e), n = t.lastIndexOf(".");
35
- return n <= 0 ? "" : t.slice(n);
36
- }
37
- function d(e) {
38
- let t = c(e), n = t.lastIndexOf(".");
39
- return n <= 0 ? t : t.slice(0, n);
40
- }
41
- function f(e) {
42
- return t.includes(u(e));
43
- }
44
- function p(...e) {
45
- return e.filter(Boolean).join("/").replace(/\\+/g, "/").replace(/\/+/g, "/").replace(/\/$/, "") || "/";
46
- }
47
- function m(e) {
48
- let t = u(e);
49
- return t ? e.slice(0, -t.length) : e;
50
- }
51
- function h(e) {
52
- return e.replace(/\\/g, "/");
53
- }
54
- //#endregion
55
- //#region src/shared/utils/url.ts
56
- var g = new Set("3g2,3gp,aac,ai,apng,au,avif,bin,bmp,cer,class,conf,crl,css,csv,dll,doc,eps,epub,exe,gif,gz,ics,ief,jar,jpe,jpeg,jpg,js,json,jsonld,m4a,man,mid,midi,mjs,mov,mp2,mp3,mp4,mpe,mpeg,mpg,mpp,oga,ogg,ogv,ogx,opus,otf,p10,p7c,p7m,p7s,pdf,png,ps,qt,roff,rtf,rtx,ser,svg,t,tif,tiff,tr,ts,tsv,ttf,txt,vtt,wav,weba,webm,webp,woff,woff2,xhtml,xml,yaml,yml,zip".split(","));
57
- function _(e, t) {
58
- return `${e}/${t}`;
59
- }
60
- function v(e) {
61
- return l(e.replace(/\/$/, "")) || "/";
62
- }
63
- function y(e) {
64
- let t = d(e);
65
- return "/" + p(l(e), t);
66
- }
67
- function b(e, t) {
68
- return t.startsWith(e + "/") || t === e;
69
- }
70
- function x(e) {
71
- return a.test(e);
72
- }
73
- function S(e) {
74
- let t = u(e).slice(1);
75
- return t === "" || !g.has(t.toLowerCase());
76
- }
77
- function C(e) {
78
- let t = e.indexOf("#");
79
- return 0 <= t ? e.slice(0, t) : e;
80
- }
81
- //#endregion
82
- //#region src/shared/utils/content.ts
83
- function w(e) {
84
- let t = {
85
- name: "",
86
- children: [],
87
- items: []
88
- };
89
- for (let n of e) {
90
- let e = n.filepath.split("/").slice(0, -1), r = t;
91
- for (let t of e) {
92
- let e = r.children.find((e) => e.name === t);
93
- e || (e = {
94
- name: t,
95
- children: [],
96
- items: []
97
- }, r.children.push(e)), r = e;
98
- }
99
- r.items.push(n);
100
- }
101
- return O(t), {
102
- rootItems: t.items,
103
- children: t.children
104
- };
105
- }
106
- function T(t, n) {
107
- let r = {};
108
- function i(e) {
109
- let t = e.items.length;
110
- for (let n of e.children) t += i(n);
111
- return t;
112
- }
113
- function a(t, n) {
114
- let r = t.items.find((t) => d(t.filepath) === e);
115
- return r ? y(r.filepath) : `${n}/${t.name}/index`;
116
- }
117
- function o(e, t) {
118
- for (let n of e) {
119
- let e = t ? `${t}/${n.name}` : `/${n.name}`;
120
- r[e] = {
121
- title: s(n.name),
122
- url: e,
123
- subdirectories: n.children.map((t) => ({
124
- name: s(t.name),
125
- url: a(t, e),
126
- count: i(t)
127
- })),
128
- items: n.items.map((e) => ({
129
- name: D(e.header, e.filepath),
130
- url: y(e.filepath)
131
- }))
132
- }, o(n.children, e);
133
- }
134
- }
135
- return r["/"] = {
136
- title: n,
137
- url: "/",
138
- subdirectories: t.map((e) => ({
139
- name: s(e.name),
140
- url: a(e, ""),
141
- count: i(e)
142
- })),
143
- items: []
144
- }, o(t, ""), r;
145
- }
146
- function E(e, t) {
147
- let n = c(l(e));
148
- return n ? s(n) : t;
149
- }
150
- function D(e, t) {
151
- if (e._label !== void 0) return String(e._label);
152
- let n = d(t);
153
- if (n === "index") {
154
- let e = c(l(t));
155
- return e ? s(e) : n;
156
- }
157
- return s(n);
158
- }
159
- function O(e) {
160
- e.children.sort((e, t) => {
161
- let n = o(e.name), r = o(t.name);
162
- return n.order === r.order ? n.rest.localeCompare(r.rest) : n.order - r.order;
163
- }), e.items.sort((e, t) => {
164
- let n = o(d(e.filepath)), r = o(d(t.filepath));
165
- return n.order === r.order ? D(e.header, e.filepath).localeCompare(D(t.header, t.filepath)) : n.order - r.order;
166
- });
167
- for (let t of e.children) O(t);
168
- }
169
- //#endregion
170
- //#region src/shared/utils/time.ts
171
- var k = 60, A = 60 * k, j = 24 * A, M = 7 * j, N = 30 * j, P = 365 * j, F = 2 * M;
172
- function I(e) {
173
- return (/* @__PURE__ */ new Date(e * 1e3)).toLocaleDateString("en-US", {
174
- year: "numeric",
175
- month: "short",
176
- day: "numeric"
177
- });
178
- }
179
- function L(e, t) {
180
- return Math.floor(Date.now() / 1e3) - e < F ? `${t} ${R(e)}` : `${t} at ${I(e)}`;
181
- }
182
- function R(e) {
183
- let t = Math.floor(Date.now() / 1e3) - e;
184
- return t < k ? "just now" : t < A ? `${Math.floor(t / k)}m ago` : t < j ? `${Math.floor(t / A)}h ago` : t < M ? `${Math.floor(t / j)}d ago` : t < N ? `${Math.floor(t / M)}w ago` : t < P ? `${Math.floor(t / N)}mo ago` : `${Math.floor(t / P)}y ago`;
185
- }
186
- var z = new Intl.DateTimeFormat("en-US", {
187
- year: "numeric",
188
- month: "short",
189
- day: "numeric"
190
- });
191
- function B(e) {
192
- let t = new Date(e);
193
- return Number.isNaN(t.getTime()) ? e : z.format(t);
194
- }
195
- //#endregion
196
- export { r as C, e as S, m as _, T as a, t as b, _ as c, b as d, x as f, f as g, d as h, w as i, v as l, C as m, L as n, E as o, S as p, R as r, D as s, B as t, y as u, s as v, i as w, n as x, a as y };
@@ -1,326 +0,0 @@
1
- import { i as e, n as t, o as n, r, s as i, t as a } from "./constants-DJbUAb1-.js";
2
- import { C as o, S as s, a as c, b as l, g as u, h as d, i as f, o as p, s as m, u as h, w as g } from "./shared-CpPZZ8IH.js";
3
- import { o as _, r as v, s as y } from "./brand-BfamszbH.js";
4
- import { t as b } from "./es-ClqUVRJn.js";
5
- import { resolve as x } from "node:path";
6
- import S from "picocolors";
7
- import C from "@tailwindcss/vite";
8
- import w from "@vitejs/plugin-vue";
9
- import { normalizePath as T } from "vite";
10
- import { createRequire as E } from "node:module";
11
- //#region src/node/lib/render/vue.ts
12
- async function D(e, t, n) {
13
- let r = {
14
- path: n,
15
- relativePath: n,
16
- cleanUrls: !0
17
- }, i = await e.md.renderAsync(t.content, r), a = d(n) === s, o = r.title || (a ? p(n, (await e.getConfig()).siteTitle) : m(t.header, n)), c = {
18
- schema: t.schema,
19
- frontmatter: t.header,
20
- headings: r.headers ?? [],
21
- title: o,
22
- metadata: t.metadata
23
- };
24
- return {
25
- vueSrc: [
26
- "<script>",
27
- `export const __pageData = JSON.parse(${JSON.stringify(JSON.stringify(c))})`,
28
- `export default { name: ${JSON.stringify(n)} }`,
29
- "<\/script>",
30
- `<template><div class="typedown-content">\n${O(i)}\n</div></template>`
31
- ].join("\n"),
32
- pageData: c
33
- };
34
- }
35
- function O(e) {
36
- return e.replaceAll("{{", "&#123;&#123;");
37
- }
38
- //#endregion
39
- //#region src/node/plugin/vite/search.ts
40
- var k = /<h(\d*).*?>(.*?<a.*? href="#.*?".*?>.*?<\/a>)<\/h\1>/gi, A = /(.*)<a.*? href="#(.*?)".*?>.*?<\/a>/i, j = class {
41
- index;
42
- pageDocIds = /* @__PURE__ */ new Map();
43
- constructor() {
44
- this.index = new b({
45
- fields: o,
46
- storeFields: g
47
- });
48
- }
49
- addAll(e) {
50
- let t = new Set(e.map((e) => e.id));
51
- for (let e of this.pageDocIds.keys()) t.has(e) || this.discardPage(e);
52
- for (let t of e) this.addPage(t);
53
- }
54
- addPage(e) {
55
- this.discardPage(e.id);
56
- let t = [];
57
- for (let n of M(e.html)) {
58
- let r = n.anchor ? `${e.id}#${n.anchor}` : e.id;
59
- this.index.has(r) && this.index.discard(r), this.index.add({
60
- id: r,
61
- text: n.text,
62
- title: n.titles.at(-1) ?? e.title,
63
- titles: 1 < n.titles.length ? n.titles.slice(0, -1) : [e.title]
64
- }), t.push(r);
65
- }
66
- this.pageDocIds.set(e.id, t);
67
- }
68
- discardPage(e) {
69
- let t = this.pageDocIds.get(e);
70
- if (t) {
71
- for (let e of t) this.index.has(e) && this.index.discard(e);
72
- this.pageDocIds.delete(e);
73
- }
74
- }
75
- serialize() {
76
- return JSON.stringify(this.index);
77
- }
78
- };
79
- function* M(e) {
80
- let t = e.split(k);
81
- t.shift();
82
- let n = [];
83
- for (let e = 0; e < t.length; e += 3) {
84
- let r = Number.parseInt(t[e]) - 1, i = t[e + 1], a = A.exec(i), o = y(a?.[1] ?? "").trim(), s = a?.[2] ?? "", c = t[e + 2];
85
- if (!o || !c) continue;
86
- let l = n.slice(0, r);
87
- l[r] = o, yield {
88
- anchor: s,
89
- titles: l.filter(Boolean),
90
- text: y(c)
91
- }, r === 0 ? (n.length = 0, n[0] = o) : n[r] = o;
92
- }
93
- }
94
- //#endregion
95
- //#region src/node/plugin/vite/alias.ts
96
- var N = E(import.meta.url);
97
- function P() {
98
- return [{
99
- find: "vue/server-renderer",
100
- replacement: N.resolve("vue/server-renderer")
101
- }, {
102
- find: "vue",
103
- replacement: N.resolve("vue/dist/vue.runtime.esm-bundler.js")
104
- }];
105
- }
106
- //#endregion
107
- //#region src/node/plugin/vite/index.ts
108
- function F(e) {
109
- let { contentDir: t } = e, n = `/${t}/**/*.{td,md}`, i = JSON.stringify({
110
- title: e.siteTitle,
111
- description: e.siteDescription,
112
- basePath: e.basePath ?? "/",
113
- repo: e.repo
114
- }), a = c(e.contentTree.children, e.siteTitle), o = JSON.stringify({
115
- contentTree: e.contentTree,
116
- schemas: e.schemas ?? {},
117
- directoryListings: a
118
- });
119
- return `
120
- import 'typerighter/style.css';
121
- import { createTypedownApp } from 'typerighter/client';
122
- import { TdDirectoryIndex } from 'typerighter/client/theme-default';
123
- import { h } from 'vue';
124
- import theme from 'typerighter/client/theme-default';
125
- import searchIndex from '${r}';
126
-
127
- const pages = import.meta.glob('${n}');
128
- const contentExts = ${JSON.stringify(l)};
129
- const siteData = { ...${o}, searchIndex };
130
-
131
- function findPage(base) {
132
- for (const ext of contentExts) {
133
- const key = base + ext;
134
- if (pages[key]) return pages[key];
135
- }
136
- }
137
-
138
- async function loadPageModule(pagePath) {
139
- const base = ('/${t}/' + pagePath).replace(/\\/+/g, '/').replace(/\\/$/, '');
140
- const loader = findPage(base);
141
- if (loader) return loader();
142
-
143
- // Only /xxx/index paths get the directory listing fallback
144
- if (pagePath.endsWith('/index')) {
145
- const dirPath = pagePath.slice(0, -'/index'.length) || '/';
146
- const dir = siteData.directoryListings[dirPath] || siteData.directoryListings[dirPath + '/'];
147
- if (dir) return {
148
- default: { name: 'DirectoryIndex', render() { return h(TdDirectoryIndex); } },
149
- __pageData: { frontmatter: {}, headings: [], title: dir.title },
150
- };
151
- }
152
-
153
- return undefined;
154
- }
155
-
156
- const { app, searchIndex: searchIndexRef } = await createTypedownApp(loadPageModule, theme.Layout, ${i}, siteData);
157
- app.mount('#app');
158
-
159
- // Accept HMR for the search index so it updates without a full reload
160
- if (import.meta.hot) {
161
- import.meta.hot.accept('${r}', (m) => {
162
- if (m) searchIndexRef.value = m.default;
163
- });
164
- }
165
- `;
166
- }
167
- function I(r = {}) {
168
- let o = r.context, s, c = new j(), l;
169
- function d() {
170
- if (o === void 0) throw Error("typedown plugin not initialized");
171
- return o.getTdContext();
172
- }
173
- return [
174
- {
175
- name: "vite-plugin-typedown",
176
- enforce: "pre",
177
- configResolved(e) {
178
- o ||= n(i(e.root));
179
- },
180
- config() {
181
- return {
182
- resolve: { alias: P() },
183
- ssr: { noExternal: ["typerighter"] }
184
- };
185
- },
186
- async buildStart() {
187
- let e = await (await d()).checkVault();
188
- if (0 < e.errorCount || 0 < e.warningCount) for (let t of e.diagnostics) {
189
- let e = `${t.filepath}:${t.line}:${t.column}`, n = t.severity === "error" ? S.red("error") : S.yellow("warn");
190
- console.error(` ${n} ${e} ${t.message} ${S.dim(`(${t.code})`)}`);
191
- }
192
- if (!s && 0 < e.errorCount) {
193
- let t = e.diagnostics.filter((e) => e.severity === "error").map((e) => ` ${e.filepath}:${e.line}:${e.column} - ${e.message} (${e.code})`);
194
- this.error(`Vault check failed with ${e.errorCount} error(s):\n${t.join("\n")}`);
195
- }
196
- },
197
- resolveId(e) {
198
- if (e === "/@typedown/app" || e === "@typedown/app") return t;
199
- if (e === "@typedown/search-index") return a;
200
- },
201
- async load(e) {
202
- if (e === "\0@typedown/search-index") return l ||= V(await d(), c), await l, `export default ${JSON.stringify(c.serialize())}`;
203
- if (e !== "\0@typedown/app") return;
204
- let t = await d(), [n, r, i] = await Promise.all([
205
- t.getConfig(),
206
- t.listFilesGroupedBySchema(),
207
- t.listSchemas()
208
- ]), a = await Promise.all(i.map(async (e) => [e, (await t.getSchema(e)).properties])), o = Object.fromEntries(a), s = f(Object.values(r).flat());
209
- return F({
210
- ...n,
211
- contentTree: s,
212
- schemas: o
213
- });
214
- },
215
- async configureServer(t) {
216
- s = t;
217
- let n = await d();
218
- n.rpc.onConfigChanged(() => s && z(s)), n.rpc.onContentChanged(({ content: e }) => {
219
- s && (L(n, e).then((e) => {
220
- e && s && (c.addPage(e), H(s));
221
- }).catch(() => {}), n.getConfig().then((t) => {
222
- if (!s) return;
223
- let n = T(x(s.config.root, t.contentDir, e)), r = s.moduleGraph.getModulesByFile(n);
224
- if (!r?.size) return;
225
- let i = [...r].map((e) => (s?.moduleGraph.invalidateModule(e), U(e)));
226
- s.hot.send({
227
- type: "update",
228
- updates: i
229
- });
230
- }).catch(() => {}));
231
- });
232
- function r() {
233
- s && (l = V(n, c), l.then(() => {
234
- s && H(s);
235
- }), B(s));
236
- }
237
- return n.rpc.onContentCreated(r), n.rpc.onContentDeleted(r), n.rpc.onSchemaChanged(() => s && B(s)), n.rpc.onSchemaCreated(() => s && B(s)), n.rpc.onSchemaDeleted(() => s && B(s)), () => {
238
- t.middlewares.use((t, r, i) => {
239
- if (!t.url || r.writableEnded || t.url.startsWith("/@") || t.url.startsWith("/node_modules") || t.url.includes(".")) return i();
240
- n.getConfig().then((t) => {
241
- let n = `<!DOCTYPE html>
242
- <html lang="en">
243
- <head>
244
- <meta charset="UTF-8">
245
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
246
- <title>${_(t.siteTitle)}</title>
247
- <link rel="icon" type="image/svg+xml" href="${v}">
248
- </head>
249
- <body>
250
- <div id="app"></div>
251
- <script type="module" src="/${e}"><\/script>
252
- </body>
253
- </html>`;
254
- r.setHeader("Content-Type", "text/html"), r.end(n);
255
- }).catch(i);
256
- });
257
- };
258
- },
259
- async transform(e, t) {
260
- let n = t.split("?")[0];
261
- if (!u(n)) return;
262
- let r = await d(), i = (await r.getConfig()).contentDir, a = n.includes(i) ? n.slice(n.indexOf(i) + i.length + 1) : n, { vueSrc: o } = await D(r, await r.getFile(a), a);
263
- return {
264
- code: o,
265
- map: null
266
- };
267
- },
268
- handleHotUpdate({ file: e }) {
269
- if (u(e)) return [];
270
- }
271
- },
272
- w({ include: /\.(?:vue|td)$/ }),
273
- ...C()
274
- ];
275
- }
276
- async function L(e, t) {
277
- try {
278
- let n = await e.getFile(t), r = await e.md.renderAsync(n.content, {
279
- path: t,
280
- relativePath: t,
281
- cleanUrls: !0
282
- });
283
- return {
284
- id: h(t),
285
- title: m(n.header, t),
286
- html: r
287
- };
288
- } catch {
289
- return;
290
- }
291
- }
292
- function R(e) {
293
- return [...e.moduleGraph.idToModuleMap.entries()].filter(([e]) => e.endsWith(".td")).map(([, e]) => e);
294
- }
295
- function z(e) {
296
- for (let t of R(e)) e.moduleGraph.invalidateModule(t);
297
- e.hot.send({ type: "full-reload" });
298
- }
299
- function B(e) {
300
- let t = R(e).map((t) => (e.moduleGraph.invalidateModule(t), U(t)));
301
- 0 < t.length && e.hot.send({
302
- type: "update",
303
- updates: t
304
- });
305
- }
306
- async function V(e, t) {
307
- let n = await e.listFiles(), r = await Promise.all(n.map((t) => L(e, t)));
308
- t.addAll(r.filter((e) => e !== void 0));
309
- }
310
- function H(e) {
311
- let t = e.moduleGraph.getModuleById(a);
312
- t && (e.moduleGraph.invalidateModule(t), e.hot.send({
313
- type: "update",
314
- updates: [U(t)]
315
- }));
316
- }
317
- function U(e) {
318
- return {
319
- type: "js-update",
320
- path: e.url,
321
- acceptedPath: e.url,
322
- timestamp: Date.now()
323
- };
324
- }
325
- //#endregion
326
- export { I as n, F as t };