@zag-js/rect-utils 2.0.0-next.2 → 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/align.d.mts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
4
|
-
|
|
5
|
-
export { alignRect };
|
|
1
|
+
import { AlignOptions, Rect } from "./types.mjs";
|
|
2
|
+
export declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
package/dist/align.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
4
|
-
|
|
5
|
-
export { alignRect };
|
|
1
|
+
import { AlignOptions, Rect } from "./types.js";
|
|
2
|
+
export declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
package/dist/align.js
CHANGED
|
@@ -1,51 +1,34 @@
|
|
|
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/align.ts
|
|
21
|
-
var align_exports = {};
|
|
22
|
-
__export(align_exports, {
|
|
23
|
-
alignRect: () => alignRect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
5
|
+
// src/align.ts
|
|
26
6
|
function hAlign(a, ref, h) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
let x = ref.minX;
|
|
8
|
+
if (h === "left-inside") x = ref.minX;
|
|
9
|
+
if (h === "left-outside") x = ref.minX - ref.width;
|
|
10
|
+
if (h === "right-inside") x = ref.maxX - ref.width;
|
|
11
|
+
if (h === "right-outside") x = ref.maxX;
|
|
12
|
+
if (h === "center") x = ref.midX - ref.width / 2;
|
|
13
|
+
return {
|
|
14
|
+
...a,
|
|
15
|
+
x
|
|
16
|
+
};
|
|
34
17
|
}
|
|
35
18
|
function vAlign(a, ref, v) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
let y = ref.minY;
|
|
20
|
+
if (v === "top-inside") y = ref.minY;
|
|
21
|
+
if (v === "top-outside") y = ref.minY - a.height;
|
|
22
|
+
if (v === "bottom-inside") y = ref.maxY - a.height;
|
|
23
|
+
if (v === "bottom-outside") y = ref.maxY;
|
|
24
|
+
if (v === "center") y = ref.midY - a.height / 2;
|
|
25
|
+
return {
|
|
26
|
+
...a,
|
|
27
|
+
y
|
|
28
|
+
};
|
|
43
29
|
}
|
|
44
30
|
function alignRect(a, ref, options) {
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
const { h, v } = options;
|
|
32
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
0 && (module.exports = {
|
|
50
|
-
alignRect
|
|
51
|
-
});
|
|
34
|
+
exports.alignRect = alignRect;
|
package/dist/align.mjs
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
// src/align.ts
|
|
2
2
|
function hAlign(a, ref, h) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
let x = ref.minX;
|
|
4
|
+
if (h === "left-inside") x = ref.minX;
|
|
5
|
+
if (h === "left-outside") x = ref.minX - ref.width;
|
|
6
|
+
if (h === "right-inside") x = ref.maxX - ref.width;
|
|
7
|
+
if (h === "right-outside") x = ref.maxX;
|
|
8
|
+
if (h === "center") x = ref.midX - ref.width / 2;
|
|
9
|
+
return {
|
|
10
|
+
...a,
|
|
11
|
+
x
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
function vAlign(a, ref, v) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
let y = ref.minY;
|
|
16
|
+
if (v === "top-inside") y = ref.minY;
|
|
17
|
+
if (v === "top-outside") y = ref.minY - a.height;
|
|
18
|
+
if (v === "bottom-inside") y = ref.maxY - a.height;
|
|
19
|
+
if (v === "bottom-outside") y = ref.maxY;
|
|
20
|
+
if (v === "center") y = ref.midY - a.height / 2;
|
|
21
|
+
return {
|
|
22
|
+
...a,
|
|
23
|
+
y
|
|
24
|
+
};
|
|
19
25
|
}
|
|
20
26
|
function alignRect(a, ref, options) {
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
const { h, v } = options;
|
|
28
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
23
29
|
}
|
|
24
|
-
export {
|
|
25
|
-
alignRect
|
|
26
|
-
};
|
|
30
|
+
export { alignRect };
|
package/dist/angle.d.mts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function getPointAngle(rect: Rect, point: Point, reference?: Point): number;
|
|
4
|
-
|
|
5
|
-
export { getPointAngle };
|
|
1
|
+
import { Point, Rect } from "./types.mjs";
|
|
2
|
+
export declare function getPointAngle(rect: Rect, point: Point, reference?: Point): number;
|
package/dist/angle.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function getPointAngle(rect: Rect, point: Point, reference?: Point): number;
|
|
4
|
-
|
|
5
|
-
export { getPointAngle };
|
|
1
|
+
import { Point, Rect } from "./types.js";
|
|
2
|
+
export declare function getPointAngle(rect: Rect, point: Point, reference?: Point): number;
|
package/dist/angle.js
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
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/angle.ts
|
|
21
|
-
var angle_exports = {};
|
|
22
|
-
__export(angle_exports, {
|
|
23
|
-
getPointAngle: () => getPointAngle
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
5
|
+
// src/angle.ts
|
|
26
6
|
function getPointAngle(rect, point, reference = rect.center) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return 360 - deg;
|
|
7
|
+
const x = point.x - reference.x;
|
|
8
|
+
const y = point.y - reference.y;
|
|
9
|
+
return 360 - (Math.atan2(x, y) * (180 / Math.PI) + 180);
|
|
31
10
|
}
|
|
32
|
-
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
getPointAngle
|
|
35
|
-
});
|
|
11
|
+
exports.getPointAngle = getPointAngle;
|
package/dist/angle.mjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// src/angle.ts
|
|
2
2
|
function getPointAngle(rect, point, reference = rect.center) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return 360 - deg;
|
|
3
|
+
const x = point.x - reference.x;
|
|
4
|
+
const y = point.y - reference.y;
|
|
5
|
+
return 360 - (Math.atan2(x, y) * (180 / Math.PI) + 180);
|
|
7
6
|
}
|
|
8
|
-
export {
|
|
9
|
-
getPointAngle
|
|
10
|
-
};
|
|
7
|
+
export { getPointAngle };
|
package/dist/clamp.d.mts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Point,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit, Size } from "./types.mjs";
|
|
2
|
+
export declare const clampPoint: (position: Point, size: Size, boundaryRect: RectInit) => {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
};
|
|
7
|
-
declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { clampPoint, clampSize };
|
|
6
|
+
export declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
package/dist/clamp.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Point,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit, Size } from "./types.js";
|
|
2
|
+
export declare const clampPoint: (position: Point, size: Size, boundaryRect: RectInit) => {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
};
|
|
7
|
-
declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { clampPoint, clampSize };
|
|
6
|
+
export declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
package/dist/clamp.js
CHANGED
|
@@ -1,51 +1,28 @@
|
|
|
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/clamp.ts
|
|
21
|
-
var clamp_exports = {};
|
|
22
|
-
__export(clamp_exports, {
|
|
23
|
-
clampPoint: () => clampPoint,
|
|
24
|
-
clampSize: () => clampSize
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
25
4
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
// src/clamp.ts
|
|
6
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
7
|
+
const clampPoint = (position, size, boundaryRect) => {
|
|
8
|
+
return {
|
|
9
|
+
x: clamp(position.x, boundaryRect.x, boundaryRect.x + boundaryRect.width - size.width),
|
|
10
|
+
y: clamp(position.y, boundaryRect.y, boundaryRect.y + boundaryRect.height - size.height)
|
|
11
|
+
};
|
|
32
12
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
const defaultMinSize = {
|
|
14
|
+
width: 0,
|
|
15
|
+
height: 0
|
|
36
16
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
const defaultMaxSize = {
|
|
18
|
+
width: 1e400,
|
|
19
|
+
height: 1e400
|
|
40
20
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
const clampSize = (size, minSize = defaultMinSize, maxSize = defaultMaxSize) => {
|
|
22
|
+
return {
|
|
23
|
+
width: Math.min(Math.max(size.width, minSize.width), maxSize.width),
|
|
24
|
+
height: Math.min(Math.max(size.height, minSize.height), maxSize.height)
|
|
25
|
+
};
|
|
46
26
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
clampPoint,
|
|
50
|
-
clampSize
|
|
51
|
-
});
|
|
27
|
+
exports.clampPoint = clampPoint;
|
|
28
|
+
exports.clampSize = clampSize;
|
package/dist/clamp.mjs
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
// src/clamp.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
3
|
+
const clampPoint = (position, size, boundaryRect) => {
|
|
4
|
+
return {
|
|
5
|
+
x: clamp(position.x, boundaryRect.x, boundaryRect.x + boundaryRect.width - size.width),
|
|
6
|
+
y: clamp(position.y, boundaryRect.y, boundaryRect.y + boundaryRect.height - size.height)
|
|
7
|
+
};
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const defaultMinSize = {
|
|
10
|
+
width: 0,
|
|
11
|
+
height: 0
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const defaultMaxSize = {
|
|
14
|
+
width: 1e400,
|
|
15
|
+
height: 1e400
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
clampPoint,
|
|
24
|
-
clampSize
|
|
17
|
+
const clampSize = (size, minSize = defaultMinSize, maxSize = defaultMaxSize) => {
|
|
18
|
+
return {
|
|
19
|
+
width: Math.min(Math.max(size.width, minSize.width), maxSize.width),
|
|
20
|
+
height: Math.min(Math.max(size.height, minSize.height), maxSize.height)
|
|
21
|
+
};
|
|
25
22
|
};
|
|
23
|
+
export { clampPoint, clampSize };
|
package/dist/closest.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { Point, Rect, RectSide } from
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
6
|
-
|
|
7
|
-
export { closest, closestSideToPoint, closestSideToRect };
|
|
1
|
+
import { Point, Rect, RectSide } from "./types.mjs";
|
|
2
|
+
export declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
3
|
+
export declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
4
|
+
export declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
package/dist/closest.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { Point, Rect, RectSide } from
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
6
|
-
|
|
7
|
-
export { closest, closestSideToPoint, closestSideToRect };
|
|
1
|
+
import { Point, Rect, RectSide } from "./types.js";
|
|
2
|
+
export declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
3
|
+
export declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
4
|
+
export declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
package/dist/closest.js
CHANGED
|
@@ -1,69 +1,42 @@
|
|
|
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/closest.ts
|
|
21
|
-
var closest_exports = {};
|
|
22
|
-
__export(closest_exports, {
|
|
23
|
-
closest: () => closest,
|
|
24
|
-
closestSideToPoint: () => closestSideToPoint,
|
|
25
|
-
closestSideToRect: () => closestSideToRect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
26
4
|
});
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const require_distance = require("./distance.js");
|
|
6
|
+
// src/closest.ts
|
|
29
7
|
function closest(...pts) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
return (a) => {
|
|
9
|
+
const ds = pts.map((b) => require_distance.distance(b, a));
|
|
10
|
+
const c = Math.min.apply(Math, ds);
|
|
11
|
+
return pts[ds.indexOf(c)];
|
|
12
|
+
};
|
|
35
13
|
}
|
|
36
14
|
function closestSideToRect(ref, r) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
if (r.maxX <= ref.minX) return "left";
|
|
16
|
+
if (r.minX >= ref.maxX) return "right";
|
|
17
|
+
if (r.maxY <= ref.minY) return "top";
|
|
18
|
+
if (r.minY >= ref.maxY) return "bottom";
|
|
19
|
+
return "left";
|
|
42
20
|
}
|
|
43
21
|
function closestSideToPoint(ref, p) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return side;
|
|
22
|
+
const { x, y } = p;
|
|
23
|
+
const dl = x - ref.minX;
|
|
24
|
+
const dr = ref.maxX - x;
|
|
25
|
+
const dt = y - ref.minY;
|
|
26
|
+
const db = ref.maxY - y;
|
|
27
|
+
let closest = dl;
|
|
28
|
+
let side = "left";
|
|
29
|
+
if (dr < closest) {
|
|
30
|
+
closest = dr;
|
|
31
|
+
side = "right";
|
|
32
|
+
}
|
|
33
|
+
if (dt < closest) {
|
|
34
|
+
closest = dt;
|
|
35
|
+
side = "top";
|
|
36
|
+
}
|
|
37
|
+
if (db < closest) side = "bottom";
|
|
38
|
+
return side;
|
|
63
39
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
closestSideToPoint,
|
|
68
|
-
closestSideToRect
|
|
69
|
-
});
|
|
40
|
+
exports.closest = closest;
|
|
41
|
+
exports.closestSideToPoint = closestSideToPoint;
|
|
42
|
+
exports.closestSideToRect = closestSideToRect;
|
package/dist/closest.mjs
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
|
-
// src/closest.ts
|
|
2
1
|
import { distance } from "./distance.mjs";
|
|
2
|
+
// src/closest.ts
|
|
3
3
|
function closest(...pts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
9
|
}
|
|
10
10
|
function closestSideToRect(ref, r) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (r.maxX <= ref.minX) return "left";
|
|
12
|
+
if (r.minX >= ref.maxX) return "right";
|
|
13
|
+
if (r.maxY <= ref.minY) return "top";
|
|
14
|
+
if (r.minY >= ref.maxY) return "bottom";
|
|
15
|
+
return "left";
|
|
16
16
|
}
|
|
17
17
|
function closestSideToPoint(ref, p) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return side;
|
|
18
|
+
const { x, y } = p;
|
|
19
|
+
const dl = x - ref.minX;
|
|
20
|
+
const dr = ref.maxX - x;
|
|
21
|
+
const dt = y - ref.minY;
|
|
22
|
+
const db = ref.maxY - y;
|
|
23
|
+
let closest = dl;
|
|
24
|
+
let side = "left";
|
|
25
|
+
if (dr < closest) {
|
|
26
|
+
closest = dr;
|
|
27
|
+
side = "right";
|
|
28
|
+
}
|
|
29
|
+
if (dt < closest) {
|
|
30
|
+
closest = dt;
|
|
31
|
+
side = "top";
|
|
32
|
+
}
|
|
33
|
+
if (db < closest) side = "bottom";
|
|
34
|
+
return side;
|
|
37
35
|
}
|
|
38
|
-
export {
|
|
39
|
-
closest,
|
|
40
|
-
closestSideToPoint,
|
|
41
|
-
closestSideToRect
|
|
42
|
-
};
|
|
36
|
+
export { closest, closestSideToPoint, closestSideToRect };
|
package/dist/compass.d.mts
CHANGED
package/dist/compass.d.ts
CHANGED
package/dist/compass.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/compass.ts
|
|
17
|
-
var compass_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(compass_exports);
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
package/dist/compass.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/constrain.d.mts
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.mjs";
|
|
2
|
+
export declare const constrainRect: (rect: RectInit, boundary: RectInit) => RectInit;
|