@dooc-dev/dooc 0.0.4 → 0.0.5

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 (95) hide show
  1. package/dist/cli.js +41 -3
  2. package/dist/compiler/asset-references.d.ts +4 -0
  3. package/dist/compiler/asset-references.js +117 -0
  4. package/dist/compiler/bundle-urls.d.ts +1 -1
  5. package/dist/compiler/bundle-urls.js +15 -5
  6. package/dist/compiler/check.js +8 -5
  7. package/dist/compiler/code-languages.js +7 -2
  8. package/dist/compiler/compile.d.ts +5 -0
  9. package/dist/compiler/compile.js +105 -10
  10. package/dist/compiler/config.js +2 -1
  11. package/dist/compiler/export.d.ts +4 -0
  12. package/dist/compiler/export.js +140 -0
  13. package/dist/compiler/figures.js +4 -0
  14. package/dist/compiler/files.js +80 -41
  15. package/dist/compiler/fonts.js +4 -1
  16. package/dist/compiler/icons.d.ts +1 -1
  17. package/dist/compiler/icons.js +11 -2
  18. package/dist/compiler/ignored-files.d.ts +3 -0
  19. package/dist/compiler/ignored-files.js +68 -0
  20. package/dist/compiler/locales.js +13 -8
  21. package/dist/compiler/ops.d.ts +6 -0
  22. package/dist/compiler/ops.js +98 -7
  23. package/dist/compiler/subformats.d.ts +24 -0
  24. package/dist/compiler/subformats.js +299 -0
  25. package/dist/compiler/textfile.js +3 -0
  26. package/dist/compiler/theme-variants.js +5 -2
  27. package/dist/core/content-metadata.d.ts +15 -6
  28. package/dist/core/content-metadata.js +278 -17
  29. package/dist/core/content-types.d.ts +3 -1
  30. package/dist/core/figure-frame.js +19 -1
  31. package/dist/core/files.d.ts +2 -1
  32. package/dist/core/files.js +6 -8
  33. package/dist/core/flow-base-css.generated.js +1 -1
  34. package/dist/core/html.js +3 -3
  35. package/dist/core/icons.d.ts +3 -0
  36. package/dist/core/icons.js +3 -0
  37. package/dist/core/json-tools.d.ts +1 -0
  38. package/dist/core/json-tools.js +12 -0
  39. package/dist/core/routing.d.ts +5 -2
  40. package/dist/core/routing.js +17 -5
  41. package/dist/core/subformat-record.d.ts +3 -0
  42. package/dist/core/subformat-record.js +131 -0
  43. package/dist/core/subformats.d.ts +43 -0
  44. package/dist/core/subformats.js +81 -0
  45. package/dist/core/toc-ui.js +25 -23
  46. package/dist/edit.global.js +322 -95
  47. package/dist/mcp.js +50 -9
  48. package/dist/plugins/index.d.ts +1 -0
  49. package/dist/plugins/transport.d.ts +22 -0
  50. package/dist/plugins/transport.js +1 -0
  51. package/dist/plugins.global.js +128 -0
  52. package/dist/subformats.global.js +127 -0
  53. package/dist/ui.global.js +91 -38
  54. package/dist/viewer/build-plugins.d.ts +7 -0
  55. package/dist/viewer/build-plugins.js +70 -0
  56. package/dist/viewer/build.d.ts +9 -0
  57. package/dist/viewer/build.js +32 -5
  58. package/dist/viewer/editor-tools.d.ts +7 -7
  59. package/dist/viewer/editor-tools.js +36 -5
  60. package/dist/viewer/font-picker.js +5 -1
  61. package/dist/viewer/git-diff.d.ts +3 -0
  62. package/dist/viewer/git-diff.js +47 -0
  63. package/dist/viewer/hmr.js +4 -1
  64. package/dist/viewer/i18n.js +7 -5
  65. package/dist/viewer/language-picker.d.ts +2 -2
  66. package/dist/viewer/language-picker.js +26 -9
  67. package/dist/viewer/lazy-graph.d.ts +2 -0
  68. package/dist/viewer/lazy-graph.js +30 -0
  69. package/dist/viewer/locales/eng.json +72 -10
  70. package/dist/viewer/locales/jpn.json +73 -11
  71. package/dist/viewer/locales/zho.json +73 -11
  72. package/dist/viewer/nav-focus.js +8 -1
  73. package/dist/viewer/nav-update.d.ts +2 -0
  74. package/dist/viewer/nav-update.js +117 -0
  75. package/dist/viewer/plugin-style.d.ts +1 -0
  76. package/dist/viewer/plugin-style.js +82 -0
  77. package/dist/viewer/resize.d.ts +0 -2
  78. package/dist/viewer/resize.js +2 -98
  79. package/dist/viewer/resource-library.d.ts +10 -8
  80. package/dist/viewer/resource-library.js +179 -30
  81. package/dist/viewer/search.d.ts +4 -2
  82. package/dist/viewer/search.js +252 -53
  83. package/dist/viewer/serve.d.ts +10 -5
  84. package/dist/viewer/serve.js +789 -278
  85. package/dist/viewer/site-icon.js +13 -6
  86. package/dist/viewer/site-title.js +15 -2
  87. package/dist/viewer/textfile.d.ts +3 -0
  88. package/dist/viewer/textfile.js +19 -2
  89. package/dist/viewer/theme-picker.d.ts +2 -0
  90. package/dist/viewer/theme-picker.js +24 -8
  91. package/dist/viewer/workspace.d.ts +2 -0
  92. package/dist/viewer/workspace.js +46 -1
  93. package/package.json +24 -9
  94. package/dist/compiler/bundle.d.ts +0 -2
  95. package/dist/compiler/bundle.js +0 -100
@@ -1,7 +1,8 @@
1
1
  import { inlineSegmenter } from "../core/inline.js";
2
2
  import { docPath } from "../core/routing.js";
3
3
  import { docDisplayName } from "../core/taxonomy.js";
4
- export const searchIndex = (site) => {
4
+ /** `files` are workspace files that open at /_files/file/<path> (edit mode only). */
5
+ export const searchIndex = (site, files = []) => {
5
6
  const parents = new Set(site.entries.map((entry) => entry.parent));
6
7
  const segments = inlineSegmenter({ terms: site.ctx.terms });
7
8
  const plain = (text) => segments(text)
@@ -55,23 +56,22 @@ export const searchIndex = (site) => {
55
56
  .join(" ");
56
57
  }
57
58
  };
58
- return site.entries.flatMap((entry) => {
59
+ const docs = site.entries.flatMap((entry) => {
59
60
  const base = {
60
61
  path: docPath(site.entries, entry.id),
61
- file: entry.file,
62
- folder: parents.has(entry.id),
62
+ file: entry.sourceFile ?? entry.file,
63
63
  title: docDisplayName(entry.frontmatter, entry.id),
64
- };
65
- let section = {
66
- ...base,
67
64
  heading: "",
68
65
  anchor: "",
69
66
  text: "",
70
67
  };
71
- const sections = [section];
68
+ let section = { ...base, kind: "text" };
69
+ const sections = [section, { ...base, kind: "file" }];
70
+ if (parents.has(entry.id))
71
+ sections.push({ ...base, kind: "folder", file: `${base.path}/` });
72
72
  for (const block of entry.blocks) {
73
73
  if (block.type === "h") {
74
- section = { ...base, heading: plain(block.text), anchor: block.slug, text: "" };
74
+ section = { ...base, kind: "text", heading: plain(block.text), anchor: block.slug };
75
75
  sections.push(section);
76
76
  }
77
77
  else
@@ -79,6 +79,21 @@ export const searchIndex = (site) => {
79
79
  }
80
80
  return sections.map((item) => ({ ...item, text: item.text.replace(/\s+/g, " ").trim() }));
81
81
  });
82
+ const sources = new Set(docs.map((section) => section.file));
83
+ return [
84
+ ...docs,
85
+ ...files
86
+ .filter((file) => !sources.has(file))
87
+ .map((file) => ({
88
+ kind: "file",
89
+ path: `/_files/file/${encodeURIComponent(file)}`,
90
+ file,
91
+ title: file.split("/").pop() ?? file,
92
+ heading: "",
93
+ anchor: "",
94
+ text: "",
95
+ })),
96
+ ];
82
97
  };
83
98
  // Self-contained: the viewer embeds this function in offline HTML as well.
84
99
  export const searchSections = (index, query, currentPath = "") => {
@@ -89,21 +104,27 @@ export const searchSections = (index, query, currentPath = "") => {
89
104
  const seen = new Set();
90
105
  return index
91
106
  .flatMap((section) => {
107
+ if (section.kind !== "text") {
108
+ // File names match on the basename, so "md" or ".md" finds extensions.
109
+ const name = normalize(section.kind === "file" ? (section.file.split("/").pop() ?? "") : section.file);
110
+ if (!words.every((word) => name.includes(word)))
111
+ return [];
112
+ // A folder document also matches as its own file; prefer showing it as a folder.
113
+ const score = (section.kind === "folder" ? 25 : 20) * words.length +
114
+ (name === words.join(" ") ? 100 : 0);
115
+ return [{ ...section, snippet: "", score }];
116
+ }
92
117
  const title = normalize(section.title);
93
118
  const heading = normalize(section.heading);
94
119
  const text = section.text.normalize("NFKC");
95
120
  const body = text.toLowerCase();
96
- const name = section.anchor ? "" : normalize(`${section.file} ${section.path}`);
97
- const all = `${title} ${heading} ${body} ${name}`;
121
+ const all = `${title} ${heading} ${body}`;
98
122
  if (!words.every((word) => all.includes(word)))
99
123
  return [];
100
124
  if (section.anchor && !words.some((word) => `${heading} ${body}`.includes(word)))
101
125
  return [];
102
126
  const score = (title === words.join(" ") ? 100 : 0) +
103
- words.reduce((sum, word) => sum +
104
- (title.includes(word) ? 10 : 0) +
105
- (name.includes(word) ? 10 : 0) +
106
- (heading.includes(word) ? 5 : 0), 0);
127
+ words.reduce((sum, word) => sum + (title.includes(word) ? 10 : 0) + (heading.includes(word) ? 5 : 0), 0);
107
128
  const matches = words.map((word) => body.indexOf(word)).filter((at) => at >= 0);
108
129
  const start = Math.max(0, (matches.length ? Math.min(...matches) : 0) - 45);
109
130
  const snippet = `${start ? "…" : ""}${text.slice(start, start + 180)}${text.length > start + 180 ? "…" : ""}`;
@@ -127,17 +148,31 @@ export const SEARCH_LABELS = [
127
148
  "Could not load search. Press Ctrl+F to retry.",
128
149
  "{count} results",
129
150
  "Showing {shown} of {count} results",
130
- "Folder",
151
+ "Matches text",
152
+ "Matches file name",
153
+ "Matches folder name",
131
154
  "Move search",
132
155
  "Resize search",
156
+ "Close search",
157
+ "Move search to sidebar",
158
+ "Float search",
159
+ "Copy path",
160
+ "Copied",
161
+ "Copy failed",
133
162
  ];
134
163
  // Embedded by page(); keep browser behavior independent of the editor bundle.
135
164
  export const mountSearch = (initial, search, labels, published) => {
165
+ const svg = (d, size = 14) => `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
166
+ const kinds = {
167
+ text: { icon: svg("M5 6h14M5 11h14M5 16h9"), label: "Matches text" },
168
+ file: { icon: svg("M6 3h8l4 4v14H6zM14 3v4h4"), label: "Matches file name" },
169
+ folder: { icon: svg("M3 6h6l2 2h10v11H3z"), label: "Matches folder name" },
170
+ };
136
171
  const dialog = document.createElement("dialog");
137
172
  dialog.id = "doc-search";
138
173
  dialog.setAttribute("aria-label", labels["Search documents"] ?? "Search documents");
139
- dialog.innerHTML = `<div class="search-head"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m16 16 4 4"/></svg><input id="doc-search-input" type="search" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="doc-search-results" autocomplete="off" spellcheck="false"></div><div class="search-status" role="status" aria-live="polite"></div><div id="doc-search-results" role="listbox"></div><div class="search-grip search-grip-left" role="button" tabindex="0"></div><div class="search-grip search-grip-right" role="button" tabindex="0"></div><div class="search-resize" role="button" tabindex="0"></div>`;
140
- document.body.append(dialog);
174
+ dialog.innerHTML = `<div class="search-grip" role="button" tabindex="0" data-label="Move search"></div><div class="search-head">${svg("M10.5 4a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM16 16l4 4", 18)}<input id="doc-search-input" type="search" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-controls="doc-search-results" autocomplete="off" spellcheck="false"><button type="button" class="search-dock"></button><button type="button" class="search-close" data-label="Close search">${svg("M6 6l12 12M18 6 6 18")}</button></div><div class="search-status" role="status" aria-live="polite"></div><div id="doc-search-results" role="listbox"></div><div class="search-resize search-resize-x" role="button" tabindex="0" data-axis="x" data-label="Resize search"></div><div class="search-resize search-resize-y" role="button" tabindex="0" data-axis="y" data-label="Resize search"></div><div class="search-resize search-resize-xy" data-axis="xy" aria-hidden="true"></div><div class="search-resize search-resize-w" role="button" tabindex="0" data-axis="w" data-label="Resize search"></div>`;
175
+ document.body.insertBefore(dialog, document.getElementById("panel"));
141
176
  const input = dialog.querySelector("input");
142
177
  const results = dialog.querySelector("#doc-search-results");
143
178
  const status = dialog.querySelector(".search-status");
@@ -155,6 +190,37 @@ export const mountSearch = (initial, search, labels, published) => {
155
190
  const currentPath = () => published
156
191
  ? location.hash.slice(1).split(/[?#]/)[0] || initial[0]?.path || ""
157
192
  : location.pathname;
193
+ // Wrap query words in <mark>, comparing each character the way searchSections() does.
194
+ const highlight = (target, text, words) => {
195
+ let folded = "";
196
+ const source = [];
197
+ for (let i = 0; i < text.length; i++) {
198
+ const part = (text[i] ?? "").normalize("NFKC").toLowerCase();
199
+ folded += part;
200
+ for (let j = 0; j < part.length; j++)
201
+ source.push(i);
202
+ }
203
+ const marked = [];
204
+ for (const word of words)
205
+ for (let at = folded.indexOf(word); at >= 0; at = folded.indexOf(word, at + 1))
206
+ for (let i = source[at] ?? 0; i <= (source[at + word.length - 1] ?? -1); i++)
207
+ marked[i] = true;
208
+ let start = 0;
209
+ for (let i = 1; i <= text.length; i++) {
210
+ if (i < text.length && !!marked[i] === !!marked[start])
211
+ continue;
212
+ const run = text.slice(start, i);
213
+ if (marked[start]) {
214
+ const mark = document.createElement("mark");
215
+ mark.textContent = run;
216
+ target.append(mark);
217
+ }
218
+ else
219
+ target.append(run);
220
+ start = i;
221
+ }
222
+ return target;
223
+ };
158
224
  const select = (position) => {
159
225
  const items = [...results.querySelectorAll("a")];
160
226
  selected = items.length ? (position + items.length) % items.length : 0;
@@ -169,8 +235,57 @@ export const mountSearch = (initial, search, labels, published) => {
169
235
  else
170
236
  input.removeAttribute("aria-activedescendant");
171
237
  };
238
+ const copyButton = (text) => {
239
+ const button = document.createElement("button");
240
+ button.type = "button";
241
+ button.className = "search-copy";
242
+ const show = (icon, label) => {
243
+ button.innerHTML = icon;
244
+ button.title = t(label);
245
+ button.setAttribute("aria-label", button.title);
246
+ };
247
+ const reset = () => show(svg("M9 9h11v11H9zM5 15H4V4h11v1"), "Copy path");
248
+ reset();
249
+ button.addEventListener("click", () => {
250
+ Promise.resolve()
251
+ .then(() => navigator.clipboard.writeText(text))
252
+ .then(() => show(svg("M5 12l5 5 9-10"), "Copied"), () => show(svg("M6 6l12 12M18 6 6 18"), "Copy failed"))
253
+ .finally(() => setTimeout(reset, 1500));
254
+ });
255
+ return button;
256
+ };
257
+ // Highlight where a clicked result leads, once navigation has shown it.
258
+ let pending;
259
+ let flashing;
260
+ const flash = (target) => {
261
+ pending = target;
262
+ clearInterval(flashing);
263
+ let tries = 0;
264
+ flashing = window.setInterval(() => {
265
+ const element = currentPath() !== target.path
266
+ ? null
267
+ : target.anchor
268
+ ? document.getElementById(target.anchor)
269
+ : (document.querySelector(".resources-pane article") ??
270
+ document.querySelector(".preview-pane.active article") ??
271
+ document.querySelector("main article"));
272
+ if (!element && ++tries < 50)
273
+ return;
274
+ clearInterval(flashing);
275
+ pending = undefined;
276
+ if (!element)
277
+ return;
278
+ element.classList.remove("search-flash");
279
+ void element.offsetWidth; // Restart the animation on repeated jumps.
280
+ element.classList.add("search-flash");
281
+ setTimeout(() => element.classList.remove("search-flash"), 2600);
282
+ }, 100);
283
+ };
172
284
  const render = () => {
173
285
  const hits = search(index, input.value, currentPath());
286
+ const words = [
287
+ ...new Set(input.value.normalize("NFKC").toLowerCase().trim().split(/\s+/)),
288
+ ].filter(Boolean);
174
289
  results.replaceChildren();
175
290
  dialog.classList.toggle("search-filled", input.value.length > 0);
176
291
  for (const [i, hit] of hits.slice(0, 60).entries()) {
@@ -178,32 +293,51 @@ export const mountSearch = (initial, search, labels, published) => {
178
293
  link.id = `doc-search-result-${i}`;
179
294
  link.setAttribute("role", "option");
180
295
  link.tabIndex = -1;
296
+ link.dataset.path = hit.path;
297
+ link.dataset.anchor = hit.anchor;
181
298
  link.href = `${published ? "#" : ""}${hit.path}${!published && language ? `?lang=${encodeURIComponent(language)}` : ""}${hit.anchor ? `#${encodeURIComponent(hit.anchor)}` : ""}`;
182
299
  const meta = document.createElement("div");
183
300
  meta.className = "search-meta";
184
- const folder = hit.folder && !hit.anchor;
185
- const type = document.createElement("small");
186
- type.textContent = folder
187
- ? t("Folder")
188
- : (hit.file.split(".").pop()?.toUpperCase() ?? "");
301
+ const kind = document.createElement("span");
302
+ kind.className = "search-kind";
303
+ kind.innerHTML = kinds[hit.kind].icon;
304
+ kind.title = t(kinds[hit.kind].label);
305
+ kind.setAttribute("role", "img");
306
+ kind.setAttribute("aria-label", kind.title);
189
307
  const path = document.createElement("small");
190
308
  path.className = "search-path";
191
- path.textContent = folder ? `${hit.path}/` : hit.file;
192
- path.title = path.textContent;
193
- meta.append(type, path);
194
- const title = document.createElement("strong");
195
- title.textContent = `${hit.title}${hit.heading ? ` › ${hit.heading}` : ""}`;
196
- const snippet = document.createElement("span");
197
- snippet.textContent = hit.snippet;
198
- link.append(meta, title, snippet);
199
- results.append(link);
309
+ path.title = hit.file;
310
+ // File hits match only the basename, so leave the folder part unmarked.
311
+ const cut = hit.kind === "file" ? hit.file.lastIndexOf("/") + 1 : 0;
312
+ path.append(hit.file.slice(0, cut));
313
+ meta.append(kind, highlight(path, hit.file.slice(cut), words));
314
+ link.append(meta);
315
+ // Name-only hits list just the path; their content has nothing to do with the match.
316
+ const named = hit.kind !== "text";
317
+ if (!named) {
318
+ const title = document.createElement("strong");
319
+ link.append(highlight(title, `${hit.title}${hit.heading ? ` › ${hit.heading}` : ""}`, words));
320
+ }
321
+ if (!named && hit.snippet) {
322
+ const snippet = document.createElement("span");
323
+ snippet.className = "search-snippet";
324
+ link.append(highlight(snippet, hit.snippet, words));
325
+ }
326
+ // The copy button sits beside the option, since buttons cannot nest inside links.
327
+ const item = document.createElement("div");
328
+ item.className = named ? "search-hit search-name" : "search-hit";
329
+ item.setAttribute("role", "none");
330
+ item.append(link);
331
+ if (named)
332
+ item.append(copyButton(hit.file));
333
+ results.append(item);
200
334
  }
201
- status.textContent = loading
202
- ? t("Searching…")
203
- : failed
204
- ? t("Could not load search. Press Ctrl+F to retry.")
205
- : !input.value.trim()
206
- ? ""
335
+ status.textContent = !input.value.trim()
336
+ ? ""
337
+ : loading
338
+ ? t("Searching…")
339
+ : failed
340
+ ? t("Could not load search. Press Ctrl+F to retry.")
207
341
  : !hits.length
208
342
  ? t("No results")
209
343
  : hits.length > 60
@@ -216,16 +350,42 @@ export const mountSearch = (initial, search, labels, published) => {
216
350
  const localize = () => {
217
351
  dialog.setAttribute("aria-label", t("Search documents"));
218
352
  input.setAttribute("aria-label", t("Search documents"));
219
- for (const handle of dialog.querySelectorAll(".search-grip, .search-resize")) {
220
- handle.title = t(handle.classList.contains("search-resize") ? "Resize search" : "Move search");
221
- handle.setAttribute("aria-label", handle.title);
353
+ for (const control of dialog.querySelectorAll("[data-label]")) {
354
+ control.title = t(control.dataset.label ?? "");
355
+ control.setAttribute("aria-label", control.title);
222
356
  }
223
357
  render();
224
358
  };
359
+ const minHeight = 44;
360
+ // Dock between the document and editor; each mode keeps its own inline geometry.
361
+ let docked = false;
362
+ let other = "";
363
+ const dockButton = dialog.querySelector(".search-dock");
364
+ const dock = (value) => {
365
+ if (value !== docked)
366
+ [dialog.style.cssText, other] = [other, dialog.style.cssText];
367
+ docked = value;
368
+ dialog.classList.toggle("search-docked", value);
369
+ dockButton.innerHTML = svg(value ? "M14 4h6v6M20 4l-9 9M18 14v6H4V6h6" : "M4 5h16v14H4zM15 5v14");
370
+ dockButton.dataset.label = value ? "Float search" : "Move search to sidebar";
371
+ dockButton.title = t(dockButton.dataset.label);
372
+ dockButton.setAttribute("aria-label", dockButton.title);
373
+ };
374
+ dock(false);
375
+ dockButton.addEventListener("click", () => {
376
+ dock(!docked);
377
+ input.focus();
378
+ });
225
379
  const position = (rect, dx, dy, resize = false) => {
226
380
  const clamp = (value, min, max) => Math.max(Math.min(min, max), Math.min(value, max));
381
+ if (docked) {
382
+ // As a sidebar only the left edge resizes the panel.
383
+ if (resize && dx)
384
+ dialog.style.width = `${clamp(rect.width + dx, 240, innerWidth - 320)}px`;
385
+ return;
386
+ }
227
387
  const width = clamp(rect.width + (resize ? dx : 0), 280, innerWidth - 16);
228
- const height = clamp(rect.height + (resize ? dy : 0), 56, innerHeight - 16);
388
+ const height = clamp(rect.height + (resize ? dy : 0), minHeight, innerHeight - 16);
229
389
  const left = clamp(rect.left + (resize ? 0 : dx), 8, innerWidth - width - 8);
230
390
  const top = clamp(rect.top + (resize ? 0 : dy), 8, innerHeight - height - 8);
231
391
  Object.assign(dialog.style, {
@@ -236,17 +396,21 @@ export const mountSearch = (initial, search, labels, published) => {
236
396
  width: `${width}px`,
237
397
  maxHeight: `${innerHeight - top - 8}px`,
238
398
  });
239
- if (resize || dialog.style.height)
399
+ // Width-only resizing keeps the height following the results.
400
+ if ((resize && dy) || dialog.style.height)
240
401
  dialog.style.height = `${height}px`;
241
402
  };
242
403
  for (const handle of dialog.querySelectorAll(".search-grip, .search-resize")) {
243
- const resize = handle.classList.contains("search-resize");
404
+ const axis = handle.dataset.axis ?? "";
405
+ const resize = axis !== "";
406
+ // The left edge ("w") grows the docked panel while moving left.
407
+ const fx = axis === "w" ? -1 : !resize || axis.includes("x") ? 1 : 0;
408
+ const fy = !resize || axis.includes("y") ? 1 : 0;
244
409
  let drag;
245
410
  handle.addEventListener("pointerdown", (event) => {
246
411
  if (event.button !== 0 || drag)
247
412
  return;
248
413
  event.preventDefault();
249
- handle.focus();
250
414
  drag = {
251
415
  id: event.pointerId,
252
416
  x: event.clientX,
@@ -257,7 +421,7 @@ export const mountSearch = (initial, search, labels, published) => {
257
421
  });
258
422
  handle.addEventListener("pointermove", (event) => {
259
423
  if (drag?.id === event.pointerId)
260
- position(drag.rect, event.clientX - drag.x, event.clientY - drag.y, resize);
424
+ position(drag.rect, fx * (event.clientX - drag.x), fy * (event.clientY - drag.y), resize);
261
425
  });
262
426
  const stop = () => {
263
427
  drag = undefined;
@@ -271,7 +435,7 @@ export const mountSearch = (initial, search, labels, published) => {
271
435
  event.preventDefault();
272
436
  event.stopPropagation();
273
437
  const step = event.shiftKey ? 40 : 10;
274
- position(dialog.getBoundingClientRect(), event.key === "ArrowRight" ? step : event.key === "ArrowLeft" ? -step : 0, event.key === "ArrowDown" ? step : event.key === "ArrowUp" ? -step : 0, resize);
438
+ position(dialog.getBoundingClientRect(), fx * (event.key === "ArrowRight" ? step : event.key === "ArrowLeft" ? -step : 0), fy * (event.key === "ArrowDown" ? step : event.key === "ArrowUp" ? -step : 0), resize);
275
439
  });
276
440
  }
277
441
  window.addEventListener("resize", () => {
@@ -340,19 +504,54 @@ export const mountSearch = (initial, search, labels, published) => {
340
504
  }
341
505
  });
342
506
  results.addEventListener("click", (event) => {
343
- if (event.target.closest("a"))
344
- dialog.close();
507
+ const link = event.target.closest("a");
508
+ if (!link || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)
509
+ return;
510
+ flash({ path: link.dataset.path ?? "", anchor: link.dataset.anchor ?? "" });
345
511
  });
512
+ // The window stays open across navigation and outside clicks; only these close it.
513
+ dialog.querySelector(".search-close")?.addEventListener("click", () => dialog.close());
346
514
  dialog.addEventListener("keydown", (event) => {
347
515
  if (event.key === "Escape" && !event.isComposing) {
348
516
  event.preventDefault();
349
517
  dialog.close();
350
518
  }
351
519
  });
352
- document.addEventListener("pointerdown", (event) => {
353
- if (dialog.open && !dialog.contains(event.target))
354
- dialog.close();
355
- });
356
520
  document.addEventListener("docs:ui-language", localize);
357
521
  localize();
522
+ // Full page loads (preview links, reloads) restore the open window for this browser tab.
523
+ const key = "docs:search";
524
+ let saved = null;
525
+ try {
526
+ saved = JSON.parse(sessionStorage.getItem(key) ?? "null");
527
+ }
528
+ catch {
529
+ /* Persistence is optional. */
530
+ }
531
+ window.addEventListener("pagehide", () => {
532
+ try {
533
+ if (dialog.open)
534
+ sessionStorage.setItem(key, JSON.stringify({
535
+ query: input.value,
536
+ style: dialog.style.cssText,
537
+ docked,
538
+ pending,
539
+ }));
540
+ else
541
+ sessionStorage.removeItem(key);
542
+ }
543
+ catch {
544
+ /* Persistence is optional. */
545
+ }
546
+ });
547
+ if (saved?.query == null)
548
+ return;
549
+ if (saved.docked)
550
+ dock(true);
551
+ if (saved.style)
552
+ dialog.style.cssText = saved.style;
553
+ input.value = saved.query;
554
+ void open();
555
+ if (saved.pending)
556
+ flash(saved.pending);
358
557
  };
@@ -3,7 +3,7 @@ import type { LanguageRegistration } from "shiki/core";
3
3
  import { type Compiled } from "../compiler/compile.js";
4
4
  import { assembleDoc } from "../compiler/ops.js";
5
5
  import { type Block, type TocEntry } from "../core/blocks.js";
6
- import type { TermEntry } from "../core/content-types.js";
6
+ import type { CompiledDoc, TermEntry } from "../core/content-types.js";
7
7
  import { type RenderCtx } from "../core/html.js";
8
8
  import { type LanguageAdapter } from "../core/language.js";
9
9
  import { type PreviewSettings } from "../core/previewers.js";
@@ -20,6 +20,7 @@ export type ServeMode = "preview" | "edit";
20
20
  */
21
21
  export interface Entry {
22
22
  id: string;
23
+ subformat?: CompiledDoc["subformat"];
23
24
  translatedLanguages?: string[];
24
25
  /** Parent doc id (omitted = top level). */
25
26
  parent?: string;
@@ -51,14 +52,18 @@ export interface Entry {
51
52
  figureRefs?: string[];
52
53
  termRefs?: string[];
53
54
  terms?: TermEntry[];
55
+ referencedFiles?: string[];
54
56
  }
55
57
  export interface Site {
58
+ sourceBase?: string;
59
+ subformats?: Compiled["subformats"];
56
60
  fonts?: readonly ProjectFont[];
57
61
  workspace?: WorkspaceSource;
58
62
  filePaths?: readonly string[];
59
63
  previews?: PreviewSettings;
60
64
  title?: string;
61
65
  icon?: string;
66
+ iconVariants?: Record<string, string>;
62
67
  codeLanguages?: string[];
63
68
  codeGrammars?: LanguageRegistration[];
64
69
  contentLanguage?: string;
@@ -76,7 +81,7 @@ export interface Site {
76
81
  themes?: readonly ("light" | "dark")[];
77
82
  }
78
83
  /** Compile result → viewer Site (shared by the server's per-request path and one-off publish). */
79
- export declare const siteFrom: ({ title, icon, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, }: Compiled, languages?: readonly LanguageAdapter[]) => Site;
84
+ export declare const siteFrom: ({ title, icon, iconVariants, docs, terms, figures, sources, siteErrors, defaultLang, previews, contentLanguages, themes, subformats, }: Compiled, languages?: readonly LanguageAdapter[]) => Site;
80
85
  export declare const filePreviewResults: (entry: Entry, site: Site) => FilePreviewResults;
81
86
  /** Renders only the requested doc, not every doc in site.entries. */
82
87
  export declare const renderEntryHtml: (site: Site, entry: Entry) => {
@@ -134,7 +139,7 @@ export declare const resourcesMain: (site: Site, rest: string) => {
134
139
  * down to figures / terms / schema graph JS). Each doc is held in a
135
140
  * <template> and switched via hash routes.
136
141
  */
137
- export declare const publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network") => string;
142
+ export declare const publishHtml: (site: Site, graphJs: string, title?: string, codeJs?: string, mode?: "static" | "network" | "live", pluginJs?: string, subformatJs?: string) => string;
138
143
  /**
139
144
  * Boot data for the client (edit-client.ts) — the same shape is passed for the initial render and
140
145
  * on doc switch. Insertion happens via the client's in-editor autocomplete (`/` palette), so the
@@ -201,8 +206,8 @@ export interface BundleCache {
201
206
  clear: () => void;
202
207
  }
203
208
  export declare const createBundleCache: () => BundleCache;
204
- /** Client bundle (src/<entry> as an IIFE). Sourcemap for the server, minified for publish. */
205
- export declare const bundleClient: (entry: string, publish?: boolean) => Promise<string>;
209
+ /** Minified client bundle shared by local viewing and published HTML. */
210
+ export declare const bundleClient: (entry: string) => Promise<string>;
206
211
  export declare const startServer: (mode: ServeMode, port?: number, pluginModule?: string, startup?: {
207
212
  file?: string;
208
213
  data?: string;