@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.
Files changed (68) hide show
  1. package/dist/align.d.ts +12 -0
  2. package/dist/align.js +71 -0
  3. package/dist/align.mjs +6 -0
  4. package/dist/chunk-2QYJISFU.mjs +21 -0
  5. package/dist/chunk-AYR2YRSU.mjs +49 -0
  6. package/dist/chunk-AYWORFWQ.mjs +32 -0
  7. package/dist/chunk-BGAHRJ6S.mjs +41 -0
  8. package/dist/chunk-DBR73IMM.mjs +54 -0
  9. package/dist/chunk-GVBSNO2Z.mjs +55 -0
  10. package/dist/chunk-IFHTGH3H.mjs +29 -0
  11. package/dist/chunk-LBA674LT.mjs +27 -0
  12. package/dist/chunk-NGMCS5TG.mjs +33 -0
  13. package/dist/chunk-QXXKPYP2.mjs +47 -0
  14. package/dist/chunk-R24UTBJ3.mjs +52 -0
  15. package/dist/chunk-S3HXSPS7.mjs +21 -0
  16. package/dist/chunk-T4IEPEZY.mjs +41 -0
  17. package/dist/chunk-TPU7B3ZS.mjs +18 -0
  18. package/dist/chunk-WBQAMGXK.mjs +0 -0
  19. package/dist/chunk-YDYJCJQZ.mjs +56 -0
  20. package/dist/closest.d.ts +8 -0
  21. package/dist/closest.js +83 -0
  22. package/dist/closest.mjs +13 -0
  23. package/dist/contains.d.ts +8 -0
  24. package/dist/contains.js +60 -0
  25. package/dist/contains.mjs +11 -0
  26. package/dist/distance.d.ts +12 -0
  27. package/dist/distance.js +79 -0
  28. package/dist/distance.mjs +14 -0
  29. package/dist/from-element.d.ts +16 -0
  30. package/dist/from-element.js +98 -0
  31. package/dist/from-element.mjs +7 -0
  32. package/dist/from-points.d.ts +6 -0
  33. package/dist/from-points.js +61 -0
  34. package/dist/from-points.mjs +7 -0
  35. package/dist/from-range.d.ts +6 -0
  36. package/dist/from-range.js +154 -0
  37. package/dist/from-range.mjs +10 -0
  38. package/dist/from-rotation.d.ts +8 -0
  39. package/dist/from-rotation.js +92 -0
  40. package/dist/from-rotation.mjs +11 -0
  41. package/dist/from-window.d.ts +24 -0
  42. package/dist/from-window.js +71 -0
  43. package/dist/from-window.mjs +9 -0
  44. package/dist/get-polygon.d.ts +8 -0
  45. package/dist/get-polygon.js +70 -0
  46. package/dist/get-polygon.mjs +7 -0
  47. package/dist/index.d.ts +16 -186
  48. package/dist/index.js +8 -9
  49. package/dist/index.mjs +67 -453
  50. package/dist/intersection.d.ts +17 -0
  51. package/dist/intersection.js +74 -0
  52. package/dist/intersection.mjs +11 -0
  53. package/dist/operations.d.ts +10 -0
  54. package/dist/operations.js +88 -0
  55. package/dist/operations.mjs +15 -0
  56. package/dist/polygon.d.ts +6 -0
  57. package/dist/polygon.js +77 -0
  58. package/dist/polygon.mjs +8 -0
  59. package/dist/rect.d.ts +64 -0
  60. package/dist/rect.js +86 -0
  61. package/dist/rect.mjs +14 -0
  62. package/dist/types.d.ts +32 -0
  63. package/dist/types.js +18 -0
  64. package/dist/types.mjs +1 -0
  65. package/dist/union.d.ts +6 -0
  66. package/dist/union.js +87 -0
  67. package/dist/union.mjs +8 -0
  68. package/package.json +18 -8
@@ -0,0 +1,83 @@
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/closest.ts
21
+ var closest_exports = {};
22
+ __export(closest_exports, {
23
+ closest: () => closest,
24
+ closestSideToPoint: () => closestSideToPoint,
25
+ closestSideToRect: () => closestSideToRect
26
+ });
27
+ module.exports = __toCommonJS(closest_exports);
28
+
29
+ // src/distance.ts
30
+ function distance(a, b = { x: 0, y: 0 }) {
31
+ return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
32
+ }
33
+
34
+ // src/closest.ts
35
+ function closest(...pts) {
36
+ return (a) => {
37
+ const ds = pts.map((b) => distance(b, a));
38
+ const c = Math.min.apply(Math, ds);
39
+ return pts[ds.indexOf(c)];
40
+ };
41
+ }
42
+ function closestSideToRect(ref, r) {
43
+ if (r.maxX <= ref.minX) {
44
+ return "left";
45
+ }
46
+ if (r.minX >= ref.maxX) {
47
+ return "right";
48
+ }
49
+ if (r.maxY <= ref.minY) {
50
+ return "top";
51
+ }
52
+ if (r.minY >= ref.maxY) {
53
+ return "bottom";
54
+ }
55
+ return "left";
56
+ }
57
+ function closestSideToPoint(ref, p) {
58
+ const { x, y } = p;
59
+ const dl = x - ref.minX;
60
+ const dr = ref.maxX - x;
61
+ const dt = y - ref.minY;
62
+ const db = ref.maxY - y;
63
+ let closest2 = dl;
64
+ let side = "left";
65
+ if (dr < closest2) {
66
+ closest2 = dr;
67
+ side = "right";
68
+ }
69
+ if (dt < closest2) {
70
+ closest2 = dt;
71
+ side = "top";
72
+ }
73
+ if (db < closest2) {
74
+ side = "bottom";
75
+ }
76
+ return side;
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ closest,
81
+ closestSideToPoint,
82
+ closestSideToRect
83
+ });
@@ -0,0 +1,13 @@
1
+ import {
2
+ closest,
3
+ closestSideToPoint,
4
+ closestSideToRect
5
+ } from "./chunk-DBR73IMM.mjs";
6
+ import "./chunk-AYR2YRSU.mjs";
7
+ import "./chunk-IFHTGH3H.mjs";
8
+ import "./chunk-YDYJCJQZ.mjs";
9
+ export {
10
+ closest,
11
+ closestSideToPoint,
12
+ closestSideToRect
13
+ };
@@ -0,0 +1,8 @@
1
+ import { Rect } from './rect.js';
2
+ import { Point } from './types.js';
3
+
4
+ declare function containsPoint(r: Rect, p: Point): boolean;
5
+ declare function containsRect(a: Rect, b: Rect): boolean;
6
+ declare function contains(r: Rect, v: Rect | Point): boolean;
7
+
8
+ export { contains, containsPoint, containsRect };
@@ -0,0 +1,60 @@
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/contains.ts
21
+ var contains_exports = {};
22
+ __export(contains_exports, {
23
+ contains: () => contains,
24
+ containsPoint: () => containsPoint,
25
+ containsRect: () => containsRect
26
+ });
27
+ module.exports = __toCommonJS(contains_exports);
28
+
29
+ // ../core/src/guard.ts
30
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
31
+
32
+ // src/rect.ts
33
+ var point = (x, y) => ({ x, y });
34
+ function isRect(v) {
35
+ return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
36
+ }
37
+ function getRectCorners(v) {
38
+ const top = point(v.minX, v.minY);
39
+ const right = point(v.maxX, v.minY);
40
+ const bottom = point(v.maxX, v.maxY);
41
+ const left = point(v.minX, v.maxY);
42
+ return { top, right, bottom, left };
43
+ }
44
+
45
+ // src/contains.ts
46
+ function containsPoint(r, p) {
47
+ return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
48
+ }
49
+ function containsRect(a, b) {
50
+ return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
51
+ }
52
+ function contains(r, v) {
53
+ return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ contains,
58
+ containsPoint,
59
+ containsRect
60
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ contains,
3
+ containsPoint,
4
+ containsRect
5
+ } from "./chunk-2QYJISFU.mjs";
6
+ import "./chunk-YDYJCJQZ.mjs";
7
+ export {
8
+ contains,
9
+ containsPoint,
10
+ containsRect
11
+ };
@@ -0,0 +1,12 @@
1
+ import { Rect } from './rect.js';
2
+ import { Point, RectSide } from './types.js';
3
+
4
+ type DistanceValue = Point & {
5
+ value: number;
6
+ };
7
+ declare function distance(a: Point, b?: Point): number;
8
+ declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
9
+ declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
10
+ declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
11
+
12
+ export { DistanceValue, distance, distanceBtwEdges, distanceFromPoint, distanceFromRect };
@@ -0,0 +1,79 @@
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/distance.ts
21
+ var distance_exports = {};
22
+ __export(distance_exports, {
23
+ distance: () => distance,
24
+ distanceBtwEdges: () => distanceBtwEdges,
25
+ distanceFromPoint: () => distanceFromPoint,
26
+ distanceFromRect: () => distanceFromRect
27
+ });
28
+ module.exports = __toCommonJS(distance_exports);
29
+
30
+ // src/intersection.ts
31
+ function intersects(a, b) {
32
+ return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
33
+ }
34
+
35
+ // src/distance.ts
36
+ function distance(a, b = { x: 0, y: 0 }) {
37
+ return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
38
+ }
39
+ function distanceFromPoint(r, p) {
40
+ let x = 0;
41
+ let y = 0;
42
+ if (p.x < r.x)
43
+ x = r.x - p.x;
44
+ else if (p.x > r.maxX)
45
+ x = p.x - r.maxX;
46
+ if (p.y < r.y)
47
+ y = r.y - p.y;
48
+ else if (p.y > r.maxY)
49
+ y = p.y - r.maxY;
50
+ return { x, y, value: distance({ x, y }) };
51
+ }
52
+ function distanceFromRect(a, b) {
53
+ if (intersects(a, b))
54
+ return { x: 0, y: 0, value: 0 };
55
+ const left = a.x < b.x ? a : b;
56
+ const right = b.x < a.x ? a : b;
57
+ const upper = a.y < b.y ? a : b;
58
+ const lower = b.y < a.y ? a : b;
59
+ let x = left.x === right.x ? 0 : right.x - left.maxX;
60
+ x = Math.max(0, x);
61
+ let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
62
+ y = Math.max(0, y);
63
+ return { x, y, value: distance({ x, y }) };
64
+ }
65
+ function distanceBtwEdges(a, b) {
66
+ return {
67
+ left: b.x - a.x,
68
+ top: b.y - a.y,
69
+ right: a.maxX - b.maxX,
70
+ bottom: a.maxY - b.maxY
71
+ };
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ distance,
76
+ distanceBtwEdges,
77
+ distanceFromPoint,
78
+ distanceFromRect
79
+ });
@@ -0,0 +1,14 @@
1
+ import {
2
+ distance,
3
+ distanceBtwEdges,
4
+ distanceFromPoint,
5
+ distanceFromRect
6
+ } from "./chunk-AYR2YRSU.mjs";
7
+ import "./chunk-IFHTGH3H.mjs";
8
+ import "./chunk-YDYJCJQZ.mjs";
9
+ export {
10
+ distance,
11
+ distanceBtwEdges,
12
+ distanceFromPoint,
13
+ distanceFromRect
14
+ };
@@ -0,0 +1,16 @@
1
+ import { Rect } from './rect.js';
2
+ import './types.js';
3
+
4
+ declare function getElementRect(el: HTMLElement, opts?: ElementRectOptions): Rect;
5
+ type ElementRectOptions = {
6
+ /**
7
+ * Whether to exclude the element's scrollbar size from the calculation.
8
+ */
9
+ excludeScrollbar?: boolean;
10
+ /**
11
+ * Whether to exclude the element's borders from the calculation.
12
+ */
13
+ excludeBorders?: boolean;
14
+ };
15
+
16
+ export { ElementRectOptions, getElementRect };
@@ -0,0 +1,98 @@
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
+
27
+ // ../dom/src/get-computed-style.ts
28
+ function getCache() {
29
+ const g = globalThis;
30
+ g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
31
+ return g.__styleCache;
32
+ }
33
+ function getComputedStyle(el) {
34
+ if (!el)
35
+ return {};
36
+ const cache = getCache();
37
+ let style = cache.get(el);
38
+ if (!style) {
39
+ const win = el?.ownerDocument.defaultView ?? window;
40
+ style = win.getComputedStyle(el);
41
+ cache.set(el, style);
42
+ }
43
+ return style;
44
+ }
45
+
46
+ // src/rect.ts
47
+ var point = (x, y) => ({ x, y });
48
+ function createRect(r) {
49
+ const { x, y, width, height } = r;
50
+ const midX = x + width / 2;
51
+ const midY = y + height / 2;
52
+ return {
53
+ x,
54
+ y,
55
+ width,
56
+ height,
57
+ minX: x,
58
+ minY: y,
59
+ maxX: x + width,
60
+ maxY: y + height,
61
+ midX,
62
+ midY,
63
+ center: point(midX, midY)
64
+ };
65
+ }
66
+
67
+ // src/from-element.ts
68
+ function getElementRect(el, opts = {}) {
69
+ return createRect(getClientRect(el, opts));
70
+ }
71
+ function getClientRect(el, opts = {}) {
72
+ const { excludeScrollbar = false, excludeBorders = false } = opts;
73
+ const { x, y, width, height } = el.getBoundingClientRect();
74
+ const r = { x, y, width, height };
75
+ const style = getComputedStyle(el);
76
+ const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
77
+ const borderXWidth = sum(borderLeftWidth, borderRightWidth);
78
+ const borderYWidth = sum(borderTopWidth, borderBottomWidth);
79
+ if (excludeBorders) {
80
+ r.width -= borderXWidth;
81
+ r.height -= borderYWidth;
82
+ r.x += px(borderLeftWidth);
83
+ r.y += px(borderTopWidth);
84
+ }
85
+ if (excludeScrollbar) {
86
+ const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
87
+ const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
88
+ r.width -= scrollbarWidth;
89
+ r.height -= scrollbarHeight;
90
+ }
91
+ return r;
92
+ }
93
+ var px = (v) => parseFloat(v.replace("px", ""));
94
+ var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ getElementRect
98
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ getElementRect
3
+ } from "./chunk-GVBSNO2Z.mjs";
4
+ import "./chunk-YDYJCJQZ.mjs";
5
+ export {
6
+ getElementRect
7
+ };
@@ -0,0 +1,6 @@
1
+ import { Rect } from './rect.js';
2
+ import { Point } from './types.js';
3
+
4
+ declare function getRectFromPoints(...pts: Point[]): Rect;
5
+
6
+ export { getRectFromPoints };
@@ -0,0 +1,61 @@
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
+
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-points.ts
49
+ function getRectFromPoints(...pts) {
50
+ const xs = pts.map((p) => p.x);
51
+ const ys = pts.map((p) => p.y);
52
+ const x = Math.min(...xs);
53
+ const y = Math.min(...ys);
54
+ const width = Math.max(...xs) - x;
55
+ const height = Math.max(...ys) - y;
56
+ return createRect({ x, y, width, height });
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getRectFromPoints
61
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ getRectFromPoints
3
+ } from "./chunk-TPU7B3ZS.mjs";
4
+ import "./chunk-YDYJCJQZ.mjs";
5
+ export {
6
+ getRectFromPoints
7
+ };
@@ -0,0 +1,6 @@
1
+ import { Rect } from './rect.js';
2
+ import './types.js';
3
+
4
+ declare function fromRange(range: Range): Rect;
5
+
6
+ export { fromRange };
@@ -0,0 +1,154 @@
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
+ // ../dom/src/get-computed-style.ts
49
+ function getCache() {
50
+ const g = globalThis;
51
+ g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
52
+ return g.__styleCache;
53
+ }
54
+ function getComputedStyle(el) {
55
+ if (!el)
56
+ return {};
57
+ const cache = getCache();
58
+ let style = cache.get(el);
59
+ if (!style) {
60
+ const win = el?.ownerDocument.defaultView ?? window;
61
+ style = win.getComputedStyle(el);
62
+ cache.set(el, style);
63
+ }
64
+ return style;
65
+ }
66
+
67
+ // src/from-element.ts
68
+ function getElementRect(el, opts = {}) {
69
+ return createRect(getClientRect(el, opts));
70
+ }
71
+ function getClientRect(el, opts = {}) {
72
+ const { excludeScrollbar = false, excludeBorders = false } = opts;
73
+ const { x, y, width, height } = el.getBoundingClientRect();
74
+ const r = { x, y, width, height };
75
+ const style = getComputedStyle(el);
76
+ const { borderLeftWidth, borderTopWidth, borderRightWidth, borderBottomWidth } = style;
77
+ const borderXWidth = sum(borderLeftWidth, borderRightWidth);
78
+ const borderYWidth = sum(borderTopWidth, borderBottomWidth);
79
+ if (excludeBorders) {
80
+ r.width -= borderXWidth;
81
+ r.height -= borderYWidth;
82
+ r.x += px(borderLeftWidth);
83
+ r.y += px(borderTopWidth);
84
+ }
85
+ if (excludeScrollbar) {
86
+ const scrollbarWidth = el.offsetWidth - el.clientWidth - borderXWidth;
87
+ const scrollbarHeight = el.offsetHeight - el.clientHeight - borderYWidth;
88
+ r.width -= scrollbarWidth;
89
+ r.height -= scrollbarHeight;
90
+ }
91
+ return r;
92
+ }
93
+ var px = (v) => parseFloat(v.replace("px", ""));
94
+ var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
95
+
96
+ // src/from-points.ts
97
+ function getRectFromPoints(...pts) {
98
+ const xs = pts.map((p) => p.x);
99
+ const ys = pts.map((p) => p.y);
100
+ const x = Math.min(...xs);
101
+ const y = Math.min(...ys);
102
+ const width = Math.max(...xs) - x;
103
+ const height = Math.max(...ys) - y;
104
+ return createRect({ x, y, width, height });
105
+ }
106
+
107
+ // src/union.ts
108
+ var { min, max } = Math;
109
+ function union(...rs) {
110
+ const pMin = {
111
+ x: min.apply(
112
+ Math,
113
+ rs.map((r) => r.minX)
114
+ ),
115
+ y: min.apply(
116
+ Math,
117
+ rs.map((r) => r.minY)
118
+ )
119
+ };
120
+ const pMax = {
121
+ x: max.apply(
122
+ Math,
123
+ rs.map((r) => r.maxX)
124
+ ),
125
+ y: max.apply(
126
+ Math,
127
+ rs.map((r) => r.maxY)
128
+ )
129
+ };
130
+ return getRectFromPoints(pMin, pMax);
131
+ }
132
+
133
+ // src/from-range.ts
134
+ function fromRange(range) {
135
+ let rs = [];
136
+ const rects = Array.from(range.getClientRects());
137
+ if (rects.length) {
138
+ rs = rs.concat(rects.map(createRect));
139
+ return union.apply(void 0, rs);
140
+ }
141
+ let start = range.startContainer;
142
+ if (start.nodeType === Node.TEXT_NODE) {
143
+ start = start.parentNode;
144
+ }
145
+ if (start instanceof HTMLElement) {
146
+ const r = getElementRect(start);
147
+ rs.push({ ...r, x: r.maxX, width: 0 });
148
+ }
149
+ return union.apply(void 0, rs);
150
+ }
151
+ // Annotate the CommonJS export names for ESM import in node:
152
+ 0 && (module.exports = {
153
+ fromRange
154
+ });
@@ -0,0 +1,10 @@
1
+ import {
2
+ fromRange
3
+ } from "./chunk-AYWORFWQ.mjs";
4
+ import "./chunk-NGMCS5TG.mjs";
5
+ import "./chunk-GVBSNO2Z.mjs";
6
+ import "./chunk-TPU7B3ZS.mjs";
7
+ import "./chunk-YDYJCJQZ.mjs";
8
+ export {
9
+ fromRange
10
+ };
@@ -0,0 +1,8 @@
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 };