gd-measurements 0.4.2 → 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 CHANGED
@@ -13,7 +13,6 @@ npm i gd-measurements
13
13
  ## Dependencies
14
14
 
15
15
  ```
16
- "lodash": "^4.17.21",
17
16
  "react": "^18.3.1 || ^19.1.1",
18
17
  ```
19
18
 
@@ -25,6 +24,69 @@ import 'gd-measurements/dist/gd-measurements.css';
25
24
 
26
25
  Required for the components to render properly (positioning) and basic style.
27
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
+
28
90
  ## Grid
29
91
 
30
92
  Creates a Grid of lines at given or predefined interval, by default every 10px sub division and every 50px main division.
@@ -62,6 +124,10 @@ Allows to configure the grid ruler labels. Can be a boolean to enable/disable la
62
124
 
63
125
  When `true`, displays debug information. Default is `false`.
64
126
 
127
+ #### `className?: string`
128
+
129
+ Additional CSS class name to apply to the Grid component.
130
+
65
131
  ### Usage Example
66
132
 
67
133
  ```tsx
@@ -169,6 +235,14 @@ Allows to configure the ruler labels. Can be a boolean to enable/disable labels,
169
235
 
170
236
  Should skip the `0` label. Only applies when `labels` is set. Default is `false`.
171
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
+
172
246
  ### Usage Example
173
247
 
174
248
  ```tsx
@@ -228,6 +302,8 @@ To override pattern color you need to apply new style to the following CSS class
228
302
 
229
303
  ## Axis
230
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
+
231
307
  ### AxisH
232
308
 
233
309
  Creates a horizontal axis line at the vertical center of its container.
@@ -239,6 +315,10 @@ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is
239
315
  - The `absolute` value should be used to put `AxisH` in some container (**note:** container needs to have `position: relative` applied).
240
316
  - The `fixed` position should be used when `AxisH` is placed at top level of the DOM structure.
241
317
 
318
+ #### `className?: string`
319
+
320
+ Additional CSS class name to apply to the AxisH component.
321
+
242
322
  #### CSS Override
243
323
 
244
324
  To override color you need to apply new style to the following CSS classes:
@@ -256,6 +336,10 @@ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is
256
336
  - The `absolute` value should be used to put `AxisV` in some container (**note:** container needs to have `position: relative` applied).
257
337
  - The `fixed` position should be used when `AxisV` is placed at top level of the DOM structure.
258
338
 
339
+ #### `className?: string`
340
+
341
+ Additional CSS class name to apply to the AxisV component.
342
+
259
343
  #### CSS Override
260
344
 
261
345
  To override color you need to apply new style to the following CSS classes:
@@ -1 +1 @@
1
- .AxisH{pointer-events:none;top:0;left:0}.AxisH.absolute{position:absolute;height:100%;width:100%}.AxisH.fixed{position:fixed;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: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:1979;height:100vh;width:100vw}.Grid_pattern_main{stroke:#d1535580}.Grid_pattern_sub{stroke:#d1535540}.Grid_units .value-label{fill:light-dark(rgb(161.2697247706,43.1302752294,45.0055045872),rgb(222.8,134.6,136));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: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(50.6311926606,43.1302752294,161.2697247706),rgb(140.2,134.6,222.8));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}
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}