modern-path2d 0.0.1 → 0.0.3

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.d.ts CHANGED
@@ -1,3 +1,322 @@
1
- declare const one = 1;
1
+ type PathCommand = {
2
+ type: 'M';
3
+ x: number;
4
+ y: number;
5
+ } | {
6
+ type: 'L';
7
+ x: number;
8
+ y: number;
9
+ } | {
10
+ type: 'C';
11
+ x1: number;
12
+ y1: number;
13
+ x2: number;
14
+ y2: number;
15
+ x: number;
16
+ y: number;
17
+ } | {
18
+ type: 'Q';
19
+ x1: number;
20
+ y1: number;
21
+ x: number;
22
+ y: number;
23
+ } | {
24
+ type: 'A';
25
+ rx: number;
26
+ ry: number;
27
+ xAxisRotation: number;
28
+ largeArcFlag: number;
29
+ sweepFlag: number;
30
+ x: number;
31
+ y: number;
32
+ } | {
33
+ type: 'Z';
34
+ };
2
35
 
3
- export { one };
36
+ declare class Point2D {
37
+ x: number;
38
+ y: number;
39
+ static get MAX(): Point2D;
40
+ static get MIN(): Point2D;
41
+ constructor(x?: number, y?: number);
42
+ set(x: number, y: number): this;
43
+ add(point: Point2D): this;
44
+ sub(point: Point2D): this;
45
+ distanceTo(point: Point2D): number;
46
+ distanceToSquared(point: Point2D): number;
47
+ length(): number;
48
+ multiplyScalar(scalar: number): this;
49
+ divideScalar(scalar: number): this;
50
+ subVectors(a: Point2D, b: Point2D): this;
51
+ normalize(): this;
52
+ lerpVectors(v1: Point2D, v2: Point2D, alpha: number): this;
53
+ equals(point: Point2D): boolean;
54
+ copy(point: Point2D): this;
55
+ clone(): Point2D;
56
+ }
57
+
58
+ declare abstract class Curve {
59
+ arcLengthDivisions: number;
60
+ protected _cacheArcLengths?: number[];
61
+ protected _needsUpdate: boolean;
62
+ abstract getPoint(t: number, output?: Point2D): Point2D;
63
+ abstract getPathCommands(): PathCommand[];
64
+ abstract drawTo(ctx: CanvasRenderingContext2D): void;
65
+ getMinMax(min?: Point2D, max?: Point2D): {
66
+ min: Point2D;
67
+ max: Point2D;
68
+ };
69
+ getDivisions(divisions: number): number;
70
+ getPointAt(u: number, output?: Point2D): Point2D;
71
+ getPoints(divisions?: number): Point2D[];
72
+ getSpacedPoints(divisions?: number): Point2D[];
73
+ getLength(): number;
74
+ getLengths(divisions?: number): number[];
75
+ updateArcLengths(): void;
76
+ getUtoTmapping(u: number, distance?: number): number;
77
+ getTangent(t: number, output?: Point2D): Point2D;
78
+ getTangentAt(u: number, output?: Point2D): Point2D;
79
+ getPathData(): string;
80
+ clone(): this;
81
+ copy(source: Curve): this;
82
+ }
83
+
84
+ declare class CurvePath extends Curve {
85
+ curves: Curve[];
86
+ currentPoint: Point2D;
87
+ autoClose: boolean;
88
+ protected _cacheLengths: number[];
89
+ constructor(points?: Point2D[]);
90
+ addCurve(curve: Curve): this;
91
+ closePath(): this;
92
+ getPoint(position: number, output?: Point2D): Point2D;
93
+ getLength(): number;
94
+ updateArcLengths(): void;
95
+ getCurveLengths(): number[];
96
+ getSpacedPoints(divisions?: number): Point2D[];
97
+ getPoints(divisions?: number): Point2D[];
98
+ setFromPoints(points: Point2D[]): this;
99
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
100
+ lineTo(x: number, y: number): this;
101
+ moveTo(x: number, y: number): this;
102
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
103
+ rect(x: number, y: number, w: number, h: number): this;
104
+ splineThru(points: Point2D[]): this;
105
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
106
+ absarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
107
+ ellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
108
+ absellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
109
+ getPathCommands(): PathCommand[];
110
+ getMinMax(min?: Point2D, max?: Point2D): {
111
+ min: Point2D;
112
+ max: Point2D;
113
+ };
114
+ drawTo(ctx: CanvasRenderingContext2D): void;
115
+ copy(source: CurvePath): this;
116
+ }
117
+
118
+ declare class CircleCurve extends Curve {
119
+ center: Point2D;
120
+ radius: number;
121
+ start: number;
122
+ end: number;
123
+ constructor(center: Point2D, radius: number, start?: number, end?: number);
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
+ getPathCommands(): PathCommand[];
132
+ drawTo(_ctx: CanvasRenderingContext2D): void;
133
+ }
134
+
135
+ declare class CubicBezierCurve extends Curve {
136
+ v0: Point2D;
137
+ v1: Point2D;
138
+ v2: Point2D;
139
+ v3: Point2D;
140
+ constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
141
+ getPoint(t: number, output?: Point2D): Point2D;
142
+ getMinMax(min?: Point2D, max?: Point2D): {
143
+ min: Point2D;
144
+ max: Point2D;
145
+ };
146
+ getPathCommands(): PathCommand[];
147
+ drawTo(ctx: CanvasRenderingContext2D): void;
148
+ copy(source: CubicBezierCurve): this;
149
+ }
150
+
151
+ declare class EllipseCurve extends Curve {
152
+ x: number;
153
+ y: number;
154
+ rx: number;
155
+ ry: number;
156
+ startAngle: number;
157
+ endAngle: number;
158
+ clockwise: boolean;
159
+ rotation: number;
160
+ constructor(x?: number, y?: number, rx?: number, ry?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
161
+ getDivisions(divisions?: number): number;
162
+ getPoint(t: number, output?: Point2D): Point2D;
163
+ getPathCommands(): PathCommand[];
164
+ drawTo(ctx: CanvasRenderingContext2D): void;
165
+ copy(source: EllipseCurve): this;
166
+ }
167
+
168
+ declare class HeartCurve extends Curve {
169
+ center: Point2D;
170
+ size: number;
171
+ start: number;
172
+ end: number;
173
+ curves: Curve[];
174
+ pointT: number;
175
+ constructor(center: Point2D, size: number, start?: number, end?: number);
176
+ getPoint(value: number): Point2D;
177
+ getPointAt(value: number): Point2D;
178
+ getCurrentLine(value: number): Curve;
179
+ getTangent(value: number): Point2D;
180
+ getNormal(value: number): Point2D;
181
+ getPathCommands(): PathCommand[];
182
+ drawTo(ctx: CanvasRenderingContext2D): void;
183
+ }
184
+
185
+ declare class LineCurve extends Curve {
186
+ v1: Point2D;
187
+ v2: Point2D;
188
+ constructor(v1?: Point2D, v2?: Point2D);
189
+ getDivisions(): number;
190
+ getPoint(t: number, output?: Point2D): Point2D;
191
+ getPointAt(u: number, output?: Point2D): Point2D;
192
+ getTangent(t: number, output?: Point2D): Point2D;
193
+ getTangentAt(u: number, output?: Point2D): Point2D;
194
+ getPathCommands(): PathCommand[];
195
+ getMinMax(min?: Point2D, max?: Point2D): {
196
+ min: Point2D;
197
+ max: Point2D;
198
+ };
199
+ drawTo(ctx: CanvasRenderingContext2D): void;
200
+ copy(source: LineCurve): this;
201
+ }
202
+
203
+ declare class PloygonCurve extends Curve {
204
+ center: Point2D;
205
+ radius: number;
206
+ num: number;
207
+ start: number;
208
+ end: number;
209
+ curves: LineCurve[];
210
+ points: Point2D[];
211
+ currentLine: LineCurve;
212
+ pointK: any;
213
+ constructor(center: Point2D, radius?: number, num?: number, start?: number, end?: number);
214
+ getPoint(value: number): Point2D;
215
+ getPointAt(value: number): Point2D;
216
+ getCurrentLine(value: number): LineCurve;
217
+ getTangent(value: number): Point2D;
218
+ getNormal(value: number): Point2D;
219
+ getPathCommands(): PathCommand[];
220
+ getMinMax(min?: Point2D, max?: Point2D): {
221
+ min: Point2D;
222
+ max: Point2D;
223
+ };
224
+ drawTo(ctx: CanvasRenderingContext2D): void;
225
+ }
226
+
227
+ declare class QuadraticBezierCurve extends Curve {
228
+ v0: Point2D;
229
+ v1: Point2D;
230
+ v2: Point2D;
231
+ constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
232
+ getPoint(t: number, output?: Point2D): Point2D;
233
+ getPathCommands(): PathCommand[];
234
+ getMinMax(min?: Point2D, max?: Point2D): {
235
+ min: Point2D;
236
+ max: Point2D;
237
+ };
238
+ drawTo(ctx: CanvasRenderingContext2D): void;
239
+ copy(source: QuadraticBezierCurve): this;
240
+ }
241
+
242
+ declare class RectangularCurve extends Curve {
243
+ center: Point2D;
244
+ rx: number;
245
+ aspectRatio: number;
246
+ start: number;
247
+ end: number;
248
+ curves: LineCurve[];
249
+ pointT: number;
250
+ get x(): number;
251
+ get y(): number;
252
+ get width(): number;
253
+ get height(): number;
254
+ constructor(center: Point2D, rx: number, aspectRatio?: number, start?: number, end?: number);
255
+ getPoint(t: number): Point2D;
256
+ getPointAt(u: number): Point2D;
257
+ getCurrentLine(t: number): LineCurve;
258
+ getTangent(t: number): Point2D;
259
+ getNormal(value: number): Point2D;
260
+ getPathCommands(): PathCommand[];
261
+ getMinMax(min?: Point2D, max?: Point2D): {
262
+ min: Point2D;
263
+ max: Point2D;
264
+ };
265
+ drawTo(ctx: CanvasRenderingContext2D): void;
266
+ }
267
+
268
+ declare class SplineCurve extends Curve {
269
+ points: Point2D[];
270
+ constructor(points?: Point2D[]);
271
+ getDivisions(divisions?: number): number;
272
+ getPoint(t: number, output?: Point2D): Point2D;
273
+ getPathCommands(): PathCommand[];
274
+ drawTo(_ctx: CanvasRenderingContext2D): void;
275
+ copy(source: SplineCurve): this;
276
+ }
277
+
278
+ /**
279
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Path2D
280
+ */
281
+ declare class Path2D {
282
+ currentPath: CurvePath;
283
+ paths: CurvePath[];
284
+ addPath(path: Path2D): this;
285
+ closePath(): this;
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;
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;
293
+ rect(x: number, y: number, w: number, h: number): this;
294
+ splineThru(points: Point2D[]): this;
295
+ getMinMax(min?: Point2D, max?: Point2D): {
296
+ min: Point2D;
297
+ max: Point2D;
298
+ };
299
+ getPathCommands(): PathCommand[];
300
+ getPathData(): string;
301
+ getBoundingBox(): {
302
+ x: number;
303
+ y: number;
304
+ width: number;
305
+ height: number;
306
+ };
307
+ getSvgString(): string;
308
+ getSvgDataUri(): string;
309
+ drawTo(ctx: CanvasRenderingContext2D): void;
310
+ strokeTo(ctx: CanvasRenderingContext2D): void;
311
+ fillTo(ctx: CanvasRenderingContext2D): void;
312
+ }
313
+
314
+ /**
315
+ * Bezier Curves formulas obtained from
316
+ * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
317
+ */
318
+ declare function catmullRom(t: number, p0: number, p1: number, p2: number, p3: number): number;
319
+ declare function quadraticBezier(t: number, p0: number, p1: number, p2: number): number;
320
+ declare function cubicBezier(t: number, p0: number, p1: number, p2: number, p3: number): number;
321
+
322
+ export { CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Path2D, type PathCommand, PloygonCurve, Point2D, QuadraticBezierCurve, RectangularCurve, SplineCurve, catmullRom, cubicBezier, quadraticBezier };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(e=typeof globalThis<"u"?globalThis:e||self,n(e.modernPath2d={}))})(this,function(e){"use strict";e.one=1,Object.defineProperty(e,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,a=i-1,u;for(;o<=a;)if(n=Math.floor(o+(a-o)/2),u=s[n]-h,u<0)o=n+1;else if(u>0)a=n-1;else{a=n;break}if(n=a,s[n]===h)return n/(i-1);const l=s[n],v=s[n+1]-l,M=(h-l)/v;return(n+M)/(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)}getPathData(){return this.getPathCommands().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))}getPathCommands(){return[]}drawTo(e){}}function m(c,e,t,s,n){const i=(s-e)*.5,h=(n-t)*.5,o=c*c,a=c*o;return(2*t-2*s+i+h)*a+(-3*t+3*s-2*i-h)*o+i*c+t}function D(c,e){const t=1-c;return t*t*e}function X(c,e){return 2*(1-c)*c*e}function E(c,e){return c*c*e}function I(c,e,t,s){return D(c,e)+X(c,t)+E(c,s)}function k(c,e){const t=1-c;return t*t*t*e}function F(c,e){const t=1-c;return 3*t*t*c*e}function Q(c,e){return 3*(1-c)*c*c*e}function U(c,e){return c*c*c*e}function z(c,e,t,s,n){return k(c,e)+F(c,t)+Q(c,s)+U(c,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}}getPathCommands(){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,a=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=a}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),a=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=a-this.y;o=y*u-v*l+this.x,a=y*l+v*u+this.y}return t.set(o,a)}getPathCommands(){const{x:e,y:t,rx:s,ry:n,startAngle:i,endAngle:h,clockwise:o}=this,a=!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),M=Math.abs(i-h),d=M>Math.PI?1:0,P=a?0:1,w=e+s*Math.cos(i+(h-i)/2),T=t+n*Math.sin(i+(h-i)/2);return M>=2*Math.PI?[{type:"M",x:u,y:l},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:1,sweepFlag:P,x:w,y:T},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:1,sweepFlag:P,x:u,y:l}]:[{type:"M",x:u,y:l},{type:"A",rx:s,ry:n,xAxisRotation:0,largeArcFlag:d,sweepFlag:P,x:y,y:v}]}drawTo(e){const{x:t,y:s,rx:n,ry:i,startAngle:h}=this,o=t+n*Math.cos(h),a=s+i*Math.sin(h);e.moveTo(o,a),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)}getPathCommands(){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,a=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(a,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),M=new L(l,.5*Math.SQRT1_2*this.size,.75*Math.PI,1.25*Math.PI),d=new r(h,o+this.size),P=new r(h+this.size,o),w=new r().lerpVectors(P,d,.75),T=new r(h-this.size,o),$=new r().lerpVectors(T,d,.75),C=new f(P,w),_=new f($,T);this.curves=[y,C,M,_,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()}getPathCommands(){return this.curves.flatMap(t=>t.getPathCommands())}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 a=o*2*Math.PI/this.num;a-=.5*Math.PI;const u=new r(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 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()}getPathCommands(){return this.curves.flatMap(t=>t.getPathCommands())}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}getPathCommands(){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),a=.5*(s.x+i.x),u=.5*(s.y+i.y);return e.x=Math.min(e.x,s.x,i.x,h,a),e.y=Math.min(e.y,s.y,i.y,o,u),t.x=Math.max(t.x,s.x,i.x,h,a),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:a}=this.center,u=this.rx,l=this.rx/this.aspectRatio,y=[new r(o-u,a-l),new r(o+u,a-l),new r(o+u,a+l),new r(o-u,a+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()}getPathCommands(){return this.curves.flatMap(t=>t.getPathCommands())}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],a=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,a.x,u.x,l.x),m(h,o.y,a.y,u.y,l.y)),t}getPathCommands(){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,a=this.curves[h],u=a.getLength();return a.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],a=o.getPoints(o.getDivisions(t));for(let u=0;u<a.length;u++){const l=a[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 a=this.currentPoint;return this.absarc(t+a.x,s+a.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,a=!1,u=0){const l=this.currentPoint;return this.absellipse(t+l.x,s+l.y,n,i,h,o,a,u),this}absellipse(t,s,n,i,h,o,a=!1,u=0){const l=new S(t,s,n,i,h,o,a,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}getPathCommands(){return this.curves.flatMap(t=>t.getPathCommands())}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,a=h.y,u=e-o,l=t-a,y=s-e,v=n-t,M=Math.sqrt(u*u+l*l),d=Math.sqrt(y*y+v*v);if(M<i||d<i)return this.lineTo(s,n),this;const P={x:u/M,y:l/M},w={x:y/d,y:v/d},T=e-P.y*i,$=t+P.x*i,C=Math.atan2(P.y,P.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,a){return this.currentPath.absellipse(e,t,s,n,h,o,!a,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}}getPathCommands(){return this.paths.flatMap(e=>e.curves.flatMap(t=>t.getPathCommands()))}getPathData(){return this.paths.map(e=>e.getPathData()).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.getPathData()}"></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"})});