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

@@ -1,24 +1,47 @@
1
- import { f as isUrlExternal, p as isUrlToPage, y as EXTERNAL_URL_RE } from "./shared-CpPZZ8IH.js";
2
- import path from "node:path";
1
+ import { B as __toESM, C as isUrlToPage, D as filestem, I as INDEX_FILENAME, L as SEARCH_FIELDS, N as EXTERNAL_URL_RE, O as isContentFile, P as CONTENT_EXTENSIONS, R as SEARCH_STORE_FIELDS, S as isUrlExternal, c as stripHtml, d as buildContentTree, f as buildDirectoryListingMap, m as getTdResourceTitle, p as getTdIndexTitle, s as escapeHtml$2, y as getTdContentUrl, z as __commonJSMin } from "./shared-BIdsxcZ2.js";
2
+ import { o as MiniSearch, r as BRAND_FAVICON_URI } from "./brand-CJDq15GW.js";
3
+ import path, { resolve } from "node:path";
3
4
  import pc from "picocolors";
4
- import { createLogger } from "vite";
5
+ import tailwindcss from "@tailwindcss/vite";
6
+ import vue from "@vitejs/plugin-vue";
7
+ import { createLogger, normalizePath } from "vite";
5
8
  import fs from "node:fs";
6
9
  import { RpcServer } from "@typerighter/rpc-server";
7
10
  import { RpcClient } from "@typerighter/rpc-client";
8
11
  import MarkdownIt from "markdown-it";
9
12
  import { createHighlighter, guessEmbeddedLanguages, isSpecialLang } from "shiki";
10
13
  import { URL as URL$1 } from "node:url";
11
- //#region \0rolldown/runtime.js
12
- var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (A, j) => () => (j || (A((j = { exports: {} }).exports, j), A = null), j.exports), __copyProps = (A, j, M, N) => {
13
- if (j && typeof j == "object" || typeof j == "function") for (var P = __getOwnPropNames(j), F = 0, I = P.length, L; F < I; F++) L = P[F], !__hasOwnProp.call(A, L) && L !== M && __defProp(A, L, {
14
- get: ((A) => j[A]).bind(null, L),
15
- enumerable: !(N = __getOwnPropDesc(j, L)) || N.enumerable
16
- });
17
- return A;
18
- }, __toESM = (A, j, M) => (M = A == null ? {} : __create(__getProtoOf(A)), __copyProps(j || !A || !A.__esModule ? __defProp(M, "default", {
19
- value: A,
20
- enumerable: !0
21
- }) : M, A)), require___vite_browser_external = /* @__PURE__ */ __commonJSMin(((A, j) => {
14
+ import { createRequire } from "node:module";
15
+ //#region src/node/lib/render/vue.ts
16
+ async function renderToVueSfc(A, j, M) {
17
+ let N = {
18
+ path: M,
19
+ relativePath: M,
20
+ cleanUrls: !0
21
+ }, P = await A.md.renderAsync(j.content, N), F = filestem(M) === INDEX_FILENAME, I = N.title || (F ? getTdIndexTitle(M, (await A.getConfig()).siteTitle) : getTdResourceTitle(j.header, M)), L = {
22
+ schema: j.schema,
23
+ frontmatter: j.header,
24
+ headings: N.headers ?? [],
25
+ title: I,
26
+ metadata: j.metadata
27
+ };
28
+ return {
29
+ vueSrc: [
30
+ "<script>",
31
+ `export const __pageData = JSON.parse(${JSON.stringify(JSON.stringify(L))})`,
32
+ `export default { name: ${JSON.stringify(M)} }`,
33
+ "<\/script>",
34
+ `<template><div class="typedown-content">\n${neutralizeInterpolation(P)}\n</div></template>`
35
+ ].join("\n"),
36
+ pageData: L
37
+ };
38
+ }
39
+ function neutralizeInterpolation(A) {
40
+ return A.replaceAll("{{", "&#123;&#123;");
41
+ }
42
+ //#endregion
43
+ //#region __vite-browser-external
44
+ var require___vite_browser_external = /* @__PURE__ */ __commonJSMin(((A, j) => {
22
45
  j.exports = {};
23
46
  })), require_kind_of = /* @__PURE__ */ __commonJSMin(((A, j) => {
24
47
  var M = Object.prototype.toString;
@@ -32184,6 +32207,290 @@ function initializeLogFile(A) {
32184
32207
  }
32185
32208
  //#endregion
32186
32209
  //#region src/node/plugin/vite/constants.ts
32187
- var VIRTUAL_APP_ID = "@typedown/app", RESOLVED_VIRTUAL_APP_ID = "\0@typedown/app", SEARCH_INDEX_ID = "@typedown/search-index", RESOLVED_SEARCH_INDEX_ID = "\0@typedown/search-index";
32210
+ var VIRTUAL_APP_ID = "@typedown/app", RESOLVED_VIRTUAL_APP_ID = "\0@typedown/app", SEARCH_INDEX_ID = "@typedown/search-index", RESOLVED_SEARCH_INDEX_ID = "\0@typedown/search-index", headingRegex = /<h(\d*).*?>(.*?<a.*? href="#.*?".*?>.*?<\/a>)<\/h\1>/gi, headingContentRegex = /(.*)<a.*? href="#(.*?)".*?>.*?<\/a>/i, SearchIndexer = class {
32211
+ index;
32212
+ pageDocIds = /* @__PURE__ */ new Map();
32213
+ constructor() {
32214
+ this.index = new MiniSearch({
32215
+ fields: SEARCH_FIELDS,
32216
+ storeFields: SEARCH_STORE_FIELDS
32217
+ });
32218
+ }
32219
+ addAll(A) {
32220
+ let j = new Set(A.map((A) => A.id));
32221
+ for (let A of this.pageDocIds.keys()) j.has(A) || this.discardPage(A);
32222
+ for (let j of A) this.addPage(j);
32223
+ }
32224
+ addPage(A) {
32225
+ this.discardPage(A.id);
32226
+ let j = [];
32227
+ for (let M of splitPageIntoSections(A.html)) {
32228
+ let N = M.anchor ? `${A.id}#${M.anchor}` : A.id;
32229
+ this.index.has(N) && this.index.discard(N), this.index.add({
32230
+ id: N,
32231
+ text: M.text,
32232
+ title: M.titles.at(-1) ?? A.title,
32233
+ titles: 1 < M.titles.length ? M.titles.slice(0, -1) : [A.title]
32234
+ }), j.push(N);
32235
+ }
32236
+ this.pageDocIds.set(A.id, j);
32237
+ }
32238
+ discardPage(A) {
32239
+ let j = this.pageDocIds.get(A);
32240
+ if (j) {
32241
+ for (let A of j) this.index.has(A) && this.index.discard(A);
32242
+ this.pageDocIds.delete(A);
32243
+ }
32244
+ }
32245
+ serialize() {
32246
+ return JSON.stringify(this.index);
32247
+ }
32248
+ };
32249
+ function* splitPageIntoSections(A) {
32250
+ let j = A.split(headingRegex);
32251
+ j.shift();
32252
+ let M = [];
32253
+ for (let A = 0; A < j.length; A += 3) {
32254
+ let N = Number.parseInt(j[A]) - 1, P = j[A + 1], F = headingContentRegex.exec(P), I = stripHtml(F?.[1] ?? "").trim(), L = F?.[2] ?? "", R = j[A + 2];
32255
+ if (!I || !R) continue;
32256
+ let z = M.slice(0, N);
32257
+ z[N] = I, yield {
32258
+ anchor: L,
32259
+ titles: z.filter(Boolean),
32260
+ text: stripHtml(R)
32261
+ }, N === 0 ? (M.length = 0, M[0] = I) : M[N] = I;
32262
+ }
32263
+ }
32264
+ //#endregion
32265
+ //#region src/node/plugin/vite/alias.ts
32266
+ var require$1 = createRequire(import.meta.url);
32267
+ function resolveAliases() {
32268
+ return [{
32269
+ find: "vue/server-renderer",
32270
+ replacement: require$1.resolve("vue/server-renderer")
32271
+ }, {
32272
+ find: "vue",
32273
+ replacement: require$1.resolve("vue/dist/vue.runtime.esm-bundler.js")
32274
+ }];
32275
+ }
32276
+ //#endregion
32277
+ //#region src/node/plugin/vite/index.ts
32278
+ function generateClientAppEntry(A) {
32279
+ let { contentDir: j } = A, M = `/${j}/**/*.{td,md}`, N = JSON.stringify({
32280
+ title: A.siteTitle,
32281
+ description: A.siteDescription,
32282
+ basePath: A.basePath ?? "/",
32283
+ repo: A.repo
32284
+ }), P = buildDirectoryListingMap(A.contentTree.children, A.siteTitle), F = JSON.stringify({
32285
+ contentTree: A.contentTree,
32286
+ schemas: A.schemas ?? {},
32287
+ directoryListings: P
32288
+ });
32289
+ return `
32290
+ import 'typerighter/style.css';
32291
+ import { createTypedownApp } from 'typerighter/client';
32292
+ import { TdDirectoryIndex } from 'typerighter/client/theme-default';
32293
+ import { isIndexUrl, getDirectoryFromPageUrl } from 'typerighter/shared';
32294
+ import { h } from 'vue';
32295
+ import theme from 'typerighter/client/theme-default';
32296
+ import searchIndex from '${SEARCH_INDEX_ID}';
32297
+
32298
+ const pages = import.meta.glob('${M}');
32299
+ const contentExts = ${JSON.stringify(CONTENT_EXTENSIONS)};
32300
+ const siteData = { ...${F}, searchIndex };
32301
+
32302
+ function findPage(base) {
32303
+ for (const ext of contentExts) {
32304
+ const key = base + ext;
32305
+ if (pages[key]) return pages[key];
32306
+ }
32307
+ }
32308
+
32309
+ async function loadPageModule(pagePath) {
32310
+ const base = ('/${j}/' + pagePath).replace(/\\/+/g, '/').replace(/\\/$/, '');
32311
+ const loader = findPage(base);
32312
+ if (loader) return loader();
32313
+
32314
+ if (isIndexUrl(pagePath)) {
32315
+ const dirPath = getDirectoryFromPageUrl(pagePath);
32316
+ const dir = siteData.directoryListings[dirPath];
32317
+ if (dir) return {
32318
+ default: { name: 'DirectoryIndex', render() { return h(TdDirectoryIndex); } },
32319
+ __pageData: { frontmatter: {}, headings: [], title: dir.title },
32320
+ };
32321
+ }
32322
+
32323
+ return undefined;
32324
+ }
32325
+
32326
+ const { app, searchIndex: searchIndexRef } = await createTypedownApp(loadPageModule, theme.Layout, ${N}, siteData);
32327
+ app.mount('#app');
32328
+
32329
+ // Accept HMR for the search index so it updates without a full reload
32330
+ if (import.meta.hot) {
32331
+ import.meta.hot.accept('${SEARCH_INDEX_ID}', (m) => {
32332
+ if (m) searchIndexRef.value = m.default;
32333
+ });
32334
+ }
32335
+ `;
32336
+ }
32337
+ function typedown(A = {}) {
32338
+ let j = A.context, M, N = new SearchIndexer(), P;
32339
+ function F() {
32340
+ if (j === void 0) throw Error("typedown plugin not initialized");
32341
+ return j.getTdContext();
32342
+ }
32343
+ return [
32344
+ {
32345
+ name: "vite-plugin-typedown",
32346
+ enforce: "pre",
32347
+ configResolved(A) {
32348
+ j ||= createAppContext(resolveProjectRoot(A.root));
32349
+ },
32350
+ config() {
32351
+ return {
32352
+ resolve: { alias: resolveAliases() },
32353
+ ssr: { noExternal: ["typerighter"] }
32354
+ };
32355
+ },
32356
+ async buildStart() {
32357
+ let A = await (await F()).checkVault();
32358
+ if (0 < A.errorCount || 0 < A.warningCount) for (let j of A.diagnostics) {
32359
+ let A = `${j.filepath}:${j.line}:${j.column}`, M = j.severity === "error" ? pc.red("error") : pc.yellow("warn");
32360
+ console.error(` ${M} ${A} ${j.message} ${pc.dim(`(${j.code})`)}`);
32361
+ }
32362
+ if (!M && 0 < A.errorCount) {
32363
+ let j = A.diagnostics.filter((A) => A.severity === "error").map((A) => ` ${A.filepath}:${A.line}:${A.column} - ${A.message} (${A.code})`);
32364
+ this.error(`Vault check failed with ${A.errorCount} error(s):\n${j.join("\n")}`);
32365
+ }
32366
+ },
32367
+ resolveId(A) {
32368
+ if (A === "/@typedown/app" || A === "@typedown/app") return RESOLVED_VIRTUAL_APP_ID;
32369
+ if (A === "@typedown/search-index") return RESOLVED_SEARCH_INDEX_ID;
32370
+ },
32371
+ async load(A) {
32372
+ if (A === "\0@typedown/search-index") return P ||= indexAllPages(await F(), N), await P, `export default ${JSON.stringify(N.serialize())}`;
32373
+ if (A !== "\0@typedown/app") return;
32374
+ let j = await F(), [M, I, L] = await Promise.all([
32375
+ j.getConfig(),
32376
+ j.listFilesGroupedBySchema(),
32377
+ j.listSchemas()
32378
+ ]), R = await Promise.all(L.map(async (A) => [A, (await j.getSchema(A)).properties])), z = Object.fromEntries(R), B = buildContentTree(Object.values(I).flat());
32379
+ return generateClientAppEntry({
32380
+ ...M,
32381
+ contentTree: B,
32382
+ schemas: z
32383
+ });
32384
+ },
32385
+ async configureServer(A) {
32386
+ M = A;
32387
+ let j = await F();
32388
+ j.rpc.onConfigChanged(() => M && hmrFullReload(M)), j.rpc.onContentChanged(({ content: A }) => {
32389
+ M && (getPageIndexInput(j, A).then((A) => {
32390
+ A && M && (N.addPage(A), invalidateSearchIndex(M));
32391
+ }).catch(() => {}), j.getConfig().then((j) => {
32392
+ if (!M) return;
32393
+ let N = normalizePath(resolve(M.config.root, j.contentDir, A)), P = M.moduleGraph.getModulesByFile(N);
32394
+ if (!P?.size) return;
32395
+ let F = [...P].map((A) => (M?.moduleGraph.invalidateModule(A), makeHmrUpdate(A)));
32396
+ M.hot.send({
32397
+ type: "update",
32398
+ updates: F
32399
+ });
32400
+ }).catch(() => {}));
32401
+ });
32402
+ function I() {
32403
+ M && (P = indexAllPages(j, N), P.then(() => {
32404
+ M && invalidateSearchIndex(M);
32405
+ }), hmrInvalidateAll(M));
32406
+ }
32407
+ return j.rpc.onContentCreated(I), j.rpc.onContentDeleted(I), j.rpc.onSchemaChanged(() => M && hmrInvalidateAll(M)), j.rpc.onSchemaCreated(() => M && hmrInvalidateAll(M)), j.rpc.onSchemaDeleted(() => M && hmrInvalidateAll(M)), () => {
32408
+ A.middlewares.use((A, M, N) => {
32409
+ if (!A.url || M.writableEnded || A.url.startsWith("/@") || A.url.startsWith("/node_modules") || A.url.includes(".")) return N();
32410
+ j.getConfig().then((A) => {
32411
+ let j = `<!DOCTYPE html>
32412
+ <html lang="en">
32413
+ <head>
32414
+ <meta charset="UTF-8">
32415
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
32416
+ <title>${escapeHtml$2(A.siteTitle)}</title>
32417
+ <link rel="icon" type="image/svg+xml" href="${BRAND_FAVICON_URI}">
32418
+ </head>
32419
+ <body>
32420
+ <div id="app"></div>
32421
+ <script type="module" src="/${VIRTUAL_APP_ID}"><\/script>
32422
+ </body>
32423
+ </html>`;
32424
+ M.setHeader("Content-Type", "text/html"), M.end(j);
32425
+ }).catch(N);
32426
+ });
32427
+ };
32428
+ },
32429
+ async transform(A, j) {
32430
+ let M = j.split("?")[0];
32431
+ if (!isContentFile(M)) return;
32432
+ let N = await F(), P = (await N.getConfig()).contentDir, I = M.includes(P) ? M.slice(M.indexOf(P) + P.length + 1) : M, { vueSrc: L } = await renderToVueSfc(N, await N.getFile(I), I);
32433
+ return {
32434
+ code: L,
32435
+ map: null
32436
+ };
32437
+ },
32438
+ handleHotUpdate({ file: A }) {
32439
+ if (isContentFile(A)) return [];
32440
+ }
32441
+ },
32442
+ vue({ include: /\.(?:vue|td)$/ }),
32443
+ ...tailwindcss()
32444
+ ];
32445
+ }
32446
+ async function getPageIndexInput(A, j) {
32447
+ try {
32448
+ let M = await A.getFile(j), N = await A.md.renderAsync(M.content, {
32449
+ path: j,
32450
+ relativePath: j,
32451
+ cleanUrls: !0
32452
+ });
32453
+ return {
32454
+ id: getTdContentUrl(j),
32455
+ title: getTdResourceTitle(M.header, j),
32456
+ html: N
32457
+ };
32458
+ } catch {
32459
+ return;
32460
+ }
32461
+ }
32462
+ function getTdModules(A) {
32463
+ return [...A.moduleGraph.idToModuleMap.entries()].filter(([A]) => A.endsWith(".td")).map(([, A]) => A);
32464
+ }
32465
+ function hmrFullReload(A) {
32466
+ for (let j of getTdModules(A)) A.moduleGraph.invalidateModule(j);
32467
+ A.hot.send({ type: "full-reload" });
32468
+ }
32469
+ function hmrInvalidateAll(A) {
32470
+ let j = getTdModules(A).map((j) => (A.moduleGraph.invalidateModule(j), makeHmrUpdate(j)));
32471
+ 0 < j.length && A.hot.send({
32472
+ type: "update",
32473
+ updates: j
32474
+ });
32475
+ }
32476
+ async function indexAllPages(A, j) {
32477
+ let M = await A.listFiles(), N = await Promise.all(M.map((j) => getPageIndexInput(A, j)));
32478
+ j.addAll(N.filter((A) => A !== void 0));
32479
+ }
32480
+ function invalidateSearchIndex(A) {
32481
+ let j = A.moduleGraph.getModuleById(RESOLVED_SEARCH_INDEX_ID);
32482
+ j && (A.moduleGraph.invalidateModule(j), A.hot.send({
32483
+ type: "update",
32484
+ updates: [makeHmrUpdate(j)]
32485
+ }));
32486
+ }
32487
+ function makeHmrUpdate(A) {
32488
+ return {
32489
+ type: "js-update",
32490
+ path: A.url,
32491
+ acceptedPath: A.url,
32492
+ timestamp: Date.now()
32493
+ };
32494
+ }
32188
32495
  //#endregion
32189
- export { CONFIG_FILE_NAMES as a, __commonJSMin as c, VIRTUAL_APP_ID as i, RESOLVED_VIRTUAL_APP_ID as n, createAppContext as o, SEARCH_INDEX_ID as r, resolveProjectRoot as s, RESOLVED_SEARCH_INDEX_ID as t };
32496
+ export { createAppContext as a, CONFIG_FILE_NAMES as i, typedown as n, VIRTUAL_APP_ID as r, generateClientAppEntry as t };
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as e, t } from "./vite-DnP-_NzR.js";
1
+ import { n as e, t } from "./vite-CASZdq-i.js";
2
2
  export { t as generateClientAppEntry, e as typedown };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "typerighter",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "description": "Typedown: A typed content framework.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,6 +27,10 @@
27
27
  "types": "./dist/client/index.d.ts",
28
28
  "import": "./dist/client.js"
29
29
  },
30
+ "./shared": {
31
+ "types": "./dist/shared/index.d.ts",
32
+ "import": "./dist/shared.js"
33
+ },
30
34
  "./client/theme-default": {
31
35
  "types": "./dist/client/theme-default/index.d.ts",
32
36
  "import": "./dist/client/theme-default.js"
@@ -81,8 +85,8 @@
81
85
  "tailwindcss": "^4.3.3",
82
86
  "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
83
87
  "vue": "^3.0.0",
84
- "@typerighter/rpc-client": "0.7.0",
85
- "@typerighter/rpc-server": "0.7.0"
88
+ "@typerighter/rpc-client": "0.8.0",
89
+ "@typerighter/rpc-server": "0.8.0"
86
90
  },
87
91
  "devDependencies": {
88
92
  "@hdnax/nuclint": "^0.17.4",