pmx-canvas 0.1.16 → 0.1.18

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 (41) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/Readme.md +14 -7
  3. package/dist/canvas/global.css +25 -0
  4. package/dist/canvas/index.js +72 -72
  5. package/dist/types/client/canvas/AnnotationLayer.d.ts +4 -0
  6. package/dist/types/client/canvas/CanvasViewport.d.ts +4 -1
  7. package/dist/types/client/canvas/use-pan-zoom.d.ts +2 -1
  8. package/dist/types/client/icons.d.ts +4 -0
  9. package/dist/types/client/state/canvas-store.d.ts +16 -1
  10. package/dist/types/client/types.d.ts +20 -0
  11. package/dist/types/mcp/canvas-access.d.ts +1 -0
  12. package/dist/types/server/canvas-serialization.d.ts +25 -1
  13. package/dist/types/server/canvas-state.d.ts +27 -1
  14. package/dist/types/server/index.d.ts +7 -2
  15. package/dist/types/server/mutation-history.d.ts +1 -1
  16. package/dist/types/server/spatial-analysis.d.ts +11 -2
  17. package/package.json +1 -1
  18. package/skills/pmx-canvas/SKILL.md +19 -0
  19. package/skills/pmx-canvas/references/excalidraw-diagram-authoring.md +145 -0
  20. package/src/cli/agent.ts +6 -0
  21. package/src/client/App.tsx +60 -3
  22. package/src/client/canvas/AnnotationLayer.tsx +28 -0
  23. package/src/client/canvas/CanvasViewport.tsx +169 -10
  24. package/src/client/canvas/ContextPinBar.tsx +2 -1
  25. package/src/client/canvas/use-pan-zoom.ts +10 -5
  26. package/src/client/icons.tsx +22 -0
  27. package/src/client/state/canvas-store.ts +52 -2
  28. package/src/client/state/sse-bridge.ts +35 -1
  29. package/src/client/theme/global.css +25 -0
  30. package/src/client/types.ts +17 -0
  31. package/src/mcp/canvas-access.ts +10 -0
  32. package/src/mcp/server.ts +43 -6
  33. package/src/server/canvas-schema.ts +25 -0
  34. package/src/server/canvas-serialization.ts +117 -1
  35. package/src/server/canvas-state.ts +74 -2
  36. package/src/server/diagram-presets.ts +54 -19
  37. package/src/server/index.ts +20 -3
  38. package/src/server/mutation-history.ts +2 -0
  39. package/src/server/server.ts +77 -2
  40. package/src/server/spatial-analysis.ts +46 -1
  41. package/src/shared/semantic-attention.ts +4 -2
@@ -41,10 +41,12 @@ import { connectSSE } from './state/sse-bridge';
41
41
  import {
42
42
  IconArrange,
43
43
  IconClearTrace,
44
+ IconEraser,
44
45
  IconFitAll,
45
46
  IconLogo,
46
47
  IconMinimap,
47
48
  IconMoon,
49
+ IconPen,
48
50
  IconResetView,
49
51
  IconSearch,
50
52
  IconShortcuts,
@@ -71,6 +73,8 @@ function sendIntent(type: string, payload: Record<string, unknown> = {}): void {
71
73
  });
72
74
  }
73
75
 
76
+ type AnnotationTool = 'pen' | 'eraser' | null;
77
+
74
78
  function ToolbarHint({
75
79
  label,
76
80
  detail,
@@ -108,6 +112,9 @@ function Toolbar({
108
112
  snapshotBtnRef,
109
113
  onOpenPalette,
110
114
  onOpenShortcuts,
115
+ annotationTool,
116
+ onToggleAnnotationMode,
117
+ onToggleAnnotationEraser,
111
118
  }: {
112
119
  minimapVisible: boolean;
113
120
  onToggleMinimap: () => void;
@@ -116,6 +123,9 @@ function Toolbar({
116
123
  snapshotBtnRef: { current: HTMLButtonElement | null };
117
124
  onOpenPalette: () => void;
118
125
  onOpenShortcuts: () => void;
126
+ annotationTool: AnnotationTool;
127
+ onToggleAnnotationMode: () => void;
128
+ onToggleAnnotationEraser: () => void;
119
129
  }) {
120
130
  const status = connectionStatus.value;
121
131
  const hasSynced = hasInitialServerLayout.value;
@@ -278,6 +288,37 @@ function Toolbar({
278
288
 
279
289
  <div class="separator" />
280
290
 
291
+ <ToolbarHint
292
+ label={annotationTool === 'pen' ? 'Stop annotating' : 'Annotate canvas'}
293
+ detail="Draw directly on the canvas for human-visible markup"
294
+ >
295
+ <button
296
+ type="button"
297
+ onClick={onToggleAnnotationMode}
298
+ aria-label={annotationTool === 'pen' ? 'Stop annotating' : 'Annotate canvas'}
299
+ aria-pressed={annotationTool === 'pen'}
300
+ style={{ color: annotationTool === 'pen' ? 'var(--c-accent)' : undefined }}
301
+ >
302
+ <IconPen />
303
+ </button>
304
+ </ToolbarHint>
305
+ <ToolbarHint
306
+ label={annotationTool === 'eraser' ? 'Stop erasing' : 'Erase annotations'}
307
+ detail="Click a drawn annotation to remove it"
308
+ >
309
+ <button
310
+ type="button"
311
+ onClick={onToggleAnnotationEraser}
312
+ aria-label={annotationTool === 'eraser' ? 'Stop erasing' : 'Erase annotations'}
313
+ aria-pressed={annotationTool === 'eraser'}
314
+ style={{ color: annotationTool === 'eraser' ? 'var(--c-accent)' : undefined }}
315
+ >
316
+ <IconEraser />
317
+ </button>
318
+ </ToolbarHint>
319
+
320
+ <div class="separator" />
321
+
281
322
  <ToolbarHint label="Search nodes and actions" shortcut={`${MOD_KEY}+K`}>
282
323
  <button
283
324
  type="button"
@@ -341,6 +382,7 @@ export function App() {
341
382
  const [snapshotOpen, setSnapshotOpen] = useState(false);
342
383
  const [paletteOpen, setPaletteOpen] = useState(false);
343
384
  const [shortcutsOpen, setShortcutsOpen] = useState(false);
385
+ const [annotationTool, setAnnotationTool] = useState<AnnotationTool>(null);
344
386
  const snapshotBtnRef = useRef<HTMLButtonElement>(null);
345
387
  const { menu, openNodeMenu, openCanvasMenu, closeMenu } = useContextMenu();
346
388
  const hasInitialLayout = hasInitialServerLayout.value;
@@ -348,14 +390,18 @@ export function App() {
348
390
  const handleToggleMinimap = useCallback(() => setMinimapVisible((v) => !v), []);
349
391
  const handleToggleSnapshot = useCallback(() => setSnapshotOpen((v) => !v), []);
350
392
  const handleCloseSnapshot = useCallback(() => setSnapshotOpen(false), []);
393
+ const handleToggleAnnotationMode = useCallback(() => setAnnotationTool((tool) => tool === 'pen' ? null : 'pen'), []);
394
+ const handleToggleAnnotationEraser = useCallback(() => setAnnotationTool((tool) => tool === 'eraser' ? null : 'eraser'), []);
351
395
 
352
396
  const handleMinimapNavigate = useCallback((x: number, y: number) => {
353
397
  animateViewport({ x, y, scale: viewport.value.scale }, 200);
354
398
  }, []);
355
399
 
356
400
  useEffect(() => {
357
- const disconnect = connectSSE();
401
+ return connectSSE();
402
+ }, []);
358
403
 
404
+ useEffect(() => {
359
405
  const handleKeyDown = (e: KeyboardEvent) => {
360
406
  const mod = e.metaKey || e.ctrlKey;
361
407
 
@@ -366,6 +412,13 @@ export function App() {
366
412
  return;
367
413
  }
368
414
 
415
+ // Esc exits annotation tools before handling overlays or selection.
416
+ if (e.key === 'Escape' && annotationTool) {
417
+ e.preventDefault();
418
+ setAnnotationTool(null);
419
+ return;
420
+ }
421
+
369
422
  // Esc always collapses expanded node first (even from inside inputs)
370
423
  if (e.key === 'Escape' && expandedNodeId.value && !pendingExpandedNodeCloseId.value) {
371
424
  e.preventDefault();
@@ -428,10 +481,9 @@ export function App() {
428
481
 
429
482
  document.addEventListener('keydown', handleKeyDown);
430
483
  return () => {
431
- disconnect();
432
484
  document.removeEventListener('keydown', handleKeyDown);
433
485
  };
434
- }, [closeMenu, paletteOpen, shortcutsOpen]);
486
+ }, [annotationTool, closeMenu, paletteOpen, shortcutsOpen]);
435
487
 
436
488
  useEffect(() => {
437
489
  if (!hasInitialLayout) return;
@@ -465,6 +517,9 @@ export function App() {
465
517
  snapshotBtnRef={snapshotBtnRef}
466
518
  onOpenPalette={() => setPaletteOpen(true)}
467
519
  onOpenShortcuts={() => setShortcutsOpen((v) => !v)}
520
+ annotationTool={annotationTool}
521
+ onToggleAnnotationMode={handleToggleAnnotationMode}
522
+ onToggleAnnotationEraser={handleToggleAnnotationEraser}
468
523
  />
469
524
  <div class="hud-right">
470
525
  {dockedRight.map((n) => (
@@ -477,6 +532,8 @@ export function App() {
477
532
  <CanvasViewport
478
533
  onNodeContextMenu={openNodeMenu}
479
534
  onCanvasContextMenu={openCanvasMenu}
535
+ annotationMode={annotationTool !== null}
536
+ annotationTool={annotationTool}
480
537
  />
481
538
  {hasInitialLayout && allNodes.filter((n) => !n.dockPosition).length === 0 && (
482
539
  <WelcomeCard onOpenPalette={() => setPaletteOpen(true)} />
@@ -0,0 +1,28 @@
1
+ import type { CanvasAnnotation, CanvasAnnotationPoint } from '../types';
2
+
3
+ function pointsToPath(points: CanvasAnnotationPoint[]): string {
4
+ const [first, ...rest] = points;
5
+ if (!first) return '';
6
+ return rest.reduce((path, point) => `${path} L ${point.x} ${point.y}`, `M ${first.x} ${first.y}`);
7
+ }
8
+
9
+ export function AnnotationLayer({ annotations }: { annotations: CanvasAnnotation[] }) {
10
+ if (annotations.length === 0) return null;
11
+
12
+ return (
13
+ <svg class="annotation-layer" aria-hidden="true">
14
+ {annotations.map((annotation) => (
15
+ <path
16
+ key={annotation.id}
17
+ d={pointsToPath(annotation.points)}
18
+ fill="none"
19
+ stroke={annotation.color === 'currentColor' ? 'var(--c-annotation)' : annotation.color}
20
+ stroke-width={annotation.width}
21
+ stroke-linecap="round"
22
+ stroke-linejoin="round"
23
+ opacity="0.9"
24
+ />
25
+ ))}
26
+ </svg>
27
+ );
28
+ }
@@ -20,16 +20,20 @@ import {
20
20
  draggingEdge,
21
21
  edges,
22
22
  expandedNodeId,
23
+ annotations,
23
24
  nodes,
24
25
  selectNodes,
25
26
  setViewport,
26
27
  viewport,
28
+ createAnnotationFromClient,
29
+ removeAnnotationFromClient,
27
30
  } from '../state/canvas-store';
28
31
  import { createEdgeFromClient, createNodeFromClient } from '../state/intent-bridge';
29
- import type { CanvasNodeState } from '../types';
32
+ import type { CanvasAnnotation, CanvasNodeState } from '../types';
30
33
  import { FocusFieldLayer } from './FocusFieldLayer';
31
34
  import { CanvasNode } from './CanvasNode';
32
35
  import { EdgeLayer } from './EdgeLayer';
36
+ import { AnnotationLayer } from './AnnotationLayer';
33
37
  import { activeGuides } from './snap-guides';
34
38
  import { usePanZoom } from './use-pan-zoom';
35
39
 
@@ -70,6 +74,45 @@ function renderNodeContent(node: CanvasNodeState) {
70
74
  }
71
75
  }
72
76
 
77
+ function distanceToSegment(
78
+ point: { x: number; y: number },
79
+ start: { x: number; y: number },
80
+ end: { x: number; y: number },
81
+ ): number {
82
+ const dx = end.x - start.x;
83
+ const dy = end.y - start.y;
84
+ const lengthSquared = dx * dx + dy * dy;
85
+ if (lengthSquared === 0) return Math.hypot(point.x - start.x, point.y - start.y);
86
+ const t = Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared));
87
+ return Math.hypot(point.x - (start.x + t * dx), point.y - (start.y + t * dy));
88
+ }
89
+
90
+ function findAnnotationAtPoint(
91
+ annotationList: CanvasAnnotation[],
92
+ point: { x: number; y: number },
93
+ hitRadius: number,
94
+ ): CanvasAnnotation | null {
95
+ for (let i = annotationList.length - 1; i >= 0; i--) {
96
+ const annotation = annotationList[i];
97
+ if (!annotation) continue;
98
+ const pad = hitRadius + annotation.width;
99
+ if (
100
+ point.x < annotation.bounds.x - pad ||
101
+ point.x > annotation.bounds.x + annotation.bounds.width + pad ||
102
+ point.y < annotation.bounds.y - pad ||
103
+ point.y > annotation.bounds.y + annotation.bounds.height + pad
104
+ ) continue;
105
+ for (let index = 1; index < annotation.points.length; index++) {
106
+ const start = annotation.points[index - 1];
107
+ const end = annotation.points[index];
108
+ if (start && end && distanceToSegment(point, start, end) <= hitRadius + annotation.width / 2) {
109
+ return annotation;
110
+ }
111
+ }
112
+ }
113
+ return null;
114
+ }
115
+
73
116
  interface LassoRect {
74
117
  startX: number;
75
118
  startY: number;
@@ -77,9 +120,27 @@ interface LassoRect {
77
120
  currentY: number;
78
121
  }
79
122
 
123
+ interface AnnotationDraft {
124
+ id: string;
125
+ type: 'freehand';
126
+ points: Array<{ x: number; y: number }>;
127
+ bounds: { x: number; y: number; width: number; height: number };
128
+ color: string;
129
+ width: number;
130
+ createdAt: string;
131
+ }
132
+
133
+ const ANNOTATION_COLOR = 'currentColor';
134
+ const ANNOTATION_WIDTH = 4;
135
+ const ERASER_HIT_RADIUS = 14;
136
+
137
+ type AnnotationTool = 'pen' | 'eraser' | null;
138
+
80
139
  interface CanvasViewportProps {
81
140
  onNodeContextMenu?: (e: MouseEvent, nodeId: string) => void;
82
141
  onCanvasContextMenu?: (e: MouseEvent, canvasX: number, canvasY: number) => void;
142
+ annotationMode?: boolean;
143
+ annotationTool?: AnnotationTool;
83
144
  }
84
145
 
85
146
  const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'bmp', 'ico', 'avif']);
@@ -165,10 +226,13 @@ export function getRenderableWorldNodes(
165
226
  return worldNodes;
166
227
  }
167
228
 
168
- export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: CanvasViewportProps) {
229
+ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu, annotationMode = false, annotationTool = null }: CanvasViewportProps) {
169
230
  const v = viewport.value;
170
231
  const isLassoing = useRef(false);
232
+ const isAnnotating = useRef(false);
233
+ const annotationPoints = useRef<Array<{ x: number; y: number }>>([]);
171
234
  const [lasso, setLasso] = useState<LassoRect | null>(null);
235
+ const [draftAnnotation, setDraftAnnotation] = useState<AnnotationDraft | null>(null);
172
236
  const [dropActive, setDropActive] = useState(false);
173
237
  const dropCounter = useRef(0);
174
238
  // Ref mirrors lasso state so pointer handlers always read the latest value
@@ -177,15 +241,16 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
177
241
 
178
242
  const containerRef = usePanZoom({
179
243
  viewport,
244
+ disabled: annotationMode,
180
245
  onViewportChange: (next) => {
181
246
  // Don't pan while lassoing — usePanZoom's pointerdown still fires
182
247
  // (native listener) before our Preact handler can stopPropagation.
183
- if (isLassoing.current) return;
248
+ if (isLassoing.current || annotationMode) return;
184
249
  cancelViewportAnimation();
185
250
  setViewport(next);
186
251
  },
187
252
  onViewportCommit: (next) => {
188
- if (isLassoing.current) return;
253
+ if (isLassoing.current || annotationMode) return;
189
254
  cancelViewportAnimation();
190
255
  commitViewport(next);
191
256
  },
@@ -222,7 +287,53 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
222
287
  const handlePointerDown = useCallback(
223
288
  (e: PointerEvent) => {
224
289
  const container = containerRef.current;
225
- if (!container || e.target !== container) return;
290
+ if (!container) return;
291
+
292
+ if (annotationTool === 'eraser') {
293
+ const target = e.target instanceof Element ? e.target : null;
294
+ if (target?.closest('.hud-layer, .snapshot-panel, .context-menu, .command-palette')) return;
295
+ e.preventDefault();
296
+ e.stopPropagation();
297
+ const rect = container.getBoundingClientRect();
298
+ const vp = viewport.value;
299
+ const point = {
300
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
301
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
302
+ };
303
+ const hit = findAnnotationAtPoint(Array.from(annotations.value.values()), point, ERASER_HIT_RADIUS / vp.scale);
304
+ if (hit) void removeAnnotationFromClient(hit.id);
305
+ return;
306
+ }
307
+
308
+ if (annotationTool === 'pen') {
309
+ const target = e.target instanceof Element ? e.target : null;
310
+ if (target?.closest('.hud-layer, .snapshot-panel, .context-menu, .command-palette')) return;
311
+ e.preventDefault();
312
+ e.stopPropagation();
313
+ activeNodeId.value = null;
314
+ clearSelection();
315
+ isAnnotating.current = true;
316
+ const rect = container.getBoundingClientRect();
317
+ const vp = viewport.value;
318
+ const point = {
319
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
320
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
321
+ };
322
+ annotationPoints.current = [point];
323
+ setDraftAnnotation({
324
+ id: 'draft-annotation',
325
+ type: 'freehand',
326
+ points: [point],
327
+ bounds: { x: 0, y: 0, width: 0, height: 0 },
328
+ color: ANNOTATION_COLOR,
329
+ width: ANNOTATION_WIDTH,
330
+ createdAt: '',
331
+ });
332
+ container.setPointerCapture(e.pointerId);
333
+ return;
334
+ }
335
+
336
+ if (e.target !== container) return;
226
337
 
227
338
  if (!e.shiftKey) {
228
339
  if (!lassoRef.current) {
@@ -243,11 +354,27 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
243
354
  setLasso(initial);
244
355
  container.setPointerCapture(e.pointerId);
245
356
  },
246
- [containerRef],
357
+ [annotationTool, containerRef],
247
358
  );
248
359
 
249
360
  const handlePointerMove = useCallback(
250
361
  (e: PointerEvent) => {
362
+ if (isAnnotating.current) {
363
+ const container = containerRef.current;
364
+ if (!container) return;
365
+ const rect = container.getBoundingClientRect();
366
+ const vp = viewport.value;
367
+ const point = {
368
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
369
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
370
+ };
371
+ const previous = annotationPoints.current.at(-1);
372
+ if (previous && Math.hypot(point.x - previous.x, point.y - previous.y) < 2) return;
373
+ annotationPoints.current = [...annotationPoints.current, point];
374
+ setDraftAnnotation((draft) => draft ? { ...draft, points: annotationPoints.current } : null);
375
+ return;
376
+ }
377
+
251
378
  if (!isLassoing.current || !lassoRef.current) return;
252
379
  const rect = containerRef.current?.getBoundingClientRect();
253
380
  if (!rect) return;
@@ -262,7 +389,22 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
262
389
  [containerRef],
263
390
  );
264
391
 
265
- const handlePointerUp = useCallback(() => {
392
+ const handlePointerUp = useCallback((e: PointerEvent) => {
393
+ if (isAnnotating.current) {
394
+ isAnnotating.current = false;
395
+ const points = annotationPoints.current;
396
+ annotationPoints.current = [];
397
+ setDraftAnnotation(null);
398
+ if (points.length >= 2) {
399
+ void createAnnotationFromClient({ points, color: ANNOTATION_COLOR, width: ANNOTATION_WIDTH });
400
+ }
401
+ const container = containerRef.current;
402
+ if (container?.hasPointerCapture(e.pointerId)) {
403
+ container.releasePointerCapture(e.pointerId);
404
+ }
405
+ return;
406
+ }
407
+
266
408
  const current = lassoRef.current;
267
409
  if (!isLassoing.current || !current) return;
268
410
  isLassoing.current = false;
@@ -306,6 +448,14 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
306
448
  setLasso(null);
307
449
  }, []);
308
450
 
451
+ useEffect(() => {
452
+ if (annotationMode) return;
453
+ if (!isAnnotating.current && !draftAnnotation) return;
454
+ isAnnotating.current = false;
455
+ annotationPoints.current = [];
456
+ setDraftAnnotation(null);
457
+ }, [annotationMode, draftAnnotation]);
458
+
309
459
  // ── Drag-to-connect: track cursor in world space, hit-test on drop ──
310
460
  useEffect(() => {
311
461
  function handleMove(e: PointerEvent) {
@@ -359,6 +509,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
359
509
  // ── Double-click on background → create new markdown node ──
360
510
  const handleDblClick = useCallback(
361
511
  (e: MouseEvent) => {
512
+ if (annotationMode) return;
362
513
  const container = containerRef.current;
363
514
  if (!container || e.target !== container) return;
364
515
  const rect = container.getBoundingClientRect();
@@ -377,11 +528,12 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
377
528
  height: nodeH,
378
529
  });
379
530
  },
380
- [containerRef],
531
+ [annotationMode, containerRef],
381
532
  );
382
533
 
383
534
  const handleContextMenu = useCallback(
384
535
  (e: MouseEvent) => {
536
+ if (annotationMode) return;
385
537
  if (!onCanvasContextMenu) return;
386
538
 
387
539
  const container = containerRef.current;
@@ -396,7 +548,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
396
548
  const canvasY = (e.clientY - rect.top - v.y) / v.scale;
397
549
  onCanvasContextMenu(e, canvasX, canvasY);
398
550
  },
399
- [containerRef, onCanvasContextMenu],
551
+ [annotationMode, containerRef, onCanvasContextMenu],
400
552
  );
401
553
 
402
554
  // ── Drag-and-drop files from filesystem ──
@@ -543,7 +695,11 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
543
695
  height: '100%',
544
696
  position: 'relative',
545
697
  overflow: 'hidden',
546
- cursor: draggingEdge.value ? 'crosshair' : isLassoing.current ? 'crosshair' : 'grab',
698
+ cursor: annotationTool === 'eraser'
699
+ ? 'cell'
700
+ : annotationMode || draggingEdge.value || isLassoing.current
701
+ ? 'crosshair'
702
+ : 'grab',
547
703
  }}
548
704
  >
549
705
  {/* D4: CSS matrix(a,b,c,d,tx,ty) — scale uniformly (a=d=scale, b=c=0)
@@ -561,6 +717,8 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
561
717
  >
562
718
  <FocusFieldLayer />
563
719
  <EdgeLayer nodes={nodes} edges={edges} />
720
+ <AnnotationLayer annotations={Array.from(annotations.value.values())} />
721
+ {draftAnnotation && draftAnnotation.points.length >= 2 && <AnnotationLayer annotations={[draftAnnotation]} />}
564
722
  {worldNodes.map((node) => (
565
723
  <CanvasNode key={node.id} node={node} onContextMenu={onNodeContextMenu}>
566
724
  {renderNodeContent(node)}
@@ -579,6 +737,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
579
737
  </svg>
580
738
  )}
581
739
  </div>
740
+ {annotationMode && <div class={`annotation-capture-layer${annotationTool === 'eraser' ? ' erasing' : ''}`} aria-hidden="true" />}
582
741
  {lassoStyle && <div class="lasso-rect" style={lassoStyle} />}
583
742
  {dropActive && (
584
743
  <div class="drop-zone-overlay">
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  clearContextPins,
3
3
  contextPinnedNodeIds,
4
+ hasOpenDockedContextPanel,
4
5
  } from '../state/canvas-store';
5
6
  import { attentionHistoryOpen } from '../state/attention-store';
6
7
 
7
8
  export function ContextPinBar() {
8
9
  const count = contextPinnedNodeIds.value.size;
9
- if (count === 0 || attentionHistoryOpen.value) return null;
10
+ if (count === 0 || attentionHistoryOpen.value || hasOpenDockedContextPanel.value) return null;
10
11
 
11
12
  return (
12
13
  <div class="context-pin-bar">
@@ -14,6 +14,7 @@ interface PanZoomOptions {
14
14
  viewport: Signal<ViewportState>;
15
15
  onViewportChange: (v: ViewportState) => void;
16
16
  onViewportCommit: (v: ViewportState) => void;
17
+ disabled?: boolean;
17
18
  }
18
19
 
19
20
  /**
@@ -23,7 +24,7 @@ interface PanZoomOptions {
23
24
  * - Pointer drag on background: pan
24
25
  * - Pinch (touch): zoom
25
26
  */
26
- export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: PanZoomOptions) {
27
+ export function usePanZoom({ viewport, onViewportChange, onViewportCommit, disabled = false }: PanZoomOptions) {
27
28
  const containerRef = useRef<HTMLDivElement>(null);
28
29
  const isPanning = useRef(false);
29
30
  const lastPointer = useRef({ x: 0, y: 0 });
@@ -42,6 +43,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
42
43
 
43
44
  const handleWheel = useCallback(
44
45
  (e: WheelEvent) => {
46
+ if (disabled) return;
45
47
  e.preventDefault();
46
48
  const v = viewport.value;
47
49
 
@@ -74,21 +76,23 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
74
76
  scheduleViewportCommit(next);
75
77
  }
76
78
  },
77
- [viewport, onViewportChange, scheduleViewportCommit],
79
+ [disabled, viewport, onViewportChange, scheduleViewportCommit],
78
80
  );
79
81
 
80
82
  const handlePointerDown = useCallback((e: PointerEvent) => {
83
+ if (disabled) return;
81
84
  // Only pan when clicking the canvas background (not nodes)
82
85
  const container = containerRef.current;
83
86
  if (!container || e.target !== container) return;
84
87
  isPanning.current = true;
85
88
  lastPointer.current = { x: e.clientX, y: e.clientY };
86
89
  container.setPointerCapture(e.pointerId);
87
- }, []);
90
+ }, [disabled]);
88
91
 
89
92
  const handlePointerMove = useCallback(
90
93
  (e: PointerEvent) => {
91
94
  if (!isPanning.current) return;
95
+ if (disabled) return;
92
96
  const dx = e.clientX - lastPointer.current.x;
93
97
  const dy = e.clientY - lastPointer.current.y;
94
98
  lastPointer.current = { x: e.clientX, y: e.clientY };
@@ -96,7 +100,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
96
100
  const v = viewport.value;
97
101
  onViewportChange({ x: v.x + dx, y: v.y + dy, scale: v.scale });
98
102
  },
99
- [viewport, onViewportChange],
103
+ [disabled, viewport, onViewportChange],
100
104
  );
101
105
 
102
106
  const handlePointerUp = useCallback(() => {
@@ -109,6 +113,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
109
113
  // Touch pinch
110
114
  const handleTouchMove = useCallback(
111
115
  (e: TouchEvent) => {
116
+ if (disabled) return;
112
117
  if (e.touches.length !== 2) {
113
118
  lastPinchDist.current = 0;
114
119
  return;
@@ -142,7 +147,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
142
147
  }
143
148
  lastPinchDist.current = dist;
144
149
  },
145
- [viewport, onViewportChange, scheduleViewportCommit],
150
+ [disabled, viewport, onViewportChange, scheduleViewportCommit],
146
151
  );
147
152
 
148
153
  const handleTouchEnd = useCallback(() => {
@@ -117,6 +117,28 @@ export function IconMoon(p: IconProps): JSX.Element {
117
117
  );
118
118
  }
119
119
 
120
+ /** Pen stroke — canvas annotation mode */
121
+ export function IconPen(p: IconProps): JSX.Element {
122
+ return (
123
+ <Icon {...p}>
124
+ <path d="M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z" />
125
+ <path d="M9.8 4.1l2.1 2.1" />
126
+ <path d="M2.5 14h11" />
127
+ </Icon>
128
+ );
129
+ }
130
+
131
+ /** Eraser — remove canvas annotations */
132
+ export function IconEraser(p: IconProps): JSX.Element {
133
+ return (
134
+ <Icon {...p}>
135
+ <path d="M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z" />
136
+ <path d="M7.5 6 12 10.5" />
137
+ <path d="M8.5 14H14" />
138
+ </Icon>
139
+ );
140
+ }
141
+
120
142
  /** Camera — snapshots */
121
143
  export function IconSnapshot(p: IconProps): JSX.Element {
122
144
  return (