@zag-js/rect-utils 0.10.2 → 0.10.3
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 +5 -9
- package/dist/align.js +5 -28
- package/dist/align.mjs +44 -6
- package/dist/closest.d.ts +5 -8
- package/dist/closest.js +8 -38
- package/dist/closest.mjs +47 -13
- package/dist/contains.d.ts +5 -8
- package/dist/contains.js +9 -48
- package/dist/contains.mjs +13 -11
- package/dist/distance.d.ts +7 -10
- package/dist/distance.js +9 -40
- package/dist/distance.mjs +41 -14
- package/dist/from-element.d.ts +3 -7
- package/dist/from-element.js +9 -53
- package/dist/from-element.mjs +39 -7
- package/dist/from-points.d.ts +3 -6
- package/dist/from-points.js +6 -50
- package/dist/from-points.mjs +13 -7
- package/dist/from-range.d.ts +2 -6
- package/dist/from-range.js +11 -127
- package/dist/from-range.mjs +23 -10
- package/dist/from-rotation.d.ts +5 -8
- package/dist/from-rotation.js +9 -62
- package/dist/from-rotation.mjs +33 -11
- package/dist/from-window.d.ts +4 -8
- package/dist/from-window.js +7 -52
- package/dist/from-window.mjs +21 -9
- package/dist/get-polygon.d.ts +2 -5
- package/dist/get-polygon.js +7 -58
- package/dist/get-polygon.mjs +15 -7
- package/dist/index.d.ts +16 -16
- package/dist/index.js +58 -539
- package/dist/index.mjs +15 -105
- package/dist/intersection.d.ts +5 -8
- package/dist/intersection.js +8 -54
- package/dist/intersection.mjs +22 -11
- package/dist/operations.d.ts +7 -10
- package/dist/operations.js +12 -60
- package/dist/operations.mjs +32 -15
- package/dist/polygon.d.ts +3 -6
- package/dist/polygon.js +6 -30
- package/dist/polygon.mjs +48 -8
- package/dist/rect.d.ts +7 -10
- package/dist/rect.js +11 -38
- package/dist/rect.mjs +47 -14
- package/dist/types.d.ts +13 -15
- package/dist/union.d.ts +2 -6
- package/dist/union.js +7 -62
- package/dist/union.mjs +28 -8
- package/package.json +2 -7
- package/dist/chunk-25JXNQDO.mjs +0 -32
- package/dist/chunk-2FRM3R57.mjs +0 -27
- package/dist/chunk-62GE3RPG.mjs +0 -21
- package/dist/chunk-BDA5H4ND.mjs +0 -44
- package/dist/chunk-BRVYSREB.mjs +0 -21
- package/dist/chunk-D46YBNP3.mjs +0 -18
- package/dist/chunk-GYYHT756.mjs +0 -29
- package/dist/chunk-K4PDUEML.mjs +0 -33
- package/dist/chunk-MM5LIN7D.mjs +0 -41
- package/dist/chunk-MNKJK37U.mjs +0 -54
- package/dist/chunk-N5AQDOKZ.mjs +0 -49
- package/dist/chunk-Q4ND66B6.mjs +0 -54
- package/dist/chunk-QXXKPYP2.mjs +0 -47
- package/dist/chunk-R24UTBJ3.mjs +0 -52
- package/dist/chunk-W5IPBTYQ.mjs +0 -41
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
1
|
+
export * from "./align";
|
|
2
|
+
export * from "./closest";
|
|
3
|
+
export * from "./contains";
|
|
4
|
+
export * from "./distance";
|
|
5
|
+
export * from "./from-element";
|
|
6
|
+
export * from "./from-points";
|
|
7
|
+
export * from "./from-range";
|
|
8
|
+
export * from "./from-rotation";
|
|
9
|
+
export * from "./from-window";
|
|
10
|
+
export * from "./get-polygon";
|
|
11
|
+
export * from "./intersection";
|
|
12
|
+
export * from "./operations";
|
|
13
|
+
export * from "./polygon";
|
|
14
|
+
export * from "./rect";
|
|
15
|
+
export * from "./types";
|
|
16
|
+
export * from "./union";
|
package/dist/index.js
CHANGED
|
@@ -1,539 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
module.exports = __toCommonJS(src_exports);
|
|
61
|
-
|
|
62
|
-
// src/align.ts
|
|
63
|
-
function hAlign(a, ref, h) {
|
|
64
|
-
let x = ref.minX;
|
|
65
|
-
if (h === "left-inside") {
|
|
66
|
-
x = ref.minX;
|
|
67
|
-
}
|
|
68
|
-
if (h === "left-outside") {
|
|
69
|
-
x = ref.minX - ref.width;
|
|
70
|
-
}
|
|
71
|
-
if (h === "right-inside") {
|
|
72
|
-
x = ref.maxX - ref.width;
|
|
73
|
-
}
|
|
74
|
-
if (h === "right-outside") {
|
|
75
|
-
x = ref.maxX;
|
|
76
|
-
}
|
|
77
|
-
if (h === "center") {
|
|
78
|
-
x = ref.midX - ref.width / 2;
|
|
79
|
-
}
|
|
80
|
-
return { ...a, x };
|
|
81
|
-
}
|
|
82
|
-
function vAlign(a, ref, v) {
|
|
83
|
-
let y = ref.minY;
|
|
84
|
-
if (v === "top-inside") {
|
|
85
|
-
y = ref.minY;
|
|
86
|
-
}
|
|
87
|
-
if (v === "top-outside") {
|
|
88
|
-
y = ref.minY - a.height;
|
|
89
|
-
}
|
|
90
|
-
if (v === "bottom-inside") {
|
|
91
|
-
y = ref.maxY - a.height;
|
|
92
|
-
}
|
|
93
|
-
if (v === "bottom-outside") {
|
|
94
|
-
y = ref.maxY;
|
|
95
|
-
}
|
|
96
|
-
if (v === "center") {
|
|
97
|
-
y = ref.midY - a.height / 2;
|
|
98
|
-
}
|
|
99
|
-
return { ...a, y };
|
|
100
|
-
}
|
|
101
|
-
function alignRect(a, ref, options) {
|
|
102
|
-
const { h, v } = options;
|
|
103
|
-
return vAlign(hAlign(a, ref, h), ref, v);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/rect.ts
|
|
107
|
-
var point = (x, y) => ({ x, y });
|
|
108
|
-
function createRect(r) {
|
|
109
|
-
const { x, y, width, height } = r;
|
|
110
|
-
const midX = x + width / 2;
|
|
111
|
-
const midY = y + height / 2;
|
|
112
|
-
return {
|
|
113
|
-
x,
|
|
114
|
-
y,
|
|
115
|
-
width,
|
|
116
|
-
height,
|
|
117
|
-
minX: x,
|
|
118
|
-
minY: y,
|
|
119
|
-
maxX: x + width,
|
|
120
|
-
maxY: y + height,
|
|
121
|
-
midX,
|
|
122
|
-
midY,
|
|
123
|
-
center: point(midX, midY)
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
127
|
-
function isRect(v) {
|
|
128
|
-
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
129
|
-
}
|
|
130
|
-
function getRectCenters(v) {
|
|
131
|
-
const top = point(v.midX, v.minY);
|
|
132
|
-
const right = point(v.maxX, v.midY);
|
|
133
|
-
const bottom = point(v.midX, v.maxY);
|
|
134
|
-
const left = point(v.minX, v.midY);
|
|
135
|
-
return { top, right, bottom, left };
|
|
136
|
-
}
|
|
137
|
-
function getRectCorners(v) {
|
|
138
|
-
const top = point(v.minX, v.minY);
|
|
139
|
-
const right = point(v.maxX, v.minY);
|
|
140
|
-
const bottom = point(v.maxX, v.maxY);
|
|
141
|
-
const left = point(v.minX, v.maxY);
|
|
142
|
-
return { top, right, bottom, left };
|
|
143
|
-
}
|
|
144
|
-
function getRectEdges(v) {
|
|
145
|
-
const c = getRectCorners(v);
|
|
146
|
-
const top = [c.top, c.right];
|
|
147
|
-
const right = [c.right, c.bottom];
|
|
148
|
-
const bottom = [c.left, c.bottom];
|
|
149
|
-
const left = [c.top, c.left];
|
|
150
|
-
return { top, right, bottom, left };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/intersection.ts
|
|
154
|
-
function intersects(a, b) {
|
|
155
|
-
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
156
|
-
}
|
|
157
|
-
function intersection(a, b) {
|
|
158
|
-
const x = Math.max(a.x, b.x);
|
|
159
|
-
const y = Math.max(a.y, b.y);
|
|
160
|
-
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
161
|
-
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
162
|
-
return createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
163
|
-
}
|
|
164
|
-
function collisions(a, b) {
|
|
165
|
-
return {
|
|
166
|
-
top: a.minY <= b.minY,
|
|
167
|
-
right: a.maxX >= b.maxX,
|
|
168
|
-
bottom: a.maxY >= b.maxY,
|
|
169
|
-
left: a.minX <= b.minX
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// src/distance.ts
|
|
174
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
175
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
176
|
-
}
|
|
177
|
-
function distanceFromPoint(r, p) {
|
|
178
|
-
let x = 0;
|
|
179
|
-
let y = 0;
|
|
180
|
-
if (p.x < r.x)
|
|
181
|
-
x = r.x - p.x;
|
|
182
|
-
else if (p.x > r.maxX)
|
|
183
|
-
x = p.x - r.maxX;
|
|
184
|
-
if (p.y < r.y)
|
|
185
|
-
y = r.y - p.y;
|
|
186
|
-
else if (p.y > r.maxY)
|
|
187
|
-
y = p.y - r.maxY;
|
|
188
|
-
return { x, y, value: distance({ x, y }) };
|
|
189
|
-
}
|
|
190
|
-
function distanceFromRect(a, b) {
|
|
191
|
-
if (intersects(a, b))
|
|
192
|
-
return { x: 0, y: 0, value: 0 };
|
|
193
|
-
const left = a.x < b.x ? a : b;
|
|
194
|
-
const right = b.x < a.x ? a : b;
|
|
195
|
-
const upper = a.y < b.y ? a : b;
|
|
196
|
-
const lower = b.y < a.y ? a : b;
|
|
197
|
-
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
198
|
-
x = Math.max(0, x);
|
|
199
|
-
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
200
|
-
y = Math.max(0, y);
|
|
201
|
-
return { x, y, value: distance({ x, y }) };
|
|
202
|
-
}
|
|
203
|
-
function distanceBtwEdges(a, b) {
|
|
204
|
-
return {
|
|
205
|
-
left: b.x - a.x,
|
|
206
|
-
top: b.y - a.y,
|
|
207
|
-
right: a.maxX - b.maxX,
|
|
208
|
-
bottom: a.maxY - b.maxY
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// src/closest.ts
|
|
213
|
-
function closest(...pts) {
|
|
214
|
-
return (a) => {
|
|
215
|
-
const ds = pts.map((b) => distance(b, a));
|
|
216
|
-
const c = Math.min.apply(Math, ds);
|
|
217
|
-
return pts[ds.indexOf(c)];
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function closestSideToRect(ref, r) {
|
|
221
|
-
if (r.maxX <= ref.minX) {
|
|
222
|
-
return "left";
|
|
223
|
-
}
|
|
224
|
-
if (r.minX >= ref.maxX) {
|
|
225
|
-
return "right";
|
|
226
|
-
}
|
|
227
|
-
if (r.maxY <= ref.minY) {
|
|
228
|
-
return "top";
|
|
229
|
-
}
|
|
230
|
-
if (r.minY >= ref.maxY) {
|
|
231
|
-
return "bottom";
|
|
232
|
-
}
|
|
233
|
-
return "left";
|
|
234
|
-
}
|
|
235
|
-
function closestSideToPoint(ref, p) {
|
|
236
|
-
const { x, y } = p;
|
|
237
|
-
const dl = x - ref.minX;
|
|
238
|
-
const dr = ref.maxX - x;
|
|
239
|
-
const dt = y - ref.minY;
|
|
240
|
-
const db = ref.maxY - y;
|
|
241
|
-
let closest2 = dl;
|
|
242
|
-
let side = "left";
|
|
243
|
-
if (dr < closest2) {
|
|
244
|
-
closest2 = dr;
|
|
245
|
-
side = "right";
|
|
246
|
-
}
|
|
247
|
-
if (dt < closest2) {
|
|
248
|
-
closest2 = dt;
|
|
249
|
-
side = "top";
|
|
250
|
-
}
|
|
251
|
-
if (db < closest2) {
|
|
252
|
-
side = "bottom";
|
|
253
|
-
}
|
|
254
|
-
return side;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// src/contains.ts
|
|
258
|
-
function containsPoint(r, p) {
|
|
259
|
-
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
260
|
-
}
|
|
261
|
-
function containsRect(a, b) {
|
|
262
|
-
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
263
|
-
}
|
|
264
|
-
function contains(r, v) {
|
|
265
|
-
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// src/from-element.ts
|
|
269
|
-
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
270
|
-
function getCacheComputedStyle(el) {
|
|
271
|
-
if (!styleCache.has(el)) {
|
|
272
|
-
const win = el.ownerDocument.defaultView || window;
|
|
273
|
-
styleCache.set(el, win.getComputedStyle(el));
|
|
274
|
-
}
|
|
275
|
-
return styleCache.get(el);
|
|
276
|
-
}
|
|
277
|
-
function getElementRect(el, opts = {}) {
|
|
278
|
-
return createRect(getClientRect(el, opts));
|
|
279
|
-
}
|
|
280
|
-
function getClientRect(el, opts = {}) {
|
|
281
|
-
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
282
|
-
const { x, y, width, height } = el.getBoundingClientRect();
|
|
283
|
-
const r = { x, y, width, height };
|
|
284
|
-
const style = getCacheComputedStyle(el);
|
|
285
|
-
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
286
|
-
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
287
|
-
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
288
|
-
if (excludeBorders) {
|
|
289
|
-
r.width -= borderXWidth;
|
|
290
|
-
r.height -= borderYWidth;
|
|
291
|
-
r.x += px(borderLeftWidth);
|
|
292
|
-
r.y += px(borderTopWidth);
|
|
293
|
-
}
|
|
294
|
-
if (excludeScrollbar) {
|
|
295
|
-
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
296
|
-
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
297
|
-
r.width -= scrollbarWidth;
|
|
298
|
-
r.height -= scrollbarHeight;
|
|
299
|
-
}
|
|
300
|
-
return r;
|
|
301
|
-
}
|
|
302
|
-
var px = (v) => parseFloat(v.replace("px", ""));
|
|
303
|
-
var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
304
|
-
|
|
305
|
-
// src/from-points.ts
|
|
306
|
-
function getRectFromPoints(...pts) {
|
|
307
|
-
const xs = pts.map((p) => p.x);
|
|
308
|
-
const ys = pts.map((p) => p.y);
|
|
309
|
-
const x = Math.min(...xs);
|
|
310
|
-
const y = Math.min(...ys);
|
|
311
|
-
const width = Math.max(...xs) - x;
|
|
312
|
-
const height = Math.max(...ys) - y;
|
|
313
|
-
return createRect({ x, y, width, height });
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// src/union.ts
|
|
317
|
-
var { min, max } = Math;
|
|
318
|
-
function union(...rs) {
|
|
319
|
-
const pMin = {
|
|
320
|
-
x: min.apply(
|
|
321
|
-
Math,
|
|
322
|
-
rs.map((r) => r.minX)
|
|
323
|
-
),
|
|
324
|
-
y: min.apply(
|
|
325
|
-
Math,
|
|
326
|
-
rs.map((r) => r.minY)
|
|
327
|
-
)
|
|
328
|
-
};
|
|
329
|
-
const pMax = {
|
|
330
|
-
x: max.apply(
|
|
331
|
-
Math,
|
|
332
|
-
rs.map((r) => r.maxX)
|
|
333
|
-
),
|
|
334
|
-
y: max.apply(
|
|
335
|
-
Math,
|
|
336
|
-
rs.map((r) => r.maxY)
|
|
337
|
-
)
|
|
338
|
-
};
|
|
339
|
-
return getRectFromPoints(pMin, pMax);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// src/from-range.ts
|
|
343
|
-
function fromRange(range) {
|
|
344
|
-
let rs = [];
|
|
345
|
-
const rects = Array.from(range.getClientRects());
|
|
346
|
-
if (rects.length) {
|
|
347
|
-
rs = rs.concat(rects.map(createRect));
|
|
348
|
-
return union.apply(void 0, rs);
|
|
349
|
-
}
|
|
350
|
-
let start = range.startContainer;
|
|
351
|
-
if (start.nodeType === Node.TEXT_NODE) {
|
|
352
|
-
start = start.parentNode;
|
|
353
|
-
}
|
|
354
|
-
if (start instanceof HTMLElement) {
|
|
355
|
-
const r = getElementRect(start);
|
|
356
|
-
rs.push({ ...r, x: r.maxX, width: 0 });
|
|
357
|
-
}
|
|
358
|
-
return union.apply(void 0, rs);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// src/from-rotation.ts
|
|
362
|
-
function toRad(d) {
|
|
363
|
-
return d % 360 * Math.PI / 180;
|
|
364
|
-
}
|
|
365
|
-
function rotate(a, d, c) {
|
|
366
|
-
const r = toRad(d);
|
|
367
|
-
const sin = Math.sin(r);
|
|
368
|
-
const cos = Math.cos(r);
|
|
369
|
-
const x = a.x - c.x;
|
|
370
|
-
const y = a.y - c.y;
|
|
371
|
-
return {
|
|
372
|
-
x: c.x + x * cos - y * sin,
|
|
373
|
-
y: c.y + x * sin + y * cos
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function getRotationRect(r, deg) {
|
|
377
|
-
const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
378
|
-
const xs = rr.map((p) => p.x);
|
|
379
|
-
const ys = rr.map((p) => p.y);
|
|
380
|
-
const minX = Math.min(...xs);
|
|
381
|
-
const minY = Math.min(...ys);
|
|
382
|
-
const maxX = Math.max(...xs);
|
|
383
|
-
const maxY = Math.max(...ys);
|
|
384
|
-
return createRect({
|
|
385
|
-
x: minX,
|
|
386
|
-
y: minY,
|
|
387
|
-
width: maxX - minX,
|
|
388
|
-
height: maxY - minY
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// src/from-window.ts
|
|
393
|
-
function getWindowRect(win, opts = {}) {
|
|
394
|
-
return createRect(getViewportRect(win, opts));
|
|
395
|
-
}
|
|
396
|
-
function getViewportRect(win, opts) {
|
|
397
|
-
const { excludeScrollbar = false } = opts;
|
|
398
|
-
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
399
|
-
const width = visualViewport?.width || innerWidth;
|
|
400
|
-
const height = visualViewport?.height || innerHeight;
|
|
401
|
-
const rect = { x: 0, y: 0, width, height };
|
|
402
|
-
if (excludeScrollbar) {
|
|
403
|
-
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
404
|
-
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
405
|
-
rect.width -= scrollbarWidth;
|
|
406
|
-
rect.height -= scrollbarHeight;
|
|
407
|
-
}
|
|
408
|
-
return rect;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// src/get-polygon.ts
|
|
412
|
-
function getElementPolygon(rectValue, placement) {
|
|
413
|
-
const rect = createRect(rectValue);
|
|
414
|
-
const { top, right, left, bottom } = getRectCorners(rect);
|
|
415
|
-
const [base] = placement.split("-");
|
|
416
|
-
return {
|
|
417
|
-
top: [left, top, right, bottom],
|
|
418
|
-
right: [top, right, bottom, left],
|
|
419
|
-
bottom: [top, left, bottom, right],
|
|
420
|
-
left: [right, top, left, bottom]
|
|
421
|
-
}[base];
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// src/operations.ts
|
|
425
|
-
var isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
426
|
-
function inset(r, i) {
|
|
427
|
-
const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
|
|
428
|
-
const { top = 0, right = 0, bottom = 0, left = 0 } = v;
|
|
429
|
-
return createRect({
|
|
430
|
-
x: r.x + left,
|
|
431
|
-
y: r.y + top,
|
|
432
|
-
width: r.width - left - right,
|
|
433
|
-
height: r.height - top - bottom
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
function expand(r, v) {
|
|
437
|
-
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
438
|
-
return inset(r, value);
|
|
439
|
-
}
|
|
440
|
-
function shrink(r, v) {
|
|
441
|
-
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
442
|
-
return inset(r, value);
|
|
443
|
-
}
|
|
444
|
-
function shift(r, o) {
|
|
445
|
-
const { x = 0, y = 0 } = o;
|
|
446
|
-
return createRect({
|
|
447
|
-
x: r.x + x,
|
|
448
|
-
y: r.y + y,
|
|
449
|
-
width: r.width,
|
|
450
|
-
height: r.height
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// src/polygon.ts
|
|
455
|
-
function isPointInPolygon(polygon, point2) {
|
|
456
|
-
const { x, y } = point2;
|
|
457
|
-
let c = false;
|
|
458
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
459
|
-
const xi = polygon[i].x;
|
|
460
|
-
const yi = polygon[i].y;
|
|
461
|
-
const xj = polygon[j].x;
|
|
462
|
-
const yj = polygon[j].y;
|
|
463
|
-
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
464
|
-
c = !c;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return c;
|
|
468
|
-
}
|
|
469
|
-
function createPolygonElement() {
|
|
470
|
-
const id = "debug-polygon";
|
|
471
|
-
const existingPolygon = document.getElementById(id);
|
|
472
|
-
if (existingPolygon) {
|
|
473
|
-
return existingPolygon;
|
|
474
|
-
}
|
|
475
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
476
|
-
Object.assign(svg.style, {
|
|
477
|
-
top: "0",
|
|
478
|
-
left: "0",
|
|
479
|
-
width: "100%",
|
|
480
|
-
height: "100%",
|
|
481
|
-
opacity: "0.15",
|
|
482
|
-
position: "fixed",
|
|
483
|
-
pointerEvents: "none",
|
|
484
|
-
fill: "red"
|
|
485
|
-
});
|
|
486
|
-
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
487
|
-
polygon.setAttribute("id", id);
|
|
488
|
-
polygon.setAttribute("points", "0,0 0,0");
|
|
489
|
-
svg.appendChild(polygon);
|
|
490
|
-
document.body.appendChild(svg);
|
|
491
|
-
return polygon;
|
|
492
|
-
}
|
|
493
|
-
function debugPolygon(polygon) {
|
|
494
|
-
const el = createPolygonElement();
|
|
495
|
-
const points = polygon.map((point2) => `${point2.x},${point2.y}`).join(" ");
|
|
496
|
-
el.setAttribute("points", points);
|
|
497
|
-
return () => {
|
|
498
|
-
el.remove();
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
502
|
-
0 && (module.exports = {
|
|
503
|
-
alignRect,
|
|
504
|
-
closest,
|
|
505
|
-
closestSideToPoint,
|
|
506
|
-
closestSideToRect,
|
|
507
|
-
collisions,
|
|
508
|
-
contains,
|
|
509
|
-
containsPoint,
|
|
510
|
-
containsRect,
|
|
511
|
-
createRect,
|
|
512
|
-
debugPolygon,
|
|
513
|
-
distance,
|
|
514
|
-
distanceBtwEdges,
|
|
515
|
-
distanceFromPoint,
|
|
516
|
-
distanceFromRect,
|
|
517
|
-
expand,
|
|
518
|
-
fromRange,
|
|
519
|
-
getElementPolygon,
|
|
520
|
-
getElementRect,
|
|
521
|
-
getRectCenters,
|
|
522
|
-
getRectCorners,
|
|
523
|
-
getRectEdges,
|
|
524
|
-
getRectFromPoints,
|
|
525
|
-
getRotationRect,
|
|
526
|
-
getViewportRect,
|
|
527
|
-
getWindowRect,
|
|
528
|
-
inset,
|
|
529
|
-
intersection,
|
|
530
|
-
intersects,
|
|
531
|
-
isPointInPolygon,
|
|
532
|
-
isRect,
|
|
533
|
-
isSymmetric,
|
|
534
|
-
rotate,
|
|
535
|
-
shift,
|
|
536
|
-
shrink,
|
|
537
|
-
toRad,
|
|
538
|
-
union
|
|
539
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const align = require('./align.js');
|
|
6
|
+
const closest = require('./closest.js');
|
|
7
|
+
const contains = require('./contains.js');
|
|
8
|
+
const distance = require('./distance.js');
|
|
9
|
+
const fromElement = require('./from-element.js');
|
|
10
|
+
const fromPoints = require('./from-points.js');
|
|
11
|
+
const fromRange = require('./from-range.js');
|
|
12
|
+
const fromRotation = require('./from-rotation.js');
|
|
13
|
+
const fromWindow = require('./from-window.js');
|
|
14
|
+
const getPolygon = require('./get-polygon.js');
|
|
15
|
+
const intersection = require('./intersection.js');
|
|
16
|
+
const operations = require('./operations.js');
|
|
17
|
+
const polygon = require('./polygon.js');
|
|
18
|
+
const rect = require('./rect.js');
|
|
19
|
+
const union = require('./union.js');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
exports.alignRect = align.alignRect;
|
|
24
|
+
exports.closest = closest.closest;
|
|
25
|
+
exports.closestSideToPoint = closest.closestSideToPoint;
|
|
26
|
+
exports.closestSideToRect = closest.closestSideToRect;
|
|
27
|
+
exports.contains = contains.contains;
|
|
28
|
+
exports.containsPoint = contains.containsPoint;
|
|
29
|
+
exports.containsRect = contains.containsRect;
|
|
30
|
+
exports.distance = distance.distance;
|
|
31
|
+
exports.distanceBtwEdges = distance.distanceBtwEdges;
|
|
32
|
+
exports.distanceFromPoint = distance.distanceFromPoint;
|
|
33
|
+
exports.distanceFromRect = distance.distanceFromRect;
|
|
34
|
+
exports.getElementRect = fromElement.getElementRect;
|
|
35
|
+
exports.getRectFromPoints = fromPoints.getRectFromPoints;
|
|
36
|
+
exports.fromRange = fromRange.fromRange;
|
|
37
|
+
exports.getRotationRect = fromRotation.getRotationRect;
|
|
38
|
+
exports.rotate = fromRotation.rotate;
|
|
39
|
+
exports.toRad = fromRotation.toRad;
|
|
40
|
+
exports.getViewportRect = fromWindow.getViewportRect;
|
|
41
|
+
exports.getWindowRect = fromWindow.getWindowRect;
|
|
42
|
+
exports.getElementPolygon = getPolygon.getElementPolygon;
|
|
43
|
+
exports.collisions = intersection.collisions;
|
|
44
|
+
exports.intersection = intersection.intersection;
|
|
45
|
+
exports.intersects = intersection.intersects;
|
|
46
|
+
exports.expand = operations.expand;
|
|
47
|
+
exports.inset = operations.inset;
|
|
48
|
+
exports.isSymmetric = operations.isSymmetric;
|
|
49
|
+
exports.shift = operations.shift;
|
|
50
|
+
exports.shrink = operations.shrink;
|
|
51
|
+
exports.debugPolygon = polygon.debugPolygon;
|
|
52
|
+
exports.isPointInPolygon = polygon.isPointInPolygon;
|
|
53
|
+
exports.createRect = rect.createRect;
|
|
54
|
+
exports.getRectCenters = rect.getRectCenters;
|
|
55
|
+
exports.getRectCorners = rect.getRectCorners;
|
|
56
|
+
exports.getRectEdges = rect.getRectEdges;
|
|
57
|
+
exports.isRect = rect.isRect;
|
|
58
|
+
exports.union = union.union;
|