@dooc-dev/dooc 0.0.21 → 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 (66) 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 +364 -133
  15. package/dist/frontend/document-links.js +31 -21
  16. package/dist/frontend/language-picker.js +1 -0
  17. package/dist/frontend/locales/eng.json +19 -2
  18. package/dist/frontend/locales/jpn.json +19 -2
  19. package/dist/frontend/locales/zho.json +19 -2
  20. package/dist/frontend/mcp-operations.js +57 -1
  21. package/dist/frontend/nav-focus.d.ts +1 -1
  22. package/dist/frontend/nav-focus.js +25 -2
  23. package/dist/frontend/nav-update.js +12 -0
  24. package/dist/frontend/page-jump.d.ts +3 -0
  25. package/dist/frontend/page-jump.js +130 -0
  26. package/dist/frontend/resource-download.d.ts +1 -1
  27. package/dist/frontend/resource-download.js +118 -28
  28. package/dist/frontend/resource-library.js +16 -7
  29. package/dist/frontend/search.js +18 -5
  30. package/dist/frontend/theme-picker.js +11 -0
  31. package/dist/manifest.global.js +349 -0
  32. package/dist/mcp-relay.mjs +71 -1
  33. package/dist/plugins.global.js +4 -4
  34. package/dist/server/assets.d.ts +1 -0
  35. package/dist/server/assets.js +4 -1
  36. package/dist/server/build-media.d.ts +6 -0
  37. package/dist/server/build-media.js +136 -0
  38. package/dist/server/build-output.d.ts +2 -1
  39. package/dist/server/build-output.js +32 -2
  40. package/dist/server/build-split.d.ts +15 -0
  41. package/dist/server/build-split.js +160 -0
  42. package/dist/server/build.d.ts +6 -1
  43. package/dist/server/build.js +37 -10
  44. package/dist/server/cli.js +20 -2
  45. package/dist/server/mcp.js +14 -1
  46. package/dist/server/serve.d.ts +21 -2
  47. package/dist/server/serve.js +26 -20
  48. package/dist/server/static-client.js +2 -1
  49. package/dist/server/workspace-server.d.ts +1 -1
  50. package/dist/server/workspace-server.js +24 -4
  51. package/dist/subformats.global.js +25 -25
  52. package/dist/ui.global.js +68 -68
  53. package/dist/workspace/client.d.ts +1 -1
  54. package/dist/workspace/client.js +22 -3
  55. package/dist/workspace/mcp-tools.js +32 -0
  56. package/dist/workspace/mcp.js +50 -1
  57. package/dist/workspace/protocol.d.ts +3 -0
  58. package/dist/workspace/server.d.ts +1 -1
  59. package/dist/workspace/server.js +14 -3
  60. package/dist/workspace/site-icon.js +17 -12
  61. package/dist/workspace/textfile.js +16 -4
  62. package/dist/workspace-mcp-worker.global.js +242 -122
  63. package/dist/workspace-reader-mcp-worker.global.js +242 -122
  64. package/dist/workspace-reader-worker.global.js +242 -122
  65. package/dist/workspace-worker.global.js +242 -122
  66. package/package.json +2 -2
@@ -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 },
@@ -455,21 +455,23 @@ export const mountSearch = (initial, search, labels, published, requestFile = fe
455
455
  window.addEventListener("resize", fit);
456
456
  if (sidebar)
457
457
  new ResizeObserver(fit).observe(sidebar);
458
- const open = async () => {
458
+ const open = async (focus = true) => {
459
459
  const request = ++revision;
460
460
  language =
461
461
  JSON.parse(document.getElementById("boot")?.textContent || "null")?.contentLanguage ??
462
462
  new URL(location.href).searchParams.get("lang") ??
463
463
  "";
464
- if (!dialog.open)
464
+ if (!dialog.open && focus)
465
465
  dialog.show();
466
466
  if (dialog.style.left)
467
467
  position(dialog.getBoundingClientRect(), 0, 0);
468
- input.focus();
469
- input.select();
468
+ if (focus) {
469
+ input.focus();
470
+ input.select();
471
+ }
470
472
  failed = false;
471
473
  loading = !published;
472
- if (!published)
474
+ if (!published && focus)
473
475
  index = [];
474
476
  render();
475
477
  if (published)
@@ -508,6 +510,17 @@ export const mountSearch = (initial, search, labels, published, requestFile = fe
508
510
  index = [];
509
511
  dialog.close();
510
512
  });
513
+ let refreshTimer;
514
+ document.addEventListener("dooc:content-changed", () => {
515
+ if (published || !dialog.open)
516
+ return;
517
+ revision++;
518
+ clearTimeout(refreshTimer);
519
+ refreshTimer = setTimeout(() => {
520
+ if (dialog.open)
521
+ void open(false);
522
+ }, 120);
523
+ });
511
524
  input.addEventListener("input", render);
512
525
  input.addEventListener("keydown", (event) => {
513
526
  if (event.isComposing)
@@ -57,7 +57,18 @@ export const mountThemePickers = (icons, themes = ["light", "dark"]) => {
57
57
  const current = (button) => button.dataset.themePicker === "editor"
58
58
  ? (root.dataset.editorTheme ?? "auto")
59
59
  : (target(button).dataset.theme ?? "auto");
60
+ const previewThemes = new WeakMap();
60
61
  const sync = () => {
62
+ for (const pane of document.querySelectorAll(".preview-pane")) {
63
+ if (pane.classList.contains("resources-pane")) {
64
+ if (!previewThemes.has(pane))
65
+ previewThemes.set(pane, pane.dataset.theme ?? documentDefault);
66
+ }
67
+ else if (previewThemes.has(pane)) {
68
+ pane.dataset.theme = previewThemes.get(pane);
69
+ previewThemes.delete(pane);
70
+ }
71
+ }
61
72
  for (const pane of document.querySelectorAll(".resources-pane, #sidebar, #panel"))
62
73
  if (pane.dataset.theme !== root.dataset.editorTheme)
63
74
  pane.dataset.theme = root.dataset.editorTheme;