gd-measurements 0.4.1

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.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Łukasz Grela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # GrelaDesign Measurement components
2
+
3
+ Set of React components to add measurement means to your components for debugging purpose.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm i gd-measurements
9
+ ```
10
+
11
+ ## Stylesheet
12
+
13
+ ```
14
+ import 'gd-measurements/dist/gd-measurements.css';
15
+ ```
16
+
17
+ Required for the components to render properly (positioning) and basic style.
18
+
19
+ ## Grid
20
+
21
+ Creates a Grid of lines at given or predefined interval, by default every 10px sub division and every 50px main division.
22
+
23
+ ### Parameters
24
+
25
+ #### `position?: TPosition`
26
+
27
+ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is `fixed`.
28
+
29
+ - The `absolute` value should be used to put `Grid` in some container (**note:** container needs to have `position: relative` applied).
30
+ - The `fixed` position should be used when `Grid` is placed at top level of the DOM structure.
31
+
32
+ #### `grid?: TGrid`
33
+
34
+ Allows to specify the grid size features. Defaults to `{ width: 50, height: 50 }`.
35
+
36
+ - `width` - Specifies the horizontal grid step (default: `50`).
37
+ - `height` - Specifies the vertical grid step (default: `50`).
38
+ - `subdivision?` - Specifies how many divisions the grid step has (default: `5`).
39
+
40
+ #### `labels?: boolean | TUnits`
41
+
42
+ Allows to configure the grid ruler labels. Can be a boolean to enable/disable labels, or an object with the following properties:
43
+
44
+ - `hOffset` - Offset of horizontal labels (number or `TPoint`).
45
+ - `vOffset` - Offset of vertical labels (number or `TPoint`).
46
+ - `zero?` - Zero label offset (number or `TPoint`).
47
+ - `size?` - Size of the label step.
48
+ - `vLabelConfig?` - Configuration of the vertical labels.
49
+ - `hLabelConfig?` - Configuration of the horizontal labels.
50
+ - `labelZeroConfig?` - Configuration of the zero label.
51
+
52
+ #### `debug?: boolean`
53
+
54
+ When `true`, displays debug information. Default is `false`.
55
+
56
+ ### Usage Example
57
+
58
+ ```tsx
59
+ import { Grid } from 'gd-measurements';
60
+
61
+ // Basic grid with default settings (fixed position)
62
+ <Grid position="fixed" />
63
+
64
+ // Grid with custom size and subdivisions in a container
65
+ <div style={{ position: 'relative', width: '800px', height: '600px' }}>
66
+ <Grid
67
+ position="absolute"
68
+ grid={{ width: 100, height: 100, subdivision: 10 }}
69
+ />
70
+ {/* Your content here */}
71
+ </div>
72
+
73
+ // Grid with labels
74
+ <Grid
75
+ position="fixed"
76
+ grid={{ width: 50, height: 50 }}
77
+ labels={{
78
+ hOffset: { x: 2, y: 0 },
79
+ vOffset: { x: 0, y: -2 },
80
+ zero: { x: 12, y: 0 },
81
+ size: { width: 50, height: 50 }
82
+ }}
83
+ />
84
+
85
+ // Grid with debug mode in a container
86
+ <div style={{ position: 'relative', width: '400px', height: '400px' }}>
87
+ <Grid position="absolute" debug />
88
+ {/* Your content here */}
89
+ </div>
90
+ ```
91
+
92
+ ### CSS Override
93
+
94
+ To override pattern color you need to apply new style to the following CSS classes:
95
+
96
+ - `.Grid_pattern_main` - main grid stroke color
97
+ - `.Grid_pattern_sub` - subdivision grid stroke color
98
+ - `.Grid .Grid_units .value-label` - label fill color
99
+
100
+ ## Ruler
101
+
102
+ Creates a ruler component with given or predefined interval, by default every 100px divisions with 10 subdivisions.
103
+
104
+ ### Parameters
105
+
106
+ #### `position?: TPosition`
107
+
108
+ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is `fixed`.
109
+
110
+ - The `absolute` value should be used to put `Ruler` in some container (**note:** container needs to have `position: relative` applied).
111
+ - The `fixed` position should be used when `Ruler` is placed at top level of the DOM structure.
112
+
113
+ #### `location?: TLocation`
114
+
115
+ Allows to specify one of 4 possible placements: `top`, `right`, `bottom`, and `left`. Default is `top`.
116
+
117
+ #### `size?: number`
118
+
119
+ Size of the main division. Default is `100`.
120
+
121
+ #### `subdivisions?: number`
122
+
123
+ Number of subdivisions. Default is `10`.
124
+
125
+ #### `width?: number`
126
+
127
+ Width of the ruler. Default is `25`.
128
+
129
+ #### `edge?: number`
130
+
131
+ Width of the edge line. Default is `3`. Maximum value is the `width`.
132
+
133
+ #### `mainTickWidth?: number`
134
+
135
+ Width of the main tick. Default is the `width`. Maximum value is the `width`.
136
+
137
+ #### `tickWidth?: number`
138
+
139
+ Width of the subdivision tick. Default is `10`. Maximum value is the `width`.
140
+
141
+ #### `showHalfTick?: boolean`
142
+
143
+ When `true`, the half size tick is rendered. Default is `true`.
144
+
145
+ #### `halfTickWidth?: number`
146
+
147
+ Width of the subdivision tick that is in the middle of `size`. Default is `20`. Maximum value is the `width`.
148
+
149
+ #### `labels?: boolean | TUnit`
150
+
151
+ Allows to configure the ruler labels. Can be a boolean to enable/disable labels, or an object with the following properties:
152
+
153
+ - `offset?` - Offset of labels (number or `TPoint`). x is distance from the tick, y is distance from the ruler's edge.
154
+ - `zero?` - Zero label offset (number or `TPoint`). x is distance from the tick, y is distance from the ruler's edge.
155
+ - `size?` - Size of the label step.
156
+ - `labelConfig?` - Configuration for the tick labels.
157
+ - `labelZeroConfig?` - Configuration for the zero tick label.
158
+
159
+ #### `skipZero?: boolean`
160
+
161
+ Should skip the `0` label. Only applies when `labels` is set. Default is `false`.
162
+
163
+ ### Usage Example
164
+
165
+ ```tsx
166
+ import { Ruler } from 'gd-measurements';
167
+
168
+ // Basic vertical ruler at top (fixed position)
169
+ <Ruler position="fixed" />
170
+
171
+ // Horizontal ruler at left in a container
172
+ <div style={{ position: 'relative', width: '600px', height: '400px' }}>
173
+ <Ruler
174
+ position="absolute"
175
+ location="left"
176
+ size={100}
177
+ subdivisions={10}
178
+ width={25}
179
+ />
180
+ {/* Your content here */}
181
+ </div>
182
+
183
+ // Ruler with labels (fixed position)
184
+ <Ruler
185
+ position="fixed"
186
+ location="top"
187
+ labels={{
188
+ offset: { x: 0, y: 10 },
189
+ zero: { x: 0, y: 20 },
190
+ size: 100
191
+ }}
192
+ />
193
+
194
+ // Ruler with custom ticks and labels in a container
195
+ <div style={{ position: 'relative', width: '500px', height: '300px' }}>
196
+ <Ruler
197
+ position="absolute"
198
+ location="bottom"
199
+ size={100}
200
+ subdivisions={10}
201
+ tickWidth={8}
202
+ halfTickWidth={15}
203
+ showHalfTick={true}
204
+ labels={true}
205
+ skipZero={true}
206
+ />
207
+ {/* Your content here */}
208
+ </div>
209
+ ```
210
+
211
+ ### CSS Override
212
+
213
+ To override pattern color you need to apply new style to the following CSS classes:
214
+
215
+ - `.Ruler_pattern_line` - ruler's edge fill color
216
+ - `.Ruler_pattern_main` - ruler's main line stroke color
217
+ - `.Ruler_pattern_sub` - ruler's subdivision line stroke color
218
+ - `.Ruler .Ruler_units .value-label` - label fill color
219
+
220
+ ## Axis
221
+
222
+ ### AxisH
223
+
224
+ Creates a horizontal axis line at the vertical center of its container.
225
+
226
+ #### `position?: TPosition`
227
+
228
+ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is `fixed`.
229
+
230
+ - The `absolute` value should be used to put `AxisH` in some container (**note:** container needs to have `position: relative` applied).
231
+ - The `fixed` position should be used when `AxisH` is placed at top level of the DOM structure.
232
+
233
+ #### CSS Override
234
+
235
+ To override color you need to apply new style to the following CSS classes:
236
+
237
+ - `.AxisH line` - Horizontal axis `line` stroke color
238
+
239
+ ### AxisV
240
+
241
+ Creates a vertical axis line at the horizontal center of its container.
242
+
243
+ #### `position?: TPosition`
244
+
245
+ Allows to specify one of 2 possible positions: `fixed` or `absolute`. Default is `fixed`.
246
+
247
+ - The `absolute` value should be used to put `AxisV` in some container (**note:** container needs to have `position: relative` applied).
248
+ - The `fixed` position should be used when `AxisV` is placed at top level of the DOM structure.
249
+
250
+ #### CSS Override
251
+
252
+ To override color you need to apply new style to the following CSS classes:
253
+
254
+ - `.AxisV line` - Vertical axis `line` stroke color
255
+
256
+ ### Usage Example
257
+
258
+ ```tsx
259
+ import { AxisH, AxisV } from 'gd-measurements';
260
+
261
+ // Fixed position axes (full viewport)
262
+ <AxisH position="fixed" />
263
+ <AxisV position="fixed" />
264
+
265
+ // Absolute position axes (within a container)
266
+ <div style={{ position: 'relative', width: '500px', height: '500px' }}>
267
+ <AxisH position="absolute" />
268
+ <AxisV position="absolute" />
269
+ {/* Your content here */}
270
+ </div>
271
+
272
+ // Both axes together in fixed position
273
+ <>
274
+ <AxisH position="fixed" />
275
+ <AxisV position="fixed" />
276
+ </>
277
+ ```
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { IProps } from './types';
3
+ export declare const AxisH: FC<IProps>;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { IProps } from './types';
3
+ export declare const AxisV: FC<IProps>;
@@ -0,0 +1,5 @@
1
+ import { TPosition } from '../types/common';
2
+ export interface IProps {
3
+ position?: TPosition;
4
+ className?: string;
5
+ }
@@ -0,0 +1,142 @@
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
+ }