@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.
Files changed (68) hide show
  1. package/dist/align.d.ts +5 -9
  2. package/dist/align.js +5 -28
  3. package/dist/align.mjs +44 -6
  4. package/dist/closest.d.ts +5 -8
  5. package/dist/closest.js +8 -38
  6. package/dist/closest.mjs +47 -13
  7. package/dist/contains.d.ts +5 -8
  8. package/dist/contains.js +9 -48
  9. package/dist/contains.mjs +13 -11
  10. package/dist/distance.d.ts +7 -10
  11. package/dist/distance.js +9 -40
  12. package/dist/distance.mjs +41 -14
  13. package/dist/from-element.d.ts +3 -7
  14. package/dist/from-element.js +9 -53
  15. package/dist/from-element.mjs +39 -7
  16. package/dist/from-points.d.ts +3 -6
  17. package/dist/from-points.js +6 -50
  18. package/dist/from-points.mjs +13 -7
  19. package/dist/from-range.d.ts +2 -6
  20. package/dist/from-range.js +11 -127
  21. package/dist/from-range.mjs +23 -10
  22. package/dist/from-rotation.d.ts +5 -8
  23. package/dist/from-rotation.js +9 -62
  24. package/dist/from-rotation.mjs +33 -11
  25. package/dist/from-window.d.ts +4 -8
  26. package/dist/from-window.js +7 -52
  27. package/dist/from-window.mjs +21 -9
  28. package/dist/get-polygon.d.ts +2 -5
  29. package/dist/get-polygon.js +7 -58
  30. package/dist/get-polygon.mjs +15 -7
  31. package/dist/index.d.ts +16 -16
  32. package/dist/index.js +58 -539
  33. package/dist/index.mjs +15 -105
  34. package/dist/intersection.d.ts +5 -8
  35. package/dist/intersection.js +8 -54
  36. package/dist/intersection.mjs +22 -11
  37. package/dist/operations.d.ts +7 -10
  38. package/dist/operations.js +12 -60
  39. package/dist/operations.mjs +32 -15
  40. package/dist/polygon.d.ts +3 -6
  41. package/dist/polygon.js +6 -30
  42. package/dist/polygon.mjs +48 -8
  43. package/dist/rect.d.ts +7 -10
  44. package/dist/rect.js +11 -38
  45. package/dist/rect.mjs +47 -14
  46. package/dist/types.d.ts +13 -15
  47. package/dist/union.d.ts +2 -6
  48. package/dist/union.js +7 -62
  49. package/dist/union.mjs +28 -8
  50. package/package.json +2 -7
  51. package/dist/chunk-25JXNQDO.mjs +0 -32
  52. package/dist/chunk-2FRM3R57.mjs +0 -27
  53. package/dist/chunk-62GE3RPG.mjs +0 -21
  54. package/dist/chunk-BDA5H4ND.mjs +0 -44
  55. package/dist/chunk-BRVYSREB.mjs +0 -21
  56. package/dist/chunk-D46YBNP3.mjs +0 -18
  57. package/dist/chunk-GYYHT756.mjs +0 -29
  58. package/dist/chunk-K4PDUEML.mjs +0 -33
  59. package/dist/chunk-MM5LIN7D.mjs +0 -41
  60. package/dist/chunk-MNKJK37U.mjs +0 -54
  61. package/dist/chunk-N5AQDOKZ.mjs +0 -49
  62. package/dist/chunk-Q4ND66B6.mjs +0 -54
  63. package/dist/chunk-QXXKPYP2.mjs +0 -47
  64. package/dist/chunk-R24UTBJ3.mjs +0 -52
  65. package/dist/chunk-W5IPBTYQ.mjs +0 -41
  66. package/dist/chunk-WBQAMGXK.mjs +0 -0
  67. package/dist/types.js +0 -18
  68. package/dist/types.mjs +0 -1
@@ -1,51 +1,9 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/from-points.ts
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
- // 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
- }
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
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- getRectFromPoints
61
- });
16
+
17
+ exports.getRectFromPoints = getRectFromPoints;
@@ -1,7 +1,13 @@
1
- import {
2
- getRectFromPoints
3
- } from "./chunk-D46YBNP3.mjs";
4
- import "./chunk-MNKJK37U.mjs";
5
- export {
6
- getRectFromPoints
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 };
@@ -1,6 +1,2 @@
1
- import { Rect } from './rect.js';
2
- import './types.js';
3
-
4
- declare function fromRange(range: Range): Rect;
5
-
6
- export { fromRange };
1
+ import { Rect } from "./rect";
2
+ export declare function fromRange(range: Range): Rect;
@@ -1,143 +1,27 @@
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-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
- // src/from-points.ts
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
- // src/union.ts
97
- var { min, max } = Math;
98
- function union(...rs) {
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
- // Annotate the CommonJS export names for ESM import in node:
141
- 0 && (module.exports = {
142
- fromRange
143
- });
26
+
27
+ exports.fromRange = fromRange;
@@ -1,10 +1,23 @@
1
- import {
2
- fromRange
3
- } from "./chunk-25JXNQDO.mjs";
4
- import "./chunk-K4PDUEML.mjs";
5
- import "./chunk-BDA5H4ND.mjs";
6
- import "./chunk-D46YBNP3.mjs";
7
- import "./chunk-MNKJK37U.mjs";
8
- export {
9
- fromRange
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 };
@@ -1,8 +1,5 @@
1
- import { Rect } from './rect.js';
2
- import { Point } from './types.js';
3
-
4
- declare function toRad(d: number): number;
5
- declare function rotate(a: Point, d: number, c: Point): Point;
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;
@@ -1,60 +1,9 @@
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);
1
+ 'use strict';
19
2
 
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);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
28
4
 
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
- }
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
- // Annotate the CommonJS export names for ESM import in node:
88
- 0 && (module.exports = {
89
- getRotationRect,
90
- rotate,
91
- toRad
92
- });
36
+
37
+ exports.getRotationRect = getRotationRect;
38
+ exports.rotate = rotate;
39
+ exports.toRad = toRad;
@@ -1,11 +1,33 @@
1
- import {
2
- getRotationRect,
3
- rotate,
4
- toRad
5
- } from "./chunk-W5IPBTYQ.mjs";
6
- import "./chunk-MNKJK37U.mjs";
7
- export {
8
- getRotationRect,
9
- rotate,
10
- toRad
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 };
@@ -1,7 +1,5 @@
1
- import { Rect } from './rect.js';
2
- import './types.js';
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 };
@@ -1,54 +1,11 @@
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);
1
+ 'use strict';
19
2
 
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);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
27
4
 
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
- }
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
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- getViewportRect,
70
- getWindowRect
71
- });
24
+
25
+ exports.getViewportRect = getViewportRect;
26
+ exports.getWindowRect = getWindowRect;
@@ -1,9 +1,21 @@
1
- import {
2
- getViewportRect,
3
- getWindowRect
4
- } from "./chunk-2FRM3R57.mjs";
5
- import "./chunk-MNKJK37U.mjs";
6
- export {
7
- getViewportRect,
8
- getWindowRect
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 };
@@ -1,8 +1,5 @@
1
- import { RectValue } from './types.js';
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 };
@@ -1,61 +1,12 @@
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);
1
+ 'use strict';
19
2
 
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);
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
26
4
 
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
- }
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
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- getElementPolygon
70
- });
18
+
19
+ exports.getElementPolygon = getElementPolygon;
@@ -1,7 +1,15 @@
1
- import {
2
- getElementPolygon
3
- } from "./chunk-BRVYSREB.mjs";
4
- import "./chunk-MNKJK37U.mjs";
5
- export {
6
- getElementPolygon
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 };