@zag-js/rect-utils 1.46.0 → 1.48.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/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.mjs +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.mjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +15 -0
- package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.mjs +10 -0
- package/dist/affine-transform.d.mts +36 -39
- package/dist/affine-transform.d.ts +36 -39
- package/dist/affine-transform.js +189 -187
- package/dist/affine-transform.mjs +185 -164
- 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 -21
- 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 -9
- 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 -22
- 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 -37
- package/dist/compass.d.mts +4 -7
- package/dist/compass.d.ts +4 -7
- package/dist/compass.js +48 -48
- package/dist/compass.mjs +43 -24
- 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 -14
- 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 -11
- 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 -34
- 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 -13
- 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 -35
- 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 -13
- 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 -21
- 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 -31
- 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 -20
- package/dist/index.d.mts +22 -22
- package/dist/index.d.ts +22 -22
- package/dist/index.js +72 -63
- package/dist/index.mjs +21 -22
- 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 -20
- 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 -30
- 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 -57
- package/dist/rect.d.mts +49 -52
- package/dist/rect.d.ts +49 -52
- package/dist/rect.js +57 -82
- package/dist/rect.mjs +46 -52
- package/dist/resize.d.mts +3 -6
- package/dist/resize.d.ts +3 -6
- package/dist/resize.js +73 -102
- package/dist/resize.mjs +68 -78
- package/dist/types.d.mts +45 -49
- package/dist/types.d.ts +45 -49
- 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 -16
- package/package.json +3 -3
- package/dist/chunk-QZ7TP4HQ.mjs +0 -7
package/dist/operations.js
CHANGED
|
@@ -1,66 +1,47 @@
|
|
|
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/operations.ts
|
|
21
|
-
var operations_exports = {};
|
|
22
|
-
__export(operations_exports, {
|
|
23
|
-
expand: () => expand,
|
|
24
|
-
inset: () => inset,
|
|
25
|
-
isSymmetric: () => isSymmetric,
|
|
26
|
-
shift: () => shift,
|
|
27
|
-
shrink: () => shrink
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
28
4
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/operations.ts
|
|
7
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
32
8
|
function inset(r, i) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = isSymmetric(i) ? {
|
|
10
|
+
left: i.dx,
|
|
11
|
+
right: i.dx,
|
|
12
|
+
top: i.dy,
|
|
13
|
+
bottom: i.dy
|
|
14
|
+
} : i;
|
|
15
|
+
return require_rect.createRect({
|
|
16
|
+
x: r.x + left,
|
|
17
|
+
y: r.y + top,
|
|
18
|
+
width: r.width - left - right,
|
|
19
|
+
height: r.height - top - bottom
|
|
20
|
+
});
|
|
41
21
|
}
|
|
42
22
|
function expand(r, v) {
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
return inset(r, typeof v === "number" ? {
|
|
24
|
+
dx: -v,
|
|
25
|
+
dy: -v
|
|
26
|
+
} : v);
|
|
45
27
|
}
|
|
46
28
|
function shrink(r, v) {
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
return inset(r, typeof v === "number" ? {
|
|
30
|
+
dx: -v,
|
|
31
|
+
dy: -v
|
|
32
|
+
} : v);
|
|
49
33
|
}
|
|
50
34
|
function shift(r, o) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
35
|
+
const { x = 0, y = 0 } = o;
|
|
36
|
+
return require_rect.createRect({
|
|
37
|
+
x: r.x + x,
|
|
38
|
+
y: r.y + y,
|
|
39
|
+
width: r.width,
|
|
40
|
+
height: r.height
|
|
41
|
+
});
|
|
58
42
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
shift,
|
|
65
|
-
shrink
|
|
66
|
-
});
|
|
43
|
+
exports.expand = expand;
|
|
44
|
+
exports.inset = inset;
|
|
45
|
+
exports.isSymmetric = isSymmetric;
|
|
46
|
+
exports.shift = shift;
|
|
47
|
+
exports.shrink = shrink;
|
package/dist/operations.mjs
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
-
|
|
3
|
-
// src/operations.ts
|
|
4
1
|
import { createRect } from "./rect.mjs";
|
|
5
|
-
|
|
2
|
+
// src/operations.ts
|
|
3
|
+
const isSymmetric = (v) => "dx" in v || "dy" in v;
|
|
6
4
|
function inset(r, i) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = isSymmetric(i) ? {
|
|
6
|
+
left: i.dx,
|
|
7
|
+
right: i.dx,
|
|
8
|
+
top: i.dy,
|
|
9
|
+
bottom: i.dy
|
|
10
|
+
} : i;
|
|
11
|
+
return createRect({
|
|
12
|
+
x: r.x + left,
|
|
13
|
+
y: r.y + top,
|
|
14
|
+
width: r.width - left - right,
|
|
15
|
+
height: r.height - top - bottom
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
18
|
function expand(r, v) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
return inset(r, typeof v === "number" ? {
|
|
20
|
+
dx: -v,
|
|
21
|
+
dy: -v
|
|
22
|
+
} : v);
|
|
19
23
|
}
|
|
20
24
|
function shrink(r, v) {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
return inset(r, typeof v === "number" ? {
|
|
26
|
+
dx: -v,
|
|
27
|
+
dy: -v
|
|
28
|
+
} : v);
|
|
23
29
|
}
|
|
24
30
|
function shift(r, o) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const { x = 0, y = 0 } = o;
|
|
32
|
+
return createRect({
|
|
33
|
+
x: r.x + x,
|
|
34
|
+
y: r.y + y,
|
|
35
|
+
width: r.width,
|
|
36
|
+
height: r.height
|
|
37
|
+
});
|
|
32
38
|
}
|
|
33
|
-
export {
|
|
34
|
-
expand,
|
|
35
|
-
inset,
|
|
36
|
-
isSymmetric,
|
|
37
|
-
shift,
|
|
38
|
-
shrink
|
|
39
|
-
};
|
|
39
|
+
export { expand, inset, isSymmetric, shift, shrink };
|
package/dist/polygon.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Point, RectInit } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit } from "./types.mjs";
|
|
2
|
+
export declare function getElementPolygon(rectValue: RectInit, placement: string): {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
}[] | undefined;
|
|
7
|
-
declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
8
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
9
|
-
|
|
10
|
-
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
|
6
|
+
export declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
7
|
+
export declare function debugPolygon(polygon: Point[]): () => void;
|
package/dist/polygon.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Point, RectInit } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y: number;
|
|
1
|
+
import { Point, RectInit } from "./types.js";
|
|
2
|
+
export declare function getElementPolygon(rectValue: RectInit, placement: string): {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
6
5
|
}[] | undefined;
|
|
7
|
-
declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
8
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
9
|
-
|
|
10
|
-
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
|
6
|
+
export declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
7
|
+
export declare function debugPolygon(polygon: Point[]): () => void;
|
package/dist/polygon.js
CHANGED
|
@@ -1,91 +1,82 @@
|
|
|
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/polygon.ts
|
|
21
|
-
var polygon_exports = {};
|
|
22
|
-
__export(polygon_exports, {
|
|
23
|
-
debugPolygon: () => debugPolygon,
|
|
24
|
-
getElementPolygon: () => getElementPolygon,
|
|
25
|
-
isPointInPolygon: () => isPointInPolygon
|
|
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/polygon.ts
|
|
29
7
|
function getElementPolygon(rectValue, placement) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const rect = require_rect.createRect(rectValue);
|
|
9
|
+
const { top, right, left, bottom } = require_rect.getRectCorners(rect);
|
|
10
|
+
const [base] = placement.split("-");
|
|
11
|
+
return {
|
|
12
|
+
top: [
|
|
13
|
+
left,
|
|
14
|
+
top,
|
|
15
|
+
right,
|
|
16
|
+
bottom
|
|
17
|
+
],
|
|
18
|
+
right: [
|
|
19
|
+
top,
|
|
20
|
+
right,
|
|
21
|
+
bottom,
|
|
22
|
+
left
|
|
23
|
+
],
|
|
24
|
+
bottom: [
|
|
25
|
+
top,
|
|
26
|
+
left,
|
|
27
|
+
bottom,
|
|
28
|
+
right
|
|
29
|
+
],
|
|
30
|
+
left: [
|
|
31
|
+
right,
|
|
32
|
+
top,
|
|
33
|
+
left,
|
|
34
|
+
bottom
|
|
35
|
+
]
|
|
36
|
+
}[base];
|
|
39
37
|
}
|
|
40
38
|
function isPointInPolygon(polygon, point) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return c;
|
|
39
|
+
const { x, y } = point;
|
|
40
|
+
let c = false;
|
|
41
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
42
|
+
const xi = polygon[i].x;
|
|
43
|
+
const yi = polygon[i].y;
|
|
44
|
+
const xj = polygon[j].x;
|
|
45
|
+
const yj = polygon[j].y;
|
|
46
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) c = !c;
|
|
47
|
+
}
|
|
48
|
+
return c;
|
|
53
49
|
}
|
|
54
50
|
function createPolygonElement() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
document.body.appendChild(svg);
|
|
76
|
-
return polygon;
|
|
51
|
+
const id = "debug-polygon";
|
|
52
|
+
const existingPolygon = document.getElementById(id);
|
|
53
|
+
if (existingPolygon) return existingPolygon;
|
|
54
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
55
|
+
Object.assign(svg.style, {
|
|
56
|
+
top: "0",
|
|
57
|
+
left: "0",
|
|
58
|
+
width: "100%",
|
|
59
|
+
height: "100%",
|
|
60
|
+
opacity: "0.15",
|
|
61
|
+
position: "fixed",
|
|
62
|
+
pointerEvents: "none",
|
|
63
|
+
fill: "red"
|
|
64
|
+
});
|
|
65
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
66
|
+
polygon.setAttribute("id", id);
|
|
67
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
68
|
+
svg.appendChild(polygon);
|
|
69
|
+
document.body.appendChild(svg);
|
|
70
|
+
return polygon;
|
|
77
71
|
}
|
|
78
72
|
function debugPolygon(polygon) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
const el = createPolygonElement();
|
|
74
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
75
|
+
el.setAttribute("points", points);
|
|
76
|
+
return () => {
|
|
77
|
+
el.remove();
|
|
78
|
+
};
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
getElementPolygon,
|
|
90
|
-
isPointInPolygon
|
|
91
|
-
});
|
|
80
|
+
exports.debugPolygon = debugPolygon;
|
|
81
|
+
exports.getElementPolygon = getElementPolygon;
|
|
82
|
+
exports.isPointInPolygon = isPointInPolygon;
|
package/dist/polygon.mjs
CHANGED
|
@@ -1,66 +1,76 @@
|
|
|
1
|
-
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
-
|
|
3
|
-
// src/polygon.ts
|
|
4
1
|
import { createRect, getRectCorners } from "./rect.mjs";
|
|
2
|
+
// src/polygon.ts
|
|
5
3
|
function getElementPolygon(rectValue, placement) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const rect = createRect(rectValue);
|
|
5
|
+
const { top, right, left, bottom } = getRectCorners(rect);
|
|
6
|
+
const [base] = placement.split("-");
|
|
7
|
+
return {
|
|
8
|
+
top: [
|
|
9
|
+
left,
|
|
10
|
+
top,
|
|
11
|
+
right,
|
|
12
|
+
bottom
|
|
13
|
+
],
|
|
14
|
+
right: [
|
|
15
|
+
top,
|
|
16
|
+
right,
|
|
17
|
+
bottom,
|
|
18
|
+
left
|
|
19
|
+
],
|
|
20
|
+
bottom: [
|
|
21
|
+
top,
|
|
22
|
+
left,
|
|
23
|
+
bottom,
|
|
24
|
+
right
|
|
25
|
+
],
|
|
26
|
+
left: [
|
|
27
|
+
right,
|
|
28
|
+
top,
|
|
29
|
+
left,
|
|
30
|
+
bottom
|
|
31
|
+
]
|
|
32
|
+
}[base];
|
|
15
33
|
}
|
|
16
34
|
function isPointInPolygon(polygon, point) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
return c;
|
|
35
|
+
const { x, y } = point;
|
|
36
|
+
let c = false;
|
|
37
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
38
|
+
const xi = polygon[i].x;
|
|
39
|
+
const yi = polygon[i].y;
|
|
40
|
+
const xj = polygon[j].x;
|
|
41
|
+
const yj = polygon[j].y;
|
|
42
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) c = !c;
|
|
43
|
+
}
|
|
44
|
+
return c;
|
|
29
45
|
}
|
|
30
46
|
function createPolygonElement() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
document.body.appendChild(svg);
|
|
52
|
-
return polygon;
|
|
47
|
+
const id = "debug-polygon";
|
|
48
|
+
const existingPolygon = document.getElementById(id);
|
|
49
|
+
if (existingPolygon) return existingPolygon;
|
|
50
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
51
|
+
Object.assign(svg.style, {
|
|
52
|
+
top: "0",
|
|
53
|
+
left: "0",
|
|
54
|
+
width: "100%",
|
|
55
|
+
height: "100%",
|
|
56
|
+
opacity: "0.15",
|
|
57
|
+
position: "fixed",
|
|
58
|
+
pointerEvents: "none",
|
|
59
|
+
fill: "red"
|
|
60
|
+
});
|
|
61
|
+
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
62
|
+
polygon.setAttribute("id", id);
|
|
63
|
+
polygon.setAttribute("points", "0,0 0,0");
|
|
64
|
+
svg.appendChild(polygon);
|
|
65
|
+
document.body.appendChild(svg);
|
|
66
|
+
return polygon;
|
|
53
67
|
}
|
|
54
68
|
function debugPolygon(polygon) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
const el = createPolygonElement();
|
|
70
|
+
const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
|
|
71
|
+
el.setAttribute("points", points);
|
|
72
|
+
return () => {
|
|
73
|
+
el.remove();
|
|
74
|
+
};
|
|
61
75
|
}
|
|
62
|
-
export {
|
|
63
|
-
debugPolygon,
|
|
64
|
-
getElementPolygon,
|
|
65
|
-
isPointInPolygon
|
|
66
|
-
};
|
|
76
|
+
export { debugPolygon, getElementPolygon, isPointInPolygon };
|
package/dist/rect.d.mts
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
|
-
import { Point,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Point, Rect, RectEdge, RectInit } from "./types.mjs";
|
|
2
|
+
export declare const createPoint: (x: number, y: number) => {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const subtractPoints: (a: Point, b: Point | null) => Point;
|
|
7
|
+
export declare const addPoints: (a: Point, b: Point) => {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function isPoint(v: any): v is Point;
|
|
12
|
+
export declare function createRect(r: RectInit): Rect;
|
|
13
|
+
export declare function isRect(v: any): v is Rect;
|
|
14
|
+
export declare function getRectCenters(v: Rect): {
|
|
15
|
+
top: {
|
|
4
16
|
x: number;
|
|
5
17
|
y: number;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
declare const addPoints: (a: Point, b: Point) => {
|
|
18
|
+
};
|
|
19
|
+
right: {
|
|
9
20
|
x: number;
|
|
10
21
|
y: number;
|
|
22
|
+
};
|
|
23
|
+
bottom: {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
left: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
};
|
|
11
31
|
};
|
|
12
|
-
declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
declare function getRectCorners(v: Rect): {
|
|
34
|
-
top: {
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
};
|
|
38
|
-
right: {
|
|
39
|
-
x: number;
|
|
40
|
-
y: number;
|
|
41
|
-
};
|
|
42
|
-
bottom: {
|
|
43
|
-
x: number;
|
|
44
|
-
y: number;
|
|
45
|
-
};
|
|
46
|
-
left: {
|
|
47
|
-
x: number;
|
|
48
|
-
y: number;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
declare function getRectEdges(v: Rect): {
|
|
52
|
-
top: RectEdge;
|
|
53
|
-
right: RectEdge;
|
|
54
|
-
bottom: RectEdge;
|
|
55
|
-
left: RectEdge;
|
|
32
|
+
export declare function getRectCorners(v: Rect): {
|
|
33
|
+
top: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
};
|
|
37
|
+
right: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
bottom: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
45
|
+
left: {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
};
|
|
56
49
|
};
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
export declare function getRectEdges(v: Rect): {
|
|
51
|
+
top: RectEdge;
|
|
52
|
+
right: RectEdge;
|
|
53
|
+
bottom: RectEdge;
|
|
54
|
+
left: RectEdge;
|
|
55
|
+
};
|