@mdzip/editor 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/AGENTS.md +8 -0
  2. package/README.md +266 -5
  3. package/dist/diff-rendered.d.ts +54 -0
  4. package/dist/diff-rendered.d.ts.map +1 -0
  5. package/dist/diff-rendered.js +462 -0
  6. package/dist/diff-rendered.js.map +1 -0
  7. package/dist/diff-view-css.d.ts +2 -0
  8. package/dist/diff-view-css.d.ts.map +1 -1
  9. package/dist/diff-view-css.js +106 -43
  10. package/dist/diff-view-css.js.map +1 -1
  11. package/dist/diff-view.d.ts +112 -9
  12. package/dist/diff-view.d.ts.map +1 -1
  13. package/dist/diff-view.js +419 -33
  14. package/dist/diff-view.js.map +1 -1
  15. package/dist/front-matter-extension.d.ts +3 -2
  16. package/dist/front-matter-extension.d.ts.map +1 -1
  17. package/dist/front-matter-extension.js +11 -11
  18. package/dist/front-matter-extension.js.map +1 -1
  19. package/dist/front-matter.d.ts +6 -0
  20. package/dist/front-matter.d.ts.map +1 -1
  21. package/dist/front-matter.js +17 -0
  22. package/dist/front-matter.js.map +1 -1
  23. package/dist/heading-outline.d.ts +66 -0
  24. package/dist/heading-outline.d.ts.map +1 -0
  25. package/dist/heading-outline.js +208 -0
  26. package/dist/heading-outline.js.map +1 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/json-validation.d.ts +97 -0
  32. package/dist/json-validation.d.ts.map +1 -0
  33. package/dist/json-validation.js +496 -0
  34. package/dist/json-validation.js.map +1 -0
  35. package/dist/library-info.d.ts +8 -3
  36. package/dist/library-info.d.ts.map +1 -1
  37. package/dist/library-info.js +9 -3
  38. package/dist/library-info.js.map +1 -1
  39. package/dist/manifest-form.d.ts +40 -0
  40. package/dist/manifest-form.d.ts.map +1 -0
  41. package/dist/manifest-form.js +318 -0
  42. package/dist/manifest-form.js.map +1 -0
  43. package/dist/mdz-archive.worker.js +718 -213
  44. package/dist/merge-conflicts.d.ts +56 -0
  45. package/dist/merge-conflicts.d.ts.map +1 -0
  46. package/dist/merge-conflicts.js +130 -0
  47. package/dist/merge-conflicts.js.map +1 -0
  48. package/dist/merge-regions.d.ts +92 -0
  49. package/dist/merge-regions.d.ts.map +1 -0
  50. package/dist/merge-regions.js +416 -0
  51. package/dist/merge-regions.js.map +1 -0
  52. package/dist/merge-view.d.ts +267 -0
  53. package/dist/merge-view.d.ts.map +1 -0
  54. package/dist/merge-view.js +2039 -0
  55. package/dist/merge-view.js.map +1 -0
  56. package/dist/preview-find.d.ts +30 -0
  57. package/dist/preview-find.d.ts.map +1 -0
  58. package/dist/preview-find.js +172 -0
  59. package/dist/preview-find.js.map +1 -0
  60. package/dist/rendering.d.ts +32 -54
  61. package/dist/rendering.d.ts.map +1 -1
  62. package/dist/rendering.js +23 -326
  63. package/dist/rendering.js.map +1 -1
  64. package/dist/scroll-anchors.d.ts +33 -0
  65. package/dist/scroll-anchors.d.ts.map +1 -0
  66. package/dist/scroll-anchors.js +80 -0
  67. package/dist/scroll-anchors.js.map +1 -0
  68. package/dist/view-css.d.ts.map +1 -1
  69. package/dist/view-css.js +2859 -2306
  70. package/dist/view-css.js.map +1 -1
  71. package/dist/view.d.ts +321 -7
  72. package/dist/view.d.ts.map +1 -1
  73. package/dist/view.js +1993 -422
  74. package/dist/view.js.map +1 -1
  75. package/dist/workspace-view.d.ts +2 -0
  76. package/dist/workspace-view.d.ts.map +1 -1
  77. package/dist/workspace-view.js +25 -2
  78. package/dist/workspace-view.js.map +1 -1
  79. package/dist/workspace.d.ts +29 -0
  80. package/dist/workspace.d.ts.map +1 -1
  81. package/dist/workspace.js +124 -9
  82. package/dist/workspace.js.map +1 -1
  83. package/package.json +93 -83
package/dist/view.js CHANGED
@@ -1,11 +1,14 @@
1
+ import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
1
2
  import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
3
+ import { json } from '@codemirror/lang-json';
2
4
  import { markdown } from '@codemirror/lang-markdown';
3
- import { HighlightStyle, syntaxHighlighting, syntaxTree } from '@codemirror/language';
5
+ import { linter } from '@codemirror/lint';
6
+ import { HighlightStyle, bracketMatching, foldGutter, foldKeymap, syntaxHighlighting, syntaxTree } from '@codemirror/language';
4
7
  import { closeSearchPanel, openSearchPanel, search, searchKeymap } from '@codemirror/search';
5
- import { Compartment, EditorState, RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
6
- import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType, dropCursor, keymap, lineNumbers } from '@codemirror/view';
8
+ import { Compartment, EditorState, Prec, RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
9
+ import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType, dropCursor, keymap, highlightWhitespace, lineNumbers } from '@codemirror/view';
7
10
  import { tags } from '@lezer/highlight';
8
- import { Bold, Check, ChevronDown, ChevronRight, ClipboardPaste, ClipboardType, Code, Columns2, Copy, Eraser, Eye, File, FileBraces, FileImage, Folder, FolderOpen, Hash, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Highlighter, ImagePlus, Info, Italic, Link2Off, Link, List, ListOrdered, CornerDownLeft, Monitor, Moon, PackagePlus, PanelLeft, Pilcrow, Quote, Save, Scissors, Search, SpellCheck, SquareCode, SquarePen, Strikethrough, Sun, TextSelect, ZoomIn } from 'lucide';
11
+ import { Bold, CaseSensitive, Check, ChevronDown, ChevronRight, ChevronUp, ClipboardPaste, ClipboardType, Code, Columns2, Copy, Eraser, Eye, File, FileBraces, FileImage, Folder, FolderOpen, Hash, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Highlighter, ImagePlus, Info, Italic, Link2Off, Link, List, ListOrdered, CornerDownLeft, Monitor, Moon, PackagePlus, PanelLeft, Pilcrow, Quote, Save, Scissors, Search, SpellCheck, SquareCode, SquarePen, Strikethrough, Braces, Text, TableOfContents, Sun, TextSelect, X, ZoomIn } from 'lucide';
9
12
  import { samePath } from '@mdzip/core-js';
10
13
  import { browserClipboardHasImage, readBrowserClipboardImage } from './browser.js';
11
14
  import { buildPackedArchiveBytes, isMarkdownArchivePath, resolveMarkdownEntryPoint } from './archive-utils.js';
@@ -13,11 +16,20 @@ import { MdzipAssetSession, mdzipArchiveSourceId, sniffImageSize } from './asset
13
16
  import { MD_MARKDOWN_ICON } from './icons/md-markdown.js';
14
17
  import { PAGE_WIDTH_DEFAULT_ICON, PAGE_WIDTH_FULL_ICON, PAGE_WIDTH_NARROW_ICON, PAGE_WIDTH_WIDE_ICON } from './icons/page-width.js';
15
18
  import { MDZIP_RUNTIME_LIBRARIES } from './library-info.js';
16
- import { MdzipWorkspaceService, extensionForMime, normalizeArchivePath, relativeArchivePath } from './workspace.js';
19
+ import { MdzipManifestInvalidError, MdzipWorkspaceService, extensionForMime, normalizeArchivePath, relativeArchivePath } from './workspace.js';
17
20
  import { buildMdzipNavTree, canEditMdzipPath, escapeHtml, isOrphanedMdzipAsset, mdzipEntryIconKind, isMdzipManifestPath, isMdzipDefaultPolicyExternalLink, isMdzipExternalLink, isMdzipWorkspaceRelativeLink, parseMdzipLink, renderMdzipPreviewHtml } from './workspace-view.js';
21
+ import { collectMdzipHeadings } from '@mdzip/renderer';
22
+ import { describeMdzipJsonValidity, formatMdzipJsonText, isMdzipJsonPath, isMdzipRootManifestPath, setMdzipJsonMember } from './json-validation.js';
23
+ import { MdzipManifestForm } from './manifest-form.js';
24
+ import { mapScrollPosition } from './scroll-anchors.js';
25
+ import { zipSync } from 'fflate';
26
+ import { collectFindText, findMatches, findPattern, findRange, setFindHighlights } from './preview-find.js';
27
+ import { MDZIP_BLOCK_ATTRIBUTE, stripMdzipBlockMarks } from '@mdzip/renderer';
28
+ import { createMdzipHeadingOutline } from './heading-outline.js';
18
29
  import { escapeMarkdownImageAlt, findImageReferenceAtOffset, formatImageEditMarkdown } from './image-edit.js';
19
30
  import { MdzipRenderingService, defaultSafeMarkdownRenderer, groupTokensIntoChunks, chunkSourceKey, collectMdzipHeadingIds, MDZIP_HEADING_ID_PREFIX, tokenEmbedsImage, tokenIsHeading } from './rendering.js';
20
31
  import { mdzipFrontMatterExtension } from './front-matter-extension.js';
32
+ import { frontMatterBlockText } from './front-matter.js';
21
33
  import { WORKSPACE_CSS } from './view-css.js';
22
34
  import { INLINE_SVG_SHADOW_CSS } from './svg-inline.js';
23
35
  const STYLE_ATTR = 'data-mdzip-ws-styles';
@@ -52,6 +64,14 @@ const PREVIEW_ICON_HTML = lucideIcon(Eye, TOOLBAR_ICON_CLASS);
52
64
  const SPLIT_ICON_HTML = lucideIcon(Columns2, TOOLBAR_ICON_CLASS);
53
65
  const SAVE_ICON_HTML = lucideIcon(Save, TOOLBAR_ICON_CLASS);
54
66
  const SEARCH_ICON_HTML = lucideIcon(Search, TOOLBAR_ICON_CLASS);
67
+ const FIND_ICON_CLASS = 'preview-find-icon';
68
+ const FIND_PREVIOUS_ICON_HTML = lucideIcon(ChevronUp, FIND_ICON_CLASS);
69
+ const FIND_NEXT_ICON_HTML = lucideIcon(ChevronDown, FIND_ICON_CLASS);
70
+ const FIND_CASE_ICON_HTML = lucideIcon(CaseSensitive, FIND_ICON_CLASS);
71
+ const FIND_CLOSE_ICON_HTML = lucideIcon(X, FIND_ICON_CLASS);
72
+ const OUTLINE_ICON_HTML = lucideIcon(TableOfContents, TOOLBAR_ICON_CLASS);
73
+ const WHITESPACE_ICON_HTML = lucideIcon(Pilcrow, TOOLBAR_ICON_CLASS);
74
+ const FORMAT_JSON_ICON_HTML = lucideIcon(Braces, TOOLBAR_ICON_CLASS);
55
75
  const ZOOM_ICON_HTML = lucideIcon(ZoomIn, TOOLBAR_ICON_CLASS);
56
76
  const DARK_THEME_ICON_HTML = lucideIcon(Moon, TOOLBAR_ICON_CLASS);
57
77
  const LIGHT_THEME_ICON_HTML = lucideIcon(Sun, TOOLBAR_ICON_CLASS);
@@ -106,7 +126,8 @@ const MENU_IMAGE_ICON_HTML = lucideIcon(ImagePlus, MENU_ICON_CLASS);
106
126
  const MENU_LINK_ICON_HTML = lucideIcon(Link, MENU_ICON_CLASS);
107
127
  const MENU_CLEAR_FORMAT_ICON_HTML = lucideIcon(Eraser, MENU_ICON_CLASS);
108
128
  const MENU_HEADING_PARENT_ICON_HTML = lucideIcon(Heading1, MENU_ICON_CLASS);
109
- const MENU_PARAGRAPH_ICON_HTML = lucideIcon(Pilcrow, MENU_ICON_CLASS);
129
+ // Lines of plain text: ¶ is the Show whitespace button's icon.
130
+ const MENU_PARAGRAPH_ICON_HTML = lucideIcon(Text, MENU_ICON_CLASS);
110
131
  const MENU_CHEVRON_ICON_HTML = lucideIcon(ChevronRight, 'nav-menu-chevron');
111
132
  const MENU_HEADING_ICON_HTML = {
112
133
  1: lucideIcon(Heading1, MENU_ICON_CLASS),
@@ -265,6 +286,7 @@ const CONTROL_PRESETS = {
265
286
  formatting: { ...NO_FORMATTING_CONTROLS },
266
287
  contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
267
288
  lineNumbers: false,
289
+ whitespace: false,
268
290
  save: false,
269
291
  zoom: false,
270
292
  previewWidth: false,
@@ -272,6 +294,7 @@ const CONTROL_PRESETS = {
272
294
  orphanActions: false,
273
295
  fileActions: false,
274
296
  search: false,
297
+ outline: false,
275
298
  codeBlockTools: true
276
299
  },
277
300
  viewer: {
@@ -283,6 +306,7 @@ const CONTROL_PRESETS = {
283
306
  formatting: { ...NO_FORMATTING_CONTROLS },
284
307
  contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
285
308
  lineNumbers: true,
309
+ whitespace: true,
286
310
  save: false,
287
311
  zoom: true,
288
312
  previewWidth: true,
@@ -290,6 +314,7 @@ const CONTROL_PRESETS = {
290
314
  orphanActions: false,
291
315
  fileActions: false,
292
316
  search: true,
317
+ outline: true,
293
318
  codeBlockTools: true
294
319
  },
295
320
  'standalone-editor': {
@@ -301,6 +326,7 @@ const CONTROL_PRESETS = {
301
326
  formatting: { ...ALL_FORMATTING_CONTROLS },
302
327
  contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
303
328
  lineNumbers: true,
329
+ whitespace: true,
304
330
  save: true,
305
331
  zoom: true,
306
332
  previewWidth: true,
@@ -308,6 +334,7 @@ const CONTROL_PRESETS = {
308
334
  orphanActions: true,
309
335
  fileActions: true,
310
336
  search: true,
337
+ outline: true,
311
338
  codeBlockTools: true
312
339
  },
313
340
  'hosted-editor': {
@@ -319,6 +346,7 @@ const CONTROL_PRESETS = {
319
346
  formatting: { ...ALL_FORMATTING_CONTROLS },
320
347
  contextMenu: { ...ALL_CONTEXT_MENU_CONTROLS },
321
348
  lineNumbers: true,
349
+ whitespace: true,
322
350
  save: false,
323
351
  zoom: true,
324
352
  previewWidth: true,
@@ -326,6 +354,7 @@ const CONTROL_PRESETS = {
326
354
  orphanActions: true,
327
355
  fileActions: true,
328
356
  search: true,
357
+ outline: true,
329
358
  codeBlockTools: true
330
359
  }
331
360
  };
@@ -441,6 +470,24 @@ function normalizeContentDensity(value) {
441
470
  return value === 'compact' ? value : 'comfortable';
442
471
  }
443
472
  const mdzipEditorTheme = EditorView.theme({
473
+ // Shown whitespace (controls.whitespace): small dots and arrows in the
474
+ // muted text color, so they stay in the background in light and dark.
475
+ '.cm-highlightSpace': {
476
+ backgroundImage: 'radial-gradient(circle at 50% 55%, var(--mdzip-muted-foreground-color, #999) 11%, transparent 13%)',
477
+ opacity: '0.7'
478
+ },
479
+ '.cm-highlightTab': {
480
+ backgroundImage: 'none',
481
+ position: 'relative',
482
+ opacity: '0.7'
483
+ },
484
+ '.cm-highlightTab::before': {
485
+ content: '"→"',
486
+ position: 'absolute',
487
+ left: '0',
488
+ color: 'var(--mdzip-muted-foreground-color, #999)',
489
+ pointerEvents: 'none'
490
+ },
444
491
  '&': {
445
492
  height: '100%',
446
493
  fontSize: 'calc(16px * var(--mdz-zoom, 1))',
@@ -602,6 +649,13 @@ const mdzipMarkdownHighlight = HighlightStyle.define([
602
649
  { tag: tags.contentSeparator, color: '#6a9955' },
603
650
  { tag: tags.atom, color: '#d100d1' },
604
651
  ]);
652
+ // JSON entries (#68), in the same palette as the Markdown style above.
653
+ const mdzipJsonHighlight = HighlightStyle.define([
654
+ { tag: tags.propertyName, color: '#008b8b' },
655
+ { tag: tags.string, color: '#c36f00' },
656
+ { tag: tags.number, color: '#6a9955' },
657
+ { tag: [tags.bool, tags.null], color: '#d100d1' },
658
+ ]);
605
659
  const hardBreakMarkerMatcher = new MatchDecorator({
606
660
  regexp: /<br\s*\/?>/gi,
607
661
  decoration: Decoration.mark({ class: 'mdzip-hard-break-marker' })
@@ -818,6 +872,22 @@ function attributesToHtml(attrs) {
818
872
  .map(([key, value]) => ` ${key}="${escapeHtml(String(value))}"`)
819
873
  .join('');
820
874
  }
875
+ // The selection key of the tree row at or around `element`: `f:<path>` for
876
+ // a file, `d:<path>` for a folder's own row (its summary), else null.
877
+ function navRowKey(element) {
878
+ if (!element) {
879
+ return null;
880
+ }
881
+ const file = element.closest('[data-nav-path]');
882
+ if (file) {
883
+ return `f:${file.getAttribute('data-nav-path') ?? ''}`;
884
+ }
885
+ const summary = element.closest('details[data-nav-dir] > summary');
886
+ if (summary) {
887
+ return `d:${summary.parentElement?.getAttribute('data-nav-dir') ?? ''}`;
888
+ }
889
+ return null;
890
+ }
821
891
  // Renders the per-row indent/guide cells: one fixed-width cell per ancestor
822
892
  // depth. An ancestor column draws a continuous vertical rail when that folder
823
893
  // still has siblings below it (so the spine keeps going), otherwise it is
@@ -854,6 +924,7 @@ depth = 0) {
854
924
  : safePath;
855
925
  const classes = [
856
926
  'nav-file',
927
+ options.selected.has(`f:${node.entry.path}`) ? 'nav-selected' : '',
857
928
  isCurrent ? 'current-entry' : '',
858
929
  isOrphaned ? 'orphaned-asset' : '',
859
930
  isEntryPoint ? 'entry-point' : ''
@@ -865,19 +936,19 @@ depth = 0) {
865
936
  : isImageFile(node.entry.path)
866
937
  ? IMAGE_ICON_HTML
867
938
  : FILE_ICON_HTML;
868
- const orphanBtnHtml = isOrphaned && options.allowOrphanActions ? `
869
- <span class="nav-orphan-button" role="button" tabindex="0"
870
- title="Orphaned asset" aria-label="Orphaned asset actions"
871
- data-orphan-path="${safePath}">
872
- ${ORPHAN_ICON_HTML}
939
+ const orphanBtnHtml = isOrphaned && options.allowOrphanActions ? `
940
+ <span class="nav-orphan-button" role="button" tabindex="0"
941
+ title="Orphaned asset" aria-label="Orphaned asset actions"
942
+ data-orphan-path="${safePath}">
943
+ ${ORPHAN_ICON_HTML}
873
944
  </span>` : '';
874
945
  const draggable = options.allowDrag && !isManifest;
875
- return `<button type="button" class="${classes}" title="${title}"
876
- data-nav-path="${safePath}" data-orphan="${isOrphaned ? 'true' : ''}"${draggable ? ' draggable="true"' : ''}>
877
- ${guides}<span class="nav-caret"></span>
878
- <span class="nav-file-icon ${iconKind}">${iconHtml}</span>
879
- ${orphanBtnHtml}
880
- <span class="nav-label">${safeName}</span>
946
+ return `<button type="button" class="${classes}" title="${title}"
947
+ data-nav-path="${safePath}" data-orphan="${isOrphaned ? 'true' : ''}"${draggable ? ' draggable="true"' : ''}>
948
+ ${guides}<span class="nav-caret"></span>
949
+ <span class="nav-file-icon ${iconKind}">${iconHtml}</span>
950
+ ${orphanBtnHtml}
951
+ <span class="nav-label">${safeName}</span>
881
952
  </button>`;
882
953
  }
883
954
  const childTrail = depth === 0 ? [] : [...trail, !isLast];
@@ -885,14 +956,16 @@ depth = 0) {
885
956
  .map((child, index) => renderNavNode(child, state, options, childTrail, index === node.children.length - 1, depth + 1))
886
957
  .join('');
887
958
  const pending = options.pendingFolders.has(node.path);
888
- return `<details class="nav-directory${pending ? ' pending-folder' : ''}" open data-nav-dir="${escapeHtml(node.path)}">
889
- <summary${pending ? ` title="${escapeHtml(node.path)} — not saved until it contains a file"` : ''}>
890
- ${guides}<span class="nav-caret" aria-hidden="true"></span>
891
- <span class="nav-folder-icon closed">${FOLDER_CLOSED_ICON_HTML}</span>
892
- <span class="nav-folder-icon open">${FOLDER_OPEN_ICON_HTML}</span>
893
- <span class="nav-label">${escapeHtml(node.name)}</span>
894
- </summary>
895
- <div class="nav-directory-children">${children}</div>
959
+ const open = options.collapsed.has(node.path) ? '' : ' open';
960
+ const selected = options.selected.has(`d:${node.path}`) ? ' class="nav-selected"' : '';
961
+ return `<details class="nav-directory${pending ? ' pending-folder' : ''}"${open} data-nav-dir="${escapeHtml(node.path)}">
962
+ <summary${selected}${pending ? ` title="${escapeHtml(node.path)} — not saved until it contains a file"` : ''}>
963
+ ${guides}<span class="nav-caret" aria-hidden="true"></span>
964
+ <span class="nav-folder-icon closed">${FOLDER_CLOSED_ICON_HTML}</span>
965
+ <span class="nav-folder-icon open">${FOLDER_OPEN_ICON_HTML}</span>
966
+ <span class="nav-label">${escapeHtml(node.name)}</span>
967
+ </summary>
968
+ <div class="nav-directory-children">${children}</div>
896
969
  </details>`;
897
970
  }
898
971
  // Inserts view-local pending (not yet saved) folders into the nav tree so they
@@ -1067,6 +1140,14 @@ export class MdzipWorkspaceView {
1067
1140
  this.contextMenuState = null;
1068
1141
  this.nameDialogState = null;
1069
1142
  this.deleteDialogState = null;
1143
+ // Selected rows of the file tree (#69): `f:<path>` / `d:<path>`, in the
1144
+ // order picked, and the row a Shift+click range starts from.
1145
+ this.navSelection = [];
1146
+ this.navSelectionAnchor = null;
1147
+ // Folders the reader closed, kept across the tree's redraws.
1148
+ this.navCollapsed = new Set();
1149
+ // A yes/no question in the editor's own dialog (see askConfirm()).
1150
+ this.confirmDialogState = null;
1070
1151
  this.pendingNewFolders = new Set();
1071
1152
  this.pendingReplacePath = null;
1072
1153
  this.conversionHookPending = false;
@@ -1090,7 +1171,12 @@ export class MdzipWorkspaceView {
1090
1171
  this.cmEditor = null;
1091
1172
  this.readOnlyCompartment = new Compartment();
1092
1173
  this.lineNumbersCompartment = new Compartment();
1174
+ this.whitespaceCompartment = new Compartment();
1093
1175
  this.searchCompartment = new Compartment();
1176
+ this.languageCompartment = new Compartment();
1177
+ this.cmLanguage = 'markdown';
1178
+ this.jsonValidity = null;
1179
+ this.jsonValidityPath = null;
1094
1180
  this.updatingCm = false;
1095
1181
  this.syncing = false;
1096
1182
  // Last value this class itself wrote to each pane's scrollTop, used to
@@ -1098,6 +1184,8 @@ export class MdzipWorkspaceView {
1098
1184
  // syncScrollFromPreview/syncScrollToPreview).
1099
1185
  this.lastSyncedEditorScrollTop = null;
1100
1186
  this.lastSyncedPreviewScrollTop = null;
1187
+ // See splitScrollBlocks().
1188
+ this.splitBlockCache = null;
1101
1189
  // Timestamp of the most recent updatePreview() call (edit-driven or
1102
1190
  // otherwise). A content change that alters a mounted element's rendered
1103
1191
  // height (a chunk reconcile re-rendering a mermaid diagram, an image
@@ -1163,6 +1251,8 @@ export class MdzipWorkspaceView {
1163
1251
  // (images loading or easing open, a diagram rendering) and push it out of
1164
1252
  // view. This holds the target at the pane's top edge until the user
1165
1253
  // scrolls either pane or the preview re-renders.
1254
+ // requestAnimationFrame handle of a smooth scroll to an anchor (see glidePreviewTo).
1255
+ this.previewGlide = null;
1166
1256
  this.anchorPin = null;
1167
1257
  // Each link's own target/rel from before the external-link policy touched
1168
1258
  // it, so a policy change can restore them before re-applying.
@@ -1199,6 +1289,36 @@ export class MdzipWorkspaceView {
1199
1289
  // matches() does not re-run on every snapshot render of the same entry.
1200
1290
  this.entryMatchMissKey = null;
1201
1291
  this.entryGeneration = 0;
1292
+ this.findOpen = false;
1293
+ this.findMatchCase = false;
1294
+ this.findState = null;
1295
+ // Each drawn chunk's text with its nodes, until something in it changes.
1296
+ this.findDomTexts = new WeakMap();
1297
+ // Every chunk's text by its source key, drawn or not, for counting.
1298
+ this.findTextCache = new Map();
1299
+ this.findObserver = null;
1300
+ this.findRefreshQueued = false;
1301
+ this.findIndexing = false;
1302
+ // Goes to the first match once typing pauses, when it isn't drawn yet.
1303
+ this.findRevealTimer = null;
1304
+ this.outlinePosition = 'right';
1305
+ // Null until set by the option or a drag: the style sheet's width applies.
1306
+ this.outlineWidth = null;
1307
+ this.outlineVisible = false;
1308
+ this.whitespaceVisible = false;
1309
+ // Which parts of the edit toolbar the last render showed (renderFormattingControls).
1310
+ this.formattingShown = false;
1311
+ // The manifest keeps its own layout (form by default); the other files'
1312
+ // layout waits in documentLayout while it's open.
1313
+ this.manifestLayout = 'preview';
1314
+ this.documentLayout = 'preview';
1315
+ this.layoutIsManifest = false;
1316
+ this.manifestForm = null;
1317
+ this.whitespaceControlShown = false;
1318
+ this.formatJsonShown = false;
1319
+ this.outlineOptions = {};
1320
+ this.outline = null;
1321
+ this.outlineGeneration = -1;
1202
1322
  this.pendingAddFilesDir = null;
1203
1323
  this.options = options;
1204
1324
  this.controlPolicy = resolveMdzipControlPolicy(options.controls);
@@ -1215,6 +1335,14 @@ export class MdzipWorkspaceView {
1215
1335
  this.colorSchemePreference = options.initialColorScheme ?? 'system';
1216
1336
  this.colorScheme = this.resolveColorScheme(this.colorSchemePreference);
1217
1337
  this.navVisible = options.navigationButtonActive ?? this.navVisible;
1338
+ this.outlineOptions = typeof options.outline === 'object' ? options.outline : {};
1339
+ this.outlineVisible = typeof options.outline === 'object' ? options.outline.visible ?? false : options.outline ?? false;
1340
+ this.outlinePosition = this.outlineOptions.position === 'left' ? 'left' : 'right';
1341
+ this.outlineWidth = typeof this.outlineOptions.width === 'number' && this.outlineOptions.width > 0
1342
+ ? Math.round(this.outlineOptions.width)
1343
+ : null;
1344
+ this.whitespaceVisible = options.showWhitespace ?? false;
1345
+ this.manifestLayout = options.manifestView === 'json' ? 'source' : 'preview';
1218
1346
  this.markdownRenderer = options.markdownRenderer;
1219
1347
  this.markdownExtensions = options.markdownExtensions ?? [];
1220
1348
  this.frontMatterOptions = options.frontMatter ?? {};
@@ -1240,6 +1368,18 @@ export class MdzipWorkspaceView {
1240
1368
  this.elSourceIcon = q('[data-ref="source-icon"]');
1241
1369
  this.elSaveBtn = q('[data-ref="save-btn"]');
1242
1370
  this.elSearchBtn = q('[data-ref="search-btn"]');
1371
+ this.elFind = q('[data-ref="preview-find"]');
1372
+ this.elFindInput = q('[data-ref="preview-find-input"]');
1373
+ this.elFindCount = q('[data-ref="preview-find-count"]');
1374
+ this.elFindCase = q('[data-ref="preview-find-case"]');
1375
+ this.elFindPrevious = q('[data-ref="preview-find-previous"]');
1376
+ this.elFindNext = q('[data-ref="preview-find-next"]');
1377
+ this.elFindClose = q('[data-ref="preview-find-close"]');
1378
+ this.elOutlineBtn = q('[data-ref="outline-btn"]');
1379
+ this.elWhitespaceBtn = q('[data-ref="whitespace-btn"]');
1380
+ this.elFormatJsonBtn = q('[data-ref="format-json-btn"]');
1381
+ this.elOutlinePane = q('[data-ref="outline-pane"]');
1382
+ this.elOutlineResizer = q('[data-ref="outline-resizer"]');
1243
1383
  this.elZoomBtn = q('[data-ref="zoom-btn"]');
1244
1384
  this.elWidthControls = q('[data-ref="width-controls"]');
1245
1385
  this.elWidthMenuBtn = q('[data-ref="width-menu-btn"]');
@@ -1263,6 +1403,7 @@ export class MdzipWorkspaceView {
1263
1403
  this.elEditToolbar = q('[data-ref="edit-toolbar"]');
1264
1404
  this.elImageInput = q('[data-ref="image-input"]');
1265
1405
  this.elEditorHost = q('[data-ref="editor-host"]');
1406
+ this.elJsonStatus = q('[data-ref="json-status"]');
1266
1407
  this.elSplitResizer = q('[data-ref="split-resizer"]');
1267
1408
  this.elPreviewPane = q('[data-ref="preview-pane"]');
1268
1409
  this.elPreviewContent = q('[data-ref="preview-content"]');
@@ -1308,6 +1449,10 @@ export class MdzipWorkspaceView {
1308
1449
  this.elNameValidation = q('[data-ref="name-validation"]');
1309
1450
  this.elNameConfirmBtn = q('[data-ref="name-confirm-btn"]');
1310
1451
  this.elDeleteDialog = q('[data-ref="delete-dialog"]');
1452
+ this.elConfirmDialog = q('[data-ref="confirm-dialog"]');
1453
+ this.elConfirmDialogTitle = q('[data-ref="confirm-dialog-title"]');
1454
+ this.elConfirmDialogText = q('[data-ref="confirm-dialog-text"]');
1455
+ this.elConfirmDialogOk = q('[data-ref="confirm-dialog-ok"]');
1311
1456
  this.elDeleteDialogText = q('[data-ref="delete-dialog-text"]');
1312
1457
  this.elDeleteConfirmBtn = q('[data-ref="delete-confirm-btn"]');
1313
1458
  this.elReplaceInput = q('[data-ref="replace-input"]');
@@ -1551,11 +1696,12 @@ export class MdzipWorkspaceView {
1551
1696
  return true;
1552
1697
  }
1553
1698
  /**
1554
- * Opens CodeMirror's find/replace panel for the current document. Unlike
1555
- * {@link executeCommand}, this works in read-only (Viewer) hosts too —
1556
- * searching doesn't require edit access, only a visible source pane. If
1557
- * the current layout is preview-only, switches to split/source first so
1558
- * the panel has somewhere to render.
1699
+ * Opens find for the current document. In the View layout it's a find
1700
+ * bar over the preview that searches the rendered text, the whole
1701
+ * document including parts not drawn yet, and leaves the layout as it is.
1702
+ * In Edit and Split it's CodeMirror's find/replace panel. Works in
1703
+ * read-only (Viewer) hosts too. When the preview belongs to an entry
1704
+ * renderer, switches to split/source for the panel.
1559
1705
  */
1560
1706
  async openSearch() {
1561
1707
  if (!this.controlPolicy.search) {
@@ -1565,6 +1711,10 @@ export class MdzipWorkspaceView {
1565
1711
  if (!snapshot || snapshot.currentPathType !== 'markdown') {
1566
1712
  return false;
1567
1713
  }
1714
+ if (this.findApplies(snapshot)) {
1715
+ this.openFind();
1716
+ return true;
1717
+ }
1568
1718
  if (this.layout === 'preview') {
1569
1719
  const nextLayout = this.controlPolicy.layout.split
1570
1720
  ? 'split'
@@ -1582,8 +1732,357 @@ export class MdzipWorkspaceView {
1582
1732
  return openSearchPanel(editor);
1583
1733
  }
1584
1734
  closeSearch() {
1735
+ if (this.findOpen) {
1736
+ return this.closeFind();
1737
+ }
1585
1738
  return this.cmEditor ? closeSearchPanel(this.cmEditor) : false;
1586
1739
  }
1740
+ /** Whether the find bar is open over the preview. */
1741
+ get isFindOpen() {
1742
+ return this.findOpen;
1743
+ }
1744
+ // --- Find in the preview (#62) ---------------------------------------------------
1745
+ findApplies(snapshot = this.workspace?.snapshot()) {
1746
+ return !!snapshot && this.controlPolicy.search && this.layout === 'preview'
1747
+ && snapshot.currentPathType === 'markdown' && !this.entryState;
1748
+ }
1749
+ openFind() {
1750
+ const doc = this.elRoot.ownerDocument;
1751
+ // Like a browser: a short selection in the document becomes the query.
1752
+ const selection = doc.getSelection?.();
1753
+ if (selection && selection.rangeCount && selection.anchorNode && this.elPreviewContent.contains(selection.anchorNode)) {
1754
+ const selected = selection.toString().trim();
1755
+ if (selected && selected.length <= 200 && !/\n/.test(selected)) {
1756
+ this.elFindInput.value = selected;
1757
+ }
1758
+ }
1759
+ this.findOpen = true;
1760
+ this.elFind.hidden = false;
1761
+ this.elSearchBtn.classList.add('active');
1762
+ this.elFindInput.focus();
1763
+ this.elFindInput.select();
1764
+ if (!this.findObserver && typeof MutationObserver !== 'undefined') {
1765
+ this.findObserver = new MutationObserver((records) => {
1766
+ for (const record of records) {
1767
+ const target = record.target.nodeType === 1 ? record.target : record.target.parentElement;
1768
+ const root = target?.closest('.mdzip-chunk') ?? this.elPreviewContent;
1769
+ this.findDomTexts.delete(root);
1770
+ }
1771
+ this.scheduleFindRefresh();
1772
+ });
1773
+ this.findObserver.observe(this.elPreviewContent, { childList: true, subtree: true, characterData: true });
1774
+ }
1775
+ this.refreshFind('viewport');
1776
+ this.revealFindMatchSoon();
1777
+ }
1778
+ // When the current match is in a chunk not drawn yet, draws it and goes
1779
+ // there once typing pauses (the next keystroke starts the wait again).
1780
+ revealFindMatchSoon() {
1781
+ if (this.findRevealTimer !== null) {
1782
+ clearTimeout(this.findRevealTimer);
1783
+ }
1784
+ this.findRevealTimer = setTimeout(() => {
1785
+ this.findRevealTimer = null;
1786
+ void this.moveFind(0);
1787
+ }, 300);
1788
+ }
1789
+ closeFind(restoreFocus = true) {
1790
+ if (!this.findOpen) {
1791
+ return false;
1792
+ }
1793
+ const doc = this.elRoot.ownerDocument;
1794
+ const hadFocus = this.elFind.contains(doc.activeElement);
1795
+ this.findOpen = false;
1796
+ if (this.findRevealTimer !== null) {
1797
+ clearTimeout(this.findRevealTimer);
1798
+ this.findRevealTimer = null;
1799
+ }
1800
+ this.elFind.hidden = true;
1801
+ this.elSearchBtn.classList.remove('active');
1802
+ this.findState = null;
1803
+ this.findObserver?.disconnect();
1804
+ this.findObserver = null;
1805
+ this.findDomTexts = new WeakMap();
1806
+ setFindHighlights(doc, this, [], null);
1807
+ if (restoreFocus && hadFocus) {
1808
+ this.elPreviewPane.focus({ preventScroll: true });
1809
+ }
1810
+ return true;
1811
+ }
1812
+ scheduleFindRefresh() {
1813
+ if (this.findRefreshQueued) {
1814
+ return;
1815
+ }
1816
+ this.findRefreshQueued = true;
1817
+ requestAnimationFrame(() => {
1818
+ this.findRefreshQueued = false;
1819
+ this.refreshFind('keep');
1820
+ });
1821
+ }
1822
+ // The chunks of the document, drawn or not. Without chunks (a custom
1823
+ // renderer), the whole preview is one.
1824
+ findChunks() {
1825
+ const state = this.chunkedRenderState;
1826
+ if (!state) {
1827
+ return [{ key: null, root: this.elPreviewContent, index: 0 }];
1828
+ }
1829
+ return state.records.map((record, index) => ({
1830
+ key: record.key,
1831
+ root: record.root && record.root.isConnected ? record.root : null,
1832
+ index
1833
+ }));
1834
+ }
1835
+ /**
1836
+ * Matches the query against every chunk's text and repaints. `viewport`
1837
+ * (a new query) makes the first match at or below the top of the pane
1838
+ * current and scrolls to it; `keep` (the document changed under the bar)
1839
+ * keeps the current match.
1840
+ */
1841
+ refreshFind(mode, scroll = mode === 'viewport') {
1842
+ if (!this.findOpen || this.destroyed) {
1843
+ return;
1844
+ }
1845
+ const previous = this.findState;
1846
+ const pattern = findPattern(this.elFindInput.value, this.findMatchCase);
1847
+ const matches = [];
1848
+ const texts = [];
1849
+ let pending = false;
1850
+ const chunks = this.findChunks();
1851
+ if (pattern) {
1852
+ for (const chunk of chunks) {
1853
+ let dom = null;
1854
+ let text;
1855
+ if (chunk.root) {
1856
+ dom = this.findDomTexts.get(chunk.root) ?? null;
1857
+ if (!dom) {
1858
+ dom = collectFindText(chunk.root);
1859
+ this.findDomTexts.set(chunk.root, dom);
1860
+ }
1861
+ text = dom.text;
1862
+ if (chunk.key !== null) {
1863
+ this.findTextCache.set(chunk.key, text);
1864
+ }
1865
+ }
1866
+ else if (chunk.key !== null) {
1867
+ text = this.findTextCache.get(chunk.key);
1868
+ }
1869
+ texts.push(dom);
1870
+ if (text === undefined) {
1871
+ pending = true;
1872
+ continue;
1873
+ }
1874
+ let ordinal = 0;
1875
+ for (const [start, end] of findMatches(text, pattern)) {
1876
+ matches.push({ chunk: chunk.index, ordinal: ordinal++, start, end });
1877
+ }
1878
+ }
1879
+ }
1880
+ let current = -1;
1881
+ if (matches.length) {
1882
+ const was = mode === 'keep' && previous && previous.current >= 0 ? previous.matches[previous.current] : null;
1883
+ if (was) {
1884
+ current = matches.findIndex((match) => match.chunk === was.chunk && match.ordinal === was.ordinal);
1885
+ if (current < 0) {
1886
+ current = Math.min(previous.current, matches.length - 1);
1887
+ }
1888
+ }
1889
+ else {
1890
+ current = this.firstFindMatchInView(matches, chunks, texts);
1891
+ // A first match (perhaps found by the background count): show it,
1892
+ // drawing its chunk first when it isn't yet.
1893
+ scroll = true;
1894
+ if (!texts[matches[current].chunk]) {
1895
+ this.revealFindMatchSoon();
1896
+ }
1897
+ }
1898
+ }
1899
+ this.findState = { matches, current, pending, texts };
1900
+ this.paintFind(scroll);
1901
+ if (pending) {
1902
+ this.indexFindChunks();
1903
+ }
1904
+ }
1905
+ // The first match at or below the top of the preview pane, or the first.
1906
+ firstFindMatchInView(matches, chunks, texts) {
1907
+ const paneTop = this.elPreviewPane.getBoundingClientRect().top;
1908
+ let skipped = -1;
1909
+ for (let i = 0; i < matches.length; i += 1) {
1910
+ const match = matches[i];
1911
+ const root = chunks[match.chunk]?.root;
1912
+ const dom = texts[match.chunk];
1913
+ if (!root || !dom) {
1914
+ // Not drawn yet: below what is.
1915
+ return i;
1916
+ }
1917
+ if (match.chunk === skipped) {
1918
+ continue;
1919
+ }
1920
+ if (root.getBoundingClientRect().bottom < paneTop) {
1921
+ skipped = match.chunk;
1922
+ continue;
1923
+ }
1924
+ const range = findRange(dom, match.start, match.end);
1925
+ if (!range || typeof range.getBoundingClientRect !== 'function' || range.getBoundingClientRect().top >= paneTop - 1) {
1926
+ return i;
1927
+ }
1928
+ }
1929
+ return 0;
1930
+ }
1931
+ // Highlights the matches near the current one (all of them, up to a
1932
+ // thousand) and the current one, and updates the count.
1933
+ paintFind(scroll) {
1934
+ const state = this.findState;
1935
+ const all = [];
1936
+ let currentRange = null;
1937
+ if (state && state.current >= 0) {
1938
+ const from = Math.max(0, state.current - 500);
1939
+ const to = Math.min(state.matches.length, state.current + 500);
1940
+ for (let i = from; i < to; i += 1) {
1941
+ const match = state.matches[i];
1942
+ const dom = state.texts[match.chunk];
1943
+ const range = dom ? findRange(dom, match.start, match.end) : null;
1944
+ if (!range) {
1945
+ continue;
1946
+ }
1947
+ if (i === state.current) {
1948
+ currentRange = range;
1949
+ }
1950
+ else {
1951
+ all.push(range);
1952
+ }
1953
+ }
1954
+ }
1955
+ setFindHighlights(this.elRoot.ownerDocument, this, all, currentRange);
1956
+ const query = this.elFindInput.value.trim();
1957
+ const total = state?.matches.length ?? 0;
1958
+ let label = '';
1959
+ if (query && state) {
1960
+ if (!total) {
1961
+ label = state.pending ? 'Searching…' : 'No results';
1962
+ }
1963
+ else {
1964
+ label = `${state.current + 1} of ${total}${state.pending ? '+' : ''}`;
1965
+ }
1966
+ }
1967
+ this.elFindCount.textContent = label;
1968
+ this.elFind.classList.toggle('no-results', !!query && !!state && !total && !state.pending);
1969
+ this.elFindPrevious.disabled = total === 0;
1970
+ this.elFindNext.disabled = total === 0;
1971
+ if (scroll && currentRange) {
1972
+ this.scrollFindRangeIntoView(currentRange);
1973
+ }
1974
+ }
1975
+ scrollFindRangeIntoView(range) {
1976
+ if (typeof range.getBoundingClientRect !== 'function') {
1977
+ return;
1978
+ }
1979
+ const pane = this.elPreviewPane;
1980
+ const rect = range.getBoundingClientRect();
1981
+ const paneRect = pane.getBoundingClientRect();
1982
+ // Below the find bar, above the bottom edge.
1983
+ if (rect.top >= paneRect.top + this.elFind.offsetHeight + 16 && rect.bottom <= paneRect.bottom - 16) {
1984
+ return;
1985
+ }
1986
+ this.releaseAnchorPin();
1987
+ pane.scrollTop += rect.top - paneRect.top - pane.clientHeight / 3;
1988
+ }
1989
+ /**
1990
+ * Goes to the next (1) or previous (-1) match, drawing its chunk first
1991
+ * when it isn't yet. A current match that hasn't been shown (its chunk
1992
+ * isn't drawn) is gone to first, not skipped; 0 only does that.
1993
+ */
1994
+ async moveFind(delta) {
1995
+ const state = this.findState;
1996
+ if (!this.findOpen || !state || !state.matches.length) {
1997
+ return;
1998
+ }
1999
+ const total = state.matches.length;
2000
+ const unseen = state.current >= 0 && !state.texts[state.matches[state.current].chunk];
2001
+ if (!unseen) {
2002
+ if (delta === 0) {
2003
+ return;
2004
+ }
2005
+ const from = state.current < 0 ? (delta > 0 ? -1 : 0) : state.current;
2006
+ state.current = (from + delta + total) % total;
2007
+ }
2008
+ const match = state.matches[state.current];
2009
+ if (!state.texts[match.chunk]) {
2010
+ await this.mountChunksThrough(match.chunk);
2011
+ this.findDomTexts = new WeakMap();
2012
+ this.refreshFind('keep', true);
2013
+ return;
2014
+ }
2015
+ this.paintFind(true);
2016
+ }
2017
+ // Draws the chunks up to and including `index`, as scrollToAnchor() does.
2018
+ async mountChunksThrough(index) {
2019
+ const pending = this.chunkedRenderState;
2020
+ if (!pending || pending.cursor > index) {
2021
+ return;
2022
+ }
2023
+ await this.drainRemainingChunks(pending, () => { }, new AbortController().signal, index);
2024
+ const remaining = this.chunkedRenderState;
2025
+ if (remaining && remaining.generation === pending.generation && !remaining.sentinelHandle
2026
+ && remaining.cursor < remaining.records.length) {
2027
+ this.armChunkSentinel(remaining.records, remaining.cursor, remaining.context, remaining.generation, remaining.animateImageHydration);
2028
+ }
2029
+ }
2030
+ /**
2031
+ * Finds the text of chunks not drawn yet, a few at a time between frames,
2032
+ * so the count covers the whole document: each chunk's HTML (cached, or
2033
+ * rendered) in a detached fragment, read the same way as the preview.
2034
+ */
2035
+ indexFindChunks() {
2036
+ const state = this.chunkedRenderState;
2037
+ if (this.findIndexing || !state) {
2038
+ return;
2039
+ }
2040
+ this.findIndexing = true;
2041
+ const records = state.records;
2042
+ const generation = state.generation;
2043
+ const live = new Set(records.map((record) => record.key));
2044
+ for (const key of Array.from(this.findTextCache.keys())) {
2045
+ if (!live.has(key)) {
2046
+ this.findTextCache.delete(key);
2047
+ }
2048
+ }
2049
+ const run = async () => {
2050
+ let batchStart = performance.now();
2051
+ for (let i = 0; i < records.length; i += 1) {
2052
+ if (!this.findOpen || this.destroyed || this.chunkedRenderState?.records !== records) {
2053
+ return;
2054
+ }
2055
+ const record = records[i];
2056
+ if ((record.root && record.root.isConnected) || this.findTextCache.has(record.key)) {
2057
+ continue;
2058
+ }
2059
+ let html = record.html
2060
+ ?? (this.chunkHtmlCache?.generation === generation ? this.chunkHtmlCache.html.get(i) : undefined);
2061
+ if (html === undefined) {
2062
+ const result = this.renderingService.renderChunk(record.tokens, state.context, { index: i, markBlocks: true });
2063
+ html = typeof result === 'string' ? result : await result;
2064
+ }
2065
+ this.findTextCache.set(record.key, collectFindText(this.inertPreviewFragment(html)).text);
2066
+ if (performance.now() - batchStart > 12) {
2067
+ this.refreshFind('keep', false);
2068
+ await new Promise((resolve) => requestAnimationFrame(() => resolve()));
2069
+ batchStart = performance.now();
2070
+ }
2071
+ }
2072
+ };
2073
+ void run()
2074
+ .catch((error) => {
2075
+ if (error?.name !== 'AbortError') {
2076
+ this.options.onFailed?.(error);
2077
+ }
2078
+ })
2079
+ .finally(() => {
2080
+ this.findIndexing = false;
2081
+ if (this.findOpen && !this.destroyed && this.chunkedRenderState?.records === records) {
2082
+ this.refreshFind('keep', false);
2083
+ }
2084
+ });
2085
+ }
1587
2086
  async convertToMdz() {
1588
2087
  if (!this.workspace || this.workspace.mode === 'read-only') {
1589
2088
  return false;
@@ -1602,6 +2101,7 @@ export class MdzipWorkspaceView {
1602
2101
  this.cmEditor?.focus();
1603
2102
  }
1604
2103
  destroy() {
2104
+ this.closeFind(false);
1605
2105
  this.systemColorSchemeQuery?.removeEventListener?.('change', this.onSystemColorSchemeChange);
1606
2106
  this.conversionDocumentGeneration += 1;
1607
2107
  this.resolveImageInsertDialog(null);
@@ -1615,6 +2115,8 @@ export class MdzipWorkspaceView {
1615
2115
  this.resetPreviewState();
1616
2116
  this.replaceAssetSession(null);
1617
2117
  this.teardownEntryRenderer();
2118
+ this.outline?.destroy();
2119
+ this.outline = null;
1618
2120
  // Release any whenRendered() waiters so their promises do not hang.
1619
2121
  this.flushRenderedWaiters();
1620
2122
  this.destroyed = true;
@@ -2038,7 +2540,13 @@ export class MdzipWorkspaceView {
2038
2540
  this.fireAssetsHydrated(snapshot, generation);
2039
2541
  }).catch((error) => this.options.onFailed?.(error));
2040
2542
  }
2543
+ else if (this.isManifestFormPath(snapshot)) {
2544
+ this.mountManifestForm(snapshot);
2545
+ this.firePreviewRendered(snapshot, generation);
2546
+ this.fireAssetsHydrated(snapshot, generation);
2547
+ }
2041
2548
  else {
2549
+ this.manifestForm = null;
2042
2550
  this.elPreviewContent.innerHTML = renderMdzipPreviewHtml(snapshot);
2043
2551
  this.firePreviewRendered(snapshot, generation);
2044
2552
  this.fireAssetsHydrated(snapshot, generation);
@@ -2568,6 +3076,19 @@ export class MdzipWorkspaceView {
2568
3076
  }
2569
3077
  });
2570
3078
  }
3079
+ /**
3080
+ * Each chunk's reuse key (`chunkSourceKey`). Chunk 0's also covers the
3081
+ * front matter: it's stripped before chunking, so no chunk's own text
3082
+ * includes it, but chunk 0 shows its panel and must re-render when it
3083
+ * changes.
3084
+ */
3085
+ chunkKeys(chunks, markdown) {
3086
+ const frontMatter = frontMatterBlockText(markdown);
3087
+ return chunks.map((chunk, index) => {
3088
+ const key = chunkSourceKey(chunk);
3089
+ return index === 0 && frontMatter ? `${frontMatter}\u0002${key}` : key;
3090
+ });
3091
+ }
2571
3092
  /** Destroys one chunk record's mounted DOM and handles (but not the record object itself). */
2572
3093
  teardownChunkRecord(record) {
2573
3094
  for (const handle of record.handles) {
@@ -2612,7 +3133,7 @@ export class MdzipWorkspaceView {
2612
3133
  return;
2613
3134
  }
2614
3135
  const oldKeys = oldRecords.map((r) => r.key);
2615
- const newKeys = newChunks.map((c) => chunkSourceKey(c));
3136
+ const newKeys = this.chunkKeys(newChunks, snapshot.currentText);
2616
3137
  const maxMatch = Math.min(oldKeys.length, newKeys.length);
2617
3138
  let prefixLen = 0;
2618
3139
  while (prefixLen < maxMatch && oldKeys[prefixLen] === newKeys[prefixLen])
@@ -2746,8 +3267,9 @@ export class MdzipWorkspaceView {
2746
3267
  this.fireAssetsHydrated(snapshot, generation);
2747
3268
  return;
2748
3269
  }
2749
- const records = chunks.map((chunkTokens) => ({
2750
- key: chunkSourceKey(chunkTokens),
3270
+ const keys = this.chunkKeys(chunks, snapshot.currentText);
3271
+ const records = chunks.map((chunkTokens, index) => ({
3272
+ key: keys[index],
2751
3273
  tokens: chunkTokens,
2752
3274
  root: null,
2753
3275
  html: null,
@@ -2894,7 +3416,7 @@ export class MdzipWorkspaceView {
2894
3416
  html = cacheHit;
2895
3417
  }
2896
3418
  else {
2897
- const result = this.renderingService.renderChunk(chunkTokens, context);
3419
+ const result = this.renderingService.renderChunk(chunkTokens, context, { index: chunkIndex, markBlocks: true });
2898
3420
  html = typeof result === 'string' ? result : await result;
2899
3421
  }
2900
3422
  }
@@ -3283,6 +3805,7 @@ export class MdzipWorkspaceView {
3283
3805
  this.restorePendingPreviewScroll(generation);
3284
3806
  this.flushPendingAnchorSoon();
3285
3807
  this.markPreviewMounted();
3808
+ this.refreshOutline();
3286
3809
  this.firingPreviewRendered = true;
3287
3810
  try {
3288
3811
  this.options.onPreviewRendered?.(snapshot);
@@ -3527,6 +4050,7 @@ export class MdzipWorkspaceView {
3527
4050
  doc: initialText,
3528
4051
  extensions: [
3529
4052
  this.lineNumbersCompartment.of(this.controlPolicy.lineNumbers ? lineNumbers() : []),
4053
+ this.whitespaceCompartment.of(this.whitespaceVisible ? highlightWhitespace() : []),
3530
4054
  this.searchCompartment.of(this.controlPolicy.search ? [search({ top: true }), keymap.of(searchKeymap)] : []),
3531
4055
  history(),
3532
4056
  keymap.of([
@@ -3535,7 +4059,7 @@ export class MdzipWorkspaceView {
3535
4059
  { key: 'Mod-k', run: () => self.runFormatShortcut('link') }
3536
4060
  ]),
3537
4061
  keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
3538
- markdown(),
4062
+ this.languageCompartment.of(markdown()),
3539
4063
  syntaxHighlighting(mdzipMarkdownHighlight),
3540
4064
  hardBreakMarkerHighlight,
3541
4065
  htmlTagMarkerHighlight,
@@ -3651,7 +4175,10 @@ export class MdzipWorkspaceView {
3651
4175
  || !canShowSourceLayout(snapshot)) {
3652
4176
  return this.cmEditor;
3653
4177
  }
4178
+ this.cmLanguage = 'markdown';
4179
+ this.jsonValidityPath = null;
3654
4180
  this.cmEditor = this.createCmEditor(this.elEditorHost, snapshot.currentText, snapshot.mode);
4181
+ this.syncEditorLanguage(snapshot);
3655
4182
  return this.cmEditor;
3656
4183
  }
3657
4184
  render() {
@@ -3680,6 +4207,7 @@ export class MdzipWorkspaceView {
3680
4207
  this.elToolbar.hidden = true;
3681
4208
  return;
3682
4209
  }
4210
+ this.swapManifestLayout(snapshot);
3683
4211
  this.layout = this.validLayoutForSnapshot(this.layout, snapshot);
3684
4212
  const entryClaimed = this.syncEntryRenderer(snapshot);
3685
4213
  const canEdit = !entryClaimed
@@ -3698,29 +4226,49 @@ export class MdzipWorkspaceView {
3698
4226
  if (!showWidthControl) {
3699
4227
  this.widthMenuOpen = false;
3700
4228
  }
3701
- const showSearchControl = this.controlPolicy.search
3702
- && canShowSource && snapshot.currentPathType === 'markdown';
4229
+ // Only where the source editor shows: Edit or Split, for a file it can edit.
4230
+ const showWhitespaceControl = this.controlPolicy.whitespace && !entryClaimed
4231
+ && canShowSource && this.shownLayout(snapshot) !== 'preview';
4232
+ const showSearchControl = this.controlPolicy.search && snapshot.currentPathType === 'markdown'
4233
+ && (canShowSource || this.findApplies(snapshot));
4234
+ if (this.findOpen && !this.findApplies(snapshot)) {
4235
+ this.closeFind(false);
4236
+ }
4237
+ const showOutlineControl = this.controlPolicy.outline && !entryClaimed
4238
+ && snapshot.currentPathType === 'markdown' && this.layout !== 'source';
3703
4239
  const showEditControls = canEdit
3704
4240
  && snapshot.currentPathType === 'markdown'
3705
4241
  && this.layout !== 'preview'
3706
4242
  && hasFormattingControls(this.controlPolicy.formatting);
3707
4243
  const showToolbar = this.controlPolicy.toolbar
3708
4244
  && (showNavigationControl || showLayoutControls || showSaveControl
3709
- || showZoomControl || showWidthControl || showColorSchemeControl || showSearchControl
3710
- || showEditControls);
4245
+ || showZoomControl || showWidthControl || showColorSchemeControl || showSearchControl || showWhitespaceControl
4246
+ || showOutlineControl || showEditControls);
3711
4247
  this.elDocumentStrip.hidden = !showTitleControl;
3712
4248
  this.elToolbar.hidden = !showToolbar;
3713
4249
  this.elToolbarLeft.hidden = !showNavigationControl;
3714
- this.elEditToolbar.hidden = !showEditControls;
4250
+ const showFormatJsonControl = canEdit && isMdzipJsonPath(snapshot.currentPath)
4251
+ && this.shownLayout(snapshot) !== 'preview';
4252
+ this.elEditToolbar.hidden = !showEditControls && !showWhitespaceControl && !showFormatJsonControl;
4253
+ this.formattingShown = showEditControls;
4254
+ this.whitespaceControlShown = showWhitespaceControl;
4255
+ this.formatJsonShown = showFormatJsonControl;
3715
4256
  this.elLayoutControls.hidden = !showLayoutControls;
3716
4257
  this.elToolbarControls.hidden = !showSaveControl && !showZoomControl
3717
- && !showWidthControl && !showColorSchemeControl && !showSearchControl;
4258
+ && !showWidthControl && !showColorSchemeControl && !showSearchControl && !showOutlineControl;
3718
4259
  this.elNavBtn.hidden = !showNavigationControl;
3719
4260
  this.elPreviewBtn.hidden = !this.controlPolicy.layout.preview;
3720
4261
  this.elSplitBtn.hidden = !this.controlPolicy.layout.split;
3721
4262
  this.elSourceBtn.hidden = !this.controlPolicy.layout.source;
3722
4263
  this.elSaveBtn.hidden = !showSaveControl;
3723
4264
  this.elSearchBtn.hidden = !showSearchControl;
4265
+ const findLabel = this.findApplies(snapshot) ? 'Find' : 'Find/replace';
4266
+ this.elSearchBtn.title = `${findLabel} (Mod-F)`;
4267
+ this.elSearchBtn.setAttribute('aria-label', findLabel);
4268
+ this.elWhitespaceBtn.setAttribute('aria-pressed', String(this.whitespaceVisible));
4269
+ this.elOutlineBtn.hidden = !showOutlineControl;
4270
+ this.elOutlineBtn.classList.toggle('active', this.outlineVisible);
4271
+ this.elOutlineBtn.setAttribute('aria-pressed', String(this.outlineVisible));
3724
4272
  this.elZoomBtn.hidden = !showZoomControl;
3725
4273
  this.elWidthControls.hidden = !showWidthControl;
3726
4274
  this.elThemeControls.hidden = !showColorSchemeControl;
@@ -3753,7 +4301,10 @@ export class MdzipWorkspaceView {
3753
4301
  || !this.controlPolicy.title.editable;
3754
4302
  this.renderMetadata(snapshot);
3755
4303
  this.elSaveBtn.disabled = snapshot.mode === 'read-only' || !snapshot.dirty;
3756
- this.elSplitBtn.disabled = !this.controlPolicy.layout.split || !canShowSource;
4304
+ // Split only means something for Markdown: for JSON and other text the
4305
+ // preview would repeat the editor's text (see shownLayout).
4306
+ this.elSplitBtn.disabled = !this.controlPolicy.layout.split || !canShowSource
4307
+ || (snapshot.currentPathType !== 'markdown' && !this.isManifestFormPath(snapshot));
3757
4308
  this.elSourceBtn.disabled = !this.controlPolicy.layout.source || !canShowSource;
3758
4309
  this.renderFormattingControls();
3759
4310
  // Update button labels based on mode
@@ -3768,11 +4319,12 @@ export class MdzipWorkspaceView {
3768
4319
  this.elSourceIcon.innerHTML = SOURCE_EDIT_ICON_HTML;
3769
4320
  }
3770
4321
  this.elPreviewBtn.classList.toggle('active', this.layout === 'preview');
3771
- this.elSplitBtn.classList.toggle('active', this.layout === 'split');
3772
- this.elSourceBtn.classList.toggle('active', this.layout === 'source');
4322
+ const shownLayout = this.shownLayout(snapshot);
4323
+ this.elSplitBtn.classList.toggle('active', shownLayout === 'split');
4324
+ this.elSourceBtn.classList.toggle('active', shownLayout === 'source');
3773
4325
  this.elPreviewBtn.setAttribute('aria-pressed', String(this.layout === 'preview'));
3774
- this.elSplitBtn.setAttribute('aria-pressed', String(this.layout === 'split'));
3775
- this.elSourceBtn.setAttribute('aria-pressed', String(this.layout === 'source'));
4326
+ this.elSplitBtn.setAttribute('aria-pressed', String(shownLayout === 'split'));
4327
+ this.elSourceBtn.setAttribute('aria-pressed', String(shownLayout === 'source'));
3776
4328
  if (snapshot.sourceFormat === 'markdown') {
3777
4329
  this.elNavBtn.innerHTML = CONVERT_TO_MDZ_ICON_HTML;
3778
4330
  this.elNavBtn.classList.remove('active');
@@ -3858,11 +4410,14 @@ export class MdzipWorkspaceView {
3858
4410
  allowOrphanActions,
3859
4411
  allowFileActions,
3860
4412
  allowDrag: snapshot.mode !== 'read-only' && snapshot.sourceFormat === 'mdz',
3861
- pendingFolders: new Set(this.pendingNewFolders)
4413
+ pendingFolders: new Set(this.pendingNewFolders),
4414
+ selected: new Set(this.navSelection),
4415
+ collapsed: this.navCollapsed
3862
4416
  };
3863
4417
  this.elNavTree.innerHTML = navTree
3864
4418
  .map((n, i) => renderNavNode(n, snapshot, navRenderOptions, [], i === navTree.length - 1, 0))
3865
4419
  .join('');
4420
+ this.syncNavSelection();
3866
4421
  this.prepareTooltips();
3867
4422
  if (this.cmEditor) {
3868
4423
  this.updatingCm = true;
@@ -3876,17 +4431,21 @@ export class MdzipWorkspaceView {
3876
4431
  this.cmEditor.dispatch({
3877
4432
  effects: this.readOnlyCompartment.reconfigure(EditorState.readOnly.of(snapshot.mode === 'read-only'))
3878
4433
  });
4434
+ this.syncEditorLanguage(snapshot);
3879
4435
  }
3880
4436
  this.updatePreview(snapshot, entryClaimed);
3881
4437
  const pt = snapshot.currentPathType;
3882
- const showEdit = !entryClaimed && (pt === 'markdown' || pt === 'text') && this.layout !== 'preview';
3883
- const showPreview = !entryClaimed && (pt === 'image' || pt === 'binary' || pt === 'text'
3884
- || (pt === 'markdown' && this.layout !== 'source'));
4438
+ const shown = this.shownLayout(snapshot);
4439
+ const showEdit = !entryClaimed && (pt === 'markdown' || pt === 'text') && shown !== 'preview';
4440
+ // A text file's preview is its text as-is: shown in View, not beside the editor.
4441
+ const showPreview = !entryClaimed && (pt === 'image' || pt === 'binary'
4442
+ || ((pt === 'markdown' || pt === 'text') && shown !== 'source'));
3885
4443
  this.elEditPane.classList.toggle('active', showEdit);
3886
4444
  this.elPreviewPane.classList.toggle('active', showPreview);
3887
4445
  this.elEntryPane.classList.toggle('active', entryClaimed);
3888
- this.elPaneStack.classList.toggle('split-mode', this.layout === 'split' && !entryClaimed);
4446
+ this.elPaneStack.classList.toggle('split-mode', shown === 'split' && !entryClaimed);
3889
4447
  this.elPaneStack.classList.toggle('entry-claimed', entryClaimed);
4448
+ this.syncOutlinePane(this.outlineVisible && !entryClaimed && pt === 'markdown' && this.layout !== 'source');
3890
4449
  if (!showTitleControl) {
3891
4450
  this.titleDialogOpen = false;
3892
4451
  this.metadataDialogOpen = false;
@@ -3977,6 +4536,12 @@ export class MdzipWorkspaceView {
3977
4536
  this.elNameValidation.textContent = this.nameDialogState.error;
3978
4537
  this.elNameConfirmBtn.disabled = Boolean(this.nameDialogState.error);
3979
4538
  }
4539
+ this.elConfirmDialog.hidden = this.confirmDialogState === null;
4540
+ if (this.confirmDialogState) {
4541
+ this.elConfirmDialogTitle.textContent = this.confirmDialogState.title;
4542
+ this.elConfirmDialogText.textContent = this.confirmDialogState.text;
4543
+ this.elConfirmDialogOk.textContent = this.confirmDialogState.confirm;
4544
+ }
3980
4545
  this.elDeleteDialog.hidden = this.deleteDialogState === null;
3981
4546
  if (this.deleteDialogState) {
3982
4547
  this.elDeleteDialogText.textContent =
@@ -4024,6 +4589,9 @@ export class MdzipWorkspaceView {
4024
4589
  if (this.widthMenuOpen) {
4025
4590
  this.closeWidthMenu(true);
4026
4591
  }
4592
+ if (this.confirmDialogState) {
4593
+ this.answerConfirm(false);
4594
+ }
4027
4595
  if (this.contextMenuState || this.deleteDialogState || this.nameDialogState) {
4028
4596
  this.contextMenuState = null;
4029
4597
  this.deleteDialogState = null;
@@ -4106,7 +4674,74 @@ export class MdzipWorkspaceView {
4106
4674
  }
4107
4675
  });
4108
4676
  this.elSearchBtn.addEventListener('click', () => {
4109
- void this.openSearch();
4677
+ if (this.findOpen) {
4678
+ this.closeFind();
4679
+ }
4680
+ else {
4681
+ void this.openSearch();
4682
+ }
4683
+ });
4684
+ this.elFindInput.addEventListener('input', () => {
4685
+ this.refreshFind('viewport');
4686
+ this.revealFindMatchSoon();
4687
+ });
4688
+ this.elFindInput.addEventListener('keydown', (event) => {
4689
+ if (event.key === 'Enter') {
4690
+ event.preventDefault();
4691
+ void this.moveFind(event.shiftKey ? -1 : 1);
4692
+ }
4693
+ else if (event.key === 'Escape') {
4694
+ event.preventDefault();
4695
+ event.stopPropagation();
4696
+ this.closeFind();
4697
+ }
4698
+ });
4699
+ this.elFindCase.addEventListener('click', () => {
4700
+ this.findMatchCase = !this.findMatchCase;
4701
+ this.elFindCase.setAttribute('aria-pressed', String(this.findMatchCase));
4702
+ this.refreshFind('viewport');
4703
+ this.revealFindMatchSoon();
4704
+ this.elFindInput.focus();
4705
+ });
4706
+ this.elFindPrevious.addEventListener('click', () => { void this.moveFind(-1); });
4707
+ this.elFindNext.addEventListener('click', () => { void this.moveFind(1); });
4708
+ this.elFindClose.addEventListener('click', () => { this.closeFind(); });
4709
+ // Ctrl/Cmd+F in the View layout opens the find bar instead of the
4710
+ // browser's, which can't see chunks not drawn yet; F3 / Shift+F3 move
4711
+ // and Escape closes while it's open.
4712
+ doc.addEventListener('keydown', (e) => {
4713
+ if (this.destroyed) {
4714
+ return;
4715
+ }
4716
+ const focused = doc.activeElement;
4717
+ const inView = !!focused && this.elRoot.contains(focused);
4718
+ const key = e.key.toLowerCase();
4719
+ if (key === 'f' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
4720
+ if (inView && this.findApplies()) {
4721
+ e.preventDefault();
4722
+ this.openFind();
4723
+ }
4724
+ }
4725
+ else if (e.key === 'F3' && this.findOpen && inView) {
4726
+ e.preventDefault();
4727
+ void this.moveFind(e.shiftKey ? -1 : 1);
4728
+ }
4729
+ else if (e.key === 'Escape' && this.findOpen && !!focused && this.elPreviewPane.contains(focused)) {
4730
+ e.preventDefault();
4731
+ this.closeFind();
4732
+ }
4733
+ });
4734
+ this.elOutlineBtn.addEventListener('click', () => {
4735
+ this.setOutlineVisible(!this.outlineVisible);
4736
+ this.options.onOutlineVisibilityChanged?.(this.outlineVisible);
4737
+ });
4738
+ this.elFormatJsonBtn.addEventListener('click', () => {
4739
+ this.formatJson();
4740
+ this.cmEditor?.focus();
4741
+ });
4742
+ this.elWhitespaceBtn.addEventListener('click', () => {
4743
+ this.setWhitespaceVisible(!this.whitespaceVisible);
4744
+ this.options.onWhitespaceVisibilityChanged?.(this.whitespaceVisible);
4110
4745
  });
4111
4746
  this.elZoomBtn.addEventListener('click', (e) => {
4112
4747
  if (!this.controlPolicy.zoom) {
@@ -4232,21 +4867,85 @@ export class MdzipWorkspaceView {
4232
4867
  this.showNavMenuForPath(orphanBtn.getAttribute('data-orphan-path'), e);
4233
4868
  return;
4234
4869
  }
4870
+ const key = navRowKey(target);
4871
+ if (key && (e.ctrlKey || e.metaKey || e.shiftKey)) {
4872
+ // Selecting, not opening (or, on a folder, not opening or closing it).
4873
+ e.preventDefault();
4874
+ if (e.shiftKey) {
4875
+ this.selectNavRange(key, e.ctrlKey || e.metaKey);
4876
+ }
4877
+ else {
4878
+ this.navSelection = this.navSelection.includes(key)
4879
+ ? this.navSelection.filter((item) => item !== key)
4880
+ : [...this.navSelection, key];
4881
+ this.navSelectionAnchor = key;
4882
+ }
4883
+ this.syncNavSelection();
4884
+ return;
4885
+ }
4886
+ if (key) {
4887
+ this.navSelection = [key];
4888
+ this.navSelectionAnchor = key;
4889
+ this.syncNavSelection();
4890
+ }
4235
4891
  const navFile = target.closest('[data-nav-path]');
4236
4892
  if (navFile) {
4237
4893
  void this.openPath(navFile.getAttribute('data-nav-path'));
4238
4894
  }
4239
4895
  });
4896
+ // Remember closed folders: the tree is redrawn on every change.
4897
+ this.elNavTree.addEventListener('toggle', (e) => {
4898
+ const details = e.target;
4899
+ if (!(details instanceof HTMLElement) || !details.matches('details[data-nav-dir]')) {
4900
+ return;
4901
+ }
4902
+ const path = details.getAttribute('data-nav-dir') ?? '';
4903
+ if (details.open) {
4904
+ this.navCollapsed.delete(path);
4905
+ }
4906
+ else {
4907
+ this.navCollapsed.add(path);
4908
+ }
4909
+ }, true);
4240
4910
  this.elNavPane.addEventListener('contextmenu', (e) => {
4241
- const target = this.navMenuTargetFromElement(e.target);
4911
+ let target = this.navMenuTargetFromElement(e.target);
4242
4912
  if (!target) {
4243
4913
  return;
4244
4914
  }
4245
4915
  e.preventDefault();
4246
4916
  e.stopPropagation();
4917
+ // Right-clicking a row outside the selection selects just that row, as
4918
+ // file managers do; inside a selection of several, the menu is for all.
4919
+ const key = navRowKey(e.target);
4920
+ if (key && !this.navSelection.includes(key)) {
4921
+ this.navSelection = [key];
4922
+ this.navSelectionAnchor = key;
4923
+ this.syncNavSelection();
4924
+ }
4925
+ else if (key && this.navSelection.length > 1) {
4926
+ target = {
4927
+ kind: 'selection',
4928
+ files: this.navSelection.filter((item) => item.startsWith('f:')).map((item) => item.slice(2)),
4929
+ folders: this.navSelection.filter((item) => item.startsWith('d:')).map((item) => item.slice(2))
4930
+ };
4931
+ }
4247
4932
  this.showNavMenu(target, e);
4248
4933
  });
4249
4934
  this.elNavTree.addEventListener('keydown', (e) => {
4935
+ if (e.key.toLowerCase() === 'a' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
4936
+ e.preventDefault();
4937
+ this.navSelection = this.navRowKeys();
4938
+ this.navSelectionAnchor = this.navSelection[0] ?? null;
4939
+ this.syncNavSelection();
4940
+ return;
4941
+ }
4942
+ if (e.key === 'Escape' && this.navSelection.length > 1) {
4943
+ e.preventDefault();
4944
+ this.navSelection = [];
4945
+ this.navSelectionAnchor = null;
4946
+ this.syncNavSelection();
4947
+ return;
4948
+ }
4250
4949
  if (e.key === 'Enter') {
4251
4950
  const orphanBtn = e.target.closest('[data-orphan-path]');
4252
4951
  if (this.controlPolicy.orphanActions && orphanBtn) {
@@ -4277,6 +4976,35 @@ export class MdzipWorkspaceView {
4277
4976
  window.addEventListener('pointermove', onMove);
4278
4977
  window.addEventListener('pointerup', onUp, { once: true });
4279
4978
  });
4979
+ // The outline's edge: it's on the document side of the panel, so dragging
4980
+ // toward the document widens it on either side.
4981
+ this.elOutlineResizer.addEventListener('pointerdown', (e) => {
4982
+ if (e.button !== 0) {
4983
+ return;
4984
+ }
4985
+ e.preventDefault();
4986
+ this.resizing = true;
4987
+ this.elRoot.classList.add('resizing');
4988
+ const start = this.outlineWidth;
4989
+ const onMove = (me) => {
4990
+ const shell = this.elWorkspaceShell.getBoundingClientRect();
4991
+ const pane = this.elOutlinePane.getBoundingClientRect();
4992
+ const raw = this.outlinePosition === 'left' ? me.clientX - pane.left : pane.right - me.clientX;
4993
+ const max = Math.max(200, Math.floor(shell.width * 0.5));
4994
+ this.outlineWidth = Math.max(160, Math.min(max, Math.round(raw)));
4995
+ this.syncOutlineGeometry();
4996
+ };
4997
+ const onUp = () => {
4998
+ this.resizing = false;
4999
+ this.elRoot.classList.remove('resizing');
5000
+ window.removeEventListener('pointermove', onMove);
5001
+ if (this.outlineWidth !== null && this.outlineWidth !== start) {
5002
+ this.options.onOutlineWidthChanged?.(this.outlineWidth);
5003
+ }
5004
+ };
5005
+ window.addEventListener('pointermove', onMove);
5006
+ window.addEventListener('pointerup', onUp, { once: true });
5007
+ });
4280
5008
  this.elSplitResizer.addEventListener('pointerdown', (e) => {
4281
5009
  if (e.button !== 0 || this.layout !== 'split') {
4282
5010
  return;
@@ -4547,6 +5275,9 @@ export class MdzipWorkspaceView {
4547
5275
  this.elNameConfirmBtn.addEventListener('click', () => {
4548
5276
  void this.confirmNameDialog();
4549
5277
  });
5278
+ this.elConfirmDialog.querySelector('[data-action="cancel-confirm"]')
5279
+ .addEventListener('click', () => this.answerConfirm(false));
5280
+ this.elConfirmDialogOk.addEventListener('click', () => this.answerConfirm(true));
4550
5281
  this.elDeleteDialog.querySelector('[data-action="cancel-delete"]')
4551
5282
  .addEventListener('click', () => {
4552
5283
  this.deleteDialogState = null;
@@ -4717,8 +5448,11 @@ export class MdzipWorkspaceView {
4717
5448
  * anchor (`''` and `'top'` scroll to the top and resolve `true`), and
4718
5449
  * `false` when nothing matches, an entry renderer owns the pane, or the
4719
5450
  * view is destroyed first.
5451
+ *
5452
+ * `{ smooth: true }` glides there instead of jumping, as an outline click
5453
+ * does; it jumps anyway when the user asked for reduced motion.
4720
5454
  */
4721
- async scrollToAnchor(anchor) {
5455
+ async scrollToAnchor(anchor, options = {}) {
4722
5456
  const fragment = anchor.startsWith('#') ? anchor.slice(1) : anchor;
4723
5457
  // onPreviewRendered runs inside the first chunk batch's completion,
4724
5458
  // before the lazy-continuation sentinel is armed — same race as
@@ -4739,15 +5473,142 @@ export class MdzipWorkspaceView {
4739
5473
  return false;
4740
5474
  }
4741
5475
  if (generation !== this.previewGeneration) {
4742
- return this.scrollToAnchor(anchor);
5476
+ return this.scrollToAnchor(anchor, options);
4743
5477
  }
4744
5478
  }
4745
5479
  if (this.entryState) {
4746
5480
  return false;
4747
5481
  }
4748
- const found = await this.scrollPreviewToAnchor(fragment);
5482
+ const found = await this.scrollPreviewToAnchor(fragment, options.smooth === true && !this.prefersReducedMotion());
4749
5483
  return found || !fragment || fragment.toLowerCase() === 'top';
4750
5484
  }
5485
+ /** Whether the outline panel is switched on (it shows while a Markdown preview is visible). */
5486
+ get isOutlineVisible() {
5487
+ return this.outlineVisible;
5488
+ }
5489
+ /** Whether spaces and tabs are shown in the source editor. */
5490
+ get isWhitespaceVisible() {
5491
+ return this.whitespaceVisible;
5492
+ }
5493
+ /** Shows or hides spaces and tabs in the source editor, as the ¶ toolbar button does (without calling `onWhitespaceVisibilityChanged`). */
5494
+ setWhitespaceVisible(visible) {
5495
+ if (this.whitespaceVisible === visible) {
5496
+ return;
5497
+ }
5498
+ this.whitespaceVisible = visible;
5499
+ this.cmEditor?.dispatch({
5500
+ effects: this.whitespaceCompartment.reconfigure(visible ? highlightWhitespace() : [])
5501
+ });
5502
+ this.render();
5503
+ }
5504
+ /** Shows or hides the outline panel, as its toolbar button does (without calling `onOutlineVisibilityChanged`). */
5505
+ setOutlineVisible(visible) {
5506
+ if (this.outlineVisible === visible) {
5507
+ return;
5508
+ }
5509
+ this.outlineVisible = visible;
5510
+ this.render();
5511
+ }
5512
+ /** Which side of the document the outline panel is on. */
5513
+ get outlineSide() {
5514
+ return this.outlinePosition;
5515
+ }
5516
+ /** Puts the outline panel on the left or the right of the document. */
5517
+ setOutlinePosition(position) {
5518
+ this.outlinePosition = position === 'left' ? 'left' : 'right';
5519
+ this.syncOutlineGeometry();
5520
+ }
5521
+ /** The outline panel's width in pixels, as last set or dragged; null while the style sheet's width applies. */
5522
+ get outlinePaneWidth() {
5523
+ return this.outlineWidth;
5524
+ }
5525
+ syncOutlineGeometry() {
5526
+ this.elRoot.classList.toggle('outline-left', this.outlinePosition === 'left');
5527
+ if (this.outlineWidth === null) {
5528
+ this.elRoot.style.removeProperty('--mdzip-outline-pane-width');
5529
+ }
5530
+ else {
5531
+ this.elRoot.style.setProperty('--mdzip-outline-pane-width', `${this.outlineWidth}px`);
5532
+ }
5533
+ }
5534
+ syncOutlinePane(show) {
5535
+ this.elRoot.classList.toggle('outline-pane-visible', show);
5536
+ this.syncOutlineGeometry();
5537
+ if (!show) {
5538
+ this.elOutlinePane.hidden = true;
5539
+ this.outline?.destroy();
5540
+ this.outline = null;
5541
+ return;
5542
+ }
5543
+ if (!this.outline) {
5544
+ // The outline hides its container while the document has no headings.
5545
+ this.outline = createMdzipHeadingOutline({
5546
+ content: this.elPreviewContent,
5547
+ container: this.elOutlinePane,
5548
+ scrollContainer: this.elPreviewPane,
5549
+ label: this.outlineOptions.label ?? 'Outline',
5550
+ collapse: this.outlineOptions.collapse,
5551
+ offset: 64,
5552
+ headings: () => this.outlineHeadings(),
5553
+ findElement: (heading) => this.findOutlineElement(heading),
5554
+ onNavigate: (heading, event) => {
5555
+ event.preventDefault();
5556
+ void this.scrollToAnchor(heading.id, { smooth: true });
5557
+ }
5558
+ });
5559
+ this.outlineGeneration = this.previewMountedGeneration;
5560
+ }
5561
+ else if (this.outlineGeneration !== this.previewMountedGeneration) {
5562
+ this.refreshOutline();
5563
+ }
5564
+ }
5565
+ /** Rebuilds the outline after the preview renders a new version of the document. */
5566
+ refreshOutline() {
5567
+ if (!this.outline) {
5568
+ return;
5569
+ }
5570
+ this.outlineGeneration = this.previewMountedGeneration;
5571
+ this.outline.refresh();
5572
+ }
5573
+ /**
5574
+ * The document's headings for the outline, ids without the
5575
+ * `user-content-` prefix. Under progressive rendering they come from the
5576
+ * chunks' tokens, so headings in chunks that aren't mounted yet are listed
5577
+ * too (without an element until they mount).
5578
+ */
5579
+ outlineHeadings() {
5580
+ if (this.entryState) {
5581
+ return [];
5582
+ }
5583
+ const levels = new Set(this.outlineOptions.levels ?? [1, 2, 3]);
5584
+ const state = this.chunkedRenderState;
5585
+ if (state && state.generation === this.previewGeneration) {
5586
+ return state.records
5587
+ .flatMap((record) => collectMdzipHeadings(record.tokens))
5588
+ .filter((heading) => levels.has(heading.level))
5589
+ .map((heading) => ({ ...heading, element: null }));
5590
+ }
5591
+ const headings = [];
5592
+ for (const element of Array.from(this.elPreviewContent.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]'))) {
5593
+ const level = Number(element.tagName[1]);
5594
+ // Only the document's own headings: not the footnotes section's label, say.
5595
+ if (!levels.has(level) || !element.id.startsWith(MDZIP_HEADING_ID_PREFIX))
5596
+ continue;
5597
+ const text = (element.textContent ?? '').replace(/\s+/g, ' ').trim();
5598
+ if (text) {
5599
+ headings.push({ id: element.id.slice(MDZIP_HEADING_ID_PREFIX.length), text, level, element });
5600
+ }
5601
+ }
5602
+ return headings;
5603
+ }
5604
+ findOutlineElement(heading) {
5605
+ const id = MDZIP_HEADING_ID_PREFIX + heading.id;
5606
+ for (const element of Array.from(this.elPreviewContent.querySelectorAll('h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]'))) {
5607
+ if (element.id === id)
5608
+ return element;
5609
+ }
5610
+ return null;
5611
+ }
4751
5612
  /**
4752
5613
  * The anchors {@link scrollToAnchor} can reach in the current preview, in
4753
5614
  * document order: every heading id (without the `user-content-` prefix),
@@ -4845,7 +5706,15 @@ export class MdzipWorkspaceView {
4845
5706
  * a chunk that hasn't been mounted yet, so this mounts everything up to and
4846
5707
  * including that chunk first. Returns whether an anchor was found.
4847
5708
  */
4848
- async scrollPreviewToAnchor(rawFragment) {
5709
+ prefersReducedMotion() {
5710
+ try {
5711
+ return this.elRoot.ownerDocument.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
5712
+ }
5713
+ catch {
5714
+ return false;
5715
+ }
5716
+ }
5717
+ async scrollPreviewToAnchor(rawFragment, smooth = false) {
4849
5718
  let fragment = rawFragment;
4850
5719
  try {
4851
5720
  fragment = decodeURIComponent(rawFragment);
@@ -4871,17 +5740,76 @@ export class MdzipWorkspaceView {
4871
5740
  if (!target) {
4872
5741
  // `#` and `#top` mean the top of the document, as in a browser.
4873
5742
  if (!fragment || fragment.toLowerCase() === 'top') {
4874
- pane.scrollTop = 0;
5743
+ this.releaseAnchorPin();
5744
+ if (smooth) {
5745
+ this.glidePreviewTo(() => 0);
5746
+ }
5747
+ else {
5748
+ pane.scrollTop = 0;
5749
+ }
4875
5750
  }
4876
5751
  return false;
4877
5752
  }
4878
- this.scrollPaneToElement(target);
5753
+ // Pin first: pinning releases any earlier pin, and with it a glide.
4879
5754
  this.pinPreviewAnchor(target);
5755
+ if (smooth) {
5756
+ this.glidePreviewTo(() => this.paneTopOf(target));
5757
+ }
5758
+ else {
5759
+ this.scrollPaneToElement(target);
5760
+ }
4880
5761
  return true;
4881
5762
  }
5763
+ paneTopOf(target) {
5764
+ const pane = this.elPreviewPane;
5765
+ return pane.scrollTop + target.getBoundingClientRect().top - pane.getBoundingClientRect().top;
5766
+ }
4882
5767
  scrollPaneToElement(target) {
5768
+ this.elPreviewPane.scrollTop = this.paneTopOf(target);
5769
+ this.syncScrollFromPreview(true);
5770
+ }
5771
+ /**
5772
+ * Scrolls the preview to `targetTop()` over a few hundred milliseconds.
5773
+ * The target is measured again every frame, so images loading above it
5774
+ * while it moves bend the path instead of restarting it (the browser's
5775
+ * own smooth scroll restarts on every change and stutters). A wheel,
5776
+ * touch or click in the pane stops it, as it releases the anchor pin.
5777
+ */
5778
+ glidePreviewTo(targetTop) {
5779
+ this.cancelPreviewGlide();
4883
5780
  const pane = this.elPreviewPane;
4884
- pane.scrollTop += target.getBoundingClientRect().top - pane.getBoundingClientRect().top;
5781
+ const start = pane.scrollTop;
5782
+ const distance = Math.abs(targetTop() - start);
5783
+ if (distance < 2) {
5784
+ pane.scrollTop = targetTop();
5785
+ this.syncScrollFromPreview(true);
5786
+ return;
5787
+ }
5788
+ // Longer for longer trips, within limits that still feel quick.
5789
+ const duration = Math.min(700, 250 + distance * 0.12);
5790
+ const startTime = performance.now();
5791
+ // performance.now(), not the frame's timestamp: the two can count from
5792
+ // different origins (another window's requestAnimationFrame, jsdom).
5793
+ const step = () => {
5794
+ const now = performance.now();
5795
+ if (this.destroyed) {
5796
+ this.previewGlide = null;
5797
+ return;
5798
+ }
5799
+ const t = Math.min(1, Math.max(0, (now - startTime) / duration));
5800
+ const eased = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
5801
+ pane.scrollTop = start + (targetTop() - start) * eased;
5802
+ // In Split, the source follows along.
5803
+ this.syncScrollFromPreview(true);
5804
+ this.previewGlide = t < 1 ? requestAnimationFrame(step) : null;
5805
+ };
5806
+ this.previewGlide = requestAnimationFrame(step);
5807
+ }
5808
+ cancelPreviewGlide() {
5809
+ if (this.previewGlide !== null) {
5810
+ cancelAnimationFrame(this.previewGlide);
5811
+ this.previewGlide = null;
5812
+ }
4885
5813
  }
4886
5814
  /** See `anchorPin`. */
4887
5815
  pinPreviewAnchor(target) {
@@ -4895,12 +5823,16 @@ export class MdzipWorkspaceView {
4895
5823
  this.releaseAnchorPin();
4896
5824
  return;
4897
5825
  }
4898
- this.scrollPaneToElement(target);
5826
+ if (this.previewGlide === null) {
5827
+ // While gliding, each frame measures the target again anyway.
5828
+ this.scrollPaneToElement(target);
5829
+ }
4899
5830
  });
4900
5831
  observer.observe(this.elPreviewContent);
4901
5832
  this.anchorPin = observer;
4902
5833
  }
4903
5834
  releaseAnchorPin() {
5835
+ this.cancelPreviewGlide();
4904
5836
  this.anchorPin?.disconnect();
4905
5837
  this.anchorPin = null;
4906
5838
  }
@@ -5084,9 +6016,160 @@ export class MdzipWorkspaceView {
5084
6016
  this.render();
5085
6017
  }
5086
6018
  catch (error) {
6019
+ if (error instanceof MdzipManifestInvalidError) {
6020
+ await this.showManifestProblems(error.validity);
6021
+ }
5087
6022
  this.options.onFailed?.(error);
5088
6023
  }
5089
6024
  }
6025
+ // Saving is blocked by an invalid manifest: show it, with its problems,
6026
+ // wherever the user is, so they can see what to fix.
6027
+ async showManifestProblems(validity) {
6028
+ const snapshot = this.workspace?.snapshot();
6029
+ if (snapshot && !isMdzipRootManifestPath(snapshot.currentPath)) {
6030
+ await this.openPath('manifest.json');
6031
+ }
6032
+ this.setJsonValidity(validity, 'manifest.json');
6033
+ if (this.layout !== 'source' && this.manifestForm) {
6034
+ // The form shows each problem under its field.
6035
+ this.manifestForm.flash();
6036
+ return;
6037
+ }
6038
+ this.elJsonStatus.classList.remove('flash');
6039
+ void this.elJsonStatus.offsetWidth;
6040
+ this.elJsonStatus.classList.add('flash');
6041
+ }
6042
+ /**
6043
+ * Re-indents the open JSON file (2 spaces), changing only whitespace, as
6044
+ * the toolbar's Format JSON button and Shift+Alt+F do. One undo step.
6045
+ * Returns `false` when no JSON file is open in an editable editor or its
6046
+ * text isn't valid JSON.
6047
+ */
6048
+ formatJson() {
6049
+ const editor = this.cmEditor;
6050
+ const snapshot = this.workspace?.snapshot();
6051
+ if (!editor || !snapshot || snapshot.mode === 'read-only' || !isMdzipJsonPath(snapshot.currentPath)) {
6052
+ return false;
6053
+ }
6054
+ const text = editor.state.doc.toString();
6055
+ const formatted = formatMdzipJsonText(text);
6056
+ if (formatted === null) {
6057
+ return false;
6058
+ }
6059
+ if (formatted !== text) {
6060
+ // Replace only what differs, so the cursor keeps its place where it can.
6061
+ let start = 0;
6062
+ while (start < text.length && start < formatted.length && text[start] === formatted[start])
6063
+ start += 1;
6064
+ let end = 0;
6065
+ while (end < text.length - start && end < formatted.length - start
6066
+ && text[text.length - 1 - end] === formatted[formatted.length - 1 - end])
6067
+ end += 1;
6068
+ editor.dispatch({
6069
+ changes: { from: start, to: text.length - end, insert: formatted.slice(start, formatted.length - end) },
6070
+ userEvent: 'input.format',
6071
+ scrollIntoView: true
6072
+ });
6073
+ }
6074
+ return true;
6075
+ }
6076
+ /**
6077
+ * The problems of the edited `manifest.json` that block saving, or `null`
6078
+ * when the archive can be saved.
6079
+ */
6080
+ getManifestValidity() {
6081
+ return this.workspace?.manifestValidity() ?? null;
6082
+ }
6083
+ // JSON files get JSON highlighting and live validation; everything else
6084
+ // keeps the Markdown language, as before.
6085
+ syncEditorLanguage(snapshot) {
6086
+ const isJson = (snapshot.currentPathType === 'text' || snapshot.currentPathType === 'markdown')
6087
+ && isMdzipJsonPath(snapshot.currentPath);
6088
+ const language = isJson ? 'json' : 'markdown';
6089
+ if (language !== this.cmLanguage && this.cmEditor) {
6090
+ this.cmLanguage = language;
6091
+ this.cmEditor.dispatch({
6092
+ effects: this.languageCompartment.reconfigure(isJson
6093
+ // No spellcheck in JSON: keys like "someNewProp" aren't words.
6094
+ ? [
6095
+ json(),
6096
+ syntaxHighlighting(mdzipJsonHighlight),
6097
+ this.jsonLinter(),
6098
+ bracketMatching(),
6099
+ closeBrackets(),
6100
+ foldGutter(),
6101
+ Prec.high(keymap.of([
6102
+ ...closeBracketsKeymap,
6103
+ ...foldKeymap,
6104
+ { key: 'Shift-Alt-f', run: () => this.formatJson() }
6105
+ ])),
6106
+ Prec.highest(EditorView.contentAttributes.of({ spellcheck: 'false' }))
6107
+ ]
6108
+ : markdown())
6109
+ });
6110
+ }
6111
+ if (!isJson) {
6112
+ this.setJsonValidity(null, null);
6113
+ }
6114
+ else if (this.jsonValidityPath !== snapshot.currentPath && this.workspace) {
6115
+ this.setJsonValidity(this.workspace.validateJsonText(snapshot.currentPath, snapshot.currentText), snapshot.currentPath);
6116
+ }
6117
+ }
6118
+ jsonLinter() {
6119
+ return linter((view) => {
6120
+ const workspace = this.workspace;
6121
+ if (!workspace) {
6122
+ return [];
6123
+ }
6124
+ const path = workspace.snapshot().currentPath;
6125
+ const validity = workspace.validateJsonText(path, view.state.doc.toString());
6126
+ this.setJsonValidity(validity, path);
6127
+ const length = view.state.doc.length;
6128
+ return validity.problems.map((problem) => {
6129
+ const from = Math.min(problem.from, length);
6130
+ return {
6131
+ from,
6132
+ to: Math.max(from, Math.min(problem.to, length)),
6133
+ severity: problem.severity,
6134
+ message: problem.message
6135
+ };
6136
+ });
6137
+ }, { delay: 300 });
6138
+ }
6139
+ setJsonValidity(validity, path) {
6140
+ const changed = this.jsonValidityPath !== path
6141
+ || JSON.stringify(this.jsonValidity?.problems ?? null) !== JSON.stringify(validity?.problems ?? null);
6142
+ this.jsonValidity = validity;
6143
+ this.jsonValidityPath = path;
6144
+ const status = this.elJsonStatus;
6145
+ status.hidden = validity === null || this.options.jsonStatus === false;
6146
+ // Format needs valid JSON; a manifest error that isn't about syntax is fine.
6147
+ this.elFormatJsonBtn.disabled = validity !== null && validity.value === undefined;
6148
+ this.elFormatJsonBtn.title = this.elFormatJsonBtn.disabled
6149
+ ? 'Format JSON: fix the syntax error first'
6150
+ : 'Format JSON (Shift+Alt+F)';
6151
+ if (validity) {
6152
+ status.dataset.status = validity.status;
6153
+ status.textContent = validity.canSave
6154
+ ? describeMdzipJsonValidity(validity)
6155
+ : `${describeMdzipJsonValidity(validity)} Saving is blocked until it's fixed.`;
6156
+ const custom = validity.customFields.length
6157
+ ? `Custom fields, kept as they are: ${validity.customFields.join(', ')}.`
6158
+ : '';
6159
+ status.title = [
6160
+ ...validity.problems.map((problem) => `${problem.severity}: ${problem.message}`),
6161
+ custom
6162
+ ].filter(Boolean).join('\n');
6163
+ }
6164
+ else {
6165
+ delete status.dataset.status;
6166
+ status.textContent = '';
6167
+ status.title = '';
6168
+ }
6169
+ if (changed) {
6170
+ this.options.onJsonValidityChanged?.(validity, path);
6171
+ }
6172
+ }
5090
6173
  downloadSavedBlob(blob, fileName) {
5091
6174
  const doc = this.elRoot.ownerDocument;
5092
6175
  const urlApi = doc.defaultView?.URL;
@@ -6022,6 +7105,9 @@ export class MdzipWorkspaceView {
6022
7105
  card.replaceWith(image);
6023
7106
  }
6024
7107
  const text = previewPlainText(container);
7108
+ for (const element of Array.from(container.querySelectorAll(`[${MDZIP_BLOCK_ATTRIBUTE}]`))) {
7109
+ element.removeAttribute(MDZIP_BLOCK_ATTRIBUTE);
7110
+ }
6025
7111
  for (const element of Array.from(container.querySelectorAll(PREVIEW_CHROME_REMOVE_SELECTOR))) {
6026
7112
  element.remove();
6027
7113
  }
@@ -6336,7 +7422,8 @@ export class MdzipWorkspaceView {
6336
7422
  chunkHtml = cacheHit;
6337
7423
  }
6338
7424
  else {
6339
- const result = this.renderingService.renderChunk(chunks[chunkIndex], context);
7425
+ // Marked like the preview's chunks: the two share chunkHtmlCache.
7426
+ const result = this.renderingService.renderChunk(chunks[chunkIndex], context, { index: chunkIndex, markBlocks: true });
6340
7427
  chunkHtml = typeof result === 'string' ? result : await result;
6341
7428
  // Only populate the shared cache if this generation is *still*
6342
7429
  // the live one at the moment this (possibly async) render
@@ -6372,7 +7459,8 @@ export class MdzipWorkspaceView {
6372
7459
  setTimeout(resolve, 0);
6373
7460
  });
6374
7461
  }
6375
- return html;
7462
+ // The split view's block marks are for this page only.
7463
+ return stripMdzipBlockMarks(html);
6376
7464
  }
6377
7465
  /**
6378
7466
  * Like `copyAllPreviewContent`, but writes a rich `text/html` clipboard
@@ -6756,6 +7844,12 @@ export class MdzipWorkspaceView {
6756
7844
  link: formatting.link,
6757
7845
  image: formatting.image
6758
7846
  };
7847
+ // Formatting only applies to Markdown; the whitespace toggle to any text the editor shows.
7848
+ for (const key of Object.keys(visibility)) {
7849
+ visibility[key] = visibility[key] && this.formattingShown;
7850
+ }
7851
+ visibility['whitespace'] = this.whitespaceControlShown;
7852
+ visibility['formatJson'] = this.formatJsonShown;
6759
7853
  this.elEditToolbar.querySelectorAll('[data-format-control]').forEach((element) => {
6760
7854
  element.hidden = !visibility[element.dataset['formatControl'] ?? ''];
6761
7855
  });
@@ -7179,20 +8273,26 @@ export class MdzipWorkspaceView {
7179
8273
  // Items for the nav context menu; null entries render as separators.
7180
8274
  navMenuItems(target, snapshot) {
7181
8275
  const canMutate = this.allowFileActions(snapshot);
8276
+ if (target.kind === 'selection') {
8277
+ return this.extractMenuItems('many', false);
8278
+ }
7182
8279
  if (target.kind === 'directory') {
8280
+ const hasFiles = this.collectExtractPaths({ files: [], folders: [target.path] }, snapshot).length > 0;
8281
+ const extract = hasFiles ? this.extractMenuItems('many', target.path === '') : [];
7183
8282
  if (!canMutate) {
7184
- return [];
8283
+ return extract;
7185
8284
  }
7186
8285
  return [
7187
8286
  { action: 'new-file', label: 'New .md File' },
7188
8287
  { action: 'new-folder', label: 'New Folder' },
7189
8288
  null,
7190
- { action: 'add-files', label: 'Add Files…' }
8289
+ { action: 'add-files', label: 'Add Files…' },
8290
+ ...(extract.length ? [null, ...extract] : [])
7191
8291
  ];
7192
8292
  }
7193
8293
  const hostItems = this.fileActionItems(target);
7194
8294
  if (target.isManifest) {
7195
- return [...hostItems, ...(hostItems.length ? [null] : []), { action: 'download', label: 'Download' }];
8295
+ return [...hostItems, ...(hostItems.length ? [null] : []), ...this.extractMenuItems('one', false)];
7196
8296
  }
7197
8297
  const groups = [];
7198
8298
  if (canMutate) {
@@ -7227,7 +8327,7 @@ export class MdzipWorkspaceView {
7227
8327
  if (hostItems.length > 0) {
7228
8328
  groups.push(hostItems);
7229
8329
  }
7230
- groups.push([{ action: 'download', label: 'Download' }]);
8330
+ groups.push(this.extractMenuItems('one', false));
7231
8331
  if (canMutate && !target.isEntryPoint) {
7232
8332
  groups.push([{
7233
8333
  action: 'delete',
@@ -7236,6 +8336,26 @@ export class MdzipWorkspaceView {
7236
8336
  }
7237
8337
  return groups.flatMap((group, index) => index === 0 ? group : [null, ...group]);
7238
8338
  }
8339
+ /**
8340
+ * Taking files out of the archive: **Extract…** where the host writes
8341
+ * them (`onExtractFiles`), else **Download** for one file, and for several
8342
+ * **Download as ZIP** plus **Extract to Folder…** where the browser can
8343
+ * write to a folder.
8344
+ */
8345
+ extractMenuItems(count, all) {
8346
+ if (this.options.onExtractFiles) {
8347
+ return [{ action: 'extract', label: all ? 'Extract All…' : 'Extract…' }];
8348
+ }
8349
+ if (count === 'one') {
8350
+ return [{ action: 'download', label: 'Download' }];
8351
+ }
8352
+ const items = [{ action: 'download-zip', label: all ? 'Download All as ZIP' : 'Download as ZIP' }];
8353
+ const win = this.elRoot.ownerDocument.defaultView;
8354
+ if (typeof win?.showDirectoryPicker === 'function') {
8355
+ items.push({ action: 'extract-folder', label: all ? 'Extract All to Folder…' : 'Extract to Folder…' });
8356
+ }
8357
+ return items;
8358
+ }
7239
8359
  /** Menu items for the host's {@link MdzipFileAction}s that apply to this file. */
7240
8360
  fileActionItems(target) {
7241
8361
  const file = fileActionTarget(target);
@@ -7311,6 +8431,11 @@ export class MdzipWorkspaceView {
7311
8431
  await this.downloadArchiveFile(target.path);
7312
8432
  }
7313
8433
  break;
8434
+ case 'extract':
8435
+ case 'download-zip':
8436
+ case 'extract-folder':
8437
+ await this.extractNavTarget(target, action);
8438
+ break;
7314
8439
  case 'duplicate':
7315
8440
  if (target.kind === 'file') {
7316
8441
  await this.duplicateFile(target.path);
@@ -7519,6 +8644,189 @@ export class MdzipWorkspaceView {
7519
8644
  const fileName = path.slice(path.lastIndexOf('/') + 1);
7520
8645
  this.downloadSavedBlob(new Blob([buffer]), fileName);
7521
8646
  }
8647
+ /**
8648
+ * The files of the archive as `{ path, bytes }`, for a host or a test to
8649
+ * write elsewhere (#69). Each path names a file, or a folder (with or
8650
+ * without a trailing `/`; `''` is the whole archive) whose files are all
8651
+ * included when `includeFolders` isn't false. `manifest.json` comes only
8652
+ * when named. In archive order, each file once; paths that match nothing
8653
+ * are skipped. Bytes are the file's current content, as Download gives.
8654
+ */
8655
+ async extractFiles(paths, options = {}) {
8656
+ const snapshot = this.workspace?.snapshot();
8657
+ if (!snapshot) {
8658
+ return [];
8659
+ }
8660
+ const files = [];
8661
+ const folders = [];
8662
+ for (const path of paths) {
8663
+ if (snapshot.content.paths.some((entry) => samePath(entry.path, path))) {
8664
+ files.push(path);
8665
+ }
8666
+ else if (options.includeFolders !== false) {
8667
+ folders.push(path.replace(/\/+$/, ''));
8668
+ }
8669
+ }
8670
+ return this.readExtractFiles(this.collectExtractPaths({ files, folders }, snapshot));
8671
+ }
8672
+ // The archive paths a selection covers, in archive order.
8673
+ collectExtractPaths(selection, snapshot) {
8674
+ return snapshot.content.paths
8675
+ .map((entry) => entry.path)
8676
+ .filter((path) => selection.files.some((file) => samePath(file, path))
8677
+ || (!isMdzipManifestPath(path) && selection.folders.some((folder) => folder === '' || path.startsWith(`${folder}/`))));
8678
+ }
8679
+ async readExtractFiles(paths) {
8680
+ const workspace = this.workspace;
8681
+ const files = [];
8682
+ for (const path of paths) {
8683
+ const bytes = await workspace?.readPathBytes(path);
8684
+ if (bytes) {
8685
+ files.push({ path, bytes });
8686
+ }
8687
+ }
8688
+ return files;
8689
+ }
8690
+ async extractNavTarget(target, action) {
8691
+ const snapshot = this.workspace?.snapshot();
8692
+ if (!snapshot) {
8693
+ return;
8694
+ }
8695
+ const selection = target.kind === 'selection'
8696
+ ? { files: target.files, folders: target.folders }
8697
+ : target.kind === 'directory'
8698
+ ? { files: [], folders: [target.path] }
8699
+ : { files: [target.path], folders: [] };
8700
+ if (action === 'extract-folder') {
8701
+ // Ask for the folder first: the picker needs the click's user activation.
8702
+ await this.extractToPickedFolder(selection, snapshot);
8703
+ return;
8704
+ }
8705
+ const files = await this.readExtractFiles(this.collectExtractPaths(selection, snapshot));
8706
+ if (!files.length) {
8707
+ return;
8708
+ }
8709
+ if (action === 'extract') {
8710
+ await this.options.onExtractFiles?.({ files, selection });
8711
+ return;
8712
+ }
8713
+ const zippable = {};
8714
+ for (const file of files) {
8715
+ // Pictures are compressed already.
8716
+ zippable[file.path] = [file.bytes, { level: /\.(png|jpe?g|gif|webp|avif|mp4|webm|zip|mdz)$/i.test(file.path) ? 0 : 6 }];
8717
+ }
8718
+ const zipped = zipSync(zippable);
8719
+ const buffer = zipped.buffer.slice(zipped.byteOffset, zipped.byteOffset + zipped.byteLength);
8720
+ const base = snapshot.fileName.replace(/\.[^.]+$/, '') || 'archive';
8721
+ const onlyFolder = selection.files.length === 0 && selection.folders.length === 1 && selection.folders[0] !== ''
8722
+ ? selection.folders[0].slice(selection.folders[0].lastIndexOf('/') + 1)
8723
+ : null;
8724
+ this.downloadSavedBlob(new Blob([buffer], { type: 'application/zip' }), `${onlyFolder ?? base}.zip`);
8725
+ }
8726
+ // Extract to Folder… in a browser that can write to one: keeps the archive
8727
+ // paths below the folder picked, and asks before replacing files.
8728
+ async extractToPickedFolder(selection, snapshot) {
8729
+ const win = this.elRoot.ownerDocument.defaultView;
8730
+ if (!win?.showDirectoryPicker) {
8731
+ return;
8732
+ }
8733
+ let root;
8734
+ try {
8735
+ root = await win.showDirectoryPicker({ mode: 'readwrite', id: 'mdzip-extract' });
8736
+ }
8737
+ catch (error) {
8738
+ if (error?.name === 'AbortError') {
8739
+ return;
8740
+ }
8741
+ throw error;
8742
+ }
8743
+ const files = await this.readExtractFiles(this.collectExtractPaths(selection, snapshot));
8744
+ const folderOf = async (path, create) => {
8745
+ let dir = root;
8746
+ for (const part of path.split('/').slice(0, -1)) {
8747
+ try {
8748
+ dir = await dir.getDirectoryHandle(part, { create });
8749
+ }
8750
+ catch {
8751
+ return null;
8752
+ }
8753
+ }
8754
+ return dir;
8755
+ };
8756
+ const nameOf = (path) => path.slice(path.lastIndexOf('/') + 1);
8757
+ let existing = 0;
8758
+ for (const file of files) {
8759
+ const dir = await folderOf(file.path, false);
8760
+ if (dir && await dir.getFileHandle(nameOf(file.path)).then(() => true, () => false)) {
8761
+ existing += 1;
8762
+ }
8763
+ }
8764
+ if (existing > 0) {
8765
+ const ok = await this.askConfirm('Replace Existing Files?', `${existing === 1 ? 'One file' : `${existing} files`} of the ${files.length} already ${existing === 1 ? 'exists' : 'exist'} in "${root.name}". Replace ${existing === 1 ? 'it' : 'them'}?`, 'Replace');
8766
+ if (!ok) {
8767
+ return;
8768
+ }
8769
+ }
8770
+ for (const file of files) {
8771
+ const dir = await folderOf(file.path, true);
8772
+ if (!dir) {
8773
+ throw new Error(`Could not create the folder for ${file.path}.`);
8774
+ }
8775
+ const writable = await (await dir.getFileHandle(nameOf(file.path), { create: true })).createWritable();
8776
+ await writable.write(file.bytes);
8777
+ await writable.close();
8778
+ }
8779
+ this.showCopyToast(`Extracted ${files.length === 1 ? 'one file' : `${files.length} files`} to "${root.name}"`);
8780
+ }
8781
+ /** Asks a yes/no question in the editor's own dialog (no browser confirm(), which some hosts block). */
8782
+ askConfirm(title, text, confirm) {
8783
+ this.confirmDialogState?.resolve(false);
8784
+ return new Promise((resolve) => {
8785
+ this.confirmDialogState = { title, text, confirm, resolve };
8786
+ this.render();
8787
+ this.elConfirmDialogOk.focus();
8788
+ });
8789
+ }
8790
+ answerConfirm(ok) {
8791
+ const state = this.confirmDialogState;
8792
+ this.confirmDialogState = null;
8793
+ this.render();
8794
+ state?.resolve(ok);
8795
+ }
8796
+ // The tree's rows in order, as selection keys.
8797
+ navRowKeys() {
8798
+ return Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))
8799
+ // Hidden in a closed folder? (A folder's own row shows while it's closed.)
8800
+ .filter((row) => !(row.matches('summary') ? row.parentElement?.parentElement : row)?.closest('details:not([open])'))
8801
+ .map((row) => navRowKey(row))
8802
+ .filter((key) => key !== null);
8803
+ }
8804
+ // Shift+click: the rows from the anchor to this one (added to the
8805
+ // selection with Ctrl/Cmd).
8806
+ selectNavRange(key, add) {
8807
+ const rows = this.navRowKeys();
8808
+ const anchor = this.navSelectionAnchor && rows.includes(this.navSelectionAnchor) ? this.navSelectionAnchor : key;
8809
+ const [from, to] = [rows.indexOf(anchor), rows.indexOf(key)].sort((a, b) => a - b);
8810
+ const range = rows.slice(from, to + 1);
8811
+ this.navSelection = add ? [...new Set([...this.navSelection, ...range])] : range;
8812
+ this.navSelectionAnchor = anchor;
8813
+ }
8814
+ // Marks the selected rows, dropping any no longer in the tree.
8815
+ syncNavSelection() {
8816
+ const present = new Set(this.navRowKeysAll());
8817
+ this.navSelection = this.navSelection.filter((key) => present.has(key));
8818
+ const selected = new Set(this.navSelection);
8819
+ for (const row of Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))) {
8820
+ const key = navRowKey(row);
8821
+ row.classList.toggle('nav-selected', !!key && selected.has(key));
8822
+ }
8823
+ this.elNavTree.classList.toggle('has-selection', this.navSelection.length > 1);
8824
+ }
8825
+ navRowKeysAll() {
8826
+ return Array.from(this.elNavTree.querySelectorAll('[data-nav-path], details[data-nav-dir] > summary'))
8827
+ .map((row) => navRowKey(row))
8828
+ .filter((key) => key !== null);
8829
+ }
7522
8830
  async duplicateFile(path) {
7523
8831
  const workspace = this.workspace;
7524
8832
  const snapshot = workspace?.snapshot();
@@ -7693,17 +9001,107 @@ export class MdzipWorkspaceView {
7693
9001
  this.options.onFailed?.(error);
7694
9002
  }
7695
9003
  }
9004
+ // The layout as drawn for the open file. Split shows the editor alone for
9005
+ // non-Markdown text (JSON, CSS, …), whose preview would only repeat the
9006
+ // text; this.layout keeps the choice, so Markdown files open split again.
9007
+ shownLayout(snapshot) {
9008
+ return this.layout === 'split' && snapshot.currentPathType === 'text' && !this.isManifestFormPath(snapshot)
9009
+ ? 'source'
9010
+ : this.layout;
9011
+ }
9012
+ // The archive's own manifest.json, which View shows as a form.
9013
+ isManifestFormPath(snapshot) {
9014
+ return snapshot.sourceFormat === 'mdz'
9015
+ && snapshot.currentPathType === 'text'
9016
+ && isMdzipRootManifestPath(snapshot.currentPath);
9017
+ }
9018
+ // Moving into or out of manifest.json swaps in that side's remembered
9019
+ // layout, so the form (View) and a document's Split don't override each other.
9020
+ swapManifestLayout(snapshot) {
9021
+ const isManifest = this.isManifestFormPath(snapshot);
9022
+ if (isManifest === this.layoutIsManifest) {
9023
+ return;
9024
+ }
9025
+ this.layoutIsManifest = isManifest;
9026
+ if (isManifest) {
9027
+ this.documentLayout = this.layout;
9028
+ this.layout = this.manifestLayout;
9029
+ }
9030
+ else {
9031
+ this.manifestLayout = this.layout;
9032
+ this.layout = this.documentLayout;
9033
+ }
9034
+ if (this.layout !== 'preview' && !this.cmEditor) {
9035
+ // The editor is created on demand; draw again once it exists.
9036
+ void this.ensureCmEditor().then(() => this.render());
9037
+ }
9038
+ }
9039
+ mountManifestForm(snapshot) {
9040
+ const workspace = this.workspace;
9041
+ if (!workspace) {
9042
+ return;
9043
+ }
9044
+ if (!this.manifestForm || !this.elPreviewContent.contains(this.manifestForm.root)) {
9045
+ this.manifestForm = new MdzipManifestForm(this.elRoot.ownerDocument, {
9046
+ editable: snapshot.mode !== 'read-only',
9047
+ markdownPaths: snapshot.content.paths.filter((entry) => entry.isMarkdown).map((entry) => entry.path),
9048
+ onChange: (path, value) => this.setManifestValue(path, value),
9049
+ onEditJson: () => {
9050
+ // In Split the JSON is already beside the form: just go to it.
9051
+ const show = this.layout === 'split' ? Promise.resolve() : this.setLayout('source');
9052
+ void show.then(() => this.cmEditor?.focus());
9053
+ }
9054
+ });
9055
+ this.elPreviewContent.replaceChildren(this.manifestForm.root);
9056
+ }
9057
+ const validity = workspace.validateJsonText(snapshot.currentPath, snapshot.currentText);
9058
+ this.manifestForm.update(validity);
9059
+ this.setJsonValidity(validity, snapshot.currentPath);
9060
+ }
9061
+ // A change made in the form: one value set in the JSON text, through the
9062
+ // editor when there is one (so Ctrl+Z undoes it), else the workspace.
9063
+ setManifestValue(path, value) {
9064
+ const workspace = this.workspace;
9065
+ if (!workspace) {
9066
+ return;
9067
+ }
9068
+ const current = this.cmEditor && this.layout !== 'preview'
9069
+ ? this.cmEditor.state.doc.toString()
9070
+ : workspace.snapshot().currentText;
9071
+ const next = setMdzipJsonMember(current, path, value);
9072
+ if (next === null || next === current) {
9073
+ return;
9074
+ }
9075
+ const editor = this.cmEditor;
9076
+ if (editor && editor.state.doc.toString() === current) {
9077
+ editor.dispatch({ changes: { from: 0, to: current.length, insert: next }, userEvent: 'input.form' });
9078
+ }
9079
+ else {
9080
+ try {
9081
+ workspace.editText(next);
9082
+ }
9083
+ catch (error) {
9084
+ this.options.onFailed?.(error);
9085
+ }
9086
+ }
9087
+ }
7696
9088
  validLayoutForSnapshot(requested, snapshot) {
7697
9089
  if (requested === 'source' || requested === 'split') {
7698
9090
  return canShowSourceLayout(snapshot) ? requested : 'preview';
7699
9091
  }
7700
9092
  return requested;
7701
9093
  }
7702
- syncScrollFromPreview() {
7703
- if (this.syncing || !this.cmEditor || this.layout !== 'split') {
9094
+ /**
9095
+ * In Split, scrolls the source to match the preview. Normally only after
9096
+ * the reader scrolled the preview themselves; `driven` is for the editor's
9097
+ * own moves (going to a heading from the outline or a link), which no
9098
+ * gesture precedes.
9099
+ */
9100
+ syncScrollFromPreview(driven = false) {
9101
+ if (this.syncing || !this.cmEditor || this.layout !== 'split' || this.layoutIsManifest) {
7704
9102
  return;
7705
9103
  }
7706
- if (performance.now() - this.lastPreviewGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
9104
+ if (!driven && performance.now() - this.lastPreviewGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
7707
9105
  return;
7708
9106
  }
7709
9107
  if (performance.now() - this.lastContentChangeTime < MdzipWorkspaceView.SCROLL_SYNC_SETTLE_MS) {
@@ -7724,19 +9122,25 @@ export class MdzipWorkspaceView {
7724
9122
  return;
7725
9123
  }
7726
9124
  this.syncing = true;
7727
- const previewHeight = this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight;
7728
- const scrollRatio = previewHeight > 0 ? currentTop / previewHeight : 0;
7729
9125
  const cmScroller = this.cmEditor.dom.querySelector('.cm-scroller');
7730
9126
  if (cmScroller) {
7731
- const editorHeight = cmScroller.scrollHeight - cmScroller.clientHeight;
7732
- const target = scrollRatio * editorHeight;
9127
+ const anchors = this.splitScrollAnchors('preview', currentTop);
9128
+ let target;
9129
+ if (anchors) {
9130
+ target = mapScrollPosition(currentTop, anchors.map(([editor, preview]) => [preview, editor]), this.elPreviewPane, cmScroller);
9131
+ }
9132
+ else {
9133
+ const previewHeight = this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight;
9134
+ const scrollRatio = previewHeight > 0 ? currentTop / previewHeight : 0;
9135
+ target = scrollRatio * (cmScroller.scrollHeight - cmScroller.clientHeight);
9136
+ }
7733
9137
  this.lastSyncedEditorScrollTop = target;
7734
9138
  cmScroller.scrollTop = target;
7735
9139
  }
7736
9140
  this.syncing = false;
7737
9141
  }
7738
9142
  syncScrollToPreview() {
7739
- if (this.syncing || !this.cmEditor || this.layout !== 'split') {
9143
+ if (this.syncing || !this.cmEditor || this.layout !== 'split' || this.layoutIsManifest) {
7740
9144
  return;
7741
9145
  }
7742
9146
  if (performance.now() - this.lastEditorGestureTime > MdzipWorkspaceView.SCROLL_SYNC_GESTURE_WINDOW_MS) {
@@ -7792,13 +9196,141 @@ export class MdzipWorkspaceView {
7792
9196
  return;
7793
9197
  }
7794
9198
  this.syncing = true;
7795
- const scrollRatio = editorHeight > 0 ? currentTop / editorHeight : 0;
7796
- const previewHeight = this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight;
7797
- const target = scrollRatio * previewHeight;
9199
+ const anchors = this.splitScrollAnchors('editor', currentTop);
9200
+ let target;
9201
+ if (anchors) {
9202
+ target = mapScrollPosition(currentTop, anchors, cmScroller, this.elPreviewPane);
9203
+ }
9204
+ else {
9205
+ const scrollRatio = editorHeight > 0 ? currentTop / editorHeight : 0;
9206
+ target = scrollRatio * (this.elPreviewPane.scrollHeight - this.elPreviewPane.clientHeight);
9207
+ }
7798
9208
  this.lastSyncedPreviewScrollTop = target;
7799
9209
  this.elPreviewPane.scrollTop = target;
7800
9210
  this.syncing = false;
7801
9211
  }
9212
+ /**
9213
+ * The two pairs of [offset in the editor, offset in the preview] for the
9214
+ * same content around `scrollTop` of one pane (#13), for
9215
+ * `mapScrollPosition` to interpolate between: the mounted top-level
9216
+ * blocks the renderer marked (`data-mdzip-block`), each at its token's
9217
+ * first source line. The panes stay together past a tall image, table or
9218
+ * code block, where one ratio for the whole document drifts. Null when
9219
+ * nothing is marked (a custom renderer) or the preview isn't laid out:
9220
+ * the sync falls back to that ratio.
9221
+ *
9222
+ * Only the two blocks around the position are measured, found by binary
9223
+ * search (both panes keep blocks in document order), so a scroll costs
9224
+ * the same in a document of any length.
9225
+ */
9226
+ splitScrollAnchors(from, scrollTop) {
9227
+ const editor = this.cmEditor;
9228
+ const blocks = this.splitScrollBlocks();
9229
+ if (!editor || !blocks || !this.elPreviewContent.offsetHeight) {
9230
+ return null;
9231
+ }
9232
+ const scroller = editor.scrollDOM;
9233
+ const pane = this.elPreviewPane;
9234
+ const previewOrigin = pane.scrollTop - pane.getBoundingClientRect().top;
9235
+ const editorOrigin = editor.documentTop - scroller.getBoundingClientRect().top + scroller.scrollTop;
9236
+ const editorTop = (i) => editor.lineBlockAt(Math.min(blocks.offsets[i], editor.state.doc.length)).top + editorOrigin;
9237
+ const previewTop = (i) => blocks.elements[i].getBoundingClientRect().top + previewOrigin;
9238
+ const top = from === 'editor' ? editorTop : previewTop;
9239
+ // The last block at or above scrollTop (-1: above the first).
9240
+ let low = 0;
9241
+ let high = blocks.offsets.length - 1;
9242
+ let at = -1;
9243
+ while (low <= high) {
9244
+ const mid = (low + high) >> 1;
9245
+ if (top(mid) <= scrollTop) {
9246
+ at = mid;
9247
+ low = mid + 1;
9248
+ }
9249
+ else {
9250
+ high = mid - 1;
9251
+ }
9252
+ }
9253
+ const anchors = [];
9254
+ for (const i of [at, at + 1]) {
9255
+ if (i >= 0 && i < blocks.offsets.length) {
9256
+ anchors.push([editorTop(i), previewTop(i)]);
9257
+ }
9258
+ }
9259
+ return anchors;
9260
+ }
9261
+ /**
9262
+ * The preview's mounted, marked blocks in order, each with its token's
9263
+ * offset in the editor's text. Offsets come from each token's `raw` text,
9264
+ * found in order in the editor's current text rather than counted from
9265
+ * the tokens: front matter is stripped before tokenizing, and the preview
9266
+ * can be a render behind the editor while typing (a block not found is
9267
+ * left out). Kept until the text or the mounted chunks change; no layout
9268
+ * is read here.
9269
+ */
9270
+ splitScrollBlocks() {
9271
+ const editor = this.cmEditor;
9272
+ const state = this.chunkedRenderState;
9273
+ if (!editor || !state) {
9274
+ return null;
9275
+ }
9276
+ const cached = this.splitBlockCache;
9277
+ if (cached && cached.doc === editor.state.doc && cached.records === state.records && cached.cursor === state.cursor) {
9278
+ return cached.blocks;
9279
+ }
9280
+ const text = editor.state.doc.toString();
9281
+ const offsets = [];
9282
+ const elements = [];
9283
+ let cursor = 0;
9284
+ let located = false;
9285
+ for (const record of state.records) {
9286
+ const tokenOffsets = [];
9287
+ for (const token of record.tokens) {
9288
+ const raw = token.raw;
9289
+ let at = -1;
9290
+ if (raw) {
9291
+ if (text.startsWith(raw, cursor)) {
9292
+ at = cursor;
9293
+ }
9294
+ else if (!located) {
9295
+ // The first block can come after front matter of any length.
9296
+ at = text.indexOf(raw, cursor);
9297
+ }
9298
+ else {
9299
+ // Later, only look a little ahead: a block edited since the
9300
+ // preview rendered isn't in the text, and mustn't cost a scan
9301
+ // of the rest of the document.
9302
+ const found = text.slice(cursor, cursor + raw.length + 4096).indexOf(raw);
9303
+ at = found < 0 ? -1 : cursor + found;
9304
+ }
9305
+ }
9306
+ tokenOffsets.push(at);
9307
+ if (at >= 0) {
9308
+ located = true;
9309
+ cursor = at + raw.length;
9310
+ }
9311
+ }
9312
+ if (!record.root) {
9313
+ continue;
9314
+ }
9315
+ // At any depth: the preview wraps some blocks after mounting (a code
9316
+ // block in its header box). Not inside another block, though: only
9317
+ // raw HTML written that way could put one there.
9318
+ for (const element of Array.from(record.root.querySelectorAll(`[${MDZIP_BLOCK_ATTRIBUTE}]`))) {
9319
+ if (element.parentElement?.closest(`[${MDZIP_BLOCK_ATTRIBUTE}]`)) {
9320
+ continue;
9321
+ }
9322
+ const index = Number(element.getAttribute(MDZIP_BLOCK_ATTRIBUTE) ?? NaN);
9323
+ const offset = Number.isInteger(index) ? tokenOffsets[index] ?? -1 : -1;
9324
+ if (offset >= 0) {
9325
+ offsets.push(offset);
9326
+ elements.push(element);
9327
+ }
9328
+ }
9329
+ }
9330
+ const blocks = offsets.length ? { offsets, elements } : null;
9331
+ this.splitBlockCache = { doc: editor.state.doc, records: state.records, cursor: state.cursor, blocks };
9332
+ return blocks;
9333
+ }
7802
9334
  /**
7803
9335
  * Handles syncScrollToPreview's bottom edge when the preview still has
7804
9336
  * unmounted chunks: force-mounts the rest (same drain Copy All uses) so
@@ -8030,349 +9562,388 @@ function formatMetadataValue(value) {
8030
9562
  }
8031
9563
  return 'Not available';
8032
9564
  }
8033
- const SHELL_HTML = `
8034
- <section class="mdzip-root">
8035
- <div class="document-strip" data-ref="document-strip" hidden>
8036
- <button type="button" class="title-button" data-ref="title-btn"></button>
8037
- <button type="button" class="document-info-button" data-ref="document-info-btn"
8038
- title="Document information" aria-label="Document information">
8039
- ${INFO_ICON_HTML}
8040
- </button>
8041
- </div>
8042
-
8043
- <header class="toolbar" data-ref="toolbar" hidden>
8044
- <div class="toolbar-start">
8045
- <div class="toolbar-left">
8046
- <button type="button" class="icon-toggle nav-toggle" data-ref="nav-btn" title="Toggle contents" aria-label="Toggle contents">
8047
- ${NAV_TOGGLE_ICON_HTML}
8048
- </button>
8049
- </div>
8050
-
8051
- <div class="edit-toolbar" data-ref="edit-toolbar" role="toolbar" aria-label="Markdown formatting">
8052
- <div class="edit-toolbar-group">
8053
- <button type="button" data-format="bold" data-format-control="bold" title="Bold" aria-label="Bold">${BOLD_ICON_HTML}</button>
8054
- <button type="button" data-format="italic" data-format-control="italic" title="Italic" aria-label="Italic">${ITALIC_ICON_HTML}</button>
8055
- <button type="button" data-format="strike" data-format-control="strikethrough" title="Strikethrough" aria-label="Strikethrough">${STRIKE_ICON_HTML}</button>
8056
- <div class="format-menu" data-format-control="headings">
8057
- <button type="button" class="format-menu-toggle" data-format-menu-toggle
8058
- aria-label="Heading" aria-haspopup="menu" aria-expanded="false">
8059
- ${HEADING_ICON_HTML}${CHEVRON_ICON_HTML}
8060
- </button>
8061
- <div class="format-menu-popover" data-format-menu role="menu" aria-label="Heading level" hidden>
8062
- <button type="button" role="menuitem" data-format="paragraph">Paragraph</button>
8063
- <button type="button" role="menuitem" data-format="heading-1" data-heading-level="1"><strong>H1</strong> Heading 1</button>
8064
- <button type="button" role="menuitem" data-format="heading-2" data-heading-level="2"><strong>H2</strong> Heading 2</button>
8065
- <button type="button" role="menuitem" data-format="heading-3" data-heading-level="3"><strong>H3</strong> Heading 3</button>
8066
- <button type="button" role="menuitem" data-format="heading-4" data-heading-level="4"><strong>H4</strong> Heading 4</button>
8067
- <button type="button" role="menuitem" data-format="heading-5" data-heading-level="5"><strong>H5</strong> Heading 5</button>
8068
- <button type="button" role="menuitem" data-format="heading-6" data-heading-level="6"><strong>H6</strong> Heading 6</button>
8069
- </div>
8070
- </div>
8071
- </div>
8072
- <span class="edit-toolbar-divider" aria-hidden="true"></span>
8073
- <div class="edit-toolbar-group">
8074
- <button type="button" data-format="bullet-list" data-format-control="bulletList" title="Bulleted list" aria-label="Bulleted list">${BULLET_LIST_ICON_HTML}</button>
8075
- <button type="button" data-format="ordered-list" data-format-control="orderedList" title="Numbered list" aria-label="Numbered list">${ORDERED_LIST_ICON_HTML}</button>
8076
- <div class="format-menu" data-format-control="code">
8077
- <button type="button" class="format-menu-toggle" data-format-menu-toggle
8078
- aria-label="Code" aria-haspopup="menu" aria-expanded="false">
8079
- ${CODE_ICON_HTML}${CHEVRON_ICON_HTML}
8080
- </button>
8081
- <div class="format-menu-popover" data-format-menu role="menu" aria-label="Code format" hidden>
8082
- <button type="button" role="menuitem" data-format="code" data-code-kind="inline">Inline code</button>
8083
- <button type="button" role="menuitem" data-format="code-block" data-code-kind="block">Code block</button>
8084
- </div>
8085
- </div>
8086
- <button type="button" data-format="quote" data-format-control="blockquote" title="Blockquote" aria-label="Blockquote">${QUOTE_ICON_HTML}</button>
8087
- <button type="button" data-format="line-break" data-format-control="lineBreak" title="Line break" aria-label="Line break">${LINE_BREAK_ICON_HTML}</button>
8088
- </div>
8089
- <span class="edit-toolbar-divider" aria-hidden="true"></span>
8090
- <div class="edit-toolbar-group">
8091
- <button type="button" data-format="link" data-format-control="link" title="Link" aria-label="Link">${LINK_ICON_HTML}</button>
8092
- <button type="button" data-format="image" data-format-control="image" title="Image" aria-label="Image">${IMAGE_FORMAT_ICON_HTML}</button>
8093
- <input type="file" data-ref="image-input" accept="image/*" hidden />
8094
- </div>
8095
- </div>
8096
- </div>
8097
-
8098
- <div class="toolbar-buttons view-mode-toggle-group" data-ref="layout-controls" role="group" aria-label="Editor layout">
8099
- <button type="button" class="icon-toggle view-mode-toggle" data-ref="source-btn" title="Edit" aria-label="Edit" aria-pressed="false">
8100
- <span class="commandbar-flex-container" data-ref="source-icon">${SOURCE_EDIT_ICON_HTML}</span>
8101
- </button>
8102
- <button type="button" class="icon-toggle view-mode-toggle" data-ref="split-btn" title="Split" aria-label="Split" aria-pressed="false">
8103
- <span class="commandbar-flex-container">
8104
- ${SPLIT_ICON_HTML}
8105
- </span>
8106
- </button>
8107
- <button type="button" class="icon-toggle view-mode-toggle" data-ref="preview-btn" title="View" aria-label="View" aria-pressed="false">
8108
- <span class="commandbar-flex-container">
8109
- ${PREVIEW_ICON_HTML}
8110
- </span>
8111
- </button>
8112
- </div>
8113
-
8114
- <div class="toolbar-controls" data-ref="toolbar-controls">
8115
- <button type="button" class="icon-toggle" data-ref="search-btn" title="Find/replace (Mod-F)" aria-label="Find/replace">
8116
- ${SEARCH_ICON_HTML}
8117
- </button>
8118
- <button type="button" class="icon-toggle" data-ref="save-btn" title="Save" aria-label="Save">
8119
- ${SAVE_ICON_HTML}
8120
- </button>
8121
- <button type="button" class="icon-toggle zoom-toggle" data-ref="zoom-btn" title="Zoom controls" aria-label="Zoom controls">
8122
- ${ZOOM_ICON_HTML}
8123
- </button>
8124
- <div class="toolbar-menu width-menu" data-ref="width-controls">
8125
- <button type="button" class="icon-toggle toolbar-menu-toggle" data-ref="width-menu-btn"
8126
- title="Page width" aria-label="Page width" aria-haspopup="menu" aria-expanded="false">
8127
- <span class="toolbar-menu-icon" data-ref="width-menu-icon">${PAGE_WIDTH_DEFAULT_ICON_HTML}</span>
8128
- </button>
8129
- <div class="toolbar-popover" data-ref="width-popover" role="menu" aria-label="Page width" hidden>
8130
- ${['narrow', 'default', 'wide', 'full'].map((choice) => `
8131
- <button type="button" role="menuitemradio" class="icon-toggle toolbar-menu-item" data-width="${choice}"
8132
- title="${PREVIEW_WIDTH_LABELS[choice]}" aria-label="${PREVIEW_WIDTH_LABELS[choice]}" aria-checked="false">
8133
- ${PREVIEW_WIDTH_ICONS_HTML[choice]}
8134
- </button>`).join('')}
8135
- </div>
8136
- </div>
8137
- <div class="theme-menu" data-ref="theme-controls">
8138
- <button type="button" class="icon-toggle theme-menu-toggle" data-ref="theme-menu-btn"
8139
- title="Color scheme" aria-label="Color scheme" aria-haspopup="menu" aria-expanded="false">
8140
- <span class="theme-menu-icon" data-ref="theme-menu-icon">${SYSTEM_THEME_ICON_HTML}</span>
8141
- </button>
8142
- <div class="theme-popover" data-ref="theme-popover" role="menu" aria-label="Color scheme" hidden>
8143
- <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="light-theme-btn"
8144
- title="Light mode" aria-label="Light mode" aria-checked="false">
8145
- ${LIGHT_THEME_ICON_HTML}
8146
- </button>
8147
- <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="dark-theme-btn"
8148
- title="Dark mode" aria-label="Dark mode" aria-checked="false">
8149
- ${DARK_THEME_ICON_HTML}
8150
- </button>
8151
- <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="system-theme-btn"
8152
- title="System setting" aria-label="System setting" aria-checked="false">
8153
- ${SYSTEM_THEME_ICON_HTML}
8154
- </button>
8155
- </div>
8156
- </div>
8157
- <div class="zoom-popover" data-ref="zoom-popover" hidden role="group" aria-label="Zoom">
8158
- <span class="zoom-level" data-ref="zoom-level">100%</span>
8159
- <span class="zoom-stepper">
8160
- <button type="button" data-action="zoom-out" title="Zoom out" aria-label="Zoom out">-</button>
8161
- <button type="button" data-action="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
8162
- </span>
8163
- <button type="button" class="zoom-reset" data-action="zoom-reset" title="Reset zoom">Reset</button>
8164
- </div>
8165
- </div>
8166
- </header>
8167
-
8168
- <div class="workspace-shell" data-ref="workspace-shell" hidden>
8169
- <aside class="nav-pane" data-ref="nav-pane" aria-label="Package contents">
8170
- <div class="nav-tree" data-ref="nav-tree"></div>
8171
- </aside>
8172
- <div class="nav-resizer" data-ref="nav-resizer"
8173
- role="separator" aria-orientation="vertical" aria-label="Resize contents pane"></div>
8174
-
8175
- <div class="pane-stack" data-ref="pane-stack">
8176
- <section class="pane edit-pane" data-ref="edit-pane">
8177
- <div class="editor-host" data-ref="editor-host"></div>
8178
- </section>
8179
- <div class="split-resizer" data-ref="split-resizer"
8180
- role="separator" aria-orientation="vertical" aria-label="Resize split panes"></div>
8181
- <section class="pane preview-pane" data-ref="preview-pane" tabindex="-1">
8182
- <article class="preview-content" data-ref="preview-content"></article>
8183
- </section>
8184
- <section class="pane entry-pane" data-ref="entry-pane"></section>
8185
- </div>
8186
- </div>
8187
-
8188
- <div class="title-dialog-backdrop" data-ref="title-dialog" hidden
8189
- role="dialog" aria-modal="true" aria-labelledby="mdzip-title-dialog-heading">
8190
- <div class="title-dialog">
8191
- <h3 id="mdzip-title-dialog-heading">Set Document Title</h3>
8192
- <p>This is the package-level title stored in manifest.json.</p>
8193
- <input type="text" maxlength="120" data-ref="title-input" aria-label="Document title" />
8194
- <p class="title-dialog-validation" data-ref="title-validation" hidden>Title cannot be empty.</p>
8195
- <p>If unset, consumers may fall back to entry point, filename, or first heading.</p>
8196
- <div class="title-dialog-actions">
8197
- <button type="button" class="reset-title" data-ref="title-reset-btn">Reset</button>
8198
- <button type="button" data-action="cancel-title">Cancel</button>
8199
- <button type="button" class="save-title" data-ref="title-save-btn">Save</button>
8200
- </div>
8201
- </div>
8202
- </div>
8203
-
8204
- <div class="title-dialog-backdrop" data-ref="conversion-dialog" hidden
8205
- role="dialog" aria-modal="true" aria-labelledby="mdzip-conversion-dialog-heading">
8206
- <div class="title-dialog">
8207
- <h3 id="mdzip-conversion-dialog-heading">Convert to MDZ?</h3>
8208
- <p>
8209
- Regular Markdown files contain only text. Convert this document to an
8210
- MDZ package to add images, package navigation, and document metadata.
8211
- </p>
8212
- <p>The next save will produce an .mdz file.</p>
8213
- <div class="title-dialog-actions">
8214
- <button type="button" data-action="cancel-conversion">Cancel</button>
8215
- <button type="button" class="save-title" data-ref="conversion-confirm-btn">Convert</button>
8216
- </div>
8217
- </div>
8218
- </div>
8219
-
8220
- <div class="title-dialog-backdrop" data-ref="image-insert-dialog" hidden
8221
- role="dialog" aria-modal="true" aria-labelledby="mdzip-image-insert-dialog-heading">
8222
- <div class="title-dialog image-insert-dialog">
8223
- <h3 id="mdzip-image-insert-dialog-heading">Insert Image</h3>
8224
- <p>Choose the Markdown inserted for this image.</p>
8225
- <fieldset class="image-insert-options">
8226
- <legend>Output</legend>
8227
- <label>
8228
- <input type="radio" name="mdzip-image-insert-mode" value="markdown"
8229
- data-ref="image-insert-mode-markdown" checked />
8230
- Markdown image
8231
- </label>
8232
- <label>
8233
- <input type="radio" name="mdzip-image-insert-mode" value="html"
8234
- data-ref="image-insert-mode-html" />
8235
- HTML &lt;img&gt; with sizing
8236
- </label>
8237
- </fieldset>
8238
- <label class="image-insert-field">
8239
- <span>Alt text</span>
8240
- <input type="text" data-ref="image-insert-alt" />
8241
- </label>
8242
- <div class="image-insert-grid">
8243
- <label class="image-insert-field">
8244
- <span>Size by</span>
8245
- <select data-ref="image-insert-size-mode">
8246
- <option value="original">Original size</option>
8247
- <option value="width" selected>Width</option>
8248
- <option value="height">Height</option>
8249
- <option value="percent">Percent</option>
8250
- </select>
8251
- </label>
8252
- <label class="image-insert-field">
8253
- <span>Value</span>
8254
- <input type="number" min="1" step="1" data-ref="image-insert-size-value" />
8255
- </label>
8256
- </div>
8257
- <label class="image-insert-field">
8258
- <span>Position</span>
8259
- <select data-ref="image-insert-position">
8260
- <option value="inline">Inline/default</option>
8261
- <option value="left">Left</option>
8262
- <option value="center">Center</option>
8263
- <option value="right">Right</option>
8264
- <option value="wrap-left">Wrap left</option>
8265
- <option value="wrap-right">Wrap right</option>
8266
- </select>
8267
- </label>
8268
- <div class="title-dialog-actions">
8269
- <button type="button" data-action="cancel-image-insert">Cancel</button>
8270
- <button type="button" class="save-title" data-ref="image-insert-confirm-btn">Insert</button>
8271
- </div>
8272
- </div>
8273
- </div>
8274
-
8275
- <div class="title-dialog-backdrop" data-ref="pack-files-dialog" hidden
8276
- role="dialog" aria-modal="true" aria-labelledby="mdzip-pack-files-dialog-heading">
8277
- <div class="title-dialog pack-files-dialog">
8278
- <h3 id="mdzip-pack-files-dialog-heading">Package Markdown Files</h3>
8279
- <p>These files contain more than one Markdown document. Choose how to package them.</p>
8280
- <fieldset class="pack-files-options">
8281
- <legend>Mode</legend>
8282
- <label>
8283
- <input type="radio" name="mdzip-pack-files-mode" value="document"
8284
- data-ref="pack-files-mode-document" checked />
8285
- Document — one primary page; the rest are attached
8286
- </label>
8287
- <label>
8288
- <input type="radio" name="mdzip-pack-files-mode" value="project"
8289
- data-ref="pack-files-mode-project" />
8290
- Project — a set of related documents
8291
- </label>
8292
- </fieldset>
8293
- <label class="pack-files-field">
8294
- <span>Entry point</span>
8295
- <select data-ref="pack-files-entry"></select>
8296
- </label>
8297
- <div class="title-dialog-actions">
8298
- <button type="button" data-action="cancel-pack-files">Cancel</button>
8299
- <button type="button" class="save-title" data-ref="pack-files-confirm-btn">Package</button>
8300
- </div>
8301
- </div>
8302
- </div>
8303
-
8304
- <div class="title-dialog-backdrop" data-ref="copy-render-dialog" hidden
8305
- role="dialog" aria-modal="true" aria-labelledby="mdzip-copy-render-dialog-heading">
8306
- <div class="title-dialog copy-render-dialog">
8307
- <h3 id="mdzip-copy-render-dialog-heading" data-ref="copy-render-heading">Copying document...</h3>
8308
- <div data-ref="copy-render-progress-section">
8309
- <p data-ref="copy-render-progress-text">Rendering the full document...</p>
8310
- <div class="copy-render-progress-track">
8311
- <div class="copy-render-progress-bar" data-ref="copy-render-progress-bar"></div>
8312
- </div>
8313
- </div>
8314
- <p data-ref="copy-render-ready-text" hidden>
8315
- The document is ready. Browsers only allow a clipboard write right after a click, so this needs one more —
8316
- click Copy to finish.
8317
- </p>
8318
- <p data-ref="copy-render-done-text" hidden></p>
8319
- <div class="title-dialog-actions">
8320
- <button type="button" data-action="cancel-copy-render" data-ref="copy-render-cancel-btn">Cancel</button>
8321
- <button type="button" data-action="cancel-copy-ready" data-ref="copy-render-ready-cancel-btn" hidden>Cancel</button>
8322
- <button type="button" class="save-title" data-action="confirm-copy-ready" data-ref="copy-render-confirm-btn" hidden>Copy</button>
8323
- <button type="button" class="save-title" data-action="dismiss-copy-render" data-ref="copy-render-dismiss-btn" hidden>Dismiss</button>
8324
- </div>
8325
- </div>
8326
- </div>
8327
-
8328
- <div class="title-dialog-backdrop" data-ref="metadata-dialog" hidden
8329
- role="dialog" aria-modal="true" aria-labelledby="mdzip-metadata-dialog-heading">
8330
- <div class="title-dialog metadata-dialog">
8331
- <h3 id="mdzip-metadata-dialog-heading">Document Information</h3>
8332
- <dl data-ref="metadata-list"></dl>
8333
- <h4>Libraries</h4>
8334
- <dl data-ref="library-list"></dl>
8335
- <div class="title-dialog-actions">
8336
- <button type="button" class="save-title" data-action="close-metadata">Close</button>
8337
- </div>
8338
- </div>
8339
- </div>
8340
-
8341
- <div class="title-dialog-backdrop" data-ref="name-dialog" hidden
8342
- role="dialog" aria-modal="true" aria-labelledby="mdzip-name-dialog-heading">
8343
- <div class="title-dialog">
8344
- <h3 id="mdzip-name-dialog-heading" data-ref="name-dialog-heading">New Markdown File</h3>
8345
- <input type="text" maxlength="260" data-ref="name-input" aria-label="File name" />
8346
- <p class="title-dialog-validation" data-ref="name-validation" hidden></p>
8347
- <div class="title-dialog-actions">
8348
- <button type="button" data-action="cancel-name">Cancel</button>
8349
- <button type="button" class="save-title" data-ref="name-confirm-btn">Create</button>
8350
- </div>
8351
- </div>
8352
- </div>
8353
-
8354
- <div class="title-dialog-backdrop" data-ref="delete-dialog" hidden
8355
- role="dialog" aria-modal="true" aria-labelledby="mdzip-delete-dialog-heading">
8356
- <div class="title-dialog">
8357
- <h3 id="mdzip-delete-dialog-heading">Delete File?</h3>
8358
- <p data-ref="delete-dialog-text"></p>
8359
- <div class="title-dialog-actions">
8360
- <button type="button" data-action="cancel-delete">Cancel</button>
8361
- <button type="button" class="danger-action" data-ref="delete-confirm-btn">Delete</button>
8362
- </div>
8363
- </div>
8364
- </div>
8365
-
8366
- <input type="file" data-ref="replace-input" hidden />
8367
- <input type="file" data-ref="add-files-input" multiple hidden />
8368
-
8369
- <div class="nav-context-menu" data-ref="nav-menu" hidden role="menu"></div>
8370
-
8371
- <div class="mdzip-tooltip" data-ref="tooltip" role="tooltip" hidden></div>
8372
-
8373
- <div class="mdzip-copy-toast" data-ref="copy-toast" role="status" aria-live="polite" hidden></div>
8374
-
8375
- <p class="mdzip-empty" data-ref="empty-state">No MDZip workspace loaded.</p>
8376
- </section>
9565
+ const SHELL_HTML = `
9566
+ <section class="mdzip-root">
9567
+ <div class="document-strip" data-ref="document-strip" hidden>
9568
+ <button type="button" class="title-button" data-ref="title-btn"></button>
9569
+ <button type="button" class="document-info-button" data-ref="document-info-btn"
9570
+ title="Document information" aria-label="Document information">
9571
+ ${INFO_ICON_HTML}
9572
+ </button>
9573
+ </div>
9574
+
9575
+ <header class="toolbar" data-ref="toolbar" hidden>
9576
+ <div class="toolbar-start">
9577
+ <div class="toolbar-left">
9578
+ <button type="button" class="icon-toggle nav-toggle" data-ref="nav-btn" title="Toggle contents" aria-label="Toggle contents">
9579
+ ${NAV_TOGGLE_ICON_HTML}
9580
+ </button>
9581
+ </div>
9582
+
9583
+ <div class="edit-toolbar" data-ref="edit-toolbar" role="toolbar" aria-label="Editing">
9584
+ <div class="edit-toolbar-group">
9585
+ <button type="button" data-format="bold" data-format-control="bold" title="Bold" aria-label="Bold">${BOLD_ICON_HTML}</button>
9586
+ <button type="button" data-format="italic" data-format-control="italic" title="Italic" aria-label="Italic">${ITALIC_ICON_HTML}</button>
9587
+ <button type="button" data-format="strike" data-format-control="strikethrough" title="Strikethrough" aria-label="Strikethrough">${STRIKE_ICON_HTML}</button>
9588
+ <div class="format-menu" data-format-control="headings">
9589
+ <button type="button" class="format-menu-toggle" data-format-menu-toggle
9590
+ aria-label="Heading" aria-haspopup="menu" aria-expanded="false">
9591
+ ${HEADING_ICON_HTML}${CHEVRON_ICON_HTML}
9592
+ </button>
9593
+ <div class="format-menu-popover" data-format-menu role="menu" aria-label="Heading level" hidden>
9594
+ <button type="button" role="menuitem" data-format="paragraph">Paragraph</button>
9595
+ <button type="button" role="menuitem" data-format="heading-1" data-heading-level="1"><strong>H1</strong> Heading 1</button>
9596
+ <button type="button" role="menuitem" data-format="heading-2" data-heading-level="2"><strong>H2</strong> Heading 2</button>
9597
+ <button type="button" role="menuitem" data-format="heading-3" data-heading-level="3"><strong>H3</strong> Heading 3</button>
9598
+ <button type="button" role="menuitem" data-format="heading-4" data-heading-level="4"><strong>H4</strong> Heading 4</button>
9599
+ <button type="button" role="menuitem" data-format="heading-5" data-heading-level="5"><strong>H5</strong> Heading 5</button>
9600
+ <button type="button" role="menuitem" data-format="heading-6" data-heading-level="6"><strong>H6</strong> Heading 6</button>
9601
+ </div>
9602
+ </div>
9603
+ </div>
9604
+ <span class="edit-toolbar-divider" aria-hidden="true"></span>
9605
+ <div class="edit-toolbar-group">
9606
+ <button type="button" data-format="bullet-list" data-format-control="bulletList" title="Bulleted list" aria-label="Bulleted list">${BULLET_LIST_ICON_HTML}</button>
9607
+ <button type="button" data-format="ordered-list" data-format-control="orderedList" title="Numbered list" aria-label="Numbered list">${ORDERED_LIST_ICON_HTML}</button>
9608
+ <div class="format-menu" data-format-control="code">
9609
+ <button type="button" class="format-menu-toggle" data-format-menu-toggle
9610
+ aria-label="Code" aria-haspopup="menu" aria-expanded="false">
9611
+ ${CODE_ICON_HTML}${CHEVRON_ICON_HTML}
9612
+ </button>
9613
+ <div class="format-menu-popover" data-format-menu role="menu" aria-label="Code format" hidden>
9614
+ <button type="button" role="menuitem" data-format="code" data-code-kind="inline">Inline code</button>
9615
+ <button type="button" role="menuitem" data-format="code-block" data-code-kind="block">Code block</button>
9616
+ </div>
9617
+ </div>
9618
+ <button type="button" data-format="quote" data-format-control="blockquote" title="Blockquote" aria-label="Blockquote">${QUOTE_ICON_HTML}</button>
9619
+ <button type="button" data-format="line-break" data-format-control="lineBreak" title="Line break" aria-label="Line break">${LINE_BREAK_ICON_HTML}</button>
9620
+ </div>
9621
+ <span class="edit-toolbar-divider" aria-hidden="true"></span>
9622
+ <div class="edit-toolbar-group">
9623
+ <button type="button" data-format="link" data-format-control="link" title="Link" aria-label="Link">${LINK_ICON_HTML}</button>
9624
+ <button type="button" data-format="image" data-format-control="image" title="Image" aria-label="Image">${IMAGE_FORMAT_ICON_HTML}</button>
9625
+ <input type="file" data-ref="image-input" accept="image/*" hidden />
9626
+ </div>
9627
+ <span class="edit-toolbar-divider" aria-hidden="true"></span>
9628
+ <div class="edit-toolbar-group">
9629
+ <button type="button" data-ref="format-json-btn" data-format-control="formatJson"
9630
+ title="Format JSON (Shift+Alt+F)" aria-label="Format JSON">${FORMAT_JSON_ICON_HTML}</button>
9631
+ <button type="button" class="edit-toolbar-toggle" data-ref="whitespace-btn" data-format-control="whitespace"
9632
+ title="Show whitespace" aria-label="Show whitespace" aria-pressed="false">${WHITESPACE_ICON_HTML}</button>
9633
+ </div>
9634
+ </div>
9635
+ </div>
9636
+
9637
+ <div class="toolbar-buttons view-mode-toggle-group" data-ref="layout-controls" role="group" aria-label="Editor layout">
9638
+ <button type="button" class="icon-toggle view-mode-toggle" data-ref="source-btn" title="Edit" aria-label="Edit" aria-pressed="false">
9639
+ <span class="commandbar-flex-container" data-ref="source-icon">${SOURCE_EDIT_ICON_HTML}</span>
9640
+ </button>
9641
+ <button type="button" class="icon-toggle view-mode-toggle" data-ref="split-btn" title="Split" aria-label="Split" aria-pressed="false">
9642
+ <span class="commandbar-flex-container">
9643
+ ${SPLIT_ICON_HTML}
9644
+ </span>
9645
+ </button>
9646
+ <button type="button" class="icon-toggle view-mode-toggle" data-ref="preview-btn" title="View" aria-label="View" aria-pressed="false">
9647
+ <span class="commandbar-flex-container">
9648
+ ${PREVIEW_ICON_HTML}
9649
+ </span>
9650
+ </button>
9651
+ </div>
9652
+
9653
+ <div class="toolbar-controls" data-ref="toolbar-controls">
9654
+ <button type="button" class="icon-toggle outline-toggle" data-ref="outline-btn" title="Outline" aria-label="Outline" aria-pressed="false">
9655
+ ${OUTLINE_ICON_HTML}
9656
+ </button>
9657
+ <button type="button" class="icon-toggle" data-ref="search-btn" title="Find/replace (Mod-F)" aria-label="Find/replace">
9658
+ ${SEARCH_ICON_HTML}
9659
+ </button>
9660
+ <button type="button" class="icon-toggle" data-ref="save-btn" title="Save" aria-label="Save">
9661
+ ${SAVE_ICON_HTML}
9662
+ </button>
9663
+ <button type="button" class="icon-toggle zoom-toggle" data-ref="zoom-btn" title="Zoom controls" aria-label="Zoom controls">
9664
+ ${ZOOM_ICON_HTML}
9665
+ </button>
9666
+ <div class="toolbar-menu width-menu" data-ref="width-controls">
9667
+ <button type="button" class="icon-toggle toolbar-menu-toggle" data-ref="width-menu-btn"
9668
+ title="Page width" aria-label="Page width" aria-haspopup="menu" aria-expanded="false">
9669
+ <span class="toolbar-menu-icon" data-ref="width-menu-icon">${PAGE_WIDTH_DEFAULT_ICON_HTML}</span>
9670
+ </button>
9671
+ <div class="toolbar-popover" data-ref="width-popover" role="menu" aria-label="Page width" hidden>
9672
+ ${['narrow', 'default', 'wide', 'full'].map((choice) => `
9673
+ <button type="button" role="menuitemradio" class="icon-toggle toolbar-menu-item" data-width="${choice}"
9674
+ title="${PREVIEW_WIDTH_LABELS[choice]}" aria-label="${PREVIEW_WIDTH_LABELS[choice]}" aria-checked="false">
9675
+ ${PREVIEW_WIDTH_ICONS_HTML[choice]}
9676
+ </button>`).join('')}
9677
+ </div>
9678
+ </div>
9679
+ <div class="theme-menu" data-ref="theme-controls">
9680
+ <button type="button" class="icon-toggle theme-menu-toggle" data-ref="theme-menu-btn"
9681
+ title="Color scheme" aria-label="Color scheme" aria-haspopup="menu" aria-expanded="false">
9682
+ <span class="theme-menu-icon" data-ref="theme-menu-icon">${SYSTEM_THEME_ICON_HTML}</span>
9683
+ </button>
9684
+ <div class="theme-popover" data-ref="theme-popover" role="menu" aria-label="Color scheme" hidden>
9685
+ <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="light-theme-btn"
9686
+ title="Light mode" aria-label="Light mode" aria-checked="false">
9687
+ ${LIGHT_THEME_ICON_HTML}
9688
+ </button>
9689
+ <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="dark-theme-btn"
9690
+ title="Dark mode" aria-label="Dark mode" aria-checked="false">
9691
+ ${DARK_THEME_ICON_HTML}
9692
+ </button>
9693
+ <button type="button" role="menuitemradio" class="icon-toggle theme-toggle" data-ref="system-theme-btn"
9694
+ title="System setting" aria-label="System setting" aria-checked="false">
9695
+ ${SYSTEM_THEME_ICON_HTML}
9696
+ </button>
9697
+ </div>
9698
+ </div>
9699
+ <div class="zoom-popover" data-ref="zoom-popover" hidden role="group" aria-label="Zoom">
9700
+ <span class="zoom-level" data-ref="zoom-level">100%</span>
9701
+ <span class="zoom-stepper">
9702
+ <button type="button" data-action="zoom-out" title="Zoom out" aria-label="Zoom out">-</button>
9703
+ <button type="button" data-action="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
9704
+ </span>
9705
+ <button type="button" class="zoom-reset" data-action="zoom-reset" title="Reset zoom">Reset</button>
9706
+ </div>
9707
+ </div>
9708
+ </header>
9709
+
9710
+ <div class="workspace-shell" data-ref="workspace-shell" hidden>
9711
+ <aside class="nav-pane" data-ref="nav-pane" aria-label="Package contents">
9712
+ <div class="nav-tree" data-ref="nav-tree"></div>
9713
+ </aside>
9714
+ <div class="nav-resizer" data-ref="nav-resizer"
9715
+ role="separator" aria-orientation="vertical" aria-label="Resize contents pane"></div>
9716
+
9717
+ <div class="pane-stack" data-ref="pane-stack">
9718
+ <section class="pane edit-pane" data-ref="edit-pane">
9719
+ <div class="editor-host" data-ref="editor-host"></div>
9720
+ <div class="json-status" data-ref="json-status" role="status" aria-live="polite" hidden></div>
9721
+ </section>
9722
+ <div class="split-resizer" data-ref="split-resizer"
9723
+ role="separator" aria-orientation="vertical" aria-label="Resize split panes"></div>
9724
+ <section class="pane preview-pane" data-ref="preview-pane" tabindex="-1">
9725
+ <article class="preview-content" data-ref="preview-content"></article>
9726
+ </section>
9727
+ <div class="preview-find" data-ref="preview-find" role="search" aria-label="Find in document" hidden>
9728
+ <input type="text" class="preview-find-input" data-ref="preview-find-input"
9729
+ placeholder="Find" aria-label="Find in document" spellcheck="false" autocomplete="off" />
9730
+ <span class="preview-find-count" data-ref="preview-find-count" aria-live="polite"></span>
9731
+ <button type="button" class="preview-find-button" data-ref="preview-find-case"
9732
+ aria-pressed="false" title="Match case" aria-label="Match case">${FIND_CASE_ICON_HTML}</button>
9733
+ <button type="button" class="preview-find-button" data-ref="preview-find-previous"
9734
+ title="Previous match (Shift+Enter)" aria-label="Previous match">${FIND_PREVIOUS_ICON_HTML}</button>
9735
+ <button type="button" class="preview-find-button" data-ref="preview-find-next"
9736
+ title="Next match (Enter)" aria-label="Next match">${FIND_NEXT_ICON_HTML}</button>
9737
+ <button type="button" class="preview-find-button" data-ref="preview-find-close"
9738
+ title="Close (Escape)" aria-label="Close find">${FIND_CLOSE_ICON_HTML}</button>
9739
+ </div>
9740
+ <section class="pane entry-pane" data-ref="entry-pane"></section>
9741
+ </div>
9742
+ <aside class="outline-pane" data-ref="outline-pane" hidden></aside>
9743
+ <div class="outline-resizer" data-ref="outline-resizer"
9744
+ role="separator" aria-orientation="vertical" aria-label="Resize outline"></div>
9745
+ </div>
9746
+
9747
+ <div class="title-dialog-backdrop" data-ref="title-dialog" hidden
9748
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-title-dialog-heading">
9749
+ <div class="title-dialog">
9750
+ <h3 id="mdzip-title-dialog-heading">Set Document Title</h3>
9751
+ <p>This is the package-level title stored in manifest.json.</p>
9752
+ <input type="text" maxlength="120" data-ref="title-input" aria-label="Document title" />
9753
+ <p class="title-dialog-validation" data-ref="title-validation" hidden>Title cannot be empty.</p>
9754
+ <p>If unset, consumers may fall back to entry point, filename, or first heading.</p>
9755
+ <div class="title-dialog-actions">
9756
+ <button type="button" class="reset-title" data-ref="title-reset-btn">Reset</button>
9757
+ <button type="button" data-action="cancel-title">Cancel</button>
9758
+ <button type="button" class="save-title" data-ref="title-save-btn">Save</button>
9759
+ </div>
9760
+ </div>
9761
+ </div>
9762
+
9763
+ <div class="title-dialog-backdrop" data-ref="conversion-dialog" hidden
9764
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-conversion-dialog-heading">
9765
+ <div class="title-dialog">
9766
+ <h3 id="mdzip-conversion-dialog-heading">Convert to MDZ?</h3>
9767
+ <p>
9768
+ Regular Markdown files contain only text. Convert this document to an
9769
+ MDZ package to add images, package navigation, and document metadata.
9770
+ </p>
9771
+ <p>The next save will produce an .mdz file.</p>
9772
+ <div class="title-dialog-actions">
9773
+ <button type="button" data-action="cancel-conversion">Cancel</button>
9774
+ <button type="button" class="save-title" data-ref="conversion-confirm-btn">Convert</button>
9775
+ </div>
9776
+ </div>
9777
+ </div>
9778
+
9779
+ <div class="title-dialog-backdrop" data-ref="image-insert-dialog" hidden
9780
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-image-insert-dialog-heading">
9781
+ <div class="title-dialog image-insert-dialog">
9782
+ <h3 id="mdzip-image-insert-dialog-heading">Insert Image</h3>
9783
+ <p>Choose the Markdown inserted for this image.</p>
9784
+ <fieldset class="image-insert-options">
9785
+ <legend>Output</legend>
9786
+ <label>
9787
+ <input type="radio" name="mdzip-image-insert-mode" value="markdown"
9788
+ data-ref="image-insert-mode-markdown" checked />
9789
+ Markdown image
9790
+ </label>
9791
+ <label>
9792
+ <input type="radio" name="mdzip-image-insert-mode" value="html"
9793
+ data-ref="image-insert-mode-html" />
9794
+ HTML &lt;img&gt; with sizing
9795
+ </label>
9796
+ </fieldset>
9797
+ <label class="image-insert-field">
9798
+ <span>Alt text</span>
9799
+ <input type="text" data-ref="image-insert-alt" />
9800
+ </label>
9801
+ <div class="image-insert-grid">
9802
+ <label class="image-insert-field">
9803
+ <span>Size by</span>
9804
+ <select data-ref="image-insert-size-mode">
9805
+ <option value="original">Original size</option>
9806
+ <option value="width" selected>Width</option>
9807
+ <option value="height">Height</option>
9808
+ <option value="percent">Percent</option>
9809
+ </select>
9810
+ </label>
9811
+ <label class="image-insert-field">
9812
+ <span>Value</span>
9813
+ <input type="number" min="1" step="1" data-ref="image-insert-size-value" />
9814
+ </label>
9815
+ </div>
9816
+ <label class="image-insert-field">
9817
+ <span>Position</span>
9818
+ <select data-ref="image-insert-position">
9819
+ <option value="inline">Inline/default</option>
9820
+ <option value="left">Left</option>
9821
+ <option value="center">Center</option>
9822
+ <option value="right">Right</option>
9823
+ <option value="wrap-left">Wrap left</option>
9824
+ <option value="wrap-right">Wrap right</option>
9825
+ </select>
9826
+ </label>
9827
+ <div class="title-dialog-actions">
9828
+ <button type="button" data-action="cancel-image-insert">Cancel</button>
9829
+ <button type="button" class="save-title" data-ref="image-insert-confirm-btn">Insert</button>
9830
+ </div>
9831
+ </div>
9832
+ </div>
9833
+
9834
+ <div class="title-dialog-backdrop" data-ref="pack-files-dialog" hidden
9835
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-pack-files-dialog-heading">
9836
+ <div class="title-dialog pack-files-dialog">
9837
+ <h3 id="mdzip-pack-files-dialog-heading">Package Markdown Files</h3>
9838
+ <p>These files contain more than one Markdown document. Choose how to package them.</p>
9839
+ <fieldset class="pack-files-options">
9840
+ <legend>Mode</legend>
9841
+ <label>
9842
+ <input type="radio" name="mdzip-pack-files-mode" value="document"
9843
+ data-ref="pack-files-mode-document" checked />
9844
+ Document — one primary page; the rest are attached
9845
+ </label>
9846
+ <label>
9847
+ <input type="radio" name="mdzip-pack-files-mode" value="project"
9848
+ data-ref="pack-files-mode-project" />
9849
+ Project — a set of related documents
9850
+ </label>
9851
+ </fieldset>
9852
+ <label class="pack-files-field">
9853
+ <span>Entry point</span>
9854
+ <select data-ref="pack-files-entry"></select>
9855
+ </label>
9856
+ <div class="title-dialog-actions">
9857
+ <button type="button" data-action="cancel-pack-files">Cancel</button>
9858
+ <button type="button" class="save-title" data-ref="pack-files-confirm-btn">Package</button>
9859
+ </div>
9860
+ </div>
9861
+ </div>
9862
+
9863
+ <div class="title-dialog-backdrop" data-ref="copy-render-dialog" hidden
9864
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-copy-render-dialog-heading">
9865
+ <div class="title-dialog copy-render-dialog">
9866
+ <h3 id="mdzip-copy-render-dialog-heading" data-ref="copy-render-heading">Copying document...</h3>
9867
+ <div data-ref="copy-render-progress-section">
9868
+ <p data-ref="copy-render-progress-text">Rendering the full document...</p>
9869
+ <div class="copy-render-progress-track">
9870
+ <div class="copy-render-progress-bar" data-ref="copy-render-progress-bar"></div>
9871
+ </div>
9872
+ </div>
9873
+ <p data-ref="copy-render-ready-text" hidden>
9874
+ The document is ready. Browsers only allow a clipboard write right after a click, so this needs one more —
9875
+ click Copy to finish.
9876
+ </p>
9877
+ <p data-ref="copy-render-done-text" hidden></p>
9878
+ <div class="title-dialog-actions">
9879
+ <button type="button" data-action="cancel-copy-render" data-ref="copy-render-cancel-btn">Cancel</button>
9880
+ <button type="button" data-action="cancel-copy-ready" data-ref="copy-render-ready-cancel-btn" hidden>Cancel</button>
9881
+ <button type="button" class="save-title" data-action="confirm-copy-ready" data-ref="copy-render-confirm-btn" hidden>Copy</button>
9882
+ <button type="button" class="save-title" data-action="dismiss-copy-render" data-ref="copy-render-dismiss-btn" hidden>Dismiss</button>
9883
+ </div>
9884
+ </div>
9885
+ </div>
9886
+
9887
+ <div class="title-dialog-backdrop" data-ref="metadata-dialog" hidden
9888
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-metadata-dialog-heading">
9889
+ <div class="title-dialog metadata-dialog">
9890
+ <h3 id="mdzip-metadata-dialog-heading">Document Information</h3>
9891
+ <dl data-ref="metadata-list"></dl>
9892
+ <h4>Libraries</h4>
9893
+ <dl data-ref="library-list"></dl>
9894
+ <div class="title-dialog-actions">
9895
+ <button type="button" class="save-title" data-action="close-metadata">Close</button>
9896
+ </div>
9897
+ </div>
9898
+ </div>
9899
+
9900
+ <div class="title-dialog-backdrop" data-ref="name-dialog" hidden
9901
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-name-dialog-heading">
9902
+ <div class="title-dialog">
9903
+ <h3 id="mdzip-name-dialog-heading" data-ref="name-dialog-heading">New Markdown File</h3>
9904
+ <input type="text" maxlength="260" data-ref="name-input" aria-label="File name" />
9905
+ <p class="title-dialog-validation" data-ref="name-validation" hidden></p>
9906
+ <div class="title-dialog-actions">
9907
+ <button type="button" data-action="cancel-name">Cancel</button>
9908
+ <button type="button" class="save-title" data-ref="name-confirm-btn">Create</button>
9909
+ </div>
9910
+ </div>
9911
+ </div>
9912
+
9913
+ <div class="title-dialog-backdrop" data-ref="delete-dialog" hidden
9914
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-delete-dialog-heading">
9915
+ <div class="title-dialog">
9916
+ <h3 id="mdzip-delete-dialog-heading">Delete File?</h3>
9917
+ <p data-ref="delete-dialog-text"></p>
9918
+ <div class="title-dialog-actions">
9919
+ <button type="button" data-action="cancel-delete">Cancel</button>
9920
+ <button type="button" class="danger-action" data-ref="delete-confirm-btn">Delete</button>
9921
+ </div>
9922
+ </div>
9923
+ </div>
9924
+
9925
+ <div class="title-dialog-backdrop" data-ref="confirm-dialog" hidden
9926
+ role="dialog" aria-modal="true" aria-labelledby="mdzip-confirm-dialog-heading">
9927
+ <div class="title-dialog">
9928
+ <h3 id="mdzip-confirm-dialog-heading" data-ref="confirm-dialog-title"></h3>
9929
+ <p data-ref="confirm-dialog-text"></p>
9930
+ <div class="title-dialog-actions">
9931
+ <button type="button" data-action="cancel-confirm">Cancel</button>
9932
+ <button type="button" class="danger-action" data-ref="confirm-dialog-ok"></button>
9933
+ </div>
9934
+ </div>
9935
+ </div>
9936
+
9937
+ <input type="file" data-ref="replace-input" hidden />
9938
+ <input type="file" data-ref="add-files-input" multiple hidden />
9939
+
9940
+ <div class="nav-context-menu" data-ref="nav-menu" hidden role="menu"></div>
9941
+
9942
+ <div class="mdzip-tooltip" data-ref="tooltip" role="tooltip" hidden></div>
9943
+
9944
+ <div class="mdzip-copy-toast" data-ref="copy-toast" role="status" aria-live="polite" hidden></div>
9945
+
9946
+ <p class="mdzip-empty" data-ref="empty-state">No MDZip workspace loaded.</p>
9947
+ </section>
8377
9948
  `;
8378
9949
  //# sourceMappingURL=view.js.map