@zag-js/rect-utils 2.0.0-next.2 → 2.0.0-next.4

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