@zag-js/rect-utils 0.2.0 → 0.2.2
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 +12 -0
- package/dist/align.js +71 -0
- package/dist/align.mjs +6 -0
- package/dist/chunk-2QYJISFU.mjs +21 -0
- package/dist/chunk-AYR2YRSU.mjs +49 -0
- package/dist/chunk-AYWORFWQ.mjs +32 -0
- package/dist/chunk-BGAHRJ6S.mjs +41 -0
- package/dist/chunk-DBR73IMM.mjs +54 -0
- package/dist/chunk-GVBSNO2Z.mjs +55 -0
- package/dist/chunk-IFHTGH3H.mjs +29 -0
- package/dist/chunk-LBA674LT.mjs +27 -0
- package/dist/chunk-NGMCS5TG.mjs +33 -0
- package/dist/chunk-QXXKPYP2.mjs +47 -0
- package/dist/chunk-R24UTBJ3.mjs +52 -0
- package/dist/chunk-S3HXSPS7.mjs +21 -0
- package/dist/chunk-T4IEPEZY.mjs +41 -0
- package/dist/chunk-TPU7B3ZS.mjs +18 -0
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-YDYJCJQZ.mjs +56 -0
- package/dist/closest.d.ts +8 -0
- package/dist/closest.js +83 -0
- package/dist/closest.mjs +13 -0
- package/dist/contains.d.ts +8 -0
- package/dist/contains.js +60 -0
- package/dist/contains.mjs +11 -0
- package/dist/distance.d.ts +12 -0
- package/dist/distance.js +79 -0
- package/dist/distance.mjs +14 -0
- package/dist/from-element.d.ts +16 -0
- package/dist/from-element.js +98 -0
- package/dist/from-element.mjs +7 -0
- package/dist/from-points.d.ts +6 -0
- package/dist/from-points.js +61 -0
- package/dist/from-points.mjs +7 -0
- package/dist/from-range.d.ts +6 -0
- package/dist/from-range.js +154 -0
- package/dist/from-range.mjs +10 -0
- package/dist/from-rotation.d.ts +8 -0
- package/dist/from-rotation.js +92 -0
- package/dist/from-rotation.mjs +11 -0
- package/dist/from-window.d.ts +24 -0
- package/dist/from-window.js +71 -0
- package/dist/from-window.mjs +9 -0
- package/dist/get-polygon.d.ts +8 -0
- package/dist/get-polygon.js +70 -0
- package/dist/get-polygon.mjs +7 -0
- package/dist/index.d.ts +16 -186
- package/dist/index.js +8 -9
- package/dist/index.mjs +67 -453
- package/dist/intersection.d.ts +17 -0
- package/dist/intersection.js +74 -0
- package/dist/intersection.mjs +11 -0
- package/dist/operations.d.ts +10 -0
- package/dist/operations.js +88 -0
- package/dist/operations.mjs +15 -0
- package/dist/polygon.d.ts +6 -0
- package/dist/polygon.js +77 -0
- package/dist/polygon.mjs +8 -0
- package/dist/rect.d.ts +64 -0
- package/dist/rect.js +86 -0
- package/dist/rect.mjs +14 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/union.d.ts +6 -0
- package/dist/union.js +87 -0
- package/dist/union.mjs +8 -0
- package/package.json +18 -8
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
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-rotation.ts
|
|
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);
|
|
28
|
+
|
|
29
|
+
// src/rect.ts
|
|
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
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/from-rotation.ts
|
|
58
|
+
function toRad(d) {
|
|
59
|
+
return d % 360 * Math.PI / 180;
|
|
60
|
+
}
|
|
61
|
+
function rotate(a, d, c) {
|
|
62
|
+
const r = toRad(d);
|
|
63
|
+
const sin = Math.sin(r);
|
|
64
|
+
const cos = Math.cos(r);
|
|
65
|
+
const x = a.x - c.x;
|
|
66
|
+
const y = a.y - c.y;
|
|
67
|
+
return {
|
|
68
|
+
x: c.x + x * cos - y * sin,
|
|
69
|
+
y: c.y + x * sin + y * cos
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function getRotationRect(r, deg) {
|
|
73
|
+
const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
|
|
74
|
+
const xs = rr.map((p) => p.x);
|
|
75
|
+
const ys = rr.map((p) => p.y);
|
|
76
|
+
const minX = Math.min(...xs);
|
|
77
|
+
const minY = Math.min(...ys);
|
|
78
|
+
const maxX = Math.max(...xs);
|
|
79
|
+
const maxY = Math.max(...ys);
|
|
80
|
+
return createRect({
|
|
81
|
+
x: minX,
|
|
82
|
+
y: minY,
|
|
83
|
+
width: maxX - minX,
|
|
84
|
+
height: maxY - minY
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
getRotationRect,
|
|
90
|
+
rotate,
|
|
91
|
+
toRad
|
|
92
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Rect } from './rect.js';
|
|
2
|
+
import './types.js';
|
|
3
|
+
|
|
4
|
+
type WindowRectOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to exclude the element's scrollbar size from the calculation.
|
|
7
|
+
*/
|
|
8
|
+
excludeScrollbar?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a rectange from window object
|
|
12
|
+
*/
|
|
13
|
+
declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
14
|
+
/**
|
|
15
|
+
* Get the rect of the window with the option to exclude the scrollbar
|
|
16
|
+
*/
|
|
17
|
+
declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { WindowRectOptions, getViewportRect, getWindowRect };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
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-window.ts
|
|
21
|
+
var from_window_exports = {};
|
|
22
|
+
__export(from_window_exports, {
|
|
23
|
+
getViewportRect: () => getViewportRect,
|
|
24
|
+
getWindowRect: () => getWindowRect
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(from_window_exports);
|
|
27
|
+
|
|
28
|
+
// src/rect.ts
|
|
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
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/from-window.ts
|
|
50
|
+
function getWindowRect(win, opts = {}) {
|
|
51
|
+
return createRect(getViewportRect(win, opts));
|
|
52
|
+
}
|
|
53
|
+
function getViewportRect(win, opts) {
|
|
54
|
+
const { excludeScrollbar = false } = opts;
|
|
55
|
+
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
56
|
+
const width = visualViewport?.width || innerWidth;
|
|
57
|
+
const height = visualViewport?.height || innerHeight;
|
|
58
|
+
const rect = { x: 0, y: 0, width, height };
|
|
59
|
+
if (excludeScrollbar) {
|
|
60
|
+
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
61
|
+
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
62
|
+
rect.width -= scrollbarWidth;
|
|
63
|
+
rect.height -= scrollbarHeight;
|
|
64
|
+
}
|
|
65
|
+
return rect;
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
getViewportRect,
|
|
70
|
+
getWindowRect
|
|
71
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
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/get-polygon.ts
|
|
21
|
+
var get_polygon_exports = {};
|
|
22
|
+
__export(get_polygon_exports, {
|
|
23
|
+
getElementPolygon: () => getElementPolygon
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_polygon_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
|
+
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
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/get-polygon.ts
|
|
56
|
+
function getElementPolygon(rectValue, placement) {
|
|
57
|
+
const rect = createRect(rectValue);
|
|
58
|
+
const { top, right, left, bottom } = getRectCorners(rect);
|
|
59
|
+
const [base] = placement.split("-");
|
|
60
|
+
return {
|
|
61
|
+
top: [left, top, right, bottom],
|
|
62
|
+
right: [top, right, bottom, left],
|
|
63
|
+
bottom: [top, left, bottom, right],
|
|
64
|
+
left: [right, top, left, bottom]
|
|
65
|
+
}[base];
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
getElementPolygon
|
|
70
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,186 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
declare type RectCorner = "topLeft" | "topRight" | "bottomLeft" | "bottomRight";
|
|
19
|
-
declare type RectCorners = Record<RectCorner, Point> & {
|
|
20
|
-
value: RectPoints;
|
|
21
|
-
};
|
|
22
|
-
declare type RectCenter = "topCenter" | "rightCenter" | "leftCenter" | "bottomCenter";
|
|
23
|
-
declare type RectCenters = Record<RectCenter, Point> & {
|
|
24
|
-
value: RectPoints;
|
|
25
|
-
};
|
|
26
|
-
declare type RectInset = Partial<Record<RectSide, number>>;
|
|
27
|
-
declare type SymmetricRectInset = {
|
|
28
|
-
dx?: number;
|
|
29
|
-
dy?: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare function createRect(r: RectValue): {
|
|
33
|
-
x: number;
|
|
34
|
-
y: number;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
minX: number;
|
|
38
|
-
minY: number;
|
|
39
|
-
maxX: number;
|
|
40
|
-
maxY: number;
|
|
41
|
-
midX: number;
|
|
42
|
-
midY: number;
|
|
43
|
-
center: {
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
declare type Rect = ReturnType<typeof createRect>;
|
|
49
|
-
declare function isRect(v: any): v is Rect;
|
|
50
|
-
declare function getRectCenters(v: Rect): {
|
|
51
|
-
top: {
|
|
52
|
-
x: number;
|
|
53
|
-
y: number;
|
|
54
|
-
};
|
|
55
|
-
right: {
|
|
56
|
-
x: number;
|
|
57
|
-
y: number;
|
|
58
|
-
};
|
|
59
|
-
bottom: {
|
|
60
|
-
x: number;
|
|
61
|
-
y: number;
|
|
62
|
-
};
|
|
63
|
-
left: {
|
|
64
|
-
x: number;
|
|
65
|
-
y: number;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
declare function getRectCorners(v: Rect): {
|
|
69
|
-
top: {
|
|
70
|
-
x: number;
|
|
71
|
-
y: number;
|
|
72
|
-
};
|
|
73
|
-
right: {
|
|
74
|
-
x: number;
|
|
75
|
-
y: number;
|
|
76
|
-
};
|
|
77
|
-
bottom: {
|
|
78
|
-
x: number;
|
|
79
|
-
y: number;
|
|
80
|
-
};
|
|
81
|
-
left: {
|
|
82
|
-
x: number;
|
|
83
|
-
y: number;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
declare function getRectEdges(v: Rect): {
|
|
87
|
-
top: RectEdge;
|
|
88
|
-
right: RectEdge;
|
|
89
|
-
bottom: RectEdge;
|
|
90
|
-
left: RectEdge;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
|
|
94
|
-
declare type AlignOptions = {
|
|
95
|
-
h: HAlign;
|
|
96
|
-
v: VAlign;
|
|
97
|
-
};
|
|
98
|
-
declare type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
99
|
-
declare type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
|
100
|
-
|
|
101
|
-
declare function closest(...pts: Point[]): (a: Point) => Point;
|
|
102
|
-
declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
|
|
103
|
-
declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
|
|
104
|
-
|
|
105
|
-
declare function containsPoint(r: Rect, p: Point): boolean;
|
|
106
|
-
declare function containsRect(a: Rect, b: Rect): boolean;
|
|
107
|
-
declare function contains(r: Rect, v: Rect | Point): boolean;
|
|
108
|
-
|
|
109
|
-
declare type DistanceValue = Point & {
|
|
110
|
-
value: number;
|
|
111
|
-
};
|
|
112
|
-
declare function distance(a: Point, b?: Point): number;
|
|
113
|
-
declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
|
|
114
|
-
declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
|
|
115
|
-
declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
|
|
116
|
-
|
|
117
|
-
declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
|
|
118
|
-
declare type ElementRectOptions = {
|
|
119
|
-
/**
|
|
120
|
-
* Whether to exclude the element's scrollbar size from the calculation.
|
|
121
|
-
*/
|
|
122
|
-
excludeScrollbar?: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* Whether to exclude the element's borders from the calculation.
|
|
125
|
-
*/
|
|
126
|
-
excludeBorders?: boolean;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
declare function getRectFromPoints(...pts: Point[]): Rect;
|
|
130
|
-
|
|
131
|
-
declare function fromRange(range: Range): Rect;
|
|
132
|
-
|
|
133
|
-
declare function toRad(d: number): number;
|
|
134
|
-
declare function rotate(a: Point, d: number, c: Point): Point;
|
|
135
|
-
declare function getRotationRect(r: Rect, deg: number): Rect;
|
|
136
|
-
|
|
137
|
-
declare type WindowRectOptions = {
|
|
138
|
-
/**
|
|
139
|
-
* Whether to exclude the element's scrollbar size from the calculation.
|
|
140
|
-
*/
|
|
141
|
-
excludeScrollbar?: boolean;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Creates a rectange from window object
|
|
145
|
-
*/
|
|
146
|
-
declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
|
|
147
|
-
/**
|
|
148
|
-
* Get the rect of the window with the option to exclude the scrollbar
|
|
149
|
-
*/
|
|
150
|
-
declare function getViewportRect(win: Window, opts: WindowRectOptions): {
|
|
151
|
-
x: number;
|
|
152
|
-
y: number;
|
|
153
|
-
width: number;
|
|
154
|
-
height: number;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
declare function getElementPolygon(rectValue: RectValue, placement: string): {
|
|
158
|
-
x: number;
|
|
159
|
-
y: number;
|
|
160
|
-
}[] | undefined;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Checks if a Rect intersects another Rect
|
|
164
|
-
*/
|
|
165
|
-
declare function intersects(a: Rect, b: Rect): boolean;
|
|
166
|
-
/**
|
|
167
|
-
* Returns a new Rect that represents the intersection between two Rects
|
|
168
|
-
*/
|
|
169
|
-
declare function intersection(a: Rect, b: Rect): Rect;
|
|
170
|
-
/**
|
|
171
|
-
* Returns whether two rects collide along each edge
|
|
172
|
-
*/
|
|
173
|
-
declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
|
|
174
|
-
|
|
175
|
-
declare const isSymmetric: (v: any) => v is SymmetricRectInset;
|
|
176
|
-
declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
|
|
177
|
-
declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
178
|
-
declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
|
|
179
|
-
declare function shift(r: Rect, o: Partial<Point>): Rect;
|
|
180
|
-
|
|
181
|
-
declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
|
|
182
|
-
declare function debugPolygon(polygon: Point[]): () => void;
|
|
183
|
-
|
|
184
|
-
declare function union(...rs: Rect[]): Rect;
|
|
185
|
-
|
|
186
|
-
export { AlignOptions, DistanceValue, ElementRectOptions, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset, VAlign, WindowRectOptions, alignRect, closest, closestSideToPoint, closestSideToRect, collisions, contains, containsPoint, containsRect, createRect, debugPolygon, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect, expand, fromRange, getElementPolygon, getElementRect, getRectCenters, getRectCorners, getRectEdges, getRectFromPoints, getRotationRect, getViewportRect, getWindowRect, inset, intersection, intersects, isPointInPolygon, isRect, isSymmetric, rotate, shift, shrink, toRad, union };
|
|
1
|
+
export { AlignOptions, HAlign, VAlign, alignRect } from './align.js';
|
|
2
|
+
export { closest, closestSideToPoint, closestSideToRect } from './closest.js';
|
|
3
|
+
export { contains, containsPoint, containsRect } from './contains.js';
|
|
4
|
+
export { DistanceValue, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect } from './distance.js';
|
|
5
|
+
export { ElementRectOptions, getElementRect } from './from-element.js';
|
|
6
|
+
export { getRectFromPoints } from './from-points.js';
|
|
7
|
+
export { fromRange } from './from-range.js';
|
|
8
|
+
export { getRotationRect, rotate, toRad } from './from-rotation.js';
|
|
9
|
+
export { WindowRectOptions, getViewportRect, getWindowRect } from './from-window.js';
|
|
10
|
+
export { getElementPolygon } from './get-polygon.js';
|
|
11
|
+
export { collisions, intersection, intersects } from './intersection.js';
|
|
12
|
+
export { expand, inset, isSymmetric, shift, shrink } from './operations.js';
|
|
13
|
+
export { debugPolygon, isPointInPolygon } from './polygon.js';
|
|
14
|
+
export { Rect, createRect, getRectCenters, getRectCorners, getRectEdges, isRect } from './rect.js';
|
|
15
|
+
export { Point, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInset, RectPoint, RectPoints, RectSide, RectValue, SymmetricRectInset } from './types.js';
|
|
16
|
+
export { union } from './union.js';
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ function alignRect(a, ref, options) {
|
|
|
103
103
|
return vAlign(hAlign(a, ref, h), ref, v);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// ../core/
|
|
106
|
+
// ../core/src/guard.ts
|
|
107
107
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
108
108
|
|
|
109
109
|
// src/rect.ts
|
|
@@ -267,20 +267,19 @@ function contains(r, v) {
|
|
|
267
267
|
return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
// ../dom/
|
|
270
|
+
// ../dom/src/get-computed-style.ts
|
|
271
271
|
function getCache() {
|
|
272
272
|
const g = globalThis;
|
|
273
273
|
g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
|
|
274
274
|
return g.__styleCache;
|
|
275
275
|
}
|
|
276
276
|
function getComputedStyle(el) {
|
|
277
|
-
var _a;
|
|
278
277
|
if (!el)
|
|
279
278
|
return {};
|
|
280
279
|
const cache = getCache();
|
|
281
280
|
let style = cache.get(el);
|
|
282
281
|
if (!style) {
|
|
283
|
-
const win =
|
|
282
|
+
const win = el?.ownerDocument.defaultView ?? window;
|
|
284
283
|
style = win.getComputedStyle(el);
|
|
285
284
|
cache.set(el, style);
|
|
286
285
|
}
|
|
@@ -409,13 +408,13 @@ function getWindowRect(win, opts = {}) {
|
|
|
409
408
|
}
|
|
410
409
|
function getViewportRect(win, opts) {
|
|
411
410
|
const { excludeScrollbar = false } = opts;
|
|
412
|
-
const { innerWidth
|
|
413
|
-
const width =
|
|
414
|
-
const height =
|
|
411
|
+
const { innerWidth, innerHeight, document: doc, visualViewport } = win;
|
|
412
|
+
const width = visualViewport?.width || innerWidth;
|
|
413
|
+
const height = visualViewport?.height || innerHeight;
|
|
415
414
|
const rect = { x: 0, y: 0, width, height };
|
|
416
415
|
if (excludeScrollbar) {
|
|
417
|
-
const scrollbarWidth =
|
|
418
|
-
const scrollbarHeight =
|
|
416
|
+
const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
|
|
417
|
+
const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
|
|
419
418
|
rect.width -= scrollbarWidth;
|
|
420
419
|
rect.height -= scrollbarHeight;
|
|
421
420
|
}
|