@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,1720 @@
1
+ // inspector/css-knobs.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 { activeDsNameFor, useAllDsTokens } from './ds-tokens.js';
5
+ import { cssColorToHex, cssHint, cssSplitUnit } from './color.js';
6
+ import { sizingModeOf, sizingModePatch } from '../../sizing-mode.ts';
7
+ import { AlignPad, AngleDial, ColorField, IconButtonGroup, IconToggleGroup, NumberField, RadiusControl, Segmented, SliderField, Toggle, UnitSelect, ValueTokenField, makeScrubHandler } from '../inspector-controls.jsx';
8
+ import { Lu, StIcon } from '../shell/icons.jsx';
9
+ import { AlignCenter as LuAlignCenter, AlignHorizontalJustifyCenter as LuJustifyCenter, AlignHorizontalJustifyEnd as LuJustifyEnd, AlignHorizontalJustifyStart as LuJustifyStart, AlignHorizontalSpaceBetween as LuSpaceBetween, AlignJustify as LuAlignJustify, AlignLeft as LuAlignLeft, AlignRight as LuAlignRight, AlignVerticalJustifyCenter as LuVJustifyCenter, AlignVerticalJustifyEnd as LuVJustifyEnd, AlignVerticalJustifyStart as LuVJustifyStart, Bold as LuBold, Braces as LuBraces, Columns3 as LuColumns3, Eye as LuEye, Italic as LuItalic, RotateCw as LuRotateCw, Rows3 as LuRows3, Scissors as LuScissors, ScrollText as LuScrollText, StretchHorizontal as LuStretch, Underline as LuUnderline, Wand2 as LuWand2 } from 'lucide-react';
10
+ import { CSS_ALIGN_SELF, CSS_ASPECT_RATIO, CSS_BLEND_MODES, CSS_BORDER_STYLES, CSS_DISPLAYS, CSS_FONTS, CSS_FONT_STYLE, CSS_OBJECT_FIT, CSS_POSITION, CSS_TEXT_TRANSFORM, CSS_UNITLESS, CSS_UNITS, CSS_WEIGHTS, CSS_WHITE_SPACE, PROP_LEAD } from './css-vocab.jsx';
11
+ import { TokenPopover } from './token-popover.jsx';
12
+ import { parseTrackList, serializeTrackList } from '../../grid-track-handles.ts';
13
+ import { GridTracksEditor } from './grid-tracks-editor.jsx';
14
+
15
+ // Writes whose success ends in a `record-edit` post to the canvas. The canvas
16
+ // asks (`undo-barrier`) before Cmd+Z so it never undoes past an edit whose
17
+ // record is still on its way (see afterShellRecords in canvas-shell.tsx).
18
+ export const recordableWrites = { pending: 0, waiters: [] };
19
+
20
+ export function trackRecordableWrite(promise) {
21
+ recordableWrites.pending += 1;
22
+ const settle = () => {
23
+ recordableWrites.pending -= 1;
24
+ if (recordableWrites.pending === 0) for (const w of recordableWrites.waiters.splice(0)) w();
25
+ };
26
+ promise.then(settle, settle);
27
+ return promise;
28
+ }
29
+
30
+ export function afterRecordableWrites() {
31
+ return recordableWrites.pending === 0
32
+ ? Promise.resolve()
33
+ : new Promise((resolve) => recordableWrites.waiters.push(resolve));
34
+ }
35
+
36
+ export function CssKnobs({ el, cfg, onOptimistic, onRecordEdit, onReplaceMedia, onUndoRedo, mode, onSetMode }) {
37
+ const editable = !!el.id;
38
+ const computed = el.computed || {};
39
+ // Phase 12.3 — optimistic local overlay over the selection's authored / custom
40
+ // / attr maps. With the redundant-reload suppression (the flicker fix), an edit
41
+ // no longer triggers a reselect that would re-post fresh `authored` values — so
42
+ // the panel must reflect its own commits immediately or it shows the stale
43
+ // pre-edit value until the user re-selects. Each commit/reset writes here;
44
+ // `null` marks a removed key. Cleared when a different element is selected —
45
+ // and whenever the canvas re-posts this selection's maps. A re-post carries
46
+ // the source as it is NOW (a teammate's change reloads the canvas); keeping
47
+ // our older commit over it showed a stale value and recorded it as the next
48
+ // undo's `before`, so Cmd+Z restored a value nobody had on screen.
49
+ const [overlay, setOverlay] = useState({ a: {}, c: {}, t: {} });
50
+ // biome-ignore lint/correctness/useExhaustiveDependencies: clear on a fresh selection payload only.
51
+ useEffect(() => {
52
+ setOverlay({ a: {}, c: {}, t: {} });
53
+ }, [el.id, el.authored, el.customStyles, el.attrs]);
54
+ const mergeOverlay = (base, ov) => {
55
+ const out = { ...(base || {}) };
56
+ for (const [k, v] of Object.entries(ov)) {
57
+ if (v === null) delete out[k];
58
+ else out[k] = v;
59
+ }
60
+ return out;
61
+ };
62
+ const authored = mergeOverlay(el.authored, overlay.a);
63
+ const customStyles = mergeOverlay(el.customStyles, overlay.c);
64
+ const attrs = mergeOverlay(el.attrs, overlay.t);
65
+ const setA = (prop, v) => setOverlay((o) => ({ ...o, a: { ...o.a, [prop]: v } }));
66
+ const setC = (prop, v) => setOverlay((o) => ({ ...o, c: { ...o.c, [prop]: v } }));
67
+ const setT = (attr, v) => setOverlay((o) => ({ ...o, t: { ...o.t, [attr]: v } }));
68
+ // Token CSS is served from the MAIN origin at the repo-relative path, i.e.
69
+ // WITH the designRoot prefix (`/.design/system/<ds>/colors_and_type.css`) —
70
+ // `tokensCssRel` from config is DS-root-relative (no `.design/`), so prepend it.
71
+ const _designRel = (cfg?.designRel || cfg?.designRoot || '.design').replace(/^\/+|\/+$/g, '');
72
+ const _activeDs = activeDsNameFor(el.file, cfg);
73
+ // W3 — tokens from EVERY configured DS, active one first, so the popover can
74
+ // offer them grouped per design system.
75
+ const allDs = useAllDsTokens(cfg, _designRel, _activeDs);
76
+ // Build per-DS popover groups for one token family (color/space/radius/…).
77
+ const tokenGroups = (familyKey) =>
78
+ allDs
79
+ .map((d) => ({ ds: d.name, names: d[familyKey] || [], vals: d.vals }))
80
+ .filter((g) => g.names.length);
81
+ const [status, setStatus] = useState({});
82
+ const [open, setOpen] = useState({
83
+ Layout: true,
84
+ Position: true,
85
+ Typography: true,
86
+ Spacing: true,
87
+ Size: true,
88
+ Media: true,
89
+ Appearance: true,
90
+ Advanced: false,
91
+ });
92
+
93
+ // Phase 12.3 — auto-expand Advanced when the selected element carries custom
94
+ // CSS props / HTML attrs, so a just-added (or pre-existing) custom value is
95
+ // visible without hunting for the disclosure. Keyed on el.id so it re-runs per
96
+ // selection (CssKnobs persists across selections — the el prop changes).
97
+ const hasCustom =
98
+ Object.keys(customStyles).length > 0 || Object.keys(attrs).length > 0;
99
+ useEffect(() => {
100
+ if (hasCustom) setOpen((o) => (o.Advanced ? o : { ...o, Advanced: true }));
101
+ }, [el.id, hasCustom]);
102
+ // DDR-171 — Designer mode's Position cluster mirrors the same auto-expand
103
+ // precedent: collapsed by default (position is the rare case), auto-opens
104
+ // the moment the element actually has a non-static position so the inset
105
+ // fields the user just set (or that came from the source) aren't hidden.
106
+ const hasCustomPosition = (authored.position || cssHint(computed.position) || 'static') !== 'static';
107
+ useEffect(() => {
108
+ if (hasCustomPosition) setOpen((o) => (o['d:Position'] ? o : { ...o, 'd:Position': true }));
109
+ }, [el.id, hasCustomPosition]);
110
+
111
+ // DDR-171 — the panel's vocabulary mode: 'advanced' (today's raw-CSS panel,
112
+ // unchanged, still the default — zero behavior change for existing users) or
113
+ // 'designer' (the Figma-vocabulary regroup). Lifted to App state (DDR-171
114
+ // follow-up) so the same preference is controllable from BOTH the in-panel
115
+ // corner toggle AND Settings → Appearance, and the two never diverge — the
116
+ // exact single-source-of-truth pattern `theme` uses. App owns the
117
+ // `maude-cp-mode` localStorage persistence; here it's a controlled prop.
118
+ const setMode = onSetMode;
119
+ // Designer-mode per-cluster "···" disclosure state (Auto layout/Wrap,
120
+ // Size/Min-Max, Position/z-index, Text/extras) — keyed by cluster name, kept
121
+ // in-memory only (unlike `open`, not persisted; matches the disclosure being
122
+ // a "peek", not a durable preference).
123
+ const [designerMore, setDesignerMore] = useState({});
124
+
125
+ async function post(url, payload, key) {
126
+ setStatus((s) => ({ ...s, [key]: 'saving' }));
127
+ try {
128
+ const res = await fetch(url, {
129
+ method: 'POST',
130
+ headers: { 'content-type': 'application/json' },
131
+ body: JSON.stringify(payload),
132
+ });
133
+ const j = await res.json().catch(() => ({}));
134
+ setStatus((s) => ({
135
+ ...s,
136
+ [key]: !res.ok || !j.ok ? `err:${(j && j.error) || `HTTP ${res.status}`}` : 'saved',
137
+ }));
138
+ return res.ok ? j : null;
139
+ } catch (err) {
140
+ setStatus((s) => ({ ...s, [key]: `err:${err && err.message ? err.message : String(err)}` }));
141
+ return null;
142
+ }
143
+ }
144
+ // Write, THEN record the undo entry from what the write actually replaced
145
+ // (`previous`, read server-side under the file lock). The panel's own value
146
+ // can be a teammate's edit old — it is not re-posted when a peer changes the
147
+ // source — and recording it made Cmd+Z restore a value nobody had on screen.
148
+ // Serialized so the stack keeps edit order; a failed write records nothing.
149
+ const writeChainRef = useRef(Promise.resolve());
150
+ const writeAndRecord = (url, payload, key, op, prop, fallbackBefore, after) => {
151
+ writeChainRef.current = trackRecordableWrite(
152
+ writeChainRef.current.then(async () => {
153
+ const j = await post(url, payload, key);
154
+ if (!j?.ok) return;
155
+ const before = Object.hasOwn(j, 'previous') ? j.previous : fallbackBefore;
156
+ if ((before ?? null) === (after ?? null)) return; // nothing changed to undo
157
+ record(op, prop, before, after);
158
+ })
159
+ );
160
+ };
161
+ // Optimistic preview: nudge the live element so the change shows before the
162
+ // edit → HMR reload lands. `value` null = remove (reset path). No-op when the
163
+ // selection has no stable id (can't be resolved in the canvas).
164
+ const optimistic = (prop, value) => {
165
+ if (!onOptimistic || !el.id) return;
166
+ onOptimistic({
167
+ id: el.id,
168
+ artboardId: el.artboardId ?? null,
169
+ index: el.index ?? 0,
170
+ prop,
171
+ value,
172
+ });
173
+ };
174
+ // Record an inline edit onto the canvas undo stack (Cmd+Z). The edit has
175
+ // already POSTed `/_api/edit-*`; the canvas iframe APPENDS the record (no
176
+ // re-run). `before`/`after` null = the prop/attr was/becomes unset.
177
+ const record = (op, key, before, after) => {
178
+ onRecordEdit?.({
179
+ op,
180
+ canvas: el.file,
181
+ id: el.id,
182
+ key,
183
+ before: before == null || before === '' ? null : before,
184
+ after: after == null || after === '' ? null : after,
185
+ });
186
+ };
187
+ const commit = (property, raw) => {
188
+ const value = (raw || '').trim();
189
+ if (!editable || !value) return;
190
+ const before = authored[property] ?? null;
191
+ if (value === (before ?? '').trim()) return; // no-op
192
+ optimistic(property, value);
193
+ setA(property, value); // reflect in the panel immediately (no reload → no reselect)
194
+ writeAndRecord(
195
+ '/_api/edit-css',
196
+ { canvas: el.file, id: el.id, property, value },
197
+ property,
198
+ 'css',
199
+ property,
200
+ before,
201
+ value
202
+ );
203
+ };
204
+ // A custom CSS property (Advanced) — same write, but the panel surfaces it from
205
+ // the customStyles map, so overlay THERE.
206
+ const commitCustom = (property, raw) => {
207
+ const value = (raw || '').trim();
208
+ const prop = property.trim();
209
+ if (!editable || !prop || !value) return;
210
+ const before = customStyles[prop] ?? null;
211
+ optimistic(prop, value);
212
+ setC(prop, value);
213
+ writeAndRecord(
214
+ '/_api/edit-css',
215
+ { canvas: el.file, id: el.id, property: prop, value },
216
+ prop,
217
+ 'css',
218
+ prop,
219
+ before,
220
+ value
221
+ );
222
+ };
223
+ const commitAttr = (attr, raw) => {
224
+ const a = (attr || '').trim();
225
+ const value = (raw || '').trim();
226
+ if (!editable || !a || !value) return;
227
+ const before = attrs[a] ?? null;
228
+ setT(a, value);
229
+ writeAndRecord(
230
+ '/_api/edit-attr',
231
+ { canvas: el.file, id: el.id, attr: a, value },
232
+ `@${a}`,
233
+ 'attr',
234
+ a,
235
+ before,
236
+ value
237
+ );
238
+ };
239
+ // Phase 12.3 — reset (remove the inline prop / attr → back to class/inherited).
240
+ const reset = (property) => {
241
+ if (!editable) return;
242
+ const before = authored[property] ?? null;
243
+ optimistic(property, null);
244
+ setA(property, null);
245
+ writeAndRecord(
246
+ '/_api/edit-css',
247
+ { canvas: el.file, id: el.id, property, reset: true },
248
+ property,
249
+ 'css',
250
+ property,
251
+ before,
252
+ null
253
+ );
254
+ };
255
+ const resetCustom = (property) => {
256
+ if (!editable) return;
257
+ const before = customStyles[property] ?? null;
258
+ optimistic(property, null);
259
+ setC(property, null);
260
+ writeAndRecord(
261
+ '/_api/edit-css',
262
+ { canvas: el.file, id: el.id, property, reset: true },
263
+ property,
264
+ 'css',
265
+ property,
266
+ before,
267
+ null
268
+ );
269
+ };
270
+ const resetAttr = (attr) => {
271
+ if (!editable) return;
272
+ const before = attrs[attr] ?? null;
273
+ setT(attr, null);
274
+ writeAndRecord(
275
+ '/_api/edit-attr',
276
+ { canvas: el.file, id: el.id, attr, reset: true },
277
+ `@${attr}`,
278
+ 'attr',
279
+ attr,
280
+ before,
281
+ null
282
+ );
283
+ };
284
+ // Stage M1 — apply a Fixed / Hug / Fill sizing mode to one axis. The pure
285
+ // `sizingModePatch` returns the exact writes (context-aware Fill: flex main axis
286
+ // → flex-grow, cross axis → align-self, block/grid → 100%) + the fill-props to
287
+ // clear. Each ride the same commit/reset lanes (per-prop edit-css + undo record);
288
+ // the server's per-file lock serializes them, so the resulting box is coherent.
289
+ const parentLayout = { display: el.parentDisplay, flexDirection: el.parentFlexDirection };
290
+ const applySizing = (axis, mode) => {
291
+ if (!editable) return;
292
+ const px = Math.round((axis === 'width' ? el.bounds?.w : el.bounds?.h) || 0);
293
+ const patch = sizingModePatch(axis, mode, parentLayout, px);
294
+ for (const p of patch.reset) if (authored[p]) reset(p);
295
+ for (const [prop, value] of patch.set) commit(prop, value);
296
+ };
297
+ const parentIsFlexChild =
298
+ el.parentDisplay === 'flex' || el.parentDisplay === 'inline-flex';
299
+ const sizeModeSeg = (axis) => {
300
+ const cur = sizingModeOf(axis, authored, computed, parentLayout);
301
+ return (
302
+ // handoff — a proper inspector row: "Width sizing" / "Height sizing" label
303
+ // in the label column, the shared Segmented right-aligned in the control
304
+ // column (aligned with the number inputs below), input-matching height.
305
+ <div className="st-cp-moderow" key={`mode-${axis}`}>
306
+ <span className="st-cp-modelabel">{axis === 'width' ? 'Width sizing' : 'Height sizing'}</span>
307
+ <div className="st-cp-modeseg" role="group" aria-label={`${axis} sizing mode`}>
308
+ <Segmented
309
+ value={cur}
310
+ ariaLabel={`${axis} sizing`}
311
+ options={[{ value: 'fixed', label: 'fixed' }, { value: 'hug', label: 'hug' }, { value: 'fill', label: 'fill' }]}
312
+ onChange={(m) => applySizing(axis, m)}
313
+ />
314
+ </div>
315
+ </div>
316
+ );
317
+ };
318
+ // DDR-171 — Designer mode's Auto-layout alignment: `AlignPad`'s 9-cell grid
319
+ // maps to the TWO real CSS axes (`justify-content` = main axis,
320
+ // `align-items` = cross axis), which axis is "horizontal" vs "vertical"
321
+ // depending on `flex-direction`. Only the 3 positional align-items values
322
+ // (start/center/end) round-trip through the pad — `stretch` reads as the
323
+ // pad's center cell (closest visual analog) but the pad never WRITES
324
+ // `stretch`; that stays an Advanced-mode-only value, same as Figma's own
325
+ // alignment pad (no "stretch" cell — it's a separate control there too).
326
+ const AP_JC = ['flex-start', 'center', 'flex-end'];
327
+ const AP_AI = ['flex-start', 'center', 'flex-end'];
328
+ const AP_ROWS = ['t', 'c', 'b'];
329
+ const AP_COLS = ['l', 'c', 'r'];
330
+ const alignPadCell = () => {
331
+ const isRow = !(authored['flex-direction'] || cssHint(computed['flex-direction']) || 'row').startsWith('column');
332
+ const jcPos = Math.max(0, AP_JC.indexOf(authored['justify-content'] || cssHint(computed['justify-content']) || 'flex-start'));
333
+ const aiRaw = authored['align-items'] || cssHint(computed['align-items']) || 'stretch';
334
+ const aiPos = aiRaw === 'stretch' ? 1 : Math.max(0, AP_AI.indexOf(aiRaw));
335
+ const [h, v] = isRow ? [jcPos, aiPos] : [aiPos, jcPos];
336
+ return AP_ROWS[v] + AP_COLS[h];
337
+ };
338
+ const setAlignPadCell = (cell) => {
339
+ const v = AP_ROWS.indexOf(cell[0]);
340
+ const h = AP_COLS.indexOf(cell[1]);
341
+ const isRow = !(authored['flex-direction'] || cssHint(computed['flex-direction']) || 'row').startsWith('column');
342
+ const [jcPos, aiPos] = isRow ? [h, v] : [v, h];
343
+ commit('justify-content', AP_JC[jcPos]);
344
+ commit('align-items', AP_AI[aiPos]);
345
+ };
346
+ // Cmd+Z / Cmd+Shift+Z (or Cmd+Y) inside the inspector forwards to the canvas
347
+ // undo stack — Figma-parity: a property field reverts the last DOCUMENT edit,
348
+ // not field text. Without this, an edit committed with focus still in the
349
+ // inspector couldn't be undone (the iframe's own keydown never sees the key).
350
+ const onKnobKeyDown = (e) => {
351
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return;
352
+ const k = e.key.toLowerCase();
353
+ if (k === 'z') {
354
+ e.preventDefault();
355
+ onUndoRedo?.(e.shiftKey ? 'redo' : 'undo');
356
+ } else if (k === 'y') {
357
+ e.preventDefault();
358
+ onUndoRedo?.('redo');
359
+ }
360
+ };
361
+ const provOf = (prop) => {
362
+ const v = authored[prop];
363
+ if (!v) return 'inherit';
364
+ return /var\(\s*--/.test(v) ? 'bound' : 'raw';
365
+ };
366
+
367
+ if (!editable) {
368
+ return (
369
+ <div className="st-cp">
370
+ <div className="st-cp-id">
371
+ <span className="st-cp-idtag">{el.tag || 'element'}</span>
372
+ </div>
373
+ <div className="st-css-disabled">
374
+ This selection has no stable element id (a legacy canvas, or a non-element target). Edit
375
+ it with <code>/design:edit</code>.
376
+ </div>
377
+ </div>
378
+ );
379
+ }
380
+
381
+ const PROVLABEL = { bound: 'token-bound', raw: 'raw override', inherit: 'inherited' };
382
+ const prov = (p) => (
383
+ <span className={`st-cp-prov st-cp-prov--${p}`} role="img" aria-label={PROVLABEL[p]} />
384
+ );
385
+
386
+ // Phase 12.3 (#4) — the LEADING dot carries it all: provenance (shape) + save
387
+ // status (a success/error/saving glow) + reset (double-click an authored row).
388
+ // No trailing ✓/⟲ that shift the input rightward (the user's gripe). A tooltip
389
+ // hints the double-click-to-reset.
390
+ const provDot = (prop, provKind) => {
391
+ const k = provKind ?? provOf(prop);
392
+ const s = status[prop];
393
+ const errMsg = typeof s === 'string' && s.startsWith('err:') ? s.slice(4) : '';
394
+ const stCls = errMsg ? ' is-err' : s === 'saved' ? ' is-saved' : s === 'saving' ? ' is-saving' : '';
395
+ const canReset = !!authored[prop];
396
+ const tip = errMsg
397
+ ? `error: ${errMsg}`
398
+ : canReset
399
+ ? `${PROVLABEL[k]} · double-click to reset`
400
+ : PROVLABEL[k];
401
+ return (
402
+ <button
403
+ type="button"
404
+ className={`st-cp-prov st-cp-prov--${k}${stCls}${canReset ? ' is-resettable' : ''}`}
405
+ aria-label={tip}
406
+ title={tip}
407
+ tabIndex={canReset ? 0 : -1}
408
+ onDoubleClick={canReset ? () => reset(prop) : undefined}
409
+ onKeyDown={
410
+ canReset
411
+ ? (e) => {
412
+ if (e.key === 'Backspace' || e.key === 'Delete') {
413
+ e.preventDefault();
414
+ reset(prop);
415
+ }
416
+ }
417
+ : undefined
418
+ }
419
+ />
420
+ );
421
+ };
422
+
423
+ // `labelOverride` (DDR-171 — Designer mode) swaps BOTH the visible label text
424
+ // AND the title tooltip together, so they never drift out of sync. Optional
425
+ // and additive — every Advanced-mode call site omits it and renders exactly
426
+ // as before (label = title = the raw CSS property name).
427
+ const row = (prop, control, provKind, labelOverride) => {
428
+ // #1 bigger-bet — scannable diff: a fully-unset single-prop row is dimmed so
429
+ // the handful of overridden rows pop (Webflow/Framer model). Composite rows
430
+ // (border — they pass an explicit provKind) are never dimmed.
431
+ const unset = provKind === undefined && !authored[prop];
432
+ const label = labelOverride ?? prop;
433
+ return (
434
+ <div className={`st-cp-row${unset ? ' is-unset' : ''}`} key={prop}>
435
+ {provDot(prop, provKind)}
436
+ <label className="st-cp-label" title={label}>
437
+ {label}
438
+ </label>
439
+ <div className="st-cp-ctl">{control}</div>
440
+ </div>
441
+ );
442
+ };
443
+
444
+ // Props each section owns — drives the per-section "reset section" affordance.
445
+ const SECTION_PROPS = {
446
+ Layout: ['display', 'flex-direction', 'flex-wrap', 'align-items', 'justify-content', 'gap'],
447
+ // feature-3-web-artboards T5 — Grid track editor + cell placement, so the
448
+ // section-reset affordance clears them like every other section.
449
+ Grid: ['grid-template-columns', 'grid-template-rows'],
450
+ 'Grid item': ['grid-column', 'grid-row'],
451
+ // feature-element-editing-robustness Stage B — promoted DDR-104 OUT-list.
452
+ Position: ['position', 'top', 'right', 'bottom', 'left', 'z-index'],
453
+ Typography: [
454
+ 'font-family',
455
+ 'color',
456
+ 'font-size',
457
+ 'font-weight',
458
+ 'line-height',
459
+ 'letter-spacing',
460
+ 'text-align',
461
+ 'font-style',
462
+ 'text-transform',
463
+ 'text-decoration',
464
+ 'white-space',
465
+ ],
466
+ Spacing: [
467
+ 'margin-top',
468
+ 'margin-right',
469
+ 'margin-bottom',
470
+ 'margin-left',
471
+ 'padding-top',
472
+ 'padding-right',
473
+ 'padding-bottom',
474
+ 'padding-left',
475
+ ],
476
+ Size: [
477
+ 'width',
478
+ 'height',
479
+ 'min-width',
480
+ 'min-height',
481
+ 'max-width',
482
+ 'max-height',
483
+ 'overflow',
484
+ // Stage M — flex-child sizing props (written by the Fill mode + shown as rows
485
+ // when the parent is flex). Included so a section-reset clears them too.
486
+ 'flex-grow',
487
+ 'flex-shrink',
488
+ 'flex-basis',
489
+ 'align-self',
490
+ ],
491
+ Media: ['object-fit', 'aspect-ratio', 'object-position'],
492
+ Appearance: [
493
+ 'background-color',
494
+ 'border-radius',
495
+ 'border-top-left-radius',
496
+ 'border-top-right-radius',
497
+ 'border-bottom-left-radius',
498
+ 'border-bottom-right-radius',
499
+ 'border-width',
500
+ 'border-style',
501
+ 'border-color',
502
+ 'box-shadow',
503
+ 'filter',
504
+ 'mix-blend-mode',
505
+ 'opacity',
506
+ 'transform',
507
+ 'transform-origin',
508
+ ],
509
+ };
510
+ const resetSection = (name) => {
511
+ (SECTION_PROPS[name] || []).forEach((p) => {
512
+ if (authored[p]) reset(p);
513
+ });
514
+ };
515
+
516
+ const sec = (name, body) => {
517
+ const dirty = (SECTION_PROPS[name] || []).some((p) => authored[p]);
518
+ return (
519
+ <section className="st-cp-sec" key={name}>
520
+ <div className="st-cp-sechd-row">
521
+ <button
522
+ type="button"
523
+ className="st-cp-sechd"
524
+ data-testid={`inspector-section-${name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`}
525
+ aria-expanded={!!open[name]}
526
+ onClick={() => setOpen((o) => ({ ...o, [name]: !o[name] }))}
527
+ >
528
+ <span className="st-cp-caret" aria-hidden="true">
529
+ {open[name] ? '▾' : '▸'}
530
+ </span>
531
+ {name}
532
+ </button>
533
+ {/* handoff — reset always present (design), dimmed when nothing to reset. */}
534
+ <button
535
+ type="button"
536
+ className={`st-cp-secreset${dirty ? '' : ' is-quiet'}`}
537
+ aria-label={`reset ${name} section to original`}
538
+ title={`reset ${name}`}
539
+ disabled={!dirty}
540
+ onClick={() => resetSection(name)}
541
+ >
542
+ <Lu as={LuRotateCw} size={12} />
543
+ </button>
544
+ </div>
545
+ {/* animated collapse — grid-rows 0fr→1fr keeps the DOM + interpolates
546
+ height (feature-inspector-controls-redesign handoff). */}
547
+ <div className={`st-cp-sec-anim${open[name] ? ' is-open' : ''}`}>
548
+ <div className="st-cp-sec-inner">{body}</div>
549
+ </div>
550
+ </section>
551
+ );
552
+ };
553
+
554
+ // DDR-171 — Designer mode's cluster wrapper. Mirrors `sec()`'s exact chrome
555
+ // (caret, reset, animated collapse — reuses `.st-cp-sec`/`.st-cp-sechd`/
556
+ // `.st-cp-sec-anim` verbatim, no new CSS shape) but takes an explicit
557
+ // `props` reset-list instead of looking one up in `SECTION_PROPS`, because
558
+ // Designer clusters cut across Advanced-mode section boundaries and don't
559
+ // map 1:1 onto it (e.g. "Auto layout" pulls from both Layout and Size).
560
+ // Open-state lives in the SAME `open` object under a `d:`-prefixed key so no
561
+ // second piece of state is needed; `defaultOpen=false` is how the Position
562
+ // cluster starts collapsed (see `hasCustomPosition` auto-expand above).
563
+ const dsec = (name, props, body, defaultOpen = true) => {
564
+ const key = `d:${name}`;
565
+ const isOpen = open[key] === undefined ? defaultOpen : open[key];
566
+ const dirty = props.some((p) => authored[p]);
567
+ return (
568
+ <section className="st-cp-sec" key={key}>
569
+ <div className="st-cp-sechd-row">
570
+ <button
571
+ type="button"
572
+ className="st-cp-sechd"
573
+ aria-expanded={isOpen}
574
+ onClick={() => setOpen((o) => ({ ...o, [key]: !isOpen }))}
575
+ >
576
+ <span className="st-cp-caret" aria-hidden="true">
577
+ {isOpen ? '▾' : '▸'}
578
+ </span>
579
+ {name}
580
+ </button>
581
+ <button
582
+ type="button"
583
+ className={`st-cp-secreset${dirty ? '' : ' is-quiet'}`}
584
+ aria-label={`reset ${name} to original`}
585
+ title={`reset ${name}`}
586
+ disabled={!dirty}
587
+ onClick={() => props.forEach((p) => { if (authored[p]) reset(p); })}
588
+ >
589
+ <Lu as={LuRotateCw} size={12} />
590
+ </button>
591
+ </div>
592
+ <div className={`st-cp-sec-anim${isOpen ? ' is-open' : ''}`}>
593
+ <div className="st-cp-sec-inner">{body}</div>
594
+ </div>
595
+ </section>
596
+ );
597
+ };
598
+ // A cluster's "···" disclosure toggle for its less-common rows (Figma's own
599
+ // per-panel overflow affordance) — distinct from the cluster's own
600
+ // open/collapse caret above. `designerMore[key]` gates the extra rows.
601
+ const moreBtn = (key) => (
602
+ <button
603
+ type="button"
604
+ className="st-cp-clustermore"
605
+ aria-expanded={!!designerMore[key]}
606
+ aria-label={designerMore[key] ? `${key} — fewer options` : `${key} — more options`}
607
+ title={designerMore[key] ? 'fewer' : 'more'}
608
+ onClick={() => setDesignerMore((m) => ({ ...m, [key]: !m[key] }))}
609
+ >
610
+ {designerMore[key] ? '▴' : '···'}
611
+ </button>
612
+ );
613
+
614
+ // native <select> committing a CSS value directly
615
+ const csel = (prop, list) => (
616
+ <select
617
+ className="st-cp-nsel"
618
+ aria-label={prop}
619
+ value={list.includes(authored[prop]) ? authored[prop] : ''}
620
+ onChange={(e) => commit(prop, e.target.value)}
621
+ >
622
+ <option value="" disabled>
623
+ {cssHint(computed[prop]) || '—'}
624
+ </option>
625
+ {list.map((v) => (
626
+ <option key={v} value={v}>
627
+ {v}
628
+ </option>
629
+ ))}
630
+ </select>
631
+ );
632
+
633
+ // ── feature-inspector-controls-redesign handoff — the design's control set,
634
+ // wired to CssKnobs' CSS-string commit lane. ────────────────────────────────
635
+ const flatTokens = (familyKey) => tokenGroups(familyKey).flatMap((g) => (g.names || []).map((n) => ({ name: n, value: g.vals?.[n] || '' })));
636
+ // enum → lucide icon button group (commits the raw CSS keyword)
637
+ const iconseg = (prop, options) => (
638
+ <IconButtonGroup value={authored[prop] || cssHint(computed[prop]) || options[0].value} ariaLabel={prop} options={options} onChange={(v) => commit(prop, v)} />
639
+ );
640
+ // number + unit + ◇ design-token binding (space / radius / type families)
641
+ const vtok = (prop, familyKey, opts = {}) => {
642
+ const cur = cssSplitUnit(authored[prop] ?? '');
643
+ const unitless = CSS_UNITLESS.has(prop);
644
+ const av = authored[prop] ?? '';
645
+ const bound = typeof av === 'string' && /var\(\s*--/.test(av);
646
+ const unit = unitless ? '' : cur.unit && cur.unit !== 'auto' ? cur.unit : 'px';
647
+ const hintN = Number.parseFloat(cssSplitUnit(cssHint(computed[prop]) ?? '').n) || 0;
648
+ const numVal = cur.n !== '' && cur.n != null ? Number.parseFloat(cur.n) || 0 : hintN;
649
+ const lead = PROP_LEAD[prop];
650
+ return (
651
+ <ValueTokenField
652
+ value={bound ? av : numVal}
653
+ tokens={flatTokens(familyKey)}
654
+ ariaLabel={prop}
655
+ min={opts.min ?? 0}
656
+ lead={lead ? (lead.node ?? lead.t) : undefined}
657
+ unitSlot={unitless ? null : <UnitSelect units={CSS_UNITS} value={cur.unit || 'px'} ariaLabel={`${prop} unit`} onChange={(u) => commit(prop, u === 'auto' ? 'auto' : `${cur.n || '0'}${u}`)} />}
658
+ onChange={(v) => commit(prop, typeof v === 'string' ? v : unitless ? `${v}` : `${v}${unit}`)}
659
+ />
660
+ );
661
+ };
662
+ // border-radius → uniform field + ▢ detach → 2×2 corner quad
663
+ const radiusControl = () => {
664
+ const parse = (p) => Number.parseFloat(cssSplitUnit(authored[p] ?? authored['border-radius'] ?? cssHint(computed[p]) ?? cssHint(computed['border-radius']) ?? '0').n) || 0;
665
+ const corners = { tl: parse('border-top-left-radius'), tr: parse('border-top-right-radius'), bl: parse('border-bottom-left-radius'), br: parse('border-bottom-right-radius') };
666
+ const onCorners = (c) => {
667
+ const uniform = c.tl === c.tr && c.tr === c.bl && c.bl === c.br;
668
+ if (uniform) {
669
+ ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-left-radius', 'border-bottom-right-radius'].forEach((p) => { if (authored[p]) reset(p); });
670
+ commit('border-radius', `${c.tl}px`);
671
+ } else {
672
+ commit('border-top-left-radius', `${c.tl}px`);
673
+ commit('border-top-right-radius', `${c.tr}px`);
674
+ commit('border-bottom-left-radius', `${c.bl}px`);
675
+ commit('border-bottom-right-radius', `${c.br}px`);
676
+ }
677
+ };
678
+ const lead = PROP_LEAD['border-radius'];
679
+ return <RadiusControl corners={corners} lead={lead ? (lead.node ?? lead.t) : undefined} onCorners={onCorners} />;
680
+ };
681
+ // border composite (width + style + colour) — DDR-171 pulled this out of the
682
+ // Advanced-mode Appearance row inline JSX so Designer mode's "Stroke"
683
+ // cluster (Task 6) can reuse the exact same control, not a re-implementation.
684
+ const borderControl = () => (
685
+ <div className="st-cp-border">
686
+ {num('border-width', null, { fixedUnit: 'px' })}
687
+ <select
688
+ className="st-cp-nsel st-cp-nsel--mini"
689
+ aria-label="border-style"
690
+ value={CSS_BORDER_STYLES.includes(authored['border-style']) ? authored['border-style'] : ''}
691
+ onChange={(e) => commit('border-style', e.target.value)}
692
+ >
693
+ <option value="" disabled>
694
+ style
695
+ </option>
696
+ {CSS_BORDER_STYLES.map((s) => (
697
+ <option key={s} value={s}>
698
+ {s}
699
+ </option>
700
+ ))}
701
+ </select>
702
+ <TokenPopover
703
+ kind="color"
704
+ groups={tokenGroups('color')}
705
+ current={authored['border-color']}
706
+ activeDs={_activeDs}
707
+ swatchBg={computed['border-color'] || authored['border-color'] || ''}
708
+ seedHex={cssColorToHex(computed['border-color'] || authored['border-color']) || '#000000'}
709
+ onPick={(v) => commit('border-color', v)}
710
+ label="border colour"
711
+ />
712
+ </div>
713
+ );
714
+ // rotation dial, reading/writing the rotate() term of `transform`
715
+ const rotationControl = () => {
716
+ const t = authored.transform || cssHint(computed.transform) || '';
717
+ const m = /rotate\(\s*(-?\d+(?:\.\d+)?)deg\s*\)/.exec(t);
718
+ const deg = (((m ? Number.parseFloat(m[1]) : 0) % 360) + 360) % 360;
719
+ const setDeg = (d) => {
720
+ const norm = ((d % 360) + 360) % 360;
721
+ const base = (authored.transform || '').replace(/\s*rotate\([^)]*\)\s*/g, ' ').trim();
722
+ commit('transform', `${base ? `${base} ` : ''}rotate(${norm}deg)`.trim());
723
+ };
724
+ return (
725
+ <div className="st-cp-num" style={{ border: 0, background: 'transparent', gap: 'var(--space-2)' }}>
726
+ <AngleDial value={deg} onChange={setDeg} />
727
+ <NumberField value={deg} min={0} max={360} ariaLabel="rotation" lead={<Lu as={LuRotateCw} />} steppers={false} unitSlot={<span className="st-cp-numsuffix" aria-hidden="true">°</span>} onCommit={setDeg} />
728
+ </div>
729
+ );
730
+ };
731
+ // DDR-171 — `filter: blur(Npx)`, scoped to blur-only for v1 (not a full
732
+ // filter-function editor). Local parse/serialize (unlike most rows this
733
+ // doesn't pass the raw string straight to `commit`) — kept as a closure here,
734
+ // not a top-level utility, so it stays governed by the "no new primitives"
735
+ // constraint. A non-blur `filter` value (set via Advanced's raw-CSS hatch)
736
+ // reads as 0 here rather than being clobbered — only written back once the
737
+ // user actually commits a blur amount.
738
+ const blurControl = () => {
739
+ const f = authored.filter || cssHint(computed.filter) || '';
740
+ const m = /blur\(\s*(-?\d+(?:\.\d+)?)px\s*\)/.exec(f);
741
+ const px = m ? Number.parseFloat(m[1]) : 0;
742
+ const setBlur = (n) => {
743
+ const base = (authored.filter || '').replace(/\s*blur\([^)]*\)\s*/g, ' ').trim();
744
+ commit('filter', n > 0 ? `${base ? `${base} ` : ''}blur(${n}px)`.trim() : base || 'none');
745
+ };
746
+ return <NumberField value={px} min={0} ariaLabel="filter blur" unitSlot={<span className="st-cp-numsuffix" aria-hidden="true">px</span>} onCommit={setBlur} />;
747
+ };
748
+ // handoff — shown as 0–100 % (design), stored as the CSS 0–1 value. Pulled
749
+ // out (DDR-171) so Designer mode's "Opacity" cluster reuses it verbatim.
750
+ const opacityControl = () => {
751
+ const a = authored.opacity;
752
+ const raw = a != null && a !== '' ? Number.parseFloat(a) : Number.parseFloat(cssHint(computed.opacity)) || 1;
753
+ const pct = Math.round((Number.isNaN(raw) ? 1 : raw) * 100);
754
+ return (
755
+ <SliderField
756
+ key={`opacity:${a ?? ''}`}
757
+ value={pct}
758
+ min={0}
759
+ max={100}
760
+ step={1}
761
+ unit="%"
762
+ ariaLabel="opacity"
763
+ onInput={(n) => optimistic('opacity', String(n / 100))}
764
+ onCommit={(n) => commit('opacity', String(n / 100))}
765
+ />
766
+ );
767
+ };
768
+ // B / I / U quick-style toggle group → font-weight / font-style / text-decoration
769
+ const textStyleToggle = () => {
770
+ const isBold = Number.parseInt(authored['font-weight'] || cssHint(computed['font-weight']) || '400', 10) >= 600;
771
+ const isItalic = (authored['font-style'] || cssHint(computed['font-style'])) === 'italic';
772
+ const isUnder = /underline/.test(authored['text-decoration'] || cssHint(computed['text-decoration']) || '');
773
+ return (
774
+ <IconToggleGroup
775
+ value={{ b: isBold, i: isItalic, u: isUnder }}
776
+ ariaLabel="text style"
777
+ options={[{ value: 'b', node: <Lu as={LuBold} />, label: 'Bold' }, { value: 'i', node: <Lu as={LuItalic} />, label: 'Italic' }, { value: 'u', node: <Lu as={LuUnderline} />, label: 'Underline' }]}
778
+ onToggle={(k) => {
779
+ if (k === 'b') commit('font-weight', isBold ? '400' : '700');
780
+ else if (k === 'i') commit('font-style', isItalic ? 'normal' : 'italic');
781
+ else commit('text-decoration', isUnder ? 'none' : 'underline');
782
+ }}
783
+ />
784
+ );
785
+ };
786
+ const DIR_OPTS = [{ value: 'row', node: <Lu as={LuColumns3} />, label: 'Row' }, { value: 'column', node: <Lu as={LuRows3} />, label: 'Column' }];
787
+ const JUSTIFY_OPTS = [{ value: 'flex-start', node: <Lu as={LuJustifyStart} />, label: 'Start' }, { value: 'center', node: <Lu as={LuJustifyCenter} />, label: 'Center' }, { value: 'flex-end', node: <Lu as={LuJustifyEnd} />, label: 'End' }, { value: 'space-between', node: <Lu as={LuSpaceBetween} />, label: 'Space between' }];
788
+ const ALIGNITEMS_OPTS = [{ value: 'flex-start', node: <Lu as={LuVJustifyStart} />, label: 'Start' }, { value: 'center', node: <Lu as={LuVJustifyCenter} />, label: 'Center' }, { value: 'flex-end', node: <Lu as={LuVJustifyEnd} />, label: 'End' }, { value: 'stretch', node: <Lu as={LuStretch} />, label: 'Stretch' }];
789
+ const TEXTALIGN_OPTS = [{ value: 'left', node: <Lu as={LuAlignLeft} />, label: 'Left' }, { value: 'center', node: <Lu as={LuAlignCenter} />, label: 'Center' }, { value: 'right', node: <Lu as={LuAlignRight} />, label: 'Right' }, { value: 'justify', node: <Lu as={LuAlignJustify} />, label: 'Justify' }];
790
+ const OVERFLOW_OPTS = [{ value: 'visible', node: <Lu as={LuEye} />, label: 'Visible' }, { value: 'hidden', node: <Lu as={LuScissors} />, label: 'Hidden' }, { value: 'scroll', node: <Lu as={LuScrollText} />, label: 'Scroll' }];
791
+
792
+ // token quick-pick — Figma-style POPOVER (W2.1) listing the DS variables for
793
+ // this property (name + resolved value), grouped per design system (W3);
794
+ // picking writes var(--token). `familyKey` selects the token family.
795
+ const tok = (prop, familyKey) => {
796
+ const groups = tokenGroups(familyKey);
797
+ return groups.length ? (
798
+ <TokenPopover
799
+ kind="value"
800
+ groups={groups}
801
+ current={authored[prop]}
802
+ activeDs={_activeDs}
803
+ onPick={(v) => commit(prop, v)}
804
+ label={`${prop} design token`}
805
+ />
806
+ ) : null;
807
+ };
808
+
809
+ // Select-all-on-focus (deferred past the browser's own click-caret placement
810
+ // so a SECOND click, already focused, places the caret instead) — the
811
+ // interaction-model rule applied to the CssKnobs fields that stay bespoke
812
+ // <input>s (free text, box-model cells) rather than the shared NumberField.
813
+ const selectAllOnFocus = (e) => {
814
+ const el = e.currentTarget;
815
+ requestAnimationFrame(() => {
816
+ if (document.activeElement === el) el.select();
817
+ });
818
+ };
819
+ // Arrow-key stepping (±1, Shift ×10) for the bespoke box-model cells — same
820
+ // keyboard model NumberField gives the main fields, hand-rolled here because
821
+ // these stay compact <input>s (no room for NumberField's handle+stepper
822
+ // chrome in a 36×24 box-model cell). Returns true if it handled the key.
823
+ const stepBoxInput = (e, commitFn) => {
824
+ if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return false;
825
+ e.preventDefault();
826
+ const mult = e.shiftKey ? 10 : 1;
827
+ const dir = e.key === 'ArrowUp' ? 1 : -1;
828
+ const n = (Number.parseFloat(e.currentTarget.value) || 0) + dir * mult;
829
+ e.currentTarget.value = String(n);
830
+ commitFn(n);
831
+ return true;
832
+ };
833
+
834
+ // free text input — raw value or var(--token), commits on blur/Enter
835
+ const text = (prop) => (
836
+ <input
837
+ className="st-cp-fin"
838
+ key={`${prop}:${authored[prop] ?? ''}`}
839
+ aria-label={prop}
840
+ defaultValue={authored[prop] ?? ''}
841
+ placeholder={cssHint(computed[prop]) || '—'}
842
+ onFocus={selectAllOnFocus}
843
+ onKeyDown={(e) => {
844
+ if (e.key === 'Enter') e.currentTarget.blur();
845
+ }}
846
+ onBlur={(e) => commit(prop, e.currentTarget.value)}
847
+ />
848
+ );
849
+
850
+ // number + steppers + unit-select (+ optional token quick-pick after) — built
851
+ // on the shared NumberField (feature-inspector-controls-redesign): the drag
852
+ // handle moves to the leading icon/grip (never the input body, so click-to-
853
+ // type + select-all-on-focus work), and arrow-key stepping comes for free.
854
+ const num = (prop, tokenList, opts = {}) => {
855
+ const cur = cssSplitUnit(authored[prop] ?? '');
856
+ // Unitless CSS properties — a bare number must commit WITHOUT a unit suffix
857
+ // (line-height: 1.5px ≠ 1.5 — knob-smoke finding, 2026-06-12).
858
+ const unitless = CSS_UNITLESS.has(prop);
859
+ // `opts.fixedUnit` — a px-only field (border-width) skips the unit <select>
860
+ // entirely so the compact border-cluster row (width + style + swatch) has
861
+ // room to fit at the panel's 260-304px widths (Task 5 overflow fix).
862
+ const unit = unitless ? '' : opts.fixedUnit || (cur.unit && cur.unit !== 'auto' ? cur.unit : 'px');
863
+ const lead = PROP_LEAD[prop];
864
+ // Unset (no authored value) shows the computed/inherited value as the
865
+ // starting number — same value the old placeholder hinted at; the row's own
866
+ // dimming (`row()`'s `is-unset`) is what signals "inherited", not this field.
867
+ const hintN = Number.parseFloat(cssSplitUnit(cssHint(computed[prop]) ?? '').n) || 0;
868
+ const shownN = cur.n !== '' && cur.n != null ? Number.parseFloat(cur.n) || 0 : hintN;
869
+ return (
870
+ <>
871
+ <NumberField
872
+ key={`${prop}:${authored[prop] ?? ''}`}
873
+ value={shownN}
874
+ min={opts.min ?? 0}
875
+ step={1}
876
+ ariaLabel={prop}
877
+ lead={lead ? (lead.node ?? lead.t) : undefined}
878
+ onCommit={(n) => commit(prop, unitless ? `${n}` : `${n}${unit}`)}
879
+ unitSlot={
880
+ unitless || opts.fixedUnit ? null : (
881
+ <UnitSelect
882
+ units={CSS_UNITS}
883
+ value={cur.unit || 'px'}
884
+ ariaLabel={`${prop} unit`}
885
+ onChange={(u) => commit(prop, u === 'auto' ? 'auto' : `${cur.n || '0'}${u}`)}
886
+ />
887
+ )
888
+ }
889
+ />
890
+ {tok(prop, tokenList)}
891
+ </>
892
+ );
893
+ };
894
+
895
+ // color swatch (native picker → hex) + raw text + token quick-pick
896
+ const color = (prop) => {
897
+ // ONE compact colour field (feature-inspector-controls-redesign handoff): the
898
+ // TokenPopover swatch is the FLUSH prefix (divider, no gap) inside ColorField,
899
+ // then the value input — swatch + value read as one field. The popover keeps
900
+ // its full HSV picker (Custom) + DS swatches (Variables) + cross-DS/security.
901
+ const resolved = computed[prop] || authored[prop] || '';
902
+ const av = authored[prop] ?? '';
903
+ const bound = typeof av === 'string' && /var\(\s*--/.test(av);
904
+ const display = bound ? av.replace(/^var\(\s*|\s*\)$/g, '').replace(/^--/, '').replace(/-/g, ' ') : av;
905
+ return (
906
+ <ColorField
907
+ swatch={
908
+ <TokenPopover
909
+ kind="color"
910
+ swatchClassName="st-cp-cf-sw"
911
+ groups={tokenGroups('color')}
912
+ current={authored[prop]}
913
+ activeDs={_activeDs}
914
+ swatchBg={resolved}
915
+ seedHex={cssColorToHex(computed[prop] || authored[prop]) || '#000000'}
916
+ onPick={(v) => commit(prop, v)}
917
+ label={`${prop} colour`}
918
+ />
919
+ }
920
+ displayValue={display}
921
+ bound={bound}
922
+ ariaLabel={prop}
923
+ onValue={(v) => commit(prop, v)}
924
+ />
925
+ );
926
+ };
927
+
928
+ // a box-model side input (margin/padding longhand). Phase 12.3 — Webflow-style:
929
+ // always shows the RESOLVED value (0 instead of blank) and a faint `is-zero`
930
+ // styling for an unset/zero side. Edits the single side (the old "link all
931
+ // sides" toggle was removed — DDR-104 Phase 12.3 W1.5).
932
+ // Built on the shared `makeScrubHandler` engine (feature-inspector-controls-
933
+ // redesign) — a plain (non-hook) factory, since `side`/`inset` are helper
934
+ // closures invoked during render, not components (can't call a hook there).
935
+ // These stay compact <input>s with whole-cell scrub (no separate drag handle
936
+ // — the Figma/Webflow convention for tiny box-model cells with no room for
937
+ // one; the 3px dead-zone already lets a plain click through to focus). A
938
+ // multi-side drag (alt = pair, alt+shift = all four) live-updates the sibling
939
+ // box inputs too, so the whole move shows in the panel, not just the dragged
940
+ // cell — `node` closes over the actual input DOM element via onPointerDown.
941
+ const boxScrub = (prop, opts) => {
942
+ let node = null;
943
+ const unit = opts.unitless ? '' : 'px';
944
+ const fmt = (n) => (opts.unitless ? `${n}` : `${n}${unit}`);
945
+ const applyToSides = (n, activeSides, fn) => {
946
+ for (const p of activeSides ?? [prop]) fn(p, fmt(n));
947
+ };
948
+ const scrub = makeScrubHandler({
949
+ getBase: () => node?.value ?? '0',
950
+ min: opts.min ?? 0,
951
+ step: 1,
952
+ sides: opts.sides,
953
+ onInput: (n, activeSides) => {
954
+ if (node) node.value = String(n);
955
+ if (activeSides) {
956
+ const box = node?.closest('.st-cp-box');
957
+ for (const p of activeSides) {
958
+ if (p === prop) continue;
959
+ const sib = box?.querySelector(`.st-cp-boxv[aria-label="${p}"]`);
960
+ if (sib) sib.value = String(n);
961
+ }
962
+ }
963
+ applyToSides(n, activeSides, optimistic);
964
+ },
965
+ onCommit: (n, activeSides) => applyToSides(n, activeSides, commit),
966
+ });
967
+ return {
968
+ onPointerDown: (e) => {
969
+ node = e.currentTarget;
970
+ scrub(e);
971
+ },
972
+ };
973
+ };
974
+
975
+ const side = (prop, group) => {
976
+ const a = authored[prop];
977
+ const shown =
978
+ a != null && a !== ''
979
+ ? cssSplitUnit(a).n || a
980
+ : cssSplitUnit(cssHint(computed[prop]) ?? '').n || '0';
981
+ const isZero = !a || a === '0' || a === '0px' || a === 'auto';
982
+ // Webflow scrub modifiers — alt = symmetric pair (block for top/bottom,
983
+ // inline for left/right), alt+shift = all four.
984
+ const edge = prop.split('-').pop();
985
+ const pair =
986
+ edge === 'top' || edge === 'bottom'
987
+ ? [`${group}-top`, `${group}-bottom`]
988
+ : [`${group}-left`, `${group}-right`];
989
+ const all = [`${group}-top`, `${group}-right`, `${group}-bottom`, `${group}-left`];
990
+ return (
991
+ <input
992
+ className={`st-cp-boxv st-cp-scrub st-cp-boxv--${group[0]}${prop.split('-').pop()[0]}${
993
+ isZero ? ' is-zero' : ''
994
+ }`}
995
+ key={`${prop}:${a ?? ''}`}
996
+ aria-label={prop}
997
+ defaultValue={shown}
998
+ title="drag to scrub · alt = symmetric · alt+shift = all sides"
999
+ {...boxScrub(prop, { sides: { pair, all } })}
1000
+ onFocus={selectAllOnFocus}
1001
+ onKeyDown={(e) => {
1002
+ if (stepBoxInput(e, (n) => commit(prop, `${n}px`))) return;
1003
+ if (e.key === 'Enter') e.currentTarget.blur();
1004
+ }}
1005
+ onBlur={(e) => {
1006
+ const raw = e.currentTarget.value.trim();
1007
+ if (!raw) return;
1008
+ const val = /[a-z%]/i.test(raw) ? raw : `${raw}px`;
1009
+ commit(prop, val);
1010
+ }}
1011
+ />
1012
+ );
1013
+ };
1014
+
1015
+ // feature-element-editing-robustness Stage B (Task B3) — a position INSET side
1016
+ // (top/right/bottom/left). Mirrors `side()` but for the bare inset longhands
1017
+ // (no group prefix), allowing NEGATIVE values and an `auto` default, and reuses
1018
+ // the same box-model scrub grammar: alt = the axis pair, alt+shift = all four.
1019
+ const inset = (prop) => {
1020
+ const a = authored[prop];
1021
+ const shown =
1022
+ a != null && a !== '' && a !== 'auto'
1023
+ ? cssSplitUnit(a).n || a
1024
+ : cssSplitUnit(cssHint(computed[prop]) ?? '').n || '';
1025
+ const isZero = !a || a === 'auto' || a === '0' || a === '0px';
1026
+ const pair = prop === 'top' || prop === 'bottom' ? ['top', 'bottom'] : ['left', 'right'];
1027
+ const all = ['top', 'right', 'bottom', 'left'];
1028
+ return (
1029
+ <input
1030
+ className={`st-cp-boxv st-cp-scrub st-cp-boxv--i${prop[0]}${isZero ? ' is-zero' : ''}`}
1031
+ key={`${prop}:${a ?? ''}`}
1032
+ aria-label={prop}
1033
+ defaultValue={shown}
1034
+ placeholder="auto"
1035
+ title="drag to scrub · alt = axis pair · alt+shift = all sides · type auto"
1036
+ {...boxScrub(prop, { sides: { pair, all }, min: -Infinity })}
1037
+ onFocus={selectAllOnFocus}
1038
+ onKeyDown={(e) => {
1039
+ if (stepBoxInput(e, (n) => commit(prop, `${n}px`))) return;
1040
+ if (e.key === 'Enter') e.currentTarget.blur();
1041
+ }}
1042
+ onBlur={(e) => {
1043
+ const raw = e.currentTarget.value.trim();
1044
+ if (!raw) return;
1045
+ const val = /[a-z%]/i.test(raw) ? raw : `${raw}px`;
1046
+ commit(prop, val);
1047
+ }}
1048
+ />
1049
+ );
1050
+ };
1051
+
1052
+ // Phase 12.3 — authored inline props with no curated row + custom HTML attrs,
1053
+ // surfaced in Advanced so the user can see/edit/remove what they added.
1054
+ const customStyleRows = Object.entries(customStyles);
1055
+ const attrRows = Object.entries(attrs);
1056
+
1057
+ // Stage B (Task B5) — Media framing gate + body, pulled out (DDR-171) so
1058
+ // Designer mode's "Media" cluster renders the identical content (just a
1059
+ // relabeled wrapper) instead of re-deriving `showMedia`/`canReplace`.
1060
+ // Rendered only for a media element (img / video / picture / svg / canvas)
1061
+ // or a selection that already carries a framing prop, so a plain <div>
1062
+ // doesn't grow object-fit rows. Media = box/framing/source (this plan); the
1063
+ // photo-editor plan's "Photo" tab owns pixels/look — separate DOM slots by
1064
+ // design.
1065
+ const mediaGate = () => {
1066
+ const t = (el.tag || '').toLowerCase();
1067
+ const isMediaEl = t === 'img' || t === 'video' || t === 'picture' || t === 'svg' || t === 'canvas';
1068
+ const showMedia =
1069
+ isMediaEl || !!authored['object-fit'] || !!authored['object-position'] || !!authored['aspect-ratio'];
1070
+ // Stage F2 — "Replace…" opens the AssetPicker to re-point src (authored
1071
+ // <img>/<video> only; a template-expression src can't be string-swapped,
1072
+ // so gate on a real src attr being present).
1073
+ const canReplace = (t === 'img' || t === 'video') && !!el.attrs?.src && !!onReplaceMedia;
1074
+ return { showMedia, canReplace };
1075
+ };
1076
+ const mediaBody = (canReplace) => (
1077
+ <>
1078
+ {canReplace && (
1079
+ <div className="st-cp-mediabtn">
1080
+ <button type="button" className="st-btn st-cp-replace" onClick={() => onReplaceMedia(el)}>
1081
+ Replace…
1082
+ </button>
1083
+ </div>
1084
+ )}
1085
+ {row('object-fit', csel('object-fit', CSS_OBJECT_FIT))}
1086
+ {row('object-position', text('object-position'))}
1087
+ {row(
1088
+ 'aspect-ratio',
1089
+ <select
1090
+ className="st-cp-nsel"
1091
+ aria-label="aspect-ratio"
1092
+ value={CSS_ASPECT_RATIO.includes(authored['aspect-ratio']) ? authored['aspect-ratio'] : ''}
1093
+ onChange={(e) => {
1094
+ const v = e.target.value;
1095
+ commit('aspect-ratio', v);
1096
+ // A fixed height overrides aspect-ratio (CSS: explicit width+height
1097
+ // win). When applying a real ratio, release the height so the ratio
1098
+ // actually reshapes the box (dogfood: "nastavil jsem 16/9 a nic se
1099
+ // nestalo").
1100
+ if (v && v !== 'auto' && authored.height) reset('height');
1101
+ }}
1102
+ >
1103
+ <option value="" disabled>
1104
+ {cssHint(computed['aspect-ratio']) || '—'}
1105
+ </option>
1106
+ {CSS_ASPECT_RATIO.map((v) => (
1107
+ <option key={v} value={v}>
1108
+ {v}
1109
+ </option>
1110
+ ))}
1111
+ </select>
1112
+ )}
1113
+ </>
1114
+ );
1115
+
1116
+ return (
1117
+ <div className={`st-cp${mode === 'designer' ? ' st-cp--designer' : ''}`} key={el.id} data-tour="css-panel" onKeyDown={onKnobKeyDown}>
1118
+ <div className="st-cp-id">
1119
+ <span className="st-cp-idtag">
1120
+ {el.tag || 'element'}
1121
+ {el.classes ? <span className="st-cp-idcls">.{el.classes.split(/\s+/)[0]}</span> : null}
1122
+ </span>
1123
+ {/* DDR-171 — vocabulary mode toggle, tucked into the id row's corner
1124
+ slot (was a full-width Segmented row — read as too heavy; a
1125
+ two-icon IconButtonGroup matches every other compact toggle in
1126
+ this panel). 'advanced' is the default (today's panel, byte-
1127
+ identical below); 'designer' swaps in the Figma-vocabulary regroup.
1128
+ Named "Advanced" (not "Simple"/"Basic") so neither mode reads as
1129
+ the lesser fallback — see DDR-171 for the naming-collision call
1130
+ against the nested Advanced *section* below. */}
1131
+ <span className="st-cp-idmode" data-tour="cp-mode">
1132
+ <IconButtonGroup
1133
+ value={mode}
1134
+ ariaLabel="panel vocabulary mode"
1135
+ options={[
1136
+ { value: 'advanced', node: <Lu as={LuBraces} size={12} />, label: 'Advanced — raw CSS' },
1137
+ { value: 'designer', node: <Lu as={LuWand2} size={12} />, label: 'Designer — Figma vocabulary' },
1138
+ ]}
1139
+ onChange={setMode}
1140
+ />
1141
+ </span>
1142
+ </div>
1143
+
1144
+ {mode === 'designer' ? (
1145
+ <>
1146
+ {dsec(
1147
+ 'Auto layout',
1148
+ ['display', 'flex-direction', 'flex-wrap', 'align-items', 'justify-content', 'gap', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left'],
1149
+ (() => {
1150
+ const disp = (authored.display || cssHint(computed.display) || '').trim();
1151
+ const isFlex = disp === 'flex' || disp === 'inline-flex';
1152
+ return isFlex ? (
1153
+ <>
1154
+ {row('flex-direction', iconseg('flex-direction', DIR_OPTS), undefined, 'Direction')}
1155
+ {row(
1156
+ 'align-items',
1157
+ <AlignPad value={alignPadCell()} onChange={setAlignPadCell} ariaLabel="auto-layout alignment" />,
1158
+ provOf('align-items'),
1159
+ 'Alignment'
1160
+ )}
1161
+ {row('gap', vtok('gap', 'space'), undefined, 'Gap')}
1162
+ <div className="st-cp-modes">
1163
+ {sizeModeSeg('width')}
1164
+ {sizeModeSeg('height')}
1165
+ </div>
1166
+ <div className="st-cp-box" aria-label="padding">
1167
+ <span className="st-cp-boxtag st-cp-boxtag--p">
1168
+ {prov(provOf('padding-top'))}padding
1169
+ </span>
1170
+ {side('padding-top', 'padding')}
1171
+ {side('padding-right', 'padding')}
1172
+ {side('padding-bottom', 'padding')}
1173
+ {side('padding-left', 'padding')}
1174
+ </div>
1175
+ <div className="st-cp-clustermore-row">{moreBtn('Auto layout')}</div>
1176
+ {designerMore['Auto layout']
1177
+ ? row(
1178
+ 'flex-wrap',
1179
+ <Toggle
1180
+ checked={/^wrap/.test(authored['flex-wrap'] || cssHint(computed['flex-wrap']) || '')}
1181
+ label="wrap items"
1182
+ ariaLabel="flex-wrap"
1183
+ onChange={(w) => commit('flex-wrap', w ? 'wrap' : 'nowrap')}
1184
+ />,
1185
+ provOf('flex-wrap'),
1186
+ 'Wrap'
1187
+ )
1188
+ : null}
1189
+ </>
1190
+ ) : (
1191
+ <button type="button" className="st-cp-makeflex" disabled={!editable} onClick={() => commit('display', 'flex')}>
1192
+ + Auto layout (flex)
1193
+ </button>
1194
+ );
1195
+ })()
1196
+ )}
1197
+
1198
+ {dsec(
1199
+ 'Size',
1200
+ ['width', 'height', 'min-width', 'max-width', 'min-height', 'max-height'],
1201
+ <>
1202
+ {row('width', num('width'), undefined, 'Width')}
1203
+ {row('height', num('height'), undefined, 'Height')}
1204
+ <div className="st-cp-clustermore-row">{moreBtn('Size')}</div>
1205
+ {designerMore.Size ? (
1206
+ <>
1207
+ {row('min-width', num('min-width'), undefined, 'Min width')}
1208
+ {row('max-width', num('max-width'), undefined, 'Max width')}
1209
+ {row('min-height', num('min-height'), undefined, 'Min height')}
1210
+ {row('max-height', num('max-height'), undefined, 'Max height')}
1211
+ </>
1212
+ ) : null}
1213
+ </>
1214
+ )}
1215
+
1216
+ {dsec(
1217
+ 'Position',
1218
+ ['position', 'top', 'right', 'bottom', 'left', 'z-index'],
1219
+ <>
1220
+ {row('position', csel('position', CSS_POSITION), undefined, 'Position')}
1221
+ <div className="st-cp-box st-cp-box--inset" aria-label="position inset (top / right / bottom / left)">
1222
+ <span className="st-cp-boxtag st-cp-boxtag--i">{prov(provOf('top'))}inset</span>
1223
+ {inset('top')}
1224
+ {inset('right')}
1225
+ {inset('bottom')}
1226
+ {inset('left')}
1227
+ <div className="st-cp-boxcore st-cp-boxcore--pos">
1228
+ {authored.position || cssHint(computed.position) || 'static'}
1229
+ </div>
1230
+ </div>
1231
+ {(authored.position || cssHint(computed.position) || 'static') === 'static' ? (
1232
+ <div className="st-cp-note">
1233
+ top / right / bottom / left apply once position is relative, absolute, fixed, or sticky
1234
+ </div>
1235
+ ) : null}
1236
+ <div className="st-cp-clustermore-row">{moreBtn('Position')}</div>
1237
+ {designerMore.Position ? row('z-index', num('z-index'), undefined, 'Layer order') : null}
1238
+ </>,
1239
+ false
1240
+ )}
1241
+
1242
+ {dsec('Fill', ['background-color'], row('background-color', color('background-color'), undefined, 'Fill'))}
1243
+
1244
+ {dsec('Stroke', ['border-width', 'border-style', 'border-color'], row('border', borderControl(), provOf('border-width'), 'Stroke'))}
1245
+
1246
+ {dsec(
1247
+ 'Corner radius',
1248
+ ['border-radius', 'border-top-left-radius', 'border-top-right-radius', 'border-bottom-left-radius', 'border-bottom-right-radius'],
1249
+ row('border-radius', radiusControl(), provOf('border-radius'), 'Corner radius')
1250
+ )}
1251
+
1252
+ {dsec(
1253
+ 'Effects',
1254
+ ['box-shadow', 'filter', 'mix-blend-mode'],
1255
+ <>
1256
+ {row('box-shadow', tok('box-shadow', 'shadow') || text('box-shadow'), undefined, 'Shadow')}
1257
+ {row('filter', blurControl(), provOf('filter'), 'Blur')}
1258
+ {row('mix-blend-mode', csel('mix-blend-mode', CSS_BLEND_MODES), undefined, 'Blend')}
1259
+ </>
1260
+ )}
1261
+
1262
+ {dsec('Opacity', ['opacity'], row('opacity', opacityControl(), undefined, 'Opacity'))}
1263
+
1264
+ {dsec(
1265
+ 'Text',
1266
+ ['font-family', 'color', 'font-size', 'font-weight', 'line-height', 'text-align', 'letter-spacing', 'font-style', 'text-transform', 'white-space'],
1267
+ <>
1268
+ {row('font-family', csel('font-family', CSS_FONTS), undefined, 'Font')}
1269
+ {row('color', color('color'), undefined, 'Color')}
1270
+ {row('font-size', vtok('font-size', 'type'), undefined, 'Size')}
1271
+ {row('font-weight', csel('font-weight', CSS_WEIGHTS), undefined, 'Weight')}
1272
+ {row('line-height', num('line-height', 'lh'), undefined, 'Line height')}
1273
+ {row('text-align', iconseg('text-align', TEXTALIGN_OPTS), undefined, 'Align')}
1274
+ <div className="st-cp-clustermore-row">{moreBtn('Text')}</div>
1275
+ {designerMore.Text ? (
1276
+ <>
1277
+ {row('letter-spacing', num('letter-spacing', null, { min: -Infinity }), undefined, 'Letter spacing')}
1278
+ {row('font-style', csel('font-style', CSS_FONT_STYLE), undefined, 'Style')}
1279
+ {row('text-transform', csel('text-transform', CSS_TEXT_TRANSFORM), undefined, 'Case')}
1280
+ {row('white-space', csel('white-space', CSS_WHITE_SPACE), undefined, 'Whitespace')}
1281
+ </>
1282
+ ) : null}
1283
+ </>
1284
+ )}
1285
+
1286
+ {dsec(
1287
+ 'Spacing',
1288
+ ['margin-top', 'margin-right', 'margin-bottom', 'margin-left'],
1289
+ <div className="st-cp-box" aria-label="margin">
1290
+ <span className="st-cp-boxtag st-cp-boxtag--m">{prov(provOf('margin-top'))}margin</span>
1291
+ {side('margin-top', 'margin')}
1292
+ {side('margin-right', 'margin')}
1293
+ {side('margin-bottom', 'margin')}
1294
+ {side('margin-left', 'margin')}
1295
+ </div>
1296
+ )}
1297
+
1298
+ {(() => {
1299
+ const { showMedia, canReplace } = mediaGate();
1300
+ return showMedia
1301
+ ? dsec('Media', ['object-fit', 'object-position', 'aspect-ratio'], mediaBody(canReplace))
1302
+ : null;
1303
+ })()}
1304
+ </>
1305
+ ) : (
1306
+ <>
1307
+ {sec(
1308
+ 'Layout',
1309
+ (() => {
1310
+ // Stage M2 — auto-layout editor. Present the flex vocabulary (Direction ·
1311
+ // Wrap · Distribution · Align · Gap) only when the element IS a flex/grid
1312
+ // container, so a plain block doesn't carry knobs that do nothing; a
1313
+ // non-container gets a one-click "make it a flex layout" instead (the
1314
+ // DDR-104 gap-degrades-gracefully precedent). align-items / justify-content
1315
+ // / gap apply to grid too; flex-direction / flex-wrap are flex-only.
1316
+ const disp = (authored.display || cssHint(computed.display) || '').trim();
1317
+ const isFlex = disp === 'flex' || disp === 'inline-flex';
1318
+ const isGrid = disp === 'grid' || disp === 'inline-grid';
1319
+ return (
1320
+ <>
1321
+ {row('display', csel('display', CSS_DISPLAYS))}
1322
+ {isFlex ? (
1323
+ <>
1324
+ {row('flex-direction', iconseg('flex-direction', DIR_OPTS))}
1325
+ {row('flex-wrap', <Toggle checked={/^wrap/.test(authored['flex-wrap'] || cssHint(computed['flex-wrap']) || '')} label="wrap items" ariaLabel="flex-wrap" onChange={(w) => commit('flex-wrap', w ? 'wrap' : 'nowrap')} />, provOf('flex-wrap'))}
1326
+ </>
1327
+ ) : null}
1328
+ {isFlex || isGrid ? (
1329
+ <>
1330
+ {row('align-items', iconseg('align-items', ALIGNITEMS_OPTS))}
1331
+ {row('justify-content', iconseg('justify-content', JUSTIFY_OPTS))}
1332
+ {row('gap', vtok('gap', 'space'))}
1333
+ </>
1334
+ ) : (
1335
+ <button
1336
+ type="button"
1337
+ className="st-cp-makeflex"
1338
+ disabled={!editable}
1339
+ onClick={() => commit('display', 'flex')}
1340
+ >
1341
+ + Auto layout (flex)
1342
+ </button>
1343
+ )}
1344
+ </>
1345
+ );
1346
+ })()
1347
+ )}
1348
+
1349
+ {(() => {
1350
+ // feature-3-web-artboards T5 (absorbed feature-grid-track-editor
1351
+ // stub) — Grid section, only when the element IS a grid container.
1352
+ // Track parse/serialize is the SAME grid-track-handles.ts module the
1353
+ // on-canvas gutter-drag overlay uses, so the Inspector and the drag
1354
+ // handles never disagree about track shape.
1355
+ const disp = (authored.display || cssHint(computed.display) || '').trim();
1356
+ const isGrid = disp === 'grid' || disp === 'inline-grid';
1357
+ if (!isGrid) return null;
1358
+ const colsRaw = authored['grid-template-columns'] || '';
1359
+ const rowsRaw = authored['grid-template-rows'] || '';
1360
+ const cols = parseTrackList(colsRaw);
1361
+ const rows = parseTrackList(rowsRaw);
1362
+ const colsEditable = cols.length > 0 || !colsRaw.trim();
1363
+ const rowsEditable = rows.length > 0 || !rowsRaw.trim();
1364
+ return sec(
1365
+ 'Grid',
1366
+ <>
1367
+ {colsEditable ? (
1368
+ <GridTracksEditor
1369
+ label="Columns"
1370
+ tracks={cols}
1371
+ editable={editable}
1372
+ onChange={(next) => commit('grid-template-columns', serializeTrackList(next))}
1373
+ />
1374
+ ) : (
1375
+ <div className="st-cp-note">
1376
+ Columns use <code>{colsRaw}</code> — not editable as tracks here (repeat()/
1377
+ minmax()/subgrid); use /design:edit for these.
1378
+ </div>
1379
+ )}
1380
+ {rowsEditable ? (
1381
+ <GridTracksEditor
1382
+ label="Rows"
1383
+ tracks={rows}
1384
+ editable={editable}
1385
+ onChange={(next) => commit('grid-template-rows', serializeTrackList(next))}
1386
+ />
1387
+ ) : (
1388
+ <div className="st-cp-note">
1389
+ Rows use <code>{rowsRaw}</code> — not editable as tracks here (repeat()/minmax()/
1390
+ subgrid); use /design:edit for these.
1391
+ </div>
1392
+ )}
1393
+ </>
1394
+ );
1395
+ })()}
1396
+
1397
+ {sec(
1398
+ 'Position',
1399
+ <>
1400
+ {row('position', csel('position', CSS_POSITION))}
1401
+ <div className="st-cp-box st-cp-box--inset" aria-label="position inset (top / right / bottom / left)">
1402
+ <span className="st-cp-boxtag st-cp-boxtag--i">{prov(provOf('top'))}inset</span>
1403
+ {inset('top')}
1404
+ {inset('right')}
1405
+ {inset('bottom')}
1406
+ {inset('left')}
1407
+ <div className="st-cp-boxcore st-cp-boxcore--pos">
1408
+ {authored.position || cssHint(computed.position) || 'static'}
1409
+ </div>
1410
+ </div>
1411
+ {(authored.position || cssHint(computed.position) || 'static') === 'static' ? (
1412
+ <div className="st-cp-note">
1413
+ top / right / bottom / left apply once position is relative, absolute, fixed, or sticky
1414
+ </div>
1415
+ ) : null}
1416
+ {row('z-index', num('z-index'))}
1417
+ </>
1418
+ )}
1419
+
1420
+ {(el.parentDisplay === 'grid' || el.parentDisplay === 'inline-grid') &&
1421
+ sec(
1422
+ 'Grid item',
1423
+ <>
1424
+ <div className="st-cp-note">
1425
+ Manual cell placement — <code>start / end</code> or <code>start / span N</code>.
1426
+ </div>
1427
+ {row('grid-column', text('grid-column'))}
1428
+ {row('grid-row', text('grid-row'))}
1429
+ </>
1430
+ )}
1431
+
1432
+ {sec(
1433
+ 'Typography',
1434
+ <>
1435
+ {row('font-family', csel('font-family', CSS_FONTS))}
1436
+ {row('color', color('color'))}
1437
+ {row('font-size', vtok('font-size', 'type'))}
1438
+ {row('font-weight', csel('font-weight', CSS_WEIGHTS))}
1439
+ {row('line-height', num('line-height', 'lh'))}
1440
+ {row('letter-spacing', num('letter-spacing', null, { min: -Infinity }))}
1441
+ {/* handoff — text-align as a lucide icon button group; B/I/U as a toggle
1442
+ group mapped to font-weight / font-style / text-decoration. */}
1443
+ {row('text-align', iconseg('text-align', TEXTALIGN_OPTS))}
1444
+ {row('font-style', textStyleToggle(), provOf('font-style'))}
1445
+ {/* Stage B (Task B4) — promoted typography knobs (was DDR-104 OUT-list). */}
1446
+ {row('text-transform', csel('text-transform', CSS_TEXT_TRANSFORM))}
1447
+ {row('white-space', csel('white-space', CSS_WHITE_SPACE))}
1448
+ </>
1449
+ )}
1450
+
1451
+ {sec(
1452
+ 'Spacing',
1453
+ <>
1454
+ <div className="st-cp-box" aria-label="margin and padding">
1455
+ <span className="st-cp-boxtag st-cp-boxtag--m">
1456
+ {prov(provOf('margin-top'))}margin
1457
+ </span>
1458
+ {side('margin-top', 'margin')}
1459
+ {side('margin-right', 'margin')}
1460
+ {side('margin-bottom', 'margin')}
1461
+ {side('margin-left', 'margin')}
1462
+ <div className="st-cp-boxpad">
1463
+ <span className="st-cp-boxtag st-cp-boxtag--p">
1464
+ {prov(provOf('padding-top'))}padding
1465
+ </span>
1466
+ {side('padding-top', 'padding')}
1467
+ {side('padding-right', 'padding')}
1468
+ {side('padding-bottom', 'padding')}
1469
+ {side('padding-left', 'padding')}
1470
+ <div className="st-cp-boxcore">
1471
+ {/* handoff — prefer the AUTHORED size (updates live as you edit
1472
+ width/height); el.bounds is stale until the canvas re-measures. */}
1473
+ {Math.round(Number.parseFloat(authored.width) || el.bounds?.w || 0)} × {Math.round(Number.parseFloat(authored.height) || el.bounds?.h || 0)}
1474
+ </div>
1475
+ </div>
1476
+ </div>
1477
+ </>
1478
+ )}
1479
+
1480
+ {sec(
1481
+ 'Size',
1482
+ <>
1483
+ {/* Stage M1 — per-axis Fixed / Hug / Fill sizing mode (Figma parity). The
1484
+ Fixed case leaves the numeric width/height knobs below in control. */}
1485
+ <div className="st-cp-modes">
1486
+ {sizeModeSeg('width')}
1487
+ {sizeModeSeg('height')}
1488
+ </div>
1489
+ {row('width', num('width'))}
1490
+ {row('height', num('height'))}
1491
+ {row('min-width', num('min-width'))}
1492
+ {row('max-width', num('max-width'))}
1493
+ {row('min-height', num('min-height'))}
1494
+ {row('max-height', num('max-height'))}
1495
+ {row('overflow', iconseg('overflow', OVERFLOW_OPTS))}
1496
+ {/* Stage M1 — flex-CHILD controls, only meaningful when the parent is a
1497
+ flex container. align-self is the cross-axis override; flex-grow/shrink/
1498
+ basis are the main-axis behavior the Fill mode writes for you. */}
1499
+ {parentIsFlexChild ? (
1500
+ <>
1501
+ <div className="st-cp-subhd">In flex parent</div>
1502
+ {row('align-self', csel('align-self', CSS_ALIGN_SELF))}
1503
+ {row('flex-grow', num('flex-grow', null, { unitless: true }))}
1504
+ {row('flex-shrink', num('flex-shrink', null, { unitless: true }))}
1505
+ {row('flex-basis', num('flex-basis'))}
1506
+ </>
1507
+ ) : null}
1508
+ </>
1509
+ )}
1510
+
1511
+ {/* Stage B (Task B5) — Media framing (gate/body pulled into mediaGate()/
1512
+ mediaBody() above, DDR-171, so Designer mode's "Media" cluster
1513
+ reuses the identical content). */}
1514
+ {(() => {
1515
+ const { showMedia, canReplace } = mediaGate();
1516
+ return showMedia ? sec('Media', mediaBody(canReplace)) : null;
1517
+ })()}
1518
+
1519
+ {sec(
1520
+ 'Appearance',
1521
+ <>
1522
+ {row('background-color', color('background-color'))}
1523
+ {row('border-radius', radiusControl(), provOf('border-radius'))}
1524
+ {row('border', borderControl(), provOf('border-width'))}
1525
+ {row('box-shadow', tok('box-shadow', 'shadow') || text('box-shadow'))}
1526
+ {/* DDR-171 — blur + blend, real Advanced-mode rows (not Designer-exclusive);
1527
+ also power Designer mode's "Effects" cluster. */}
1528
+ {row('filter', blurControl(), provOf('filter'))}
1529
+ {row('mix-blend-mode', csel('mix-blend-mode', CSS_BLEND_MODES))}
1530
+ {row('opacity', opacityControl())}
1531
+ {/* Stage B (Task B4) — transform as a free-value row (mirrors box-shadow). */}
1532
+ {row('rotation', rotationControl(), provOf('transform'))}
1533
+ {row('transform', text('transform'))}
1534
+ {row('transform-origin', text('transform-origin'))}
1535
+ </>
1536
+ )}
1537
+
1538
+ {/* #5 — the idle/saved status now lives in each row's leading dot (a glow),
1539
+ so the panel no longer carries a confusing standing 'written to source'
1540
+ line. Only a hard ERROR surfaces here, with the failing property. */}
1541
+ {(() => {
1542
+ const err = Object.entries(status).find(
1543
+ ([, s]) => typeof s === 'string' && s.startsWith('err:')
1544
+ );
1545
+ return err ? (
1546
+ <div className="st-cp-save is-err" role="status">
1547
+ <StIcon name="x" size={12} />
1548
+ {err[0]}: {err[1].slice(4)}
1549
+ </div>
1550
+ ) : null;
1551
+ })()}
1552
+
1553
+ {sec(
1554
+ 'Advanced',
1555
+ <div className="st-cp-advbody">
1556
+ {customStyleRows.length ? (
1557
+ <>
1558
+ <div className="st-cp-advgrp">Custom CSS properties</div>
1559
+ {customStyleRows.map(([p, v]) => (
1560
+ <div className="st-cp-kv" key={`cs:${p}`}>
1561
+ <input
1562
+ className="st-cp-fin st-cp-fin--ro"
1563
+ readOnly
1564
+ value={p}
1565
+ aria-label={`custom property ${p} name`}
1566
+ />
1567
+ <input
1568
+ className="st-cp-fin"
1569
+ key={`cs:${p}:${v}`}
1570
+ defaultValue={v}
1571
+ aria-label={`${p} value`}
1572
+ onKeyDown={(e) => {
1573
+ if (e.key === 'Enter') e.currentTarget.blur();
1574
+ }}
1575
+ onBlur={(e) => commitCustom(p, e.currentTarget.value)}
1576
+ />
1577
+ <button
1578
+ type="button"
1579
+ className="st-cp-kvx"
1580
+ aria-label={`remove ${p}`}
1581
+ title="remove"
1582
+ onClick={() => resetCustom(p)}
1583
+ >
1584
+ <StIcon name="x" size={11} />
1585
+ </button>
1586
+ </div>
1587
+ ))}
1588
+ </>
1589
+ ) : null}
1590
+ <div className="st-cp-advgrp">Add CSS property</div>
1591
+ <RawKnob commit={commitCustom} />
1592
+ <div className="st-cp-note">applied as-is — not token-bound</div>
1593
+ {attrRows.length ? (
1594
+ <>
1595
+ <div className="st-cp-advgrp">Custom HTML attributes</div>
1596
+ {attrRows.map(([a, v]) => (
1597
+ <div className="st-cp-kv" key={`at:${a}`}>
1598
+ <input
1599
+ className="st-cp-fin st-cp-fin--ro"
1600
+ readOnly
1601
+ value={a}
1602
+ aria-label={`attribute ${a} name`}
1603
+ />
1604
+ <input
1605
+ className="st-cp-fin"
1606
+ key={`at:${a}:${v}`}
1607
+ defaultValue={v}
1608
+ aria-label={`${a} value`}
1609
+ onKeyDown={(e) => {
1610
+ if (e.key === 'Enter') e.currentTarget.blur();
1611
+ }}
1612
+ onBlur={(e) => commitAttr(a, e.currentTarget.value)}
1613
+ />
1614
+ <button
1615
+ type="button"
1616
+ className="st-cp-kvx"
1617
+ aria-label={`remove ${a}`}
1618
+ title="remove"
1619
+ onClick={() => resetAttr(a)}
1620
+ >
1621
+ <StIcon name="x" size={11} />
1622
+ </button>
1623
+ </div>
1624
+ ))}
1625
+ </>
1626
+ ) : null}
1627
+ <div className="st-cp-advgrp">Add HTML attribute</div>
1628
+ <AttrKnob commit={commitAttr} />
1629
+ </div>
1630
+ )}
1631
+ </>
1632
+ )}
1633
+
1634
+ <div className="st-cp-legend">
1635
+ <span>
1636
+ <i className="st-cp-prov st-cp-prov--bound" aria-hidden="true" />
1637
+ token
1638
+ </span>
1639
+ <span>
1640
+ <i className="st-cp-prov st-cp-prov--raw" aria-hidden="true" />
1641
+ override
1642
+ </span>
1643
+ <span>
1644
+ <i className="st-cp-prov st-cp-prov--inherit" aria-hidden="true" />
1645
+ inherited
1646
+ </span>
1647
+ </div>
1648
+ </div>
1649
+ );
1650
+ }
1651
+
1652
+ // Custom CSS property hatch — writes an arbitrary `property: value` to inline style.
1653
+ export function RawKnob({ commit }) {
1654
+ const [prop, setProp] = useState('');
1655
+ const [val, setVal] = useState('');
1656
+ const submit = () => {
1657
+ if (prop.trim() && val.trim()) {
1658
+ commit(prop.trim(), val);
1659
+ setProp('');
1660
+ setVal('');
1661
+ }
1662
+ };
1663
+ return (
1664
+ <div className="st-cp-kv">
1665
+ <input
1666
+ className="st-cp-fin"
1667
+ aria-label="custom property name"
1668
+ placeholder="property"
1669
+ value={prop}
1670
+ onChange={(e) => setProp(e.target.value)}
1671
+ />
1672
+ <input
1673
+ className="st-cp-fin"
1674
+ aria-label="custom property value"
1675
+ placeholder="value"
1676
+ value={val}
1677
+ onChange={(e) => setVal(e.target.value)}
1678
+ onKeyDown={(e) => {
1679
+ if (e.key === 'Enter') submit();
1680
+ }}
1681
+ onBlur={submit}
1682
+ />
1683
+ </div>
1684
+ );
1685
+ }
1686
+
1687
+ // Custom HTML attribute hatch — writes a plain JSX attribute (data-*, aria-*, …).
1688
+ export function AttrKnob({ commit }) {
1689
+ const [attr, setAttr] = useState('');
1690
+ const [val, setVal] = useState('');
1691
+ const submit = () => {
1692
+ if (attr.trim() && val.trim()) {
1693
+ commit(attr.trim(), val);
1694
+ setAttr('');
1695
+ setVal('');
1696
+ }
1697
+ };
1698
+ return (
1699
+ <div className="st-cp-kv">
1700
+ <input
1701
+ className="st-cp-fin"
1702
+ aria-label="custom attribute name"
1703
+ placeholder="data-…"
1704
+ value={attr}
1705
+ onChange={(e) => setAttr(e.target.value)}
1706
+ />
1707
+ <input
1708
+ className="st-cp-fin"
1709
+ aria-label="custom attribute value"
1710
+ placeholder="value"
1711
+ value={val}
1712
+ onChange={(e) => setVal(e.target.value)}
1713
+ onKeyDown={(e) => {
1714
+ if (e.key === 'Enter') submit();
1715
+ }}
1716
+ onBlur={submit}
1717
+ />
1718
+ </div>
1719
+ );
1720
+ }