@dooc-dev/dooc 0.0.22 → 0.0.23

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 (65) hide show
  1. package/dist/client.global.js +1 -1
  2. package/dist/edit.global.js +269 -263
  3. package/dist/engine/compiler/check.js +17 -0
  4. package/dist/engine/compiler/export.js +18 -1
  5. package/dist/engine/compiler/files.js +13 -2
  6. package/dist/engine/compiler/manifest.js +4 -0
  7. package/dist/engine/compiler/skills.d.ts +10 -0
  8. package/dist/engine/compiler/skills.js +95 -0
  9. package/dist/engine/core/content-metadata.d.ts +7 -1
  10. package/dist/engine/core/content-metadata.js +52 -18
  11. package/dist/engine/core/files.d.ts +1 -0
  12. package/dist/engine/core/files.js +3 -0
  13. package/dist/frontend/document-application.d.ts +11 -2
  14. package/dist/frontend/document-application.js +356 -130
  15. package/dist/frontend/language-picker.js +1 -0
  16. package/dist/frontend/locales/eng.json +17 -1
  17. package/dist/frontend/locales/jpn.json +17 -1
  18. package/dist/frontend/locales/zho.json +17 -1
  19. package/dist/frontend/mcp-operations.js +57 -1
  20. package/dist/frontend/nav-focus.d.ts +1 -1
  21. package/dist/frontend/nav-focus.js +25 -2
  22. package/dist/frontend/nav-update.js +12 -0
  23. package/dist/frontend/page-jump.d.ts +3 -0
  24. package/dist/frontend/page-jump.js +130 -0
  25. package/dist/frontend/resource-download.d.ts +1 -1
  26. package/dist/frontend/resource-download.js +118 -28
  27. package/dist/frontend/resource-library.js +16 -7
  28. package/dist/frontend/search.js +18 -5
  29. package/dist/frontend/theme-picker.js +11 -0
  30. package/dist/manifest.global.js +349 -0
  31. package/dist/mcp-relay.mjs +71 -1
  32. package/dist/plugins.global.js +4 -4
  33. package/dist/server/assets.d.ts +1 -0
  34. package/dist/server/assets.js +4 -1
  35. package/dist/server/build-media.d.ts +6 -0
  36. package/dist/server/build-media.js +136 -0
  37. package/dist/server/build-output.d.ts +2 -1
  38. package/dist/server/build-output.js +32 -2
  39. package/dist/server/build-split.d.ts +15 -0
  40. package/dist/server/build-split.js +160 -0
  41. package/dist/server/build.d.ts +6 -1
  42. package/dist/server/build.js +37 -10
  43. package/dist/server/cli.js +20 -2
  44. package/dist/server/mcp.js +14 -1
  45. package/dist/server/serve.d.ts +21 -2
  46. package/dist/server/serve.js +26 -20
  47. package/dist/server/static-client.js +2 -1
  48. package/dist/server/workspace-server.d.ts +1 -1
  49. package/dist/server/workspace-server.js +24 -4
  50. package/dist/subformats.global.js +38 -38
  51. package/dist/ui.global.js +68 -68
  52. package/dist/workspace/client.d.ts +1 -1
  53. package/dist/workspace/client.js +22 -3
  54. package/dist/workspace/mcp-tools.js +32 -0
  55. package/dist/workspace/mcp.js +50 -1
  56. package/dist/workspace/protocol.d.ts +3 -0
  57. package/dist/workspace/server.d.ts +1 -1
  58. package/dist/workspace/server.js +14 -3
  59. package/dist/workspace/site-icon.js +17 -12
  60. package/dist/workspace/textfile.js +16 -4
  61. package/dist/workspace-mcp-worker.global.js +234 -119
  62. package/dist/workspace-reader-mcp-worker.global.js +234 -119
  63. package/dist/workspace-reader-worker.global.js +234 -119
  64. package/dist/workspace-worker.global.js +234 -119
  65. package/package.json +2 -2
@@ -302,6 +302,7 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
302
302
  }
303
303
  else if (event.key === "Escape" && isOpen()) {
304
304
  event.preventDefault();
305
+ event.stopPropagation();
305
306
  popup.hidePopover();
306
307
  if (!workspace)
307
308
  input.select();
@@ -38,6 +38,7 @@
38
38
  "View settings": "View settings",
39
39
  "Auto save": "Auto save",
40
40
  "Wrap lines": "Wrap lines",
41
+ "Space + arrow page jump": "space+arrow page jump",
41
42
  "Front-matter fields": "Front-matter fields",
42
43
  "title": "title",
43
44
  "desc": "desc",
@@ -450,5 +451,20 @@
450
451
  "This website could not be displayed here. Open it externally?": "This website could not be displayed here. Open it externally?",
451
452
  "This website has not loaded.": "This website has not loaded.",
452
453
  "This website could not be loaded.": "This website could not be loaded.",
453
- "Loading website…": "Loading website…"
454
+ "Loading website…": "Loading website…",
455
+ "Zoom in": "Zoom in",
456
+ "Zoom out": "Zoom out",
457
+ "Reset zoom": "Reset zoom",
458
+ "Image preview": "Image preview",
459
+ "Manifest editor": "Manifest editor",
460
+ "Settings": "Settings",
461
+ "Title": "Title",
462
+ "Add file": "Add file",
463
+ "Light and dark": "Light and dark",
464
+ "Automatic": "Automatic",
465
+ "Edit this legacy manifest in YAML.": "Edit this legacy manifest in YAML.",
466
+ "Manifest file is unavailable.": "Manifest file is unavailable.",
467
+ "Discard changes and reload the manifest?": "Discard changes and reload the manifest?",
468
+ "Load failed": "Load failed",
469
+ "Remove path": "Remove path"
454
470
  }
@@ -38,6 +38,7 @@
38
38
  "View settings": "表示設定",
39
39
  "Auto save": "自動保存",
40
40
  "Wrap lines": "折り返す",
41
+ "Space + arrow page jump": "space+矢印 page jump",
41
42
  "Front-matter fields": "文書の属性を表示",
42
43
  "title": "タイトル",
43
44
  "desc": "説明",
@@ -450,5 +451,20 @@
450
451
  "This website could not be displayed here. Open it externally?": "ここではWebサイトを表示できませんでした。外部で開きますか?",
451
452
  "This website has not loaded.": "Webサイトの読み込みが完了していません。",
452
453
  "This website could not be loaded.": "Webサイトを読み込めませんでした。",
453
- "Loading website…": "Webサイトを読み込み中…"
454
+ "Loading website…": "Webサイトを読み込み中…",
455
+ "Zoom in": "拡大",
456
+ "Zoom out": "縮小",
457
+ "Reset zoom": "ズームをリセット",
458
+ "Image preview": "画像プレビュー",
459
+ "Manifest editor": "マニフェスト編集",
460
+ "Settings": "設定",
461
+ "Title": "タイトル",
462
+ "Add file": "ファイルを追加",
463
+ "Light and dark": "ライトとダーク",
464
+ "Automatic": "自動",
465
+ "Edit this legacy manifest in YAML.": "この旧形式の設定は YAML で編集してください。",
466
+ "Manifest file is unavailable.": "設定ファイルを読み込めません。",
467
+ "Discard changes and reload the manifest?": "変更を破棄して設定ファイルを再読み込みしますか?",
468
+ "Load failed": "読み込みに失敗しました",
469
+ "Remove path": "参照を外す"
454
470
  }
@@ -38,6 +38,7 @@
38
38
  "View settings": "显示设置",
39
39
  "Auto save": "自动保存",
40
40
  "Wrap lines": "自动换行",
41
+ "Space + arrow page jump": "space+方向键 page jump",
41
42
  "Front-matter fields": "显示文档属性",
42
43
  "title": "标题",
43
44
  "desc": "描述",
@@ -450,5 +451,20 @@
450
451
  "This website could not be displayed here. Open it externally?": "无法在此显示该网站。在外部打开?",
451
452
  "This website has not loaded.": "此网站尚未加载。",
452
453
  "This website could not be loaded.": "无法加载此网站。",
453
- "Loading website…": "正在加载网站…"
454
+ "Loading website…": "正在加载网站…",
455
+ "Zoom in": "放大",
456
+ "Zoom out": "缩小",
457
+ "Reset zoom": "重置缩放",
458
+ "Image preview": "图像预览",
459
+ "Manifest editor": "清单编辑器",
460
+ "Settings": "设置",
461
+ "Title": "标题",
462
+ "Add file": "添加文件",
463
+ "Light and dark": "浅色和深色",
464
+ "Automatic": "自动",
465
+ "Edit this legacy manifest in YAML.": "请使用 YAML 编辑此旧格式清单。",
466
+ "Manifest file is unavailable.": "无法读取清单文件。",
467
+ "Discard changes and reload the manifest?": "放弃更改并重新加载清单?",
468
+ "Load failed": "加载失败",
469
+ "Remove path": "移除路径"
454
470
  }
@@ -3,9 +3,10 @@ import { createCompiler } from "../engine/compiler/compile.js";
3
3
  import { exportBundle } from "../engine/compiler/export.js";
4
4
  import { filesSnapshot, updateFiles, uploadFile } from "../engine/compiler/files.js";
5
5
  import { listProjectFonts, removeProjectFont } from "../engine/compiler/fonts.js";
6
- import { dirname, join, mkdirSync, randomUUID, readFileSync, realpathSync, relative, renameSync, rmSync, writeFileSync, } from "../engine/compiler/host.js";
6
+ import { createHash, dirname, join, mkdirSync, randomUUID, readFileSync, realpathSync, relative, renameSync, rmSync, writeFileSync, } from "../engine/compiler/host.js";
7
7
  import { manifestFile } from "../engine/compiler/manifest.js";
8
8
  import { createDocOps, isOpError } from "../engine/compiler/ops.js";
9
+ import { readProjectSkills } from "../engine/compiler/skills.js";
9
10
  import { validateSubformatFile } from "../engine/compiler/subformats.js";
10
11
  import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
11
12
  import { localFile } from "../engine/core/files.js";
@@ -28,6 +29,61 @@ export const createMcpOperations = (root, options = {}) => {
28
29
  return file ? (compiled.sources.get(file)?.errors ?? []) : [];
29
30
  };
30
31
  return {
32
+ skills: (a) => {
33
+ const skills = readProjectSkills(root);
34
+ const uri = (name, file) => `skill://${name}/${file.split("/").map(encodeURIComponent).join("/")}`;
35
+ const entry = (skill) => ({
36
+ uri: uri(skill.frontmatter.name, "SKILL.md"),
37
+ frontmatter: skill.frontmatter,
38
+ resources: [...skill.files].map(([file, data]) => ({
39
+ uri: uri(skill.frontmatter.name, file),
40
+ digest: `sha256:${createHash("sha256").update(data).digest("hex")}`,
41
+ size: data.length,
42
+ })),
43
+ });
44
+ if (a.action === "list")
45
+ return { resultType: "complete", skills: skills.map(entry) };
46
+ if (typeof a.uri !== "string")
47
+ throw new Error("A skill resource URI is required");
48
+ for (const skill of skills) {
49
+ if (a.action === "get" && a.uri === uri(skill.frontmatter.name, "SKILL.md"))
50
+ return { resultType: "complete", skill: entry(skill) };
51
+ if (a.action !== "read")
52
+ continue;
53
+ for (const [file, data] of skill.files) {
54
+ if (a.uri !== uri(skill.frontmatter.name, file))
55
+ continue;
56
+ let text;
57
+ try {
58
+ text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(data);
59
+ if (text.includes("\0"))
60
+ text = undefined;
61
+ }
62
+ catch {
63
+ text = undefined;
64
+ }
65
+ return {
66
+ contents: [
67
+ {
68
+ uri: a.uri,
69
+ ...(text === undefined
70
+ ? {
71
+ mimeType: "application/octet-stream",
72
+ blob: data.toString("base64"),
73
+ }
74
+ : {
75
+ mimeType: file.endsWith(".md")
76
+ ? "text/markdown"
77
+ : "text/plain",
78
+ text,
79
+ }),
80
+ },
81
+ ],
82
+ };
83
+ }
84
+ }
85
+ return { error: "Unknown project skill or resource", status: 404 };
86
+ },
31
87
  export: () => {
32
88
  const file = "dist/bundle.zip";
33
89
  const data = exportBundle(root);
@@ -1,2 +1,2 @@
1
1
  /** In narrow trees, show the current level beneath its compact ancestor chain. */
2
- export declare const focusNavTree: (root: HTMLElement | null) => void;
2
+ export declare const focusNavTree: (root: HTMLElement | null, href?: string) => void;
@@ -1,7 +1,26 @@
1
1
  /** In narrow trees, show the current level beneath its compact ancestor chain. */
2
- export const focusNavTree = (root) => {
2
+ export const focusNavTree = (root, href) => {
3
3
  if (!root)
4
4
  return;
5
+ if (href !== undefined) {
6
+ const target = new URL(href, location.href);
7
+ for (const link of document.querySelectorAll("#site-title, #nav-groups .nav-row > a[href]")) {
8
+ const url = new URL(link.href, location.href);
9
+ const current = url.origin === target.origin &&
10
+ url.pathname === target.pathname &&
11
+ (!target.hash.startsWith("#/") ||
12
+ url.hash.split("#")[1]?.split("?")[0] ===
13
+ target.hash.split("#")[1]?.split("?")[0]);
14
+ link.classList.toggle("cur", current);
15
+ if (current)
16
+ link.setAttribute("aria-current", "page");
17
+ else
18
+ link.removeAttribute("aria-current");
19
+ if (current)
20
+ for (let item = link.closest(".nav-item")?.parentElement?.closest(".nav-item"); item; item = item.parentElement?.closest(".nav-item"))
21
+ item.classList.add("open");
22
+ }
23
+ }
5
24
  const current = root.querySelector(".nav-row > a.cur")?.closest("[data-doc-id]");
6
25
  const path = [];
7
26
  for (let item = current; item; item = item.parentElement?.closest("[data-doc-id]")) {
@@ -68,6 +87,10 @@ export const focusNavTree = (root) => {
68
87
  item.classList.add("open");
69
88
  current?.querySelector(":scope > .nav-row")?.scrollIntoView({ block: "nearest" });
70
89
  }
71
- for (const item of items)
90
+ for (const item of items) {
91
+ const list = item.querySelector(":scope > .nav-list");
92
+ if (list)
93
+ list.inert = !item.classList.contains("open");
72
94
  item.querySelector(":scope > .nav-row > .nav-tree-toggle")?.setAttribute("aria-expanded", String(item.classList.contains("open")));
95
+ }
73
96
  };
@@ -2,6 +2,18 @@
2
2
  export const updateNav = (root, html) => {
3
3
  const template = root.ownerDocument.createElement("template");
4
4
  template.innerHTML = html;
5
+ // Selection runs before the link observer, so mount new routes synchronously.
6
+ for (const link of template.content.querySelectorAll("a[href]")) {
7
+ const href = link.getAttribute("href") ?? "";
8
+ if (!globalThis.__doocClientBase ||
9
+ !href.startsWith("/") ||
10
+ href.startsWith("//") ||
11
+ href === link.dataset.doocClientHref)
12
+ continue;
13
+ const mounted = `${globalThis.__doocClientBase ?? ""}${href}`;
14
+ link.setAttribute("href", mounted);
15
+ link.dataset.doocClientHref = mounted;
16
+ }
5
17
  const key = (node) => {
6
18
  if (!(node instanceof HTMLElement))
7
19
  return;
@@ -0,0 +1,3 @@
1
+ import type { focusNavTree } from "./nav-focus.js";
2
+ /** Self-contained for live pages and standalone readers. */
3
+ export declare const mountPageJump: (select: typeof focusNavTree) => void;
@@ -0,0 +1,130 @@
1
+ /** Self-contained for live pages and standalone readers. */
2
+ export const mountPageJump = (select) => {
3
+ const key = "docs-edit:page-jump";
4
+ const editor = document.body.classList.contains("edit");
5
+ const toggle = document.getElementById("opt-page-jump");
6
+ let enabled = true;
7
+ try {
8
+ if (editor)
9
+ enabled = localStorage.getItem(key) !== "0";
10
+ }
11
+ catch { }
12
+ let held = null;
13
+ let jumped = false;
14
+ const reset = () => {
15
+ held = null;
16
+ jumped = false;
17
+ };
18
+ const current = () => document.querySelector("#site-title.cur, #nav-groups [data-doc-id] > .nav-row > a.cur");
19
+ const surface = (target) => {
20
+ if (!enabled ||
21
+ !(target instanceof Element) ||
22
+ !current() ||
23
+ document.querySelector('dialog[open], [aria-modal="true"]') ||
24
+ target.closest('input, textarea, select, button, label, a, summary, iframe, audio, video, canvas, svg, .cm-editor, [contenteditable]:not([contenteditable="false"]), [role="button"], [role="textbox"], [role="searchbox"], [role="combobox"], [role="checkbox"], [role="radio"], [role="radiogroup"], [role="spinbutton"], [role="slider"], [role="tablist"], [role="tree"], [role="grid"], [role="listbox"], [role="menu"], [role="application"]'))
25
+ return null;
26
+ if (target === document.body && !editor)
27
+ return document.querySelector("main");
28
+ return target.closest(editor ? ".preview-pane.active" : "main");
29
+ };
30
+ if (toggle) {
31
+ toggle.checked = enabled;
32
+ toggle.addEventListener("change", () => {
33
+ enabled = toggle.checked;
34
+ reset();
35
+ try {
36
+ localStorage.setItem(key, enabled ? "1" : "0");
37
+ }
38
+ catch { }
39
+ });
40
+ }
41
+ document.addEventListener("pointerdown", (event) => {
42
+ const pane = surface(event.target);
43
+ if (pane !== held)
44
+ reset();
45
+ if (pane) {
46
+ if (!pane.hasAttribute("tabindex"))
47
+ pane.tabIndex = -1;
48
+ pane.focus({ preventScroll: true });
49
+ }
50
+ });
51
+ document.addEventListener("focusin", (event) => {
52
+ if (held && surface(event.target) !== held)
53
+ reset();
54
+ });
55
+ window.addEventListener("blur", reset);
56
+ document.addEventListener("visibilitychange", () => {
57
+ if (document.hidden)
58
+ reset();
59
+ });
60
+ document.addEventListener("keydown", (event) => {
61
+ if (event.defaultPrevented ||
62
+ event.isComposing ||
63
+ event.ctrlKey ||
64
+ event.altKey ||
65
+ event.metaKey ||
66
+ event.shiftKey) {
67
+ reset();
68
+ return;
69
+ }
70
+ const pane = surface(event.target);
71
+ if (!pane) {
72
+ reset();
73
+ return;
74
+ }
75
+ if (event.code === "Space" || event.key === " ") {
76
+ if (!held && !event.repeat) {
77
+ held = pane;
78
+ jumped = false;
79
+ }
80
+ if (held)
81
+ event.preventDefault();
82
+ return;
83
+ }
84
+ if (!held ||
85
+ held !== pane ||
86
+ !["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(event.key))
87
+ return;
88
+ event.preventDefault();
89
+ jumped = true;
90
+ const selected = current();
91
+ const item = selected?.closest(".nav-item[data-doc-id]");
92
+ const link = (item) => item?.querySelector(":scope > .nav-row > a[href]");
93
+ let destination;
94
+ if (event.key === "ArrowRight") {
95
+ const list = item?.querySelector(":scope > .nav-list") ??
96
+ (!item ? document.querySelector("#nav-groups > .nav-root") : null);
97
+ destination = link(list?.querySelector(":scope > .nav-item[data-doc-id]"));
98
+ if (destination && item)
99
+ window.__docsNavOpen?.(item.dataset.docId ?? "", true);
100
+ }
101
+ else if (event.key === "ArrowLeft" && item) {
102
+ destination =
103
+ link(item.parentElement?.closest(".nav-item[data-doc-id]")) ??
104
+ document.querySelector("#site-title[href]");
105
+ }
106
+ else if (item && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
107
+ const siblings = [...(item.parentElement?.children ?? [])].filter((node) => node.matches(".nav-item[data-doc-id]"));
108
+ destination = link(siblings[siblings.indexOf(item) + (event.key === "ArrowUp" ? -1 : 1)]);
109
+ }
110
+ if (!destination)
111
+ return;
112
+ if (!pane.hasAttribute("tabindex"))
113
+ pane.tabIndex = -1;
114
+ pane.focus({ preventScroll: true });
115
+ select(document.getElementById("nav-groups"), destination.href);
116
+ destination.click();
117
+ });
118
+ document.addEventListener("keyup", (event) => {
119
+ if (event.code !== "Space" && event.key !== " ")
120
+ return;
121
+ const pane = held;
122
+ const scroll = !jumped && pane && surface(event.target) === pane;
123
+ reset();
124
+ if (!pane)
125
+ return;
126
+ event.preventDefault();
127
+ if (scroll)
128
+ pane.scrollBy({ top: pane.clientHeight * 0.875, behavior: "auto" });
129
+ });
130
+ };
@@ -2,7 +2,7 @@ export declare function mountDownloadBlock(): void;
2
2
  /** Self-contained for standalone HTML; data URLs use the browser's native download behavior. */
3
3
  export declare const mountResourceDownloads: (request?: (url: string, init?: RequestInit, workspace?: string) => Promise<Response>) => void;
4
4
  /**
5
- * Expanded view of a block: wheel zooms around the pointer, middle-button dragging pans while zoomed.
5
+ * Expanded view with pointer, keyboard and touch zoom and pan controls.
6
6
  * Self-contained (stringified with toString and embedded in the page).
7
7
  */
8
8
  export declare const mountResourceExpand: () => void;
@@ -103,7 +103,7 @@ export const mountResourceDownloads = (request = fetch) => {
103
103
  });
104
104
  };
105
105
  /**
106
- * Expanded view of a block: wheel zooms around the pointer, middle-button dragging pans while zoomed.
106
+ * Expanded view with pointer, keyboard and touch zoom and pan controls.
107
107
  * Self-contained (stringified with toString and embedded in the page).
108
108
  */
109
109
  export const mountResourceExpand = () => {
@@ -118,7 +118,7 @@ export const mountResourceExpand = () => {
118
118
  const dialog = document.createElement("dialog");
119
119
  dialog.className = "resource-modal";
120
120
  dialog.innerHTML =
121
- '<div class="resource-stage"></div><div class="resource-surface"></div><div class="resource-modal-bar"><output>100%</output><button type="button" class="resource-download resource-expand" title="Close" aria-label="Close"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M5 5l10 10M15 5 5 15"/></svg></button></div>';
121
+ '<div class="resource-stage"></div><div class="resource-surface" tabindex="0" role="region" aria-label="Image preview"></div><div class="resource-modal-bar"><output>100%</output><button type="button" data-zoom="out" aria-label="Zoom out">−</button><button type="button" data-zoom="reset" aria-label="Reset zoom">100%</button><button type="button" data-zoom="in" aria-label="Zoom in">+</button><button data-close type="button" class="resource-download resource-expand" title="Close" aria-label="Close"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M5 5l10 10M15 5 5 15"/></svg></button></div>';
122
122
  const [stage, surface, bar] = dialog.children;
123
123
  if (!stage || !surface || !bar)
124
124
  return;
@@ -130,50 +130,140 @@ export const mountResourceExpand = () => {
130
130
  let zoom = 1;
131
131
  let x = 0;
132
132
  let y = 0;
133
+ const points = new Map();
134
+ const translate = (key) => window.__docsTranslate?.(key) ?? key;
135
+ for (const control of dialog.querySelectorAll("[aria-label]")) {
136
+ const label = translate(control.getAttribute("aria-label") ?? "");
137
+ control.setAttribute("aria-label", label);
138
+ control.title = label;
139
+ }
133
140
  const apply = () => {
134
141
  const fit = Math.min((dialog.clientWidth - 48) / stage.offsetWidth, (dialog.clientHeight - 48) / stage.offsetHeight, 4);
135
142
  stage.style.transform = `translate(calc(-50% + ${x}px), calc(-50% + ${y}px)) scale(${fit * zoom})`;
136
- surface.style.cursor = zoom === 1 ? "" : "grab";
143
+ surface.style.cursor = points.size ? "grabbing" : zoom === 1 ? "" : "grab";
137
144
  bar.firstElementChild.textContent = `${Math.round(zoom * 100)}%`;
138
145
  };
139
- // shortcut: the surface takes every pointer event, so embedded HTML is not interactive
140
- // while expanded; forward events to the frame if that is needed.
146
+ const setZoom = (value, cx = 0, cy = 0) => {
147
+ const next = Math.min(16, Math.max(0.25, value));
148
+ x = next === 1 ? 0 : cx - ((cx - x) * next) / zoom;
149
+ y = next === 1 ? 0 : cy - ((cy - y) * next) / zoom;
150
+ zoom = next;
151
+ };
152
+ // shortcut: expanded HTML is a preview; the surface owns its zoom and pan gestures.
141
153
  surface.addEventListener("wheel", (wheel) => {
142
154
  wheel.preventDefault();
143
- let next = Math.min(16, Math.max(0.25, zoom * (wheel.deltaY < 0 ? 1.1 : 1 / 1.1)));
155
+ let next = zoom * (wheel.deltaY < 0 ? 1.1 : 1 / 1.1);
144
156
  if (Math.abs(next - 1) < 0.04)
145
157
  next = 1;
146
158
  const box = surface.getBoundingClientRect();
147
- const cx = wheel.clientX - box.left - box.width / 2;
148
- const cy = wheel.clientY - box.top - box.height / 2;
149
- // Keep the point under the pointer fixed; 100% always returns to the centre.
150
- x = next === 1 ? 0 : cx - ((cx - x) * next) / zoom;
151
- y = next === 1 ? 0 : cy - ((cy - y) * next) / zoom;
152
- zoom = next;
159
+ setZoom(next, wheel.clientX - box.left - box.width / 2, wheel.clientY - box.top - box.height / 2);
153
160
  apply();
154
161
  }, { passive: false });
155
- // The middle button pans; cancelling mousedown keeps the browser's autoscroll off.
156
- surface.addEventListener("mousedown", (down) => {
157
- if (down.button === 1)
158
- down.preventDefault();
159
- });
162
+ for (const type of ["mousedown", "auxclick"])
163
+ surface.addEventListener(type, (event) => {
164
+ if (event.button === 1)
165
+ event.preventDefault();
166
+ });
167
+ const release = (id) => {
168
+ points.delete(id);
169
+ if (surface.hasPointerCapture(id))
170
+ surface.releasePointerCapture(id);
171
+ apply();
172
+ };
173
+ const stop = () => {
174
+ for (const id of [...points.keys()])
175
+ release(id);
176
+ };
160
177
  surface.addEventListener("pointerdown", (down) => {
161
- if (zoom === 1 || down.button !== 1)
178
+ if (points.size >= 2 ||
179
+ (down.pointerType !== "touch" && (points.size || zoom === 1 || down.button !== 1)))
162
180
  return;
181
+ down.preventDefault();
182
+ points.set(down.pointerId, { x: down.clientX, y: down.clientY });
163
183
  surface.setPointerCapture(down.pointerId);
164
- const startX = x - down.clientX;
165
- const startY = y - down.clientY;
166
- const move = (drag) => {
167
- x = startX + drag.clientX;
168
- y = startY + drag.clientY;
169
- apply();
170
- };
171
- surface.addEventListener("pointermove", move);
172
- surface.addEventListener("lostpointercapture", () => surface.removeEventListener("pointermove", move), { once: true });
184
+ apply();
185
+ });
186
+ surface.addEventListener("pointermove", (drag) => {
187
+ const previous = points.get(drag.pointerId);
188
+ if (!previous)
189
+ return;
190
+ if (drag.pointerType !== "touch" && !(drag.buttons & 4))
191
+ return release(drag.pointerId);
192
+ const other = [...points.entries()].find(([id]) => id !== drag.pointerId)?.[1];
193
+ if (other) {
194
+ const before = Math.hypot(previous.x - other.x, previous.y - other.y);
195
+ const after = Math.hypot(drag.clientX - other.x, drag.clientY - other.y);
196
+ if (before > 0 && after > 0) {
197
+ const box = surface.getBoundingClientRect();
198
+ setZoom((zoom * after) / before, (previous.x + other.x) / 2 - box.left - box.width / 2, (previous.y + other.y) / 2 - box.top - box.height / 2);
199
+ x += (drag.clientX - previous.x) / 2;
200
+ y += (drag.clientY - previous.y) / 2;
201
+ }
202
+ }
203
+ else if (zoom !== 1) {
204
+ x += drag.clientX - previous.x;
205
+ y += drag.clientY - previous.y;
206
+ }
207
+ points.set(drag.pointerId, { x: drag.clientX, y: drag.clientY });
208
+ apply();
209
+ });
210
+ const endPointer = (event) => {
211
+ const id = event.pointerId;
212
+ if (points.has(id))
213
+ release(id);
214
+ };
215
+ for (const type of ["pointerup", "pointercancel", "lostpointercapture"])
216
+ surface.addEventListener(type, endPointer);
217
+ window.addEventListener("pointerup", endPointer);
218
+ surface.addEventListener("mouseup", (up) => {
219
+ if (up.button === 1)
220
+ stop();
221
+ });
222
+ window.addEventListener("blur", stop);
223
+ const visibility = () => {
224
+ if (document.hidden)
225
+ stop();
226
+ };
227
+ document.addEventListener("visibilitychange", visibility);
228
+ bar.addEventListener("click", (event) => {
229
+ const button = event.target.closest("button");
230
+ if (!button)
231
+ return;
232
+ if (button.hasAttribute("data-close")) {
233
+ dialog.close();
234
+ return;
235
+ }
236
+ stop();
237
+ setZoom(button.dataset.zoom === "reset"
238
+ ? 1
239
+ : zoom * (button.dataset.zoom === "in" ? 1.25 : 0.8));
240
+ apply();
241
+ });
242
+ dialog.addEventListener("keydown", (event) => {
243
+ if (event.isComposing || event.ctrlKey || event.metaKey || event.altKey)
244
+ return;
245
+ if (["+", "=", "-", "0", "Home"].includes(event.key)) {
246
+ setZoom(event.key === "0" || event.key === "Home"
247
+ ? 1
248
+ : zoom * (event.key === "-" ? 0.8 : 1.25));
249
+ }
250
+ else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) {
251
+ const step = event.shiftKey ? 120 : 40;
252
+ x += event.key === "ArrowLeft" ? step : event.key === "ArrowRight" ? -step : 0;
253
+ y += event.key === "ArrowUp" ? step : event.key === "ArrowDown" ? -step : 0;
254
+ }
255
+ else
256
+ return;
257
+ event.preventDefault();
258
+ event.stopPropagation();
259
+ apply();
173
260
  });
174
- bar.querySelector("button")?.addEventListener("click", () => dialog.close());
175
261
  dialog.addEventListener("click", (click) => click.stopPropagation());
176
262
  dialog.addEventListener("close", () => {
263
+ stop();
264
+ window.removeEventListener("blur", stop);
265
+ window.removeEventListener("pointerup", endPointer);
266
+ document.removeEventListener("visibilitychange", visibility);
177
267
  resize.disconnect();
178
268
  dialog.remove();
179
269
  });
@@ -1,8 +1,9 @@
1
1
  import { bundledLanguagesInfo } from "shiki/langs";
2
2
  import { visit } from "unist-util-visit";
3
3
  import { parseContentSource } from "../engine/compiler/code-blocks.js";
4
+ import { rebaseFileLinks } from "../engine/compiler/files.js";
4
5
  import { basename, extname } from "../engine/compiler/host.js";
5
- import { readManifest } from "../engine/compiler/manifest.js";
6
+ import { readManifest, sourceOrigin } from "../engine/compiler/manifest.js";
6
7
  import { loadSubformat, parseSubformatRecord, subformatIconSvg, subformatRelations, validateSubformatRecord, } from "../engine/compiler/subformats.js";
7
8
  import { parseTermSource } from "../engine/compiler/terms.js";
8
9
  import { readTextfile, selectTextfileRange } from "../engine/compiler/textfile.js";
@@ -183,7 +184,7 @@ export const resourceIndex = (root, files, domains = []) => {
183
184
  validateTerms(raw, source);
184
185
  }
185
186
  else {
186
- const tree = parseMdast(raw);
187
+ const tree = parseMdast(rebaseFileLinks(raw, sourceOrigin(manifest, file)));
187
188
  scan(tree, file);
188
189
  for (const ref of subformatReferences(tree)) {
189
190
  if (!formats.has(fileExtension(ref.file)))
@@ -202,15 +203,23 @@ export const resourceIndex = (root, files, domains = []) => {
202
203
  const listed = new Set(flattenTree(manifest.tree).flatMap((node) => node.library && node.library !== "termth" && Object.hasOwn(CODE_TEMPLATES, node.library)
203
204
  ? [node.library]
204
205
  : []));
205
- const embedded = new Set(result.codeblocks.map((item) => item.reference?.file));
206
- for (const file of paths) {
206
+ const explicit = new Set([
207
+ ...(manifest.libraryFiles ?? []),
208
+ ...(manifest.includedLibraryFiles ?? []),
209
+ ]);
210
+ const indexed = new Set(result.codeblocks.flatMap((item) => [item.reference?.file, item.source.file]));
211
+ for (const file of new Set([...paths, ...explicit])) {
207
212
  const format = fileExtension(file);
208
- if (!listed.has(format) || embedded.has(file))
213
+ if ((!listed.has(format) && !explicit.has(file)) ||
214
+ indexed.has(file) ||
215
+ (paths.has(file) && /\.md$/i.test(file)))
209
216
  continue;
210
217
  try {
218
+ if (!paths.has(file))
219
+ throw new Error("File is not available in the workspace");
211
220
  result.codeblocks.push({
212
- language: format,
213
- format,
221
+ language: format || "text",
222
+ format: codeFormat(format || "text"),
214
223
  caption: file,
215
224
  content: readTextfile(root, file),
216
225
  source: { file, line: 1 },