@zag-js/rect-utils 0.1.2 → 0.1.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
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/dist/index.d.ts CHANGED
@@ -1,7 +1,186 @@
1
- export * from "./rect";
2
- export * from "./types";
3
- export * from "./from-element";
4
- export * from "./point";
5
- export * from "./operations";
6
- export * from "./polygon";
7
- //# sourceMappingURL=index.d.ts.map
1
+ declare type Point = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ declare type RectValue = {
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ };
11
+ declare type RectSide = "top" | "right" | "bottom" | "left";
12
+ declare type RectPoint = "top-left" | "top-center" | "top-right" | "right-center" | "left-center" | "bottom-left" | "bottom-right" | "bottom-center" | "center";
13
+ declare type RectEdge = [Point, Point];
14
+ declare type RectPoints = [Point, Point, Point, Point];
15
+ declare type RectEdges = Record<RectSide, RectEdge> & {
16
+ value: RectEdge[];
17
+ };
18
+ declare type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
19
+ declare type RectCorners = Record<RectCorner, Point> & {
20
+ value: RectPoints;
21
+ };
22
+ declare type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter";
23
+ declare type RectCenters = Record<RectCenter, Point> & {
24
+ value: RectPoints;
25
+ };
26
+ declare type RectInset = Partial<Record<RectSide, number>>;
27
+ declare type SymmetricRectInset = {
28
+ dx?: number;
29
+ dy?: number;
30
+ };
31
+
32
+ declare function createRect(r: RectValue): {
33
+ x: number;
34
+ y: number;
35
+ width: number;
36
+ height: number;
37
+ minX: number;
38
+ minY: number;
39
+ maxX: number;
40
+ maxY: number;
41
+ midX: number;
42
+ midY: number;
43
+ center: {
44
+ x: number;
45
+ y: number;
46
+ };
47
+ };
48
+ declare type Rect = ReturnType<typeof createRect>;
49
+ declare function isRect(v: any): v is Rect;
50
+ declare function getRectCenters(v: Rect): {
51
+ top: {
52
+ x: number;
53
+ y: number;
54
+ };
55
+ right: {
56
+ x: number;
57
+ y: number;
58
+ };
59
+ bottom: {
60
+ x: number;
61
+ y: number;
62
+ };
63
+ left: {
64
+ x: number;
65
+ y: number;
66
+ };
67
+ };
68
+ declare function getRectCorners(v: Rect): {
69
+ top: {
70
+ x: number;
71
+ y: number;
72
+ };
73
+ right: {
74
+ x: number;
75
+ y: number;
76
+ };
77
+ bottom: {
78
+ x: number;
79
+ y: number;
80
+ };
81
+ left: {
82
+ x: number;
83
+ y: number;
84
+ };
85
+ };
86
+ declare function getRectEdges(v: Rect): {
87
+ top: RectEdge;
88
+ right: RectEdge;
89
+ bottom: RectEdge;
90
+ left: RectEdge;
91
+ };
92
+
93
+ declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
94
+ declare type AlignOptions = {
95
+ h: HAlign;
96
+ v: VAlign;
97
+ };
98
+ declare type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
99
+ declare type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
100
+
101
+ declare function closest(...pts: Point[]): (a: Point) => Point;
102
+ declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
103
+ declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
104
+
105
+ declare function containsPoint(r: Rect, p: Point): boolean;
106
+ declare function containsRect(a: Rect, b: Rect): boolean;
107
+ declare function contains(r: Rect, v: Rect | Point): boolean;
108
+
109
+ declare type DistanceValue = Point & {
110
+ value: number;
111
+ };
112
+ declare function distance(a: Point, b?: Point): number;
113
+ declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
114
+ declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
115
+ declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
116
+
117
+ declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
118
+ declare type ElementRectOptions = {
119
+ /**
120
+ * Whether to exclude the element's scrollbar size from the calculation.
121
+ */
122
+ excludeScrollbar?: boolean;
123
+ /**
124
+ * Whether to exclude the element's borders from the calculation.
125
+ */
126
+ excludeBorders?: boolean;
127
+ };
128
+
129
+ declare function getRectFromPoints(...pts: Point[]): Rect;
130
+
131
+ declare function fromRange(range: Range): Rect;
132
+
133
+ declare function toRad(d: number): number;
134
+ declare function rotate(a: Point, d: number, c: Point): Point;
135
+ declare function getRotationRect(r: Rect, deg: number): Rect;
136
+
137
+ declare type WindowRectOptions = {
138
+ /**
139
+ * Whether to exclude the element's scrollbar size from the calculation.
140
+ */
141
+ excludeScrollbar?: boolean;
142
+ };
143
+ /**
144
+ * Creates a rectange from window object
145
+ */
146
+ declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
147
+ /**
148
+ * Get the rect of the window with the option to exclude the scrollbar
149
+ */
150
+ declare function getViewportRect(win: Window, opts: WindowRectOptions): {
151
+ x: number;
152
+ y: number;
153
+ width: number;
154
+ height: number;
155
+ };
156
+
157
+ declare function getElementPolygon(rectValue: RectValue, placement: string): {
158
+ x: number;
159
+ y: number;
160
+ }[] | undefined;
161
+
162
+ /**
163
+ * Checks if a Rect intersects another Rect
164
+ */
165
+ declare function intersects(a: Rect, b: Rect): boolean;
166
+ /**
167
+ * Returns a new Rect that represents the intersection between two Rects
168
+ */
169
+ declare function intersection(a: Rect, b: Rect): Rect;
170
+ /**
171
+ * Returns whether two rects collide along each edge
172
+ */
173
+ declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
174
+
175
+ declare const isSymmetric: (v: any) => v is SymmetricRectInset;
176
+ declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
177
+ declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
178
+ declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
179
+ declare function shift(r: Rect, o: Partial<Point>): Rect;
180
+
181
+ declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
182
+ declare function debugPolygon(polygon: Point[]): () => void;
183
+
184
+ declare function union(...rs: Rect[]): Rect;
185
+
186
+ export { AlignOptions, DistanceValue, ElementRectOptions, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset, VAlign, WindowRectOptions, alignRect, closest, closestSideToPoint, closestSideToRect, collisions, contains, containsPoint, containsRect, createRect, debugPolygon, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect, expand, fromRange, getElementPolygon, getElementRect, getRectCenters, getRectCorners, getRectEdges, getRectFromPoints, getRotationRect, getViewportRect, getWindowRect, inset, intersection, intersects, isPointInPolygon, isRect, isSymmetric, rotate, shift, shrink, toRad, union };