@zag-js/rect-utils 0.10.2 → 0.10.3
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/from-points.js
CHANGED
|
@@ -1,51 +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 from_points_exports = {};
|
|
22
|
-
__export(from_points_exports, {
|
|
23
|
-
getRectFromPoints: () => getRectFromPoints
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(from_points_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
|
-
// src/from-points.ts
|
|
49
7
|
function getRectFromPoints(...pts) {
|
|
50
8
|
const xs = pts.map((p) => p.x);
|
|
51
9
|
const ys = pts.map((p) => p.y);
|
|
@@ -53,9 +11,7 @@ function getRectFromPoints(...pts) {
|
|
|
53
11
|
const y = Math.min(...ys);
|
|
54
12
|
const width = Math.max(...xs) - x;
|
|
55
13
|
const height = Math.max(...ys) - y;
|
|
56
|
-
return createRect({ x, y, width, height });
|
|
14
|
+
return rect.createRect({ x, y, width, height });
|
|
57
15
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
getRectFromPoints
|
|
61
|
-
});
|
|
16
|
+
|
|
17
|
+
exports.getRectFromPoints = getRectFromPoints;
|
package/dist/from-points.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function getRectFromPoints(...pts) {
|
|
4
|
+
const xs = pts.map((p) => p.x);
|
|
5
|
+
const ys = pts.map((p) => p.y);
|
|
6
|
+
const x = Math.min(...xs);
|
|
7
|
+
const y = Math.min(...ys);
|
|
8
|
+
const width = Math.max(...xs) - x;
|
|
9
|
+
const height = Math.max(...ys) - y;
|
|
10
|
+
return createRect({ x, y, width, height });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { getRectFromPoints };
|
package/dist/from-range.d.ts
CHANGED
package/dist/from-range.js
CHANGED
|
@@ -1,143 +1,27 @@
|
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/from-range.ts
|
|
21
|
-
var from_range_exports = {};
|
|
22
|
-
__export(from_range_exports, {
|
|
23
|
-
fromRange: () => fromRange
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(from_range_exports);
|
|
26
|
-
|
|
27
|
-
// src/rect.ts
|
|
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
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/from-element.ts
|
|
49
|
-
var styleCache = /* @__PURE__ */ new WeakMap();
|
|
50
|
-
function getCacheComputedStyle(el) {
|
|
51
|
-
if (!styleCache.has(el)) {
|
|
52
|
-
const win = el.ownerDocument.defaultView || window;
|
|
53
|
-
styleCache.set(el, win.getComputedStyle(el));
|
|
54
|
-
}
|
|
55
|
-
return styleCache.get(el);
|
|
56
|
-
}
|
|
57
|
-
function getElementRect(el, opts = {}) {
|
|
58
|
-
return createRect(getClientRect(el, opts));
|
|
59
|
-
}
|
|
60
|
-
function getClientRect(el, opts = {}) {
|
|
61
|
-
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
62
|
-
const { x, y, width, height } = el.getBoundingClientRect();
|
|
63
|
-
const r = { x, y, width, height };
|
|
64
|
-
const style = getCacheComputedStyle(el);
|
|
65
|
-
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
66
|
-
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
67
|
-
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
68
|
-
if (excludeBorders) {
|
|
69
|
-
r.width -= borderXWidth;
|
|
70
|
-
r.height -= borderYWidth;
|
|
71
|
-
r.x += px(borderLeftWidth);
|
|
72
|
-
r.y += px(borderTopWidth);
|
|
73
|
-
}
|
|
74
|
-
if (excludeScrollbar) {
|
|
75
|
-
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
76
|
-
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
77
|
-
r.width -= scrollbarWidth;
|
|
78
|
-
r.height -= scrollbarHeight;
|
|
79
|
-
}
|
|
80
|
-
return r;
|
|
81
|
-
}
|
|
82
|
-
var px = (v) => parseFloat(v.replace("px", ""));
|
|
83
|
-
var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
1
|
+
'use strict';
|
|
84
2
|
|
|
85
|
-
|
|
86
|
-
function getRectFromPoints(...pts) {
|
|
87
|
-
const xs = pts.map((p) => p.x);
|
|
88
|
-
const ys = pts.map((p) => p.y);
|
|
89
|
-
const x = Math.min(...xs);
|
|
90
|
-
const y = Math.min(...ys);
|
|
91
|
-
const width = Math.max(...xs) - x;
|
|
92
|
-
const height = Math.max(...ys) - y;
|
|
93
|
-
return createRect({ x, y, width, height });
|
|
94
|
-
}
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
95
4
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const pMin = {
|
|
100
|
-
x: min.apply(
|
|
101
|
-
Math,
|
|
102
|
-
rs.map((r) => r.minX)
|
|
103
|
-
),
|
|
104
|
-
y: min.apply(
|
|
105
|
-
Math,
|
|
106
|
-
rs.map((r) => r.minY)
|
|
107
|
-
)
|
|
108
|
-
};
|
|
109
|
-
const pMax = {
|
|
110
|
-
x: max.apply(
|
|
111
|
-
Math,
|
|
112
|
-
rs.map((r) => r.maxX)
|
|
113
|
-
),
|
|
114
|
-
y: max.apply(
|
|
115
|
-
Math,
|
|
116
|
-
rs.map((r) => r.maxY)
|
|
117
|
-
)
|
|
118
|
-
};
|
|
119
|
-
return getRectFromPoints(pMin, pMax);
|
|
120
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
6
|
+
const fromElement = require('./from-element.js');
|
|
7
|
+
const union = require('./union.js');
|
|
121
8
|
|
|
122
|
-
// src/from-range.ts
|
|
123
9
|
function fromRange(range) {
|
|
124
10
|
let rs = [];
|
|
125
11
|
const rects = Array.from(range.getClientRects());
|
|
126
12
|
if (rects.length) {
|
|
127
|
-
rs = rs.concat(rects.map(createRect));
|
|
128
|
-
return union.apply(void 0, rs);
|
|
13
|
+
rs = rs.concat(rects.map(rect.createRect));
|
|
14
|
+
return union.union.apply(void 0, rs);
|
|
129
15
|
}
|
|
130
16
|
let start = range.startContainer;
|
|
131
17
|
if (start.nodeType === Node.TEXT_NODE) {
|
|
132
18
|
start = start.parentNode;
|
|
133
19
|
}
|
|
134
20
|
if (start instanceof HTMLElement) {
|
|
135
|
-
const r = getElementRect(start);
|
|
21
|
+
const r = fromElement.getElementRect(start);
|
|
136
22
|
rs.push({ ...r, x: r.maxX, width: 0 });
|
|
137
23
|
}
|
|
138
|
-
return union.apply(void 0, rs);
|
|
24
|
+
return union.union.apply(void 0, rs);
|
|
139
25
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
fromRange
|
|
143
|
-
});
|
|
26
|
+
|
|
27
|
+
exports.fromRange = fromRange;
|
package/dist/from-range.mjs
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
import { getElementRect } from './from-element.mjs';
|
|
3
|
+
import { union } from './union.mjs';
|
|
4
|
+
|
|
5
|
+
function fromRange(range) {
|
|
6
|
+
let rs = [];
|
|
7
|
+
const rects = Array.from(range.getClientRects());
|
|
8
|
+
if (rects.length) {
|
|
9
|
+
rs = rs.concat(rects.map(createRect));
|
|
10
|
+
return union.apply(void 0, rs);
|
|
11
|
+
}
|
|
12
|
+
let start = range.startContainer;
|
|
13
|
+
if (start.nodeType === Node.TEXT_NODE) {
|
|
14
|
+
start = start.parentNode;
|
|
15
|
+
}
|
|
16
|
+
if (start instanceof HTMLElement) {
|
|
17
|
+
const r = getElementRect(start);
|
|
18
|
+
rs.push({ ...r, x: r.maxX, width: 0 });
|
|
19
|
+
}
|
|
20
|
+
return union.apply(void 0, rs);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { fromRange };
|
package/dist/from-rotation.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 getRotationRect(r: Rect, deg: number): Rect;
|
|
7
|
-
|
|
8
|
-
export { getRotationRect, rotate, toRad };
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
import type { Point } from "./types";
|
|
3
|
+
export declare function toRad(d: number): number;
|
|
4
|
+
export declare function rotate(a: Point, d: number, c: Point): Point;
|
|
5
|
+
export declare function getRotationRect(r: Rect, deg: number): Rect;
|
package/dist/from-rotation.js
CHANGED
|
@@ -1,60 +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 from_rotation_exports = {};
|
|
22
|
-
__export(from_rotation_exports, {
|
|
23
|
-
getRotationRect: () => getRotationRect,
|
|
24
|
-
rotate: () => rotate,
|
|
25
|
-
toRad: () => toRad
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(from_rotation_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
4
|
|
|
29
|
-
|
|
30
|
-
var point = (x, y) => ({ x, y });
|
|
31
|
-
function createRect(r) {
|
|
32
|
-
const { x, y, width, height } = r;
|
|
33
|
-
const midX = x + width / 2;
|
|
34
|
-
const midY = y + height / 2;
|
|
35
|
-
return {
|
|
36
|
-
x,
|
|
37
|
-
y,
|
|
38
|
-
width,
|
|
39
|
-
height,
|
|
40
|
-
minX: x,
|
|
41
|
-
minY: y,
|
|
42
|
-
maxX: x + width,
|
|
43
|
-
maxY: y + height,
|
|
44
|
-
midX,
|
|
45
|
-
midY,
|
|
46
|
-
center: point(midX, midY)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function getRectCorners(v) {
|
|
50
|
-
const top = point(v.minX, v.minY);
|
|
51
|
-
const right = point(v.maxX, v.minY);
|
|
52
|
-
const bottom = point(v.maxX, v.maxY);
|
|
53
|
-
const left = point(v.minX, v.maxY);
|
|
54
|
-
return { top, right, bottom, left };
|
|
55
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
56
6
|
|
|
57
|
-
// src/from-rotation.ts
|
|
58
7
|
function toRad(d) {
|
|
59
8
|
return d % 360 * Math.PI / 180;
|
|
60
9
|
}
|
|
@@ -70,23 +19,21 @@ function rotate(a, d, c) {
|
|
|
70
19
|
};
|
|
71
20
|
}
|
|
72
21
|
function getRotationRect(r, deg) {
|
|
73
|
-
const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
22
|
+
const rr = Object.values(rect.getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
74
23
|
const xs = rr.map((p) => p.x);
|
|
75
24
|
const ys = rr.map((p) => p.y);
|
|
76
25
|
const minX = Math.min(...xs);
|
|
77
26
|
const minY = Math.min(...ys);
|
|
78
27
|
const maxX = Math.max(...xs);
|
|
79
28
|
const maxY = Math.max(...ys);
|
|
80
|
-
return createRect({
|
|
29
|
+
return rect.createRect({
|
|
81
30
|
x: minX,
|
|
82
31
|
y: minY,
|
|
83
32
|
width: maxX - minX,
|
|
84
33
|
height: maxY - minY
|
|
85
34
|
});
|
|
86
35
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
toRad
|
|
92
|
-
});
|
|
36
|
+
|
|
37
|
+
exports.getRotationRect = getRotationRect;
|
|
38
|
+
exports.rotate = rotate;
|
|
39
|
+
exports.toRad = toRad;
|
package/dist/from-rotation.mjs
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { getRectCorners, createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function toRad(d) {
|
|
4
|
+
return d % 360 * Math.PI / 180;
|
|
5
|
+
}
|
|
6
|
+
function rotate(a, d, c) {
|
|
7
|
+
const r = toRad(d);
|
|
8
|
+
const sin = Math.sin(r);
|
|
9
|
+
const cos = Math.cos(r);
|
|
10
|
+
const x = a.x - c.x;
|
|
11
|
+
const y = a.y - c.y;
|
|
12
|
+
return {
|
|
13
|
+
x: c.x + x * cos - y * sin,
|
|
14
|
+
y: c.y + x * sin + y * cos
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getRotationRect(r, deg) {
|
|
18
|
+
const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
19
|
+
const xs = rr.map((p) => p.x);
|
|
20
|
+
const ys = rr.map((p) => p.y);
|
|
21
|
+
const minX = Math.min(...xs);
|
|
22
|
+
const minY = Math.min(...ys);
|
|
23
|
+
const maxX = Math.max(...xs);
|
|
24
|
+
const maxY = Math.max(...ys);
|
|
25
|
+
return createRect({
|
|
26
|
+
x: minX,
|
|
27
|
+
y: minY,
|
|
28
|
+
width: maxX - minX,
|
|
29
|
+
height: maxY - minY
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { getRotationRect, rotate, toRad };
|
package/dist/from-window.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type WindowRectOptions = {
|
|
1
|
+
import { Rect } from "./rect";
|
|
2
|
+
export type WindowRectOptions = {
|
|
5
3
|
/**
|
|
6
4
|
* Whether to exclude the element's scrollbar size from the calculation.
|
|
7
5
|
*/
|
|
@@ -10,15 +8,13 @@ type WindowRectOptions = {
|
|
|
10
8
|
/**
|
|
11
9
|
* Creates a rectange from window object
|
|
12
10
|
*/
|
|
13
|
-
declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
11
|
+
export declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
14
12
|
/**
|
|
15
13
|
* Get the rect of the window with the option to exclude the scrollbar
|
|
16
14
|
*/
|
|
17
|
-
declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
15
|
+
export declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
18
16
|
x: number;
|
|
19
17
|
y: number;
|
|
20
18
|
width: number;
|
|
21
19
|
height: number;
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
export { WindowRectOptions, getViewportRect, getWindowRect };
|
package/dist/from-window.js
CHANGED
|
@@ -1,54 +1,11 @@
|
|
|
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_window_exports = {};
|
|
22
|
-
__export(from_window_exports, {
|
|
23
|
-
getViewportRect: () => getViewportRect,
|
|
24
|
-
getWindowRect: () => getWindowRect
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(from_window_exports);
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
27
4
|
|
|
28
|
-
|
|
29
|
-
var point = (x, y) => ({ x, y });
|
|
30
|
-
function createRect(r) {
|
|
31
|
-
const { x, y, width, height } = r;
|
|
32
|
-
const midX = x + width / 2;
|
|
33
|
-
const midY = y + height / 2;
|
|
34
|
-
return {
|
|
35
|
-
x,
|
|
36
|
-
y,
|
|
37
|
-
width,
|
|
38
|
-
height,
|
|
39
|
-
minX: x,
|
|
40
|
-
minY: y,
|
|
41
|
-
maxX: x + width,
|
|
42
|
-
maxY: y + height,
|
|
43
|
-
midX,
|
|
44
|
-
midY,
|
|
45
|
-
center: point(midX, midY)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
48
6
|
|
|
49
|
-
// src/from-window.ts
|
|
50
7
|
function getWindowRect(win, opts = {}) {
|
|
51
|
-
return createRect(getViewportRect(win, opts));
|
|
8
|
+
return rect.createRect(getViewportRect(win, opts));
|
|
52
9
|
}
|
|
53
10
|
function getViewportRect(win, opts) {
|
|
54
11
|
const { excludeScrollbar = false } = opts;
|
|
@@ -64,8 +21,6 @@ function getViewportRect(win, opts) {
|
|
|
64
21
|
}
|
|
65
22
|
return rect;
|
|
66
23
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
getWindowRect
|
|
71
|
-
});
|
|
24
|
+
|
|
25
|
+
exports.getViewportRect = getViewportRect;
|
|
26
|
+
exports.getWindowRect = getWindowRect;
|
package/dist/from-window.mjs
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { createRect } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function getWindowRect(win, opts = {}) {
|
|
4
|
+
return createRect(getViewportRect(win, opts));
|
|
5
|
+
}
|
|
6
|
+
function getViewportRect(win, opts) {
|
|
7
|
+
const { excludeScrollbar = false } = opts;
|
|
8
|
+
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
9
|
+
const width = visualViewport?.width || innerWidth;
|
|
10
|
+
const height = visualViewport?.height || innerHeight;
|
|
11
|
+
const rect = { x: 0, y: 0, width, height };
|
|
12
|
+
if (excludeScrollbar) {
|
|
13
|
+
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
14
|
+
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
15
|
+
rect.width -= scrollbarWidth;
|
|
16
|
+
rect.height -= scrollbarHeight;
|
|
17
|
+
}
|
|
18
|
+
return rect;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { getViewportRect, getWindowRect };
|
package/dist/get-polygon.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { RectValue } from
|
|
2
|
-
|
|
3
|
-
declare function getElementPolygon(rectValue: RectValue, placement: string): {
|
|
1
|
+
import type { RectValue } from "./types";
|
|
2
|
+
export declare function getElementPolygon(rectValue: RectValue, placement: string): {
|
|
4
3
|
x: number;
|
|
5
4
|
y: number;
|
|
6
5
|
}[] | undefined;
|
|
7
|
-
|
|
8
|
-
export { getElementPolygon };
|
package/dist/get-polygon.js
CHANGED
|
@@ -1,61 +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 get_polygon_exports = {};
|
|
22
|
-
__export(get_polygon_exports, {
|
|
23
|
-
getElementPolygon: () => getElementPolygon
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(get_polygon_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
|
-
}
|
|
47
|
-
function getRectCorners(v) {
|
|
48
|
-
const top = point(v.minX, v.minY);
|
|
49
|
-
const right = point(v.maxX, v.minY);
|
|
50
|
-
const bottom = point(v.maxX, v.maxY);
|
|
51
|
-
const left = point(v.minX, v.maxY);
|
|
52
|
-
return { top, right, bottom, left };
|
|
53
|
-
}
|
|
5
|
+
const rect = require('./rect.js');
|
|
54
6
|
|
|
55
|
-
// src/get-polygon.ts
|
|
56
7
|
function getElementPolygon(rectValue, placement) {
|
|
57
|
-
const rect = createRect(rectValue);
|
|
58
|
-
const { top, right, left, bottom } = getRectCorners(rect);
|
|
8
|
+
const rect$1 = rect.createRect(rectValue);
|
|
9
|
+
const { top, right, left, bottom } = rect.getRectCorners(rect$1);
|
|
59
10
|
const [base] = placement.split("-");
|
|
60
11
|
return {
|
|
61
12
|
top: [left, top, right, bottom],
|
|
@@ -64,7 +15,5 @@ function getElementPolygon(rectValue, placement) {
|
|
|
64
15
|
left: [right, top, left, bottom]
|
|
65
16
|
}[base];
|
|
66
17
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getElementPolygon
|
|
70
|
-
});
|
|
18
|
+
|
|
19
|
+
exports.getElementPolygon = getElementPolygon;
|
package/dist/get-polygon.mjs
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { createRect, getRectCorners } from './rect.mjs';
|
|
2
|
+
|
|
3
|
+
function getElementPolygon(rectValue, placement) {
|
|
4
|
+
const rect = createRect(rectValue);
|
|
5
|
+
const { top, right, left, bottom } = getRectCorners(rect);
|
|
6
|
+
const [base] = placement.split("-");
|
|
7
|
+
return {
|
|
8
|
+
top: [left, top, right, bottom],
|
|
9
|
+
right: [top, right, bottom, left],
|
|
10
|
+
bottom: [top, left, bottom, right],
|
|
11
|
+
left: [right, top, left, bottom]
|
|
12
|
+
}[base];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getElementPolygon };
|