modern-path2d 0.1.10 → 0.1.11
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 +112 -40
- package/dist/index.d.cts +131 -85
- package/dist/index.d.mts +131 -85
- package/dist/index.d.ts +131 -85
- package/dist/index.js +1 -1
- package/dist/index.mjs +107 -41
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const lineJoinMap = {
|
|
4
|
+
"arcs": "bevel",
|
|
5
|
+
"bevel": "bevel",
|
|
6
|
+
"miter": "miter",
|
|
7
|
+
"miter-clip": "miter",
|
|
8
|
+
"round": "round"
|
|
9
|
+
};
|
|
10
|
+
function setCanvasContextByPath(ctx, path) {
|
|
11
|
+
const {
|
|
12
|
+
fill = "#000",
|
|
13
|
+
stroke = "none",
|
|
14
|
+
strokeWidth = stroke === "none" ? 0 : 1,
|
|
15
|
+
strokeLinecap = "round",
|
|
16
|
+
strokeLinejoin = "miter",
|
|
17
|
+
strokeMiterlimit = 0,
|
|
18
|
+
strokeDasharray,
|
|
19
|
+
strokeDashoffset = 0
|
|
20
|
+
} = path.style;
|
|
21
|
+
ctx.fillStyle = fill;
|
|
22
|
+
ctx.strokeStyle = stroke;
|
|
23
|
+
ctx.lineWidth = strokeWidth;
|
|
24
|
+
ctx.lineCap = strokeLinecap;
|
|
25
|
+
ctx.lineJoin = lineJoinMap[strokeLinejoin];
|
|
26
|
+
ctx.miterLimit = strokeMiterlimit;
|
|
27
|
+
ctx.lineDashOffset = strokeDashoffset;
|
|
28
|
+
strokeDasharray && ctx.setLineDash(strokeDasharray);
|
|
29
|
+
}
|
|
30
|
+
|
|
3
31
|
class Vector2 {
|
|
4
32
|
constructor(x = 0, y = 0) {
|
|
5
33
|
this.x = x;
|
|
@@ -2080,6 +2108,10 @@ class CurvePath extends Curve {
|
|
|
2080
2108
|
}
|
|
2081
2109
|
}
|
|
2082
2110
|
|
|
2111
|
+
function toKebabCase(str) {
|
|
2112
|
+
return str.replace(/[^a-z0-9]/gi, "-").replace(/\B([A-Z])/g, "-$1").toLowerCase();
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2083
2115
|
var __defProp = Object.defineProperty;
|
|
2084
2116
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2085
2117
|
var __publicField = (obj, key, value) => {
|
|
@@ -2090,7 +2122,7 @@ class Path2D {
|
|
|
2090
2122
|
constructor(path) {
|
|
2091
2123
|
__publicField(this, "currentPath", new CurvePath());
|
|
2092
2124
|
__publicField(this, "paths", [this.currentPath]);
|
|
2093
|
-
__publicField(this, "
|
|
2125
|
+
__publicField(this, "style", {});
|
|
2094
2126
|
if (path) {
|
|
2095
2127
|
if (path instanceof Path2D) {
|
|
2096
2128
|
this.addPath(path);
|
|
@@ -2107,6 +2139,9 @@ class Path2D {
|
|
|
2107
2139
|
get currentPoint() {
|
|
2108
2140
|
return this.currentPath.currentPoint;
|
|
2109
2141
|
}
|
|
2142
|
+
get strokeWidth() {
|
|
2143
|
+
return this.style.strokeWidth ?? ((this.style.stroke ?? "none") === "none" ? 0 : 1);
|
|
2144
|
+
}
|
|
2110
2145
|
addPath(path) {
|
|
2111
2146
|
if (path instanceof Path2D) {
|
|
2112
2147
|
this.paths.push(...path.paths.map((v) => v.clone()));
|
|
@@ -2194,9 +2229,17 @@ class Path2D {
|
|
|
2194
2229
|
this.forEachCurve((curve) => curve.getMinMax(min, max));
|
|
2195
2230
|
return { min, max };
|
|
2196
2231
|
}
|
|
2197
|
-
getBoundingBox() {
|
|
2232
|
+
getBoundingBox(withStrokeWidth = true) {
|
|
2198
2233
|
const { min, max } = this.getMinMax();
|
|
2199
|
-
|
|
2234
|
+
const bbox = new BoundingBox(min.x, min.y, max.x - min.x, max.y - min.y);
|
|
2235
|
+
if (withStrokeWidth) {
|
|
2236
|
+
const strokeWidth = this.strokeWidth;
|
|
2237
|
+
bbox.left -= strokeWidth / 2;
|
|
2238
|
+
bbox.top -= strokeWidth / 2;
|
|
2239
|
+
bbox.width += strokeWidth;
|
|
2240
|
+
bbox.height += strokeWidth;
|
|
2241
|
+
}
|
|
2242
|
+
return bbox;
|
|
2200
2243
|
}
|
|
2201
2244
|
getCommands() {
|
|
2202
2245
|
return this.paths.flatMap((path) => path.getCommands());
|
|
@@ -2204,46 +2247,74 @@ class Path2D {
|
|
|
2204
2247
|
getData() {
|
|
2205
2248
|
return this.paths.map((path) => path.getData()).join(" ");
|
|
2206
2249
|
}
|
|
2207
|
-
|
|
2250
|
+
getSvgPathXml() {
|
|
2251
|
+
const style = {
|
|
2252
|
+
...this.style,
|
|
2253
|
+
fill: this.style.fill ?? "#000",
|
|
2254
|
+
stroke: this.style.stroke ?? "none"
|
|
2255
|
+
};
|
|
2256
|
+
const cssStyle = {};
|
|
2257
|
+
for (const key in style) {
|
|
2258
|
+
if (style[key] !== void 0) {
|
|
2259
|
+
cssStyle[toKebabCase(key)] = style[key];
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
Object.assign(cssStyle, {
|
|
2263
|
+
"stroke-width": `${this.strokeWidth}px`
|
|
2264
|
+
});
|
|
2265
|
+
let cssText = "";
|
|
2266
|
+
for (const key in cssStyle) {
|
|
2267
|
+
if (cssStyle[key] !== void 0) {
|
|
2268
|
+
cssText += `${key}:${cssStyle[key]};`;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
return `<path d="${this.getData()}" style="${cssText}"></path>`;
|
|
2272
|
+
}
|
|
2273
|
+
getSvgXml() {
|
|
2208
2274
|
const { x, y, width, height } = this.getBoundingBox();
|
|
2209
|
-
const
|
|
2210
|
-
return `<svg viewBox="${x
|
|
2275
|
+
const path = this.getSvgPathXml();
|
|
2276
|
+
return `<svg viewBox="${x} ${y} ${width} ${height}" width="${width}px" height="${height}px" xmlns="http://www.w3.org/2000/svg">${path}</svg>`;
|
|
2211
2277
|
}
|
|
2212
2278
|
getSvgDataUri() {
|
|
2213
|
-
return `data:image/svg+xml;base64,${btoa(this.
|
|
2279
|
+
return `data:image/svg+xml;base64,${btoa(this.getSvgXml())}`;
|
|
2214
2280
|
}
|
|
2215
2281
|
drawTo(ctx) {
|
|
2282
|
+
const {
|
|
2283
|
+
fill = "#000",
|
|
2284
|
+
stroke = "none"
|
|
2285
|
+
} = this.style;
|
|
2286
|
+
setCanvasContextByPath(ctx, this);
|
|
2216
2287
|
this.paths.forEach((path) => {
|
|
2217
2288
|
path.drawTo(ctx);
|
|
2218
2289
|
});
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
this.drawTo(ctx);
|
|
2226
|
-
ctx.fill();
|
|
2290
|
+
if (fill !== "none") {
|
|
2291
|
+
ctx.fill();
|
|
2292
|
+
}
|
|
2293
|
+
if (stroke !== "none") {
|
|
2294
|
+
ctx.stroke();
|
|
2295
|
+
}
|
|
2227
2296
|
}
|
|
2228
2297
|
copy(source) {
|
|
2229
2298
|
this.currentPath = source.currentPath.clone();
|
|
2230
2299
|
this.paths = source.paths.map((path) => path.clone());
|
|
2231
|
-
this.
|
|
2300
|
+
this.style = { ...source.style };
|
|
2232
2301
|
return this;
|
|
2233
2302
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2303
|
+
toSvg() {
|
|
2304
|
+
return new DOMParser().parseFromString(this.getSvgXml(), "image/svg+xml").documentElement;
|
|
2305
|
+
}
|
|
2306
|
+
toCanvas(pixelRatio = 2) {
|
|
2236
2307
|
const { left, top, width, height } = this.getBoundingBox();
|
|
2237
|
-
canvas
|
|
2238
|
-
canvas.
|
|
2308
|
+
const canvas = document.createElement("canvas");
|
|
2309
|
+
canvas.width = width * pixelRatio;
|
|
2310
|
+
canvas.height = height * pixelRatio;
|
|
2311
|
+
canvas.style.width = `${width}px`;
|
|
2312
|
+
canvas.style.height = `${height}px`;
|
|
2239
2313
|
const ctx = canvas.getContext("2d");
|
|
2240
2314
|
if (ctx) {
|
|
2315
|
+
ctx.scale(pixelRatio, pixelRatio);
|
|
2241
2316
|
ctx.translate(-left, -top);
|
|
2242
|
-
|
|
2243
|
-
this.fillTo(ctx);
|
|
2244
|
-
} else {
|
|
2245
|
-
this.strokeTo(ctx);
|
|
2246
|
-
}
|
|
2317
|
+
this.drawTo(ctx);
|
|
2247
2318
|
}
|
|
2248
2319
|
return canvas;
|
|
2249
2320
|
}
|
|
@@ -2636,18 +2707,21 @@ function parseStyle(node, style, stylesheets) {
|
|
|
2636
2707
|
function positive(v) {
|
|
2637
2708
|
return Math.max(0, parseFloatWithUnits(v));
|
|
2638
2709
|
}
|
|
2710
|
+
function array(v) {
|
|
2711
|
+
return v.split(" ").filter((v2) => v2 !== "").map((v2) => parseFloatWithUnits(v2));
|
|
2712
|
+
}
|
|
2639
2713
|
addStyle("fill", "fill");
|
|
2640
2714
|
addStyle("fill-opacity", "fillOpacity", clamp);
|
|
2641
2715
|
addStyle("fill-rule", "fillRule");
|
|
2642
2716
|
addStyle("opacity", "opacity", clamp);
|
|
2643
2717
|
addStyle("stroke", "stroke");
|
|
2644
|
-
addStyle("stroke-dashoffset", "strokeDashoffset");
|
|
2645
|
-
addStyle("stroke-dasharray", "strokeDasharray");
|
|
2646
|
-
addStyle("stroke-linecap", "strokeLineCap");
|
|
2647
|
-
addStyle("stroke-linejoin", "strokeLineJoin");
|
|
2648
|
-
addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
|
|
2649
2718
|
addStyle("stroke-opacity", "strokeOpacity", clamp);
|
|
2650
2719
|
addStyle("stroke-width", "strokeWidth", positive);
|
|
2720
|
+
addStyle("stroke-linecap", "strokeLinecap");
|
|
2721
|
+
addStyle("stroke-linejoin", "strokeLinejoin");
|
|
2722
|
+
addStyle("stroke-miterlimit", "strokeMiterlimit", positive);
|
|
2723
|
+
addStyle("stroke-dasharray", "strokeDasharray", array);
|
|
2724
|
+
addStyle("stroke-dashoffset", "strokeDashoffset", parseFloatWithUnits);
|
|
2651
2725
|
addStyle("visibility", "visibility");
|
|
2652
2726
|
return style;
|
|
2653
2727
|
}
|
|
@@ -2722,7 +2796,7 @@ function parseNode(node, style, paths = []) {
|
|
|
2722
2796
|
if (path) {
|
|
2723
2797
|
path.transform(currentTransform);
|
|
2724
2798
|
paths.push(path);
|
|
2725
|
-
path.
|
|
2799
|
+
path.style = style;
|
|
2726
2800
|
}
|
|
2727
2801
|
const childNodes = node.childNodes;
|
|
2728
2802
|
for (let i = 0, len = childNodes.length; i < len; i++) {
|
|
@@ -2766,15 +2840,7 @@ function parseSvgToDom(svg) {
|
|
|
2766
2840
|
}
|
|
2767
2841
|
}
|
|
2768
2842
|
function parseSvg(svg) {
|
|
2769
|
-
return parseNode(parseSvgToDom(svg), {
|
|
2770
|
-
fill: "#000",
|
|
2771
|
-
fillOpacity: 1,
|
|
2772
|
-
strokeOpacity: 1,
|
|
2773
|
-
strokeWidth: 1,
|
|
2774
|
-
strokeLineJoin: "miter",
|
|
2775
|
-
strokeLineCap: "butt",
|
|
2776
|
-
strokeMiterLimit: 4
|
|
2777
|
-
});
|
|
2843
|
+
return parseNode(parseSvgToDom(svg), {});
|
|
2778
2844
|
}
|
|
2779
2845
|
|
|
2780
2846
|
exports.BoundingBox = BoundingBox;
|
|
@@ -2792,5 +2858,11 @@ exports.QuadraticBezierCurve = QuadraticBezierCurve;
|
|
|
2792
2858
|
exports.RectangularCurve = RectangularCurve;
|
|
2793
2859
|
exports.SplineCurve = SplineCurve;
|
|
2794
2860
|
exports.Vector2 = Vector2;
|
|
2861
|
+
exports.addPathCommandsToPath2D = addPathCommandsToPath2D;
|
|
2862
|
+
exports.parseArcCommand = parseArcCommand;
|
|
2863
|
+
exports.parsePathDataArgs = parsePathDataArgs;
|
|
2795
2864
|
exports.parseSvg = parseSvg;
|
|
2796
2865
|
exports.parseSvgToDom = parseSvgToDom;
|
|
2866
|
+
exports.pathCommandsToPathData = pathCommandsToPathData;
|
|
2867
|
+
exports.pathDataToPathCommands = pathDataToPathCommands;
|
|
2868
|
+
exports.setCanvasContextByPath = setCanvasContextByPath;
|
package/dist/index.d.cts
CHANGED
|
@@ -65,90 +65,6 @@ declare class BoundingBox {
|
|
|
65
65
|
toArray(): [number, number, number, number];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
declare class CurvePath extends Curve {
|
|
69
|
-
curves: Curve[];
|
|
70
|
-
startPoint?: Vector2;
|
|
71
|
-
currentPoint: Vector2;
|
|
72
|
-
autoClose: boolean;
|
|
73
|
-
protected _cacheLengths: number[];
|
|
74
|
-
constructor(points?: Vector2[]);
|
|
75
|
-
addCurve(curve: Curve): this;
|
|
76
|
-
addPoints(points: Vector2[]): this;
|
|
77
|
-
addCommands(commands: PathCommand[]): this;
|
|
78
|
-
addData(data: string): this;
|
|
79
|
-
getPoint(t: number, output?: Vector2): Vector2;
|
|
80
|
-
getLength(): number;
|
|
81
|
-
updateArcLengths(): void;
|
|
82
|
-
getCurveLengths(): number[];
|
|
83
|
-
getSpacedPoints(divisions?: number): Vector2[];
|
|
84
|
-
getPoints(divisions?: number): Vector2[];
|
|
85
|
-
protected _setCurrentPoint(point: VectorLike): this;
|
|
86
|
-
closePath(): this;
|
|
87
|
-
moveTo(x: number, y: number): this;
|
|
88
|
-
lineTo(x: number, y: number): this;
|
|
89
|
-
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
90
|
-
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
91
|
-
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
92
|
-
relativeArc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
93
|
-
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
94
|
-
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
95
|
-
relativeEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
96
|
-
rect(x: number, y: number, w: number, h: number): this;
|
|
97
|
-
splineThru(points: Vector2[]): this;
|
|
98
|
-
transformPoint(cb: (point: Vector2) => void): this;
|
|
99
|
-
getMinMax(min?: Vector2, max?: Vector2): {
|
|
100
|
-
min: Vector2;
|
|
101
|
-
max: Vector2;
|
|
102
|
-
};
|
|
103
|
-
getBoundingBox(): BoundingBox;
|
|
104
|
-
getCommands(): PathCommand[];
|
|
105
|
-
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
106
|
-
copy(source: CurvePath): this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Path2D
|
|
111
|
-
*/
|
|
112
|
-
declare class Path2D<T = any> {
|
|
113
|
-
currentPath: CurvePath;
|
|
114
|
-
paths: CurvePath[];
|
|
115
|
-
userData?: T;
|
|
116
|
-
get startPoint(): Vector2 | undefined;
|
|
117
|
-
get currentPoint(): Vector2 | undefined;
|
|
118
|
-
constructor(path?: Path2D | PathCommand[] | string);
|
|
119
|
-
addPath(path: Path2D | CurvePath): this;
|
|
120
|
-
closePath(): this;
|
|
121
|
-
moveTo(x: number, y: number): this;
|
|
122
|
-
lineTo(x: number, y: number): this;
|
|
123
|
-
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
124
|
-
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
125
|
-
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
126
|
-
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
127
|
-
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
128
|
-
rect(x: number, y: number, w: number, h: number): this;
|
|
129
|
-
addCommands(commands: PathCommand[]): this;
|
|
130
|
-
addData(data: string): this;
|
|
131
|
-
splineThru(points: Vector2[]): this;
|
|
132
|
-
forEachCurve(cb: (curve: Curve) => void): this;
|
|
133
|
-
transformPoint(cb: (point: Vector2) => void): this;
|
|
134
|
-
transform(matrix: Matrix3): this;
|
|
135
|
-
getMinMax(min?: Vector2, max?: Vector2): {
|
|
136
|
-
min: Vector2;
|
|
137
|
-
max: Vector2;
|
|
138
|
-
};
|
|
139
|
-
getBoundingBox(): BoundingBox;
|
|
140
|
-
getCommands(): PathCommand[];
|
|
141
|
-
getData(): string;
|
|
142
|
-
getSvgString(): string;
|
|
143
|
-
getSvgDataUri(): string;
|
|
144
|
-
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
145
|
-
strokeTo(ctx: CanvasRenderingContext2D): void;
|
|
146
|
-
fillTo(ctx: CanvasRenderingContext2D): void;
|
|
147
|
-
copy(source: Path2D): this;
|
|
148
|
-
toCanvas(fill?: boolean): HTMLCanvasElement;
|
|
149
|
-
clone(): this;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
68
|
/**
|
|
153
69
|
* @link https://developer.mozilla.org/docs/Web/SVG/Attribute/d
|
|
154
70
|
*/
|
|
@@ -202,6 +118,49 @@ type PathCommand = {
|
|
|
202
118
|
} | {
|
|
203
119
|
type: 'z' | 'Z';
|
|
204
120
|
};
|
|
121
|
+
type FillRule = 'nonzero' | 'evenodd';
|
|
122
|
+
type StrokeLinecap = 'butt' | 'round' | 'square';
|
|
123
|
+
type StrokeLinejoin = 'arcs' | 'bevel' | 'miter' | 'miter-clip' | 'round';
|
|
124
|
+
interface PathStyle {
|
|
125
|
+
[key: string]: any;
|
|
126
|
+
fill?: string;
|
|
127
|
+
fillOpacity?: number;
|
|
128
|
+
fillRule?: FillRule;
|
|
129
|
+
opacity?: number;
|
|
130
|
+
stroke?: string;
|
|
131
|
+
strokeOpacity?: number;
|
|
132
|
+
strokeWidth?: number;
|
|
133
|
+
strokeLinecap?: StrokeLinecap;
|
|
134
|
+
strokeLinejoin?: StrokeLinejoin;
|
|
135
|
+
strokeMiterlimit?: number;
|
|
136
|
+
strokeDasharray?: number[];
|
|
137
|
+
strokeDashoffset?: number;
|
|
138
|
+
visibility?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @link http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
|
|
143
|
+
*/
|
|
144
|
+
declare function addPathCommandsToPath2D(commands: PathCommand[], path: Path2D | CurvePath): void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
|
148
|
+
* https://mortoray.com/2017/02/16/rendering-an-svg-elliptical-arc-as-bezier-curves/ Appendix: Endpoint to center arc conversion
|
|
149
|
+
* From
|
|
150
|
+
* rx ry x-axis-rotation large-arc-flag sweep-flag x y
|
|
151
|
+
* To
|
|
152
|
+
* aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation
|
|
153
|
+
*/
|
|
154
|
+
declare function parseArcCommand(path: Path2D | CurvePath, rx: number, ry: number, xAxisRotation: number, largeArcFlag: number, sweepFlag: number, start: Vector2, end: Vector2): void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* from https://github.com/ppvg/svg-numbers (MIT License)
|
|
158
|
+
*/
|
|
159
|
+
declare function parsePathDataArgs(input: string, flags?: number[], stride?: number): number[];
|
|
160
|
+
|
|
161
|
+
declare function pathCommandsToPathData(commands: PathCommand[]): string;
|
|
162
|
+
|
|
163
|
+
declare function pathDataToPathCommands(d: string): PathCommand[];
|
|
205
164
|
|
|
206
165
|
declare abstract class Curve {
|
|
207
166
|
arcLengthDivisions: number;
|
|
@@ -410,7 +369,94 @@ declare class SplineCurve extends Curve {
|
|
|
410
369
|
copy(source: SplineCurve): this;
|
|
411
370
|
}
|
|
412
371
|
|
|
372
|
+
declare class CurvePath extends Curve {
|
|
373
|
+
curves: Curve[];
|
|
374
|
+
startPoint?: Vector2;
|
|
375
|
+
currentPoint: Vector2;
|
|
376
|
+
autoClose: boolean;
|
|
377
|
+
protected _cacheLengths: number[];
|
|
378
|
+
constructor(points?: Vector2[]);
|
|
379
|
+
addCurve(curve: Curve): this;
|
|
380
|
+
addPoints(points: Vector2[]): this;
|
|
381
|
+
addCommands(commands: PathCommand[]): this;
|
|
382
|
+
addData(data: string): this;
|
|
383
|
+
getPoint(t: number, output?: Vector2): Vector2;
|
|
384
|
+
getLength(): number;
|
|
385
|
+
updateArcLengths(): void;
|
|
386
|
+
getCurveLengths(): number[];
|
|
387
|
+
getSpacedPoints(divisions?: number): Vector2[];
|
|
388
|
+
getPoints(divisions?: number): Vector2[];
|
|
389
|
+
protected _setCurrentPoint(point: VectorLike): this;
|
|
390
|
+
closePath(): this;
|
|
391
|
+
moveTo(x: number, y: number): this;
|
|
392
|
+
lineTo(x: number, y: number): this;
|
|
393
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
394
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
395
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
396
|
+
relativeArc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
397
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
398
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
399
|
+
relativeEllipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
400
|
+
rect(x: number, y: number, w: number, h: number): this;
|
|
401
|
+
splineThru(points: Vector2[]): this;
|
|
402
|
+
transformPoint(cb: (point: Vector2) => void): this;
|
|
403
|
+
getMinMax(min?: Vector2, max?: Vector2): {
|
|
404
|
+
min: Vector2;
|
|
405
|
+
max: Vector2;
|
|
406
|
+
};
|
|
407
|
+
getBoundingBox(): BoundingBox;
|
|
408
|
+
getCommands(): PathCommand[];
|
|
409
|
+
drawTo(ctx: CanvasRenderingContext2D): this;
|
|
410
|
+
copy(source: CurvePath): this;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Path2D
|
|
415
|
+
*/
|
|
416
|
+
declare class Path2D {
|
|
417
|
+
currentPath: CurvePath;
|
|
418
|
+
paths: CurvePath[];
|
|
419
|
+
style: PathStyle;
|
|
420
|
+
get startPoint(): Vector2 | undefined;
|
|
421
|
+
get currentPoint(): Vector2 | undefined;
|
|
422
|
+
get strokeWidth(): number;
|
|
423
|
+
constructor(path?: Path2D | PathCommand[] | string);
|
|
424
|
+
addPath(path: Path2D | CurvePath): this;
|
|
425
|
+
closePath(): this;
|
|
426
|
+
moveTo(x: number, y: number): this;
|
|
427
|
+
lineTo(x: number, y: number): this;
|
|
428
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
|
|
429
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
430
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
431
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
|
|
432
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): this;
|
|
433
|
+
rect(x: number, y: number, w: number, h: number): this;
|
|
434
|
+
addCommands(commands: PathCommand[]): this;
|
|
435
|
+
addData(data: string): this;
|
|
436
|
+
splineThru(points: Vector2[]): this;
|
|
437
|
+
forEachCurve(cb: (curve: Curve) => void): this;
|
|
438
|
+
transformPoint(cb: (point: Vector2) => void): this;
|
|
439
|
+
transform(matrix: Matrix3): this;
|
|
440
|
+
getMinMax(min?: Vector2, max?: Vector2): {
|
|
441
|
+
min: Vector2;
|
|
442
|
+
max: Vector2;
|
|
443
|
+
};
|
|
444
|
+
getBoundingBox(withStrokeWidth?: boolean): BoundingBox;
|
|
445
|
+
getCommands(): PathCommand[];
|
|
446
|
+
getData(): string;
|
|
447
|
+
getSvgPathXml(): string;
|
|
448
|
+
getSvgXml(): string;
|
|
449
|
+
getSvgDataUri(): string;
|
|
450
|
+
drawTo(ctx: CanvasRenderingContext2D): void;
|
|
451
|
+
copy(source: Path2D): this;
|
|
452
|
+
toSvg(): SVGElement;
|
|
453
|
+
toCanvas(pixelRatio?: number): HTMLCanvasElement;
|
|
454
|
+
clone(): this;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
declare function setCanvasContextByPath(ctx: CanvasRenderingContext2D, path: Path2D): void;
|
|
458
|
+
|
|
413
459
|
declare function parseSvgToDom(svg: string | SVGElement): SVGElement;
|
|
414
460
|
declare function parseSvg(svg: string | SVGElement): Path2D[];
|
|
415
461
|
|
|
416
|
-
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, HeartCurve, LineCurve, Matrix3, Path2D, PloygonCurve, QuadraticBezierCurve, RectangularCurve, SplineCurve, Vector2, type VectorLike, parseSvg, parseSvgToDom };
|
|
462
|
+
export { BoundingBox, CircleCurve, CubicBezierCurve, Curve, CurvePath, EllipseCurve, type FillRule, HeartCurve, LineCurve, Matrix3, Path2D, type PathCommand, type PathStyle, PloygonCurve, QuadraticBezierCurve, RectangularCurve, SplineCurve, type StrokeLinecap, type StrokeLinejoin, Vector2, type VectorLike, addPathCommandsToPath2D, parseArcCommand, parsePathDataArgs, parseSvg, parseSvgToDom, pathCommandsToPathData, pathDataToPathCommands, setCanvasContextByPath };
|