@tnotesjs/core 0.4.2 → 0.6.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.
Files changed (48) hide show
  1. package/dist/chunk-3R7QSABB.cjs +502 -0
  2. package/dist/chunk-CZXRQPFJ.js +11 -0
  3. package/dist/{chunk-XCWFZLER.js → chunk-DUTS75WQ.js} +27 -493
  4. package/dist/chunk-HXED7KVT.cjs +11 -0
  5. package/dist/chunk-IHFUHB4J.cjs +176 -0
  6. package/dist/chunk-MZIXIY2Y.cjs +216 -0
  7. package/dist/chunk-TJ4527KA.cjs +5264 -0
  8. package/dist/chunk-U6IBLREL.js +502 -0
  9. package/dist/chunk-UNFSW5C2.js +176 -0
  10. package/dist/cli/index.cjs +936 -0
  11. package/dist/cli/index.d.cts +2 -0
  12. package/dist/cli/index.d.ts +2 -0
  13. package/dist/cli/index.js +9 -6
  14. package/dist/index.cjs +8 -0
  15. package/dist/index.d.cts +56 -0
  16. package/dist/index.d.ts +56 -0
  17. package/dist/markdown/index.cjs +82 -0
  18. package/dist/markdown/index.d.cts +36 -0
  19. package/dist/markdown/index.d.ts +36 -0
  20. package/dist/markdown/index.js +82 -0
  21. package/dist/note-oGm44Rw8.d.cts +84 -0
  22. package/dist/note-oGm44Rw8.d.ts +84 -0
  23. package/dist/types-CpsEy8lA.d.cts +221 -0
  24. package/dist/types-CwBWwNVv.d.ts +221 -0
  25. package/dist/vitepress/config/index.cjs +1669 -0
  26. package/dist/vitepress/config/index.d.cts +12 -0
  27. package/dist/vitepress/config/index.d.ts +12 -0
  28. package/dist/vitepress/config/index.js +26 -192
  29. package/dist/workspace/index.cjs +1207 -0
  30. package/dist/workspace/index.d.cts +14 -0
  31. package/dist/workspace/index.d.ts +14 -0
  32. package/dist/workspace/index.js +1207 -0
  33. package/package.json +16 -3
  34. package/vitepress/components/MindmapPreview/MindmapPreview.vue +189 -34
  35. package/vitepress/components/MindmapPreview/MindmapViewIcon.vue +41 -0
  36. package/vitepress/components/MindmapPreview/markdown.test.ts +67 -0
  37. package/vitepress/components/MindmapPreview/markdown.ts +83 -0
  38. package/vitepress/components/MindmapPreview/wheelInteraction.test.ts +23 -0
  39. package/vitepress/components/MindmapPreview/wheelInteraction.ts +7 -0
  40. package/vitepress/components/Settings/Settings.vue +3 -3
  41. package/vitepress/components/SidebarCard/SidebarCard.vue +3 -3
  42. package/vitepress/components/constants.ts +0 -5
  43. package/vitepress/configs/markdown.config.ts +6 -199
  44. package/vitepress/plugins/localSearchReindexLogic.ts +11 -3
  45. package/vitepress/theme/index.ts +0 -2
  46. package/vitepress/components/MindmapPreview/compat.test.ts +0 -93
  47. package/vitepress/components/MindmapPreview/compat.ts +0 -128
  48. package/vitepress/components/MindmapPreview/legacyCorpus.test.ts +0 -57
@@ -0,0 +1,12 @@
1
+ import * as vitepress from 'vitepress';
2
+ import { UserConfig } from 'vitepress';
3
+
4
+ /**
5
+ * 创建 VitePress 站点配置
6
+ *
7
+ * @param overrides - 可选的覆盖配置,会与默认配置合并
8
+ * @returns VitePress 配置对象
9
+ */
10
+ declare function defineNotesConfig(overrides?: UserConfig): UserConfig<vitepress.DefaultTheme.Config>;
11
+
12
+ export { defineNotesConfig };
@@ -0,0 +1,12 @@
1
+ import * as vitepress from 'vitepress';
2
+ import { UserConfig } from 'vitepress';
3
+
4
+ /**
5
+ * 创建 VitePress 站点配置
6
+ *
7
+ * @param overrides - 可选的覆盖配置,会与默认配置合并
8
+ * @returns VitePress 配置对象
9
+ */
10
+ declare function defineNotesConfig(overrides?: UserConfig): UserConfig<vitepress.DefaultTheme.Config>;
11
+
12
+ export { defineNotesConfig };
@@ -5,12 +5,15 @@ import {
5
5
  RenameNoteCommand,
6
6
  TocService,
7
7
  UpdateNoteConfigCommand,
8
- generateAnchor,
9
8
  logger
10
- } from "../../chunk-XCWFZLER.js";
9
+ } from "../../chunk-DUTS75WQ.js";
11
10
  import {
12
11
  ConfigManager
13
12
  } from "../../chunk-UJG3UU5X.js";
13
+ import "../../chunk-U6IBLREL.js";
14
+ import {
15
+ generateAnchor
16
+ } from "../../chunk-CZXRQPFJ.js";
14
17
 
15
18
  // vitepress/config/index.ts
16
19
  import fs3 from "fs";
@@ -65,45 +68,24 @@ import mila from "markdown-it-link-attributes";
65
68
  import markdownItTaskLists from "markdown-it-task-lists";
66
69
  import path from "path";
67
70
 
68
- // vitepress/components/MindmapPreview/compat.ts
71
+ // vitepress/components/MindmapPreview/markdown.ts
69
72
  function cleanHeadingText(value) {
70
73
  return value.trim().replace(/\s+#+\s*$/, "").trim();
71
74
  }
72
- function promoteLegacyRootList(body, rootTitle) {
73
- const firstContentIndex = body.findIndex((line) => line.trim() !== "");
74
- if (firstContentIndex < 0) return body;
75
- const firstItem = body[firstContentIndex].match(/^[-+*]\s+(.+?)\s*$/);
76
- if (!firstItem || cleanHeadingText(firstItem[1]) !== rootTitle) return body;
77
- const descendants = body.slice(firstContentIndex + 1);
78
- if (descendants.some((line) => line.trim() !== "" && !/^\s{2,}/.test(line))) return body;
79
- return [
80
- ...body.slice(0, firstContentIndex),
81
- ...descendants.map((line) => line.replace(/^ {2}/, ""))
82
- ];
83
- }
84
- function parseMarkmapFence(openLine) {
75
+ function parseMindmapFence(openLine) {
85
76
  const fenceBody = openLine.trim().replace(/^`+\s*/, "");
86
- const nameMatch = fenceBody.match(/^(mindmap|markmap)(?=\s|\{|\[|$)/);
87
- if (!nameMatch) return {};
88
- let rest = fenceBody.slice(nameMatch[1].length).trim();
77
+ const nameMatch = fenceBody.match(/^mindmap(?=\s|\[|$)/);
78
+ if (!nameMatch) return null;
79
+ let rest = fenceBody.slice(nameMatch[0].length).trim();
89
80
  const options = {};
90
81
  const titleMatch = rest.match(/\[([^\]]+)\]/);
91
82
  if (titleMatch) {
92
- options.title = titleMatch[1].trim();
83
+ options.title = cleanHeadingText(titleMatch[1]) || void 0;
93
84
  rest = `${rest.slice(0, titleMatch.index)} ${rest.slice((titleMatch.index ?? 0) + titleMatch[0].length)}`.trim();
94
85
  }
95
- const braceMatch = rest.match(/\{([^}]*)\}/);
96
- const paramPart = braceMatch ? braceMatch[1].trim() : rest;
97
- const tokens = paramPart.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
98
- for (const [index, token] of tokens.entries()) {
99
- if (/^\d+$/.test(token) && index === 0) {
100
- options.initialExpandLevel = Number(token);
101
- continue;
102
- }
103
- const pair = token.match(/^([^=:\s]+)\s*(?:=|:)\s*(.+)$/);
104
- if (!pair || pair[1] !== "initialExpandLevel") continue;
105
- const value = pair[2].replace(/^['"]|['"]$/g, "");
106
- if (/^\d+$/.test(value)) options.initialExpandLevel = Number(value);
86
+ if (rest && !/^\d+$/.test(rest)) return null;
87
+ if (rest) {
88
+ options.initialExpandLevel = Math.max(1, Number(rest));
107
89
  }
108
90
  return options;
109
91
  }
@@ -132,30 +114,12 @@ function normalizeMindmapMarkdown(source, options = {}) {
132
114
  break;
133
115
  }
134
116
  const rootTitle = cleanHeadingText(options.title || existingTitle || options.defaultTitle || "root") || "root";
135
- const body = [];
136
- let headingDepth = null;
137
- for (let index = 0; index < lines.length; index++) {
138
- if (index === rootIndex) continue;
139
- const line = lines[index];
140
- const heading = line.match(/^\s{0,3}(#{2,6})\s+(.+?)\s*$/);
141
- if (heading) {
142
- headingDepth = heading[1].length - 2;
143
- body.push(`${" ".repeat(headingDepth)}- ${cleanHeadingText(heading[2])}`);
144
- continue;
145
- }
146
- const listItem = line.match(/^(\s*)([-+*])\s+(.+)$/);
147
- if (listItem && headingDepth !== null) {
148
- body.push(`${" ".repeat(headingDepth + 1)}${line}`);
149
- continue;
150
- }
151
- body.push(line);
152
- }
153
- const normalizedBody = promoteLegacyRootList(body, rootTitle);
154
- while (normalizedBody[0]?.trim() === "") normalizedBody.shift();
155
- while (normalizedBody[normalizedBody.length - 1]?.trim() === "") normalizedBody.pop();
156
- return normalizedBody.length > 0 ? `# ${rootTitle}
117
+ const body = lines.filter((_, index) => index !== rootIndex);
118
+ while (body[0]?.trim() === "") body.shift();
119
+ while (body[body.length - 1]?.trim() === "") body.pop();
120
+ return body.length > 0 ? `# ${rootTitle}
157
121
 
158
- ${normalizedBody.join("\n")}
122
+ ${body.join("\n")}
159
123
  ` : `# ${rootTitle}
160
124
  `;
161
125
  }
@@ -192,145 +156,13 @@ var simpleMermaidMarkdown = (md) => {
192
156
  return fence(tokens, index, options, env, slf);
193
157
  };
194
158
  };
195
- function configureMindmapContainer(md) {
196
- md.use(markdownItContainer, "markmap", {
197
- marker: "`",
198
- validate(params) {
199
- return (params || "").trim().startsWith("markmap");
200
- },
201
- render() {
202
- return "";
203
- }
204
- });
205
- md.core.ruler.after("block", "tn_replace_markmap_container", (state) => {
206
- const src = state.env.source || "";
207
- const lines = src.split("\n");
208
- const tokens = state.tokens;
209
- for (let i = 0; i < tokens.length; i++) {
210
- const t = tokens[i];
211
- if (t.type === "container_markmap_open") {
212
- const containerName = "markmap";
213
- const closeType = "container_markmap_close";
214
- let j = i + 1;
215
- while (j < tokens.length && tokens[j].type !== closeType)
216
- j++;
217
- if (j >= tokens.length) continue;
218
- const open = t;
219
- const startLine = open.map ? open.map[0] + 1 : null;
220
- const endLine = open.map ? open.map[1] - 1 : null;
221
- const params = {};
222
- let explicitTitle;
223
- if (open.map && typeof open.map[0] === "number") {
224
- const openLine = (lines[open.map[0]] || "").trim();
225
- const fenceOptions = parseMarkmapFence(openLine);
226
- explicitTitle = fenceOptions.title;
227
- let paramPart = "";
228
- const braceMatch = openLine.match(/\{([^}]*)\}/);
229
- if (braceMatch) {
230
- paramPart = braceMatch[1].trim();
231
- } else {
232
- const after = openLine.replace(/^`+\s*/, "");
233
- if (after.startsWith(containerName)) {
234
- paramPart = after.slice(containerName.length).trim();
235
- }
236
- }
237
- if (fenceOptions.initialExpandLevel !== void 0) {
238
- params.initialExpandLevel = fenceOptions.initialExpandLevel;
239
- }
240
- if (paramPart) {
241
- const tokenArr = paramPart.match(/"[^"]*"|'[^']*'|\S+/g) || [];
242
- let startIdx = 0;
243
- if (tokenArr.length > 0 && /^\d+$/.test(tokenArr[0])) {
244
- params.initialExpandLevel = Number(tokenArr[0]);
245
- startIdx = 1;
246
- }
247
- for (let k = startIdx; k < tokenArr.length; k++) {
248
- const pair = tokenArr[k];
249
- if (!pair) continue;
250
- const m = pair.match(/^([^=:\s]+)\s*(=|:)\s*(.+)$/);
251
- if (m) {
252
- const key = m[1];
253
- let val = m[3];
254
- if (/^".*"$/.test(val) && val.length >= 2 || /^'.*'$/.test(val) && val.length >= 2) {
255
- val = val.slice(1, -1);
256
- } else if (/^\d+$/.test(val)) {
257
- val = String(Number(val));
258
- }
259
- params[key] = val;
260
- }
261
- }
262
- }
263
- }
264
- let content = "";
265
- if (startLine !== null && endLine !== null) {
266
- for (let k = startLine; k <= endLine && k < lines.length; k++) {
267
- content += lines[k] + "\n";
268
- }
269
- } else {
270
- for (let k = i + 1; k < j; k++) {
271
- content += tokens[k].content || "";
272
- }
273
- }
274
- const firstNonEmptyLine = (content || "").split("\n").find((ln) => ln.trim() !== "") || "";
275
- const reference = parseMindmapReference(firstNonEmptyLine);
276
- let referencedTitle;
277
- if (reference) {
278
- const refRaw = reference.path;
279
- referencedTitle = reference.title;
280
- try {
281
- const env = state.env || {};
282
- const possibleRel = env.relativePath || env.path || env.filePath || env.file || "";
283
- let refFullPath = refRaw;
284
- if (!path.isAbsolute(refRaw)) {
285
- if (possibleRel) {
286
- const currentDir = path.dirname(possibleRel);
287
- refFullPath = path.resolve(process.cwd(), currentDir, refRaw);
288
- } else {
289
- refFullPath = path.resolve(process.cwd(), refRaw);
290
- }
291
- } else {
292
- refFullPath = refRaw;
293
- }
294
- const fileContent = fs.readFileSync(refFullPath, "utf-8");
295
- content = fileContent;
296
- } catch (err) {
297
- const errorMsg = err instanceof Error ? err.message : String(err);
298
- content = `- Failed to load referenced file: ${esc(String(refRaw))}
299
- - Error: ${esc(errorMsg)}`;
300
- }
301
- }
302
- content = normalizeMindmapMarkdown(content, {
303
- title: explicitTitle || referencedTitle
304
- });
305
- const encodedContent = encodeURIComponent(content.trim());
306
- let propsStr = `content="${encodedContent}"`;
307
- for (const [k, v] of Object.entries(params)) {
308
- if (typeof v === "number" || /^\d+$/.test(String(v))) {
309
- propsStr += ` :${k}="${v}"`;
310
- } else {
311
- const safe = String(v).replace(/"/g, "&quot;");
312
- propsStr += ` ${k}="${safe}"`;
313
- }
314
- }
315
- const html = `<MindmapPreview ${propsStr}></MindmapPreview>
316
- `;
317
- const htmlToken = new state.Token("html_block", "", 0);
318
- htmlToken.content = html;
319
- tokens.splice(i, j - i + 1, htmlToken);
320
- }
321
- }
322
- return true;
323
- });
324
- }
325
159
  function configureMindmapFence(md) {
326
160
  const fence = md.renderer.rules.fence ? md.renderer.rules.fence.bind(md.renderer.rules) : () => "";
327
161
  md.renderer.rules.fence = (tokens, index, options, env, slf) => {
328
162
  const token = tokens[index];
329
163
  const info = token.info.trim();
330
- if (!/^mindmap(?=\s|\{|\[|$)/.test(info)) {
331
- return fence(tokens, index, options, env, slf);
332
- }
333
- const fenceOptions = parseMarkmapFence(info);
164
+ const fenceOptions = parseMindmapFence(info);
165
+ if (!fenceOptions) return fence(tokens, index, options, env, slf);
334
166
  let content = token.content;
335
167
  const firstNonEmptyLine = content.split("\n").find((line) => line.trim()) ?? "";
336
168
  const reference = parseMindmapReference(firstNonEmptyLine);
@@ -424,7 +256,6 @@ function getMarkdownConfig() {
424
256
  return true;
425
257
  });
426
258
  simpleMermaidMarkdown(md);
427
- configureMindmapContainer(md);
428
259
  configureMindmapFence(md);
429
260
  md.use(markdownItTaskLists);
430
261
  md.use(mila, {
@@ -947,8 +778,11 @@ function isNoteReadmePath(filePath, ignoreDirNames = []) {
947
778
  return !ignoreDirNames.some((dir) => folderName === dir);
948
779
  }
949
780
  function getDocIdFromFile(input) {
950
- const absoluteFile = path2.isAbsolute(input.absoluteOrRelativeFile) ? input.absoluteOrRelativeFile : path2.join(input.srcDir, input.absoluteOrRelativeFile);
951
- let relFile = slash(path2.relative(input.srcDir, absoluteFile));
781
+ const pathApi = /^[a-zA-Z]:[\\/]/.test(
782
+ input.absoluteOrRelativeFile || input.srcDir
783
+ ) ? path2.win32 : path2;
784
+ const absoluteFile = pathApi.isAbsolute(input.absoluteOrRelativeFile) ? input.absoluteOrRelativeFile : pathApi.join(input.srcDir, input.absoluteOrRelativeFile);
785
+ let relFile = slash(pathApi.relative(input.srcDir, absoluteFile));
952
786
  if (input.rewrites?.[relFile]) {
953
787
  relFile = input.rewrites[relFile];
954
788
  }