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 +9 -0
- package/README.md +277 -0
- package/dist/center/AxisH.d.ts +3 -0
- package/dist/center/AxisV.d.ts +3 -0
- package/dist/center/types.d.ts +5 -0
- package/dist/gd-measurements.css +142 -0
- package/dist/gd-measurements.js +2329 -0
- package/dist/grid/Grid.d.ts +3 -0
- package/dist/grid/types.d.ts +63 -0
- package/dist/hooks/useResizeObserver.d.ts +20 -0
- package/dist/index.d.ts +4 -0
- package/dist/labels/Label/Label.d.ts +3 -0
- package/dist/labels/Label/index.d.ts +2 -0
- package/dist/labels/Label/types.d.ts +11 -0
- package/dist/labels/Units/Units.d.ts +3 -0
- package/dist/labels/Units/index.d.ts +2 -0
- package/dist/labels/Units/types.d.ts +31 -0
- package/dist/ruler/Ruler.d.ts +3 -0
- package/dist/ruler/types.d.ts +89 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/utils/classNames/classNames.d.ts +10 -0
- package/dist/utils/classNames/classNamesToCssSelector.d.ts +6 -0
- package/dist/utils/classNames/index.d.ts +2 -0
- package/dist/utils/debug/Arrow.d.ts +8 -0
- package/dist/utils/debug/Crosshair.d.ts +5 -0
- package/dist/utils/domrect/rectsEqual.d.ts +1 -0
- package/dist/utils/getOffset.d.ts +2 -0
- package/dist/utils/point/negatePoint.d.ts +2 -0
- package/dist/utils/svg/HorizontalLine.d.ts +6 -0
- package/dist/utils/svg/VerticalLine.d.ts +6 -0
- package/dist/utils/svg/getParentSvg.d.ts +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TPoint, TPosition, TSize } from '../types/common';
|
|
2
|
+
import { IProps as IUnitsProps } from '../labels/Units';
|
|
3
|
+
/**
|
|
4
|
+
* Grid size features config.
|
|
5
|
+
*/
|
|
6
|
+
export type TGrid = TSize & {
|
|
7
|
+
/**
|
|
8
|
+
* Subdivision of the Grid box (sub grid lines). Defaults to `5`.
|
|
9
|
+
*/
|
|
10
|
+
subdivision?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Units size features
|
|
14
|
+
*/
|
|
15
|
+
export type TUnits = {
|
|
16
|
+
/**
|
|
17
|
+
* Offset of horizontal labels
|
|
18
|
+
*/
|
|
19
|
+
hOffset: number | TPoint;
|
|
20
|
+
/**
|
|
21
|
+
* Offset of vertical labels
|
|
22
|
+
*/
|
|
23
|
+
vOffset: number | TPoint;
|
|
24
|
+
/**
|
|
25
|
+
* Zero label offset
|
|
26
|
+
*/
|
|
27
|
+
zero?: number | TPoint;
|
|
28
|
+
/**
|
|
29
|
+
* Size of the label step
|
|
30
|
+
*/
|
|
31
|
+
size?: TSize;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration of the vertical labels
|
|
34
|
+
*/
|
|
35
|
+
vLabelConfig?: IUnitsProps["labelConfig"];
|
|
36
|
+
/**
|
|
37
|
+
* Configuration of the horizontal labels
|
|
38
|
+
*/
|
|
39
|
+
hLabelConfig?: IUnitsProps["labelConfig"];
|
|
40
|
+
/**
|
|
41
|
+
* Configuration of the zero label
|
|
42
|
+
*/
|
|
43
|
+
labelZeroConfig?: IUnitsProps["labelZeroConfig"];
|
|
44
|
+
};
|
|
45
|
+
export interface IProps {
|
|
46
|
+
/**
|
|
47
|
+
* Allows to specify one of 2 possible `position`'s: `fixed` or `absolute`. Default is `fixed`.
|
|
48
|
+
*
|
|
49
|
+
- The `absolute` value should be used to put `Grid` in some container (**note:** container needs to have `position: relative` applied).
|
|
50
|
+
- The `fixed` position should be used when `Grid` is placed at top level of the DOM structure.
|
|
51
|
+
*/
|
|
52
|
+
position?: TPosition;
|
|
53
|
+
/**
|
|
54
|
+
* Allows to specify the grid size features. Defaults to `{ width: 50, height: 50 }`
|
|
55
|
+
*/
|
|
56
|
+
grid?: TGrid;
|
|
57
|
+
/**
|
|
58
|
+
* Allows to configure the units labels.
|
|
59
|
+
*/
|
|
60
|
+
labels?: boolean | TUnits;
|
|
61
|
+
debug?: boolean;
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to observe size changes.
|
|
4
|
+
*
|
|
5
|
+
```TS
|
|
6
|
+
import { useRef } from 'react';
|
|
7
|
+
import { useResizeObserver } from '@/hooks';
|
|
8
|
+
|
|
9
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
10
|
+
useResizeObserver(ref, (rect) => {
|
|
11
|
+
console.log(rect.width, rect.height)
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<div ref={ref}>...</div>
|
|
16
|
+
```
|
|
17
|
+
* @param elementRef
|
|
18
|
+
* @param callback
|
|
19
|
+
*/
|
|
20
|
+
export declare const useResizeObserver: <T extends Element = Element>(elementRef: RefObject<T | null> | undefined, callback: (rect: DOMRect) => void) => void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SVGAttributes } from 'react';
|
|
2
|
+
import { TPoint } from '../../types/common';
|
|
3
|
+
export interface IProps {
|
|
4
|
+
alignment?: SVGAttributes<SVGTSpanElement>["alignmentBaseline"];
|
|
5
|
+
anchor?: "start" | "middle" | "end";
|
|
6
|
+
translate?: TPoint;
|
|
7
|
+
children: SVGAttributes<SVGTSpanElement>["children"];
|
|
8
|
+
rotation?: number;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { TPoint } from '../../types/common';
|
|
3
|
+
import { IProps as ILabelProps } from '../Label';
|
|
4
|
+
export interface IProps {
|
|
5
|
+
orientation: "horizontal" | "vertical";
|
|
6
|
+
/**
|
|
7
|
+
* Container SVG reference
|
|
8
|
+
*/
|
|
9
|
+
svgRef: RefObject<SVGSVGElement | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Size of the label step
|
|
12
|
+
*/
|
|
13
|
+
size: number;
|
|
14
|
+
className?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Offset of labels. Defaults to `{x:0, y:0}`
|
|
17
|
+
*/
|
|
18
|
+
offset?: number | TPoint;
|
|
19
|
+
/**
|
|
20
|
+
* Zero label offset. Defaults to `{ x: 10, y: 0 }`
|
|
21
|
+
*/
|
|
22
|
+
zero?: number | TPoint;
|
|
23
|
+
/**
|
|
24
|
+
* Should skip `0` label
|
|
25
|
+
*/
|
|
26
|
+
skipZero?: boolean;
|
|
27
|
+
translate?: TPoint;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
labelConfig?: Pick<ILabelProps, "alignment" | "anchor" | "rotation">;
|
|
30
|
+
labelZeroConfig?: Pick<ILabelProps, "alignment" | "anchor" | "rotation">;
|
|
31
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { TPoint, TPosition } from '../types/common';
|
|
2
|
+
import { IProps as IUnitsProps } from '../labels/Units';
|
|
3
|
+
export type TLocation = "top" | "left" | "right" | "bottom";
|
|
4
|
+
/**
|
|
5
|
+
* Unit size features
|
|
6
|
+
*/
|
|
7
|
+
export type TUnit = {
|
|
8
|
+
/**
|
|
9
|
+
* Offset of labels.
|
|
10
|
+
* x - Distance from the tick
|
|
11
|
+
* y - Distance from the rulers edge
|
|
12
|
+
*/
|
|
13
|
+
offset?: number | TPoint;
|
|
14
|
+
/**
|
|
15
|
+
* Zero label offset
|
|
16
|
+
* x - Distance from the tick
|
|
17
|
+
* y - Distance from the rulers edge
|
|
18
|
+
*/
|
|
19
|
+
zero?: number | TPoint;
|
|
20
|
+
/**
|
|
21
|
+
* Size of the label step
|
|
22
|
+
*/
|
|
23
|
+
size?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for the tick labels
|
|
26
|
+
*/
|
|
27
|
+
labelConfig?: IUnitsProps["labelConfig"];
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for the zero tick label
|
|
30
|
+
*/
|
|
31
|
+
labelZeroConfig?: IUnitsProps["labelZeroConfig"];
|
|
32
|
+
};
|
|
33
|
+
export type TRuler = {
|
|
34
|
+
/**
|
|
35
|
+
* Size of the main division. Defaults to `100`.
|
|
36
|
+
*/
|
|
37
|
+
size?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Number of subdivisions. Defaults to `10`.
|
|
40
|
+
*/
|
|
41
|
+
subdivisions?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Width of the ruler. Defaults to `25`.
|
|
44
|
+
*/
|
|
45
|
+
width?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Width of the edge line. Defaults to `3`. Maximum value `TRuler#width`.
|
|
48
|
+
*/
|
|
49
|
+
edge?: number;
|
|
50
|
+
/**
|
|
51
|
+
* width of the main tick. Defaults to `TRuler#width`. Maximum value `TRuler#width`.
|
|
52
|
+
*/
|
|
53
|
+
mainTickWidth?: number;
|
|
54
|
+
/**
|
|
55
|
+
* width of the subdivision tick. Defaults to `10`. Maximum value `TRuler#width`.
|
|
56
|
+
*/
|
|
57
|
+
tickWidth?: number;
|
|
58
|
+
/**
|
|
59
|
+
* When `true` the half size tick is rendered. Defaults to `true`.
|
|
60
|
+
*/
|
|
61
|
+
showHalfTick?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* width of the subdivision tick that is in the middle of `size`. Defaults to `20`. Maximum value `TRuler#width`.
|
|
64
|
+
*/
|
|
65
|
+
halfTickWidth?: number;
|
|
66
|
+
};
|
|
67
|
+
export interface IProps extends TRuler {
|
|
68
|
+
/**
|
|
69
|
+
* Allows to specify one of 2 possible `position`'s: `fixed` or `absolute`. Default is `fixed`.
|
|
70
|
+
|
|
71
|
+
- The `absolute` value should be used to put `Grid` in some container (**note:** container needs to have `position: relative` applied).
|
|
72
|
+
- The `fixed` position should be used when `Grid` is placed at top level of the DOM structure.
|
|
73
|
+
*/
|
|
74
|
+
position?: TPosition;
|
|
75
|
+
/**
|
|
76
|
+
* Allows to specify one of 4 possible placements: `top`, `right`, `bottom` and `left`. Default is `top`.
|
|
77
|
+
*/
|
|
78
|
+
location?: TLocation;
|
|
79
|
+
/**
|
|
80
|
+
* Allows to configure the units labels.
|
|
81
|
+
*/
|
|
82
|
+
labels?: boolean | TUnit;
|
|
83
|
+
/**
|
|
84
|
+
* Should skip `0` label. If `labels` is set.
|
|
85
|
+
*/
|
|
86
|
+
skipZero?: boolean;
|
|
87
|
+
debug?: boolean;
|
|
88
|
+
className?: string;
|
|
89
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to construct className string conditionally.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* <div className={classNames('MyComponent', isLoading && 'loading', isDisabled && 'disabled')}></div>
|
|
6
|
+
* ```
|
|
7
|
+
* @param classes list of arguments to combine into a className string
|
|
8
|
+
* @returns combined string class name or empty string
|
|
9
|
+
*/
|
|
10
|
+
export declare const classNames: (...classes: (string | undefined | null | false | number)[]) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function rectsEqual(rectA: DOMRect | null, rectB: DOMRect | null): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSvgParent(element?: SVGElement | null): SVGSVGElement | null;
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gd-measurements",
|
|
3
|
+
"description": "Set of React components to add measurement means to your components for debugging purpose.",
|
|
4
|
+
"version": "0.4.1",
|
|
5
|
+
"main": "dist/gd-measurements.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Łukasz Grela",
|
|
13
|
+
"email": "lukasz.grela@gmail.com"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/LukaszGrela/gd-measurements.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/LukaszGrela/gd-measurements/issues"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"lodash": "^4.17.21",
|
|
24
|
+
"react": "^18.3.1 || ^19.1.1",
|
|
25
|
+
"react-dom": "^18.3.1 || ^19.1.1"
|
|
26
|
+
}
|
|
27
|
+
}
|