gap-inspector 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +878 -0
- package/dist/measurement.d.ts +79 -0
- package/dist/measurement.js +1209 -0
- package/dist/styles.d.ts +1 -0
- package/dist/styles.js +620 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bence Redmond
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Gap Inspector
|
|
2
|
+
|
|
3
|
+
Gap Inspector is a React dev overlay for explaining visual spacing. It lets you draw a horizontal or vertical line between rendered elements, then copies a markdown report with the selected DOM elements, total gap, CSS/layout contributors, and a pixel equation.
|
|
4
|
+
|
|
5
|
+
It is built for the frontend workflow where "make this gap match that gap" is too vague for an agent to execute reliably.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install gap-inspector -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { GapInspector } from "gap-inspector";
|
|
17
|
+
|
|
18
|
+
export function App() {
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<YourApp />
|
|
22
|
+
<GapInspector />
|
|
23
|
+
</>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The toolbar appears in the bottom-right corner. Open it and draw a line between two rendered edges; the measurement axis is inferred from the drag direction. Drag the panel header to move the inspector anywhere on screen.
|
|
29
|
+
|
|
30
|
+
## What It Reports
|
|
31
|
+
|
|
32
|
+
```md
|
|
33
|
+
Measured horizontal gap: 48px
|
|
34
|
+
|
|
35
|
+
From: `.Sidebar`
|
|
36
|
+
To: `.PreviewPanel`
|
|
37
|
+
Common ancestor: `.MainShell`
|
|
38
|
+
|
|
39
|
+
Contributions:
|
|
40
|
+
- 16px from `.MainShell` column-gap (16px) - flex parent
|
|
41
|
+
- 8px from `.TableWrap` padding-right (8px)
|
|
42
|
+
- 6px from `.MarketTableBody` scrollbar gutter - Native scrollbar gutter inside this scroll container.
|
|
43
|
+
- 24px from `.MainShell` flex space-between - Rendered space between sibling layout branches.
|
|
44
|
+
|
|
45
|
+
Equation: 16px + 8px + 6px + 24px = 54px
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Notes
|
|
49
|
+
|
|
50
|
+
The tool measures rendered geometry first, then attributes pixels to computed CSS where it can. Some spacing is not directly caused by a single margin or padding declaration. Flex distribution, grid tracks, explicit widths, `min-width`, transforms, scrollbars, and empty wrappers may show up as layout or unattributed space.
|
|
51
|
+
|
|
52
|
+
That distinction is deliberate: the report should be useful to an LLM without inventing false causes.
|
|
53
|
+
|
|
54
|
+
Adjacent vertical margins that collapse are reported as the single winning margin (with a note about the collapsed sibling). Negative margins and transformed elements cannot be expressed as positive contributors, so they are surfaced as warnings instead.
|
|
55
|
+
|
|
56
|
+
Hold <kbd>⌥</kbd>/<kbd>Alt</kbd> while the inspector is open to let pointer events through to the page — useful for opening click-driven menus or scrolling nested panes into the state you want to measure.
|
|
57
|
+
|
|
58
|
+
## Limitations
|
|
59
|
+
|
|
60
|
+
- **Closed shadow roots** cannot be inspected. Open shadow roots are pierced for hit-testing and get `host >>> inner` selectors in reports.
|
|
61
|
+
- **Iframes** are measured as opaque boxes; their contents render in a separate document and cannot be attributed (the report warns when an endpoint is an iframe).
|
|
62
|
+
- **CSS-only `:hover` states** collapse as soon as the pointer moves onto the inspector canvas, so they cannot be measured. The Alt passthrough covers UI that stays open after a click.
|
|
63
|
+
- **`position: fixed`/`sticky` elements** move relative to the document, so their committed overlays catch up one frame behind during scroll (everything else tracks scroll with zero lag).
|
|
64
|
+
|
|
65
|
+
## API
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
<GapInspector
|
|
69
|
+
initiallyOpen={false}
|
|
70
|
+
onMeasure={(measurement) => {
|
|
71
|
+
console.log(measurement.markdown);
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You can also call the measurement engine directly:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { measureGap } from "gap-inspector";
|
|
80
|
+
|
|
81
|
+
const measurement = measureGap({
|
|
82
|
+
axis: "horizontal",
|
|
83
|
+
start: { x: 220, y: 340 },
|
|
84
|
+
end: { x: 420, y: 340 }
|
|
85
|
+
});
|
|
86
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { inferAxis, measureGap, type GapMeasurement } from "./measurement";
|
|
2
|
+
export type GapInspectorProps = {
|
|
3
|
+
initiallyOpen?: boolean;
|
|
4
|
+
onMeasure?: (measurement: GapMeasurement) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function GapInspector({ initiallyOpen, onMeasure }: GapInspectorProps): import("react").JSX.Element;
|
|
7
|
+
export { inferAxis, measureGap };
|
|
8
|
+
export type { GapAxis, GapContribution, GapMeasurement, GapPoint, PointInspection } from "./measurement";
|