@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
@@ -5,15 +5,17 @@ import { filesSnapshot, updateFiles } from "../engine/compiler/files.js";
5
5
  import { loadProjectFonts } from "../engine/compiler/fonts.js";
6
6
  import { formatCollectionBlock, readFormatCollection, } from "../engine/compiler/format-collections.js";
7
7
  import { createHash, dirname, existsSync, join, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync, } from "../engine/compiler/host.js";
8
- import { ICONS_DIR, loadIcons, ownsDocIcon, squareSvg } from "../engine/compiler/icons.js";
8
+ import { ICONS_DIR, loadIcons, ownsDocIcon, projectIcon, siteIconAssets, squareSvg, } from "../engine/compiler/icons.js";
9
9
  import { ignoredFiles, withIgnoredFilesCache } from "../engine/compiler/ignored-files.js";
10
10
  import { contentLanguageCode, contentLanguages, isContentLanguage, webLanguage, } from "../engine/compiler/language-codes.js";
11
11
  import { setDocTranslation, siteContentLanguages, translationFile, translationFiles, } from "../engine/compiler/locales.js";
12
12
  import { manifestFile, readManifest, writeManifest } from "../engine/compiler/manifest.js";
13
13
  import { assembleDoc, createDocOps, isOpError, } from "../engine/compiler/ops.js";
14
14
  import { isRemoteSourceFile } from "../engine/compiler/remote-manifests.js";
15
+ import { rootPageSource } from "../engine/compiler/root-page.js";
16
+ import { previewSidebarRemoval, removeSidebarEntry, reviewSidebarRemoval, } from "../engine/compiler/sidebar-removal.js";
15
17
  import { readProjectSkills } from "../engine/compiler/skills.js";
16
- import { compileSubformatSchema, subformatIconSvg, subformatResponse, validateSubformatFile, } from "../engine/compiler/subformats.js";
18
+ import { compileSubformatSchema, recordSubformat, subformatIconSvg, subformatResponse, validateSubformatFile, } from "../engine/compiler/subformats.js";
17
19
  import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
18
20
  import { walkBlocks } from "../engine/core/blocks.js";
19
21
  import { selectCodeGrammars, subformatCodeGrammars } from "../engine/core/code-grammars.js";
@@ -21,7 +23,7 @@ import { docIdOfFile, flattenTree, isContentPage, pageUrlKind, } from "../engine
21
23
  import { figureFrameHtml, mountFigureFrames } from "../engine/core/figure-frame.js";
22
24
  import { defaultFilePath, docIconFile, isSkillFile, manifestDirectory, parseFileLayout, docFile as sourceDocFile, suggestDocFileName, } from "../engine/core/files.js";
23
25
  import { FORMAT_TRAITS, formatSelector, matchesFormat, parseFormatQuery, } from "../engine/core/format-collections.js";
24
- import { fileFormat, isReferenceLibrary, REFERENCE_LIBRARIES, } from "../engine/core/formats.js";
26
+ import { fenceFormat, fileFormat, isReferenceLibrary, REFERENCE_LIBRARIES, } from "../engine/core/formats.js";
25
27
  import { blocksHtml, docHtml, escapeHtml, resourceDownloadHtml, termsHtml, } from "../engine/core/html.js";
26
28
  import { FOLDER_ICON_PATH, LIBRARY_ICONS, LLM_ICON, libraryIcon, PLUGINS_ICON, SUBFORMATS_ICON, } from "../engine/core/icons.js";
27
29
  import { DEFAULT_LANG, isLangTag, resolveLanguage, } from "../engine/core/language.js";
@@ -32,6 +34,7 @@ import { CODE_LANGS, docDisplayName } from "../engine/core/taxonomy.js";
32
34
  import { isTermFile, termAnchor, termFileUrl } from "../engine/core/term-reference.js";
33
35
  import { isRemoteTextfile, textfileName } from "../engine/core/textfile.js";
34
36
  import { mountThemeVariants } from "../engine/core/theme-variants.js";
37
+ import { tocReference, tocUrl } from "../engine/core/toc-library.js";
35
38
  import { workspaceLabel } from "../engine/core/workspace.js";
36
39
  import { clientPath } from "../workspace/client-path.js";
37
40
  import { codeFileResponse } from "../workspace/code-file.js";
@@ -108,7 +111,7 @@ export const createDocumentApplication = (root, host) => {
108
111
  let compiler = createCompiler(root);
109
112
  const ops = createDocOps(root);
110
113
  /** Compile result → reader Site (shared by the server's per-request path and one-off publish). */
111
- const siteFrom = ({ title, icon, iconVariants, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }, languages = DEFAULT_SITE_LANGUAGES.languages, code = {}) => {
114
+ const siteFrom = ({ title, icon, iconVariants, accentColor, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }, languages = DEFAULT_SITE_LANGUAGES.languages, code = {}) => {
112
115
  const entries = docs.flatMap((doc) => {
113
116
  const source = sources.get(doc.file);
114
117
  return source ? [toEntry(doc, source)] : [];
@@ -149,6 +152,7 @@ export const createDocumentApplication = (root, host) => {
149
152
  ...(title === undefined ? {} : { title }),
150
153
  ...(icon === undefined ? {} : { icon }),
151
154
  ...(iconVariants === undefined ? {} : { iconVariants }),
155
+ ...(accentColor ? { accentColor } : {}),
152
156
  entries,
153
157
  ctx: {
154
158
  docLinks: new Map(docs.filter(isContentPage).map((doc) => [doc.file, docHref(docs, doc.id)])),
@@ -258,6 +262,7 @@ export const createDocumentApplication = (root, host) => {
258
262
  fonts: loadProjectFonts(root),
259
263
  workspace,
260
264
  sourceBase: sourceFileBase(root),
265
+ uploadDirectory: manifest.files?.uploadDirectory,
261
266
  filePaths: snapshot?.files.map((file) => file.path),
262
267
  contentLanguage: locale,
263
268
  };
@@ -322,26 +327,26 @@ export const createDocumentApplication = (root, host) => {
322
327
  translated.has(translationFile(sourceDocFile(current.id, manifest.files), language, current.origin))),
323
328
  ];
324
329
  }
325
- let icon;
326
- if (manifest.icon) {
327
- try {
328
- icon = squareSvg(readTextfile(root, manifest.icon));
329
- }
330
- catch { }
330
+ let siteIcons = {};
331
+ try {
332
+ siteIcons = siteIconAssets(root, manifest);
331
333
  }
334
+ catch { }
332
335
  return {
333
336
  entries,
334
337
  title,
335
- icon,
338
+ ...siteIcons,
336
339
  subformats: manifest.subformats,
340
+ uploadDirectory: manifest.files?.uploadDirectory,
337
341
  contentLanguage: locale,
338
342
  themes: manifest.themes,
343
+ accentColor: manifest.accentColor,
339
344
  workspace: workspaceSource ?? readWorkspaceSource(root),
340
345
  };
341
346
  });
342
347
  const draftContext = (site) => ({
343
348
  previews: site.previews,
344
- root,
349
+ root: site.root ?? root,
345
350
  docs: site.entries.filter(isContentPage).map((e) => ({
346
351
  id: e.id,
347
352
  url: e.url,
@@ -374,6 +379,7 @@ export const createDocumentApplication = (root, host) => {
374
379
  };
375
380
  const renderEntry = (site, entry, fallbackTitle) => docLinks(site, docHtml(entry.frontmatter ?? { title: fallbackTitle }, entry.blocks, [...site.errors, ...entry.errors], {
376
381
  ...site.ctx,
382
+ pageContents: (file, recursive, title) => contentsLibrary(site, file, recursive, title),
377
383
  ...pageDownload(site, entry),
378
384
  terms: entry.terms ?? site.ctx.terms,
379
385
  lang: webLanguage(entry.lang),
@@ -444,22 +450,36 @@ export const createDocumentApplication = (root, host) => {
444
450
  // changed. Rebuild if any of them did.
445
451
  const renderSignature = (site, entry) => JSON.stringify([site.ctx.terms, site.errors, entry.errors, entry.frontmatter, entry.lang]) +
446
452
  site.entries
447
- .map((e) => [e.sourceFile ?? CONTENT_PREFIX + e.file, docPath(site.entries, e.id)])
448
- .sort()
453
+ .map((e) => [
454
+ e.sourceFile ?? CONTENT_PREFIX + e.file,
455
+ docPath(site.entries, e.id),
456
+ e.frontmatter?.title,
457
+ e.url,
458
+ e.icon,
459
+ ])
449
460
  .join("\n");
450
461
  const entryHtmlCache = new Map();
451
462
  /** Renders only the requested doc, not every doc in site.entries. */
452
463
  const renderEntryHtml = (site, entry) => {
453
- if (entry.library || entry.format) {
454
- if (entry.format &&
455
- (entry.format.includes("/") || Object.hasOwn(FORMAT_TRAITS, entry.format)))
456
- return {
457
- html: `<article class="res-page resource-library">${renderFormatCollection(site, entry.format)}</article>`,
458
- errors: [...site.errors, ...entry.errors],
459
- };
464
+ const contents = entry.url && tocReference(entry.url);
465
+ if (entry.library === "toc" || contents) {
466
+ const file = contents
467
+ ? contents.file
468
+ : (entry.origin ?? manifestFile(site.root ?? root));
469
+ return {
470
+ html: `<article class="resource-library">${contentsLibrary(site, file, contents ? contents.recursive : true, docDisplayName(entry.frontmatter, entry.id))}</article>`,
471
+ errors: [...site.errors, ...entry.errors],
472
+ };
473
+ }
474
+ if (entry.format)
475
+ return {
476
+ html: `<article class="res-page resource-library">${renderFormatCollection(site, entry.format, "", docDisplayName(entry.frontmatter, entry.id))}</article>`,
477
+ errors: [...site.errors, ...entry.errors],
478
+ };
479
+ if (entry.library) {
460
480
  const index = resourceIndex(site.root ?? root, site.filePaths ?? filesSnapshot(site.root ?? root).files.map((item) => item.path), site.previews?.domains);
461
481
  return {
462
- html: `<article class="res-page resource-library subformat-page">${entry.format ? formatPageHtml(index, entry.format, docDisplayName(entry.frontmatter, entry.id), formatPreview(site, index.files?.map((item) => item.file) ?? [])) : libraryPageHtml(index, entry.library ?? "", docDisplayName(entry.frontmatter, entry.id))}</article>`,
482
+ html: `<article class="res-page resource-library subformat-page">${libraryPageHtml(index, entry.library, docDisplayName(entry.frontmatter, entry.id))}</article>`,
463
483
  errors: [...site.errors, ...entry.errors],
464
484
  };
465
485
  }
@@ -794,6 +814,12 @@ body.sidebar-closed #sidebar-toggle svg { visibility: hidden; }
794
814
  padding: 10px 0 8px; }
795
815
  #nav-groups { flex: 1; min-height: 0; display: flex; flex-direction: column; }
796
816
  #nav-groups > .nav-root { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable; }
817
+ #nav-groups:has(> #nav-docs[hidden])::before { content: ""; flex: 1; }
818
+ body.sidebar-closed [data-root-source], body[data-version-read-only=true] [data-root-source] { display: none; }
819
+ .root-source-fields { display: grid; gap: 12px; }
820
+ .root-source-fields label { display: grid; gap: 4px; }
821
+ .root-source-fields .root-source-depth { display: flex; align-items: center; gap: 8px; }
822
+ .root-source-fields [hidden] { display: none; }
797
823
  .language-select, .language-picker { font: 13px/18px var(--font-sans); font-weight: var(--fw-body); }
798
824
  .language-select { position: relative; }
799
825
  .language-select-input { width: 100%; min-width: 0; height: 28px; padding: 4px 26px 4px 8px;
@@ -838,7 +864,7 @@ body.sidebar-closed #document-versions { padding: 8px 4px 12px; }
838
864
  body.sidebar-closed #document-versions :is(.subformat-control-label, .version-select > .version-status) { display: none; }
839
865
  body.sidebar-closed #document-versions .version-select .language-select-input { display: block; height: 36px; padding: 3px 2px 13px; font-size: 11px; text-align: center; }
840
866
  body.sidebar-closed .version-select::after { top: 26px; right: calc(50% - 2px); width: 4px; height: 4px; }
841
- body[data-version-read-only="true"] :is(.nav-doc-actions, .nav-icon-clear, #site-icon-slot input, #save, #validate, .cm-textfile-validate) { display: none; }
867
+ body[data-version-read-only="true"] :is(.nav-doc-actions, .nav-icon-clear, #site-icon-slot .nav-icon-pick, #save, #validate, .cm-textfile-validate) { display: none; }
842
868
  .nav-link { position: relative; display: flex; align-items: center; gap: 14px; padding: 10px 16px;
843
869
  color: var(--c-fg-muted); text-decoration: none; background: transparent; border: none;
844
870
  font: inherit; text-align: left; cursor: pointer; min-width: 0; }
@@ -880,10 +906,10 @@ body[data-version-read-only="true"] :is(.nav-doc-actions, .nav-icon-clear, #site
880
906
  .nav-list > .nav-item.open { grid-template-rows: auto 1fr; }
881
907
  .nav-item > .nav-list { min-height: 0; overflow: hidden; visibility: hidden; transition: visibility 0s 260ms; }
882
908
  .nav-item.open > .nav-list { visibility: visible; transition-delay: 0s; }
883
- .nav-tree-toggle { flex: none; display: flex; align-items: center; justify-content: center;
909
+ .nav-tree-toggle, [data-root-source] { flex: none; display: flex; align-items: center; justify-content: center;
884
910
  width: 28px; height: 28px; margin-right: 6px; padding: 0; background: transparent; border: none;
885
911
  border-radius: 4px; color: var(--c-fg-faint); cursor: pointer; }
886
- .nav-tree-toggle:hover { color: var(--c-fg); }
912
+ .nav-tree-toggle:hover, [data-root-source]:hover { color: var(--c-fg); }
887
913
  .nav-tree-toggle svg { transition: transform var(--nav-motion); }
888
914
  .nav-tree-toggle[aria-expanded="true"]:not([data-expansion="all"]) svg { transform: rotate(90deg); }
889
915
  .nav-tree-toggle .nav-chevron-double, .nav-tree-toggle[data-expansion="all"] .nav-chevron-single, .nav-tree-toggle[hidden], #nav-docs[hidden] { display: none; }
@@ -968,8 +994,8 @@ body.sidebar-closed #nav-groups .nav-doc-icon { z-index: 1; pointer-events: none
968
994
  .workspace-location::-webkit-details-marker { display: none; }
969
995
  .workspace-location:hover { color: var(--c-fg); }
970
996
  .workspace-location > .nav-icon { flex: none; width: 14px; height: 14px; background: var(--c-bg1); }
971
- .workspace-location > .nav-icon:last-child { margin-left: auto; }
972
- #nav-tools[open] > .workspace-location > .nav-icon:last-child { transform: rotate(90deg); }
997
+ .workspace-location > .nav-icon:nth-last-child(2) { margin-left: auto; }
998
+ #nav-tools[open] > .workspace-location > .nav-icon:nth-last-child(2) { transform: rotate(90deg); }
973
999
  .workspace-address { min-width: 0; padding: 0 2px; background: var(--c-bg1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
974
1000
  body.sidebar-closed #nav-tools { margin-left: 4px; margin-right: 4px; padding-left: 0; padding-right: 0; }
975
1001
  body.sidebar-closed .workspace-location { left: 2px; right: 2px; min-height: 16px; }
@@ -985,16 +1011,21 @@ body.sidebar-closed .workspace-address { display: none; }
985
1011
  .files-upload-status:empty { display: none; }
986
1012
  .files-upload-status[data-state="error"] { color: var(--c-danger); }
987
1013
  .files-upload-status[data-state="done"] { color: var(--doc-ok); }
988
- .files-drop-hint, .extensions-drop-hint { position: absolute; inset: 0; display: none; align-items: center;
989
- justify-content: center; gap: 6px; padding: 6px; pointer-events: none; text-align: center; }
990
- .files-drop-hint > svg { width: 28px; height: 28px; }
991
- .files-drop-hint ul { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 8px;
992
- margin: 0; padding: 0; list-style: none; font: 11px var(--doc-mono); color: var(--c-fg-muted); }
993
- @container (max-height: 140px) { .files-drop-hint ul { display: none; } }
994
- body.files-dragging #nav-files { border-color: var(--c-accent); }
995
- body.files-dragging :is(#nav-files, #nav-extensions) > .nav-item { opacity: .15; }
996
- body.files-dragging :is(.files-drop-hint, .extensions-drop-hint) { display: flex; }
997
- body.files-over #nav-files { background: color-mix(in srgb, var(--c-accent) 10%, var(--c-bg1)); }
1014
+ .files-drop-hint, .extensions-drop-hint { display: none; }
1015
+ body.files-dragging #nav-tools { min-height: 104px; border: 1px dashed var(--c-accent); border-radius: 8px; background: var(--c-bg1); }
1016
+ body.files-dragging #nav-tools .workspace-location { inset: 0; transform: none; justify-content: center; pointer-events: none; }
1017
+ body.files-dragging #nav-tools .workspace-location > :not(.files-drop-hint) { display: none; }
1018
+ body.files-dragging .nav-tool-cards > * { visibility: hidden; }
1019
+ body.files-dragging .files-drop-hint { display: grid; justify-items: center; gap: 6px; padding: 8px; color: var(--c-fg); font: 12px/1.4 var(--font-sans); text-align: center; }
1020
+ .files-drop-hint svg { width: 27px; height: 27px; color: var(--c-accent); }
1021
+ .files-drop-hint > span { color: var(--c-fg-muted); }
1022
+ body.files-plugin-drag #nav-extensions { z-index: 4; visibility: visible; }
1023
+ body.files-plugin-drag #nav-extensions .nav-item { visibility: hidden; }
1024
+ body.files-plugin-drag #nav-extensions .extensions-drop-hint { display: flex; height: 100%; gap: 6px; align-items: center; justify-content: center; color: var(--c-fg-muted); font-size: 11px; position: absolute; inset: 0; pointer-events: none; }
1025
+ body.files-over #nav-tools, .files-table tr.file-drop-over > td, .nav-doc-row.file-drop-over, #site-icon-slot.file-drop-over { background: color-mix(in srgb, var(--c-accent) 12%, var(--c-bg1)); }
1026
+ :is(.nav-doc-icon, #site-icon-slot, .nav-placeholder, #files-manager).file-drop-over { outline: 2px solid var(--c-accent); outline-offset: -2px; }
1027
+ body.sidebar-closed.files-dragging #nav-groups .files-drop-hint { display: flex; }
1028
+ body.sidebar-closed .files-drop-hint > :not(svg) { display: none; }
998
1029
  #nav-status { min-height: 16px; margin: 6px 16px 0; color: var(--c-fg-faint); font-size: 11px;
999
1030
  line-height: 1.35; }
1000
1031
  #nav-status.err { color: var(--c-danger); }
@@ -1275,6 +1306,7 @@ article blockquote > :first-child { margin-top: 0; }
1275
1306
  article blockquote > :last-child { margin-bottom: 0; }
1276
1307
  ul.idx { list-style: none; padding: 0; }
1277
1308
  ul.idx li { margin: 10px 0; }
1309
+ ul.idx ul { list-style: none; padding-inline-start: 16px; margin-inline-start: 20px; border-inline-start: 1px solid var(--doc-border); }
1278
1310
  ul.idx a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--doc-border); border-radius: 6px; color: var(--doc-fg); text-decoration: none; }
1279
1311
  ul.idx a:hover { background: var(--doc-panel-2); }
1280
1312
  ul.idx a > .nav-icon { width: 18px; height: 18px; }
@@ -1397,6 +1429,13 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1397
1429
  .manifest-completions button { border: 0; border-radius: 0; background: transparent; }
1398
1430
  .resources-pane .manifest-tabs { margin: 0 0 4px; padding: 0; }
1399
1431
  .manifest-tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 14px; background: transparent; color: var(--c-fg-muted); }
1432
+ .manifest-icon-field, .manifest-color-field { display:flex; align-items:end; gap:6px; }
1433
+ .manifest-icon-field .manifest-field, .manifest-color-field .manifest-field { flex:1; min-width:0; }
1434
+ .manifest-icon-field button, .manifest-color-field input[type="color"] { width:32px; height:32px; flex:none; padding:4px; cursor:pointer; }
1435
+ .cm-accent-picker { width: 24px; height: 20px; padding: 0 2px; margin-inline-start: 4px; border: 0; background: transparent; vertical-align: middle; cursor: pointer; }
1436
+ .manifest-icon-field button { display:grid; place-items:center; }
1437
+ .manifest-icon-field img { width:18px; height:18px; object-fit:contain; }
1438
+ .manifest-icon-field img:not([src]), .manifest-icon-field button:has(img[src]) svg { display:none; }
1400
1439
  .manifest-tabs button[aria-selected="true"] { color: var(--c-accent); border-bottom-color: currentColor; }
1401
1440
  .manifest-fields { min-width: 0; margin: 0; padding: 12px 0; border: 0; }
1402
1441
  .manifest-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 16px; min-width: 0; }
@@ -1610,6 +1649,7 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1610
1649
  .format-navigation code { color: var(--doc-fg-3); overflow-wrap: anywhere; }
1611
1650
  .format-navigation select, .format-folder select { min-height: 34px; border: 1px solid var(--c-line); border-radius: 4px; padding: 4px 8px; background: var(--doc-bg); color: var(--doc-fg); font: inherit; box-sizing: border-box; }
1612
1651
  .format-navigation select { max-width: min(240px, 65vw); }
1652
+ .toc-library-options > code { flex-basis: 100%; user-select: all; }
1613
1653
  .format-collection .subformat-embed-toolbar { align-items: center; gap: 8px; }
1614
1654
  .format-collection .format-folder { display: block; flex: 1 1 120px; max-width: 240px; margin: 0; order: 1; }
1615
1655
  .format-folder select { width: 100%; max-width: none; }
@@ -1629,7 +1669,8 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1629
1669
  .format-grid-boxes { display: block; width: 100%; height: 100%; stroke: currentColor; stroke-width: 1; fill: color-mix(in srgb, currentColor 8%, transparent); }
1630
1670
  .format-grid-boxes > * { vector-effect: non-scaling-stroke; }
1631
1671
  .format-grid-ellipsis { fill: none; stroke-width: 1.5; stroke-linecap: round; }
1632
- .format-grid-grip { position: absolute; right: -12px; bottom: -12px; display: grid; place-items: center; width: 24px; height: 24px; background: var(--c-bg1); color: var(--doc-fg); }
1672
+ .format-grid-grip { fill: none; stroke: currentColor; stroke-linecap: round; }
1673
+ .format-column-count { display: inline-flex; align-items: center; gap: 6px; }
1633
1674
  .format-display-settings { order: 5; font: 12px/1.6 var(--font-sans); }
1634
1675
  .format-display-settings > button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; }
1635
1676
  .format-display-fields { width: min(300px, calc(100vw - 16px)); padding: 16px 12px; }
@@ -1650,6 +1691,10 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1650
1691
  .format-gallery > button:enabled:hover { background: var(--c-raised); }
1651
1692
  .format-collection :is(.format-gallery > button, .format-view-switch button, .format-display-settings > button, .format-grid-size > button):focus-visible { outline: 2px solid var(--doc-accent); outline-offset: -2px; }
1652
1693
  .format-collection [data-subformat-view="grid"] .subformat-cards { display: grid; grid-template-columns: repeat(var(--format-columns, 3), minmax(min(100%, 240px), 1fr)); gap: 16px; }
1694
+ .format-collection [data-subformat-view="expand"] .subformat-cards { display: grid; grid-template-columns: repeat(var(--format-columns, 3), minmax(0, 1fr)); gap: 16px; align-items: start; }
1695
+ .format-collection [data-subformat-board][data-subformat-view="expand"] { max-height: none; overflow: visible; }
1696
+ .format-collection [data-subformat-view="expand"] .format-card > .format-preview:has(.fig) { container-type: normal; min-height: 0; max-height: none; }
1697
+ .format-collection [data-subformat-view="expand"] .format-preview .fig > img:not(.resource-modal *) { width: 100%; height: auto; max-height: none; }
1653
1698
  .format-collection .format-card { display: flex; flex-direction: column; padding: 0; border-radius: 8px; overflow: hidden; }
1654
1699
  .format-card-header { display: flex; align-items: center; gap: 8px; padding: 3px 8px; min-height: 32px; border-bottom: 1px solid var(--c-line); }
1655
1700
  .format-card-header > h3 { flex: 1; min-width: 0; margin: 0; font: 500 13px/1.4 var(--font-sans); }
@@ -1663,6 +1708,8 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1663
1708
  .format-preview :is(img, video, iframe):not(.resource-modal *) { max-width: 100%; max-height: 220px; object-fit: contain; }
1664
1709
  .format-card > .format-preview { display: grid; flex: 1; align-items: center; min-height: 180px; padding: 12px; box-sizing: border-box; background: var(--doc-bg-2); }
1665
1710
  .format-card > .format-preview .fig > :is(img, iframe) { margin-inline: auto; }
1711
+ .format-card > .format-preview:has(.fig > :is(img, iframe[data-doc-figure-frame="svg"])) { container-type: size; grid-template-columns: minmax(0, 1fr); }
1712
+ .format-card > .format-preview .fig > :is(img, iframe[data-doc-figure-frame="svg"]):not(.resource-modal *) { max-height: 100cqh; }
1666
1713
  .format-card > .format-preview:has(video) { display: block; min-height: 0; max-height: none; padding: 0; overflow: visible; }
1667
1714
  .format-card > .format-preview .video-player > video:not(.resource-modal *) { height: 180px; border-radius: 0; }
1668
1715
  .format-card .video-controls:not(.resource-modal *) { flex-wrap: wrap; padding: 6px 10px; gap: 4px; border-top: 1px solid var(--c-line); }
@@ -1775,7 +1822,60 @@ body.extensions-over #nav-extensions, body.extensions-over .extensions-dropzone
1775
1822
  .app-dialog button { padding: 7px 14px; color: inherit; background: var(--c-bg0); border: 1px solid var(--c-line); border-radius: 5px; cursor: pointer; }
1776
1823
  .app-dialog button:hover { background: var(--c-raised); border-color: var(--c-fg-muted); }
1777
1824
  .app-dialog button:focus-visible { outline-color: var(--c-fg-muted); }
1825
+ .sidebar-removal, .removal-summary { margin-bottom: 18px; min-width: 0; }
1826
+ .sidebar-removal [hidden] { display: none; }
1827
+ .removal-scroll, .removal-summary { max-height: min(58dvh, 440px); overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
1828
+ .removal-tree, .removal-tree ul { list-style: none; margin: 0; padding: 0; }
1829
+ .removal-tree .nav-tree { --nav-pad: min(calc(4px + var(--removal-depth) * 23px), 40%); --nav-line: calc(var(--nav-pad) - 16px); }
1830
+ .removal-tree .nav-tree > .nav-item > .nav-row::before { width: 11px; }
1831
+ .removal-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 36px; padding: 2px 4px 2px var(--nav-pad, 4px); }
1832
+ .removal-row > label { display: flex; align-items: center; gap: 8px; min-height: 30px; min-width: 0; cursor: pointer; }
1833
+ .removal-row label span { overflow-wrap: anywhere; }
1834
+ .removal-row:focus-within, .removal-row:hover { background: var(--c-raised); }
1835
+ .removal-all { position: sticky; inset-block-start: 0; z-index: 4; border-bottom: 1px solid var(--c-line); background: var(--c-bg1); font-weight: 600; }
1836
+ .removal-modes { flex: none; display: inline-flex; overflow: hidden; border: 1px solid var(--c-line); border-radius: 5px; }
1837
+ .removal-modes button { display: grid; place-items: center; min-width: 30px; height: 28px; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--c-fg-muted); }
1838
+ .removal-modes button + button { border-inline-start: 1px solid var(--c-line); }
1839
+ .removal-modes button[aria-pressed=true] { color: var(--c-fg); background: var(--c-line); }
1840
+ .removal-modes button:disabled { opacity: .4; cursor: default; }
1841
+ .removal-modes button:focus-visible { outline-offset: -3px; }
1842
+ .removal-sources { margin-inline-start: calc(var(--nav-pad, 4px) + 23px); font-size: 12px; }
1843
+ .removal-sources label { display: flex; align-items: center; gap: 8px; min-height: 30px; overflow-wrap: anywhere; }
1844
+ .removal-summary > * + * { border-top: 1px solid var(--c-line); }
1845
+ .removal-stat { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 38px; padding: 4px; }
1846
+ .removal-stat::before { content: ""; }
1847
+ summary.removal-stat { cursor: pointer; list-style: none; }
1848
+ summary.removal-stat::-webkit-details-marker { display: none; }
1849
+ summary.removal-stat::before { width: 5px; height: 5px; border: solid currentColor; border-width: 0 1px 1px 0; transform: rotate(-45deg); }
1850
+ details[open] > summary.removal-stat::before { transform: rotate(45deg); }
1851
+ .removal-stat strong { font-variant-numeric: tabular-nums; }
1852
+ .removal-subtotal { position: relative; padding-inline-start: 20px; color: var(--c-fg-muted); }
1853
+ .removal-subtotal::before { content: ""; position: absolute; inset-inline-start: 7px; inset-block-start: 0; width: 10px; height: 19px; border-inline-start: 1px solid var(--c-line); border-block-end: 1px solid var(--c-line); pointer-events: none; }
1854
+ .removal-summary ul { margin: 0 0 8px; padding-inline-start: 38px; overflow-wrap: anywhere; }
1855
+ .removal-summary li { padding-block: 2px; }
1856
+ .removal-summary code { color: var(--c-fg-muted); }
1857
+ .app-dialog:has(.removal-summary) .dialog-actions > :first-child { margin-inline-end: auto; }
1858
+ @media (forced-colors: active) { .removal-modes button[aria-pressed=true] { outline: 1px solid Highlight; outline-offset: -2px; } }
1859
+ @media (pointer: coarse) {
1860
+ .removal-row, .removal-row label, .removal-modes button { min-height: 44px; }
1861
+ .removal-modes button { min-width: 44px; }
1862
+ }
1778
1863
  .app-dialog button.danger { color: var(--c-danger); }
1864
+ .file-placement, .icon-picker { display: grid; gap: 14px; margin-bottom: 18px; }
1865
+ .file-placement label { display: grid; gap: 5px; font-weight: 600; }
1866
+ .file-placement :is(input, select), .icon-picker input[type=search] { width: 100%; box-sizing: border-box; min-width: 0; min-height: 34px; padding: 5px 8px; border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-bg0); color: var(--c-fg); font: inherit; }
1867
+ .file-placement-list { max-height: min(36dvh, 280px); overflow: auto; padding: 0; margin: 0; list-style: none; }
1868
+ .file-placement-list li { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 4px 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--c-line); overflow-wrap: anywhere; }
1869
+ .file-placement-list li > :is(small, select, input) { grid-column: 2; }
1870
+ .file-placement-list small, .icon-picker small { color: var(--c-fg-muted); }
1871
+ .file-placement-list svg { display: block; color: var(--c-fg-muted); }
1872
+ .icon-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(110px, 100%), 1fr)); gap: 6px; max-height: min(48dvh, 360px); overflow: auto; }
1873
+ .icon-picker-grid button { display: grid; gap: 3px; align-content: start; justify-items: center; overflow-wrap: anywhere; min-width: 0; }
1874
+ .icon-picker-grid button[hidden] { display: none; }
1875
+ .icon-picker-grid img { width: 36px; height: 36px; object-fit: contain; margin: 3px 0 5px; }
1876
+ .icon-picker > button { justify-self: start; }
1877
+ .app-dialog:has(.file-placement) .dialog-actions button:last-child { color: var(--c-bg0); background: var(--c-fg); }
1878
+
1779
1879
  .history-dialog input { box-sizing: border-box; width: 100%; padding: 8px; color: var(--c-fg); background: var(--c-bg0); border: 1px solid var(--c-line); border-radius: 4px; font: inherit; }
1780
1880
  .history-dialog ul { max-height: 50dvh; margin: 12px 0 20px; padding: 0; overflow-y: auto; list-style: none; color: var(--c-fg-muted); }
1781
1881
  .history-dialog li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
@@ -1883,10 +1983,10 @@ a.file-editor-title:hover { color: var(--c-accent); text-decoration: underline;
1883
1983
  body.git-diff-hidden .cm-lineNumbers :is(.cm-git-added, .cm-git-modified, .cm-git-deleted-start, .cm-git-deleted-end) { box-shadow: none; }
1884
1984
  body.git-diff-hidden .cm-line:is(.cm-git-added, .cm-git-modified, .cm-git-deleted-start, .cm-git-deleted-end) { background-color: transparent; }
1885
1985
  #site-title .nav-rename-form { inset: 0; padding: 0; }
1886
- #site-icon-slot input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
1986
+ #site-icon-slot .nav-icon-pick { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
1887
1987
  #site-icon-slot:hover, #site-icon-slot:focus-within, #sidebar-head.over #site-icon-slot { background: var(--c-line); border-radius: 3px; }
1888
1988
  #site-icon-slot:focus-within, #sidebar-head.over #site-icon-slot { outline: 1px solid var(--c-fg-muted); outline-offset: 2px; }
1889
- body.sidebar-closed #site-icon-slot input { display: none; }
1989
+ body.sidebar-closed #site-icon-slot .nav-icon-pick { display: none; }
1890
1990
  /* Right panel = header / properties / editor stacked on one surface, separated by rules (no
1891
1991
  nested frames). */
1892
1992
  #panel { width: var(--panel-width, min(760px, 52vw)); flex-shrink: 0; position: sticky; top: 0; height: 100dvh; container: editor-panel / inline-size;
@@ -1944,10 +2044,11 @@ body.textfile-open:has(#file-editor:is(form), #file-editor .cm-content[contented
1944
2044
  .schema-builder .schema-type-control > .subformat-control-label { padding: 0 4px; }
1945
2045
  .schema-builder :is(input, textarea) { width: 100%; }
1946
2046
  .schema-builder textarea { resize: vertical; }
1947
- .schema-builder input[type="checkbox"] { flex: none; width: 14px; height: 14px; margin: 0; padding: 0; border-color: var(--c-fg-muted); border-radius: 3px; background: transparent; }
1948
- .schema-builder input[type="checkbox"]:checked { border-color: var(--c-fg-muted); }
1949
- .schema-builder input[type="checkbox"]:checked::after { left: 4px; top: 1px; width: 3px; height: 7px; border-color: var(--c-fg); border-width: 0 1.5px 1.5px 0; }
1950
- .schema-builder input[type="checkbox"]:focus-visible { outline: 1px solid var(--c-fg-muted); outline-offset: 3px; }
2047
+ :is(.schema-builder, .sidebar-removal) input[type="checkbox"] { flex: none; width: 14px; height: 14px; margin: 0; padding: 0; border-color: var(--c-fg-muted); border-radius: 3px; background: transparent; }
2048
+ :is(.schema-builder, .sidebar-removal) input[type="checkbox"]:checked { border-color: var(--c-fg-muted); }
2049
+ :is(.schema-builder, .sidebar-removal) input[type="checkbox"]:checked::after { left: 4px; top: 1px; width: 3px; height: 7px; border-color: var(--c-fg); border-width: 0 1.5px 1.5px 0; }
2050
+ :is(.schema-builder, .sidebar-removal) input[type="checkbox"]:indeterminate::after { left: 50%; top: 50%; width: 7px; height: 0; border: 0; border-top: 1.5px solid var(--c-fg); transform: translate(-50%, -50%); }
2051
+ :is(.schema-builder, .sidebar-removal) input[type="checkbox"]:focus-visible { outline: 1px solid var(--c-fg-muted); outline-offset: 3px; }
1951
2052
  .schema-builder button { cursor: pointer; }
1952
2053
  .schema-builder button:hover { background: var(--c-raised); }
1953
2054
  .schema-builder button:disabled { opacity: .45; cursor: default; }
@@ -2097,8 +2198,8 @@ body.edit #nav-groups { --nav-rail: 22px; --nav-icon-half: 9px; }
2097
2198
  .nav-doc-name { display: flex; flex: 1; flex-direction: column; min-width: 0; line-height: 17px; }
2098
2199
  .nav-doc-icon { position: relative; flex: none; display: flex; align-items: center; justify-content: center;
2099
2200
  width: 20px; height: 24px; cursor: pointer; border-radius: 3px; color: var(--c-fg-faint); }
2100
- .nav-doc-icon:hover, .nav-doc-icon.over, .nav-doc-icon:focus-within { background: var(--c-line); color: var(--c-fg); }
2101
- .nav-doc-icon input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
2201
+ .nav-doc-icon:hover, .nav-doc-icon.file-drop-over, .nav-doc-icon:focus-within { background: var(--c-line); color: var(--c-fg); }
2202
+ .nav-doc-icon .nav-icon-pick { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
2102
2203
  .nav-doc-icon > :is(.nav-icon, .doc-icon-frame) { width: 18px; height: 18px; }
2103
2204
  .nav-icon-clear { position: absolute; right: -4px; top: -4px; width: 13px; height: 13px; padding: 0;
2104
2205
  border: 1px solid var(--c-line); border-radius: 50%; font: 10px/11px sans-serif;
@@ -2183,7 +2284,8 @@ main.editor-workspace { padding: 0; height: 100dvh; display: flex; flex-directio
2183
2284
  #preview-panes.split .preview-pane.active { border-top-color: var(--c-accent); }
2184
2285
  #preview-panes .preview-pane:has(> .pane-resource .document-web, > .preview-content:not([hidden]) .document-web) { position: relative; padding: 0; border: 0; overflow: hidden; }
2185
2286
  .preview-pane:has(> .preview-content:not([hidden]) .document-web) > .pane-actions { display: none; }
2186
- .preview-pane:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
2287
+ #preview-panes:not(.split) > .preview-pane:focus-visible { outline:none; }
2288
+ #preview-panes.split .preview-pane:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }
2187
2289
  @media (max-width: 820px) {
2188
2290
  body.edit:has(#panel) { display: grid; grid-template-columns: 52px minmax(0, 1fr); grid-template-rows: 50dvh 50dvh; height: 100dvh; min-height: 0; overflow: hidden; }
2189
2291
  body.edit:has(#panel) #sidebar { grid-column: 1; grid-row: 1 / 3; height: 100dvh; z-index: 10; }
@@ -2336,7 +2438,7 @@ body.corr main article > [data-ln].corr-hi {
2336
2438
  background: transparent; color: var(--c-fg-muted); cursor: pointer; opacity: 0; }
2337
2439
  .nav-row:hover :is(.new, .nav-delete), .nav-row:focus-within :is(.new, .nav-delete),
2338
2440
  .nav-row.renaming :is(.nav-rename-save, .nav-rename-cancel) { opacity: 1; }
2339
- .nav-row.renaming > :is(.new, .nav-delete, .nav-tree-toggle, .nav-tree-spacer, .llm-trigger) { display: none; }
2441
+ .nav-row.renaming > :is(.new, .nav-delete, .nav-tree-toggle, .nav-tree-spacer) { display: none; }
2340
2442
  .nav-row :is(.new, .nav-delete, .nav-create, .nav-rename-save, .nav-rename-cancel):is(:hover, :focus-visible) { background: var(--c-line); }
2341
2443
  .nav-row :is(.nav-rename-save, .nav-rename-cancel):disabled { opacity: .5; cursor: wait; }
2342
2444
  .nav-row :is(.nav-rename-save, .nav-rename-cancel) svg { width: 15px; height: 15px; }
@@ -2439,16 +2541,21 @@ body.edit .nav-row { cursor: grab; }
2439
2541
  // shortcut: Edit included tree structure in its manifest until cross-manifest transactions are supported.
2440
2542
  if (mode === "edit" && !e.origin) {
2441
2543
  link = `<a class="${depth === 0 ? "nav-link" : "nav-tree-link"}${cur}" href="/${e.id}" title="${label}" aria-keyshortcuts="F2"><span class="nav-doc-name"><span class="nav-label">${label}</span></span></a>`;
2442
- editableIcon = `<span class="nav-doc-icon" title="icon" data-i18n-title="icon">${entryIcon(e, "doc-icon")}<input type="file" accept=".svg,image/svg+xml" aria-label="icon" data-i18n-aria-label="icon">${e.icon ? '<button class="nav-icon-clear" type="button" title="Remove icon" data-i18n-title="Remove icon" aria-label="Remove icon" data-i18n-aria-label="Remove icon">×</button>' : ""}</span>`;
2544
+ editableIcon = `<span class="nav-doc-icon" title="icon" data-i18n-title="icon">${entryIcon(e, "doc-icon")}<button class="nav-icon-pick" type="button" aria-label="Choose an icon" data-i18n-aria-label="Choose an icon" aria-haspopup="dialog"></button>${e.icon ? '<button class="nav-icon-clear" type="button" title="Remove icon" data-i18n-title="Remove icon" aria-label="Remove icon" data-i18n-aria-label="Remove icon">×</button>' : ""}</span>`;
2443
2545
  actions = `<button class="new" type="button" data-parent="${escapeHtml(e.id)}" popovertarget="nav-page-menu" aria-haspopup="menu" title="Add doc" data-i18n-title="Add doc" aria-label="Add doc" data-i18n-aria-label="Add doc">${PLUS_ICON}</button><button class="nav-delete" type="button" data-doc-action="delete" title="Delete doc" data-i18n-title="Delete doc" aria-label="Delete doc" data-i18n-aria-label="Delete doc">${DELETE_ICON}</button>`;
2444
2546
  }
2547
+ if (mode === "edit" &&
2548
+ e.included &&
2549
+ !site.entries.find((parent) => parent.id === e.parent)?.origin &&
2550
+ !actions)
2551
+ actions = `<button class="nav-delete" type="button" data-doc-action="delete" title="Delete doc" data-i18n-title="Delete doc" aria-label="Delete doc" data-i18n-aria-label="Delete doc">${DELETE_ICON}</button>`;
2445
2552
  const branch = childrenOf(site.entries, e.id).length > 0;
2446
2553
  const toggle = branch
2447
2554
  ? `<button class="nav-tree-toggle" type="button" aria-expanded="${open.has(e.id)}" aria-label="Toggle ${label}">${DISCLOSURE_ICON}</button>`
2448
2555
  : mode === "edit"
2449
2556
  ? '<span class="nav-tree-spacer" aria-hidden="true"></span>'
2450
2557
  : "";
2451
- return `<div class="nav-item${open.has(e.id) ? " open" : ""}" data-doc-id="${escapeHtml(e.id)}"${!isContentPage(e) ? " data-subformat-nav" : ""}><div class="nav-row${mode === "edit" && !e.origin ? " nav-doc-row" : ""}"${mode === "edit" && !e.origin ? ' draggable="true"' : ""}>${editableIcon}${link}${actions}${toggle}</div>${list(e.id, depth + 1)}</div>`;
2558
+ return `<div class="nav-item${open.has(e.id) ? " open" : ""}" data-doc-id="${escapeHtml(e.id)}"${mode === "edit" && isContentPage(e) ? ` data-source-file="${escapeHtml(e.sourceFile ?? CONTENT_PREFIX + e.file)}"` : ""}${!isContentPage(e) ? " data-subformat-nav" : ""}><div class="nav-row${mode === "edit" && !e.origin ? " nav-doc-row" : ""}"${mode === "edit" && !e.origin ? ' draggable="true"' : ""}>${editableIcon}${link}${actions}${toggle}</div>${list(e.id, depth + 1)}</div>`;
2452
2559
  })
2453
2560
  .join("");
2454
2561
  const placeholder = mode === "edit" && depth === 0
@@ -2503,16 +2610,16 @@ body.edit .nav-row { cursor: grab; }
2503
2610
  const format = currentRes?.startsWith("_format") ||
2504
2611
  ["codeblocks", "_library/codeblocks", "dictionary", "code"].includes(currentRes ?? "");
2505
2612
  const library = !format && (currentRes?.startsWith("_library") || isReferenceLibrary(currentRes));
2506
- const hint = `<div class="files-drop-hint" aria-hidden="true">${UPLOAD_ICON}<span data-i18n="Upload files">Upload files</span></div>`;
2613
+ const hint = `<span class="files-drop-hint" aria-hidden="true">${UPLOAD_ICON}<strong data-i18n="Drop files here">Drop files here</strong><span data-i18n="Choose where to place them">Choose where to place them</span></span>`;
2507
2614
  const location = source?.protocol === "git"
2508
- ? `<summary class="workspace-location" aria-label="Workspace tools" data-i18n-aria-label="Workspace tools" data-workspace-protocol="git" title="${escapeHtml(`${source.repo ?? "repo"}[${source.branch}]`)}">${GIT_ICON}<span class="workspace-address"><span class="git-repo-name">${escapeHtml(source.repo ?? "repo")}</span><span class="git-branch-caption">[${escapeHtml(source.branch)}]</span></span>${CHEVRON_ICON}</summary>`
2509
- : `<summary class="workspace-location" aria-label="Workspace tools" data-i18n-aria-label="Workspace tools" id="nav-storage" data-workspace-protocol="storage" title="${escapeHtml(workspaceName(site))}">${workspaceIcon(site)}<span class="workspace-address">${escapeHtml(source?.folder ?? "Files")} / ${escapeHtml(source?.service ?? "Local")}</span>${CHEVRON_ICON}</summary>`;
2615
+ ? `<summary class="workspace-location" aria-label="Workspace tools" data-i18n-aria-label="Workspace tools" data-workspace-protocol="git" title="${escapeHtml(`${source.repo ?? "repo"}[${source.branch}]`)}">${GIT_ICON}<span class="workspace-address"><span class="git-repo-name">${escapeHtml(source.repo ?? "repo")}</span><span class="git-branch-caption">[${escapeHtml(source.branch)}]</span></span>${CHEVRON_ICON}${hint}</summary>`
2616
+ : `<summary class="workspace-location" aria-label="Workspace tools" data-i18n-aria-label="Workspace tools" id="nav-storage" data-workspace-protocol="storage" title="${escapeHtml(workspaceName(site))}">${workspaceIcon(site)}<span class="workspace-address">${escapeHtml(source?.folder ?? "Files")} / ${escapeHtml(source?.service ?? "Local")}</span>${CHEVRON_ICON}${hint}</summary>`;
2510
2617
  const git = source?.protocol === "git" && sharedBranch === undefined
2511
2618
  ? `<div class="nav-resources" id="nav-git"><div class="nav-item" data-node-id="_git"><div class="nav-row"><a class="nav-link${currentRes === "_git" ? " cur" : ""}" href="/_git" title="Git controls" data-i18n-title="Git controls">${GIT_ICON}<span class="nav-label">Git</span></a></div></div></div>`
2512
2619
  : "";
2513
2620
  const extensions = `<div class="nav-resources" id="nav-extensions" data-scope="${createHash("sha256").update(root).digest("hex")}"><div class="nav-item" data-node-id="_extensions"><div class="nav-row"><a class="nav-link${currentRes === "_extensions" ? " cur" : ""}" href="/_extensions" title="Plugins" data-i18n-title="Plugins">${PLUGINS_ICON}<span class="nav-label" data-i18n="Plugins">Plugins</span></a></div></div><div class="extensions-drop-hint" aria-hidden="true">${PLUGINS_ICON}<span data-i18n="Add plugins">Add plugins</span></div></div>`;
2514
- const subformats = `<div class="nav-resources" id="nav-subformats"><div class="nav-item" data-node-id="_subformats"><div class="nav-row"><a class="nav-link${currentRes === "_subformats" ? " cur" : ""}" href="/_subformats" title="Subformats" data-i18n-title="Subformats">${SUBFORMATS_ICON}<span class="nav-label" data-i18n="Subformats">Subformats</span></a></div></div></div><div class="nav-resources" id="nav-llm"><div class="nav-item" data-node-id="_llm"><div class="nav-row"><a class="nav-link${currentRes === "_llm" ? " cur" : ""}" href="/_llm" title="LLM">${LLM_ICON}<span class="nav-label">LLM</span></a></div></div></div>`;
2515
- return `<details id="nav-tools" open>${location}<div class="nav-tool-cards"><div class="nav-resources" id="nav-manifest"><div class="nav-item" data-node-id="_manifest"><div class="nav-row"><a class="nav-link${currentRes === "_manifest" ? " cur" : ""}" href="/_manifest" title="dooc.yaml">${GEAR_ICON}<span class="nav-label">dooc.yaml</span></a></div></div></div><div class="nav-resources" id="nav-files"><div class="nav-item" data-node-id="_files"><div class="nav-row"><a class="nav-link${currentRes !== undefined && currentRes !== "_manifest" && currentRes !== "_git" && currentRes !== "_extensions" && currentRes !== "_subformats" && currentRes !== "_llm" && !library && !format ? " cur" : ""}" href="/_files" title="Files" data-i18n-title="Files">${FOLDER_ICON}<span class="nav-label" data-i18n="Files">Files</span></a><span class="files-upload-status" role="status"></span></div></div>${hint}</div><div class="nav-resources" id="nav-library"><div class="nav-item" data-node-id="_library"><div class="nav-row"><a class="nav-link${library ? " cur" : ""}" href="/_library" title="Library" data-i18n-title="Library">${STATICS_ICON}<span class="nav-label" data-i18n="Library">Library</span></a></div></div></div><div class="nav-resources" id="nav-format"><div class="nav-item" data-node-id="_format"><div class="nav-row"><a class="nav-link${format ? " cur" : ""}" href="/_format" title="Format" data-i18n-title="Format">${libraryIcon("codeblocks") ?? STATICS_ICON}<span class="nav-label" data-i18n="Format">Format</span></a></div></div></div>${subformats}${git}${extensions}</div></details>`;
2621
+ const subformats = `<div class="nav-resources" id="nav-subformats"><div class="nav-item" data-node-id="_subformats"><div class="nav-row"><a class="nav-link${currentRes === "_subformats" ? " cur" : ""}" href="/_subformats" title="Subformats" data-i18n-title="Subformats">${SUBFORMATS_ICON}<span class="nav-label" data-i18n="Subformats">Subformats</span></a></div></div></div>`;
2622
+ return `<details id="nav-tools" open${site.uploadDirectory ? ` data-upload-directory="${escapeHtml(site.uploadDirectory)}"` : ""}>${location}<div class="nav-tool-cards"><div class="nav-resources" id="nav-manifest"><div class="nav-item" data-node-id="_manifest"><div class="nav-row"><a class="nav-link${currentRes === "_manifest" ? " cur" : ""}" href="/_manifest" title="dooc.yaml">${GEAR_ICON}<span class="nav-label">dooc.yaml</span></a></div></div></div><div class="nav-resources" id="nav-files"><div class="nav-item" data-node-id="_files"><div class="nav-row"><a class="nav-link${currentRes !== undefined && currentRes !== "_manifest" && currentRes !== "_git" && currentRes !== "_extensions" && currentRes !== "_subformats" && currentRes !== "_llm" && !library && !format ? " cur" : ""}" href="/_files" title="Files" data-i18n-title="Files">${FOLDER_ICON}<span class="nav-label" data-i18n="Files">Files</span></a><span class="files-upload-status" role="status"></span></div></div></div><div class="nav-resources" id="nav-library"><div class="nav-item" data-node-id="_library"><div class="nav-row"><a class="nav-link${library ? " cur" : ""}" href="/_library" title="Library" data-i18n-title="Library">${STATICS_ICON}<span class="nav-label" data-i18n="Library">Library</span></a></div></div></div><div class="nav-resources" id="nav-format"><div class="nav-item" data-node-id="_format"><div class="nav-row"><a class="nav-link${format ? " cur" : ""}" href="/_format" title="Format" data-i18n-title="Format">${libraryIcon("codeblocks") ?? STATICS_ICON}<span class="nav-label" data-i18n="Format">Format</span></a></div></div></div>${subformats}${git}${extensions}</div></details>`;
2516
2623
  };
2517
2624
  const formatSize = (bytes) => bytes < 1024
2518
2625
  ? `${bytes} B`
@@ -2574,6 +2681,17 @@ body.edit .nav-row { cursor: grab; }
2574
2681
  if (errors.length)
2575
2682
  return { html: "", errors };
2576
2683
  try {
2684
+ if (language === "md" || language === "markdown") {
2685
+ const { doc, source: parsed } = compileDraft(draftContext(site), file, source);
2686
+ return {
2687
+ html: blocksHtml(doc.blocks, {
2688
+ ...site.ctx,
2689
+ terms: [...site.ctx.terms, ...parsed.terms],
2690
+ pageContents: (file, recursive, title) => contentsLibrary(site, file, recursive, title),
2691
+ }),
2692
+ errors: parsed.errors,
2693
+ };
2694
+ }
2577
2695
  return {
2578
2696
  html: blocksHtml(parsed?.blocks ?? [
2579
2697
  {
@@ -2604,16 +2722,6 @@ body.edit .nav-row { cursor: grab; }
2604
2722
  catch (error) {
2605
2723
  errors.push(error instanceof Error ? error.message : String(error));
2606
2724
  }
2607
- if (/\.(md|markdown)$/i.test(file)) {
2608
- const { doc, source: parsed } = compileDraft(draftContext(site), file, source);
2609
- errors.push(...parsed.errors);
2610
- try {
2611
- blocksHtml(doc.blocks, site.ctx);
2612
- }
2613
- catch (error) {
2614
- errors.push(error instanceof Error ? error.message : String(error));
2615
- }
2616
- }
2617
2725
  return errors;
2618
2726
  };
2619
2727
  /** Hidden skill entries are readable only through the validated project skill list. */
@@ -2691,16 +2799,26 @@ body.edit .nav-row { cursor: grab; }
2691
2799
  }
2692
2800
  };
2693
2801
  };
2694
- const renderFormatCollection = (site, selector, query = "") => {
2695
- const collection = readFormatCollection(site.root ?? root, selector, parseFormatQuery(query));
2802
+ const renderFormatCollection = (site, selector, query = "", title = selector) => {
2803
+ const project = site.root ?? root;
2804
+ const alias = selector && fenceFormat(selector);
2805
+ if (!query && site.subformats?.some(({ ext }) => ext === selector || ext === alias)) {
2806
+ const files = site.filePaths ?? filesSnapshot(project).files.map((item) => item.path);
2807
+ const index = resourceIndex(project, files, site.previews?.domains);
2808
+ const format = index.formats?.includes(selector) ? selector : alias;
2809
+ if (index.subformats.some(({ ext }) => ext === format))
2810
+ return `<div class="subformat-page">${formatPageHtml(index, format, title)}</div>`;
2811
+ }
2812
+ const options = parseFormatQuery(query);
2813
+ const collection = readFormatCollection(project, selector, options);
2696
2814
  const missing = collection.records
2697
2815
  .filter((record) => record.preview?.some((block) => block.type === "figureRef" && !site.ctx.figures.has(block.name)))
2698
2816
  .map((record) => record.file);
2699
2817
  const figures = new Map(site.ctx.figures);
2700
2818
  if (missing.length)
2701
- for (const figure of loadFigures(join(site.root ?? root, "figures"), missing).figures)
2819
+ for (const figure of loadFigures(join(project, "figures"), missing).figures)
2702
2820
  figures.set(figure.name, figure);
2703
- return blocksHtml([formatCollectionBlock(collection, parseFormatQuery(query))], {
2821
+ return blocksHtml([formatCollectionBlock(collection, options)], {
2704
2822
  ...site.ctx,
2705
2823
  figures,
2706
2824
  figurePreview: figureFrameHtml,
@@ -2754,10 +2872,7 @@ body.edit .nav-row { cursor: grab; }
2754
2872
  }
2755
2873
  choices.add(selector);
2756
2874
  const navigation = `<nav class="format-navigation" aria-label="Format collections" data-i18n-aria-label="Format collections"><label><span data-i18n="Collection">Collection</span><select data-format-path>${[...choices].map((value) => `<option value="${escapeHtml(value)}"${value === selector ? " selected" : ""}${value ? "" : ' data-i18n="All formats"'}>${escapeHtml(value || "All formats")}</option>`).join("")}</select></label><code>format/${escapeHtml(selector || "all")}</code></nav>`;
2757
- const registered = !query && site.subformats?.some((format) => format.ext === selector);
2758
- const content = registered
2759
- ? formatPageHtml(resourceIndex(site.root ?? root, files, site.previews?.domains), selector, selector)
2760
- : renderFormatCollection(site, selector, query);
2875
+ const content = renderFormatCollection(site, selector, query);
2761
2876
  return {
2762
2877
  title: "Format",
2763
2878
  main: `<article class="res-page resource-library resource-results">${navigation}${content}</article>`,
@@ -2781,6 +2896,24 @@ body.edit .nav-row { cursor: grab; }
2781
2896
  }
2782
2897
  if (!file && (kind === "dictionary" || kind === "code"))
2783
2898
  return resourcesMain(site, "codeblocks");
2899
+ if (!file && kind === "toc") {
2900
+ const owner = site.root ?? root;
2901
+ const manifest = manifestFile(owner);
2902
+ const sources = new Map([[manifest, ""]]);
2903
+ for (const entry of site.entries) {
2904
+ if (entry.included && entry.origin)
2905
+ sources.set(entry.origin, entry.root ? "" : entry.id);
2906
+ if (isContentPage(entry) && entry.sourceFile)
2907
+ sources.set(entry.sourceFile, entry.root ? "" : entry.id);
2908
+ }
2909
+ const choices = [...sources]
2910
+ .map(([path, id]) => `<option value="${escapeHtml(path)}" data-page="${escapeHtml(id)}">${escapeHtml(path)}</option>`)
2911
+ .join("");
2912
+ return {
2913
+ title: "Table of contents",
2914
+ main: `<article class="res-page resource-library" data-toc-library>${resourceTabs("toc", readManifest(owner).libraries)}<div class="format-navigation toc-library-options"><label><span data-i18n="Page or manifest file">Page or manifest file</span><select data-toc-source>${choices}</select></label><label><input type="checkbox" data-toc-recursive checked><span data-i18n="Include all descendants">Include all descendants</span></label><code data-toc-embed aria-live="polite">![](${escapeHtml(tocUrl(manifest))})</code></div><div data-toc-results>${contentsLibrary(site, manifest, true)}</div></article>`,
2915
+ };
2916
+ }
2784
2917
  if (kind === "schema" && file) {
2785
2918
  const config = site.subformats?.find((format) => format.ext === file);
2786
2919
  if (!config)
@@ -2913,6 +3046,14 @@ body.edit .nav-row { cursor: grab; }
2913
3046
  ? title
2914
3047
  : `${title} — ${site.title ?? "dooc edit"}`;
2915
3048
  // Navigation follows the manifest hierarchy via routing.docPath.
3049
+ const siteIconImages = (site) => {
3050
+ const iconImg = `<img id="site-icon" alt=""${site.icon ? ` src="${svgDataUri(site.icon)}"` : " hidden"}>`;
3051
+ const iconVariants = Object.entries(site.iconVariants ?? {});
3052
+ // The base image sits in a wrapper so theme switching and edit-client's #site-icon.hidden never fight.
3053
+ return iconVariants.length
3054
+ ? `<span class="site-icon-variants" data-theme-variants><span data-theme-variant="">${iconImg}</span>${iconVariants.map(([theme, svg]) => `<img data-theme-variant="${escapeHtml(theme)}" alt="" src="${svgDataUri(svg)}" hidden>`).join("")}</span>`
3055
+ : iconImg;
3056
+ };
2916
3057
  const page = (mode, site, opts) => {
2917
3058
  const currentDocument = site.entries.find((entry) => entry.id === opts.currentId);
2918
3059
  const rootPage = site.entries.find((entry) => entry.root);
@@ -2920,8 +3061,9 @@ body.edit .nav-row { cursor: grab; }
2920
3061
  const rootCurrent = currentDocument?.root && (!opts.currentRes || opts.currentRes === "/");
2921
3062
  const nav = navGroupsHtml(historicalReadOnly || opts.loading ? "preview" : mode, site, opts.currentId, opts.currentRes);
2922
3063
  const siteTitle = escapeHtml(site.title ?? "dooc");
2923
- const iconImg = `<img id="site-icon" alt=""${site.icon ? ` src="${svgDataUri(site.icon)}"` : " hidden"}>`;
2924
- const iconVariants = Object.entries(site.iconVariants ?? {});
3064
+ const rootEdit = mode === "edit" && !historicalReadOnly
3065
+ ? `<button type="button" data-root-source aria-haspopup="dialog" aria-label="Edit root page" title="Edit root page" data-i18n-aria-label="Edit root page" data-i18n-title="Edit root page">${icon('<path d="m4 12 8.8-8.8a1.6 1.6 0 0 1 2.3 2.3L6.3 14.3l-3.4.9Z"/><path d="m11.4 4.6 2.3 2.3"/>', 16)}</button>`
3066
+ : "";
2925
3067
  const tabIcons = { "": site.icon, ...site.iconVariants };
2926
3068
  const favicons = mode === "preview"
2927
3069
  ? Object.entries(tabIcons)
@@ -2930,11 +3072,7 @@ body.edit .nav-row { cursor: grab; }
2930
3072
  : [])
2931
3073
  .join("\n")
2932
3074
  : "";
2933
- // The base image sits in a wrapper so theme switching and edit-client's #site-icon.hidden never fight.
2934
- const iconHtml = iconVariants.length
2935
- ? `<span class="site-icon-variants" data-theme-variants><span data-theme-variant="">${iconImg}</span>${iconVariants.map(([theme, svg]) => `<img data-theme-variant="${escapeHtml(theme)}" alt="" src="${svgDataUri(svg)}" hidden>`).join("")}</span>`
2936
- : iconImg;
2937
- const siteIcon = `<span id="site-icon-slot"${mode === "edit" ? ' title="Change site icon" data-i18n-title="Change site icon"' : ""}>${iconHtml}${DOCS_ICON}${mode === "edit" ? '<input type="file" accept=".svg,image/svg+xml" aria-label="Change site icon" data-i18n-aria-label="Change site icon">' : ""}</span>`;
3075
+ const siteIcon = `<span id="site-icon-slot"${mode === "edit" ? ' title="Change site icon" data-i18n-title="Change site icon"' : ""}>${siteIconImages(site)}${DOCS_ICON}${mode === "edit" ? '<button class="nav-icon-pick" type="button" aria-label="Change site icon" data-i18n-aria-label="Change site icon" aria-haspopup="dialog"></button>' : ""}</span>`;
2938
3076
  const output = opts.publish?.output;
2939
3077
  const script = (js) => output
2940
3078
  ? `<script src="${escapeHtml(output.asset(js, "js"))}"></script>`
@@ -2961,16 +3099,16 @@ body.edit .nav-row { cursor: grab; }
2961
3099
 
2962
3100
 
2963
3101
  <div id="preview-language-menu" role="menu" aria-label="Change language" data-i18n-aria-label="Change language" hidden></div>
2964
- <div id="preview-panes"${opts.currentRes !== undefined ? " hidden" : ""}><section class="preview-pane active" tabindex="0" aria-label="Active pane" data-i18n-aria-label="Active pane"><div class="pane-actions"><button class="pbtn" type="button" data-theme-picker="document" aria-label="Preview theme"></button>${fontButton("reader")}<button class="pbtn pane-language" type="button" aria-haspopup="menu" aria-expanded="false" aria-controls="preview-language-menu" aria-label="Change language" data-i18n-aria-label="Change language" title="Change language" data-i18n-title="Change language">${GLOBE_ICON}</button></div><div class="preview-content">${opts.main}</div></section></div></main>`
3102
+ <div id="preview-panes"${opts.currentRes !== undefined ? " hidden" : ""}><section class="preview-pane active" aria-label="Active pane" data-i18n-aria-label="Active pane"><div class="pane-actions"><button class="pbtn" type="button" data-theme-picker="document" aria-label="Preview theme"></button>${fontButton("reader")}<button class="pbtn pane-language" type="button" aria-haspopup="menu" aria-expanded="false" aria-controls="preview-language-menu" aria-label="Change language" data-i18n-aria-label="Change language" title="Change language" data-i18n-title="Change language">${GLOBE_ICON}</button></div><div class="preview-content">${opts.main}</div></section></div></main>`
2965
3103
  : mode === "edit" && opts.currentRes !== undefined
2966
3104
  ? `<main class="resources-pane">${opts.main}</main>`
2967
- : `<main><div class="page-actions"><button class="pbtn" type="button" data-theme-picker="document" aria-label="Preview theme"></button>${fontButton("reader")}</div>${opts.main}</main>`;
3105
+ : `<main tabindex="-1"><div class="page-actions"><button class="pbtn" type="button" data-theme-picker="document" aria-label="Preview theme"></button>${fontButton("reader")}</div>${opts.main}</main>`;
2968
3106
  const graphScript = output?.graph
2969
3107
  ? `<script type="module" src="${escapeHtml(output.graph)}"></script>`
2970
3108
  : opts.publish
2971
3109
  ? script(opts.publish.graphJs)
2972
3110
  : `<script>(${loadPreviewScript.toString()})("/assets/graph.js", "svg[data-sg-layout], [data-mermaid]", "module");</script>`;
2973
- const frame = `<!doctype html><html lang="en"><head><meta charset="utf-8">
3111
+ const frame = `<!doctype html><html lang="en"${site.accentColor ? ` style="--project-accent:${escapeHtml(site.accentColor)}"` : ""}><head><meta charset="utf-8">
2974
3112
  ${opts.publish ? `<meta name="referrer" content="no-referrer"><meta http-equiv="x-dns-prefetch-control" content="off">${opts.publish.network ? "" : `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src ${self}'unsafe-inline'; style-src ${self}'unsafe-inline' data:; img-src ${self}data: blob:; media-src ${self}data: blob:; object-src ${self}data:; font-src ${self}data: blob:; frame-src ${self}data: blob:; connect-src ${output ? "'self'" : "'none'"}; base-uri 'none'; form-action 'none'">`}` : ""}
2975
3113
  <meta name="viewport" content="width=device-width, initial-scale=1">
2976
3114
  <title>${escapeHtml(pageTitle(mode, opts.title, site))}</title>
@@ -2979,7 +3117,7 @@ ${script(`var __name = (f) => f;
2979
3117
  (${initializeThemes.toString()})(${JSON.stringify(site.themes)});
2980
3118
  (${mountFigureFrames.toString()})(document);`)}
2981
3119
  ${stylesheet}</head>
2982
- <body data-content-language="${escapeHtml(site.contentLanguage ?? site.defaultLang)}" data-document-manifest="${escapeHtml(currentDocument?.origin ?? "")}" data-document-path="${escapeHtml(currentDocument ? docPath(site.entries, currentDocument.id) : "/")}"${mode === "edit" ? ' class="edit"' : ""}${site.download ? ` data-download="${site.download}"` : ""}${site.sourceBase ? ` data-source-base="${escapeHtml(site.sourceBase)}"` : ""}><nav id="sidebar"><div id="sidebar-resize" class="panel-resize" role="separator" tabindex="0" aria-orientation="vertical" aria-controls="sidebar" aria-label="Resize sidebar" data-i18n-aria-label="Resize sidebar" title="Resize sidebar" data-i18n-title="Resize sidebar"></div><div id="sidebar-head">${siteIcon}<a id="site-title" class="site-title${rootCurrent ? " cur" : ""}" href="/"${/^https?:\/\//i.test(rootJump) ? ` data-jump-url="${escapeHtml(rootJump)}"` : ""} title="${siteTitle}"${rootCurrent ? ' aria-current="page"' : ""}${mode === "edit" ? ` data-title="${escapeHtml(site.title ?? "")}" aria-keyshortcuts="F2"` : ""}>${siteTitle}</a><button class="nav-tree-toggle" type="button" data-nav-root-toggle aria-controls="nav-docs" aria-expanded="true" aria-label="Toggle ${siteTitle}">${DISCLOSURE_ICON}</button><button id="sidebar-toggle" type="button" aria-controls="sidebar-content" aria-expanded="true" title="Close sidebar" data-i18n-title="Close sidebar">${SIDEBAR_ICON}</button></div><div id="sidebar-content"><div id="nav-groups">${nav}</div><div id="nav-status" role="status" aria-live="polite"></div></div></nav>${main}${opts.aside ?? ""}
3120
+ <body${mode === "edit" ? ` data-draft-project="${escapeHtml(root)}"` : ""} data-content-language="${escapeHtml(site.contentLanguage ?? site.defaultLang)}" data-document-manifest="${escapeHtml(currentDocument?.origin ?? "")}" data-document-path="${escapeHtml(currentDocument ? docPath(site.entries, currentDocument.id) : "/")}"${mode === "edit" ? ' class="edit"' : ""}${site.download ? ` data-download="${site.download}"` : ""}${site.sourceBase ? ` data-source-base="${escapeHtml(site.sourceBase)}"` : ""}><nav id="sidebar"><div id="sidebar-resize" class="panel-resize" role="separator" tabindex="0" aria-orientation="vertical" aria-controls="sidebar" aria-label="Resize sidebar" data-i18n-aria-label="Resize sidebar" title="Resize sidebar" data-i18n-title="Resize sidebar"></div><div id="sidebar-head">${siteIcon}<a id="site-title" class="site-title${rootCurrent ? " cur" : ""}" href="/"${/^https?:\/\//i.test(rootJump) ? ` data-jump-url="${escapeHtml(rootJump)}"` : ""} title="${siteTitle}"${rootCurrent ? ' aria-current="page"' : ""}${mode === "edit" ? ` data-title="${escapeHtml(site.title ?? "")}" aria-keyshortcuts="F2"` : ""}>${siteTitle}</a>${rootEdit}<button class="nav-tree-toggle" type="button" data-nav-root-toggle aria-controls="nav-docs" aria-expanded="true" aria-label="Toggle ${siteTitle}">${DISCLOSURE_ICON}</button><button id="sidebar-toggle" type="button" aria-controls="sidebar-content" aria-expanded="true" title="Close sidebar" data-i18n-title="Close sidebar">${SIDEBAR_ICON}</button></div><div id="sidebar-content"><div id="nav-groups">${nav}</div><div id="nav-status" role="status" aria-live="polite"></div></div></nav>${main}${opts.aside ?? ""}
2983
3121
  `;
2984
3122
  if (opts.loading)
2985
3123
  return `${frame}<script>document.body.dataset.clientLoading = "true";
@@ -3130,6 +3268,13 @@ ${mode === "edit"
3130
3268
  const res = await localeFetch("/api/nav?current=" + encodeURIComponent(id) + (rp == null ? "" : "&res=" + encodeURIComponent(rp)));
3131
3269
  if (res.ok) {
3132
3270
  const data = await res.json();
3271
+ document.documentElement.style.setProperty("--project-accent", data.accentColor || "");
3272
+ const slot = document.getElementById("site-icon-slot");
3273
+ if (slot && data.iconImages && slot.dataset.images !== data.iconImages) {
3274
+ slot.querySelector(".site-icon-variants, #site-icon")?.remove();
3275
+ slot.insertAdjacentHTML("afterbegin",data.iconImages);
3276
+ slot.dataset.images = data.iconImages;
3277
+ }
3133
3278
  (${updateNav.toString()})(document.getElementById("nav-groups"), data.html);
3134
3279
  const currentPage = document.querySelector('[data-subformat-nav][data-doc-id="' + CSS.escape(id) + '"] > .nav-row > a');
3135
3280
  if (currentPage && currentPage.pathname !== location.pathname) {
@@ -3153,17 +3298,16 @@ ${mode === "edit"
3153
3298
  return data;
3154
3299
  };
3155
3300
 
3301
+ window.__docsRefreshSidebar = refresh;
3156
3302
  const docAction = (item, action) => {
3157
- if (item.hasAttribute("data-subformat-nav")) {
3158
- document.dispatchEvent(new CustomEvent("docs:subformat-page-action", { detail: { id: item.dataset.docId, action } }));
3303
+ if (action === "delete") {
3304
+ document.dispatchEvent(new CustomEvent("docs:remove-sidebar-entry", {detail: item}));
3159
3305
  return;
3160
3306
  }
3161
- if (window.__docsDocAction) {
3162
- void window.__docsDocAction(item.dataset.docId, action);
3307
+ if (item.hasAttribute("data-subformat-nav") || !window.__docsDocAction) {
3308
+ document.dispatchEvent(new CustomEvent("docs:rename-sidebar-entry", { detail: item }));
3163
3309
  } else {
3164
- const url = new URL(item.querySelector(":scope > .nav-row > a").href);
3165
- url.searchParams.set("doc-action", action);
3166
- location.href = url.href;
3310
+ void window.__docsDocAction(item.dataset.docId, action);
3167
3311
  }
3168
3312
  };
3169
3313
  document.addEventListener("click", (event) => {
@@ -3224,17 +3368,18 @@ ${mode === "edit"
3224
3368
  try {
3225
3369
  const result = await post("/api/site-title", { title: input.value, baseTitle, language: target.language }, target);
3226
3370
  if (!current(target)) { close(); return; }
3371
+ const restoreFocus = form.contains(document.activeElement);
3227
3372
  closed = true;
3228
3373
  form.remove();
3229
3374
  label.textContent = label.title = result.title;
3230
3375
  label.dataset.title = result.title;
3231
3376
  label.setAttribute("href", href);
3377
+ if (restoreFocus) label.focus({preventScroll:true});
3232
3378
  await refresh();
3233
- label.focus();
3234
3379
  setStatus("", false);
3235
3380
  } catch (error) {
3236
3381
  setStatus(error.message, true);
3237
- input.focus();
3382
+ if (form.contains(document.activeElement)) input.focus();
3238
3383
  } finally {
3239
3384
  busy = false;
3240
3385
  input.readOnly = false;
@@ -3258,60 +3403,6 @@ ${mode === "edit"
3258
3403
  };
3259
3404
  document.addEventListener("dblclick", editLabel);
3260
3405
  document.addEventListener("keydown", (event) => { if (event.key === "F2") editLabel(event); });
3261
- const setIcon = async (slot, file) => {
3262
- const target = context();
3263
- if (file && !/\\.svg$/i.test(file.name) && file.type !== "image/svg+xml") {
3264
- setStatus("Icon must be svg", true);
3265
- return;
3266
- }
3267
- const id = slot.closest(".nav-item")?.dataset.docId;
3268
- try {
3269
- const data = file ? btoa(Array.from(new Uint8Array(await file.arrayBuffer()), (byte) => String.fromCharCode(byte)).join("")) : null;
3270
- const result = await post(id ? "/api/icon" : "/api/site-icon", { file: id ? id + ".md" : undefined, data, theme: getComputedStyle(document.documentElement).colorScheme === "dark" ? "dark" : "light" }, target);
3271
- if (!current(target)) return;
3272
- if (!id) {
3273
- const logo = document.getElementById("site-icon");
3274
- logo.src = result.icon;
3275
- logo.hidden = false;
3276
- }
3277
- setStatus("", false);
3278
- await refresh();
3279
- } catch (error) {
3280
- setStatus(error.message, true);
3281
- }
3282
- };
3283
- document.addEventListener("change", (event) => {
3284
- const input = event.target;
3285
- if (!(input instanceof HTMLInputElement) || !input.closest(".nav-doc-icon, #site-icon-slot")) return;
3286
- const file = input.files[0];
3287
- input.value = "";
3288
- if (file) void setIcon(input.closest(".nav-doc-icon, #site-icon-slot"), file);
3289
- });
3290
- document.addEventListener("click", (event) => {
3291
- const clear = event.target instanceof Element ? event.target.closest(".nav-icon-clear") : null;
3292
- if (!clear) return;
3293
- event.preventDefault();
3294
- void setIcon(clear.closest(".nav-doc-icon"), null);
3295
- });
3296
- document.addEventListener("dragover", (event) => {
3297
- const slot = event.target instanceof Element ? event.target.closest(".nav-doc-icon, #sidebar-head") : null;
3298
- if (!slot || !event.dataTransfer?.types.includes("Files")) return;
3299
- event.preventDefault();
3300
- slot.classList.add("over");
3301
- });
3302
- document.addEventListener("dragleave", (event) => {
3303
- const slot = event.target instanceof Element ? event.target.closest(".nav-doc-icon, #sidebar-head") : null;
3304
- if (slot && !slot.contains(event.relatedTarget)) slot.classList.remove("over");
3305
- });
3306
- document.addEventListener("drop", (event) => {
3307
- const slot = event.target instanceof Element ? event.target.closest(".nav-doc-icon, #sidebar-head") : null;
3308
- const file = event.dataTransfer?.files[0];
3309
- if (!slot || !file) return;
3310
- event.preventDefault();
3311
- slot.classList.remove("over");
3312
- void setIcon(slot, file);
3313
- });
3314
-
3315
3406
  let dragContext;
3316
3407
  let dragged = null;
3317
3408
  let drop = null;
@@ -3431,7 +3522,7 @@ ${mode === "edit"
3431
3522
  form.innerHTML =
3432
3523
  '<p class="nav-new-heading" data-i18n="Markdown page">Markdown page</p>' +
3433
3524
  '<input name="title" placeholder="title" data-i18n-placeholder="title" aria-label="title" data-i18n-aria-label="title" required autocomplete="off">' +
3434
- '<div class="nav-new-file"><input name="name" placeholder="File name" data-i18n-placeholder="File name" aria-label="File name" data-i18n-aria-label="File name" required autocomplete="off" spellcheck="false"></div>' +
3525
+ '<div class="nav-new-file"><input name="name" placeholder="File path" data-i18n-placeholder="File path" aria-label="File path" data-i18n-aria-label="File path" required autocomplete="off" spellcheck="false"></div>' +
3435
3526
  '<div class="nav-new-actions"><button type="button" class="nav-new-cancel" data-i18n="Cancel">Cancel</button><button class="nav-new-go" type="submit" data-i18n="Create">Create</button></div>' +
3436
3527
  '<div class="err" role="alert"></div>';
3437
3528
  row.append(form);
@@ -3450,7 +3541,11 @@ ${mode === "edit"
3450
3541
  trigger.focus();
3451
3542
  };
3452
3543
  form.querySelector(".nav-new-cancel").addEventListener("click", cancel);
3453
- title.addEventListener("input", () => { if (!nameTouched) nameInput.value = suggestFileName(title.value); });
3544
+ const directory = document.getElementById("nav-tools")?.dataset.uploadDirectory;
3545
+ title.addEventListener("input", () => {
3546
+ const name = suggestFileName(title.value);
3547
+ if (!nameTouched) nameInput.value = name && directory && directory !== "." ? directory + "/" + name : name;
3548
+ });
3454
3549
  nameInput.addEventListener("input", () => { nameTouched = true; });
3455
3550
  form.addEventListener("keydown", (e) => {
3456
3551
  if (e.key === "Escape") { e.preventDefault(); cancel(); }
@@ -3467,7 +3562,7 @@ ${mode === "edit"
3467
3562
  submit.setAttribute("aria-busy", "true");
3468
3563
  err.textContent = "";
3469
3564
  try {
3470
- await post("/api/create", { parent: parent || undefined, title: title.value.trim(), name: nameInput.value.trim() }, target);
3565
+ await post("/api/create", { parent: parent || undefined, title: title.value.trim(), path: nameInput.value.trim() }, target);
3471
3566
  if (!current(target)) return;
3472
3567
  closeForm();
3473
3568
  await refresh();
@@ -3799,17 +3894,15 @@ ${opts.publish ? `${opts.publish.pages}${script(`${publishRouterScript(opts.publ
3799
3894
  // Linked files get their previewer page too.
3800
3895
  // shortcut: file names containing HTML-escaped characters (& < > " ') get no page, decode entities if needed
3801
3896
  const routes = new Set(pages.map((p) => p.route));
3802
- for (const [, encoded] of pages
3803
- .map((p) => p.main)
3804
- .join("")
3805
- .matchAll(/href="\/(_files\/file\/[^"#&]+)/g)) {
3806
- if (!encoded || routes.has(encoded))
3807
- continue;
3808
- routes.add(encoded);
3809
- const linked = linkedFilePage(site, decodeURIComponent(encoded.slice("_files/file/".length)));
3810
- if (linked)
3811
- pages.push({ route: encoded, ...linked });
3812
- }
3897
+ for (const page of pages)
3898
+ for (const [, encoded] of page.main.matchAll(/href="\/(_files\/file\/[^"#&]+)/g)) {
3899
+ if (!encoded || routes.has(encoded))
3900
+ continue;
3901
+ routes.add(encoded);
3902
+ const linked = linkedFilePage(site, decodeURIComponent(encoded.slice("_files/file/".length)));
3903
+ if (linked)
3904
+ pages.push({ route: encoded, ...linked });
3905
+ }
3813
3906
  const templates = pages
3814
3907
  .map((p) => {
3815
3908
  const content = toHashLinks(p.main, p.route);
@@ -3832,8 +3925,6 @@ ${opts.publish ? `${opts.publish.pages}${script(`${publishRouterScript(opts.publ
3832
3925
  },
3833
3926
  }), first);
3834
3927
  };
3835
- // A doc's main content. A doc with an empty body and children (a chapter-heading-only doc) shows
3836
- // its children list in place of the body.
3837
3928
  const entryMain = (site, e) => {
3838
3929
  if (e.url && /^https?:\/\//i.test(e.url)) {
3839
3930
  const title = docDisplayName(e.frontmatter, e.id);
@@ -3844,14 +3935,44 @@ ${opts.publish ? `${opts.publish.pages}${script(`${publishRouterScript(opts.publ
3844
3935
  `<article><p role="alert">File not found: ${escapeHtml(e.url)}</p></article>`);
3845
3936
  const html = renderEntryHtml(site, e).html;
3846
3937
  const kids = childrenOf(site.entries, e.id);
3847
- if (e.subformat || e.library || e.format || e.blocks.length > 0 || kids.length === 0) {
3938
+ if (e.subformat ||
3939
+ e.library ||
3940
+ e.format ||
3941
+ (e.url && tocReference(e.url)) ||
3942
+ e.blocks.length ||
3943
+ (e.root && isContentPage(e)) ||
3944
+ (!e.root && !kids.length)) {
3848
3945
  return html;
3849
3946
  }
3850
- const items = kids
3851
- .map((k) => `<li><a href="/${k.id}">${entryIcon(k, "doc-icon")}<span class="document-card-label">${escapeHtml(docDisplayName(k.frontmatter, k.id))}</span></a></li>`)
3852
- .join("");
3853
- return docLinks(site, html.replace(/<\/article>\s*$/, `<ul class="idx">${items}</ul></article>`));
3947
+ return html.replace(/<\/article>\s*$/, () => `${contentsTree(site, e, true)}</article>`);
3854
3948
  };
3949
+ function contentsTree(site, parent, recursive) {
3950
+ const children = new Map();
3951
+ for (const entry of site.entries) {
3952
+ const group = children.get(entry.parent) ?? [];
3953
+ group.push(entry);
3954
+ children.set(entry.parent, group);
3955
+ }
3956
+ const items = (id) => (children.get(id) ?? [])
3957
+ .map((entry) => {
3958
+ const nested = recursive && children.has(entry.id) ? `<ul>${items(entry.id)}</ul>` : "";
3959
+ return `<li data-toc-page="${escapeHtml(entry.id)}"><a href="/${escapeHtml(entry.id)}">${entryIcon(entry, "doc-icon")}<span class="document-card-label">${escapeHtml(docDisplayName(entry.frontmatter, entry.id))}</span></a>${nested}</li>`;
3960
+ })
3961
+ .join("");
3962
+ return children.has(parent.id)
3963
+ ? docLinks(site, `<ul class="idx" data-library="toc">${items(parent.id)}</ul>`)
3964
+ : '<p data-library="toc" data-i18n="No child pages">No child pages</p>';
3965
+ }
3966
+ function contentsLibrary(site, file, recursive, title) {
3967
+ const entry = file === manifestFile(site.root ?? root)
3968
+ ? site.entries.find((page) => page.root)
3969
+ : site.entries.find((page) => (page.included && page.origin === file) ||
3970
+ (isContentPage(page) && page.sourceFile === file));
3971
+ const listing = entry
3972
+ ? contentsTree(site, entry, recursive)
3973
+ : `<p role="alert">Table of contents source is not in this document: ${escapeHtml(file)}</p>`;
3974
+ return title ? `<section><h2>${escapeHtml(title)}</h2>${listing}</section>` : listing;
3975
+ }
3855
3976
  const languageFieldHtml = (defaultLang, language = contentLanguageCode(defaultLang), translatedLanguages = [contentLanguageCode(defaultLang)], declaredLanguages) => {
3856
3977
  const existing = new Set(translatedLanguages);
3857
3978
  const options = [...contentLanguages]
@@ -3944,6 +4065,7 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
3944
4065
  </div><div id="editor-header-workspace"></div><div id="editor-header-actions">
3945
4066
  <button id="validate" class="pbtn" type="button" title="Validate and apply" data-i18n-title="Validate and apply" aria-label="Validate and apply" data-i18n-aria-label="Validate and apply">${icon('<path d="M5 5l-4 5 4 5M15 5l4 5-4 5M7 10l2 2 4-5"/>')}</button>
3946
4067
  <button id="save" class="pbtn" data-state="saved" type="button" title="Save (Ctrl+S)" data-i18n-title="Save (Ctrl+S)" aria-label="Save" data-i18n-aria-label="Save">${icon('<path d="M3 3h11l3 3v11H3z"/><path d="M6 3v5h7V3M6 17v-6h8v6"/>')}</button>
4068
+ <button id="editor-llm" class="pbtn" type="button" aria-controls="llm-chat" aria-label="Open chat" data-i18n-aria-label="Open chat" title="Open chat" data-i18n-title="Open chat">${LLM_ICON}</button>
3947
4069
  <button id="split-preview" class="pbtn" type="button" aria-pressed="false" aria-label="Split view" data-i18n-aria-label="Split view" title="Split view" data-i18n-title="Split view">${icon('<rect x="3" y="3" width="14" height="14" rx="2"/><path d="M10 3v14"/>')}</button>
3948
4070
  <div id="gear"><button class="pbtn" type="button" aria-expanded="false" aria-controls="gearmenu" aria-label="View settings" data-i18n-aria-label="View settings" title="View settings" data-i18n-title="View settings">${GEAR_ICON}</button><div id="gearmenu">
3949
4071
  <div class="editor-setting"><span class="editor-setting-icon" data-setting-theme-icon aria-hidden="true"></span><div class="subformat-control"><span class="subformat-control-label" data-i18n="Editor theme">Editor theme</span><button class="setting-picker" type="button" data-theme-picker="editor" aria-label="Editor theme"><span data-picker-value></span>${SELECT_ICON}</button></div></div>
@@ -4219,13 +4341,14 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4219
4341
  ? ops.addLibrary(body.library, title, parent)
4220
4342
  : typeof body?.subformat === "string"
4221
4343
  ? ops.addSubformat(body.subformat, title, parent)
4222
- : ops.addFile(name, title, parent);
4344
+ : typeof body?.path === "string"
4345
+ ? ops.addFile(body.path, title, parent, body.reference === true ? "reference" : "path")
4346
+ : ops.addFile(name, title, parent);
4223
4347
  sendOp(res, isOpError(result)
4224
4348
  ? result
4225
4349
  : { ...result, path: docPath(loadSite().entries, result.id) });
4226
4350
  };
4227
- // Add a figure (sidebar file picker / drag-and-drop). Returns the written file name
4228
- // (the client inserts ![](figures/<file>)).
4351
+ // Compatibility endpoint for clients that upload figure bytes.
4229
4352
  const handleFigure = async (req, res) => {
4230
4353
  const body = await readJson(req);
4231
4354
  if (typeof body?.name !== "string" || typeof body?.data !== "string") {
@@ -4237,8 +4360,6 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4237
4360
  ? result
4238
4361
  : { ...result, path: result.path ?? `figures/${result.file}` });
4239
4362
  };
4240
- // Doc icon (the header's icon slot). data = base64 of an svg (null = remove). Pads it to 1:1 and
4241
- // writes icons/<id>.svg. Response icon = the new data URI (null if removed).
4242
4363
  const handleIcon = async (req, res) => {
4243
4364
  const body = await readJson(req);
4244
4365
  const manifest = readManifest(root);
@@ -4259,6 +4380,22 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4259
4380
  sendJson(res, 403, { error: "Remote document sources are read-only" });
4260
4381
  return;
4261
4382
  }
4383
+ if (body?.path !== undefined) {
4384
+ try {
4385
+ const svg = projectIcon(root, body.path);
4386
+ manifest.files ??= parseFileLayout({});
4387
+ manifest.files.icons ??= {};
4388
+ manifest.files.icons[id] = body.path;
4389
+ writeManifest(root, manifest.tree, manifest);
4390
+ sendJson(res, 200, { ok: true, icon: svgDataUri(svg) });
4391
+ }
4392
+ catch (error) {
4393
+ sendJson(res, 400, {
4394
+ error: error instanceof Error ? error.message : String(error),
4395
+ });
4396
+ }
4397
+ return;
4398
+ }
4262
4399
  let file = manifest.format === undefined &&
4263
4400
  manifest.files?.defaultLayout !== false &&
4264
4401
  !Object.hasOwn(manifest.files?.icons ?? {}, id) &&
@@ -4336,37 +4473,82 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4336
4473
  const file = sourceDocFile(target.id, snapshot.layout);
4337
4474
  if (body?.sourceFile !== file)
4338
4475
  throw new Error("Files changed. Reload before retrying.");
4339
- const result = updateFiles(root, {
4476
+ updateFiles(root, {
4340
4477
  action: "rename",
4341
4478
  file,
4342
4479
  name: typeof body?.name === "string" ? body.name.trim() : "",
4343
4480
  revision: snapshot.revision,
4344
4481
  });
4345
- sendOp(res, {
4346
- path: docPath(loadSite().entries, target.id),
4347
- sourceFile: sourceDocFile(target.id, result.layout),
4348
- });
4482
+ const next = file.slice(0, file.lastIndexOf("/") + 1) + String(body?.name).trim();
4483
+ const manifest = readManifest(root);
4484
+ const entries = flattenTree(manifest.tree);
4485
+ const renamed = entries.find((entry) => isContentPage(entry) && sourceDocFile(entry.id, manifest.files) === next);
4486
+ if (!renamed)
4487
+ throw new Error("Renamed page not found");
4488
+ sendOp(res, { id: renamed.id, path: docPath(entries, renamed.id), sourceFile: next });
4349
4489
  }
4350
4490
  catch (error) {
4351
4491
  sendJson(res, 409, { error: error instanceof Error ? error.message : String(error) });
4352
4492
  }
4353
4493
  };
4354
- // Delete a doc. If it's referenced, refuse without force and return the referrers (the client
4355
- // confirms and resends with force). Response parent = where to navigate after deletion.
4356
4494
  const handleDelete = async (req, res) => {
4357
4495
  const body = await readJson(req);
4496
+ if (typeof body?.id === "string") {
4497
+ if (body.preview === true &&
4498
+ body.selected === undefined &&
4499
+ body.children === undefined) {
4500
+ sendOp(res, previewSidebarRemoval(root, body.id));
4501
+ return;
4502
+ }
4503
+ if ((body.selected === undefined
4504
+ ? body.children !== "remove" && body.children !== "promote"
4505
+ : !Array.isArray(body.selected) ||
4506
+ !body.selected.every((id) => typeof id === "string")) ||
4507
+ (body.files !== "keep" &&
4508
+ body.files !== "delete" &&
4509
+ (!Array.isArray(body.files) ||
4510
+ !body.files.every((path) => typeof path === "string"))) ||
4511
+ (body.confirmation !== undefined && typeof body.confirmation !== "string") ||
4512
+ (body.preview !== undefined && typeof body.preview !== "boolean") ||
4513
+ typeof body.revision !== "string") {
4514
+ sendJson(res, 400, { error: "Review the sidebar and choose what to remove" });
4515
+ return;
4516
+ }
4517
+ const options = {
4518
+ children: body.children === "remove" || body.children === "promote"
4519
+ ? body.children
4520
+ : undefined,
4521
+ selected: body.selected,
4522
+ files: body.files,
4523
+ revision: body.revision,
4524
+ confirmation: body.confirmation,
4525
+ force: body.force === true,
4526
+ };
4527
+ try {
4528
+ const changed = options.files === "delete" ||
4529
+ (Array.isArray(options.files) && options.files.length)
4530
+ ? await host.changedTrackedFiles(root)
4531
+ : new Set();
4532
+ const operation = body.preview === true ? reviewSidebarRemoval : removeSidebarEntry;
4533
+ sendOp(res, operation(root, body.id, options, changed));
4534
+ }
4535
+ catch {
4536
+ sendJson(res, 409, {
4537
+ error: "Could not check Git changes. Review the deletion again.",
4538
+ });
4539
+ }
4540
+ return;
4541
+ }
4542
+ if (body?.preview !== undefined || body?.confirmation !== undefined) {
4543
+ sendJson(res, 400, { error: "Use the sidebar entry ID to review or confirm deletion" });
4544
+ return;
4545
+ }
4358
4546
  const target = resolveContentFile(body?.file);
4359
4547
  if (!target) {
4360
4548
  sendJson(res, 404, { error: "target doc not found" });
4361
4549
  return;
4362
4550
  }
4363
- const result = ops.remove(target.id, body?.force === true);
4364
- sendOp(res, isOpError(result)
4365
- ? result
4366
- : {
4367
- ...result,
4368
- path: result.parent ? docPath(loadSite().entries, result.parent) : "/",
4369
- });
4551
+ sendOp(res, removeSidebarEntry(root, target.id, { files: "delete", force: body?.force === true }));
4370
4552
  };
4371
4553
  const handle = async (mode, req, res) => {
4372
4554
  const requestUrl = new URL(req.url ?? "/", "http://localhost");
@@ -4472,7 +4654,7 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4472
4654
  const grammar = siteLanguages.codeGrammars?.find((entry) => entry.name === extension || entry.aliases?.includes(extension));
4473
4655
  const language = existsSync(join(root, ".dooc/editor-tools", `${extension}.json`))
4474
4656
  ? extension
4475
- : (readManifest(root).subformats?.find((config) => config.ext === extension)?.format ??
4657
+ : (recordSubformat(root, readManifest(root), input.file, applicationPreviews.domains)?.format ??
4476
4658
  grammar?.name ??
4477
4659
  extension);
4478
4660
  const result = await validateTextfileCode(root, language, input.content);
@@ -4560,6 +4742,30 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4560
4742
  await handleCreate(req, res);
4561
4743
  return;
4562
4744
  }
4745
+ if (path === "/api/root-source") {
4746
+ const body = await readJson(req);
4747
+ if (body?.action !== "read" && body?.action !== "save") {
4748
+ sendJson(res, 400, { error: "Unknown root page action" });
4749
+ return;
4750
+ }
4751
+ sendOp(res, rootPageSource(root, body.action === "save" ? body : undefined));
4752
+ return;
4753
+ }
4754
+ if (path === "/api/sidebar-title") {
4755
+ const body = await readJson(req);
4756
+ const entry = loadNavigation(locale, null).entries.find((entry) => entry.id === body?.id);
4757
+ if (!entry || entry.origin) {
4758
+ sendJson(res, 404, { error: "Sidebar entry not found" });
4759
+ return;
4760
+ }
4761
+ if (typeof body?.title !== "string" ||
4762
+ body.baseTitle !== docDisplayName(entry.frontmatter, entry.id)) {
4763
+ sendJson(res, 409, { error: "The title changed. Review it before renaming." });
4764
+ return;
4765
+ }
4766
+ sendOp(res, ops.setTitle(entry.id, body.title));
4767
+ return;
4768
+ }
4563
4769
  if (path === "/api/subformat-page") {
4564
4770
  const body = await readJson(req);
4565
4771
  const id = typeof body?.id === "string" ? body.id : "";
@@ -4583,7 +4789,13 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4583
4789
  const result = path === "/api/site-title"
4584
4790
  ? siteTitleResponse(root, input)
4585
4791
  : siteIconResponse(root, input);
4586
- sendJson(res, result.status, result.body);
4792
+ if (path === "/api/site-icon" && input?.path && result.status === 200)
4793
+ sendJson(res, 200, {
4794
+ ...result.body,
4795
+ images: siteIconImages(loadSite(locale)),
4796
+ });
4797
+ else
4798
+ sendJson(res, result.status, result.body);
4587
4799
  return;
4588
4800
  }
4589
4801
  if (path === "/api/figure") {
@@ -4622,6 +4834,8 @@ ${languageFieldHtml(site.defaultLang, site.contentLanguage, entry.translatedLang
4622
4834
  const currentId = params.get("current") || resolveDocPath(site.entries, params.get("route") ?? "/");
4623
4835
  sendJson(res, 200, {
4624
4836
  siteTitle: site.title,
4837
+ accentColor: site.accentColor,
4838
+ iconImages: siteIconImages(site),
4625
4839
  siteIcon: site.icon ? svgDataUri(site.icon) : undefined,
4626
4840
  themes: site.themes,
4627
4841
  rootJump: docHref(site.entries, site.entries.find((entry) => entry.root)?.id ?? ""),