@zag-js/rect-utils 0.10.2 → 0.10.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.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/align.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
5
|
-
type AlignOptions = {
|
|
1
|
+
import type { Rect } from "./rect";
|
|
2
|
+
export declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
3
|
+
export type AlignOptions = {
|
|
6
4
|
h: HAlign;
|
|
7
5
|
v: VAlign;
|
|
8
6
|
};
|
|
9
|
-
type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
10
|
-
type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
|
11
|
-
|
|
12
|
-
export { AlignOptions, HAlign, VAlign, alignRect };
|
|
7
|
+
export type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
8
|
+
export type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
package/dist/align.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
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);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
19
4
|
|
|
20
|
-
// src/align.ts
|
|
21
|
-
var align_exports = {};
|
|
22
|
-
__export(align_exports, {
|
|
23
|
-
alignRect: () => alignRect
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(align_exports);
|
|
26
5
|
function hAlign(a, ref, h) {
|
|
27
6
|
let x = ref.minX;
|
|
28
7
|
if (h === "left-inside") {
|
|
@@ -65,7 +44,5 @@ function alignRect(a, ref, options) {
|
|
|
65
44
|
const { h, v } = options;
|
|
66
45
|
return vAlign(hAlign(a, ref, h), ref, v);
|
|
67
46
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
alignRect
|
|
71
|
-
});
|
|
47
|
+
|
|
48
|
+
exports.alignRect = alignRect;
|
package/dist/align.mjs
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function hAlign(a, ref, h) {
|
|
2
|
+
let x = ref.minX;
|
|
3
|
+
if (h === "left-inside") {
|
|
4
|
+
x = ref.minX;
|
|
5
|
+
}
|
|
6
|
+
if (h === "left-outside") {
|
|
7
|
+
x = ref.minX - ref.width;
|
|
8
|
+
}
|
|
9
|
+
if (h === "right-inside") {
|
|
10
|
+
x = ref.maxX - ref.width;
|
|
11
|
+
}
|
|
12
|
+
if (h === "right-outside") {
|
|
13
|
+
x = ref.maxX;
|
|
14
|
+
}
|
|
15
|
+
if (h === "center") {
|
|
16
|
+
x = ref.midX - ref.width / 2;
|
|
17
|
+
}
|
|
18
|
+
return { ...a, x };
|
|
19
|
+
}
|
|
20
|
+
function vAlign(a, ref, v) {
|
|
21
|
+
let y = ref.minY;
|
|
22
|
+
if (v === "top-inside") {
|
|
23
|
+
y = ref.minY;
|
|
24
|
+
}
|
|
25
|
+
if (v === "top-outside") {
|
|
26
|
+
y = ref.minY - a.height;
|
|
27
|
+
}
|
|
28
|
+
if (v === "bottom-inside") {
|
|
29
|
+
y = ref.maxY - a.height;
|
|
30
|
+
}
|
|
31
|
+
if (v === "bottom-outside") {
|
|
32
|
+
y = ref.maxY;
|
|
33
|
+
}
|
|
34
|
+
if (v === "center") {
|
|
35
|
+
y = ref.midY - a.height / 2;
|
|
36
|
+
}
|
|
37
|
+
return { ...a, y };
|
|
38
|
+
}
|
|
39
|
+
function alignRect(a, ref, options) {
|
|
40
|
+
const { h, v } = options;
|
|
41
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { alignRect };
|
package/dist/closest.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import { Point, RectSide } from
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
7
|
-
|
|
8
|
-
export { closest, closestSideToPoint, closestSideToRect };
|
|
1
|
+
import type { Rect } from "./rect";
|
|
2
|
+
import type { Point, RectSide } from "./types";
|
|
3
|
+
export declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
4
|
+
export declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
5
|
+
export declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
package/dist/closest.js
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
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 closest_exports = {};
|
|
22
|
-
__export(closest_exports, {
|
|
23
|
-
closest: () => closest,
|
|
24
|
-
closestSideToPoint: () => closestSideToPoint,
|
|
25
|
-
closestSideToRect: () => closestSideToRect
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(closest_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
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
|
-
}
|
|
5
|
+
const distance = require('./distance.js');
|
|
33
6
|
|
|
34
|
-
// src/closest.ts
|
|
35
7
|
function closest(...pts) {
|
|
36
8
|
return (a) => {
|
|
37
|
-
const ds = pts.map((b) => distance(b, a));
|
|
9
|
+
const ds = pts.map((b) => distance.distance(b, a));
|
|
38
10
|
const c = Math.min.apply(Math, ds);
|
|
39
11
|
return pts[ds.indexOf(c)];
|
|
40
12
|
};
|
|
@@ -75,9 +47,7 @@ function closestSideToPoint(ref, p) {
|
|
|
75
47
|
}
|
|
76
48
|
return side;
|
|
77
49
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
closestSideToRect
|
|
83
|
-
});
|
|
50
|
+
|
|
51
|
+
exports.closest = closest;
|
|
52
|
+
exports.closestSideToPoint = closestSideToPoint;
|
|
53
|
+
exports.closestSideToRect = closestSideToRect;
|
package/dist/closest.mjs
CHANGED
|
@@ -1,13 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
import { distance } from './distance.mjs';
|
|
2
|
+
|
|
3
|
+
function closest(...pts) {
|
|
4
|
+
return (a) => {
|
|
5
|
+
const ds = pts.map((b) => distance(b, a));
|
|
6
|
+
const c = Math.min.apply(Math, ds);
|
|
7
|
+
return pts[ds.indexOf(c)];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function closestSideToRect(ref, r) {
|
|
11
|
+
if (r.maxX <= ref.minX) {
|
|
12
|
+
return "left";
|
|
13
|
+
}
|
|
14
|
+
if (r.minX >= ref.maxX) {
|
|
15
|
+
return "right";
|
|
16
|
+
}
|
|
17
|
+
if (r.maxY <= ref.minY) {
|
|
18
|
+
return "top";
|
|
19
|
+
}
|
|
20
|
+
if (r.minY >= ref.maxY) {
|
|
21
|
+
return "bottom";
|
|
22
|
+
}
|
|
23
|
+
return "left";
|
|
24
|
+
}
|
|
25
|
+
function closestSideToPoint(ref, p) {
|
|
26
|
+
const { x, y } = p;
|
|
27
|
+
const dl = x - ref.minX;
|
|
28
|
+
const dr = ref.maxX - x;
|
|
29
|
+
const dt = y - ref.minY;
|
|
30
|
+
const db = ref.maxY - y;
|
|
31
|
+
let closest2 = dl;
|
|
32
|
+
let side = "left";
|
|
33
|
+
if (dr < closest2) {
|
|
34
|
+
closest2 = dr;
|
|
35
|
+
side = "right";
|
|
36
|
+
}
|
|
37
|
+
if (dt < closest2) {
|
|
38
|
+
closest2 = dt;
|
|
39
|
+
side = "top";
|
|
40
|
+
}
|
|
41
|
+
if (db < closest2) {
|
|
42
|
+
side = "bottom";
|
|
43
|
+
}
|
|
44
|
+
return side;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { closest, closestSideToPoint, closestSideToRect };
|
package/dist/contains.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import { Point } from
|
|
3
|
-
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
6
|
-
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
7
|
-
|
|
8
|
-
export { contains, containsPoint, containsRect };
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point } from "./types";
|
|
3
|
+
export declare function containsPoint(r: Rect, p: Point): boolean;
|
|
4
|
+
export declare function containsRect(a: Rect, b: Rect): boolean;
|
|
5
|
+
export declare function contains(r: Rect, v: Rect | Point): boolean;
|
package/dist/contains.js
CHANGED
|
@@ -1,58 +1,19 @@
|
|
|
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 contains_exports = {};
|
|
22
|
-
__export(contains_exports, {
|
|
23
|
-
contains: () => contains,
|
|
24
|
-
containsPoint: () => containsPoint,
|
|
25
|
-
containsRect: () => containsRect
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(contains_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
var point = (x, y) => ({ x, y });
|
|
31
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
32
|
-
function isRect(v) {
|
|
33
|
-
return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
|
|
34
|
-
}
|
|
35
|
-
function getRectCorners(v) {
|
|
36
|
-
const top = point(v.minX, v.minY);
|
|
37
|
-
const right = point(v.maxX, v.minY);
|
|
38
|
-
const bottom = point(v.maxX, v.maxY);
|
|
39
|
-
const left = point(v.minX, v.maxY);
|
|
40
|
-
return { top, right, bottom, left };
|
|
41
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
42
6
|
|
|
43
|
-
// src/contains.ts
|
|
44
7
|
function containsPoint(r, p) {
|
|
45
8
|
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
46
9
|
}
|
|
47
10
|
function containsRect(a, b) {
|
|
48
|
-
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
11
|
+
return Object.values(rect.getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
49
12
|
}
|
|
50
13
|
function contains(r, v) {
|
|
51
|
-
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
14
|
+
return rect.isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
52
15
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
containsRect
|
|
58
|
-
});
|
|
16
|
+
|
|
17
|
+
exports.contains = contains;
|
|
18
|
+
exports.containsPoint = containsPoint;
|
|
19
|
+
exports.containsRect = containsRect;
|
package/dist/contains.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
containsRect
|
|
11
|
-
}
|
|
1
|
+
import { getRectCorners, isRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function containsPoint(r, p) {
|
|
4
|
+
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
5
|
+
}
|
|
6
|
+
function containsRect(a, b) {
|
|
7
|
+
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
8
|
+
}
|
|
9
|
+
function contains(r, v) {
|
|
10
|
+
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { contains, containsPoint, containsRect };
|
package/dist/distance.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import { Point, RectSide } from
|
|
3
|
-
|
|
4
|
-
type DistanceValue = Point & {
|
|
1
|
+
import type { Rect } from "./rect";
|
|
2
|
+
import type { Point, RectSide } from "./types";
|
|
3
|
+
export type DistanceValue = Point & {
|
|
5
4
|
value: number;
|
|
6
5
|
};
|
|
7
|
-
declare function distance(a: Point, b?: Point): number;
|
|
8
|
-
declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
9
|
-
declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
10
|
-
declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
|
11
|
-
|
|
12
|
-
export { DistanceValue, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
|
6
|
+
export declare function distance(a: Point, b?: Point): number;
|
|
7
|
+
export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
8
|
+
export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
9
|
+
export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
package/dist/distance.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
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 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);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
29
4
|
|
|
30
|
-
|
|
31
|
-
function intersects(a, b) {
|
|
32
|
-
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
33
|
-
}
|
|
5
|
+
const intersection = require('./intersection.js');
|
|
34
6
|
|
|
35
|
-
// src/distance.ts
|
|
36
7
|
function distance(a, b = { x: 0, y: 0 }) {
|
|
37
8
|
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
38
9
|
}
|
|
@@ -50,7 +21,7 @@ function distanceFromPoint(r, p) {
|
|
|
50
21
|
return { x, y, value: distance({ x, y }) };
|
|
51
22
|
}
|
|
52
23
|
function distanceFromRect(a, b) {
|
|
53
|
-
if (intersects(a, b))
|
|
24
|
+
if (intersection.intersects(a, b))
|
|
54
25
|
return { x: 0, y: 0, value: 0 };
|
|
55
26
|
const left = a.x < b.x ? a : b;
|
|
56
27
|
const right = b.x < a.x ? a : b;
|
|
@@ -70,10 +41,8 @@ function distanceBtwEdges(a, b) {
|
|
|
70
41
|
bottom: a.maxY - b.maxY
|
|
71
42
|
};
|
|
72
43
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
distanceFromRect
|
|
79
|
-
});
|
|
44
|
+
|
|
45
|
+
exports.distance = distance;
|
|
46
|
+
exports.distanceBtwEdges = distanceBtwEdges;
|
|
47
|
+
exports.distanceFromPoint = distanceFromPoint;
|
|
48
|
+
exports.distanceFromRect = distanceFromRect;
|
package/dist/distance.mjs
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { intersects } from './intersection.mjs';
|
|
2
|
+
|
|
3
|
+
function distance(a, b = { x: 0, y: 0 }) {
|
|
4
|
+
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
5
|
+
}
|
|
6
|
+
function distanceFromPoint(r, p) {
|
|
7
|
+
let x = 0;
|
|
8
|
+
let y = 0;
|
|
9
|
+
if (p.x < r.x)
|
|
10
|
+
x = r.x - p.x;
|
|
11
|
+
else if (p.x > r.maxX)
|
|
12
|
+
x = p.x - r.maxX;
|
|
13
|
+
if (p.y < r.y)
|
|
14
|
+
y = r.y - p.y;
|
|
15
|
+
else if (p.y > r.maxY)
|
|
16
|
+
y = p.y - r.maxY;
|
|
17
|
+
return { x, y, value: distance({ x, y }) };
|
|
18
|
+
}
|
|
19
|
+
function distanceFromRect(a, b) {
|
|
20
|
+
if (intersects(a, b))
|
|
21
|
+
return { x: 0, y: 0, value: 0 };
|
|
22
|
+
const left = a.x < b.x ? a : b;
|
|
23
|
+
const right = b.x < a.x ? a : b;
|
|
24
|
+
const upper = a.y < b.y ? a : b;
|
|
25
|
+
const lower = b.y < a.y ? a : b;
|
|
26
|
+
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
27
|
+
x = Math.max(0, x);
|
|
28
|
+
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
29
|
+
y = Math.max(0, y);
|
|
30
|
+
return { x, y, value: distance({ x, y }) };
|
|
31
|
+
}
|
|
32
|
+
function distanceBtwEdges(a, b) {
|
|
33
|
+
return {
|
|
34
|
+
left: b.x - a.x,
|
|
35
|
+
top: b.y - a.y,
|
|
36
|
+
right: a.maxX - b.maxX,
|
|
37
|
+
bottom: a.maxY - b.maxY
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
package/dist/from-element.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
5
|
-
type ElementRectOptions = {
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
export declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
3
|
+
export type ElementRectOptions = {
|
|
6
4
|
/**
|
|
7
5
|
* Whether to exclude the element's scrollbar size from the calculation.
|
|
8
6
|
*/
|
|
@@ -12,5 +10,3 @@ type ElementRectOptions = {
|
|
|
12
10
|
*/
|
|
13
11
|
excludeBorders?: boolean;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
export { ElementRectOptions, getElementRect };
|
package/dist/from-element.js
CHANGED
|
@@ -1,52 +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 from_element_exports = {};
|
|
22
|
-
__export(from_element_exports, {
|
|
23
|
-
getElementRect: () => getElementRect
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(from_element_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 rect = require('./rect.js');
|
|
47
6
|
|
|
48
|
-
|
|
49
|
-
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
50
8
|
function getCacheComputedStyle(el) {
|
|
51
9
|
if (!styleCache.has(el)) {
|
|
52
10
|
const win = el.ownerDocument.defaultView || window;
|
|
@@ -55,7 +13,7 @@ function getCacheComputedStyle(el) {
|
|
|
55
13
|
return styleCache.get(el);
|
|
56
14
|
}
|
|
57
15
|
function getElementRect(el, opts = {}) {
|
|
58
|
-
return createRect(getClientRect(el, opts));
|
|
16
|
+
return rect.createRect(getClientRect(el, opts));
|
|
59
17
|
}
|
|
60
18
|
function getClientRect(el, opts = {}) {
|
|
61
19
|
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
@@ -79,9 +37,7 @@ function getClientRect(el, opts = {}) {
|
|
|
79
37
|
}
|
|
80
38
|
return r;
|
|
81
39
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
getElementRect
|
|
87
|
-
});
|
|
40
|
+
const px = (v) => parseFloat(v.replace("px", ""));
|
|
41
|
+
const sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
42
|
+
|
|
43
|
+
exports.getElementRect = getElementRect;
|
package/dist/from-element.mjs
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function getCacheComputedStyle(el) {
|
|
5
|
+
if (!styleCache.has(el)) {
|
|
6
|
+
const win = el.ownerDocument.defaultView || window;
|
|
7
|
+
styleCache.set(el, win.getComputedStyle(el));
|
|
8
|
+
}
|
|
9
|
+
return styleCache.get(el);
|
|
10
|
+
}
|
|
11
|
+
function getElementRect(el, opts = {}) {
|
|
12
|
+
return createRect(getClientRect(el, opts));
|
|
13
|
+
}
|
|
14
|
+
function getClientRect(el, opts = {}) {
|
|
15
|
+
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
16
|
+
const { x, y, width, height } = el.getBoundingClientRect();
|
|
17
|
+
const r = { x, y, width, height };
|
|
18
|
+
const style = getCacheComputedStyle(el);
|
|
19
|
+
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
20
|
+
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
21
|
+
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
22
|
+
if (excludeBorders) {
|
|
23
|
+
r.width -= borderXWidth;
|
|
24
|
+
r.height -= borderYWidth;
|
|
25
|
+
r.x += px(borderLeftWidth);
|
|
26
|
+
r.y += px(borderTopWidth);
|
|
27
|
+
}
|
|
28
|
+
if (excludeScrollbar) {
|
|
29
|
+
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
30
|
+
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
31
|
+
r.width -= scrollbarWidth;
|
|
32
|
+
r.height -= scrollbarHeight;
|
|
33
|
+
}
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
const px = (v) => parseFloat(v.replace("px", ""));
|
|
37
|
+
const sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
38
|
+
|
|
39
|
+
export { getElementRect };
|
package/dist/from-points.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
import { Point } from
|
|
3
|
-
|
|
4
|
-
declare function getRectFromPoints(...pts: Point[]): Rect;
|
|
5
|
-
|
|
6
|
-
export { getRectFromPoints };
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point } from "./types";
|
|
3
|
+
export declare function getRectFromPoints(...pts: Point[]): Rect;
|