@luci-dev/capture 0.7.1 → 0.8.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 (44) hide show
  1. package/dist/component.d.ts.map +1 -1
  2. package/dist/component.js +35 -13
  3. package/dist/component.js.map +1 -1
  4. package/dist/dom.js +3 -3
  5. package/dist/dom.js.map +1 -1
  6. package/dist/layout.js +1 -1
  7. package/dist/layout.js.map +1 -1
  8. package/dist/luci-capture.js +4769 -1470
  9. package/dist/ui/devSettings.d.ts.map +1 -1
  10. package/dist/ui/devSettings.js +5 -9
  11. package/dist/ui/devSettings.js.map +1 -1
  12. package/dist/ui/figmaPanel.d.ts +80 -0
  13. package/dist/ui/figmaPanel.d.ts.map +1 -0
  14. package/dist/ui/figmaPanel.js +290 -0
  15. package/dist/ui/figmaPanel.js.map +1 -0
  16. package/dist/ui/index.d.ts +3 -2
  17. package/dist/ui/index.d.ts.map +1 -1
  18. package/dist/ui/index.js +2 -1
  19. package/dist/ui/index.js.map +1 -1
  20. package/dist/ui/mount.d.ts +7 -1
  21. package/dist/ui/mount.d.ts.map +1 -1
  22. package/dist/ui/mount.js +11 -2
  23. package/dist/ui/mount.js.map +1 -1
  24. package/dist/ui/onSpec.d.ts +34 -1
  25. package/dist/ui/onSpec.d.ts.map +1 -1
  26. package/dist/ui/onSpec.js +313 -30
  27. package/dist/ui/onSpec.js.map +1 -1
  28. package/dist/ui/specWatcher.d.ts +31 -10
  29. package/dist/ui/specWatcher.d.ts.map +1 -1
  30. package/dist/ui/specWatcher.js +825 -146
  31. package/dist/ui/specWatcher.js.map +1 -1
  32. package/dist/ui/styles.d.ts +3 -3
  33. package/dist/ui/styles.d.ts.map +1 -1
  34. package/dist/ui/styles.js +79 -12
  35. package/dist/ui/styles.js.map +1 -1
  36. package/dist/ui/toolbar.d.ts +18 -0
  37. package/dist/ui/toolbar.d.ts.map +1 -1
  38. package/dist/ui/toolbar.js +95 -17
  39. package/dist/ui/toolbar.js.map +1 -1
  40. package/dist/ui/tools.d.ts +6 -1
  41. package/dist/ui/tools.d.ts.map +1 -1
  42. package/dist/ui/tools.js +18 -2
  43. package/dist/ui/tools.js.map +1 -1
  44. package/package.json +3 -3
package/dist/ui/onSpec.js CHANGED
@@ -12,10 +12,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "preact/jsx-ru
12
12
  */
13
13
  import { h, render } from 'preact';
14
14
  import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
15
- import { SPEC_MATCHES_PHRASE, SPEC_STATE_LABELS, formatDriftDetail, formatRuleOrigin, formatSpecReport, formatSpecSummary, getRuleChallengeStatus } from '@luci-dev/format/capture';
15
+ import { SPEC_MATCHES_PHRASE, SPEC_REASON_MESSAGES, SPEC_STATE_LABELS, formatDriftDetail, formatRuleOrigin, formatSpecReport, formatSpecSummary, formatWidthNotCheckedNote, getRuleChallengeStatus } from '@luci-dev/format/capture';
16
16
  import { REVIEWER_ROLES } from '@luci-dev/format/feedback';
17
- import { Icon, IconCheck, IconClose, IconCopy, IconHide, IconInfo, IconOnSpec, IconReset, IconSuccess, IconWarning, UI_CSS, loadFonts } from '@luci-dev/ui';
17
+ import { Icon, IconCheck, IconClose, IconCopy, IconFigmaDiff, IconHide, IconImport, IconInfo, IconLocalOverride, IconOnSpec, IconReset, IconSelect, IconSuccess, IconWarning, UI_CSS, loadFonts } from '@luci-dev/ui';
18
18
  import { LUCI_UI_ATTRIBUTE } from '../dom.js';
19
+ import { FigmaPanel } from './figmaPanel.js';
19
20
  import { ON_SPEC_CSS } from './styles.js';
20
21
  import { readUiPrefs, UI_PREFS_EVENT } from './theme.js';
21
22
  export const ON_SPEC_TAG = 'luci-on-spec';
@@ -30,6 +31,7 @@ function StateIcon({ state, earned }) {
30
31
  return _jsx(Icon, { icon: IconInfo, size: "compact" });
31
32
  }
32
33
  const normalizeRuleKey = (ruleFile) => ruleFile.replace(/^\.luci\/design\//, '').replace(/^\/+/, '');
34
+ const badgeLabel = (comp) => comp.reason === 'width-not-checked' ? 'Not checked' : SPEC_STATE_LABELS[comp.state];
33
35
  function findLiveElement(doc, selector) {
34
36
  if (!selector)
35
37
  return null;
@@ -70,8 +72,9 @@ function OnSpecView({ doc, store, callbacks }) {
70
72
  useEffect(() => store.subscribe(() => setSnap(store.get())), [store]);
71
73
  const { data, open, revealReq } = snap;
72
74
  const setOpen = (v) => store.setOpen(v);
73
- const { state, rulesMeta, report, settings, profile } = data;
75
+ const { state, rulesMeta, report, settings, profile, figma } = data;
74
76
  const components = state.components;
77
+ const [panelTab, setPanelTab] = useState('on-spec');
75
78
  const [side, setSide] = useState(() => (readUiPrefs(doc).dock === 'left' ? 'right' : 'left'));
76
79
  const [copied, setCopied] = useState(false);
77
80
  const [busy, setBusy] = useState(false);
@@ -80,8 +83,21 @@ function OnSpecView({ doc, store, callbacks }) {
80
83
  const [errorMsg, setErrorMsg] = useState(null);
81
84
  const [whyOpenId, setWhyOpenId] = useState(null);
82
85
  const [activeAction, setActiveAction] = useState(null);
86
+ const [chosenFigmaLayerKey, setChosenFigmaLayerKey] = useState('');
87
+ const [addedUndo, setAddedUndo] = useState(null);
88
+ const addedUndoTimerRef = useRef(null);
89
+ const [removedUndo, setRemovedUndo] = useState(null);
83
90
  const [excuseReason, setExcuseReason] = useState('');
84
91
  const [sendBackNote, setSendBackNote] = useState('');
92
+ const [overrideMode, setOverrideMode] = useState(false);
93
+ const [overridePart, setOverridePart] = useState('container');
94
+ const [overrideProp, setOverrideProp] = useState('padding');
95
+ const [overrideVal, setOverrideVal] = useState('');
96
+ const [overrideReason, setOverrideReason] = useState('');
97
+ const [copiedFigmaLink, setCopiedFigmaLink] = useState(false);
98
+ const [figmaPointing, setFigmaPointing] = useState(false);
99
+ const [pointingMatch, setPointingMatch] = useState(null);
100
+ const anyPointing = figmaPointing || pointingMatch !== null;
85
101
  const [pendingRole, setPendingRole] = useState(null);
86
102
  const [chosenRole, setChosenRole] = useState(profile.role);
87
103
  // On-page Annotate-style pins: calm by default, auto-shown on drift, panel open, or after save
@@ -182,6 +198,8 @@ function OnSpecView({ doc, store, callbacks }) {
182
198
  const onKey = (e) => {
183
199
  if (e.key !== 'Escape')
184
200
  return;
201
+ if (anyPointing)
202
+ return;
185
203
  if (selectedPinId) {
186
204
  setSelectedPinId(null);
187
205
  return;
@@ -191,7 +209,7 @@ function OnSpecView({ doc, store, callbacks }) {
191
209
  };
192
210
  doc.addEventListener('keydown', onKey, true);
193
211
  return () => doc.removeEventListener('keydown', onKey, true);
194
- }, [doc, selectedPinId, open, store]);
212
+ }, [doc, selectedPinId, open, anyPointing, store]);
195
213
  useEffect(() => {
196
214
  if (!settings.hoverBadge || !callbacks.verdictForElement) {
197
215
  setHoverInfo(null);
@@ -211,6 +229,7 @@ function OnSpecView({ doc, store, callbacks }) {
211
229
  const r = target.getBoundingClientRect();
212
230
  setHoverInfo({
213
231
  state: verdict.state,
232
+ ...(verdict.reason ? { reason: verdict.reason } : {}),
214
233
  name: verdict.name,
215
234
  x: Math.max(8, Math.min(r.left, (win.innerWidth || 1200) - 180)),
216
235
  y: Math.max(8, r.top - 28)
@@ -243,6 +262,7 @@ function OnSpecView({ doc, store, callbacks }) {
243
262
  const selectedPin = selectedPinId ? pinById.get(selectedPinId) ?? null : null;
244
263
  const activeHighlight = (hoveredId ? pinById.get(hoveredId) : null) ?? selectedPin ?? null;
245
264
  const withRoleCheck = async (label, run) => {
265
+ dismissRemovedUndo();
246
266
  if (!profile.saved) {
247
267
  setPendingRole({ label, run });
248
268
  return;
@@ -280,10 +300,72 @@ function OnSpecView({ doc, store, callbacks }) {
280
300
  useEffect(() => () => {
281
301
  if (checkDoneTimerRef.current)
282
302
  clearTimeout(checkDoneTimerRef.current);
303
+ if (addedUndoTimerRef.current)
304
+ clearTimeout(addedUndoTimerRef.current);
283
305
  }, []);
306
+ const dismissRemovedUndo = () => {
307
+ setRemovedUndo(null);
308
+ };
309
+ const showRuleRemovedUndo = (undo) => {
310
+ setRemovedUndo(undo);
311
+ };
312
+ const matchesRemovedUndo = (comp) => Boolean(removedUndo && (removedUndo.componentId
313
+ ? removedUndo.componentId === comp.id
314
+ : Boolean(removedUndo.selector && removedUndo.selector === comp.selector)));
315
+ const undoRemovedRule = async () => {
316
+ if (!removedUndo || !callbacks.onRestoreRule)
317
+ return;
318
+ const target = removedUndo;
319
+ dismissRemovedUndo();
320
+ setBusy(true);
321
+ setErrorMsg(null);
322
+ try {
323
+ await callbacks.onRestoreRule(target);
324
+ }
325
+ catch (err) {
326
+ setErrorMsg(err instanceof Error ? err.message : String(err));
327
+ }
328
+ finally {
329
+ setBusy(false);
330
+ }
331
+ };
332
+ const renderRemovedUndoBanner = () => (removedUndo ? (_jsxs("div", { class: "status-msg info os-status-banner", "data-part": "rule-removed-undo", role: "status", children: [_jsxs("div", { class: "os-on-spec-line", children: [_jsx(Icon, { icon: IconInfo, size: "compact" }), _jsxs("span", { class: "status-detail", children: [_jsx("strong", { children: "Rule removed" }), " \u00B7"] }), _jsx("button", { type: "button", class: "btn-link btn-sm", "data-action": "undo-removed-rule", disabled: busy || !callbacks.onRestoreRule, onClick: () => void undoRemovedRule(), children: "Undo" })] }), _jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "dismiss-removed-undo", "aria-label": "Dismiss", title: "Dismiss", onClick: dismissRemovedUndo, children: _jsx(Icon, { icon: IconClose, size: "compact" }) })] })) : null);
333
+ const showRuleAddedUndo = (id, selector, ruleFile) => {
334
+ if (addedUndoTimerRef.current)
335
+ clearTimeout(addedUndoTimerRef.current);
336
+ setAddedUndo({ id, selector, ruleFile });
337
+ addedUndoTimerRef.current = setTimeout(() => {
338
+ addedUndoTimerRef.current = null;
339
+ setAddedUndo(null);
340
+ }, 10_000);
341
+ };
342
+ const undoAddedRule = async () => {
343
+ if (!addedUndo || !callbacks.onRemoveRule)
344
+ return;
345
+ dismissRemovedUndo();
346
+ if (addedUndoTimerRef.current) {
347
+ clearTimeout(addedUndoTimerRef.current);
348
+ addedUndoTimerRef.current = null;
349
+ }
350
+ const target = addedUndo;
351
+ setAddedUndo(null);
352
+ setBusy(true);
353
+ setErrorMsg(null);
354
+ try {
355
+ await callbacks.onRemoveRule({ ruleFile: target.ruleFile, selector: target.selector });
356
+ }
357
+ catch (err) {
358
+ setErrorMsg(err instanceof Error ? err.message : String(err));
359
+ }
360
+ finally {
361
+ setBusy(false);
362
+ }
363
+ };
364
+ const renderAddedUndoBanner = () => (addedUndo ? (_jsx("div", { class: "os-inline-box", "data-part": "rule-added-undo", role: "status", children: _jsxs("div", { class: "os-on-spec-line", children: [_jsxs("span", { class: "os-sub", children: [_jsx("strong", { children: "Rule added" }), " \u00B7"] }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "undo-added-rule", disabled: busy || !callbacks.onRemoveRule, onClick: () => void undoAddedRule(), children: "Undo" })] }) })) : null);
284
365
  const runCheckNow = async () => {
285
366
  if (busy || checkState === 'checking')
286
367
  return;
368
+ dismissRemovedUndo();
287
369
  if (checkDoneTimerRef.current) {
288
370
  clearTimeout(checkDoneTimerRef.current);
289
371
  checkDoneTimerRef.current = null;
@@ -311,6 +393,7 @@ function OnSpecView({ doc, store, callbacks }) {
311
393
  }
312
394
  };
313
395
  const copyReport = async () => {
396
+ dismissRemovedUndo();
314
397
  const md = report || formatSpecReport(state, rulesMeta);
315
398
  try {
316
399
  await win.navigator.clipboard?.writeText(md);
@@ -335,35 +418,177 @@ function OnSpecView({ doc, store, callbacks }) {
335
418
  setSelectedPinId(comp.id);
336
419
  };
337
420
  const renderRolePrompt = () => (pendingRole ? (_jsxs("div", { class: "os-role-prompt", "data-part": "role-prompt", children: [_jsx("strong", { children: "Choose your role once" }), _jsxs("p", { class: "os-sub", children: ["Saved locally in ", _jsx("code", { children: "~/.luci/profile.json" }), " (roles only, never personal names). Used when you Excuse or Update a rule."] }), _jsx("div", { class: "os-role-choices", role: "radiogroup", "aria-label": "Your role", children: REVIEWER_ROLES.map(r => (_jsx("button", { type: "button", class: `btn btn-sm ${chosenRole === r ? 'btn-primary' : 'btn-secondary'}`, "data-role-choice": r, "aria-pressed": chosenRole === r, onClick: () => setChosenRole(r), children: r }, r))) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn btn-primary btn-sm", "data-action": "role-confirm", disabled: busy, onClick: () => void confirmRoleAndContinue(), children: "Save role & continue" }), _jsx("button", { type: "button", class: "btn btn-ghost btn-sm", onClick: () => setPendingRole(null), children: "Cancel" })] })] })) : null);
421
+ const openAction = (next) => {
422
+ dismissRemovedUndo();
423
+ setActiveAction(next);
424
+ };
425
+ const startChangeMatchPicker = (candidate) => {
426
+ if (!callbacks.onStartFigmaPicker || !callbacks.onChangeFigmaMatch)
427
+ return;
428
+ dismissRemovedUndo();
429
+ const role = profile.role;
430
+ const hint = figma?.layerSizes?.[candidate.layerKey];
431
+ const label = hint?.label ?? candidate.label;
432
+ const sizes = hint?.sizes ?? [];
433
+ setSelectedPinId(null);
434
+ setPointingMatch({ label });
435
+ callbacks.onStartFigmaPicker?.({
436
+ label,
437
+ sizes,
438
+ onConfirm: async (selector, match) => {
439
+ setPointingMatch(null);
440
+ setBusy(true);
441
+ setErrorMsg(null);
442
+ try {
443
+ const sel = match?.selector || selector || undefined;
444
+ const comp = match?.component || undefined;
445
+ await callbacks.onChangeFigmaMatch?.({
446
+ layerKey: candidate.layerKey,
447
+ ...(comp ? { component: comp } : {}),
448
+ ...(sel ? { selector: sel } : {}),
449
+ role
450
+ });
451
+ }
452
+ catch (err) {
453
+ setErrorMsg(err instanceof Error ? err.message : String(err));
454
+ }
455
+ finally {
456
+ setBusy(false);
457
+ }
458
+ },
459
+ onCancel: () => setPointingMatch(null)
460
+ });
461
+ };
338
462
  const renderComponentBody = (comp, snippet, mode) => {
339
463
  const ruleKey = comp.ruleFile ? normalizeRuleKey(comp.ruleFile) : null;
340
464
  const meta = ruleKey ? rulesMeta[ruleKey] ?? null : null;
465
+ const figmaMatched = ruleKey ? figma?.status.matchedRules.find(m => normalizeRuleKey(m.ruleFile) === ruleKey) ?? null : null;
466
+ const candidateRuleKey = comp.matchedRuleFile ? normalizeRuleKey(comp.matchedRuleFile) : null;
467
+ const isAmbiguous = comp.state === 'no-rule' && comp.reason === 'ambiguous-rule';
468
+ const hasWaitingFigmaQuestions = (figma?.questions.length ?? 0) > 0;
469
+ const normLabel = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '');
470
+ const compNorm = normLabel(comp.name);
471
+ const figmaRules = figma?.status.matchedRules ?? [];
472
+ const figmaCandidate = !figmaMatched && figma
473
+ ? figmaRules.find(m => (candidateRuleKey && normalizeRuleKey(m.ruleFile) === candidateRuleKey) || (Boolean(m.selector) && m.selector === comp.selector)) ?? (isAmbiguous
474
+ ? figmaRules.find(m => normLabel(m.component ?? '') === compNorm || normLabel(m.label) === compNorm) ?? null
475
+ : null)
476
+ : null;
477
+ const pendingNeedsMatch = figma?.pendingDiff?.items.filter(i => i.decision === 'pending' && i.group === 'needs-match') ?? [];
478
+ const waitingFigmaRule = figmaCandidate && (figmaCandidate.status === 'orphaned' || figmaCandidate.status === 'unmatched')
479
+ ? figmaCandidate
480
+ : figmaRules.find(m => (m.status === 'orphaned' || m.status === 'unmatched') && ((candidateRuleKey && normalizeRuleKey(m.ruleFile) === candidateRuleKey) ||
481
+ (Boolean(m.selector) && m.selector === comp.selector) ||
482
+ (compNorm.length > 0 && (normLabel(m.component ?? '') === compNorm || normLabel(m.label) === compNorm)))) ?? null;
483
+ const isWidthNotChecked = comp.reason === 'width-not-checked';
484
+ const isLowConfidenceFigma = comp.state === 'no-rule' && comp.reason === 'low-confidence-match' && figmaCandidate !== null;
485
+ const waitingLayerKey = waitingFigmaRule?.layerKey ?? null;
486
+ const figmaLayerIsMatched = figmaCandidate !== null && figmaCandidate.status === 'matched';
487
+ const hasRowWaitingFigma = Boolean(waitingFigmaRule ||
488
+ (!figmaLayerIsMatched && (pendingNeedsMatch.some(i => (i.ruleFile && candidateRuleKey && normalizeRuleKey(i.ruleFile) === candidateRuleKey) ||
489
+ (compNorm.length >= 3 && normLabel(i.title.replace(/^Needs a match:\s*/i, '')) === compNorm)) ||
490
+ (figma?.questions ?? []).some(q => (waitingLayerKey && q.targetId.split(',').includes(waitingLayerKey)) ||
491
+ (compNorm.length >= 3 && normLabel(q.prompt).includes(compNorm))))));
492
+ const showOpenFigmaQuestions = comp.state === 'no-rule' && !isLowConfidenceFigma && (hasRowWaitingFigma || (isAmbiguous && hasWaitingFigmaQuestions));
493
+ const noRuleReasonText = comp.note
494
+ || (comp.reason && comp.reason !== 'excused' ? SPEC_REASON_MESSAGES[comp.reason] : 'No saved rule matches this component.');
341
495
  const challenge = getRuleChallengeStatus(meta);
342
496
  const isWhyOpen = whyOpenId === comp.id;
343
497
  const isEditingThis = activeAction?.id === comp.id;
344
498
  const showSnippet = snippet && snippet.toLowerCase() !== comp.name.toLowerCase();
345
499
  const hasLiveEl = pinById.has(comp.id);
346
- return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "os-row-top", children: [_jsx("div", { class: "os-comp-meta", children: mode === 'list' && hasLiveEl ? (_jsxs("button", { type: "button", class: "os-comp-link", "data-action": "locate-component", title: `Show on page (${comp.selector})`, onClick: () => locateComponent(comp), children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) : (_jsxs("div", { class: "os-comp-heading", title: comp.selector, children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) }), _jsxs("div", { class: "os-row-right", children: [_jsxs("span", { class: "os-badge", "data-part": "on-spec-state", "data-state": comp.state, children: [_jsx(StateIcon, { state: comp.state, earned: earnedIds.has(comp.id) }), _jsx("span", { children: SPEC_STATE_LABELS[comp.state] })] }), mode === 'popover' && (_jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-popover", "aria-label": "Close component check", onClick: () => setSelectedPinId(null), children: _jsx(Icon, { icon: IconClose, size: "compact" }) }))] })] }), comp.state === 'on-spec' && (_jsxs("div", { class: "os-on-spec-line", children: [_jsx("p", { class: "os-sub", children: SPEC_MATCHES_PHRASE }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }))] })), comp.state === 'drift' && (_jsxs(_Fragment, { children: [comp.needsHuman && (_jsxs("p", { class: "os-sub", "data-part": "needs-human-note", children: [_jsx("strong", { children: "Needs you" }), " \u2014 2 automatic fix rounds reached. Choose Excuse, Update rule, or Send back."] })), comp.differences.length > 0 && (_jsxs("ul", { class: "os-diffs", children: [comp.differences.slice(0, 4).map((d, i) => (_jsx("li", { children: formatDriftDetail(d) }, i))), comp.differences.length > 4 && (_jsxs("li", { children: ["+", comp.differences.length - 4, " more differences"] }))] })), _jsxs("div", { class: "os-actions", "data-part": "decision-bar", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "excuse-open", title: "Allow this drift with a required reason (records your role and clears the gate for this item)", onClick: () => {
347
- setActiveAction({ id: comp.id, kind: 'excuse' });
500
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { class: "os-row-top", children: [_jsx("div", { class: "os-comp-meta", children: mode === 'list' && hasLiveEl ? (_jsxs("button", { type: "button", class: "os-comp-link", "data-action": "locate-component", title: `Show on page (${comp.selector})`, onClick: () => locateComponent(comp), children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) : (_jsxs("div", { class: "os-comp-heading", title: comp.selector, children: [_jsx("span", { class: "os-comp-name", children: comp.name }), showSnippet && _jsx("span", { class: "os-comp-snippet", children: snippet })] })) }), _jsxs("div", { class: "os-row-right", children: [meta?.origin === 'figma' && (_jsxs("span", { class: "fg-chip", "data-kind": "imported", children: [_jsx(Icon, { icon: IconImport, size: "compact" }), _jsx("span", { children: "Imported from Figma" })] })), figmaMatched && figmaMatched.overrides.length > 0 && (_jsxs("span", { class: "fg-chip", "data-kind": "local-override", children: [_jsx(Icon, { icon: IconLocalOverride, size: "compact" }), _jsx("span", { children: "Local override" })] })), _jsxs("span", { class: "os-badge", "data-part": "on-spec-state", "data-state": comp.state, children: [_jsx(StateIcon, { state: comp.state, earned: earnedIds.has(comp.id) }), _jsx("span", { children: badgeLabel(comp) })] }), mode === 'popover' && (_jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-popover", "aria-label": "Close component check", onClick: () => setSelectedPinId(null), children: _jsx(Icon, { icon: IconClose, size: "compact" }) }))] })] }), comp.state === 'on-spec' && (_jsxs(_Fragment, { children: [_jsxs("div", { class: "os-on-spec-line", children: [_jsx("p", { class: "os-sub", children: SPEC_MATCHES_PHRASE }), comp.ruleFile && (_jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => {
501
+ dismissRemovedUndo();
502
+ setWhyOpenId(isWhyOpen ? null : comp.id);
503
+ }, children: "Why this rule?" }), callbacks.onRemoveRule && (_jsx("button", { type: "button", class: "btn-danger-text btn-sm", "data-action": "remove-rule-open", title: "Delete this rule file and its history entry", disabled: busy, onClick: () => openAction({ id: comp.id, kind: 'remove' }), children: "Remove rule" }))] }))] }), comp.variant && _jsxs("p", { class: "os-sub", "data-part": "variant-checked-as", children: ["Checked as ", comp.variant] }), comp.widthsChecked.length > 0 && (_jsxs("p", { class: "os-sub", "data-part": "widths-checked", children: ["Checked at ", comp.widthsChecked.map(w => `${w}px`).join(', ')] })), comp.note && _jsx("p", { class: "os-sub", "data-part": "width-not-checked-note", children: comp.note })] })), comp.state === 'drift' && (_jsxs(_Fragment, { children: [comp.variant && _jsxs("p", { class: "os-sub", "data-part": "variant-checked-as", children: ["Checked as ", comp.variant] }), comp.widthsChecked.length > 0 && (_jsxs("p", { class: "os-sub", "data-part": "widths-checked", children: ["Checked at ", comp.widthsChecked.map(w => `${w}px`).join(', ')] })), comp.needsHuman && (_jsxs("p", { class: "os-sub", "data-part": "needs-human-note", children: [_jsx("strong", { children: "Needs you" }), ": 2 automatic fix rounds reached. Choose Excuse, Update rule, or Send back."] })), comp.differences.length > 0 && (_jsxs("ul", { class: "os-diffs", children: [comp.differences.slice(0, 4).map((d, i) => (_jsx("li", { children: formatDriftDetail(d) }, i))), comp.differences.length > 4 && (_jsxs("li", { children: ["+", comp.differences.length - 4, " more differences"] }))] })), comp.note && _jsx("p", { class: "os-sub", "data-part": "width-not-checked-note", children: comp.note }), _jsxs("div", { class: "os-actions", "data-part": "decision-bar", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "excuse-open", title: "Allow this drift with a required reason (records your role and clears the gate for this item)", onClick: () => {
504
+ openAction({ id: comp.id, kind: 'excuse' });
348
505
  setExcuseReason('');
349
- }, children: "Excuse" }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "update-rule-open", title: "Replace the saved .design.md rule with this component's current live styles", onClick: () => setActiveAction({ id: comp.id, kind: 'update' }), children: "Update rule" })), _jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "send-back-open", title: "Queue a Feedback fix note for your agent and reset its 2 automatic fix rounds", onClick: () => {
350
- setActiveAction({ id: comp.id, kind: 'send-back' });
506
+ }, children: "Excuse" }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "update-rule-open", title: "Replace the saved .design.md rule with this component's current live styles", onClick: () => {
507
+ const firstDiff = comp.differences[0];
508
+ setOverrideMode(false);
509
+ setCopiedFigmaLink(false);
510
+ setOverridePart(firstDiff?.part || 'container');
511
+ setOverrideProp(firstDiff?.property || 'padding');
512
+ setOverrideVal(firstDiff?.actual || '');
513
+ setOverrideReason('');
514
+ openAction({ id: comp.id, kind: 'update' });
515
+ }, children: "Update rule" })), _jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "send-back-open", title: "Queue a Feedback fix note for your agent and reset its 2 automatic fix rounds", onClick: () => {
516
+ openAction({ id: comp.id, kind: 'send-back' });
351
517
  setSendBackNote('');
352
- }, children: "Send back" }), comp.ruleFile && (_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }))] })] })), comp.state === 'excused' && (_jsxs(_Fragment, { children: [_jsx("p", { class: "os-sub", "data-part": "excuse-reason", children: comp.excuse ? `${comp.excuse.reason} — ${comp.excuse.role}, ${comp.excuse.at.slice(0, 10)}` : 'Excused' }), comp.ruleFile && (_jsx("div", { class: "os-actions", children: _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", "aria-expanded": isWhyOpen, onClick: () => setWhyOpenId(isWhyOpen ? null : comp.id), children: "Why this rule?" }) }))] })), comp.state === 'no-rule' && (_jsxs("div", { class: "os-actions", children: [_jsx("span", { class: "os-sub", children: "No saved rule matches this component." }), _jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "add-rule", title: "Capture this component right now as a saved rule in .luci/design/", disabled: busy, onClick: async () => {
518
+ }, children: "Send back" }), comp.ruleFile && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", title: "Inspect where this saved rule came from and its decision history", "aria-expanded": isWhyOpen, onClick: () => {
519
+ dismissRemovedUndo();
520
+ setWhyOpenId(isWhyOpen ? null : comp.id);
521
+ }, children: "Why this rule?" }), callbacks.onRemoveRule && (_jsx("button", { type: "button", class: "btn-danger-text btn-sm", "data-action": "remove-rule-open", title: "Delete this rule file and its history entry", disabled: busy, onClick: () => openAction({ id: comp.id, kind: 'remove' }), children: "Remove rule" }))] }))] })] })), comp.state === 'excused' && (_jsxs(_Fragment, { children: [_jsx("p", { class: "os-sub", "data-part": "excuse-reason", children: comp.excuse ? `${comp.excuse.reason} (${comp.excuse.role}, ${comp.excuse.at.slice(0, 10)})` : 'Excused' }), comp.variant && _jsxs("p", { class: "os-sub", "data-part": "variant-checked-as", children: ["Checked as ", comp.variant] }), comp.widthsChecked.length > 0 && (_jsxs("p", { class: "os-sub", "data-part": "widths-checked", children: ["Checked at ", comp.widthsChecked.map(w => `${w}px`).join(', ')] })), comp.note && _jsx("p", { class: "os-sub", "data-part": "width-not-checked-note", children: comp.note }), comp.ruleFile && (_jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", "aria-expanded": isWhyOpen, onClick: () => {
522
+ dismissRemovedUndo();
523
+ setWhyOpenId(isWhyOpen ? null : comp.id);
524
+ }, children: "Why this rule?" }), callbacks.onRemoveRule && (_jsx("button", { type: "button", class: "btn-danger-text btn-sm", "data-action": "remove-rule-open", title: "Delete this rule file and its history entry", disabled: busy, onClick: () => openAction({ id: comp.id, kind: 'remove' }), children: "Remove rule" }))] }))] })), isWidthNotChecked && (_jsxs("div", { class: "os-actions", children: [_jsx("p", { class: "os-sub", "data-part": "width-not-checked-note", children: comp.note || formatWidthNotCheckedNote(state.widths) }), comp.ruleFile && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "why-rule", "aria-expanded": isWhyOpen, onClick: () => {
525
+ dismissRemovedUndo();
526
+ setWhyOpenId(isWhyOpen ? null : comp.id);
527
+ }, children: "Why this rule?" }), callbacks.onRemoveRule && (_jsx("button", { type: "button", class: "btn-danger-text btn-sm", "data-action": "remove-rule-open", title: "Delete this rule file and its history entry", disabled: busy, onClick: () => openAction({ id: comp.id, kind: 'remove' }), children: "Remove rule" }))] }))] })), comp.state === 'no-rule' && !isWidthNotChecked && (_jsxs("div", { class: "os-actions", children: [_jsx("span", { class: "os-sub", "data-part": "no-rule-reason", children: noRuleReasonText }), showOpenFigmaQuestions ? (_jsxs("button", { type: "button", class: "btn-secondary btn-sm btn-with-ico", "data-action": "open-figma-questions", disabled: busy, onClick: () => {
528
+ dismissRemovedUndo();
529
+ setSelectedPinId(null);
530
+ setOpen(true);
531
+ setPanelTab('figma');
532
+ }, children: [_jsx(Icon, { icon: IconFigmaDiff, size: "compact" }), _jsx("span", { children: "Open Figma questions" })] })) : isAmbiguous ? (_jsxs("button", { type: "button", class: "btn-secondary btn-sm btn-with-ico", "data-action": "change-figma-match", ...(figmaCandidate ? { 'data-layer-key': figmaCandidate.layerKey } : {}), disabled: busy || (!figmaCandidate && figmaRules.length === 0) || !callbacks.onStartFigmaPicker || !callbacks.onChangeFigmaMatch, onClick: () => {
533
+ if (figmaCandidate) {
534
+ startChangeMatchPicker(figmaCandidate);
535
+ }
536
+ else if (figmaRules.length > 0) {
537
+ setChosenFigmaLayerKey('');
538
+ openAction({ id: comp.id, kind: 'choose-figma-rule' });
539
+ }
540
+ }, children: [_jsx(Icon, { icon: IconSelect, size: "compact" }), _jsx("span", { children: "Change match" })] })) : isLowConfidenceFigma && figmaCandidate ? (_jsxs("button", { type: "button", class: "btn-secondary btn-sm btn-with-ico", "data-action": "change-figma-match", "data-layer-key": figmaCandidate.layerKey, title: "Pick a different matching element on the page for this Figma layer", disabled: busy || !callbacks.onStartFigmaPicker || !callbacks.onChangeFigmaMatch, onClick: () => startChangeMatchPicker(figmaCandidate), children: [_jsx(Icon, { icon: IconSelect, size: "compact" }), _jsx("span", { children: "Change match" })] })) : (_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "add-rule", title: "Capture this component right now as a saved rule in .luci/design/", disabled: busy, onClick: async () => {
541
+ dismissRemovedUndo();
353
542
  setBusy(true);
543
+ setErrorMsg(null);
354
544
  try {
355
- await callbacks.onAddRule({ component: comp });
545
+ const added = await callbacks.onAddRule({ component: comp });
546
+ const addedRuleFile = added && typeof added === 'object' && 'ruleFile' in added
547
+ ? added.ruleFile
548
+ : (store.get().data.state.components.find(c => c.id === comp.id || c.selector === comp.selector)?.ruleFile ?? null);
549
+ if (addedRuleFile)
550
+ showRuleAddedUndo(comp.id, comp.selector, addedRuleFile);
551
+ }
552
+ catch (err) {
553
+ setErrorMsg(err instanceof Error ? err.message : String(err));
356
554
  }
357
555
  finally {
358
556
  setBusy(false);
359
557
  }
360
- }, children: "Add a rule?" })] })), challenge.challenged && challenge.message && comp.ruleFile && (_jsxs("div", { class: "os-challenge", "data-part": "challenge-banner", children: [_jsx("span", { children: challenge.message }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "challenge-update-rule", title: "Replace the saved rule with this component's current live styles", onClick: () => setActiveAction({ id: comp.id, kind: 'update' }), children: "Update rule" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "mark-reviewed", title: "Confirm the saved rule is still right and clear this challenge banner", disabled: busy, onClick: () => void withRoleCheck('Keep as is (reviewed)', async (role) => {
558
+ }, children: "Add a rule?" }))] })), challenge.challenged && challenge.message && comp.ruleFile && (_jsxs("div", { class: "os-challenge", "data-part": "challenge-banner", children: [_jsx("span", { children: challenge.message }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "challenge-update-rule", title: "Replace the saved rule with this component's current live styles", onClick: () => {
559
+ setOverrideMode(false);
560
+ openAction({ id: comp.id, kind: 'update' });
561
+ }, children: "Update rule" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "mark-reviewed", title: "Confirm the saved rule is still right and clear this challenge banner", disabled: busy, onClick: () => void withRoleCheck('Keep as is (reviewed)', async (role) => {
361
562
  await callbacks.onMarkReviewed({ ruleFile: comp.ruleFile, role });
362
- }), children: "Keep as is (reviewed)" })] })] })), isEditingThis && activeAction?.kind === 'excuse' && (_jsxs("div", { class: "os-inline-box", "data-part": "excuse-box", children: [_jsx("label", { class: "os-sub", for: `excuse-${mode}-${comp.id}`, children: "Reason (required)" }), _jsx("input", { id: `excuse-${mode}-${comp.id}`, type: "text", "data-part": "excuse-input", placeholder: "Why is this difference intentional?", value: excuseReason, onInput: (e) => setExcuseReason(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "excuse-confirm", disabled: busy || excuseReason.trim().length === 0, onClick: () => void withRoleCheck('Excuse', async (role) => {
563
+ }), children: "Keep as is (reviewed)" })] })] })), isEditingThis && activeAction?.kind === 'choose-figma-rule' && figmaRules.length > 0 && (_jsxs("div", { class: "os-inline-box", "data-part": "choose-figma-rule-box", children: [_jsx("p", { class: "os-sub", children: "Match to which Figma rule?" }), _jsx("div", { class: "os-choice-list", role: "radiogroup", "aria-label": "Figma rules", children: figmaRules.map(rule => (_jsxs("label", { class: "os-radio-choice", children: [_jsx("input", { type: "radio", name: `choose-figma-rule-${mode}-${comp.id}`, value: rule.layerKey, "data-part": "choose-figma-rule-option", checked: chosenFigmaLayerKey === rule.layerKey, onChange: () => setChosenFigmaLayerKey(rule.layerKey) }), _jsx("span", { children: (rule.component && rule.component.trim()) || rule.label.trim() })] }, rule.layerKey))) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "choose-figma-rule-confirm", disabled: busy || !chosenFigmaLayerKey, onClick: () => {
564
+ const chosen = figmaRules.find(r => r.layerKey === chosenFigmaLayerKey);
565
+ if (!chosen)
566
+ return;
567
+ setActiveAction(null);
568
+ setChosenFigmaLayerKey('');
569
+ startChangeMatchPicker(chosen);
570
+ }, children: "Point at it" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => {
571
+ setActiveAction(null);
572
+ setChosenFigmaLayerKey('');
573
+ }, children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'excuse' && (_jsxs("div", { class: "os-inline-box", "data-part": "excuse-box", children: [_jsx("label", { class: "os-sub", for: `excuse-${mode}-${comp.id}`, children: "Reason (required)" }), _jsx("input", { id: `excuse-${mode}-${comp.id}`, type: "text", "data-part": "excuse-input", placeholder: "Why is this difference intentional?", value: excuseReason, onInput: (e) => setExcuseReason(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "excuse-confirm", disabled: busy || excuseReason.trim().length === 0, onClick: () => void withRoleCheck('Excuse', async (role) => {
363
574
  await callbacks.onExcuse({ componentId: comp.id, reason: excuseReason.trim(), role });
364
575
  setActiveAction(null);
365
576
  setExcuseReason('');
366
- }), children: "Save excuse" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'update' && comp.ruleFile && (_jsxs("div", { class: "os-inline-box", "data-part": "update-rule-confirm-box", children: [_jsxs("p", { class: "os-sub", children: ["Save the current build as the rule for ", _jsx("strong", { children: comp.name }), "? This updates ", _jsx("code", { children: comp.ruleFile }), "."] }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "update-rule-confirm", disabled: busy, onClick: () => void withRoleCheck('Update rule', async (role) => {
577
+ }), children: "Save excuse" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'update' && comp.ruleFile && (meta?.origin === 'figma' ? (_jsxs("div", { class: "confirm-card", "data-part": "figma-update-dialog", children: [_jsx("p", { class: "os-sub", children: "This rule comes from Figma. Update it in Figma, then re-import." }), !overrideMode ? (_jsxs("div", { class: "os-actions", children: [meta.originDetail && (_jsx("button", { type: "button", class: "btn-secondary btn-sm", "data-action": "copy-figma-link", onClick: () => {
578
+ void win.navigator?.clipboard?.writeText(meta.originDetail);
579
+ setCopiedFigmaLink(true);
580
+ }, children: copiedFigmaLink ? 'Copied Figma link' : 'Copy Figma link' })), _jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "keep-local-override-open", disabled: !callbacks.onOverrideFigmaRule, onClick: () => setOverrideMode(true), children: "Keep local override" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })) : (_jsxs(_Fragment, { children: [_jsxs("label", { class: "os-sub", for: `ov-val-${mode}-${comp.id}`, children: ["Local value (", overridePart, " ", overrideProp, ")"] }), _jsx("input", { id: `ov-val-${mode}-${comp.id}`, type: "text", "data-part": "local-override-value-input", placeholder: "e.g. 16px", value: overrideVal, onInput: (e) => setOverrideVal(e.currentTarget.value) }), _jsx("label", { class: "os-sub", for: `ov-reason-${mode}-${comp.id}`, children: "Reason for local override (required)" }), _jsx("input", { id: `ov-reason-${mode}-${comp.id}`, type: "text", "data-part": "local-override-reason-input", placeholder: "Why keep this local value instead of Figma?", value: overrideReason, onInput: (e) => setOverrideReason(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "keep-local-override-confirm", disabled: busy || !callbacks.onOverrideFigmaRule || !overrideVal.trim() || !overrideReason.trim(), onClick: () => void withRoleCheck('Keep local override', async (role) => {
581
+ await callbacks.onOverrideFigmaRule?.({
582
+ ruleFile: comp.ruleFile,
583
+ part: overridePart.trim() || 'container',
584
+ property: overrideProp.trim() || 'padding',
585
+ localValue: overrideVal.trim(),
586
+ reason: overrideReason.trim(),
587
+ role
588
+ });
589
+ setOverrideMode(false);
590
+ setActiveAction(null);
591
+ }), children: "Keep local override" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => { setOverrideMode(false); setActiveAction(null); }, children: "Cancel" })] })] }))] })) : (_jsxs("div", { class: "os-inline-box", "data-part": "update-rule-confirm-box", children: [_jsxs("p", { class: "os-sub", children: ["Save the current build as the rule for ", _jsx("strong", { children: comp.name }), "? This updates ", _jsx("code", { children: comp.ruleFile }), "."] }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "update-rule-confirm", disabled: busy, onClick: () => void withRoleCheck('Update rule', async (role) => {
367
592
  await callbacks.onUpdateRule({
368
593
  componentId: comp.id,
369
594
  ruleFile: comp.ruleFile,
@@ -371,7 +596,8 @@ function OnSpecView({ doc, store, callbacks }) {
371
596
  role
372
597
  });
373
598
  setActiveAction(null);
374
- }), children: "Confirm update" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'send-back' && (_jsxs("div", { class: "os-inline-box", "data-part": "send-back-box", children: [_jsx("label", { class: "os-sub", for: `sendback-${mode}-${comp.id}`, children: "Note for your agent (optional)" }), _jsx("input", { id: `sendback-${mode}-${comp.id}`, type: "text", "data-part": "send-back-input", placeholder: "e.g. Use the 16px token from our spacing scale", value: sendBackNote, onInput: (e) => setSendBackNote(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "send-back-confirm", disabled: busy, onClick: async () => {
599
+ }), children: "Confirm update" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] }))), isEditingThis && activeAction?.kind === 'send-back' && (_jsxs("div", { class: "os-inline-box", "data-part": "send-back-box", children: [_jsx("label", { class: "os-sub", for: `sendback-${mode}-${comp.id}`, children: "Note for your agent (optional)" }), _jsx("input", { id: `sendback-${mode}-${comp.id}`, type: "text", "data-part": "send-back-input", placeholder: "e.g. Use the 16px token from our spacing scale", value: sendBackNote, onInput: (e) => setSendBackNote(e.currentTarget.value) }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-primary btn-sm", "data-action": "send-back-confirm", disabled: busy, onClick: async () => {
600
+ dismissRemovedUndo();
375
601
  setBusy(true);
376
602
  setErrorMsg(null);
377
603
  try {
@@ -389,11 +615,41 @@ function OnSpecView({ doc, store, callbacks }) {
389
615
  finally {
390
616
  setBusy(false);
391
617
  }
392
- }, children: "Send to agent" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isWhyOpen && comp.ruleFile && (_jsxs("div", { class: "os-why", "data-part": "why-rule-card", children: [_jsx("strong", { children: "Why this rule? (Saved history)" }), _jsxs("span", { children: ["Rule file: ", _jsx("code", { children: comp.ruleFile })] }), _jsxs("span", { class: "os-comp-sel", children: ["Selector: ", _jsx("code", { children: comp.selector })] }), meta ? (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Origin: ", formatRuleOrigin(meta)] }), _jsxs("span", { children: ["Originally confirmed by: ", meta.confirmedByRole, " on ", meta.confirmedAt.slice(0, 10)] }), meta.history.length > 0 && (_jsx("ul", { class: "os-history", children: meta.history.slice(-8).map((entry, idx) => (_jsxs("li", { children: [_jsx("strong", { children: entry.kind }), " (", entry.role, ", ", entry.at.slice(0, 10), ")", entry.reason ? ` — ${entry.reason}` : entry.note ? ` — ${entry.note}` : ''] }, idx))) }))] })) : (_jsx("span", { children: "Origin: Saved in .luci/design/" })), _jsxs("span", { class: "os-comp-sel", children: ["Your current role: ", profile.role, " (used for new decisions)"] })] }))] }));
618
+ }, children: "Send to agent" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isEditingThis && activeAction?.kind === 'remove' && comp.ruleFile && (_jsxs("div", { class: "confirm-card", "data-part": "remove-rule-confirm-box", children: [_jsxs("p", { class: "os-sub", children: ["Remove this rule? Luci stops checking ", _jsx("strong", { children: comp.name }), " against it."] }), _jsxs("div", { class: "os-actions", children: [_jsx("button", { type: "button", class: "btn-danger btn-sm", "data-action": "remove-rule-confirm", disabled: busy, onClick: async () => {
619
+ dismissRemovedUndo();
620
+ setBusy(true);
621
+ setErrorMsg(null);
622
+ try {
623
+ const res = await callbacks.onRemoveRule?.({ ruleFile: comp.ruleFile, selector: comp.selector });
624
+ setActiveAction(null);
625
+ if (res?.undo?.markdown) {
626
+ showRuleRemovedUndo({
627
+ ...res.undo,
628
+ ...(comp.selector ? { selector: comp.selector } : {}),
629
+ componentId: comp.id
630
+ });
631
+ }
632
+ }
633
+ catch (err) {
634
+ setErrorMsg(err instanceof Error ? err.message : String(err));
635
+ }
636
+ finally {
637
+ setBusy(false);
638
+ }
639
+ }, children: "Remove" }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", onClick: () => setActiveAction(null), children: "Cancel" })] })] })), isWhyOpen && comp.ruleFile && (_jsxs("div", { class: "os-why", "data-part": "why-rule-card", children: [_jsx("strong", { children: "Why this rule? (Saved history)" }), _jsxs("span", { children: ["Rule file: ", _jsx("code", { children: comp.ruleFile })] }), _jsxs("span", { class: "os-comp-sel", children: ["Selector: ", _jsx("code", { children: comp.selector })] }), meta ? (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Origin: ", formatRuleOrigin(meta)] }), meta.originDetail && meta.origin === 'figma' && (_jsxs("span", { children: ["Figma link: ", _jsx("code", { children: meta.originDetail })] })), _jsxs("span", { children: ["Originally confirmed by: ", meta.confirmedByRole, " on ", meta.confirmedAt.slice(0, 10)] }), figmaMatched && figmaMatched.overrides.length > 0 && (_jsx("div", { class: "fg-overrides-list", children: figmaMatched.overrides.map((ov, idx) => (_jsxs("div", { class: "fg-override-item", children: [_jsxs("span", { class: "fg-chip", "data-kind": "local-override", children: [_jsx(Icon, { icon: IconLocalOverride, size: "compact" }), _jsx("span", { children: "Local override" })] }), _jsxs("span", { children: [ov.part, " ", ov.property, ": ", _jsx("code", { children: ov.localValue }), " (Figma: ", _jsx("code", { children: ov.figmaValue }), ") - ", ov.reason] })] }, idx))) })), meta.history.length > 0 && (_jsx("ul", { class: "os-history", children: meta.history.slice(-8).map((entry, idx) => (_jsxs("li", { children: [_jsx("strong", { children: entry.kind }), " (", entry.role, ", ", entry.at.slice(0, 10), ")", entry.reason ? `: ${entry.reason}` : entry.note ? `: ${entry.note}` : ''] }, idx))) }))] })) : (_jsx("span", { children: "Origin: Saved in .luci/design/" })), _jsxs("span", { class: "os-comp-sel", children: ["Your current role: ", profile.role, " (used for new decisions)"] })] }))] }));
393
640
  };
394
641
  const summaryText = formatSpecSummary(components);
395
642
  const hasDrift = components.some(c => c.state === 'drift');
396
- const showPill = components.length > 0 || open;
643
+ const pendingFigmaDiffCount = figma?.pendingDiff?.items.filter(i => i.decision === 'pending').length ?? 0;
644
+ const pendingFigmaQuestionsCount = figma?.questions.length ?? 0;
645
+ const hasFigmaContent = Boolean(figma && (figma.status.layersCount > 0 || pendingFigmaQuestionsCount > 0 || pendingFigmaDiffCount > 0));
646
+ const figmaReviewCount = pendingFigmaDiffCount + pendingFigmaQuestionsCount;
647
+ const pillLabel = pendingFigmaDiffCount > 0
648
+ ? (components.length > 0 ? `${summaryText} · Figma re-import: ${pendingFigmaDiffCount} to review` : `Figma re-import: ${pendingFigmaDiffCount} to review`)
649
+ : pendingFigmaQuestionsCount > 0
650
+ ? (components.length > 0 ? `${summaryText} · ${pendingFigmaQuestionsCount} Figma question${pendingFigmaQuestionsCount === 1 ? '' : 's'}` : `${pendingFigmaQuestionsCount} Figma question${pendingFigmaQuestionsCount === 1 ? '' : 's'}`)
651
+ : summaryText;
652
+ const showPill = components.length > 0 || open || figmaReviewCount > 0 || hasFigmaContent;
397
653
  const vw = win.innerWidth || 1280;
398
654
  const vh = win.innerHeight || 800;
399
655
  // Position focused popover near the selected element without leaving the viewport
@@ -420,36 +676,63 @@ function OnSpecView({ doc, store, callbacks }) {
420
676
  const pinTop = clamp(rect.top - 14, 8, vh - 36);
421
677
  const isSelected = selectedPinId === comp.id;
422
678
  const diffCount = comp.state === 'drift' ? comp.differences.length : 0;
423
- const label = `${comp.name}${snippet && snippet.toLowerCase() !== comp.name.toLowerCase() ? ` (${snippet})` : ''}: ${SPEC_STATE_LABELS[comp.state]}`;
679
+ const label = `${comp.name}${snippet && snippet.toLowerCase() !== comp.name.toLowerCase() ? ` (${snippet})` : ''}: ${badgeLabel(comp)}`;
424
680
  return (_jsxs("button", { type: "button", class: "os-pin", "data-part": "on-spec-pin", "data-spec-state": comp.state, "data-component-id": comp.id, "data-selected": isSelected ? 'true' : undefined, "aria-label": label, "aria-expanded": isSelected, title: label, style: { left: `${pinLeft}px`, top: `${pinTop}px` }, onPointerEnter: () => setHoveredId(comp.id), onPointerLeave: () => setHoveredId(prev => (prev === comp.id ? null : prev)), onClick: (e) => {
425
681
  e.stopPropagation();
426
682
  setOpen(false);
427
683
  setSelectedPinId(prev => (prev === comp.id ? null : comp.id));
428
684
  }, children: [_jsx("span", { class: earnedIds.has(comp.id) ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: IconOnSpec, size: "compact" }) }), diffCount > 0 && _jsx("span", { class: "os-pin-count", children: diffCount })] }, comp.id));
429
- }), selectedPin && popoverStyle && (_jsxs("div", { class: "os-popover", role: "dialog", "aria-label": `On spec: ${selectedPin.comp.name}`, "data-part": "on-spec-popover", "data-component-id": selectedPin.comp.id, style: popoverStyle, children: [errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), renderRolePrompt(), renderComponentBody(selectedPin.comp, selectedPin.snippet, 'popover')] })), hoverInfo && (_jsxs("div", { class: "os-hover-badge", "data-part": "on-spec-hover-badge", "data-spec-state": hoverInfo.state, style: { left: `${hoverInfo.x}px`, top: `${hoverInfo.y}px` }, children: [_jsx(StateIcon, { state: hoverInfo.state }), _jsx("span", { children: SPEC_STATE_LABELS[hoverInfo.state] })] })), showPill && (_jsxs("button", { type: "button", class: "os-pill", "data-part": "on-spec-pill", "data-side": side, "data-has-drift": hasDrift ? 'true' : undefined, "aria-expanded": open, "aria-label": `On spec: ${summaryText}`, title: "On spec: click to view component verdicts, drift actions and Spec report", onClick: () => {
685
+ }), selectedPin && popoverStyle && (_jsxs("div", { class: "os-popover", role: "dialog", "aria-label": `On spec: ${selectedPin.comp.name}`, "data-part": "on-spec-popover", "data-component-id": selectedPin.comp.id, style: popoverStyle, children: [errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), addedUndo && (addedUndo.id === selectedPin.comp.id || addedUndo.selector === selectedPin.comp.selector) && renderAddedUndoBanner(), matchesRemovedUndo(selectedPin.comp) && renderRemovedUndoBanner(), renderRolePrompt(), renderComponentBody(selectedPin.comp, selectedPin.snippet, 'popover')] })), hoverInfo && (_jsxs("div", { class: "os-hover-badge", "data-part": "on-spec-hover-badge", "data-spec-state": hoverInfo.state, style: { left: `${hoverInfo.x}px`, top: `${hoverInfo.y}px` }, children: [_jsx(StateIcon, { state: hoverInfo.state }), _jsx("span", { children: badgeLabel(hoverInfo) })] })), showPill && (_jsxs("button", { type: "button", class: "os-pill", "data-part": "on-spec-pill", "data-side": side, "data-has-drift": hasDrift ? 'true' : undefined, "aria-expanded": open, "aria-label": `On spec: ${pillLabel}`, title: "On spec: click to view component verdicts, Figma imports, drift actions and Spec report", onClick: () => {
430
686
  const nextOpen = !open;
431
687
  setSelectedPinId(null);
688
+ if (nextOpen && components.length === 0 && hasFigmaContent) {
689
+ setPanelTab('figma');
690
+ }
432
691
  setOpen(nextOpen);
433
692
  if (nextOpen)
434
693
  setPinsVisible(true);
435
- }, children: [_jsx("span", { class: pillEarned ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: IconOnSpec, size: "compact" }) }), _jsx("span", { children: summaryText })] })), open && (_jsxs("div", { class: "os-panel", role: "dialog", "aria-label": "On spec", "data-part": "on-spec-panel", "data-side": side, children: [_jsxs("div", { class: "os-head", children: [_jsxs("h2", { class: "os-title", children: [_jsx(Icon, { icon: IconOnSpec, size: "content" }), _jsx("span", { children: "On spec" })] }), _jsxs("div", { class: "os-head-actions", children: [_jsx("button", { type: "button", class: `btn-secondary btn-sm btn-icon${checkState === 'done' ? ' os-btn-done' : ''}`, "data-action": "check-now", "data-check-state": checkState, "aria-busy": checkState === 'checking' ? 'true' : undefined, "aria-label": checkState === 'checking' ? 'Checking' : checkState === 'done' ? 'Checked' : 'Re-check', title: checkState === 'checking' ? 'Checking…' : checkState === 'done' ? 'Checked just now' : 'Re-run On spec checks at both widths right now', disabled: busy || checkState === 'checking', onClick: () => void runCheckNow(), children: _jsx("span", { class: checkState === 'checking' ? 'os-spin' : undefined, children: _jsx(Icon, { icon: checkState === 'done' ? IconSuccess : IconReset, size: "compact" }) }) }), _jsx("button", { type: "button", class: "btn-secondary btn-sm btn-icon", "data-action": "toggle-pins", "aria-pressed": pinsVisible, "aria-label": pinsVisible ? 'Hide pins on page' : 'Show pins on page', title: pinsVisible ? 'Hide on-page component pins' : 'Show on-page component pins', onClick: () => {
694
+ }, children: [_jsx("span", { class: pillEarned ? 'os-paw-earned' : undefined, children: _jsx(Icon, { icon: pendingFigmaDiffCount > 0 && components.length === 0 ? IconFigmaDiff : IconOnSpec, size: "compact" }) }), _jsx("span", { children: pillLabel })] })), open && (_jsxs("div", { class: "os-panel", role: "dialog", "aria-label": "On spec", "data-part": "on-spec-panel", "data-side": side, "data-pointing": anyPointing ? 'true' : undefined, children: [!anyPointing && (_jsxs("div", { class: "os-head", children: [_jsxs("h2", { class: "os-title", children: [_jsx(Icon, { icon: IconOnSpec, size: "content" }), _jsx("span", { children: "On spec" })] }), _jsxs("div", { class: "os-head-actions", children: [_jsx("button", { type: "button", class: `btn-secondary btn-sm btn-icon${checkState === 'done' ? ' os-btn-done' : ''}`, "data-action": "check-now", "data-check-state": checkState, "aria-busy": checkState === 'checking' ? 'true' : undefined, "aria-label": checkState === 'checking' ? 'Checking' : checkState === 'done' ? 'Checked' : 'Re-check', title: checkState === 'checking' ? 'Checking…' : checkState === 'done' ? 'Checked just now' : 'Re-run On spec checks right now', disabled: busy || checkState === 'checking', onClick: () => void runCheckNow(), children: _jsx("span", { class: checkState === 'checking' ? 'os-spin' : undefined, children: _jsx(Icon, { icon: checkState === 'done' ? IconSuccess : IconReset, size: "compact" }) }) }), _jsx("button", { type: "button", class: "btn-secondary btn-sm btn-icon", "data-action": "toggle-pins", "aria-pressed": pinsVisible, "aria-label": pinsVisible ? 'Hide pins on page' : 'Show pins on page', title: pinsVisible ? 'Hide on-page component pins' : 'Show on-page component pins', onClick: () => {
695
+ dismissRemovedUndo();
436
696
  setPinsVisible(v => {
437
697
  const next = !v;
438
698
  if (!next)
439
699
  setSelectedPinId(null);
440
700
  return next;
441
701
  });
442
- }, children: _jsx(Icon, { icon: pinsVisible ? IconCheck : IconHide, size: "compact" }) }), _jsxs("button", { type: "button", class: "btn-secondary btn-sm btn-with-ico", "data-action": "copy-spec-report", title: "Copy a markdown Spec report of every checked component", onClick: () => void copyReport(), children: [_jsx(Icon, { icon: copied ? IconSuccess : IconCopy, size: "compact" }), _jsx("span", { children: copied ? 'Copied' : 'Copy report' })] }), _jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-on-spec", "aria-label": "Close On spec", title: "Close On spec panel", onClick: () => setOpen(false), children: _jsx(Icon, { icon: IconClose, size: "compact" }) })] })] }), _jsx("p", { class: "os-summary", "data-part": "on-spec-summary", children: checkState === 'checking'
443
- ? 'Checking components…'
444
- : checkState === 'done'
445
- ? `${summaryText} · Checked just now · Role: ${profile.role}`
446
- : components.length === 0
447
- ? `No components checked yet. Save a component rule in Capture or edit a ruled component. · Role: ${profile.role}`
448
- : `${summaryText} · ${components.every(c => c.state === 'on-spec') ? SPEC_MATCHES_PHRASE : `Widths: ${state.widths.map(w => `${w}px`).join(', ')}`} · Role: ${profile.role}` }), errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), renderRolePrompt(), components.length > 0 && (_jsx("ul", { class: "os-list", "data-part": "on-spec-list", children: components.map(comp => {
449
- const pin = pinById.get(comp.id);
450
- return (_jsx("li", { class: "os-row", "data-part": "on-spec-row", "data-spec-state": comp.state, "data-component-id": comp.id, onPointerEnter: () => { if (pin)
451
- setHoveredId(comp.id); }, onPointerLeave: () => setHoveredId(prev => (prev === comp.id ? null : prev)), children: renderComponentBody(comp, pin?.snippet ?? '', 'list') }, comp.id));
452
- }) }))] }))] }));
702
+ }, children: _jsx(Icon, { icon: pinsVisible ? IconCheck : IconHide, size: "compact" }) }), _jsx("button", { type: "button", class: "btn-secondary btn-sm btn-icon", "data-action": "copy-spec-report", "aria-label": copied ? 'Copied' : 'Copy report', "data-tip": copied ? 'Copied' : 'Copy report', "data-tip-align": "right", title: copied ? 'Copied' : 'Copy report', onClick: () => void copyReport(), children: _jsx(Icon, { icon: copied ? IconSuccess : IconCopy, size: "compact" }) }), _jsx("button", { type: "button", class: "btn-ghost btn-sm btn-icon", "data-action": "close-on-spec", "aria-label": "Close On spec", title: "Close On spec panel", onClick: () => setOpen(false), children: _jsx(Icon, { icon: IconClose, size: "compact" }) })] })] })), !anyPointing && hasFigmaContent && (_jsxs("div", { class: "os-tabs", role: "tablist", "aria-label": "On spec views", children: [_jsx("button", { type: "button", role: "tab", class: "os-tab", "data-tab": "on-spec", "aria-selected": panelTab === 'on-spec', onClick: () => {
703
+ dismissRemovedUndo();
704
+ setPanelTab('on-spec');
705
+ }, children: _jsx("span", { children: "On spec" }) }), _jsx("button", { type: "button", role: "tab", class: "os-tab", "data-tab": "figma", "aria-selected": panelTab === 'figma', onClick: () => {
706
+ dismissRemovedUndo();
707
+ setPanelTab('figma');
708
+ }, children: _jsxs("span", { children: ["Figma", figmaReviewCount > 0 ? ` (${figmaReviewCount})` : ''] }) })] })), pointingMatch ? (_jsx("div", { class: "os-inline-box fg-pointing-banner", "data-part": "figma-pointing-banner", children: _jsxs("div", { class: "os-row-top", children: [_jsx("p", { class: "os-sub", children: _jsx("strong", { children: "Hover and click the matching element. Press \u2191 to select the element around it. Esc cancels." }) }), _jsx("button", { type: "button", class: "btn-ghost btn-sm", "data-action": "figma-point-cancel", onClick: () => {
709
+ setPointingMatch(null);
710
+ callbacks.onCancelFigmaPicker?.();
711
+ }, children: "Cancel" })] }) })) : panelTab === 'figma' && figma ? (_jsx(FigmaPanel, { doc: doc, data: figma, role: profile.role, onPointingChange: setFigmaPointing, callbacks: {
712
+ ...(callbacks.onAnswerFigmaQuestion
713
+ ? { onAnswerQuestion: async (input) => { dismissRemovedUndo(); await callbacks.onAnswerFigmaQuestion?.(input); } }
714
+ : {}),
715
+ ...(callbacks.onDecideFigmaDiff
716
+ ? { onDecideDiff: async (input) => { dismissRemovedUndo(); await callbacks.onDecideFigmaDiff?.(input); } }
717
+ : {}),
718
+ ...(callbacks.onChangeFigmaMatch
719
+ ? { onChangeLayerMatch: async (input) => { dismissRemovedUndo(); await callbacks.onChangeFigmaMatch?.(input); } }
720
+ : {}),
721
+ ...(callbacks.onStartFigmaPicker
722
+ ? { onStartPicker: req => { dismissRemovedUndo(); callbacks.onStartFigmaPicker?.(req); } }
723
+ : {}),
724
+ ...(callbacks.onCancelFigmaPicker ? { onCancelPicker: callbacks.onCancelFigmaPicker } : {})
725
+ } })) : (_jsxs(_Fragment, { children: [_jsx("p", { class: "os-summary", "data-part": "on-spec-summary", children: checkState === 'checking'
726
+ ? 'Checking components…'
727
+ : checkState === 'done'
728
+ ? `${summaryText} · Checked just now · Role: ${profile.role}`
729
+ : components.length === 0
730
+ ? `No components checked yet. Save a component rule in Capture or edit a ruled component. · Role: ${profile.role}`
731
+ : `${summaryText} · ${components.every(c => c.state === 'on-spec') ? SPEC_MATCHES_PHRASE : `Widths: ${state.widths.map(w => `${w}px`).join(', ')}`} · Role: ${profile.role}` }), errorMsg && _jsx("p", { class: "os-sub", role: "alert", children: errorMsg }), renderAddedUndoBanner(), renderRolePrompt(), components.length > 0 && (_jsx("ul", { class: "os-list", "data-part": "on-spec-list", children: components.map(comp => {
732
+ const pin = pinById.get(comp.id);
733
+ return (_jsxs("li", { class: "os-row", "data-part": "on-spec-row", "data-spec-state": comp.state, "data-component-id": comp.id, onPointerEnter: () => { if (pin)
734
+ setHoveredId(comp.id); }, onPointerLeave: () => setHoveredId(prev => (prev === comp.id ? null : prev)), children: [renderComponentBody(comp, pin?.snippet ?? '', 'list'), matchesRemovedUndo(comp) && renderRemovedUndoBanner()] }, comp.id));
735
+ }) }))] }))] }))] }));
453
736
  }
454
737
  /** Mount the calm On spec pill, on-page pins, overview panel, and optional hover badge in its own shadow root. */
455
738
  export function mountOnSpec(options) {