@zag-js/rect-utils 1.34.0 → 1.35.0
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/affine-transform.d.mts +39 -0
- package/dist/affine-transform.d.ts +39 -0
- package/dist/affine-transform.js +189 -0
- package/dist/affine-transform.mjs +166 -0
- package/dist/align.d.mts +5 -0
- package/dist/align.d.ts +5 -0
- package/dist/align.js +51 -0
- package/dist/align.mjs +28 -0
- package/dist/angle.d.mts +5 -0
- package/dist/angle.d.ts +5 -0
- package/dist/angle.js +35 -0
- package/dist/angle.mjs +12 -0
- package/dist/chunk-QZ7TP4HQ.mjs +7 -0
- package/dist/clamp.d.mts +12 -0
- package/dist/clamp.d.ts +12 -0
- package/dist/clamp.js +51 -0
- package/dist/clamp.mjs +27 -0
- package/dist/closest.d.mts +7 -0
- package/dist/closest.d.ts +7 -0
- package/dist/closest.js +69 -0
- package/dist/closest.mjs +44 -0
- package/dist/compass.d.mts +7 -0
- package/dist/compass.d.ts +7 -0
- package/dist/compass.js +51 -0
- package/dist/compass.mjs +27 -0
- package/dist/constrain.d.mts +5 -0
- package/dist/constrain.d.ts +5 -0
- package/dist/constrain.js +39 -0
- package/dist/constrain.mjs +16 -0
- package/dist/contains.d.mts +7 -0
- package/dist/contains.d.ts +7 -0
- package/dist/contains.js +43 -0
- package/dist/contains.mjs +18 -0
- package/dist/distance.d.mts +11 -0
- package/dist/distance.d.ts +11 -0
- package/dist/distance.js +68 -0
- package/dist/distance.mjs +42 -0
- package/dist/equality.d.mts +7 -0
- package/dist/equality.d.ts +7 -0
- package/dist/equality.js +42 -0
- package/dist/equality.mjs +17 -0
- package/dist/from-element.d.mts +15 -0
- package/dist/from-element.d.ts +15 -0
- package/dist/from-element.js +65 -0
- package/dist/from-element.mjs +42 -0
- package/dist/from-points.d.mts +5 -0
- package/dist/from-points.d.ts +5 -0
- package/dist/from-points.js +39 -0
- package/dist/from-points.mjs +16 -0
- package/dist/from-range.d.mts +5 -0
- package/dist/from-range.d.ts +5 -0
- package/dist/from-range.js +49 -0
- package/dist/from-range.mjs +26 -0
- package/dist/from-rotation.d.mts +7 -0
- package/dist/from-rotation.d.ts +7 -0
- package/dist/from-rotation.js +63 -0
- package/dist/from-rotation.mjs +38 -0
- package/dist/from-window.d.mts +23 -0
- package/dist/from-window.d.ts +23 -0
- package/dist/from-window.js +49 -0
- package/dist/from-window.mjs +25 -0
- package/dist/index.d.mts +22 -253
- package/dist/index.d.ts +22 -253
- package/dist/index.js +62 -772
- package/dist/index.mjs +22 -724
- package/dist/intersection.d.mts +16 -0
- package/dist/intersection.d.ts +16 -0
- package/dist/intersection.js +52 -0
- package/dist/intersection.mjs +27 -0
- package/dist/operations.d.mts +9 -0
- package/dist/operations.d.ts +9 -0
- package/dist/operations.js +66 -0
- package/dist/operations.mjs +39 -0
- package/dist/polygon.d.mts +10 -0
- package/dist/polygon.d.ts +10 -0
- package/dist/polygon.js +91 -0
- package/dist/polygon.mjs +66 -0
- package/dist/rect.d.mts +58 -0
- package/dist/rect.d.ts +58 -0
- package/dist/rect.js +97 -0
- package/dist/rect.mjs +66 -0
- package/dist/resize.d.mts +6 -0
- package/dist/resize.d.ts +6 -0
- package/dist/resize.js +113 -0
- package/dist/resize.mjs +90 -0
- package/dist/types.d.mts +55 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/dist/union.d.mts +5 -0
- package/dist/union.d.ts +5 -0
- package/dist/union.js +42 -0
- package/dist/union.mjs +19 -0
- package/package.json +1 -1
package/dist/clamp.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/clamp.ts
|
|
4
|
+
var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
5
|
+
var clampPoint = (position, size, boundaryRect) => {
|
|
6
|
+
const x = clamp(position.x, boundaryRect.x, boundaryRect.x + boundaryRect.width - size.width);
|
|
7
|
+
const y = clamp(position.y, boundaryRect.y, boundaryRect.y + boundaryRect.height - size.height);
|
|
8
|
+
return { x, y };
|
|
9
|
+
};
|
|
10
|
+
var defaultMinSize = {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0
|
|
13
|
+
};
|
|
14
|
+
var defaultMaxSize = {
|
|
15
|
+
width: Infinity,
|
|
16
|
+
height: Infinity
|
|
17
|
+
};
|
|
18
|
+
var clampSize = (size, minSize = defaultMinSize, maxSize = defaultMaxSize) => {
|
|
19
|
+
return {
|
|
20
|
+
width: Math.min(Math.max(size.width, minSize.width), maxSize.width),
|
|
21
|
+
height: Math.min(Math.max(size.height, minSize.height), maxSize.height)
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
clampPoint,
|
|
26
|
+
clampSize
|
|
27
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point, Rect, RectSide } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
4
|
+
declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
5
|
+
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
6
|
+
|
|
7
|
+
export { closest, closestSideToPoint, closestSideToRect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point, Rect, RectSide } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
4
|
+
declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
5
|
+
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
6
|
+
|
|
7
|
+
export { closest, closestSideToPoint, closestSideToRect };
|
package/dist/closest.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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/closest.ts
|
|
21
|
+
var closest_exports = {};
|
|
22
|
+
__export(closest_exports, {
|
|
23
|
+
closest: () => closest,
|
|
24
|
+
closestSideToPoint: () => closestSideToPoint,
|
|
25
|
+
closestSideToRect: () => closestSideToRect
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(closest_exports);
|
|
28
|
+
var import_distance = require("./distance.cjs");
|
|
29
|
+
function closest(...pts) {
|
|
30
|
+
return (a) => {
|
|
31
|
+
const ds = pts.map((b) => (0, import_distance.distance)(b, a));
|
|
32
|
+
const c = Math.min.apply(Math, ds);
|
|
33
|
+
return pts[ds.indexOf(c)];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function closestSideToRect(ref, r) {
|
|
37
|
+
if (r.maxX <= ref.minX) return "left";
|
|
38
|
+
if (r.minX >= ref.maxX) return "right";
|
|
39
|
+
if (r.maxY <= ref.minY) return "top";
|
|
40
|
+
if (r.minY >= ref.maxY) return "bottom";
|
|
41
|
+
return "left";
|
|
42
|
+
}
|
|
43
|
+
function closestSideToPoint(ref, p) {
|
|
44
|
+
const { x, y } = p;
|
|
45
|
+
const dl = x - ref.minX;
|
|
46
|
+
const dr = ref.maxX - x;
|
|
47
|
+
const dt = y - ref.minY;
|
|
48
|
+
const db = ref.maxY - y;
|
|
49
|
+
let closest2 = dl;
|
|
50
|
+
let side = "left";
|
|
51
|
+
if (dr < closest2) {
|
|
52
|
+
closest2 = dr;
|
|
53
|
+
side = "right";
|
|
54
|
+
}
|
|
55
|
+
if (dt < closest2) {
|
|
56
|
+
closest2 = dt;
|
|
57
|
+
side = "top";
|
|
58
|
+
}
|
|
59
|
+
if (db < closest2) {
|
|
60
|
+
side = "bottom";
|
|
61
|
+
}
|
|
62
|
+
return side;
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
closest,
|
|
67
|
+
closestSideToPoint,
|
|
68
|
+
closestSideToRect
|
|
69
|
+
});
|
package/dist/closest.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/closest.ts
|
|
4
|
+
import { distance } from "./distance.mjs";
|
|
5
|
+
function closest(...pts) {
|
|
6
|
+
return (a) => {
|
|
7
|
+
const ds = pts.map((b) => distance(b, a));
|
|
8
|
+
const c = Math.min.apply(Math, ds);
|
|
9
|
+
return pts[ds.indexOf(c)];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function closestSideToRect(ref, r) {
|
|
13
|
+
if (r.maxX <= ref.minX) return "left";
|
|
14
|
+
if (r.minX >= ref.maxX) return "right";
|
|
15
|
+
if (r.maxY <= ref.minY) return "top";
|
|
16
|
+
if (r.minY >= ref.maxY) return "bottom";
|
|
17
|
+
return "left";
|
|
18
|
+
}
|
|
19
|
+
function closestSideToPoint(ref, p) {
|
|
20
|
+
const { x, y } = p;
|
|
21
|
+
const dl = x - ref.minX;
|
|
22
|
+
const dr = ref.maxX - x;
|
|
23
|
+
const dt = y - ref.minY;
|
|
24
|
+
const db = ref.maxY - y;
|
|
25
|
+
let closest2 = dl;
|
|
26
|
+
let side = "left";
|
|
27
|
+
if (dr < closest2) {
|
|
28
|
+
closest2 = dr;
|
|
29
|
+
side = "right";
|
|
30
|
+
}
|
|
31
|
+
if (dt < closest2) {
|
|
32
|
+
closest2 = dt;
|
|
33
|
+
side = "top";
|
|
34
|
+
}
|
|
35
|
+
if (db < closest2) {
|
|
36
|
+
side = "bottom";
|
|
37
|
+
}
|
|
38
|
+
return side;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
closest,
|
|
42
|
+
closestSideToPoint,
|
|
43
|
+
closestSideToRect
|
|
44
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
type CompassDirection = "n" | "ne" | "e" | "se" | "s" | "sw" | "w" | "nw";
|
|
4
|
+
declare const compassDirectionMap: Record<CompassDirection, Point>;
|
|
5
|
+
declare const oppositeDirectionMap: Record<CompassDirection, CompassDirection>;
|
|
6
|
+
|
|
7
|
+
export { type CompassDirection, compassDirectionMap, oppositeDirectionMap };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point } from './types.js';
|
|
2
|
+
|
|
3
|
+
type CompassDirection = "n" | "ne" | "e" | "se" | "s" | "sw" | "w" | "nw";
|
|
4
|
+
declare const compassDirectionMap: Record<CompassDirection, Point>;
|
|
5
|
+
declare const oppositeDirectionMap: Record<CompassDirection, CompassDirection>;
|
|
6
|
+
|
|
7
|
+
export { type CompassDirection, compassDirectionMap, oppositeDirectionMap };
|
package/dist/compass.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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/compass.ts
|
|
21
|
+
var compass_exports = {};
|
|
22
|
+
__export(compass_exports, {
|
|
23
|
+
compassDirectionMap: () => compassDirectionMap,
|
|
24
|
+
oppositeDirectionMap: () => oppositeDirectionMap
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(compass_exports);
|
|
27
|
+
var compassDirectionMap = {
|
|
28
|
+
n: { x: 0.5, y: 0 },
|
|
29
|
+
ne: { x: 1, y: 0 },
|
|
30
|
+
e: { x: 1, y: 0.5 },
|
|
31
|
+
se: { x: 1, y: 1 },
|
|
32
|
+
s: { x: 0.5, y: 1 },
|
|
33
|
+
sw: { x: 0, y: 1 },
|
|
34
|
+
w: { x: 0, y: 0.5 },
|
|
35
|
+
nw: { x: 0, y: 0 }
|
|
36
|
+
};
|
|
37
|
+
var oppositeDirectionMap = {
|
|
38
|
+
n: "s",
|
|
39
|
+
ne: "sw",
|
|
40
|
+
e: "w",
|
|
41
|
+
se: "nw",
|
|
42
|
+
s: "n",
|
|
43
|
+
sw: "ne",
|
|
44
|
+
w: "e",
|
|
45
|
+
nw: "se"
|
|
46
|
+
};
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
compassDirectionMap,
|
|
50
|
+
oppositeDirectionMap
|
|
51
|
+
});
|
package/dist/compass.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/compass.ts
|
|
4
|
+
var compassDirectionMap = {
|
|
5
|
+
n: { x: 0.5, y: 0 },
|
|
6
|
+
ne: { x: 1, y: 0 },
|
|
7
|
+
e: { x: 1, y: 0.5 },
|
|
8
|
+
se: { x: 1, y: 1 },
|
|
9
|
+
s: { x: 0.5, y: 1 },
|
|
10
|
+
sw: { x: 0, y: 1 },
|
|
11
|
+
w: { x: 0, y: 0.5 },
|
|
12
|
+
nw: { x: 0, y: 0 }
|
|
13
|
+
};
|
|
14
|
+
var oppositeDirectionMap = {
|
|
15
|
+
n: "s",
|
|
16
|
+
ne: "sw",
|
|
17
|
+
e: "w",
|
|
18
|
+
se: "nw",
|
|
19
|
+
s: "n",
|
|
20
|
+
sw: "ne",
|
|
21
|
+
w: "e",
|
|
22
|
+
nw: "se"
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
compassDirectionMap,
|
|
26
|
+
oppositeDirectionMap
|
|
27
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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/constrain.ts
|
|
21
|
+
var constrain_exports = {};
|
|
22
|
+
__export(constrain_exports, {
|
|
23
|
+
constrainRect: () => constrainRect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constrain_exports);
|
|
26
|
+
var constrainRect = (rect, boundary) => {
|
|
27
|
+
const left = Math.max(boundary.x, Math.min(rect.x, boundary.x + boundary.width - rect.width));
|
|
28
|
+
const top = Math.max(boundary.y, Math.min(rect.y, boundary.y + boundary.height - rect.height));
|
|
29
|
+
return {
|
|
30
|
+
x: left,
|
|
31
|
+
y: top,
|
|
32
|
+
width: Math.min(rect.width, boundary.width),
|
|
33
|
+
height: Math.min(rect.height, boundary.height)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
constrainRect
|
|
39
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/constrain.ts
|
|
4
|
+
var constrainRect = (rect, boundary) => {
|
|
5
|
+
const left = Math.max(boundary.x, Math.min(rect.x, boundary.x + boundary.width - rect.width));
|
|
6
|
+
const top = Math.max(boundary.y, Math.min(rect.y, boundary.y + boundary.height - rect.height));
|
|
7
|
+
return {
|
|
8
|
+
x: left,
|
|
9
|
+
y: top,
|
|
10
|
+
width: Math.min(rect.width, boundary.width),
|
|
11
|
+
height: Math.min(rect.height, boundary.height)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
constrainRect
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rect, Point } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare function containsPoint(r: Rect, p: Point): boolean;
|
|
4
|
+
declare function containsRect(a: Rect, b: Rect): boolean;
|
|
5
|
+
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
6
|
+
|
|
7
|
+
export { contains, containsPoint, containsRect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rect, Point } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare function containsPoint(r: Rect, p: Point): boolean;
|
|
4
|
+
declare function containsRect(a: Rect, b: Rect): boolean;
|
|
5
|
+
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
6
|
+
|
|
7
|
+
export { contains, containsPoint, containsRect };
|
package/dist/contains.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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/contains.ts
|
|
21
|
+
var contains_exports = {};
|
|
22
|
+
__export(contains_exports, {
|
|
23
|
+
contains: () => contains,
|
|
24
|
+
containsPoint: () => containsPoint,
|
|
25
|
+
containsRect: () => containsRect
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(contains_exports);
|
|
28
|
+
var import_rect = require("./rect.cjs");
|
|
29
|
+
function containsPoint(r, p) {
|
|
30
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
31
|
+
}
|
|
32
|
+
function containsRect(a, b) {
|
|
33
|
+
return Object.values((0, import_rect.getRectCorners)(b)).every((c) => containsPoint(a, c));
|
|
34
|
+
}
|
|
35
|
+
function contains(r, v) {
|
|
36
|
+
return (0, import_rect.isRect)(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
contains,
|
|
41
|
+
containsPoint,
|
|
42
|
+
containsRect
|
|
43
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/contains.ts
|
|
4
|
+
import { getRectCorners, isRect } from "./rect.mjs";
|
|
5
|
+
function containsPoint(r, p) {
|
|
6
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
7
|
+
}
|
|
8
|
+
function containsRect(a, b) {
|
|
9
|
+
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
10
|
+
}
|
|
11
|
+
function contains(r, v) {
|
|
12
|
+
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
contains,
|
|
16
|
+
containsPoint,
|
|
17
|
+
containsRect
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Point, Rect, RectSide } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
interface DistanceValue extends Point {
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
declare function distance(a: Point, b?: Point): number;
|
|
7
|
+
declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
8
|
+
declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
9
|
+
declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
|
10
|
+
|
|
11
|
+
export { type DistanceValue, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Point, Rect, RectSide } from './types.js';
|
|
2
|
+
|
|
3
|
+
interface DistanceValue extends Point {
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
declare function distance(a: Point, b?: Point): number;
|
|
7
|
+
declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
8
|
+
declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
9
|
+
declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
|
10
|
+
|
|
11
|
+
export { type DistanceValue, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
package/dist/distance.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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/distance.ts
|
|
21
|
+
var distance_exports = {};
|
|
22
|
+
__export(distance_exports, {
|
|
23
|
+
distance: () => distance,
|
|
24
|
+
distanceBtwEdges: () => distanceBtwEdges,
|
|
25
|
+
distanceFromPoint: () => distanceFromPoint,
|
|
26
|
+
distanceFromRect: () => distanceFromRect
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(distance_exports);
|
|
29
|
+
var import_intersection = require("./intersection.cjs");
|
|
30
|
+
function distance(a, b = { x: 0, y: 0 }) {
|
|
31
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
32
|
+
}
|
|
33
|
+
function distanceFromPoint(r, p) {
|
|
34
|
+
let x = 0;
|
|
35
|
+
let y = 0;
|
|
36
|
+
if (p.x < r.x) x = r.x - p.x;
|
|
37
|
+
else if (p.x > r.maxX) x = p.x - r.maxX;
|
|
38
|
+
if (p.y < r.y) y = r.y - p.y;
|
|
39
|
+
else if (p.y > r.maxY) y = p.y - r.maxY;
|
|
40
|
+
return { x, y, value: distance({ x, y }) };
|
|
41
|
+
}
|
|
42
|
+
function distanceFromRect(a, b) {
|
|
43
|
+
if ((0, import_intersection.intersects)(a, b)) return { x: 0, y: 0, value: 0 };
|
|
44
|
+
const left = a.x < b.x ? a : b;
|
|
45
|
+
const right = b.x < a.x ? a : b;
|
|
46
|
+
const upper = a.y < b.y ? a : b;
|
|
47
|
+
const lower = b.y < a.y ? a : b;
|
|
48
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
49
|
+
x = Math.max(0, x);
|
|
50
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
51
|
+
y = Math.max(0, y);
|
|
52
|
+
return { x, y, value: distance({ x, y }) };
|
|
53
|
+
}
|
|
54
|
+
function distanceBtwEdges(a, b) {
|
|
55
|
+
return {
|
|
56
|
+
left: b.x - a.x,
|
|
57
|
+
top: b.y - a.y,
|
|
58
|
+
right: a.maxX - b.maxX,
|
|
59
|
+
bottom: a.maxY - b.maxY
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
distance,
|
|
65
|
+
distanceBtwEdges,
|
|
66
|
+
distanceFromPoint,
|
|
67
|
+
distanceFromRect
|
|
68
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/distance.ts
|
|
4
|
+
import { intersects } from "./intersection.mjs";
|
|
5
|
+
function distance(a, b = { x: 0, y: 0 }) {
|
|
6
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
7
|
+
}
|
|
8
|
+
function distanceFromPoint(r, p) {
|
|
9
|
+
let x = 0;
|
|
10
|
+
let y = 0;
|
|
11
|
+
if (p.x < r.x) x = r.x - p.x;
|
|
12
|
+
else if (p.x > r.maxX) x = p.x - r.maxX;
|
|
13
|
+
if (p.y < r.y) y = r.y - p.y;
|
|
14
|
+
else if (p.y > r.maxY) y = p.y - r.maxY;
|
|
15
|
+
return { x, y, value: distance({ x, y }) };
|
|
16
|
+
}
|
|
17
|
+
function distanceFromRect(a, b) {
|
|
18
|
+
if (intersects(a, b)) return { x: 0, y: 0, value: 0 };
|
|
19
|
+
const left = a.x < b.x ? a : b;
|
|
20
|
+
const right = b.x < a.x ? a : b;
|
|
21
|
+
const upper = a.y < b.y ? a : b;
|
|
22
|
+
const lower = b.y < a.y ? a : b;
|
|
23
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
24
|
+
x = Math.max(0, x);
|
|
25
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
26
|
+
y = Math.max(0, y);
|
|
27
|
+
return { x, y, value: distance({ x, y }) };
|
|
28
|
+
}
|
|
29
|
+
function distanceBtwEdges(a, b) {
|
|
30
|
+
return {
|
|
31
|
+
left: b.x - a.x,
|
|
32
|
+
top: b.y - a.y,
|
|
33
|
+
right: a.maxX - b.maxX,
|
|
34
|
+
bottom: a.maxY - b.maxY
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
distance,
|
|
39
|
+
distanceBtwEdges,
|
|
40
|
+
distanceFromPoint,
|
|
41
|
+
distanceFromRect
|
|
42
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point, RectInit, Size } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare const isSizeEqual: (a: Size, b: Size | undefined) => boolean;
|
|
4
|
+
declare const isPointEqual: (a: Point, b: Point | undefined) => boolean;
|
|
5
|
+
declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
|
6
|
+
|
|
7
|
+
export { isPointEqual, isRectEqual, isSizeEqual };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Point, RectInit, Size } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare const isSizeEqual: (a: Size, b: Size | undefined) => boolean;
|
|
4
|
+
declare const isPointEqual: (a: Point, b: Point | undefined) => boolean;
|
|
5
|
+
declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
|
6
|
+
|
|
7
|
+
export { isPointEqual, isRectEqual, isSizeEqual };
|
package/dist/equality.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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/equality.ts
|
|
21
|
+
var equality_exports = {};
|
|
22
|
+
__export(equality_exports, {
|
|
23
|
+
isPointEqual: () => isPointEqual,
|
|
24
|
+
isRectEqual: () => isRectEqual,
|
|
25
|
+
isSizeEqual: () => isSizeEqual
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(equality_exports);
|
|
28
|
+
var isSizeEqual = (a, b) => {
|
|
29
|
+
return a.width === b?.width && a.height === b?.height;
|
|
30
|
+
};
|
|
31
|
+
var isPointEqual = (a, b) => {
|
|
32
|
+
return a.x === b?.x && a.y === b?.y;
|
|
33
|
+
};
|
|
34
|
+
var isRectEqual = (a, b) => {
|
|
35
|
+
return isPointEqual(a, b) && isSizeEqual(a, b);
|
|
36
|
+
};
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
isPointEqual,
|
|
40
|
+
isRectEqual,
|
|
41
|
+
isSizeEqual
|
|
42
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/equality.ts
|
|
4
|
+
var isSizeEqual = (a, b) => {
|
|
5
|
+
return a.width === b?.width && a.height === b?.height;
|
|
6
|
+
};
|
|
7
|
+
var isPointEqual = (a, b) => {
|
|
8
|
+
return a.x === b?.x && a.y === b?.y;
|
|
9
|
+
};
|
|
10
|
+
var isRectEqual = (a, b) => {
|
|
11
|
+
return isPointEqual(a, b) && isSizeEqual(a, b);
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
isPointEqual,
|
|
15
|
+
isRectEqual,
|
|
16
|
+
isSizeEqual
|
|
17
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Rect } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
4
|
+
type ElementRectOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
7
|
+
*/
|
|
8
|
+
excludeScrollbar?: boolean | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to exclude the element's borders from the calculation.
|
|
11
|
+
*/
|
|
12
|
+
excludeBorders?: boolean | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { type ElementRectOptions, getElementRect };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Rect } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
4
|
+
type ElementRectOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
7
|
+
*/
|
|
8
|
+
excludeScrollbar?: boolean | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to exclude the element's borders from the calculation.
|
|
11
|
+
*/
|
|
12
|
+
excludeBorders?: boolean | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { type ElementRectOptions, getElementRect };
|