svg-path-commander 2.1.2 → 2.1.5
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 +4 -4
- package/dist/svg-path-commander.cjs +1 -1
- package/dist/svg-path-commander.cjs.map +1 -1
- package/dist/svg-path-commander.d.ts +755 -849
- package/dist/svg-path-commander.js +1 -1
- package/dist/svg-path-commander.js.map +1 -1
- package/dist/svg-path-commander.mjs +947 -611
- package/dist/svg-path-commander.mjs.map +1 -1
- package/package.json +14 -22
- package/.eslintrc.cjs +0 -225
- package/.prettierrc.json +0 -15
- package/dts.config.ts +0 -15
- package/src/convert/pathToAbsolute.ts +0 -18
- package/src/convert/pathToCurve.ts +0 -43
- package/src/convert/pathToRelative.ts +0 -18
- package/src/convert/pathToString.ts +0 -50
- package/src/index.ts +0 -454
- package/src/interface.ts +0 -130
- package/src/math/arcTools.ts +0 -396
- package/src/math/bezier.ts +0 -261
- package/src/math/cubicTools.ts +0 -124
- package/src/math/distanceSquareRoot.ts +0 -15
- package/src/math/lineTools.ts +0 -69
- package/src/math/midPoint.ts +0 -18
- package/src/math/polygonTools.ts +0 -48
- package/src/math/quadTools.ts +0 -100
- package/src/math/rotateVector.ts +0 -17
- package/src/math/roundTo.ts +0 -7
- package/src/options/options.ts +0 -9
- package/src/parser/error.ts +0 -2
- package/src/parser/finalizeSegment.ts +0 -35
- package/src/parser/invalidPathValue.ts +0 -2
- package/src/parser/isArcCommand.ts +0 -11
- package/src/parser/isDigit.ts +0 -12
- package/src/parser/isDigitStart.ts +0 -14
- package/src/parser/isMoveCommand.ts +0 -17
- package/src/parser/isPathCommand.ts +0 -28
- package/src/parser/isSpace.ts +0 -23
- package/src/parser/paramsCount.ts +0 -16
- package/src/parser/paramsParser.ts +0 -14
- package/src/parser/parsePathString.ts +0 -33
- package/src/parser/pathParser.ts +0 -29
- package/src/parser/scanFlag.ts +0 -29
- package/src/parser/scanParam.ts +0 -102
- package/src/parser/scanSegment.ts +0 -84
- package/src/parser/skipSpaces.ts +0 -17
- package/src/process/absolutizeSegment.ts +0 -63
- package/src/process/arcToCubic.ts +0 -128
- package/src/process/getSVGMatrix.ts +0 -70
- package/src/process/iterate.ts +0 -58
- package/src/process/lineToCubic.ts +0 -17
- package/src/process/normalizePath.ts +0 -33
- package/src/process/normalizeSegment.ts +0 -84
- package/src/process/optimizePath.ts +0 -63
- package/src/process/projection2d.ts +0 -52
- package/src/process/quadToCubic.ts +0 -31
- package/src/process/relativizeSegment.ts +0 -59
- package/src/process/reverseCurve.ts +0 -24
- package/src/process/reversePath.ts +0 -114
- package/src/process/roundPath.ts +0 -33
- package/src/process/roundSegment.ts +0 -9
- package/src/process/segmentToCubic.ts +0 -48
- package/src/process/shortenSegment.ts +0 -71
- package/src/process/splitCubic.ts +0 -29
- package/src/process/splitPath.ts +0 -63
- package/src/process/transformPath.ts +0 -110
- package/src/types.ts +0 -228
- package/src/util/distanceEpsilon.ts +0 -3
- package/src/util/getClosestPoint.ts +0 -15
- package/src/util/getDrawDirection.ts +0 -16
- package/src/util/getPathArea.ts +0 -70
- package/src/util/getPathBBox.ts +0 -98
- package/src/util/getPointAtLength.ts +0 -110
- package/src/util/getPropertiesAtLength.ts +0 -67
- package/src/util/getPropertiesAtPoint.ts +0 -84
- package/src/util/getSegmentAtLength.ts +0 -15
- package/src/util/getSegmentOfPoint.ts +0 -18
- package/src/util/getTotalLength.ts +0 -68
- package/src/util/isAbsoluteArray.ts +0 -18
- package/src/util/isCurveArray.ts +0 -15
- package/src/util/isNormalizedArray.ts +0 -16
- package/src/util/isPathArray.ts +0 -24
- package/src/util/isPointInStroke.ts +0 -16
- package/src/util/isRelativeArray.ts +0 -18
- package/src/util/isValidPath.ts +0 -27
- package/src/util/shapeParams.ts +0 -16
- package/src/util/shapeToPath.ts +0 -86
- package/src/util/shapeToPathArray.ts +0 -183
- package/test/class.test.ts +0 -504
- package/test/fixtures/getMarkup.ts +0 -17
- package/test/fixtures/shapeObjects.ts +0 -11
- package/test/fixtures/shapes.js +0 -104
- package/test/fixtures/simpleShapes.js +0 -75
- package/test/static.test.ts +0 -330
- package/vite.config.mts +0 -41
- package/vitest.config-ui.mts +0 -26
- package/vitest.config.mts +0 -26
package/src/math/cubicTools.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { getBezierLength, minmaxC } from './bezier';
|
|
2
|
-
import { type CubicCoordinates } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns a point at a given length of a CubicBezier segment.
|
|
6
|
-
*
|
|
7
|
-
* @param x1 the starting point X
|
|
8
|
-
* @param y1 the starting point Y
|
|
9
|
-
* @param c1x the first control point X
|
|
10
|
-
* @param c1y the first control point Y
|
|
11
|
-
* @param c2x the second control point X
|
|
12
|
-
* @param c2y the second control point Y
|
|
13
|
-
* @param x2 the ending point X
|
|
14
|
-
* @param y2 the ending point Y
|
|
15
|
-
* @param t a [0-1] ratio
|
|
16
|
-
* @returns the point at cubic-bezier segment length
|
|
17
|
-
*/
|
|
18
|
-
const getPointAtCubicSegmentLength = ([x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates, t: number) => {
|
|
19
|
-
const t1 = 1 - t;
|
|
20
|
-
return {
|
|
21
|
-
x: t1 ** 3 * x1 + 3 * t1 ** 2 * t * c1x + 3 * t1 * t ** 2 * c2x + t ** 3 * x2,
|
|
22
|
-
y: t1 ** 3 * y1 + 3 * t1 ** 2 * t * c1y + 3 * t1 * t ** 2 * c2y + t ** 3 * y2,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns the length of a CubicBezier segment.
|
|
28
|
-
*
|
|
29
|
-
* @param x1 the starting point X
|
|
30
|
-
* @param y1 the starting point Y
|
|
31
|
-
* @param c1x the first control point X
|
|
32
|
-
* @param c1y the first control point Y
|
|
33
|
-
* @param c2x the second control point X
|
|
34
|
-
* @param c2y the second control point Y
|
|
35
|
-
* @param x2 the ending point X
|
|
36
|
-
* @param y2 the ending point Y
|
|
37
|
-
* @returns the CubicBezier segment length
|
|
38
|
-
*/
|
|
39
|
-
const getCubicLength = (
|
|
40
|
-
x1: number,
|
|
41
|
-
y1: number,
|
|
42
|
-
c1x: number,
|
|
43
|
-
c1y: number,
|
|
44
|
-
c2x: number,
|
|
45
|
-
c2y: number,
|
|
46
|
-
x2: number,
|
|
47
|
-
y2: number,
|
|
48
|
-
) => {
|
|
49
|
-
return getBezierLength([x1, y1, c1x, c1y, c2x, c2y, x2, y2]);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns the point along a CubicBezier segment at a given distance.
|
|
54
|
-
*
|
|
55
|
-
* @param x1 the starting point X
|
|
56
|
-
* @param y1 the starting point Y
|
|
57
|
-
* @param c1x the first control point X
|
|
58
|
-
* @param c1y the first control point Y
|
|
59
|
-
* @param c2x the second control point X
|
|
60
|
-
* @param c2y the second control point Y
|
|
61
|
-
* @param x2 the ending point X
|
|
62
|
-
* @param y2 the ending point Y
|
|
63
|
-
* @param distance the distance to look at
|
|
64
|
-
* @returns the point at CubicBezier length
|
|
65
|
-
*/
|
|
66
|
-
const getPointAtCubicLength = (
|
|
67
|
-
x1: number,
|
|
68
|
-
y1: number,
|
|
69
|
-
c1x: number,
|
|
70
|
-
c1y: number,
|
|
71
|
-
c2x: number,
|
|
72
|
-
c2y: number,
|
|
73
|
-
x2: number,
|
|
74
|
-
y2: number,
|
|
75
|
-
distance?: number,
|
|
76
|
-
) => {
|
|
77
|
-
const distanceIsNumber = typeof distance === 'number';
|
|
78
|
-
let point = { x: x1, y: y1 };
|
|
79
|
-
/* istanbul ignore else @preserve */
|
|
80
|
-
if (distanceIsNumber) {
|
|
81
|
-
const currentLength = getBezierLength([x1, y1, c1x, c1y, c2x, c2y, x2, y2]);
|
|
82
|
-
if (distance <= 0) {
|
|
83
|
-
// first point already defined
|
|
84
|
-
} else if (distance >= currentLength) {
|
|
85
|
-
point = { x: x2, y: y2 };
|
|
86
|
-
} else {
|
|
87
|
-
point = getPointAtCubicSegmentLength([x1, y1, c1x, c1y, c2x, c2y, x2, y2], distance / currentLength);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return point;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns the boundig box of a CubicBezier segment.
|
|
95
|
-
*
|
|
96
|
-
* @param x1 the starting point X
|
|
97
|
-
* @param y1 the starting point Y
|
|
98
|
-
* @param c1x the first control point X
|
|
99
|
-
* @param c1y the first control point Y
|
|
100
|
-
* @param c2x the second control point X
|
|
101
|
-
* @param c2y the second control point Y
|
|
102
|
-
* @param x2 the ending point X
|
|
103
|
-
* @param y2 the ending point Y
|
|
104
|
-
* @returns the point at CubicBezier length
|
|
105
|
-
*/
|
|
106
|
-
const getCubicBBox = (
|
|
107
|
-
x1: number,
|
|
108
|
-
y1: number,
|
|
109
|
-
c1x: number,
|
|
110
|
-
c1y: number,
|
|
111
|
-
c2x: number,
|
|
112
|
-
c2y: number,
|
|
113
|
-
x2: number,
|
|
114
|
-
y2: number,
|
|
115
|
-
) => {
|
|
116
|
-
const cxMinMax = minmaxC([x1, c1x, c2x, x2]);
|
|
117
|
-
const cyMinMax = minmaxC([y1, c1y, c2y, y2]);
|
|
118
|
-
return {
|
|
119
|
-
min: { x: cxMinMax[0], y: cyMinMax[0] },
|
|
120
|
-
max: { x: cxMinMax[1], y: cyMinMax[1] },
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export { getCubicLength, getCubicBBox, getPointAtCubicLength, getPointAtCubicSegmentLength };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type PointTuple } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the square root of the distance
|
|
5
|
-
* between two given points.
|
|
6
|
-
*
|
|
7
|
-
* @param a the first point coordinates
|
|
8
|
-
* @param b the second point coordinates
|
|
9
|
-
* @returns the distance value
|
|
10
|
-
*/
|
|
11
|
-
const distanceSquareRoot = (a: PointTuple, b: PointTuple) => {
|
|
12
|
-
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default distanceSquareRoot;
|
package/src/math/lineTools.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import midPoint from './midPoint';
|
|
2
|
-
import distanceSquareRoot from './distanceSquareRoot';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns length for line segments (MoveTo, LineTo).
|
|
6
|
-
*
|
|
7
|
-
* @param x1 the starting point X
|
|
8
|
-
* @param y1 the starting point Y
|
|
9
|
-
* @param x2 the ending point X
|
|
10
|
-
* @param y2 the ending point Y
|
|
11
|
-
* @returns the line segment length
|
|
12
|
-
*/
|
|
13
|
-
const getLineLength = (x1: number, y1: number, x2: number, y2: number) => {
|
|
14
|
-
return distanceSquareRoot([x1, y1], [x2, y2]);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Returns a point along the line segments (MoveTo, LineTo).
|
|
19
|
-
*
|
|
20
|
-
* @param x1 the starting point X
|
|
21
|
-
* @param y1 the starting point Y
|
|
22
|
-
* @param x2 the ending point X
|
|
23
|
-
* @param y2 the ending point Y
|
|
24
|
-
* @param distance the distance to point in [0-1] range
|
|
25
|
-
* @returns the point at length
|
|
26
|
-
*/
|
|
27
|
-
const getPointAtLineLength = (x1: number, y1: number, x2: number, y2: number, distance?: number) => {
|
|
28
|
-
let point = { x: x1, y: y1 };
|
|
29
|
-
|
|
30
|
-
/* istanbul ignore else @preserve */
|
|
31
|
-
if (typeof distance === 'number') {
|
|
32
|
-
const length = distanceSquareRoot([x1, y1], [x2, y2]);
|
|
33
|
-
if (distance <= 0) {
|
|
34
|
-
point = { x: x1, y: y1 };
|
|
35
|
-
} else if (distance >= length) {
|
|
36
|
-
point = { x: x2, y: y2 };
|
|
37
|
-
} else {
|
|
38
|
-
const [x, y] = midPoint([x1, y1], [x2, y2], distance / length);
|
|
39
|
-
point = { x, y };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return point;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns bounding box for line segments (MoveTo, LineTo).
|
|
47
|
-
*
|
|
48
|
-
* @param x1 the starting point X
|
|
49
|
-
* @param y1 the starting point Y
|
|
50
|
-
* @param x2 the ending point X
|
|
51
|
-
* @param y2 the ending point Y
|
|
52
|
-
* @param distance the distance to point in [0-1] range
|
|
53
|
-
* @returns the extrema for line segments
|
|
54
|
-
*/
|
|
55
|
-
const getLineBBox = (x1: number, y1: number, x2: number, y2: number) => {
|
|
56
|
-
const { min, max } = Math;
|
|
57
|
-
return {
|
|
58
|
-
min: {
|
|
59
|
-
x: min(x1, x2),
|
|
60
|
-
y: min(y1, y2),
|
|
61
|
-
},
|
|
62
|
-
max: {
|
|
63
|
-
x: max(x1, x2),
|
|
64
|
-
y: max(y1, y2),
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export { getPointAtLineLength, getLineBBox, getLineLength };
|
package/src/math/midPoint.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { PointTuple } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the coordinates of a specified distance
|
|
5
|
-
* ratio between two points.
|
|
6
|
-
*
|
|
7
|
-
* @param a the first point coordinates
|
|
8
|
-
* @param b the second point coordinates
|
|
9
|
-
* @param t the ratio
|
|
10
|
-
* @returns the midpoint coordinates
|
|
11
|
-
*/
|
|
12
|
-
const midPoint = (a: PointTuple, b: PointTuple, t: number): PointTuple => {
|
|
13
|
-
const [ax, ay] = a;
|
|
14
|
-
const [bx, by] = b;
|
|
15
|
-
return [ax + (bx - ax) * t, ay + (by - ay) * t];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default midPoint;
|
package/src/math/polygonTools.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import distanceSquareRoot from './distanceSquareRoot';
|
|
2
|
-
import { type PointTuple } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* d3-polygon-area
|
|
6
|
-
* https://github.com/d3/d3-polygon
|
|
7
|
-
*
|
|
8
|
-
* Returns the area of a polygon.
|
|
9
|
-
*
|
|
10
|
-
* @param polygon an array of coordinates
|
|
11
|
-
* @returns the polygon area
|
|
12
|
-
*/
|
|
13
|
-
const polygonArea = (polygon: PointTuple[]) => {
|
|
14
|
-
const n = polygon.length;
|
|
15
|
-
let i = -1;
|
|
16
|
-
let a: PointTuple;
|
|
17
|
-
let b = polygon[n - 1];
|
|
18
|
-
let area = 0;
|
|
19
|
-
|
|
20
|
-
/* eslint-disable-next-line */
|
|
21
|
-
while (++i < n) {
|
|
22
|
-
a = b;
|
|
23
|
-
b = polygon[i];
|
|
24
|
-
area += a[1] * b[0] - a[0] * b[1];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return area / 2;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* d3-polygon-length
|
|
32
|
-
* https://github.com/d3/d3-polygon
|
|
33
|
-
*
|
|
34
|
-
* Returns the perimeter of a polygon.
|
|
35
|
-
*
|
|
36
|
-
* @param polygon an array of coordinates
|
|
37
|
-
* @returns the polygon length
|
|
38
|
-
*/
|
|
39
|
-
const polygonLength = (polygon: PointTuple[]) => {
|
|
40
|
-
return polygon.reduce((length, point, i) => {
|
|
41
|
-
if (i) {
|
|
42
|
-
return length + distanceSquareRoot(polygon[i - 1], point);
|
|
43
|
-
}
|
|
44
|
-
return 0;
|
|
45
|
-
}, 0);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { polygonArea, polygonLength };
|
package/src/math/quadTools.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { getBezierLength, minmaxQ } from './bezier';
|
|
2
|
-
import { type QuadCoordinates } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns the {x,y} coordinates of a point at a
|
|
6
|
-
* given length of a quadratic-bezier segment.
|
|
7
|
-
*
|
|
8
|
-
* @see https://github.com/substack/point-at-length
|
|
9
|
-
*
|
|
10
|
-
* @param x1 the starting point X
|
|
11
|
-
* @param y1 the starting point Y
|
|
12
|
-
* @param cx the control point X
|
|
13
|
-
* @param cy the control point Y
|
|
14
|
-
* @param x2 the ending point X
|
|
15
|
-
* @param y2 the ending point Y
|
|
16
|
-
* @param t a [0-1] ratio
|
|
17
|
-
* @returns the requested {x,y} coordinates
|
|
18
|
-
*/
|
|
19
|
-
const getPointAtQuadSegmentLength = ([x1, y1, cx, cy, x2, y2]: QuadCoordinates, t: number) => {
|
|
20
|
-
const t1 = 1 - t;
|
|
21
|
-
return {
|
|
22
|
-
x: t1 ** 2 * x1 + 2 * t1 * t * cx + t ** 2 * x2,
|
|
23
|
-
y: t1 ** 2 * y1 + 2 * t1 * t * cy + t ** 2 * y2,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns the length of a QuadraticBezier segment.
|
|
29
|
-
*
|
|
30
|
-
* @param x1 the starting point X
|
|
31
|
-
* @param y1 the starting point Y
|
|
32
|
-
* @param cx the control point X
|
|
33
|
-
* @param cy the control point Y
|
|
34
|
-
* @param x2 the ending point X
|
|
35
|
-
* @param y2 the ending point Y
|
|
36
|
-
* @returns the QuadraticBezier segment length
|
|
37
|
-
*/
|
|
38
|
-
const getQuadLength = (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => {
|
|
39
|
-
return getBezierLength([x1, y1, cx, cy, x2, y2]);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Returns the point along a QuadraticBezier segment at a given distance.
|
|
44
|
-
*
|
|
45
|
-
* @param x1 the starting point X
|
|
46
|
-
* @param y1 the starting point Y
|
|
47
|
-
* @param cx the control point X
|
|
48
|
-
* @param cy the control point Y
|
|
49
|
-
* @param x2 the ending point X
|
|
50
|
-
* @param y2 the ending point Y
|
|
51
|
-
* @param distance the distance to look at
|
|
52
|
-
* @returns the point at QuadraticBezier length
|
|
53
|
-
*/
|
|
54
|
-
const getPointAtQuadLength = (
|
|
55
|
-
x1: number,
|
|
56
|
-
y1: number,
|
|
57
|
-
cx: number,
|
|
58
|
-
cy: number,
|
|
59
|
-
x2: number,
|
|
60
|
-
y2: number,
|
|
61
|
-
distance?: number,
|
|
62
|
-
) => {
|
|
63
|
-
const distanceIsNumber = typeof distance === 'number';
|
|
64
|
-
let point = { x: x1, y: y1 };
|
|
65
|
-
|
|
66
|
-
/* istanbul ignore else @preserve */
|
|
67
|
-
if (distanceIsNumber) {
|
|
68
|
-
const currentLength = getBezierLength([x1, y1, cx, cy, x2, y2]);
|
|
69
|
-
if (distance <= 0) {
|
|
70
|
-
// first point already defined
|
|
71
|
-
} else if (distance >= currentLength) {
|
|
72
|
-
point = { x: x2, y: y2 };
|
|
73
|
-
} else {
|
|
74
|
-
point = getPointAtQuadSegmentLength([x1, y1, cx, cy, x2, y2], distance / currentLength);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return point;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns the boundig box of a QuadraticBezier segment.
|
|
82
|
-
*
|
|
83
|
-
* @param x1 the starting point X
|
|
84
|
-
* @param y1 the starting point Y
|
|
85
|
-
* @param cx the control point X
|
|
86
|
-
* @param cy the control point Y
|
|
87
|
-
* @param x2 the ending point X
|
|
88
|
-
* @param y2 the ending point Y
|
|
89
|
-
* @returns the point at CubicBezier length
|
|
90
|
-
*/
|
|
91
|
-
const getQuadBBox = (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => {
|
|
92
|
-
const cxMinMax = minmaxQ([x1, cx, x2]);
|
|
93
|
-
const cyMinMax = minmaxQ([y1, cy, y2]);
|
|
94
|
-
return {
|
|
95
|
-
min: { x: cxMinMax[0], y: cyMinMax[0] },
|
|
96
|
-
max: { x: cxMinMax[1], y: cyMinMax[1] },
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export { getPointAtQuadSegmentLength, getQuadLength, getQuadBBox, getPointAtQuadLength };
|
package/src/math/rotateVector.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an {x,y} vector rotated by a given
|
|
3
|
-
* angle in radian.
|
|
4
|
-
*
|
|
5
|
-
* @param x the initial vector x
|
|
6
|
-
* @param y the initial vector y
|
|
7
|
-
* @param rad the radian vector angle
|
|
8
|
-
* @returns the rotated vector
|
|
9
|
-
*/
|
|
10
|
-
const rotateVector = (x: number, y: number, rad: number): { x: number; y: number } => {
|
|
11
|
-
const { sin, cos } = Math;
|
|
12
|
-
const X = x * cos(rad) - y * sin(rad);
|
|
13
|
-
const Y = x * sin(rad) + y * cos(rad);
|
|
14
|
-
return { x: X, y: Y };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default rotateVector;
|
package/src/math/roundTo.ts
DELETED
package/src/options/options.ts
DELETED
package/src/parser/error.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import paramsCount from './paramsCount';
|
|
2
|
-
import PathParser from './pathParser';
|
|
3
|
-
import type { PathCommand, PathSegment, RelativeCommand } from '../types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Breaks the parsing of a pathString once a segment is finalized.
|
|
7
|
-
*
|
|
8
|
-
* @param path the `PathParser` instance
|
|
9
|
-
*/
|
|
10
|
-
const finalizeSegment = (path: PathParser) => {
|
|
11
|
-
let pathCommand = path.pathValue[path.segmentStart] as PathCommand;
|
|
12
|
-
let relativeCommand = pathCommand.toLowerCase() as RelativeCommand;
|
|
13
|
-
const { data } = path;
|
|
14
|
-
|
|
15
|
-
while (data.length >= paramsCount[relativeCommand]) {
|
|
16
|
-
// overloaded `moveTo`
|
|
17
|
-
// https://github.com/rveciana/svg-path-properties/blob/master/src/parse.ts
|
|
18
|
-
if (relativeCommand === 'm' && data.length > 2) {
|
|
19
|
-
path.segments.push([pathCommand as PathCommand | number].concat(data.splice(0, 2) as number[]) as PathSegment);
|
|
20
|
-
relativeCommand = 'l';
|
|
21
|
-
pathCommand = pathCommand === 'm' ? 'l' : 'L';
|
|
22
|
-
} else {
|
|
23
|
-
path.segments.push(
|
|
24
|
-
[pathCommand as PathCommand | number].concat(
|
|
25
|
-
data.splice(0, paramsCount[relativeCommand]) as number[],
|
|
26
|
-
) as PathSegment,
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!paramsCount[relativeCommand]) {
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
export default finalizeSegment;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the character is an A (arc-to) path command.
|
|
3
|
-
*
|
|
4
|
-
* @param code the character to check
|
|
5
|
-
* @returns check result
|
|
6
|
-
*/
|
|
7
|
-
const isArcCommand = (code: number): code is 0x61 => {
|
|
8
|
-
// eslint-disable-next-line no-bitwise -- Impossible to satisfy
|
|
9
|
-
return (code | 0x20) === 0x61;
|
|
10
|
-
};
|
|
11
|
-
export default isArcCommand;
|
package/src/parser/isDigit.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DigitNumber } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a character is a digit.
|
|
5
|
-
*
|
|
6
|
-
* @param code the character to check
|
|
7
|
-
* @returns check result
|
|
8
|
-
*/
|
|
9
|
-
const isDigit = (code: number): code is DigitNumber => {
|
|
10
|
-
return code >= 48 && code <= 57; // 0..9
|
|
11
|
-
};
|
|
12
|
-
export default isDigit;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import isDigit from './isDigit';
|
|
2
|
-
import type { DigitNumber } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Checks if the character is or belongs to a number.
|
|
6
|
-
* [0-9]|+|-|.
|
|
7
|
-
*
|
|
8
|
-
* @param code the character to check
|
|
9
|
-
* @returns check result
|
|
10
|
-
*/
|
|
11
|
-
const isDigitStart = (code: number): code is DigitNumber | 0x2b | 0x2d | 0x2e => {
|
|
12
|
-
return isDigit(code) /* 0..9 */ || code === 0x2b /* + */ || code === 0x2d /* - */ || code === 0x2e; /* . */
|
|
13
|
-
};
|
|
14
|
-
export default isDigitStart;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the character is a MoveTo command.
|
|
3
|
-
*
|
|
4
|
-
* @param code the character to check
|
|
5
|
-
* @returns check result
|
|
6
|
-
*/
|
|
7
|
-
const isMoveCommand = (code: number): code is 0x6d | 0x4d => {
|
|
8
|
-
// eslint-disable-next-line no-bitwise -- Impossible to satisfy
|
|
9
|
-
switch (code | 0x20) {
|
|
10
|
-
case 0x6d /* m */:
|
|
11
|
-
case 0x4d /* M */:
|
|
12
|
-
return true;
|
|
13
|
-
default:
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export default isMoveCommand;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { PathCommandNumber } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the character is a path command.
|
|
5
|
-
*
|
|
6
|
-
* @param code the character to check
|
|
7
|
-
* @returns check result
|
|
8
|
-
*/
|
|
9
|
-
const isPathCommand = (code: number): code is PathCommandNumber => {
|
|
10
|
-
// eslint-disable-next-line no-bitwise -- Impossible to satisfy
|
|
11
|
-
switch (code | 0x20) {
|
|
12
|
-
case 0x6d /* m */:
|
|
13
|
-
case 0x7a /* z */:
|
|
14
|
-
case 0x6c /* l */:
|
|
15
|
-
case 0x68 /* h */:
|
|
16
|
-
case 0x76 /* v */:
|
|
17
|
-
case 0x63 /* c */:
|
|
18
|
-
case 0x73 /* s */:
|
|
19
|
-
case 0x71 /* q */:
|
|
20
|
-
case 0x74 /* t */:
|
|
21
|
-
case 0x61 /* a */:
|
|
22
|
-
// case 0x72/* r */:
|
|
23
|
-
return true;
|
|
24
|
-
default:
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export default isPathCommand;
|
package/src/parser/isSpace.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { SpaceNumber } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the character is a space.
|
|
5
|
-
*
|
|
6
|
-
* @param ch the character to check
|
|
7
|
-
* @returns check result
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const isSpace = (ch: number): ch is SpaceNumber => {
|
|
11
|
-
const allSpaces = [
|
|
12
|
-
// Special spaces
|
|
13
|
-
0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x202f,
|
|
14
|
-
0x205f, 0x3000, 0xfeff,
|
|
15
|
-
// Line terminators
|
|
16
|
-
0x0a, 0x0d, 0x2028, 0x2029,
|
|
17
|
-
// White spaces
|
|
18
|
-
0x20, 0x09, 0x0b, 0x0c, 0xa0,
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
return allSpaces.includes(ch);
|
|
22
|
-
};
|
|
23
|
-
export default isSpace;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import scanSegment from './scanSegment';
|
|
2
|
-
import skipSpaces from './skipSpaces';
|
|
3
|
-
import PathParser from './pathParser';
|
|
4
|
-
import type { PathArray } from '../types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Parses a path string value and returns an array
|
|
8
|
-
* of segments we like to call `pathArray`.
|
|
9
|
-
*
|
|
10
|
-
* @param pathInput the string to be parsed
|
|
11
|
-
* @returns the resulted `pathArray` or error string
|
|
12
|
-
*/
|
|
13
|
-
const parsePathString = <T extends PathArray>(pathInput: string | T) => {
|
|
14
|
-
if (typeof pathInput !== 'string') {
|
|
15
|
-
return pathInput.slice(0) as typeof pathInput;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const path = new PathParser(pathInput);
|
|
19
|
-
|
|
20
|
-
skipSpaces(path);
|
|
21
|
-
|
|
22
|
-
while (path.index < path.max && !path.err.length) {
|
|
23
|
-
scanSegment(path);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (path?.err.length) {
|
|
27
|
-
throw TypeError(path.err);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return path.segments as PathArray;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default parsePathString;
|
package/src/parser/pathParser.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { PathArray, PathSegment } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The `PathParser` is used by the `parsePathString` static method
|
|
5
|
-
* to generate a `pathArray`.
|
|
6
|
-
*
|
|
7
|
-
* @param pathString
|
|
8
|
-
*/
|
|
9
|
-
export default class PathParser {
|
|
10
|
-
declare segments: PathArray | PathSegment[];
|
|
11
|
-
declare pathValue: string;
|
|
12
|
-
declare max: number;
|
|
13
|
-
declare index: number;
|
|
14
|
-
declare param: number;
|
|
15
|
-
declare segmentStart: number;
|
|
16
|
-
declare data: (string | number)[];
|
|
17
|
-
declare err: string;
|
|
18
|
-
|
|
19
|
-
constructor(pathString: string) {
|
|
20
|
-
this.segments = [];
|
|
21
|
-
this.pathValue = pathString;
|
|
22
|
-
this.max = pathString.length;
|
|
23
|
-
this.index = 0;
|
|
24
|
-
this.param = 0.0;
|
|
25
|
-
this.segmentStart = 0;
|
|
26
|
-
this.data = [];
|
|
27
|
-
this.err = '';
|
|
28
|
-
}
|
|
29
|
-
}
|