@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/rect.mjs
CHANGED
|
@@ -1,14 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
const point = (x, y) => ({ x, y });
|
|
2
|
+
function createRect(r) {
|
|
3
|
+
const { x, y, width, height } = r;
|
|
4
|
+
const midX = x + width / 2;
|
|
5
|
+
const midY = y + height / 2;
|
|
6
|
+
return {
|
|
7
|
+
x,
|
|
8
|
+
y,
|
|
9
|
+
width,
|
|
10
|
+
height,
|
|
11
|
+
minX: x,
|
|
12
|
+
minY: y,
|
|
13
|
+
maxX: x + width,
|
|
14
|
+
maxY: y + height,
|
|
15
|
+
midX,
|
|
16
|
+
midY,
|
|
17
|
+
center: point(midX, midY)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
21
|
+
function isRect(v) {
|
|
22
|
+
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
23
|
+
}
|
|
24
|
+
function getRectCenters(v) {
|
|
25
|
+
const top = point(v.midX, v.minY);
|
|
26
|
+
const right = point(v.maxX, v.midY);
|
|
27
|
+
const bottom = point(v.midX, v.maxY);
|
|
28
|
+
const left = point(v.minX, v.midY);
|
|
29
|
+
return { top, right, bottom, left };
|
|
30
|
+
}
|
|
31
|
+
function getRectCorners(v) {
|
|
32
|
+
const top = point(v.minX, v.minY);
|
|
33
|
+
const right = point(v.maxX, v.minY);
|
|
34
|
+
const bottom = point(v.maxX, v.maxY);
|
|
35
|
+
const left = point(v.minX, v.maxY);
|
|
36
|
+
return { top, right, bottom, left };
|
|
37
|
+
}
|
|
38
|
+
function getRectEdges(v) {
|
|
39
|
+
const c = getRectCorners(v);
|
|
40
|
+
const top = [c.top, c.right];
|
|
41
|
+
const right = [c.right, c.bottom];
|
|
42
|
+
const bottom = [c.left, c.bottom];
|
|
43
|
+
const left = [c.top, c.left];
|
|
44
|
+
return { top, right, bottom, left };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { createRect, getRectCenters, getRectCorners, getRectEdges, isRect };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
type Point = {
|
|
1
|
+
export type Point = {
|
|
2
2
|
x: number;
|
|
3
3
|
y: number;
|
|
4
4
|
};
|
|
5
|
-
type RectValue = {
|
|
5
|
+
export type RectValue = {
|
|
6
6
|
x: number;
|
|
7
7
|
y: number;
|
|
8
8
|
width: number;
|
|
9
9
|
height: number;
|
|
10
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> & {
|
|
11
|
+
export type RectSide = "top" | "right" | "bottom" | "left";
|
|
12
|
+
export type RectPoint = "top-left" | "top-center" | "top-right" | "right-center" | "left-center" | "bottom-left" | "bottom-right" | "bottom-center" | "center";
|
|
13
|
+
export type RectEdge = [Point, Point];
|
|
14
|
+
export type RectPoints = [Point, Point, Point, Point];
|
|
15
|
+
export type RectEdges = Record<RectSide, RectEdge> & {
|
|
16
16
|
value: RectEdge[];
|
|
17
17
|
};
|
|
18
|
-
type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
|
|
19
|
-
type RectCorners = Record<RectCorner, Point> & {
|
|
18
|
+
export type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
|
|
19
|
+
export type RectCorners = Record<RectCorner, Point> & {
|
|
20
20
|
value: RectPoints;
|
|
21
21
|
};
|
|
22
|
-
type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter";
|
|
23
|
-
type RectCenters = Record<RectCenter, Point> & {
|
|
22
|
+
export type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter";
|
|
23
|
+
export type RectCenters = Record<RectCenter, Point> & {
|
|
24
24
|
value: RectPoints;
|
|
25
25
|
};
|
|
26
|
-
type RectInset = Partial<Record<RectSide, number>>;
|
|
27
|
-
type SymmetricRectInset = {
|
|
26
|
+
export type RectInset = Partial<Record<RectSide, number>>;
|
|
27
|
+
export type SymmetricRectInset = {
|
|
28
28
|
dx?: number;
|
|
29
29
|
dy?: number;
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
export { Point, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset };
|
package/dist/union.d.ts
CHANGED
package/dist/union.js
CHANGED
|
@@ -1,63 +1,10 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var union_exports = {};
|
|
22
|
-
__export(union_exports, {
|
|
23
|
-
union: () => union
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(union_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
26
4
|
|
|
27
|
-
|
|
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
|
-
}
|
|
5
|
+
const fromPoints = require('./from-points.js');
|
|
47
6
|
|
|
48
|
-
|
|
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;
|
|
7
|
+
const { min, max } = Math;
|
|
61
8
|
function union(...rs) {
|
|
62
9
|
const pMin = {
|
|
63
10
|
x: min.apply(
|
|
@@ -79,9 +26,7 @@ function union(...rs) {
|
|
|
79
26
|
rs.map((r) => r.maxY)
|
|
80
27
|
)
|
|
81
28
|
};
|
|
82
|
-
return getRectFromPoints(pMin, pMax);
|
|
29
|
+
return fromPoints.getRectFromPoints(pMin, pMax);
|
|
83
30
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
union
|
|
87
|
-
});
|
|
31
|
+
|
|
32
|
+
exports.union = union;
|
package/dist/union.mjs
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getRectFromPoints } from './from-points.mjs';
|
|
2
|
+
|
|
3
|
+
const { min, max } = Math;
|
|
4
|
+
function union(...rs) {
|
|
5
|
+
const pMin = {
|
|
6
|
+
x: min.apply(
|
|
7
|
+
Math,
|
|
8
|
+
rs.map((r) => r.minX)
|
|
9
|
+
),
|
|
10
|
+
y: min.apply(
|
|
11
|
+
Math,
|
|
12
|
+
rs.map((r) => r.minY)
|
|
13
|
+
)
|
|
14
|
+
};
|
|
15
|
+
const pMax = {
|
|
16
|
+
x: max.apply(
|
|
17
|
+
Math,
|
|
18
|
+
rs.map((r) => r.maxX)
|
|
19
|
+
),
|
|
20
|
+
y: max.apply(
|
|
21
|
+
Math,
|
|
22
|
+
rs.map((r) => r.maxY)
|
|
23
|
+
)
|
|
24
|
+
};
|
|
25
|
+
return getRectFromPoints(pMin, pMax);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { union };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/rect-utils",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -38,13 +38,8 @@
|
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build
|
|
42
|
-
"start": "pnpm build --watch",
|
|
43
|
-
"build": "tsup src --dts",
|
|
44
|
-
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
41
|
+
"build": "vite build -c ../../../vite.config.ts",
|
|
45
42
|
"lint": "eslint src --ext .ts,.tsx",
|
|
46
|
-
"test-ci": "pnpm test --ci --runInBand",
|
|
47
|
-
"test-watch": "pnpm test --watch -u",
|
|
48
43
|
"typecheck": "tsc --noEmit"
|
|
49
44
|
}
|
|
50
45
|
}
|
package/dist/chunk-25JXNQDO.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
union
|
|
3
|
-
} from "./chunk-K4PDUEML.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getElementRect
|
|
6
|
-
} from "./chunk-BDA5H4ND.mjs";
|
|
7
|
-
import {
|
|
8
|
-
createRect
|
|
9
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
10
|
-
|
|
11
|
-
// src/from-range.ts
|
|
12
|
-
function fromRange(range) {
|
|
13
|
-
let rs = [];
|
|
14
|
-
const rects = Array.from(range.getClientRects());
|
|
15
|
-
if (rects.length) {
|
|
16
|
-
rs = rs.concat(rects.map(createRect));
|
|
17
|
-
return union.apply(void 0, rs);
|
|
18
|
-
}
|
|
19
|
-
let start = range.startContainer;
|
|
20
|
-
if (start.nodeType === Node.TEXT_NODE) {
|
|
21
|
-
start = start.parentNode;
|
|
22
|
-
}
|
|
23
|
-
if (start instanceof HTMLElement) {
|
|
24
|
-
const r = getElementRect(start);
|
|
25
|
-
rs.push({ ...r, x: r.maxX, width: 0 });
|
|
26
|
-
}
|
|
27
|
-
return union.apply(void 0, rs);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
fromRange
|
|
32
|
-
};
|
package/dist/chunk-2FRM3R57.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect
|
|
3
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
4
|
-
|
|
5
|
-
// src/from-window.ts
|
|
6
|
-
function getWindowRect(win, opts = {}) {
|
|
7
|
-
return createRect(getViewportRect(win, opts));
|
|
8
|
-
}
|
|
9
|
-
function getViewportRect(win, opts) {
|
|
10
|
-
const { excludeScrollbar = false } = opts;
|
|
11
|
-
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
12
|
-
const width = visualViewport?.width || innerWidth;
|
|
13
|
-
const height = visualViewport?.height || innerHeight;
|
|
14
|
-
const rect = { x: 0, y: 0, width, height };
|
|
15
|
-
if (excludeScrollbar) {
|
|
16
|
-
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
17
|
-
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
18
|
-
rect.width -= scrollbarWidth;
|
|
19
|
-
rect.height -= scrollbarHeight;
|
|
20
|
-
}
|
|
21
|
-
return rect;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
getWindowRect,
|
|
26
|
-
getViewportRect
|
|
27
|
-
};
|
package/dist/chunk-62GE3RPG.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getRectCorners,
|
|
3
|
-
isRect
|
|
4
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
5
|
-
|
|
6
|
-
// src/contains.ts
|
|
7
|
-
function containsPoint(r, p) {
|
|
8
|
-
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
9
|
-
}
|
|
10
|
-
function containsRect(a, b) {
|
|
11
|
-
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
12
|
-
}
|
|
13
|
-
function contains(r, v) {
|
|
14
|
-
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
containsPoint,
|
|
19
|
-
containsRect,
|
|
20
|
-
contains
|
|
21
|
-
};
|
package/dist/chunk-BDA5H4ND.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect
|
|
3
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
4
|
-
|
|
5
|
-
// src/from-element.ts
|
|
6
|
-
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
function getCacheComputedStyle(el) {
|
|
8
|
-
if (!styleCache.has(el)) {
|
|
9
|
-
const win = el.ownerDocument.defaultView || window;
|
|
10
|
-
styleCache.set(el, win.getComputedStyle(el));
|
|
11
|
-
}
|
|
12
|
-
return styleCache.get(el);
|
|
13
|
-
}
|
|
14
|
-
function getElementRect(el, opts = {}) {
|
|
15
|
-
return createRect(getClientRect(el, opts));
|
|
16
|
-
}
|
|
17
|
-
function getClientRect(el, opts = {}) {
|
|
18
|
-
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
19
|
-
const { x, y, width, height } = el.getBoundingClientRect();
|
|
20
|
-
const r = { x, y, width, height };
|
|
21
|
-
const style = getCacheComputedStyle(el);
|
|
22
|
-
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
23
|
-
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
24
|
-
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
25
|
-
if (excludeBorders) {
|
|
26
|
-
r.width -= borderXWidth;
|
|
27
|
-
r.height -= borderYWidth;
|
|
28
|
-
r.x += px(borderLeftWidth);
|
|
29
|
-
r.y += px(borderTopWidth);
|
|
30
|
-
}
|
|
31
|
-
if (excludeScrollbar) {
|
|
32
|
-
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
33
|
-
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
34
|
-
r.width -= scrollbarWidth;
|
|
35
|
-
r.height -= scrollbarHeight;
|
|
36
|
-
}
|
|
37
|
-
return r;
|
|
38
|
-
}
|
|
39
|
-
var px = (v) => parseFloat(v.replace("px", ""));
|
|
40
|
-
var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
getElementRect
|
|
44
|
-
};
|
package/dist/chunk-BRVYSREB.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect,
|
|
3
|
-
getRectCorners
|
|
4
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
5
|
-
|
|
6
|
-
// src/get-polygon.ts
|
|
7
|
-
function getElementPolygon(rectValue, placement) {
|
|
8
|
-
const rect = createRect(rectValue);
|
|
9
|
-
const { top, right, left, bottom } = getRectCorners(rect);
|
|
10
|
-
const [base] = placement.split("-");
|
|
11
|
-
return {
|
|
12
|
-
top: [left, top, right, bottom],
|
|
13
|
-
right: [top, right, bottom, left],
|
|
14
|
-
bottom: [top, left, bottom, right],
|
|
15
|
-
left: [right, top, left, bottom]
|
|
16
|
-
}[base];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
getElementPolygon
|
|
21
|
-
};
|
package/dist/chunk-D46YBNP3.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect
|
|
3
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
4
|
-
|
|
5
|
-
// src/from-points.ts
|
|
6
|
-
function getRectFromPoints(...pts) {
|
|
7
|
-
const xs = pts.map((p) => p.x);
|
|
8
|
-
const ys = pts.map((p) => p.y);
|
|
9
|
-
const x = Math.min(...xs);
|
|
10
|
-
const y = Math.min(...ys);
|
|
11
|
-
const width = Math.max(...xs) - x;
|
|
12
|
-
const height = Math.max(...ys) - y;
|
|
13
|
-
return createRect({ x, y, width, height });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
getRectFromPoints
|
|
18
|
-
};
|
package/dist/chunk-GYYHT756.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect
|
|
3
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
4
|
-
|
|
5
|
-
// src/intersection.ts
|
|
6
|
-
function intersects(a, b) {
|
|
7
|
-
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
8
|
-
}
|
|
9
|
-
function intersection(a, b) {
|
|
10
|
-
const x = Math.max(a.x, b.x);
|
|
11
|
-
const y = Math.max(a.y, b.y);
|
|
12
|
-
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
13
|
-
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
14
|
-
return createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
15
|
-
}
|
|
16
|
-
function collisions(a, b) {
|
|
17
|
-
return {
|
|
18
|
-
top: a.minY <= b.minY,
|
|
19
|
-
right: a.maxX >= b.maxX,
|
|
20
|
-
bottom: a.maxY >= b.maxY,
|
|
21
|
-
left: a.minX <= b.minX
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
intersects,
|
|
27
|
-
intersection,
|
|
28
|
-
collisions
|
|
29
|
-
};
|
package/dist/chunk-K4PDUEML.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getRectFromPoints
|
|
3
|
-
} from "./chunk-D46YBNP3.mjs";
|
|
4
|
-
|
|
5
|
-
// src/union.ts
|
|
6
|
-
var { min, max } = Math;
|
|
7
|
-
function union(...rs) {
|
|
8
|
-
const pMin = {
|
|
9
|
-
x: min.apply(
|
|
10
|
-
Math,
|
|
11
|
-
rs.map((r) => r.minX)
|
|
12
|
-
),
|
|
13
|
-
y: min.apply(
|
|
14
|
-
Math,
|
|
15
|
-
rs.map((r) => r.minY)
|
|
16
|
-
)
|
|
17
|
-
};
|
|
18
|
-
const pMax = {
|
|
19
|
-
x: max.apply(
|
|
20
|
-
Math,
|
|
21
|
-
rs.map((r) => r.maxX)
|
|
22
|
-
),
|
|
23
|
-
y: max.apply(
|
|
24
|
-
Math,
|
|
25
|
-
rs.map((r) => r.maxY)
|
|
26
|
-
)
|
|
27
|
-
};
|
|
28
|
-
return getRectFromPoints(pMin, pMax);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
union
|
|
33
|
-
};
|
package/dist/chunk-MM5LIN7D.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRect
|
|
3
|
-
} from "./chunk-MNKJK37U.mjs";
|
|
4
|
-
|
|
5
|
-
// src/operations.ts
|
|
6
|
-
var isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
7
|
-
function inset(r, i) {
|
|
8
|
-
const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
|
|
9
|
-
const { top = 0, right = 0, bottom = 0, left = 0 } = v;
|
|
10
|
-
return createRect({
|
|
11
|
-
x: r.x + left,
|
|
12
|
-
y: r.y + top,
|
|
13
|
-
width: r.width - left - right,
|
|
14
|
-
height: r.height - top - bottom
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function expand(r, v) {
|
|
18
|
-
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
19
|
-
return inset(r, value);
|
|
20
|
-
}
|
|
21
|
-
function shrink(r, v) {
|
|
22
|
-
const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
|
|
23
|
-
return inset(r, value);
|
|
24
|
-
}
|
|
25
|
-
function shift(r, o) {
|
|
26
|
-
const { x = 0, y = 0 } = o;
|
|
27
|
-
return createRect({
|
|
28
|
-
x: r.x + x,
|
|
29
|
-
y: r.y + y,
|
|
30
|
-
width: r.width,
|
|
31
|
-
height: r.height
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
isSymmetric,
|
|
37
|
-
inset,
|
|
38
|
-
expand,
|
|
39
|
-
shrink,
|
|
40
|
-
shift
|
|
41
|
-
};
|
package/dist/chunk-MNKJK37U.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// src/rect.ts
|
|
2
|
-
var point = (x, y) => ({ x, y });
|
|
3
|
-
function createRect(r) {
|
|
4
|
-
const { x, y, width, height } = r;
|
|
5
|
-
const midX = x + width / 2;
|
|
6
|
-
const midY = y + height / 2;
|
|
7
|
-
return {
|
|
8
|
-
x,
|
|
9
|
-
y,
|
|
10
|
-
width,
|
|
11
|
-
height,
|
|
12
|
-
minX: x,
|
|
13
|
-
minY: y,
|
|
14
|
-
maxX: x + width,
|
|
15
|
-
maxY: y + height,
|
|
16
|
-
midX,
|
|
17
|
-
midY,
|
|
18
|
-
center: point(midX, midY)
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
function isRect(v) {
|
|
23
|
-
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
24
|
-
}
|
|
25
|
-
function getRectCenters(v) {
|
|
26
|
-
const top = point(v.midX, v.minY);
|
|
27
|
-
const right = point(v.maxX, v.midY);
|
|
28
|
-
const bottom = point(v.midX, v.maxY);
|
|
29
|
-
const left = point(v.minX, v.midY);
|
|
30
|
-
return { top, right, bottom, left };
|
|
31
|
-
}
|
|
32
|
-
function getRectCorners(v) {
|
|
33
|
-
const top = point(v.minX, v.minY);
|
|
34
|
-
const right = point(v.maxX, v.minY);
|
|
35
|
-
const bottom = point(v.maxX, v.maxY);
|
|
36
|
-
const left = point(v.minX, v.maxY);
|
|
37
|
-
return { top, right, bottom, left };
|
|
38
|
-
}
|
|
39
|
-
function getRectEdges(v) {
|
|
40
|
-
const c = getRectCorners(v);
|
|
41
|
-
const top = [c.top, c.right];
|
|
42
|
-
const right = [c.right, c.bottom];
|
|
43
|
-
const bottom = [c.left, c.bottom];
|
|
44
|
-
const left = [c.top, c.left];
|
|
45
|
-
return { top, right, bottom, left };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
createRect,
|
|
50
|
-
isRect,
|
|
51
|
-
getRectCenters,
|
|
52
|
-
getRectCorners,
|
|
53
|
-
getRectEdges
|
|
54
|
-
};
|
package/dist/chunk-N5AQDOKZ.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
intersects
|
|
3
|
-
} from "./chunk-GYYHT756.mjs";
|
|
4
|
-
|
|
5
|
-
// src/distance.ts
|
|
6
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
7
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
8
|
-
}
|
|
9
|
-
function distanceFromPoint(r, p) {
|
|
10
|
-
let x = 0;
|
|
11
|
-
let y = 0;
|
|
12
|
-
if (p.x < r.x)
|
|
13
|
-
x = r.x - p.x;
|
|
14
|
-
else if (p.x > r.maxX)
|
|
15
|
-
x = p.x - r.maxX;
|
|
16
|
-
if (p.y < r.y)
|
|
17
|
-
y = r.y - p.y;
|
|
18
|
-
else if (p.y > r.maxY)
|
|
19
|
-
y = p.y - r.maxY;
|
|
20
|
-
return { x, y, value: distance({ x, y }) };
|
|
21
|
-
}
|
|
22
|
-
function distanceFromRect(a, b) {
|
|
23
|
-
if (intersects(a, b))
|
|
24
|
-
return { x: 0, y: 0, value: 0 };
|
|
25
|
-
const left = a.x < b.x ? a : b;
|
|
26
|
-
const right = b.x < a.x ? a : b;
|
|
27
|
-
const upper = a.y < b.y ? a : b;
|
|
28
|
-
const lower = b.y < a.y ? a : b;
|
|
29
|
-
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
30
|
-
x = Math.max(0, x);
|
|
31
|
-
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
32
|
-
y = Math.max(0, y);
|
|
33
|
-
return { x, y, value: distance({ x, y }) };
|
|
34
|
-
}
|
|
35
|
-
function distanceBtwEdges(a, b) {
|
|
36
|
-
return {
|
|
37
|
-
left: b.x - a.x,
|
|
38
|
-
top: b.y - a.y,
|
|
39
|
-
right: a.maxX - b.maxX,
|
|
40
|
-
bottom: a.maxY - b.maxY
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
distance,
|
|
46
|
-
distanceFromPoint,
|
|
47
|
-
distanceFromRect,
|
|
48
|
-
distanceBtwEdges
|
|
49
|
-
};
|