@dooc-dev/dooc 0.0.27 → 0.0.29

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 (88) hide show
  1. package/dist/client.global.js +1 -1
  2. package/dist/edit.global.js +220 -221
  3. package/dist/engine/compiler/check.js +5 -3
  4. package/dist/engine/compiler/compile.d.ts +5 -0
  5. package/dist/engine/compiler/compile.js +44 -23
  6. package/dist/engine/compiler/dialect.js +1 -1
  7. package/dist/engine/compiler/document-diff.d.ts +53 -0
  8. package/dist/engine/compiler/document-diff.js +92 -0
  9. package/dist/engine/compiler/export.js +11 -3
  10. package/dist/engine/compiler/files.d.ts +1 -0
  11. package/dist/engine/compiler/files.js +75 -14
  12. package/dist/engine/compiler/format-collections.js +8 -2
  13. package/dist/engine/compiler/from-mdast.js +12 -1
  14. package/dist/engine/compiler/icons.d.ts +7 -7
  15. package/dist/engine/compiler/icons.js +35 -37
  16. package/dist/engine/compiler/manifest.d.ts +1 -0
  17. package/dist/engine/compiler/manifest.js +25 -0
  18. package/dist/engine/compiler/ops.d.ts +2 -2
  19. package/dist/engine/compiler/ops.js +55 -112
  20. package/dist/engine/compiler/resource-index.js +4 -4
  21. package/dist/engine/compiler/root-page.d.ts +13 -0
  22. package/dist/engine/compiler/root-page.js +96 -0
  23. package/dist/engine/compiler/sidebar-removal.d.ts +63 -0
  24. package/dist/engine/compiler/sidebar-removal.js +317 -0
  25. package/dist/engine/compiler/subformats.d.ts +3 -0
  26. package/dist/engine/compiler/subformats.js +126 -32
  27. package/dist/engine/core/blocks.d.ts +5 -0
  28. package/dist/engine/core/content-metadata.d.ts +9 -4
  29. package/dist/engine/core/content-metadata.js +100 -16
  30. package/dist/engine/core/file-embed.d.ts +2 -1
  31. package/dist/engine/core/file-embed.js +4 -0
  32. package/dist/engine/core/files.d.ts +1 -0
  33. package/dist/engine/core/files.js +6 -1
  34. package/dist/engine/core/format-collections.js +2 -2
  35. package/dist/engine/core/formats.d.ts +1 -1
  36. package/dist/engine/core/formats.js +1 -1
  37. package/dist/engine/core/html.d.ts +1 -0
  38. package/dist/engine/core/html.js +9 -5
  39. package/dist/engine/core/icons.d.ts +7 -0
  40. package/dist/engine/core/icons.js +38 -0
  41. package/dist/engine/core/subformats.d.ts +2 -1
  42. package/dist/engine/core/subformats.js +6 -1
  43. package/dist/engine/core/toc-library.d.ts +5 -0
  44. package/dist/engine/core/toc-library.js +27 -0
  45. package/dist/frontend/document-application.d.ts +5 -2
  46. package/dist/frontend/document-application.js +403 -189
  47. package/dist/frontend/edit-dialog.d.ts +1 -0
  48. package/dist/frontend/edit-dialog.js +12 -8
  49. package/dist/frontend/file-references.js +1 -1
  50. package/dist/frontend/locales/eng.json +62 -1
  51. package/dist/frontend/locales/jpn.json +62 -1
  52. package/dist/frontend/locales/zho.json +62 -1
  53. package/dist/frontend/page-jump.js +17 -10
  54. package/dist/frontend/resize.js +38 -12
  55. package/dist/frontend/resource-library.js +1 -0
  56. package/dist/frontend/search.js +2 -0
  57. package/dist/frontend/theme-picker.d.ts +2 -2
  58. package/dist/frontend/theme-picker.js +2 -2
  59. package/dist/manifest.global.js +193 -192
  60. package/dist/mcp-relay.mjs +8 -4
  61. package/dist/plugins.global.js +49 -49
  62. package/dist/server/build.js +11 -8
  63. package/dist/server/cli.js +18 -1
  64. package/dist/server/document-diff-cli.d.ts +1 -0
  65. package/dist/server/document-diff-cli.js +193 -0
  66. package/dist/server/document-diff-report.d.ts +3 -0
  67. package/dist/server/document-diff-report.js +124 -0
  68. package/dist/server/document-diff-sources.d.ts +40 -0
  69. package/dist/server/document-diff-sources.js +128 -0
  70. package/dist/server/document-versions.d.ts +3 -1
  71. package/dist/server/document-versions.js +19 -70
  72. package/dist/server/git-diff.d.ts +1 -0
  73. package/dist/server/git-diff.js +22 -2
  74. package/dist/server/git-document-snapshot.d.ts +2 -0
  75. package/dist/server/git-document-snapshot.js +63 -0
  76. package/dist/server/operation-log.js +2 -0
  77. package/dist/server/serve.d.ts +2 -2
  78. package/dist/server/serve.js +4 -9
  79. package/dist/server/workspace-server.js +6 -10
  80. package/dist/subformats.global.js +478 -74
  81. package/dist/ui.global.js +435 -80
  82. package/dist/workspace/file-operation.d.ts +10 -0
  83. package/dist/workspace/file-operation.js +47 -0
  84. package/dist/workspace/mcp-tools.js +8 -4
  85. package/dist/workspace/site-icon.js +30 -23
  86. package/dist/workspace/textfile.js +8 -8
  87. package/dist/workspace-worker.global.js +241 -197
  88. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  // dooc.yaml owns document hierarchy and display settings. Nested manifests identify documents
2
2
  // by complete source paths; legacy manifests retain their authored IDs during migration.
3
- import { stringify } from "yaml";
3
+ import { parse, stringify } from "yaml";
4
4
  import { parseVersionConfig } from "./document-version.js";
5
5
  import { docFile, fileDocumentId, isSkillFile, localFile, parseFileLayout, } from "./files.js";
6
6
  import { isFormatSelector } from "./format-collections.js";
@@ -8,6 +8,7 @@ import { isReferenceLibrary, parseCollections, } from "./formats.js";
8
8
  import { contentLanguageCode, DEFAULT_LANG, isLangTag } from "./language.js";
9
9
  import { isRemoteManifest, remoteManifestSource } from "./remote-manifest.js";
10
10
  import { parseSubformats } from "./subformats.js";
11
+ import { tocReference } from "./toc-library.js";
11
12
  export const MANIFEST_FILE = "dooc.yaml";
12
13
  export const isManifestFile = (name) => /^(?:[^/\\]+\.)?dooc\.yaml$/.test(name);
13
14
  export const pageUrlKind = (url) => {
@@ -15,6 +16,8 @@ export const pageUrlKind = (url) => {
15
16
  return "index";
16
17
  if (url === "redirect:first")
17
18
  return "redirect";
19
+ if (tocReference(url))
20
+ return "toc";
18
21
  // biome-ignore lint/suspicious/noControlCharactersInRegex: Reject control characters before URL normalization.
19
22
  if (/[\\\u0000-\u001f\u007f]/.test(url))
20
23
  throw new Error("Invalid document URL");
@@ -65,6 +68,34 @@ export const docIdOfFile = (name) => {
65
68
  * Validates id shape and duplicates.
66
69
  */
67
70
  export const parseManifest = (value) => {
71
+ if (value && typeof value === "object" && !Array.isArray(value) && "root_url" in value) {
72
+ const { root_url: url, ...settings } = value;
73
+ const manifest = parseManifest(settings);
74
+ try {
75
+ if (manifest.format === "document" || typeof url !== "string")
76
+ throw new Error("Use document.url in a document manifest");
77
+ const kind = pageUrlKind(url);
78
+ if (kind === "manifest")
79
+ throw new Error("A legacy root cannot include another manifest");
80
+ const entries = flattenTree(manifest.tree);
81
+ let id = "document-root";
82
+ while (entries.some((entry) => entry.id === id))
83
+ id += "-root";
84
+ if (kind === "content") {
85
+ if (entries.some((entry) => isContentPage(entry) && docFile(entry.id, manifest.files) === url))
86
+ throw new Error("This Markdown file already has a sidebar entry");
87
+ manifest.files ??= { defaultLayout: true, documents: {} };
88
+ manifest.files.documents[id] = url;
89
+ }
90
+ manifest.tree = [
91
+ { id, root: true, url, title: manifest.title, children: manifest.tree },
92
+ ];
93
+ }
94
+ catch (error) {
95
+ manifest.errors.push(String(error));
96
+ }
97
+ return manifest;
98
+ }
68
99
  if (value &&
69
100
  typeof value === "object" &&
70
101
  !Array.isArray(value) &&
@@ -197,6 +228,7 @@ export const parseManifest = (value) => {
197
228
  const at = `${path}[${i}]`;
198
229
  let id;
199
230
  let children;
231
+ let label;
200
232
  if (item &&
201
233
  typeof item === "object" &&
202
234
  !Array.isArray(item) &&
@@ -255,6 +287,16 @@ export const parseManifest = (value) => {
255
287
  if (typeof item === "string") {
256
288
  id = item;
257
289
  }
290
+ else if (item &&
291
+ typeof item === "object" &&
292
+ typeof item.id === "string" &&
293
+ typeof item.title === "string" &&
294
+ item.title.trim() &&
295
+ Object.keys(item).every((key) => ["id", "title", "children"].includes(key))) {
296
+ id = item.id;
297
+ label = item.title.trim();
298
+ children = item.children;
299
+ }
258
300
  else if (typeof item === "object" &&
259
301
  item != null &&
260
302
  !Array.isArray(item) &&
@@ -274,7 +316,11 @@ export const parseManifest = (value) => {
274
316
  continue;
275
317
  }
276
318
  seen.add(id);
277
- nodes.push({ id, children: walk(children, `${at}.${id}`) });
319
+ nodes.push({
320
+ id,
321
+ ...(label ? { title: label } : {}),
322
+ children: walk(children, `${at}.${id}`),
323
+ });
278
324
  }
279
325
  return nodes;
280
326
  };
@@ -334,12 +380,17 @@ const parseNestedManifest = (input) => {
334
380
  "default_lang",
335
381
  "themes",
336
382
  "licence",
383
+ "accent_color",
337
384
  "skills",
338
385
  "files",
339
386
  "library",
340
387
  "format",
341
388
  ], "system");
342
389
  const collections = parseCollections(system);
390
+ const accentColor = system.accent_color;
391
+ if (accentColor !== undefined &&
392
+ (typeof accentColor !== "string" || !/^#[0-9a-f]{6}$/i.test(accentColor)))
393
+ throw new Error("system.accent_color must be a six-digit hex color, such as #2367b2");
343
394
  const licence = system.licence;
344
395
  if (licence !== undefined && (!localFile(licence) || !licence.trim()))
345
396
  throw new Error("system.licence must be a local file path");
@@ -350,7 +401,7 @@ const parseNestedManifest = (input) => {
350
401
  new Set(skills).size !== skills.length))
351
402
  throw new Error("system.skills must be a list of unique project-relative SKILL.md paths");
352
403
  const sidebar = object(document?.sidebar ?? root.left_sidebar ?? {}, ["title", "icon"], "sidebar");
353
- const layout = object(system.files ?? {}, ["default_layout", "order"], "system.files");
404
+ const layout = object(system.files ?? {}, ["default_layout", "upload_directory", "order"], "system.files");
354
405
  const titles = {};
355
406
  if (sidebar.title !== undefined) {
356
407
  if (!sidebar.title || typeof sidebar.title !== "object" || Array.isArray(sidebar.title))
@@ -536,6 +587,7 @@ const parseNestedManifest = (input) => {
536
587
  ...(icon === undefined ? {} : { icon }),
537
588
  files: {
538
589
  defaultLayout: layout.default_layout,
590
+ uploadDirectory: layout.upload_directory,
539
591
  documents,
540
592
  ...(Object.keys(icons).length ? { icons } : {}),
541
593
  },
@@ -551,6 +603,7 @@ const parseNestedManifest = (input) => {
551
603
  ...(licence === undefined ? {} : { licence }),
552
604
  ...(skills === undefined ? {} : { skills: skills }),
553
605
  ...collections,
606
+ ...(accentColor === undefined ? {} : { accentColor }),
554
607
  ...(sidebar.title === undefined ? {} : { titles }),
555
608
  ...(rootIcon !== undefined && scalarIcon === undefined ? { themeIcons } : {}),
556
609
  };
@@ -575,7 +628,25 @@ export const migrateDocumentIcon = (document) => {
575
628
  return true;
576
629
  };
577
630
  /** Serialize the authored format; legacy manifests remain readable during migration. */
578
- export const serializeManifest = (tree, { format, version, titles, themeIcons, title, icon, defaultLang, licence, skills, libraries, formats, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, } = {}) => {
631
+ export const serializeManifest = (tree, settings = {}) => {
632
+ const root = tree[0];
633
+ if (!root?.root || settings.format === "document")
634
+ return serializeManifestBody(tree, settings);
635
+ const files = settings.files && {
636
+ ...settings.files,
637
+ documents: { ...settings.files.documents },
638
+ };
639
+ if (files)
640
+ delete files.documents[root.id];
641
+ const raw = serializeManifestBody(root.children, { ...settings, files });
642
+ const contents = raw.startsWith("# Doc hierarchy")
643
+ ? stringify({ docs: parse(raw) ?? [] })
644
+ : raw;
645
+ return (stringify({
646
+ root_url: isContentPage(root) ? docFile(root.id, settings.files) : (root.url ?? ""),
647
+ }) + contents);
648
+ };
649
+ const serializeManifestBody = (tree, { format, version, titles, themeIcons, title, icon, defaultLang, licence, skills, libraries, formats, files, languages, themes, subformats, defaultSubformatFolder, includedSubformats, accentColor, } = {}) => {
579
650
  if (format) {
580
651
  const contents = (nodes) => nodes.map((node) => {
581
652
  const page = {
@@ -619,6 +690,7 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
619
690
  ...(languages ? { languages } : {}),
620
691
  default_lang: defaultLang ?? DEFAULT_LANG,
621
692
  ...(licence === undefined ? {} : { licence }),
693
+ ...(accentColor === undefined ? {} : { accent_color: accentColor }),
622
694
  ...(skills === undefined ? {} : { skills }),
623
695
  ...(libraries === undefined ? {} : { library: libraries }),
624
696
  ...(formats === undefined ? {} : { format: formats }),
@@ -627,6 +699,9 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
627
699
  ? {
628
700
  files: {
629
701
  default_layout: files.defaultLayout,
702
+ ...(files.uploadDirectory
703
+ ? { upload_directory: files.uploadDirectory }
704
+ : {}),
630
705
  },
631
706
  }
632
707
  : {}),
@@ -652,7 +727,7 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
652
727
  : {}),
653
728
  }, { lineWidth: 0 });
654
729
  }
655
- if (flattenTree(tree).some((node) => node.subformat || node.library || node.format)) {
730
+ if (flattenTree(tree).some((node) => node.subformat || node.library || node.format || node.title)) {
656
731
  const contents = (nodes) => nodes.map((node) => node.library || node.format
657
732
  ? {
658
733
  ...(node.library ? { library: node.library } : { format: node.format }),
@@ -665,9 +740,17 @@ export const serializeManifest = (tree, { format, version, titles, themeIcons, t
665
740
  title: node.title,
666
741
  ...(node.children.length ? { children: contents(node.children) } : {}),
667
742
  }
668
- : node.children.length
669
- ? { [node.id]: contents(node.children) }
670
- : node.id);
743
+ : node.title
744
+ ? {
745
+ id: node.id,
746
+ title: node.title,
747
+ ...(node.children.length
748
+ ? { children: contents(node.children) }
749
+ : {}),
750
+ }
751
+ : node.children.length
752
+ ? { [node.id]: contents(node.children) }
753
+ : node.id);
671
754
  return stringify({
672
755
  ...(version === undefined ? {} : { version }),
673
756
  ...(title ? { title } : {}),
@@ -736,7 +819,7 @@ export const flattenTree = (tree) => {
736
819
  return out;
737
820
  };
738
821
  const clone = (tree) => tree.map((n) => ({ ...n, children: clone(n.children) }));
739
- const findNode = (tree, id) => {
822
+ export const findNode = (tree, id) => {
740
823
  for (const n of tree) {
741
824
  if (n.id === id) {
742
825
  return n;
@@ -749,13 +832,15 @@ const findNode = (tree, id) => {
749
832
  return undefined;
750
833
  };
751
834
  /** Detach the node with this id (along with its children). Returns the detached node. */
752
- const detach = (tree, id) => {
835
+ const detach = (tree, id, promote = false) => {
753
836
  const i = tree.findIndex((n) => n.id === id);
754
837
  if (i !== -1) {
755
- return tree.splice(i, 1)[0];
838
+ const node = tree[i];
839
+ tree.splice(i, 1, ...(promote ? node.children : []));
840
+ return node;
756
841
  }
757
842
  for (const n of tree) {
758
- const hit = detach(n.children, id);
843
+ const hit = detach(n.children, id, promote);
759
844
  if (hit) {
760
845
  return hit;
761
846
  }
@@ -798,14 +883,13 @@ export const moveDoc = (tree, id, parent, index) => {
798
883
  list.splice(index, 0, moved);
799
884
  return next;
800
885
  };
801
- /** Remove a doc. Docs with children are not removed (we don't decide where the children go). */
802
- export const removeDoc = (tree, id) => {
886
+ export const removeDoc = (tree, id, children) => {
803
887
  const node = findNode(tree, id);
804
- if (!node || node.root || node.children.length > 0) {
888
+ if (!node || node.root || (node.children.length > 0 && !children)) {
805
889
  return undefined;
806
890
  }
807
891
  const next = clone(tree);
808
- detach(next, id);
892
+ detach(next, id, children === "promote");
809
893
  return next;
810
894
  };
811
895
  /** Change a doc's id (position and children stay as they are). */
@@ -11,5 +11,6 @@ export declare const parseFileEmbed: (source: string, settings?: PreviewSettings
11
11
  range?: string;
12
12
  tableMode?: "header";
13
13
  embed?: SubformatEmbedOptions;
14
- kind: "textfile" | "figure" | "html" | "external";
14
+ recursive?: boolean;
15
+ kind: "textfile" | "figure" | "html" | "external" | "toc";
15
16
  };
@@ -3,6 +3,7 @@ import { formatReference, parseFormatQuery } from "./format-collections.js";
3
3
  import { resolvePreviewer } from "./previewers.js";
4
4
  import { parseSubformatQuery } from "./subformats.js";
5
5
  import { parseFileReference } from "./textfile.js";
6
+ import { tocReference } from "./toc-library.js";
6
7
  /** Local visual links share the same asset catalog as image embeds. */
7
8
  export const parseFigureLink = (source) => {
8
9
  if (/^(?:[a-z][a-z\d+.-]*:|\/)/i.test(source))
@@ -24,6 +25,9 @@ export const parseFileEmbed = (source, settings) => {
24
25
  throw new Error("Embed URLs must not contain credentials");
25
26
  return { file: source, kind: "external" };
26
27
  }
28
+ const toc = tocReference(source);
29
+ if (toc)
30
+ return { ...toc, kind: "toc" };
27
31
  const { query, ...ref } = parseFileReference(source, true);
28
32
  if (formatReference(ref.file) !== undefined) {
29
33
  if (ref.range)
@@ -1,5 +1,6 @@
1
1
  export interface FileLayout {
2
2
  defaultLayout: boolean;
3
+ uploadDirectory?: string;
3
4
  documents: Record<string, string>;
4
5
  icons?: Record<string, string>;
5
6
  }
@@ -33,9 +33,13 @@ export const parseFileLayout = (value) => {
33
33
  throw new Error("files must be an object");
34
34
  const v = value;
35
35
  // Accept the retired order field when opening older manifests, without retaining it.
36
- if (Object.keys(v).some((key) => !["defaultLayout", "documents", "order", "icons"].includes(key)) ||
36
+ if (Object.keys(v).some((key) => !["defaultLayout", "uploadDirectory", "documents", "order", "icons"].includes(key)) ||
37
37
  (v.defaultLayout !== undefined && typeof v.defaultLayout !== "boolean"))
38
38
  throw new Error("Invalid file layout");
39
+ if (v.uploadDirectory !== undefined &&
40
+ !localFile(v.uploadDirectory) &&
41
+ v.uploadDirectory !== ".")
42
+ throw new Error("Expected a relative upload directory");
39
43
  const documents = v.documents ?? {};
40
44
  const icons = v.icons;
41
45
  if (icons !== undefined &&
@@ -52,6 +56,7 @@ export const parseFileLayout = (value) => {
52
56
  throw new Error("Invalid file paths");
53
57
  return {
54
58
  defaultLayout: v.defaultLayout !== false,
59
+ ...(typeof v.uploadDirectory === "string" ? { uploadDirectory: v.uploadDirectory } : {}),
55
60
  documents: documents,
56
61
  ...(icons ? { icons: icons } : {}),
57
62
  };
@@ -64,8 +64,8 @@ export const parseFormatQuery = (query) => {
64
64
  if (value === null)
65
65
  continue;
66
66
  if (key === "view") {
67
- if (value === "grid") {
68
- extra.view = "grid";
67
+ if (value === "grid" || value === "expand") {
68
+ extra.view = value;
69
69
  params.delete(key);
70
70
  }
71
71
  }
@@ -1,5 +1,5 @@
1
1
  import { type Document } from "yaml";
2
- export declare const REFERENCE_LIBRARIES: readonly ["urls", "url-previews", "skills"];
2
+ export declare const REFERENCE_LIBRARIES: readonly ["urls", "url-previews", "skills", "toc"];
3
3
  export type ReferenceLibrary = (typeof REFERENCE_LIBRARIES)[number];
4
4
  export interface FormatSources {
5
5
  folders?: string[];
@@ -1,6 +1,6 @@
1
1
  import { isMap, isScalar, isSeq } from "yaml";
2
2
  import { fileExtension, localFile } from "./files.js";
3
- export const REFERENCE_LIBRARIES = ["urls", "url-previews", "skills"];
3
+ export const REFERENCE_LIBRARIES = ["urls", "url-previews", "skills", "toc"];
4
4
  export const isFormat = (value) => typeof value === "string" && /^[a-z0-9][a-z0-9_+#-]*$/.test(value);
5
5
  export const isReferenceLibrary = (value) => REFERENCE_LIBRARIES.some((view) => view === value);
6
6
  const fenceExtensions = {
@@ -6,6 +6,7 @@ import type { SubformatCollection } from "./subformats.js";
6
6
  import type { Frontmatter } from "./taxonomy.js";
7
7
  export { escapeHtml } from "./escape-html.js";
8
8
  export interface RenderCtx {
9
+ pageContents?: (file: string, recursive: boolean, title?: string) => string;
9
10
  downloads?: ReadonlyMap<string, string>;
10
11
  /** Source file to published document route. */
11
12
  docLinks?: ReadonlyMap<string, string>;
@@ -36,13 +36,14 @@ const inlineHtml = (segments, ctx) => segments
36
36
  let href = s.url;
37
37
  try {
38
38
  const ref = parseDocLink(s.url);
39
- const target = ref && ctx.docLinks?.get(ref.file);
40
- if (target && ref)
39
+ if (ref) {
40
+ const target = ctx.docLinks?.get(ref.file) ??
41
+ `/_files/file/${encodeURIComponent(ref.file)}`;
41
42
  href =
42
43
  target +
43
44
  (ref.fragment ? `#${encodeURIComponent(ref.fragment)}` : "");
44
- // Other local files open their resource page instead of a dead relative URL.
45
- if (!ref && !/^(?:[a-z][a-z\d+.-]*:|[/#])/i.test(s.url)) {
45
+ }
46
+ else if (!/^(?:[a-z][a-z\d+.-]*:|[/#])/i.test(s.url)) {
46
47
  const { file, range } = parseFileReference(s.url);
47
48
  const local = file.replace(/^(\.\/)+/, "");
48
49
  if (localFile(local))
@@ -400,7 +401,7 @@ const blockContentHtml = (b, ctx, seg) => {
400
401
  const label = b.embed?.title ?? b.alt ?? b.subformat.ext;
401
402
  const fields = b.embed?.fields?.flatMap((name) => b.subformat?.fields.filter((field) => field.name === name) ?? []) ?? b.subformat.fields;
402
403
  const previews = b.subformat.resource
403
- ? `<template data-format-previews>${b.subformat.records.map((record) => `<div data-format-preview="${escapeHtml(JSON.stringify(record.data))}">${blocksHtml(record.preview ?? [], ctx)}</div>`).join("")}</template>`
404
+ ? `<template data-format-previews>${b.subformat.records.map((record) => `<div data-format-preview="${escapeHtml(JSON.stringify(record.data))}">${blocksHtml(record.preview ?? [], ctx)}<a class="resource-source" href="/_files/file/${encodeURIComponent(record.file)}">${escapeHtml(record.file)}</a></div>`).join("")}</template>`
404
405
  : "";
405
406
  const collection = b.subformat.resource
406
407
  ? {
@@ -450,6 +451,9 @@ const blockContentHtml = (b, ctx, seg) => {
450
451
  }
451
452
  case "term":
452
453
  return termsHtml([b.entry], ctx.language);
454
+ case "pageContents":
455
+ return (ctx.pageContents?.(b.file, b.recursive, b.title) ??
456
+ `<p>${escapeHtml(b.title ?? b.file)}</p>`);
453
457
  case "figures":
454
458
  // Figure list. The h2 doubles as the label, so captions omit it. h2 id = fig name
455
459
  // (anchor).
@@ -8,3 +8,10 @@ export declare const SUBFORMATS_ICON: string;
8
8
  /** One glyph per Library view, so views are told apart without reading their names. */
9
9
  export declare const LIBRARY_ICONS: Readonly<Record<string, string>>;
10
10
  export declare const libraryIcon: (view: string) => string | undefined;
11
+ /**
12
+ * Normalize an SVG to 1:1 (padding is added automatically = the shorter side is widened, centered;
13
+ * nothing is cropped). Builds a square viewBox from the root's viewBox (or width / height if it has
14
+ * none) and removes fixed width / height (so it scales to the display box). Returns undefined for
15
+ * SVGs whose dimensions can't be read.
16
+ */
17
+ export declare const squareSvg: (svg: string) => string | undefined;
@@ -9,6 +9,7 @@ export const SUBFORMATS_ICON = glyph('<path d="m6 6-4 4 4 4M14 6l4 4-4 4"/><circ
9
9
  /** One glyph per Library view, so views are told apart without reading their names. */
10
10
  export const LIBRARY_ICONS = {
11
11
  codeblocks: glyph('<path d="m7 6-4 4 4 4M13 6l4 4-4 4"/>'),
12
+ toc: glyph('<path d="M4 3v13m0-10h4m-4 5h4m-4 5h4m3-10h6m-6 5h6m-6 5h6"/>'),
12
13
  urls: glyph('<path d="M8.5 11.5a3 3 0 0 0 4.2 0l3-3a3 3 0 0 0-4.2-4.2l-1 1M11.5 8.5a3 3 0 0 0-4.2 0l-3 3a3 3 0 0 0 4.2 4.2l1-1"/>'),
13
14
  "url-previews": glyph('<rect x="3" y="4" width="14" height="12" rx="1.5"/><path d="M3 8h14M6 12.5h5"/>'),
14
15
  skills: glyph('<path d="M5 2.5h7l3 3v12H5ZM12 2.5V6h3M7.5 11l1.5 1.5 3.5-4"/>'),
@@ -21,3 +22,40 @@ export const LIBRARY_ICONS = {
21
22
  termth: glyph('<path d="M5 3h10v14H5Z"/><path d="m8 12 2-5 2 5M8.7 10.5h2.6"/>'),
22
23
  };
23
24
  export const libraryIcon = (view) => Object.hasOwn(LIBRARY_ICONS, view) ? LIBRARY_ICONS[view] : undefined;
25
+ const num = (v) => {
26
+ const n = v == null ? Number.NaN : Number.parseFloat(v);
27
+ return Number.isFinite(n) && n > 0 ? n : undefined;
28
+ };
29
+ /**
30
+ * Normalize an SVG to 1:1 (padding is added automatically = the shorter side is widened, centered;
31
+ * nothing is cropped). Builds a square viewBox from the root's viewBox (or width / height if it has
32
+ * none) and removes fixed width / height (so it scales to the display box). Returns undefined for
33
+ * SVGs whose dimensions can't be read.
34
+ */
35
+ export const squareSvg = (svg) => {
36
+ const root = /<svg\b[^>]*>/i.exec(svg)?.[0];
37
+ if (!root) {
38
+ return undefined;
39
+ }
40
+ const attr = (name) => new RegExp(`\\s${name}\\s*=\\s*["']([^"']*)["']`, "i").exec(root)?.[1];
41
+ const vb = attr("viewBox")
42
+ ?.trim()
43
+ .split(/[\s,]+/)
44
+ .map(Number);
45
+ let [x, y, w, h] = vb && vb.length === 4 && vb.every(Number.isFinite)
46
+ ? vb
47
+ : [0, 0, num(attr("width")), num(attr("height"))];
48
+ if (x == null || y == null || w == null || h == null || w <= 0 || h <= 0) {
49
+ return undefined;
50
+ }
51
+ const side = Math.max(w, h);
52
+ x -= (side - w) / 2;
53
+ y -= (side - h) / 2;
54
+ const round = (n) => Math.round(n * 1000) / 1000;
55
+ // Rendered via <img> (data URI), so it won't draw without xmlns — add it if missing.
56
+ const xmlns = /\sxmlns\s*=/.test(root) ? "" : ' xmlns="http://www.w3.org/2000/svg"';
57
+ const next = root
58
+ .replace(/\s(viewBox|width|height|preserveAspectRatio)\s*=\s*(["'])[^"']*\2/gi, "")
59
+ .replace(/^<svg\b/i, `<svg${xmlns} viewBox="${[x, y, side, side].map(round).join(" ")}" preserveAspectRatio="xMidYMid meet"`);
60
+ return svg.replace(root, next);
61
+ };
@@ -4,6 +4,7 @@ export interface Subformat {
4
4
  ext: string;
5
5
  format: "yaml" | "json" | "toml";
6
6
  schema: string;
7
+ files?: string[];
7
8
  /** Local SVG file shown wherever the subformat is listed. */
8
9
  icon?: string;
9
10
  layouts?: {
@@ -15,7 +16,7 @@ export interface Subformat {
15
16
  };
16
17
  }
17
18
  export interface SubformatEmbedOptions {
18
- view?: "card" | "list" | "table" | "grid";
19
+ view?: "card" | "list" | "table" | "grid" | "expand";
19
20
  columns?: number;
20
21
  rows?: number;
21
22
  folder?: string;
@@ -149,7 +149,7 @@ export const parseSubformats = (input) => {
149
149
  if (!value ||
150
150
  typeof value !== "object" ||
151
151
  Array.isArray(value) ||
152
- Object.keys(value).some((key) => !["ext", "format", "schema", "icon", "layouts"].includes(key)) ||
152
+ Object.keys(value).some((key) => !["ext", "format", "schema", "icon", "layouts", "files"].includes(key)) ||
153
153
  typeof value.ext !== "string" ||
154
154
  !/^[a-z0-9][a-z0-9_-]*$/.test(value.ext) ||
155
155
  !["yaml", "json", "toml"].includes(value.format) ||
@@ -169,6 +169,10 @@ export const parseSubformats = (input) => {
169
169
  if (value.icon !== undefined &&
170
170
  (!localFile(value.icon) || !value.icon.toLowerCase().endsWith(".svg")))
171
171
  throw new Error("Subformat icon must be a local .svg file path");
172
+ if (value.files !== undefined &&
173
+ (!Array.isArray(value.files) ||
174
+ value.files.some((file) => !localFile(file) || !file.toLowerCase().endsWith(`.${value.ext}`))))
175
+ throw new Error("Subformat files must be local record paths with the configured extension");
172
176
  if (seen.has(value.ext))
173
177
  throw new Error(`Duplicate subformat extension: ${value.ext}`);
174
178
  seen.add(value.ext);
@@ -176,6 +180,7 @@ export const parseSubformats = (input) => {
176
180
  ext: value.ext,
177
181
  format: value.format,
178
182
  schema: value.schema,
183
+ ...(value.files === undefined ? {} : { files: [...new Set(value.files)] }),
179
184
  ...(value.icon === undefined ? {} : { icon: value.icon }),
180
185
  ...(value.layouts === undefined ? {} : { layouts: { ...value.layouts } }),
181
186
  };
@@ -0,0 +1,5 @@
1
+ export declare const tocUrl: (file: string, recursive?: boolean) => string;
2
+ export declare const tocReference: (url: string) => {
3
+ file: string;
4
+ recursive: boolean;
5
+ } | undefined;
@@ -0,0 +1,27 @@
1
+ import { localFile } from "./files.js";
2
+ import { parseFileReference } from "./textfile.js";
3
+ export const tocUrl = (file, recursive = true) => file
4
+ .split("/")
5
+ .map((part) => encodeURIComponent(part).replaceAll("(", "%28").replaceAll(")", "%29"))
6
+ .join("/") +
7
+ "?library=toc" +
8
+ (recursive ? "" : "&recursive=false");
9
+ export const tocReference = (url) => {
10
+ if (!url.includes("?") || /^(?:[a-z][\w+.-]*:|\/)/i.test(url))
11
+ return;
12
+ const { file, query, range } = parseFileReference(url, true);
13
+ const params = new URLSearchParams(query);
14
+ if (!params.has("library"))
15
+ return;
16
+ if (params.get("library") !== "toc" ||
17
+ params.getAll("library").length !== 1 ||
18
+ [...params.keys()].some((key) => key !== "library" && key !== "recursive"))
19
+ throw new Error("Use ?library=toc with an optional recursive parameter");
20
+ const target = file.replace(/^(\.\/)+/, "");
21
+ if (range !== undefined || !localFile(target) || !/(?:\.md|(?:^|[/.])dooc\.yaml)$/.test(target))
22
+ throw new Error("A table of contents needs a local Markdown page or document manifest");
23
+ const recursive = params.get("recursive") ?? "true";
24
+ if (params.getAll("recursive").length > 1 || !["true", "false"].includes(recursive))
25
+ throw new Error("recursive must be true or false");
26
+ return { file: target, recursive: recursive === "true" };
27
+ };
@@ -65,6 +65,7 @@ export interface Site {
65
65
  fonts?: readonly ProjectFont[];
66
66
  workspace?: WorkspaceSource;
67
67
  filePaths?: readonly string[];
68
+ uploadDirectory?: string;
68
69
  previews?: PreviewSettings;
69
70
  title?: string;
70
71
  icon?: string;
@@ -87,9 +88,10 @@ export interface Site {
87
88
  /** Declared site languages, when the manifest restricts the language picker. */
88
89
  contentLanguages?: readonly string[];
89
90
  themes?: readonly ("light" | "dark")[];
91
+ accentColor?: string;
90
92
  }
91
93
  type NavigationEntry = Pick<Entry, "id" | "url" | "root" | "name" | "origin" | "included" | "parent" | "file" | "sourceFile" | "frontmatter" | "icon" | "subformat" | "library" | "format" | "translatedLanguages">;
92
- type NavigationSite = Pick<Site, "title" | "icon" | "workspace" | "subformats" | "contentLanguage" | "themes"> & {
94
+ type NavigationSite = Pick<Site, "title" | "icon" | "iconVariants" | "accentColor" | "workspace" | "subformats" | "contentLanguage" | "themes" | "uploadDirectory"> & {
93
95
  entries: NavigationEntry[];
94
96
  };
95
97
  export interface PublishOutput {
@@ -149,6 +151,7 @@ export interface ApplicationHost {
149
151
  sourceFileBase(root: string): string | undefined;
150
152
  gitBaseBody: typeof GitDiff.gitBaseBody;
151
153
  gitBaseText: typeof GitDiff.gitBaseText;
154
+ changedTrackedFiles: typeof GitDiff.changedTrackedFiles;
152
155
  setSubformatChanges: typeof GitDiff.setSubformatChanges;
153
156
  runCodeTool: typeof Tools.runCodeTool;
154
157
  validateCodeTools: typeof Tools.validateCodeTools;
@@ -156,7 +159,7 @@ export interface ApplicationHost {
156
159
  }
157
160
  export declare const createDocumentApplication: (root: string, host: ApplicationHost) => {
158
161
  clientShell(readOnly?: boolean): string;
159
- siteFrom: ({ title, icon, iconVariants, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: Compiled, languages?: readonly LanguageAdapter[], code?: Pick<SiteLanguages, "codeLanguages" | "codeGrammars">) => Site;
162
+ siteFrom: ({ title, icon, iconVariants, accentColor, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: Compiled, languages?: readonly LanguageAdapter[], code?: Pick<SiteLanguages, "codeLanguages" | "codeGrammars">) => Site;
160
163
  filePreviewResults: (entry: Entry, site: Site) => FilePreviewResults;
161
164
  renderEntryHtml: (site: Site, entry: Entry) => {
162
165
  html: string;