modern-path2d 0.0.1 → 0.0.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/README.md +23 -2
- package/dist/index.cjs +984 -2
- package/dist/index.d.cts +270 -2
- package/dist/index.d.mts +270 -2
- package/dist/index.d.ts +270 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +969 -2
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,271 @@
|
|
|
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
|
-
|
|
36
|
+
declare class Point2D {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
constructor(x?: number, y?: number);
|
|
40
|
+
set(x: number, y: number): this;
|
|
41
|
+
add(point: Point2D): this;
|
|
42
|
+
sub(point: Point2D): this;
|
|
43
|
+
distanceTo(point: Point2D): number;
|
|
44
|
+
distanceToSquared(point: Point2D): number;
|
|
45
|
+
length(): number;
|
|
46
|
+
multiplyScalar(scalar: number): this;
|
|
47
|
+
divideScalar(scalar: number): this;
|
|
48
|
+
subVectors(a: Point2D, b: Point2D): this;
|
|
49
|
+
normalize(): this;
|
|
50
|
+
lerpVectors(v1: Point2D, v2: Point2D, alpha: number): this;
|
|
51
|
+
equals(point: Point2D): boolean;
|
|
52
|
+
copy(point: Point2D): this;
|
|
53
|
+
clone(): Point2D;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare abstract class Curve {
|
|
57
|
+
arcLengthDivisions: number;
|
|
58
|
+
protected _cacheArcLengths?: number[];
|
|
59
|
+
protected _needsUpdate: boolean;
|
|
60
|
+
abstract getPoint(t: number, output?: Point2D): Point2D;
|
|
61
|
+
abstract toPathCommands(): PathCommand[];
|
|
62
|
+
abstract drawTo(ctx: CanvasRenderingContext2D): void;
|
|
63
|
+
getDivisions(divisions: number): number;
|
|
64
|
+
getPointAt(u: number, output?: Point2D): Point2D;
|
|
65
|
+
getPoints(divisions?: number): Point2D[];
|
|
66
|
+
getSpacedPoints(divisions?: number): Point2D[];
|
|
67
|
+
getLength(): number;
|
|
68
|
+
getLengths(divisions?: number): number[];
|
|
69
|
+
updateArcLengths(): void;
|
|
70
|
+
getUtoTmapping(u: number, distance?: number): number;
|
|
71
|
+
getTangent(t: number, output?: Point2D): Point2D;
|
|
72
|
+
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
73
|
+
clone(): this;
|
|
74
|
+
copy(source: Curve): this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare class CurvePath extends Curve {
|
|
78
|
+
curves: Curve[];
|
|
79
|
+
currentPoint: Point2D;
|
|
80
|
+
autoClose: boolean;
|
|
81
|
+
protected _cacheLengths: number[];
|
|
82
|
+
constructor(points?: Point2D[]);
|
|
83
|
+
addCurve(curve: Curve): this;
|
|
84
|
+
closePath(): this;
|
|
85
|
+
getPoint(position: number, output?: Point2D): Point2D;
|
|
86
|
+
getLength(): number;
|
|
87
|
+
updateArcLengths(): void;
|
|
88
|
+
getCurveLengths(): number[];
|
|
89
|
+
getSpacedPoints(divisions?: number): Point2D[];
|
|
90
|
+
getPoints(divisions?: number): Point2D[];
|
|
91
|
+
setFromPoints(points: Point2D[]): this;
|
|
92
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
93
|
+
lineTo(x: number, y: number): this;
|
|
94
|
+
moveTo(x: number, y: number): this;
|
|
95
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
96
|
+
rect(x: number, y: number, w: number, h: number): this;
|
|
97
|
+
splineThru(points: Point2D[]): this;
|
|
98
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
|
|
99
|
+
absarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, clockwise?: boolean): this;
|
|
100
|
+
ellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
101
|
+
absellipse(x: number, y: number, xRadius: number, yRadius: number, startAngle: number, endAngle: number, clockwise?: boolean, rotation?: number): this;
|
|
102
|
+
toPathCommands(): PathCommand[];
|
|
103
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
104
|
+
copy(source: CurvePath): this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class CircleCurve extends Curve {
|
|
108
|
+
center: Point2D;
|
|
109
|
+
radius: number;
|
|
110
|
+
start: number;
|
|
111
|
+
end: number;
|
|
112
|
+
constructor(center: Point2D, radius: number, start?: number, end?: number);
|
|
113
|
+
getPole(min: Point2D, max: Point2D): void;
|
|
114
|
+
getPoint(index: number): Point2D;
|
|
115
|
+
getTangent(index: number): Point2D;
|
|
116
|
+
getNormal(index: number): Point2D;
|
|
117
|
+
toPathCommands(): PathCommand[];
|
|
118
|
+
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare class CubicBezierCurve extends Curve {
|
|
122
|
+
v0: Point2D;
|
|
123
|
+
v1: Point2D;
|
|
124
|
+
v2: Point2D;
|
|
125
|
+
v3: Point2D;
|
|
126
|
+
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D, v3?: Point2D);
|
|
127
|
+
getPoint(t: number, output?: Point2D): Point2D;
|
|
128
|
+
toPathCommands(): PathCommand[];
|
|
129
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
130
|
+
copy(source: CubicBezierCurve): this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class EllipseCurve extends Curve {
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
rx: number;
|
|
137
|
+
ry: number;
|
|
138
|
+
startAngle: number;
|
|
139
|
+
endAngle: number;
|
|
140
|
+
clockwise: boolean;
|
|
141
|
+
rotation: number;
|
|
142
|
+
constructor(x?: number, y?: number, rx?: number, ry?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number);
|
|
143
|
+
getDivisions(divisions?: number): number;
|
|
144
|
+
getPoint(t: number, output?: Point2D): Point2D;
|
|
145
|
+
toPathCommands(): PathCommand[];
|
|
146
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
147
|
+
copy(source: EllipseCurve): this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
declare class HeartCurve extends Curve {
|
|
151
|
+
center: Point2D;
|
|
152
|
+
size: number;
|
|
153
|
+
start: number;
|
|
154
|
+
end: number;
|
|
155
|
+
curves: Curve[];
|
|
156
|
+
pointT: number;
|
|
157
|
+
constructor(center: Point2D, size: number, start?: number, end?: number);
|
|
158
|
+
getPoint(value: number): Point2D;
|
|
159
|
+
getPointAt(value: number): Point2D;
|
|
160
|
+
getCurrentLine(value: number): Curve;
|
|
161
|
+
getTangent(value: number): Point2D;
|
|
162
|
+
getNormal(value: number): Point2D;
|
|
163
|
+
toPathCommands(): PathCommand[];
|
|
164
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class LineCurve extends Curve {
|
|
168
|
+
v1: Point2D;
|
|
169
|
+
v2: Point2D;
|
|
170
|
+
constructor(v1?: Point2D, v2?: Point2D);
|
|
171
|
+
getDivisions(): number;
|
|
172
|
+
getPoint(t: number, output?: Point2D): Point2D;
|
|
173
|
+
getPointAt(u: number, output?: Point2D): Point2D;
|
|
174
|
+
getTangent(t: number, output?: Point2D): Point2D;
|
|
175
|
+
getTangentAt(u: number, output?: Point2D): Point2D;
|
|
176
|
+
toPathCommands(): PathCommand[];
|
|
177
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
178
|
+
copy(source: LineCurve): this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
declare class PloygonCurve extends Curve {
|
|
182
|
+
center: Point2D;
|
|
183
|
+
radius: number;
|
|
184
|
+
num: number;
|
|
185
|
+
start: number;
|
|
186
|
+
end: number;
|
|
187
|
+
curves: LineCurve[];
|
|
188
|
+
points: Point2D[];
|
|
189
|
+
currentLine: LineCurve;
|
|
190
|
+
pointK: any;
|
|
191
|
+
constructor(center: Point2D, radius?: number, num?: number, start?: number, end?: number);
|
|
192
|
+
getPoint(value: number): Point2D;
|
|
193
|
+
getPointAt(value: number): Point2D;
|
|
194
|
+
getCurrentLine(value: number): LineCurve;
|
|
195
|
+
getTangent(value: number): Point2D;
|
|
196
|
+
getNormal(value: number): Point2D;
|
|
197
|
+
toPathCommands(): PathCommand[];
|
|
198
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class QuadraticBezierCurve extends Curve {
|
|
202
|
+
v0: Point2D;
|
|
203
|
+
v1: Point2D;
|
|
204
|
+
v2: Point2D;
|
|
205
|
+
constructor(v0?: Point2D, v1?: Point2D, v2?: Point2D);
|
|
206
|
+
getPoint(t: number, output?: Point2D): Point2D;
|
|
207
|
+
toPathCommands(): PathCommand[];
|
|
208
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
209
|
+
copy(source: QuadraticBezierCurve): this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class RectangularCurve extends Curve {
|
|
213
|
+
center: Point2D;
|
|
214
|
+
rx: number;
|
|
215
|
+
aspectRatio: number;
|
|
216
|
+
start: number;
|
|
217
|
+
end: number;
|
|
218
|
+
curves: LineCurve[];
|
|
219
|
+
pointT: number;
|
|
220
|
+
get x(): number;
|
|
221
|
+
get y(): number;
|
|
222
|
+
get width(): number;
|
|
223
|
+
get height(): number;
|
|
224
|
+
constructor(center: Point2D, rx: number, aspectRatio?: number, start?: number, end?: number);
|
|
225
|
+
getPoint(t: number): Point2D;
|
|
226
|
+
getPointAt(u: number): Point2D;
|
|
227
|
+
getCurrentLine(t: number): LineCurve;
|
|
228
|
+
getTangent(t: number): Point2D;
|
|
229
|
+
getNormal(value: number): Point2D;
|
|
230
|
+
toPathCommands(): PathCommand[];
|
|
231
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
declare class SplineCurve extends Curve {
|
|
235
|
+
points: Point2D[];
|
|
236
|
+
constructor(points?: Point2D[]);
|
|
237
|
+
getDivisions(divisions?: number): number;
|
|
238
|
+
getPoint(t: number, output?: Point2D): Point2D;
|
|
239
|
+
toPathCommands(): PathCommand[];
|
|
240
|
+
drawTo(_ctx: CanvasRenderingContext2D): void;
|
|
241
|
+
copy(source: SplineCurve): this;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Path2D
|
|
246
|
+
*/
|
|
247
|
+
declare class Path2D {
|
|
248
|
+
currentPath: CurvePath;
|
|
249
|
+
paths: CurvePath[];
|
|
250
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
251
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
252
|
+
lineTo(x: number, y: number): this;
|
|
253
|
+
moveTo(x: number, y: number): this;
|
|
254
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
255
|
+
rect(x: number, y: number, w: number, h: number): this;
|
|
256
|
+
splineThru(points: Point2D[]): this;
|
|
257
|
+
toPathCommands(): PathCommand[];
|
|
258
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
259
|
+
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
260
|
+
fillTo(ctx: CanvasRenderingContext2D): void;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Bezier Curves formulas obtained from
|
|
265
|
+
* https://en.wikipedia.org/wiki/B%C3%A9zier_curve
|
|
266
|
+
*/
|
|
267
|
+
declare function catmullRom(t: number, p0: number, p1: number, p2: number, p3: number): number;
|
|
268
|
+
declare function quadraticBezier(t: number, p0: number, p1: number, p2: number): number;
|
|
269
|
+
declare function cubicBezier(t: number, p0: number, p1: number, p2: number, p3: number): number;
|
|
270
|
+
|
|
271
|
+
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,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"})});
|