modern-path2d 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +202 -45
- package/dist/index.d.cts +70 -19
- package/dist/index.d.mts +70 -19
- package/dist/index.d.ts +70 -19
- package/dist/index.js +1 -1
- package/dist/index.mjs +202 -45
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -36,6 +36,8 @@ type PathCommand = {
|
|
|
36
36
|
declare class Point2D {
|
|
37
37
|
x: number;
|
|
38
38
|
y: number;
|
|
39
|
+
static get MAX(): Point2D;
|
|
40
|
+
static get MIN(): Point2D;
|
|
39
41
|
constructor(x?: number, y?: number);
|
|
40
42
|
set(x: number, y: number): this;
|
|
41
43
|
add(point: Point2D): this;
|
|
@@ -58,8 +60,12 @@ declare abstract class Curve {
|
|
|
58
60
|
protected _cacheArcLengths?: number[];
|
|
59
61
|
protected _needsUpdate: boolean;
|
|
60
62
|
abstract getPoint(t: number, output?: Point2D): Point2D;
|
|
61
|
-
abstract
|
|
63
|
+
abstract getCommands(): PathCommand[];
|
|
62
64
|
abstract drawTo(ctx: CanvasRenderingContext2D): void;
|
|
65
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
66
|
+
min: Point2D;
|
|
67
|
+
max: Point2D;
|
|
68
|
+
};
|
|
63
69
|
getDivisions(divisions: number): number;
|
|
64
70
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
65
71
|
getPoints(divisions?: number): Point2D[];
|
|
@@ -70,6 +76,7 @@ declare abstract class Curve {
|
|
|
70
76
|
getUtoTmapping(u: number, distance?: number): number;
|
|
71
77
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
72
78
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
79
|
+
getData(): string;
|
|
73
80
|
clone(): this;
|
|
74
81
|
copy(source: Curve): this;
|
|
75
82
|
}
|
|
@@ -99,7 +106,11 @@ declare class CurvePath extends Curve {
|
|
|
99
106
|
absarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
|
|
100
107
|
ellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
101
108
|
absellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
102
|
-
|
|
109
|
+
getCommands(): PathCommand[];
|
|
110
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
111
|
+
min: Point2D;
|
|
112
|
+
max: Point2D;
|
|
113
|
+
};
|
|
103
114
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
104
115
|
copy(source: CurvePath): this;
|
|
105
116
|
}
|
|
@@ -110,11 +121,14 @@ declare class CircleCurve extends Curve {
|
|
|
110
121
|
start: number;
|
|
111
122
|
end: number;
|
|
112
123
|
constructor(center: Point2D, radius: number, start?: number, end?: number);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
125
|
+
min: Point2D;
|
|
126
|
+
max: Point2D;
|
|
127
|
+
};
|
|
128
|
+
getPoint(t: number): Point2D;
|
|
129
|
+
getTangent(t: number): Point2D;
|
|
130
|
+
getNormal(t: number): Point2D;
|
|
131
|
+
getCommands(): PathCommand[];
|
|
118
132
|
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
119
133
|
}
|
|
120
134
|
|
|
@@ -125,7 +139,11 @@ declare class CubicBezierCurve extends Curve {
|
|
|
125
139
|
v3: Point2D;
|
|
126
140
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
|
|
127
141
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
128
|
-
|
|
142
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
143
|
+
min: Point2D;
|
|
144
|
+
max: Point2D;
|
|
145
|
+
};
|
|
146
|
+
getCommands(): PathCommand[];
|
|
129
147
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
130
148
|
copy(source: CubicBezierCurve): this;
|
|
131
149
|
}
|
|
@@ -142,7 +160,7 @@ declare class EllipseCurve extends Curve {
|
|
|
142
160
|
constructor(x?: number, y?: number, rx?: number, ry?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
|
|
143
161
|
getDivisions(divisions?: number): number;
|
|
144
162
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
145
|
-
|
|
163
|
+
getCommands(): PathCommand[];
|
|
146
164
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
147
165
|
copy(source: EllipseCurve): this;
|
|
148
166
|
}
|
|
@@ -160,7 +178,7 @@ declare class HeartCurve extends Curve {
|
|
|
160
178
|
getCurrentLine(value: number): Curve;
|
|
161
179
|
getTangent(value: number): Point2D;
|
|
162
180
|
getNormal(value: number): Point2D;
|
|
163
|
-
|
|
181
|
+
getCommands(): PathCommand[];
|
|
164
182
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
165
183
|
}
|
|
166
184
|
|
|
@@ -173,7 +191,11 @@ declare class LineCurve extends Curve {
|
|
|
173
191
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
174
192
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
175
193
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
176
|
-
|
|
194
|
+
getCommands(): PathCommand[];
|
|
195
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
196
|
+
min: Point2D;
|
|
197
|
+
max: Point2D;
|
|
198
|
+
};
|
|
177
199
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
178
200
|
copy(source: LineCurve): this;
|
|
179
201
|
}
|
|
@@ -194,7 +216,11 @@ declare class PloygonCurve extends Curve {
|
|
|
194
216
|
getCurrentLine(value: number): LineCurve;
|
|
195
217
|
getTangent(value: number): Point2D;
|
|
196
218
|
getNormal(value: number): Point2D;
|
|
197
|
-
|
|
219
|
+
getCommands(): PathCommand[];
|
|
220
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
221
|
+
min: Point2D;
|
|
222
|
+
max: Point2D;
|
|
223
|
+
};
|
|
198
224
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
199
225
|
}
|
|
200
226
|
|
|
@@ -204,7 +230,11 @@ declare class QuadraticBezierCurve extends Curve {
|
|
|
204
230
|
v2: Point2D;
|
|
205
231
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
|
|
206
232
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
207
|
-
|
|
233
|
+
getCommands(): PathCommand[];
|
|
234
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
235
|
+
min: Point2D;
|
|
236
|
+
max: Point2D;
|
|
237
|
+
};
|
|
208
238
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
209
239
|
copy(source: QuadraticBezierCurve): this;
|
|
210
240
|
}
|
|
@@ -227,7 +257,11 @@ declare class RectangularCurve extends Curve {
|
|
|
227
257
|
getCurrentLine(t: number): LineCurve;
|
|
228
258
|
getTangent(t: number): Point2D;
|
|
229
259
|
getNormal(value: number): Point2D;
|
|
230
|
-
|
|
260
|
+
getCommands(): PathCommand[];
|
|
261
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
262
|
+
min: Point2D;
|
|
263
|
+
max: Point2D;
|
|
264
|
+
};
|
|
231
265
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
232
266
|
}
|
|
233
267
|
|
|
@@ -236,7 +270,7 @@ declare class SplineCurve extends Curve {
|
|
|
236
270
|
constructor(points?: Point2D[]);
|
|
237
271
|
getDivisions(divisions?: number): number;
|
|
238
272
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
239
|
-
|
|
273
|
+
getCommands(): PathCommand[];
|
|
240
274
|
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
241
275
|
copy(source: SplineCurve): this;
|
|
242
276
|
}
|
|
@@ -247,14 +281,31 @@ declare class SplineCurve extends Curve {
|
|
|
247
281
|
declare class Path2D {
|
|
248
282
|
currentPath: CurvePath;
|
|
249
283
|
paths: CurvePath[];
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
lineTo(x: number, y: number): this;
|
|
284
|
+
addPath(path: Path2D): this;
|
|
285
|
+
closePath(): this;
|
|
253
286
|
moveTo(x: number, y: number): this;
|
|
287
|
+
lineTo(x: number, y: number): this;
|
|
288
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
254
289
|
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
290
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
291
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
292
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise: number): this;
|
|
255
293
|
rect(x: number, y: number, w: number, h: number): this;
|
|
256
294
|
splineThru(points: Point2D[]): this;
|
|
257
|
-
|
|
295
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
296
|
+
min: Point2D;
|
|
297
|
+
max: Point2D;
|
|
298
|
+
};
|
|
299
|
+
getCommands(): PathCommand[];
|
|
300
|
+
getData(): string;
|
|
301
|
+
getBoundingBox(): {
|
|
302
|
+
x: number;
|
|
303
|
+
y: number;
|
|
304
|
+
width: number;
|
|
305
|
+
height: number;
|
|
306
|
+
};
|
|
307
|
+
getSvgString(): string;
|
|
308
|
+
getSvgDataUri(): string;
|
|
258
309
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
259
310
|
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
260
311
|
fillTo(ctx: CanvasRenderingContext2D): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ type PathCommand = {
|
|
|
36
36
|
declare class Point2D {
|
|
37
37
|
x: number;
|
|
38
38
|
y: number;
|
|
39
|
+
static get MAX(): Point2D;
|
|
40
|
+
static get MIN(): Point2D;
|
|
39
41
|
constructor(x?: number, y?: number);
|
|
40
42
|
set(x: number, y: number): this;
|
|
41
43
|
add(point: Point2D): this;
|
|
@@ -58,8 +60,12 @@ declare abstract class Curve {
|
|
|
58
60
|
protected _cacheArcLengths?: number[];
|
|
59
61
|
protected _needsUpdate: boolean;
|
|
60
62
|
abstract getPoint(t: number, output?: Point2D): Point2D;
|
|
61
|
-
abstract
|
|
63
|
+
abstract getCommands(): PathCommand[];
|
|
62
64
|
abstract drawTo(ctx: CanvasRenderingContext2D): void;
|
|
65
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
66
|
+
min: Point2D;
|
|
67
|
+
max: Point2D;
|
|
68
|
+
};
|
|
63
69
|
getDivisions(divisions: number): number;
|
|
64
70
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
65
71
|
getPoints(divisions?: number): Point2D[];
|
|
@@ -70,6 +76,7 @@ declare abstract class Curve {
|
|
|
70
76
|
getUtoTmapping(u: number, distance?: number): number;
|
|
71
77
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
72
78
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
79
|
+
getData(): string;
|
|
73
80
|
clone(): this;
|
|
74
81
|
copy(source: Curve): this;
|
|
75
82
|
}
|
|
@@ -99,7 +106,11 @@ declare class CurvePath extends Curve {
|
|
|
99
106
|
absarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
|
|
100
107
|
ellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
101
108
|
absellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
102
|
-
|
|
109
|
+
getCommands(): PathCommand[];
|
|
110
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
111
|
+
min: Point2D;
|
|
112
|
+
max: Point2D;
|
|
113
|
+
};
|
|
103
114
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
104
115
|
copy(source: CurvePath): this;
|
|
105
116
|
}
|
|
@@ -110,11 +121,14 @@ declare class CircleCurve extends Curve {
|
|
|
110
121
|
start: number;
|
|
111
122
|
end: number;
|
|
112
123
|
constructor(center: Point2D, radius: number, start?: number, end?: number);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
125
|
+
min: Point2D;
|
|
126
|
+
max: Point2D;
|
|
127
|
+
};
|
|
128
|
+
getPoint(t: number): Point2D;
|
|
129
|
+
getTangent(t: number): Point2D;
|
|
130
|
+
getNormal(t: number): Point2D;
|
|
131
|
+
getCommands(): PathCommand[];
|
|
118
132
|
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
119
133
|
}
|
|
120
134
|
|
|
@@ -125,7 +139,11 @@ declare class CubicBezierCurve extends Curve {
|
|
|
125
139
|
v3: Point2D;
|
|
126
140
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
|
|
127
141
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
128
|
-
|
|
142
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
143
|
+
min: Point2D;
|
|
144
|
+
max: Point2D;
|
|
145
|
+
};
|
|
146
|
+
getCommands(): PathCommand[];
|
|
129
147
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
130
148
|
copy(source: CubicBezierCurve): this;
|
|
131
149
|
}
|
|
@@ -142,7 +160,7 @@ declare class EllipseCurve extends Curve {
|
|
|
142
160
|
constructor(x?: number, y?: number, rx?: number, ry?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
|
|
143
161
|
getDivisions(divisions?: number): number;
|
|
144
162
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
145
|
-
|
|
163
|
+
getCommands(): PathCommand[];
|
|
146
164
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
147
165
|
copy(source: EllipseCurve): this;
|
|
148
166
|
}
|
|
@@ -160,7 +178,7 @@ declare class HeartCurve extends Curve {
|
|
|
160
178
|
getCurrentLine(value: number): Curve;
|
|
161
179
|
getTangent(value: number): Point2D;
|
|
162
180
|
getNormal(value: number): Point2D;
|
|
163
|
-
|
|
181
|
+
getCommands(): PathCommand[];
|
|
164
182
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
165
183
|
}
|
|
166
184
|
|
|
@@ -173,7 +191,11 @@ declare class LineCurve extends Curve {
|
|
|
173
191
|
getPointAt(u: number, output?: Point2D): Point2D;
|
|
174
192
|
getTangent(t: number, output?: Point2D): Point2D;
|
|
175
193
|
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
176
|
-
|
|
194
|
+
getCommands(): PathCommand[];
|
|
195
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
196
|
+
min: Point2D;
|
|
197
|
+
max: Point2D;
|
|
198
|
+
};
|
|
177
199
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
178
200
|
copy(source: LineCurve): this;
|
|
179
201
|
}
|
|
@@ -194,7 +216,11 @@ declare class PloygonCurve extends Curve {
|
|
|
194
216
|
getCurrentLine(value: number): LineCurve;
|
|
195
217
|
getTangent(value: number): Point2D;
|
|
196
218
|
getNormal(value: number): Point2D;
|
|
197
|
-
|
|
219
|
+
getCommands(): PathCommand[];
|
|
220
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
221
|
+
min: Point2D;
|
|
222
|
+
max: Point2D;
|
|
223
|
+
};
|
|
198
224
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
199
225
|
}
|
|
200
226
|
|
|
@@ -204,7 +230,11 @@ declare class QuadraticBezierCurve extends Curve {
|
|
|
204
230
|
v2: Point2D;
|
|
205
231
|
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
|
|
206
232
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
207
|
-
|
|
233
|
+
getCommands(): PathCommand[];
|
|
234
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
235
|
+
min: Point2D;
|
|
236
|
+
max: Point2D;
|
|
237
|
+
};
|
|
208
238
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
209
239
|
copy(source: QuadraticBezierCurve): this;
|
|
210
240
|
}
|
|
@@ -227,7 +257,11 @@ declare class RectangularCurve extends Curve {
|
|
|
227
257
|
getCurrentLine(t: number): LineCurve;
|
|
228
258
|
getTangent(t: number): Point2D;
|
|
229
259
|
getNormal(value: number): Point2D;
|
|
230
|
-
|
|
260
|
+
getCommands(): PathCommand[];
|
|
261
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
262
|
+
min: Point2D;
|
|
263
|
+
max: Point2D;
|
|
264
|
+
};
|
|
231
265
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
232
266
|
}
|
|
233
267
|
|
|
@@ -236,7 +270,7 @@ declare class SplineCurve extends Curve {
|
|
|
236
270
|
constructor(points?: Point2D[]);
|
|
237
271
|
getDivisions(divisions?: number): number;
|
|
238
272
|
getPoint(t: number, output?: Point2D): Point2D;
|
|
239
|
-
|
|
273
|
+
getCommands(): PathCommand[];
|
|
240
274
|
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
241
275
|
copy(source: SplineCurve): this;
|
|
242
276
|
}
|
|
@@ -247,14 +281,31 @@ declare class SplineCurve extends Curve {
|
|
|
247
281
|
declare class Path2D {
|
|
248
282
|
currentPath: CurvePath;
|
|
249
283
|
paths: CurvePath[];
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
lineTo(x: number, y: number): this;
|
|
284
|
+
addPath(path: Path2D): this;
|
|
285
|
+
closePath(): this;
|
|
253
286
|
moveTo(x: number, y: number): this;
|
|
287
|
+
lineTo(x: number, y: number): this;
|
|
288
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
254
289
|
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
290
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
291
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
292
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise: number): this;
|
|
255
293
|
rect(x: number, y: number, w: number, h: number): this;
|
|
256
294
|
splineThru(points: Point2D[]): this;
|
|
257
|
-
|
|
295
|
+
getMinMax(min?: Point2D, max?: Point2D): {
|
|
296
|
+
min: Point2D;
|
|
297
|
+
max: Point2D;
|
|
298
|
+
};
|
|
299
|
+
getCommands(): PathCommand[];
|
|
300
|
+
getData(): string;
|
|
301
|
+
getBoundingBox(): {
|
|
302
|
+
x: number;
|
|
303
|
+
y: number;
|
|
304
|
+
width: number;
|
|
305
|
+
height: number;
|
|
306
|
+
};
|
|
307
|
+
getSvgString(): string;
|
|
308
|
+
getSvgDataUri(): string;
|
|
258
309
|
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
259
310
|
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
260
311
|
fillTo(ctx: CanvasRenderingContext2D): void;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(g,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(g=typeof globalThis<"u"?globalThis:g||self,h(g.modernPath2d={}))})(this,function(g){"use strict";var j=Object.defineProperty;var H=(g,h,v)=>h in g?j(g,h,{enumerable:!0,configurable:!0,writable:!0,value:v}):g[h]=v;var p=(g,h,v)=>H(g,typeof h!="symbol"?h+"":h,v);class h{constructor(s=0,t=0){this.x=s,this.y=t}set(s,t){return this.x=s,this.y=t,this}add(s){return this.x+=s.x,this.y+=s.y,this}sub(s){return this.x-=s.x,this.y-=s.y,this}distanceTo(s){return Math.sqrt(this.distanceToSquared(s))}distanceToSquared(s){const t=this.x-s.x,e=this.y-s.y;return t*t+e*e}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}multiplyScalar(s){return this.x*=s,this.y*=s,this}divideScalar(s){return this.multiplyScalar(1/s)}subVectors(s,t){return this.x=s.x-t.x,this.y=s.y-t.y,this}normalize(){return this.divideScalar(this.length()||1)}lerpVectors(s,t,e){return this.x=s.x+(t.x-s.x)*e,this.y=s.y+(t.y-s.y)*e,this}equals(s){return this.x===s.x&&this.y===s.y}copy(s){return this.x=s.x,this.y=s.y,this}clone(){return new h(this.x,this.y)}}class v{constructor(){p(this,"arcLengthDivisions",200);p(this,"_cacheArcLengths");p(this,"_needsUpdate",!1)}getDivisions(s){return s}getPointAt(s,t=new h){return this.getPoint(this.getUtoTmapping(s),t)}getPoints(s=5){const t=[];for(let e=0;e<=s;e++)t.push(this.getPoint(e/s));return t}getSpacedPoints(s=5){const t=[];for(let e=0;e<=s;e++)t.push(this.getPointAt(e/s));return t}getLength(){const s=this.getLengths();return s[s.length-1]}getLengths(s=this.arcLengthDivisions){if(this._cacheArcLengths&&this._cacheArcLengths.length===s+1&&!this._needsUpdate)return this._cacheArcLengths;this._needsUpdate=!1;const t=[];let e,n=this.getPoint(0),i=0;t.push(0);for(let r=1;r<=s;r++)e=this.getPoint(r/s),i+=e.distanceTo(n),t.push(i),n=e;return this._cacheArcLengths=t,t}updateArcLengths(){this._needsUpdate=!0,this.getLengths()}getUtoTmapping(s,t){const e=this.getLengths();let n=0;const i=e.length;let r;t?r=t:r=s*e[i-1];let o=0,a=i-1,u;for(;o<=a;)if(n=Math.floor(o+(a-o)/2),u=e[n]-r,u<0)o=n+1;else if(u>0)a=n-1;else{a=n;break}if(n=a,e[n]===r)return n/(i-1);const l=e[n],P=e[n+1]-l,w=(r-l)/P;return(n+w)/(i-1)}getTangent(s,t=new h){let n=s-1e-4,i=s+1e-4;return n<0&&(n=0),i>1&&(i=1),t.copy(this.getPoint(i)).sub(this.getPoint(n)).normalize()}getTangentAt(s,t=new h){return this.getTangent(this.getUtoTmapping(s),t)}clone(){return new this.constructor().copy(this)}copy(s){return this.arcLengthDivisions=s.arcLengthDivisions,this}}class f extends v{constructor(s,t,e=0,n=Math.PI*2){super(),this.center=s,this.radius=t,this.start=e,this.end=n}getPole(s,t){s.x=Math.min(s.x,this.center.x-this.radius),s.y=Math.min(s.y,this.center.y-this.radius),t.x=Math.max(t.x,this.center.x+this.radius),t.y=Math.max(t.y,this.center.y+this.radius)}getPoint(s){const{radius:t,center:e}=this;return e.clone().add(this.getNormal(s).clone().multiplyScalar(t))}getTangent(s){const{x:t,y:e}=this.getNormal(s);return new h(-e,t)}getNormal(s){const{start:t,end:e}=this,n=s*(e-t)+t-.5*Math.PI;return new h(Math.cos(n),Math.sin(n))}toPathCommands(){return[]}drawTo(s){}}function x(c,s,t,e,n){const i=(e-s)*.5,r=(n-t)*.5,o=c*c,a=c*o;return(2*t-2*e+i+r)*a+(-3*t+3*e-2*i-r)*o+i*c+t}function S(c,s){const t=1-c;return t*t*s}function q(c,s){return 2*(1-c)*c*s}function B(c,s){return c*c*s}function m(c,s,t,e){return S(c,s)+q(c,t)+B(c,e)}function k(c,s){const t=1-c;return t*t*t*s}function D(c,s){const t=1-c;return 3*t*t*c*s}function E(c,s){return 3*(1-c)*c*c*s}function N(c,s){return c*c*c*s}function T(c,s,t,e,n){return k(c,s)+D(c,t)+E(c,e)+N(c,n)}class M extends v{constructor(s=new h,t=new h,e=new h,n=new h){super(),this.v0=s,this.v1=t,this.v2=e,this.v3=n}getPoint(s,t=new h){const{v0:e,v1:n,v2:i,v3:r}=this;return t.set(T(s,e.x,n.x,i.x,r.x),T(s,e.y,n.y,i.y,r.y)),t}toPathCommands(){return[]}drawTo(s){const{v0:t,v1:e,v2:n,v3:i}=this;s.moveTo(t.x,t.y),s.bezierCurveTo(e.x,e.y,n.x,n.y,i.x,i.y)}copy(s){return super.copy(s),this.v0.copy(s.v0),this.v1.copy(s.v1),this.v2.copy(s.v2),this.v3.copy(s.v3),this}}class L extends v{constructor(s=0,t=0,e=1,n=1,i=0,r=Math.PI*2,o=!1,a=0){super(),this.x=s,this.y=t,this.rx=e,this.ry=n,this.startAngle=i,this.endAngle=r,this.clockwise=o,this.rotation=a}getDivisions(s=12){return s*2}getPoint(s,t=new h){const e=Math.PI*2;let n=this.endAngle-this.startAngle;const i=Math.abs(n)<Number.EPSILON;for(;n<0;)n+=e;for(;n>e;)n-=e;n<Number.EPSILON&&(i?n=0:n=e),this.clockwise&&!i&&(n===e?n=-e:n=n-e);const r=this.startAngle+s*n;let o=this.x+this.rx*Math.cos(r),a=this.y+this.ry*Math.sin(r);if(this.rotation!==0){const u=Math.cos(this.rotation),l=Math.sin(this.rotation),d=o-this.x,P=a-this.y;o=d*u-P*l+this.x,a=d*l+P*u+this.y}return t.set(o,a)}toPathCommands(){const{x:s,y:t,rx:e,ry:n,startAngle:i,endAngle:r,clockwise:o}=this,a=s+e*Math.cos(i),u=t+n*Math.sin(i),l=s+e*Math.cos(r),d=t+n*Math.sin(r),P=(r-i)%(2*Math.PI)>Math.PI?1:0;return[{type:"M",x:a,y:u},{type:"A",rx:e,ry:n,xAxisRotation:0,largeArcFlag:P,sweepFlag:o?0:1,x:l,y:d}]}drawTo(s){const{x:t,y:e,rx:n,ry:i,startAngle:r}=this,o=t+n*Math.cos(r),a=e+i*Math.sin(r);s.moveTo(o,a),s.arc(this.x,this.y,this.rx,this.startAngle,this.endAngle,!this.clockwise)}copy(s){return super.copy(s),this.x=s.x,this.y=s.y,this.rx=s.rx,this.ry=s.ry,this.startAngle=s.startAngle,this.endAngle=s.endAngle,this.clockwise=s.clockwise,this.rotation=s.rotation,this}}class y extends v{constructor(s=new h,t=new h){super(),this.v1=s,this.v2=t}getDivisions(){return 1}getPoint(s,t=new h){return s===1?t.copy(this.v2):(t.copy(this.v2).sub(this.v1),t.multiplyScalar(s).add(this.v1)),t}getPointAt(s,t=new h){return this.getPoint(s,t)}getTangent(s,t=new h){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(s,t=new h){return this.getTangent(s,t)}toPathCommands(){return[{type:"M",x:this.v1.x,y:this.v1.y},{type:"L",x:this.v2.x,y:this.v2.y}]}drawTo(s){const{v1:t,v2:e}=this;s.moveTo(t.x,t.y),s.lineTo(e.x,e.y)}copy(s){return super.copy(s),this.v1.copy(s.v1),this.v2.copy(s.v2),this}}class U extends v{constructor(t,e,n=0,i=1){super();p(this,"curves");p(this,"pointT",0);this.center=t,this.size=e,this.start=n,this.end=i;const{x:r,y:o}=this.center,a=new h(r+.5*this.size,o-.5*this.size),u=new h(r-.5*this.size,o-.5*this.size),l=new h(r,o+.5*this.size),d=new f(a,Math.SQRT1_2*this.size,-.25*Math.PI,.75*Math.PI),P=new f(u,Math.SQRT1_2*this.size,-.75*Math.PI,.25*Math.PI),w=new f(l,.5*Math.SQRT1_2*this.size,.75*Math.PI,1.25*Math.PI),I=new h(r,o+this.size),R=new h(r+this.size,o),V=new h().lerpVectors(R,I,.75),_=new h(r-this.size,o),X=new h().lerpVectors(_,I,.75),Y=new y(R,V),O=new y(X,_);this.curves=[d,Y,w,O,P]}getPoint(t){return this.getCurrentLine(t).getPoint(this.pointT)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let e=(t*(this.end-this.start)+this.start)%1;e<0&&(e+=1),e*=9*Math.PI/8+1.5;let n;const i=.5*Math.PI;return e<i?(n=0,this.pointT=e/i):e<i+.75?(n=1,this.pointT=(e-i)/.75):e<5*Math.PI/8+.75?(n=2,this.pointT=(e-i-.75)/(Math.PI/8)):e<5*Math.PI/8+1.5?(n=3,this.pointT=(e-5*Math.PI/8-.75)/.75):(n=4,this.pointT=(e-5*Math.PI/8-1.5)/i),this.curves[n]}getTangent(t){return this.getCurrentLine(t).getTangent(this.pointT).normalize()}getNormal(t){const e=this.getCurrentLine(t);return new h(e.v2.y-e.v1.y,-(e.v2.x-e.v1.x)).normalize()}toPathCommands(){return this.curves.flatMap(t=>t.toPathCommands())}drawTo(t){this.curves.forEach(e=>e.drawTo(t))}}class F extends v{constructor(t,e=0,n=0,i=0,r=1){super();p(this,"curves",[]);p(this,"points",[]);this.center=t,this.radius=e,this.num=n,this.start=i,this.end=r;for(let o=0;o<this.num;o++){let a=o*2*Math.PI/this.num;a-=.5*Math.PI;const u=new h(this.radius*Math.cos(a),this.radius*Math.sin(a));u.add(this.center),this.points.push(u)}for(let o=0;o<this.num;o++)this.curves.push(new y(this.points[o],this.points[(o+1)%this.num]))}getPoint(t){return this.getCurrentLine(t),this.currentLine.getPoint(this.pointK)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let e=(t*(this.end-this.start)+this.start)%1;e<0&&(e+=1);const n=e*this.num,i=Math.floor(n);return this.pointK=n-i,this.currentLine=this.curves[i],this.currentLine}getTangent(t){return this.getCurrentLine(t).getTangent(0).normalize()}getNormal(t){const e=this.getCurrentLine(t);return new h(e.v2.y-e.v1.y,-(e.v2.x-e.v1.x)).normalize()}toPathCommands(){return this.curves.flatMap(t=>t.toPathCommands())}drawTo(t){this.curves.forEach(e=>e.drawTo(t))}}class z extends v{constructor(s=new h,t=new h,e=new h){super(),this.v0=s,this.v1=t,this.v2=e}getPoint(s,t=new h){const{v0:e,v1:n,v2:i}=this;return t.set(m(s,e.x,n.x,i.x),m(s,e.y,n.y,i.y)),t}toPathCommands(){return[]}drawTo(s){const{v0:t,v1:e,v2:n}=this;s.moveTo(t.x,t.y),s.quadraticCurveTo(e.x,e.y,n.x,n.y)}copy(s){return super.copy(s),this.v0.copy(s.v0),this.v1.copy(s.v1),this.v2.copy(s.v2),this}}class A extends v{constructor(t,e,n=1,i=0,r=1){super();p(this,"curves",[]);p(this,"pointT",0);this.center=t,this.rx=e,this.aspectRatio=n,this.start=i,this.end=r;const{x:o,y:a}=this.center,u=this.rx,l=this.rx/this.aspectRatio,d=[new h(o-u,a-l),new h(o+u,a-l),new h(o+u,a+l),new h(o-u,a+l)];for(let P=0;P<4;P++)this.curves.push(new y(d[P],d[(P+1)%4]))}get x(){return this.center.x-this.rx}get y(){return this.center.y-this.rx/this.aspectRatio}get width(){return this.rx*2}get height(){return this.rx/this.aspectRatio*2}getPoint(t){return this.getCurrentLine(t).getPoint(this.pointT)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let e=(t*(this.end-this.start)+this.start)%1;e<0&&(e+=1),e*=(1+this.aspectRatio)*2;let n;return e<this.aspectRatio?(n=0,this.pointT=e/this.aspectRatio):e<this.aspectRatio+1?(n=1,this.pointT=(e-this.aspectRatio)/1):e<2*this.aspectRatio+1?(n=2,this.pointT=(e-this.aspectRatio-1)/this.aspectRatio):(n=3,this.pointT=(e-2*this.aspectRatio-1)/1),this.curves[n]}getTangent(t){return this.getCurrentLine(t).getTangent(0).normalize()}getNormal(t){const{v1:e,v2:n}=this.getCurrentLine(t);return new h(n.y-e.y,-(n.x-e.x)).normalize()}toPathCommands(){return this.curves.flatMap(t=>t.toPathCommands())}drawTo(t){this.curves.forEach(e=>e.drawTo(t))}}class b extends v{constructor(s=[]){super(),this.points=s}getDivisions(s=12){return s*this.points.length}getPoint(s,t=new h){const{points:e}=this,n=(e.length-1)*s,i=Math.floor(n),r=n-i,o=e[i===0?i:i-1],a=e[i],u=e[i>e.length-2?e.length-1:i+1],l=e[i>e.length-3?e.length-1:i+2];return t.set(x(r,o.x,a.x,u.x,l.x),x(r,o.y,a.y,u.y,l.y)),t}toPathCommands(){return[]}drawTo(s){}copy(s){super.copy(s),this.points=[];for(let t=0,e=s.points.length;t<e;t++){const n=s.points[t];this.points.push(n.clone())}return this}}class C extends v{constructor(t){super();p(this,"curves",[]);p(this,"currentPoint",new h);p(this,"autoClose",!1);p(this,"_cacheLengths",[]);t&&this.setFromPoints(t)}addCurve(t){return this.curves.push(t),this}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);return t.equals(e)||this.curves.push(new y(e,t)),this}getPoint(t,e=new h){const n=t*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=n){const o=i[r]-n,a=this.curves[r],u=a.getLength();return a.getPointAt(u===0?0:1-o/u,e)}r++}return e}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){super.updateArcLengths(),this._cacheLengths=[],this.getCurveLengths()}getCurveLengths(){if(this._cacheLengths.length===this.curves.length)return this._cacheLengths;const t=[];let e=0;for(let n=0,i=this.curves.length;n<i;n++)e+=this.curves[n].getLength(),t.push(e);return this._cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let n;for(let i=0,r=this.curves;i<r.length;i++){const o=r[i],a=o.getPoints(o.getDivisions(t));for(let u=0;u<a.length;u++){const l=a[u];n&&n.equals(l)||(e.push(l),n=l)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,n=t.length;e<n;e++)this.lineTo(t[e].x,t[e].y);return this}bezierCurveTo(t,e,n,i,r,o){return this.curves.push(new M(this.currentPoint.clone(),new h(t,e),new h(n,i),new h(r,o))),this.currentPoint.set(r,o),this}lineTo(t,e){const n=new y(this.currentPoint.clone(),new h(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}moveTo(t,e){return this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,i){return this.curves.push(new z(this.currentPoint.clone(),new h(t,e),new h(n,i))),this.currentPoint.set(n,i),this}rect(t,e,n,i){return this.curves.push(new A(new h(t+n/2,e+i/2),n/2,n/i)),this.currentPoint.set(t,e),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t);return this.curves.push(new b(e)),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,n,i,r,o=!1){const a=this.currentPoint;return this.absarc(t+a.x,e+a.y,n,i,r,o),this}absarc(t,e,n,i,r,o=!1){return this.absellipse(t,e,n,n,i,r,o),this}ellipse(t,e,n,i,r,o,a=!1,u=0){const l=this.currentPoint;return this.absellipse(t+l.x,e+l.y,n,i,r,o,a,u),this}absellipse(t,e,n,i,r,o,a=!1,u=0){const l=new L(t,e,n,i,r,o,a,u);if(this.curves.length>0){const d=l.getPoint(0);d.equals(this.currentPoint)||this.lineTo(d.x,d.y)}return this.curves.push(l),this.currentPoint.copy(l.getPoint(1)),this}toPathCommands(){return this.curves.flatMap(t=>t.toPathCommands())}drawTo(t){this.curves.forEach(e=>e.drawTo(t))}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const i=t.curves[e];this.curves.push(i.clone())}return this.autoClose=t.autoClose,this.currentPoint.copy(t.currentPoint),this}}class Q{constructor(){p(this,"currentPath",new C);p(this,"paths",[this.currentPath])}arc(s,t,e,n,i,r){return this.currentPath.absarc(s,t,e,n,i,!r),this}bezierCurveTo(s,t,e,n,i,r){return this.currentPath.bezierCurveTo(s,t,e,n,i,r),this}lineTo(s,t){return this.currentPath.lineTo(s,t),this}moveTo(s,t){return this.currentPath=new C,this.paths.push(this.currentPath),this.currentPath.moveTo(s,t),this}quadraticCurveTo(s,t,e,n){return this.currentPath.quadraticCurveTo(s,t,e,n),this}rect(s,t,e,n){return this.currentPath.rect(s,t,e,n),this}splineThru(s){return this.currentPath.splineThru(s),this}toPathCommands(){return this.paths.flatMap(s=>s.curves.flatMap(t=>t.toPathCommands()))}drawTo(s){this.paths.forEach(t=>{t.curves.forEach(e=>{e.drawTo(s)})})}strokeTo(s){this.drawTo(s),s.stroke()}fillTo(s){this.drawTo(s),s.fill()}}g.CircleCurve=f,g.CubicBezierCurve=M,g.Curve=v,g.CurvePath=C,g.EllipseCurve=L,g.HeartCurve=U,g.LineCurve=y,g.Path2D=Q,g.PloygonCurve=F,g.Point2D=h,g.QuadraticBezierCurve=z,g.RectangularCurve=A,g.SplineCurve=b,g.catmullRom=x,g.cubicBezier=T,g.quadraticBezier=m,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(g,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(g=typeof globalThis<"u"?globalThis:g||self,r(g.modernPath2d={}))})(this,function(g){"use strict";var O=Object.defineProperty;var H=(g,r,x)=>r in g?O(g,r,{enumerable:!0,configurable:!0,writable:!0,value:x}):g[r]=x;var p=(g,r,x)=>H(g,typeof r!="symbol"?r+"":r,x);class r{constructor(e=0,t=0){this.x=e,this.y=t}static get MAX(){return new r(1/0,1/0)}static get MIN(){return new r(-1/0,-1/0)}set(e,t){return this.x=e,this.y=t,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,s=this.y-e.y;return t*t+s*s}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(1/e)}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}normalize(){return this.divideScalar(this.length()||1)}lerpVectors(e,t,s){return this.x=e.x+(t.x-e.x)*s,this.y=e.y+(t.y-e.y)*s,this}equals(e){return this.x===e.x&&this.y===e.y}copy(e){return this.x=e.x,this.y=e.y,this}clone(){return new r(this.x,this.y)}}class x{constructor(){p(this,"arcLengthDivisions",200);p(this,"_cacheArcLengths");p(this,"_needsUpdate",!1)}getMinMax(e=r.MAX,t=r.MIN){return{min:e,max:t}}getDivisions(e){return e}getPointAt(e,t=new r){return this.getPoint(this.getUtoTmapping(e),t)}getPoints(e=5){const t=[];for(let s=0;s<=e;s++)t.push(this.getPoint(s/e));return t}getSpacedPoints(e=5){const t=[];for(let s=0;s<=e;s++)t.push(this.getPointAt(s/e));return t}getLength(){const e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this._cacheArcLengths&&this._cacheArcLengths.length===e+1&&!this._needsUpdate)return this._cacheArcLengths;this._needsUpdate=!1;const t=[];let s,n=this.getPoint(0),i=0;t.push(0);for(let h=1;h<=e;h++)s=this.getPoint(h/e),i+=s.distanceTo(n),t.push(i),n=s;return this._cacheArcLengths=t,t}updateArcLengths(){this._needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t){const s=this.getLengths();let n=0;const i=s.length;let h;t?h=t:h=e*s[i-1];let o=0,c=i-1,u;for(;o<=c;)if(n=Math.floor(o+(c-o)/2),u=s[n]-h,u<0)o=n+1;else if(u>0)c=n-1;else{c=n;break}if(n=c,s[n]===h)return n/(i-1);const l=s[n],v=s[n+1]-l,d=(h-l)/v;return(n+d)/(i-1)}getTangent(e,t=new r){let n=e-1e-4,i=e+1e-4;return n<0&&(n=0),i>1&&(i=1),t.copy(this.getPoint(i)).sub(this.getPoint(n)).normalize()}getTangentAt(e,t=new r){return this.getTangent(this.getUtoTmapping(e),t)}getData(){return this.getCommands().map(e=>{switch(e.type){case"M":return`M ${e.x} ${e.y}`;case"L":return`L ${e.x} ${e.y}`;case"C":return`C ${e.x1} ${e.y1} ${e.x2} ${e.y2} ${e.x} ${e.y}`;case"Q":return`Q ${e.x1} ${e.y1} ${e.x} ${e.y}`;case"A":return`A ${e.rx} ${e.ry} ${e.xAxisRotation} ${e.largeArcFlag} ${e.sweepFlag} ${e.x} ${e.y}`;case"Z":return"Z";default:return""}}).join(" ")}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}}class L extends x{constructor(e,t,s=0,n=Math.PI*2){super(),this.center=e,this.radius=t,this.start=s,this.end=n}getMinMax(e=r.MAX,t=r.MIN){return e.x=Math.min(e.x,this.center.x-this.radius),e.y=Math.min(e.y,this.center.y-this.radius),t.x=Math.max(t.x,this.center.x+this.radius),t.y=Math.max(t.y,this.center.y+this.radius),{min:e,max:t}}getPoint(e){const{radius:t,center:s}=this;return s.clone().add(this.getNormal(e).clone().multiplyScalar(t))}getTangent(e){const{x:t,y:s}=this.getNormal(e);return new r(-s,t)}getNormal(e){const{start:t,end:s}=this,n=e*(s-t)+t-.5*Math.PI;return new r(Math.cos(n),Math.sin(n))}getCommands(){return[]}drawTo(e){}}function m(a,e,t,s,n){const i=(s-e)*.5,h=(n-t)*.5,o=a*a,c=a*o;return(2*t-2*s+i+h)*c+(-3*t+3*s-2*i-h)*o+i*a+t}function D(a,e){const t=1-a;return t*t*e}function X(a,e){return 2*(1-a)*a*e}function E(a,e){return a*a*e}function I(a,e,t,s){return D(a,e)+X(a,t)+E(a,s)}function k(a,e){const t=1-a;return t*t*t*e}function F(a,e){const t=1-a;return 3*t*t*a*e}function Q(a,e){return 3*(1-a)*a*a*e}function U(a,e){return a*a*a*e}function z(a,e,t,s,n){return k(a,e)+F(a,t)+Q(a,s)+U(a,n)}class R extends x{constructor(e=new r,t=new r,s=new r,n=new r){super(),this.v0=e,this.v1=t,this.v2=s,this.v3=n}getPoint(e,t=new r){const{v0:s,v1:n,v2:i,v3:h}=this;return t.set(z(e,s.x,n.x,i.x,h.x),z(e,s.y,n.y,i.y,h.y)),t}getMinMax(e=r.MAX,t=r.MIN){const{v0:s,v1:n,v2:i,v3:h}=this;return e.x=Math.min(e.x,s.x,n.x,i.x,h.x),e.y=Math.min(e.y,s.y,n.y,i.y,h.y),t.x=Math.max(t.x,s.x,n.x,i.x,h.x),t.y=Math.max(t.y,s.y,n.y,i.y,h.y),{min:e,max:t}}getCommands(){const{v0:e,v1:t,v2:s,v3:n}=this;return[{type:"M",x:e.x,y:e.y},{type:"C",x1:t.x,y1:t.y,x2:s.x,y2:s.y,x:n.x,y:n.y}]}drawTo(e){const{v0:t,v1:s,v2:n,v3:i}=this;e.moveTo(t.x,t.y),e.bezierCurveTo(s.x,s.y,n.x,n.y,i.x,i.y)}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}}class S extends x{constructor(e=0,t=0,s=1,n=1,i=0,h=Math.PI*2,o=!1,c=0){super(),this.x=e,this.y=t,this.rx=s,this.ry=n,this.startAngle=i,this.endAngle=h,this.clockwise=o,this.rotation=c}getDivisions(e=12){return e*2}getPoint(e,t=new r){const s=Math.PI*2;let n=this.endAngle-this.startAngle;const i=Math.abs(n)<Number.EPSILON;for(;n<0;)n+=s;for(;n>s;)n-=s;n<Number.EPSILON&&(i?n=0:n=s),this.clockwise&&!i&&(n===s?n=-s:n=n-s);const h=this.startAngle+e*n;let o=this.x+this.rx*Math.cos(h),c=this.y+this.ry*Math.sin(h);if(this.rotation!==0){const u=Math.cos(this.rotation),l=Math.sin(this.rotation),y=o-this.x,v=c-this.y;o=y*u-v*l+this.x,c=y*l+v*u+this.y}return t.set(o,c)}getCommands(){const{x:e,y:t,rx:s,ry:n,startAngle:i,endAngle:h,clockwise:o}=this,c=!o,u=e+s*Math.cos(i),l=t+n*Math.sin(i),y=e+s*Math.cos(h),v=t+n*Math.sin(h),d=Math.abs(i-h),P=d>Math.PI?1:0,M=c?0:1,w=e+s*Math.cos(i+(h-i)/2),T=t+n*Math.sin(i+(h-i)/2);return d>=2*Math.PI?[{type:"M",x:u,y:l},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:1,sweepFlag:M,x:w,y:T},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:1,sweepFlag:M,x:u,y:l}]:[{type:"M",x:u,y:l},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:P,sweepFlag:M,x:y,y:v}]}drawTo(e){const{x:t,y:s,rx:n,ry:i,startAngle:h}=this,o=t+n*Math.cos(h),c=s+i*Math.sin(h);e.moveTo(o,c),e.arc(this.x,this.y,this.rx,this.startAngle,this.endAngle,!this.clockwise)}copy(e){return super.copy(e),this.x=e.x,this.y=e.y,this.rx=e.rx,this.ry=e.ry,this.startAngle=e.startAngle,this.endAngle=e.endAngle,this.clockwise=e.clockwise,this.rotation=e.rotation,this}}class f extends x{constructor(e=new r,t=new r){super(),this.v1=e,this.v2=t}getDivisions(){return 1}getPoint(e,t=new r){return e===1?t.copy(this.v2):(t.copy(this.v2).sub(this.v1),t.multiplyScalar(e).add(this.v1)),t}getPointAt(e,t=new r){return this.getPoint(e,t)}getTangent(e,t=new r){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t=new r){return this.getTangent(e,t)}getCommands(){const{v1:e,v2:t}=this;return[{type:"M",x:e.x,y:e.y},{type:"L",x:t.x,y:t.y}]}getMinMax(e=r.MAX,t=r.MIN){const{v1:s,v2:n}=this;return e.x=Math.min(e.x,s.x,n.x),e.y=Math.min(e.y,s.y,n.y),t.x=Math.max(t.x,s.x,n.x),t.y=Math.max(t.y,s.y,n.y),{min:e,max:t}}drawTo(e){const{v1:t,v2:s}=this;e.moveTo(t.x,t.y),e.lineTo(s.x,s.y)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}}class V extends x{constructor(t,s,n=0,i=1){super();p(this,"curves");p(this,"pointT",0);this.center=t,this.size=s,this.start=n,this.end=i;const{x:h,y:o}=this.center,c=new r(h+.5*this.size,o-.5*this.size),u=new r(h-.5*this.size,o-.5*this.size),l=new r(h,o+.5*this.size),y=new L(c,Math.SQRT1_2*this.size,-.25*Math.PI,.75*Math.PI),v=new L(u,Math.SQRT1_2*this.size,-.75*Math.PI,.25*Math.PI),d=new L(l,.5*Math.SQRT1_2*this.size,.75*Math.PI,1.25*Math.PI),P=new r(h,o+this.size),M=new r(h+this.size,o),w=new r().lerpVectors(M,P,.75),T=new r(h-this.size,o),$=new r().lerpVectors(T,P,.75),C=new f(M,w),_=new f($,T);this.curves=[y,C,d,_,v]}getPoint(t){return this.getCurrentLine(t).getPoint(this.pointT)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let s=(t*(this.end-this.start)+this.start)%1;s<0&&(s+=1),s*=9*Math.PI/8+1.5;let n;const i=.5*Math.PI;return s<i?(n=0,this.pointT=s/i):s<i+.75?(n=1,this.pointT=(s-i)/.75):s<5*Math.PI/8+.75?(n=2,this.pointT=(s-i-.75)/(Math.PI/8)):s<5*Math.PI/8+1.5?(n=3,this.pointT=(s-5*Math.PI/8-.75)/.75):(n=4,this.pointT=(s-5*Math.PI/8-1.5)/i),this.curves[n]}getTangent(t){return this.getCurrentLine(t).getTangent(this.pointT).normalize()}getNormal(t){const s=this.getCurrentLine(t);return new r(s.v2.y-s.v1.y,-(s.v2.x-s.v1.x)).normalize()}getCommands(){return this.curves.flatMap(t=>t.getCommands())}drawTo(t){this.curves.forEach(s=>s.drawTo(t))}}class Y extends x{constructor(t,s=0,n=0,i=0,h=1){super();p(this,"curves",[]);p(this,"points",[]);this.center=t,this.radius=s,this.num=n,this.start=i,this.end=h;for(let o=0;o<this.num;o++){let c=o*2*Math.PI/this.num;c-=.5*Math.PI;const u=new r(this.radius*Math.cos(c),this.radius*Math.sin(c));u.add(this.center),this.points.push(u)}for(let o=0;o<this.num;o++)this.curves.push(new f(this.points[o],this.points[(o+1)%this.num]))}getPoint(t){return this.getCurrentLine(t),this.currentLine.getPoint(this.pointK)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let s=(t*(this.end-this.start)+this.start)%1;s<0&&(s+=1);const n=s*this.num,i=Math.floor(n);return this.pointK=n-i,this.currentLine=this.curves[i],this.currentLine}getTangent(t){return this.getCurrentLine(t).getTangent(0).normalize()}getNormal(t){const s=this.getCurrentLine(t);return new r(s.v2.y-s.v1.y,-(s.v2.x-s.v1.x)).normalize()}getCommands(){return this.curves.flatMap(t=>t.getCommands())}getMinMax(t=r.MAX,s=r.MIN){return this.curves.forEach(n=>n.getMinMax(t,s)),{min:t,max:s}}drawTo(t){this.curves.forEach(s=>s.drawTo(t))}}class B extends x{constructor(e=new r,t=new r,s=new r){super(),this.v0=e,this.v1=t,this.v2=s}getPoint(e,t=new r){const{v0:s,v1:n,v2:i}=this;return t.set(I(e,s.x,n.x,i.x),I(e,s.y,n.y,i.y)),t}getCommands(){const{v0:e,v1:t,v2:s}=this;return[{type:"M",x:e.x,y:e.y},{type:"Q",x1:t.x,y1:t.y,x:s.x,y:s.y}]}getMinMax(e=r.MAX,t=r.MIN){const{v0:s,v1:n,v2:i}=this,h=.5*(s.x+n.x),o=.5*(s.y+n.y),c=.5*(s.x+i.x),u=.5*(s.y+i.y);return e.x=Math.min(e.x,s.x,i.x,h,c),e.y=Math.min(e.y,s.y,i.y,o,u),t.x=Math.max(t.x,s.x,i.x,h,c),t.y=Math.max(t.y,s.y,i.y,o,u),{min:e,max:t}}drawTo(e){const{v0:t,v1:s,v2:n}=this;e.moveTo(t.x,t.y),e.quadraticCurveTo(s.x,s.y,n.x,n.y)}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}}class q extends x{constructor(t,s,n=1,i=0,h=1){super();p(this,"curves",[]);p(this,"pointT",0);this.center=t,this.rx=s,this.aspectRatio=n,this.start=i,this.end=h;const{x:o,y:c}=this.center,u=this.rx,l=this.rx/this.aspectRatio,y=[new r(o-u,c-l),new r(o+u,c-l),new r(o+u,c+l),new r(o-u,c+l)];for(let v=0;v<4;v++)this.curves.push(new f(y[v],y[(v+1)%4]))}get x(){return this.center.x-this.rx}get y(){return this.center.y-this.rx/this.aspectRatio}get width(){return this.rx*2}get height(){return this.rx/this.aspectRatio*2}getPoint(t){return this.getCurrentLine(t).getPoint(this.pointT)}getPointAt(t){return this.getPoint(t)}getCurrentLine(t){let s=(t*(this.end-this.start)+this.start)%1;s<0&&(s+=1),s*=(1+this.aspectRatio)*2;let n;return s<this.aspectRatio?(n=0,this.pointT=s/this.aspectRatio):s<this.aspectRatio+1?(n=1,this.pointT=(s-this.aspectRatio)/1):s<2*this.aspectRatio+1?(n=2,this.pointT=(s-this.aspectRatio-1)/this.aspectRatio):(n=3,this.pointT=(s-2*this.aspectRatio-1)/1),this.curves[n]}getTangent(t){return this.getCurrentLine(t).getTangent(0).normalize()}getNormal(t){const{v1:s,v2:n}=this.getCurrentLine(t);return new r(n.y-s.y,-(n.x-s.x)).normalize()}getCommands(){return this.curves.flatMap(t=>t.getCommands())}getMinMax(t=r.MAX,s=r.MIN){return this.curves.forEach(n=>n.getMinMax(t,s)),{min:t,max:s}}drawTo(t){this.curves.forEach(s=>s.drawTo(t))}}class N extends x{constructor(e=[]){super(),this.points=e}getDivisions(e=12){return e*this.points.length}getPoint(e,t=new r){const{points:s}=this,n=(s.length-1)*e,i=Math.floor(n),h=n-i,o=s[i===0?i:i-1],c=s[i],u=s[i>s.length-2?s.length-1:i+1],l=s[i>s.length-3?s.length-1:i+2];return t.set(m(h,o.x,c.x,u.x,l.x),m(h,o.y,c.y,u.y,l.y)),t}getCommands(){return[]}drawTo(e){}copy(e){super.copy(e),this.points=[];for(let t=0,s=e.points.length;t<s;t++)this.points.push(e.points[t].clone());return this}}class b extends x{constructor(t){super();p(this,"curves",[]);p(this,"currentPoint",new r);p(this,"autoClose",!1);p(this,"_cacheLengths",[]);t&&this.setFromPoints(t)}addCurve(t){return this.curves.push(t),this}closePath(){const t=this.curves[0].getPoint(0),s=this.curves[this.curves.length-1].getPoint(1);return t.equals(s)||this.curves.push(new f(s,t)),this}getPoint(t,s=new r){const n=t*this.getLength(),i=this.getCurveLengths();let h=0;for(;h<i.length;){if(i[h]>=n){const o=i[h]-n,c=this.curves[h],u=c.getLength();return c.getPointAt(u===0?0:1-o/u,s)}h++}return s}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){super.updateArcLengths(),this._cacheLengths=[],this.getCurveLengths()}getCurveLengths(){if(this._cacheLengths.length===this.curves.length)return this._cacheLengths;const t=[];let s=0;for(let n=0,i=this.curves.length;n<i;n++)s+=this.curves[n].getLength(),t.push(s);return this._cacheLengths=t,t}getSpacedPoints(t=40){const s=[];for(let n=0;n<=t;n++)s.push(this.getPoint(n/t));return this.autoClose&&s.push(s[0]),s}getPoints(t=12){const s=[];let n;for(let i=0,h=this.curves;i<h.length;i++){const o=h[i],c=o.getPoints(o.getDivisions(t));for(let u=0;u<c.length;u++){const l=c[u];n&&n.equals(l)||(s.push(l),n=l)}}return this.autoClose&&s.length>1&&!s[s.length-1].equals(s[0])&&s.push(s[0]),s}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let s=1,n=t.length;s<n;s++)this.lineTo(t[s].x,t[s].y);return this}bezierCurveTo(t,s,n,i,h,o){return this.curves.push(new R(this.currentPoint.clone(),new r(t,s),new r(n,i),new r(h,o))),this.currentPoint.set(h,o),this}lineTo(t,s){const n=new f(this.currentPoint.clone(),new r(t,s));return this.curves.push(n),this.currentPoint.set(t,s),this}moveTo(t,s){return this.currentPoint.set(t,s),this}quadraticCurveTo(t,s,n,i){return this.curves.push(new B(this.currentPoint.clone(),new r(t,s),new r(n,i))),this.currentPoint.set(n,i),this}rect(t,s,n,i){return this.curves.push(new q(new r(t+n/2,s+i/2),n/2,n/i)),this.currentPoint.set(t,s),this}splineThru(t){const s=[this.currentPoint.clone()].concat(t);return this.curves.push(new N(s)),this.currentPoint.copy(t[t.length-1]),this}arc(t,s,n,i,h,o=!1){const c=this.currentPoint;return this.absarc(t+c.x,s+c.y,n,i,h,o),this}absarc(t,s,n,i,h,o=!1){return this.absellipse(t,s,n,n,i,h,o),this}ellipse(t,s,n,i,h,o,c=!1,u=0){const l=this.currentPoint;return this.absellipse(t+l.x,s+l.y,n,i,h,o,c,u),this}absellipse(t,s,n,i,h,o,c=!1,u=0){const l=new S(t,s,n,i,h,o,c,u);if(this.curves.length>0){const y=l.getPoint(0);y.equals(this.currentPoint)||this.lineTo(y.x,y.y)}return this.curves.push(l),this.currentPoint.copy(l.getPoint(1)),this}getCommands(){return this.curves.flatMap(t=>t.getCommands())}getMinMax(t=r.MAX,s=r.MIN){return this.curves.forEach(n=>n.getMinMax(t,s)),{min:t,max:s}}drawTo(t){this.curves.forEach(s=>s.drawTo(t))}copy(t){super.copy(t),this.curves=[];for(let s=0,n=t.curves.length;s<n;s++){const i=t.curves[s];this.curves.push(i.clone())}return this.autoClose=t.autoClose,this.currentPoint.copy(t.currentPoint),this}}class j{constructor(){p(this,"currentPath",new b);p(this,"paths",[this.currentPath])}addPath(e){return this.paths.push(...e.paths.map(t=>t.clone())),this}closePath(){return this.currentPath.closePath(),this}moveTo(e,t){return this.currentPath=new b,this.paths.push(this.currentPath),this.currentPath.moveTo(e,t),this}lineTo(e,t){return this.currentPath.lineTo(e,t),this}bezierCurveTo(e,t,s,n,i,h){return this.currentPath.bezierCurveTo(e,t,s,n,i,h),this}quadraticCurveTo(e,t,s,n){return this.currentPath.quadraticCurveTo(e,t,s,n),this}arc(e,t,s,n,i,h){return this.currentPath.absarc(e,t,s,n,i,!h),this}arcTo(e,t,s,n,i){const h=this.currentPath.currentPoint,o=h.x,c=h.y,u=e-o,l=t-c,y=s-e,v=n-t,d=Math.sqrt(u*u+l*l),P=Math.sqrt(y*y+v*v);if(d<i||P<i)return this.lineTo(s,n),this;const M={x:u/d,y:l/d},w={x:y/P,y:v/P},T=e-M.y*i,$=t+M.x*i,C=Math.atan2(M.y,M.x);let A=Math.atan2(w.y,w.x)-C;return A>Math.PI?A-=2*Math.PI:A<-Math.PI&&(A+=2*Math.PI),this.arc(T,$,i,C,C+A,!1),this.lineTo(s,n),this}ellipse(e,t,s,n,i,h,o,c){return this.currentPath.absellipse(e,t,s,n,h,o,!c,i),this}rect(e,t,s,n){return this.currentPath.rect(e,t,s,n),this}splineThru(e){return this.currentPath.splineThru(e),this}getMinMax(e=new r,t=new r){return this.paths.forEach(s=>s.curves.forEach(n=>n.getMinMax(e,t))),{min:e,max:t}}getCommands(){return this.paths.flatMap(e=>e.curves.flatMap(t=>t.getCommands()))}getData(){return this.paths.map(e=>e.getData()).join(" ")}getBoundingBox(){const e=r.MAX,t=r.MIN;return this.paths.forEach(s=>s.getMinMax(e,t)),{x:e.x,y:e.y,width:t.x-e.x,height:t.y-e.y}}getSvgString(){const{x:e,y:t,width:s,height:n}=this.getBoundingBox();return`<svg viewBox="${e} ${t} ${s} ${n}" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke="currentColor" d="${this.getData()}"></path></svg>`}getSvgDataUri(){return`data:image/svg+xml;base64,${btoa(this.getSvgString())}`}drawTo(e){this.paths.forEach(t=>{t.curves.forEach(s=>{s.drawTo(e)})})}strokeTo(e){this.drawTo(e),e.stroke()}fillTo(e){this.drawTo(e),e.fill()}}g.CircleCurve=L,g.CubicBezierCurve=R,g.Curve=x,g.CurvePath=b,g.EllipseCurve=S,g.HeartCurve=V,g.LineCurve=f,g.Path2D=j,g.PloygonCurve=Y,g.Point2D=r,g.QuadraticBezierCurve=B,g.RectangularCurve=q,g.SplineCurve=N,g.catmullRom=m,g.cubicBezier=z,g.quadraticBezier=I,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|