@zag-js/rect-utils 0.1.1 → 0.1.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.
@@ -0,0 +1,8 @@
1
+ import type { Rect } from "./rect";
2
+ export declare function alignRect(a: Rect, ref: Rect, options: AlignOptions): Rect;
3
+ export declare type AlignOptions = {
4
+ h: HAlign;
5
+ v: VAlign;
6
+ };
7
+ export declare type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
8
+ export declare type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
@@ -0,0 +1,5 @@
1
+ import type { Rect } from "./rect";
2
+ import type { Point, RectSide } from "./types";
3
+ export declare function closest(...pts: Point[]): (a: Point) => Point;
4
+ export declare function closestSideToRect(ref: Rect, r: Rect): RectSide;
5
+ export declare function closestSideToPoint(ref: Rect, p: Point): RectSide;
@@ -0,0 +1,5 @@
1
+ import { Rect } from "./rect";
2
+ import type { Point } from "./types";
3
+ export declare function containsPoint(r: Rect, p: Point): boolean;
4
+ export declare function containsRect(a: Rect, b: Rect): boolean;
5
+ export declare function contains(r: Rect, v: Rect | Point): boolean;
@@ -0,0 +1,9 @@
1
+ import type { Rect } from "./rect";
2
+ import type { Point, RectSide } from "./types";
3
+ export declare type DistanceValue = Point & {
4
+ value: number;
5
+ };
6
+ export declare function distance(a: Point, b?: Point): number;
7
+ export declare function distanceFromPoint(r: Rect, p: Point): DistanceValue;
8
+ export declare function distanceFromRect(a: Rect, b: Rect): DistanceValue;
9
+ export declare function distanceBtwEdges(a: Rect, b: Rect): Record<RectSide, number>;
@@ -10,4 +10,3 @@ export declare type ElementRectOptions = {
10
10
  */
11
11
  excludeBorders?: boolean;
12
12
  };
13
- //# sourceMappingURL=from-element.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { Rect } from "./rect";
2
+ import type { Point } from "./types";
3
+ export declare function getRectFromPoints(...pts: Point[]): Rect;
@@ -0,0 +1,2 @@
1
+ import { Rect } from "./rect";
2
+ export declare function fromRange(range: Range): Rect;
@@ -0,0 +1,5 @@
1
+ import { Rect } from "./rect";
2
+ import type { Point } from "./types";
3
+ export declare function toRad(d: number): number;
4
+ export declare function rotate(a: Point, d: number, c: Point): Point;
5
+ export declare function getRotationRect(r: Rect, deg: number): Rect;
@@ -0,0 +1,20 @@
1
+ import { Rect } from "./rect";
2
+ export declare type WindowRectOptions = {
3
+ /**
4
+ * Whether to exclude the element's scrollbar size from the calculation.
5
+ */
6
+ excludeScrollbar?: boolean;
7
+ };
8
+ /**
9
+ * Creates a rectange from window object
10
+ */
11
+ export declare function getWindowRect(win: Window, opts?: WindowRectOptions): Rect;
12
+ /**
13
+ * Get the rect of the window with the option to exclude the scrollbar
14
+ */
15
+ export declare function getViewportRect(win: Window, opts: WindowRectOptions): {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ };
@@ -0,0 +1,5 @@
1
+ import type { RectValue } from "./types";
2
+ export declare function getElementPolygon(rectValue: RectValue, placement: string): {
3
+ x: number;
4
+ y: number;
5
+ }[];
package/dist/index.d.ts CHANGED
@@ -1,7 +1,16 @@
1
- export * from "./rect";
2
- export * from "./types";
1
+ export * from "./align";
2
+ export * from "./closest";
3
+ export * from "./contains";
4
+ export * from "./distance";
3
5
  export * from "./from-element";
4
- export * from "./point";
6
+ export * from "./from-points";
7
+ export * from "./from-range";
8
+ export * from "./from-rotation";
9
+ export * from "./from-window";
10
+ export * from "./get-polygon";
11
+ export * from "./intersection";
5
12
  export * from "./operations";
6
13
  export * from "./polygon";
7
- //# sourceMappingURL=index.d.ts.map
14
+ export * from "./rect";
15
+ export * from "./types";
16
+ export * from "./union";
package/dist/index.js CHANGED
@@ -1,7 +1,25 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
2
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
5
23
  var __export = (target, all) => {
6
24
  for (var name in all)
7
25
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -19,112 +37,276 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
37
  // src/index.ts
20
38
  var src_exports = {};
21
39
  __export(src_exports, {
22
- Rect: () => Rect,
40
+ alignRect: () => alignRect,
23
41
  closest: () => closest,
42
+ closestSideToPoint: () => closestSideToPoint,
43
+ closestSideToRect: () => closestSideToRect,
44
+ collisions: () => collisions,
45
+ contains: () => contains,
46
+ containsPoint: () => containsPoint,
47
+ containsRect: () => containsRect,
48
+ createRect: () => createRect,
24
49
  debugPolygon: () => debugPolygon,
25
50
  distance: () => distance,
51
+ distanceBtwEdges: () => distanceBtwEdges,
52
+ distanceFromPoint: () => distanceFromPoint,
53
+ distanceFromRect: () => distanceFromRect,
26
54
  expand: () => expand,
55
+ fromRange: () => fromRange,
56
+ getElementPolygon: () => getElementPolygon,
27
57
  getElementRect: () => getElementRect,
28
- getEventPoint: () => getEventPoint,
58
+ getRectCenters: () => getRectCenters,
59
+ getRectCorners: () => getRectCorners,
60
+ getRectEdges: () => getRectEdges,
61
+ getRectFromPoints: () => getRectFromPoints,
62
+ getRotationRect: () => getRotationRect,
63
+ getViewportRect: () => getViewportRect,
64
+ getWindowRect: () => getWindowRect,
29
65
  inset: () => inset,
66
+ intersection: () => intersection,
67
+ intersects: () => intersects,
68
+ isPointInPolygon: () => isPointInPolygon,
69
+ isRect: () => isRect,
30
70
  isSymmetric: () => isSymmetric,
31
- relativeToNode: () => relativeToNode,
71
+ rotate: () => rotate,
32
72
  shift: () => shift,
33
73
  shrink: () => shrink,
34
- withinPolygon: () => withinPolygon
74
+ toRad: () => toRad,
75
+ union: () => union
35
76
  });
36
77
  module.exports = __toCommonJS(src_exports);
37
78
 
38
- // src/rect.ts
39
- var point = (x, y) => ({ x, y });
40
- var Rect = class {
41
- constructor(v) {
42
- this.v = v;
43
- }
44
- static create(v) {
45
- return new Rect(v);
79
+ // src/align.ts
80
+ function hAlign(a, ref, h) {
81
+ let x = ref.minX;
82
+ if (h === "left-inside") {
83
+ x = ref.minX;
46
84
  }
47
- set(n) {
48
- return new Rect(Object.assign({}, this.v, n));
85
+ if (h === "left-outside") {
86
+ x = ref.minX - ref.width;
49
87
  }
50
- clone() {
51
- return new Rect(this.v);
88
+ if (h === "right-inside") {
89
+ x = ref.maxX - ref.width;
52
90
  }
53
- get x() {
54
- return this.v.x;
91
+ if (h === "right-outside") {
92
+ x = ref.maxX;
55
93
  }
56
- get y() {
57
- return this.v.y;
94
+ if (h === "center") {
95
+ x = ref.midX - ref.width / 2;
58
96
  }
59
- get width() {
60
- return this.v.width;
97
+ return __spreadProps(__spreadValues({}, a), { x });
98
+ }
99
+ function vAlign(a, ref, v) {
100
+ let y = ref.minY;
101
+ if (v === "top-inside") {
102
+ y = ref.minY;
61
103
  }
62
- get height() {
63
- return this.v.height;
104
+ if (v === "top-outside") {
105
+ y = ref.minY - a.height;
64
106
  }
65
- get minX() {
66
- return this.v.x;
107
+ if (v === "bottom-inside") {
108
+ y = ref.maxY - a.height;
67
109
  }
68
- get midX() {
69
- return this.v.x + this.v.width / 2;
110
+ if (v === "bottom-outside") {
111
+ y = ref.maxY;
70
112
  }
71
- get maxX() {
72
- return this.v.x + this.v.width;
113
+ if (v === "center") {
114
+ y = ref.midY - a.height / 2;
73
115
  }
74
- get minY() {
75
- return this.v.y;
116
+ return __spreadProps(__spreadValues({}, a), { y });
117
+ }
118
+ function alignRect(a, ref, options) {
119
+ const { h, v } = options;
120
+ return vAlign(hAlign(a, ref, h), ref, v);
121
+ }
122
+
123
+ // ../core/dist/index.mjs
124
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
125
+
126
+ // src/rect.ts
127
+ var point = (x, y) => ({ x, y });
128
+ function createRect(r) {
129
+ const { x, y, width, height } = r;
130
+ const midX = x + width / 2;
131
+ const midY = y + height / 2;
132
+ return {
133
+ x,
134
+ y,
135
+ width,
136
+ height,
137
+ minX: x,
138
+ minY: y,
139
+ maxX: x + width,
140
+ maxY: y + height,
141
+ midX,
142
+ midY,
143
+ center: point(midX, midY)
144
+ };
145
+ }
146
+ function isRect(v) {
147
+ return hasProp(v, "x") && hasProp(v, "y") && hasProp(v, "width") && hasProp(v, "height");
148
+ }
149
+ function getRectCenters(v) {
150
+ const top = point(v.midX, v.minY);
151
+ const right = point(v.maxX, v.midY);
152
+ const bottom = point(v.midX, v.maxY);
153
+ const left = point(v.minX, v.midY);
154
+ return { top, right, bottom, left };
155
+ }
156
+ function getRectCorners(v) {
157
+ const top = point(v.minX, v.minY);
158
+ const right = point(v.maxX, v.minY);
159
+ const bottom = point(v.maxX, v.maxY);
160
+ const left = point(v.minX, v.maxY);
161
+ return { top, right, bottom, left };
162
+ }
163
+ function getRectEdges(v) {
164
+ const c = getRectCorners(v);
165
+ const top = [c.top, c.right];
166
+ const right = [c.right, c.bottom];
167
+ const bottom = [c.left, c.bottom];
168
+ const left = [c.top, c.left];
169
+ return { top, right, bottom, left };
170
+ }
171
+
172
+ // src/intersection.ts
173
+ function intersects(a, b) {
174
+ return a.x < b.maxX && a.y < b.maxY && a.maxX > b.x && a.maxY > b.y;
175
+ }
176
+ function intersection(a, b) {
177
+ const x = Math.max(a.x, b.x);
178
+ const y = Math.max(a.y, b.y);
179
+ const x2 = Math.min(a.x + a.width, b.x + b.width);
180
+ const y2 = Math.min(a.y + a.height, b.y + b.height);
181
+ return createRect({ x, y, width: x2 - x, height: y2 - y });
182
+ }
183
+ function collisions(a, b) {
184
+ return {
185
+ top: a.minY <= b.minY,
186
+ right: a.maxX >= b.maxX,
187
+ bottom: a.maxY >= b.maxY,
188
+ left: a.minX <= b.minX
189
+ };
190
+ }
191
+
192
+ // src/distance.ts
193
+ function distance(a, b = { x: 0, y: 0 }) {
194
+ return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
195
+ }
196
+ function distanceFromPoint(r, p) {
197
+ let x = 0;
198
+ let y = 0;
199
+ if (p.x < r.x)
200
+ x = r.x - p.x;
201
+ else if (p.x > r.maxX)
202
+ x = p.x - r.maxX;
203
+ if (p.y < r.y)
204
+ y = r.y - p.y;
205
+ else if (p.y > r.maxY)
206
+ y = p.y - r.maxY;
207
+ return { x, y, value: distance({ x, y }) };
208
+ }
209
+ function distanceFromRect(a, b) {
210
+ if (intersects(a, b))
211
+ return { x: 0, y: 0, value: 0 };
212
+ const left = a.x < b.x ? a : b;
213
+ const right = b.x < a.x ? a : b;
214
+ const upper = a.y < b.y ? a : b;
215
+ const lower = b.y < a.y ? a : b;
216
+ let x = left.x === right.x ? 0 : right.x - left.maxX;
217
+ x = Math.max(0, x);
218
+ let y = upper.y === lower.y ? 0 : lower.y - upper.maxY;
219
+ y = Math.max(0, y);
220
+ return { x, y, value: distance({ x, y }) };
221
+ }
222
+ function distanceBtwEdges(a, b) {
223
+ return {
224
+ left: b.x - a.x,
225
+ top: b.y - a.y,
226
+ right: a.maxX - b.maxX,
227
+ bottom: a.maxY - b.maxY
228
+ };
229
+ }
230
+
231
+ // src/closest.ts
232
+ function closest(...pts) {
233
+ return (a) => {
234
+ const ds = pts.map((b) => distance(b, a));
235
+ const c = Math.min.apply(Math, ds);
236
+ return pts[ds.indexOf(c)];
237
+ };
238
+ }
239
+ function closestSideToRect(ref, r) {
240
+ if (r.maxX <= ref.minX) {
241
+ return "left";
76
242
  }
77
- get midY() {
78
- return this.v.y + this.v.height / 2;
243
+ if (r.minX >= ref.maxX) {
244
+ return "right";
79
245
  }
80
- get maxY() {
81
- return this.v.y + this.v.height;
246
+ if (r.maxY <= ref.minY) {
247
+ return "top";
82
248
  }
83
- get center() {
84
- return point(this.midX, this.midY);
249
+ if (r.minY >= ref.maxY) {
250
+ return "bottom";
85
251
  }
86
- get centers() {
87
- const top = point(this.midX, this.minY);
88
- const right = point(this.maxX, this.midY);
89
- const bottom = point(this.midX, this.maxY);
90
- const left = point(this.minX, this.midY);
91
- return { top, right, bottom, left };
252
+ return "left";
253
+ }
254
+ function closestSideToPoint(ref, p) {
255
+ const { x, y } = p;
256
+ const dl = x - ref.minX;
257
+ const dr = ref.maxX - x;
258
+ const dt = y - ref.minY;
259
+ const db = ref.maxY - y;
260
+ let closest2 = dl;
261
+ let side = "left";
262
+ if (dr < closest2) {
263
+ closest2 = dr;
264
+ side = "right";
92
265
  }
93
- get corners() {
94
- const top = point(this.minX, this.minY);
95
- const right = point(this.maxX, this.minY);
96
- const bottom = point(this.maxX, this.maxY);
97
- const left = point(this.minX, this.maxY);
98
- return { top, right, bottom, left };
266
+ if (dt < closest2) {
267
+ closest2 = dt;
268
+ side = "top";
99
269
  }
100
- get edges() {
101
- const c = this.corners;
102
- const top = [c.top, c.right];
103
- const right = [c.right, c.bottom];
104
- const bottom = [c.left, c.bottom];
105
- const left = [c.top, c.left];
106
- return { top, right, bottom, left };
270
+ if (db < closest2) {
271
+ side = "bottom";
107
272
  }
108
- };
273
+ return side;
274
+ }
109
275
 
110
- // src/computed-style.ts
111
- var styleCache = /* @__PURE__ */ new WeakMap();
276
+ // src/contains.ts
277
+ function containsPoint(r, p) {
278
+ return r.minX <= p.x && p.x <= r.maxX && r.minY <= p.y && p.y <= r.maxY;
279
+ }
280
+ function containsRect(a, b) {
281
+ return Object.values(getRectCorners(b)).every((c) => containsPoint(a, c));
282
+ }
283
+ function contains(r, v) {
284
+ return isRect(v) ? containsRect(r, v) : containsPoint(r, v);
285
+ }
286
+
287
+ // ../dom/dist/index.mjs
288
+ function getCache() {
289
+ const g = globalThis;
290
+ g.__styleCache = g.__styleCache || /* @__PURE__ */ new WeakMap();
291
+ return g.__styleCache;
292
+ }
112
293
  function getComputedStyle(el) {
113
294
  var _a;
114
295
  if (!el)
115
296
  return {};
116
- let style = styleCache.get(el);
297
+ const cache = getCache();
298
+ let style = cache.get(el);
117
299
  if (!style) {
118
300
  const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
119
301
  style = win.getComputedStyle(el);
120
- styleCache.set(el, style);
302
+ cache.set(el, style);
121
303
  }
122
304
  return style;
123
305
  }
124
306
 
125
307
  // src/from-element.ts
126
308
  function getElementRect(el, opts = {}) {
127
- return Rect.create(getClientRect(el, opts));
309
+ return createRect(getClientRect(el, opts));
128
310
  }
129
311
  function getClientRect(el, opts = {}) {
130
312
  const { excludeScrollbar = false, excludeBorders = false } = opts;
@@ -151,42 +333,124 @@ function getClientRect(el, opts = {}) {
151
333
  var px = (v) => parseFloat(v.replace("px", ""));
152
334
  var sum = (...vals) => vals.reduce((sum2, v) => sum2 + (v ? px(v) : 0), 0);
153
335
 
154
- // ../core/dist/index.mjs
155
- var isArray = (v) => Array.isArray(v);
156
- var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
157
- var isTouchEvent = (v) => isObject(v) && "touches" in v;
158
-
159
- // src/point.ts
160
- function distance(a, b = { x: 0, y: 0 }) {
161
- return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
336
+ // src/from-points.ts
337
+ function getRectFromPoints(...pts) {
338
+ const xs = pts.map((p) => p.x);
339
+ const ys = pts.map((p) => p.y);
340
+ const x = Math.min(...xs);
341
+ const y = Math.min(...ys);
342
+ const width = Math.max(...xs) - x;
343
+ const height = Math.max(...ys) - y;
344
+ return createRect({ x, y, width, height });
162
345
  }
163
- function closest(...pts) {
164
- return (a) => {
165
- const ds = pts.map((b) => distance(b, a));
166
- const c = Math.min.apply(Math, ds);
167
- return pts[ds.indexOf(c)];
346
+
347
+ // src/union.ts
348
+ var { min, max } = Math;
349
+ function union(...rs) {
350
+ const pMin = {
351
+ x: min.apply(Math, rs.map((r) => r.minX)),
352
+ y: min.apply(Math, rs.map((r) => r.minY))
168
353
  };
354
+ const pMax = {
355
+ x: max.apply(Math, rs.map((r) => r.maxX)),
356
+ y: max.apply(Math, rs.map((r) => r.maxY))
357
+ };
358
+ return getRectFromPoints(pMin, pMax);
359
+ }
360
+
361
+ // src/from-range.ts
362
+ function fromRange(range) {
363
+ let rs = [];
364
+ const rects = Array.from(range.getClientRects());
365
+ if (rects.length) {
366
+ rs = rs.concat(rects.map(createRect));
367
+ return union.apply(void 0, rs);
368
+ }
369
+ let start = range.startContainer;
370
+ if (start.nodeType === Node.TEXT_NODE) {
371
+ start = start.parentNode;
372
+ }
373
+ if (start instanceof HTMLElement) {
374
+ const r = getElementRect(start);
375
+ rs.push(__spreadProps(__spreadValues({}, r), { x: r.maxX, width: 0 }));
376
+ }
377
+ return union.apply(void 0, rs);
169
378
  }
170
- var fallback = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
171
- function getEventPoint(e, t = "page") {
172
- const p = isTouchEvent(e) ? e.touches[0] || e.changedTouches[0] || fallback : e;
173
- return { x: p[`${t}X`], y: p[`${t}Y`] };
379
+
380
+ // src/from-rotation.ts
381
+ function toRad(d) {
382
+ return d % 360 * Math.PI / 180;
174
383
  }
175
- function relativeToNode(p, el) {
176
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
177
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
384
+ function rotate(a, d, c) {
385
+ const r = toRad(d);
386
+ const sin = Math.sin(r);
387
+ const cos = Math.cos(r);
388
+ const x = a.x - c.x;
389
+ const y = a.y - c.y;
178
390
  return {
179
- point: { x: dx, y: dy },
180
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
391
+ x: c.x + x * cos - y * sin,
392
+ y: c.y + x * sin + y * cos
181
393
  };
182
394
  }
395
+ function getRotationRect(r, deg) {
396
+ const rr = Object.values(getRectCorners(r)).map((p) => rotate(p, deg, r.center));
397
+ const xs = rr.map((p) => p.x);
398
+ const ys = rr.map((p) => p.y);
399
+ const minX = Math.min(...xs);
400
+ const minY = Math.min(...ys);
401
+ const maxX = Math.max(...xs);
402
+ const maxY = Math.max(...ys);
403
+ return createRect({
404
+ x: minX,
405
+ y: minY,
406
+ width: maxX - minX,
407
+ height: maxY - minY
408
+ });
409
+ }
410
+
411
+ // src/from-window.ts
412
+ function getWindowRect(win, opts = {}) {
413
+ return createRect(getViewportRect(win, opts));
414
+ }
415
+ function getViewportRect(win, opts) {
416
+ const { excludeScrollbar = false } = opts;
417
+ const { innerWidth: innerWidth2, innerHeight: innerHeight2, document: doc, visualViewport } = win;
418
+ const width = visualViewport.width || innerWidth2;
419
+ const height = visualViewport.height || innerHeight2;
420
+ const rect = { x: 0, y: 0, width, height };
421
+ if (excludeScrollbar) {
422
+ const scrollbarWidth = innerWidth2 - doc.documentElement.clientWidth;
423
+ const scrollbarHeight = innerHeight2 - doc.documentElement.clientHeight;
424
+ rect.width -= scrollbarWidth;
425
+ rect.height -= scrollbarHeight;
426
+ }
427
+ return rect;
428
+ }
429
+
430
+ // src/get-polygon.ts
431
+ function getElementPolygon(rectValue, placement) {
432
+ const rect = createRect(rectValue);
433
+ const { top, right, left, bottom } = getRectCorners(rect);
434
+ const [base] = placement.split("-");
435
+ return {
436
+ top: [left, top, right, bottom],
437
+ right: [top, right, bottom, left],
438
+ bottom: [top, left, bottom, right],
439
+ left: [right, top, left, bottom]
440
+ }[base];
441
+ }
183
442
 
184
443
  // src/operations.ts
185
444
  var isSymmetric = (v) => "dx" in v || "dy" in v;
186
445
  function inset(r, i) {
187
446
  const v = isSymmetric(i) ? { left: i.dx, right: i.dx, top: i.dy, bottom: i.dy } : i;
188
447
  const { top = 0, right = 0, bottom = 0, left = 0 } = v;
189
- return Rect.create({ x: r.x + left, y: r.y + top, width: r.width - left - right, height: r.height - top - bottom });
448
+ return createRect({
449
+ x: r.x + left,
450
+ y: r.y + top,
451
+ width: r.width - left - right,
452
+ height: r.height - top - bottom
453
+ });
190
454
  }
191
455
  function expand(r, v) {
192
456
  const value = typeof v === "number" ? { dx: -v, dy: -v } : v;
@@ -198,11 +462,16 @@ function shrink(r, v) {
198
462
  }
199
463
  function shift(r, o) {
200
464
  const { x = 0, y = 0 } = o;
201
- return Rect.create({ x: r.x + x, y: r.y + y, width: r.width, height: r.height });
465
+ return createRect({
466
+ x: r.x + x,
467
+ y: r.y + y,
468
+ width: r.width,
469
+ height: r.height
470
+ });
202
471
  }
203
472
 
204
473
  // src/polygon.ts
205
- function withinPolygon(polygon, point2) {
474
+ function isPointInPolygon(polygon, point2) {
206
475
  const { x, y } = point2;
207
476
  let c = false;
208
477
  for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
@@ -230,7 +499,8 @@ function createPolygonElement() {
230
499
  height: "100%",
231
500
  opacity: "0.15",
232
501
  position: "fixed",
233
- pointerEvents: "none"
502
+ pointerEvents: "none",
503
+ fill: "red"
234
504
  });
235
505
  const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
236
506
  polygon.setAttribute("id", id);
@@ -243,5 +513,7 @@ function debugPolygon(polygon) {
243
513
  const el = createPolygonElement();
244
514
  const points = polygon.map((point2) => `${point2.x},${point2.y}`).join(" ");
245
515
  el.setAttribute("points", points);
516
+ return () => {
517
+ el.remove();
518
+ };
246
519
  }
247
- //# sourceMappingURL=index.js.map