@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/from-element.js
CHANGED
|
@@ -1,65 +1,46 @@
|
|
|
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/from-element.ts
|
|
21
|
-
var from_element_exports = {};
|
|
22
|
-
__export(from_element_exports, {
|
|
23
|
-
getElementRect: () => getElementRect
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/from-element.ts
|
|
7
|
+
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
28
8
|
function getCacheComputedStyle(el) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
if (!styleCache.has(el)) {
|
|
10
|
+
const win = el.ownerDocument.defaultView || window;
|
|
11
|
+
styleCache.set(el, win.getComputedStyle(el));
|
|
12
|
+
}
|
|
13
|
+
return styleCache.get(el);
|
|
34
14
|
}
|
|
35
15
|
function getElementRect(el, opts = {}) {
|
|
36
|
-
|
|
16
|
+
return require_rect.createRect(getClientRect(el, opts));
|
|
37
17
|
}
|
|
38
18
|
function getClientRect(el, opts = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
19
|
+
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
20
|
+
const { x, y, width, height } = el.getBoundingClientRect();
|
|
21
|
+
const r = {
|
|
22
|
+
x,
|
|
23
|
+
y,
|
|
24
|
+
width,
|
|
25
|
+
height
|
|
26
|
+
};
|
|
27
|
+
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = getCacheComputedStyle(el);
|
|
28
|
+
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
29
|
+
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
30
|
+
if (excludeBorders) {
|
|
31
|
+
r.width -= borderXWidth;
|
|
32
|
+
r.height -= borderYWidth;
|
|
33
|
+
r.x += px(borderLeftWidth);
|
|
34
|
+
r.y += px(borderTopWidth);
|
|
35
|
+
}
|
|
36
|
+
if (excludeScrollbar) {
|
|
37
|
+
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
38
|
+
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
39
|
+
r.width -= scrollbarWidth;
|
|
40
|
+
r.height -= scrollbarHeight;
|
|
41
|
+
}
|
|
42
|
+
return r;
|
|
59
43
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
0 && (module.exports = {
|
|
64
|
-
getElementRect
|
|
65
|
-
});
|
|
44
|
+
const px = (v) => parseFloat(v.replace("px", ""));
|
|
45
|
+
const sum = (...vals) => vals.reduce((sum, v) => sum + (v ? px(v) : 0), 0);
|
|
46
|
+
exports.getElementRect = getElementRect;
|
package/dist/from-element.mjs
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
// src/from-element.ts
|
|
2
1
|
import { createRect } from "./rect.mjs";
|
|
3
|
-
|
|
2
|
+
// src/from-element.ts
|
|
3
|
+
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
function getCacheComputedStyle(el) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
10
|
}
|
|
11
11
|
function getElementRect(el, opts = {}) {
|
|
12
|
-
|
|
12
|
+
return createRect(getClientRect(el, opts));
|
|
13
13
|
}
|
|
14
14
|
function getClientRect(el, opts = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
16
|
+
const { x, y, width, height } = el.getBoundingClientRect();
|
|
17
|
+
const r = {
|
|
18
|
+
x,
|
|
19
|
+
y,
|
|
20
|
+
width,
|
|
21
|
+
height
|
|
22
|
+
};
|
|
23
|
+
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = getCacheComputedStyle(el);
|
|
24
|
+
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
25
|
+
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
26
|
+
if (excludeBorders) {
|
|
27
|
+
r.width -= borderXWidth;
|
|
28
|
+
r.height -= borderYWidth;
|
|
29
|
+
r.x += px(borderLeftWidth);
|
|
30
|
+
r.y += px(borderTopWidth);
|
|
31
|
+
}
|
|
32
|
+
if (excludeScrollbar) {
|
|
33
|
+
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
34
|
+
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
35
|
+
r.width -= scrollbarWidth;
|
|
36
|
+
r.height -= scrollbarHeight;
|
|
37
|
+
}
|
|
38
|
+
return r;
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export {
|
|
39
|
-
getElementRect
|
|
40
|
-
};
|
|
40
|
+
const px = (v) => parseFloat(v.replace("px", ""));
|
|
41
|
+
const sum = (...vals) => vals.reduce((sum, v) => sum + (v ? px(v) : 0), 0);
|
|
42
|
+
export { getElementRect };
|
package/dist/from-points.d.mts
CHANGED
package/dist/from-points.d.ts
CHANGED
package/dist/from-points.js
CHANGED
|
@@ -1,39 +1,21 @@
|
|
|
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/from-points.ts
|
|
21
|
-
var from_points_exports = {};
|
|
22
|
-
__export(from_points_exports, {
|
|
23
|
-
getRectFromPoints: () => getRectFromPoints
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
// src/from-points.ts
|
|
27
7
|
function getRectFromPoints(...pts) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
const xs = pts.map((p) => p.x);
|
|
9
|
+
const ys = pts.map((p) => p.y);
|
|
10
|
+
const x = Math.min(...xs);
|
|
11
|
+
const y = Math.min(...ys);
|
|
12
|
+
const width = Math.max(...xs) - x;
|
|
13
|
+
const height = Math.max(...ys) - y;
|
|
14
|
+
return require_rect.createRect({
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
width,
|
|
18
|
+
height
|
|
19
|
+
});
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
getRectFromPoints
|
|
39
|
-
});
|
|
21
|
+
exports.getRectFromPoints = getRectFromPoints;
|
package/dist/from-points.mjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// src/from-points.ts
|
|
2
1
|
import { createRect } from "./rect.mjs";
|
|
2
|
+
// src/from-points.ts
|
|
3
3
|
function getRectFromPoints(...pts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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({
|
|
11
|
+
x,
|
|
12
|
+
y,
|
|
13
|
+
width,
|
|
14
|
+
height
|
|
15
|
+
});
|
|
11
16
|
}
|
|
12
|
-
export {
|
|
13
|
-
getRectFromPoints
|
|
14
|
-
};
|
|
17
|
+
export { getRectFromPoints };
|
package/dist/from-range.d.mts
CHANGED
package/dist/from-range.d.ts
CHANGED
package/dist/from-range.js
CHANGED
|
@@ -1,49 +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/from-range.ts
|
|
21
|
-
var from_range_exports = {};
|
|
22
|
-
__export(from_range_exports, {
|
|
23
|
-
fromRange: () => fromRange
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const require_rect = require("./rect.js");
|
|
6
|
+
const require_from_element = require("./from-element.js");
|
|
7
|
+
const require_union = require("./union.js");
|
|
8
|
+
// src/from-range.ts
|
|
29
9
|
function fromRange(range) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
10
|
+
let rs = [];
|
|
11
|
+
const rects = Array.from(range.getClientRects());
|
|
12
|
+
if (rects.length) {
|
|
13
|
+
rs = rs.concat(rects.map(require_rect.createRect));
|
|
14
|
+
return require_union.union.apply(void 0, rs);
|
|
15
|
+
}
|
|
16
|
+
let start = range.startContainer;
|
|
17
|
+
if (start.nodeType === Node.TEXT_NODE) start = start.parentNode;
|
|
18
|
+
if (start instanceof HTMLElement) {
|
|
19
|
+
const r = require_from_element.getElementRect(start);
|
|
20
|
+
rs.push({
|
|
21
|
+
...r,
|
|
22
|
+
x: r.maxX,
|
|
23
|
+
width: 0
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return require_union.union.apply(void 0, rs);
|
|
45
27
|
}
|
|
46
|
-
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
fromRange
|
|
49
|
-
});
|
|
28
|
+
exports.fromRange = fromRange;
|
package/dist/from-range.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
// src/from-range.ts
|
|
2
1
|
import { createRect } from "./rect.mjs";
|
|
3
2
|
import { getElementRect } from "./from-element.mjs";
|
|
4
3
|
import { union } from "./union.mjs";
|
|
4
|
+
// src/from-range.ts
|
|
5
5
|
function fromRange(range) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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) start = start.parentNode;
|
|
14
|
+
if (start instanceof HTMLElement) {
|
|
15
|
+
const r = getElementRect(start);
|
|
16
|
+
rs.push({
|
|
17
|
+
...r,
|
|
18
|
+
x: r.maxX,
|
|
19
|
+
width: 0
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return union.apply(void 0, rs);
|
|
21
23
|
}
|
|
22
|
-
export {
|
|
23
|
-
fromRange
|
|
24
|
-
};
|
|
24
|
+
export { fromRange };
|
package/dist/from-rotation.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function getRotationRect(r: Rect, deg: number): Rect;
|
|
6
|
-
|
|
7
|
-
export { getRotationRect, rotate, toRad };
|
|
1
|
+
import { Point, Rect } from "./types.mjs";
|
|
2
|
+
export declare function toRad(d: number): number;
|
|
3
|
+
export declare function rotate(a: Point, d: number, c: Point): Point;
|
|
4
|
+
export declare function getRotationRect(r: Rect, deg: number): Rect;
|
package/dist/from-rotation.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function
|
|
5
|
-
declare function getRotationRect(r: Rect, deg: number): Rect;
|
|
6
|
-
|
|
7
|
-
export { getRotationRect, rotate, toRad };
|
|
1
|
+
import { Point, Rect } from "./types.js";
|
|
2
|
+
export declare function toRad(d: number): number;
|
|
3
|
+
export declare function rotate(a: Point, d: number, c: Point): Point;
|
|
4
|
+
export declare function getRotationRect(r: Rect, deg: number): Rect;
|
package/dist/from-rotation.js
CHANGED
|
@@ -1,63 +1,38 @@
|
|
|
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/from-rotation.ts
|
|
21
|
-
var from_rotation_exports = {};
|
|
22
|
-
__export(from_rotation_exports, {
|
|
23
|
-
getRotationRect: () => getRotationRect,
|
|
24
|
-
rotate: () => rotate,
|
|
25
|
-
toRad: () => toRad
|
|
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/from-rotation.ts
|
|
29
7
|
function toRad(d) {
|
|
30
|
-
|
|
8
|
+
return d % 360 * Math.PI / 180;
|
|
31
9
|
}
|
|
32
10
|
function rotate(a, d, c) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
const r = toRad(d);
|
|
12
|
+
const sin = Math.sin(r);
|
|
13
|
+
const cos = Math.cos(r);
|
|
14
|
+
const x = a.x - c.x;
|
|
15
|
+
const y = a.y - c.y;
|
|
16
|
+
return {
|
|
17
|
+
x: c.x + x * cos - y * sin,
|
|
18
|
+
y: c.y + x * sin + y * cos
|
|
19
|
+
};
|
|
42
20
|
}
|
|
43
21
|
function getRotationRect(r, deg) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
const rr = Object.values(require_rect.getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
23
|
+
const xs = rr.map((p) => p.x);
|
|
24
|
+
const ys = rr.map((p) => p.y);
|
|
25
|
+
const minX = Math.min(...xs);
|
|
26
|
+
const minY = Math.min(...ys);
|
|
27
|
+
const maxX = Math.max(...xs);
|
|
28
|
+
const maxY = Math.max(...ys);
|
|
29
|
+
return require_rect.createRect({
|
|
30
|
+
x: minX,
|
|
31
|
+
y: minY,
|
|
32
|
+
width: maxX - minX,
|
|
33
|
+
height: maxY - minY
|
|
34
|
+
});
|
|
57
35
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
rotate,
|
|
62
|
-
toRad
|
|
63
|
-
});
|
|
36
|
+
exports.getRotationRect = getRotationRect;
|
|
37
|
+
exports.rotate = rotate;
|
|
38
|
+
exports.toRad = toRad;
|
package/dist/from-rotation.mjs
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
// src/from-rotation.ts
|
|
2
1
|
import { createRect, getRectCorners } from "./rect.mjs";
|
|
2
|
+
// src/from-rotation.ts
|
|
3
3
|
function toRad(d) {
|
|
4
|
-
|
|
4
|
+
return d % 360 * Math.PI / 180;
|
|
5
5
|
}
|
|
6
6
|
function rotate(a, d, c) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
16
|
}
|
|
17
17
|
function getRotationRect(r, deg) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
31
|
}
|
|
32
|
-
export {
|
|
33
|
-
getRotationRect,
|
|
34
|
-
rotate,
|
|
35
|
-
toRad
|
|
36
|
-
};
|
|
32
|
+
export { getRotationRect, rotate, toRad };
|
package/dist/from-window.d.mts
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { Rect } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
excludeScrollbar?: boolean | undefined;
|
|
1
|
+
import { Rect } from "./types.mjs";
|
|
2
|
+
export type WindowRectOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
5
|
+
*/
|
|
6
|
+
excludeScrollbar?: boolean | undefined;
|
|
8
7
|
};
|
|
9
8
|
/**
|
|
10
9
|
* Creates a rectangle from window object
|
|
11
10
|
*/
|
|
12
|
-
declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
11
|
+
export declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
13
12
|
/**
|
|
14
13
|
* Get the rect of the window with the option to exclude the scrollbar
|
|
15
14
|
*/
|
|
16
|
-
declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { type WindowRectOptions, getViewportRect, getWindowRect };
|
|
15
|
+
export declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|