@zag-js/rect-utils 1.34.1 → 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,16 @@
1
+ import { Rect, RectSide } from './types.mjs';
2
+
3
+ /**
4
+ * Checks if a Rect intersects another Rect
5
+ */
6
+ declare function intersects(a: Rect, b: Rect): boolean;
7
+ /**
8
+ * Returns a new Rect that represents the intersection between two Rects
9
+ */
10
+ declare function intersection(a: Rect, b: Rect): Rect;
11
+ /**
12
+ * Returns whether two rects collide along each edge
13
+ */
14
+ declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
15
+
16
+ export { collisions, intersection, intersects };
@@ -0,0 +1,16 @@
1
+ import { Rect, RectSide } from './types.js';
2
+
3
+ /**
4
+ * Checks if a Rect intersects another Rect
5
+ */
6
+ declare function intersects(a: Rect, b: Rect): boolean;
7
+ /**
8
+ * Returns a new Rect that represents the intersection between two Rects
9
+ */
10
+ declare function intersection(a: Rect, b: Rect): Rect;
11
+ /**
12
+ * Returns whether two rects collide along each edge
13
+ */
14
+ declare function collisions(a: Rect, b: Rect): Record<RectSide, boolean>;
15
+
16
+ export { collisions, intersection, intersects };
@@ -0,0 +1,52 @@
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/intersection.ts
21
+ var intersection_exports = {};
22
+ __export(intersection_exports, {
23
+ collisions: () => collisions,
24
+ intersection: () => intersection,
25
+ intersects: () => intersects
26
+ });
27
+ module.exports = __toCommonJS(intersection_exports);
28
+ var import_rect = require("./rect.cjs");
29
+ function intersects(a, b) {
30
+ return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
31
+ }
32
+ function intersection(a, b) {
33
+ const x = Math.max(a.x, b.x);
34
+ const y = Math.max(a.y, b.y);
35
+ const x2 = Math.min(a.x + a.width, b.x + b.width);
36
+ const y2 = Math.min(a.y + a.height, b.y + b.height);
37
+ return (0, import_rect.createRect)({ x, y, width: x2 - x, height: y2 - y });
38
+ }
39
+ function collisions(a, b) {
40
+ return {
41
+ top: a.minY <= b.minY,
42
+ right: a.maxX >= b.maxX,
43
+ bottom: a.maxY >= b.maxY,
44
+ left: a.minX <= b.minX
45
+ };
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ collisions,
50
+ intersection,
51
+ intersects
52
+ });
@@ -0,0 +1,27 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/intersection.ts
4
+ import { createRect } from "./rect.mjs";
5
+ function intersects(a, b) {
6
+ return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
7
+ }
8
+ function intersection(a, b) {
9
+ const x = Math.max(a.x, b.x);
10
+ const y = Math.max(a.y, b.y);
11
+ const x2 = Math.min(a.x + a.width, b.x + b.width);
12
+ const y2 = Math.min(a.y + a.height, b.y + b.height);
13
+ return createRect({ x, y, width: x2 - x, height: y2 - y });
14
+ }
15
+ function collisions(a, b) {
16
+ return {
17
+ top: a.minY <= b.minY,
18
+ right: a.maxX >= b.maxX,
19
+ bottom: a.maxY >= b.maxY,
20
+ left: a.minX <= b.minX
21
+ };
22
+ }
23
+ export {
24
+ collisions,
25
+ intersection,
26
+ intersects
27
+ };
@@ -0,0 +1,9 @@
1
+ import { Rect, SymmetricRectInset, RectInset, Point } from './types.mjs';
2
+
3
+ declare const isSymmetric: (v: any) => v is SymmetricRectInset;
4
+ declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
5
+ declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
6
+ declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
7
+ declare function shift(r: Rect, o: Partial<Point>): Rect;
8
+
9
+ export { expand, inset, isSymmetric, shift, shrink };
@@ -0,0 +1,9 @@
1
+ import { Rect, SymmetricRectInset, RectInset, Point } from './types.js';
2
+
3
+ declare const isSymmetric: (v: any) => v is SymmetricRectInset;
4
+ declare function inset(r: Rect, i: RectInset | SymmetricRectInset): Rect;
5
+ declare function expand(r: Rect, v: number | SymmetricRectInset): Rect;
6
+ declare function shrink(r: Rect, v: number | SymmetricRectInset): Rect;
7
+ declare function shift(r: Rect, o: Partial<Point>): Rect;
8
+
9
+ export { expand, inset, isSymmetric, shift, shrink };
@@ -0,0 +1,66 @@
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/operations.ts
21
+ var operations_exports = {};
22
+ __export(operations_exports, {
23
+ expand: () => expand,
24
+ inset: () => inset,
25
+ isSymmetric: () => isSymmetric,
26
+ shift: () => shift,
27
+ shrink: () => shrink
28
+ });
29
+ module.exports = __toCommonJS(operations_exports);
30
+ var import_rect = require("./rect.cjs");
31
+ var isSymmetric = (v) => "dx" in v || "dy" in v;
32
+ function inset(r, i) {
33
+ const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
34
+ const { top = 0, right = 0, bottom = 0, left = 0 } = v;
35
+ return (0, import_rect.createRect)({
36
+ x: r.x + left,
37
+ y: r.y + top,
38
+ width: r.width - left - right,
39
+ height: r.height - top - bottom
40
+ });
41
+ }
42
+ function expand(r, v) {
43
+ const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
44
+ return inset(r, value);
45
+ }
46
+ function shrink(r, v) {
47
+ const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
48
+ return inset(r, value);
49
+ }
50
+ function shift(r, o) {
51
+ const { x = 0, y = 0 } = o;
52
+ return (0, import_rect.createRect)({
53
+ x: r.x + x,
54
+ y: r.y + y,
55
+ width: r.width,
56
+ height: r.height
57
+ });
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ expand,
62
+ inset,
63
+ isSymmetric,
64
+ shift,
65
+ shrink
66
+ });
@@ -0,0 +1,39 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/operations.ts
4
+ import { createRect } from "./rect.mjs";
5
+ var isSymmetric = (v) => "dx" in v || "dy" in v;
6
+ function inset(r, i) {
7
+ const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
8
+ const { top = 0, right = 0, bottom = 0, left = 0 } = v;
9
+ return createRect({
10
+ x: r.x + left,
11
+ y: r.y + top,
12
+ width: r.width - left - right,
13
+ height: r.height - top - bottom
14
+ });
15
+ }
16
+ function expand(r, v) {
17
+ const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
18
+ return inset(r, value);
19
+ }
20
+ function shrink(r, v) {
21
+ const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
22
+ return inset(r, value);
23
+ }
24
+ function shift(r, o) {
25
+ const { x = 0, y = 0 } = o;
26
+ return createRect({
27
+ x: r.x + x,
28
+ y: r.y + y,
29
+ width: r.width,
30
+ height: r.height
31
+ });
32
+ }
33
+ export {
34
+ expand,
35
+ inset,
36
+ isSymmetric,
37
+ shift,
38
+ shrink
39
+ };
@@ -0,0 +1,10 @@
1
+ import { Point, RectInit } from './types.mjs';
2
+
3
+ declare function getElementPolygon(rectValue: RectInit, placement: string): {
4
+ x: number;
5
+ y: number;
6
+ }[] | undefined;
7
+ declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
8
+ declare function debugPolygon(polygon: Point[]): () => void;
9
+
10
+ export { debugPolygon, getElementPolygon, isPointInPolygon };
@@ -0,0 +1,10 @@
1
+ import { Point, RectInit } from './types.js';
2
+
3
+ declare function getElementPolygon(rectValue: RectInit, placement: string): {
4
+ x: number;
5
+ y: number;
6
+ }[] | undefined;
7
+ declare function isPointInPolygon(polygon: Point[], point: Point): boolean;
8
+ declare function debugPolygon(polygon: Point[]): () => void;
9
+
10
+ export { debugPolygon, getElementPolygon, isPointInPolygon };
@@ -0,0 +1,91 @@
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/polygon.ts
21
+ var polygon_exports = {};
22
+ __export(polygon_exports, {
23
+ debugPolygon: () => debugPolygon,
24
+ getElementPolygon: () => getElementPolygon,
25
+ isPointInPolygon: () => isPointInPolygon
26
+ });
27
+ module.exports = __toCommonJS(polygon_exports);
28
+ var import_rect = require("./rect.cjs");
29
+ function getElementPolygon(rectValue, placement) {
30
+ const rect = (0, import_rect.createRect)(rectValue);
31
+ const { top, right, left, bottom } = (0, import_rect.getRectCorners)(rect);
32
+ const [base] = placement.split("-");
33
+ return {
34
+ top: [left, top, right, bottom],
35
+ right: [top, right, bottom, left],
36
+ bottom: [top, left, bottom, right],
37
+ left: [right, top, left, bottom]
38
+ }[base];
39
+ }
40
+ function isPointInPolygon(polygon, point) {
41
+ const { x, y } = point;
42
+ let c = false;
43
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
44
+ const xi = polygon[i].x;
45
+ const yi = polygon[i].y;
46
+ const xj = polygon[j].x;
47
+ const yj = polygon[j].y;
48
+ if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
49
+ c = !c;
50
+ }
51
+ }
52
+ return c;
53
+ }
54
+ function createPolygonElement() {
55
+ const id = "debug-polygon";
56
+ const existingPolygon = document.getElementById(id);
57
+ if (existingPolygon) {
58
+ return existingPolygon;
59
+ }
60
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
61
+ Object.assign(svg.style, {
62
+ top: "0",
63
+ left: "0",
64
+ width: "100%",
65
+ height: "100%",
66
+ opacity: "0.15",
67
+ position: "fixed",
68
+ pointerEvents: "none",
69
+ fill: "red"
70
+ });
71
+ const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
72
+ polygon.setAttribute("id", id);
73
+ polygon.setAttribute("points", "0,0 0,0");
74
+ svg.appendChild(polygon);
75
+ document.body.appendChild(svg);
76
+ return polygon;
77
+ }
78
+ function debugPolygon(polygon) {
79
+ const el = createPolygonElement();
80
+ const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
81
+ el.setAttribute("points", points);
82
+ return () => {
83
+ el.remove();
84
+ };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ debugPolygon,
89
+ getElementPolygon,
90
+ isPointInPolygon
91
+ });
@@ -0,0 +1,66 @@
1
+ import "./chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/polygon.ts
4
+ import { createRect, getRectCorners } from "./rect.mjs";
5
+ function getElementPolygon(rectValue, placement) {
6
+ const rect = createRect(rectValue);
7
+ const { top, right, left, bottom } = getRectCorners(rect);
8
+ const [base] = placement.split("-");
9
+ return {
10
+ top: [left, top, right, bottom],
11
+ right: [top, right, bottom, left],
12
+ bottom: [top, left, bottom, right],
13
+ left: [right, top, left, bottom]
14
+ }[base];
15
+ }
16
+ function isPointInPolygon(polygon, point) {
17
+ const { x, y } = point;
18
+ let c = false;
19
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
20
+ const xi = polygon[i].x;
21
+ const yi = polygon[i].y;
22
+ const xj = polygon[j].x;
23
+ const yj = polygon[j].y;
24
+ if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
25
+ c = !c;
26
+ }
27
+ }
28
+ return c;
29
+ }
30
+ function createPolygonElement() {
31
+ const id = "debug-polygon";
32
+ const existingPolygon = document.getElementById(id);
33
+ if (existingPolygon) {
34
+ return existingPolygon;
35
+ }
36
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
37
+ Object.assign(svg.style, {
38
+ top: "0",
39
+ left: "0",
40
+ width: "100%",
41
+ height: "100%",
42
+ opacity: "0.15",
43
+ position: "fixed",
44
+ pointerEvents: "none",
45
+ fill: "red"
46
+ });
47
+ const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
48
+ polygon.setAttribute("id", id);
49
+ polygon.setAttribute("points", "0,0 0,0");
50
+ svg.appendChild(polygon);
51
+ document.body.appendChild(svg);
52
+ return polygon;
53
+ }
54
+ function debugPolygon(polygon) {
55
+ const el = createPolygonElement();
56
+ const points = polygon.map((point) => `${point.x},${point.y}`).join(" ");
57
+ el.setAttribute("points", points);
58
+ return () => {
59
+ el.remove();
60
+ };
61
+ }
62
+ export {
63
+ debugPolygon,
64
+ getElementPolygon,
65
+ isPointInPolygon
66
+ };
@@ -0,0 +1,58 @@
1
+ import { Point, RectInit, Rect, RectEdge } from './types.mjs';
2
+
3
+ declare const createPoint: (x: number, y: number) => {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ declare const subtractPoints: (a: Point, b: Point | null) => Point;
8
+ declare const addPoints: (a: Point, b: Point) => {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ declare function isPoint(v: any): v is Point;
13
+ declare function createRect(r: RectInit): Rect;
14
+ declare function isRect(v: any): v is Rect;
15
+ declare function getRectCenters(v: Rect): {
16
+ top: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ right: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ bottom: {
25
+ x: number;
26
+ y: number;
27
+ };
28
+ left: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ };
33
+ declare function getRectCorners(v: Rect): {
34
+ top: {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ right: {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ bottom: {
43
+ x: number;
44
+ y: number;
45
+ };
46
+ left: {
47
+ x: number;
48
+ y: number;
49
+ };
50
+ };
51
+ declare function getRectEdges(v: Rect): {
52
+ top: RectEdge;
53
+ right: RectEdge;
54
+ bottom: RectEdge;
55
+ left: RectEdge;
56
+ };
57
+
58
+ export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
package/dist/rect.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { Point, RectInit, Rect, RectEdge } from './types.js';
2
+
3
+ declare const createPoint: (x: number, y: number) => {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ declare const subtractPoints: (a: Point, b: Point | null) => Point;
8
+ declare const addPoints: (a: Point, b: Point) => {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ declare function isPoint(v: any): v is Point;
13
+ declare function createRect(r: RectInit): Rect;
14
+ declare function isRect(v: any): v is Rect;
15
+ declare function getRectCenters(v: Rect): {
16
+ top: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ right: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ bottom: {
25
+ x: number;
26
+ y: number;
27
+ };
28
+ left: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ };
33
+ declare function getRectCorners(v: Rect): {
34
+ top: {
35
+ x: number;
36
+ y: number;
37
+ };
38
+ right: {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ bottom: {
43
+ x: number;
44
+ y: number;
45
+ };
46
+ left: {
47
+ x: number;
48
+ y: number;
49
+ };
50
+ };
51
+ declare function getRectEdges(v: Rect): {
52
+ top: RectEdge;
53
+ right: RectEdge;
54
+ bottom: RectEdge;
55
+ left: RectEdge;
56
+ };
57
+
58
+ export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
package/dist/rect.js ADDED
@@ -0,0 +1,97 @@
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/rect.ts
21
+ var rect_exports = {};
22
+ __export(rect_exports, {
23
+ addPoints: () => addPoints,
24
+ createPoint: () => createPoint,
25
+ createRect: () => createRect,
26
+ getRectCenters: () => getRectCenters,
27
+ getRectCorners: () => getRectCorners,
28
+ getRectEdges: () => getRectEdges,
29
+ isPoint: () => isPoint,
30
+ isRect: () => isRect,
31
+ subtractPoints: () => subtractPoints
32
+ });
33
+ module.exports = __toCommonJS(rect_exports);
34
+ var createPoint = (x, y) => ({ x, y });
35
+ var subtractPoints = (a, b) => {
36
+ if (!b) return a;
37
+ return createPoint(a.x - b.x, a.y - b.y);
38
+ };
39
+ var addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
40
+ function isPoint(v) {
41
+ return Reflect.has(v, "x") && Reflect.has(v, "y");
42
+ }
43
+ function createRect(r) {
44
+ const { x, y, width, height } = r;
45
+ const midX = x + width / 2;
46
+ const midY = y + height / 2;
47
+ return {
48
+ x,
49
+ y,
50
+ width,
51
+ height,
52
+ minX: x,
53
+ minY: y,
54
+ maxX: x + width,
55
+ maxY: y + height,
56
+ midX,
57
+ midY,
58
+ center: createPoint(midX, midY)
59
+ };
60
+ }
61
+ function isRect(v) {
62
+ return Reflect.has(v, "x") && Reflect.has(v, "y") && Reflect.has(v, "width") && Reflect.has(v, "height");
63
+ }
64
+ function getRectCenters(v) {
65
+ const top = createPoint(v.midX, v.minY);
66
+ const right = createPoint(v.maxX, v.midY);
67
+ const bottom = createPoint(v.midX, v.maxY);
68
+ const left = createPoint(v.minX, v.midY);
69
+ return { top, right, bottom, left };
70
+ }
71
+ function getRectCorners(v) {
72
+ const top = createPoint(v.minX, v.minY);
73
+ const right = createPoint(v.maxX, v.minY);
74
+ const bottom = createPoint(v.maxX, v.maxY);
75
+ const left = createPoint(v.minX, v.maxY);
76
+ return { top, right, bottom, left };
77
+ }
78
+ function getRectEdges(v) {
79
+ const c = getRectCorners(v);
80
+ const top = [c.top, c.right];
81
+ const right = [c.right, c.bottom];
82
+ const bottom = [c.left, c.bottom];
83
+ const left = [c.top, c.left];
84
+ return { top, right, bottom, left };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ addPoints,
89
+ createPoint,
90
+ createRect,
91
+ getRectCenters,
92
+ getRectCorners,
93
+ getRectEdges,
94
+ isPoint,
95
+ isRect,
96
+ subtractPoints
97
+ });