@1agh/maude 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +166 -0
  3. package/cli/bin/maude.exe +15 -0
  4. package/cli/bin/maude.mjs +45 -0
  5. package/cli/bin/mdcc.exe +10 -0
  6. package/cli/bin/mdcc.mjs +7 -0
  7. package/cli/cli-wrapper.cjs +67 -0
  8. package/cli/commands/config.mjs +94 -0
  9. package/cli/commands/design.mjs +386 -0
  10. package/cli/commands/help.mjs +57 -0
  11. package/cli/commands/init.mjs +178 -0
  12. package/cli/commands/version.mjs +7 -0
  13. package/cli/install.cjs +113 -0
  14. package/cli/lib/argv.mjs +37 -0
  15. package/cli/lib/argv.test.mjs +46 -0
  16. package/cli/lib/copy-tree.mjs +78 -0
  17. package/package.json +94 -0
  18. package/plugins/design/dev-server/annotations-context-toolbar.tsx +397 -0
  19. package/plugins/design/dev-server/annotations-layer.tsx +1717 -0
  20. package/plugins/design/dev-server/api.ts +674 -0
  21. package/plugins/design/dev-server/bin/_screenshot-playwright.mjs +50 -0
  22. package/plugins/design/dev-server/bin/bootstrap-check.sh +83 -0
  23. package/plugins/design/dev-server/bin/canvas-edit.sh +48 -0
  24. package/plugins/design/dev-server/bin/handoff.sh +27 -0
  25. package/plugins/design/dev-server/bin/screenshot.sh +232 -0
  26. package/plugins/design/dev-server/bin/server-up.sh +135 -0
  27. package/plugins/design/dev-server/bin/slug.sh +22 -0
  28. package/plugins/design/dev-server/bin/smoke.sh +272 -0
  29. package/plugins/design/dev-server/build.ts +267 -0
  30. package/plugins/design/dev-server/canvas-build.ts +219 -0
  31. package/plugins/design/dev-server/canvas-edit.ts +388 -0
  32. package/plugins/design/dev-server/canvas-header.ts +165 -0
  33. package/plugins/design/dev-server/canvas-icons.tsx +131 -0
  34. package/plugins/design/dev-server/canvas-lib-inline.ts +260 -0
  35. package/plugins/design/dev-server/canvas-lib-resolver.ts +85 -0
  36. package/plugins/design/dev-server/canvas-lib.tsx +1995 -0
  37. package/plugins/design/dev-server/canvas-meta.schema.json +181 -0
  38. package/plugins/design/dev-server/canvas-pipeline.ts +270 -0
  39. package/plugins/design/dev-server/canvas-shell.tsx +813 -0
  40. package/plugins/design/dev-server/client/app.jsx +2027 -0
  41. package/plugins/design/dev-server/client/hmr.mjs +85 -0
  42. package/plugins/design/dev-server/client/iframe-lazy.mjs +121 -0
  43. package/plugins/design/dev-server/client/index.html +15 -0
  44. package/plugins/design/dev-server/client/styles/0-reset.css +18 -0
  45. package/plugins/design/dev-server/client/styles/1-tokens.css +297 -0
  46. package/plugins/design/dev-server/client/styles/2-layout.css +35 -0
  47. package/plugins/design/dev-server/client/styles/3-shell.css +906 -0
  48. package/plugins/design/dev-server/client/styles/4-components.css +1268 -0
  49. package/plugins/design/dev-server/client/styles/5-utilities.css +4 -0
  50. package/plugins/design/dev-server/client/styles/_index.css +24 -0
  51. package/plugins/design/dev-server/client/styles.css +1419 -0
  52. package/plugins/design/dev-server/config.schema.json +147 -0
  53. package/plugins/design/dev-server/context-menu.tsx +343 -0
  54. package/plugins/design/dev-server/context.ts +173 -0
  55. package/plugins/design/dev-server/dist/client.bundle.js +20323 -0
  56. package/plugins/design/dev-server/dist/styles.css +2875 -0
  57. package/plugins/design/dev-server/examples/README.md +9 -0
  58. package/plugins/design/dev-server/examples/perf-100-artboards.tsx +113 -0
  59. package/plugins/design/dev-server/fs-watch.ts +63 -0
  60. package/plugins/design/dev-server/handoff.ts +721 -0
  61. package/plugins/design/dev-server/history.ts +125 -0
  62. package/plugins/design/dev-server/hmr-broadcast.ts +114 -0
  63. package/plugins/design/dev-server/http.ts +413 -0
  64. package/plugins/design/dev-server/input-router.tsx +485 -0
  65. package/plugins/design/dev-server/inspect.ts +365 -0
  66. package/plugins/design/dev-server/locator.ts +159 -0
  67. package/plugins/design/dev-server/mem.ts +97 -0
  68. package/plugins/design/dev-server/runtime-bundle.ts +235 -0
  69. package/plugins/design/dev-server/server.mjs +1246 -0
  70. package/plugins/design/dev-server/server.ts +131 -0
  71. package/plugins/design/dev-server/test/_helpers.ts +81 -0
  72. package/plugins/design/dev-server/test/active-state.test.ts +145 -0
  73. package/plugins/design/dev-server/test/annotations-api.test.ts +146 -0
  74. package/plugins/design/dev-server/test/annotations-layer.test.ts +419 -0
  75. package/plugins/design/dev-server/test/binary-smoke.test.ts +47 -0
  76. package/plugins/design/dev-server/test/bundle-smoke.test.ts +29 -0
  77. package/plugins/design/dev-server/test/canvas-build.test.ts +78 -0
  78. package/plugins/design/dev-server/test/canvas-edit.test.ts +139 -0
  79. package/plugins/design/dev-server/test/canvas-header.test.ts +127 -0
  80. package/plugins/design/dev-server/test/canvas-lib-inline.test.ts +146 -0
  81. package/plugins/design/dev-server/test/canvas-lib-resolver.test.ts +112 -0
  82. package/plugins/design/dev-server/test/canvas-meta-api.test.ts +236 -0
  83. package/plugins/design/dev-server/test/canvas-pipeline.test.ts +180 -0
  84. package/plugins/design/dev-server/test/canvas-route.test.ts +176 -0
  85. package/plugins/design/dev-server/test/fs-watch.test.ts +41 -0
  86. package/plugins/design/dev-server/test/handoff-static-frames.test.ts +215 -0
  87. package/plugins/design/dev-server/test/handoff.test.ts +281 -0
  88. package/plugins/design/dev-server/test/history-rollback.test.ts +62 -0
  89. package/plugins/design/dev-server/test/hmr-broadcast.test.ts +108 -0
  90. package/plugins/design/dev-server/test/input-router.test.ts +316 -0
  91. package/plugins/design/dev-server/test/locator.test.ts +214 -0
  92. package/plugins/design/dev-server/test/perf-harness.ts +193 -0
  93. package/plugins/design/dev-server/test/phase-3.6-smoke.test.ts +77 -0
  94. package/plugins/design/dev-server/test/runtime-bundle.test.ts +69 -0
  95. package/plugins/design/dev-server/test/server-lifecycle.test.ts +28 -0
  96. package/plugins/design/dev-server/test/tool-palette.test.tsx +55 -0
  97. package/plugins/design/dev-server/test/use-annotation-selection.test.tsx +77 -0
  98. package/plugins/design/dev-server/test/use-artboard-drag.test.ts +325 -0
  99. package/plugins/design/dev-server/test/use-selection-set.test.tsx +166 -0
  100. package/plugins/design/dev-server/test/use-snap-guides.test.ts +190 -0
  101. package/plugins/design/dev-server/test/use-tool-mode.test.tsx +93 -0
  102. package/plugins/design/dev-server/test/ws-handshake.test.ts +33 -0
  103. package/plugins/design/dev-server/tool-palette.tsx +278 -0
  104. package/plugins/design/dev-server/tsconfig.json +26 -0
  105. package/plugins/design/dev-server/use-annotation-selection.tsx +92 -0
  106. package/plugins/design/dev-server/use-annotations-visibility.tsx +43 -0
  107. package/plugins/design/dev-server/use-artboard-drag.tsx +445 -0
  108. package/plugins/design/dev-server/use-selection-set.tsx +224 -0
  109. package/plugins/design/dev-server/use-snap-guides.tsx +215 -0
  110. package/plugins/design/dev-server/use-tool-mode.tsx +114 -0
  111. package/plugins/design/dev-server/ws.ts +90 -0
  112. package/plugins/design/templates/_shell.html +177 -0
  113. package/plugins/design/templates/canvas.tsx.template +54 -0
  114. package/plugins/design/templates/design-system-inspiration/_MAPPING.md +277 -0
  115. package/plugins/design/templates/design-system-inspiration/_README.md +71 -0
  116. package/plugins/design/templates/design-system-inspiration/audience-consumer/components-banner.html +68 -0
  117. package/plugins/design/templates/design-system-inspiration/audience-consumer/components-empty-state-generous.html +39 -0
  118. package/plugins/design/templates/design-system-inspiration/audience-consumer/components-feature-grid.html +62 -0
  119. package/plugins/design/templates/design-system-inspiration/audience-consumer/components-marketing-card.html +63 -0
  120. package/plugins/design/templates/design-system-inspiration/audience-consumer/components-testimonial.html +80 -0
  121. package/plugins/design/templates/design-system-inspiration/audience-developer/components-code-block.html +71 -0
  122. package/plugins/design/templates/design-system-inspiration/audience-developer/components-diff-view.html +65 -0
  123. package/plugins/design/templates/design-system-inspiration/audience-developer/components-log-stream.html +62 -0
  124. package/plugins/design/templates/design-system-inspiration/audience-developer/components-monospace-table.html +57 -0
  125. package/plugins/design/templates/design-system-inspiration/audience-developer/components-terminal-pane.html +67 -0
  126. package/plugins/design/templates/design-system-inspiration/audience-developer/type-mono.html +57 -0
  127. package/plugins/design/templates/design-system-inspiration/audience-pro/colors-presence.html +74 -0
  128. package/plugins/design/templates/design-system-inspiration/audience-pro/components-command-palette.html +90 -0
  129. package/plugins/design/templates/design-system-inspiration/audience-pro/components-keyboard.html +51 -0
  130. package/plugins/design/templates/design-system-inspiration/audience-pro/components-list.html +89 -0
  131. package/plugins/design/templates/design-system-inspiration/audience-pro/components-shortcuts-overlay.html +85 -0
  132. package/plugins/design/templates/design-system-inspiration/audience-pro/components-toast-menu.html +80 -0
  133. package/plugins/design/templates/design-system-inspiration/core/INDEX.md.tpl +25 -0
  134. package/plugins/design/templates/design-system-inspiration/core/README.orchestration.md.tpl +71 -0
  135. package/plugins/design/templates/design-system-inspiration/core/README.philosophy.md.tpl +77 -0
  136. package/plugins/design/templates/design-system-inspiration/core/SKILL.md.tpl +50 -0
  137. package/plugins/design/templates/design-system-inspiration/core/colors_and_type.css.tpl +111 -0
  138. package/plugins/design/templates/design-system-inspiration/core/config.json.tpl +28 -0
  139. package/plugins/design/templates/design-system-inspiration/core/preview/_layout.css +113 -0
  140. package/plugins/design/templates/design-system-inspiration/core/preview/colors-accent.html +48 -0
  141. package/plugins/design/templates/design-system-inspiration/core/preview/colors-surfaces.html +49 -0
  142. package/plugins/design/templates/design-system-inspiration/core/preview/colors-text.html +52 -0
  143. package/plugins/design/templates/design-system-inspiration/core/preview/components-buttons.html +83 -0
  144. package/plugins/design/templates/design-system-inspiration/core/preview/components-cards.html +79 -0
  145. package/plugins/design/templates/design-system-inspiration/core/preview/components-inputs.html +82 -0
  146. package/plugins/design/templates/design-system-inspiration/core/preview/motion.html +66 -0
  147. package/plugins/design/templates/design-system-inspiration/core/preview/spacing-scale.html +53 -0
  148. package/plugins/design/templates/design-system-inspiration/core/preview/type-scale.html +62 -0
  149. package/plugins/design/templates/design-system-inspiration/foundations/borders.html +39 -0
  150. package/plugins/design/templates/design-system-inspiration/foundations/elevation.html +46 -0
  151. package/plugins/design/templates/design-system-inspiration/foundations/focus.html +48 -0
  152. package/plugins/design/templates/design-system-inspiration/foundations/grid.html +51 -0
  153. package/plugins/design/templates/design-system-inspiration/foundations/iconography.html +73 -0
  154. package/plugins/design/templates/design-system-inspiration/foundations/opacity.html +45 -0
  155. package/plugins/design/templates/design-system-inspiration/foundations/radii.html +40 -0
  156. package/plugins/design/templates/design-system-inspiration/foundations/selection.html +45 -0
  157. package/plugins/design/templates/design-system-inspiration/meta/accessibility.html +62 -0
  158. package/plugins/design/templates/design-system-inspiration/meta/i18n.html +73 -0
  159. package/plugins/design/templates/design-system-inspiration/meta/presence-multiplayer.html +71 -0
  160. package/plugins/design/templates/design-system-inspiration/meta/tokens-index.html +80 -0
  161. package/plugins/design/templates/design-system-inspiration/patterns/patterns-auth.html +78 -0
  162. package/plugins/design/templates/design-system-inspiration/patterns/patterns-data-density.html +61 -0
  163. package/plugins/design/templates/design-system-inspiration/patterns/patterns-error-pages.html +70 -0
  164. package/plugins/design/templates/design-system-inspiration/patterns/patterns-form-layouts.html +70 -0
  165. package/plugins/design/templates/design-system-inspiration/patterns/patterns-onboarding.html +71 -0
  166. package/plugins/design/templates/design-system-inspiration/patterns/patterns-pricing.html +83 -0
  167. package/plugins/design/templates/design-system-inspiration/platform-desktop/components-resize-panels.html +63 -0
  168. package/plugins/design/templates/design-system-inspiration/platform-desktop/ui_kits-desktop-index.html +55 -0
  169. package/plugins/design/templates/design-system-inspiration/platform-desktop/ui_kits-desktop-showcase.html +302 -0
  170. package/plugins/design/templates/design-system-inspiration/platform-mobile/components-bottom-sheet.html +63 -0
  171. package/plugins/design/templates/design-system-inspiration/platform-mobile/components-pull-to-refresh.html +74 -0
  172. package/plugins/design/templates/design-system-inspiration/platform-mobile/components-segmented-control.html +51 -0
  173. package/plugins/design/templates/design-system-inspiration/platform-mobile/components-tab-bar.html +57 -0
  174. package/plugins/design/templates/design-system-inspiration/platform-mobile/ui_kits-mobile-index.html +58 -0
  175. package/plugins/design/templates/design-system-inspiration/platform-mobile/ui_kits-mobile-showcase.html +237 -0
  176. package/plugins/design/templates/design-system-inspiration/status/colors-status.html +49 -0
  177. package/plugins/design/templates/design-system-inspiration/status/components-status.html +63 -0
  178. package/plugins/design/templates/design-system-inspiration/status/skeletons.html +74 -0
  179. package/plugins/design/templates/design-system-inspiration/theme-both/colors-themes-side-by-side.html +59 -0
  180. package/plugins/design/templates/design-system-inspiration/universal/components-callout.html +74 -0
  181. package/plugins/design/templates/design-system-inspiration/universal/components-dialogs.html +81 -0
  182. package/plugins/design/templates/design-system-inspiration/universal/components-tables.html +101 -0
  183. package/plugins/design/templates/design-system-inspiration/universal/components-toggles.html +74 -0
  184. package/plugins/design/templates/design-system-inspiration/universal/components-tooltips.html +74 -0
  185. package/plugins/design/templates/design-system-inspiration/universal/empty-state.html.tpl +34 -0
  186. package/plugins/design/templates/design-system-inspiration/universal/logo.html +42 -0
  187. package/plugins/design/templates/ds-specimen.tsx.template +59 -0
  188. package/plugins/flow/.claude-plugin/config.schema.json +398 -0
  189. package/plugins/flow/README.md +45 -0
  190. package/plugins/flow/templates/ai-skeleton/INDEX.md +50 -0
  191. package/plugins/flow/templates/ai-skeleton/README.md +46 -0
  192. package/plugins/flow/templates/ai-skeleton/browser/har/.gitkeep +0 -0
  193. package/plugins/flow/templates/ai-skeleton/browser/snapshots/.gitkeep +0 -0
  194. package/plugins/flow/templates/ai-skeleton/business/README.md +12 -0
  195. package/plugins/flow/templates/ai-skeleton/context/README.md +12 -0
  196. package/plugins/flow/templates/ai-skeleton/decisions/README.md +20 -0
  197. package/plugins/flow/templates/ai-skeleton/design-import/.gitkeep +0 -0
  198. package/plugins/flow/templates/ai-skeleton/dev-logs/.gitkeep +0 -0
  199. package/plugins/flow/templates/ai-skeleton/device/.gitkeep +0 -0
  200. package/plugins/flow/templates/ai-skeleton/docs/README.md +5 -0
  201. package/plugins/flow/templates/ai-skeleton/logs/.gitkeep +0 -0
  202. package/plugins/flow/templates/ai-skeleton/logs/README.md +13 -0
  203. package/plugins/flow/templates/ai-skeleton/plans/README.md +16 -0
  204. package/plugins/flow/templates/ai-skeleton/plans/archive/.gitkeep +0 -0
  205. package/plugins/flow/templates/ai-skeleton/release-guide.md +35 -0
  206. package/plugins/flow/templates/ai-skeleton/reviews/README.md +15 -0
  207. package/plugins/flow/templates/ai-skeleton/scenarios/README.md +26 -0
  208. package/plugins/flow/templates/ai-skeleton/scenarios/_lib/.gitkeep +0 -0
  209. package/plugins/flow/templates/ai-skeleton/state/STATE.md +25 -0
  210. package/plugins/flow/templates/ai-skeleton/templates/HANDOFF.md +32 -0
  211. package/plugins/flow/templates/ai-skeleton/workflows.config.json +74 -0
@@ -0,0 +1,397 @@
1
+ /**
2
+ * @file annotations-context-toolbar.tsx — Phase 5.1 per-selection toolbar
3
+ * @scope plugins/design/dev-server/annotations-context-toolbar.tsx
4
+ * @purpose FigJam-style floating chrome anchored above the currently
5
+ * selected annotation strokes. Reads `useAnnotationSelection` +
6
+ * `useStrokesStore`; mutations dispatch through the store so the
7
+ * debounced save kicks in automatically.
8
+ *
9
+ * Positioning:
10
+ * - Compute the union bbox in screen coords by calling
11
+ * `getBoundingClientRect` on each selected stroke's rendered SVG node
12
+ * (the SVG sits inside `.dc-world` so the rect already reflects the
13
+ * world's CSS zoom + translate).
14
+ * - Anchor 8 px above the bbox. Fall back to BELOW if there's no headroom.
15
+ *
16
+ * Field visibility — intersect across selection per the plan:
17
+ * - color, delete: always
18
+ * - fill: only when every stroke is rect or ellipse
19
+ * - thickness: only when every stroke is pen or arrow
20
+ * - font-size: only when at least one stroke is text (and the rest are its host)
21
+ */
22
+
23
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
24
+
25
+ import { type Stroke, useStrokesStore } from './annotations-layer.tsx';
26
+ import { useAnnotationSelectionOptional } from './use-annotation-selection.tsx';
27
+
28
+ const PALETTE = ['#d63b1f', '#f5a623', '#1a8f3e', '#1d6cf0', '#7a4ad3', '#1a1a1a'] as const;
29
+
30
+ const FILL_PALETTE = ['#fff4d6', '#e6f4ea', '#e3edff', '#f0e8fb', '#ffe5e0', '#f4f1ee'] as const;
31
+
32
+ const TOOLBAR_CSS = `
33
+ .dc-annot-ctx {
34
+ position: fixed;
35
+ z-index: 7;
36
+ display: flex;
37
+ align-items: center;
38
+ gap: 6px;
39
+ background: var(--bg-1, rgba(255,255,255,0.98));
40
+ border: 1px solid var(--u-border-2, rgba(0,0,0,0.08));
41
+ border-radius: 8px;
42
+ padding: 6px 8px;
43
+ box-shadow: 0 8px 24px rgba(0,0,0,0.10);
44
+ font-family: ui-sans-serif, system-ui, sans-serif;
45
+ font-size: 12px;
46
+ color: var(--fg-0, #1a1a1a);
47
+ user-select: none;
48
+ pointer-events: auto;
49
+ }
50
+ .dc-annot-ctx-sw {
51
+ width: 16px;
52
+ height: 16px;
53
+ border-radius: 3px;
54
+ border: 1px solid rgba(0,0,0,0.12);
55
+ cursor: pointer;
56
+ padding: 0;
57
+ appearance: none;
58
+ }
59
+ .dc-annot-ctx-sw[aria-pressed="true"] {
60
+ box-shadow: 0 0 0 2px var(--accent, #d63b1f);
61
+ border-color: transparent;
62
+ }
63
+ .dc-annot-ctx-fill--none {
64
+ background: #fff;
65
+ position: relative;
66
+ }
67
+ .dc-annot-ctx-fill--none::after {
68
+ content: "";
69
+ position: absolute; inset: 2px;
70
+ background:
71
+ linear-gradient(135deg, transparent 47%, #d63b1f 47%, #d63b1f 53%, transparent 53%);
72
+ }
73
+ .dc-annot-ctx-sep {
74
+ width: 1px;
75
+ align-self: stretch;
76
+ background: rgba(0,0,0,0.10);
77
+ margin: 0 2px;
78
+ }
79
+ .dc-annot-ctx-btn {
80
+ appearance: none;
81
+ background: transparent;
82
+ border: 1px solid rgba(0,0,0,0.12);
83
+ border-radius: 4px;
84
+ padding: 3px 8px;
85
+ font: inherit;
86
+ color: inherit;
87
+ cursor: pointer;
88
+ }
89
+ .dc-annot-ctx-btn[aria-pressed="true"] {
90
+ background: var(--accent, #d63b1f);
91
+ color: var(--accent-fg, #fff);
92
+ border-color: transparent;
93
+ }
94
+ .dc-annot-ctx-btn:hover { background: rgba(0,0,0,0.04); }
95
+ .dc-annot-ctx-btn--danger { color: #b3271a; }
96
+ .dc-annot-ctx-btn--danger:hover { background: rgba(214,59,31,0.08); }
97
+ `.trim();
98
+
99
+ function ensureToolbarStyles(): void {
100
+ if (typeof document === 'undefined') return;
101
+ if (document.getElementById('dc-annot-ctx-css')) return;
102
+ const s = document.createElement('style');
103
+ s.id = 'dc-annot-ctx-css';
104
+ s.textContent = TOOLBAR_CSS;
105
+ document.head.appendChild(s);
106
+ }
107
+
108
+ function unionRect(rects: DOMRect[]): { x: number; y: number; w: number; h: number } | null {
109
+ if (rects.length === 0) return null;
110
+ let xMin = Number.POSITIVE_INFINITY;
111
+ let yMin = Number.POSITIVE_INFINITY;
112
+ let xMax = Number.NEGATIVE_INFINITY;
113
+ let yMax = Number.NEGATIVE_INFINITY;
114
+ for (const r of rects) {
115
+ if (r.width === 0 && r.height === 0) continue;
116
+ if (r.left < xMin) xMin = r.left;
117
+ if (r.top < yMin) yMin = r.top;
118
+ if (r.right > xMax) xMax = r.right;
119
+ if (r.bottom > yMax) yMax = r.bottom;
120
+ }
121
+ if (!Number.isFinite(xMin)) return null;
122
+ return { x: xMin, y: yMin, w: xMax - xMin, h: yMax - yMin };
123
+ }
124
+
125
+ export function AnnotationContextToolbar() {
126
+ ensureToolbarStyles();
127
+ const annotSel = useAnnotationSelectionOptional();
128
+ const store = useStrokesStore();
129
+ const ref = useRef<HTMLDivElement | null>(null);
130
+ const rafRef = useRef<number | null>(null);
131
+ const [, force] = useState({});
132
+
133
+ const selectedStrokes = useMemo<Stroke[]>(() => {
134
+ if (!annotSel || !store) return [];
135
+ const map = new Map(store.strokes.map((s) => [s.id, s]));
136
+ const out: Stroke[] = [];
137
+ for (const id of annotSel.selectedIds) {
138
+ const s = map.get(id);
139
+ if (s) out.push(s);
140
+ }
141
+ return out;
142
+ }, [annotSel, store]);
143
+
144
+ // Capabilities — intersection across selected types.
145
+ const caps = useMemo(() => {
146
+ if (selectedStrokes.length === 0) {
147
+ return { color: false, fill: false, thickness: false, fontSize: false };
148
+ }
149
+ const allFillable = selectedStrokes.every((s) => s.tool === 'rect' || s.tool === 'ellipse');
150
+ const allThickness = selectedStrokes.every((s) => s.tool === 'pen' || s.tool === 'arrow');
151
+ const anyText = selectedStrokes.some((s) => s.tool === 'text');
152
+ return {
153
+ color: true,
154
+ fill: allFillable,
155
+ thickness: allThickness,
156
+ fontSize: anyText,
157
+ };
158
+ }, [selectedStrokes]);
159
+
160
+ // Position tracker — uses rAF to follow pan/zoom while the toolbar is up.
161
+ useEffect(() => {
162
+ if (selectedStrokes.length === 0) return;
163
+ const tick = () => {
164
+ rafRef.current = null;
165
+ const el = ref.current;
166
+ if (!el) return;
167
+ const rects: DOMRect[] = [];
168
+ for (const s of selectedStrokes) {
169
+ const node = document.querySelector(`[data-id="${cssEscape(s.id)}"]`);
170
+ if (node) rects.push(node.getBoundingClientRect());
171
+ }
172
+ const u = unionRect(rects);
173
+ if (!u) {
174
+ el.style.display = 'none';
175
+ rafRef.current = requestAnimationFrame(tick);
176
+ return;
177
+ }
178
+ el.style.display = 'flex';
179
+ // Lay out off-screen first so the size is real, then position.
180
+ const tbW = el.offsetWidth || 280;
181
+ const tbH = el.offsetHeight || 36;
182
+ const margin = 8;
183
+ let top = u.y - tbH - margin;
184
+ if (top < 8) top = u.y + u.h + margin;
185
+ let left = u.x + (u.w - tbW) / 2;
186
+ const winW = typeof window !== 'undefined' ? window.innerWidth : tbW + 16;
187
+ if (left < 8) left = 8;
188
+ if (left + tbW > winW - 8) left = winW - tbW - 8;
189
+ el.style.left = `${Math.round(left)}px`;
190
+ el.style.top = `${Math.round(top)}px`;
191
+ rafRef.current = requestAnimationFrame(tick);
192
+ };
193
+ rafRef.current = requestAnimationFrame(tick);
194
+ return () => {
195
+ if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
196
+ };
197
+ }, [selectedStrokes]);
198
+
199
+ // Force a re-render when the strokes themselves mutate (the position rAF
200
+ // already follows the bbox; this ensures the active-state of the swatches
201
+ // reflects the current color/fill/thickness without a full app re-render).
202
+ // biome-ignore lint/correctness/useExhaustiveDependencies: selectedStrokes is the trigger; force is a setState identity.
203
+ useEffect(() => {
204
+ force({});
205
+ }, [selectedStrokes]);
206
+
207
+ const setColor = useCallback(
208
+ (c: string) => {
209
+ if (!store) return;
210
+ for (const s of selectedStrokes) store.updateStroke(s.id, { color: c });
211
+ },
212
+ [store, selectedStrokes]
213
+ );
214
+ const setFill = useCallback(
215
+ (f: string | null) => {
216
+ if (!store) return;
217
+ for (const s of selectedStrokes) {
218
+ if (s.tool === 'rect' || s.tool === 'ellipse') {
219
+ store.updateStroke(s.id, { fill: f } as Partial<Stroke>);
220
+ }
221
+ }
222
+ },
223
+ [store, selectedStrokes]
224
+ );
225
+ const setThickness = useCallback(
226
+ (w: number) => {
227
+ if (!store) return;
228
+ for (const s of selectedStrokes) {
229
+ if (s.tool === 'pen' || s.tool === 'arrow') {
230
+ store.updateStroke(s.id, { width: w } as Partial<Stroke>);
231
+ }
232
+ }
233
+ },
234
+ [store, selectedStrokes]
235
+ );
236
+ const setFontSize = useCallback(
237
+ (sz: number) => {
238
+ if (!store) return;
239
+ for (const s of selectedStrokes) {
240
+ if (s.tool === 'text') {
241
+ store.updateStroke(s.id, { fontSize: sz } as Partial<Stroke>);
242
+ }
243
+ }
244
+ },
245
+ [store, selectedStrokes]
246
+ );
247
+ const remove = useCallback(() => {
248
+ if (!annotSel || !store) return;
249
+ store.deleteStrokes(annotSel.selectedIds);
250
+ annotSel.clear();
251
+ }, [annotSel, store]);
252
+
253
+ if (!annotSel || !store || selectedStrokes.length === 0) return null;
254
+
255
+ // Active values for swatch highlighting — when uniform across selection.
256
+ const uniqColor = uniformValue(selectedStrokes.map((s) => s.color));
257
+ const uniqFill = caps.fill
258
+ ? uniformValue(
259
+ selectedStrokes.map((s) =>
260
+ s.tool === 'rect' || s.tool === 'ellipse' ? (s.fill ?? null) : undefined
261
+ )
262
+ )
263
+ : undefined;
264
+ const uniqThickness = caps.thickness
265
+ ? uniformValue(
266
+ selectedStrokes.map((s) => (s.tool === 'pen' || s.tool === 'arrow' ? s.width : undefined))
267
+ )
268
+ : undefined;
269
+ const uniqFontSize = caps.fontSize
270
+ ? uniformValue(selectedStrokes.map((s) => (s.tool === 'text' ? s.fontSize : undefined)))
271
+ : undefined;
272
+
273
+ return (
274
+ <div
275
+ ref={ref}
276
+ className="dc-annot-ctx"
277
+ role="toolbar"
278
+ aria-label="Annotation properties"
279
+ style={{ display: 'flex', top: -9999, left: -9999 }}
280
+ >
281
+ {PALETTE.map((c) => (
282
+ <button
283
+ key={c}
284
+ type="button"
285
+ className="dc-annot-ctx-sw"
286
+ aria-label={`Color ${c}`}
287
+ aria-pressed={uniqColor === c}
288
+ title={`Color ${c}`}
289
+ style={{ background: c }}
290
+ onClick={() => setColor(c)}
291
+ />
292
+ ))}
293
+ {caps.fill ? (
294
+ <>
295
+ <div className="dc-annot-ctx-sep" />
296
+ <button
297
+ type="button"
298
+ className="dc-annot-ctx-sw dc-annot-ctx-fill--none"
299
+ aria-label="No fill"
300
+ aria-pressed={uniqFill == null}
301
+ title="No fill"
302
+ onClick={() => setFill(null)}
303
+ />
304
+ {FILL_PALETTE.map((c) => (
305
+ <button
306
+ key={c}
307
+ type="button"
308
+ className="dc-annot-ctx-sw"
309
+ aria-label={`Fill ${c}`}
310
+ aria-pressed={uniqFill === c}
311
+ title={`Fill ${c}`}
312
+ style={{ background: c }}
313
+ onClick={() => setFill(c)}
314
+ />
315
+ ))}
316
+ </>
317
+ ) : null}
318
+ {caps.thickness ? (
319
+ <>
320
+ <div className="dc-annot-ctx-sep" />
321
+ <button
322
+ type="button"
323
+ className="dc-annot-ctx-btn"
324
+ aria-pressed={uniqThickness === 2}
325
+ title="Thin (2px)"
326
+ onClick={() => setThickness(2)}
327
+ >
328
+ Thin
329
+ </button>
330
+ <button
331
+ type="button"
332
+ className="dc-annot-ctx-btn"
333
+ aria-pressed={uniqThickness === 6}
334
+ title="Thick (6px)"
335
+ onClick={() => setThickness(6)}
336
+ >
337
+ Thick
338
+ </button>
339
+ </>
340
+ ) : null}
341
+ {caps.fontSize ? (
342
+ <>
343
+ <div className="dc-annot-ctx-sep" />
344
+ <button
345
+ type="button"
346
+ className="dc-annot-ctx-btn"
347
+ aria-pressed={uniqFontSize === 12}
348
+ title="Small (12px)"
349
+ onClick={() => setFontSize(12)}
350
+ >
351
+ S
352
+ </button>
353
+ <button
354
+ type="button"
355
+ className="dc-annot-ctx-btn"
356
+ aria-pressed={uniqFontSize === 14}
357
+ title="Medium (14px)"
358
+ onClick={() => setFontSize(14)}
359
+ >
360
+ M
361
+ </button>
362
+ <button
363
+ type="button"
364
+ className="dc-annot-ctx-btn"
365
+ aria-pressed={uniqFontSize === 20}
366
+ title="Large (20px)"
367
+ onClick={() => setFontSize(20)}
368
+ >
369
+ L
370
+ </button>
371
+ </>
372
+ ) : null}
373
+ <div className="dc-annot-ctx-sep" />
374
+ <button
375
+ type="button"
376
+ className="dc-annot-ctx-btn dc-annot-ctx-btn--danger"
377
+ title="Delete (Backspace)"
378
+ aria-label="Delete selected annotations"
379
+ onClick={remove}
380
+ >
381
+ Delete
382
+ </button>
383
+ </div>
384
+ );
385
+ }
386
+ AnnotationContextToolbar.displayName = 'AnnotationContextToolbar';
387
+
388
+ function uniformValue<T>(values: (T | undefined)[]): T | undefined {
389
+ const filtered = values.filter((v) => v !== undefined) as T[];
390
+ if (filtered.length === 0) return undefined;
391
+ const first = filtered[0];
392
+ return filtered.every((v) => v === first) ? first : undefined;
393
+ }
394
+
395
+ function cssEscape(s: string): string {
396
+ return s.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
397
+ }