@luci-dev/capture 0.0.0-stage → 0.5.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 (148) hide show
  1. package/LICENSE +21 -0
  2. package/dist/a11y.d.ts +54 -0
  3. package/dist/a11y.d.ts.map +1 -0
  4. package/dist/a11y.js +144 -0
  5. package/dist/a11y.js.map +1 -0
  6. package/dist/browser.d.ts +4 -0
  7. package/dist/browser.d.ts.map +1 -0
  8. package/dist/browser.js +4 -0
  9. package/dist/browser.js.map +1 -0
  10. package/dist/color.d.ts +44 -0
  11. package/dist/color.d.ts.map +1 -0
  12. package/dist/color.js +230 -0
  13. package/dist/color.js.map +1 -0
  14. package/dist/component.d.ts +94 -0
  15. package/dist/component.d.ts.map +1 -0
  16. package/dist/component.js +445 -0
  17. package/dist/component.js.map +1 -0
  18. package/dist/dom.d.ts +36 -0
  19. package/dist/dom.d.ts.map +1 -0
  20. package/dist/dom.js +365 -0
  21. package/dist/dom.js.map +1 -0
  22. package/dist/eligibility.d.ts +24 -0
  23. package/dist/eligibility.d.ts.map +1 -0
  24. package/dist/eligibility.js +33 -0
  25. package/dist/eligibility.js.map +1 -0
  26. package/dist/font.d.ts +18 -0
  27. package/dist/font.d.ts.map +1 -0
  28. package/dist/font.js +86 -0
  29. package/dist/font.js.map +1 -0
  30. package/dist/icon.d.ts +11 -0
  31. package/dist/icon.d.ts.map +1 -0
  32. package/dist/icon.js +221 -0
  33. package/dist/icon.js.map +1 -0
  34. package/dist/image.d.ts +82 -0
  35. package/dist/image.d.ts.map +1 -0
  36. package/dist/image.js +283 -0
  37. package/dist/image.js.map +1 -0
  38. package/dist/index.d.ts +20 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +20 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/layout.d.ts +9 -0
  43. package/dist/layout.d.ts.map +1 -0
  44. package/dist/layout.js +115 -0
  45. package/dist/layout.js.map +1 -0
  46. package/dist/luci-capture.js +35510 -0
  47. package/dist/model.d.ts +60 -0
  48. package/dist/model.d.ts.map +1 -0
  49. package/dist/model.js +43 -0
  50. package/dist/model.js.map +1 -0
  51. package/dist/naming.d.ts +8 -0
  52. package/dist/naming.d.ts.map +1 -0
  53. package/dist/naming.js +33 -0
  54. package/dist/naming.js.map +1 -0
  55. package/dist/page.d.ts +38 -0
  56. package/dist/page.d.ts.map +1 -0
  57. package/dist/page.js +102 -0
  58. package/dist/page.js.map +1 -0
  59. package/dist/realm.d.ts +17 -0
  60. package/dist/realm.d.ts.map +1 -0
  61. package/dist/realm.js +18 -0
  62. package/dist/realm.js.map +1 -0
  63. package/dist/responsive.d.ts +74 -0
  64. package/dist/responsive.d.ts.map +1 -0
  65. package/dist/responsive.js +237 -0
  66. package/dist/responsive.js.map +1 -0
  67. package/dist/section.d.ts +50 -0
  68. package/dist/section.d.ts.map +1 -0
  69. package/dist/section.js +244 -0
  70. package/dist/section.js.map +1 -0
  71. package/dist/spacing.d.ts +43 -0
  72. package/dist/spacing.d.ts.map +1 -0
  73. package/dist/spacing.js +113 -0
  74. package/dist/spacing.js.map +1 -0
  75. package/dist/stack.d.ts +11 -0
  76. package/dist/stack.d.ts.map +1 -0
  77. package/dist/stack.js +150 -0
  78. package/dist/stack.js.map +1 -0
  79. package/dist/states.d.ts +89 -0
  80. package/dist/states.d.ts.map +1 -0
  81. package/dist/states.js +457 -0
  82. package/dist/states.js.map +1 -0
  83. package/dist/text.d.ts +30 -0
  84. package/dist/text.d.ts.map +1 -0
  85. package/dist/text.js +156 -0
  86. package/dist/text.js.map +1 -0
  87. package/dist/ui/basket.d.ts +50 -0
  88. package/dist/ui/basket.d.ts.map +1 -0
  89. package/dist/ui/basket.js +93 -0
  90. package/dist/ui/basket.js.map +1 -0
  91. package/dist/ui/check.d.ts +43 -0
  92. package/dist/ui/check.d.ts.map +1 -0
  93. package/dist/ui/check.js +168 -0
  94. package/dist/ui/check.js.map +1 -0
  95. package/dist/ui/devSettings.d.ts +66 -0
  96. package/dist/ui/devSettings.d.ts.map +1 -0
  97. package/dist/ui/devSettings.js +115 -0
  98. package/dist/ui/devSettings.js.map +1 -0
  99. package/dist/ui/index.d.ts +14 -0
  100. package/dist/ui/index.d.ts.map +1 -0
  101. package/dist/ui/index.js +14 -0
  102. package/dist/ui/index.js.map +1 -0
  103. package/dist/ui/loading.d.ts +18 -0
  104. package/dist/ui/loading.d.ts.map +1 -0
  105. package/dist/ui/loading.js +23 -0
  106. package/dist/ui/loading.js.map +1 -0
  107. package/dist/ui/modeSwitch.d.ts +17 -0
  108. package/dist/ui/modeSwitch.d.ts.map +1 -0
  109. package/dist/ui/modeSwitch.js +6 -0
  110. package/dist/ui/modeSwitch.js.map +1 -0
  111. package/dist/ui/mount.d.ts +83 -0
  112. package/dist/ui/mount.d.ts.map +1 -0
  113. package/dist/ui/mount.js +81 -0
  114. package/dist/ui/mount.js.map +1 -0
  115. package/dist/ui/picker.d.ts +22 -0
  116. package/dist/ui/picker.d.ts.map +1 -0
  117. package/dist/ui/picker.js +73 -0
  118. package/dist/ui/picker.js.map +1 -0
  119. package/dist/ui/remap.d.ts +27 -0
  120. package/dist/ui/remap.d.ts.map +1 -0
  121. package/dist/ui/remap.js +76 -0
  122. package/dist/ui/remap.js.map +1 -0
  123. package/dist/ui/screenshot.d.ts +39 -0
  124. package/dist/ui/screenshot.d.ts.map +1 -0
  125. package/dist/ui/screenshot.js +59 -0
  126. package/dist/ui/screenshot.js.map +1 -0
  127. package/dist/ui/styles.d.ts +2 -0
  128. package/dist/ui/styles.d.ts.map +1 -0
  129. package/dist/ui/styles.js +381 -0
  130. package/dist/ui/styles.js.map +1 -0
  131. package/dist/ui/theme.d.ts +59 -0
  132. package/dist/ui/theme.d.ts.map +1 -0
  133. package/dist/ui/theme.js +93 -0
  134. package/dist/ui/theme.js.map +1 -0
  135. package/dist/ui/toolbar.d.ts +101 -0
  136. package/dist/ui/toolbar.d.ts.map +1 -0
  137. package/dist/ui/toolbar.js +1494 -0
  138. package/dist/ui/toolbar.js.map +1 -0
  139. package/dist/ui/tools.d.ts +165 -0
  140. package/dist/ui/tools.d.ts.map +1 -0
  141. package/dist/ui/tools.js +345 -0
  142. package/dist/ui/tools.js.map +1 -0
  143. package/dist/ui/zip.d.ts +16 -0
  144. package/dist/ui/zip.d.ts.map +1 -0
  145. package/dist/ui/zip.js +104 -0
  146. package/dist/ui/zip.js.map +1 -0
  147. package/package.json +29 -3
  148. package/README.md +0 -3
@@ -0,0 +1,1494 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ /**
3
+ * The on-page toolbar (FR1-FR5): tool modes, the picker with hover label and arrow-key navigation,
4
+ * the eligibility check, the two outputs per pick, and the preview with copy and download.
5
+ * Rendered by mount.ts inside a shadow root.
6
+ */
7
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'preact/hooks';
8
+ import { RemapSection, pageTokenStore, remapOutput } from './remap.js';
9
+ import { CSS_VARS_FILE_NAME, STITCH_FILE_NAME, TAILWIND_V3_FILE_NAME, TAILWIND_V4_FILE_NAME, cleanSource, compareCaptures, estimatePalette, formatCapture, formatCssVariables, formatStitch, formatTailwind, formatTailwindV3, formatCompareReport, groupOf, imageColorSystem, imageFileName, mergeGroups, withInstructions } from '@luci-dev/format/capture';
10
+ import { addToBasket, exportBasket, exportItem, mergeInBasket, noteInBasket, removeFromBasket, renameInBasket, sourceLabel } from './basket.js';
11
+ import { manualState } from '../states.js';
12
+ import { elementName } from '../naming.js';
13
+ import { LUCI_UI_ATTRIBUTE } from '../dom.js';
14
+ import { elementAt, eligibilityOf, eventTarget, firstChildOf, hoverLabel, parentOf, scrollableAncestor } from './picker.js';
15
+ import { ButtonSpinner, Loading, nextPaint } from './loading.js';
16
+ import { ModeSwitch } from './modeSwitch.js';
17
+ import { Button, COPY, EmptyState, Icon, IconBasket, IconCheck, IconClose, IconColour, IconComponent, IconCopy, IconDownload, IconInfo, IconPage, IconSpacing, IconSuccess, IconText, LUCI_REPO_URL, Mascot, RepoButton, Select, useShortcuts } from '@luci-dev/ui';
18
+ import { AppearanceControls, LuciLogo, useUiPrefs } from './theme.js';
19
+ import { DevSettingsPanel } from './devSettings.js';
20
+ import { zip } from './zip.js';
21
+ import { CheckResultPanel, DesignChooser } from './check.js';
22
+ import { ALL_SPACING, TOOLS, captureComponent, checkAgainst, readResponsive, capturePageInSteps, captureSection, captureDistance, readComponentStates, restingValues, stateTargets, captureOne, capturePixel, captureSystem, liveSnapshot, spacingChoices } from './tools.js';
23
+ /** The check being watched, kept for this tab so a reload picks it up again (v0.4). */
24
+ const AUTO_CHECK_KEY = 'luci.autoCheck';
25
+ const clamp = (v, min, max) => Math.max(min, Math.min(v, Math.max(min, max)));
26
+ /** Keep at least this much of the window between the dragged bar and its edges. */
27
+ const EDGE = 8;
28
+ /** "Save to project", then where it went (or why not). */
29
+ function SaveButton(props) {
30
+ const [state, setState] = useState({});
31
+ const run = async () => {
32
+ setState({ busy: true });
33
+ try {
34
+ const r = await props.save();
35
+ setState({ done: `${r.replaced ? 'Replaced' : 'Saved'} ${r.path}` });
36
+ }
37
+ catch (err) {
38
+ setState({ error: err instanceof Error ? err.message : String(err) });
39
+ }
40
+ };
41
+ const label = props.projectName ? `Save to ${props.projectName}` : 'Save to project';
42
+ const title = props.projectName
43
+ ? `Into ${props.projectName}/.luci/design/, where your agent reads it`
44
+ : "Into the project's .luci/design/, where your agent reads it";
45
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-action": "save-to-project", disabled: state.busy, title: title, onClick: () => void run(), children: state.busy ? _jsxs(_Fragment, { children: [_jsx(ButtonSpinner, {}), "Saving\u2026"] }) : label }), state.done && _jsx("span", { class: "dim", "data-part": "saved", children: state.done }), state.error && _jsx("span", { class: "error", "data-part": "save-error", children: state.error })] }));
46
+ }
47
+ /**
48
+ * "Make it a rule" (v0.3.2): the capture is saved into the project, then a rule pointing at it is
49
+ * proposed in .luci/memory/proposed/; the person keeps it by moving the line into rules.md.
50
+ */
51
+ function RuleButton(props) {
52
+ const [state, setState] = useState({});
53
+ const run = async () => {
54
+ setState({ busy: true });
55
+ try {
56
+ setState({ done: await props.make() });
57
+ }
58
+ catch (err) {
59
+ setState({ error: err instanceof Error ? err.message : String(err) });
60
+ }
61
+ };
62
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "data-action": "make-rule", disabled: state.busy || Boolean(state.done), title: "Save it into the project and propose a rule for .luci/rules.md that points at it; you review the rule before it counts", onClick: () => void run(), children: state.busy ? _jsxs(_Fragment, { children: [_jsx(ButtonSpinner, {}), "Proposing\u2026"] }) : state.done ? 'Rule proposed' : 'Make it a rule' }), state.error && _jsx("span", { class: "error", "data-part": "rule-error", children: state.error }), state.done && (_jsxs("div", { class: "stack rule", "data-part": "rule", children: [_jsxs("span", { class: "dim", children: [state.done.existed ? 'This rule is already waiting for your review' : 'Proposed for your review', " in ", _jsx("code", { children: state.done.path }), " (the capture is saved too). To keep it, move this line into ", _jsx("code", { children: ".luci/rules.md" }), "; Luci never edits rules.md itself."] }), _jsx("code", { "data-part": "rule-text", children: state.done.rule })] }))] }));
63
+ }
64
+ const STATE_ORDER = ['hover', 'focus', 'focus-visible', 'active', 'disabled'];
65
+ /** The "Capture by hand" choice that walks through every state Luci could not read. */
66
+ const ALL_MISSING = 'all-missing';
67
+ /** A state Luci checked through the browser and found no change in (not a gap to fill by hand). */
68
+ const checked = (s) => !s.detected && (s.method === 'forced' || s.method === 'pointer' || s.method === 'attribute');
69
+ /** States Luci could not be sure about. Disabled cannot be set by hand, so the guided walk skips it. */
70
+ const missingStates = (states) => states.filter(s => !s.detected && !checked(s) && s.state !== 'disabled').map(s => s.state);
71
+ /** How to put a component in each state, shown during the countdown. */
72
+ const STATE_HOW = {
73
+ hover: 'point at it',
74
+ focus: 'click into it, or Tab to it',
75
+ 'focus-visible': 'Tab to it',
76
+ active: 'press and hold it',
77
+ disabled: 'disable it'
78
+ };
79
+ const STATE_SECONDS = 3;
80
+ const DRAG_PX = 6;
81
+ /** What to do with each tool, shown under the bar while it is picking. */
82
+ export const TOOL_HINTS = {
83
+ component: 'Click a button, card, link or field.',
84
+ text: 'Click any text.',
85
+ color: 'Click an element. Or switch to Pixel for any spot.',
86
+ spacing: 'Click for padding, margin and gap. Drag between two elements to measure.'
87
+ };
88
+ /** What each output gives, shown with the two buttons after a pick. */
89
+ export const OUTPUT_HINTS = {
90
+ component: { one: 'its parts, tokens and states', system: 'it, plus every variant on the page' },
91
+ text: { one: 'this text style', system: 'every text style, grouped by role' },
92
+ color: { one: 'this colour and where it is used', system: 'every colour, grouped by role' },
93
+ spacing: { one: 'its padding, margin and gap, or one value', system: 'the page\'s scale, base unit and outliers' }
94
+ };
95
+ /** "This section" (v0.2), for the Component tool. */
96
+ export const SECTION_HINT = 'its layout, plus one file per kind of component in it. ↑ Wider takes the whole section';
97
+ /** Pixel mode's loupe: 15 × 15 pixels around the pointer, each drawn 8 px. */
98
+ const LOUPE_CELLS = 15;
99
+ const LOUPE_ZOOM = 8;
100
+ const LOUPE_PX = LOUPE_CELLS * LOUPE_ZOOM;
101
+ function Loupe(props) {
102
+ const ref = useRef(null);
103
+ useLayoutEffect(() => {
104
+ const c = ref.current;
105
+ const g = c?.getContext('2d');
106
+ if (!c || !g)
107
+ return;
108
+ c.width = LOUPE_PX;
109
+ c.height = LOUPE_PX;
110
+ g.imageSmoothingEnabled = false;
111
+ const half = Math.floor(LOUPE_CELLS / 2);
112
+ const sx = Math.floor(props.x * props.shot.scale) - half;
113
+ const sy = Math.floor(props.y * props.shot.scale) - half;
114
+ g.clearRect(0, 0, LOUPE_PX, LOUPE_PX);
115
+ g.drawImage(props.shot.ctx.canvas, sx, sy, LOUPE_CELLS, LOUPE_CELLS, 0, 0, LOUPE_PX, LOUPE_PX);
116
+ // Frame the picked pixel in whichever of Charcoal or Muzzle White stands out on it
117
+ const [r, gr, b] = [1, 3, 5].map(i => parseInt(props.hex.slice(i, i + 2), 16));
118
+ const light = 0.2126 * r + 0.7152 * gr + 0.0722 * b > 140;
119
+ g.lineWidth = 2;
120
+ g.strokeStyle = getComputedStyle(c).getPropertyValue(light ? '--luci-color-muzzle-900' : '--luci-color-muzzle-50').trim();
121
+ g.strokeRect(half * LOUPE_ZOOM + 1, half * LOUPE_ZOOM + 1, LOUPE_ZOOM - 2, LOUPE_ZOOM - 2);
122
+ }, [props.x, props.y, props.hex, props.shot]);
123
+ return _jsx("canvas", { ref: ref, class: "loupe", "data-part": "pixel-loupe", "aria-hidden": "true", style: { left: `${props.left}px`, top: `${props.top}px` } });
124
+ }
125
+ /** The toolbar's single-key shortcuts (in each tooltip; the menu lists them under Keys). */
126
+ export const KEYS = { component: 'V', text: 'T', color: 'C', spacing: 'S', page: 'P', check: 'K', basket: 'B', menu: 'M' };
127
+ /** Each tool's icon in the toolbar (brand/luci-icons.json). */
128
+ const TOOL_ICONS = { component: IconComponent, text: IconText, color: IconColour, spacing: IconSpacing };
129
+ /** Luci's pose in each tool's hint (brand/BRAND.md section 5, tool table). Check uses "compare". */
130
+ export const TOOL_POSES = { component: 'press', text: 'read', color: 'swatch', spacing: 'measure' };
131
+ const px = (v) => parseFloat(v) || 0;
132
+ function entryFor(live, el) {
133
+ // Elements the snapshot skips (script, br...) are picked through their parent
134
+ for (let n = el; n; n = parentOf(n)) {
135
+ const e = live.entryFor(n);
136
+ if (e)
137
+ return e;
138
+ }
139
+ return null;
140
+ }
141
+ export function Toolbar(props) {
142
+ const { doc } = props;
143
+ const win = doc.defaultView ?? window;
144
+ const [tool, setTool] = useState(null);
145
+ const [picking, setPicking] = useState(false);
146
+ const [candidate, setCandidate] = useState(null);
147
+ const [notice, setNotice] = useState(null);
148
+ const [picked, setPicked] = useState(null);
149
+ const [result, setResult] = useState(null);
150
+ const [choice, setChoice] = useState(ALL_SPACING);
151
+ const [settings, setSettings] = useState(props.settings);
152
+ const useDebugger = settings.useDebugger ?? true;
153
+ const forcedStatesReader = useDebugger ? props.readForcedStates : undefined;
154
+ const viewportWidthSetter = useDebugger ? props.setViewportWidth : undefined;
155
+ const [copied, setCopied] = useState(false);
156
+ const [dropperOpen, setDropperOpen] = useState(false);
157
+ const [basketOpen, setBasketOpen] = useState(false);
158
+ const [settingsOpen, setSettingsOpen] = useState(false);
159
+ const [uiPrefs, setUiPrefs] = useUiPrefs(doc);
160
+ const [, setTick] = useState(0);
161
+ // A movable bar (the extension): dragged by its own background or Luci's head, then kept where it was dropped
162
+ const shellRef = useRef(null);
163
+ const barRef = useRef(null);
164
+ const moveRef = useRef(null);
165
+ const justMoved = useRef(false);
166
+ const [moving, setMoving] = useState(null);
167
+ const trail = useRef([]);
168
+ const drag = useRef(null);
169
+ const lastPointer = useRef(null);
170
+ // Page listeners read these, not render-time values: they must see a key press's effect at once
171
+ const candidateRef = useRef(null);
172
+ const settingsRef = useRef(settings);
173
+ settingsRef.current = settings;
174
+ const aim = (el) => {
175
+ candidateRef.current = el;
176
+ setCandidate(el);
177
+ };
178
+ // The click that follows a pick (or drag) must not reach the page: picking a link must not follow it
179
+ const swallowClickUntil = useRef(0);
180
+ useLayoutEffect(() => {
181
+ const swallow = (e) => {
182
+ if (performance.now() < swallowClickUntil.current && eventTarget(e)) {
183
+ e.preventDefault();
184
+ e.stopPropagation();
185
+ swallowClickUntil.current = 0;
186
+ }
187
+ };
188
+ doc.addEventListener('click', swallow, true);
189
+ doc.addEventListener('auxclick', swallow, true);
190
+ return () => {
191
+ doc.removeEventListener('click', swallow, true);
192
+ doc.removeEventListener('auxclick', swallow, true);
193
+ };
194
+ }, []);
195
+ // Responsive (v0.3.4): read at other widths on request; kept on this pick's later files (a state captured by hand)
196
+ const responsiveRef = useRef(null);
197
+ const withResponsive = (o) => {
198
+ const r = responsiveRef.current;
199
+ const c = o.capture;
200
+ if (!r || (c.meta.scope !== 'component' && c.meta.scope !== 'section') || c.meta.selector !== r.selector)
201
+ return o;
202
+ return { ...o, capture: { ...c, responsive: r.data } };
203
+ };
204
+ const show = (given) => {
205
+ const r = given.ok ? { ok: true, output: withResponsive(given.output) } : given;
206
+ setResult(r);
207
+ setCopied(false);
208
+ setAdded(false);
209
+ setBasketOpen(false);
210
+ setSettingsOpen(false);
211
+ setEdited(null);
212
+ setViewFile(null);
213
+ if (r.ok)
214
+ props.onOutput?.(r.output);
215
+ };
216
+ // The Component tool reads states before showing its file; a state can also be captured by hand after
217
+ const [busy, setBusy] = useState(null);
218
+ const [stateNote, setStateNote] = useState(null);
219
+ const [componentCtx, setComponentCtx] = useState(null);
220
+ const [manualTarget, setManualTarget] = useState(ALL_MISSING);
221
+ const [countdown, setCountdown] = useState(null);
222
+ const [capturing, setCapturing] = useState(null);
223
+ // Bumped to cancel a running countdown (a new pick, the whole page, closing)
224
+ const captureRun = useRef(0);
225
+ // While states are captured by hand the user presses and clicks the component: until this time,
226
+ // clicks on the page do nothing (a link or submit button must not navigate away)
227
+ const guardUntil = useRef(0);
228
+ useLayoutEffect(() => {
229
+ const guard = (e) => {
230
+ if (performance.now() > guardUntil.current || !eventTarget(e))
231
+ return;
232
+ if (e.type === 'click' || e.type === 'auxclick' || e.type === 'submit')
233
+ e.preventDefault();
234
+ e.stopImmediatePropagation();
235
+ };
236
+ const types = ['pointerdown', 'pointerup', 'mousedown', 'mouseup', 'click', 'auxclick', 'submit'];
237
+ for (const t of types)
238
+ win.addEventListener(t, guard, true);
239
+ return () => { for (const t of types)
240
+ win.removeEventListener(t, guard, true); };
241
+ }, []);
242
+ /** An unexpected error: said in the panel, and logged in full to the page's console for a bug report. */
243
+ const failed = (err) => {
244
+ console.error('Luci:', err);
245
+ // A format check lists its problems as JSON: say the first one only
246
+ const issue = err.issues?.[0];
247
+ const reason = issue ? `${issue.path.map(String).join('.')}: ${issue.message}` : err instanceof Error ? err.message : String(err);
248
+ show({ ok: false, message: `Luci could not read this page (${reason.slice(0, 200)}). The details are in the browser console (F12).` });
249
+ };
250
+ // The design check (v0.3): choose a design, pick the built component, see the differences
251
+ const [checkOpen, setCheckOpen] = useState(false);
252
+ const [checkDesign, setCheckDesign] = useState(null);
253
+ const [checkOutcome, setCheckOutcome] = useState(null);
254
+ /*
255
+ * Automatic design check (v0.4): after a check, Luci watches the page and checks the built component
256
+ * again whenever it changes (an edit reloading it, hot module replacement), says what changed, and
257
+ * sends each run to the project (dev toolbar) where the agent reads it. The watch survives a reload of
258
+ * the tab. Its own reading never counts as a change.
259
+ */
260
+ const [watchCheck, setWatchCheck] = useState(Boolean(props.autoCheck));
261
+ const [checkVersion, setCheckVersion] = useState(0);
262
+ const [autoNote, setAutoNote] = useState(null);
263
+ const checkingNow = useRef(false);
264
+ const checkRun = useRef(0);
265
+ const session = (() => { try {
266
+ return win.sessionStorage;
267
+ }
268
+ catch {
269
+ return null;
270
+ } })();
271
+ const forgetWatch = () => { try {
272
+ session?.removeItem(AUTO_CHECK_KEY);
273
+ }
274
+ catch { /* storage blocked */ } };
275
+ const afterCheck = async (outcome, design, selector) => {
276
+ setCheckOutcome(outcome);
277
+ setCheckVersion(v => v + 1);
278
+ const res = await Promise.resolve(props.onCheckRun?.({
279
+ design: design.file, label: design.label, selector, page: cleanSource(doc.location.href), checkedAt: new Date().toISOString(),
280
+ matches: outcome.result.matches.length,
281
+ differences: outcome.result.differences.map(d => ({ kind: d.kind, part: d.part, ...(d.state ? { state: d.state } : {}), property: d.property, expected: d.expected, actual: d.actual, comment: d.comment, priority: d.priority }))
282
+ })).catch(() => undefined);
283
+ if (watchCheck) {
284
+ try {
285
+ session?.setItem(AUTO_CHECK_KEY, JSON.stringify({ selector, design, path: doc.location.pathname }));
286
+ }
287
+ catch { /* storage blocked */ }
288
+ }
289
+ return res;
290
+ };
291
+ const runCheck = async () => {
292
+ if (!picked || !checkDesign)
293
+ return;
294
+ setBusy('Reading the built component and its states, then comparing it with the design…');
295
+ setAutoNote(null);
296
+ checkingNow.current = true;
297
+ try {
298
+ const outcome = await checkAgainst(picked.live, picked.entry, checkDesign, forcedStatesReader);
299
+ if (outcome.ok)
300
+ await afterCheck(outcome, checkDesign, picked.entry.selector);
301
+ else
302
+ show(outcome);
303
+ }
304
+ catch (err) {
305
+ failed(err);
306
+ }
307
+ finally {
308
+ checkingNow.current = false;
309
+ setBusy(null);
310
+ }
311
+ };
312
+ /** Check the same built component again (it may be a new node after a reload of the component). */
313
+ const recheck = async () => {
314
+ if (!checkDesign || !checkOutcome || !picked)
315
+ return;
316
+ const run = ++checkRun.current;
317
+ const selector = picked.entry.selector;
318
+ const el = doc.querySelector(selector);
319
+ if (!el) {
320
+ setAutoNote('The built component is not on the page right now. Luci checks again when it is back.');
321
+ return;
322
+ }
323
+ checkingNow.current = true;
324
+ try {
325
+ const live = liveSnapshot(doc);
326
+ const entry = entryFor(live, el);
327
+ if (!entry)
328
+ return;
329
+ const before = checkOutcome.result.differences.length;
330
+ const outcome = await checkAgainst(live, entry, checkDesign, forcedStatesReader);
331
+ if (run !== checkRun.current || !outcome.ok)
332
+ return;
333
+ setPicked(p => (p ? { ...p, el, entry, live } : p));
334
+ const res = await afterCheck(outcome, checkDesign, selector);
335
+ const n = outcome.result.differences.length;
336
+ const time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
337
+ const resolvedMsg = res && typeof res === 'object' && 'resolved' in res && Array.isArray(res.resolved) && res.resolved.length
338
+ ? ` ${res.resolved.length} feedback note${res.resolved.length === 1 ? '' : 's'} resolved automatically (${res.resolved.join(', ')}).`
339
+ : '';
340
+ setAutoNote(`Checked again at ${time}: ${n ? `${n} difference${n === 1 ? '' : 's'}` : 'it matches the design'}${n !== before ? ` (was ${before})` : ''}.${resolvedMsg}`);
341
+ }
342
+ catch {
343
+ // A page in the middle of reloading: the next change checks again
344
+ }
345
+ finally {
346
+ checkingNow.current = false;
347
+ }
348
+ };
349
+ useEffect(() => {
350
+ if (!watchCheck || !checkOutcome || !checkDesign || !picked || typeof MutationObserver === 'undefined')
351
+ return;
352
+ let timer;
353
+ const ours = (n) => {
354
+ const el = n instanceof Element ? n : n.parentElement;
355
+ return Boolean(el?.closest(`[${LUCI_UI_ATTRIBUTE}]`));
356
+ };
357
+ const observer = new MutationObserver(records => {
358
+ // Luci's own reading (a state set for a moment) and Luci's own UI never count
359
+ if (checkingNow.current || records.every(r => ours(r.target)))
360
+ return;
361
+ clearTimeout(timer);
362
+ timer = setTimeout(() => { void recheck(); }, 700);
363
+ });
364
+ observer.observe(doc.documentElement, { subtree: true, childList: true, attributes: true, characterData: true });
365
+ return () => { observer.disconnect(); clearTimeout(timer); };
366
+ }, [watchCheck, checkVersion, checkDesign, picked?.entry.selector]);
367
+ // After a reload of the tab: pick up the check that was being watched, once the component is on the page
368
+ useEffect(() => {
369
+ let saved = null;
370
+ try {
371
+ saved = JSON.parse(session?.getItem(AUTO_CHECK_KEY) ?? 'null');
372
+ }
373
+ catch {
374
+ saved = null;
375
+ }
376
+ if (!saved || !props.autoCheck || saved.path !== doc.location.pathname)
377
+ return;
378
+ const watch = saved;
379
+ let tries = 0;
380
+ const timer = setInterval(() => {
381
+ const el = doc.querySelector(watch.selector);
382
+ if (!el && ++tries < 40)
383
+ return;
384
+ clearInterval(timer);
385
+ if (!el) {
386
+ forgetWatch();
387
+ return;
388
+ }
389
+ const live = liveSnapshot(doc);
390
+ const entry = entryFor(live, el);
391
+ if (!entry)
392
+ return;
393
+ setTool('component');
394
+ setCheckDesign(watch.design);
395
+ setPicked({ el, entry, live, eligibility: eligibilityOf(el) });
396
+ checkingNow.current = true;
397
+ void checkAgainst(live, entry, watch.design, forcedStatesReader)
398
+ .then(outcome => { if (outcome.ok) {
399
+ afterCheck(outcome, watch.design, watch.selector);
400
+ setAutoNote('Checked again after the page reloaded.');
401
+ } })
402
+ .finally(() => { checkingNow.current = false; });
403
+ }, 250);
404
+ return () => clearInterval(timer);
405
+ }, []);
406
+ const produce = async (system, section = false) => {
407
+ if (!picked || !tool)
408
+ return;
409
+ if (checkDesign) {
410
+ await runCheck();
411
+ return;
412
+ }
413
+ if (section) {
414
+ // "This section": the section file plus its component files (v0.2)
415
+ setComponentCtx(null);
416
+ setStateNote(null);
417
+ setBusy('Reading the section: its layout, then each kind of component in it…');
418
+ await nextPaint(win);
419
+ try {
420
+ show(captureSection(picked.live, picked.entry, settings));
421
+ }
422
+ catch (err) {
423
+ failed(err);
424
+ }
425
+ finally {
426
+ setBusy(null);
427
+ }
428
+ return;
429
+ }
430
+ if (tool !== 'component') {
431
+ setComponentCtx(null);
432
+ try {
433
+ show(system ? captureSystem(tool, picked.live, settings, picked.entry) : captureOne(tool, picked.live, picked.entry, settings, choice));
434
+ }
435
+ catch (err) {
436
+ failed(err);
437
+ }
438
+ return;
439
+ }
440
+ if (system && (picked.entry.tag === 'body' || picked.entry.tag === 'html')) {
441
+ try {
442
+ show(captureSystem(tool, picked.live, settings, picked.entry));
443
+ }
444
+ catch (err) {
445
+ failed(err);
446
+ }
447
+ return;
448
+ }
449
+ setBusy('Reading hover, focus, active and disabled…');
450
+ try {
451
+ const rest = restingValues(stateTargets(picked.live, picked.entry));
452
+ const { states, note } = await readComponentStates(picked.live, picked.entry, forcedStatesReader);
453
+ setStateNote(note);
454
+ setComponentCtx({ live: picked.live, entry: picked.entry, system, states, rest });
455
+ setManualTarget(missingStates(states).length ? ALL_MISSING : 'hover');
456
+ show(captureComponent(picked.live, picked.entry, settings, { system, states }));
457
+ }
458
+ catch (err) {
459
+ failed(err);
460
+ }
461
+ finally {
462
+ setBusy(null);
463
+ }
464
+ };
465
+ /** Capture by hand: one state, or every missing one in turn, each after a short countdown. */
466
+ const captureCurrentState = () => {
467
+ if (!componentCtx)
468
+ return;
469
+ const ctx = componentCtx;
470
+ const queue = manualTarget === ALL_MISSING ? missingStates(ctx.states) : [manualTarget];
471
+ if (!queue.length)
472
+ return;
473
+ const run = ++captureRun.current;
474
+ const targets = stateTargets(ctx.live, ctx.entry);
475
+ let states = ctx.states;
476
+ const step = (i) => {
477
+ if (run !== captureRun.current)
478
+ return;
479
+ if (i >= queue.length) {
480
+ setCountdown(null);
481
+ setCapturing(null);
482
+ // The release after "press and hold" comes a moment later
483
+ guardUntil.current = performance.now() + 1500;
484
+ setManualTarget(missingStates(states).length ? ALL_MISSING : 'hover');
485
+ return;
486
+ }
487
+ const state = queue[i];
488
+ let n = STATE_SECONDS;
489
+ setCapturing({ state, index: i + 1, total: queue.length });
490
+ setCountdown(n);
491
+ const tick = () => {
492
+ if (run !== captureRun.current)
493
+ return;
494
+ guardUntil.current = performance.now() + 60_000;
495
+ n -= 1;
496
+ if (n > 0) {
497
+ setCountdown(n);
498
+ setTimeout(tick, 1000);
499
+ return;
500
+ }
501
+ const captured = manualState(state, targets, ctx.rest);
502
+ states = [...states.filter(s => s.state !== state), captured].sort((a, b) => STATE_ORDER.indexOf(a.state) - STATE_ORDER.indexOf(b.state));
503
+ setComponentCtx({ ...ctx, states });
504
+ show(captureComponent(ctx.live, ctx.entry, settingsRef.current, { system: ctx.system, states }));
505
+ step(i + 1);
506
+ };
507
+ guardUntil.current = performance.now() + 60_000;
508
+ setTimeout(tick, 1000);
509
+ };
510
+ step(0);
511
+ };
512
+ const cancelCapture = () => {
513
+ captureRun.current++;
514
+ guardUntil.current = 0;
515
+ setCountdown(null);
516
+ setCapturing(null);
517
+ };
518
+ // "Whole page": the page's systems and every kind of component on it, in one file
519
+ const [pageBusy, setPageBusy] = useState(false);
520
+ const [pageStep, setPageStep] = useState(null);
521
+ // Bumped when another action starts, so a page read still running does not show its result over it
522
+ const pageRun = useRef(0);
523
+ const [wholePage, setWholePage] = useState(false);
524
+ const endCheck = () => {
525
+ setCheckOpen(false);
526
+ setCheckDesign(null);
527
+ setCheckOutcome(null);
528
+ setAutoNote(null);
529
+ forgetWatch();
530
+ };
531
+ /** The bar's "Check": choose the design first. */
532
+ const openCheck = () => {
533
+ cancelCapture();
534
+ pageRun.current++;
535
+ setPageBusy(false);
536
+ setWholePage(false);
537
+ setPicking(false);
538
+ setPicked(null);
539
+ setResult(null);
540
+ setNotice(null);
541
+ setBasketOpen(false);
542
+ setSettingsOpen(false);
543
+ setPixelMode(false);
544
+ aim(null);
545
+ setCheckOutcome(null);
546
+ setCheckOpen(true);
547
+ // The basket's components can be designs
548
+ if (store)
549
+ void store.load().then(setBasket);
550
+ };
551
+ const chooseDesign = (d) => {
552
+ setCheckDesign(d);
553
+ startPicking('component');
554
+ };
555
+ const captureWholePage = () => {
556
+ cancelCapture();
557
+ setTool(null);
558
+ setPicking(false);
559
+ setPicked(null);
560
+ setResult(null);
561
+ setNotice(null);
562
+ setComponentCtx(null);
563
+ setStateNote(null);
564
+ setBasketOpen(false);
565
+ setSettingsOpen(false);
566
+ setPixelMode(false);
567
+ setPixelHover(null);
568
+ setInstructions('');
569
+ endCheck();
570
+ aim(null);
571
+ setWholePage(true);
572
+ setPageBusy(true);
573
+ setPageStep(null);
574
+ // In steps, each painted before its work, so the loader says where Luci is
575
+ const run = ++pageRun.current;
576
+ void capturePageInSteps(doc, settingsRef.current, {
577
+ onStep: s => { if (run === pageRun.current)
578
+ setPageStep(s); },
579
+ pause: () => nextPaint(win)
580
+ }).then(r => { if (run === pageRun.current)
581
+ show(r); }, err => { if (run === pageRun.current)
582
+ failed(err); })
583
+ .finally(() => { if (run === pageRun.current) {
584
+ setPageBusy(false);
585
+ setPageStep(null);
586
+ } });
587
+ };
588
+ const startPicking = (t) => {
589
+ // Focus leaves the tool button, so Enter picks instead of pressing the button again
590
+ const active = (doc.querySelector('luci-toolbar')?.shadowRoot?.activeElement ?? null);
591
+ active?.blur();
592
+ cancelCapture();
593
+ pageRun.current++;
594
+ setPageBusy(false);
595
+ setImageMode(false);
596
+ setPageStep(null);
597
+ setWholePage(false);
598
+ // A design check keeps its design while picking the built component; its last result goes
599
+ setCheckOutcome(null);
600
+ responsiveRef.current = null;
601
+ setWidthNote(null);
602
+ setCheckOpen(false);
603
+ setTool(t);
604
+ setPicking(true);
605
+ setPicked(null);
606
+ setResult(null);
607
+ setNotice(null);
608
+ setComponentCtx(null);
609
+ setStateNote(null);
610
+ setCountdown(null);
611
+ setBasketOpen(false);
612
+ setSettingsOpen(false);
613
+ setPixelMode(false);
614
+ setPixelHover(null);
615
+ setInstructions('');
616
+ aim(null);
617
+ lastPointer.current = null;
618
+ trail.current = [];
619
+ };
620
+ const select = (el) => {
621
+ const elig = eligibilityOf(el);
622
+ if (elig.status === 'blocked') {
623
+ setNotice(elig.reason);
624
+ return;
625
+ }
626
+ const live = liveSnapshot(doc);
627
+ const entry = entryFor(live, el);
628
+ if (!entry)
629
+ return;
630
+ responsiveRef.current = null;
631
+ setWidthNote(null);
632
+ // Widening while hovering carries over, so ↓ can walk back down after the click
633
+ pickedTrail.current = [...trail.current];
634
+ setPicked({ el, entry, live, eligibility: elig });
635
+ setPicking(false);
636
+ setNotice(null);
637
+ setChoice(ALL_SPACING);
638
+ setResult(null);
639
+ };
640
+ // After a click the selection stays, and ↑ ↓ (or the Wider / Narrower buttons) change it before an output is chosen
641
+ const pickedTrail = useRef([]);
642
+ const reselect = (el) => {
643
+ if (!picked)
644
+ return;
645
+ const entry = entryFor(picked.live, el);
646
+ if (!entry)
647
+ return;
648
+ setPicked({ ...picked, el, entry, eligibility: eligibilityOf(el) });
649
+ setChoice(ALL_SPACING);
650
+ };
651
+ const widerOf = (el) => { const p = parentOf(el); return p && p !== doc.documentElement ? p : null; };
652
+ const narrowerOf = (el) => pickedTrail.current[pickedTrail.current.length - 1] ?? firstChildOf(el);
653
+ const widen = () => {
654
+ if (!picked)
655
+ return;
656
+ const p = widerOf(picked.el);
657
+ if (!p)
658
+ return;
659
+ pickedTrail.current.push(picked.el);
660
+ reselect(p);
661
+ };
662
+ const narrow = () => {
663
+ if (!picked)
664
+ return;
665
+ const c = pickedTrail.current.pop() ?? firstChildOf(picked.el);
666
+ if (c)
667
+ reselect(c);
668
+ };
669
+ const choosing = !picking && !basketOpen && !settingsOpen && Boolean(picked) && !result && !busy && !checkOutcome;
670
+ const checking = checkOpen || checkDesign !== null;
671
+ useLayoutEffect(() => {
672
+ if (!choosing)
673
+ return;
674
+ const onKey = (e) => {
675
+ const focused = e.composedPath()[0];
676
+ if (focused instanceof HTMLElement && /^(INPUT|SELECT|TEXTAREA|BUTTON)$/.test(focused.tagName) && e.key === 'Enter')
677
+ return;
678
+ if (e.key === 'ArrowUp') {
679
+ e.preventDefault();
680
+ widen();
681
+ }
682
+ else if (e.key === 'ArrowDown') {
683
+ e.preventDefault();
684
+ narrow();
685
+ }
686
+ else if (e.key === 'Enter' && picked?.eligibility.status === 'allowed') {
687
+ e.preventDefault();
688
+ void produce(false);
689
+ }
690
+ };
691
+ doc.addEventListener('keydown', onKey, true);
692
+ return () => doc.removeEventListener('keydown', onKey, true);
693
+ }, [choosing, picked]);
694
+ // The eyedropper color can come from the shell or a test
695
+ useEffect(() => {
696
+ props.registerPixelInput?.((hex) => {
697
+ const live = liveSnapshot(doc);
698
+ setTool('color');
699
+ setPicking(false);
700
+ setPicked(null);
701
+ show(capturePixel(live, hex, settings));
702
+ });
703
+ });
704
+ // While picking, a transparent layer above the page takes every pointer event (see the pick-layer
705
+ // below), so the page never sees a press or click, however its links and buttons are wired.
706
+ // These handlers get the layer's pointer positions and find the page element under them.
707
+ const pickMove = (x, y) => {
708
+ // Chrome sends a move when the layout under a still pointer changes; only real moves re-aim the picker
709
+ const last = lastPointer.current;
710
+ if (last && last.x === x && last.y === y)
711
+ return;
712
+ lastPointer.current = { x, y };
713
+ const target = elementAt(doc, x, y);
714
+ if (!target)
715
+ return;
716
+ trail.current = [];
717
+ aim(target);
718
+ };
719
+ const pickDown = (x, y) => {
720
+ const target = elementAt(doc, x, y);
721
+ if (target)
722
+ drag.current = { el: target, x, y };
723
+ };
724
+ const pickWheel = (e) => {
725
+ // The layer would stop scrolling inside the page's own scroll areas: pass the wheel on
726
+ const area = scrollableAncestor(elementAt(doc, e.clientX, e.clientY), e.deltaX, e.deltaY);
727
+ if (area) {
728
+ e.preventDefault();
729
+ area.scrollBy(e.deltaX, e.deltaY);
730
+ }
731
+ };
732
+ const pickUp = (x, y) => {
733
+ {
734
+ const target = elementAt(doc, x, y);
735
+ const start = drag.current;
736
+ drag.current = null;
737
+ if (!target || !start || !tool)
738
+ return;
739
+ const moved = Math.hypot(x - start.x, y - start.y) > DRAG_PX;
740
+ if (tool === 'spacing' && moved && target !== start.el) {
741
+ // A drag between two elements measures the distance between them (FR15)
742
+ const blocked = [start.el, target].map(eligibilityOf).find(x => x.status !== 'allowed');
743
+ if (blocked) {
744
+ setNotice('reason' in blocked ? blocked.reason : null);
745
+ return;
746
+ }
747
+ const live = liveSnapshot(doc);
748
+ const a = entryFor(live, start.el);
749
+ const b = entryFor(live, target);
750
+ if (!a || !b)
751
+ return;
752
+ setPicking(false);
753
+ setPicked(null);
754
+ show(captureDistance(live, a, b, settingsRef.current));
755
+ return;
756
+ }
757
+ // After arrow keys, a click picks what the keys aimed at
758
+ select(candidateRef.current && trail.current.length ? candidateRef.current : target);
759
+ }
760
+ };
761
+ // Keys while picking (move, pick, cancel); after scrolling, re-aim at what is now under the pointer
762
+ useLayoutEffect(() => {
763
+ if (!picking || !tool)
764
+ return;
765
+ const onKey = (e) => {
766
+ if (e.key === 'Escape') {
767
+ e.preventDefault();
768
+ setPicking(false);
769
+ aim(null);
770
+ setNotice(null);
771
+ return;
772
+ }
773
+ // While picking, arrows and Enter belong to the picker, wherever focus is, except in a form field
774
+ const focused = e.composedPath()[0];
775
+ if (focused instanceof HTMLElement && /^(INPUT|SELECT|TEXTAREA)$/.test(focused.tagName))
776
+ return;
777
+ const current = candidateRef.current;
778
+ if (!current)
779
+ return;
780
+ if (e.key === 'ArrowUp') {
781
+ // Widen to the parent; ArrowDown goes back the same way, or into the first child
782
+ const parent = parentOf(current);
783
+ if (parent && parent !== doc.documentElement) {
784
+ trail.current.push(current);
785
+ aim(parent);
786
+ }
787
+ e.preventDefault();
788
+ }
789
+ else if (e.key === 'ArrowDown') {
790
+ const child = trail.current.pop() ?? firstChildOf(current);
791
+ if (child)
792
+ aim(child);
793
+ e.preventDefault();
794
+ }
795
+ else if (e.key === 'Enter') {
796
+ e.preventDefault();
797
+ select(current);
798
+ }
799
+ };
800
+ const onScroll = () => {
801
+ const p = lastPointer.current;
802
+ if (p && !trail.current.length) {
803
+ const target = elementAt(doc, p.x, p.y);
804
+ if (target)
805
+ aim(target);
806
+ }
807
+ setTick(t => t + 1);
808
+ };
809
+ doc.addEventListener('keydown', onKey, true);
810
+ win.addEventListener('scroll', onScroll, true);
811
+ return () => {
812
+ doc.removeEventListener('keydown', onKey, true);
813
+ win.removeEventListener('scroll', onScroll, true);
814
+ };
815
+ }, [picking, tool]);
816
+ // Esc also closes the panel when not picking
817
+ useLayoutEffect(() => {
818
+ if (picking)
819
+ return;
820
+ const onKey = (e) => {
821
+ if (e.key === 'Escape' && (settingsOpen || picked || result || checkOutcome || checkOpen)) {
822
+ if (settingsOpen) {
823
+ setSettingsOpen(false);
824
+ return;
825
+ }
826
+ setPicked(null);
827
+ setResult(null);
828
+ endCheck();
829
+ }
830
+ };
831
+ doc.addEventListener('keydown', onKey, true);
832
+ return () => doc.removeEventListener('keydown', onKey, true);
833
+ }, [picking, settingsOpen, picked, result, checkOutcome, checkOpen]);
834
+ const copyTimer = useRef(undefined);
835
+ useEffect(() => () => clearTimeout(copyTimer.current), []);
836
+ const changeSettings = (next) => {
837
+ // Hand edits belong to one file format: switching it starts from the capture again
838
+ if ((next.style ?? 'luci') !== (settings.style ?? 'luci'))
839
+ setEdited(null);
840
+ setSettings(next);
841
+ setCopied(false);
842
+ props.onSettingsChange?.(next);
843
+ };
844
+ const output = result?.ok ? result.output : null;
845
+ // "Use my tokens" (v0.4): the person's tokens, and the rewrite in place (with the site's values to undo it)
846
+ const myTokens = useMemo(() => props.myTokens ?? pageTokenStore(doc), [props.myTokens]);
847
+ const [remapped, setRemapped] = useState(null);
848
+ // The user's instructions for their agent go into the file word for word; the file can also be edited
849
+ // by hand, and then copy, download and the basket use exactly the edited text
850
+ const [instructions, setInstructions] = useState('');
851
+ const [edited, setEdited] = useState(null);
852
+ const captureWithInstructions = output ? { ...output.capture, ...(instructions.trim() ? { instructions: instructions.trim() } : {}) } : null;
853
+ // The file people copy and download: Luci's tables, DESIGN.md for Google Stitch, Tailwind CSS, or CSS Variables
854
+ const isStitch = settings.style === 'stitch';
855
+ const isTailwind = settings.style === 'tailwind';
856
+ const isTailwindV3 = settings.style === 'tailwind-v3';
857
+ const isCssVars = settings.style === 'css-vars';
858
+ const isTokenExport = isTailwind || isTailwindV3 || isCssVars;
859
+ const isCustomExport = isStitch || isTokenExport;
860
+ const stitch = isStitch;
861
+ const luciMarkdown = (!isCustomExport ? edited : null) ?? (captureWithInstructions ? formatCapture(captureWithInstructions, settings) : '');
862
+ const markdown = edited ?? (captureWithInstructions
863
+ ? (isStitch
864
+ ? formatStitch([captureWithInstructions, ...(output?.files ?? []).map(f => f.capture)])
865
+ : isTailwind
866
+ ? formatTailwind([captureWithInstructions, ...(output?.files ?? []).map(f => f.capture)])
867
+ : isTailwindV3
868
+ ? formatTailwindV3([captureWithInstructions, ...(output?.files ?? []).map(f => f.capture)])
869
+ : isCssVars
870
+ ? formatCssVariables([captureWithInstructions, ...(output?.files ?? []).map(f => f.capture)])
871
+ : luciMarkdown)
872
+ : '');
873
+ const outputName = output
874
+ ? (isStitch
875
+ ? STITCH_FILE_NAME
876
+ : isTailwind
877
+ ? TAILWIND_V4_FILE_NAME
878
+ : isTailwindV3
879
+ ? TAILWIND_V3_FILE_NAME
880
+ : isCssVars
881
+ ? CSS_VARS_FILE_NAME
882
+ : output.fileName)
883
+ : '';
884
+ const changeInstructions = (text) => {
885
+ setInstructions(text);
886
+ setCopied(false);
887
+ // Edited text keeps the edits; only its instructions section follows the box
888
+ if (edited !== null)
889
+ setEdited(withInstructions(edited, text));
890
+ };
891
+ const copyText = async (text) => {
892
+ try {
893
+ await win.navigator.clipboard.writeText(text);
894
+ }
895
+ catch {
896
+ // Without clipboard permission: the classic copy through a selected text area
897
+ const area = doc.createElement('textarea');
898
+ area.value = text;
899
+ area.setAttribute('data-luci-ui', '');
900
+ doc.body.appendChild(area);
901
+ area.select();
902
+ doc.execCommand('copy');
903
+ area.remove();
904
+ }
905
+ setCopied(true);
906
+ clearTimeout(copyTimer.current);
907
+ copyTimer.current = setTimeout(() => setCopied(false), 1400);
908
+ };
909
+ const downloadText = (fileName, text) => {
910
+ const mime = fileName.endsWith('.css')
911
+ ? 'text/css'
912
+ : fileName.endsWith('.js')
913
+ ? 'text/javascript'
914
+ : 'text/markdown';
915
+ const url = URL.createObjectURL(new Blob([text], { type: mime }));
916
+ const a = doc.createElement('a');
917
+ a.href = url;
918
+ a.download = fileName;
919
+ a.setAttribute('data-luci-ui', '');
920
+ doc.body.appendChild(a);
921
+ a.click();
922
+ a.remove();
923
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
924
+ };
925
+ const [widthBusy, setWidthBusy] = useState(null);
926
+ const [widthNote, setWidthNote] = useState(null);
927
+ /** "How it changes by width": read at the site's own breakpoints, then add Responsive to the file. */
928
+ const addResponsive = async () => {
929
+ if (!picked || !output)
930
+ return;
931
+ const kind = output.capture.meta.scope === 'section' ? 'section' : 'component';
932
+ const onWidth = (w, i, n) => setWidthBusy(`Reading it at ${w}px (${i + 1} of ${n})…`);
933
+ setWidthNote(null);
934
+ setWidthBusy('Finding the widths in the site\'s media queries…');
935
+ await nextPaint(win);
936
+ try {
937
+ let data;
938
+ let note = null;
939
+ try {
940
+ data = await readResponsive(picked.live, picked.entry, kind, { ...(viewportWidthSetter ? { setWidth: viewportWidthSetter } : {}), onWidth });
941
+ }
942
+ catch (err) {
943
+ if (!viewportWidthSetter)
944
+ throw err;
945
+ // The window could not be resized (the debugger was refused): a frame of the page instead
946
+ data = await readResponsive(picked.live, picked.entry, kind, { onWidth });
947
+ note = `The window could not be resized (${err instanceof Error ? err.message : String(err)}), so Luci read the page in a hidden frame instead.`;
948
+ }
949
+ responsiveRef.current = { selector: output.capture.meta.selector, data };
950
+ show({ ok: true, output });
951
+ setWidthNote({ text: note ?? `${data.changes.length ? `${data.changes.length} change${data.changes.length === 1 ? '' : 's'}` : 'Nothing changes'} at ${data.widths.map(w => `${w}px`).join(', ')}: see Responsive in the file.` });
952
+ }
953
+ catch (err) {
954
+ setWidthNote({ error: true, text: `Luci could not read other widths: ${err instanceof Error ? err.message : String(err)}.` });
955
+ }
956
+ finally {
957
+ setWidthBusy(null);
958
+ }
959
+ };
960
+ const copy = () => copyText(markdown);
961
+ const download = () => { if (output)
962
+ downloadText(outputName, markdown); };
963
+ // A section (v0.2): its component files follow the unit and color settings too
964
+ const [viewFile, setViewFile] = useState(null);
965
+ const sectionFiles = (output?.files ?? []).map(f => ({ fileName: f.fileName, markdown: formatCapture(f.capture, settings), capture: f.capture }));
966
+ const downloadZip = () => {
967
+ if (!output)
968
+ return;
969
+ const bytes = zip([{ name: output.fileName, data: markdown }, ...sectionFiles.map(f => ({ name: f.fileName, data: f.markdown }))]);
970
+ const url = URL.createObjectURL(new Blob([bytes], { type: 'application/zip' }));
971
+ const a = doc.createElement('a');
972
+ a.href = url;
973
+ a.download = output.fileName.replace(/\.design\.md$/, '.zip');
974
+ a.setAttribute('data-luci-ui', '');
975
+ doc.body.appendChild(a);
976
+ a.click();
977
+ a.remove();
978
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
979
+ };
980
+ /** Save to project: the file, and a section's component files with it. */
981
+ const saveAll = async () => {
982
+ // The project keeps Luci's tables (the design check and the agent's tools read them), whatever is copied
983
+ const first = await props.saveToProject(output.fileName, luciMarkdown);
984
+ for (const f of sectionFiles)
985
+ await props.saveToProject(f.fileName, f.markdown);
986
+ return sectionFiles.length ? { ...first, path: `${first.path} and ${sectionFiles.length} component file${sectionFiles.length === 1 ? '' : 's'}` } : first;
987
+ };
988
+ // The basket (FR18, FR19): kept by the shell's store, so it survives pages and sites
989
+ const [basket, setBasket] = useState([]);
990
+ const [basketExport, setBasketExport] = useState(null);
991
+ // Compare mode (v0.4): two basket items picked, and their comparison when asked
992
+ const [compareIds, setCompareIds] = useState([]);
993
+ const [comparison, setComparison] = useState(null);
994
+ const compareItems = (() => {
995
+ const picked2 = compareIds.map(id => basket.find(i => i.id === id)).filter((i) => Boolean(i));
996
+ return picked2.length === 2 ? [picked2[0], picked2[1]] : null;
997
+ })();
998
+ const [added, setAdded] = useState(false);
999
+ const [confirmClear, setConfirmClear] = useState(false);
1000
+ const store = props.basket;
1001
+ // Until the stored basket has loaded, changes start from the stored items, never from an empty list
1002
+ const basketLoaded = useRef(false);
1003
+ useEffect(() => {
1004
+ if (store)
1005
+ void store.load().then(items => { basketLoaded.current = true; setBasket(items); });
1006
+ }, [store]);
1007
+ const saveBasket = (next) => {
1008
+ setBasket(next);
1009
+ void store?.save(next);
1010
+ };
1011
+ const addCurrent = async () => {
1012
+ if (!output)
1013
+ return;
1014
+ setAdded(true);
1015
+ const current = basketLoaded.current || !store ? basket : await store.load();
1016
+ basketLoaded.current = true;
1017
+ let next = addToBasket(current, captureWithInstructions ?? output.capture, (!isCustomExport ? edited : null) ?? undefined);
1018
+ // A section's component files go in with it
1019
+ for (const f of output.files ?? [])
1020
+ next = addToBasket(next, f.capture);
1021
+ saveBasket(next);
1022
+ };
1023
+ const openBasket = () => {
1024
+ endCheck();
1025
+ setMergedNote(null);
1026
+ setPicking(false);
1027
+ aim(null);
1028
+ setSettingsOpen(false);
1029
+ setBasketOpen(true);
1030
+ setBasketExport(null);
1031
+ setConfirmClear(false);
1032
+ setCopied(false);
1033
+ setBasketStatus(null);
1034
+ // The latest items, in case another tab added some
1035
+ if (store)
1036
+ void store.load().then(setBasket);
1037
+ };
1038
+ // Multi-page system merge (v0.3.3): systems of one site from several pages, as one site-level system
1039
+ const mergeable = mergeGroups(basket);
1040
+ const [mergedNote, setMergedNote] = useState(null);
1041
+ const mergeSystemsNow = () => {
1042
+ const { items, merged } = mergeInBasket(basket);
1043
+ saveBasket(items);
1044
+ setMergedNote(`Added to the basket: ${merged.map(m => `${m.name} (${sourceLabel(m)})`).join(', ')}. The page systems stay; export the site system${merged.length === 1 ? '' : 's'} like any item.`);
1045
+ };
1046
+ // Connected project info (v0.4.4): active project name from luci serve /health
1047
+ const [activeProject, setActiveProject] = useState(null);
1048
+ const [bridgePortInput, setBridgePortInput] = useState('');
1049
+ const refreshProject = () => {
1050
+ if (props.projectInfo?.get) {
1051
+ props.projectInfo.get().then(info => {
1052
+ setActiveProject(info);
1053
+ if (info?.url)
1054
+ setBridgePortInput(info.url);
1055
+ }).catch(() => { setActiveProject(null); });
1056
+ }
1057
+ };
1058
+ useEffect(() => {
1059
+ refreshProject();
1060
+ }, [props.projectInfo]);
1061
+ // Debugger permission status (v0.4.4 Option 3)
1062
+ const [debuggerGranted, setDebuggerGranted] = useState(null);
1063
+ useEffect(() => {
1064
+ if (!props.debuggerPermission)
1065
+ return;
1066
+ props.debuggerPermission.get().then(setDebuggerGranted).catch(() => setDebuggerGranted(false));
1067
+ }, [props.debuggerPermission, settingsOpen]);
1068
+ // Direct send to project (v0.4.4): push basket captures straight to .luci/design/
1069
+ const [itemSent, setItemSent] = useState({});
1070
+ const [basketSending, setBasketSending] = useState(false);
1071
+ const [basketStatus, setBasketStatus] = useState(null);
1072
+ const sendOneToProject = async (item) => {
1073
+ if (!props.saveToProject)
1074
+ return;
1075
+ const { fileName, markdown } = exportItem(item, settings);
1076
+ try {
1077
+ const res = await props.saveToProject(fileName, markdown);
1078
+ setItemSent(prev => ({ ...prev, [item.id]: { path: res.path } }));
1079
+ const target = activeProject?.name ? `${activeProject.name}/` : '';
1080
+ setBasketStatus({ text: `${res.replaced ? 'Replaced in' : 'Saved to'} ${target}${res.path}` });
1081
+ }
1082
+ catch (err) {
1083
+ const msg = err instanceof Error ? err.message : String(err);
1084
+ setItemSent(prev => ({ ...prev, [item.id]: { error: msg } }));
1085
+ setBasketStatus({ text: msg, error: true });
1086
+ }
1087
+ };
1088
+ const sendAllToProject = async () => {
1089
+ if (!props.saveToProject || !basket.length)
1090
+ return;
1091
+ setBasketSending(true);
1092
+ try {
1093
+ let saved = 0;
1094
+ for (const item of basket) {
1095
+ const { fileName, markdown } = exportItem(item, settings);
1096
+ const res = await props.saveToProject(fileName, markdown);
1097
+ setItemSent(prev => ({ ...prev, [item.id]: { path: res.path } }));
1098
+ saved++;
1099
+ }
1100
+ const target = activeProject?.name ? `${activeProject.name}/.luci/design/` : '.luci/design/';
1101
+ setBasketStatus({ text: `Saved ${saved} capture${saved === 1 ? '' : 's'} into ${target}.` });
1102
+ }
1103
+ catch (err) {
1104
+ setBasketStatus({ text: err instanceof Error ? err.message : String(err), error: true });
1105
+ }
1106
+ finally {
1107
+ setBasketSending(false);
1108
+ }
1109
+ };
1110
+ const exported = basketExport
1111
+ ? (isStitch
1112
+ // DESIGN.md for Stitch: the item, or the whole basket, in one file (with each item's note)
1113
+ ? { fileName: STITCH_FILE_NAME, markdown: formatStitch((basketExport.item ? [basketExport.item] : basket).map(i => i.capture)) }
1114
+ : isTailwind
1115
+ ? { fileName: TAILWIND_V4_FILE_NAME, markdown: formatTailwind((basketExport.item ? [basketExport.item] : basket).map(i => i.capture)) }
1116
+ : isTailwindV3
1117
+ ? { fileName: TAILWIND_V3_FILE_NAME, markdown: formatTailwindV3((basketExport.item ? [basketExport.item] : basket).map(i => i.capture)) }
1118
+ : isCssVars
1119
+ ? { fileName: CSS_VARS_FILE_NAME, markdown: formatCssVariables((basketExport.item ? [basketExport.item] : basket).map(i => i.capture)) }
1120
+ : basketExport.item ? exportItem(basketExport.item, settings) : basket.length ? exportBasket(basket, settings) : null)
1121
+ : null;
1122
+ const Dropper = win.EyeDropper;
1123
+ const hasDropper = Boolean(Dropper);
1124
+ // Pixel mode: a screenshot of the page (taken with Luci hidden), read under the pointer. Unlike the
1125
+ // browser's eyedropper it leaves Luci's own panels usable, and stays on until a pixel is picked.
1126
+ const [pixelMode, setPixelMode] = useState(false);
1127
+ const [pixelHover, setPixelHover] = useState(null);
1128
+ const shot = useRef(null);
1129
+ const canPickPixels = Boolean(props.captureScreen) || hasDropper;
1130
+ const takeShot = async () => {
1131
+ if (!props.captureScreen)
1132
+ return;
1133
+ const host = doc.querySelector('luci-toolbar');
1134
+ if (host)
1135
+ host.style.visibility = 'hidden';
1136
+ try {
1137
+ // Let the browser paint the page without Luci before the screenshot
1138
+ await Promise.race([
1139
+ new Promise(r => win.requestAnimationFrame(() => win.requestAnimationFrame(r))),
1140
+ new Promise(r => setTimeout(r, 120))
1141
+ ]);
1142
+ const img = new Image();
1143
+ img.src = await props.captureScreen();
1144
+ await img.decode();
1145
+ const canvas = doc.createElement('canvas');
1146
+ canvas.width = img.naturalWidth;
1147
+ canvas.height = img.naturalHeight;
1148
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
1149
+ ctx.drawImage(img, 0, 0);
1150
+ shot.current = { ctx, scale: img.naturalWidth / win.innerWidth };
1151
+ }
1152
+ finally {
1153
+ if (host)
1154
+ host.style.visibility = '';
1155
+ }
1156
+ };
1157
+ const samplePixel = (x, y) => {
1158
+ const s = shot.current;
1159
+ if (!s)
1160
+ return null;
1161
+ const [r, g, b] = s.ctx.getImageData(Math.floor(x * s.scale), Math.floor(y * s.scale), 1, 1).data;
1162
+ const hex = `#${[r, g, b].map(n => (n ?? 0).toString(16).padStart(2, '0')).join('')}`;
1163
+ return { x, y, hex };
1164
+ };
1165
+ const pickPixelAt = (x, y) => {
1166
+ const p = samplePixel(x, y);
1167
+ if (!p)
1168
+ return;
1169
+ setPixelMode(false);
1170
+ setPixelHover(null);
1171
+ show(capturePixel(liveSnapshot(doc), p.hex, settingsRef.current));
1172
+ };
1173
+ const startPixel = async () => {
1174
+ if (!props.captureScreen) {
1175
+ await pickPixel();
1176
+ return;
1177
+ }
1178
+ setPicking(false);
1179
+ aim(null);
1180
+ setPicked(null);
1181
+ setResult(null);
1182
+ setTool('color');
1183
+ try {
1184
+ await takeShot();
1185
+ setPixelMode(true);
1186
+ }
1187
+ catch (err) {
1188
+ const reason = err instanceof Error ? err.message : String(err);
1189
+ // Keep working: fall back to the browser's eyedropper, and say why
1190
+ if (hasDropper) {
1191
+ setStateNote(`Luci's own pixel picker is not available here (${reason}), so the browser's eyedropper was used instead.`);
1192
+ await pickPixel();
1193
+ return;
1194
+ }
1195
+ startPicking('color');
1196
+ setNotice(`Pixel mode could not start: ${reason} Click an element to take its color.`);
1197
+ }
1198
+ };
1199
+ useLayoutEffect(() => {
1200
+ if (!pixelMode)
1201
+ return;
1202
+ const onKey = (e) => {
1203
+ if (e.key !== 'Escape')
1204
+ return;
1205
+ e.preventDefault();
1206
+ setPixelMode(false);
1207
+ setPixelHover(null);
1208
+ startPicking('color');
1209
+ };
1210
+ // After scrolling, the screenshot is out of date: take a new one
1211
+ let timer;
1212
+ const onScroll = () => {
1213
+ setPixelHover(null);
1214
+ clearTimeout(timer);
1215
+ timer = setTimeout(() => { void takeShot(); }, 200);
1216
+ };
1217
+ doc.addEventListener('keydown', onKey, true);
1218
+ win.addEventListener('scroll', onScroll, true);
1219
+ win.addEventListener('resize', onScroll);
1220
+ return () => {
1221
+ clearTimeout(timer);
1222
+ doc.removeEventListener('keydown', onKey, true);
1223
+ win.removeEventListener('scroll', onScroll, true);
1224
+ win.removeEventListener('resize', onScroll);
1225
+ };
1226
+ }, [pixelMode]);
1227
+ /*
1228
+ * Screenshot mode (v0.4): the Colour tool's Image. A screenshot (dropped, pasted or chosen) gives a
1229
+ * color system estimated from its pixels: the palette, each color's share and a guessed role.
1230
+ */
1231
+ const [imageMode, setImageMode] = useState(false);
1232
+ const [imageBusy, setImageBusy] = useState(false);
1233
+ const imageInput = useRef(null);
1234
+ const startImage = () => {
1235
+ setPicking(false);
1236
+ aim(null);
1237
+ setPicked(null);
1238
+ setResult(null);
1239
+ setPixelMode(false);
1240
+ setTool('color');
1241
+ setNotice(null);
1242
+ setImageMode(true);
1243
+ };
1244
+ const readImageFile = async (file, name) => {
1245
+ if (!/^image\//.test(file.type)) {
1246
+ setNotice(`${name} is not an image. Drop a PNG, JPEG or WebP screenshot.`);
1247
+ return;
1248
+ }
1249
+ setImageBusy(true);
1250
+ try {
1251
+ const bitmap = await createImageBitmap(file);
1252
+ // A small copy is enough for a palette, and keeps a large screenshot fast
1253
+ const scale = Math.min(1, 240 / Math.max(bitmap.width, bitmap.height, 1));
1254
+ const canvas = doc.createElement('canvas');
1255
+ canvas.width = Math.max(1, Math.round(bitmap.width * scale));
1256
+ canvas.height = Math.max(1, Math.round(bitmap.height * scale));
1257
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
1258
+ ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
1259
+ bitmap.close?.();
1260
+ const system = imageColorSystem(estimatePalette(ctx.getImageData(0, 0, canvas.width, canvas.height).data), { file: name, captured: new Date().toISOString().slice(0, 10) });
1261
+ setImageMode(false);
1262
+ show(system
1263
+ ? { ok: true, output: { capture: system, fileName: imageFileName(name), markdown: formatCapture(system, settingsRef.current) } }
1264
+ : { ok: false, message: 'Luci found no colours in this image: it is empty or see-through.' });
1265
+ }
1266
+ catch (err) {
1267
+ setNotice(`Luci could not read this image (${err instanceof Error ? err.message : String(err)}).`);
1268
+ }
1269
+ finally {
1270
+ setImageBusy(false);
1271
+ }
1272
+ };
1273
+ useLayoutEffect(() => {
1274
+ if (!imageMode)
1275
+ return;
1276
+ // Paste a screenshot from the clipboard; Esc goes back to Element
1277
+ const onPaste = (e) => {
1278
+ const file = [...(e.clipboardData?.items ?? [])].find(i => i.kind === 'file' && i.type.startsWith('image/'))?.getAsFile();
1279
+ if (!file)
1280
+ return;
1281
+ e.preventDefault();
1282
+ void readImageFile(file, file.name && file.name !== 'image.png' ? file.name : 'pasted-image.png');
1283
+ };
1284
+ const onKey = (e) => {
1285
+ if (e.key !== 'Escape')
1286
+ return;
1287
+ e.preventDefault();
1288
+ setImageMode(false);
1289
+ startPicking('color');
1290
+ };
1291
+ doc.addEventListener('paste', onPaste, true);
1292
+ doc.addEventListener('keydown', onKey, true);
1293
+ return () => { doc.removeEventListener('paste', onPaste, true); doc.removeEventListener('keydown', onKey, true); };
1294
+ }, [imageMode]);
1295
+ const pickPixel = async () => {
1296
+ if (!Dropper)
1297
+ return;
1298
+ // While the eyedropper is open, the page picker steps aside
1299
+ setPicking(false);
1300
+ setDropperOpen(true);
1301
+ try {
1302
+ const { sRGBHex } = await new Dropper().open();
1303
+ setDropperOpen(false);
1304
+ setPicked(null);
1305
+ show(capturePixel(liveSnapshot(doc), sRGBHex, settings));
1306
+ }
1307
+ catch {
1308
+ // Esc in the eyedropper: back to picking an element
1309
+ setDropperOpen(false);
1310
+ startPicking('color');
1311
+ }
1312
+ };
1313
+ // The tool in use, for the pill (including Pixel mode and the eyedropper)
1314
+ const currentTool = !checking && !wholePage && tool && (picking || dropperOpen || pixelMode || imageMode || Boolean(picked) || Boolean(result)) ? tool : null;
1315
+ const pickTool = (t) => { setSettingsOpen(false); setBasketOpen(false); setCheckDesign(null); startPicking(t); };
1316
+ const toggleMenu = () => setSettingsOpen(s => !s);
1317
+ const toggleBasket = () => { setSettingsOpen(false); if (basketOpen)
1318
+ setBasketOpen(false);
1319
+ else
1320
+ openBasket(); };
1321
+ // Single-key shortcuts while the toolbar is open (never while typing; DESIGN.md section 7)
1322
+ useShortcuts(doc, [
1323
+ ...TOOLS.map(t => ({ key: KEYS[t], run: () => pickTool(t) })),
1324
+ { key: KEYS.page, run: () => void captureWholePage() },
1325
+ { key: KEYS.check, run: openCheck },
1326
+ { key: KEYS.basket, run: toggleBasket },
1327
+ { key: KEYS.menu, run: toggleMenu }
1328
+ ], countdown === null);
1329
+ // First run: Luci greets once, until the first tool or panel is opened (BRAND.md: first run, slow blink)
1330
+ const idle = !settingsOpen && !basketOpen && !picking && !picked && !result && !pageBusy && !checkOpen && !pixelMode && !dropperOpen && !imageMode;
1331
+ const greeting = idle && !uiPrefs.greeted;
1332
+ useEffect(() => { if (!idle && !uiPrefs.greeted)
1333
+ setUiPrefs({ greeted: true }); }, [idle]);
1334
+ // ---- Moving the bar (the extension): anywhere in the window, kept per site ----------------
1335
+ const place = props.movable ? uiPrefs.place ?? null : null;
1336
+ useEffect(() => {
1337
+ if (!place)
1338
+ return;
1339
+ const onResize = () => setTick(t => t + 1);
1340
+ win.addEventListener('resize', onResize);
1341
+ return () => win.removeEventListener('resize', onResize);
1342
+ }, [Boolean(place)]);
1343
+ const startMove = (e) => {
1344
+ const bar = barRef.current, shell = shellRef.current;
1345
+ if (!props.movable || e.button !== 0 || !bar || !shell)
1346
+ return;
1347
+ // The bar's own background, its separators or Luci's head: the tools stay plain buttons
1348
+ const t = e.target;
1349
+ if (t !== bar && !t.closest?.('.menu-btn, .bar-sep'))
1350
+ return;
1351
+ const isBtn = Boolean(t.closest?.('.menu-btn'));
1352
+ moveRef.current = { id: e.pointerId, x: e.clientX, y: e.clientY, shell: shell.getBoundingClientRect(), bar: bar.getBoundingClientRect(), moved: false, isBtn };
1353
+ // Follow the pointer wherever it goes (a quick drag leaves the bar before it counts as one)
1354
+ const onUp = (ev) => {
1355
+ endMove(ev);
1356
+ if (moveRef.current)
1357
+ return;
1358
+ doc.removeEventListener('pointermove', doMove, true);
1359
+ doc.removeEventListener('pointerup', onUp, true);
1360
+ doc.removeEventListener('pointercancel', onUp, true);
1361
+ };
1362
+ doc.addEventListener('pointermove', doMove, true);
1363
+ doc.addEventListener('pointerup', onUp, true);
1364
+ doc.addEventListener('pointercancel', onUp, true);
1365
+ };
1366
+ const doMove = (e) => {
1367
+ const m = moveRef.current;
1368
+ if (!m || m.id !== e.pointerId)
1369
+ return;
1370
+ // Released outside the bar before a drag began: nothing to move
1371
+ if (!m.moved && !(e.buttons & 1)) {
1372
+ moveRef.current = null;
1373
+ return;
1374
+ }
1375
+ const rawX = e.clientX - m.x, rawY = e.clientY - m.y;
1376
+ // A few pixels first, so a click on Luci's head still opens the menu
1377
+ const threshold = m.isBtn ? 14 : 4;
1378
+ if (!m.moved && Math.hypot(rawX, rawY) < threshold)
1379
+ return;
1380
+ // Only now take the pointer: capturing on press would turn a click on Luci's head into a click on the bar
1381
+ if (!m.moved)
1382
+ barRef.current?.setPointerCapture?.(e.pointerId);
1383
+ m.moved = true;
1384
+ const dx = clamp(rawX, EDGE - m.bar.left, win.innerWidth - EDGE - m.bar.right);
1385
+ const dy = clamp(rawY, EDGE - m.bar.top, win.innerHeight - EDGE - m.bar.bottom);
1386
+ setMoving({ left: m.shell.left + dx, top: m.shell.top + dy });
1387
+ };
1388
+ const endMove = (e) => {
1389
+ const m = moveRef.current;
1390
+ if (!m || m.id !== e.pointerId)
1391
+ return;
1392
+ moveRef.current = null;
1393
+ barRef.current?.releasePointerCapture?.(e.pointerId);
1394
+ if (!m.moved || !barRef.current)
1395
+ return;
1396
+ // The click that ends a drag is not a click on Luci's head
1397
+ justMoved.current = true;
1398
+ win.setTimeout(() => { justMoved.current = false; }, 0);
1399
+ const r = barRef.current.getBoundingClientRect();
1400
+ const vw = win.innerWidth, vh = win.innerHeight;
1401
+ const h = r.left + r.width / 2 < vw / 2 ? 'left' : 'right';
1402
+ const v = r.top + r.height / 2 < vh / 2 ? 'top' : 'bottom';
1403
+ setMoving(null);
1404
+ setUiPrefs({ place: { h, v, x: Math.round(h === 'left' ? r.left : vw - r.right), y: Math.round(v === 'top' ? r.top : vh - r.bottom) }, dock: h });
1405
+ };
1406
+ const swallowDragClick = (e) => {
1407
+ if (!justMoved.current)
1408
+ return;
1409
+ justMoved.current = false;
1410
+ e.stopPropagation();
1411
+ e.preventDefault();
1412
+ };
1413
+ // Where the shell goes: under the pointer while dragging, else the saved corner, kept inside the window.
1414
+ // Cards open on the side with room: below a bar in the top half, above one in the bottom half.
1415
+ const shellStyle = (() => {
1416
+ if (moving)
1417
+ return { left: `${moving.left}px`, top: `${moving.top}px`, right: 'auto', bottom: 'auto', maxHeight: `calc(100vh - ${EDGE * 2}px)` };
1418
+ if (!place)
1419
+ return undefined;
1420
+ const barW = barRef.current?.offsetWidth ?? 0, barH = barRef.current?.offsetHeight ?? 0;
1421
+ const x = clamp(place.x, EDGE, win.innerWidth - EDGE - barW);
1422
+ const y = clamp(place.y, EDGE, win.innerHeight - EDGE - barH);
1423
+ return {
1424
+ [place.h]: `${x}px`, [place.h === 'left' ? 'right' : 'left']: 'auto',
1425
+ [place.v]: `${y}px`, [place.v === 'top' ? 'bottom' : 'top']: 'auto',
1426
+ maxHeight: `calc(100vh - ${y + EDGE}px)`
1427
+ };
1428
+ })();
1429
+ const hovered = picking ? candidate : null;
1430
+ const hoverElig = hovered ? eligibilityOf(hovered) : null;
1431
+ const rect = hovered?.getBoundingClientRect();
1432
+ const cs = hovered && tool === 'spacing' ? win.getComputedStyle(hovered) : null;
1433
+ return (_jsxs("div", { class: "luci luci-theme", "data-theme": uiPrefs.theme, "data-dock": uiPrefs.dock, children: [_jsxs("div", { class: "shell", "data-part": "shell", ref: shellRef, style: shellStyle, ...(props.movable ? { 'data-movable': '' } : {}), ...(moving ? { 'data-moving': '' } : {}), ...(place ? { 'data-h': place.h, 'data-v': place.v } : {}), children: [_jsxs("div", { class: "bar", role: "toolbar", "aria-label": props.modes ? COPY.capture.devTitle : COPY.capture.title, ref: barRef, onPointerDown: startMove, onClickCapture: swallowDragClick, children: [_jsx("button", { type: "button", class: "menu-btn", "data-action": "settings", "aria-label": COPY.common.menu, "aria-pressed": settingsOpen, "aria-keyshortcuts": KEYS.menu, "data-tip": `${COPY.common.menu} ${KEYS.menu}`, onClick: toggleMenu, children: _jsx(LuciLogo, { size: 48 }) }), props.modes && _jsx(ModeSwitch, { ...props.modes }), _jsx("span", { class: "bar-sep", "aria-hidden": "true" }), TOOLS.map(t => (_jsx(Button, { iconOnly: true, size: "lg", class: "tool", icon: TOOL_ICONS[t], label: COPY.capture.tools[t], shortcut: KEYS[t], "data-tool": t, "aria-pressed": currentTool === t, onClick: () => pickTool(t) }))), _jsx(Button, { iconOnly: true, size: "lg", class: "tool", icon: IconPage, label: COPY.capture.tools.page, shortcut: KEYS.page, "data-action": "whole-page", "aria-pressed": wholePage && (pageBusy || Boolean(result)), onClick: captureWholePage }), _jsx(Button, { iconOnly: true, size: "lg", class: "tool", icon: IconCheck, label: COPY.capture.tools.check, shortcut: KEYS.check, "data-action": "check", "aria-pressed": checking, onClick: openCheck }), _jsx("span", { class: "bar-sep", "aria-hidden": "true" }), _jsxs("button", { type: "button", class: "basket-pill", "data-action": "basket", "aria-pressed": basketOpen && !settingsOpen, "aria-label": COPY.capture.basketLabel(basket.length), "aria-keyshortcuts": KEYS.basket, "data-tip": `Basket ${KEYS.basket}`, onClick: toggleBasket, children: [_jsx(Icon, { icon: IconBasket }), COPY.capture.basket(basket.length)] }), _jsx(Button, { iconOnly: true, size: "lg", class: "tool", icon: IconClose, label: COPY.common.close, "data-action": "close", onClick: props.onClose })] }), greeting && (_jsxs("div", { class: "panel greet", role: "status", "data-part": "greeting", children: [_jsx(Mascot, { pose: "hello", size: 96 }), _jsxs("div", { class: "stack", children: [_jsx("p", { class: "t-title", children: COPY.capture.greeting.title }), _jsx("p", { class: "hint", children: COPY.capture.greeting.body })] })] })), props.modes && idle && !greeting && (_jsxs("div", { class: "sub with-luci", role: "note", "data-part": "intro", children: [_jsx(Mascot, { pose: "peek", size: 96 }), _jsxs("div", { class: "sub-body", children: [_jsx("p", { class: "hint", children: COPY.devToolbar.intro.capture.body }), _jsx("p", { class: "keys", children: COPY.devToolbar.intro.capture.keys })] })] })), settingsOpen && (props.modes ? (_jsx(DevSettingsPanel, { currentMode: "capture", uiPrefs: uiPrefs, onUiPrefsChange: setUiPrefs, projectInfo: props.projectInfo, store: props.store, captureSettings: settings, onCaptureSettingsChange: changeSettings, debuggerPermission: props.debuggerPermission })) : (_jsxs("div", { class: "panel", role: "dialog", "aria-label": COPY.common.menu, "data-part": "settings", children: [_jsxs("div", { class: "menu-head", children: [_jsx(Mascot, { pose: "sit", size: 96 }), _jsxs("div", { class: "brand-stack", children: [_jsxs("div", { class: "brand-title-line", children: [_jsx("span", { class: "brand-title", "data-part": "brand-title", children: props.modes ? COPY.capture.devTitle : COPY.capture.title }), _jsx("span", { class: "brand-sub", "data-part": "brand-sub", children: props.modes ? COPY.capture.devByline : COPY.capture.byline })] }), _jsx("p", { class: "brand-desc", children: props.modes ? COPY.capture.devDescription : COPY.capture.description }), props.onHelp && _jsx("div", { class: "row", children: _jsx(Button, { variant: "secondary", icon: IconInfo, "data-action": "help", onClick: () => props.onHelp(), children: COPY.common.help }) })] }), _jsx(RepoButton, {})] }), !props.modes && (_jsxs("div", { class: "invite", "data-part": "invite", children: [_jsx("p", { class: "invite-title", children: COPY.capture.invite.title }), _jsx("p", { class: "invite-body", children: COPY.capture.invite.body }), LUCI_REPO_URL
1434
+ ? _jsx("a", { class: "btn-link invite-action", "data-action": "take-home", href: LUCI_REPO_URL, target: "_blank", rel: "noopener noreferrer", children: COPY.capture.invite.action })
1435
+ : props.onHelp && _jsx(Button, { variant: "link", class: "invite-action", "data-action": "take-home", onClick: () => props.onHelp('take-luci-home'), children: COPY.capture.invite.action })] })), _jsxs("div", { class: "project-card", "data-part": "connected-project", children: [_jsxs("div", { class: "project-header", children: [_jsx("span", { class: `status-dot ${activeProject?.project ? 'online' : 'offline'}`, "aria-hidden": "true" }), _jsxs("div", { class: "project-info", children: [_jsx("span", { class: "project-name", children: activeProject?.name ? `Connected to ${activeProject.name}` : 'Not connected to a project' }), activeProject?.project && _jsx("span", { class: "project-path dim", title: activeProject.project, children: activeProject.project }), !activeProject?.project && _jsxs("span", { class: "project-hint dim", children: ["Run ", _jsx("code", { children: "luci serve" }), " in your project terminal"] })] })] }), props.projectInfo?.setUrl && (_jsxs("div", { class: "project-port-row", children: [_jsx("label", { class: "dim", for: "luci-bridge-url", children: "Bridge:" }), _jsx("input", { id: "luci-bridge-url", type: "text", class: "port-input", "data-part": "port-input", value: bridgePortInput, placeholder: "http://127.0.0.1:4545", onChange: e => {
1436
+ const val = e.currentTarget.value;
1437
+ setBridgePortInput(val);
1438
+ void props.projectInfo?.setUrl?.(val).then(refreshProject);
1439
+ } })] }))] }), props.debuggerPermission && (_jsxs("div", { class: "project-card", "data-part": "debugger-permission", children: [_jsxs("div", { class: "project-header", children: [_jsx("span", { class: `status-dot ${debuggerGranted && useDebugger ? 'online' : 'offline'}`, "aria-hidden": "true" }), _jsxs("div", { class: "project-info", children: [_jsx("span", { class: "project-name", children: debuggerGranted
1440
+ ? (useDebugger ? 'Debugger: active' : 'Debugger: disabled')
1441
+ : 'Debugger: optional (not enabled)' }), _jsx("span", { class: "project-hint dim", children: debuggerGranted
1442
+ ? (useDebugger
1443
+ ? 'Briefly attaches only during captures for exact CDP states'
1444
+ : 'CSS rules & hidden frames active. Debugger will never be attached.')
1445
+ : 'CSS rules & frame fallback active' })] })] }), _jsx("div", { class: "project-port-row", children: debuggerGranted ? (_jsx("button", { type: "button", class: "btn-secondary", "data-action": "toggle-debugger", onClick: () => changeSettings({ ...settings, useDebugger: !useDebugger }), children: useDebugger ? 'Disable debugger' : 'Enable debugger' })) : (_jsx("button", { type: "button", class: "btn-secondary", "data-action": "enable-debugger", onClick: () => {
1446
+ if (props.debuggerPermission?.request) {
1447
+ props.debuggerPermission.request();
1448
+ }
1449
+ else if (props.onHelp) {
1450
+ props.onHelp('debugger-permission');
1451
+ }
1452
+ }, children: "Enable in Help" })) })] })), _jsx("hr", { class: "settings-divider" }), _jsx(AppearanceControls, { prefs: uiPrefs, onChange: setUiPrefs, movable: Boolean(props.movable || props.modes), moved: props.movable ? Boolean(place) : Boolean(props.modes && uiPrefs.devPlace) }), _jsx("hr", { class: "settings-divider" }), _jsxs("div", { class: "stack", children: [_jsx("span", { class: "field-label", children: "Default file format" }), _jsxs("div", { class: "settings-grid", children: [_jsxs("label", { class: "field-stack", children: [_jsx("span", { class: "dim", children: "Units" }), _jsxs(Select, { "data-setting": "units", value: settings.units ?? 'px', onChange: e => changeSettings({ ...settings, units: e.currentTarget.value }), children: [_jsx("option", { value: "px", children: "px" }), _jsx("option", { value: "rem", children: "rem" }), _jsx("option", { value: "both", children: "both" })] })] }), _jsxs("label", { class: "field-stack", children: [_jsx("span", { class: "dim", children: "Colours" }), _jsxs(Select, { "data-setting": "colors", value: settings.colors ?? 'hex', onChange: e => changeSettings({ ...settings, colors: e.currentTarget.value }), children: [_jsx("option", { value: "hex", children: "hex" }), _jsx("option", { value: "rgb", children: "rgb" }), _jsx("option", { value: "hsl", children: "hsl" }), _jsx("option", { value: "oklch", children: "oklch" })] })] }), _jsxs("label", { class: "field-stack", title: "The file's source line: the page address, or only the site name", children: [_jsx("span", { class: "dim", children: "Source" }), _jsxs(Select, { "data-setting": "source", value: settings.source ?? 'page', onChange: e => changeSettings({ ...settings, source: e.currentTarget.value }), children: [_jsx("option", { value: "page", children: "page address" }), _jsx("option", { value: "site", children: "site name only" })] })] }), _jsxs("label", { class: "field-stack", title: "The file you copy, download and export: Luci's tables, DESIGN.md for Google Stitch, Tailwind CSS, or CSS Variables", children: [_jsx("span", { class: "dim", children: "File" }), _jsxs(Select, { "data-setting": "style", value: settings.style ?? 'luci', onChange: e => changeSettings({ ...settings, style: e.currentTarget.value }), children: [_jsx("option", { value: "luci", children: "Luci tables" }), _jsx("option", { value: "stitch", children: "DESIGN.md (Stitch)" }), _jsx("option", { value: "tailwind", children: "Tailwind v4 (@theme)" }), _jsx("option", { value: "tailwind-v3", children: "Tailwind v3 (config.js)" }), _jsx("option", { value: "css-vars", children: "CSS Variables (tokens.css)" })] })] })] })] }), _jsx("hr", { class: "settings-divider" }), _jsxs("div", { class: "stack", children: [_jsx("span", { class: "field-label", children: "Keys" }), _jsxs("div", { class: "shortcut-list", "data-part": "keys", children: [_jsx("span", { children: TOOLS.map(t => _jsxs(_Fragment, { children: [_jsx("kbd", { class: "kbd", children: KEYS[t] }), " "] })) }), _jsx("span", { class: "dim", children: "Component, Text, Colour, Spacing" }), _jsxs("span", { children: [_jsx("kbd", { class: "kbd", children: KEYS.page }), " ", _jsx("kbd", { class: "kbd", children: KEYS.check })] }), _jsx("span", { class: "dim", children: "Whole page, Check a build" }), _jsxs("span", { children: [_jsx("kbd", { class: "kbd", children: KEYS.basket }), " ", _jsx("kbd", { class: "kbd", children: KEYS.menu })] }), _jsx("span", { class: "dim", children: "Basket, this menu" }), _jsxs("span", { children: [_jsx("kbd", { class: "kbd", children: "\u2191" }), " ", _jsx("kbd", { class: "kbd", children: "\u2193" })] }), _jsx("span", { class: "dim", children: "Wider or narrower selection" }), _jsx("span", { children: _jsx("kbd", { class: "kbd", children: "Enter" }) }), _jsx("span", { class: "dim", children: "Pick, then take This one" }), _jsx("span", { children: _jsx("kbd", { class: "kbd", children: "Esc" }) }), _jsx("span", { class: "dim", children: "Stop picking, or close the panel" })] })] })] }))), !settingsOpen && pageBusy && !basketOpen && (_jsx("div", { class: "panel", children: _jsx(Loading, { sleep: true, text: COPY.capture.readingPage, step: pageStep }) })), !settingsOpen && basketOpen && (_jsx("div", { class: "panel", role: "dialog", "aria-label": "Basket", "data-part": "basket", children: comparison ? (_jsxs(_Fragment, { children: [_jsx("h2", { children: "Compare" }), _jsxs("p", { class: "hint", "data-part": "compare-summary", children: ["A: ", comparison.result.a.name, " (", sourceLabel(comparison.items[0]), "). B: ", comparison.result.b.name, " (", sourceLabel(comparison.items[1]), "). ", comparison.result.same.length, " value", comparison.result.same.length === 1 ? ' is' : 's are', " the same; ", comparison.result.differences.length, " differ", comparison.result.differences.length === 1 ? 's' : '', "."] }), comparison.result.differences.length ? (_jsx("div", { class: "compare-scroll", children: _jsxs("table", { class: "compare", "data-part": "compare-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { class: "col-what", children: "What" }), _jsx("th", { class: "col-a", children: "A" }), _jsx("th", { class: "col-b", children: "B" })] }) }), _jsx("tbody", { children: comparison.result.differences.map(d => _jsxs("tr", { children: [_jsx("td", { class: "col-what", children: d.what }), _jsx("td", { class: "col-a", children: d.a }), _jsx("td", { class: "col-b", children: d.b })] })) })] }) })) : _jsx("p", { class: "hint", children: "No differences: every value compared is the same." }), _jsxs("div", { class: "row actions", children: [_jsx(Button, { variant: "primary", size: "md", iconOnly: true, tipAbove: true, tipAlign: "left", icon: copied ? IconSuccess : IconCopy, label: copied ? COPY.common.copied : 'Copy the comparison', "data-action": "copy-compare", onClick: () => void copyText(formatCompareReport(comparison.result, { a: comparison.items[0].name, b: comparison.items[1].name })) }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "compare-back", onClick: () => { setComparison(null); setCopied(false); }, children: "Back to the basket" })] })] })) : basketExport && exported ? (_jsxs(_Fragment, { children: [_jsx("h2", { children: basketExport.title }), _jsx("div", { class: "file", "data-part": "file-name", children: exported.fileName }), _jsx("pre", { "data-part": "preview", children: exported.markdown }), _jsxs("div", { class: "row actions", children: [_jsx(Button, { variant: "primary", size: "md", iconOnly: true, tipAbove: true, tipAlign: "left", icon: copied ? IconSuccess : IconCopy, label: copied ? COPY.common.copied : COPY.capture.actions.copy, "data-action": "copy", onClick: () => void copyText(exported.markdown) }), _jsx(Button, { variant: "secondary", size: "md", iconOnly: true, tipAbove: true, icon: IconDownload, label: COPY.capture.actions.download, "data-action": "download", onClick: () => downloadText(exported.fileName, exported.markdown) }), props.saveToProject && _jsx(SaveButton, { save: () => props.saveToProject(exported.fileName, exported.markdown), projectName: activeProject?.name }, exported.fileName), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "basket-back", onClick: () => { setBasketExport(null); setCopied(false); }, children: "Back to the basket" })] })] })) : (_jsxs(_Fragment, { children: [_jsx("h2", { children: "Basket" }), !basket.length ? (_jsx(EmptyState, { pose: "box", title: COPY.capture.basketEmpty.title, body: COPY.capture.basketEmpty.body, part: "basket-empty" })) : (_jsx("ul", { class: "items", children: basket.map(item => (_jsxs("li", { "data-item": item.id, children: [_jsxs("span", { class: "meta", children: [groupOf(item.capture), " \u00B7 ", sourceLabel(item)] }), basket.length > 1 && (_jsxs("label", { class: "compare-pick", title: "Pick two items to compare them", children: [_jsx("input", { type: "checkbox", "data-item-compare": true, checked: compareIds.includes(item.id), onChange: e => setCompareIds(ids => (e.currentTarget.checked ? [...ids.filter(i => i !== item.id), item.id].slice(-2) : ids.filter(i => i !== item.id))) }), "Compare"] })), _jsx("input", { type: "text", "aria-label": "Name", "data-item-name": true, value: item.name, onChange: e => saveBasket(renameInBasket(basket, item.id, e.currentTarget.value)) }), _jsxs("span", { class: "row", children: [_jsx("button", { type: "button", class: "btn-secondary", "data-item-export": true, onClick: () => setBasketExport({ title: item.name, item }), children: "Export" }), props.saveToProject && (_jsx("button", { type: "button", class: "btn-secondary", "data-item-send-project": true, title: activeProject?.name ? `Save this capture to ${activeProject.name}/.luci/design/` : "Save this capture to .luci/design/ in your project", onClick: () => void sendOneToProject(item), children: itemSent[item.id]?.error ? 'Failed' : itemSent[item.id] ? 'Saved' : activeProject?.name ? `Send to ${activeProject.name}` : 'Send' })), _jsx("button", { class: "btn-danger", type: "button", "data-item-remove": true, "aria-label": `Remove ${item.name}`, onClick: () => saveBasket(removeFromBasket(basket, item.id)), children: "Remove" })] }), _jsx("textarea", { "data-item-note": true, "aria-label": `Note for your agent about ${item.name}`, placeholder: "Note for your agent (optional). What to use it for, what to change.", value: item.capture.instructions ?? '', onChange: e => saveBasket(noteInBasket(basket, item.id, e.currentTarget.value)) })] }))) })), mergeable.length > 0 && (_jsxs("div", { class: "stack", "data-part": "merge", children: [_jsxs("span", { class: "dim", children: ["One site, several pages: ", mergeable.map(g => `${g.type} from ${g.pages.length} pages of ${g.site}`).join(', '), ". Merge them into one site file. Each row says which pages use it; values that differ are listed as conflicts."] }), _jsx("span", { class: "row", children: _jsxs("button", { type: "button", class: "btn-secondary", "data-action": "merge-systems", onClick: mergeSystemsNow, children: ["Merge into site system", mergeable.length === 1 ? '' : 's', " (", mergeable.length, ")"] }) })] })), mergedNote && _jsx("p", { class: "hint", "data-part": "merged", children: mergedNote }), compareItems && (_jsxs("div", { class: "row", "data-part": "compare-pick", children: [_jsxs("span", { class: "dim", children: [compareItems[0].name, " and ", compareItems[1].name] }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "compare", onClick: () => { setComparison({ items: compareItems, result: compareCaptures(compareItems[0].capture, compareItems[1].capture) }); setCopied(false); }, children: "Compare the two" })] })), _jsxs("div", { class: "row", children: [_jsx("button", { type: "button", class: "btn-primary", "data-action": "export-all", disabled: !basket.length, onClick: () => setBasketExport({ title: `All ${basket.length} items, one file` }), children: "Export all as one file" }), props.saveToProject && (_jsx("button", { type: "button", class: "btn-secondary", "data-action": "send-all-project", disabled: !basket.length || basketSending, title: activeProject?.name ? `Save each capture in the basket to ${activeProject.name}/.luci/design/` : "Save each capture in the basket to .luci/design/ in your project", onClick: () => void sendAllToProject(), children: basketSending ? _jsxs(_Fragment, { children: [_jsx(ButtonSpinner, {}), "Sending\u2026"] }) : activeProject?.name ? `Send all to ${activeProject.name}` : 'Send all to project' })), basket.length > 0 && (confirmClear
1453
+ ? _jsx("button", { type: "button", class: "btn-danger", "data-action": "clear-basket-confirm", onClick: () => { saveBasket([]); setConfirmClear(false); }, children: "Yes, empty the basket" })
1454
+ : _jsx("button", { type: "button", class: "btn-danger", "data-action": "clear-basket", onClick: () => setConfirmClear(true), children: "Empty basket" }))] }), basketStatus && _jsx("p", { class: basketStatus.error ? 'error' : 'hint', "data-part": "basket-status", children: basketStatus.text })] })) })), !settingsOpen && (picking || dropperOpen || pixelMode || imageMode) && tool && (_jsxs("div", { class: `sub with-luci${imageMode ? ' image-drop' : ''}`, "data-part": "tool-hint", role: "note", ...(imageMode ? {
1455
+ onDragOver: (e) => { e.preventDefault(); },
1456
+ onDrop: (e) => {
1457
+ e.preventDefault();
1458
+ const file = [...(e.dataTransfer?.files ?? [])][0];
1459
+ if (file)
1460
+ void readImageFile(file, file.name || 'dropped-image.png');
1461
+ }
1462
+ } : {}), children: [_jsx(Mascot, { pose: checkDesign ? 'compare' : TOOL_POSES[tool], size: 96 }), _jsxs("div", { class: "sub-body", children: [tool === 'color' && (_jsxs("div", { class: "seg", role: "group", "aria-label": "Pick a colour from", children: [_jsx("button", { type: "button", "aria-pressed": !dropperOpen && !pixelMode && !imageMode, "data-color-mode": "element", onClick: () => { setPixelMode(false); setImageMode(false); startPicking('color'); }, children: "Element" }), _jsx("button", { type: "button", "aria-pressed": dropperOpen || pixelMode, "data-color-mode": "pixel", "data-action": "eyedropper", disabled: !canPickPixels, title: canPickPixels ? 'Pick any spot on the page' : 'This browser cannot pick pixels. Click an element instead.', onClick: () => { setImageMode(false); void startPixel(); }, children: "Pixel" }), _jsx("button", { type: "button", "aria-pressed": imageMode, "data-color-mode": "image", title: "Estimate the colours of a screenshot or any image", onClick: startImage, children: "Image" })] })), _jsx("p", { class: "hint", "data-part": "hint", children: imageMode ? (imageBusy ? 'Reading the image…' : 'Drop a screenshot here, paste one, or choose a file. Luci estimates its colours: every value is a guess.')
1463
+ : pixelMode ? 'Point at any spot. Click to take its colour.'
1464
+ : checkDesign ? `Click the component you built. Luci checks it against ${checkDesign.label}.`
1465
+ : `${TOOL_HINTS[tool]}${tool === 'color' && !canPickPixels ? ' This browser cannot pick pixels.' : ''}` }), imageMode && (_jsxs("div", { class: "row", children: [_jsx("input", { ref: imageInput, type: "file", accept: "image/*", "data-part": "image-file", hidden: true, onChange: e => { const f = e.currentTarget.files?.[0]; if (f)
1466
+ void readImageFile(f, f.name); } }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "choose-image", disabled: imageBusy, onClick: () => imageInput.current?.click(), children: "Choose an image" })] })), _jsx("p", { class: "keys", children: pixelMode || imageMode ? 'Esc: back to Element' : '↑ ↓ after clicking: wider or narrower · Esc: stop' })] })] })), !settingsOpen && picking && notice && (_jsx("div", { class: "panel", role: "status", children: _jsx("p", { class: "error", "data-part": "notice", children: notice }) })), !settingsOpen && checkOpen && !basketOpen && (_jsx(DesignChooser, { ...(props.designs ? { designs: props.designs } : {}), basket: basket, onChoose: chooseDesign, onCancel: endCheck })), !settingsOpen && !picking && !basketOpen && checkOutcome && checkDesign && picked && (_jsx(CheckResultPanel, { outcome: checkOutcome, watching: watchCheck, onWatch: on => { setWatchCheck(on); setAutoNote(null); if (!on)
1467
+ forgetWatch(); }, autoNote: autoNote, design: checkDesign, el: picked.el, selector: picked.entry.selector, ...(props.addCheckNotes ? { addNotes: props.addCheckNotes } : {}), ...(props.checkNotesWhere ? { notesWhere: props.checkNotesWhere } : {}), onCopy: copyText, onAgain: () => startPicking('component'), onChangeDesign: openCheck }, `${picked.entry.selector} ${checkDesign.file} ${checkVersion}`)), !settingsOpen && !picking && !basketOpen && picked && checkDesign && !checkOutcome && !result && (_jsx("div", { class: "panel", role: "dialog", "aria-label": "Design check", "data-part": "check-selected", children: _jsxs("div", { class: "selected-card", children: [_jsxs("div", { class: "selected-head", children: [_jsxs("h2", { children: ["Built: ", _jsx("span", { "data-part": "selected-name", children: elementName(picked.entry.tag, picked.entry.role) })] }), _jsxs("span", { class: "dim", children: [Math.round(picked.el.getBoundingClientRect().width), " \u00D7 ", Math.round(picked.el.getBoundingClientRect().height)] })] }), _jsxs("div", { class: "row", children: [_jsx("button", { type: "button", class: "btn-secondary", "data-action": "widen", disabled: !widerOf(picked.el), onClick: widen, title: "Select the element around this one (\u2191)", children: "\u2191 Wider" }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "narrow", disabled: !narrowerOf(picked.el), onClick: narrow, title: "Select the element inside this one (\u2193)", children: "\u2193 Narrower" }), _jsx("span", { class: "dim", children: "or \u2191 \u2193" })] }), picked.eligibility.status !== 'allowed' && _jsxs("p", { class: "error", "data-part": "notice", children: [picked.eligibility.reason, " Go wider or narrower."] }), busy ? _jsx(Loading, { text: busy }) : (_jsxs(_Fragment, { children: [_jsxs("div", { class: "row", children: [_jsx("button", { type: "button", class: "btn-primary", "data-action": "check-run", disabled: picked.eligibility.status !== 'allowed', onClick: () => void runCheck(), children: "Check against the design" }), _jsx("button", { type: "button", class: "btn-secondary", onClick: () => startPicking('component'), children: "Pick again" }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "check-design", onClick: openCheck, children: "Change design" })] }), _jsxs("p", { class: "tip-box", "data-part": "check-against", children: ["Design: ", checkDesign.label] })] }))] }) })), !settingsOpen && !picking && !basketOpen && picked && !checkDesign && !result && tool && (_jsx("div", { class: "panel", role: "dialog", "aria-label": "Capture", children: _jsxs("div", { class: "selected-card", children: [_jsxs("div", { class: "selected-head", children: [_jsxs("h2", { children: ["Selected \u00B7 ", _jsx("span", { "data-part": "selected-name", children: elementName(picked.entry.tag, picked.entry.role) })] }), _jsxs("span", { class: "dim", children: [Math.round(picked.el.getBoundingClientRect().width), " \u00D7 ", Math.round(picked.el.getBoundingClientRect().height)] })] }), _jsxs("div", { class: "row", children: [_jsx("button", { type: "button", class: "btn-secondary", "data-action": "widen", disabled: !widerOf(picked.el), onClick: widen, title: "Select the element around this one (\u2191)", children: "\u2191 Wider" }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "narrow", disabled: !narrowerOf(picked.el), onClick: narrow, title: "Select the element inside this one (\u2193)", children: "\u2193 Narrower" }), _jsx("span", { class: "dim", children: "or \u2191 \u2193" })] }), picked.eligibility.status === 'redirected' && _jsx("p", { class: "hint", children: picked.eligibility.reason }), picked.eligibility.status === 'blocked' && _jsxs("p", { class: "error", "data-part": "notice", children: [picked.eligibility.reason, " Go wider or narrower."] }), tool === 'spacing' && picked.eligibility.status === 'allowed' && spacingChoices(picked.entry).length > 1 && (_jsxs("div", { class: "row", children: [_jsxs("button", { type: "button", class: "btn-secondary", "aria-pressed": choice === ALL_SPACING, "data-choice": "all", onClick: () => setChoice(ALL_SPACING), children: ["All (", spacingChoices(picked.entry).length, ")"] }), spacingChoices(picked.entry).map((u, i) => (_jsxs("button", { type: "button", class: "btn-secondary", "aria-pressed": choice === i, "data-choice": u.property, onClick: () => setChoice(i), children: [u.property, " ", u.computed] })))] })), busy ? _jsx(Loading, { text: busy }) : (_jsxs(_Fragment, { children: [_jsxs("div", { class: "row", children: [picked.eligibility.status === 'allowed' && (_jsx("button", { type: "button", class: "btn-primary", "data-output": "one", onClick: () => void produce(false), children: "This one" })), picked.eligibility.status !== 'blocked' && (_jsx("button", { type: "button", class: picked.eligibility.status === 'allowed' ? 'btn-secondary' : 'btn-primary', "data-output": "system", onClick: () => void produce(true), children: "The whole system" })), tool === 'component' && picked.eligibility.status === 'allowed' && (_jsx("button", { type: "button", class: "btn-secondary", "data-output": "section", title: SECTION_HINT, onClick: () => void produce(false, true), children: "This section" })), _jsx("button", { type: "button", class: "btn-secondary", onClick: () => startPicking(tool), children: "Pick again" })] }), picked.eligibility.status !== 'blocked' && (_jsxs("p", { class: "tip-box", "data-part": "output-hints", children: [picked.eligibility.status === 'allowed' && _jsxs(_Fragment, { children: ["This one: ", OUTPUT_HINTS[tool].one, ". "] }), "The whole system: ", OUTPUT_HINTS[tool].system, ".", tool === 'component' && picked.eligibility.status === 'allowed' && _jsxs(_Fragment, { children: [" This section: ", SECTION_HINT, "."] })] }))] }))] }) })), !settingsOpen && !picking && !basketOpen && result && (_jsx("div", { class: result.ok ? 'panel result-panel' : 'panel', role: "dialog", "aria-label": "Capture file", children: result.ok ? (_jsxs(_Fragment, { children: [_jsxs("div", { class: "panel-body", children: [_jsxs("div", { class: "file-row", children: [_jsx("div", { class: "file", "data-part": "file-name", children: outputName }), _jsx("span", { class: "scope-pill badge", children: result.output.capture.meta.scope })] }), sectionFiles.length > 0 && (_jsxs("div", { class: "stack", "data-part": "section-files", children: [_jsxs("span", { class: "dim", children: ["Plus ", sectionFiles.length, " component file", sectionFiles.length === 1 ? '' : 's', ", each described once. The section file places them."] }), _jsx("ul", { class: "files", children: sectionFiles.map(f => (_jsxs("li", { "data-file": f.fileName, children: [_jsx("code", { children: f.fileName }), " ", _jsx("button", { type: "button", class: "btn-secondary", "data-file-view": true, onClick: () => setViewFile(f), children: "View" })] }))) })] })), viewFile && (_jsxs("div", { class: "stack", "data-part": "file-view-box", children: [_jsxs("span", { class: "row", children: [_jsx("code", { children: viewFile.fileName }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "file-view-close", onClick: () => setViewFile(null), children: "Back to the section file" })] }), _jsx("pre", { class: "preview", "data-part": "file-view", children: viewFile.markdown })] })), _jsxs("div", { class: "settings-grid", children: [_jsxs("label", { class: "field-stack", children: [_jsx("span", { class: "field-label", children: "Units" }), _jsxs(Select, { "data-setting": "units", value: settings.units ?? 'px', onChange: e => changeSettings({ ...settings, units: e.currentTarget.value }), children: [_jsx("option", { value: "px", children: "px" }), _jsx("option", { value: "rem", children: "rem" }), _jsx("option", { value: "both", children: "both" })] })] }), _jsxs("label", { class: "field-stack", children: [_jsx("span", { class: "field-label", children: "Colours" }), _jsxs(Select, { "data-setting": "colors", value: settings.colors ?? 'hex', onChange: e => changeSettings({ ...settings, colors: e.currentTarget.value }), children: [_jsx("option", { value: "hex", children: "hex" }), _jsx("option", { value: "rgb", children: "rgb" }), _jsx("option", { value: "hsl", children: "hsl" }), _jsx("option", { value: "oklch", children: "oklch" })] })] }), _jsxs("label", { class: "field-stack", title: "The file's source line: the page address, or only the site name", children: [_jsx("span", { class: "field-label", children: "Source" }), _jsxs(Select, { "data-setting": "source", value: settings.source ?? 'page', onChange: e => changeSettings({ ...settings, source: e.currentTarget.value }), children: [_jsx("option", { value: "page", children: "page address" }), _jsx("option", { value: "site", children: "site name only" })] })] }), _jsxs("label", { class: "field-stack", title: "The file you copy and download: Luci's tables, DESIGN.md for Google Stitch, Tailwind CSS, or CSS Variables", children: [_jsx("span", { class: "field-label", children: "File" }), _jsxs(Select, { "data-setting": "style", value: settings.style ?? 'luci', onChange: e => changeSettings({ ...settings, style: e.currentTarget.value }), children: [_jsx("option", { value: "luci", children: "Luci tables" }), _jsx("option", { value: "stitch", children: "DESIGN.md (Stitch)" }), _jsx("option", { value: "tailwind", children: "Tailwind v4 (@theme)" }), _jsx("option", { value: "tailwind-v3", children: "Tailwind v3 (config.js)" }), _jsx("option", { value: "css-vars", children: "CSS Variables (tokens.css)" })] })] })] }), isCustomExport && props.saveToProject && _jsx("p", { class: "dim", "data-part": "stitch-note", children: "Save to project keeps Luci's tables: the design check and your agent's tools read them." }), stateNote && _jsx("p", { class: "hint", "data-part": "state-note", children: stateNote }), componentCtx && result.output.capture.meta.scope === 'component' && (_jsxs("div", { class: "stack", "data-part": "manual-state", children: [_jsx("hr", { class: "settings-divider" }), _jsxs("div", { class: "stack", "data-part": "states-summary", children: [_jsx("span", { class: "field-label", children: "States in this file" }), _jsxs("div", { class: "states-list", children: [_jsx("span", { class: "state default detected", "data-state": "default", title: "Resting state", children: "Default \u2713" }), componentCtx.states.map(s => (_jsxs("span", { class: s.detected ? 'state detected' : 'state missing', "data-state": s.state, title: s.detected ? (s.trigger ? `In the file. Set by the ${s.trigger.element} around it.` : 'In the file.')
1468
+ : checked(s) ? 'Checked in the browser. Nothing changes.'
1469
+ : 'Not detected. It may change through JavaScript. Capture it by hand below.', children: [s.state, " ", s.detected ? `✓${s.trigger ? ` (via ${s.trigger.element.split(' ')[0]})` : ''}` : checked(s) ? '– no change' : '– not detected'] })))] })] }), _jsx("hr", { class: "settings-divider" }), countdown !== null && capturing ? (_jsxs("div", { class: "row", children: [_jsxs("p", { class: "hint", "data-part": "countdown", children: [capturing.total > 1 ? `${capturing.index} of ${capturing.total}: ` : '', "Put it in its ", _jsx("strong", { children: capturing.state }), " state now (", STATE_HOW[capturing.state], "). Capturing in ", countdown, "\u2026"] }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "cancel-capture", onClick: cancelCapture, children: "Stop" })] })) : (_jsxs("div", { class: "manual-row", children: [_jsxs("div", { class: "section-copy", children: [_jsx("label", { class: "field-label", for: "luci-manual-state", children: "Capture by hand" }), _jsx("span", { class: "dim", children: "Set hover, focus or active yourself. 3 second countdown." })] }), _jsxs("div", { class: "manual-actions", children: [_jsxs(Select, { id: "luci-manual-state", "data-setting": "manual-state", value: manualTarget, onChange: e => setManualTarget(e.currentTarget.value), children: [missingStates(componentCtx.states).length > 0 && _jsxs("option", { value: ALL_MISSING, children: ["All missing states (", missingStates(componentCtx.states).length, ")"] }), STATE_ORDER.filter(s => s !== 'disabled').map(s => _jsx("option", { value: s, children: s }))] }), _jsx("button", { type: "button", class: "btn-secondary", "data-action": "capture-state", onClick: captureCurrentState, children: manualTarget === ALL_MISSING ? 'Capture' : 'Capture state' })] })] }))] })), picked && (result.output.capture.meta.scope === 'component' || result.output.capture.meta.scope === 'section') && result.output.capture.meta.selector === picked.entry.selector && (_jsxs("div", { class: "stack", "data-part": "responsive", children: [_jsx("hr", { class: "settings-divider" }), widthBusy ? _jsx(Loading, { text: widthBusy }) : (_jsxs("div", { class: "manual-row", children: [_jsxs("div", { class: "section-copy", children: [_jsx("span", { class: "field-label", children: "Breakpoints" }), !widthNote && _jsx("span", { class: "dim", children: responsiveRef.current ? 'In the file, under Responsive.' : 'The site\'s own breakpoints. 2 or 3 widths.' })] }), _jsx("div", { class: "manual-actions", children: _jsx("button", { type: "button", class: "btn-secondary", "data-action": "responsive", title: "Read it at the widths where the site's media queries change it, and add the changes to the file", onClick: () => void addResponsive(), children: responsiveRef.current ? 'Read the widths again' : 'How it changes by width' }) })] })), widthNote && _jsx("p", { class: widthNote.error ? 'error' : 'hint', "data-part": "responsive-note", children: widthNote.text })] })), _jsx("hr", { class: "settings-divider" }), _jsx(RemapSection, { source: myTokens, edited: edited !== null, applied: remapped && remapped.fileName === result.output.fileName ? remapped.summary : null, onApply: tokens => {
1470
+ const next = remapOutput(result.output, tokens, settings.rootFontSize);
1471
+ setRemapped({ fileName: result.output.fileName, original: result.output, summary: next.summary });
1472
+ setResult({ ok: true, output: next.output });
1473
+ setCopied(false);
1474
+ }, onUndo: () => {
1475
+ if (remapped)
1476
+ setResult({ ok: true, output: remapped.original });
1477
+ setRemapped(null);
1478
+ setCopied(false);
1479
+ } }), _jsx("hr", { class: "settings-divider" }), _jsxs("label", { class: "field-stack", children: [_jsxs("span", { class: "field-label", children: ["Note for your agent ", _jsx("span", { class: "dim", children: "(optional)" })] }), _jsx("textarea", { "data-part": "instructions", rows: 2, value: instructions, placeholder: "e.g. Use this as our primary button, with our brand blue #1d4ed8 and a 12px radius.", onInput: e => changeInstructions(e.currentTarget.value) })] })] }), _jsxs("div", { class: "md-section", children: [_jsxs("div", { class: "md-head", children: [_jsxs("span", { class: "md-title", children: ["The file ", _jsx("span", { class: "dim", children: "(you can edit it)" })] }), edited !== null && (_jsxs("span", { class: "row", children: [_jsx("span", { class: "dim", "data-part": "edited-note", children: "Edited by hand. Units and colours no longer change it." }), _jsx("button", { type: "button", class: "btn-danger", "data-action": "undo-edits", onClick: () => setEdited(null), children: "Undo my edits" })] }))] }), _jsx("textarea", { class: "preview", "data-part": "preview", spellcheck: false, value: markdown, onInput: e => { setEdited(e.currentTarget.value); setCopied(false); } }), _jsxs("div", { class: "row actions", children: [_jsx(Button, { variant: "primary", size: "md", iconOnly: true, tipAbove: true, tipAlign: "left", icon: copied ? IconSuccess : IconCopy, "data-action": "copy", onClick: copy, label: copied ? COPY.common.copied : sectionFiles.length && !isCustomExport ? COPY.capture.actions.copySection : COPY.capture.actions.copy }), sectionFiles.length && !isCustomExport
1480
+ ? _jsx(Button, { variant: "secondary", size: "md", iconOnly: true, tipAbove: true, icon: IconDownload, "data-action": "download-zip", onClick: downloadZip, label: COPY.capture.actions.downloadZip(sectionFiles.length + 1) })
1481
+ : _jsx(Button, { variant: "secondary", size: "md", iconOnly: true, tipAbove: true, icon: IconDownload, "data-action": "download", onClick: download, label: COPY.capture.actions.download }), _jsx(Button, { variant: "secondary", size: "md", iconOnly: true, tipAbove: true, icon: added ? IconSuccess : IconBasket, "data-action": "add-to-basket", label: added ? COPY.capture.actions.inBasket : COPY.capture.actions.addToBasket, onClick: () => { if (added)
1482
+ openBasket();
1483
+ else
1484
+ void addCurrent(); } }), tool && _jsx(Button, { variant: "secondary", size: "md", iconOnly: true, tipAbove: true, icon: TOOL_ICONS[tool], "data-action": "pick-again", label: COPY.capture.actions.pickAgain, onClick: () => startPicking(tool) }), props.saveToProject && output && _jsx(SaveButton, { save: saveAll, projectName: activeProject?.name }, output.fileName), props.makeRule && output && output.capture.meta.scope === 'component' && (_jsx(RuleButton, { make: () => props.makeRule(output.fileName, markdown) }, `rule ${output.fileName}`))] })] })] })) : (_jsxs(_Fragment, { children: [_jsxs("div", { class: "greet", children: [_jsx(Mascot, { pose: "annoyed", size: 96 }), _jsx("p", { class: "error", "data-part": "error", children: result.message })] }), tool && _jsx("div", { class: "row", children: _jsx(Button, { variant: "secondary", icon: TOOL_ICONS[tool], "data-action": "pick-again", onClick: () => startPicking(tool), children: COPY.capture.actions.pickAgain }) })] })) }))] }), picking && tool && (_jsx("div", { class: "pick-layer", "data-part": "pick-layer", onPointerMove: e => pickMove(e.clientX, e.clientY), onPointerDown: e => { e.preventDefault(); e.currentTarget.setPointerCapture?.(e.pointerId); pickDown(e.clientX, e.clientY); }, onPointerUp: e => { e.preventDefault(); pickUp(e.clientX, e.clientY); }, onWheel: e => pickWheel(e), onContextMenu: e => e.preventDefault() })), pixelMode && (_jsxs(_Fragment, { children: [_jsx("div", { class: "pixel-layer", "data-part": "pixel-layer", onPointerMove: e => setPixelHover(samplePixel(e.clientX, e.clientY)), onPointerLeave: () => setPixelHover(null), onClick: e => pickPixelAt(e.clientX, e.clientY) }), pixelHover && shot.current && (() => {
1485
+ // The loupe and the hex sit below and right of the pointer, or flip to stay in the window
1486
+ const left = pixelHover.x + 20 + LOUPE_PX > win.innerWidth ? pixelHover.x - 20 - LOUPE_PX : pixelHover.x + 20;
1487
+ const top = pixelHover.y + 20 + LOUPE_PX + 36 > win.innerHeight ? pixelHover.y - 20 - LOUPE_PX - 36 : pixelHover.y + 20;
1488
+ return (_jsxs(_Fragment, { children: [_jsx(Loupe, { shot: shot.current, x: pixelHover.x, y: pixelHover.y, hex: pixelHover.hex, left: left, top: top }), _jsxs("div", { class: "swatch", "data-part": "pixel-swatch", style: { top: `${top + LOUPE_PX + 8}px`, left: `${left + LOUPE_PX / 2 - 52}px` }, children: [_jsx("span", { class: "chip", style: { background: pixelHover.hex } }), pixelHover.hex] })] }));
1489
+ })()] })), choosing && picked && !pixelMode && (() => {
1490
+ const r = picked.el.getBoundingClientRect();
1491
+ return (_jsxs(_Fragment, { children: [_jsx("div", { class: `highlight locked${picked.eligibility.status === 'blocked' ? ' blocked' : ''}`, "data-part": "selection", style: { top: `${r.top}px`, left: `${r.left}px`, width: `${r.width}px`, height: `${r.height}px` } }), _jsx("div", { class: "label", style: { top: `${Math.max(4, r.top - 28)}px`, left: `${Math.max(4, r.left)}px` }, children: hoverLabel(picked.el) })] }));
1492
+ })(), hovered && rect && (_jsxs(_Fragment, { children: [_jsx("div", { class: `highlight${hoverElig?.status === 'blocked' ? ' blocked' : ''}`, style: { top: `${rect.top}px`, left: `${rect.left}px`, width: `${rect.width}px`, height: `${rect.height}px` } }), cs && (_jsxs(_Fragment, { children: [_jsx("div", { class: "pad", style: { top: `${rect.top + px(cs.borderTopWidth)}px`, left: `${rect.left + px(cs.borderLeftWidth)}px`, width: `${rect.width - px(cs.borderLeftWidth) - px(cs.borderRightWidth)}px`, height: `${rect.height - px(cs.borderTopWidth) - px(cs.borderBottomWidth)}px`, borderWidth: `${cs.paddingTop} ${cs.paddingRight} ${cs.paddingBottom} ${cs.paddingLeft}` } }), _jsx("div", { class: "margin", style: { top: `${rect.top - px(cs.marginTop)}px`, left: `${rect.left - px(cs.marginLeft)}px`, width: `${rect.width + px(cs.marginLeft) + px(cs.marginRight)}px`, height: `${rect.height + px(cs.marginTop) + px(cs.marginBottom)}px`, borderWidth: `${cs.marginTop} ${cs.marginRight} ${cs.marginBottom} ${cs.marginLeft}` } })] })), _jsxs("div", { class: "label", "data-part": "hover-label", style: { top: `${Math.max(4, rect.top - 28)}px`, left: `${Math.max(4, rect.left)}px` }, children: [hoverLabel(hovered), cs && `\npadding ${cs.padding} margin ${cs.margin}${/flex|grid/.test(cs.display) ? ` gap ${cs.rowGap} ${cs.columnGap}` : ''}`, hoverElig && hoverElig.status !== 'allowed' && _jsx("span", { class: "reason", children: hoverElig.reason })] })] }))] }));
1493
+ }
1494
+ //# sourceMappingURL=toolbar.js.map