@zag-js/rect-utils 0.0.0-dev-20220605192656 → 0.0.0-dev-20220627213111
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/dist/align.d.ts +8 -0
- package/dist/closest.d.ts +5 -0
- package/dist/contains.d.ts +5 -0
- package/dist/distance.d.ts +9 -0
- package/dist/from-element.d.ts +0 -1
- package/dist/from-points.d.ts +3 -0
- package/dist/from-range.d.ts +2 -0
- package/dist/from-rotation.d.ts +5 -0
- package/dist/from-window.d.ts +20 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.js +256 -34
- package/dist/index.mjs +257 -34
- package/dist/intersection.d.ts +14 -0
- package/dist/operations.d.ts +0 -1
- package/dist/polygon.d.ts +0 -1
- package/dist/rect.d.ts +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/union.d.ts +2 -0
- package/package.json +3 -2
- package/dist/computed-style.d.ts +0 -6
- package/dist/computed-style.d.ts.map +0 -1
- package/dist/from-element.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -7
- package/dist/index.mjs.map +0 -7
- package/dist/operations.d.ts.map +0 -1
- package/dist/point.d.ts +0 -16
- package/dist/point.d.ts.map +0 -1
- package/dist/polygon.d.ts.map +0 -1
- package/dist/rect.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/dist/align.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
export declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
3
|
+
export declare type AlignOptions = {
|
|
4
|
+
h: HAlign;
|
|
5
|
+
v: VAlign;
|
|
6
|
+
};
|
|
7
|
+
export declare type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
8
|
+
export declare type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point, RectSide } from "./types";
|
|
3
|
+
export declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
4
|
+
export declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
5
|
+
export declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point } from "./types";
|
|
3
|
+
export declare function containsPoint(r: Rect, p: Point): boolean;
|
|
4
|
+
export declare function containsRect(a: Rect, b: Rect): boolean;
|
|
5
|
+
export declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import { Point, RectSide } from "./types";
|
|
3
|
+
export declare type DistanceValue = Point & {
|
|
4
|
+
value: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function distance(a: Point, b?: Point): number;
|
|
7
|
+
export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
8
|
+
export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
9
|
+
export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
package/dist/from-element.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
export declare type WindowRectOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
5
|
+
*/
|
|
6
|
+
excludeScrollbar?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Creates a rectange from window object
|
|
10
|
+
*/
|
|
11
|
+
export declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
12
|
+
/**
|
|
13
|
+
* Get the rect of the window with the option to exclude the scrollbar
|
|
14
|
+
*/
|
|
15
|
+
export declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./align";
|
|
2
|
+
export * from "./closest";
|
|
3
|
+
export * from "./contains";
|
|
4
|
+
export * from "./distance";
|
|
3
5
|
export * from "./from-element";
|
|
4
|
-
export * from "./
|
|
6
|
+
export * from "./from-points";
|
|
7
|
+
export * from "./from-range";
|
|
8
|
+
export * from "./from-rotation";
|
|
9
|
+
export * from "./from-window";
|
|
10
|
+
export * from "./intersection";
|
|
5
11
|
export * from "./operations";
|
|
6
12
|
export * from "./polygon";
|
|
7
|
-
|
|
13
|
+
export * from "./rect";
|
|
14
|
+
export * from "./types";
|
|
15
|
+
export * from "./union";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -20,21 +21,73 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
21
|
var src_exports = {};
|
|
21
22
|
__export(src_exports, {
|
|
22
23
|
Rect: () => Rect,
|
|
24
|
+
alignRect: () => alignRect,
|
|
23
25
|
closest: () => closest,
|
|
26
|
+
closestSideToPoint: () => closestSideToPoint,
|
|
27
|
+
closestSideToRect: () => closestSideToRect,
|
|
28
|
+
collisions: () => collisions,
|
|
29
|
+
contains: () => contains,
|
|
30
|
+
containsPoint: () => containsPoint,
|
|
31
|
+
containsRect: () => containsRect,
|
|
24
32
|
debugPolygon: () => debugPolygon,
|
|
25
33
|
distance: () => distance,
|
|
34
|
+
distanceBtwEdges: () => distanceBtwEdges,
|
|
35
|
+
distanceFromPoint: () => distanceFromPoint,
|
|
36
|
+
distanceFromRect: () => distanceFromRect,
|
|
26
37
|
expand: () => expand,
|
|
38
|
+
fromRange: () => fromRange,
|
|
27
39
|
getElementRect: () => getElementRect,
|
|
28
|
-
|
|
40
|
+
getRectFromPoints: () => getRectFromPoints,
|
|
41
|
+
getRotationRect: () => getRotationRect,
|
|
42
|
+
getViewportRect: () => getViewportRect,
|
|
43
|
+
getWindowRect: () => getWindowRect,
|
|
29
44
|
inset: () => inset,
|
|
45
|
+
intersection: () => intersection,
|
|
46
|
+
intersects: () => intersects,
|
|
30
47
|
isSymmetric: () => isSymmetric,
|
|
31
|
-
|
|
48
|
+
rotate: () => rotate,
|
|
32
49
|
shift: () => shift,
|
|
33
50
|
shrink: () => shrink,
|
|
51
|
+
toRad: () => toRad,
|
|
52
|
+
union: () => union,
|
|
34
53
|
withinPolygon: () => withinPolygon
|
|
35
54
|
});
|
|
36
55
|
module.exports = __toCommonJS(src_exports);
|
|
37
56
|
|
|
57
|
+
// src/align.ts
|
|
58
|
+
function hAlign(a, ref, h) {
|
|
59
|
+
let x = ref.minX;
|
|
60
|
+
if (h === "left-inside")
|
|
61
|
+
x = ref.minX;
|
|
62
|
+
if (h === "left-outside")
|
|
63
|
+
x = ref.minX - ref.width;
|
|
64
|
+
if (h === "right-inside")
|
|
65
|
+
x = ref.maxX - ref.width;
|
|
66
|
+
if (h === "right-outside")
|
|
67
|
+
x = ref.maxX;
|
|
68
|
+
if (h === "center")
|
|
69
|
+
x = ref.midX - ref.width / 2;
|
|
70
|
+
return a.clone().set({ x });
|
|
71
|
+
}
|
|
72
|
+
function vAlign(a, ref, v) {
|
|
73
|
+
let y = ref.minY;
|
|
74
|
+
if (v === "top-inside")
|
|
75
|
+
y = ref.minY;
|
|
76
|
+
if (v === "top-outside")
|
|
77
|
+
y = ref.minY - a.height;
|
|
78
|
+
if (v === "bottom-inside")
|
|
79
|
+
y = ref.maxY - a.height;
|
|
80
|
+
if (v === "bottom-outside")
|
|
81
|
+
y = ref.maxY;
|
|
82
|
+
if (v === "center")
|
|
83
|
+
y = ref.midY - a.height / 2;
|
|
84
|
+
return a.clone().set({ y });
|
|
85
|
+
}
|
|
86
|
+
function alignRect(a, ref, options) {
|
|
87
|
+
const { h, v } = options;
|
|
88
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
89
|
+
}
|
|
90
|
+
|
|
38
91
|
// src/rect.ts
|
|
39
92
|
var point = (x, y) => ({ x, y });
|
|
40
93
|
var Rect = class {
|
|
@@ -107,17 +160,133 @@ var Rect = class {
|
|
|
107
160
|
}
|
|
108
161
|
};
|
|
109
162
|
|
|
110
|
-
// src/
|
|
111
|
-
|
|
163
|
+
// src/intersection.ts
|
|
164
|
+
function intersects(a, b) {
|
|
165
|
+
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
166
|
+
}
|
|
167
|
+
function intersection(a, b) {
|
|
168
|
+
const x = Math.max(a.x, b.x);
|
|
169
|
+
const y = Math.max(a.y, b.y);
|
|
170
|
+
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
171
|
+
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
172
|
+
return Rect.create({ x, y, width: x2 - x, height: y2 - y });
|
|
173
|
+
}
|
|
174
|
+
function collisions(a, b) {
|
|
175
|
+
return {
|
|
176
|
+
top: a.minY <= b.minY,
|
|
177
|
+
right: a.maxX >= b.maxX,
|
|
178
|
+
bottom: a.maxY >= b.maxY,
|
|
179
|
+
left: a.minX <= b.minX
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/distance.ts
|
|
184
|
+
function distance(a, b = { x: 0, y: 0 }) {
|
|
185
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
186
|
+
}
|
|
187
|
+
function distanceFromPoint(r, p) {
|
|
188
|
+
let x = 0;
|
|
189
|
+
let y = 0;
|
|
190
|
+
if (p.x < r.x)
|
|
191
|
+
x = r.x - p.x;
|
|
192
|
+
else if (p.x > r.maxX)
|
|
193
|
+
x = p.x - r.maxX;
|
|
194
|
+
if (p.y < r.y)
|
|
195
|
+
y = r.y - p.y;
|
|
196
|
+
else if (p.y > r.maxY)
|
|
197
|
+
y = p.y - r.maxY;
|
|
198
|
+
return { x, y, value: distance({ x, y }) };
|
|
199
|
+
}
|
|
200
|
+
function distanceFromRect(a, b) {
|
|
201
|
+
if (intersects(a, b))
|
|
202
|
+
return { x: 0, y: 0, value: 0 };
|
|
203
|
+
const left = a.x < b.x ? a : b;
|
|
204
|
+
const right = b.x < a.x ? a : b;
|
|
205
|
+
const upper = a.y < b.y ? a : b;
|
|
206
|
+
const lower = b.y < a.y ? a : b;
|
|
207
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
208
|
+
x = Math.max(0, x);
|
|
209
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
210
|
+
y = Math.max(0, y);
|
|
211
|
+
return { x, y, value: distance({ x, y }) };
|
|
212
|
+
}
|
|
213
|
+
function distanceBtwEdges(a, b) {
|
|
214
|
+
return {
|
|
215
|
+
left: b.x - a.x,
|
|
216
|
+
top: b.y - a.y,
|
|
217
|
+
right: a.maxX - b.maxX,
|
|
218
|
+
bottom: a.maxY - b.maxY
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/closest.ts
|
|
223
|
+
function closest(...pts) {
|
|
224
|
+
return (a) => {
|
|
225
|
+
const ds = pts.map((b) => distance(b, a));
|
|
226
|
+
const c = Math.min.apply(Math, ds);
|
|
227
|
+
return pts[ds.indexOf(c)];
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function closestSideToRect(ref, r) {
|
|
231
|
+
if (r.maxX <= ref.minX)
|
|
232
|
+
return "left";
|
|
233
|
+
if (r.minX >= ref.maxX)
|
|
234
|
+
return "right";
|
|
235
|
+
if (r.maxY <= ref.minY)
|
|
236
|
+
return "top";
|
|
237
|
+
if (r.minY >= ref.maxY)
|
|
238
|
+
return "bottom";
|
|
239
|
+
return "left";
|
|
240
|
+
}
|
|
241
|
+
function closestSideToPoint(ref, p) {
|
|
242
|
+
const { x, y } = p;
|
|
243
|
+
const dl = x - ref.minX;
|
|
244
|
+
const dr = ref.maxX - x;
|
|
245
|
+
const dt = y - ref.minY;
|
|
246
|
+
const db = ref.maxY - y;
|
|
247
|
+
let closest2 = dl;
|
|
248
|
+
let side = "left";
|
|
249
|
+
if (dr < closest2) {
|
|
250
|
+
closest2 = dr;
|
|
251
|
+
side = "right";
|
|
252
|
+
}
|
|
253
|
+
if (dt < closest2) {
|
|
254
|
+
closest2 = dt;
|
|
255
|
+
side = "top";
|
|
256
|
+
}
|
|
257
|
+
if (db < closest2) {
|
|
258
|
+
side = "bottom";
|
|
259
|
+
}
|
|
260
|
+
return side;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/contains.ts
|
|
264
|
+
function containsPoint(r, p) {
|
|
265
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
266
|
+
}
|
|
267
|
+
function containsRect(a, b) {
|
|
268
|
+
return Object.values(b.corners).every((c) => containsPoint(a, c));
|
|
269
|
+
}
|
|
270
|
+
function contains(r, v) {
|
|
271
|
+
return v instanceof Rect ? containsRect(r, v) : containsPoint(r, v);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ../dom/dist/index.mjs
|
|
275
|
+
function getCache() {
|
|
276
|
+
const g = globalThis;
|
|
277
|
+
g.__styleCache__ = g.__styleCache__ || /* @__PURE__ */ new WeakMap();
|
|
278
|
+
return g.__styleCache__;
|
|
279
|
+
}
|
|
112
280
|
function getComputedStyle(el) {
|
|
113
281
|
var _a;
|
|
114
282
|
if (!el)
|
|
115
283
|
return {};
|
|
116
|
-
|
|
284
|
+
const cache = getCache();
|
|
285
|
+
let style = cache.get(el);
|
|
117
286
|
if (!style) {
|
|
118
287
|
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
119
288
|
style = win.getComputedStyle(el);
|
|
120
|
-
|
|
289
|
+
cache.set(el, style);
|
|
121
290
|
}
|
|
122
291
|
return style;
|
|
123
292
|
}
|
|
@@ -151,37 +320,91 @@ function getClientRect(el, opts = {}) {
|
|
|
151
320
|
var px = (v) => parseFloat(v.replace("px", ""));
|
|
152
321
|
var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
153
322
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
164
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
323
|
+
// src/from-points.ts
|
|
324
|
+
function getRectFromPoints(...pts) {
|
|
325
|
+
const xs = pts.map((p) => p.x);
|
|
326
|
+
const ys = pts.map((p) => p.y);
|
|
327
|
+
const x = Math.min(...xs);
|
|
328
|
+
const y = Math.min(...ys);
|
|
329
|
+
const width = Math.max(...xs) - x;
|
|
330
|
+
const height = Math.max(...ys) - y;
|
|
331
|
+
return Rect.create({ x, y, width, height });
|
|
165
332
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
333
|
+
|
|
334
|
+
// src/union.ts
|
|
335
|
+
var { min, max } = Math;
|
|
336
|
+
function union(...rs) {
|
|
337
|
+
const pMin = {
|
|
338
|
+
x: min.apply(Math, rs.map((r) => r.minX)),
|
|
339
|
+
y: min.apply(Math, rs.map((r) => r.minY))
|
|
171
340
|
};
|
|
341
|
+
const pMax = {
|
|
342
|
+
x: max.apply(Math, rs.map((r) => r.maxX)),
|
|
343
|
+
y: max.apply(Math, rs.map((r) => r.maxY))
|
|
344
|
+
};
|
|
345
|
+
return getRectFromPoints(pMin, pMax);
|
|
172
346
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
347
|
+
|
|
348
|
+
// src/from-range.ts
|
|
349
|
+
function fromRange(range) {
|
|
350
|
+
let rs = [];
|
|
351
|
+
const rects = Array.from(range.getClientRects());
|
|
352
|
+
if (rects.length) {
|
|
353
|
+
rs = rs.concat(rects.map((r) => Rect.create(r)));
|
|
354
|
+
} else {
|
|
355
|
+
let start = range.startContainer;
|
|
356
|
+
if (start.nodeType === Node.TEXT_NODE) {
|
|
357
|
+
start = start.parentNode;
|
|
358
|
+
}
|
|
359
|
+
if (start instanceof HTMLElement) {
|
|
360
|
+
let r = getElementRect(start);
|
|
361
|
+
r.clone().set({ x: r.maxX, width: 0 });
|
|
362
|
+
rs.push(r);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return union.apply(void 0, rs);
|
|
177
366
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
367
|
+
|
|
368
|
+
// src/from-rotation.ts
|
|
369
|
+
function toRad(d) {
|
|
370
|
+
return d % 360 * Math.PI / 180;
|
|
371
|
+
}
|
|
372
|
+
function rotate(a, d, c) {
|
|
373
|
+
const r = toRad(d);
|
|
374
|
+
const sin = Math.sin(r);
|
|
375
|
+
const cos = Math.cos(r);
|
|
376
|
+
const x = a.x - c.x;
|
|
377
|
+
const y = a.y - c.y;
|
|
378
|
+
return { x: c.x + x * cos - y * sin, y: c.y + x * sin + y * cos };
|
|
379
|
+
}
|
|
380
|
+
function getRotationRect(r, deg) {
|
|
381
|
+
const rr = Object.values(r.corners).map((p) => rotate(p, deg, r.center));
|
|
382
|
+
const xs = rr.map((p) => p.x);
|
|
383
|
+
const ys = rr.map((p) => p.y);
|
|
384
|
+
const minX = Math.min(...xs);
|
|
385
|
+
const minY = Math.min(...ys);
|
|
386
|
+
const maxX = Math.max(...xs);
|
|
387
|
+
const maxY = Math.max(...ys);
|
|
388
|
+
return Rect.create({ x: minX, y: minY, width: maxX - minX, height: maxY - minY });
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/from-window.ts
|
|
392
|
+
function getWindowRect(win, opts = {}) {
|
|
393
|
+
return Rect.create(getViewportRect(win, opts));
|
|
394
|
+
}
|
|
395
|
+
function getViewportRect(win, opts) {
|
|
396
|
+
const { excludeScrollbar = false } = opts;
|
|
397
|
+
const { innerWidth: innerWidth2, innerHeight: innerHeight2, document: doc, visualViewport } = win;
|
|
398
|
+
const width = visualViewport.width || innerWidth2;
|
|
399
|
+
const height = visualViewport.height || innerHeight2;
|
|
400
|
+
const rect = { x: 0, y: 0, width, height };
|
|
401
|
+
if (excludeScrollbar) {
|
|
402
|
+
const scrollbarWidth = innerWidth2 - doc.documentElement.clientWidth;
|
|
403
|
+
const scrollbarHeight = innerHeight2 - doc.documentElement.clientHeight;
|
|
404
|
+
rect.width -= scrollbarWidth;
|
|
405
|
+
rect.height -= scrollbarHeight;
|
|
406
|
+
}
|
|
407
|
+
return rect;
|
|
185
408
|
}
|
|
186
409
|
|
|
187
410
|
// src/operations.ts
|
|
@@ -247,4 +470,3 @@ function debugPolygon(polygon) {
|
|
|
247
470
|
const points = polygon.map((point2) => `${point2.x},${point2.y}`).join(" ");
|
|
248
471
|
el.setAttribute("points", points);
|
|
249
472
|
}
|
|
250
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/align.ts
|
|
4
|
+
function hAlign(a, ref, h) {
|
|
5
|
+
let x = ref.minX;
|
|
6
|
+
if (h === "left-inside")
|
|
7
|
+
x = ref.minX;
|
|
8
|
+
if (h === "left-outside")
|
|
9
|
+
x = ref.minX - ref.width;
|
|
10
|
+
if (h === "right-inside")
|
|
11
|
+
x = ref.maxX - ref.width;
|
|
12
|
+
if (h === "right-outside")
|
|
13
|
+
x = ref.maxX;
|
|
14
|
+
if (h === "center")
|
|
15
|
+
x = ref.midX - ref.width / 2;
|
|
16
|
+
return a.clone().set({ x });
|
|
17
|
+
}
|
|
18
|
+
function vAlign(a, ref, v) {
|
|
19
|
+
let y = ref.minY;
|
|
20
|
+
if (v === "top-inside")
|
|
21
|
+
y = ref.minY;
|
|
22
|
+
if (v === "top-outside")
|
|
23
|
+
y = ref.minY - a.height;
|
|
24
|
+
if (v === "bottom-inside")
|
|
25
|
+
y = ref.maxY - a.height;
|
|
26
|
+
if (v === "bottom-outside")
|
|
27
|
+
y = ref.maxY;
|
|
28
|
+
if (v === "center")
|
|
29
|
+
y = ref.midY - a.height / 2;
|
|
30
|
+
return a.clone().set({ y });
|
|
31
|
+
}
|
|
32
|
+
function alignRect(a, ref, options) {
|
|
33
|
+
const { h, v } = options;
|
|
34
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
35
|
+
}
|
|
36
|
+
|
|
1
37
|
// src/rect.ts
|
|
2
38
|
var point = (x, y) => ({ x, y });
|
|
3
39
|
var Rect = class {
|
|
@@ -70,17 +106,133 @@ var Rect = class {
|
|
|
70
106
|
}
|
|
71
107
|
};
|
|
72
108
|
|
|
73
|
-
// src/
|
|
74
|
-
|
|
109
|
+
// src/intersection.ts
|
|
110
|
+
function intersects(a, b) {
|
|
111
|
+
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
112
|
+
}
|
|
113
|
+
function intersection(a, b) {
|
|
114
|
+
const x = Math.max(a.x, b.x);
|
|
115
|
+
const y = Math.max(a.y, b.y);
|
|
116
|
+
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
117
|
+
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
118
|
+
return Rect.create({ x, y, width: x2 - x, height: y2 - y });
|
|
119
|
+
}
|
|
120
|
+
function collisions(a, b) {
|
|
121
|
+
return {
|
|
122
|
+
top: a.minY <= b.minY,
|
|
123
|
+
right: a.maxX >= b.maxX,
|
|
124
|
+
bottom: a.maxY >= b.maxY,
|
|
125
|
+
left: a.minX <= b.minX
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/distance.ts
|
|
130
|
+
function distance(a, b = { x: 0, y: 0 }) {
|
|
131
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
132
|
+
}
|
|
133
|
+
function distanceFromPoint(r, p) {
|
|
134
|
+
let x = 0;
|
|
135
|
+
let y = 0;
|
|
136
|
+
if (p.x < r.x)
|
|
137
|
+
x = r.x - p.x;
|
|
138
|
+
else if (p.x > r.maxX)
|
|
139
|
+
x = p.x - r.maxX;
|
|
140
|
+
if (p.y < r.y)
|
|
141
|
+
y = r.y - p.y;
|
|
142
|
+
else if (p.y > r.maxY)
|
|
143
|
+
y = p.y - r.maxY;
|
|
144
|
+
return { x, y, value: distance({ x, y }) };
|
|
145
|
+
}
|
|
146
|
+
function distanceFromRect(a, b) {
|
|
147
|
+
if (intersects(a, b))
|
|
148
|
+
return { x: 0, y: 0, value: 0 };
|
|
149
|
+
const left = a.x < b.x ? a : b;
|
|
150
|
+
const right = b.x < a.x ? a : b;
|
|
151
|
+
const upper = a.y < b.y ? a : b;
|
|
152
|
+
const lower = b.y < a.y ? a : b;
|
|
153
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
154
|
+
x = Math.max(0, x);
|
|
155
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
156
|
+
y = Math.max(0, y);
|
|
157
|
+
return { x, y, value: distance({ x, y }) };
|
|
158
|
+
}
|
|
159
|
+
function distanceBtwEdges(a, b) {
|
|
160
|
+
return {
|
|
161
|
+
left: b.x - a.x,
|
|
162
|
+
top: b.y - a.y,
|
|
163
|
+
right: a.maxX - b.maxX,
|
|
164
|
+
bottom: a.maxY - b.maxY
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/closest.ts
|
|
169
|
+
function closest(...pts) {
|
|
170
|
+
return (a) => {
|
|
171
|
+
const ds = pts.map((b) => distance(b, a));
|
|
172
|
+
const c = Math.min.apply(Math, ds);
|
|
173
|
+
return pts[ds.indexOf(c)];
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function closestSideToRect(ref, r) {
|
|
177
|
+
if (r.maxX <= ref.minX)
|
|
178
|
+
return "left";
|
|
179
|
+
if (r.minX >= ref.maxX)
|
|
180
|
+
return "right";
|
|
181
|
+
if (r.maxY <= ref.minY)
|
|
182
|
+
return "top";
|
|
183
|
+
if (r.minY >= ref.maxY)
|
|
184
|
+
return "bottom";
|
|
185
|
+
return "left";
|
|
186
|
+
}
|
|
187
|
+
function closestSideToPoint(ref, p) {
|
|
188
|
+
const { x, y } = p;
|
|
189
|
+
const dl = x - ref.minX;
|
|
190
|
+
const dr = ref.maxX - x;
|
|
191
|
+
const dt = y - ref.minY;
|
|
192
|
+
const db = ref.maxY - y;
|
|
193
|
+
let closest2 = dl;
|
|
194
|
+
let side = "left";
|
|
195
|
+
if (dr < closest2) {
|
|
196
|
+
closest2 = dr;
|
|
197
|
+
side = "right";
|
|
198
|
+
}
|
|
199
|
+
if (dt < closest2) {
|
|
200
|
+
closest2 = dt;
|
|
201
|
+
side = "top";
|
|
202
|
+
}
|
|
203
|
+
if (db < closest2) {
|
|
204
|
+
side = "bottom";
|
|
205
|
+
}
|
|
206
|
+
return side;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/contains.ts
|
|
210
|
+
function containsPoint(r, p) {
|
|
211
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
212
|
+
}
|
|
213
|
+
function containsRect(a, b) {
|
|
214
|
+
return Object.values(b.corners).every((c) => containsPoint(a, c));
|
|
215
|
+
}
|
|
216
|
+
function contains(r, v) {
|
|
217
|
+
return v instanceof Rect ? containsRect(r, v) : containsPoint(r, v);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ../dom/dist/index.mjs
|
|
221
|
+
function getCache() {
|
|
222
|
+
const g = globalThis;
|
|
223
|
+
g.__styleCache__ = g.__styleCache__ || /* @__PURE__ */ new WeakMap();
|
|
224
|
+
return g.__styleCache__;
|
|
225
|
+
}
|
|
75
226
|
function getComputedStyle(el) {
|
|
76
227
|
var _a;
|
|
77
228
|
if (!el)
|
|
78
229
|
return {};
|
|
79
|
-
|
|
230
|
+
const cache = getCache();
|
|
231
|
+
let style = cache.get(el);
|
|
80
232
|
if (!style) {
|
|
81
233
|
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
82
234
|
style = win.getComputedStyle(el);
|
|
83
|
-
|
|
235
|
+
cache.set(el, style);
|
|
84
236
|
}
|
|
85
237
|
return style;
|
|
86
238
|
}
|
|
@@ -114,37 +266,91 @@ function getClientRect(el, opts = {}) {
|
|
|
114
266
|
var px = (v) => parseFloat(v.replace("px", ""));
|
|
115
267
|
var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
116
268
|
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
127
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
269
|
+
// src/from-points.ts
|
|
270
|
+
function getRectFromPoints(...pts) {
|
|
271
|
+
const xs = pts.map((p) => p.x);
|
|
272
|
+
const ys = pts.map((p) => p.y);
|
|
273
|
+
const x = Math.min(...xs);
|
|
274
|
+
const y = Math.min(...ys);
|
|
275
|
+
const width = Math.max(...xs) - x;
|
|
276
|
+
const height = Math.max(...ys) - y;
|
|
277
|
+
return Rect.create({ x, y, width, height });
|
|
128
278
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
279
|
+
|
|
280
|
+
// src/union.ts
|
|
281
|
+
var { min, max } = Math;
|
|
282
|
+
function union(...rs) {
|
|
283
|
+
const pMin = {
|
|
284
|
+
x: min.apply(Math, rs.map((r) => r.minX)),
|
|
285
|
+
y: min.apply(Math, rs.map((r) => r.minY))
|
|
134
286
|
};
|
|
287
|
+
const pMax = {
|
|
288
|
+
x: max.apply(Math, rs.map((r) => r.maxX)),
|
|
289
|
+
y: max.apply(Math, rs.map((r) => r.maxY))
|
|
290
|
+
};
|
|
291
|
+
return getRectFromPoints(pMin, pMax);
|
|
135
292
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
293
|
+
|
|
294
|
+
// src/from-range.ts
|
|
295
|
+
function fromRange(range) {
|
|
296
|
+
let rs = [];
|
|
297
|
+
const rects = Array.from(range.getClientRects());
|
|
298
|
+
if (rects.length) {
|
|
299
|
+
rs = rs.concat(rects.map((r) => Rect.create(r)));
|
|
300
|
+
} else {
|
|
301
|
+
let start = range.startContainer;
|
|
302
|
+
if (start.nodeType === Node.TEXT_NODE) {
|
|
303
|
+
start = start.parentNode;
|
|
304
|
+
}
|
|
305
|
+
if (start instanceof HTMLElement) {
|
|
306
|
+
let r = getElementRect(start);
|
|
307
|
+
r.clone().set({ x: r.maxX, width: 0 });
|
|
308
|
+
rs.push(r);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return union.apply(void 0, rs);
|
|
140
312
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
313
|
+
|
|
314
|
+
// src/from-rotation.ts
|
|
315
|
+
function toRad(d) {
|
|
316
|
+
return d % 360 * Math.PI / 180;
|
|
317
|
+
}
|
|
318
|
+
function rotate(a, d, c) {
|
|
319
|
+
const r = toRad(d);
|
|
320
|
+
const sin = Math.sin(r);
|
|
321
|
+
const cos = Math.cos(r);
|
|
322
|
+
const x = a.x - c.x;
|
|
323
|
+
const y = a.y - c.y;
|
|
324
|
+
return { x: c.x + x * cos - y * sin, y: c.y + x * sin + y * cos };
|
|
325
|
+
}
|
|
326
|
+
function getRotationRect(r, deg) {
|
|
327
|
+
const rr = Object.values(r.corners).map((p) => rotate(p, deg, r.center));
|
|
328
|
+
const xs = rr.map((p) => p.x);
|
|
329
|
+
const ys = rr.map((p) => p.y);
|
|
330
|
+
const minX = Math.min(...xs);
|
|
331
|
+
const minY = Math.min(...ys);
|
|
332
|
+
const maxX = Math.max(...xs);
|
|
333
|
+
const maxY = Math.max(...ys);
|
|
334
|
+
return Rect.create({ x: minX, y: minY, width: maxX - minX, height: maxY - minY });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/from-window.ts
|
|
338
|
+
function getWindowRect(win, opts = {}) {
|
|
339
|
+
return Rect.create(getViewportRect(win, opts));
|
|
340
|
+
}
|
|
341
|
+
function getViewportRect(win, opts) {
|
|
342
|
+
const { excludeScrollbar = false } = opts;
|
|
343
|
+
const { innerWidth: innerWidth2, innerHeight: innerHeight2, document: doc, visualViewport } = win;
|
|
344
|
+
const width = visualViewport.width || innerWidth2;
|
|
345
|
+
const height = visualViewport.height || innerHeight2;
|
|
346
|
+
const rect = { x: 0, y: 0, width, height };
|
|
347
|
+
if (excludeScrollbar) {
|
|
348
|
+
const scrollbarWidth = innerWidth2 - doc.documentElement.clientWidth;
|
|
349
|
+
const scrollbarHeight = innerHeight2 - doc.documentElement.clientHeight;
|
|
350
|
+
rect.width -= scrollbarWidth;
|
|
351
|
+
rect.height -= scrollbarHeight;
|
|
352
|
+
}
|
|
353
|
+
return rect;
|
|
148
354
|
}
|
|
149
355
|
|
|
150
356
|
// src/operations.ts
|
|
@@ -212,17 +418,34 @@ function debugPolygon(polygon) {
|
|
|
212
418
|
}
|
|
213
419
|
export {
|
|
214
420
|
Rect,
|
|
421
|
+
alignRect,
|
|
215
422
|
closest,
|
|
423
|
+
closestSideToPoint,
|
|
424
|
+
closestSideToRect,
|
|
425
|
+
collisions,
|
|
426
|
+
contains,
|
|
427
|
+
containsPoint,
|
|
428
|
+
containsRect,
|
|
216
429
|
debugPolygon,
|
|
217
430
|
distance,
|
|
431
|
+
distanceBtwEdges,
|
|
432
|
+
distanceFromPoint,
|
|
433
|
+
distanceFromRect,
|
|
218
434
|
expand,
|
|
435
|
+
fromRange,
|
|
219
436
|
getElementRect,
|
|
220
|
-
|
|
437
|
+
getRectFromPoints,
|
|
438
|
+
getRotationRect,
|
|
439
|
+
getViewportRect,
|
|
440
|
+
getWindowRect,
|
|
221
441
|
inset,
|
|
442
|
+
intersection,
|
|
443
|
+
intersects,
|
|
222
444
|
isSymmetric,
|
|
223
|
-
|
|
445
|
+
rotate,
|
|
224
446
|
shift,
|
|
225
447
|
shrink,
|
|
448
|
+
toRad,
|
|
449
|
+
union,
|
|
226
450
|
withinPolygon
|
|
227
451
|
};
|
|
228
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { RectSide } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a Rect intersects another Rect
|
|
5
|
+
*/
|
|
6
|
+
export declare function intersects(a: Rect, b: Rect): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a new Rect that represents the intersection between two Rects
|
|
9
|
+
*/
|
|
10
|
+
export declare function intersection(a: Rect, b: Rect): Rect;
|
|
11
|
+
/**
|
|
12
|
+
* Returns whether two rects collide along each edge
|
|
13
|
+
*/
|
|
14
|
+
export declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
package/dist/operations.d.ts
CHANGED
|
@@ -5,4 +5,3 @@ export declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
|
|
|
5
5
|
export declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
6
6
|
export declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
7
7
|
export declare function shift(r: Rect, o: Partial<Point>): Rect;
|
|
8
|
-
//# sourceMappingURL=operations.d.ts.map
|
package/dist/polygon.d.ts
CHANGED
package/dist/rect.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/union.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/rect-utils",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220627213111",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@zag-js/utils": "0.0.0-dev-
|
|
28
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220627213111",
|
|
29
|
+
"@zag-js/utils": "0.1.2"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
32
|
"build:fast": "zag build",
|
package/dist/computed-style.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
declare type Key = keyof CSSStyleDeclaration | (string & {});
|
|
2
|
-
declare type Styles = Record<Key, any>;
|
|
3
|
-
declare type El = HTMLElement | null | undefined;
|
|
4
|
-
export declare function getComputedStyle(el: El): Styles;
|
|
5
|
-
export {};
|
|
6
|
-
//# sourceMappingURL=computed-style.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"computed-style.d.ts","sourceRoot":"","sources":["../src/computed-style.ts"],"names":[],"mappings":"AAAA,aAAK,GAAG,GAAG,MAAM,mBAAmB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AACpD,aAAK,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAC9B,aAAK,EAAE,GAAG,WAAW,GAAG,IAAI,GAAG,SAAS,CAAA;AAIxC,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAS/C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-element.d.ts","sourceRoot":"","sources":["../src/from-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG7B,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,GAAE,kBAAuB,GAAG,IAAI,CAEnF;AAED,oBAAY,kBAAkB,GAAG;IAC/B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
package/dist/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/rect.ts", "../src/computed-style.ts", "../src/from-element.ts", "../../core/src/array.ts", "../../core/src/guard.ts", "../../core/src/platform.ts", "../../core/src/events.ts", "../../core/src/functions.ts", "../../core/src/warning.ts", "../src/point.ts", "../src/operations.ts", "../src/polygon.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"./rect\"\nexport * from \"./types\"\nexport * from \"./from-element\"\nexport * from \"./point\"\nexport * from \"./operations\"\nexport * from \"./polygon\"\n", "import { RectEdge, RectValue } from \"./types\"\n\nconst point = (x: number, y: number) => ({ x, y })\n\nexport class Rect {\n static create(v: RectValue) {\n return new Rect(v)\n }\n protected constructor(private v: RectValue) {}\n set(n: Partial<RectValue>) {\n return new Rect(Object.assign({}, this.v, n))\n }\n clone() {\n return new Rect(this.v)\n }\n get x() {\n return this.v.x\n }\n get y() {\n return this.v.y\n }\n get width() {\n return this.v.width\n }\n get height() {\n return this.v.height\n }\n get minX() {\n return this.v.x\n }\n get midX() {\n return this.v.x + this.v.width / 2\n }\n get maxX() {\n return this.v.x + this.v.width\n }\n get minY() {\n return this.v.y\n }\n get midY() {\n return this.v.y + this.v.height / 2\n }\n get maxY() {\n return this.v.y + this.v.height\n }\n get center() {\n return point(this.midX, this.midY)\n }\n get centers() {\n const top = point(this.midX, this.minY)\n const right = point(this.maxX, this.midY)\n const bottom = point(this.midX, this.maxY)\n const left = point(this.minX, this.midY)\n return { top, right, bottom, left }\n }\n get corners() {\n const top = point(this.minX, this.minY)\n const right = point(this.maxX, this.minY)\n const bottom = point(this.maxX, this.maxY)\n const left = point(this.minX, this.maxY)\n return { top, right, bottom, left }\n }\n\n get edges() {\n const c = this.corners\n const top: RectEdge = [c.top, c.right]\n const right: RectEdge = [c.right, c.bottom]\n const bottom: RectEdge = [c.left, c.bottom]\n const left: RectEdge = [c.top, c.left]\n return { top, right, bottom, left }\n }\n}\n", "type Key = keyof CSSStyleDeclaration | (string & {})\ntype Styles = Record<Key, any>\ntype El = HTMLElement | null | undefined\n\nconst styleCache: WeakMap<HTMLElement, Styles> = new WeakMap()\n\nexport function getComputedStyle(el: El): Styles {\n if (!el) return {} as Styles\n let style: Styles | undefined = styleCache.get(el)\n if (!style) {\n const win = el?.ownerDocument.defaultView ?? window\n style = win.getComputedStyle(el) as Styles\n styleCache.set(el, style)\n }\n return style\n}\n", "import { Rect } from \"./rect\"\nimport { getComputedStyle } from \"./computed-style\"\n\nexport function getElementRect(el: HTMLElement, opts: ElementRectOptions = {}): Rect {\n return Rect.create(getClientRect(el, opts))\n}\n\nexport type ElementRectOptions = {\n /**\n * Whether to exclude the element's scrollbar size from the calculation.\n */\n excludeScrollbar?: boolean\n /**\n * Whether to exclude the element's borders from the calculation.\n */\n excludeBorders?: boolean\n}\n\nfunction getClientRect(el: HTMLElement, opts: ElementRectOptions = {}) {\n const { excludeScrollbar = false, excludeBorders = false } = opts\n\n const { x, y, width, height } = el.getBoundingClientRect()\n const r = { x, y, width, height }\n\n const style = getComputedStyle(el)\n\n const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style\n\n const borderXWidth = sum(borderLeftWidth, borderRightWidth)\n const borderYWidth = sum(borderTopWidth, borderBottomWidth)\n\n if (excludeBorders) {\n r.width -= borderXWidth\n r.height -= borderYWidth\n r.x += px(borderLeftWidth)\n r.y += px(borderTopWidth)\n }\n\n if (excludeScrollbar) {\n const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth\n const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth\n r.width -= scrollbarWidth\n r.height -= scrollbarHeight\n }\n\n return r\n}\n\nconst px = (v: string) => parseFloat(v.replace(\"px\", \"\"))\n\nconst sum = (...vals: string[]) => vals.reduce((sum, v) => sum + (v ? px(v) : 0), 0)\n", "export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n", "export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isDom = () => typeof window !== \"undefined\"\n\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n", "import { isDom } from \"./guard\"\n\nexport function getPlatform() {\n const agent = (navigator as any).userAgentData\n return agent?.platform ?? navigator.platform\n}\n\nconst pt = (v: RegExp) => isDom() && v.test(getPlatform())\nconst ua = (v: RegExp) => isDom() && v.test(navigator.userAgent)\nconst vn = (v: RegExp) => isDom() && v.test(navigator.vendor)\n\nexport const isTouchDevice = isDom() && !!navigator.maxTouchPoints\nexport const isMac = () => pt(/^Mac/) && !isTouchDevice\nexport const isIPhone = () => pt(/^iPhone/)\nexport const isSafari = () => isApple() && vn(/apple/i)\nexport const isFirefox = () => ua(/firefox\\//i)\nexport const isApple = () => pt(/mac|iphone|ipad|ipod/i)\nexport const isIos = () => isApple() && !isMac()\n", "import { hasProp, isDom, isObject } from \"./guard\"\nimport { isMac } from \"./platform\"\n\nexport const supportsPointerEvent = () => isDom() && window.onpointerdown === null\nexport const supportsTouchEvent = () => isDom() && window.ontouchstart === null\nexport const supportsMouseEvent = () => isDom() && window.onmousedown === null\n\nexport const isMouseEvent = (v: any): v is MouseEvent => isObject(v) && hasProp(v, \"button\")\nexport const isTouchEvent = (v: any): v is TouchEvent => isObject(v) && hasProp(v, \"touches\")\nexport const isLeftClick = (v: { button: number }) => v.button === 0\nexport const isRightClick = (v: { button: number }) => v.button === 2\nexport const isModifiedEvent = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\" | \"altKey\">) =>\n v.ctrlKey || v.altKey || v.metaKey\n\nexport const isCtrlKey = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\">) =>\n isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey\n", "export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const pipe =\n <T>(...fns: Array<(a: T) => T>) =>\n (v: T) =>\n fns.reduce((a, b) => b(a), v)\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n\nexport function merge<T, U>(origin: T, patch: U): T & U {\n if (!(typeof patch === \"object\")) return patch as any\n const result = !(typeof origin === \"object\") ? {} : Object.assign({}, origin)\n for (const key of Object.keys(patch)) {\n const value = patch[key]\n const src = result[key]\n if (value === null) delete result[key]\n else if (Array.isArray(value) || Array.isArray(src)) result[key] = (src || []).concat(value || [])\n else result[key] = merge(src, value)\n }\n return result as any\n}\n", "export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n", "import { isTouchEvent } from \"@zag-js/utils\"\nimport { Point } from \"./types\"\n\nexport function distance(a: Point, b: Point = { x: 0, y: 0 }): number {\n return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2))\n}\n\nexport function closest(...pts: Point[]) {\n return (a: Point): Point => {\n const ds = pts.map((b) => distance(b, a))\n const c = Math.min.apply(Math, ds)\n return pts[ds.indexOf(c)]\n }\n}\n\nconst fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 }\n\nexport function getEventPoint(e: AnyPointerEvent, t: PointType = \"page\"): Point {\n const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e\n return { x: p[`${t}X`], y: p[`${t}Y`] }\n}\n\nexport function relativeToNode(p: Point, el: HTMLElement): RelativeValue {\n const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft\n const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop\n return {\n point: { x: dx, y: dy },\n progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight },\n }\n}\n\ntype AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent\n\ntype RelativeValue = {\n point: Point\n progress: { x: number; y: number }\n}\n\ntype PointType = \"page\" | \"client\"\n", "import { Rect } from \"./rect\"\nimport type { Point, RectInset, SymmetricRectInset } from \"./types\"\n\nexport const isSymmetric = (v: any): v is SymmetricRectInset => \"dx\" in v || \"dy\" in v\n\nexport function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect {\n const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i\n const { top = 0, right = 0, bottom = 0, left = 0 } = v\n return Rect.create({ x: r.x + left, y: r.y + top, width: r.width - left - right, height: r.height - top - bottom })\n}\n\nexport function expand(r: Rect, v: number | SymmetricRectInset): Rect {\n const value = typeof v === \"number\" ? { dx: -v, dy: -v } : v\n return inset(r, value)\n}\n\nexport function shrink(r: Rect, v: number | SymmetricRectInset): Rect {\n const value = typeof v === \"number\" ? { dx: -v, dy: -v } : v\n return inset(r, value)\n}\n\nexport function shift(r: Rect, o: Partial<Point>): Rect {\n const { x = 0, y = 0 } = o\n return Rect.create({ x: r.x + x, y: r.y + y, width: r.width, height: r.height })\n}\n", "import { Point } from \"./types\"\n\nexport function withinPolygon(polygon: Point[], point: Point) {\n const { x, y } = point\n let c = false\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x\n const yi = polygon[i].y\n const xj = polygon[j].x\n const yj = polygon[j].y\n\n if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) {\n c = !c\n }\n }\n return c\n}\n\nfunction createPolygonElement() {\n const id = \"debug-polygon\"\n const existingPolygon = document.getElementById(id)\n if (existingPolygon) {\n return existingPolygon\n }\n const svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\")\n Object.assign(svg.style, {\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n opacity: \"0.15\",\n position: \"fixed\",\n pointerEvents: \"none\",\n })\n\n const polygon = document.createElementNS(\"http://www.w3.org/2000/svg\", \"polygon\")\n polygon.setAttribute(\"id\", id)\n polygon.setAttribute(\"points\", \"0,0 0,0\")\n svg.appendChild(polygon)\n document.body.appendChild(svg)\n return polygon\n}\n\nexport function debugPolygon(polygon: Point[]) {\n const el = createPolygonElement()\n const points = polygon.map((point) => `${point.x},${point.y}`).join(\" \")\n el.setAttribute(\"points\", points)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,QAAQ,CAAC,GAAW,MAAe,GAAE,GAAG,EAAE;AAEzC,iBAAW;AAAA,EAIN,YAAoB,GAAc;AAAd;AAAA,EAAe;AAAA,SAHtC,OAAO,GAAc;AAC1B,WAAO,IAAI,KAAK,CAAC;AAAA,EACnB;AAAA,EAEA,IAAI,GAAuB;AACzB,WAAO,IAAI,KAAK,OAAO,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAAA,EAC9C;AAAA,EACA,QAAQ;AACN,WAAO,IAAI,KAAK,KAAK,CAAC;AAAA,EACxB;AAAA,MACI,IAAI;AACN,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,IAAI;AACN,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,QAAQ;AACV,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,SAAS;AACX,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE,IAAI,KAAK,EAAE,QAAQ;AAAA,EACnC;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE,IAAI,KAAK,EAAE;AAAA,EAC3B;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE;AAAA,EAChB;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE,IAAI,KAAK,EAAE,SAAS;AAAA,EACpC;AAAA,MACI,OAAO;AACT,WAAO,KAAK,EAAE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,EAAE;AAClD,MAAI,iBAAiB;AACnB,WAAO;AAAA,EACT;AACA,QAAM,MAAM,SAAS,gBAAgB,8BAA8B,KAAK;AACxE,SAAO,OAAO,IAAI,OAAO;AAAA,IACvB,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,UAAU;AAAA,IACV,eAAe;AAAA,EACjB,CAAC;AAED,QAAM,UAAU,SAAS,gBAAgB,8BAA8B,SAAS;AAChF,UAAQ,aAAa,MAAM,EAAE;AAC7B,UAAQ,aAAa,UAAU,SAAS;AACxC,MAAI,YAAY,OAAO;AACvB,WAAS,KAAK,YAAY,GAAG;AAC7B,SAAO;AACT;AAEO,sBAAsB,SAAkB;AAC7C,QAAM,KAAK,qBAAqB;AAChC,QAAM,SAAS,QAAQ,IAAI,CAAC,WAAU,GAAG,OAAM,KAAK,OAAM,GAAG,EAAE,KAAK,GAAG;AACvE,KAAG,aAAa,UAAU,MAAM;AAClC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/index.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/rect.ts", "../src/computed-style.ts", "../src/from-element.ts", "../../core/src/array.ts", "../../core/src/guard.ts", "../../core/src/platform.ts", "../../core/src/events.ts", "../../core/src/functions.ts", "../../core/src/warning.ts", "../src/point.ts", "../src/operations.ts", "../src/polygon.ts"],
|
|
4
|
-
"sourcesContent": ["import { RectEdge, RectValue } from \"./types\"\n\nconst point = (x: number, y: number) => ({ x, y })\n\nexport class Rect {\n static create(v: RectValue) {\n return new Rect(v)\n }\n protected constructor(private v: RectValue) {}\n set(n: Partial<RectValue>) {\n return new Rect(Object.assign({}, this.v, n))\n }\n clone() {\n return new Rect(this.v)\n }\n get x() {\n return this.v.x\n }\n get y() {\n return this.v.y\n }\n get width() {\n return this.v.width\n }\n get height() {\n return this.v.height\n }\n get minX() {\n return this.v.x\n }\n get midX() {\n return this.v.x + this.v.width / 2\n }\n get maxX() {\n return this.v.x + this.v.width\n }\n get minY() {\n return this.v.y\n }\n get midY() {\n return this.v.y + this.v.height / 2\n }\n get maxY() {\n return this.v.y + this.v.height\n }\n get center() {\n return point(this.midX, this.midY)\n }\n get centers() {\n const top = point(this.midX, this.minY)\n const right = point(this.maxX, this.midY)\n const bottom = point(this.midX, this.maxY)\n const left = point(this.minX, this.midY)\n return { top, right, bottom, left }\n }\n get corners() {\n const top = point(this.minX, this.minY)\n const right = point(this.maxX, this.minY)\n const bottom = point(this.maxX, this.maxY)\n const left = point(this.minX, this.maxY)\n return { top, right, bottom, left }\n }\n\n get edges() {\n const c = this.corners\n const top: RectEdge = [c.top, c.right]\n const right: RectEdge = [c.right, c.bottom]\n const bottom: RectEdge = [c.left, c.bottom]\n const left: RectEdge = [c.top, c.left]\n return { top, right, bottom, left }\n }\n}\n", "type Key = keyof CSSStyleDeclaration | (string & {})\ntype Styles = Record<Key, any>\ntype El = HTMLElement | null | undefined\n\nconst styleCache: WeakMap<HTMLElement, Styles> = new WeakMap()\n\nexport function getComputedStyle(el: El): Styles {\n if (!el) return {} as Styles\n let style: Styles | undefined = styleCache.get(el)\n if (!style) {\n const win = el?.ownerDocument.defaultView ?? window\n style = win.getComputedStyle(el) as Styles\n styleCache.set(el, style)\n }\n return style\n}\n", "import { Rect } from \"./rect\"\nimport { getComputedStyle } from \"./computed-style\"\n\nexport function getElementRect(el: HTMLElement, opts: ElementRectOptions = {}): Rect {\n return Rect.create(getClientRect(el, opts))\n}\n\nexport type ElementRectOptions = {\n /**\n * Whether to exclude the element's scrollbar size from the calculation.\n */\n excludeScrollbar?: boolean\n /**\n * Whether to exclude the element's borders from the calculation.\n */\n excludeBorders?: boolean\n}\n\nfunction getClientRect(el: HTMLElement, opts: ElementRectOptions = {}) {\n const { excludeScrollbar = false, excludeBorders = false } = opts\n\n const { x, y, width, height } = el.getBoundingClientRect()\n const r = { x, y, width, height }\n\n const style = getComputedStyle(el)\n\n const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style\n\n const borderXWidth = sum(borderLeftWidth, borderRightWidth)\n const borderYWidth = sum(borderTopWidth, borderBottomWidth)\n\n if (excludeBorders) {\n r.width -= borderXWidth\n r.height -= borderYWidth\n r.x += px(borderLeftWidth)\n r.y += px(borderTopWidth)\n }\n\n if (excludeScrollbar) {\n const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth\n const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth\n r.width -= scrollbarWidth\n r.height -= scrollbarHeight\n }\n\n return r\n}\n\nconst px = (v: string) => parseFloat(v.replace(\"px\", \"\"))\n\nconst sum = (...vals: string[]) => vals.reduce((sum, v) => sum + (v ? px(v) : 0), 0)\n", "export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n", "export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isDom = () => typeof window !== \"undefined\"\n\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n", "import { isDom } from \"./guard\"\n\nexport function getPlatform() {\n const agent = (navigator as any).userAgentData\n return agent?.platform ?? navigator.platform\n}\n\nconst pt = (v: RegExp) => isDom() && v.test(getPlatform())\nconst ua = (v: RegExp) => isDom() && v.test(navigator.userAgent)\nconst vn = (v: RegExp) => isDom() && v.test(navigator.vendor)\n\nexport const isTouchDevice = isDom() && !!navigator.maxTouchPoints\nexport const isMac = () => pt(/^Mac/) && !isTouchDevice\nexport const isIPhone = () => pt(/^iPhone/)\nexport const isSafari = () => isApple() && vn(/apple/i)\nexport const isFirefox = () => ua(/firefox\\//i)\nexport const isApple = () => pt(/mac|iphone|ipad|ipod/i)\nexport const isIos = () => isApple() && !isMac()\n", "import { hasProp, isDom, isObject } from \"./guard\"\nimport { isMac } from \"./platform\"\n\nexport const supportsPointerEvent = () => isDom() && window.onpointerdown === null\nexport const supportsTouchEvent = () => isDom() && window.ontouchstart === null\nexport const supportsMouseEvent = () => isDom() && window.onmousedown === null\n\nexport const isMouseEvent = (v: any): v is MouseEvent => isObject(v) && hasProp(v, \"button\")\nexport const isTouchEvent = (v: any): v is TouchEvent => isObject(v) && hasProp(v, \"touches\")\nexport const isLeftClick = (v: { button: number }) => v.button === 0\nexport const isRightClick = (v: { button: number }) => v.button === 2\nexport const isModifiedEvent = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\" | \"altKey\">) =>\n v.ctrlKey || v.altKey || v.metaKey\n\nexport const isCtrlKey = (v: Pick<KeyboardEvent, \"ctrlKey\" | \"metaKey\">) =>\n isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey\n", "export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const pipe =\n <T>(...fns: Array<(a: T) => T>) =>\n (v: T) =>\n fns.reduce((a, b) => b(a), v)\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n\nexport function merge<T, U>(origin: T, patch: U): T & U {\n if (!(typeof patch === \"object\")) return patch as any\n const result = !(typeof origin === \"object\") ? {} : Object.assign({}, origin)\n for (const key of Object.keys(patch)) {\n const value = patch[key]\n const src = result[key]\n if (value === null) delete result[key]\n else if (Array.isArray(value) || Array.isArray(src)) result[key] = (src || []).concat(value || [])\n else result[key] = merge(src, value)\n }\n return result as any\n}\n", "export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n", "import { isTouchEvent } from \"@zag-js/utils\"\nimport { Point } from \"./types\"\n\nexport function distance(a: Point, b: Point = { x: 0, y: 0 }): number {\n return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2))\n}\n\nexport function closest(...pts: Point[]) {\n return (a: Point): Point => {\n const ds = pts.map((b) => distance(b, a))\n const c = Math.min.apply(Math, ds)\n return pts[ds.indexOf(c)]\n }\n}\n\nconst fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 }\n\nexport function getEventPoint(e: AnyPointerEvent, t: PointType = \"page\"): Point {\n const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e\n return { x: p[`${t}X`], y: p[`${t}Y`] }\n}\n\nexport function relativeToNode(p: Point, el: HTMLElement): RelativeValue {\n const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft\n const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop\n return {\n point: { x: dx, y: dy },\n progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight },\n }\n}\n\ntype AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent\n\ntype RelativeValue = {\n point: Point\n progress: { x: number; y: number }\n}\n\ntype PointType = \"page\" | \"client\"\n", "import { Rect } from \"./rect\"\nimport type { Point, RectInset, SymmetricRectInset } from \"./types\"\n\nexport const isSymmetric = (v: any): v is SymmetricRectInset => \"dx\" in v || \"dy\" in v\n\nexport function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect {\n const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i\n const { top = 0, right = 0, bottom = 0, left = 0 } = v\n return Rect.create({ x: r.x + left, y: r.y + top, width: r.width - left - right, height: r.height - top - bottom })\n}\n\nexport function expand(r: Rect, v: number | SymmetricRectInset): Rect {\n const value = typeof v === \"number\" ? { dx: -v, dy: -v } : v\n return inset(r, value)\n}\n\nexport function shrink(r: Rect, v: number | SymmetricRectInset): Rect {\n const value = typeof v === \"number\" ? { dx: -v, dy: -v } : v\n return inset(r, value)\n}\n\nexport function shift(r: Rect, o: Partial<Point>): Rect {\n const { x = 0, y = 0 } = o\n return Rect.create({ x: r.x + x, y: r.y + y, width: r.width, height: r.height })\n}\n", "import { Point } from \"./types\"\n\nexport function withinPolygon(polygon: Point[], point: Point) {\n const { x, y } = point\n let c = false\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x\n const yi = polygon[i].y\n const xj = polygon[j].x\n const yj = polygon[j].y\n\n if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) {\n c = !c\n }\n }\n return c\n}\n\nfunction createPolygonElement() {\n const id = \"debug-polygon\"\n const existingPolygon = document.getElementById(id)\n if (existingPolygon) {\n return existingPolygon\n }\n const svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\")\n Object.assign(svg.style, {\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\",\n opacity: \"0.15\",\n position: \"fixed\",\n pointerEvents: \"none\",\n })\n\n const polygon = document.createElementNS(\"http://www.w3.org/2000/svg\", \"polygon\")\n polygon.setAttribute(\"id\", id)\n polygon.setAttribute(\"points\", \"0,0 0,0\")\n svg.appendChild(polygon)\n document.body.appendChild(svg)\n return polygon\n}\n\nexport function debugPolygon(polygon: Point[]) {\n const el = createPolygonElement()\n const points = polygon.map((point) => `${point.x},${point.y}`).join(\" \")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A,EACjB,CAAC;AAED,QAAM,UAAU,SAAS,gBAAgB,8BAA8B,SAAS;AAChF,UAAQ,aAAa,MAAM,EAAE;AAC7B,UAAQ,aAAa,UAAU,SAAS;AACxC,MAAI,YAAY,OAAO;AACvB,WAAS,KAAK,YAAY,GAAG;AAC7B,SAAO;AACT;AAEO,sBAAsB,SAAkB;AAC7C,QAAM,KAAK,qBAAqB;AAChC,QAAM,SAAS,QAAQ,IAAI,CAAC,WAAU,GAAG,OAAM,KAAK,OAAM,GAAG,EAAE,KAAK,GAAG;AACvE,KAAG,aAAa,UAAU,MAAM;AAClC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/operations.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEnE,eAAO,MAAM,WAAW,MAAO,GAAG,4BAAoD,CAAA;AAEtF,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,GAAG,kBAAkB,GAAG,IAAI,CAItE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAGpE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAGpE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAGtD"}
|
package/dist/point.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Point } from "./types";
|
|
2
|
-
export declare function distance(a: Point, b?: Point): number;
|
|
3
|
-
export declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
4
|
-
export declare function getEventPoint(e: AnyPointerEvent, t?: PointType): Point;
|
|
5
|
-
export declare function relativeToNode(p: Point, el: HTMLElement): RelativeValue;
|
|
6
|
-
declare type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
|
|
7
|
-
declare type RelativeValue = {
|
|
8
|
-
point: Point;
|
|
9
|
-
progress: {
|
|
10
|
-
x: number;
|
|
11
|
-
y: number;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
declare type PointType = "page" | "client";
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=point.d.ts.map
|
package/dist/point.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../src/point.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAE,KAAsB,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,OAC1B,KAAK,KAAG,KAAK,CAKzB;AAID,wBAAgB,aAAa,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,GAAE,SAAkB,GAAG,KAAK,CAG9E;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,GAAG,aAAa,CAOvE;AAED,aAAK,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAA;AAE7D,aAAK,aAAa,GAAG;IACnB,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACnC,CAAA;AAED,aAAK,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA"}
|
package/dist/polygon.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../src/polygon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,wBAAgB,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,WAe3D;AA2BD,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,QAI5C"}
|
package/dist/rect.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../src/rect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAI7C,qBAAa,IAAI;IAIO,OAAO,CAAC,CAAC;IAH/B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS;IAG1B,SAAS,aAAqB,CAAC,EAAE,SAAS;IAC1C,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC;IAGzB,KAAK;IAGL,IAAI,CAAC,WAEJ;IACD,IAAI,CAAC,WAEJ;IACD,IAAI,KAAK,WAER;IACD,IAAI,MAAM,WAET;IACD,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,WAEP;IACD,IAAI,IAAI,WAEP;IACD,IAAI,MAAM;;;MAET;IACD,IAAI,OAAO;;;;;;;;;;;;;;;;;MAMV;IACD,IAAI,OAAO;;;;;;;;;;;;;;;;;MAMV;IAED,IAAI,KAAK;;;;;MAOR;CACF"}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,C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