gap-inspector 0.2.0 → 0.2.2

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,2946 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var reactDom = require('react-dom');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/index.tsx
8
+
9
+ // src/measurement.ts
10
+ var AXIS_PROPS = {
11
+ horizontal: {
12
+ start: "left",
13
+ end: "right",
14
+ size: "width",
15
+ beforeMargin: "marginLeft",
16
+ afterMargin: "marginRight",
17
+ beforePadding: "paddingLeft",
18
+ afterPadding: "paddingRight",
19
+ beforeBorder: "borderLeftWidth",
20
+ afterBorder: "borderRightWidth",
21
+ gap: "columnGap",
22
+ alternateGap: "gap",
23
+ perpStart: "top",
24
+ perpEnd: "bottom"
25
+ },
26
+ vertical: {
27
+ start: "top",
28
+ end: "bottom",
29
+ size: "height",
30
+ beforeMargin: "marginTop",
31
+ afterMargin: "marginBottom",
32
+ beforePadding: "paddingTop",
33
+ afterPadding: "paddingBottom",
34
+ beforeBorder: "borderTopWidth",
35
+ afterBorder: "borderBottomWidth",
36
+ gap: "rowGap",
37
+ alternateGap: "gap",
38
+ perpStart: "left",
39
+ perpEnd: "right"
40
+ }
41
+ };
42
+ function inferAxis(start, end) {
43
+ return Math.abs(end.x - start.x) >= Math.abs(end.y - start.y) ? "horizontal" : "vertical";
44
+ }
45
+ function measureGap(options) {
46
+ const doc = options.document ?? document;
47
+ const axis = options.axis ?? inferAxis(options.start, options.end);
48
+ const props = AXIS_PROPS[axis];
49
+ const ignoreElements = new Set(
50
+ (options.ignoreElements ?? []).filter((element) => Boolean(element))
51
+ );
52
+ const line = normalizeLine(axis, options.start, options.end);
53
+ const endpoints = findEndpointElementsFromPointer(doc, axis, options.start, options.end, ignoreElements) ?? (options.boundaryScan === false ? null : findBoundaryElements(doc, axis, line, ignoreElements));
54
+ if (!endpoints) {
55
+ return null;
56
+ }
57
+ if (endpoints.kind === "internal") {
58
+ return measureInternalGap(axis, endpoints);
59
+ }
60
+ const fromElement = endpoints.from;
61
+ const toElement = endpoints.to;
62
+ const fromRect = toGapRect(endpoints.from.getBoundingClientRect());
63
+ const toRect = toGapRect(endpoints.to.getBoundingClientRect());
64
+ const totalPx = Math.max(
65
+ 0,
66
+ toRect[props.start] - fromRect[props.end]
67
+ );
68
+ const commonAncestor = findCommonAncestor(fromElement, toElement);
69
+ const fromBranch = commonAncestor ? childBranchUnderAncestor(fromElement, commonAncestor) : null;
70
+ const toBranch = commonAncestor ? childBranchUnderAncestor(toElement, commonAncestor) : null;
71
+ const contributions = [];
72
+ const warnings = [];
73
+ for (const element of [fromElement, toElement]) {
74
+ if (element.tagName.toLowerCase() === "iframe") {
75
+ warnings.push(
76
+ `\`${selectorForElement(element)}\` is an iframe; its contents render in a separate document and cannot be inspected or attributed.`
77
+ );
78
+ }
79
+ }
80
+ appendGeometryWarnings(warnings, [fromElement, toElement, fromBranch, toBranch, commonAncestor]);
81
+ if (commonAncestor && fromBranch && fromBranch !== endpoints.from) {
82
+ contributions.push(
83
+ ...describeInternalSpace(axis, fromElement, fromBranch, "after", warnings)
84
+ );
85
+ }
86
+ if (commonAncestor && fromBranch && toBranch && fromBranch !== toBranch) {
87
+ contributions.push(
88
+ ...describeBetweenBranches(axis, commonAncestor, fromBranch, toBranch, warnings)
89
+ );
90
+ } else {
91
+ contributions.push(
92
+ makeUnknownContribution(axis, fromElement, totalPx, "Unable to isolate sibling branches for this gap.")
93
+ );
94
+ }
95
+ if (commonAncestor && toBranch && toBranch !== endpoints.to) {
96
+ contributions.push(
97
+ ...describeInternalSpace(axis, toElement, toBranch, "before", warnings)
98
+ );
99
+ }
100
+ const visibleContributions = limitContributionsToMeasuredGap(
101
+ collapseContributions(contributions).filter((contribution) => contribution.valuePx > 0.49),
102
+ totalPx,
103
+ warnings
104
+ );
105
+ const attributedPx = roundPx(
106
+ visibleContributions.reduce((sum, contribution) => sum + contribution.valuePx, 0)
107
+ );
108
+ const unattributedPx = roundPx(Math.max(0, totalPx - attributedPx));
109
+ if (unattributedPx > 0.49) {
110
+ warnings.push(
111
+ `${formatPx(unattributedPx)} is rendered space that could not be tied to a direct margin, padding, border, or gap declaration. Check flex/grid distribution, widths, min-width, transforms, or empty wrappers.`
112
+ );
113
+ }
114
+ const measurement = {
115
+ axis,
116
+ totalPx: roundPx(totalPx),
117
+ attributedPx,
118
+ unattributedPx,
119
+ from: elementInfo(fromElement),
120
+ to: elementInfo(toElement),
121
+ commonAncestor: commonAncestor ? elementInfo(commonAncestor) : void 0,
122
+ contributions: visibleContributions,
123
+ warnings
124
+ };
125
+ const equation = buildEquation(measurement);
126
+ return {
127
+ ...measurement,
128
+ equation,
129
+ markdown: buildMarkdown({ ...measurement, equation})
130
+ };
131
+ }
132
+ function inspectPoint(options) {
133
+ const doc = options.document ?? document;
134
+ const axis = options.axis ?? "horizontal";
135
+ const ignoreElements = new Set(
136
+ (options.ignoreElements ?? []).filter((element) => Boolean(element))
137
+ );
138
+ const marginInspection = inspectMarginAtPoint(doc, axis, options.point, ignoreElements);
139
+ if (marginInspection) {
140
+ return marginInspection;
141
+ }
142
+ const target = deepestElementAtPoint(doc, options.point.x, options.point.y, ignoreElements);
143
+ if (!target || isStructuralPageElement(target)) {
144
+ return inspectGapAtPoint(doc, axis, options.point, ignoreElements);
145
+ }
146
+ if (isContainerLikeHit(target, options.point)) {
147
+ const gapInspection = inspectGapAtPoint(doc, axis, options.point, ignoreElements);
148
+ if (gapInspection) {
149
+ return gapInspection;
150
+ }
151
+ }
152
+ return inspectElementAtPoint(axis, options.point, target);
153
+ }
154
+ function measureInternalGap(axis, endpoints) {
155
+ const props = AXIS_PROPS[axis];
156
+ const containerRect = toGapRect(endpoints.container.getBoundingClientRect());
157
+ const childRect = toGapRect(endpoints.child.getBoundingClientRect());
158
+ const totalPx = endpoints.side === "before" ? Math.max(0, childRect[props.start] - containerRect[props.start]) : Math.max(0, containerRect[props.end] - childRect[props.end]);
159
+ const warnings = [];
160
+ appendGeometryWarnings(warnings, [endpoints.container, endpoints.child]);
161
+ const visibleContributions = limitContributionsToMeasuredGap(
162
+ collapseContributions(
163
+ describeContainedGap(axis, endpoints.container, endpoints.child, endpoints.side, warnings)
164
+ ).filter((contribution) => contribution.valuePx > 0.49),
165
+ totalPx,
166
+ warnings
167
+ );
168
+ const attributedPx = roundPx(
169
+ visibleContributions.reduce((sum, contribution) => sum + contribution.valuePx, 0)
170
+ );
171
+ const unattributedPx = roundPx(Math.max(0, totalPx - attributedPx));
172
+ if (unattributedPx > 0.49) {
173
+ warnings.push(
174
+ `${formatPx(unattributedPx)} is internal rendered space that could not be tied to a direct margin, padding, border, or gap declaration. Check nested wrappers, explicit widths, or positioned children.`
175
+ );
176
+ }
177
+ const measurement = {
178
+ axis,
179
+ totalPx: roundPx(totalPx),
180
+ attributedPx,
181
+ unattributedPx,
182
+ from: elementInfo(endpoints.container),
183
+ to: elementInfo(endpoints.child),
184
+ commonAncestor: elementInfo(endpoints.container),
185
+ internalSide: endpoints.side,
186
+ contributions: visibleContributions,
187
+ warnings
188
+ };
189
+ const equation = buildEquation(measurement);
190
+ return {
191
+ ...measurement,
192
+ equation,
193
+ markdown: buildMarkdown({ ...measurement, equation})
194
+ };
195
+ }
196
+ function normalizeLine(axis, start, end) {
197
+ const props = AXIS_PROPS[axis];
198
+ const startAlong = axis === "horizontal" ? start.x : start.y;
199
+ const endAlong = axis === "horizontal" ? end.x : end.y;
200
+ const perp = axis === "horizontal" ? (start.y + end.y) / 2 : (start.x + end.x) / 2;
201
+ return {
202
+ min: Math.min(startAlong, endAlong),
203
+ max: Math.max(startAlong, endAlong),
204
+ mid: (startAlong + endAlong) / 2,
205
+ perp,
206
+ props
207
+ };
208
+ }
209
+ function findBoundaryElements(doc, axis, line, ignoreElements) {
210
+ const elements = uniqueElementCandidates(
211
+ queryAllDeep(doc.body).filter((element) => shouldInspectElement(element, ignoreElements)).map((element) => normalizeScannedTarget(element)).filter((element) => !isStructuralPageElement(element))
212
+ ).map((element) => ({ element, rect: toGapRect(element.getBoundingClientRect()) })).filter(({ rect }) => rect.width > 0 && rect.height > 0).filter(({ rect }) => line.perp >= rect[line.props.perpStart] - 2 && line.perp <= rect[line.props.perpEnd] + 2);
213
+ const fromCandidates = elements.filter(({ rect }) => rect[line.props.end] <= line.max + 8).sort((a, b) => edgeCandidateScore(a.element, a.rect, line, "from") - edgeCandidateScore(b.element, b.rect, line, "from"));
214
+ const toCandidates = elements.filter(({ rect }) => rect[line.props.start] >= line.min - 8).sort((a, b) => edgeCandidateScore(a.element, a.rect, line, "to") - edgeCandidateScore(b.element, b.rect, line, "to"));
215
+ const bestPair = chooseBestEndpointPair(fromCandidates, toCandidates, line);
216
+ if (bestPair) {
217
+ return bestPair;
218
+ }
219
+ const startElement = elementFromPointIgnoring(doc, axis, line.min, line.perp, ignoreElements);
220
+ const endElement = elementFromPointIgnoring(doc, axis, line.max, line.perp, ignoreElements);
221
+ if (!startElement || !endElement || startElement === endElement) {
222
+ return null;
223
+ }
224
+ const startRect = toGapRect(startElement.getBoundingClientRect());
225
+ const endRect = toGapRect(endElement.getBoundingClientRect());
226
+ return startRect[line.props.end] <= endRect[line.props.start] ? { kind: "normal", from: startElement, to: endElement } : { kind: "normal", from: endElement, to: startElement };
227
+ }
228
+ function findEndpointElementsFromPointer(doc, axis, start, end, ignoreElements) {
229
+ const startElement = deepestElementAtPoint(doc, start.x, start.y, ignoreElements);
230
+ const endElement = deepestElementAtPoint(doc, end.x, end.y, ignoreElements);
231
+ if (!startElement || !endElement || startElement === endElement) {
232
+ return null;
233
+ }
234
+ if (startElement.contains(endElement) || endElement.contains(startElement)) {
235
+ return containedEndpointPair(axis, startElement, endElement, start, end);
236
+ }
237
+ const props = AXIS_PROPS[axis];
238
+ const startRect = toGapRect(startElement.getBoundingClientRect());
239
+ const endRect = toGapRect(endElement.getBoundingClientRect());
240
+ if (startRect[props.end] <= endRect[props.start]) {
241
+ if (endRect[props.start] - startRect[props.end] < 0.5) {
242
+ return null;
243
+ }
244
+ return { kind: "normal", from: startElement, to: endElement };
245
+ }
246
+ if (endRect[props.end] <= startRect[props.start]) {
247
+ if (startRect[props.start] - endRect[props.end] < 0.5) {
248
+ return null;
249
+ }
250
+ return { kind: "normal", from: endElement, to: startElement };
251
+ }
252
+ return null;
253
+ }
254
+ function containedEndpointPair(axis, startElement, endElement, start, end) {
255
+ const startContainsEnd = startElement.contains(endElement);
256
+ const container = startContainsEnd ? startElement : endElement;
257
+ const child = startContainsEnd ? endElement : startElement;
258
+ const containerPoint = startContainsEnd ? start : end;
259
+ const childPoint = startContainsEnd ? end : start;
260
+ const childRect = toGapRect(child.getBoundingClientRect());
261
+ const props = AXIS_PROPS[axis];
262
+ const pointAlong = axis === "horizontal" ? containerPoint.x : containerPoint.y;
263
+ const childPointAlong = axis === "horizontal" ? childPoint.x : childPoint.y;
264
+ const side = pointAlong <= childRect[props.start] ? "before" : pointAlong >= childRect[props.end] ? "after" : pointAlong < childPointAlong ? "before" : "after";
265
+ const containerRect = toGapRect(container.getBoundingClientRect());
266
+ const totalPx = side === "before" ? childRect[props.start] - containerRect[props.start] : containerRect[props.end] - childRect[props.end];
267
+ if (totalPx < 0.5) {
268
+ return null;
269
+ }
270
+ return {
271
+ kind: "internal",
272
+ container,
273
+ child,
274
+ side
275
+ };
276
+ }
277
+ function deepestElementAtPoint(doc, x, y, ignoreElements) {
278
+ const elements = elementsFromPointDeep(doc, x, y, ignoreElements);
279
+ for (const element of elements) {
280
+ if (!(element instanceof HTMLElement)) {
281
+ continue;
282
+ }
283
+ if (!shouldInspectElement(element, ignoreElements)) {
284
+ continue;
285
+ }
286
+ if (isStructuralPageElement(element)) {
287
+ continue;
288
+ }
289
+ return element;
290
+ }
291
+ return null;
292
+ }
293
+ function elementsFromPointDeep(doc, x, y, ignoreElements) {
294
+ const layers = [];
295
+ let scope = doc;
296
+ for (let depth = 0; depth < 12; depth += 1) {
297
+ const elements = scope.elementsFromPoint(x, y).filter((element) => element.getRootNode() === scope);
298
+ if (!elements.length) {
299
+ break;
300
+ }
301
+ layers.push(elements);
302
+ const top = elements.find(
303
+ (element) => element instanceof HTMLElement && !ignoreElements.has(element) && !containsAnyIgnored(element, ignoreElements)
304
+ );
305
+ const shadowRoot = top instanceof HTMLElement ? top.shadowRoot : null;
306
+ if (!shadowRoot) {
307
+ break;
308
+ }
309
+ scope = shadowRoot;
310
+ }
311
+ return layers.reverse().flat();
312
+ }
313
+ function queryAllDeep(scope) {
314
+ const results = [];
315
+ const visit = (node) => {
316
+ for (const element of Array.from(node.querySelectorAll("*"))) {
317
+ results.push(element);
318
+ if (element.shadowRoot) {
319
+ visit(element.shadowRoot);
320
+ }
321
+ }
322
+ };
323
+ visit(scope);
324
+ return results;
325
+ }
326
+ function parentThroughShadow(element) {
327
+ if (element.parentElement) {
328
+ return element.parentElement;
329
+ }
330
+ const root = element.getRootNode();
331
+ return root instanceof ShadowRoot ? root.host : null;
332
+ }
333
+ function normalizeScannedTarget(element) {
334
+ let current = element;
335
+ while (current.parentElement && !isStructuralPageElement(current.parentElement) && shouldClimbPointTarget(current, current.parentElement)) {
336
+ current = current.parentElement;
337
+ }
338
+ return current;
339
+ }
340
+ function uniqueElementCandidates(elements) {
341
+ return Array.from(new Set(elements));
342
+ }
343
+ function shouldClimbPointTarget(element, parent) {
344
+ const tagName = element.tagName.toLowerCase();
345
+ const rect = element.getBoundingClientRect();
346
+ const parentRect = parent.getBoundingClientRect();
347
+ const style = getComputedStyle(element);
348
+ if (["span", "strong", "em", "small", "label", "b", "i"].includes(tagName)) {
349
+ return true;
350
+ }
351
+ if (style.display === "inline") {
352
+ return true;
353
+ }
354
+ if (rect.height < 22 && parentRect.height > rect.height * 1.5) {
355
+ return true;
356
+ }
357
+ if (rect.width < 32 && parentRect.width > rect.width * 1.5) {
358
+ return true;
359
+ }
360
+ return false;
361
+ }
362
+ var STRUCTURAL_ROOT_IDS = /* @__PURE__ */ new Set(["root", "app", "__next", "__nuxt"]);
363
+ function isStructuralPageElement(element) {
364
+ const tagName = element.tagName.toLowerCase();
365
+ return tagName === "html" || tagName === "body" || STRUCTURAL_ROOT_IDS.has(element.id);
366
+ }
367
+ function edgeCandidateScore(element, rect, line, side) {
368
+ const edge = side === "from" ? rect[line.props.end] : rect[line.props.start];
369
+ const target = side === "from" ? line.min : line.max;
370
+ const endpointDistance = Math.abs(edge - target);
371
+ const elementSizePenalty = Math.sqrt(rectArea(rect)) * 0.015;
372
+ const depthReward = elementDepth(element) * 0.35;
373
+ return endpointDistance + elementSizePenalty - depthReward;
374
+ }
375
+ function chooseBestEndpointPair(fromCandidates, toCandidates, line) {
376
+ const drawnGap = line.max - line.min;
377
+ let best = null;
378
+ for (const fromCandidate of fromCandidates.slice(0, 40)) {
379
+ for (const toCandidate of toCandidates.slice(0, 40)) {
380
+ if (fromCandidate.element === toCandidate.element) {
381
+ continue;
382
+ }
383
+ if (fromCandidate.element.contains(toCandidate.element) || toCandidate.element.contains(fromCandidate.element)) {
384
+ continue;
385
+ }
386
+ const gap = toCandidate.rect[line.props.start] - fromCandidate.rect[line.props.end];
387
+ if (gap < 0.5) {
388
+ continue;
389
+ }
390
+ const score = edgeCandidateScore(fromCandidate.element, fromCandidate.rect, line, "from") + edgeCandidateScore(toCandidate.element, toCandidate.rect, line, "to") + Math.abs(gap - drawnGap) * 0.4 + sharedAncestorDistance(fromCandidate.element, toCandidate.element) * 0.2;
391
+ if (!best || score < best.score) {
392
+ best = {
393
+ from: fromCandidate.element,
394
+ to: toCandidate.element,
395
+ score
396
+ };
397
+ }
398
+ }
399
+ }
400
+ return best ? { kind: "normal", from: best.from, to: best.to } : null;
401
+ }
402
+ function describeInternalSpace(axis, element, branch, direction, warnings) {
403
+ const levels = [];
404
+ const props = AXIS_PROPS[axis];
405
+ let current = element;
406
+ while (current && current !== branch) {
407
+ const parent = parentThroughShadow(current);
408
+ if (!parent) {
409
+ break;
410
+ }
411
+ const currentRect = toGapRect(current.getBoundingClientRect());
412
+ const parentRect = toGapRect(parent.getBoundingClientRect());
413
+ const style = getComputedStyle(parent);
414
+ const childStyle = getComputedStyle(current);
415
+ const measured = direction === "after" ? parentRect[props.end] - currentRect[props.end] : currentRect[props.start] - parentRect[props.start];
416
+ warnNegativeMargin(warnings, childStyle, direction === "after" ? props.afterMargin : props.beforeMargin, current);
417
+ if (measured > 0.49) {
418
+ const marginProperty = direction === "after" ? props.afterMargin : props.beforeMargin;
419
+ const paddingProperty = direction === "after" ? props.afterPadding : props.beforePadding;
420
+ const borderProperty = direction === "after" ? props.afterBorder : props.beforeBorder;
421
+ const margin = positivePx(childStyle[marginProperty]);
422
+ const padding = positivePx(style[paddingProperty]);
423
+ const border = positivePx(style[borderProperty]);
424
+ const scrollbar = scrollbarGutterPx(axis, direction, parent, style);
425
+ const residual = measured - margin - padding - border - scrollbar;
426
+ const level = [];
427
+ pushContribution(level, "margin", marginProperty, margin, childStyle[marginProperty], current);
428
+ pushContribution(
429
+ level,
430
+ "layout",
431
+ direction === "after" ? "inner inline-end space" : "inner inline-start space",
432
+ residual,
433
+ void 0,
434
+ parent,
435
+ "Rendered space inside this wrapper between the measured element and the wrapper edge."
436
+ );
437
+ pushContribution(level, "padding", paddingProperty, padding, style[paddingProperty], parent);
438
+ pushContribution(
439
+ level,
440
+ "scrollbar",
441
+ "scrollbar gutter",
442
+ Math.min(scrollbar, measured),
443
+ style.scrollbarGutter,
444
+ parent,
445
+ "Native scrollbar gutter inside this scroll container."
446
+ );
447
+ pushContribution(level, "border", borderProperty, border, style[borderProperty], parent);
448
+ if (direction === "before") {
449
+ level.reverse();
450
+ }
451
+ levels.push(level);
452
+ }
453
+ current = parent;
454
+ }
455
+ if (direction === "before") {
456
+ levels.reverse();
457
+ }
458
+ return levels.flat();
459
+ }
460
+ function describeBetweenBranches(axis, ancestor, fromBranch, toBranch, warnings) {
461
+ const props = AXIS_PROPS[axis];
462
+ const ancestorStyle = getComputedStyle(ancestor);
463
+ const fromStyle = getComputedStyle(fromBranch);
464
+ const toStyle = getComputedStyle(toBranch);
465
+ const fromRect = toGapRect(fromBranch.getBoundingClientRect());
466
+ const toRect = toGapRect(toBranch.getBoundingClientRect());
467
+ const measured = Math.max(0, toRect[props.start] - fromRect[props.end]);
468
+ const contributions = [];
469
+ const afterMargin = positivePx(fromStyle[props.afterMargin]);
470
+ const beforeMargin = positivePx(toStyle[props.beforeMargin]);
471
+ const gap = layoutGapPx(ancestorStyle, props.gap, props.alternateGap);
472
+ warnNegativeMargin(warnings, fromStyle, props.afterMargin, fromBranch);
473
+ warnNegativeMargin(warnings, toStyle, props.beforeMargin, toBranch);
474
+ const marginsCollapse = axis === "vertical" && !isGapLayout(ancestorStyle.display) && !ancestorStyle.display.includes("table") && isBlockLevel(fromStyle) && isBlockLevel(toStyle);
475
+ if (marginsCollapse && (afterMargin > 0.49 || beforeMargin > 0.49)) {
476
+ const fromWins = afterMargin >= beforeMargin;
477
+ const winner = fromWins ? { property: props.afterMargin, value: afterMargin, cssValue: fromStyle[props.afterMargin], element: fromBranch } : { property: props.beforeMargin, value: beforeMargin, cssValue: toStyle[props.beforeMargin], element: toBranch };
478
+ const loser = fromWins ? { property: props.beforeMargin, value: beforeMargin, cssValue: toStyle[props.beforeMargin] } : { property: props.afterMargin, value: afterMargin, cssValue: fromStyle[props.afterMargin] };
479
+ pushContribution(
480
+ contributions,
481
+ "margin",
482
+ winner.property,
483
+ winner.value,
484
+ winner.cssValue,
485
+ winner.element,
486
+ loser.value > 0.49 ? `Adjacent vertical margins collapse: ${cssPropertyName(loser.property)} (${loser.cssValue}) on the sibling collapsed into this larger margin.` : void 0
487
+ );
488
+ } else {
489
+ pushContribution(contributions, "margin", props.afterMargin, afterMargin, fromStyle[props.afterMargin], fromBranch);
490
+ }
491
+ if (isGapLayout(ancestorStyle.display)) {
492
+ pushContribution(
493
+ contributions,
494
+ "gap",
495
+ props.gap,
496
+ Math.min(gap, measured),
497
+ ancestorStyle[props.gap] || ancestorStyle[props.alternateGap],
498
+ ancestor,
499
+ `${ancestorStyle.display} parent`
500
+ );
501
+ }
502
+ const attributedMargins = marginsCollapse ? Math.max(afterMargin, beforeMargin) : afterMargin + beforeMargin;
503
+ const residual = measured - attributedMargins - (isGapLayout(ancestorStyle.display) ? gap : 0);
504
+ pushContribution(
505
+ contributions,
506
+ "layout",
507
+ layoutDistributionProperty(ancestorStyle),
508
+ residual,
509
+ void 0,
510
+ ancestor,
511
+ "Rendered space between the sibling layout branches."
512
+ );
513
+ if (!marginsCollapse) {
514
+ pushContribution(contributions, "margin", props.beforeMargin, beforeMargin, toStyle[props.beforeMargin], toBranch);
515
+ }
516
+ return contributions;
517
+ }
518
+ function describeContainedGap(axis, container, child, side, warnings) {
519
+ const props = AXIS_PROPS[axis];
520
+ const containerRect = toGapRect(container.getBoundingClientRect());
521
+ const childRect = toGapRect(child.getBoundingClientRect());
522
+ const containerStyle = getComputedStyle(container);
523
+ const childStyle = getComputedStyle(child);
524
+ const measured = side === "before" ? childRect[props.start] - containerRect[props.start] : containerRect[props.end] - childRect[props.end];
525
+ const contributions = [];
526
+ const paddingProperty = side === "before" ? props.beforePadding : props.afterPadding;
527
+ const borderProperty = side === "before" ? props.beforeBorder : props.afterBorder;
528
+ const marginProperty = side === "before" ? props.beforeMargin : props.afterMargin;
529
+ const padding = positivePx(containerStyle[paddingProperty]);
530
+ const border = positivePx(containerStyle[borderProperty]);
531
+ const margin = positivePx(childStyle[marginProperty]);
532
+ warnNegativeMargin(warnings, childStyle, marginProperty, child);
533
+ const residual = measured - padding - border - margin;
534
+ const residualContribution = [
535
+ "layout",
536
+ side === "before" ? "internal start space" : "internal end space",
537
+ residual,
538
+ void 0,
539
+ container,
540
+ "Rendered internal space between the container edge and the selected child."
541
+ ];
542
+ if (side === "before") {
543
+ pushContribution(contributions, "border", borderProperty, border, containerStyle[borderProperty], container);
544
+ pushContribution(contributions, "padding", paddingProperty, padding, containerStyle[paddingProperty], container);
545
+ pushContribution(contributions, ...residualContribution);
546
+ pushContribution(contributions, "margin", marginProperty, margin, childStyle[marginProperty], child);
547
+ } else {
548
+ pushContribution(contributions, "margin", marginProperty, margin, childStyle[marginProperty], child);
549
+ pushContribution(contributions, ...residualContribution);
550
+ pushContribution(contributions, "padding", paddingProperty, padding, containerStyle[paddingProperty], container);
551
+ pushContribution(contributions, "border", borderProperty, border, containerStyle[borderProperty], container);
552
+ }
553
+ return contributions;
554
+ }
555
+ function makeUnknownContribution(axis, element, valuePx, note) {
556
+ return {
557
+ kind: "unknown",
558
+ property: `${axis} gap`,
559
+ valuePx: roundPx(valuePx),
560
+ selector: selectorForElement(element),
561
+ element: elementInfo(element),
562
+ note
563
+ };
564
+ }
565
+ function pushContribution(contributions, kind, property, valuePx, cssValue, element, note) {
566
+ if (valuePx <= 0.49) {
567
+ return;
568
+ }
569
+ contributions.push({
570
+ kind,
571
+ property: cssPropertyName(property),
572
+ valuePx: roundPx(valuePx),
573
+ cssValue,
574
+ selector: selectorForElement(element),
575
+ element: elementInfo(element),
576
+ note
577
+ });
578
+ }
579
+ function collapseContributions(contributions) {
580
+ const byKey = /* @__PURE__ */ new Map();
581
+ for (const contribution of contributions) {
582
+ const key = [
583
+ contribution.kind,
584
+ contribution.property,
585
+ contribution.selector,
586
+ contribution.note ?? ""
587
+ ].join("::");
588
+ const existing = byKey.get(key);
589
+ if (existing) {
590
+ existing.valuePx = roundPx(existing.valuePx + contribution.valuePx);
591
+ } else {
592
+ byKey.set(key, { ...contribution });
593
+ }
594
+ }
595
+ return Array.from(byKey.values());
596
+ }
597
+ function limitContributionsToMeasuredGap(contributions, totalPx, warnings) {
598
+ let remaining = roundPx(totalPx);
599
+ const limited = [];
600
+ let capped = false;
601
+ for (const contribution of contributions) {
602
+ if (remaining <= 0.49) {
603
+ capped = true;
604
+ continue;
605
+ }
606
+ if (contribution.valuePx > remaining) {
607
+ capped = true;
608
+ limited.push({
609
+ ...contribution,
610
+ valuePx: remaining,
611
+ note: [
612
+ contribution.note,
613
+ `Raw computed value was ${formatPx(contribution.valuePx)}; capped to the remaining measured gap.`
614
+ ].filter(Boolean).join(" ")
615
+ });
616
+ remaining = 0;
617
+ continue;
618
+ }
619
+ limited.push(contribution);
620
+ remaining = roundPx(remaining - contribution.valuePx);
621
+ }
622
+ if (capped) {
623
+ warnings.push(
624
+ "Candidate contributors exceeded the rendered gap, usually because nested wrappers overlap in the measurement path. Values were capped so the equation stays tied to measured geometry."
625
+ );
626
+ }
627
+ return limited;
628
+ }
629
+ function buildEquation(measurement) {
630
+ const parts = measurement.contributions.map((contribution) => formatPx(contribution.valuePx));
631
+ if (measurement.unattributedPx > 0.49) {
632
+ parts.push(`${formatPx(measurement.unattributedPx)} unattributed`);
633
+ }
634
+ return `${parts.length ? parts.join(" + ") : "0px"} = ${formatPx(measurement.totalPx)}`;
635
+ }
636
+ function buildMarkdown(measurement) {
637
+ const lines = [
638
+ `Measured ${measurement.axis} gap: ${formatPx(measurement.totalPx)}`,
639
+ "",
640
+ `From: \`${measurement.from.selector}\``,
641
+ `To: \`${measurement.to.selector}\``
642
+ ];
643
+ if (measurement.commonAncestor) {
644
+ lines.push(`Common ancestor: \`${measurement.commonAncestor.selector}\``);
645
+ }
646
+ lines.push("", "Contributions:");
647
+ if (measurement.contributions.length === 0) {
648
+ lines.push("- No direct box-model contributors found.");
649
+ } else {
650
+ for (const contribution of measurement.contributions) {
651
+ const cssValue = contribution.cssValue ? ` (${contribution.cssValue})` : "";
652
+ const note = contribution.note ? ` - ${contribution.note}` : "";
653
+ lines.push(
654
+ `- ${formatPx(contribution.valuePx)} from \`${contribution.selector}\` ${contribution.property}${cssValue}${note}`
655
+ );
656
+ }
657
+ }
658
+ lines.push("", `Equation: ${measurement.equation}`);
659
+ if (measurement.warnings.length) {
660
+ lines.push("", "Warnings:");
661
+ for (const warning of measurement.warnings) {
662
+ lines.push(`- ${warning}`);
663
+ }
664
+ }
665
+ return lines.join("\n");
666
+ }
667
+ function shouldInspectElement(element, ignoreElements) {
668
+ if (ignoreElements.has(element) || containsAnyIgnored(element, ignoreElements)) {
669
+ return false;
670
+ }
671
+ const tagName = element.tagName.toLowerCase();
672
+ if (["script", "style", "template", "noscript", "meta", "link"].includes(tagName)) {
673
+ return false;
674
+ }
675
+ const style = getComputedStyle(element);
676
+ return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
677
+ }
678
+ function containsAnyIgnored(element, ignoreElements) {
679
+ for (const ignored of ignoreElements) {
680
+ if (ignored.contains(element) || element.contains(ignored)) {
681
+ return true;
682
+ }
683
+ }
684
+ return false;
685
+ }
686
+ function elementFromPointIgnoring(doc, axis, along, perp, ignoreElements) {
687
+ const x = axis === "horizontal" ? along : perp;
688
+ const y = axis === "horizontal" ? perp : along;
689
+ return elementsFromPointDeep(doc, x, y, ignoreElements).find(
690
+ (element) => element instanceof HTMLElement && !ignoreElements.has(element) && !containsAnyIgnored(element, ignoreElements)
691
+ ) ?? null;
692
+ }
693
+ function findCommonAncestor(a, b) {
694
+ const ancestors = /* @__PURE__ */ new Set();
695
+ let current = a;
696
+ while (current) {
697
+ ancestors.add(current);
698
+ current = parentThroughShadow(current);
699
+ }
700
+ current = b;
701
+ while (current) {
702
+ if (ancestors.has(current)) {
703
+ return current;
704
+ }
705
+ current = parentThroughShadow(current);
706
+ }
707
+ return null;
708
+ }
709
+ function childBranchUnderAncestor(element, ancestor) {
710
+ let current = element;
711
+ let parent = parentThroughShadow(current);
712
+ while (parent && parent !== ancestor) {
713
+ current = parent;
714
+ parent = parentThroughShadow(current);
715
+ }
716
+ return parent === ancestor ? current : null;
717
+ }
718
+ function layoutGapPx(style, primary, fallback) {
719
+ return positivePx(style[primary]) || positivePx(style[fallback]);
720
+ }
721
+ function isGapLayout(display) {
722
+ return display.includes("flex") || display.includes("grid");
723
+ }
724
+ function isBlockLevel(style) {
725
+ return !style.display.startsWith("inline") && style.cssFloat === "none" && style.position !== "absolute" && style.position !== "fixed";
726
+ }
727
+ function warnNegativeMargin(warnings, style, property, element) {
728
+ const cssValue = style[property];
729
+ const parsed = Number.parseFloat(cssValue);
730
+ if (Number.isFinite(parsed) && parsed < -0.49) {
731
+ const warning = `${cssPropertyName(property)}: ${cssValue} on \`${selectorForElement(element)}\` pulls the boxes closer together; negative margins are not listed as contributors.`;
732
+ if (!warnings.includes(warning)) {
733
+ warnings.push(warning);
734
+ }
735
+ }
736
+ }
737
+ function appendGeometryWarnings(warnings, elements) {
738
+ const seen = /* @__PURE__ */ new Set();
739
+ for (const element of elements) {
740
+ if (!element || seen.has(element)) {
741
+ continue;
742
+ }
743
+ seen.add(element);
744
+ const style = getComputedStyle(element);
745
+ const zoom = style.getPropertyValue("zoom");
746
+ const transformed = style.transform !== "none" || isActiveTransformValue(style.getPropertyValue("translate")) || isActiveTransformValue(style.getPropertyValue("rotate")) || isActiveTransformValue(style.getPropertyValue("scale")) || zoom !== "" && zoom !== "1" && zoom !== "normal";
747
+ if (transformed) {
748
+ warnings.push(
749
+ `\`${selectorForElement(element)}\` is transformed (transform/translate/rotate/scale/zoom); rendered pixels may not match its computed CSS values.`
750
+ );
751
+ }
752
+ }
753
+ }
754
+ function isActiveTransformValue(value) {
755
+ return value !== "" && value !== "none";
756
+ }
757
+ function scrollbarGutterPx(axis, direction, element, style) {
758
+ if (!(element instanceof HTMLElement)) {
759
+ return 0;
760
+ }
761
+ const directionStyle = style.direction || "ltr";
762
+ if (axis === "horizontal") {
763
+ const overflowY = style.overflowY;
764
+ const canScrollY = overflowY === "auto" || overflowY === "scroll";
765
+ const hasScrollableContent2 = element.scrollHeight > element.clientHeight;
766
+ if (!canScrollY || !hasScrollableContent2 && overflowY !== "scroll") {
767
+ return 0;
768
+ }
769
+ const borderLeft = positivePx(style.borderLeftWidth);
770
+ const borderRight = positivePx(style.borderRightWidth);
771
+ const gutter2 = Math.max(0, element.offsetWidth - element.clientWidth - borderLeft - borderRight);
772
+ const gutterIsOnMeasuredSide = direction === "after" && directionStyle !== "rtl" || direction === "before" && directionStyle === "rtl";
773
+ return gutterIsOnMeasuredSide ? gutter2 : 0;
774
+ }
775
+ const overflowX = style.overflowX;
776
+ const canScrollX = overflowX === "auto" || overflowX === "scroll";
777
+ const hasScrollableContent = element.scrollWidth > element.clientWidth;
778
+ if (!canScrollX || !hasScrollableContent && overflowX !== "scroll") {
779
+ return 0;
780
+ }
781
+ const borderTop = positivePx(style.borderTopWidth);
782
+ const borderBottom = positivePx(style.borderBottomWidth);
783
+ const gutter = Math.max(0, element.offsetHeight - element.clientHeight - borderTop - borderBottom);
784
+ return direction === "after" ? gutter : 0;
785
+ }
786
+ function layoutDistributionProperty(style) {
787
+ if (style.display.includes("flex")) {
788
+ return `flex ${style.justifyContent || "layout space"}`;
789
+ }
790
+ if (style.display.includes("grid")) {
791
+ return "grid track/layout space";
792
+ }
793
+ if (style.position !== "static") {
794
+ return `${style.position} positioning`;
795
+ }
796
+ return "layout space";
797
+ }
798
+ function selectorForElement(element) {
799
+ const root = element.getRootNode();
800
+ if (root instanceof ShadowRoot) {
801
+ return `${selectorForElement(root.host)} >>> ${selectorWithinRoot(element, root)}`;
802
+ }
803
+ return selectorWithinRoot(element, element.ownerDocument ?? document);
804
+ }
805
+ function selectorWithinRoot(element, root) {
806
+ if (element.id) {
807
+ const idSelector = `#${cssEscape(element.id)}`;
808
+ if (isUniqueInRoot(idSelector, element, root)) {
809
+ return idSelector;
810
+ }
811
+ }
812
+ const testId = element.getAttribute("data-testid") ?? element.getAttribute("data-test");
813
+ if (testId) {
814
+ const attribute = element.hasAttribute("data-testid") ? "data-testid" : "data-test";
815
+ const testSelector = `[${attribute}="${testId.replace(/"/g, '\\"')}"]`;
816
+ if (isUniqueInRoot(testSelector, element, root)) {
817
+ return testSelector;
818
+ }
819
+ }
820
+ const readable = readablePathSelector(element);
821
+ if (readable && isUniqueInRoot(readable, element, root)) {
822
+ return readable;
823
+ }
824
+ return uniquePathSelector(element);
825
+ }
826
+ function readablePathSelector(element) {
827
+ const parts = [];
828
+ let current = element;
829
+ while (current && parts.length < 4 && current.tagName.toLowerCase() !== "html") {
830
+ const tag = current.tagName.toLowerCase();
831
+ const classes = Array.from(current.classList).filter((className) => !className.includes(":")).slice(0, 2).map((className) => `.${cssEscape(className)}`).join("");
832
+ const nth = nthOfType(current);
833
+ parts.unshift(`${tag}${classes}${nth ? `:nth-of-type(${nth})` : ""}`);
834
+ current = current.parentElement;
835
+ }
836
+ return parts.join(" > ");
837
+ }
838
+ function isUniqueInRoot(selector, element, root) {
839
+ try {
840
+ const matches = root.querySelectorAll(selector);
841
+ return matches.length === 1 && matches[0] === element;
842
+ } catch {
843
+ return false;
844
+ }
845
+ }
846
+ function uniquePathSelector(element) {
847
+ const parts = [];
848
+ let current = element;
849
+ while (current) {
850
+ const tag = current.tagName.toLowerCase();
851
+ const parent = current.parentNode;
852
+ if (parent && (parent instanceof Element || parent instanceof ShadowRoot)) {
853
+ const index = Array.prototype.indexOf.call(parent.children, current) + 1;
854
+ parts.unshift(`${tag}:nth-child(${index})`);
855
+ current = parent instanceof Element ? parent : null;
856
+ } else {
857
+ parts.unshift(tag);
858
+ current = null;
859
+ }
860
+ }
861
+ return parts.join(" > ");
862
+ }
863
+ function resolveSelector(selector, doc = document) {
864
+ const segments = selector.split(" >>> ");
865
+ let scope = doc;
866
+ let element = null;
867
+ for (let index = 0; index < segments.length; index += 1) {
868
+ try {
869
+ element = scope.querySelector(segments[index]);
870
+ } catch {
871
+ return null;
872
+ }
873
+ if (!element) {
874
+ return null;
875
+ }
876
+ if (index < segments.length - 1) {
877
+ if (!element.shadowRoot) {
878
+ return null;
879
+ }
880
+ scope = element.shadowRoot;
881
+ }
882
+ }
883
+ return element;
884
+ }
885
+ function nthOfType(element) {
886
+ const parent = element.parentElement;
887
+ if (!parent) {
888
+ return null;
889
+ }
890
+ const sameTagSiblings = Array.from(parent.children).filter((child) => child.tagName === element.tagName);
891
+ if (sameTagSiblings.length <= 1) {
892
+ return null;
893
+ }
894
+ return sameTagSiblings.indexOf(element) + 1;
895
+ }
896
+ function elementInfo(element) {
897
+ return {
898
+ selector: selectorForElement(element),
899
+ tagName: element.tagName.toLowerCase(),
900
+ className: element.getAttribute("class") ?? "",
901
+ rect: toGapRect(element.getBoundingClientRect()),
902
+ element
903
+ };
904
+ }
905
+ function inspectElementAtPoint(axis, point, element) {
906
+ const rect = toGapRect(element.getBoundingClientRect());
907
+ const style = getComputedStyle(element);
908
+ const borderRect = rect;
909
+ const paddingRect = shrinkRect(borderRect, {
910
+ top: positivePx(style.borderTopWidth),
911
+ right: positivePx(style.borderRightWidth),
912
+ bottom: positivePx(style.borderBottomWidth),
913
+ left: positivePx(style.borderLeftWidth)
914
+ });
915
+ const contentRect = shrinkRect(paddingRect, {
916
+ top: positivePx(style.paddingTop),
917
+ right: positivePx(style.paddingRight),
918
+ bottom: positivePx(style.paddingBottom),
919
+ left: positivePx(style.paddingLeft)
920
+ });
921
+ let region = "content";
922
+ let property = "content box";
923
+ let cssValue;
924
+ let totalPx;
925
+ if (!pointInRect(point, paddingRect)) {
926
+ region = "border";
927
+ const side = nearestSide(point, borderRect);
928
+ property = cssPropertyName(`border${capitalize(side)}Width`);
929
+ cssValue = style[`border${capitalize(side)}Width`];
930
+ totalPx = positivePx(cssValue);
931
+ } else if (!pointInRect(point, contentRect)) {
932
+ region = "padding";
933
+ const side = nearestSide(point, paddingRect);
934
+ property = cssPropertyName(`padding${capitalize(side)}`);
935
+ cssValue = style[`padding${capitalize(side)}`];
936
+ totalPx = positivePx(cssValue);
937
+ }
938
+ const inspection = {
939
+ kind: "point",
940
+ axis,
941
+ point,
942
+ region,
943
+ totalPx,
944
+ property,
945
+ cssValue,
946
+ element: elementInfo(element),
947
+ rect,
948
+ note: `Clicked inside ${region} region.`,
949
+ markdown: ""
950
+ };
951
+ return {
952
+ ...inspection,
953
+ markdown: buildPointMarkdown(inspection)
954
+ };
955
+ }
956
+ function inspectMarginAtPoint(doc, axis, point, ignoreElements) {
957
+ const candidates = queryAllDeep(doc.body).filter((element) => shouldInspectElement(element, ignoreElements)).map((element) => {
958
+ const style = getComputedStyle(element);
959
+ const rect = toGapRect(element.getBoundingClientRect());
960
+ const marginRect = expandRect(rect, {
961
+ top: positivePx(style.marginTop),
962
+ right: positivePx(style.marginRight),
963
+ bottom: positivePx(style.marginBottom),
964
+ left: positivePx(style.marginLeft)
965
+ });
966
+ return { element, style, rect, marginRect };
967
+ }).filter(({ rect, marginRect }) => pointInRect(point, marginRect) && !pointInRect(point, rect)).sort((a, b) => rectArea(a.marginRect) - rectArea(b.marginRect));
968
+ const candidate = candidates[0];
969
+ if (!candidate) {
970
+ return null;
971
+ }
972
+ const side = nearestMarginSide(point, candidate.rect);
973
+ const property = cssPropertyName(`margin${capitalize(side)}`);
974
+ const cssValue = candidate.style[`margin${capitalize(side)}`];
975
+ const inspection = {
976
+ kind: "point",
977
+ axis,
978
+ point,
979
+ region: "margin",
980
+ totalPx: positivePx(cssValue),
981
+ property,
982
+ cssValue,
983
+ element: elementInfo(candidate.element),
984
+ rect: candidate.marginRect,
985
+ note: "Clicked inside computed margin area.",
986
+ markdown: ""
987
+ };
988
+ return {
989
+ ...inspection,
990
+ markdown: buildPointMarkdown(inspection)
991
+ };
992
+ }
993
+ function inspectGapAtPoint(doc, axis, point, ignoreElements) {
994
+ const props = AXIS_PROPS[axis];
995
+ const along = axis === "horizontal" ? point.x : point.y;
996
+ const perp = axis === "horizontal" ? point.y : point.x;
997
+ const candidates = uniqueElementCandidates(
998
+ queryAllDeep(doc.body).filter((element) => shouldInspectElement(element, ignoreElements)).map((element) => normalizeScannedTarget(element)).filter((element) => !isStructuralPageElement(element))
999
+ ).map((element) => ({ element, rect: toGapRect(element.getBoundingClientRect()) })).filter(({ rect: rect2 }) => perp >= rect2[props.perpStart] - 1 && perp <= rect2[props.perpEnd] + 1).filter(({ rect: rect2 }) => !pointInRect(point, rect2));
1000
+ const before = candidates.filter(({ rect: rect2 }) => rect2[props.end] <= along).sort((a, b) => b.rect[props.end] - a.rect[props.end] || rectArea(a.rect) - rectArea(b.rect))[0];
1001
+ const after = candidates.filter(({ rect: rect2 }) => rect2[props.start] >= along).sort((a, b) => a.rect[props.start] - b.rect[props.start] || rectArea(a.rect) - rectArea(b.rect))[0];
1002
+ if (!before || !after || before.element === after.element) {
1003
+ return null;
1004
+ }
1005
+ const totalPx = roundPx(after.rect[props.start] - before.rect[props.end]);
1006
+ if (totalPx < 0.5) {
1007
+ return null;
1008
+ }
1009
+ const rect = axis === "horizontal" ? {
1010
+ left: before.rect.right,
1011
+ right: after.rect.left,
1012
+ top: perp - 6,
1013
+ bottom: perp + 6,
1014
+ width: totalPx,
1015
+ height: 12
1016
+ } : {
1017
+ left: perp - 6,
1018
+ right: perp + 6,
1019
+ top: before.rect.bottom,
1020
+ bottom: after.rect.top,
1021
+ width: 12,
1022
+ height: totalPx
1023
+ };
1024
+ const inspection = {
1025
+ kind: "point",
1026
+ axis,
1027
+ point,
1028
+ region: "gap",
1029
+ totalPx,
1030
+ property: `${axis} rendered gap`,
1031
+ from: elementInfo(before.element),
1032
+ to: elementInfo(after.element),
1033
+ rect,
1034
+ note: "Clicked in empty rendered space between two visible edges.",
1035
+ markdown: ""
1036
+ };
1037
+ return {
1038
+ ...inspection,
1039
+ markdown: buildPointMarkdown(inspection)
1040
+ };
1041
+ }
1042
+ function buildPointMarkdown(inspection) {
1043
+ const lines = [
1044
+ `Point inspection: ${inspection.region}`,
1045
+ `Point: ${Math.round(inspection.point.x)}, ${Math.round(inspection.point.y)}`
1046
+ ];
1047
+ if (inspection.totalPx !== void 0) {
1048
+ lines.push(`Value: ${formatPx(inspection.totalPx)}`);
1049
+ }
1050
+ if (inspection.property) {
1051
+ lines.push(`Property: ${inspection.property}${inspection.cssValue ? ` (${inspection.cssValue})` : ""}`);
1052
+ }
1053
+ if (inspection.element) {
1054
+ lines.push(`Element: \`${inspection.element.selector}\``);
1055
+ }
1056
+ if (inspection.from && inspection.to) {
1057
+ lines.push(`From: \`${inspection.from.selector}\``);
1058
+ lines.push(`To: \`${inspection.to.selector}\``);
1059
+ }
1060
+ if (inspection.note) {
1061
+ lines.push(`Note: ${inspection.note}`);
1062
+ }
1063
+ return lines.join("\n");
1064
+ }
1065
+ function isContainerLikeHit(element, point) {
1066
+ const rect = toGapRect(element.getBoundingClientRect());
1067
+ const tagName = element.tagName.toLowerCase();
1068
+ const area = rect.width * rect.height;
1069
+ if (["button", "a", "input", "textarea", "select", "h1", "h2", "h3", "p", "span"].includes(tagName)) {
1070
+ return false;
1071
+ }
1072
+ return area > 8e3 || !pointInRect(point, rect);
1073
+ }
1074
+ function pointInRect(point, rect) {
1075
+ return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom;
1076
+ }
1077
+ function shrinkRect(rect, inset) {
1078
+ const left = rect.left + inset.left;
1079
+ const right = rect.right - inset.right;
1080
+ const top = rect.top + inset.top;
1081
+ const bottom = rect.bottom - inset.bottom;
1082
+ return {
1083
+ left,
1084
+ right,
1085
+ top,
1086
+ bottom,
1087
+ width: Math.max(0, right - left),
1088
+ height: Math.max(0, bottom - top)
1089
+ };
1090
+ }
1091
+ function expandRect(rect, outset) {
1092
+ const left = rect.left - outset.left;
1093
+ const right = rect.right + outset.right;
1094
+ const top = rect.top - outset.top;
1095
+ const bottom = rect.bottom + outset.bottom;
1096
+ return {
1097
+ left,
1098
+ right,
1099
+ top,
1100
+ bottom,
1101
+ width: Math.max(0, right - left),
1102
+ height: Math.max(0, bottom - top)
1103
+ };
1104
+ }
1105
+ function nearestSide(point, rect) {
1106
+ const distances = [
1107
+ { side: "Top", distance: Math.abs(point.y - rect.top) },
1108
+ { side: "Right", distance: Math.abs(point.x - rect.right) },
1109
+ { side: "Bottom", distance: Math.abs(point.y - rect.bottom) },
1110
+ { side: "Left", distance: Math.abs(point.x - rect.left) }
1111
+ ];
1112
+ return distances.sort((a, b) => a.distance - b.distance)[0].side;
1113
+ }
1114
+ function nearestMarginSide(point, rect) {
1115
+ if (point.x < rect.left) {
1116
+ return "Left";
1117
+ }
1118
+ if (point.x > rect.right) {
1119
+ return "Right";
1120
+ }
1121
+ if (point.y < rect.top) {
1122
+ return "Top";
1123
+ }
1124
+ return "Bottom";
1125
+ }
1126
+ function capitalize(value) {
1127
+ return `${value.slice(0, 1).toUpperCase()}${value.slice(1)}`;
1128
+ }
1129
+ function toGapRect(rect) {
1130
+ return {
1131
+ top: roundPx(rect.top),
1132
+ right: roundPx(rect.right),
1133
+ bottom: roundPx(rect.bottom),
1134
+ left: roundPx(rect.left),
1135
+ width: roundPx(rect.width),
1136
+ height: roundPx(rect.height)
1137
+ };
1138
+ }
1139
+ function rectArea(rect) {
1140
+ return rect.width * rect.height;
1141
+ }
1142
+ function elementDepth(element) {
1143
+ let depth = 0;
1144
+ let current = element;
1145
+ while (current) {
1146
+ depth += 1;
1147
+ current = parentThroughShadow(current);
1148
+ }
1149
+ return depth;
1150
+ }
1151
+ function sharedAncestorDistance(a, b) {
1152
+ const commonAncestor = findCommonAncestor(a, b);
1153
+ if (!commonAncestor) {
1154
+ return 100;
1155
+ }
1156
+ return distanceToAncestor(a, commonAncestor) + distanceToAncestor(b, commonAncestor);
1157
+ }
1158
+ function distanceToAncestor(element, ancestor) {
1159
+ let distance = 0;
1160
+ let current = element;
1161
+ while (current && current !== ancestor) {
1162
+ distance += 1;
1163
+ current = parentThroughShadow(current);
1164
+ }
1165
+ return current === ancestor ? distance : 100;
1166
+ }
1167
+ function positivePx(value) {
1168
+ if (typeof value === "number") {
1169
+ return Number.isFinite(value) && value > 0 ? value : 0;
1170
+ }
1171
+ if (!value || value === "auto" || value === "normal") {
1172
+ return 0;
1173
+ }
1174
+ const parsed = Number.parseFloat(value);
1175
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
1176
+ }
1177
+ function roundPx(value) {
1178
+ const nearest = Math.round(value);
1179
+ if (Math.abs(value - nearest) < 0.15) {
1180
+ return nearest;
1181
+ }
1182
+ return Math.round(value * 10) / 10;
1183
+ }
1184
+ function formatPx(value) {
1185
+ const rounded = roundPx(value);
1186
+ return `${Number.isInteger(rounded) ? rounded : rounded.toFixed(1)}px`;
1187
+ }
1188
+ function cssPropertyName(property) {
1189
+ return property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
1190
+ }
1191
+ function cssEscape(value) {
1192
+ if (typeof CSS !== "undefined" && CSS.escape) {
1193
+ return CSS.escape(value);
1194
+ }
1195
+ return value.replace(/[^a-zA-Z0-9_-]/g, (character) => `\\${character}`);
1196
+ }
1197
+
1198
+ // src/styles.ts
1199
+ var gapInspectorStyles = `
1200
+ .gi-root,
1201
+ .gi-svg {
1202
+ --gi-chrome: #131313;
1203
+ --gi-surface: #1a1a1a;
1204
+ --gi-well: #0d0d0d;
1205
+ --gi-text: #f7f7f7;
1206
+ --gi-text-secondary: #c2c6cc;
1207
+ --gi-text-muted: #8a9099;
1208
+ --gi-hairline: rgba(255, 255, 255, 0.09);
1209
+ --gi-hairline-soft: rgba(255, 255, 255, 0.05);
1210
+ --gi-accent: #12a0f0;
1211
+ --gi-danger: #f04438;
1212
+ --gi-amber: #f5a623;
1213
+ --gi-margin: #f5a623;
1214
+ --gi-padding: #4ade80;
1215
+ --gi-border-kind: #f87171;
1216
+ --gi-scrollbar: #2dd4bf;
1217
+ --gi-gap-kind: #a78bfa;
1218
+ --gi-layout: #9ba1a8;
1219
+ --gi-content: #12a0f0;
1220
+ --gi-unknown: #ec4899;
1221
+ --gi-shadow:
1222
+ inset 0 1px 0 rgba(255, 255, 255, 0.06),
1223
+ 0 1px 2px rgba(0, 0, 0, 0.6),
1224
+ 0 32px 70px -16px rgba(0, 0, 0, 0.75);
1225
+ --gi-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
1226
+ --gi-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
1227
+ }
1228
+
1229
+ .gi-root {
1230
+ color: var(--gi-text);
1231
+ font-family: var(--gi-font);
1232
+ -webkit-font-smoothing: antialiased;
1233
+ -moz-osx-font-smoothing: grayscale;
1234
+ font-synthesis: none;
1235
+ position: fixed;
1236
+ inset: 0;
1237
+ z-index: 2147483647;
1238
+ pointer-events: none;
1239
+ }
1240
+
1241
+ .gi-button {
1242
+ align-items: center;
1243
+ background: var(--gi-chrome);
1244
+ border: 1px solid var(--gi-hairline);
1245
+ border-radius: 10px;
1246
+ bottom: 18px;
1247
+ box-shadow:
1248
+ inset 0 1px 0 rgba(255, 255, 255, 0.06),
1249
+ 0 1px 2px rgba(0, 0, 0, 0.6),
1250
+ 0 12px 32px -8px rgba(0, 0, 0, 0.6);
1251
+ color: var(--gi-text);
1252
+ cursor: pointer;
1253
+ display: inline-flex;
1254
+ font: inherit;
1255
+ font-size: 12.5px;
1256
+ font-weight: 500;
1257
+ gap: 8px;
1258
+ height: 34px;
1259
+ overflow: clip;
1260
+ padding: 0 14px;
1261
+ pointer-events: auto;
1262
+ position: fixed;
1263
+ right: 18px;
1264
+ touch-action: none;
1265
+ transition: border-color 120ms ease, background-color 120ms ease;
1266
+ white-space: nowrap;
1267
+ }
1268
+
1269
+ .gi-button:hover {
1270
+ background: #181818;
1271
+ border-color: rgba(255, 255, 255, 0.16);
1272
+ }
1273
+
1274
+ .gi-button-mark {
1275
+ background: var(--gi-accent);
1276
+ border-radius: 999px;
1277
+ box-shadow: 0 0 8px rgba(18, 160, 240, 0.8);
1278
+ display: inline-block;
1279
+ height: 6px;
1280
+ width: 6px;
1281
+ }
1282
+
1283
+ .gi-panel {
1284
+ background: var(--gi-chrome);
1285
+ border-radius: 14px;
1286
+ bottom: 18px;
1287
+ box-shadow: var(--gi-shadow);
1288
+ display: flex;
1289
+ flex-direction: column;
1290
+ max-height: min(560px, calc(100vh - 36px));
1291
+ overflow: clip;
1292
+ padding: 4px;
1293
+ pointer-events: auto;
1294
+ position: fixed;
1295
+ right: 18px;
1296
+ width: min(400px, calc(100vw - 36px));
1297
+ }
1298
+
1299
+ @media (prefers-reduced-motion: no-preference) {
1300
+ .gi-panel {
1301
+ animation: gi-pop-in 170ms cubic-bezier(0.32, 0.72, 0, 1);
1302
+ }
1303
+ }
1304
+
1305
+ @keyframes gi-pop-in {
1306
+ from {
1307
+ opacity: 0;
1308
+ transform: scale(0.96) translateY(6px);
1309
+ }
1310
+ }
1311
+
1312
+ .gi-body {
1313
+ background: var(--gi-surface);
1314
+ border: 1px solid var(--gi-hairline);
1315
+ border-radius: 10px;
1316
+ display: flex;
1317
+ flex-direction: column;
1318
+ min-height: 0;
1319
+ overflow: clip;
1320
+ }
1321
+
1322
+ .gi-header {
1323
+ align-items: center;
1324
+ border-bottom: 1px solid var(--gi-hairline-soft);
1325
+ cursor: grab;
1326
+ display: flex;
1327
+ flex-shrink: 0;
1328
+ justify-content: space-between;
1329
+ padding: 11px 11px 11px 14px;
1330
+ touch-action: none;
1331
+ user-select: none;
1332
+ }
1333
+
1334
+ .gi-header:active {
1335
+ cursor: grabbing;
1336
+ }
1337
+
1338
+ .gi-header .gi-close {
1339
+ cursor: pointer;
1340
+ }
1341
+
1342
+ .gi-title {
1343
+ font-size: 13px;
1344
+ font-weight: 600;
1345
+ letter-spacing: -0.01em;
1346
+ line-height: 16px;
1347
+ }
1348
+
1349
+ .gi-close {
1350
+ align-items: center;
1351
+ appearance: none;
1352
+ background: transparent;
1353
+ border: 1px solid transparent;
1354
+ border-radius: 7px;
1355
+ color: var(--gi-text-muted);
1356
+ cursor: pointer;
1357
+ display: inline-flex;
1358
+ height: 24px;
1359
+ justify-content: center;
1360
+ padding: 0;
1361
+ transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
1362
+ width: 24px;
1363
+ }
1364
+
1365
+ .gi-close:hover {
1366
+ background: rgba(255, 255, 255, 0.06);
1367
+ border-color: var(--gi-hairline);
1368
+ color: var(--gi-text-secondary);
1369
+ }
1370
+
1371
+ .gi-content {
1372
+ display: flex;
1373
+ flex-direction: column;
1374
+ gap: 12px;
1375
+ min-height: 0;
1376
+ overflow-y: auto;
1377
+ padding: 14px;
1378
+ }
1379
+
1380
+ .gi-content::-webkit-scrollbar {
1381
+ width: 8px;
1382
+ }
1383
+
1384
+ .gi-content::-webkit-scrollbar-thumb {
1385
+ background: rgba(255, 255, 255, 0.12);
1386
+ background-clip: padding-box;
1387
+ border: 2px solid transparent;
1388
+ border-radius: 999px;
1389
+ }
1390
+
1391
+ .gi-empty {
1392
+ color: var(--gi-text-muted);
1393
+ display: flex;
1394
+ flex-direction: column;
1395
+ font-size: 12.5px;
1396
+ gap: 12px;
1397
+ line-height: 1.55;
1398
+ }
1399
+
1400
+ .gi-empty p {
1401
+ margin: 0;
1402
+ }
1403
+
1404
+ .gi-hint {
1405
+ align-items: center;
1406
+ color: var(--gi-text-muted);
1407
+ display: flex;
1408
+ font-size: 12px;
1409
+ gap: 8px;
1410
+ }
1411
+
1412
+ .gi-kbd {
1413
+ align-items: center;
1414
+ background: var(--gi-well);
1415
+ border: 1px solid var(--gi-hairline);
1416
+ border-radius: 5px;
1417
+ color: var(--gi-text-secondary);
1418
+ display: inline-flex;
1419
+ flex-shrink: 0;
1420
+ font-size: 11px;
1421
+ height: 18px;
1422
+ justify-content: center;
1423
+ line-height: 1;
1424
+ min-width: 18px;
1425
+ padding: 0 4px;
1426
+ }
1427
+
1428
+ .gi-footer {
1429
+ align-items: center;
1430
+ display: flex;
1431
+ flex-shrink: 0;
1432
+ gap: 8px;
1433
+ justify-content: flex-end;
1434
+ padding: 8px 6px 4px;
1435
+ }
1436
+
1437
+ .gi-ghost,
1438
+ .gi-primary {
1439
+ appearance: none;
1440
+ border: 0;
1441
+ border-radius: 8px;
1442
+ cursor: pointer;
1443
+ font: inherit;
1444
+ font-size: 12.5px;
1445
+ line-height: 16px;
1446
+ padding: 7px 12px;
1447
+ transition: background-color 120ms ease, filter 120ms ease;
1448
+ }
1449
+
1450
+ .gi-ghost {
1451
+ background: transparent;
1452
+ color: var(--gi-text-secondary);
1453
+ font-weight: 500;
1454
+ }
1455
+
1456
+ .gi-ghost:hover {
1457
+ background: rgba(255, 255, 255, 0.06);
1458
+ }
1459
+
1460
+ .gi-primary {
1461
+ background: var(--gi-accent);
1462
+ box-shadow:
1463
+ inset 0 1px 0 rgba(255, 255, 255, 0.24),
1464
+ 0 1px 2px rgba(0, 0, 0, 0.45);
1465
+ color: #ffffff;
1466
+ font-weight: 600;
1467
+ }
1468
+
1469
+ .gi-primary:hover {
1470
+ filter: brightness(1.08);
1471
+ }
1472
+
1473
+ .gi-primary[data-state="failed"] {
1474
+ background: var(--gi-danger);
1475
+ }
1476
+
1477
+ .gi-report-title {
1478
+ align-items: baseline;
1479
+ display: flex;
1480
+ gap: 7px;
1481
+ }
1482
+
1483
+ .gi-metric {
1484
+ color: var(--gi-kind-color, var(--gi-text));
1485
+ font-family: var(--gi-mono);
1486
+ font-size: 18px;
1487
+ font-variant-numeric: tabular-nums;
1488
+ font-weight: 600;
1489
+ letter-spacing: -0.02em;
1490
+ line-height: 22px;
1491
+ }
1492
+
1493
+ .gi-metric-axis {
1494
+ color: var(--gi-text-muted);
1495
+ font-size: 12px;
1496
+ font-weight: 500;
1497
+ }
1498
+
1499
+ .gi-bar {
1500
+ display: flex;
1501
+ gap: 2px;
1502
+ height: 14px;
1503
+ }
1504
+
1505
+ .gi-bar-segment {
1506
+ background: var(--gi-kind-color, var(--gi-layout));
1507
+ background-clip: padding-box;
1508
+ border-block: 4px solid transparent;
1509
+ border-radius: 6px;
1510
+ box-sizing: border-box;
1511
+ flex-basis: 0;
1512
+ min-width: 3px;
1513
+ }
1514
+
1515
+ .gi-bar-segment:hover {
1516
+ filter: brightness(1.25);
1517
+ }
1518
+
1519
+ .gi-bar-unattributed {
1520
+ background: repeating-linear-gradient(
1521
+ 135deg,
1522
+ rgba(255, 255, 255, 0.28) 0 2px,
1523
+ rgba(255, 255, 255, 0.08) 2px 5px
1524
+ );
1525
+ }
1526
+
1527
+ .gi-equation {
1528
+ background: var(--gi-well);
1529
+ border: 1px solid var(--gi-hairline);
1530
+ border-radius: 9px;
1531
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
1532
+ color: var(--gi-text);
1533
+ font-family: var(--gi-mono);
1534
+ font-size: 11.5px;
1535
+ font-variant-numeric: tabular-nums;
1536
+ line-height: 1.6;
1537
+ overflow-wrap: anywhere;
1538
+ padding: 9px 11px;
1539
+ }
1540
+
1541
+ .gi-caps {
1542
+ color: var(--gi-text-muted);
1543
+ font-size: 10px;
1544
+ font-weight: 600;
1545
+ letter-spacing: 0.08em;
1546
+ text-transform: uppercase;
1547
+ }
1548
+
1549
+ .gi-contribs {
1550
+ display: flex;
1551
+ flex-direction: column;
1552
+ }
1553
+
1554
+ .gi-contribs .gi-caps {
1555
+ margin-bottom: 2px;
1556
+ }
1557
+
1558
+ .gi-contrib {
1559
+ display: flex;
1560
+ flex-direction: column;
1561
+ gap: 4px;
1562
+ padding: 9px 1px;
1563
+ }
1564
+
1565
+ .gi-contrib + .gi-contrib {
1566
+ border-top: 1px solid var(--gi-hairline-soft);
1567
+ }
1568
+
1569
+ .gi-contrib:hover {
1570
+ background: rgba(255, 255, 255, 0.03);
1571
+ }
1572
+
1573
+ .gi-contrib-row {
1574
+ align-items: center;
1575
+ display: flex;
1576
+ gap: 8px;
1577
+ }
1578
+
1579
+ .gi-kind-label {
1580
+ background: color-mix(in srgb, var(--gi-kind-color) 15%, transparent);
1581
+ border-radius: 5px;
1582
+ color: var(--gi-kind-color);
1583
+ flex-shrink: 0;
1584
+ font-size: 10px;
1585
+ font-weight: 600;
1586
+ letter-spacing: 0.04em;
1587
+ line-height: 1;
1588
+ padding: 4px 6px;
1589
+ text-transform: uppercase;
1590
+ }
1591
+
1592
+ .gi-contrib-prop {
1593
+ color: var(--gi-text);
1594
+ flex: 1;
1595
+ font-size: 12px;
1596
+ font-weight: 500;
1597
+ min-width: 0;
1598
+ overflow-wrap: anywhere;
1599
+ }
1600
+
1601
+ .gi-contrib-css {
1602
+ color: var(--gi-text-muted);
1603
+ font-family: var(--gi-mono);
1604
+ font-size: 11px;
1605
+ font-weight: 400;
1606
+ }
1607
+
1608
+ .gi-contrib-value {
1609
+ color: var(--gi-text);
1610
+ flex-shrink: 0;
1611
+ font-family: var(--gi-mono);
1612
+ font-size: 12px;
1613
+ font-variant-numeric: tabular-nums;
1614
+ font-weight: 600;
1615
+ margin-left: auto;
1616
+ }
1617
+
1618
+ .gi-contrib-note {
1619
+ color: var(--gi-text-muted);
1620
+ font-size: 11.5px;
1621
+ line-height: 1.5;
1622
+ }
1623
+
1624
+ .gi-warning {
1625
+ background: color-mix(in srgb, var(--gi-amber) 9%, transparent);
1626
+ border: 1px solid color-mix(in srgb, var(--gi-amber) 28%, transparent);
1627
+ border-radius: 9px;
1628
+ color: #f2c069;
1629
+ font-size: 11.5px;
1630
+ line-height: 1.55;
1631
+ padding: 8px 11px;
1632
+ }
1633
+
1634
+ .gi-hovercard {
1635
+ background: var(--gi-surface);
1636
+ border: 1px solid var(--gi-hairline);
1637
+ border-radius: 10px;
1638
+ box-shadow:
1639
+ inset 0 1px 0 rgba(255, 255, 255, 0.06),
1640
+ 0 8px 24px rgba(0, 0, 0, 0.55);
1641
+ display: flex;
1642
+ flex-direction: column;
1643
+ gap: 6px;
1644
+ padding: 10px 11px;
1645
+ pointer-events: none;
1646
+ position: fixed;
1647
+ z-index: 10;
1648
+ }
1649
+
1650
+ .gi-hovercard-row {
1651
+ align-items: center;
1652
+ display: flex;
1653
+ gap: 8px;
1654
+ }
1655
+
1656
+ .gi-hovercard-prop {
1657
+ color: var(--gi-text);
1658
+ flex: 1;
1659
+ font-size: 12px;
1660
+ font-weight: 500;
1661
+ min-width: 0;
1662
+ overflow-wrap: anywhere;
1663
+ }
1664
+
1665
+ .gi-hovercard-value {
1666
+ color: var(--gi-text);
1667
+ flex-shrink: 0;
1668
+ font-family: var(--gi-mono);
1669
+ font-size: 12px;
1670
+ font-variant-numeric: tabular-nums;
1671
+ font-weight: 600;
1672
+ }
1673
+
1674
+ .gi-hovercard-selector {
1675
+ color: #dfe2e6;
1676
+ font-family: var(--gi-mono);
1677
+ font-size: 10.5px;
1678
+ line-height: 1.5;
1679
+ overflow-wrap: anywhere;
1680
+ }
1681
+
1682
+ .gi-hovercard-meta {
1683
+ color: var(--gi-text-muted);
1684
+ font-family: var(--gi-mono);
1685
+ font-size: 10.5px;
1686
+ }
1687
+
1688
+ .gi-hovercard-note {
1689
+ color: var(--gi-text-muted);
1690
+ font-size: 11px;
1691
+ line-height: 1.5;
1692
+ }
1693
+
1694
+ .gi-canvas {
1695
+ cursor: crosshair;
1696
+ inset: 0;
1697
+ pointer-events: auto;
1698
+ position: fixed;
1699
+ touch-action: none;
1700
+ }
1701
+
1702
+ .gi-canvas[data-passthrough="true"] {
1703
+ pointer-events: none;
1704
+ }
1705
+
1706
+ .gi-svg {
1707
+ left: 0;
1708
+ overflow: visible;
1709
+ pointer-events: none;
1710
+ position: absolute;
1711
+ top: 0;
1712
+ z-index: 2147483646;
1713
+ }
1714
+
1715
+ .gi-line {
1716
+ stroke: var(--gi-accent);
1717
+ stroke-dasharray: 5 5;
1718
+ stroke-linecap: round;
1719
+ stroke-width: 1.5;
1720
+ }
1721
+
1722
+ .gi-gap-band {
1723
+ fill: rgba(18, 160, 240, 0.16);
1724
+ stroke: rgba(18, 160, 240, 0.8);
1725
+ stroke-width: 1;
1726
+ }
1727
+
1728
+ .gi-preview-gap {
1729
+ fill: rgba(18, 160, 240, 0.1);
1730
+ stroke-dasharray: 4 4;
1731
+ }
1732
+
1733
+ .gi-element-box {
1734
+ fill: rgba(18, 160, 240, 0.06);
1735
+ stroke: rgba(18, 160, 240, 0.85);
1736
+ stroke-width: 1;
1737
+ }
1738
+
1739
+ .gi-preview-box {
1740
+ fill: rgba(18, 160, 240, 0.03);
1741
+ stroke-dasharray: 7 4;
1742
+ }
1743
+
1744
+ .gi-contributor-box {
1745
+ fill: color-mix(in srgb, var(--gi-kind-color) 38%, transparent);
1746
+ stroke: color-mix(in srgb, var(--gi-kind-color) 85%, transparent);
1747
+ stroke-width: 1;
1748
+ }
1749
+
1750
+ .gi-preview-contributor {
1751
+ opacity: 0.62;
1752
+ }
1753
+
1754
+ .gi-series-box {
1755
+ fill: color-mix(in srgb, var(--gi-kind-color) 5%, transparent);
1756
+ opacity: 0.34;
1757
+ stroke: var(--gi-kind-color);
1758
+ stroke-dasharray: 2 6;
1759
+ stroke-width: 1;
1760
+ }
1761
+
1762
+ .gi-preview-series {
1763
+ opacity: 0.2;
1764
+ }
1765
+
1766
+ .gi-edge-marker {
1767
+ fill: var(--gi-accent);
1768
+ stroke: none;
1769
+ }
1770
+
1771
+ .gi-preview-edge {
1772
+ fill: rgba(18, 160, 240, 0.85);
1773
+ }
1774
+
1775
+ .gi-from-edge {
1776
+ opacity: 0.92;
1777
+ }
1778
+
1779
+ .gi-to-edge {
1780
+ opacity: 0.92;
1781
+ }
1782
+
1783
+ .gi-kind-margin {
1784
+ --gi-kind-color: var(--gi-margin);
1785
+ }
1786
+
1787
+ .gi-kind-padding {
1788
+ --gi-kind-color: var(--gi-padding);
1789
+ }
1790
+
1791
+ .gi-kind-border {
1792
+ --gi-kind-color: var(--gi-border-kind);
1793
+ }
1794
+
1795
+ .gi-kind-scrollbar {
1796
+ --gi-kind-color: var(--gi-scrollbar);
1797
+ }
1798
+
1799
+ .gi-kind-gap {
1800
+ --gi-kind-color: var(--gi-gap-kind);
1801
+ }
1802
+
1803
+ .gi-kind-layout {
1804
+ --gi-kind-color: var(--gi-layout);
1805
+ }
1806
+
1807
+ .gi-kind-content {
1808
+ --gi-kind-color: var(--gi-content);
1809
+ }
1810
+
1811
+ .gi-kind-unknown {
1812
+ --gi-kind-color: var(--gi-unknown);
1813
+ }
1814
+
1815
+ .gi-hover-box {
1816
+ fill: color-mix(in srgb, var(--gi-kind-color) 35%, transparent);
1817
+ stroke: var(--gi-kind-color);
1818
+ stroke-width: 1.5;
1819
+ }
1820
+
1821
+ .gi-point-region {
1822
+ fill: color-mix(in srgb, var(--gi-kind-color) 20%, transparent);
1823
+ stroke: var(--gi-kind-color);
1824
+ stroke-dasharray: 5 3;
1825
+ stroke-width: 1.5;
1826
+ }
1827
+
1828
+ .gi-point-dot {
1829
+ fill: var(--gi-kind-color);
1830
+ stroke: #131313;
1831
+ stroke-width: 2;
1832
+ }
1833
+ `;
1834
+ function GapInspector({
1835
+ initiallyOpen = false,
1836
+ onMeasure
1837
+ }) {
1838
+ const rootRef = react.useRef(null);
1839
+ const [open, setOpen] = react.useState(initiallyOpen);
1840
+ const [drag, setDrag] = react.useState(null);
1841
+ const dragRef = react.useRef(null);
1842
+ const [measurement, setMeasurement] = react.useState(null);
1843
+ const [pointInspection, setPointInspection] = react.useState(null);
1844
+ const [copyState, setCopyState] = react.useState("idle");
1845
+ const [preview, setPreview] = react.useState(null);
1846
+ const [passThrough, setPassThrough] = react.useState(false);
1847
+ const panelRef = react.useRef(null);
1848
+ const launcherRef = react.useRef(null);
1849
+ const gripRef = react.useRef(null);
1850
+ const suppressLauncherClickRef = react.useRef(false);
1851
+ const [panelPosition, setPanelPosition] = react.useState(null);
1852
+ const [hover, setHover] = react.useState(null);
1853
+ react.useEffect(() => {
1854
+ setHover(null);
1855
+ }, [measurement]);
1856
+ const panelHeightAnimRef = react.useRef(null);
1857
+ const lastPanelHeightRef = react.useRef(null);
1858
+ const closingSizeRef = react.useRef(null);
1859
+ react.useLayoutEffect(() => {
1860
+ const panel = panelRef.current;
1861
+ if (!panel) {
1862
+ panelHeightAnimRef.current = null;
1863
+ lastPanelHeightRef.current = null;
1864
+ return;
1865
+ }
1866
+ const previousAnim = panelHeightAnimRef.current;
1867
+ const inFlight = previousAnim && previousAnim.playState === "running" ? panel.getBoundingClientRect().height : null;
1868
+ previousAnim?.cancel();
1869
+ const natural = panel.offsetHeight;
1870
+ const from = inFlight ?? lastPanelHeightRef.current;
1871
+ lastPanelHeightRef.current = natural;
1872
+ if (from === null || Math.abs(from - natural) < 1 || window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
1873
+ return;
1874
+ }
1875
+ panelHeightAnimRef.current = panel.animate(
1876
+ [{ height: `${from}px` }, { height: `${natural}px` }],
1877
+ { duration: 260, easing: "cubic-bezier(0.32, 0.72, 0, 1)" }
1878
+ );
1879
+ }, [open, measurement, pointInspection]);
1880
+ react.useLayoutEffect(() => {
1881
+ const launcher = launcherRef.current;
1882
+ const fromSize = closingSizeRef.current;
1883
+ closingSizeRef.current = null;
1884
+ if (open || !launcher || !fromSize || window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
1885
+ return;
1886
+ }
1887
+ launcher.animate(
1888
+ [
1889
+ { width: `${fromSize.width}px`, height: `${fromSize.height}px`, borderRadius: "14px" },
1890
+ { width: `${launcher.offsetWidth}px`, height: `${launcher.offsetHeight}px`, borderRadius: "10px" }
1891
+ ],
1892
+ { duration: 240, easing: "cubic-bezier(0.32, 0.72, 0, 1)" }
1893
+ );
1894
+ }, [open]);
1895
+ const activeAxis = drag ? inferAxis(drag.start, drag.end) : "horizontal";
1896
+ function buildPreview(nextDrag) {
1897
+ if (dragDistance(nextDrag) < 8) {
1898
+ return null;
1899
+ }
1900
+ const previewReport = measureGap({
1901
+ axis: inferAxis(nextDrag.start, nextDrag.end),
1902
+ start: nextDrag.start,
1903
+ end: nextDrag.end,
1904
+ ignoreElements: [rootRef.current],
1905
+ boundaryScan: false
1906
+ });
1907
+ if (!previewReport) {
1908
+ return null;
1909
+ }
1910
+ const snapshot = buildOverlaySnapshot(previewReport);
1911
+ return snapshot ? { measurement: previewReport, snapshot } : null;
1912
+ }
1913
+ react.useEffect(() => {
1914
+ if (!open) {
1915
+ return;
1916
+ }
1917
+ function handleKeyDown(event) {
1918
+ if (event.key === "Alt") {
1919
+ setPassThrough(true);
1920
+ }
1921
+ }
1922
+ function handleKeyUp(event) {
1923
+ if (event.key === "Alt") {
1924
+ setPassThrough(false);
1925
+ }
1926
+ }
1927
+ function handleBlur() {
1928
+ setPassThrough(false);
1929
+ }
1930
+ window.addEventListener("keydown", handleKeyDown);
1931
+ window.addEventListener("keyup", handleKeyUp);
1932
+ window.addEventListener("blur", handleBlur);
1933
+ return () => {
1934
+ window.removeEventListener("keydown", handleKeyDown);
1935
+ window.removeEventListener("keyup", handleKeyUp);
1936
+ window.removeEventListener("blur", handleBlur);
1937
+ setPassThrough(false);
1938
+ };
1939
+ }, [open]);
1940
+ function beginMeasure(event) {
1941
+ if (event.button !== 0) {
1942
+ return;
1943
+ }
1944
+ event.currentTarget.setPointerCapture(event.pointerId);
1945
+ const point = pointFromEvent(event);
1946
+ const nextDrag = { start: point, end: point };
1947
+ dragRef.current = nextDrag;
1948
+ setDrag(nextDrag);
1949
+ setPreview(null);
1950
+ setCopyState("idle");
1951
+ }
1952
+ function updateMeasure(event) {
1953
+ if (!dragRef.current) {
1954
+ return;
1955
+ }
1956
+ const nextDrag = { ...dragRef.current, end: pointFromEvent(event) };
1957
+ dragRef.current = nextDrag;
1958
+ setDrag(nextDrag);
1959
+ setPreview(buildPreview(nextDrag));
1960
+ }
1961
+ function finishMeasure(event) {
1962
+ if (!dragRef.current) {
1963
+ return;
1964
+ }
1965
+ const end = pointFromEvent(event);
1966
+ const nextDrag = { ...dragRef.current, end };
1967
+ dragRef.current = null;
1968
+ const distance = dragDistance(nextDrag);
1969
+ if (distance < 6) {
1970
+ if (measurement || pointInspection) {
1971
+ setMeasurement(null);
1972
+ setPointInspection(null);
1973
+ } else {
1974
+ const inspection = inspectPoint({
1975
+ point: end,
1976
+ ignoreElements: [rootRef.current]
1977
+ });
1978
+ setPointInspection(inspection ? toDocumentInspection(inspection) : inspection);
1979
+ }
1980
+ setDrag(null);
1981
+ setPreview(null);
1982
+ return;
1983
+ }
1984
+ const axis = inferAxis(nextDrag.start, nextDrag.end);
1985
+ const report = measureGap({
1986
+ axis,
1987
+ start: nextDrag.start,
1988
+ end,
1989
+ ignoreElements: [rootRef.current]
1990
+ });
1991
+ if (report) {
1992
+ setMeasurement(report);
1993
+ setPointInspection(null);
1994
+ onMeasure?.(report);
1995
+ }
1996
+ setDrag(null);
1997
+ setPreview(null);
1998
+ }
1999
+ function cancelMeasure() {
2000
+ dragRef.current = null;
2001
+ setDrag(null);
2002
+ setPreview(null);
2003
+ }
2004
+ function beginInspectorDrag(event, target) {
2005
+ if (event.button !== 0 || !target) {
2006
+ return;
2007
+ }
2008
+ if (event.target instanceof Element && event.target.closest(".gi-close")) {
2009
+ return;
2010
+ }
2011
+ const rect = target.getBoundingClientRect();
2012
+ gripRef.current = {
2013
+ dx: event.clientX - rect.left,
2014
+ dy: event.clientY - rect.top,
2015
+ startX: event.clientX,
2016
+ startY: event.clientY,
2017
+ target,
2018
+ moved: false
2019
+ };
2020
+ event.currentTarget.setPointerCapture(event.pointerId);
2021
+ }
2022
+ function updateInspectorDrag(event) {
2023
+ const grip = gripRef.current;
2024
+ if (!grip) {
2025
+ return;
2026
+ }
2027
+ if (!grip.moved && Math.hypot(event.clientX - grip.startX, event.clientY - grip.startY) < 4) {
2028
+ return;
2029
+ }
2030
+ grip.moved = true;
2031
+ setPanelPosition(clampToViewport(event.clientX - grip.dx, event.clientY - grip.dy, grip.target));
2032
+ }
2033
+ function endInspectorDrag() {
2034
+ suppressLauncherClickRef.current = Boolean(gripRef.current?.moved);
2035
+ gripRef.current = null;
2036
+ }
2037
+ function handleLauncherClick() {
2038
+ if (suppressLauncherClickRef.current) {
2039
+ suppressLauncherClickRef.current = false;
2040
+ return;
2041
+ }
2042
+ setOpen(true);
2043
+ }
2044
+ react.useEffect(() => {
2045
+ if (!panelPosition) {
2046
+ return;
2047
+ }
2048
+ const target = open ? panelRef.current : launcherRef.current;
2049
+ if (!target) {
2050
+ return;
2051
+ }
2052
+ const clampNow = () => {
2053
+ setPanelPosition(
2054
+ (current) => current ? clampToViewport(current.x, current.y, target) : current
2055
+ );
2056
+ };
2057
+ clampNow();
2058
+ window.addEventListener("resize", clampNow);
2059
+ return () => {
2060
+ window.removeEventListener("resize", clampNow);
2061
+ };
2062
+ }, [panelPosition !== null, open]);
2063
+ async function copyMeasurement() {
2064
+ const markdown = measurement?.markdown ?? pointInspection?.markdown;
2065
+ if (!markdown) {
2066
+ return;
2067
+ }
2068
+ try {
2069
+ await navigator.clipboard.writeText(markdown);
2070
+ setCopyState("copied");
2071
+ } catch {
2072
+ setCopyState("failed");
2073
+ }
2074
+ }
2075
+ if (!open) {
2076
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-root", ref: rootRef, children: [
2077
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: gapInspectorStyles }),
2078
+ /* @__PURE__ */ jsxRuntime.jsxs(
2079
+ "button",
2080
+ {
2081
+ className: "gi-button",
2082
+ type: "button",
2083
+ ref: launcherRef,
2084
+ style: panelPosition ? { left: panelPosition.x, top: panelPosition.y, right: "auto", bottom: "auto" } : void 0,
2085
+ onPointerDown: (event) => beginInspectorDrag(event, launcherRef.current),
2086
+ onPointerMove: updateInspectorDrag,
2087
+ onPointerUp: endInspectorDrag,
2088
+ onPointerCancel: endInspectorDrag,
2089
+ onClick: handleLauncherClick,
2090
+ children: [
2091
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-button-mark", "aria-hidden": "true" }),
2092
+ "Gap Inspector"
2093
+ ]
2094
+ }
2095
+ )
2096
+ ] });
2097
+ }
2098
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-root", ref: rootRef, children: [
2099
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: gapInspectorStyles }),
2100
+ /* @__PURE__ */ jsxRuntime.jsx(
2101
+ "div",
2102
+ {
2103
+ className: "gi-canvas",
2104
+ "data-passthrough": passThrough ? "true" : void 0,
2105
+ onPointerDown: beginMeasure,
2106
+ onPointerMove: updateMeasure,
2107
+ onPointerUp: finishMeasure,
2108
+ onPointerCancel: cancelMeasure
2109
+ }
2110
+ ),
2111
+ typeof document === "undefined" ? null : reactDom.createPortal(
2112
+ /* @__PURE__ */ jsxRuntime.jsx(
2113
+ MeasurementOverlay,
2114
+ {
2115
+ drag,
2116
+ axis: activeAxis,
2117
+ measurement,
2118
+ pointInspection,
2119
+ preview,
2120
+ hover
2121
+ }
2122
+ ),
2123
+ document.body
2124
+ ),
2125
+ /* @__PURE__ */ jsxRuntime.jsxs(
2126
+ "section",
2127
+ {
2128
+ className: "gi-panel",
2129
+ "aria-label": "Gap Inspector",
2130
+ ref: panelRef,
2131
+ style: panelPosition ? { left: panelPosition.x, top: panelPosition.y, right: "auto", bottom: "auto" } : void 0,
2132
+ children: [
2133
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-body", children: [
2134
+ /* @__PURE__ */ jsxRuntime.jsxs(
2135
+ "div",
2136
+ {
2137
+ className: "gi-header",
2138
+ onPointerDown: (event) => beginInspectorDrag(event, panelRef.current),
2139
+ onPointerMove: updateInspectorDrag,
2140
+ onPointerUp: endInspectorDrag,
2141
+ onPointerCancel: endInspectorDrag,
2142
+ children: [
2143
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-title", children: "Gap Inspector" }),
2144
+ /* @__PURE__ */ jsxRuntime.jsx(
2145
+ "button",
2146
+ {
2147
+ className: "gi-close",
2148
+ type: "button",
2149
+ "aria-label": "Close Gap Inspector",
2150
+ onClick: () => {
2151
+ const panel = panelRef.current;
2152
+ if (panel) {
2153
+ closingSizeRef.current = { width: panel.offsetWidth, height: panel.offsetHeight };
2154
+ }
2155
+ setOpen(false);
2156
+ },
2157
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 3l6 6M9 3l-6 6", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })
2158
+ }
2159
+ )
2160
+ ]
2161
+ }
2162
+ ),
2163
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-content", children: measurement ? /* @__PURE__ */ jsxRuntime.jsx(Report, { measurement, hover, onHover: setHover }) : pointInspection ? /* @__PURE__ */ jsxRuntime.jsx(PointReport, { inspection: pointInspection }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-empty", children: [
2164
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Draw a line between two rendered edges to measure the gap and see which CSS declarations produce it. Click once to inspect a point." }),
2165
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-hint", children: [
2166
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-kbd", children: "\u2325" }),
2167
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Hold Alt to interact with the page underneath." })
2168
+ ] })
2169
+ ] }) })
2170
+ ] }),
2171
+ measurement || pointInspection ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-footer", children: [
2172
+ /* @__PURE__ */ jsxRuntime.jsx(
2173
+ "button",
2174
+ {
2175
+ className: "gi-ghost",
2176
+ type: "button",
2177
+ onClick: () => {
2178
+ setMeasurement(null);
2179
+ setPointInspection(null);
2180
+ },
2181
+ children: "Clear"
2182
+ }
2183
+ ),
2184
+ /* @__PURE__ */ jsxRuntime.jsx(
2185
+ "button",
2186
+ {
2187
+ className: "gi-primary",
2188
+ "data-state": copyState,
2189
+ type: "button",
2190
+ onClick: copyMeasurement,
2191
+ children: copyState === "copied" ? "Copied" : copyState === "failed" ? "Failed" : "Copy report"
2192
+ }
2193
+ )
2194
+ ] }) : null
2195
+ ]
2196
+ }
2197
+ )
2198
+ ] });
2199
+ }
2200
+ function SpacingBar({
2201
+ measurement,
2202
+ onHover
2203
+ }) {
2204
+ if (measurement.totalPx < 0.5) {
2205
+ return null;
2206
+ }
2207
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-bar", role: "img", "aria-label": measurement.equation, children: [
2208
+ measurement.contributions.map((contribution, index) => /* @__PURE__ */ jsxRuntime.jsx(
2209
+ "span",
2210
+ {
2211
+ className: `gi-bar-segment gi-kind-${contribution.kind}`,
2212
+ style: { flexGrow: contribution.valuePx },
2213
+ onPointerEnter: (event) => onHover(contributionHover(contribution, index, event.currentTarget)),
2214
+ onPointerLeave: () => onHover(null)
2215
+ },
2216
+ `${contribution.selector}-${contribution.property}-${index}`
2217
+ )),
2218
+ measurement.unattributedPx > 0.49 ? /* @__PURE__ */ jsxRuntime.jsx(
2219
+ "span",
2220
+ {
2221
+ className: "gi-bar-segment gi-bar-unattributed",
2222
+ style: { flexGrow: measurement.unattributedPx },
2223
+ onPointerEnter: (event) => onHover(unattributedHover(measurement, event.currentTarget)),
2224
+ onPointerLeave: () => onHover(null)
2225
+ }
2226
+ ) : null
2227
+ ] });
2228
+ }
2229
+ function contributionHover(contribution, index, target) {
2230
+ const element = liveElement(contribution.element);
2231
+ let meta;
2232
+ if (element) {
2233
+ const rect = element.getBoundingClientRect();
2234
+ meta = `${element.tagName.toLowerCase()} \xB7 ${getComputedStyle(element).display} \xB7 ${roundPx2(rect.width)} \xD7 ${roundPx2(rect.height)}px`;
2235
+ }
2236
+ const anchor = target.getBoundingClientRect();
2237
+ return {
2238
+ kind: contribution.kind,
2239
+ index,
2240
+ property: contribution.property,
2241
+ valuePx: contribution.valuePx,
2242
+ cssValue: contribution.cssValue,
2243
+ selector: contribution.selector,
2244
+ meta,
2245
+ note: contribution.note,
2246
+ element: contribution.element,
2247
+ anchor: { left: anchor.left, top: anchor.top, bottom: anchor.bottom }
2248
+ };
2249
+ }
2250
+ function unattributedHover(measurement, target) {
2251
+ const anchor = target.getBoundingClientRect();
2252
+ return {
2253
+ kind: "unknown",
2254
+ index: measurement.contributions.length,
2255
+ property: "unattributed space",
2256
+ valuePx: measurement.unattributedPx,
2257
+ note: "Rendered space not tied to a direct margin, padding, border, or gap declaration.",
2258
+ anchor: { left: anchor.left, top: anchor.top, bottom: anchor.bottom }
2259
+ };
2260
+ }
2261
+ function HoverCard({ info }) {
2262
+ const width = 280;
2263
+ const left = Math.min(Math.max(info.anchor.left, 8), Math.max(8, window.innerWidth - width - 8));
2264
+ const placeBelow = info.anchor.top < 240;
2265
+ const style = placeBelow ? { left, top: info.anchor.bottom + 8, width } : { left, bottom: window.innerHeight - info.anchor.top + 8, width };
2266
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `gi-hovercard gi-kind-${info.kind}`, style, children: [
2267
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-hovercard-row", children: [
2268
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-kind-label", children: info.kind }),
2269
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "gi-hovercard-prop", children: [
2270
+ info.property,
2271
+ info.cssValue ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "gi-contrib-css", children: [
2272
+ " \xB7 ",
2273
+ info.cssValue
2274
+ ] }) : null
2275
+ ] }),
2276
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-hovercard-value", children: formatPx2(info.valuePx) })
2277
+ ] }),
2278
+ info.selector ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-hovercard-selector", children: info.selector }) : null,
2279
+ info.meta ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-hovercard-meta", children: info.meta }) : null,
2280
+ info.note ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-hovercard-note", children: info.note }) : null
2281
+ ] });
2282
+ }
2283
+ function Report({
2284
+ measurement,
2285
+ hover,
2286
+ onHover
2287
+ }) {
2288
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2289
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-report-title", children: [
2290
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-metric", children: formatPx2(measurement.totalPx) }),
2291
+ " ",
2292
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-metric-axis", children: measurement.axis })
2293
+ ] }),
2294
+ /* @__PURE__ */ jsxRuntime.jsx(SpacingBar, { measurement, onHover }),
2295
+ measurement.contributions.length ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-contribs", children: [
2296
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-caps", children: "Contributors" }),
2297
+ measurement.contributions.map((contribution, index) => /* @__PURE__ */ jsxRuntime.jsxs(
2298
+ "div",
2299
+ {
2300
+ className: `gi-contrib gi-kind-${contribution.kind}`,
2301
+ "data-kind": contribution.kind,
2302
+ onPointerEnter: (event) => onHover(contributionHover(contribution, index, event.currentTarget)),
2303
+ onPointerLeave: () => onHover(null),
2304
+ children: [
2305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-contrib-row", children: [
2306
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-kind-label", children: contribution.kind }),
2307
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "gi-contrib-prop", children: [
2308
+ contribution.property,
2309
+ contribution.cssValue ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "gi-contrib-css", children: [
2310
+ " \xB7 ",
2311
+ contribution.cssValue
2312
+ ] }) : null
2313
+ ] }),
2314
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-contrib-value", children: formatPx2(contribution.valuePx) })
2315
+ ] }),
2316
+ contribution.note ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-contrib-note", children: contribution.note }) : null
2317
+ ]
2318
+ },
2319
+ `${contribution.selector}-${contribution.property}-${index}`
2320
+ ))
2321
+ ] }) : null,
2322
+ measurement.warnings.map((warning) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-warning", children: warning }, warning)),
2323
+ hover ? /* @__PURE__ */ jsxRuntime.jsx(HoverCard, { info: hover }) : null
2324
+ ] });
2325
+ }
2326
+ function PointReport({ inspection }) {
2327
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2328
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: `gi-report-title gi-kind-${inspection.region}`, children: inspection.totalPx !== void 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2329
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-metric", children: formatPx2(inspection.totalPx) }),
2330
+ " ",
2331
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-metric-axis", children: inspection.region })
2332
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "gi-metric", children: inspection.region }) }),
2333
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gi-equation", children: [
2334
+ inspection.property ?? inspection.region,
2335
+ inspection.cssValue ? ` (${inspection.cssValue})` : ""
2336
+ ] }),
2337
+ inspection.note ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "gi-contrib-note", children: inspection.note }) : null
2338
+ ] });
2339
+ }
2340
+ function MeasurementOverlay({
2341
+ drag,
2342
+ axis,
2343
+ measurement,
2344
+ pointInspection,
2345
+ preview,
2346
+ hover
2347
+ }) {
2348
+ const snapshot = useLiveOverlaySnapshot(measurement);
2349
+ const pointSnapshot = useLivePointSnapshot(pointInspection);
2350
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { className: "gi-svg", width: "100%", height: "100%", "aria-hidden": "true", children: [
2351
+ measurement && snapshot && !drag ? /* @__PURE__ */ jsxRuntime.jsx(MeasurementRects, { measurement, snapshot, variant: "committed", hover }) : null,
2352
+ pointInspection && pointSnapshot && !drag ? /* @__PURE__ */ jsxRuntime.jsx(PointInspectionRects, { inspection: pointInspection, snapshot: pointSnapshot }) : null,
2353
+ drag && preview ? /* @__PURE__ */ jsxRuntime.jsx(
2354
+ MeasurementRects,
2355
+ {
2356
+ measurement: preview.measurement,
2357
+ snapshot: preview.snapshot,
2358
+ variant: "preview",
2359
+ line: lineFromDrag(preview.measurement.axis, drag)
2360
+ }
2361
+ ) : null,
2362
+ drag ? /* @__PURE__ */ jsxRuntime.jsx(DragLine, { drag, axis }) : null
2363
+ ] });
2364
+ }
2365
+ function DragLine({ drag, axis }) {
2366
+ const start = toDocumentPoint(drag.start);
2367
+ const end = toDocumentPoint(drag.end);
2368
+ const x1 = axis === "horizontal" ? start.x : (start.x + end.x) / 2;
2369
+ const x2 = axis === "horizontal" ? end.x : (start.x + end.x) / 2;
2370
+ const y1 = axis === "horizontal" ? (start.y + end.y) / 2 : start.y;
2371
+ const y2 = axis === "horizontal" ? (start.y + end.y) / 2 : end.y;
2372
+ return /* @__PURE__ */ jsxRuntime.jsx("line", { className: "gi-line", x1, y1, x2, y2 });
2373
+ }
2374
+ function MeasurementRects({
2375
+ measurement,
2376
+ snapshot,
2377
+ variant,
2378
+ line,
2379
+ hover
2380
+ }) {
2381
+ const from = snapshot.from;
2382
+ const to = snapshot.to;
2383
+ const geometry = bandGeometry(measurement, from, to, line);
2384
+ const band = geometry ? rectFromBand(measurement.axis, geometry.start, geometry.end, geometry.perp, GAP_BAND_THICKNESS) : null;
2385
+ const { strips, remainder } = geometry ? contributionStrips(measurement, geometry) : { strips: [], remainder: null };
2386
+ const hoverStrip = hover ? hover.index === measurement.contributions.length ? remainder : strips[hover.index] ?? null : null;
2387
+ const hoverRect = hover && hoverStrip ? hoverHighlightRect(measurement.axis, hoverStrip, hover) : null;
2388
+ const fromEdge = measurement.internalSide ? internalEdgeMarkerRect(measurement.axis, from, measurement.internalSide, "container") : edgeMarkerRect(measurement.axis, from, "from");
2389
+ const toEdge = measurement.internalSide ? internalEdgeMarkerRect(measurement.axis, to, measurement.internalSide, "child") : edgeMarkerRect(measurement.axis, to, "to");
2390
+ const prefix = variant === "preview" ? "gi-preview" : "gi-committed";
2391
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2392
+ snapshot.series.map((series, index) => /* @__PURE__ */ jsxRuntime.jsx(
2393
+ "rect",
2394
+ {
2395
+ className: `gi-series-box ${prefix}-series gi-kind-${series.kind}`,
2396
+ ...svgRect(series.rect)
2397
+ },
2398
+ `${series.kind}-${index}`
2399
+ )),
2400
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-element-box ${prefix}-box gi-from-box`, ...svgRect(from) }),
2401
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-element-box ${prefix}-box gi-to-box`, ...svgRect(to) }),
2402
+ band ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-gap-band ${prefix}-gap`, ...svgRect(band) }) : null,
2403
+ strips.map(
2404
+ (strip, index) => strip ? /* @__PURE__ */ jsxRuntime.jsx(
2405
+ "rect",
2406
+ {
2407
+ className: `gi-contributor-box ${prefix}-contributor gi-kind-${measurement.contributions[index].kind}`,
2408
+ ...svgRect(strip)
2409
+ },
2410
+ `${measurement.contributions[index].kind}-${index}`
2411
+ ) : null
2412
+ ),
2413
+ hover && hoverRect ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-hover-box gi-kind-${hover.kind}`, ...svgRect(hoverRect) }) : null,
2414
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-edge-marker ${prefix}-edge gi-from-edge`, ...svgRect(fromEdge) }),
2415
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-edge-marker ${prefix}-edge gi-to-edge`, ...svgRect(toEdge) })
2416
+ ] });
2417
+ }
2418
+ var GAP_BAND_THICKNESS = 12;
2419
+ function bandGeometry(measurement, from, to, line) {
2420
+ const horizontal = measurement.axis === "horizontal";
2421
+ const props = horizontal ? { start: "left", end: "right", perpStart: "top", perpEnd: "bottom" } : { start: "top", end: "bottom", perpStart: "left", perpEnd: "right" };
2422
+ let start;
2423
+ let end;
2424
+ let fallbackPerp;
2425
+ if (measurement.internalSide) {
2426
+ start = measurement.internalSide === "before" ? from[props.start] : to[props.end];
2427
+ end = measurement.internalSide === "before" ? to[props.start] : from[props.end];
2428
+ fallbackPerp = (to[props.perpStart] + to[props.perpEnd]) / 2;
2429
+ } else {
2430
+ start = from[props.end];
2431
+ end = to[props.start];
2432
+ fallbackPerp = (Math.max(Math.min(from[props.perpStart], to[props.perpStart]), 0) + Math.max(from[props.perpEnd], to[props.perpEnd])) / 2;
2433
+ }
2434
+ const overlapStart = Math.max(from[props.perpStart], to[props.perpStart]);
2435
+ const overlapEnd = Math.min(from[props.perpEnd], to[props.perpEnd]);
2436
+ const perp = line?.perp ?? (overlapEnd > overlapStart ? (overlapStart + overlapEnd) / 2 : fallbackPerp);
2437
+ return end > start ? { start, end, perp } : null;
2438
+ }
2439
+ function rectFromBand(axis, start, end, perp, thickness) {
2440
+ if (axis === "horizontal") {
2441
+ return {
2442
+ left: start,
2443
+ right: end,
2444
+ top: perp - thickness / 2,
2445
+ bottom: perp + thickness / 2,
2446
+ width: end - start,
2447
+ height: thickness
2448
+ };
2449
+ }
2450
+ return {
2451
+ left: perp - thickness / 2,
2452
+ right: perp + thickness / 2,
2453
+ top: start,
2454
+ bottom: end,
2455
+ width: thickness,
2456
+ height: end - start
2457
+ };
2458
+ }
2459
+ function contributionStrips(measurement, geometry) {
2460
+ const strips = [];
2461
+ let cursor = geometry.start;
2462
+ for (const contribution of measurement.contributions) {
2463
+ const next = Math.min(cursor + contribution.valuePx, geometry.end);
2464
+ strips.push(
2465
+ next - cursor > 0.1 ? rectFromBand(measurement.axis, cursor, next, geometry.perp, GAP_BAND_THICKNESS) : null
2466
+ );
2467
+ cursor = next;
2468
+ }
2469
+ const remainder = geometry.end - cursor > 0.1 ? rectFromBand(measurement.axis, cursor, geometry.end, geometry.perp, GAP_BAND_THICKNESS) : null;
2470
+ return { strips, remainder };
2471
+ }
2472
+ function hoverHighlightRect(axis, strip, hover) {
2473
+ const blockRect = hover.element ? liveRect(hover.element) : null;
2474
+ if (!blockRect) {
2475
+ return expandAcross(strip, axis, 4);
2476
+ }
2477
+ return axis === "horizontal" ? {
2478
+ left: strip.left,
2479
+ right: strip.right,
2480
+ top: blockRect.top,
2481
+ bottom: blockRect.bottom,
2482
+ width: strip.width,
2483
+ height: blockRect.bottom - blockRect.top
2484
+ } : {
2485
+ left: blockRect.left,
2486
+ right: blockRect.right,
2487
+ top: strip.top,
2488
+ bottom: strip.bottom,
2489
+ width: blockRect.right - blockRect.left,
2490
+ height: strip.height
2491
+ };
2492
+ }
2493
+ function expandAcross(rect, axis, amount) {
2494
+ return axis === "horizontal" ? { ...rect, top: rect.top - amount, bottom: rect.bottom + amount, height: rect.height + amount * 2 } : { ...rect, left: rect.left - amount, right: rect.right + amount, width: rect.width + amount * 2 };
2495
+ }
2496
+ function PointInspectionRects({
2497
+ inspection,
2498
+ snapshot
2499
+ }) {
2500
+ const kindClass = pointKindClass(inspection.region);
2501
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2502
+ snapshot.from ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: "gi-element-box gi-committed-box", ...svgRect(snapshot.from) }) : null,
2503
+ snapshot.to ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: "gi-element-box gi-committed-box", ...svgRect(snapshot.to) }) : null,
2504
+ snapshot.element ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: "gi-element-box gi-committed-box", ...svgRect(snapshot.element) }) : null,
2505
+ snapshot.rect ? /* @__PURE__ */ jsxRuntime.jsx("rect", { className: `gi-point-region ${kindClass}`, ...svgRect(snapshot.rect) }) : null,
2506
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { className: `gi-point-dot ${kindClass}`, cx: inspection.point.x, cy: inspection.point.y, r: 4 })
2507
+ ] });
2508
+ }
2509
+ function useLivePointSnapshot(inspection) {
2510
+ return useLiveSnapshot(inspection, buildPointSnapshot);
2511
+ }
2512
+ function buildPointSnapshot(inspection) {
2513
+ const rect = inspection.rect;
2514
+ const element = inspection.element ? liveRect(inspection.element) ?? void 0 : void 0;
2515
+ const from = inspection.from ? liveRect(inspection.from) ?? void 0 : void 0;
2516
+ const to = inspection.to ? liveRect(inspection.to) ?? void 0 : void 0;
2517
+ const key = [
2518
+ rect ? rectKey(rect) : "",
2519
+ element ? rectKey(element) : "",
2520
+ from ? rectKey(from) : "",
2521
+ to ? rectKey(to) : ""
2522
+ ].join("::");
2523
+ if (!rect && !element && !from && !to) {
2524
+ return null;
2525
+ }
2526
+ return { key, rect, element, from, to };
2527
+ }
2528
+ function useLiveOverlaySnapshot(measurement) {
2529
+ return useLiveSnapshot(measurement, buildOverlaySnapshot);
2530
+ }
2531
+ function useLiveSnapshot(input, build) {
2532
+ const [snapshot, setSnapshot] = react.useState(null);
2533
+ react.useEffect(() => {
2534
+ if (!input) {
2535
+ setSnapshot(null);
2536
+ return;
2537
+ }
2538
+ let frame = 0;
2539
+ let lastKey = null;
2540
+ const recompute = () => {
2541
+ frame = 0;
2542
+ const nextSnapshot = build(input);
2543
+ if (!nextSnapshot) {
2544
+ if (lastKey !== "") {
2545
+ lastKey = "";
2546
+ setSnapshot(null);
2547
+ }
2548
+ return;
2549
+ }
2550
+ if (nextSnapshot.key !== lastKey) {
2551
+ lastKey = nextSnapshot.key;
2552
+ setSnapshot(nextSnapshot);
2553
+ }
2554
+ };
2555
+ const schedule = () => {
2556
+ if (!frame) {
2557
+ frame = requestAnimationFrame(recompute);
2558
+ }
2559
+ };
2560
+ recompute();
2561
+ const resizeObserver = new ResizeObserver(schedule);
2562
+ resizeObserver.observe(document.documentElement);
2563
+ resizeObserver.observe(document.body);
2564
+ const mutationObserver = new MutationObserver((records) => {
2565
+ if (records.every(isInspectorMutation)) {
2566
+ return;
2567
+ }
2568
+ schedule();
2569
+ });
2570
+ mutationObserver.observe(document.body, { attributes: true, childList: true, subtree: true });
2571
+ window.addEventListener("scroll", schedule, { capture: true, passive: true });
2572
+ window.addEventListener("resize", schedule);
2573
+ window.addEventListener("transitionend", schedule, true);
2574
+ window.addEventListener("animationend", schedule, true);
2575
+ return () => {
2576
+ if (frame) {
2577
+ cancelAnimationFrame(frame);
2578
+ }
2579
+ resizeObserver.disconnect();
2580
+ mutationObserver.disconnect();
2581
+ window.removeEventListener("scroll", schedule, true);
2582
+ window.removeEventListener("resize", schedule);
2583
+ window.removeEventListener("transitionend", schedule, true);
2584
+ window.removeEventListener("animationend", schedule, true);
2585
+ };
2586
+ }, [input, build]);
2587
+ return snapshot;
2588
+ }
2589
+ function buildOverlaySnapshot(measurement) {
2590
+ const from = liveRect(measurement.from);
2591
+ const to = liveRect(measurement.to);
2592
+ if (!from || !to) {
2593
+ return null;
2594
+ }
2595
+ const occupiedKeys = /* @__PURE__ */ new Set([rectKey(from), rectKey(to)]);
2596
+ const series = repeatedSeriesRects(measurement, occupiedKeys);
2597
+ const key = [
2598
+ rectKey(from),
2599
+ rectKey(to),
2600
+ series.map((item) => `${item.kind}:${rectKey(item.rect)}`).join("|")
2601
+ ].join("::");
2602
+ return { key, from, to, series };
2603
+ }
2604
+ var SERIES_SCAN_LIMIT = 80;
2605
+ var SERIES_RENDER_LIMIT = 28;
2606
+ function repeatedSeriesRects(measurement, occupiedKeys) {
2607
+ const rects = [];
2608
+ const seen = /* @__PURE__ */ new Set();
2609
+ for (const contribution of measurement.contributions) {
2610
+ const element = liveElement(contribution.element);
2611
+ if (!element) {
2612
+ continue;
2613
+ }
2614
+ const candidates = contribution.kind === "gap" ? gapSeriesRects(measurement.axis, element, contribution.kind, occupiedKeys) : siblingSeriesRects(element, contribution.kind, contribution.property, contribution.cssValue, occupiedKeys);
2615
+ for (const candidate of candidates) {
2616
+ const key = `${candidate.kind}:${rectKey(candidate.rect)}`;
2617
+ if (seen.has(key)) {
2618
+ continue;
2619
+ }
2620
+ seen.add(key);
2621
+ rects.push(candidate);
2622
+ if (rects.length >= SERIES_RENDER_LIMIT) {
2623
+ return rects;
2624
+ }
2625
+ }
2626
+ }
2627
+ return rects;
2628
+ }
2629
+ function siblingSeriesRects(element, kind, property, cssValue, occupiedKeys) {
2630
+ if (kind === "unknown") {
2631
+ return [];
2632
+ }
2633
+ const parent = element.parentElement;
2634
+ const cssProperty = normalizeCssProperty(property);
2635
+ if (!parent || !cssProperty) {
2636
+ return [];
2637
+ }
2638
+ const style = getComputedStyle(element);
2639
+ const expectedValue = normalizeCssValue(cssValue ?? style.getPropertyValue(cssProperty));
2640
+ if (!expectedValue) {
2641
+ return [];
2642
+ }
2643
+ const signature = elementSeriesSignature(element);
2644
+ const candidates = siblingWindow(parent, element);
2645
+ const rects = [];
2646
+ for (const candidate of candidates) {
2647
+ if (candidate === element || elementSeriesSignature(candidate) !== signature) {
2648
+ continue;
2649
+ }
2650
+ const candidateValue = normalizeCssValue(getComputedStyle(candidate).getPropertyValue(cssProperty));
2651
+ if (candidateValue !== expectedValue) {
2652
+ continue;
2653
+ }
2654
+ const rect = visibleRectForElement(candidate);
2655
+ if (!rect || occupiedKeys.has(rectKey(rect))) {
2656
+ continue;
2657
+ }
2658
+ rects.push({ kind, rect });
2659
+ if (rects.length >= SERIES_RENDER_LIMIT) {
2660
+ break;
2661
+ }
2662
+ }
2663
+ return rects;
2664
+ }
2665
+ function gapSeriesRects(axis, container, kind, occupiedKeys) {
2666
+ const children = Array.from(container.children).slice(0, SERIES_SCAN_LIMIT).map((element) => ({ element, rect: visibleRectForElement(element) })).filter((item) => Boolean(item.rect));
2667
+ if (children.length < 2) {
2668
+ return [];
2669
+ }
2670
+ const rects = [];
2671
+ const sorted = children.sort((a, b) => axisStart(axis, a.rect) - axisStart(axis, b.rect));
2672
+ for (const child of sorted) {
2673
+ if (!occupiedKeys.has(rectKey(child.rect))) {
2674
+ rects.push({ kind, rect: child.rect });
2675
+ }
2676
+ if (rects.length >= SERIES_RENDER_LIMIT) {
2677
+ return rects;
2678
+ }
2679
+ }
2680
+ for (let index = 0; index < sorted.length - 1; index += 1) {
2681
+ const before = sorted[index].rect;
2682
+ const after = sorted[index + 1].rect;
2683
+ const band = repeatedGapBandRect(axis, before, after);
2684
+ if (!band || occupiedKeys.has(rectKey(band))) {
2685
+ continue;
2686
+ }
2687
+ rects.push({ kind, rect: band });
2688
+ if (rects.length >= SERIES_RENDER_LIMIT) {
2689
+ break;
2690
+ }
2691
+ }
2692
+ return rects;
2693
+ }
2694
+ function siblingWindow(parent, element) {
2695
+ const siblings = Array.from(parent.children);
2696
+ const index = siblings.indexOf(element);
2697
+ if (index === -1 || siblings.length <= SERIES_SCAN_LIMIT) {
2698
+ return siblings.slice(0, SERIES_SCAN_LIMIT);
2699
+ }
2700
+ const halfWindow = Math.floor(SERIES_SCAN_LIMIT / 2);
2701
+ const start = Math.max(0, Math.min(index - halfWindow, siblings.length - SERIES_SCAN_LIMIT));
2702
+ return siblings.slice(start, start + SERIES_SCAN_LIMIT);
2703
+ }
2704
+ function normalizeCssProperty(property) {
2705
+ const normalized = property.trim().replace(/\s+/g, "-");
2706
+ if (!normalized || normalized.includes("layout") || normalized.includes("space-between")) {
2707
+ return null;
2708
+ }
2709
+ return normalized;
2710
+ }
2711
+ function normalizeCssValue(value) {
2712
+ const normalized = value?.trim();
2713
+ return normalized && normalized !== "normal" && normalized !== "auto" ? normalized : null;
2714
+ }
2715
+ function elementSeriesSignature(element) {
2716
+ return [
2717
+ element.tagName.toLowerCase(),
2718
+ Array.from(element.classList).sort().join(".")
2719
+ ].join(":");
2720
+ }
2721
+ function axisStart(axis, rect) {
2722
+ return axis === "horizontal" ? rect.left : rect.top;
2723
+ }
2724
+ function repeatedGapBandRect(axis, before, after) {
2725
+ if (axis === "horizontal") {
2726
+ const left2 = before.right;
2727
+ const right2 = after.left;
2728
+ const top2 = Math.max(before.top, after.top);
2729
+ const bottom2 = Math.min(before.bottom, after.bottom);
2730
+ return right2 > left2 && bottom2 > top2 ? { left: left2, right: right2, top: top2, bottom: bottom2, width: roundPx2(right2 - left2), height: roundPx2(bottom2 - top2) } : null;
2731
+ }
2732
+ const top = before.bottom;
2733
+ const bottom = after.top;
2734
+ const left = Math.max(before.left, after.left);
2735
+ const right = Math.min(before.right, after.right);
2736
+ return bottom > top && right > left ? { left, right, top, bottom, width: roundPx2(right - left), height: roundPx2(bottom - top) } : null;
2737
+ }
2738
+ function liveElement(info) {
2739
+ if (info.element?.isConnected) {
2740
+ return info.element;
2741
+ }
2742
+ const resolved = resolveSelector(info.selector);
2743
+ info.element = resolved ?? void 0;
2744
+ return resolved;
2745
+ }
2746
+ function liveRect(info) {
2747
+ const element = liveElement(info);
2748
+ if (!element) {
2749
+ return null;
2750
+ }
2751
+ return visibleRectForElement(element);
2752
+ }
2753
+ function visibleRectForElement(element) {
2754
+ let rect = rectFromDomRect(element.getBoundingClientRect());
2755
+ if (rect.width <= 0 || rect.height <= 0) {
2756
+ return null;
2757
+ }
2758
+ for (const ancestor of scrollAncestors(element)) {
2759
+ rect = intersectRects(rect, rectFromDomRect(ancestor.getBoundingClientRect()));
2760
+ if (rect.width <= 0 || rect.height <= 0) {
2761
+ return null;
2762
+ }
2763
+ }
2764
+ return offsetRect(rect, window.scrollX, window.scrollY);
2765
+ }
2766
+ function offsetRect(rect, dx, dy) {
2767
+ return {
2768
+ top: roundPx2(rect.top + dy),
2769
+ right: roundPx2(rect.right + dx),
2770
+ bottom: roundPx2(rect.bottom + dy),
2771
+ left: roundPx2(rect.left + dx),
2772
+ width: rect.width,
2773
+ height: rect.height
2774
+ };
2775
+ }
2776
+ function rectFromDomRect(rect) {
2777
+ return {
2778
+ top: roundPx2(rect.top),
2779
+ right: roundPx2(rect.right),
2780
+ bottom: roundPx2(rect.bottom),
2781
+ left: roundPx2(rect.left),
2782
+ width: roundPx2(rect.width),
2783
+ height: roundPx2(rect.height)
2784
+ };
2785
+ }
2786
+ function scrollAncestors(element) {
2787
+ const ancestors = [];
2788
+ let current = element.parentElement;
2789
+ while (current && current !== document.body && current !== document.documentElement) {
2790
+ const style = getComputedStyle(current);
2791
+ const overflow = `${style.overflow}${style.overflowX}${style.overflowY}`;
2792
+ if (/(auto|scroll|clip|hidden)/.test(overflow)) {
2793
+ ancestors.push(current);
2794
+ }
2795
+ current = current.parentElement;
2796
+ }
2797
+ return ancestors;
2798
+ }
2799
+ function intersectRects(a, b) {
2800
+ const left = Math.max(a.left, b.left);
2801
+ const right = Math.min(a.right, b.right);
2802
+ const top = Math.max(a.top, b.top);
2803
+ const bottom = Math.min(a.bottom, b.bottom);
2804
+ return {
2805
+ top: roundPx2(top),
2806
+ right: roundPx2(right),
2807
+ bottom: roundPx2(bottom),
2808
+ left: roundPx2(left),
2809
+ width: roundPx2(Math.max(0, right - left)),
2810
+ height: roundPx2(Math.max(0, bottom - top))
2811
+ };
2812
+ }
2813
+ function pointKindClass(region) {
2814
+ switch (region) {
2815
+ case "margin":
2816
+ return "gi-kind-margin";
2817
+ case "padding":
2818
+ return "gi-kind-padding";
2819
+ case "border":
2820
+ return "gi-kind-border";
2821
+ case "gap":
2822
+ return "gi-kind-gap";
2823
+ case "content":
2824
+ return "gi-kind-content";
2825
+ default:
2826
+ return "gi-kind-unknown";
2827
+ }
2828
+ }
2829
+ function rectKey(rect) {
2830
+ return [rect.left, rect.top, rect.width, rect.height].join(":");
2831
+ }
2832
+ function edgeMarkerRect(axis, rect, side) {
2833
+ const thickness = 3;
2834
+ if (axis === "horizontal") {
2835
+ const left = side === "from" ? rect.right - thickness : rect.left;
2836
+ return {
2837
+ left,
2838
+ right: left + thickness,
2839
+ top: rect.top,
2840
+ bottom: rect.bottom,
2841
+ width: thickness,
2842
+ height: rect.height
2843
+ };
2844
+ }
2845
+ const top = side === "from" ? rect.bottom - thickness : rect.top;
2846
+ return {
2847
+ left: rect.left,
2848
+ right: rect.right,
2849
+ top,
2850
+ bottom: top + thickness,
2851
+ width: rect.width,
2852
+ height: thickness
2853
+ };
2854
+ }
2855
+ function internalEdgeMarkerRect(axis, rect, side, role) {
2856
+ const thickness = 3;
2857
+ if (axis === "horizontal") {
2858
+ const edge2 = side === "before" ? role === "container" ? rect.left : rect.left : role === "container" ? rect.right - thickness : rect.right - thickness;
2859
+ return {
2860
+ left: edge2,
2861
+ right: edge2 + thickness,
2862
+ top: rect.top,
2863
+ bottom: rect.bottom,
2864
+ width: thickness,
2865
+ height: rect.height
2866
+ };
2867
+ }
2868
+ const edge = side === "before" ? role === "container" ? rect.top : rect.top : role === "container" ? rect.bottom - thickness : rect.bottom - thickness;
2869
+ return {
2870
+ left: rect.left,
2871
+ right: rect.right,
2872
+ top: edge,
2873
+ bottom: edge + thickness,
2874
+ width: rect.width,
2875
+ height: thickness
2876
+ };
2877
+ }
2878
+ function svgRect(rect) {
2879
+ return {
2880
+ x: rect.left,
2881
+ y: rect.top,
2882
+ width: rect.width,
2883
+ height: rect.height
2884
+ };
2885
+ }
2886
+ function isInspectorMutation(record) {
2887
+ const target = record.target instanceof Element ? record.target : record.target.parentElement;
2888
+ return Boolean(target?.closest(".gi-root, .gi-svg"));
2889
+ }
2890
+ function clampToViewport(x, y, target) {
2891
+ const rect = target.getBoundingClientRect();
2892
+ const margin = 8;
2893
+ return {
2894
+ x: Math.min(Math.max(x, margin), Math.max(margin, window.innerWidth - rect.width - margin)),
2895
+ y: Math.min(Math.max(y, margin), Math.max(margin, window.innerHeight - rect.height - margin))
2896
+ };
2897
+ }
2898
+ function pointFromEvent(event) {
2899
+ return {
2900
+ x: event.clientX,
2901
+ y: event.clientY
2902
+ };
2903
+ }
2904
+ function toDocumentPoint(point) {
2905
+ return {
2906
+ x: point.x + window.scrollX,
2907
+ y: point.y + window.scrollY
2908
+ };
2909
+ }
2910
+ function toDocumentInspection(inspection) {
2911
+ return {
2912
+ ...inspection,
2913
+ point: toDocumentPoint(inspection.point),
2914
+ rect: inspection.rect ? offsetRect(inspection.rect, window.scrollX, window.scrollY) : inspection.rect
2915
+ };
2916
+ }
2917
+ function dragDistance(drag) {
2918
+ return Math.hypot(drag.end.x - drag.start.x, drag.end.y - drag.start.y);
2919
+ }
2920
+ function lineFromDrag(axis, drag) {
2921
+ const start = toDocumentPoint(drag.start);
2922
+ const end = toDocumentPoint(drag.end);
2923
+ const startAlong = axis === "horizontal" ? start.x : start.y;
2924
+ const endAlong = axis === "horizontal" ? end.x : end.y;
2925
+ const perp = axis === "horizontal" ? (start.y + end.y) / 2 : (start.x + end.x) / 2;
2926
+ return {
2927
+ min: Math.min(startAlong, endAlong),
2928
+ max: Math.max(startAlong, endAlong),
2929
+ perp
2930
+ };
2931
+ }
2932
+ function formatPx2(value) {
2933
+ const rounded = roundPx2(value);
2934
+ return `${Number.isInteger(rounded) ? rounded : rounded.toFixed(1)}px`;
2935
+ }
2936
+ function roundPx2(value) {
2937
+ const nearest = Math.round(value);
2938
+ if (Math.abs(value - nearest) < 0.15) {
2939
+ return nearest;
2940
+ }
2941
+ return Math.round(value * 10) / 10;
2942
+ }
2943
+
2944
+ exports.GapInspector = GapInspector;
2945
+ exports.inferAxis = inferAxis;
2946
+ exports.measureGap = measureGap;