@zag-js/rect-utils 1.41.0 → 2.0.0-next.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 (45) hide show
  1. package/dist/align.mjs +0 -2
  2. package/dist/angle.mjs +0 -2
  3. package/dist/clamp.mjs +0 -2
  4. package/dist/closest.mjs +0 -2
  5. package/dist/compass.d.mts +1 -5
  6. package/dist/compass.d.ts +1 -5
  7. package/dist/compass.js +0 -33
  8. package/dist/compass.mjs +0 -27
  9. package/dist/constrain.mjs +0 -2
  10. package/dist/contains.mjs +0 -2
  11. package/dist/distance.mjs +0 -2
  12. package/dist/equality.mjs +0 -2
  13. package/dist/from-element.mjs +0 -2
  14. package/dist/from-points.mjs +0 -2
  15. package/dist/from-range.mjs +0 -2
  16. package/dist/from-rotation.mjs +0 -2
  17. package/dist/from-window.mjs +0 -2
  18. package/dist/index.d.mts +3 -4
  19. package/dist/index.d.ts +3 -4
  20. package/dist/index.js +2 -4
  21. package/dist/index.mjs +1 -2
  22. package/dist/interact.d.mts +71 -0
  23. package/dist/interact.d.ts +71 -0
  24. package/dist/interact.js +377 -0
  25. package/dist/interact.mjs +338 -0
  26. package/dist/intersection.mjs +0 -2
  27. package/dist/operations.mjs +0 -2
  28. package/dist/polygon.mjs +0 -2
  29. package/dist/rect.d.mts +9 -2
  30. package/dist/rect.d.ts +9 -2
  31. package/dist/rect.js +40 -0
  32. package/dist/rect.mjs +33 -2
  33. package/dist/types.d.mts +1 -5
  34. package/dist/types.d.ts +1 -5
  35. package/dist/union.mjs +0 -2
  36. package/package.json +1 -1
  37. package/dist/affine-transform.d.mts +0 -39
  38. package/dist/affine-transform.d.ts +0 -39
  39. package/dist/affine-transform.js +0 -189
  40. package/dist/affine-transform.mjs +0 -166
  41. package/dist/chunk-QZ7TP4HQ.mjs +0 -7
  42. package/dist/resize.d.mts +0 -6
  43. package/dist/resize.d.ts +0 -6
  44. package/dist/resize.js +0 -113
  45. package/dist/resize.mjs +0 -90
@@ -1,166 +0,0 @@
1
- import {
2
- __publicField
3
- } from "./chunk-QZ7TP4HQ.mjs";
4
-
5
- // src/affine-transform.ts
6
- var AffineTransform = class _AffineTransform {
7
- constructor([m00, m01, m02, m10, m11, m12] = [0, 0, 0, 0, 0, 0]) {
8
- __publicField(this, "m00");
9
- __publicField(this, "m01");
10
- __publicField(this, "m02");
11
- __publicField(this, "m10");
12
- __publicField(this, "m11");
13
- __publicField(this, "m12");
14
- __publicField(this, "rotate", (...args) => {
15
- return this.prepend(_AffineTransform.rotate(...args));
16
- });
17
- __publicField(this, "scale", (...args) => {
18
- return this.prepend(_AffineTransform.scale(...args));
19
- });
20
- __publicField(this, "translate", (...args) => {
21
- return this.prepend(_AffineTransform.translate(...args));
22
- });
23
- this.m00 = m00;
24
- this.m01 = m01;
25
- this.m02 = m02;
26
- this.m10 = m10;
27
- this.m11 = m11;
28
- this.m12 = m12;
29
- }
30
- applyTo(point) {
31
- const { x, y } = point;
32
- const { m00, m01, m02, m10, m11, m12 } = this;
33
- return {
34
- x: m00 * x + m01 * y + m02,
35
- y: m10 * x + m11 * y + m12
36
- };
37
- }
38
- prepend(other) {
39
- return new _AffineTransform([
40
- this.m00 * other.m00 + this.m01 * other.m10,
41
- // m00
42
- this.m00 * other.m01 + this.m01 * other.m11,
43
- // m01
44
- this.m00 * other.m02 + this.m01 * other.m12 + this.m02,
45
- // m02
46
- this.m10 * other.m00 + this.m11 * other.m10,
47
- // m10
48
- this.m10 * other.m01 + this.m11 * other.m11,
49
- // m11
50
- this.m10 * other.m02 + this.m11 * other.m12 + this.m12
51
- // m12
52
- ]);
53
- }
54
- append(other) {
55
- return new _AffineTransform([
56
- other.m00 * this.m00 + other.m01 * this.m10,
57
- // m00
58
- other.m00 * this.m01 + other.m01 * this.m11,
59
- // m01
60
- other.m00 * this.m02 + other.m01 * this.m12 + other.m02,
61
- // m02
62
- other.m10 * this.m00 + other.m11 * this.m10,
63
- // m10
64
- other.m10 * this.m01 + other.m11 * this.m11,
65
- // m11
66
- other.m10 * this.m02 + other.m11 * this.m12 + other.m12
67
- // m12
68
- ]);
69
- }
70
- get determinant() {
71
- return this.m00 * this.m11 - this.m01 * this.m10;
72
- }
73
- get isInvertible() {
74
- const det = this.determinant;
75
- return isFinite(det) && isFinite(this.m02) && isFinite(this.m12) && det !== 0;
76
- }
77
- invert() {
78
- const det = this.determinant;
79
- return new _AffineTransform([
80
- this.m11 / det,
81
- // m00
82
- -this.m01 / det,
83
- // m01
84
- (this.m01 * this.m12 - this.m11 * this.m02) / det,
85
- // m02
86
- -this.m10 / det,
87
- // m10
88
- this.m00 / det,
89
- // m11
90
- (this.m10 * this.m02 - this.m00 * this.m12) / det
91
- // m12
92
- ]);
93
- }
94
- get array() {
95
- return [this.m00, this.m01, this.m02, this.m10, this.m11, this.m12, 0, 0, 1];
96
- }
97
- get float32Array() {
98
- return new Float32Array(this.array);
99
- }
100
- // Static
101
- static get identity() {
102
- return new _AffineTransform([1, 0, 0, 0, 1, 0]);
103
- }
104
- static rotate(theta, origin) {
105
- const rotation = new _AffineTransform([Math.cos(theta), -Math.sin(theta), 0, Math.sin(theta), Math.cos(theta), 0]);
106
- if (origin && (origin.x !== 0 || origin.y !== 0)) {
107
- return _AffineTransform.multiply(
108
- _AffineTransform.translate(origin.x, origin.y),
109
- rotation,
110
- _AffineTransform.translate(-origin.x, -origin.y)
111
- );
112
- }
113
- return rotation;
114
- }
115
- static scale(sx, sy = sx, origin = { x: 0, y: 0 }) {
116
- const scale = new _AffineTransform([sx, 0, 0, 0, sy, 0]);
117
- if (origin.x !== 0 || origin.y !== 0) {
118
- return _AffineTransform.multiply(
119
- _AffineTransform.translate(origin.x, origin.y),
120
- scale,
121
- _AffineTransform.translate(-origin.x, -origin.y)
122
- );
123
- }
124
- return scale;
125
- }
126
- static translate(tx, ty) {
127
- return new _AffineTransform([1, 0, tx, 0, 1, ty]);
128
- }
129
- static multiply(...[first, ...rest]) {
130
- if (!first) return _AffineTransform.identity;
131
- return rest.reduce((result, item) => result.prepend(item), first);
132
- }
133
- get a() {
134
- return this.m00;
135
- }
136
- get b() {
137
- return this.m10;
138
- }
139
- get c() {
140
- return this.m01;
141
- }
142
- get d() {
143
- return this.m11;
144
- }
145
- get tx() {
146
- return this.m02;
147
- }
148
- get ty() {
149
- return this.m12;
150
- }
151
- get scaleComponents() {
152
- return { x: this.a, y: this.d };
153
- }
154
- get translationComponents() {
155
- return { x: this.tx, y: this.ty };
156
- }
157
- get skewComponents() {
158
- return { x: this.c, y: this.b };
159
- }
160
- toString() {
161
- return `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.tx}, ${this.ty})`;
162
- }
163
- };
164
- export {
165
- AffineTransform
166
- };
@@ -1,7 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
-
5
- export {
6
- __publicField
7
- };
package/dist/resize.d.mts DELETED
@@ -1,6 +0,0 @@
1
- import { CompassDirection } from './compass.mjs';
2
- import { Rect, Point, ScalingOptions, RectInit } from './types.mjs';
3
-
4
- declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
5
-
6
- export { resizeRect };
package/dist/resize.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { CompassDirection } from './compass.js';
2
- import { Rect, Point, ScalingOptions, RectInit } from './types.js';
3
-
4
- declare function resizeRect(rect: Rect, offset: Point, direction: CompassDirection, opts: ScalingOptions): RectInit;
5
-
6
- export { resizeRect };
package/dist/resize.js DELETED
@@ -1,113 +0,0 @@
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/resize.ts
21
- var resize_exports = {};
22
- __export(resize_exports, {
23
- resizeRect: () => resizeRect
24
- });
25
- module.exports = __toCommonJS(resize_exports);
26
- var import_affine_transform = require("./affine-transform.js");
27
- var import_compass = require("./compass.js");
28
- var { sign, abs, min } = Math;
29
- function getRectExtentPoint(rect, direction) {
30
- const { minX, minY, maxX, maxY, midX, midY } = rect;
31
- const x = direction.includes("w") ? minX : direction.includes("e") ? maxX : midX;
32
- const y = direction.includes("n") ? minY : direction.includes("s") ? maxY : midY;
33
- return { x, y };
34
- }
35
- function getOppositeDirection(direction) {
36
- return import_compass.oppositeDirectionMap[direction];
37
- }
38
- function resizeRect(rect, offset, direction, opts) {
39
- const { scalingOriginMode, lockAspectRatio } = opts;
40
- const extent = getRectExtentPoint(rect, direction);
41
- const oppositeDirection = getOppositeDirection(direction);
42
- const oppositeExtent = getRectExtentPoint(rect, oppositeDirection);
43
- if (scalingOriginMode === "center") {
44
- offset = { x: offset.x * 2, y: offset.y * 2 };
45
- }
46
- const newExtent = {
47
- x: extent.x + offset.x,
48
- y: extent.y + offset.y
49
- };
50
- const multiplier = {
51
- x: import_compass.compassDirectionMap[direction].x * 2 - 1,
52
- y: import_compass.compassDirectionMap[direction].y * 2 - 1
53
- };
54
- const newSize = {
55
- width: newExtent.x - oppositeExtent.x,
56
- height: newExtent.y - oppositeExtent.y
57
- };
58
- const scaleX = multiplier.x * newSize.width / rect.width;
59
- const scaleY = multiplier.y * newSize.height / rect.height;
60
- const largestMagnitude = abs(scaleX) > abs(scaleY) ? scaleX : scaleY;
61
- const scale = lockAspectRatio ? { x: largestMagnitude, y: largestMagnitude } : {
62
- x: extent.x === oppositeExtent.x ? 1 : scaleX,
63
- y: extent.y === oppositeExtent.y ? 1 : scaleY
64
- };
65
- if (extent.y === oppositeExtent.y) {
66
- scale.y = abs(scale.y);
67
- } else if (sign(scale.y) !== sign(scaleY)) {
68
- scale.y *= -1;
69
- }
70
- if (extent.x === oppositeExtent.x) {
71
- scale.x = abs(scale.x);
72
- } else if (sign(scale.x) !== sign(scaleX)) {
73
- scale.x *= -1;
74
- }
75
- switch (scalingOriginMode) {
76
- case "extent":
77
- return transformRect(rect, import_affine_transform.AffineTransform.scale(scale.x, scale.y, oppositeExtent), false);
78
- case "center":
79
- return transformRect(
80
- rect,
81
- import_affine_transform.AffineTransform.scale(scale.x, scale.y, {
82
- x: rect.midX,
83
- y: rect.midY
84
- }),
85
- false
86
- );
87
- }
88
- }
89
- function createRectFromPoints(initialPoint, finalPoint, normalized = true) {
90
- if (normalized) {
91
- return {
92
- x: min(finalPoint.x, initialPoint.x),
93
- y: min(finalPoint.y, initialPoint.y),
94
- width: abs(finalPoint.x - initialPoint.x),
95
- height: abs(finalPoint.y - initialPoint.y)
96
- };
97
- }
98
- return {
99
- x: initialPoint.x,
100
- y: initialPoint.y,
101
- width: finalPoint.x - initialPoint.x,
102
- height: finalPoint.y - initialPoint.y
103
- };
104
- }
105
- function transformRect(rect, transform, normalized = true) {
106
- const p1 = transform.applyTo({ x: rect.minX, y: rect.minY });
107
- const p2 = transform.applyTo({ x: rect.maxX, y: rect.maxY });
108
- return createRectFromPoints(p1, p2, normalized);
109
- }
110
- // Annotate the CommonJS export names for ESM import in node:
111
- 0 && (module.exports = {
112
- resizeRect
113
- });
package/dist/resize.mjs DELETED
@@ -1,90 +0,0 @@
1
- import "./chunk-QZ7TP4HQ.mjs";
2
-
3
- // src/resize.ts
4
- import { AffineTransform } from "./affine-transform.mjs";
5
- import { compassDirectionMap, oppositeDirectionMap } from "./compass.mjs";
6
- var { sign, abs, min } = Math;
7
- function getRectExtentPoint(rect, direction) {
8
- const { minX, minY, maxX, maxY, midX, midY } = rect;
9
- const x = direction.includes("w") ? minX : direction.includes("e") ? maxX : midX;
10
- const y = direction.includes("n") ? minY : direction.includes("s") ? maxY : midY;
11
- return { x, y };
12
- }
13
- function getOppositeDirection(direction) {
14
- return oppositeDirectionMap[direction];
15
- }
16
- function resizeRect(rect, offset, direction, opts) {
17
- const { scalingOriginMode, lockAspectRatio } = opts;
18
- const extent = getRectExtentPoint(rect, direction);
19
- const oppositeDirection = getOppositeDirection(direction);
20
- const oppositeExtent = getRectExtentPoint(rect, oppositeDirection);
21
- if (scalingOriginMode === "center") {
22
- offset = { x: offset.x * 2, y: offset.y * 2 };
23
- }
24
- const newExtent = {
25
- x: extent.x + offset.x,
26
- y: extent.y + offset.y
27
- };
28
- const multiplier = {
29
- x: compassDirectionMap[direction].x * 2 - 1,
30
- y: compassDirectionMap[direction].y * 2 - 1
31
- };
32
- const newSize = {
33
- width: newExtent.x - oppositeExtent.x,
34
- height: newExtent.y - oppositeExtent.y
35
- };
36
- const scaleX = multiplier.x * newSize.width / rect.width;
37
- const scaleY = multiplier.y * newSize.height / rect.height;
38
- const largestMagnitude = abs(scaleX) > abs(scaleY) ? scaleX : scaleY;
39
- const scale = lockAspectRatio ? { x: largestMagnitude, y: largestMagnitude } : {
40
- x: extent.x === oppositeExtent.x ? 1 : scaleX,
41
- y: extent.y === oppositeExtent.y ? 1 : scaleY
42
- };
43
- if (extent.y === oppositeExtent.y) {
44
- scale.y = abs(scale.y);
45
- } else if (sign(scale.y) !== sign(scaleY)) {
46
- scale.y *= -1;
47
- }
48
- if (extent.x === oppositeExtent.x) {
49
- scale.x = abs(scale.x);
50
- } else if (sign(scale.x) !== sign(scaleX)) {
51
- scale.x *= -1;
52
- }
53
- switch (scalingOriginMode) {
54
- case "extent":
55
- return transformRect(rect, AffineTransform.scale(scale.x, scale.y, oppositeExtent), false);
56
- case "center":
57
- return transformRect(
58
- rect,
59
- AffineTransform.scale(scale.x, scale.y, {
60
- x: rect.midX,
61
- y: rect.midY
62
- }),
63
- false
64
- );
65
- }
66
- }
67
- function createRectFromPoints(initialPoint, finalPoint, normalized = true) {
68
- if (normalized) {
69
- return {
70
- x: min(finalPoint.x, initialPoint.x),
71
- y: min(finalPoint.y, initialPoint.y),
72
- width: abs(finalPoint.x - initialPoint.x),
73
- height: abs(finalPoint.y - initialPoint.y)
74
- };
75
- }
76
- return {
77
- x: initialPoint.x,
78
- y: initialPoint.y,
79
- width: finalPoint.x - initialPoint.x,
80
- height: finalPoint.y - initialPoint.y
81
- };
82
- }
83
- function transformRect(rect, transform, normalized = true) {
84
- const p1 = transform.applyTo({ x: rect.minX, y: rect.minY });
85
- const p2 = transform.applyTo({ x: rect.maxX, y: rect.maxY });
86
- return createRectFromPoints(p1, p2, normalized);
87
- }
88
- export {
89
- resizeRect
90
- };