@zag-js/rect-utils 0.1.8 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/align.d.ts +12 -0
  2. package/dist/align.js +71 -0
  3. package/dist/align.mjs +6 -0
  4. package/dist/chunk-2QYJISFU.mjs +21 -0
  5. package/dist/chunk-AYR2YRSU.mjs +49 -0
  6. package/dist/chunk-BGAHRJ6S.mjs +41 -0
  7. package/dist/chunk-BPWQOPHU.mjs +32 -0
  8. package/dist/chunk-C2OCKGLJ.mjs +27 -0
  9. package/dist/chunk-DBR73IMM.mjs +54 -0
  10. package/dist/chunk-IFHTGH3H.mjs +29 -0
  11. package/dist/chunk-LCJDCPGN.mjs +56 -0
  12. package/dist/chunk-NGMCS5TG.mjs +33 -0
  13. package/dist/chunk-QXXKPYP2.mjs +47 -0
  14. package/dist/chunk-R24UTBJ3.mjs +52 -0
  15. package/dist/chunk-S3HXSPS7.mjs +21 -0
  16. package/dist/chunk-T4IEPEZY.mjs +41 -0
  17. package/dist/chunk-TPU7B3ZS.mjs +18 -0
  18. package/dist/chunk-WBQAMGXK.mjs +0 -0
  19. package/dist/chunk-YDYJCJQZ.mjs +56 -0
  20. package/dist/closest.d.ts +8 -0
  21. package/dist/closest.js +83 -0
  22. package/dist/closest.mjs +13 -0
  23. package/dist/contains.d.ts +8 -0
  24. package/dist/contains.js +60 -0
  25. package/dist/contains.mjs +11 -0
  26. package/dist/distance.d.ts +12 -0
  27. package/dist/distance.js +79 -0
  28. package/dist/distance.mjs +14 -0
  29. package/dist/from-element.d.ts +16 -0
  30. package/dist/from-element.js +99 -0
  31. package/dist/from-element.mjs +7 -0
  32. package/dist/from-points.d.ts +6 -0
  33. package/dist/from-points.js +61 -0
  34. package/dist/from-points.mjs +7 -0
  35. package/dist/from-range.d.ts +6 -0
  36. package/dist/from-range.js +155 -0
  37. package/dist/from-range.mjs +10 -0
  38. package/dist/from-rotation.d.ts +8 -0
  39. package/dist/from-rotation.js +92 -0
  40. package/dist/from-rotation.mjs +11 -0
  41. package/dist/from-window.d.ts +24 -0
  42. package/dist/from-window.js +71 -0
  43. package/dist/from-window.mjs +9 -0
  44. package/dist/get-polygon.d.ts +8 -0
  45. package/dist/get-polygon.js +70 -0
  46. package/dist/get-polygon.mjs +7 -0
  47. package/dist/index.d.ts +16 -186
  48. package/dist/index.js +9 -8
  49. package/dist/index.mjs +67 -452
  50. package/dist/intersection.d.ts +17 -0
  51. package/dist/intersection.js +74 -0
  52. package/dist/intersection.mjs +11 -0
  53. package/dist/operations.d.ts +10 -0
  54. package/dist/operations.js +88 -0
  55. package/dist/operations.mjs +15 -0
  56. package/dist/polygon.d.ts +6 -0
  57. package/dist/polygon.js +77 -0
  58. package/dist/polygon.mjs +8 -0
  59. package/dist/rect.d.ts +64 -0
  60. package/dist/rect.js +86 -0
  61. package/dist/rect.mjs +14 -0
  62. package/dist/types.d.ts +32 -0
  63. package/dist/types.js +18 -0
  64. package/dist/types.mjs +1 -0
  65. package/dist/union.d.ts +6 -0
  66. package/dist/union.js +87 -0
  67. package/dist/union.mjs +8 -0
  68. package/package.json +18 -8
package/dist/index.mjs CHANGED
@@ -1,455 +1,70 @@
1
- // src/align.ts
2
- function hAlign(a, ref, h) {
3
- let x = ref.minX;
4
- if (h === "left-inside") {
5
- x = ref.minX;
6
- }
7
- if (h === "left-outside") {
8
- x = ref.minX - ref.width;
9
- }
10
- if (h === "right-inside") {
11
- x = ref.maxX - ref.width;
12
- }
13
- if (h === "right-outside") {
14
- x = ref.maxX;
15
- }
16
- if (h === "center") {
17
- x = ref.midX - ref.width / 2;
18
- }
19
- return { ...a, x };
20
- }
21
- function vAlign(a, ref, v) {
22
- let y = ref.minY;
23
- if (v === "top-inside") {
24
- y = ref.minY;
25
- }
26
- if (v === "top-outside") {
27
- y = ref.minY - a.height;
28
- }
29
- if (v === "bottom-inside") {
30
- y = ref.maxY - a.height;
31
- }
32
- if (v === "bottom-outside") {
33
- y = ref.maxY;
34
- }
35
- if (v === "center") {
36
- y = ref.midY - a.height / 2;
37
- }
38
- return { ...a, y };
39
- }
40
- function alignRect(a, ref, options) {
41
- const { h, v } = options;
42
- return vAlign(hAlign(a, ref, h), ref, v);
43
- }
44
-
45
- // ../core/dist/index.mjs
46
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
47
-
48
- // src/rect.ts
49
- var point = (x, y) => ({ x, y });
50
- function createRect(r) {
51
- const { x, y, width, height } = r;
52
- const midX = x + width / 2;
53
- const midY = y + height / 2;
54
- return {
55
- x,
56
- y,
57
- width,
58
- height,
59
- minX: x,
60
- minY: y,
61
- maxX: x + width,
62
- maxY: y + height,
63
- midX,
64
- midY,
65
- center: point(midX, midY)
66
- };
67
- }
68
- function isRect(v) {
69
- return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
70
- }
71
- function getRectCenters(v) {
72
- const top = point(v.midX, v.minY);
73
- const right = point(v.maxX, v.midY);
74
- const bottom = point(v.midX, v.maxY);
75
- const left = point(v.minX, v.midY);
76
- return { top, right, bottom, left };
77
- }
78
- function getRectCorners(v) {
79
- const top = point(v.minX, v.minY);
80
- const right = point(v.maxX, v.minY);
81
- const bottom = point(v.maxX, v.maxY);
82
- const left = point(v.minX, v.maxY);
83
- return { top, right, bottom, left };
84
- }
85
- function getRectEdges(v) {
86
- const c = getRectCorners(v);
87
- const top = [c.top, c.right];
88
- const right = [c.right, c.bottom];
89
- const bottom = [c.left, c.bottom];
90
- const left = [c.top, c.left];
91
- return { top, right, bottom, left };
92
- }
93
-
94
- // src/intersection.ts
95
- function intersects(a, b) {
96
- return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
97
- }
98
- function intersection(a, b) {
99
- const x = Math.max(a.x, b.x);
100
- const y = Math.max(a.y, b.y);
101
- const x2 = Math.min(a.x + a.width, b.x + b.width);
102
- const y2 = Math.min(a.y + a.height, b.y + b.height);
103
- return createRect({ x, y, width: x2 - x, height: y2 - y });
104
- }
105
- function collisions(a, b) {
106
- return {
107
- top: a.minY <= b.minY,
108
- right: a.maxX >= b.maxX,
109
- bottom: a.maxY >= b.maxY,
110
- left: a.minX <= b.minX
111
- };
112
- }
113
-
114
- // src/distance.ts
115
- function distance(a, b = { x: 0, y: 0 }) {
116
- return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
117
- }
118
- function distanceFromPoint(r, p) {
119
- let x = 0;
120
- let y = 0;
121
- if (p.x < r.x)
122
- x = r.x - p.x;
123
- else if (p.x > r.maxX)
124
- x = p.x - r.maxX;
125
- if (p.y < r.y)
126
- y = r.y - p.y;
127
- else if (p.y > r.maxY)
128
- y = p.y - r.maxY;
129
- return { x, y, value: distance({ x, y }) };
130
- }
131
- function distanceFromRect(a, b) {
132
- if (intersects(a, b))
133
- return { x: 0, y: 0, value: 0 };
134
- const left = a.x < b.x ? a : b;
135
- const right = b.x < a.x ? a : b;
136
- const upper = a.y < b.y ? a : b;
137
- const lower = b.y < a.y ? a : b;
138
- let x = left.x === right.x ? 0 : right.x - left.maxX;
139
- x = Math.max(0, x);
140
- let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
141
- y = Math.max(0, y);
142
- return { x, y, value: distance({ x, y }) };
143
- }
144
- function distanceBtwEdges(a, b) {
145
- return {
146
- left: b.x - a.x,
147
- top: b.y - a.y,
148
- right: a.maxX - b.maxX,
149
- bottom: a.maxY - b.maxY
150
- };
151
- }
152
-
153
- // src/closest.ts
154
- function closest(...pts) {
155
- return (a) => {
156
- const ds = pts.map((b) => distance(b, a));
157
- const c = Math.min.apply(Math, ds);
158
- return pts[ds.indexOf(c)];
159
- };
160
- }
161
- function closestSideToRect(ref, r) {
162
- if (r.maxX <= ref.minX) {
163
- return "left";
164
- }
165
- if (r.minX >= ref.maxX) {
166
- return "right";
167
- }
168
- if (r.maxY <= ref.minY) {
169
- return "top";
170
- }
171
- if (r.minY >= ref.maxY) {
172
- return "bottom";
173
- }
174
- return "left";
175
- }
176
- function closestSideToPoint(ref, p) {
177
- const { x, y } = p;
178
- const dl = x - ref.minX;
179
- const dr = ref.maxX - x;
180
- const dt = y - ref.minY;
181
- const db = ref.maxY - y;
182
- let closest2 = dl;
183
- let side = "left";
184
- if (dr < closest2) {
185
- closest2 = dr;
186
- side = "right";
187
- }
188
- if (dt < closest2) {
189
- closest2 = dt;
190
- side = "top";
191
- }
192
- if (db < closest2) {
193
- side = "bottom";
194
- }
195
- return side;
196
- }
197
-
198
- // src/contains.ts
199
- function containsPoint(r, p) {
200
- return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
201
- }
202
- function containsRect(a, b) {
203
- return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
204
- }
205
- function contains(r, v) {
206
- return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
207
- }
208
-
209
- // ../dom/dist/index.mjs
210
- function getCache() {
211
- const g = globalThis;
212
- g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
213
- return g.__styleCache;
214
- }
215
- function getComputedStyle(el) {
216
- if (!el)
217
- return {};
218
- const cache = getCache();
219
- let style = cache.get(el);
220
- if (!style) {
221
- const win = (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
222
- style = win.getComputedStyle(el);
223
- cache.set(el, style);
224
- }
225
- return style;
226
- }
227
-
228
- // src/from-element.ts
229
- function getElementRect(el, opts = {}) {
230
- return createRect(getClientRect(el, opts));
231
- }
232
- function getClientRect(el, opts = {}) {
233
- const { excludeScrollbar = false, excludeBorders = false } = opts;
234
- const { x, y, width, height } = el.getBoundingClientRect();
235
- const r = { x, y, width, height };
236
- const style = getComputedStyle(el);
237
- const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
238
- const borderXWidth = sum(borderLeftWidth, borderRightWidth);
239
- const borderYWidth = sum(borderTopWidth, borderBottomWidth);
240
- if (excludeBorders) {
241
- r.width -= borderXWidth;
242
- r.height -= borderYWidth;
243
- r.x += px(borderLeftWidth);
244
- r.y += px(borderTopWidth);
245
- }
246
- if (excludeScrollbar) {
247
- const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
248
- const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
249
- r.width -= scrollbarWidth;
250
- r.height -= scrollbarHeight;
251
- }
252
- return r;
253
- }
254
- var px = (v) => parseFloat(v.replace("px", ""));
255
- var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
256
-
257
- // src/from-points.ts
258
- function getRectFromPoints(...pts) {
259
- const xs = pts.map((p) => p.x);
260
- const ys = pts.map((p) => p.y);
261
- const x = Math.min(...xs);
262
- const y = Math.min(...ys);
263
- const width = Math.max(...xs) - x;
264
- const height = Math.max(...ys) - y;
265
- return createRect({ x, y, width, height });
266
- }
267
-
268
- // src/union.ts
269
- var { min, max } = Math;
270
- function union(...rs) {
271
- const pMin = {
272
- x: min.apply(
273
- Math,
274
- rs.map((r) => r.minX)
275
- ),
276
- y: min.apply(
277
- Math,
278
- rs.map((r) => r.minY)
279
- )
280
- };
281
- const pMax = {
282
- x: max.apply(
283
- Math,
284
- rs.map((r) => r.maxX)
285
- ),
286
- y: max.apply(
287
- Math,
288
- rs.map((r) => r.maxY)
289
- )
290
- };
291
- return getRectFromPoints(pMin, pMax);
292
- }
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(createRect));
300
- return union.apply(void 0, rs);
301
- }
302
- let start = range.startContainer;
303
- if (start.nodeType === Node.TEXT_NODE) {
304
- start = start.parentNode;
305
- }
306
- if (start instanceof HTMLElement) {
307
- const r = getElementRect(start);
308
- rs.push({ ...r, x: r.maxX, width: 0 });
309
- }
310
- return union.apply(void 0, rs);
311
- }
312
-
313
- // src/from-rotation.ts
314
- function toRad(d) {
315
- return d % 360 * Math.PI / 180;
316
- }
317
- function rotate(a, d, c) {
318
- const r = toRad(d);
319
- const sin = Math.sin(r);
320
- const cos = Math.cos(r);
321
- const x = a.x - c.x;
322
- const y = a.y - c.y;
323
- return {
324
- x: c.x + x * cos - y * sin,
325
- y: c.y + x * sin + y * cos
326
- };
327
- }
328
- function getRotationRect(r, deg) {
329
- const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
330
- const xs = rr.map((p) => p.x);
331
- const ys = rr.map((p) => p.y);
332
- const minX = Math.min(...xs);
333
- const minY = Math.min(...ys);
334
- const maxX = Math.max(...xs);
335
- const maxY = Math.max(...ys);
336
- return createRect({
337
- x: minX,
338
- y: minY,
339
- width: maxX - minX,
340
- height: maxY - minY
341
- });
342
- }
343
-
344
- // src/from-window.ts
345
- function getWindowRect(win, opts = {}) {
346
- return createRect(getViewportRect(win, opts));
347
- }
348
- function getViewportRect(win, opts) {
349
- const { excludeScrollbar = false } = opts;
350
- const { innerWidth: innerWidth2, innerHeight: innerHeight2, document: doc, visualViewport } = win;
351
- const width = (visualViewport == null ? void 0 : visualViewport.width) || innerWidth2;
352
- const height = (visualViewport == null ? void 0 : visualViewport.height) || innerHeight2;
353
- const rect = { x: 0, y: 0, width, height };
354
- if (excludeScrollbar) {
355
- const scrollbarWidth = innerWidth2 - doc.documentElement.clientWidth;
356
- const scrollbarHeight = innerHeight2 - doc.documentElement.clientHeight;
357
- rect.width -= scrollbarWidth;
358
- rect.height -= scrollbarHeight;
359
- }
360
- return rect;
361
- }
362
-
363
- // src/get-polygon.ts
364
- function getElementPolygon(rectValue, placement) {
365
- const rect = createRect(rectValue);
366
- const { top, right, left, bottom } = getRectCorners(rect);
367
- const [base] = placement.split("-");
368
- return {
369
- top: [left, top, right, bottom],
370
- right: [top, right, bottom, left],
371
- bottom: [top, left, bottom, right],
372
- left: [right, top, left, bottom]
373
- }[base];
374
- }
375
-
376
- // src/operations.ts
377
- var isSymmetric = (v) => "dx" in v || "dy" in v;
378
- function inset(r, i) {
379
- const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
380
- const { top = 0, right = 0, bottom = 0, left = 0 } = v;
381
- return createRect({
382
- x: r.x + left,
383
- y: r.y + top,
384
- width: r.width - left - right,
385
- height: r.height - top - bottom
386
- });
387
- }
388
- function expand(r, v) {
389
- const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
390
- return inset(r, value);
391
- }
392
- function shrink(r, v) {
393
- const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
394
- return inset(r, value);
395
- }
396
- function shift(r, o) {
397
- const { x = 0, y = 0 } = o;
398
- return createRect({
399
- x: r.x + x,
400
- y: r.y + y,
401
- width: r.width,
402
- height: r.height
403
- });
404
- }
405
-
406
- // src/polygon.ts
407
- function isPointInPolygon(polygon, point2) {
408
- const { x, y } = point2;
409
- let c = false;
410
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
411
- const xi = polygon[i].x;
412
- const yi = polygon[i].y;
413
- const xj = polygon[j].x;
414
- const yj = polygon[j].y;
415
- if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
416
- c = !c;
417
- }
418
- }
419
- return c;
420
- }
421
- function createPolygonElement() {
422
- const id = "debug-polygon";
423
- const existingPolygon = document.getElementById(id);
424
- if (existingPolygon) {
425
- return existingPolygon;
426
- }
427
- const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
428
- Object.assign(svg.style, {
429
- top: "0",
430
- left: "0",
431
- width: "100%",
432
- height: "100%",
433
- opacity: "0.15",
434
- position: "fixed",
435
- pointerEvents: "none",
436
- fill: "red"
437
- });
438
- const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
439
- polygon.setAttribute("id", id);
440
- polygon.setAttribute("points", "0,0 0,0");
441
- svg.appendChild(polygon);
442
- document.body.appendChild(svg);
443
- return polygon;
444
- }
445
- function debugPolygon(polygon) {
446
- const el = createPolygonElement();
447
- const points = polygon.map((point2) => `${point2.x},${point2.y}`).join(" ");
448
- el.setAttribute("points", points);
449
- return () => {
450
- el.remove();
451
- };
452
- }
1
+ import {
2
+ getViewportRect,
3
+ getWindowRect
4
+ } from "./chunk-C2OCKGLJ.mjs";
5
+ import {
6
+ getElementPolygon
7
+ } from "./chunk-S3HXSPS7.mjs";
8
+ import {
9
+ expand,
10
+ inset,
11
+ isSymmetric,
12
+ shift,
13
+ shrink
14
+ } from "./chunk-T4IEPEZY.mjs";
15
+ import {
16
+ debugPolygon,
17
+ isPointInPolygon
18
+ } from "./chunk-R24UTBJ3.mjs";
19
+ import "./chunk-WBQAMGXK.mjs";
20
+ import {
21
+ alignRect
22
+ } from "./chunk-QXXKPYP2.mjs";
23
+ import {
24
+ closest,
25
+ closestSideToPoint,
26
+ closestSideToRect
27
+ } from "./chunk-DBR73IMM.mjs";
28
+ import {
29
+ contains,
30
+ containsPoint,
31
+ containsRect
32
+ } from "./chunk-2QYJISFU.mjs";
33
+ import {
34
+ distance,
35
+ distanceBtwEdges,
36
+ distanceFromPoint,
37
+ distanceFromRect
38
+ } from "./chunk-AYR2YRSU.mjs";
39
+ import {
40
+ collisions,
41
+ intersection,
42
+ intersects
43
+ } from "./chunk-IFHTGH3H.mjs";
44
+ import {
45
+ fromRange
46
+ } from "./chunk-BPWQOPHU.mjs";
47
+ import {
48
+ union
49
+ } from "./chunk-NGMCS5TG.mjs";
50
+ import {
51
+ getElementRect
52
+ } from "./chunk-LCJDCPGN.mjs";
53
+ import {
54
+ getRectFromPoints
55
+ } from "./chunk-TPU7B3ZS.mjs";
56
+ import {
57
+ getRotationRect,
58
+ rotate,
59
+ toRad
60
+ } from "./chunk-BGAHRJ6S.mjs";
61
+ import {
62
+ createRect,
63
+ getRectCenters,
64
+ getRectCorners,
65
+ getRectEdges,
66
+ isRect
67
+ } from "./chunk-YDYJCJQZ.mjs";
453
68
  export {
454
69
  alignRect,
455
70
  closest,
@@ -0,0 +1,17 @@
1
+ import { Rect } from './rect.js';
2
+ import { RectSide } from './types.js';
3
+
4
+ /**
5
+ * Checks if a Rect intersects another Rect
6
+ */
7
+ declare function intersects(a: Rect, b: Rect): boolean;
8
+ /**
9
+ * Returns a new Rect that represents the intersection between two Rects
10
+ */
11
+ declare function intersection(a: Rect, b: Rect): Rect;
12
+ /**
13
+ * Returns whether two rects collide along each edge
14
+ */
15
+ declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
16
+
17
+ export { collisions, intersection, intersects };
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/intersection.ts
21
+ var intersection_exports = {};
22
+ __export(intersection_exports, {
23
+ collisions: () => collisions,
24
+ intersection: () => intersection,
25
+ intersects: () => intersects
26
+ });
27
+ module.exports = __toCommonJS(intersection_exports);
28
+
29
+ // src/rect.ts
30
+ var point = (x, y) => ({ x, y });
31
+ function createRect(r) {
32
+ const { x, y, width, height } = r;
33
+ const midX = x + width / 2;
34
+ const midY = y + height / 2;
35
+ return {
36
+ x,
37
+ y,
38
+ width,
39
+ height,
40
+ minX: x,
41
+ minY: y,
42
+ maxX: x + width,
43
+ maxY: y + height,
44
+ midX,
45
+ midY,
46
+ center: point(midX, midY)
47
+ };
48
+ }
49
+
50
+ // src/intersection.ts
51
+ function intersects(a, b) {
52
+ return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
53
+ }
54
+ function intersection(a, b) {
55
+ const x = Math.max(a.x, b.x);
56
+ const y = Math.max(a.y, b.y);
57
+ const x2 = Math.min(a.x + a.width, b.x + b.width);
58
+ const y2 = Math.min(a.y + a.height, b.y + b.height);
59
+ return createRect({ x, y, width: x2 - x, height: y2 - y });
60
+ }
61
+ function collisions(a, b) {
62
+ return {
63
+ top: a.minY <= b.minY,
64
+ right: a.maxX >= b.maxX,
65
+ bottom: a.maxY >= b.maxY,
66
+ left: a.minX <= b.minX
67
+ };
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ collisions,
72
+ intersection,
73
+ intersects
74
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ collisions,
3
+ intersection,
4
+ intersects
5
+ } from "./chunk-IFHTGH3H.mjs";
6
+ import "./chunk-YDYJCJQZ.mjs";
7
+ export {
8
+ collisions,
9
+ intersection,
10
+ intersects
11
+ };
@@ -0,0 +1,10 @@
1
+ import { Rect } from './rect.js';
2
+ import { SymmetricRectInset, RectInset, Point } from './types.js';
3
+
4
+ declare const isSymmetric: (v: any) => v is SymmetricRectInset;
5
+ declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
6
+ declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
7
+ declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
8
+ declare function shift(r: Rect, o: Partial<Point>): Rect;
9
+
10
+ export { expand, inset, isSymmetric, shift, shrink };