gd-measurements 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -0
- package/dist/gd-measurements.css +1 -142
- package/dist/gd-measurements.js +484 -2191
- package/dist/utils/getOffset.d.ts +11 -0
- package/dist/utils/number/index.d.ts +1 -0
- package/dist/utils/number/number.d.ts +17 -0
- package/dist/utils/throttle/index.d.ts +1 -0
- package/dist/utils/throttle/throttle.d.ts +23 -0
- package/package.json +54 -4
package/README.md
CHANGED
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Set of React components to add measurement means to your components for debugging purpose.
|
|
4
4
|
|
|
5
|
+
[Example page on github.io](https://lukaszgrela.github.io/gd-measurements/)
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```
|
|
8
10
|
npm i gd-measurements
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
## Dependencies
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
"react": "^18.3.1 || ^19.1.1",
|
|
17
|
+
```
|
|
18
|
+
|
|
11
19
|
## Stylesheet
|
|
12
20
|
|
|
13
21
|
```
|
|
@@ -16,6 +24,69 @@ import 'gd-measurements/dist/gd-measurements.css';
|
|
|
16
24
|
|
|
17
25
|
Required for the components to render properly (positioning) and basic style.
|
|
18
26
|
|
|
27
|
+
## Z-index
|
|
28
|
+
|
|
29
|
+
`Grid`, `Ruler`, `AxisH` and `AxisV` are rendered above your UI with a very high
|
|
30
|
+
`z-index`. When using the `fixed` position you can override it with a CSS custom
|
|
31
|
+
property instead of recompiling the stylesheet:
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
:root {
|
|
35
|
+
/* Grid and Ruler - default 1979 */
|
|
36
|
+
--gd-measurements-z-index: 10;
|
|
37
|
+
/* AxisH and AxisV - default 19791306 */
|
|
38
|
+
--gd-measurements-axis-z-index: 11;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The custom properties are inherited, so setting them on any ancestor of the
|
|
43
|
+
rendered component works as well.
|
|
44
|
+
|
|
45
|
+
## Numeric props
|
|
46
|
+
|
|
47
|
+
Numeric props are validated before they reach the SVG attributes, so values a
|
|
48
|
+
plain JavaScript consumer can pass (`0`, `-1`, `NaN`, `Infinity`, `undefined`)
|
|
49
|
+
never produce broken geometry.
|
|
50
|
+
|
|
51
|
+
| Prop | Component | Fallback | Minimum |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| `grid.width` | `Grid` | `50` | `1` |
|
|
54
|
+
| `grid.height` | `Grid` | `50` | `1` |
|
|
55
|
+
| `grid.subdivision` | `Grid` | `5` | `1` |
|
|
56
|
+
| `labels.size.width` | `Grid` | grid `width` | `1` |
|
|
57
|
+
| `labels.size.height` | `Grid` | grid `height` | `1` |
|
|
58
|
+
| `size` | `Ruler` | `100` | `1` |
|
|
59
|
+
| `subdivisions` | `Ruler` | `10` | `1` |
|
|
60
|
+
| `width` | `Ruler` | `25` | `1` |
|
|
61
|
+
| `edge` | `Ruler` | `3` | `0` |
|
|
62
|
+
| `tickWidth` | `Ruler` | `10` | `0` |
|
|
63
|
+
| `halfTickWidth` | `Ruler` | `20` | `0` |
|
|
64
|
+
| `mainTickWidth` | `Ruler` | `width` | `0` |
|
|
65
|
+
|
|
66
|
+
The fallback is only used when the value is missing or not a finite number.
|
|
67
|
+
Counts (`subdivision`, `subdivisions`) are also floored to an integer, because
|
|
68
|
+
they end up as the length of a generated list. `Infinity` therefore falls back
|
|
69
|
+
to the default instead of producing an enormous SVG.
|
|
70
|
+
|
|
71
|
+
Offset props (`offset`, `zero`, `hOffset`, `vOffset`) accept a number, which is
|
|
72
|
+
used for both axes, or a `TPoint`. A missing or non-finite coordinate falls
|
|
73
|
+
back to `0` for that axis.
|
|
74
|
+
|
|
75
|
+
## Tests
|
|
76
|
+
|
|
77
|
+
The components are covered by unit tests written with `vitest` and
|
|
78
|
+
`@testing-library/react`. The test setup lives in `vitest.config.ts`, which runs
|
|
79
|
+
the suite in the `jsdom` environment and adds the same aliases the library
|
|
80
|
+
build uses.
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
npm test # single run
|
|
84
|
+
npm run test:watch # watch mode
|
|
85
|
+
npm run test:coverage # coverage report (HTML in coverage/)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Test files sit next to the sources, e.g. `lib/grid/Grid.test.tsx`.
|
|
89
|
+
|
|
19
90
|
## Grid
|
|
20
91
|
|
|
21
92
|
Creates a Grid of lines at given or predefined interval, by default every 10px sub division and every 50px main division.
|
|
@@ -53,6 +124,10 @@ Allows to configure the grid ruler labels. Can be a boolean to enable/disable la
|
|
|
53
124
|
|
|
54
125
|
When `true`, displays debug information. Default is `false`.
|
|
55
126
|
|
|
127
|
+
#### `className?: string`
|
|
128
|
+
|
|
129
|
+
Additional CSS class name to apply to the Grid component.
|
|
130
|
+
|
|
56
131
|
### Usage Example
|
|
57
132
|
|
|
58
133
|
```tsx
|
|
@@ -160,6 +235,14 @@ Allows to configure the ruler labels. Can be a boolean to enable/disable labels,
|
|
|
160
235
|
|
|
161
236
|
Should skip the `0` label. Only applies when `labels` is set. Default is `false`.
|
|
162
237
|
|
|
238
|
+
#### `debug?: boolean`
|
|
239
|
+
|
|
240
|
+
When `true`, displays debug information. Default is `false`.
|
|
241
|
+
|
|
242
|
+
#### `className?: string`
|
|
243
|
+
|
|
244
|
+
Additional CSS class name to apply to the Ruler component.
|
|
245
|
+
|
|
163
246
|
### Usage Example
|
|
164
247
|
|
|
165
248
|
```tsx
|
|
@@ -219,6 +302,8 @@ To override pattern color you need to apply new style to the following CSS class
|
|
|
219
302
|
|
|
220
303
|
## Axis
|
|
221
304
|
|
|
305
|
+
This component can adapt to the container size and will always be positioned in the center of its container. It can be used to create a horizontal or vertical axis.
|
|
306
|
+
|
|
222
307
|
### AxisH
|
|
223
308
|
|
|
224
309
|
Creates a horizontal axis line at the vertical center of its container.
|
|
@@ -230,6 +315,10 @@ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is
|
|
|
230
315
|
- The `absolute` value should be used to put `AxisH` in some container (**note:** container needs to have `position: relative` applied).
|
|
231
316
|
- The `fixed` position should be used when `AxisH` is placed at top level of the DOM structure.
|
|
232
317
|
|
|
318
|
+
#### `className?: string`
|
|
319
|
+
|
|
320
|
+
Additional CSS class name to apply to the AxisH component.
|
|
321
|
+
|
|
233
322
|
#### CSS Override
|
|
234
323
|
|
|
235
324
|
To override color you need to apply new style to the following CSS classes:
|
|
@@ -247,6 +336,10 @@ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is
|
|
|
247
336
|
- The `absolute` value should be used to put `AxisV` in some container (**note:** container needs to have `position: relative` applied).
|
|
248
337
|
- The `fixed` position should be used when `AxisV` is placed at top level of the DOM structure.
|
|
249
338
|
|
|
339
|
+
#### `className?: string`
|
|
340
|
+
|
|
341
|
+
Additional CSS class name to apply to the AxisV component.
|
|
342
|
+
|
|
250
343
|
#### CSS Override
|
|
251
344
|
|
|
252
345
|
To override color you need to apply new style to the following CSS classes:
|
package/dist/gd-measurements.css
CHANGED
|
@@ -1,142 +1 @@
|
|
|
1
|
-
.AxisH {
|
|
2
|
-
pointer-events: none;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
}
|
|
6
|
-
.AxisH.absolute {
|
|
7
|
-
position: absolute;
|
|
8
|
-
height: 100%;
|
|
9
|
-
width: 100%;
|
|
10
|
-
}
|
|
11
|
-
.AxisH.fixed {
|
|
12
|
-
position: fixed;
|
|
13
|
-
z-index: 19791306;
|
|
14
|
-
height: 100vh;
|
|
15
|
-
width: 100vw;
|
|
16
|
-
}
|
|
17
|
-
.AxisH line {
|
|
18
|
-
stroke: rgba(88, 211, 72, 0.5);
|
|
19
|
-
stroke-width: 1;
|
|
20
|
-
stroke-dasharray: 10 5 1 5;
|
|
21
|
-
}.AxisV {
|
|
22
|
-
pointer-events: none;
|
|
23
|
-
top: 0;
|
|
24
|
-
left: 0;
|
|
25
|
-
}
|
|
26
|
-
.AxisV.absolute {
|
|
27
|
-
position: absolute;
|
|
28
|
-
height: 100%;
|
|
29
|
-
width: 100%;
|
|
30
|
-
}
|
|
31
|
-
.AxisV.fixed {
|
|
32
|
-
position: fixed;
|
|
33
|
-
z-index: 19791306;
|
|
34
|
-
height: 100vh;
|
|
35
|
-
width: 100vw;
|
|
36
|
-
}
|
|
37
|
-
.AxisV line {
|
|
38
|
-
stroke: rgba(91, 83, 209, 0.5);
|
|
39
|
-
stroke-width: 1;
|
|
40
|
-
stroke-dasharray: 10 5 1 5;
|
|
41
|
-
}.Grid {
|
|
42
|
-
pointer-events: none;
|
|
43
|
-
top: 0;
|
|
44
|
-
left: 0;
|
|
45
|
-
}
|
|
46
|
-
.Grid.absolute {
|
|
47
|
-
position: absolute;
|
|
48
|
-
height: 100%;
|
|
49
|
-
width: 100%;
|
|
50
|
-
}
|
|
51
|
-
.Grid.fixed {
|
|
52
|
-
position: fixed;
|
|
53
|
-
z-index: 1979;
|
|
54
|
-
height: 100vh;
|
|
55
|
-
width: 100vw;
|
|
56
|
-
}
|
|
57
|
-
.Grid_pattern_main {
|
|
58
|
-
stroke: rgba(209, 83, 85, 0.5);
|
|
59
|
-
}
|
|
60
|
-
.Grid_pattern_sub {
|
|
61
|
-
stroke: rgba(209, 83, 85, 0.25);
|
|
62
|
-
}
|
|
63
|
-
.Grid_units .value-label {
|
|
64
|
-
fill: light-dark(rgb(161.2697247706, 43.1302752294, 45.0055045872), rgb(222.8, 134.6, 136));
|
|
65
|
-
font-family: monospace;
|
|
66
|
-
font-size: 10px;
|
|
67
|
-
alignment-baseline: text-before-edge;
|
|
68
|
-
}
|
|
69
|
-
.Grid_units .value-label tspan {
|
|
70
|
-
alignment-baseline: text-before-edge;
|
|
71
|
-
}
|
|
72
|
-
.Grid_units .value-label.horizontal {
|
|
73
|
-
text-anchor: start;
|
|
74
|
-
}
|
|
75
|
-
.Grid_units .value-label.horizontal.first {
|
|
76
|
-
text-anchor: end;
|
|
77
|
-
}
|
|
78
|
-
.Grid_units .value-label.vertical {
|
|
79
|
-
text-anchor: start;
|
|
80
|
-
}.Ruler {
|
|
81
|
-
pointer-events: none;
|
|
82
|
-
}
|
|
83
|
-
.Ruler.absolute {
|
|
84
|
-
position: absolute;
|
|
85
|
-
}
|
|
86
|
-
.Ruler.absolute.vertical {
|
|
87
|
-
height: 100%;
|
|
88
|
-
}
|
|
89
|
-
.Ruler.absolute.horizontal {
|
|
90
|
-
width: 100%;
|
|
91
|
-
}
|
|
92
|
-
.Ruler.fixed {
|
|
93
|
-
position: fixed;
|
|
94
|
-
z-index: 1979;
|
|
95
|
-
}
|
|
96
|
-
.Ruler.fixed.vertical {
|
|
97
|
-
height: 100vh;
|
|
98
|
-
}
|
|
99
|
-
.Ruler.fixed.horizontal {
|
|
100
|
-
width: 100vw;
|
|
101
|
-
}
|
|
102
|
-
.Ruler.top {
|
|
103
|
-
top: 0;
|
|
104
|
-
left: 0;
|
|
105
|
-
}
|
|
106
|
-
.Ruler.bottom {
|
|
107
|
-
bottom: 0;
|
|
108
|
-
left: 0;
|
|
109
|
-
}
|
|
110
|
-
.Ruler.right {
|
|
111
|
-
top: 0;
|
|
112
|
-
right: 0;
|
|
113
|
-
}
|
|
114
|
-
.Ruler.left {
|
|
115
|
-
top: 0;
|
|
116
|
-
left: 0;
|
|
117
|
-
}
|
|
118
|
-
.Ruler_pattern_line {
|
|
119
|
-
fill: rgba(91, 83, 209, 0.5);
|
|
120
|
-
}
|
|
121
|
-
.Ruler_pattern_main {
|
|
122
|
-
stroke: rgba(91, 83, 209, 0.5);
|
|
123
|
-
stroke-width: 1;
|
|
124
|
-
}
|
|
125
|
-
.Ruler_pattern_sub {
|
|
126
|
-
stroke: rgba(91, 83, 209, 0.25);
|
|
127
|
-
stroke-width: 1;
|
|
128
|
-
}
|
|
129
|
-
.Ruler_units .value-label {
|
|
130
|
-
fill: light-dark(rgb(50.6311926606, 43.1302752294, 161.2697247706), rgb(140.2, 134.6, 222.8));
|
|
131
|
-
font-family: monospace;
|
|
132
|
-
font-size: 10px;
|
|
133
|
-
}
|
|
134
|
-
.Ruler_units .value-label.horizontal {
|
|
135
|
-
text-anchor: start;
|
|
136
|
-
}
|
|
137
|
-
.Ruler_units .value-label.horizontal.first {
|
|
138
|
-
text-anchor: end;
|
|
139
|
-
}
|
|
140
|
-
.Ruler_units .value-label.vertical {
|
|
141
|
-
text-anchor: start;
|
|
142
|
-
}
|
|
1
|
+
.AxisH{pointer-events:none;top:0;left:0}.AxisH.absolute{position:absolute;height:100%;width:100%}.AxisH.fixed{position:fixed;z-index:var(--gd-measurements-axis-z-index, 19791306);height:100vh;width:100vw}.AxisH line{stroke:#58d34880;stroke-width:1;stroke-dasharray:10 5 1 5}.AxisV{pointer-events:none;top:0;left:0}.AxisV.absolute{position:absolute;height:100%;width:100%}.AxisV.fixed{position:fixed;z-index:var(--gd-measurements-axis-z-index, 19791306);height:100vh;width:100vw}.AxisV line{stroke:#5b53d180;stroke-width:1;stroke-dasharray:10 5 1 5}.Grid{pointer-events:none;top:0;left:0}.Grid.absolute{position:absolute;height:100%;width:100%}.Grid.fixed{position:fixed;z-index:var(--gd-measurements-z-index, 1979);height:100vh;width:100vw}.Grid_pattern_main{stroke:#d1535580}.Grid_pattern_sub{stroke:#d1535540}.Grid_units .value-label{fill:light-dark(rgb(63.2430293218%,16.9138334233%,17.6492174852%),rgb(87.3725490196%,52.7843137255%,53.3333333333%));font-family:monospace;font-size:10px;alignment-baseline:text-before-edge}.Grid_units .value-label tspan{alignment-baseline:text-before-edge}.Grid_units .value-label.horizontal{text-anchor:start}.Grid_units .value-label.horizontal.first{text-anchor:end}.Grid_units .value-label.vertical{text-anchor:start}.Ruler{pointer-events:none}.Ruler.absolute{position:absolute}.Ruler.absolute.vertical{height:100%}.Ruler.absolute.horizontal{width:100%}.Ruler.fixed{position:fixed;z-index:var(--gd-measurements-z-index, 1979)}.Ruler.fixed.vertical{height:100vh}.Ruler.fixed.horizontal{width:100vw}.Ruler.top{top:0;left:0}.Ruler.bottom{bottom:0;left:0}.Ruler.right{top:0;right:0}.Ruler.left{top:0;left:0}.Ruler_pattern_line{fill:#5b53d180}.Ruler_pattern_main{stroke:#5b53d180;stroke-width:1}.Ruler_pattern_sub{stroke:#5b53d140;stroke-width:1}.Ruler_units .value-label{fill:light-dark(rgb(19.8553696708%,16.9138334233%,63.2430293218%),rgb(54.9803921569%,52.7843137255%,87.3725490196%));font-family:monospace;font-size:10px}.Ruler_units .value-label.horizontal{text-anchor:start}.Ruler_units .value-label.horizontal.first{text-anchor:end}.Ruler_units .value-label.vertical{text-anchor:start}
|