@zag-js/rect-utils 1.34.0 → 1.35.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.
Files changed (94) hide show
  1. package/dist/affine-transform.d.mts +39 -0
  2. package/dist/affine-transform.d.ts +39 -0
  3. package/dist/affine-transform.js +189 -0
  4. package/dist/affine-transform.mjs +166 -0
  5. package/dist/align.d.mts +5 -0
  6. package/dist/align.d.ts +5 -0
  7. package/dist/align.js +51 -0
  8. package/dist/align.mjs +28 -0
  9. package/dist/angle.d.mts +5 -0
  10. package/dist/angle.d.ts +5 -0
  11. package/dist/angle.js +35 -0
  12. package/dist/angle.mjs +12 -0
  13. package/dist/chunk-QZ7TP4HQ.mjs +7 -0
  14. package/dist/clamp.d.mts +12 -0
  15. package/dist/clamp.d.ts +12 -0
  16. package/dist/clamp.js +51 -0
  17. package/dist/clamp.mjs +27 -0
  18. package/dist/closest.d.mts +7 -0
  19. package/dist/closest.d.ts +7 -0
  20. package/dist/closest.js +69 -0
  21. package/dist/closest.mjs +44 -0
  22. package/dist/compass.d.mts +7 -0
  23. package/dist/compass.d.ts +7 -0
  24. package/dist/compass.js +51 -0
  25. package/dist/compass.mjs +27 -0
  26. package/dist/constrain.d.mts +5 -0
  27. package/dist/constrain.d.ts +5 -0
  28. package/dist/constrain.js +39 -0
  29. package/dist/constrain.mjs +16 -0
  30. package/dist/contains.d.mts +7 -0
  31. package/dist/contains.d.ts +7 -0
  32. package/dist/contains.js +43 -0
  33. package/dist/contains.mjs +18 -0
  34. package/dist/distance.d.mts +11 -0
  35. package/dist/distance.d.ts +11 -0
  36. package/dist/distance.js +68 -0
  37. package/dist/distance.mjs +42 -0
  38. package/dist/equality.d.mts +7 -0
  39. package/dist/equality.d.ts +7 -0
  40. package/dist/equality.js +42 -0
  41. package/dist/equality.mjs +17 -0
  42. package/dist/from-element.d.mts +15 -0
  43. package/dist/from-element.d.ts +15 -0
  44. package/dist/from-element.js +65 -0
  45. package/dist/from-element.mjs +42 -0
  46. package/dist/from-points.d.mts +5 -0
  47. package/dist/from-points.d.ts +5 -0
  48. package/dist/from-points.js +39 -0
  49. package/dist/from-points.mjs +16 -0
  50. package/dist/from-range.d.mts +5 -0
  51. package/dist/from-range.d.ts +5 -0
  52. package/dist/from-range.js +49 -0
  53. package/dist/from-range.mjs +26 -0
  54. package/dist/from-rotation.d.mts +7 -0
  55. package/dist/from-rotation.d.ts +7 -0
  56. package/dist/from-rotation.js +63 -0
  57. package/dist/from-rotation.mjs +38 -0
  58. package/dist/from-window.d.mts +23 -0
  59. package/dist/from-window.d.ts +23 -0
  60. package/dist/from-window.js +49 -0
  61. package/dist/from-window.mjs +25 -0
  62. package/dist/index.d.mts +22 -253
  63. package/dist/index.d.ts +22 -253
  64. package/dist/index.js +62 -772
  65. package/dist/index.mjs +22 -724
  66. package/dist/intersection.d.mts +16 -0
  67. package/dist/intersection.d.ts +16 -0
  68. package/dist/intersection.js +52 -0
  69. package/dist/intersection.mjs +27 -0
  70. package/dist/operations.d.mts +9 -0
  71. package/dist/operations.d.ts +9 -0
  72. package/dist/operations.js +66 -0
  73. package/dist/operations.mjs +39 -0
  74. package/dist/polygon.d.mts +10 -0
  75. package/dist/polygon.d.ts +10 -0
  76. package/dist/polygon.js +91 -0
  77. package/dist/polygon.mjs +66 -0
  78. package/dist/rect.d.mts +58 -0
  79. package/dist/rect.d.ts +58 -0
  80. package/dist/rect.js +97 -0
  81. package/dist/rect.mjs +66 -0
  82. package/dist/resize.d.mts +6 -0
  83. package/dist/resize.d.ts +6 -0
  84. package/dist/resize.js +113 -0
  85. package/dist/resize.mjs +90 -0
  86. package/dist/types.d.mts +55 -0
  87. package/dist/types.d.ts +55 -0
  88. package/dist/types.js +18 -0
  89. package/dist/types.mjs +0 -0
  90. package/dist/union.d.mts +5 -0
  91. package/dist/union.d.ts +5 -0
  92. package/dist/union.js +42 -0
  93. package/dist/union.mjs +19 -0
  94. package/package.json +1 -1
@@ -0,0 +1,65 @@
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-element.ts
21
+ var from_element_exports = {};
22
+ __export(from_element_exports, {
23
+ getElementRect: () => getElementRect
24
+ });
25
+ module.exports = __toCommonJS(from_element_exports);
26
+ var import_rect = require("./rect.cjs");
27
+ var styleCache = /* @__PURE__ */ new WeakMap();
28
+ function getCacheComputedStyle(el) {
29
+ if (!styleCache.has(el)) {
30
+ const win = el.ownerDocument.defaultView || window;
31
+ styleCache.set(el, win.getComputedStyle(el));
32
+ }
33
+ return styleCache.get(el);
34
+ }
35
+ function getElementRect(el, opts = {}) {
36
+ return (0, import_rect.createRect)(getClientRect(el, opts));
37
+ }
38
+ function getClientRect(el, opts = {}) {
39
+ const { excludeScrollbar = false, excludeBorders = false } = opts;
40
+ const { x, y, width, height } = el.getBoundingClientRect();
41
+ const r = { x, y, width, height };
42
+ const style = getCacheComputedStyle(el);
43
+ const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
44
+ const borderXWidth = sum(borderLeftWidth, borderRightWidth);
45
+ const borderYWidth = sum(borderTopWidth, borderBottomWidth);
46
+ if (excludeBorders) {
47
+ r.width -= borderXWidth;
48
+ r.height -= borderYWidth;
49
+ r.x += px(borderLeftWidth);
50
+ r.y += px(borderTopWidth);
51
+ }
52
+ if (excludeScrollbar) {
53
+ const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
54
+ const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
55
+ r.width -= scrollbarWidth;
56
+ r.height -= scrollbarHeight;
57
+ }
58
+ return r;
59
+ }
60
+ var px = (v) => parseFloat(v.replace("px", ""));
61
+ var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ getElementRect
65
+ });
@@ -0,0 +1,42 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/from-element.ts
4
+ import { createRect } from "./rect.mjs";
5
+ var styleCache = /* @__PURE__ */ new WeakMap();
6
+ function getCacheComputedStyle(el) {
7
+ if (!styleCache.has(el)) {
8
+ const win = el.ownerDocument.defaultView || window;
9
+ styleCache.set(el, win.getComputedStyle(el));
10
+ }
11
+ return styleCache.get(el);
12
+ }
13
+ function getElementRect(el, opts = {}) {
14
+ return createRect(getClientRect(el, opts));
15
+ }
16
+ function getClientRect(el, opts = {}) {
17
+ const { excludeScrollbar = false, excludeBorders = false } = opts;
18
+ const { x, y, width, height } = el.getBoundingClientRect();
19
+ const r = { x, y, width, height };
20
+ const style = getCacheComputedStyle(el);
21
+ const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
22
+ const borderXWidth = sum(borderLeftWidth, borderRightWidth);
23
+ const borderYWidth = sum(borderTopWidth, borderBottomWidth);
24
+ if (excludeBorders) {
25
+ r.width -= borderXWidth;
26
+ r.height -= borderYWidth;
27
+ r.x += px(borderLeftWidth);
28
+ r.y += px(borderTopWidth);
29
+ }
30
+ if (excludeScrollbar) {
31
+ const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
32
+ const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
33
+ r.width -= scrollbarWidth;
34
+ r.height -= scrollbarHeight;
35
+ }
36
+ return r;
37
+ }
38
+ var px = (v) => parseFloat(v.replace("px", ""));
39
+ var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
40
+ export {
41
+ getElementRect
42
+ };
@@ -0,0 +1,5 @@
1
+ import { Point, Rect } from './types.mjs';
2
+
3
+ declare function getRectFromPoints(...pts: Point[]): Rect;
4
+
5
+ export { getRectFromPoints };
@@ -0,0 +1,5 @@
1
+ import { Point, Rect } from './types.js';
2
+
3
+ declare function getRectFromPoints(...pts: Point[]): Rect;
4
+
5
+ export { getRectFromPoints };
@@ -0,0 +1,39 @@
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-points.ts
21
+ var from_points_exports = {};
22
+ __export(from_points_exports, {
23
+ getRectFromPoints: () => getRectFromPoints
24
+ });
25
+ module.exports = __toCommonJS(from_points_exports);
26
+ var import_rect = require("./rect.cjs");
27
+ function getRectFromPoints(...pts) {
28
+ const xs = pts.map((p) => p.x);
29
+ const ys = pts.map((p) => p.y);
30
+ const x = Math.min(...xs);
31
+ const y = Math.min(...ys);
32
+ const width = Math.max(...xs) - x;
33
+ const height = Math.max(...ys) - y;
34
+ return (0, import_rect.createRect)({ x, y, width, height });
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ getRectFromPoints
39
+ });
@@ -0,0 +1,16 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/from-points.ts
4
+ import { createRect } from "./rect.mjs";
5
+ function getRectFromPoints(...pts) {
6
+ const xs = pts.map((p) => p.x);
7
+ const ys = pts.map((p) => p.y);
8
+ const x = Math.min(...xs);
9
+ const y = Math.min(...ys);
10
+ const width = Math.max(...xs) - x;
11
+ const height = Math.max(...ys) - y;
12
+ return createRect({ x, y, width, height });
13
+ }
14
+ export {
15
+ getRectFromPoints
16
+ };
@@ -0,0 +1,5 @@
1
+ import { Rect } from './types.mjs';
2
+
3
+ declare function fromRange(range: Range): Rect;
4
+
5
+ export { fromRange };
@@ -0,0 +1,5 @@
1
+ import { Rect } from './types.js';
2
+
3
+ declare function fromRange(range: Range): Rect;
4
+
5
+ export { fromRange };
@@ -0,0 +1,49 @@
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
+ var import_rect = require("./rect.cjs");
27
+ var import_from_element = require("./from-element.cjs");
28
+ var import_union = require("./union.cjs");
29
+ function fromRange(range) {
30
+ let rs = [];
31
+ const rects = Array.from(range.getClientRects());
32
+ if (rects.length) {
33
+ rs = rs.concat(rects.map(import_rect.createRect));
34
+ return import_union.union.apply(void 0, rs);
35
+ }
36
+ let start = range.startContainer;
37
+ if (start.nodeType === Node.TEXT_NODE) {
38
+ start = start.parentNode;
39
+ }
40
+ if (start instanceof HTMLElement) {
41
+ const r = (0, import_from_element.getElementRect)(start);
42
+ rs.push({ ...r, x: r.maxX, width: 0 });
43
+ }
44
+ return import_union.union.apply(void 0, rs);
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ fromRange
49
+ });
@@ -0,0 +1,26 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/from-range.ts
4
+ import { createRect } from "./rect.mjs";
5
+ import { getElementRect } from "./from-element.mjs";
6
+ import { union } from "./union.mjs";
7
+ function fromRange(range) {
8
+ let rs = [];
9
+ const rects = Array.from(range.getClientRects());
10
+ if (rects.length) {
11
+ rs = rs.concat(rects.map(createRect));
12
+ return union.apply(void 0, rs);
13
+ }
14
+ let start = range.startContainer;
15
+ if (start.nodeType === Node.TEXT_NODE) {
16
+ start = start.parentNode;
17
+ }
18
+ if (start instanceof HTMLElement) {
19
+ const r = getElementRect(start);
20
+ rs.push({ ...r, x: r.maxX, width: 0 });
21
+ }
22
+ return union.apply(void 0, rs);
23
+ }
24
+ export {
25
+ fromRange
26
+ };
@@ -0,0 +1,7 @@
1
+ import { Rect, Point } from './types.mjs';
2
+
3
+ declare function toRad(d: number): number;
4
+ declare function rotate(a: Point, d: number, c: Point): Point;
5
+ declare function getRotationRect(r: Rect, deg: number): Rect;
6
+
7
+ export { getRotationRect, rotate, toRad };
@@ -0,0 +1,7 @@
1
+ import { Rect, Point } from './types.js';
2
+
3
+ declare function toRad(d: number): number;
4
+ declare function rotate(a: Point, d: number, c: Point): Point;
5
+ declare function getRotationRect(r: Rect, deg: number): Rect;
6
+
7
+ export { getRotationRect, rotate, toRad };
@@ -0,0 +1,63 @@
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
+ var import_rect = require("./rect.cjs");
29
+ function toRad(d) {
30
+ return d % 360 * Math.PI / 180;
31
+ }
32
+ function rotate(a, d, c) {
33
+ const r = toRad(d);
34
+ const sin = Math.sin(r);
35
+ const cos = Math.cos(r);
36
+ const x = a.x - c.x;
37
+ const y = a.y - c.y;
38
+ return {
39
+ x: c.x + x * cos - y * sin,
40
+ y: c.y + x * sin + y * cos
41
+ };
42
+ }
43
+ function getRotationRect(r, deg) {
44
+ const rr = Object.values((0, import_rect.getRectCorners)(r)).map((p) => rotate(p, deg, r.center));
45
+ const xs = rr.map((p) => p.x);
46
+ const ys = rr.map((p) => p.y);
47
+ const minX = Math.min(...xs);
48
+ const minY = Math.min(...ys);
49
+ const maxX = Math.max(...xs);
50
+ const maxY = Math.max(...ys);
51
+ return (0, import_rect.createRect)({
52
+ x: minX,
53
+ y: minY,
54
+ width: maxX - minX,
55
+ height: maxY - minY
56
+ });
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getRotationRect,
61
+ rotate,
62
+ toRad
63
+ });
@@ -0,0 +1,38 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/from-rotation.ts
4
+ import { createRect, getRectCorners } from "./rect.mjs";
5
+ function toRad(d) {
6
+ return d % 360 * Math.PI / 180;
7
+ }
8
+ function rotate(a, d, c) {
9
+ const r = toRad(d);
10
+ const sin = Math.sin(r);
11
+ const cos = Math.cos(r);
12
+ const x = a.x - c.x;
13
+ const y = a.y - c.y;
14
+ return {
15
+ x: c.x + x * cos - y * sin,
16
+ y: c.y + x * sin + y * cos
17
+ };
18
+ }
19
+ function getRotationRect(r, deg) {
20
+ const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
21
+ const xs = rr.map((p) => p.x);
22
+ const ys = rr.map((p) => p.y);
23
+ const minX = Math.min(...xs);
24
+ const minY = Math.min(...ys);
25
+ const maxX = Math.max(...xs);
26
+ const maxY = Math.max(...ys);
27
+ return createRect({
28
+ x: minX,
29
+ y: minY,
30
+ width: maxX - minX,
31
+ height: maxY - minY
32
+ });
33
+ }
34
+ export {
35
+ getRotationRect,
36
+ rotate,
37
+ toRad
38
+ };
@@ -0,0 +1,23 @@
1
+ import { Rect } from './types.mjs';
2
+
3
+ type WindowRectOptions = {
4
+ /**
5
+ * Whether to exclude the element's scrollbar size from the calculation.
6
+ */
7
+ excludeScrollbar?: boolean | undefined;
8
+ };
9
+ /**
10
+ * Creates a rectangle from window object
11
+ */
12
+ declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
13
+ /**
14
+ * Get the rect of the window with the option to exclude the scrollbar
15
+ */
16
+ declare function getViewportRect(win: Window, opts: WindowRectOptions): {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+
23
+ export { type WindowRectOptions, getViewportRect, getWindowRect };
@@ -0,0 +1,23 @@
1
+ import { Rect } from './types.js';
2
+
3
+ type WindowRectOptions = {
4
+ /**
5
+ * Whether to exclude the element's scrollbar size from the calculation.
6
+ */
7
+ excludeScrollbar?: boolean | undefined;
8
+ };
9
+ /**
10
+ * Creates a rectangle from window object
11
+ */
12
+ declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
13
+ /**
14
+ * Get the rect of the window with the option to exclude the scrollbar
15
+ */
16
+ declare function getViewportRect(win: Window, opts: WindowRectOptions): {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+
23
+ export { type WindowRectOptions, getViewportRect, getWindowRect };
@@ -0,0 +1,49 @@
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
+ var import_rect = require("./rect.cjs");
28
+ function getWindowRect(win, opts = {}) {
29
+ return (0, import_rect.createRect)(getViewportRect(win, opts));
30
+ }
31
+ function getViewportRect(win, opts) {
32
+ const { excludeScrollbar = false } = opts;
33
+ const { innerWidth, innerHeight, document: doc, visualViewport } = win;
34
+ const width = visualViewport?.width || innerWidth;
35
+ const height = visualViewport?.height || innerHeight;
36
+ const rect = { x: 0, y: 0, width, height };
37
+ if (excludeScrollbar) {
38
+ const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
39
+ const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
40
+ rect.width -= scrollbarWidth;
41
+ rect.height -= scrollbarHeight;
42
+ }
43
+ return rect;
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ getViewportRect,
48
+ getWindowRect
49
+ });
@@ -0,0 +1,25 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/from-window.ts
4
+ import { createRect } from "./rect.mjs";
5
+ function getWindowRect(win, opts = {}) {
6
+ return createRect(getViewportRect(win, opts));
7
+ }
8
+ function getViewportRect(win, opts) {
9
+ const { excludeScrollbar = false } = opts;
10
+ const { innerWidth, innerHeight, document: doc, visualViewport } = win;
11
+ const width = visualViewport?.width || innerWidth;
12
+ const height = visualViewport?.height || innerHeight;
13
+ const rect = { x: 0, y: 0, width, height };
14
+ if (excludeScrollbar) {
15
+ const scrollbarWidth = innerWidth - doc.documentElement.clientWidth;
16
+ const scrollbarHeight = innerHeight - doc.documentElement.clientHeight;
17
+ rect.width -= scrollbarWidth;
18
+ rect.height -= scrollbarHeight;
19
+ }
20
+ return rect;
21
+ }
22
+ export {
23
+ getViewportRect,
24
+ getWindowRect
25
+ };