@zag-js/rect-utils 0.10.4 → 0.11.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/index.d.mts +186 -0
- package/dist/index.d.ts +186 -16
- package/dist/index.js +540 -58
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +478 -15
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/align.d.ts +0 -8
- package/dist/align.js +0 -48
- package/dist/align.mjs +0 -44
- package/dist/closest.d.ts +0 -5
- package/dist/closest.js +0 -53
- package/dist/closest.mjs +0 -47
- package/dist/contains.d.ts +0 -5
- package/dist/contains.js +0 -19
- package/dist/contains.mjs +0 -13
- package/dist/distance.d.ts +0 -9
- package/dist/distance.js +0 -48
- package/dist/distance.mjs +0 -41
- package/dist/from-element.d.ts +0 -12
- package/dist/from-element.js +0 -43
- package/dist/from-element.mjs +0 -39
- package/dist/from-points.d.ts +0 -3
- package/dist/from-points.js +0 -17
- package/dist/from-points.mjs +0 -13
- package/dist/from-range.d.ts +0 -2
- package/dist/from-range.js +0 -27
- package/dist/from-range.mjs +0 -23
- package/dist/from-rotation.d.ts +0 -5
- package/dist/from-rotation.js +0 -39
- package/dist/from-rotation.mjs +0 -33
- package/dist/from-window.d.ts +0 -20
- package/dist/from-window.js +0 -26
- package/dist/from-window.mjs +0 -21
- package/dist/get-polygon.d.ts +0 -5
- package/dist/get-polygon.js +0 -19
- package/dist/get-polygon.mjs +0 -15
- package/dist/intersection.d.ts +0 -14
- package/dist/intersection.js +0 -28
- package/dist/intersection.mjs +0 -22
- package/dist/operations.d.ts +0 -7
- package/dist/operations.js +0 -40
- package/dist/operations.mjs +0 -32
- package/dist/polygon.d.ts +0 -3
- package/dist/polygon.js +0 -53
- package/dist/polygon.mjs +0 -48
- package/dist/rect.d.ts +0 -61
- package/dist/rect.js +0 -55
- package/dist/rect.mjs +0 -47
- package/dist/types.d.ts +0 -30
- package/dist/union.d.ts +0 -2
- package/dist/union.js +0 -32
- package/dist/union.mjs +0 -28
package/dist/closest.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const distance = require('./distance.js');
|
|
6
|
-
|
|
7
|
-
function closest(...pts) {
|
|
8
|
-
return (a) => {
|
|
9
|
-
const ds = pts.map((b) => distance.distance(b, a));
|
|
10
|
-
const c = Math.min.apply(Math, ds);
|
|
11
|
-
return pts[ds.indexOf(c)];
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function closestSideToRect(ref, r) {
|
|
15
|
-
if (r.maxX <= ref.minX) {
|
|
16
|
-
return "left";
|
|
17
|
-
}
|
|
18
|
-
if (r.minX >= ref.maxX) {
|
|
19
|
-
return "right";
|
|
20
|
-
}
|
|
21
|
-
if (r.maxY <= ref.minY) {
|
|
22
|
-
return "top";
|
|
23
|
-
}
|
|
24
|
-
if (r.minY >= ref.maxY) {
|
|
25
|
-
return "bottom";
|
|
26
|
-
}
|
|
27
|
-
return "left";
|
|
28
|
-
}
|
|
29
|
-
function closestSideToPoint(ref, p) {
|
|
30
|
-
const { x, y } = p;
|
|
31
|
-
const dl = x - ref.minX;
|
|
32
|
-
const dr = ref.maxX - x;
|
|
33
|
-
const dt = y - ref.minY;
|
|
34
|
-
const db = ref.maxY - y;
|
|
35
|
-
let closest2 = dl;
|
|
36
|
-
let side = "left";
|
|
37
|
-
if (dr < closest2) {
|
|
38
|
-
closest2 = dr;
|
|
39
|
-
side = "right";
|
|
40
|
-
}
|
|
41
|
-
if (dt < closest2) {
|
|
42
|
-
closest2 = dt;
|
|
43
|
-
side = "top";
|
|
44
|
-
}
|
|
45
|
-
if (db < closest2) {
|
|
46
|
-
side = "bottom";
|
|
47
|
-
}
|
|
48
|
-
return side;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.closest = closest;
|
|
52
|
-
exports.closestSideToPoint = closestSideToPoint;
|
|
53
|
-
exports.closestSideToRect = closestSideToRect;
|
package/dist/closest.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { distance } from './distance.mjs';
|
|
2
|
-
|
|
3
|
-
function closest(...pts) {
|
|
4
|
-
return (a) => {
|
|
5
|
-
const ds = pts.map((b) => distance(b, a));
|
|
6
|
-
const c = Math.min.apply(Math, ds);
|
|
7
|
-
return pts[ds.indexOf(c)];
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function closestSideToRect(ref, r) {
|
|
11
|
-
if (r.maxX <= ref.minX) {
|
|
12
|
-
return "left";
|
|
13
|
-
}
|
|
14
|
-
if (r.minX >= ref.maxX) {
|
|
15
|
-
return "right";
|
|
16
|
-
}
|
|
17
|
-
if (r.maxY <= ref.minY) {
|
|
18
|
-
return "top";
|
|
19
|
-
}
|
|
20
|
-
if (r.minY >= ref.maxY) {
|
|
21
|
-
return "bottom";
|
|
22
|
-
}
|
|
23
|
-
return "left";
|
|
24
|
-
}
|
|
25
|
-
function closestSideToPoint(ref, p) {
|
|
26
|
-
const { x, y } = p;
|
|
27
|
-
const dl = x - ref.minX;
|
|
28
|
-
const dr = ref.maxX - x;
|
|
29
|
-
const dt = y - ref.minY;
|
|
30
|
-
const db = ref.maxY - y;
|
|
31
|
-
let closest2 = dl;
|
|
32
|
-
let side = "left";
|
|
33
|
-
if (dr < closest2) {
|
|
34
|
-
closest2 = dr;
|
|
35
|
-
side = "right";
|
|
36
|
-
}
|
|
37
|
-
if (dt < closest2) {
|
|
38
|
-
closest2 = dt;
|
|
39
|
-
side = "top";
|
|
40
|
-
}
|
|
41
|
-
if (db < closest2) {
|
|
42
|
-
side = "bottom";
|
|
43
|
-
}
|
|
44
|
-
return side;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { closest, closestSideToPoint, closestSideToRect };
|
package/dist/contains.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Rect } from "./rect";
|
|
2
|
-
import type { Point } from "./types";
|
|
3
|
-
export declare function containsPoint(r: Rect, p: Point): boolean;
|
|
4
|
-
export declare function containsRect(a: Rect, b: Rect): boolean;
|
|
5
|
-
export declare function contains(r: Rect, v: Rect | Point): boolean;
|
package/dist/contains.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function containsPoint(r, p) {
|
|
8
|
-
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
9
|
-
}
|
|
10
|
-
function containsRect(a, b) {
|
|
11
|
-
return Object.values(rect.getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
12
|
-
}
|
|
13
|
-
function contains(r, v) {
|
|
14
|
-
return rect.isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.contains = contains;
|
|
18
|
-
exports.containsPoint = containsPoint;
|
|
19
|
-
exports.containsRect = containsRect;
|
package/dist/contains.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { getRectCorners, isRect } from './rect.mjs';
|
|
2
|
-
|
|
3
|
-
function containsPoint(r, p) {
|
|
4
|
-
return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
|
|
5
|
-
}
|
|
6
|
-
function containsRect(a, b) {
|
|
7
|
-
return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
|
|
8
|
-
}
|
|
9
|
-
function contains(r, v) {
|
|
10
|
-
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { contains, containsPoint, containsRect };
|
package/dist/distance.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Rect } from "./rect";
|
|
2
|
-
import type { Point, RectSide } from "./types";
|
|
3
|
-
export type DistanceValue = Point & {
|
|
4
|
-
value: number;
|
|
5
|
-
};
|
|
6
|
-
export declare function distance(a: Point, b?: Point): number;
|
|
7
|
-
export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
8
|
-
export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
9
|
-
export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
package/dist/distance.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const intersection = require('./intersection.js');
|
|
6
|
-
|
|
7
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
8
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
9
|
-
}
|
|
10
|
-
function distanceFromPoint(r, p) {
|
|
11
|
-
let x = 0;
|
|
12
|
-
let y = 0;
|
|
13
|
-
if (p.x < r.x)
|
|
14
|
-
x = r.x - p.x;
|
|
15
|
-
else if (p.x > r.maxX)
|
|
16
|
-
x = p.x - r.maxX;
|
|
17
|
-
if (p.y < r.y)
|
|
18
|
-
y = r.y - p.y;
|
|
19
|
-
else if (p.y > r.maxY)
|
|
20
|
-
y = p.y - r.maxY;
|
|
21
|
-
return { x, y, value: distance({ x, y }) };
|
|
22
|
-
}
|
|
23
|
-
function distanceFromRect(a, b) {
|
|
24
|
-
if (intersection.intersects(a, b))
|
|
25
|
-
return { x: 0, y: 0, value: 0 };
|
|
26
|
-
const left = a.x < b.x ? a : b;
|
|
27
|
-
const right = b.x < a.x ? a : b;
|
|
28
|
-
const upper = a.y < b.y ? a : b;
|
|
29
|
-
const lower = b.y < a.y ? a : b;
|
|
30
|
-
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
31
|
-
x = Math.max(0, x);
|
|
32
|
-
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
33
|
-
y = Math.max(0, y);
|
|
34
|
-
return { x, y, value: distance({ x, y }) };
|
|
35
|
-
}
|
|
36
|
-
function distanceBtwEdges(a, b) {
|
|
37
|
-
return {
|
|
38
|
-
left: b.x - a.x,
|
|
39
|
-
top: b.y - a.y,
|
|
40
|
-
right: a.maxX - b.maxX,
|
|
41
|
-
bottom: a.maxY - b.maxY
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
exports.distance = distance;
|
|
46
|
-
exports.distanceBtwEdges = distanceBtwEdges;
|
|
47
|
-
exports.distanceFromPoint = distanceFromPoint;
|
|
48
|
-
exports.distanceFromRect = distanceFromRect;
|
package/dist/distance.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { intersects } from './intersection.mjs';
|
|
2
|
-
|
|
3
|
-
function distance(a, b = { x: 0, y: 0 }) {
|
|
4
|
-
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
|
5
|
-
}
|
|
6
|
-
function distanceFromPoint(r, p) {
|
|
7
|
-
let x = 0;
|
|
8
|
-
let y = 0;
|
|
9
|
-
if (p.x < r.x)
|
|
10
|
-
x = r.x - p.x;
|
|
11
|
-
else if (p.x > r.maxX)
|
|
12
|
-
x = p.x - r.maxX;
|
|
13
|
-
if (p.y < r.y)
|
|
14
|
-
y = r.y - p.y;
|
|
15
|
-
else if (p.y > r.maxY)
|
|
16
|
-
y = p.y - r.maxY;
|
|
17
|
-
return { x, y, value: distance({ x, y }) };
|
|
18
|
-
}
|
|
19
|
-
function distanceFromRect(a, b) {
|
|
20
|
-
if (intersects(a, b))
|
|
21
|
-
return { x: 0, y: 0, value: 0 };
|
|
22
|
-
const left = a.x < b.x ? a : b;
|
|
23
|
-
const right = b.x < a.x ? a : b;
|
|
24
|
-
const upper = a.y < b.y ? a : b;
|
|
25
|
-
const lower = b.y < a.y ? a : b;
|
|
26
|
-
let x = left.x === right.x ? 0 : right.x - left.maxX;
|
|
27
|
-
x = Math.max(0, x);
|
|
28
|
-
let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
|
|
29
|
-
y = Math.max(0, y);
|
|
30
|
-
return { x, y, value: distance({ x, y }) };
|
|
31
|
-
}
|
|
32
|
-
function distanceBtwEdges(a, b) {
|
|
33
|
-
return {
|
|
34
|
-
left: b.x - a.x,
|
|
35
|
-
top: b.y - a.y,
|
|
36
|
-
right: a.maxX - b.maxX,
|
|
37
|
-
bottom: a.maxY - b.maxY
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
|
package/dist/from-element.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Rect } from "./rect";
|
|
2
|
-
export declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
3
|
-
export type ElementRectOptions = {
|
|
4
|
-
/**
|
|
5
|
-
* Whether to exclude the element's scrollbar size from the calculation.
|
|
6
|
-
*/
|
|
7
|
-
excludeScrollbar?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Whether to exclude the element's borders from the calculation.
|
|
10
|
-
*/
|
|
11
|
-
excludeBorders?: boolean;
|
|
12
|
-
};
|
package/dist/from-element.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
function getCacheComputedStyle(el) {
|
|
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);
|
|
14
|
-
}
|
|
15
|
-
function getElementRect(el, opts = {}) {
|
|
16
|
-
return rect.createRect(getClientRect(el, opts));
|
|
17
|
-
}
|
|
18
|
-
function getClientRect(el, opts = {}) {
|
|
19
|
-
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
20
|
-
const { x, y, width, height } = el.getBoundingClientRect();
|
|
21
|
-
const r = { x, y, width, height };
|
|
22
|
-
const style = getCacheComputedStyle(el);
|
|
23
|
-
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
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;
|
|
39
|
-
}
|
|
40
|
-
const px = (v) => parseFloat(v.replace("px", ""));
|
|
41
|
-
const sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
42
|
-
|
|
43
|
-
exports.getElementRect = getElementRect;
|
package/dist/from-element.mjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createRect } from './rect.mjs';
|
|
2
|
-
|
|
3
|
-
const styleCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
-
function getCacheComputedStyle(el) {
|
|
5
|
-
if (!styleCache.has(el)) {
|
|
6
|
-
const win = el.ownerDocument.defaultView || window;
|
|
7
|
-
styleCache.set(el, win.getComputedStyle(el));
|
|
8
|
-
}
|
|
9
|
-
return styleCache.get(el);
|
|
10
|
-
}
|
|
11
|
-
function getElementRect(el, opts = {}) {
|
|
12
|
-
return createRect(getClientRect(el, opts));
|
|
13
|
-
}
|
|
14
|
-
function getClientRect(el, opts = {}) {
|
|
15
|
-
const { excludeScrollbar = false, excludeBorders = false } = opts;
|
|
16
|
-
const { x, y, width, height } = el.getBoundingClientRect();
|
|
17
|
-
const r = { x, y, width, height };
|
|
18
|
-
const style = getCacheComputedStyle(el);
|
|
19
|
-
const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
|
|
20
|
-
const borderXWidth = sum(borderLeftWidth, borderRightWidth);
|
|
21
|
-
const borderYWidth = sum(borderTopWidth, borderBottomWidth);
|
|
22
|
-
if (excludeBorders) {
|
|
23
|
-
r.width -= borderXWidth;
|
|
24
|
-
r.height -= borderYWidth;
|
|
25
|
-
r.x += px(borderLeftWidth);
|
|
26
|
-
r.y += px(borderTopWidth);
|
|
27
|
-
}
|
|
28
|
-
if (excludeScrollbar) {
|
|
29
|
-
const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
|
|
30
|
-
const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
|
|
31
|
-
r.width -= scrollbarWidth;
|
|
32
|
-
r.height -= scrollbarHeight;
|
|
33
|
-
}
|
|
34
|
-
return r;
|
|
35
|
-
}
|
|
36
|
-
const px = (v) => parseFloat(v.replace("px", ""));
|
|
37
|
-
const sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
|
|
38
|
-
|
|
39
|
-
export { getElementRect };
|
package/dist/from-points.d.ts
DELETED
package/dist/from-points.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function getRectFromPoints(...pts) {
|
|
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 rect.createRect({ x, y, width, height });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.getRectFromPoints = getRectFromPoints;
|
package/dist/from-points.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
DELETED
package/dist/from-range.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
const fromElement = require('./from-element.js');
|
|
7
|
-
const union = require('./union.js');
|
|
8
|
-
|
|
9
|
-
function fromRange(range) {
|
|
10
|
-
let rs = [];
|
|
11
|
-
const rects = Array.from(range.getClientRects());
|
|
12
|
-
if (rects.length) {
|
|
13
|
-
rs = rs.concat(rects.map(rect.createRect));
|
|
14
|
-
return union.union.apply(void 0, rs);
|
|
15
|
-
}
|
|
16
|
-
let start = range.startContainer;
|
|
17
|
-
if (start.nodeType === Node.TEXT_NODE) {
|
|
18
|
-
start = start.parentNode;
|
|
19
|
-
}
|
|
20
|
-
if (start instanceof HTMLElement) {
|
|
21
|
-
const r = fromElement.getElementRect(start);
|
|
22
|
-
rs.push({ ...r, x: r.maxX, width: 0 });
|
|
23
|
-
}
|
|
24
|
-
return union.union.apply(void 0, rs);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.fromRange = fromRange;
|
package/dist/from-range.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
DELETED
package/dist/from-rotation.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function toRad(d) {
|
|
8
|
-
return d % 360 * Math.PI / 180;
|
|
9
|
-
}
|
|
10
|
-
function rotate(a, d, c) {
|
|
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
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function getRotationRect(r, deg) {
|
|
22
|
-
const rr = Object.values(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 rect.createRect({
|
|
30
|
-
x: minX,
|
|
31
|
-
y: minY,
|
|
32
|
-
width: maxX - minX,
|
|
33
|
-
height: maxY - minY
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
exports.getRotationRect = getRotationRect;
|
|
38
|
-
exports.rotate = rotate;
|
|
39
|
-
exports.toRad = toRad;
|
package/dist/from-rotation.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Rect } from "./rect";
|
|
2
|
-
export type WindowRectOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Whether to exclude the element's scrollbar size from the calculation.
|
|
5
|
-
*/
|
|
6
|
-
excludeScrollbar?: boolean;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Creates a rectange from window object
|
|
10
|
-
*/
|
|
11
|
-
export declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
12
|
-
/**
|
|
13
|
-
* Get the rect of the window with the option to exclude the scrollbar
|
|
14
|
-
*/
|
|
15
|
-
export declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
16
|
-
x: number;
|
|
17
|
-
y: number;
|
|
18
|
-
width: number;
|
|
19
|
-
height: number;
|
|
20
|
-
};
|
package/dist/from-window.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function getWindowRect(win, opts = {}) {
|
|
8
|
-
return rect.createRect(getViewportRect(win, opts));
|
|
9
|
-
}
|
|
10
|
-
function getViewportRect(win, opts) {
|
|
11
|
-
const { excludeScrollbar = false } = opts;
|
|
12
|
-
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
13
|
-
const width = visualViewport?.width || innerWidth;
|
|
14
|
-
const height = visualViewport?.height || innerHeight;
|
|
15
|
-
const rect = { x: 0, y: 0, width, height };
|
|
16
|
-
if (excludeScrollbar) {
|
|
17
|
-
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
18
|
-
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
19
|
-
rect.width -= scrollbarWidth;
|
|
20
|
-
rect.height -= scrollbarHeight;
|
|
21
|
-
}
|
|
22
|
-
return rect;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.getViewportRect = getViewportRect;
|
|
26
|
-
exports.getWindowRect = getWindowRect;
|
package/dist/from-window.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
package/dist/get-polygon.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function getElementPolygon(rectValue, placement) {
|
|
8
|
-
const rect$1 = rect.createRect(rectValue);
|
|
9
|
-
const { top, right, left, bottom } = rect.getRectCorners(rect$1);
|
|
10
|
-
const [base] = placement.split("-");
|
|
11
|
-
return {
|
|
12
|
-
top: [left, top, right, bottom],
|
|
13
|
-
right: [top, right, bottom, left],
|
|
14
|
-
bottom: [top, left, bottom, right],
|
|
15
|
-
left: [right, top, left, bottom]
|
|
16
|
-
}[base];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.getElementPolygon = getElementPolygon;
|
package/dist/get-polygon.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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 };
|
package/dist/intersection.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Rect } from "./rect";
|
|
2
|
-
import type { RectSide } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a Rect intersects another Rect
|
|
5
|
-
*/
|
|
6
|
-
export declare function intersects(a: Rect, b: Rect): boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Returns a new Rect that represents the intersection between two Rects
|
|
9
|
-
*/
|
|
10
|
-
export declare function intersection(a: Rect, b: Rect): Rect;
|
|
11
|
-
/**
|
|
12
|
-
* Returns whether two rects collide along each edge
|
|
13
|
-
*/
|
|
14
|
-
export declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
package/dist/intersection.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
5
|
-
const rect = require('./rect.js');
|
|
6
|
-
|
|
7
|
-
function intersects(a, b) {
|
|
8
|
-
return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
|
|
9
|
-
}
|
|
10
|
-
function intersection(a, b) {
|
|
11
|
-
const x = Math.max(a.x, b.x);
|
|
12
|
-
const y = Math.max(a.y, b.y);
|
|
13
|
-
const x2 = Math.min(a.x + a.width, b.x + b.width);
|
|
14
|
-
const y2 = Math.min(a.y + a.height, b.y + b.height);
|
|
15
|
-
return rect.createRect({ x, y, width: x2 - x, height: y2 - y });
|
|
16
|
-
}
|
|
17
|
-
function collisions(a, b) {
|
|
18
|
-
return {
|
|
19
|
-
top: a.minY <= b.minY,
|
|
20
|
-
right: a.maxX >= b.maxX,
|
|
21
|
-
bottom: a.maxY >= b.maxY,
|
|
22
|
-
left: a.minX <= b.minX
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.collisions = collisions;
|
|
27
|
-
exports.intersection = intersection;
|
|
28
|
-
exports.intersects = intersects;
|