@zag-js/rect-utils 2.0.0-next.3 → 2.0.0-next.4
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.mts +2 -5
- package/dist/align.d.ts +2 -5
- package/dist/align.js +27 -44
- package/dist/align.mjs +23 -19
- package/dist/angle.d.mts +2 -5
- package/dist/angle.d.ts +2 -5
- package/dist/angle.js +8 -32
- package/dist/angle.mjs +4 -7
- package/dist/clamp.d.mts +8 -11
- package/dist/clamp.d.ts +8 -11
- package/dist/clamp.js +23 -46
- package/dist/clamp.mjs +18 -20
- package/dist/closest.d.mts +4 -7
- package/dist/closest.d.ts +4 -7
- package/dist/closest.js +35 -62
- package/dist/closest.mjs +29 -35
- package/dist/compass.d.mts +1 -3
- package/dist/compass.d.ts +1 -3
- package/dist/compass.js +4 -18
- package/dist/compass.mjs +1 -0
- package/dist/constrain.d.mts +2 -5
- package/dist/constrain.d.ts +2 -5
- package/dist/constrain.js +12 -37
- package/dist/constrain.mjs +8 -12
- package/dist/contains.d.mts +4 -7
- package/dist/contains.d.ts +4 -7
- package/dist/contains.js +11 -36
- package/dist/contains.mjs +5 -9
- package/dist/distance.d.mts +7 -10
- package/dist/distance.d.ts +7 -10
- package/dist/distance.js +55 -60
- package/dist/distance.mjs +48 -32
- package/dist/equality.d.mts +4 -7
- package/dist/equality.d.ts +4 -7
- package/dist/equality.js +13 -38
- package/dist/equality.mjs +7 -11
- package/dist/from-element.d.mts +12 -15
- package/dist/from-element.d.ts +12 -15
- package/dist/from-element.js +39 -58
- package/dist/from-element.mjs +35 -33
- package/dist/from-points.d.mts +2 -5
- package/dist/from-points.d.ts +2 -5
- package/dist/from-points.js +18 -36
- package/dist/from-points.mjs +14 -11
- package/dist/from-range.d.mts +2 -5
- package/dist/from-range.d.ts +2 -5
- package/dist/from-range.js +25 -46
- package/dist/from-range.mjs +19 -19
- package/dist/from-rotation.d.mts +4 -7
- package/dist/from-rotation.d.ts +4 -7
- package/dist/from-rotation.js +31 -56
- package/dist/from-rotation.mjs +25 -29
- package/dist/from-window.d.mts +13 -16
- package/dist/from-window.d.ts +13 -16
- package/dist/from-window.js +29 -44
- package/dist/from-window.mjs +24 -18
- package/dist/index.d.mts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +91 -61
- package/dist/index.mjs +20 -21
- package/dist/interact.d.mts +34 -37
- package/dist/interact.d.ts +34 -37
- package/dist/interact.js +414 -350
- package/dist/interact.mjs +396 -311
- package/dist/intersection.d.mts +4 -7
- package/dist/intersection.d.ts +4 -7
- package/dist/intersection.js +34 -45
- package/dist/intersection.mjs +28 -18
- package/dist/operations.d.mts +6 -9
- package/dist/operations.d.ts +6 -9
- package/dist/operations.js +38 -57
- package/dist/operations.mjs +30 -28
- package/dist/polygon.d.mts +6 -9
- package/dist/polygon.d.ts +6 -9
- package/dist/polygon.js +73 -82
- package/dist/polygon.mjs +67 -55
- package/dist/rect.d.mts +55 -58
- package/dist/rect.d.ts +55 -58
- package/dist/rect.js +88 -117
- package/dist/rect.mjs +70 -78
- package/dist/types.d.mts +42 -46
- package/dist/types.d.ts +42 -46
- package/dist/types.js +4 -18
- package/dist/types.mjs +1 -0
- package/dist/union.d.mts +2 -5
- package/dist/union.d.ts +2 -5
- package/dist/union.js +16 -39
- package/dist/union.mjs +12 -14
- package/package.json +2 -2
package/dist/constrain.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { RectInit } from
|
|
2
|
-
|
|
3
|
-
declare const constrainRect: (rect: RectInit, boundary: RectInit) => RectInit;
|
|
4
|
-
|
|
5
|
-
export { constrainRect };
|
|
1
|
+
import { RectInit } from "./types.js";
|
|
2
|
+
export declare const constrainRect: (rect: RectInit, boundary: RectInit) => RectInit;
|
package/dist/constrain.js
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
height: Math.min(rect.height, boundary.height)
|
|
34
|
-
};
|
|
5
|
+
// src/constrain.ts
|
|
6
|
+
const constrainRect = (rect, boundary) => {
|
|
7
|
+
return {
|
|
8
|
+
x: Math.max(boundary.x, Math.min(rect.x, boundary.x + boundary.width - rect.width)),
|
|
9
|
+
y: Math.max(boundary.y, Math.min(rect.y, boundary.y + boundary.height - rect.height)),
|
|
10
|
+
width: Math.min(rect.width, boundary.width),
|
|
11
|
+
height: Math.min(rect.height, boundary.height)
|
|
12
|
+
};
|
|
35
13
|
};
|
|
36
|
-
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
constrainRect
|
|
39
|
-
});
|
|
14
|
+
exports.constrainRect = constrainRect;
|
package/dist/constrain.mjs
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
// src/constrain.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
height: Math.min(rect.height, boundary.height)
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
constrainRect
|
|
2
|
+
const constrainRect = (rect, boundary) => {
|
|
3
|
+
return {
|
|
4
|
+
x: Math.max(boundary.x, Math.min(rect.x, boundary.x + boundary.width - rect.width)),
|
|
5
|
+
y: Math.max(boundary.y, Math.min(rect.y, boundary.y + boundary.height - rect.height)),
|
|
6
|
+
width: Math.min(rect.width, boundary.width),
|
|
7
|
+
height: Math.min(rect.height, boundary.height)
|
|
8
|
+
};
|
|
14
9
|
};
|
|
10
|
+
export { constrainRect };
|
package/dist/contains.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
6
|
-
|
|
7
|
-
export { contains, containsPoint, containsRect };
|
|
1
|
+
import { Point, Rect } from "./types.mjs";
|
|
2
|
+
export declare function containsPoint(r: Rect, p: Point): boolean;
|
|
3
|
+
export declare function containsRect(a: Rect, b: Rect): boolean;
|
|
4
|
+
export declare function contains(r: Rect, v: Rect | Point): boolean;
|
package/dist/contains.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
6
|
-
|
|
7
|
-
export { contains, containsPoint, containsRect };
|
|
1
|
+
import { Point, Rect } from "./types.js";
|
|
2
|
+
export declare function containsPoint(r: Rect, p: Point): boolean;
|
|
3
|
+
export declare function containsRect(a: Rect, b: Rect): boolean;
|
|
4
|
+
export declare function contains(r: Rect, v: Rect | Point): boolean;
|
package/dist/contains.js
CHANGED
|
@@ -1,43 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
4
|
});
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/contains.ts
|
|
29
7
|
function containsPoint(r, p) {
|
|
30
|
-
|
|
8
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
31
9
|
}
|
|
32
10
|
function containsRect(a, b) {
|
|
33
|
-
|
|
11
|
+
return Object.values(require_rect.getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
34
12
|
}
|
|
35
13
|
function contains(r, v) {
|
|
36
|
-
|
|
14
|
+
return require_rect.isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
37
15
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
containsPoint,
|
|
42
|
-
containsRect
|
|
43
|
-
});
|
|
16
|
+
exports.contains = contains;
|
|
17
|
+
exports.containsPoint = containsPoint;
|
|
18
|
+
exports.containsRect = containsRect;
|
package/dist/contains.mjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
// src/contains.ts
|
|
2
1
|
import { getRectCorners, isRect } from "./rect.mjs";
|
|
2
|
+
// src/contains.ts
|
|
3
3
|
function containsPoint(r, p) {
|
|
4
|
-
|
|
4
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
5
5
|
}
|
|
6
6
|
function containsRect(a, b) {
|
|
7
|
-
|
|
7
|
+
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
8
8
|
}
|
|
9
9
|
function contains(r, v) {
|
|
10
|
-
|
|
10
|
+
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
11
11
|
}
|
|
12
|
-
export {
|
|
13
|
-
contains,
|
|
14
|
-
containsPoint,
|
|
15
|
-
containsRect
|
|
16
|
-
};
|
|
12
|
+
export { contains, containsPoint, containsRect };
|
package/dist/distance.d.mts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { Point, Rect, RectSide } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: number;
|
|
1
|
+
import { Point, Rect, RectSide } from "./types.mjs";
|
|
2
|
+
export interface DistanceValue extends Point {
|
|
3
|
+
value: number;
|
|
5
4
|
}
|
|
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 };
|
|
5
|
+
export declare function distance(a: Point, b?: Point): number;
|
|
6
|
+
export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
7
|
+
export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
8
|
+
export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
package/dist/distance.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { Point, Rect, RectSide } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: number;
|
|
1
|
+
import { Point, Rect, RectSide } from "./types.js";
|
|
2
|
+
export interface DistanceValue extends Point {
|
|
3
|
+
value: number;
|
|
5
4
|
}
|
|
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 };
|
|
5
|
+
export declare function distance(a: Point, b?: Point): number;
|
|
6
|
+
export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
7
|
+
export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
8
|
+
export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
package/dist/distance.js
CHANGED
|
@@ -1,68 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
4
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function distance(a, b = {
|
|
31
|
-
|
|
5
|
+
const require_intersection = require("./intersection.js");
|
|
6
|
+
// src/distance.ts
|
|
7
|
+
function distance(a, b = {
|
|
8
|
+
x: 0,
|
|
9
|
+
y: 0
|
|
10
|
+
}) {
|
|
11
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
32
12
|
}
|
|
33
13
|
function distanceFromPoint(r, p) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
14
|
+
let x = 0;
|
|
15
|
+
let y = 0;
|
|
16
|
+
if (p.x < r.x) x = r.x - p.x;
|
|
17
|
+
else if (p.x > r.maxX) x = p.x - r.maxX;
|
|
18
|
+
if (p.y < r.y) y = r.y - p.y;
|
|
19
|
+
else if (p.y > r.maxY) y = p.y - r.maxY;
|
|
20
|
+
return {
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
value: distance({
|
|
24
|
+
x,
|
|
25
|
+
y
|
|
26
|
+
})
|
|
27
|
+
};
|
|
41
28
|
}
|
|
42
29
|
function distanceFromRect(a, b) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
if (require_intersection.intersects(a, b)) return {
|
|
31
|
+
x: 0,
|
|
32
|
+
y: 0,
|
|
33
|
+
value: 0
|
|
34
|
+
};
|
|
35
|
+
const left = a.x < b.x ? a : b;
|
|
36
|
+
const right = b.x < a.x ? a : b;
|
|
37
|
+
const upper = a.y < b.y ? a : b;
|
|
38
|
+
const lower = b.y < a.y ? a : b;
|
|
39
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
40
|
+
x = Math.max(0, x);
|
|
41
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
42
|
+
y = Math.max(0, y);
|
|
43
|
+
return {
|
|
44
|
+
x,
|
|
45
|
+
y,
|
|
46
|
+
value: distance({
|
|
47
|
+
x,
|
|
48
|
+
y
|
|
49
|
+
})
|
|
50
|
+
};
|
|
53
51
|
}
|
|
54
52
|
function distanceBtwEdges(a, b) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
return {
|
|
54
|
+
left: b.x - a.x,
|
|
55
|
+
top: b.y - a.y,
|
|
56
|
+
right: a.maxX - b.maxX,
|
|
57
|
+
bottom: a.maxY - b.maxY
|
|
58
|
+
};
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
distanceFromPoint,
|
|
67
|
-
distanceFromRect
|
|
68
|
-
});
|
|
60
|
+
exports.distance = distance;
|
|
61
|
+
exports.distanceBtwEdges = distanceBtwEdges;
|
|
62
|
+
exports.distanceFromPoint = distanceFromPoint;
|
|
63
|
+
exports.distanceFromRect = distanceFromRect;
|
package/dist/distance.mjs
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
// src/distance.ts
|
|
2
1
|
import { intersects } from "./intersection.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
// src/distance.ts
|
|
3
|
+
function distance(a, b = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 0
|
|
6
|
+
}) {
|
|
7
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
5
8
|
}
|
|
6
9
|
function distanceFromPoint(r, p) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let x = 0;
|
|
11
|
+
let y = 0;
|
|
12
|
+
if (p.x < r.x) x = r.x - p.x;
|
|
13
|
+
else if (p.x > r.maxX) x = p.x - r.maxX;
|
|
14
|
+
if (p.y < r.y) y = r.y - p.y;
|
|
15
|
+
else if (p.y > r.maxY) y = p.y - r.maxY;
|
|
16
|
+
return {
|
|
17
|
+
x,
|
|
18
|
+
y,
|
|
19
|
+
value: distance({
|
|
20
|
+
x,
|
|
21
|
+
y
|
|
22
|
+
})
|
|
23
|
+
};
|
|
14
24
|
}
|
|
15
25
|
function distanceFromRect(a, b) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (intersects(a, b)) return {
|
|
27
|
+
x: 0,
|
|
28
|
+
y: 0,
|
|
29
|
+
value: 0
|
|
30
|
+
};
|
|
31
|
+
const left = a.x < b.x ? a : b;
|
|
32
|
+
const right = b.x < a.x ? a : b;
|
|
33
|
+
const upper = a.y < b.y ? a : b;
|
|
34
|
+
const lower = b.y < a.y ? a : b;
|
|
35
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
36
|
+
x = Math.max(0, x);
|
|
37
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
38
|
+
y = Math.max(0, y);
|
|
39
|
+
return {
|
|
40
|
+
x,
|
|
41
|
+
y,
|
|
42
|
+
value: distance({
|
|
43
|
+
x,
|
|
44
|
+
y
|
|
45
|
+
})
|
|
46
|
+
};
|
|
26
47
|
}
|
|
27
48
|
function distanceBtwEdges(a, b) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
return {
|
|
50
|
+
left: b.x - a.x,
|
|
51
|
+
top: b.y - a.y,
|
|
52
|
+
right: a.maxX - b.maxX,
|
|
53
|
+
bottom: a.maxY - b.maxY
|
|
54
|
+
};
|
|
34
55
|
}
|
|
35
|
-
export {
|
|
36
|
-
distance,
|
|
37
|
-
distanceBtwEdges,
|
|
38
|
-
distanceFromPoint,
|
|
39
|
-
distanceFromRect
|
|
40
|
-
};
|
|
56
|
+
export { distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
package/dist/equality.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { Point, RectInit, Size } from
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
declare const
|
|
5
|
-
declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
|
6
|
-
|
|
7
|
-
export { isPointEqual, isRectEqual, isSizeEqual };
|
|
1
|
+
import { Point, RectInit, Size } from "./types.mjs";
|
|
2
|
+
export declare const isSizeEqual: (a: Size, b: Size | undefined) => boolean;
|
|
3
|
+
export declare const isPointEqual: (a: Point, b: Point | undefined) => boolean;
|
|
4
|
+
export declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
package/dist/equality.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { Point, RectInit, Size } from
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
declare const
|
|
5
|
-
declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
|
6
|
-
|
|
7
|
-
export { isPointEqual, isRectEqual, isSizeEqual };
|
|
1
|
+
import { Point, RectInit, Size } from "./types.js";
|
|
2
|
+
export declare const isSizeEqual: (a: Size, b: Size | undefined) => boolean;
|
|
3
|
+
export declare const isPointEqual: (a: Point, b: Point | undefined) => boolean;
|
|
4
|
+
export declare const isRectEqual: (a: RectInit, b: RectInit | undefined) => boolean;
|
package/dist/equality.js
CHANGED
|
@@ -1,42 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
4
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
// src/equality.ts
|
|
6
|
+
const isSizeEqual = (a, b) => {
|
|
7
|
+
return a.width === b?.width && a.height === b?.height;
|
|
30
8
|
};
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
const isPointEqual = (a, b) => {
|
|
10
|
+
return a.x === b?.x && a.y === b?.y;
|
|
33
11
|
};
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
const isRectEqual = (a, b) => {
|
|
13
|
+
return isPointEqual(a, b) && isSizeEqual(a, b);
|
|
36
14
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
isRectEqual,
|
|
41
|
-
isSizeEqual
|
|
42
|
-
});
|
|
15
|
+
exports.isPointEqual = isPointEqual;
|
|
16
|
+
exports.isRectEqual = isRectEqual;
|
|
17
|
+
exports.isSizeEqual = isSizeEqual;
|
package/dist/equality.mjs
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
// src/equality.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const isSizeEqual = (a, b) => {
|
|
3
|
+
return a.width === b?.width && a.height === b?.height;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const isPointEqual = (a, b) => {
|
|
6
|
+
return a.x === b?.x && a.y === b?.y;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
isPointEqual,
|
|
13
|
-
isRectEqual,
|
|
14
|
-
isSizeEqual
|
|
8
|
+
const isRectEqual = (a, b) => {
|
|
9
|
+
return isPointEqual(a, b) && isSizeEqual(a, b);
|
|
15
10
|
};
|
|
11
|
+
export { isPointEqual, isRectEqual, isSizeEqual };
|
package/dist/from-element.d.mts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { type ElementRectOptions, getElementRect };
|
|
1
|
+
import { Rect } from "./types.mjs";
|
|
2
|
+
export declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
3
|
+
export type ElementRectOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
6
|
+
*/
|
|
7
|
+
excludeScrollbar?: boolean | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to exclude the element's borders from the calculation.
|
|
10
|
+
*/
|
|
11
|
+
excludeBorders?: boolean | undefined;
|
|
12
|
+
};
|
package/dist/from-element.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { type ElementRectOptions, getElementRect };
|
|
1
|
+
import { Rect } from "./types.js";
|
|
2
|
+
export declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
3
|
+
export type ElementRectOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
6
|
+
*/
|
|
7
|
+
excludeScrollbar?: boolean | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to exclude the element's borders from the calculation.
|
|
10
|
+
*/
|
|
11
|
+
excludeBorders?: boolean | undefined;
|
|
12
|
+
};
|