@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.
- package/dist/align.d.ts +12 -0
- package/dist/align.js +71 -0
- package/dist/align.mjs +6 -0
- package/dist/chunk-2QYJISFU.mjs +21 -0
- package/dist/chunk-AYR2YRSU.mjs +49 -0
- package/dist/chunk-BGAHRJ6S.mjs +41 -0
- package/dist/chunk-BPWQOPHU.mjs +32 -0
- package/dist/chunk-C2OCKGLJ.mjs +27 -0
- package/dist/chunk-DBR73IMM.mjs +54 -0
- package/dist/chunk-IFHTGH3H.mjs +29 -0
- package/dist/chunk-LCJDCPGN.mjs +56 -0
- package/dist/chunk-NGMCS5TG.mjs +33 -0
- package/dist/chunk-QXXKPYP2.mjs +47 -0
- package/dist/chunk-R24UTBJ3.mjs +52 -0
- package/dist/chunk-S3HXSPS7.mjs +21 -0
- package/dist/chunk-T4IEPEZY.mjs +41 -0
- package/dist/chunk-TPU7B3ZS.mjs +18 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-YDYJCJQZ.mjs +56 -0
- package/dist/closest.d.ts +8 -0
- package/dist/closest.js +83 -0
- package/dist/closest.mjs +13 -0
- package/dist/contains.d.ts +8 -0
- package/dist/contains.js +60 -0
- package/dist/contains.mjs +11 -0
- package/dist/distance.d.ts +12 -0
- package/dist/distance.js +79 -0
- package/dist/distance.mjs +14 -0
- package/dist/from-element.d.ts +16 -0
- package/dist/from-element.js +99 -0
- package/dist/from-element.mjs +7 -0
- package/dist/from-points.d.ts +6 -0
- package/dist/from-points.js +61 -0
- package/dist/from-points.mjs +7 -0
- package/dist/from-range.d.ts +6 -0
- package/dist/from-range.js +155 -0
- package/dist/from-range.mjs +10 -0
- package/dist/from-rotation.d.ts +8 -0
- package/dist/from-rotation.js +92 -0
- package/dist/from-rotation.mjs +11 -0
- package/dist/from-window.d.ts +24 -0
- package/dist/from-window.js +71 -0
- package/dist/from-window.mjs +9 -0
- package/dist/get-polygon.d.ts +8 -0
- package/dist/get-polygon.js +70 -0
- package/dist/get-polygon.mjs +7 -0
- package/dist/index.d.ts +16 -186
- package/dist/index.js +9 -8
- package/dist/index.mjs +67 -452
- package/dist/intersection.d.ts +17 -0
- package/dist/intersection.js +74 -0
- package/dist/intersection.mjs +11 -0
- package/dist/operations.d.ts +10 -0
- package/dist/operations.js +88 -0
- package/dist/operations.mjs +15 -0
- package/dist/polygon.d.ts +6 -0
- package/dist/polygon.js +77 -0
- package/dist/polygon.mjs +8 -0
- package/dist/rect.d.ts +64 -0
- package/dist/rect.js +86 -0
- package/dist/rect.mjs +14 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/union.d.ts +6 -0
- package/dist/union.js +87 -0
- package/dist/union.mjs +8 -0
- package/package.json +18 -8
|
@@ -0,0 +1,88 @@
|
|
|
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/operations.ts
|
|
21
|
+
var operations_exports = {};
|
|
22
|
+
__export(operations_exports, {
|
|
23
|
+
expand: () => expand,
|
|
24
|
+
inset: () => inset,
|
|
25
|
+
isSymmetric: () => isSymmetric,
|
|
26
|
+
shift: () => shift,
|
|
27
|
+
shrink: () => shrink
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(operations_exports);
|
|
30
|
+
|
|
31
|
+
// src/rect.ts
|
|
32
|
+
var point = (x, y) => ({ x, y });
|
|
33
|
+
function createRect(r) {
|
|
34
|
+
const { x, y, width, height } = r;
|
|
35
|
+
const midX = x + width / 2;
|
|
36
|
+
const midY = y + height / 2;
|
|
37
|
+
return {
|
|
38
|
+
x,
|
|
39
|
+
y,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
minX: x,
|
|
43
|
+
minY: y,
|
|
44
|
+
maxX: x + width,
|
|
45
|
+
maxY: y + height,
|
|
46
|
+
midX,
|
|
47
|
+
midY,
|
|
48
|
+
center: point(midX, midY)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/operations.ts
|
|
53
|
+
var isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
54
|
+
function inset(r, i) {
|
|
55
|
+
const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
|
|
56
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = v;
|
|
57
|
+
return createRect({
|
|
58
|
+
x: r.x + left,
|
|
59
|
+
y: r.y + top,
|
|
60
|
+
width: r.width - left - right,
|
|
61
|
+
height: r.height - top - bottom
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function expand(r, v) {
|
|
65
|
+
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
66
|
+
return inset(r, value);
|
|
67
|
+
}
|
|
68
|
+
function shrink(r, v) {
|
|
69
|
+
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
70
|
+
return inset(r, value);
|
|
71
|
+
}
|
|
72
|
+
function shift(r, o) {
|
|
73
|
+
const { x = 0, y = 0 } = o;
|
|
74
|
+
return createRect({
|
|
75
|
+
x: r.x + x,
|
|
76
|
+
y: r.y + y,
|
|
77
|
+
width: r.width,
|
|
78
|
+
height: r.height
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
expand,
|
|
84
|
+
inset,
|
|
85
|
+
isSymmetric,
|
|
86
|
+
shift,
|
|
87
|
+
shrink
|
|
88
|
+
});
|
package/dist/polygon.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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/polygon.ts
|
|
21
|
+
var polygon_exports = {};
|
|
22
|
+
__export(polygon_exports, {
|
|
23
|
+
debugPolygon: () => debugPolygon,
|
|
24
|
+
isPointInPolygon: () => isPointInPolygon
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(polygon_exports);
|
|
27
|
+
function isPointInPolygon(polygon, point) {
|
|
28
|
+
const { x, y } = point;
|
|
29
|
+
let c = false;
|
|
30
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
31
|
+
const xi = polygon[i].x;
|
|
32
|
+
const yi = polygon[i].y;
|
|
33
|
+
const xj = polygon[j].x;
|
|
34
|
+
const yj = polygon[j].y;
|
|
35
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
36
|
+
c = !c;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return c;
|
|
40
|
+
}
|
|
41
|
+
function createPolygonElement() {
|
|
42
|
+
const id = "debug-polygon";
|
|
43
|
+
const existingPolygon = document.getElementById(id);
|
|
44
|
+
if (existingPolygon) {
|
|
45
|
+
return existingPolygon;
|
|
46
|
+
}
|
|
47
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
48
|
+
Object.assign(svg.style, {
|
|
49
|
+
top: "0",
|
|
50
|
+
left: "0",
|
|
51
|
+
width: "100%",
|
|
52
|
+
height: "100%",
|
|
53
|
+
opacity: "0.15",
|
|
54
|
+
position: "fixed",
|
|
55
|
+
pointerEvents: "none",
|
|
56
|
+
fill: "red"
|
|
57
|
+
});
|
|
58
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
59
|
+
polygon.setAttribute("id", id);
|
|
60
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
61
|
+
svg.appendChild(polygon);
|
|
62
|
+
document.body.appendChild(svg);
|
|
63
|
+
return polygon;
|
|
64
|
+
}
|
|
65
|
+
function debugPolygon(polygon) {
|
|
66
|
+
const el = createPolygonElement();
|
|
67
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
68
|
+
el.setAttribute("points", points);
|
|
69
|
+
return () => {
|
|
70
|
+
el.remove();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
debugPolygon,
|
|
76
|
+
isPointInPolygon
|
|
77
|
+
});
|
package/dist/polygon.mjs
ADDED
package/dist/rect.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { RectValue, RectEdge } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare function createRect(r: RectValue): {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
minX: number;
|
|
9
|
+
minY: number;
|
|
10
|
+
maxX: number;
|
|
11
|
+
maxY: number;
|
|
12
|
+
midX: number;
|
|
13
|
+
midY: number;
|
|
14
|
+
center: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type Rect = ReturnType<typeof createRect>;
|
|
20
|
+
declare function isRect(v: any): v is Rect;
|
|
21
|
+
declare function getRectCenters(v: Rect): {
|
|
22
|
+
top: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
};
|
|
26
|
+
right: {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
};
|
|
30
|
+
bottom: {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
};
|
|
34
|
+
left: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
declare function getRectCorners(v: Rect): {
|
|
40
|
+
top: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
};
|
|
44
|
+
right: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
};
|
|
48
|
+
bottom: {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
};
|
|
52
|
+
left: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
declare function getRectEdges(v: Rect): {
|
|
58
|
+
top: RectEdge;
|
|
59
|
+
right: RectEdge;
|
|
60
|
+
bottom: RectEdge;
|
|
61
|
+
left: RectEdge;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { Rect, createRect, getRectCenters, getRectCorners, getRectEdges, isRect };
|
package/dist/rect.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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/rect.ts
|
|
21
|
+
var rect_exports = {};
|
|
22
|
+
__export(rect_exports, {
|
|
23
|
+
createRect: () => createRect,
|
|
24
|
+
getRectCenters: () => getRectCenters,
|
|
25
|
+
getRectCorners: () => getRectCorners,
|
|
26
|
+
getRectEdges: () => getRectEdges,
|
|
27
|
+
isRect: () => isRect
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(rect_exports);
|
|
30
|
+
|
|
31
|
+
// ../core/src/guard.ts
|
|
32
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
33
|
+
|
|
34
|
+
// src/rect.ts
|
|
35
|
+
var point = (x, y) => ({ x, y });
|
|
36
|
+
function createRect(r) {
|
|
37
|
+
const { x, y, width, height } = r;
|
|
38
|
+
const midX = x + width / 2;
|
|
39
|
+
const midY = y + height / 2;
|
|
40
|
+
return {
|
|
41
|
+
x,
|
|
42
|
+
y,
|
|
43
|
+
width,
|
|
44
|
+
height,
|
|
45
|
+
minX: x,
|
|
46
|
+
minY: y,
|
|
47
|
+
maxX: x + width,
|
|
48
|
+
maxY: y + height,
|
|
49
|
+
midX,
|
|
50
|
+
midY,
|
|
51
|
+
center: point(midX, midY)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function isRect(v) {
|
|
55
|
+
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
56
|
+
}
|
|
57
|
+
function getRectCenters(v) {
|
|
58
|
+
const top = point(v.midX, v.minY);
|
|
59
|
+
const right = point(v.maxX, v.midY);
|
|
60
|
+
const bottom = point(v.midX, v.maxY);
|
|
61
|
+
const left = point(v.minX, v.midY);
|
|
62
|
+
return { top, right, bottom, left };
|
|
63
|
+
}
|
|
64
|
+
function getRectCorners(v) {
|
|
65
|
+
const top = point(v.minX, v.minY);
|
|
66
|
+
const right = point(v.maxX, v.minY);
|
|
67
|
+
const bottom = point(v.maxX, v.maxY);
|
|
68
|
+
const left = point(v.minX, v.maxY);
|
|
69
|
+
return { top, right, bottom, left };
|
|
70
|
+
}
|
|
71
|
+
function getRectEdges(v) {
|
|
72
|
+
const c = getRectCorners(v);
|
|
73
|
+
const top = [c.top, c.right];
|
|
74
|
+
const right = [c.right, c.bottom];
|
|
75
|
+
const bottom = [c.left, c.bottom];
|
|
76
|
+
const left = [c.top, c.left];
|
|
77
|
+
return { top, right, bottom, left };
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
createRect,
|
|
82
|
+
getRectCenters,
|
|
83
|
+
getRectCorners,
|
|
84
|
+
getRectEdges,
|
|
85
|
+
isRect
|
|
86
|
+
});
|
package/dist/rect.mjs
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
type RectValue = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
type RectSide = "top" | "right" | "bottom" | "left";
|
|
12
|
+
type RectPoint = "top-left" | "top-center" | "top-right" | "right-center" | "left-center" | "bottom-left" | "bottom-right" | "bottom-center" | "center";
|
|
13
|
+
type RectEdge = [Point, Point];
|
|
14
|
+
type RectPoints = [Point, Point, Point, Point];
|
|
15
|
+
type RectEdges = Record<RectSide, RectEdge> & {
|
|
16
|
+
value: RectEdge[];
|
|
17
|
+
};
|
|
18
|
+
type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
|
|
19
|
+
type RectCorners = Record<RectCorner, Point> & {
|
|
20
|
+
value: RectPoints;
|
|
21
|
+
};
|
|
22
|
+
type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter";
|
|
23
|
+
type RectCenters = Record<RectCenter, Point> & {
|
|
24
|
+
value: RectPoints;
|
|
25
|
+
};
|
|
26
|
+
type RectInset = Partial<Record<RectSide, number>>;
|
|
27
|
+
type SymmetricRectInset = {
|
|
28
|
+
dx?: number;
|
|
29
|
+
dy?: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { Point, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-WBQAMGXK.mjs";
|
package/dist/union.d.ts
ADDED
package/dist/union.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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/union.ts
|
|
21
|
+
var union_exports = {};
|
|
22
|
+
__export(union_exports, {
|
|
23
|
+
union: () => union
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(union_exports);
|
|
26
|
+
|
|
27
|
+
// src/rect.ts
|
|
28
|
+
var point = (x, y) => ({ x, y });
|
|
29
|
+
function createRect(r) {
|
|
30
|
+
const { x, y, width, height } = r;
|
|
31
|
+
const midX = x + width / 2;
|
|
32
|
+
const midY = y + height / 2;
|
|
33
|
+
return {
|
|
34
|
+
x,
|
|
35
|
+
y,
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
minX: x,
|
|
39
|
+
minY: y,
|
|
40
|
+
maxX: x + width,
|
|
41
|
+
maxY: y + height,
|
|
42
|
+
midX,
|
|
43
|
+
midY,
|
|
44
|
+
center: point(midX, midY)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/from-points.ts
|
|
49
|
+
function getRectFromPoints(...pts) {
|
|
50
|
+
const xs = pts.map((p) => p.x);
|
|
51
|
+
const ys = pts.map((p) => p.y);
|
|
52
|
+
const x = Math.min(...xs);
|
|
53
|
+
const y = Math.min(...ys);
|
|
54
|
+
const width = Math.max(...xs) - x;
|
|
55
|
+
const height = Math.max(...ys) - y;
|
|
56
|
+
return createRect({ x, y, width, height });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/union.ts
|
|
60
|
+
var { min, max } = Math;
|
|
61
|
+
function union(...rs) {
|
|
62
|
+
const pMin = {
|
|
63
|
+
x: min.apply(
|
|
64
|
+
Math,
|
|
65
|
+
rs.map((r) => r.minX)
|
|
66
|
+
),
|
|
67
|
+
y: min.apply(
|
|
68
|
+
Math,
|
|
69
|
+
rs.map((r) => r.minY)
|
|
70
|
+
)
|
|
71
|
+
};
|
|
72
|
+
const pMax = {
|
|
73
|
+
x: max.apply(
|
|
74
|
+
Math,
|
|
75
|
+
rs.map((r) => r.maxX)
|
|
76
|
+
),
|
|
77
|
+
y: max.apply(
|
|
78
|
+
Math,
|
|
79
|
+
rs.map((r) => r.maxY)
|
|
80
|
+
)
|
|
81
|
+
};
|
|
82
|
+
return getRectFromPoints(pMin, pMax);
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
union
|
|
87
|
+
});
|
package/dist/union.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/rect-utils",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"js",
|
|
10
7
|
"utils",
|
|
@@ -25,13 +22,26 @@
|
|
|
25
22
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
23
|
},
|
|
27
24
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"@zag-js/utils": "0.
|
|
25
|
+
"clean-package": "2.2.0",
|
|
26
|
+
"@zag-js/dom-utils": "0.2.2",
|
|
27
|
+
"@zag-js/utils": "0.3.2"
|
|
28
|
+
},
|
|
29
|
+
"clean-package": "../../../clean-package.config.json",
|
|
30
|
+
"main": "dist/index.js",
|
|
31
|
+
"module": "dist/index.mjs",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.mjs",
|
|
37
|
+
"require": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
30
40
|
},
|
|
31
41
|
"scripts": {
|
|
32
|
-
"build-fast": "tsup src
|
|
42
|
+
"build-fast": "tsup src",
|
|
33
43
|
"start": "pnpm build --watch",
|
|
34
|
-
"build": "tsup src
|
|
44
|
+
"build": "tsup src --dts",
|
|
35
45
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
36
46
|
"lint": "eslint src --ext .ts,.tsx",
|
|
37
47
|
"test-ci": "pnpm test --ci --runInBand",
|