@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/chunk-Q4ND66B6.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
distance
|
|
3
|
-
} from "./chunk-N5AQDOKZ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/closest.ts
|
|
6
|
-
function closest(...pts) {
|
|
7
|
-
return (a) => {
|
|
8
|
-
const ds = pts.map((b) => distance(b, a));
|
|
9
|
-
const c = Math.min.apply(Math, ds);
|
|
10
|
-
return pts[ds.indexOf(c)];
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function closestSideToRect(ref, r) {
|
|
14
|
-
if (r.maxX <= ref.minX) {
|
|
15
|
-
return "left";
|
|
16
|
-
}
|
|
17
|
-
if (r.minX >= ref.maxX) {
|
|
18
|
-
return "right";
|
|
19
|
-
}
|
|
20
|
-
if (r.maxY <= ref.minY) {
|
|
21
|
-
return "top";
|
|
22
|
-
}
|
|
23
|
-
if (r.minY >= ref.maxY) {
|
|
24
|
-
return "bottom";
|
|
25
|
-
}
|
|
26
|
-
return "left";
|
|
27
|
-
}
|
|
28
|
-
function closestSideToPoint(ref, p) {
|
|
29
|
-
const { x, y } = p;
|
|
30
|
-
const dl = x - ref.minX;
|
|
31
|
-
const dr = ref.maxX - x;
|
|
32
|
-
const dt = y - ref.minY;
|
|
33
|
-
const db = ref.maxY - y;
|
|
34
|
-
let closest2 = dl;
|
|
35
|
-
let side = "left";
|
|
36
|
-
if (dr < closest2) {
|
|
37
|
-
closest2 = dr;
|
|
38
|
-
side = "right";
|
|
39
|
-
}
|
|
40
|
-
if (dt < closest2) {
|
|
41
|
-
closest2 = dt;
|
|
42
|
-
side = "top";
|
|
43
|
-
}
|
|
44
|
-
if (db < closest2) {
|
|
45
|
-
side = "bottom";
|
|
46
|
-
}
|
|
47
|
-
return side;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
closest,
|
|
52
|
-
closestSideToRect,
|
|
53
|
-
closestSideToPoint
|
|
54
|
-
};
|
package/dist/chunk-QXXKPYP2.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
export {
|
|
46
|
-
alignRect
|
|
47
|
-
};
|
package/dist/chunk-R24UTBJ3.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// src/polygon.ts
|
|
2
|
-
function isPointInPolygon(polygon, point) {
|
|
3
|
-
const { x, y } = point;
|
|
4
|
-
let c = false;
|
|
5
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
6
|
-
const xi = polygon[i].x;
|
|
7
|
-
const yi = polygon[i].y;
|
|
8
|
-
const xj = polygon[j].x;
|
|
9
|
-
const yj = polygon[j].y;
|
|
10
|
-
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
|
|
11
|
-
c = !c;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return c;
|
|
15
|
-
}
|
|
16
|
-
function createPolygonElement() {
|
|
17
|
-
const id = "debug-polygon";
|
|
18
|
-
const existingPolygon = document.getElementById(id);
|
|
19
|
-
if (existingPolygon) {
|
|
20
|
-
return existingPolygon;
|
|
21
|
-
}
|
|
22
|
-
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
23
|
-
Object.assign(svg.style, {
|
|
24
|
-
top: "0",
|
|
25
|
-
left: "0",
|
|
26
|
-
width: "100%",
|
|
27
|
-
height: "100%",
|
|
28
|
-
opacity: "0.15",
|
|
29
|
-
position: "fixed",
|
|
30
|
-
pointerEvents: "none",
|
|
31
|
-
fill: "red"
|
|
32
|
-
});
|
|
33
|
-
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
34
|
-
polygon.setAttribute("id", id);
|
|
35
|
-
polygon.setAttribute("points", "0,0 0,0");
|
|
36
|
-
svg.appendChild(polygon);
|
|
37
|
-
document.body.appendChild(svg);
|
|
38
|
-
return polygon;
|
|
39
|
-
}
|
|
40
|
-
function debugPolygon(polygon) {
|
|
41
|
-
const el = createPolygonElement();
|
|
42
|
-
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
43
|
-
el.setAttribute("points", points);
|
|
44
|
-
return () => {
|
|
45
|
-
el.remove();
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
isPointInPolygon,
|
|
51
|
-
debugPolygon
|
|
52
|
-
};
|
package/dist/chunk-W5IPBTYQ.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect,
|
|
3
|
-
getRectCorners
|
|
4
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
5
|
-
|
|
6
|
-
// src/from-rotation.ts
|
|
7
|
-
function toRad(d) {
|
|
8
|
-
return d % 360 * Math.PI / 180;
|
|
9
|
-
}
|
|
10
|
-
function rotate(a, d, c) {
|
|
11
|
-
const r = toRad(d);
|
|
12
|
-
const sin = Math.sin(r);
|
|
13
|
-
const cos = Math.cos(r);
|
|
14
|
-
const x = a.x - c.x;
|
|
15
|
-
const y = a.y - c.y;
|
|
16
|
-
return {
|
|
17
|
-
x: c.x + x * cos - y * sin,
|
|
18
|
-
y: c.y + x * sin + y * cos
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function getRotationRect(r, deg) {
|
|
22
|
-
const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
23
|
-
const xs = rr.map((p) => p.x);
|
|
24
|
-
const ys = rr.map((p) => p.y);
|
|
25
|
-
const minX = Math.min(...xs);
|
|
26
|
-
const minY = Math.min(...ys);
|
|
27
|
-
const maxX = Math.max(...xs);
|
|
28
|
-
const maxY = Math.max(...ys);
|
|
29
|
-
return createRect({
|
|
30
|
-
x: minX,
|
|
31
|
-
y: minY,
|
|
32
|
-
width: maxX - minX,
|
|
33
|
-
height: maxY - minY
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
toRad,
|
|
39
|
-
rotate,
|
|
40
|
-
getRotationRect
|
|
41
|
-
};
|
package/dist/chunk-WBQAMGXK.mjs
DELETED
|
File without changes
|
package/dist/types.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./chunk-WBQAMGXK.mjs";
|