@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.
- package/dist/align.mjs +0 -2
- package/dist/angle.mjs +0 -2
- package/dist/clamp.mjs +0 -2
- package/dist/closest.mjs +0 -2
- package/dist/compass.d.mts +1 -5
- package/dist/compass.d.ts +1 -5
- package/dist/compass.js +0 -33
- package/dist/compass.mjs +0 -27
- package/dist/constrain.mjs +0 -2
- package/dist/contains.mjs +0 -2
- package/dist/distance.mjs +0 -2
- package/dist/equality.mjs +0 -2
- package/dist/from-element.mjs +0 -2
- package/dist/from-points.mjs +0 -2
- package/dist/from-range.mjs +0 -2
- package/dist/from-rotation.mjs +0 -2
- package/dist/from-window.mjs +0 -2
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -4
- package/dist/index.mjs +1 -2
- package/dist/interact.d.mts +71 -0
- package/dist/interact.d.ts +71 -0
- package/dist/interact.js +377 -0
- package/dist/interact.mjs +338 -0
- package/dist/intersection.mjs +0 -2
- package/dist/operations.mjs +0 -2
- package/dist/polygon.mjs +0 -2
- package/dist/rect.d.mts +9 -2
- package/dist/rect.d.ts +9 -2
- package/dist/rect.js +40 -0
- package/dist/rect.mjs +33 -2
- package/dist/types.d.mts +1 -5
- package/dist/types.d.ts +1 -5
- package/dist/union.mjs +0 -2
- package/package.json +1 -1
- package/dist/affine-transform.d.mts +0 -39
- package/dist/affine-transform.d.ts +0 -39
- package/dist/affine-transform.js +0 -189
- package/dist/affine-transform.mjs +0 -166
- package/dist/chunk-QZ7TP4HQ.mjs +0 -7
- package/dist/resize.d.mts +0 -6
- package/dist/resize.d.ts +0 -6
- package/dist/resize.js +0 -113
- package/dist/resize.mjs +0 -90
package/dist/intersection.mjs
CHANGED
package/dist/operations.mjs
CHANGED
package/dist/polygon.mjs
CHANGED
package/dist/rect.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Point, RectInit, Rect, RectEdge } from './types.mjs';
|
|
1
|
+
import { Point, RectInit, Rect, RectEdge, Size } from './types.mjs';
|
|
2
2
|
|
|
3
|
+
declare const ZERO_POINT: Point;
|
|
3
4
|
declare const createPoint: (x: number, y: number) => {
|
|
4
5
|
x: number;
|
|
5
6
|
y: number;
|
|
@@ -9,6 +10,7 @@ declare const addPoints: (a: Point, b: Point) => {
|
|
|
9
10
|
x: number;
|
|
10
11
|
y: number;
|
|
11
12
|
};
|
|
13
|
+
declare const getMidpoint: (a: Point, b: Point, offset?: Point) => Point;
|
|
12
14
|
declare function isPoint(v: any): v is Point;
|
|
13
15
|
declare function createRect(r: RectInit): Rect;
|
|
14
16
|
declare function isRect(v: any): v is Rect;
|
|
@@ -54,5 +56,10 @@ declare function getRectEdges(v: Rect): {
|
|
|
54
56
|
bottom: RectEdge;
|
|
55
57
|
left: RectEdge;
|
|
56
58
|
};
|
|
59
|
+
declare const getCenterPoint: (rect: RectInit) => Point;
|
|
60
|
+
declare const isVisibleSize: (size: Size) => boolean;
|
|
61
|
+
declare const scaleSize: (size: Size, factor: number) => Size;
|
|
62
|
+
declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
63
|
+
declare const roundRect: (rect: RectInit) => RectInit;
|
|
57
64
|
|
|
58
|
-
export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
|
|
65
|
+
export { ZERO_POINT, addPoints, createPoint, createRect, getCenterPoint, getMidpoint, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, isVisibleSize, roundRect, scaleRect, scaleSize, subtractPoints };
|
package/dist/rect.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Point, RectInit, Rect, RectEdge } from './types.js';
|
|
1
|
+
import { Point, RectInit, Rect, RectEdge, Size } from './types.js';
|
|
2
2
|
|
|
3
|
+
declare const ZERO_POINT: Point;
|
|
3
4
|
declare const createPoint: (x: number, y: number) => {
|
|
4
5
|
x: number;
|
|
5
6
|
y: number;
|
|
@@ -9,6 +10,7 @@ declare const addPoints: (a: Point, b: Point) => {
|
|
|
9
10
|
x: number;
|
|
10
11
|
y: number;
|
|
11
12
|
};
|
|
13
|
+
declare const getMidpoint: (a: Point, b: Point, offset?: Point) => Point;
|
|
12
14
|
declare function isPoint(v: any): v is Point;
|
|
13
15
|
declare function createRect(r: RectInit): Rect;
|
|
14
16
|
declare function isRect(v: any): v is Rect;
|
|
@@ -54,5 +56,10 @@ declare function getRectEdges(v: Rect): {
|
|
|
54
56
|
bottom: RectEdge;
|
|
55
57
|
left: RectEdge;
|
|
56
58
|
};
|
|
59
|
+
declare const getCenterPoint: (rect: RectInit) => Point;
|
|
60
|
+
declare const isVisibleSize: (size: Size) => boolean;
|
|
61
|
+
declare const scaleSize: (size: Size, factor: number) => Size;
|
|
62
|
+
declare const scaleRect: (rect: RectInit, scale: Point) => RectInit;
|
|
63
|
+
declare const roundRect: (rect: RectInit) => RectInit;
|
|
57
64
|
|
|
58
|
-
export { addPoints, createPoint, createRect, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, subtractPoints };
|
|
65
|
+
export { ZERO_POINT, addPoints, createPoint, createRect, getCenterPoint, getMidpoint, getRectCenters, getRectCorners, getRectEdges, isPoint, isRect, isVisibleSize, roundRect, scaleRect, scaleSize, subtractPoints };
|
package/dist/rect.js
CHANGED
|
@@ -20,23 +20,35 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/rect.ts
|
|
21
21
|
var rect_exports = {};
|
|
22
22
|
__export(rect_exports, {
|
|
23
|
+
ZERO_POINT: () => ZERO_POINT,
|
|
23
24
|
addPoints: () => addPoints,
|
|
24
25
|
createPoint: () => createPoint,
|
|
25
26
|
createRect: () => createRect,
|
|
27
|
+
getCenterPoint: () => getCenterPoint,
|
|
28
|
+
getMidpoint: () => getMidpoint,
|
|
26
29
|
getRectCenters: () => getRectCenters,
|
|
27
30
|
getRectCorners: () => getRectCorners,
|
|
28
31
|
getRectEdges: () => getRectEdges,
|
|
29
32
|
isPoint: () => isPoint,
|
|
30
33
|
isRect: () => isRect,
|
|
34
|
+
isVisibleSize: () => isVisibleSize,
|
|
35
|
+
roundRect: () => roundRect,
|
|
36
|
+
scaleRect: () => scaleRect,
|
|
37
|
+
scaleSize: () => scaleSize,
|
|
31
38
|
subtractPoints: () => subtractPoints
|
|
32
39
|
});
|
|
33
40
|
module.exports = __toCommonJS(rect_exports);
|
|
41
|
+
var ZERO_POINT = Object.freeze({ x: 0, y: 0 });
|
|
34
42
|
var createPoint = (x, y) => ({ x, y });
|
|
35
43
|
var subtractPoints = (a, b) => {
|
|
36
44
|
if (!b) return a;
|
|
37
45
|
return createPoint(a.x - b.x, a.y - b.y);
|
|
38
46
|
};
|
|
39
47
|
var addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
|
|
48
|
+
var getMidpoint = (a, b, offset) => ({
|
|
49
|
+
x: (a.x + b.x) / 2 - (offset?.x ?? 0),
|
|
50
|
+
y: (a.y + b.y) / 2 - (offset?.y ?? 0)
|
|
51
|
+
});
|
|
40
52
|
function isPoint(v) {
|
|
41
53
|
return Reflect.has(v, "x") && Reflect.has(v, "y");
|
|
42
54
|
}
|
|
@@ -83,15 +95,43 @@ function getRectEdges(v) {
|
|
|
83
95
|
const left = [c.top, c.left];
|
|
84
96
|
return { top, right, bottom, left };
|
|
85
97
|
}
|
|
98
|
+
var getCenterPoint = (rect) => ({
|
|
99
|
+
x: rect.x + rect.width / 2,
|
|
100
|
+
y: rect.y + rect.height / 2
|
|
101
|
+
});
|
|
102
|
+
var isVisibleSize = (size) => size.width > 0 && size.height > 0;
|
|
103
|
+
var scaleSize = (size, factor) => ({
|
|
104
|
+
width: size.width * factor,
|
|
105
|
+
height: size.height * factor
|
|
106
|
+
});
|
|
107
|
+
var scaleRect = (rect, scale) => ({
|
|
108
|
+
x: rect.x * scale.x,
|
|
109
|
+
y: rect.y * scale.y,
|
|
110
|
+
width: rect.width * scale.x,
|
|
111
|
+
height: rect.height * scale.y
|
|
112
|
+
});
|
|
113
|
+
var roundRect = (rect) => ({
|
|
114
|
+
x: Math.round(rect.x),
|
|
115
|
+
y: Math.round(rect.y),
|
|
116
|
+
width: Math.round(rect.width),
|
|
117
|
+
height: Math.round(rect.height)
|
|
118
|
+
});
|
|
86
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
120
|
0 && (module.exports = {
|
|
121
|
+
ZERO_POINT,
|
|
88
122
|
addPoints,
|
|
89
123
|
createPoint,
|
|
90
124
|
createRect,
|
|
125
|
+
getCenterPoint,
|
|
126
|
+
getMidpoint,
|
|
91
127
|
getRectCenters,
|
|
92
128
|
getRectCorners,
|
|
93
129
|
getRectEdges,
|
|
94
130
|
isPoint,
|
|
95
131
|
isRect,
|
|
132
|
+
isVisibleSize,
|
|
133
|
+
roundRect,
|
|
134
|
+
scaleRect,
|
|
135
|
+
scaleSize,
|
|
96
136
|
subtractPoints
|
|
97
137
|
});
|
package/dist/rect.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
-
|
|
3
1
|
// src/rect.ts
|
|
2
|
+
var ZERO_POINT = Object.freeze({ x: 0, y: 0 });
|
|
4
3
|
var createPoint = (x, y) => ({ x, y });
|
|
5
4
|
var subtractPoints = (a, b) => {
|
|
6
5
|
if (!b) return a;
|
|
7
6
|
return createPoint(a.x - b.x, a.y - b.y);
|
|
8
7
|
};
|
|
9
8
|
var addPoints = (a, b) => createPoint(a.x + b.x, a.y + b.y);
|
|
9
|
+
var getMidpoint = (a, b, offset) => ({
|
|
10
|
+
x: (a.x + b.x) / 2 - (offset?.x ?? 0),
|
|
11
|
+
y: (a.y + b.y) / 2 - (offset?.y ?? 0)
|
|
12
|
+
});
|
|
10
13
|
function isPoint(v) {
|
|
11
14
|
return Reflect.has(v, "x") && Reflect.has(v, "y");
|
|
12
15
|
}
|
|
@@ -53,14 +56,42 @@ function getRectEdges(v) {
|
|
|
53
56
|
const left = [c.top, c.left];
|
|
54
57
|
return { top, right, bottom, left };
|
|
55
58
|
}
|
|
59
|
+
var getCenterPoint = (rect) => ({
|
|
60
|
+
x: rect.x + rect.width / 2,
|
|
61
|
+
y: rect.y + rect.height / 2
|
|
62
|
+
});
|
|
63
|
+
var isVisibleSize = (size) => size.width > 0 && size.height > 0;
|
|
64
|
+
var scaleSize = (size, factor) => ({
|
|
65
|
+
width: size.width * factor,
|
|
66
|
+
height: size.height * factor
|
|
67
|
+
});
|
|
68
|
+
var scaleRect = (rect, scale) => ({
|
|
69
|
+
x: rect.x * scale.x,
|
|
70
|
+
y: rect.y * scale.y,
|
|
71
|
+
width: rect.width * scale.x,
|
|
72
|
+
height: rect.height * scale.y
|
|
73
|
+
});
|
|
74
|
+
var roundRect = (rect) => ({
|
|
75
|
+
x: Math.round(rect.x),
|
|
76
|
+
y: Math.round(rect.y),
|
|
77
|
+
width: Math.round(rect.width),
|
|
78
|
+
height: Math.round(rect.height)
|
|
79
|
+
});
|
|
56
80
|
export {
|
|
81
|
+
ZERO_POINT,
|
|
57
82
|
addPoints,
|
|
58
83
|
createPoint,
|
|
59
84
|
createRect,
|
|
85
|
+
getCenterPoint,
|
|
86
|
+
getMidpoint,
|
|
60
87
|
getRectCenters,
|
|
61
88
|
getRectCorners,
|
|
62
89
|
getRectEdges,
|
|
63
90
|
isPoint,
|
|
64
91
|
isRect,
|
|
92
|
+
isVisibleSize,
|
|
93
|
+
roundRect,
|
|
94
|
+
scaleRect,
|
|
95
|
+
scaleSize,
|
|
65
96
|
subtractPoints
|
|
66
97
|
};
|
package/dist/types.d.mts
CHANGED
|
@@ -41,10 +41,6 @@ interface SymmetricRectInset {
|
|
|
41
41
|
dx?: number | undefined;
|
|
42
42
|
dy?: number | undefined;
|
|
43
43
|
}
|
|
44
|
-
interface ScalingOptions {
|
|
45
|
-
scalingOriginMode: "center" | "extent";
|
|
46
|
-
lockAspectRatio: boolean;
|
|
47
|
-
}
|
|
48
44
|
interface AlignOptions {
|
|
49
45
|
h: HAlign;
|
|
50
46
|
v: VAlign;
|
|
@@ -52,4 +48,4 @@ interface AlignOptions {
|
|
|
52
48
|
type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
53
49
|
type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
|
54
50
|
|
|
55
|
-
export type { AlignOptions, Bounds, CenterPoint, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInit, RectInset, RectPoint, RectPoints, RectSide,
|
|
51
|
+
export type { AlignOptions, Bounds, CenterPoint, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInit, RectInset, RectPoint, RectPoints, RectSide, Size, SymmetricRectInset, VAlign };
|
package/dist/types.d.ts
CHANGED
|
@@ -41,10 +41,6 @@ interface SymmetricRectInset {
|
|
|
41
41
|
dx?: number | undefined;
|
|
42
42
|
dy?: number | undefined;
|
|
43
43
|
}
|
|
44
|
-
interface ScalingOptions {
|
|
45
|
-
scalingOriginMode: "center" | "extent";
|
|
46
|
-
lockAspectRatio: boolean;
|
|
47
|
-
}
|
|
48
44
|
interface AlignOptions {
|
|
49
45
|
h: HAlign;
|
|
50
46
|
v: VAlign;
|
|
@@ -52,4 +48,4 @@ interface AlignOptions {
|
|
|
52
48
|
type HAlign = "left-inside" | "left-outside" | "center" | "right-inside" | "right-outside";
|
|
53
49
|
type VAlign = "top-inside" | "top-outside" | "center" | "bottom-inside" | "bottom-outside";
|
|
54
50
|
|
|
55
|
-
export type { AlignOptions, Bounds, CenterPoint, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInit, RectInset, RectPoint, RectPoints, RectSide,
|
|
51
|
+
export type { AlignOptions, Bounds, CenterPoint, HAlign, Point, Rect, RectCenter, RectCenters, RectCorner, RectCorners, RectEdge, RectEdges, RectInit, RectInset, RectPoint, RectPoints, RectSide, Size, SymmetricRectInset, VAlign };
|
package/dist/union.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
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 };
|
|
@@ -1,39 +0,0 @@
|
|
|
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 };
|
package/dist/affine-transform.js
DELETED
|
@@ -1,189 +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 __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
|
-
});
|