modern-path2d 0.1.0 → 0.1.2
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/index.cjs +198 -129
- package/dist/index.d.cts +31 -15
- package/dist/index.d.mts +31 -15
- package/dist/index.d.ts +31 -15
- package/dist/index.js +1 -1
- package/dist/index.mjs +198 -130
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,145 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
class Point2D {
|
|
4
|
+
constructor(x = 0, y = 0) {
|
|
5
|
+
this.x = x;
|
|
6
|
+
this.y = y;
|
|
7
|
+
}
|
|
8
|
+
static get MAX() {
|
|
9
|
+
return new Point2D(Infinity, Infinity);
|
|
10
|
+
}
|
|
11
|
+
static get MIN() {
|
|
12
|
+
return new Point2D(-Infinity, -Infinity);
|
|
13
|
+
}
|
|
14
|
+
set(x, y) {
|
|
15
|
+
this.x = x;
|
|
16
|
+
this.y = y;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
add(point) {
|
|
20
|
+
this.x += point.x;
|
|
21
|
+
this.y += point.y;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
sub(point) {
|
|
25
|
+
this.x -= point.x;
|
|
26
|
+
this.y -= point.y;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
distanceTo(point) {
|
|
30
|
+
return Math.sqrt(this.distanceToSquared(point));
|
|
31
|
+
}
|
|
32
|
+
distanceToSquared(point) {
|
|
33
|
+
const dx = this.x - point.x;
|
|
34
|
+
const dy = this.y - point.y;
|
|
35
|
+
return dx * dx + dy * dy;
|
|
36
|
+
}
|
|
37
|
+
length() {
|
|
38
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
39
|
+
}
|
|
40
|
+
multiplyScalar(scalar) {
|
|
41
|
+
this.x *= scalar;
|
|
42
|
+
this.y *= scalar;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
divideScalar(scalar) {
|
|
46
|
+
return this.multiplyScalar(1 / scalar);
|
|
47
|
+
}
|
|
48
|
+
subVectors(a, b) {
|
|
49
|
+
this.x = a.x - b.x;
|
|
50
|
+
this.y = a.y - b.y;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
normalize() {
|
|
54
|
+
return this.divideScalar(this.length() || 1);
|
|
55
|
+
}
|
|
56
|
+
lerpVectors(v1, v2, alpha) {
|
|
57
|
+
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
58
|
+
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
equals(point) {
|
|
62
|
+
return this.x === point.x && this.y === point.y;
|
|
63
|
+
}
|
|
64
|
+
applyMatrix3(matrix3) {
|
|
65
|
+
const [a, c, tx, b, d, ty] = matrix3.elements;
|
|
66
|
+
const { x, y } = this;
|
|
67
|
+
this.set(
|
|
68
|
+
a * x + c * y + tx,
|
|
69
|
+
b * x + d * y + ty
|
|
70
|
+
);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
copy(point) {
|
|
74
|
+
this.x = point.x;
|
|
75
|
+
this.y = point.y;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
clone() {
|
|
79
|
+
return new Point2D(this.x, this.y);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class BoundingBox {
|
|
84
|
+
constructor(left = 0, top = 0, width = 0, height = 0) {
|
|
85
|
+
this.left = left;
|
|
86
|
+
this.top = top;
|
|
87
|
+
this.width = width;
|
|
88
|
+
this.height = height;
|
|
89
|
+
}
|
|
90
|
+
get x() {
|
|
91
|
+
return this.left;
|
|
92
|
+
}
|
|
93
|
+
set x(val) {
|
|
94
|
+
this.left = val;
|
|
95
|
+
}
|
|
96
|
+
get y() {
|
|
97
|
+
return this.top;
|
|
98
|
+
}
|
|
99
|
+
set y(val) {
|
|
100
|
+
this.top = val;
|
|
101
|
+
}
|
|
102
|
+
get right() {
|
|
103
|
+
return this.left + this.width;
|
|
104
|
+
}
|
|
105
|
+
get bottom() {
|
|
106
|
+
return this.top + this.height;
|
|
107
|
+
}
|
|
108
|
+
static from(...boxes) {
|
|
109
|
+
const firstBox = boxes[0];
|
|
110
|
+
const merged = boxes.slice(1).reduce(
|
|
111
|
+
(merged2, box) => {
|
|
112
|
+
merged2.left = Math.min(merged2.left, box.left);
|
|
113
|
+
merged2.top = Math.min(merged2.top, box.top);
|
|
114
|
+
merged2.right = Math.max(merged2.right, box.right);
|
|
115
|
+
merged2.bottom = Math.max(merged2.bottom, box.bottom);
|
|
116
|
+
return merged2;
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
left: firstBox?.left ?? 0,
|
|
120
|
+
top: firstBox?.top ?? 0,
|
|
121
|
+
right: firstBox?.right ?? 0,
|
|
122
|
+
bottom: firstBox?.bottom ?? 0
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
return new BoundingBox(merged.left, merged.top, merged.right - merged.left, merged.bottom - merged.top);
|
|
126
|
+
}
|
|
127
|
+
translate(tx, ty) {
|
|
128
|
+
this.left += tx;
|
|
129
|
+
this.top += ty;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
getCenterPoint() {
|
|
133
|
+
return new Point2D((this.left + this.right) / 2, (this.top + this.bottom) / 2);
|
|
134
|
+
}
|
|
135
|
+
clone() {
|
|
136
|
+
return new BoundingBox(this.left, this.top, this.width, this.height);
|
|
137
|
+
}
|
|
138
|
+
toArray() {
|
|
139
|
+
return [this.left, this.top, this.width, this.height];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
3
143
|
var __defProp$6 = Object.defineProperty;
|
|
4
144
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
145
|
var __publicField$6 = (obj, key, value) => {
|
|
@@ -202,86 +342,6 @@ class Matrix3 {
|
|
|
202
342
|
}
|
|
203
343
|
const _m3 = /* @__PURE__ */ new Matrix3();
|
|
204
344
|
|
|
205
|
-
class Point2D {
|
|
206
|
-
constructor(x = 0, y = 0) {
|
|
207
|
-
this.x = x;
|
|
208
|
-
this.y = y;
|
|
209
|
-
}
|
|
210
|
-
static get MAX() {
|
|
211
|
-
return new Point2D(Infinity, Infinity);
|
|
212
|
-
}
|
|
213
|
-
static get MIN() {
|
|
214
|
-
return new Point2D(-Infinity, -Infinity);
|
|
215
|
-
}
|
|
216
|
-
set(x, y) {
|
|
217
|
-
this.x = x;
|
|
218
|
-
this.y = y;
|
|
219
|
-
return this;
|
|
220
|
-
}
|
|
221
|
-
add(point) {
|
|
222
|
-
this.x += point.x;
|
|
223
|
-
this.y += point.y;
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
sub(point) {
|
|
227
|
-
this.x -= point.x;
|
|
228
|
-
this.y -= point.y;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
distanceTo(point) {
|
|
232
|
-
return Math.sqrt(this.distanceToSquared(point));
|
|
233
|
-
}
|
|
234
|
-
distanceToSquared(point) {
|
|
235
|
-
const dx = this.x - point.x;
|
|
236
|
-
const dy = this.y - point.y;
|
|
237
|
-
return dx * dx + dy * dy;
|
|
238
|
-
}
|
|
239
|
-
length() {
|
|
240
|
-
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
241
|
-
}
|
|
242
|
-
multiplyScalar(scalar) {
|
|
243
|
-
this.x *= scalar;
|
|
244
|
-
this.y *= scalar;
|
|
245
|
-
return this;
|
|
246
|
-
}
|
|
247
|
-
divideScalar(scalar) {
|
|
248
|
-
return this.multiplyScalar(1 / scalar);
|
|
249
|
-
}
|
|
250
|
-
subVectors(a, b) {
|
|
251
|
-
this.x = a.x - b.x;
|
|
252
|
-
this.y = a.y - b.y;
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
normalize() {
|
|
256
|
-
return this.divideScalar(this.length() || 1);
|
|
257
|
-
}
|
|
258
|
-
lerpVectors(v1, v2, alpha) {
|
|
259
|
-
this.x = v1.x + (v2.x - v1.x) * alpha;
|
|
260
|
-
this.y = v1.y + (v2.y - v1.y) * alpha;
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
263
|
-
equals(point) {
|
|
264
|
-
return this.x === point.x && this.y === point.y;
|
|
265
|
-
}
|
|
266
|
-
applyMatrix3(matrix3) {
|
|
267
|
-
const [a, c, tx, b, d, ty] = matrix3.elements;
|
|
268
|
-
const { x, y } = this;
|
|
269
|
-
this.set(
|
|
270
|
-
a * x + c * y + tx,
|
|
271
|
-
b * x + d * y + ty
|
|
272
|
-
);
|
|
273
|
-
return this;
|
|
274
|
-
}
|
|
275
|
-
copy(point) {
|
|
276
|
-
this.x = point.x;
|
|
277
|
-
this.y = point.y;
|
|
278
|
-
return this;
|
|
279
|
-
}
|
|
280
|
-
clone() {
|
|
281
|
-
return new Point2D(this.x, this.y);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
345
|
function svgAngle(ux, uy, vx, vy) {
|
|
286
346
|
const dot = ux * vx + uy * vy;
|
|
287
347
|
const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
|
|
@@ -979,13 +1039,13 @@ class Curve {
|
|
|
979
1039
|
drawTo(ctx) {
|
|
980
1040
|
return this;
|
|
981
1041
|
}
|
|
982
|
-
clone() {
|
|
983
|
-
return new this.constructor().copy(this);
|
|
984
|
-
}
|
|
985
1042
|
copy(source) {
|
|
986
1043
|
this.arcLengthDivisions = source.arcLengthDivisions;
|
|
987
1044
|
return this;
|
|
988
1045
|
}
|
|
1046
|
+
clone() {
|
|
1047
|
+
return new this.constructor().copy(this);
|
|
1048
|
+
}
|
|
989
1049
|
}
|
|
990
1050
|
|
|
991
1051
|
class CircleCurve extends Curve {
|
|
@@ -1072,6 +1132,13 @@ class CubicBezierCurve extends Curve {
|
|
|
1072
1132
|
);
|
|
1073
1133
|
return output;
|
|
1074
1134
|
}
|
|
1135
|
+
transform(matrix) {
|
|
1136
|
+
this.v0.applyMatrix3(matrix);
|
|
1137
|
+
this.v1.applyMatrix3(matrix);
|
|
1138
|
+
this.v2.applyMatrix3(matrix);
|
|
1139
|
+
this.v3.applyMatrix3(matrix);
|
|
1140
|
+
return this;
|
|
1141
|
+
}
|
|
1075
1142
|
getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
|
|
1076
1143
|
const { v0, v1, v2, v3 } = this;
|
|
1077
1144
|
min.x = Math.min(min.x, v0.x, v1.x, v2.x, v3.x);
|
|
@@ -1080,13 +1147,6 @@ class CubicBezierCurve extends Curve {
|
|
|
1080
1147
|
max.y = Math.max(max.y, v0.y, v1.y, v2.y, v3.y);
|
|
1081
1148
|
return { min, max };
|
|
1082
1149
|
}
|
|
1083
|
-
transform(matrix) {
|
|
1084
|
-
this.v0.applyMatrix3(matrix);
|
|
1085
|
-
this.v1.applyMatrix3(matrix);
|
|
1086
|
-
this.v2.applyMatrix3(matrix);
|
|
1087
|
-
this.v3.applyMatrix3(matrix);
|
|
1088
|
-
return this;
|
|
1089
|
-
}
|
|
1090
1150
|
getCommands() {
|
|
1091
1151
|
const { v0, v1, v2, v3 } = this;
|
|
1092
1152
|
return [
|
|
@@ -1126,9 +1186,6 @@ class EllipseCurve extends Curve {
|
|
|
1126
1186
|
this.clockwise = clockwise;
|
|
1127
1187
|
this.rotation = rotation;
|
|
1128
1188
|
}
|
|
1129
|
-
getDivisions(divisions = 12) {
|
|
1130
|
-
return divisions * 2;
|
|
1131
|
-
}
|
|
1132
1189
|
getPoint(t, output = new Point2D()) {
|
|
1133
1190
|
const twoPi = Math.PI * 2;
|
|
1134
1191
|
let deltaAngle = this.endAngle - this.startAngle;
|
|
@@ -1164,6 +1221,9 @@ class EllipseCurve extends Curve {
|
|
|
1164
1221
|
}
|
|
1165
1222
|
return output.set(_x, _y);
|
|
1166
1223
|
}
|
|
1224
|
+
getDivisions(divisions = 12) {
|
|
1225
|
+
return divisions * 2;
|
|
1226
|
+
}
|
|
1167
1227
|
getCommands() {
|
|
1168
1228
|
const { x, y, radiusX, radiusY, startAngle, endAngle, clockwise } = this;
|
|
1169
1229
|
const anticlockwise = !clockwise;
|
|
@@ -1377,9 +1437,6 @@ class LineCurve extends Curve {
|
|
|
1377
1437
|
this.v1 = v1;
|
|
1378
1438
|
this.v2 = v2;
|
|
1379
1439
|
}
|
|
1380
|
-
getDivisions() {
|
|
1381
|
-
return 1;
|
|
1382
|
-
}
|
|
1383
1440
|
getPoint(t, output = new Point2D()) {
|
|
1384
1441
|
if (t === 1) {
|
|
1385
1442
|
output.copy(this.v2);
|
|
@@ -1398,12 +1455,13 @@ class LineCurve extends Curve {
|
|
|
1398
1455
|
getTangentAt(u, output = new Point2D()) {
|
|
1399
1456
|
return this.getTangent(u, output);
|
|
1400
1457
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1458
|
+
transform(matrix) {
|
|
1459
|
+
this.v1.applyMatrix3(matrix);
|
|
1460
|
+
this.v2.applyMatrix3(matrix);
|
|
1461
|
+
return this;
|
|
1462
|
+
}
|
|
1463
|
+
getDivisions() {
|
|
1464
|
+
return 1;
|
|
1407
1465
|
}
|
|
1408
1466
|
getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
|
|
1409
1467
|
const { v1, v2 } = this;
|
|
@@ -1413,10 +1471,12 @@ class LineCurve extends Curve {
|
|
|
1413
1471
|
max.y = Math.max(max.y, v1.y, v2.y);
|
|
1414
1472
|
return { min, max };
|
|
1415
1473
|
}
|
|
1416
|
-
|
|
1417
|
-
this
|
|
1418
|
-
|
|
1419
|
-
|
|
1474
|
+
getCommands() {
|
|
1475
|
+
const { v1, v2 } = this;
|
|
1476
|
+
return [
|
|
1477
|
+
{ type: "M", x: v1.x, y: v1.y },
|
|
1478
|
+
{ type: "L", x: v2.x, y: v2.y }
|
|
1479
|
+
];
|
|
1420
1480
|
}
|
|
1421
1481
|
drawTo(ctx) {
|
|
1422
1482
|
const { v1, v2 } = this;
|
|
@@ -1587,12 +1647,11 @@ class QuadraticBezierCurve extends Curve {
|
|
|
1587
1647
|
);
|
|
1588
1648
|
return output;
|
|
1589
1649
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
];
|
|
1650
|
+
transform(matrix) {
|
|
1651
|
+
this.v0.applyMatrix3(matrix);
|
|
1652
|
+
this.v1.applyMatrix3(matrix);
|
|
1653
|
+
this.v2.applyMatrix3(matrix);
|
|
1654
|
+
return this;
|
|
1596
1655
|
}
|
|
1597
1656
|
getMinMax(min = Point2D.MAX, max = Point2D.MIN) {
|
|
1598
1657
|
const { v0, v1, v2 } = this;
|
|
@@ -1606,11 +1665,12 @@ class QuadraticBezierCurve extends Curve {
|
|
|
1606
1665
|
max.y = Math.max(max.y, v0.y, v2.y, y1, y2);
|
|
1607
1666
|
return { min, max };
|
|
1608
1667
|
}
|
|
1609
|
-
|
|
1610
|
-
this
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1668
|
+
getCommands() {
|
|
1669
|
+
const { v0, v1, v2 } = this;
|
|
1670
|
+
return [
|
|
1671
|
+
{ type: "M", x: v0.x, y: v0.y },
|
|
1672
|
+
{ type: "Q", x1: v1.x, y1: v1.y, x: v2.x, y: v2.y }
|
|
1673
|
+
];
|
|
1614
1674
|
}
|
|
1615
1675
|
drawTo(ctx) {
|
|
1616
1676
|
const { v0, v1, v2 } = this;
|
|
@@ -1939,9 +1999,8 @@ class CurvePath extends Curve {
|
|
|
1939
1999
|
copy(source) {
|
|
1940
2000
|
super.copy(source);
|
|
1941
2001
|
this.curves = [];
|
|
1942
|
-
for (let i = 0,
|
|
1943
|
-
|
|
1944
|
-
this.curves.push(curve.clone());
|
|
2002
|
+
for (let i = 0, len = source.curves.length; i < len; i++) {
|
|
2003
|
+
this.curves.push(source.curves[i].clone());
|
|
1945
2004
|
}
|
|
1946
2005
|
this.autoClose = source.autoClose;
|
|
1947
2006
|
this.currentPoint.copy(source.currentPoint);
|
|
@@ -2066,21 +2125,21 @@ class Path2D {
|
|
|
2066
2125
|
this.forEachCurve((curve) => curve.getMinMax(min, max));
|
|
2067
2126
|
return { min, max };
|
|
2068
2127
|
}
|
|
2128
|
+
getBoundingBox() {
|
|
2129
|
+
const { min, max } = this.getMinMax();
|
|
2130
|
+
return new BoundingBox(
|
|
2131
|
+
min.x,
|
|
2132
|
+
min.y,
|
|
2133
|
+
max.x - min.x,
|
|
2134
|
+
max.y - min.y
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2069
2137
|
getCommands() {
|
|
2070
2138
|
return this.paths.flatMap((path) => path.curves.flatMap((curve) => curve.getCommands()));
|
|
2071
2139
|
}
|
|
2072
2140
|
getData() {
|
|
2073
2141
|
return this.paths.map((path) => path.getData()).join(" ");
|
|
2074
2142
|
}
|
|
2075
|
-
getBoundingBox() {
|
|
2076
|
-
const { min, max } = this.getMinMax();
|
|
2077
|
-
return {
|
|
2078
|
-
x: min.x,
|
|
2079
|
-
y: min.y,
|
|
2080
|
-
width: max.x - min.x,
|
|
2081
|
-
height: max.y - min.y
|
|
2082
|
-
};
|
|
2083
|
-
}
|
|
2084
2143
|
getSvgString() {
|
|
2085
2144
|
const { x, y, width, height } = this.getBoundingBox();
|
|
2086
2145
|
return `<svg viewBox="${x} ${y} ${width} ${height}" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke="currentColor" d="${this.getData()}"></path></svg>`;
|
|
@@ -2101,6 +2160,15 @@ class Path2D {
|
|
|
2101
2160
|
this.drawTo(ctx);
|
|
2102
2161
|
ctx.fill();
|
|
2103
2162
|
}
|
|
2163
|
+
copy(source) {
|
|
2164
|
+
source.currentPath = this.currentPath.clone();
|
|
2165
|
+
source.paths = this.paths.map((path) => path.clone());
|
|
2166
|
+
source.userData = this.userData;
|
|
2167
|
+
return this;
|
|
2168
|
+
}
|
|
2169
|
+
clone() {
|
|
2170
|
+
return new Path2D().copy(this);
|
|
2171
|
+
}
|
|
2104
2172
|
}
|
|
2105
2173
|
|
|
2106
2174
|
const defaultUnit = "px";
|
|
@@ -2610,6 +2678,7 @@ function parseSvg(svg) {
|
|
|
2610
2678
|
});
|
|
2611
2679
|
}
|
|
2612
2680
|
|
|
2681
|
+
exports.BoundingBox = BoundingBox;
|
|
2613
2682
|
exports.CircleCurve = CircleCurve;
|
|
2614
2683
|
exports.CubicBezierCurve = CubicBezierCurve;
|
|
2615
2684
|
exports.Curve = Curve;
|
package/dist/index.d.cts
CHANGED
|
@@ -42,6 +42,25 @@ declare class Point2D {
|
|
|
42
42
|
clone(): Point2D;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
declare class BoundingBox {
|
|
46
|
+
left: number;
|
|
47
|
+
top: number;
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
get x(): number;
|
|
51
|
+
set x(val: number);
|
|
52
|
+
get y(): number;
|
|
53
|
+
set y(val: number);
|
|
54
|
+
get right(): number;
|
|
55
|
+
get bottom(): number;
|
|
56
|
+
constructor(left?: number, top?: number, width?: number, height?: number);
|
|
57
|
+
static from(...boxes: BoundingBox[]): BoundingBox;
|
|
58
|
+
translate(tx: number, ty: number): this;
|
|
59
|
+
getCenterPoint(): Point2D;
|
|
60
|
+
clone(): BoundingBox;
|
|
61
|
+
toArray(): [number, number, number, number];
|
|
62
|
+
}
|
|
63
|
+
|
|
45
64
|
declare class CurvePath extends Curve {
|
|
46
65
|
curves: Curve[];
|
|
47
66
|
currentPoint: Point2D;
|
|
@@ -103,19 +122,16 @@ declare class Path2D<T = any> {
|
|
|
103
122
|
min: Point2D;
|
|
104
123
|
max: Point2D;
|
|
105
124
|
};
|
|
125
|
+
getBoundingBox(): BoundingBox;
|
|
106
126
|
getCommands(): PathCommand[];
|
|
107
127
|
getData(): string;
|
|
108
|
-
getBoundingBox(): {
|
|
109
|
-
x: number;
|
|
110
|
-
y: number;
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
};
|
|
114
128
|
getSvgString(): string;
|
|
115
129
|
getSvgDataUri(): string;
|
|
116
130
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
117
131
|
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
118
132
|
fillTo(ctx: CanvasRenderingContext2D): void;
|
|
133
|
+
copy(source: Path2D): this;
|
|
134
|
+
clone(): Path2D;
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
/**
|
|
@@ -200,8 +216,8 @@ declare abstract class Curve {
|
|
|
200
216
|
getData(): string;
|
|
201
217
|
/** overrideable */
|
|
202
218
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
203
|
-
clone(): this;
|
|
204
219
|
copy(source: Curve): this;
|
|
220
|
+
clone(): this;
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
declare class CircleCurve extends Curve {
|
|
@@ -226,11 +242,11 @@ declare class CubicBezierCurve extends Curve {
|
|
|
226
242
|
v3: Point2D;
|
|
227
243
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
|
|
228
244
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
245
|
+
transform(matrix: Matrix3): this;
|
|
229
246
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
230
247
|
min: Point2D;
|
|
231
248
|
max: Point2D;
|
|
232
249
|
};
|
|
233
|
-
transform(matrix: Matrix3): this;
|
|
234
250
|
getCommands(): PathCommand[];
|
|
235
251
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
236
252
|
copy(source: CubicBezierCurve): this;
|
|
@@ -246,8 +262,8 @@ declare class EllipseCurve extends Curve {
|
|
|
246
262
|
clockwise: boolean;
|
|
247
263
|
rotation: number;
|
|
248
264
|
constructor(x?: number, y?: number, radiusX?: number, radiusY?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
|
|
249
|
-
getDivisions(divisions?: number): number;
|
|
250
265
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
266
|
+
getDivisions(divisions?: number): number;
|
|
251
267
|
getCommands(): PathCommand[];
|
|
252
268
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
253
269
|
transform(matrix: Matrix3): this;
|
|
@@ -275,17 +291,17 @@ declare class LineCurve extends Curve {
|
|
|
275
291
|
v1: Point2D;
|
|
276
292
|
v2: Point2D;
|
|
277
293
|
constructor(v1?: Point2D, v2?: Point2D);
|
|
278
|
-
getDivisions(): number;
|
|
279
294
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
280
295
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
281
296
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
282
297
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
283
|
-
|
|
298
|
+
transform(matrix: Matrix3): this;
|
|
299
|
+
getDivisions(): number;
|
|
284
300
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
285
301
|
min: Point2D;
|
|
286
302
|
max: Point2D;
|
|
287
303
|
};
|
|
288
|
-
|
|
304
|
+
getCommands(): PathCommand[];
|
|
289
305
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
290
306
|
copy(source: LineCurve): this;
|
|
291
307
|
}
|
|
@@ -320,12 +336,12 @@ declare class QuadraticBezierCurve extends Curve {
|
|
|
320
336
|
v2: Point2D;
|
|
321
337
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
|
|
322
338
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
323
|
-
|
|
339
|
+
transform(matrix: Matrix3): this;
|
|
324
340
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
325
341
|
min: Point2D;
|
|
326
342
|
max: Point2D;
|
|
327
343
|
};
|
|
328
|
-
|
|
344
|
+
getCommands(): PathCommand[];
|
|
329
345
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
330
346
|
copy(source: QuadraticBezierCurve): this;
|
|
331
347
|
}
|
|
@@ -366,4 +382,4 @@ declare class SplineCurve extends Curve {
|
|
|
366
382
|
|
|
367
383
|
declare function parseSvg(svg: string | SVGElement): Path2D[];
|
|
368
384
|
|
|
369
|
-
export { CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, Point2D, QuadraticBezierCurve, RectangularCurve, SplineCurve, parseSvg };
|
|
385
|
+
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, Point2D, QuadraticBezierCurve, RectangularCurve, SplineCurve, parseSvg };
|
package/dist/index.d.mts
CHANGED
|
@@ -42,6 +42,25 @@ declare class Point2D {
|
|
|
42
42
|
clone(): Point2D;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
declare class BoundingBox {
|
|
46
|
+
left: number;
|
|
47
|
+
top: number;
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
get x(): number;
|
|
51
|
+
set x(val: number);
|
|
52
|
+
get y(): number;
|
|
53
|
+
set y(val: number);
|
|
54
|
+
get right(): number;
|
|
55
|
+
get bottom(): number;
|
|
56
|
+
constructor(left?: number, top?: number, width?: number, height?: number);
|
|
57
|
+
static from(...boxes: BoundingBox[]): BoundingBox;
|
|
58
|
+
translate(tx: number, ty: number): this;
|
|
59
|
+
getCenterPoint(): Point2D;
|
|
60
|
+
clone(): BoundingBox;
|
|
61
|
+
toArray(): [number, number, number, number];
|
|
62
|
+
}
|
|
63
|
+
|
|
45
64
|
declare class CurvePath extends Curve {
|
|
46
65
|
curves: Curve[];
|
|
47
66
|
currentPoint: Point2D;
|
|
@@ -103,19 +122,16 @@ declare class Path2D<T = any> {
|
|
|
103
122
|
min: Point2D;
|
|
104
123
|
max: Point2D;
|
|
105
124
|
};
|
|
125
|
+
getBoundingBox(): BoundingBox;
|
|
106
126
|
getCommands(): PathCommand[];
|
|
107
127
|
getData(): string;
|
|
108
|
-
getBoundingBox(): {
|
|
109
|
-
x: number;
|
|
110
|
-
y: number;
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
};
|
|
114
128
|
getSvgString(): string;
|
|
115
129
|
getSvgDataUri(): string;
|
|
116
130
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
117
131
|
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
118
132
|
fillTo(ctx: CanvasRenderingContext2D): void;
|
|
133
|
+
copy(source: Path2D): this;
|
|
134
|
+
clone(): Path2D;
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
/**
|
|
@@ -200,8 +216,8 @@ declare abstract class Curve {
|
|
|
200
216
|
getData(): string;
|
|
201
217
|
/** overrideable */
|
|
202
218
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
203
|
-
clone(): this;
|
|
204
219
|
copy(source: Curve): this;
|
|
220
|
+
clone(): this;
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
declare class CircleCurve extends Curve {
|
|
@@ -226,11 +242,11 @@ declare class CubicBezierCurve extends Curve {
|
|
|
226
242
|
v3: Point2D;
|
|
227
243
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
|
|
228
244
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
245
|
+
transform(matrix: Matrix3): this;
|
|
229
246
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
230
247
|
min: Point2D;
|
|
231
248
|
max: Point2D;
|
|
232
249
|
};
|
|
233
|
-
transform(matrix: Matrix3): this;
|
|
234
250
|
getCommands(): PathCommand[];
|
|
235
251
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
236
252
|
copy(source: CubicBezierCurve): this;
|
|
@@ -246,8 +262,8 @@ declare class EllipseCurve extends Curve {
|
|
|
246
262
|
clockwise: boolean;
|
|
247
263
|
rotation: number;
|
|
248
264
|
constructor(x?: number, y?: number, radiusX?: number, radiusY?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
|
|
249
|
-
getDivisions(divisions?: number): number;
|
|
250
265
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
266
|
+
getDivisions(divisions?: number): number;
|
|
251
267
|
getCommands(): PathCommand[];
|
|
252
268
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
253
269
|
transform(matrix: Matrix3): this;
|
|
@@ -275,17 +291,17 @@ declare class LineCurve extends Curve {
|
|
|
275
291
|
v1: Point2D;
|
|
276
292
|
v2: Point2D;
|
|
277
293
|
constructor(v1?: Point2D, v2?: Point2D);
|
|
278
|
-
getDivisions(): number;
|
|
279
294
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
280
295
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
281
296
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
282
297
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
283
|
-
|
|
298
|
+
transform(matrix: Matrix3): this;
|
|
299
|
+
getDivisions(): number;
|
|
284
300
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
285
301
|
min: Point2D;
|
|
286
302
|
max: Point2D;
|
|
287
303
|
};
|
|
288
|
-
|
|
304
|
+
getCommands(): PathCommand[];
|
|
289
305
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
290
306
|
copy(source: LineCurve): this;
|
|
291
307
|
}
|
|
@@ -320,12 +336,12 @@ declare class QuadraticBezierCurve extends Curve {
|
|
|
320
336
|
v2: Point2D;
|
|
321
337
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
|
|
322
338
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
323
|
-
|
|
339
|
+
transform(matrix: Matrix3): this;
|
|
324
340
|
getMinMax(min?: Point2D, max?: Point2D): {
|
|
325
341
|
min: Point2D;
|
|
326
342
|
max: Point2D;
|
|
327
343
|
};
|
|
328
|
-
|
|
344
|
+
getCommands(): PathCommand[];
|
|
329
345
|
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
330
346
|
copy(source: QuadraticBezierCurve): this;
|
|
331
347
|
}
|
|
@@ -366,4 +382,4 @@ declare class SplineCurve extends Curve {
|
|
|
366
382
|
|
|
367
383
|
declare function parseSvg(svg: string | SVGElement): Path2D[];
|
|
368
384
|
|
|
369
|
-
export { CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, Point2D, QuadraticBezierCurve, RectangularCurve, SplineCurve, parseSvg };
|
|
385
|
+
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, Point2D, QuadraticBezierCurve, RectangularCurve, SplineCurve, parseSvg };
|