@1agh/maude 1.8.1 → 1.9.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 (73) hide show
  1. package/apps/studio/acp/bridge.ts +14 -2
  2. package/apps/studio/acp/probe.ts +51 -1
  3. package/apps/studio/api.ts +19 -4
  4. package/apps/studio/bin/_curl-local.mjs +7 -0
  5. package/apps/studio/bin/annotate.mjs +16 -7
  6. package/apps/studio/bin/read-annotations.mjs +62 -4
  7. package/apps/studio/client/app.jsx +428 -15977
  8. package/apps/studio/client/dialogs/asset-picker.jsx +331 -0
  9. package/apps/studio/client/dialogs/command-palette.jsx +112 -0
  10. package/apps/studio/client/dialogs/export-dialog.jsx +782 -0
  11. package/apps/studio/client/dialogs/help-modal.jsx +324 -0
  12. package/apps/studio/client/dialogs/shortcuts-overlay.jsx +144 -0
  13. package/apps/studio/client/hooks/use-canvas-bridge.jsx +2150 -0
  14. package/apps/studio/client/hooks/use-git-actions.jsx +236 -0
  15. package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +297 -0
  16. package/apps/studio/client/hooks/use-palette-and-panels.jsx +474 -0
  17. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +901 -0
  18. package/apps/studio/client/hooks/use-project-data.jsx +90 -0
  19. package/apps/studio/client/hooks/use-shell-core.jsx +1212 -0
  20. package/apps/studio/client/hooks/use-tabs.jsx +723 -0
  21. package/apps/studio/client/hooks/use-web-socket.jsx +13 -0
  22. package/apps/studio/client/inspector/artboard-knobs.jsx +456 -0
  23. package/apps/studio/client/inspector/color-picker.jsx +196 -0
  24. package/apps/studio/client/inspector/color.js +92 -0
  25. package/apps/studio/client/inspector/css-knobs.jsx +1720 -0
  26. package/apps/studio/client/inspector/css-vocab.jsx +131 -0
  27. package/apps/studio/client/inspector/ds-tokens.js +90 -0
  28. package/apps/studio/client/inspector/grid-tracks-editor.jsx +97 -0
  29. package/apps/studio/client/inspector/inspect-computed.jsx +68 -0
  30. package/apps/studio/client/inspector/inspector-panel.jsx +769 -0
  31. package/apps/studio/client/inspector/layers.jsx +322 -0
  32. package/apps/studio/client/inspector/selection.js +65 -0
  33. package/apps/studio/client/inspector/token-popover.jsx +301 -0
  34. package/apps/studio/client/menus/menubar.jsx +856 -0
  35. package/apps/studio/client/selection-scope.js +40 -0
  36. package/apps/studio/client/shell/banners.jsx +272 -0
  37. package/apps/studio/client/shell/collapsed-rail.jsx +23 -0
  38. package/apps/studio/client/shell/comments-panel.jsx +177 -0
  39. package/apps/studio/client/shell/constants.js +60 -0
  40. package/apps/studio/client/shell/dock.jsx +131 -0
  41. package/apps/studio/client/shell/icons.jsx +370 -0
  42. package/apps/studio/client/shell/status-bar.jsx +215 -0
  43. package/apps/studio/client/shell/util.js +332 -0
  44. package/apps/studio/client/shell/viewport.jsx +254 -0
  45. package/apps/studio/client/system/system-view.jsx +255 -0
  46. package/apps/studio/client/tree/tree.jsx +1243 -0
  47. package/apps/studio/comments-overlay.tsx +6 -4
  48. package/apps/studio/config.schema.json +5 -0
  49. package/apps/studio/context.ts +13 -0
  50. package/apps/studio/dist/client.bundle.js +1337 -1337
  51. package/apps/studio/dist/comment-mount.js +2 -2
  52. package/apps/studio/exporters/_browser-bundles.ts +21 -2
  53. package/apps/studio/exporters/jobs.ts +75 -15
  54. package/apps/studio/exporters/scope.ts +15 -12
  55. package/apps/studio/format.ts +296 -0
  56. package/apps/studio/http.ts +213 -23
  57. package/apps/studio/server.ts +118 -29
  58. package/apps/studio/sync/accepted-link.ts +6 -0
  59. package/apps/studio/sync/agent.ts +9 -1
  60. package/apps/studio/sync/cold-start-apply.ts +29 -4
  61. package/apps/studio/sync/cold-start.ts +78 -0
  62. package/apps/studio/sync/file-plane.ts +61 -1
  63. package/apps/studio/sync/format-sync.ts +160 -0
  64. package/apps/studio/sync/index.ts +134 -10
  65. package/apps/studio/sync/journal-client.ts +25 -5
  66. package/apps/studio/sync/migrate-seed.ts +8 -1
  67. package/apps/studio/sync/status.ts +2 -0
  68. package/apps/studio/sync/transaction-client.ts +130 -13
  69. package/apps/studio/ui-prefs.ts +95 -10
  70. package/apps/studio/whats-new.json +9 -0
  71. package/apps/studio/ws.ts +19 -4
  72. package/cli/bin/claude-design-server.mjs +0 -0
  73. package/package.json +10 -8
@@ -0,0 +1,13 @@
1
+ // hooks/use-web-socket.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
2
+
3
+ import { useEffect, useRef } from 'react';
4
+
5
+ export function useWebSocket({ loadAllComments }) {
6
+ useEffect(() => {
7
+ loadAllComments();
8
+ }, [loadAllComments]);
9
+
10
+ // ----- WebSocket -----
11
+ const canvasListChangeRef = useRef(() => {});
12
+ return { canvasListChangeRef };
13
+ }
@@ -0,0 +1,456 @@
1
+ // inspector/artboard-knobs.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
2
+
3
+ import { activeDsNameFor, useAllDsTokens } from './ds-tokens.js';
4
+ import { SCREEN_PRESETS } from './css-vocab.jsx';
5
+ import { PAPER_PRESETS, resolvePrintArtboard } from '../../print/units.ts';
6
+ import { resolveHeightCommit } from '../../artboard-hug-commit.ts';
7
+ import { ColorField, NumberField, Segmented, Select, ValueTokenField } from '../inspector-controls.jsx';
8
+ import { TokenPopover } from './token-popover.jsx';
9
+ import { cssColorToHex } from './color.js';
10
+
11
+ // Dogfood 2026-07-07 — resolve the artboard id for a whole-artboard selection
12
+ // defensively: prefer `el.artboardId` (set by `hoverTargetToSelection` for a
13
+ // live chrome click), but fall back to parsing it out of `el.selector` — some
14
+ // selection-construction paths (Layers-tree artboard row, a restored
15
+ // `_active.json` selection) may not carry `artboardId` even though the
16
+ // selector is always the `[data-dc-screen="…"]` chrome form for one.
17
+ export function resolveArtboardIdFromSelection(el) {
18
+ if (el.artboardId) return el.artboardId;
19
+ const m = /^\[data-dc-screen="([^"]+)"\]$/.exec(el.selector || '');
20
+ return m ? m[1] : null;
21
+ }
22
+
23
+ // Dogfood 2026-07-07 — the CSS tab showed everything disabled for a
24
+ // whole-ARTBOARD selection (`CssKnobs`'s `editable = !!el.id`, and an artboard
25
+ // chrome click has NO data-cd-id — DCArtboard doesn't forward it to the DOM).
26
+ // A dedicated, MUCH smaller panel: exact width/height fields (writes via
27
+ // /_api/resize-artboard, NOT edit-css — DDR-027 numeric JSX props) + the SAME
28
+ // SCREEN_PRESETS the "+ Artboard" menu uses, so picking "Tablet" resizes the
29
+ // CURRENT artboard to 834×1194 in one click instead of typing both fields.
30
+ export const ARTBOARD_LAYOUT_OPTIONS = [
31
+ ['', 'Block (default)'],
32
+ ['flex-col', 'Flex ↓ (column)'],
33
+ ['flex-row', 'Flex → (row)'],
34
+ ['grid', 'Grid'],
35
+ ];
36
+
37
+ // feature-1-artboard-kinds-foundation, T8 — kind picker options. Order
38
+ // mirrors the DCArtboard `kind` union; 'digital' is the implicit default
39
+ // (writes `kind: null`, clearing the explicit prop, per applySetArtboardKind).
40
+ export const ARTBOARD_KIND_OPTIONS = [
41
+ ['digital', 'Digital'],
42
+ ['print', 'Print'],
43
+ ['web', 'Web'],
44
+ ['video', 'Video'],
45
+ ];
46
+
47
+ export function ArtboardKnobs({
48
+ el,
49
+ cfg,
50
+ onResizeArtboard,
51
+ onSetArtboardHug,
52
+ onSetArtboardStyle,
53
+ onSetArtboardKind,
54
+ onSetArtboardPrint,
55
+ onDuplicateArtboard,
56
+ }) {
57
+ const artboardId = resolveArtboardIdFromSelection(el);
58
+ // Dogfood (artboard panel ↔ shared inspector controls) — the panel now uses
59
+ // the SAME control library + design-token plumbing as CssKnobs (NumberField
60
+ // / Segmented / Select / ColorField+TokenPopover / ValueTokenField), so Bg
61
+ // binds color variables and Pad/Gap bind space variables exactly like any
62
+ // CSS-panel row. Token resolution mirrors CssKnobs' own tokenGroups/
63
+ // flatTokens closures over useAllDsTokens.
64
+ const _designRel = (cfg?.designRel || cfg?.designRoot || '.design').replace(/^\/+|\/+$/g, '');
65
+ const _activeDs = activeDsNameFor(el.file, cfg);
66
+ const allDs = useAllDsTokens(cfg, _designRel, _activeDs);
67
+ const tokenGroups = (familyKey) =>
68
+ allDs
69
+ .map((d) => ({ ds: d.name, names: d[familyKey] || [], vals: d.vals }))
70
+ .filter((g) => g.names.length);
71
+ const flatTokens = (familyKey) =>
72
+ tokenGroups(familyKey).flatMap((g) => (g.names || []).map((n) => ({ name: n, value: g.vals?.[n] || '' })));
73
+ // Resolve a `var(--x)` binding to its concrete value across every DS (for
74
+ // the Bg swatch color); a raw value passes through.
75
+ const resolveTokenValue = (v) => {
76
+ const m = /^var\(\s*(--[\w-]+)\s*\)$/.exec(v || '');
77
+ if (!m) return v || '';
78
+ for (const d of allDs) {
79
+ const val = d.vals?.[m[1]];
80
+ if (val) return val;
81
+ }
82
+ return '';
83
+ };
84
+ // Dogfood 2026-07-07 (round 2) — `worldW`/`worldH` (zoom-independent) are
85
+ // undefined for a selection that reached here via a code path predating
86
+ // that field (a canvas iframe that hasn't remounted since); fall back to
87
+ // `bounds` (the SCREEN rect — always populated, but wrong at any zoom other
88
+ // than 100%) so the fields show SOMETHING rather than sit empty. Self-heals
89
+ // to the exact value the moment `worldW`/`worldH` are present.
90
+ const w = Number.isFinite(el.worldW)
91
+ ? el.worldW
92
+ : Number.isFinite(el.bounds?.w)
93
+ ? el.bounds.w
94
+ : null;
95
+ const h = Number.isFinite(el.worldH)
96
+ ? el.worldH
97
+ : Number.isFinite(el.bounds?.h)
98
+ ? el.bounds.h
99
+ : null;
100
+ const commitSize = (width, height) => {
101
+ if (!artboardId) return;
102
+ const nw = Number.isFinite(width) && width > 0 ? Math.round(width) : undefined;
103
+ const nh = Number.isFinite(height) && height > 0 ? Math.round(height) : undefined;
104
+ if (nw == null && nh == null) return;
105
+ onResizeArtboard?.(artboardId, nw, nh);
106
+ };
107
+ const activePreset = Object.entries(SCREEN_PRESETS).find(
108
+ ([, p]) => p.width === w && p.height === h
109
+ )?.[0];
110
+ // feature-3-web-artboards T2 — a web artboard hugs height (Design Decision
111
+ // 1), so its `h` rarely equals a preset's device height even when the
112
+ // artboard genuinely represents that breakpoint. Match by WIDTH alone so
113
+ // the picker still shows "Desktop" selected after the hugged height
114
+ // settles to the content's real size.
115
+ const activeWidthPreset = Object.entries(SCREEN_PRESETS).find(([, p]) => p.width === w)?.[0];
116
+ // Hug default (artboard "hug height") — current mode + the "more settings"
117
+ // (background/padding/layout/gap) read off the SAME generic `attrs` escape
118
+ // hatch dom-selection.ts already scrapes for every selection (the `data-dc-*`
119
+ // attributes DCArtboard stamps on the frame purely for this panel to read
120
+ // its own resolved props back — see canvas-lib.tsx readBackAttrs).
121
+ const fixed = el.attrs?.['data-dc-fixed'] === 'true';
122
+ const bg = el.attrs?.['data-dc-bg'] ?? '';
123
+ const padding = el.attrs?.['data-dc-padding'] ?? '';
124
+ const layoutMode = el.attrs?.['data-dc-layout'] ?? '';
125
+ const gap = el.attrs?.['data-dc-gap'] ?? '';
126
+ // T8 — `data-dc-kind` is DCArtboard's RESOLVED kind (readBackAttrs always
127
+ // emits it, unlike the optional-override attrs above — see T1's comment on
128
+ // why), so this reads 'digital' even for an implicit/unmigrated artboard.
129
+ const kind = el.attrs?.['data-dc-kind'] || 'digital';
130
+ // feature-2-print-artboards T2 — paper/orientation/bleed. Read-back mirrors
131
+ // `data-dc-kind` above: a small JSON attr DCArtboard stamps for exactly this
132
+ // panel (canvas-lib.tsx readBackAttrs), since `print` (unlike bg/padding/…)
133
+ // is object-valued, not a scalar.
134
+ let print = null;
135
+ try {
136
+ print = el.attrs?.['data-dc-print'] ? JSON.parse(el.attrs['data-dc-print']) : null;
137
+ } catch {
138
+ /* malformed attr — treat as absent */
139
+ }
140
+ const setKind = (nextKind) => {
141
+ if (!artboardId) return;
142
+ // Dogfood fix — switching TO "print" with no print prop yet left the
143
+ // artboard half-configured (no guides geometry, no bleed for the PDF
144
+ // exporter). Seed a default A4 print prop + its resolved px size in the
145
+ // SAME gesture. Round 6: the seed is PASSED THROUGH the kind flow (not
146
+ // written immediately) so the freeze-convert the canvas may enqueue first
147
+ // lands BEFORE the A4 resize — resizing pre-freeze moved elements around
148
+ // while the confirm dialog was still open.
149
+ let seedPrint = null;
150
+ if (nextKind === 'print' && !print) {
151
+ const defaults = { paper: 'a4' };
152
+ try {
153
+ const resolved = resolvePrintArtboard(defaults);
154
+ if (resolved) {
155
+ seedPrint = { defaults, widthPx: resolved.widthPx, heightPx: resolved.heightPx };
156
+ }
157
+ } catch {
158
+ /* keep null */
159
+ }
160
+ }
161
+ // Picking "Digital" clears the explicit prop back to the implicit
162
+ // default (applySetArtboardKind's `kind: null` path) rather than writing
163
+ // a redundant `kind="digital"`.
164
+ onSetArtboardKind?.(artboardId, nextKind === 'digital' ? null : nextKind, seedPrint);
165
+ // feature-3-web-artboards Design Decision 1 — a web artboard's height
166
+ // hugs content (`fixed` omitted); switching TO "web" flips hug mode in
167
+ // the same gesture so the artboard doesn't stay pinned to whatever exact
168
+ // height a prior digital/print size left it at. Mirrors the print
169
+ // auto-seed above — switching kind should never require a second,
170
+ // easy-to-miss step in the Hug/Fixed segmented control above.
171
+ if (nextKind === 'web' && fixed) {
172
+ onSetArtboardHug?.(artboardId, false, undefined);
173
+ }
174
+ };
175
+ const setPrint = (patch) => {
176
+ if (!artboardId) return;
177
+ const next = { paper: 'a4', ...print, ...patch };
178
+ let resolved;
179
+ try {
180
+ resolved = resolvePrintArtboard(next);
181
+ } catch {
182
+ return; // unknown paper id — ignore rather than write garbage
183
+ }
184
+ // Design Decision 2 — the picker writes BOTH the resolved px size (via
185
+ // the existing resize lane, DDR-027) and the `print` intent prop, in the
186
+ // same gesture, so geometry and intent never drift apart.
187
+ onResizeArtboard?.(artboardId, resolved.widthPx, resolved.heightPx);
188
+ onSetArtboardPrint?.(artboardId, next);
189
+ };
190
+ const setHug = (nextFixed, explicitHeight) => {
191
+ if (!artboardId) return;
192
+ const src = Number.isFinite(explicitHeight) ? explicitHeight : h;
193
+ const freezeHeight = nextFixed && Number.isFinite(src) ? Math.round(src) : undefined;
194
+ onSetArtboardHug?.(artboardId, nextFixed, freezeHeight);
195
+ };
196
+ const commitHeight = (n) => {
197
+ const action = resolveHeightCommit(fixed, n);
198
+ if (action.kind === 'resize') commitSize(null, action.height);
199
+ else if (action.kind === 'promote-to-fixed') setHug(true, action.height);
200
+ };
201
+ const commitStyle = (patch) => {
202
+ if (!artboardId) return;
203
+ onSetArtboardStyle?.(artboardId, patch);
204
+ };
205
+ return (
206
+ <section className="st-cp-sec">
207
+ <div className="st-cp-sechd-row">
208
+ <span className="st-cp-sechd">Artboard</span>
209
+ </div>
210
+ <div style={{ display: 'flex', gap: 8, padding: '4px 12px' }}>
211
+ <NumberField
212
+ value={w ?? 0}
213
+ min={1}
214
+ ariaLabel="artboard width"
215
+ lead="W"
216
+ steppers={false}
217
+ onCommit={(n) => commitSize(n, null)}
218
+ />
219
+ <NumberField
220
+ value={h ?? 0}
221
+ min={1}
222
+ ariaLabel="artboard height"
223
+ lead="H"
224
+ steppers={false}
225
+ scrub={fixed}
226
+ onCommit={commitHeight}
227
+ />
228
+ </div>
229
+ <div style={{ padding: '0 12px 8px' }}>
230
+ {kind === 'print' ? (
231
+ // Dogfood follow-up — a PRINT artboard's "Preset size…" dropdown
232
+ // showed only the screen presets (Desktop/Laptop/Tablet/Mobile),
233
+ // which are meaningless for paper. Show the paper ladder here
234
+ // instead, writing through the SAME setPrint lane as the Print
235
+ // section below (resolved px + print prop together).
236
+ <select
237
+ className="st-cp-nsel"
238
+ aria-label="artboard paper preset"
239
+ value={print?.paper ?? ''}
240
+ onChange={(e) => setPrint({ paper: e.currentTarget.value })}
241
+ >
242
+ <option value="" disabled>
243
+ Paper size…
244
+ </option>
245
+ {PAPER_PRESETS.map((p) => (
246
+ <option key={p.id} value={p.id}>
247
+ {p.label} — {p.width}×{p.height}
248
+ {p.unit}
249
+ </option>
250
+ ))}
251
+ </select>
252
+ ) : kind === 'web' ? (
253
+ // feature-3-web-artboards T2 — a web artboard's "Preset size…"
254
+ // dropdown reads as BREAKPOINT selection, not exact-box selection:
255
+ // same SCREEN_PRESETS widths (Design Decision 2 — no separate
256
+ // preset table needed), but commits width-only (height stays
257
+ // hug-driven) and labels each option as the breakpoint it is.
258
+ <select
259
+ className="st-cp-nsel"
260
+ aria-label="artboard breakpoint preset"
261
+ value={activeWidthPreset ?? ''}
262
+ onChange={(e) => {
263
+ const p = SCREEN_PRESETS[e.currentTarget.value];
264
+ if (p) commitSize(p.width, null);
265
+ }}
266
+ >
267
+ <option value="" disabled>
268
+ {activeWidthPreset
269
+ ? `${SCREEN_PRESETS[activeWidthPreset].label} — ≤ ${SCREEN_PRESETS[activeWidthPreset].width}px`
270
+ : 'Breakpoint…'}
271
+ </option>
272
+ {Object.entries(SCREEN_PRESETS).map(([key, p]) => (
273
+ <option key={key} value={key}>
274
+ {p.label} — ≤ {p.width}px breakpoint
275
+ </option>
276
+ ))}
277
+ </select>
278
+ ) : (
279
+ <select
280
+ className="st-cp-nsel"
281
+ aria-label="artboard size preset"
282
+ value={activePreset ?? ''}
283
+ onChange={(e) => {
284
+ const p = SCREEN_PRESETS[e.currentTarget.value];
285
+ if (p) commitSize(p.width, p.height);
286
+ }}
287
+ >
288
+ <option value="" disabled>
289
+ {activePreset ? SCREEN_PRESETS[activePreset].label : 'Preset size…'}
290
+ </option>
291
+ {Object.entries(SCREEN_PRESETS).map(([key, p]) => (
292
+ <option key={key} value={key}>
293
+ {p.label} — {p.width}×{p.height}
294
+ </option>
295
+ ))}
296
+ </select>
297
+ )}
298
+ </div>
299
+ <div style={{ padding: '0 12px 8px' }}>
300
+ <Segmented
301
+ value={fixed ? 'fixed' : 'hug'}
302
+ ariaLabel="artboard height sizing mode"
303
+ options={[
304
+ { value: 'hug', label: 'Hug' },
305
+ { value: 'fixed', label: 'Fixed' },
306
+ ]}
307
+ onChange={(v) => setHug(v === 'fixed')}
308
+ />
309
+ </div>
310
+ <div className="st-cp-sechd-row">
311
+ <span className="st-cp-sechd">Kind</span>
312
+ </div>
313
+ <div style={{ padding: '0 12px 8px' }}>
314
+ <Select
315
+ value={kind}
316
+ ariaLabel="artboard kind"
317
+ options={ARTBOARD_KIND_OPTIONS.map(([value, label]) => ({ value, label }))}
318
+ onChange={setKind}
319
+ />
320
+ </div>
321
+ {kind !== 'print' && artboardId && onDuplicateArtboard ? (
322
+ // feature-3-web-artboards T3 — "Duplicate at width…". A stateless
323
+ // action trigger (not a size preset reflecting current state, unlike
324
+ // the Preset-size select above), so the control resets to its
325
+ // placeholder after firing rather than showing the last pick as
326
+ // though it were now selected. Gated off kind="print" — paper size
327
+ // is picked via the Artboard preset dropdown above, not a px width.
328
+ <div style={{ padding: '0 12px 8px' }}>
329
+ <select
330
+ className="st-cp-nsel"
331
+ aria-label="duplicate artboard at breakpoint width"
332
+ value=""
333
+ onChange={(e) => {
334
+ const p = SCREEN_PRESETS[e.currentTarget.value];
335
+ if (p) onDuplicateArtboard(artboardId, p.width);
336
+ e.currentTarget.value = '';
337
+ }}
338
+ >
339
+ <option value="" disabled>
340
+ Duplicate at width…
341
+ </option>
342
+ {Object.entries(SCREEN_PRESETS).map(([key, p]) => (
343
+ <option key={key} value={key}>
344
+ {p.label} — {p.width}px
345
+ </option>
346
+ ))}
347
+ </select>
348
+ </div>
349
+ ) : null}
350
+ {kind === 'print' ? (
351
+ <>
352
+ <div className="st-cp-sechd-row">
353
+ <span className="st-cp-sechd">Print</span>
354
+ </div>
355
+ {/* Paper picker lives in the Artboard section's own preset dropdown
356
+ above (it REPLACES the screen presets for kind="print") — this
357
+ section carries the print-specific residue: orientation + bleed. */}
358
+ <div style={{ padding: '0 12px 8px' }}>
359
+ <Segmented
360
+ value={print?.orientation ?? 'portrait'}
361
+ ariaLabel="paper orientation"
362
+ options={[
363
+ { value: 'portrait', label: 'Portrait' },
364
+ { value: 'landscape', label: 'Landscape' },
365
+ ]}
366
+ onChange={(v) => setPrint({ orientation: v })}
367
+ />
368
+ </div>
369
+ <div style={{ padding: '0 12px 8px' }}>
370
+ <NumberField
371
+ value={Number.isFinite(print?.bleedMm) ? print.bleedMm : 3}
372
+ min={0}
373
+ step={0.5}
374
+ ariaLabel="bleed, millimeters"
375
+ // Single-glyph lead — the drag-handle slot is sized for 1–2
376
+ // chars ("W"/"Pad"); a full word clips. mm suffix + aria carry
377
+ // the meaning.
378
+ lead="B"
379
+ steppers={false}
380
+ unitSlot={
381
+ <span className="st-cp-numsuffix" aria-hidden="true">
382
+ mm
383
+ </span>
384
+ }
385
+ onCommit={(n) => setPrint({ bleedMm: n })}
386
+ />
387
+ </div>
388
+ </>
389
+ ) : null}
390
+ <div className="st-cp-sechd-row">
391
+ <span className="st-cp-sechd">Style</span>
392
+ </div>
393
+ <div style={{ padding: '4px 12px 8px', display: 'flex', flexDirection: 'column', gap: 8 }}>
394
+ {(() => {
395
+ // Bg — the CssKnobs `color()` recipe: TokenPopover swatch as the
396
+ // flush prefix inside ColorField (HSV picker + per-DS variables).
397
+ const bgResolved = resolveTokenValue(bg);
398
+ const bgBound = /var\(\s*--/.test(bg);
399
+ const bgDisplay = bgBound
400
+ ? bg.replace(/^var\(\s*|\s*\)$/g, '').replace(/^--/, '').replace(/-/g, ' ')
401
+ : bg;
402
+ return (
403
+ <ColorField
404
+ swatch={
405
+ <TokenPopover
406
+ kind="color"
407
+ swatchClassName="st-cp-cf-sw"
408
+ groups={tokenGroups('color')}
409
+ current={bg}
410
+ activeDs={_activeDs}
411
+ swatchBg={bgResolved}
412
+ seedHex={cssColorToHex(bgResolved) || '#000000'}
413
+ onPick={(v) => commitStyle({ background: v || null })}
414
+ label="artboard background colour"
415
+ />
416
+ }
417
+ displayValue={bgDisplay}
418
+ bound={bgBound}
419
+ ariaLabel="artboard background"
420
+ onValue={(v) => commitStyle({ background: (v || '').trim() || null })}
421
+ />
422
+ );
423
+ })()}
424
+ <Select
425
+ value={layoutMode}
426
+ ariaLabel="artboard body layout"
427
+ options={ARTBOARD_LAYOUT_OPTIONS.map(([value, label]) => ({
428
+ value,
429
+ label,
430
+ }))}
431
+ onChange={(v) => commitStyle({ layout: v || null })}
432
+ />
433
+ <div style={{ display: 'flex', gap: 8 }}>
434
+ <ValueTokenField
435
+ value={/^var\(/.test(padding) ? padding : Number.parseFloat(padding) || 0}
436
+ tokens={flatTokens('space')}
437
+ ariaLabel="artboard padding"
438
+ lead="Pad"
439
+ min={0}
440
+ onChange={(v) =>
441
+ commitStyle({ padding: typeof v === 'string' ? v : v > 0 ? v : null })
442
+ }
443
+ />
444
+ <ValueTokenField
445
+ value={/^var\(/.test(gap) ? gap : Number.parseFloat(gap) || 0}
446
+ tokens={flatTokens('space')}
447
+ ariaLabel="artboard gap"
448
+ lead="Gap"
449
+ min={0}
450
+ onChange={(v) => commitStyle({ gap: typeof v === 'string' ? v : v > 0 ? v : null })}
451
+ />
452
+ </div>
453
+ </div>
454
+ </section>
455
+ );
456
+ }
@@ -0,0 +1,196 @@
1
+ // inspector/color-picker.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
2
+
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { clamp01, hexToRgb, hsvToRgb, rgbToHex, rgbToHsv } from './color.js';
5
+ import { StIcon } from '../shell/icons.jsx';
6
+
7
+ // Phase 12.3 (#4) — the "Custom" tab of the colour popover: a normal colour
8
+ // input (native OS picker via a large swatch) + a hex/value text field. Applies
9
+ // LIVE as you adjust (onApply), so the canvas previews while the picker is open.
10
+ // #6 — the unified colour picker (Custom tab). A real HSV control: a
11
+ // saturation/value square + a hue slider + a hex field + an eyedropper — the
12
+ // Figma model. Replaces BOTH the old native <input type="color"> on the swatch
13
+ // AND the simple hex field, so colours have ONE popover (Custom · Variables).
14
+ // `seed` is the resolved current colour (hex). Drag updates the picker UI live;
15
+ // commits on pointer-up (one source write per drag); the hex field commits on
16
+ // blur/Enter.
17
+ export function ColorPicker({ seed, label, onApply }) {
18
+ const [hsv, setHsv] = useState(() => rgbToHsv(hexToRgb(seed || '#000000')));
19
+ const hsvRef = useRef(hsv);
20
+ hsvRef.current = hsv;
21
+ const svRef = useRef(null);
22
+ const hueRef = useRef(null);
23
+ // Reseed when the selection's colour changes (but not while the user drags).
24
+ const seedRef = useRef(seed);
25
+ // biome-ignore lint/correctness/useExhaustiveDependencies: reseed on seed change only.
26
+ useEffect(() => {
27
+ if (seed && seed !== seedRef.current) {
28
+ seedRef.current = seed;
29
+ setHsv(rgbToHsv(hexToRgb(seed)));
30
+ }
31
+ }, [seed]);
32
+ const hex = rgbToHex(hsvToRgb(hsv));
33
+
34
+ const dragSV = (e) => {
35
+ e.preventDefault();
36
+ const r = svRef.current?.getBoundingClientRect();
37
+ if (!r) return;
38
+ const h = hsvRef.current.h;
39
+ const move = (ev) => {
40
+ setHsv({
41
+ h,
42
+ s: clamp01((ev.clientX - r.left) / r.width),
43
+ v: clamp01(1 - (ev.clientY - r.top) / r.height),
44
+ });
45
+ };
46
+ move(e);
47
+ const up = () => {
48
+ document.removeEventListener('pointermove', move);
49
+ document.removeEventListener('pointerup', up);
50
+ onApply(rgbToHex(hsvToRgb(hsvRef.current)));
51
+ };
52
+ document.addEventListener('pointermove', move);
53
+ document.addEventListener('pointerup', up);
54
+ };
55
+ const dragHue = (e) => {
56
+ e.preventDefault();
57
+ const r = hueRef.current?.getBoundingClientRect();
58
+ if (!r) return;
59
+ const { s, v } = hsvRef.current;
60
+ const move = (ev) => {
61
+ setHsv({ h: clamp01((ev.clientX - r.left) / r.width) * 360, s, v });
62
+ };
63
+ move(e);
64
+ const up = () => {
65
+ document.removeEventListener('pointermove', move);
66
+ document.removeEventListener('pointerup', up);
67
+ onApply(rgbToHex(hsvToRgb(hsvRef.current)));
68
+ };
69
+ document.addEventListener('pointermove', move);
70
+ document.addEventListener('pointerup', up);
71
+ };
72
+ // Keyboard equivalents for dragSV/dragHue (feature-photo-editor follow-up
73
+ // debt, Task 18) — the pad + hue bar were pointer-only. Arrow keys nudge
74
+ // the same `setHsv`/`onApply` path the drag handlers use; shift = a bigger
75
+ // step (mirrors makeScrub's shift=×10 modifier convention elsewhere).
76
+ const nudgeHsv = (patch) => {
77
+ const next = { ...hsvRef.current, ...patch };
78
+ setHsv(next);
79
+ onApply(rgbToHex(hsvToRgb(next)));
80
+ };
81
+ const onSvKeyDown = (e) => {
82
+ const step = e.shiftKey ? 0.1 : 0.02;
83
+ const deltas = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, step], ArrowDown: [0, -step] };
84
+ const d = deltas[e.key];
85
+ if (!d) return;
86
+ e.preventDefault();
87
+ nudgeHsv({ s: clamp01(hsvRef.current.s + d[0]), v: clamp01(hsvRef.current.v + d[1]) });
88
+ };
89
+ const onHueKeyDown = (e) => {
90
+ const step = e.shiftKey ? 20 : 2;
91
+ const deltas = { ArrowLeft: -step, ArrowRight: step };
92
+ const d = deltas[e.key];
93
+ if (d == null) return;
94
+ e.preventDefault();
95
+ nudgeHsv({ h: Math.min(360, Math.max(0, hsvRef.current.h + d)) });
96
+ };
97
+ const eyedrop = async () => {
98
+ try {
99
+ // EyeDropper is Chromium-only; guarded.
100
+ const ED = window.EyeDropper;
101
+ if (!ED) return;
102
+ const res = await new ED().open();
103
+ if (res?.sRGBHex) {
104
+ setHsv(rgbToHsv(hexToRgb(res.sRGBHex)));
105
+ onApply(res.sRGBHex);
106
+ }
107
+ } catch {
108
+ /* user cancelled */
109
+ }
110
+ };
111
+
112
+ // handoff — RGB numeric fields (design parity). Editing one re-derives hsv.
113
+ const rgb = hsvToRgb(hsv);
114
+ const setRgb = (patch) => {
115
+ const next = { ...rgb, ...patch };
116
+ const h = rgbToHsv({ r: clamp01(next.r / 255) * 255, g: clamp01(next.g / 255) * 255, b: clamp01(next.b / 255) * 255 });
117
+ setHsv(h);
118
+ onApply(rgbToHex(hsvToRgb(h)));
119
+ };
120
+ return (
121
+ <div className="st-cp-cpick">
122
+ {/* hex + swatch on top (design), then the SV pad, controls, RGB */}
123
+ <div className="st-cp-cpick-hexrow">
124
+ <span className="st-cp-cpick-hexsw" style={{ background: hex }} />
125
+ <input
126
+ className="st-cp-cpick-hex"
127
+ type="text"
128
+ value={hex}
129
+ aria-label={label ? `${label} hex value` : 'hex value'}
130
+ onChange={(e) => {
131
+ const v = e.target.value;
132
+ if (/^#?[0-9a-f]{6}$/i.test(v)) setHsv(rgbToHsv(hexToRgb(v)));
133
+ }}
134
+ onKeyDown={(e) => {
135
+ if (e.key === 'Enter') onApply(e.currentTarget.value);
136
+ }}
137
+ onBlur={(e) => onApply(e.currentTarget.value)}
138
+ onFocus={(e) => e.currentTarget.select()}
139
+ />
140
+ </div>
141
+ <button
142
+ type="button"
143
+ ref={svRef}
144
+ className="st-cp-cpick-sv"
145
+ aria-label={label ? `${label} saturation and value` : 'saturation and value'}
146
+ style={{ background: `hsl(${hsv.h} 100% 50%)` }}
147
+ onPointerDown={dragSV}
148
+ onKeyDown={onSvKeyDown}
149
+ >
150
+ <span className="st-cp-cpick-svwhite" />
151
+ <span className="st-cp-cpick-svblack" />
152
+ <span
153
+ className="st-cp-cpick-knob"
154
+ style={{ left: `${hsv.s * 100}%`, top: `${(1 - hsv.v) * 100}%`, background: hex }}
155
+ />
156
+ </button>
157
+ <div className="st-cp-cpick-controls">
158
+ {window.EyeDropper ? (
159
+ <button
160
+ type="button"
161
+ className="st-cp-cpick-eye"
162
+ aria-label="pick from screen"
163
+ title="eyedropper"
164
+ onClick={eyedrop}
165
+ >
166
+ <StIcon name="eyedropper" size={14} />
167
+ </button>
168
+ ) : null}
169
+ <span className="st-cp-cpick-preview" style={{ background: hex }} aria-hidden="true" />
170
+ <button
171
+ type="button"
172
+ ref={hueRef}
173
+ className="st-cp-cpick-hue"
174
+ aria-label={label ? `${label} hue` : 'hue'}
175
+ onPointerDown={dragHue}
176
+ onKeyDown={onHueKeyDown}
177
+ >
178
+ <span className="st-cp-cpick-huethumb" style={{ left: `${(hsv.h / 360) * 100}%` }} />
179
+ </button>
180
+ </div>
181
+ <div className="st-cp-cpick-rgb">
182
+ {['r', 'g', 'b'].map((k) => (
183
+ <label key={k} className="st-cp-cpick-rgbf">
184
+ <input
185
+ aria-label={k.toUpperCase()}
186
+ value={Math.round(rgb[k])}
187
+ onChange={(e) => setRgb({ [k]: clamp01((Number.parseFloat(e.target.value) || 0) / 255) * 255 })}
188
+ onFocus={(e) => e.currentTarget.select()}
189
+ />
190
+ <span>{k.toUpperCase()}</span>
191
+ </label>
192
+ ))}
193
+ </div>
194
+ </div>
195
+ );
196
+ }