@zag-js/rect-utils 1.34.0 → 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.
- package/dist/affine-transform.d.mts +39 -0
- package/dist/affine-transform.d.ts +39 -0
- package/dist/affine-transform.js +189 -0
- package/dist/affine-transform.mjs +166 -0
- package/dist/align.d.mts +5 -0
- package/dist/align.d.ts +5 -0
- package/dist/align.js +51 -0
- package/dist/align.mjs +28 -0
- package/dist/angle.d.mts +5 -0
- package/dist/angle.d.ts +5 -0
- package/dist/angle.js +35 -0
- package/dist/angle.mjs +12 -0
- package/dist/chunk-QZ7TP4HQ.mjs +7 -0
- package/dist/clamp.d.mts +12 -0
- package/dist/clamp.d.ts +12 -0
- package/dist/clamp.js +51 -0
- package/dist/clamp.mjs +27 -0
- package/dist/closest.d.mts +7 -0
- package/dist/closest.d.ts +7 -0
- package/dist/closest.js +69 -0
- package/dist/closest.mjs +44 -0
- package/dist/compass.d.mts +7 -0
- package/dist/compass.d.ts +7 -0
- package/dist/compass.js +51 -0
- package/dist/compass.mjs +27 -0
- package/dist/constrain.d.mts +5 -0
- package/dist/constrain.d.ts +5 -0
- package/dist/constrain.js +39 -0
- package/dist/constrain.mjs +16 -0
- package/dist/contains.d.mts +7 -0
- package/dist/contains.d.ts +7 -0
- package/dist/contains.js +43 -0
- package/dist/contains.mjs +18 -0
- package/dist/distance.d.mts +11 -0
- package/dist/distance.d.ts +11 -0
- package/dist/distance.js +68 -0
- package/dist/distance.mjs +42 -0
- package/dist/equality.d.mts +7 -0
- package/dist/equality.d.ts +7 -0
- package/dist/equality.js +42 -0
- package/dist/equality.mjs +17 -0
- package/dist/from-element.d.mts +15 -0
- package/dist/from-element.d.ts +15 -0
- package/dist/from-element.js +65 -0
- package/dist/from-element.mjs +42 -0
- package/dist/from-points.d.mts +5 -0
- package/dist/from-points.d.ts +5 -0
- package/dist/from-points.js +39 -0
- package/dist/from-points.mjs +16 -0
- package/dist/from-range.d.mts +5 -0
- package/dist/from-range.d.ts +5 -0
- package/dist/from-range.js +49 -0
- package/dist/from-range.mjs +26 -0
- package/dist/from-rotation.d.mts +7 -0
- package/dist/from-rotation.d.ts +7 -0
- package/dist/from-rotation.js +63 -0
- package/dist/from-rotation.mjs +38 -0
- package/dist/from-window.d.mts +23 -0
- package/dist/from-window.d.ts +23 -0
- package/dist/from-window.js +49 -0
- package/dist/from-window.mjs +25 -0
- package/dist/index.d.mts +22 -253
- package/dist/index.d.ts +22 -253
- package/dist/index.js +62 -772
- package/dist/index.mjs +22 -724
- package/dist/intersection.d.mts +16 -0
- package/dist/intersection.d.ts +16 -0
- package/dist/intersection.js +52 -0
- package/dist/intersection.mjs +27 -0
- package/dist/operations.d.mts +9 -0
- package/dist/operations.d.ts +9 -0
- package/dist/operations.js +66 -0
- package/dist/operations.mjs +39 -0
- package/dist/polygon.d.mts +10 -0
- package/dist/polygon.d.ts +10 -0
- package/dist/polygon.js +91 -0
- package/dist/polygon.mjs +66 -0
- package/dist/rect.d.mts +58 -0
- package/dist/rect.d.ts +58 -0
- package/dist/rect.js +97 -0
- package/dist/rect.mjs +66 -0
- package/dist/resize.d.mts +6 -0
- package/dist/resize.d.ts +6 -0
- package/dist/resize.js +113 -0
- package/dist/resize.mjs +90 -0
- package/dist/types.d.mts +55 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/dist/union.d.mts +5 -0
- package/dist/union.d.ts +5 -0
- package/dist/union.js +42 -0
- package/dist/union.mjs +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Point } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare class AffineTransform {
|
|
4
|
+
m00: number;
|
|
5
|
+
m01: number;
|
|
6
|
+
m02: number;
|
|
7
|
+
m10: number;
|
|
8
|
+
m11: number;
|
|
9
|
+
m12: number;
|
|
10
|
+
constructor([m00, m01, m02, m10, m11, m12]?: Iterable<number>);
|
|
11
|
+
applyTo(point: Point): Point;
|
|
12
|
+
prepend(other: AffineTransform): AffineTransform;
|
|
13
|
+
append(other: AffineTransform): AffineTransform;
|
|
14
|
+
get determinant(): number;
|
|
15
|
+
get isInvertible(): boolean;
|
|
16
|
+
invert(): AffineTransform;
|
|
17
|
+
get array(): number[];
|
|
18
|
+
get float32Array(): Float32Array;
|
|
19
|
+
static get identity(): AffineTransform;
|
|
20
|
+
static rotate(theta: number, origin?: Point): AffineTransform;
|
|
21
|
+
rotate: (typeof AffineTransform)["rotate"];
|
|
22
|
+
static scale(sx: number, sy?: number, origin?: Point): AffineTransform;
|
|
23
|
+
scale: (typeof AffineTransform)["scale"];
|
|
24
|
+
static translate(tx: number, ty: number): AffineTransform;
|
|
25
|
+
translate: (typeof AffineTransform)["translate"];
|
|
26
|
+
static multiply(...[first, ...rest]: AffineTransform[]): AffineTransform;
|
|
27
|
+
get a(): number;
|
|
28
|
+
get b(): number;
|
|
29
|
+
get c(): number;
|
|
30
|
+
get d(): number;
|
|
31
|
+
get tx(): number;
|
|
32
|
+
get ty(): number;
|
|
33
|
+
get scaleComponents(): Point;
|
|
34
|
+
get translationComponents(): Point;
|
|
35
|
+
get skewComponents(): Point;
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { AffineTransform };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Point } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare class AffineTransform {
|
|
4
|
+
m00: number;
|
|
5
|
+
m01: number;
|
|
6
|
+
m02: number;
|
|
7
|
+
m10: number;
|
|
8
|
+
m11: number;
|
|
9
|
+
m12: number;
|
|
10
|
+
constructor([m00, m01, m02, m10, m11, m12]?: Iterable<number>);
|
|
11
|
+
applyTo(point: Point): Point;
|
|
12
|
+
prepend(other: AffineTransform): AffineTransform;
|
|
13
|
+
append(other: AffineTransform): AffineTransform;
|
|
14
|
+
get determinant(): number;
|
|
15
|
+
get isInvertible(): boolean;
|
|
16
|
+
invert(): AffineTransform;
|
|
17
|
+
get array(): number[];
|
|
18
|
+
get float32Array(): Float32Array;
|
|
19
|
+
static get identity(): AffineTransform;
|
|
20
|
+
static rotate(theta: number, origin?: Point): AffineTransform;
|
|
21
|
+
rotate: (typeof AffineTransform)["rotate"];
|
|
22
|
+
static scale(sx: number, sy?: number, origin?: Point): AffineTransform;
|
|
23
|
+
scale: (typeof AffineTransform)["scale"];
|
|
24
|
+
static translate(tx: number, ty: number): AffineTransform;
|
|
25
|
+
translate: (typeof AffineTransform)["translate"];
|
|
26
|
+
static multiply(...[first, ...rest]: AffineTransform[]): AffineTransform;
|
|
27
|
+
get a(): number;
|
|
28
|
+
get b(): number;
|
|
29
|
+
get c(): number;
|
|
30
|
+
get d(): number;
|
|
31
|
+
get tx(): number;
|
|
32
|
+
get ty(): number;
|
|
33
|
+
get scaleComponents(): Point;
|
|
34
|
+
get translationComponents(): Point;
|
|
35
|
+
get skewComponents(): Point;
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { AffineTransform };
|
|
@@ -0,0 +1,189 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/affine-transform.ts
|
|
23
|
+
var affine_transform_exports = {};
|
|
24
|
+
__export(affine_transform_exports, {
|
|
25
|
+
AffineTransform: () => AffineTransform
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(affine_transform_exports);
|
|
28
|
+
var AffineTransform = class _AffineTransform {
|
|
29
|
+
constructor([m00, m01, m02, m10, m11, m12] = [0, 0, 0, 0, 0, 0]) {
|
|
30
|
+
__publicField(this, "m00");
|
|
31
|
+
__publicField(this, "m01");
|
|
32
|
+
__publicField(this, "m02");
|
|
33
|
+
__publicField(this, "m10");
|
|
34
|
+
__publicField(this, "m11");
|
|
35
|
+
__publicField(this, "m12");
|
|
36
|
+
__publicField(this, "rotate", (...args) => {
|
|
37
|
+
return this.prepend(_AffineTransform.rotate(...args));
|
|
38
|
+
});
|
|
39
|
+
__publicField(this, "scale", (...args) => {
|
|
40
|
+
return this.prepend(_AffineTransform.scale(...args));
|
|
41
|
+
});
|
|
42
|
+
__publicField(this, "translate", (...args) => {
|
|
43
|
+
return this.prepend(_AffineTransform.translate(...args));
|
|
44
|
+
});
|
|
45
|
+
this.m00 = m00;
|
|
46
|
+
this.m01 = m01;
|
|
47
|
+
this.m02 = m02;
|
|
48
|
+
this.m10 = m10;
|
|
49
|
+
this.m11 = m11;
|
|
50
|
+
this.m12 = m12;
|
|
51
|
+
}
|
|
52
|
+
applyTo(point) {
|
|
53
|
+
const { x, y } = point;
|
|
54
|
+
const { m00, m01, m02, m10, m11, m12 } = this;
|
|
55
|
+
return {
|
|
56
|
+
x: m00 * x + m01 * y + m02,
|
|
57
|
+
y: m10 * x + m11 * y + m12
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
prepend(other) {
|
|
61
|
+
return new _AffineTransform([
|
|
62
|
+
this.m00 * other.m00 + this.m01 * other.m10,
|
|
63
|
+
// m00
|
|
64
|
+
this.m00 * other.m01 + this.m01 * other.m11,
|
|
65
|
+
// m01
|
|
66
|
+
this.m00 * other.m02 + this.m01 * other.m12 + this.m02,
|
|
67
|
+
// m02
|
|
68
|
+
this.m10 * other.m00 + this.m11 * other.m10,
|
|
69
|
+
// m10
|
|
70
|
+
this.m10 * other.m01 + this.m11 * other.m11,
|
|
71
|
+
// m11
|
|
72
|
+
this.m10 * other.m02 + this.m11 * other.m12 + this.m12
|
|
73
|
+
// m12
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
append(other) {
|
|
77
|
+
return new _AffineTransform([
|
|
78
|
+
other.m00 * this.m00 + other.m01 * this.m10,
|
|
79
|
+
// m00
|
|
80
|
+
other.m00 * this.m01 + other.m01 * this.m11,
|
|
81
|
+
// m01
|
|
82
|
+
other.m00 * this.m02 + other.m01 * this.m12 + other.m02,
|
|
83
|
+
// m02
|
|
84
|
+
other.m10 * this.m00 + other.m11 * this.m10,
|
|
85
|
+
// m10
|
|
86
|
+
other.m10 * this.m01 + other.m11 * this.m11,
|
|
87
|
+
// m11
|
|
88
|
+
other.m10 * this.m02 + other.m11 * this.m12 + other.m12
|
|
89
|
+
// m12
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
get determinant() {
|
|
93
|
+
return this.m00 * this.m11 - this.m01 * this.m10;
|
|
94
|
+
}
|
|
95
|
+
get isInvertible() {
|
|
96
|
+
const det = this.determinant;
|
|
97
|
+
return isFinite(det) && isFinite(this.m02) && isFinite(this.m12) && det !== 0;
|
|
98
|
+
}
|
|
99
|
+
invert() {
|
|
100
|
+
const det = this.determinant;
|
|
101
|
+
return new _AffineTransform([
|
|
102
|
+
this.m11 / det,
|
|
103
|
+
// m00
|
|
104
|
+
-this.m01 / det,
|
|
105
|
+
// m01
|
|
106
|
+
(this.m01 * this.m12 - this.m11 * this.m02) / det,
|
|
107
|
+
// m02
|
|
108
|
+
-this.m10 / det,
|
|
109
|
+
// m10
|
|
110
|
+
this.m00 / det,
|
|
111
|
+
// m11
|
|
112
|
+
(this.m10 * this.m02 - this.m00 * this.m12) / det
|
|
113
|
+
// m12
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
get array() {
|
|
117
|
+
return [this.m00, this.m01, this.m02, this.m10, this.m11, this.m12, 0, 0, 1];
|
|
118
|
+
}
|
|
119
|
+
get float32Array() {
|
|
120
|
+
return new Float32Array(this.array);
|
|
121
|
+
}
|
|
122
|
+
// Static
|
|
123
|
+
static get identity() {
|
|
124
|
+
return new _AffineTransform([1, 0, 0, 0, 1, 0]);
|
|
125
|
+
}
|
|
126
|
+
static rotate(theta, origin) {
|
|
127
|
+
const rotation = new _AffineTransform([Math.cos(theta), -Math.sin(theta), 0, Math.sin(theta), Math.cos(theta), 0]);
|
|
128
|
+
if (origin && (origin.x !== 0 || origin.y !== 0)) {
|
|
129
|
+
return _AffineTransform.multiply(
|
|
130
|
+
_AffineTransform.translate(origin.x, origin.y),
|
|
131
|
+
rotation,
|
|
132
|
+
_AffineTransform.translate(-origin.x, -origin.y)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return rotation;
|
|
136
|
+
}
|
|
137
|
+
static scale(sx, sy = sx, origin = { x: 0, y: 0 }) {
|
|
138
|
+
const scale = new _AffineTransform([sx, 0, 0, 0, sy, 0]);
|
|
139
|
+
if (origin.x !== 0 || origin.y !== 0) {
|
|
140
|
+
return _AffineTransform.multiply(
|
|
141
|
+
_AffineTransform.translate(origin.x, origin.y),
|
|
142
|
+
scale,
|
|
143
|
+
_AffineTransform.translate(-origin.x, -origin.y)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return scale;
|
|
147
|
+
}
|
|
148
|
+
static translate(tx, ty) {
|
|
149
|
+
return new _AffineTransform([1, 0, tx, 0, 1, ty]);
|
|
150
|
+
}
|
|
151
|
+
static multiply(...[first, ...rest]) {
|
|
152
|
+
if (!first) return _AffineTransform.identity;
|
|
153
|
+
return rest.reduce((result, item) => result.prepend(item), first);
|
|
154
|
+
}
|
|
155
|
+
get a() {
|
|
156
|
+
return this.m00;
|
|
157
|
+
}
|
|
158
|
+
get b() {
|
|
159
|
+
return this.m10;
|
|
160
|
+
}
|
|
161
|
+
get c() {
|
|
162
|
+
return this.m01;
|
|
163
|
+
}
|
|
164
|
+
get d() {
|
|
165
|
+
return this.m11;
|
|
166
|
+
}
|
|
167
|
+
get tx() {
|
|
168
|
+
return this.m02;
|
|
169
|
+
}
|
|
170
|
+
get ty() {
|
|
171
|
+
return this.m12;
|
|
172
|
+
}
|
|
173
|
+
get scaleComponents() {
|
|
174
|
+
return { x: this.a, y: this.d };
|
|
175
|
+
}
|
|
176
|
+
get translationComponents() {
|
|
177
|
+
return { x: this.tx, y: this.ty };
|
|
178
|
+
}
|
|
179
|
+
get skewComponents() {
|
|
180
|
+
return { x: this.c, y: this.b };
|
|
181
|
+
}
|
|
182
|
+
toString() {
|
|
183
|
+
return `matrix(${this.a}, ${this.b}, ${this.c}, ${this.d}, ${this.tx}, ${this.ty})`;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
+
0 && (module.exports = {
|
|
188
|
+
AffineTransform
|
|
189
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
};
|
package/dist/align.d.mts
ADDED
package/dist/align.d.ts
ADDED
package/dist/align.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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/align.ts
|
|
21
|
+
var align_exports = {};
|
|
22
|
+
__export(align_exports, {
|
|
23
|
+
alignRect: () => alignRect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(align_exports);
|
|
26
|
+
function hAlign(a, ref, h) {
|
|
27
|
+
let x = ref.minX;
|
|
28
|
+
if (h === "left-inside") x = ref.minX;
|
|
29
|
+
if (h === "left-outside") x = ref.minX - ref.width;
|
|
30
|
+
if (h === "right-inside") x = ref.maxX - ref.width;
|
|
31
|
+
if (h === "right-outside") x = ref.maxX;
|
|
32
|
+
if (h === "center") x = ref.midX - ref.width / 2;
|
|
33
|
+
return { ...a, x };
|
|
34
|
+
}
|
|
35
|
+
function vAlign(a, ref, v) {
|
|
36
|
+
let y = ref.minY;
|
|
37
|
+
if (v === "top-inside") y = ref.minY;
|
|
38
|
+
if (v === "top-outside") y = ref.minY - a.height;
|
|
39
|
+
if (v === "bottom-inside") y = ref.maxY - a.height;
|
|
40
|
+
if (v === "bottom-outside") y = ref.maxY;
|
|
41
|
+
if (v === "center") y = ref.midY - a.height / 2;
|
|
42
|
+
return { ...a, y };
|
|
43
|
+
}
|
|
44
|
+
function alignRect(a, ref, options) {
|
|
45
|
+
const { h, v } = options;
|
|
46
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
alignRect
|
|
51
|
+
});
|
package/dist/align.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/align.ts
|
|
4
|
+
function hAlign(a, ref, h) {
|
|
5
|
+
let x = ref.minX;
|
|
6
|
+
if (h === "left-inside") x = ref.minX;
|
|
7
|
+
if (h === "left-outside") x = ref.minX - ref.width;
|
|
8
|
+
if (h === "right-inside") x = ref.maxX - ref.width;
|
|
9
|
+
if (h === "right-outside") x = ref.maxX;
|
|
10
|
+
if (h === "center") x = ref.midX - ref.width / 2;
|
|
11
|
+
return { ...a, x };
|
|
12
|
+
}
|
|
13
|
+
function vAlign(a, ref, v) {
|
|
14
|
+
let y = ref.minY;
|
|
15
|
+
if (v === "top-inside") y = ref.minY;
|
|
16
|
+
if (v === "top-outside") y = ref.minY - a.height;
|
|
17
|
+
if (v === "bottom-inside") y = ref.maxY - a.height;
|
|
18
|
+
if (v === "bottom-outside") y = ref.maxY;
|
|
19
|
+
if (v === "center") y = ref.midY - a.height / 2;
|
|
20
|
+
return { ...a, y };
|
|
21
|
+
}
|
|
22
|
+
function alignRect(a, ref, options) {
|
|
23
|
+
const { h, v } = options;
|
|
24
|
+
return vAlign(hAlign(a, ref, h), ref, v);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
alignRect
|
|
28
|
+
};
|
package/dist/angle.d.mts
ADDED
package/dist/angle.d.ts
ADDED
package/dist/angle.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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/angle.ts
|
|
21
|
+
var angle_exports = {};
|
|
22
|
+
__export(angle_exports, {
|
|
23
|
+
getPointAngle: () => getPointAngle
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(angle_exports);
|
|
26
|
+
function getPointAngle(rect, point, reference = rect.center) {
|
|
27
|
+
const x = point.x - reference.x;
|
|
28
|
+
const y = point.y - reference.y;
|
|
29
|
+
const deg = Math.atan2(x, y) * (180 / Math.PI) + 180;
|
|
30
|
+
return 360 - deg;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
getPointAngle
|
|
35
|
+
});
|
package/dist/angle.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/angle.ts
|
|
4
|
+
function getPointAngle(rect, point, reference = rect.center) {
|
|
5
|
+
const x = point.x - reference.x;
|
|
6
|
+
const y = point.y - reference.y;
|
|
7
|
+
const deg = Math.atan2(x, y) * (180 / Math.PI) + 180;
|
|
8
|
+
return 360 - deg;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
getPointAngle
|
|
12
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
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/clamp.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Point, Size, RectInit } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare const clampPoint: (position: Point, size: Size, boundaryRect: RectInit) => {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { clampPoint, clampSize };
|
package/dist/clamp.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Point, Size, RectInit } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare const clampPoint: (position: Point, size: Size, boundaryRect: RectInit) => {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
declare const clampSize: (size: Size, minSize?: Size, maxSize?: Size) => {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { clampPoint, clampSize };
|
package/dist/clamp.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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/clamp.ts
|
|
21
|
+
var clamp_exports = {};
|
|
22
|
+
__export(clamp_exports, {
|
|
23
|
+
clampPoint: () => clampPoint,
|
|
24
|
+
clampSize: () => clampSize
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(clamp_exports);
|
|
27
|
+
var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
28
|
+
var clampPoint = (position, size, boundaryRect) => {
|
|
29
|
+
const x = clamp(position.x, boundaryRect.x, boundaryRect.x + boundaryRect.width - size.width);
|
|
30
|
+
const y = clamp(position.y, boundaryRect.y, boundaryRect.y + boundaryRect.height - size.height);
|
|
31
|
+
return { x, y };
|
|
32
|
+
};
|
|
33
|
+
var defaultMinSize = {
|
|
34
|
+
width: 0,
|
|
35
|
+
height: 0
|
|
36
|
+
};
|
|
37
|
+
var defaultMaxSize = {
|
|
38
|
+
width: Infinity,
|
|
39
|
+
height: Infinity
|
|
40
|
+
};
|
|
41
|
+
var clampSize = (size, minSize = defaultMinSize, maxSize = defaultMaxSize) => {
|
|
42
|
+
return {
|
|
43
|
+
width: Math.min(Math.max(size.width, minSize.width), maxSize.width),
|
|
44
|
+
height: Math.min(Math.max(size.height, minSize.height), maxSize.height)
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
clampPoint,
|
|
50
|
+
clampSize
|
|
51
|
+
});
|