svg-path-commander 2.1.1 → 2.1.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.
Files changed (56) hide show
  1. package/README.md +2 -2
  2. package/dist/svg-path-commander.cjs +1 -1
  3. package/dist/svg-path-commander.cjs.map +1 -1
  4. package/dist/svg-path-commander.d.ts +207 -19
  5. package/dist/svg-path-commander.js +1 -1
  6. package/dist/svg-path-commander.js.map +1 -1
  7. package/dist/svg-path-commander.mjs +1052 -969
  8. package/dist/svg-path-commander.mjs.map +1 -1
  9. package/package.json +7 -7
  10. package/src/convert/pathToAbsolute.ts +2 -31
  11. package/src/convert/pathToCurve.ts +13 -27
  12. package/src/convert/pathToRelative.ts +2 -47
  13. package/src/convert/pathToString.ts +40 -7
  14. package/src/index.ts +132 -39
  15. package/src/interface.ts +2 -1
  16. package/src/math/arcTools.ts +53 -51
  17. package/src/math/bezier.ts +41 -33
  18. package/src/math/cubicTools.ts +10 -8
  19. package/src/math/distanceSquareRoot.ts +1 -1
  20. package/src/math/lineTools.ts +6 -4
  21. package/src/math/polygonTools.ts +48 -0
  22. package/src/math/quadTools.ts +8 -6
  23. package/src/math/rotateVector.ts +3 -2
  24. package/src/math/roundTo.ts +7 -0
  25. package/src/parser/finalizeSegment.ts +11 -7
  26. package/src/parser/parsePathString.ts +2 -3
  27. package/src/parser/pathParser.ts +1 -1
  28. package/src/process/absolutizeSegment.ts +35 -30
  29. package/src/process/arcToCubic.ts +2 -2
  30. package/src/process/iterate.ts +41 -16
  31. package/src/process/lineToCubic.ts +1 -1
  32. package/src/process/normalizePath.ts +14 -31
  33. package/src/process/normalizeSegment.ts +53 -15
  34. package/src/process/optimizePath.ts +40 -60
  35. package/src/process/projection2d.ts +2 -2
  36. package/src/process/relativizeSegment.ts +33 -35
  37. package/src/process/reverseCurve.ts +8 -5
  38. package/src/process/reversePath.ts +87 -74
  39. package/src/process/roundPath.ts +14 -8
  40. package/src/process/roundSegment.ts +9 -0
  41. package/src/process/segmentToCubic.ts +9 -7
  42. package/src/process/shortenSegment.ts +24 -32
  43. package/src/process/splitCubic.ts +2 -2
  44. package/src/process/transformPath.ts +35 -40
  45. package/src/types.ts +7 -11
  46. package/src/util/getPathArea.ts +2 -2
  47. package/src/util/getPathBBox.ts +25 -42
  48. package/src/util/getPointAtLength.ts +51 -49
  49. package/src/util/getPropertiesAtLength.ts +4 -5
  50. package/src/util/getPropertiesAtPoint.ts +5 -5
  51. package/src/util/getTotalLength.ts +23 -38
  52. package/test/class.test.ts +2 -0
  53. package/test/fixtures/shapes.js +5 -5
  54. package/test/static.test.ts +18 -12
  55. package/src/math/polygonArea.ts +0 -29
  56. package/src/math/polygonLength.ts +0 -22
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svg-path-commander",
3
3
  "author": "thednp",
4
4
  "license": "MIT",
5
- "version": "2.1.1",
5
+ "version": "2.1.2",
6
6
  "description": "Modern TypeScript tools for SVG",
7
7
  "source": "./src/index.ts",
8
8
  "main": "./dist/svg-path-commander.js",
@@ -40,19 +40,19 @@
40
40
  "devDependencies": {
41
41
  "@typescript-eslint/eslint-plugin": "^5.62.0",
42
42
  "@typescript-eslint/parser": "^5.62.0",
43
- "@vitest/browser": "^2.1.2",
44
- "@vitest/coverage-istanbul": "^2.1.2",
45
- "@vitest/ui": "^2.1.2",
43
+ "@vitest/browser": "^2.1.3",
44
+ "@vitest/coverage-istanbul": "^2.1.3",
45
+ "@vitest/ui": "^2.1.3",
46
46
  "dts-bundle-generator": "^9.5.1",
47
47
  "eslint": "^8.57.1",
48
48
  "eslint-plugin-jsdoc": "^46.10.1",
49
49
  "eslint-plugin-prefer-arrow": "^1.2.3",
50
50
  "eslint-plugin-prettier": "^4.2.1",
51
- "playwright": "^1.48.0",
51
+ "playwright": "^1.48.1",
52
52
  "prettier": "^2.8.8",
53
53
  "typescript": "^5.6.3",
54
- "vite": "^5.4.8",
55
- "vitest": "^2.1.2"
54
+ "vite": "^5.4.9",
55
+ "vitest": "^2.1.3"
56
56
  },
57
57
  "dependencies": {
58
58
  "@thednp/dommatrix": "^2.0.8"
@@ -1,6 +1,6 @@
1
1
  import parsePathString from '../parser/parsePathString';
2
2
  import absolutizeSegment from '../process/absolutizeSegment';
3
- import type { AbsoluteArray, AbsoluteCommand, HSegment, PathArray, PointTuple, VSegment } from '../types';
3
+ import type { AbsoluteArray, PathArray } from '../types';
4
4
  import iterate from '../process/iterate';
5
5
 
6
6
  /**
@@ -11,37 +11,8 @@ import iterate from '../process/iterate';
11
11
  * @returns the resulted `pathArray` with absolute values
12
12
  */
13
13
  const pathToAbsolute = (pathInput: string | PathArray) => {
14
- let x = 0;
15
- let y = 0;
16
- let mx = 0;
17
- let my = 0;
18
- let pathCommand = 'M';
19
14
  const path = parsePathString(pathInput);
20
15
 
21
- return iterate<AbsoluteArray>(path, (seg, params) => {
22
- [pathCommand] = seg;
23
- const result = absolutizeSegment(seg, params);
24
- const absCommand = pathCommand.toUpperCase() as AbsoluteCommand;
25
-
26
- if (absCommand === 'Z') {
27
- x = mx;
28
- y = my;
29
- } else if (absCommand === 'H') {
30
- [, x] = result as HSegment;
31
- } else if (absCommand === 'V') {
32
- [, y] = result as VSegment;
33
- } else {
34
- [x, y] = result.slice(-2) as PointTuple;
35
-
36
- if (absCommand === 'M') {
37
- mx = x;
38
- my = y;
39
- }
40
- }
41
-
42
- params.x = x;
43
- params.y = y;
44
- return result;
45
- });
16
+ return iterate<AbsoluteArray>(path, absolutizeSegment);
46
17
  };
47
18
  export default pathToAbsolute;
@@ -1,9 +1,9 @@
1
1
  import segmentToCubic from '../process/segmentToCubic';
2
- import { AbsoluteCommand, CSegment, CurveArray, PathArray, PointTuple } from '../types';
2
+ import { AbsoluteCommand, CSegment, CurveArray, PathArray } from '../types';
3
3
  import iterate from '../process/iterate';
4
4
  import parsePathString from '../parser/parsePathString';
5
5
  import normalizeSegment from '../process/normalizeSegment';
6
- import absolutizeSegment from '../process/absolutizeSegment';
6
+ import paramsParser from '../parser/paramsParser';
7
7
 
8
8
  /**
9
9
  * Parses a path string value or 'pathArray' and returns a new one
@@ -16,41 +16,27 @@ import absolutizeSegment from '../process/absolutizeSegment';
16
16
  * @returns the resulted `pathArray` converted to cubic-bezier
17
17
  */
18
18
  const pathToCurve = (pathInput: string | PathArray): CurveArray => {
19
- let x = 0;
20
- let y = 0;
21
- let mx = 0;
22
- let my = 0;
23
- let pathCommand = 'M';
24
-
19
+ const params = { ...paramsParser };
25
20
  const path = parsePathString(pathInput);
26
- return iterate<CurveArray>(path, (seg, params, i) => {
27
- const absSegment = absolutizeSegment(seg, params);
28
- [pathCommand] = absSegment;
29
21
 
30
- const absCommand = pathCommand.toUpperCase() as AbsoluteCommand;
31
- const normalSegment = normalizeSegment(absSegment, params);
22
+ return iterate<CurveArray>(path, (seg, index, lastX, lastY) => {
23
+ params.x = lastX;
24
+ params.y = lastY;
25
+ const normalSegment = normalizeSegment(seg, params);
32
26
  let result = segmentToCubic(normalSegment, params);
33
27
  const isLongArc = result[0] === 'C' && result.length > 7;
34
28
 
35
29
  if (isLongArc) {
36
- path.splice(i + 1, 0, ['C', ...result.slice(7)] as CSegment);
30
+ path.splice(index + 1, 0, ['C' as AbsoluteCommand | number].concat(result.slice(7)) as CSegment);
37
31
  result = result.slice(0, 7) as CSegment;
38
32
  }
39
33
 
40
- if (absCommand === 'Z') {
41
- x = mx;
42
- y = my;
43
- } else {
44
- [x, y] = result.slice(-2) as PointTuple;
45
-
46
- if (absCommand === 'M') {
47
- mx = x;
48
- my = y;
49
- }
50
- }
34
+ const seglen = result.length;
35
+ params.x1 = +result[seglen - 2];
36
+ params.y1 = +result[seglen - 1];
37
+ params.x2 = +result[seglen - 4] || params.x1;
38
+ params.y2 = +result[seglen - 3] || params.y1;
51
39
 
52
- params.x = x;
53
- params.y = y;
54
40
  return result;
55
41
  });
56
42
  };
@@ -1,12 +1,4 @@
1
- import type {
2
- AbsoluteCommand,
3
- hSegment,
4
- PathArray,
5
- PointTuple,
6
- RelativeArray,
7
- RelativeCommand,
8
- vSegment,
9
- } from '../types';
1
+ import type { PathArray, RelativeArray } from '../types';
10
2
  import parsePathString from '../parser/parsePathString';
11
3
  import iterate from '../process/iterate';
12
4
  import relativizeSegment from '../process/relativizeSegment';
@@ -19,45 +11,8 @@ import relativizeSegment from '../process/relativizeSegment';
19
11
  * @returns the resulted `pathArray` with relative values
20
12
  */
21
13
  const pathToRelative = (pathInput: string | PathArray): RelativeArray => {
22
- let x = 0;
23
- let y = 0;
24
- let mx = 0;
25
- let my = 0;
26
- let pathCommand = 'M';
27
14
  const path = parsePathString(pathInput);
28
15
 
29
- return iterate<RelativeArray>(path, (seg, params, i) => {
30
- [pathCommand] = seg;
31
- const result = relativizeSegment(seg, params, i);
32
- const [resultedCommand] = result;
33
- const absCommand = pathCommand.toUpperCase() as AbsoluteCommand;
34
- const relCommand = pathCommand.toLowerCase() as RelativeCommand;
35
- const isRelative = resultedCommand === relCommand;
36
-
37
- if (absCommand === 'Z') {
38
- x = mx;
39
- y = my;
40
- } else if (absCommand === 'H') {
41
- [, x] = result as hSegment;
42
- x += isRelative ? params.x : /* istanbul ignore next @preserve */ 0;
43
- } else if (absCommand === 'V') {
44
- [, y] = result as vSegment;
45
- y += isRelative ? params.y : /* istanbul ignore next @preserve */ 0;
46
- } else {
47
- [x, y] = result.slice(-2) as PointTuple;
48
- x += isRelative ? params.x : 0;
49
- y += isRelative ? params.y : 0;
50
-
51
- if (absCommand === 'M') {
52
- mx = x;
53
- my = y;
54
- }
55
- }
56
-
57
- params.x = x;
58
- params.y = y;
59
-
60
- return result;
61
- });
16
+ return iterate<RelativeArray>(path, relativizeSegment);
62
17
  };
63
18
  export default pathToRelative;
@@ -1,17 +1,50 @@
1
- import type { PathArray } from '../types';
2
- import roundPath from '../process/roundPath';
1
+ import type { PathArray, PathSegment } from '../types';
2
+ import defaultOptions from '../options/options';
3
+ import roundTo from '../math/roundTo';
3
4
 
4
5
  /**
5
6
  * Returns a valid `d` attribute string value created
6
7
  * by rounding values and concatenating the `pathArray` segments.
7
8
  *
8
9
  * @param path the `pathArray` object
9
- * @param round amount of decimals to round values to
10
+ * @param roundOption amount of decimals to round values to
10
11
  * @returns the concatenated path string
11
12
  */
12
- const pathToString = (path: PathArray, round?: number | 'off'): string => {
13
- return roundPath(path, round)
14
- .map(x => x[0] + x.slice(1).join(' '))
15
- .join('');
13
+ const pathToString = (path: PathArray, roundOption?: number | 'off'): string => {
14
+ const pathLen = path.length;
15
+ let { round } = defaultOptions;
16
+ let segment = path[0] as PathSegment;
17
+ let result = '';
18
+
19
+ // allow for ZERO decimals
20
+ round =
21
+ roundOption === 'off'
22
+ ? roundOption
23
+ : typeof roundOption === 'number' && roundOption >= 0
24
+ ? roundOption
25
+ : typeof round === 'number' && round >= 0
26
+ ? round
27
+ : /* istanbul ignore next @preserve */ 'off';
28
+
29
+ for (let i = 0; i < pathLen; i += 1) {
30
+ segment = path[i];
31
+ const [pathCommand] = segment;
32
+ const values = segment.slice(1) as number[];
33
+ result += pathCommand;
34
+ if (round === 'off') {
35
+ result += values.join(' ');
36
+ } else {
37
+ let j = 0;
38
+ const valLen = values.length;
39
+ while (j < valLen) {
40
+ result += roundTo(values[j], round);
41
+ if (j !== valLen - 1) result += ' ';
42
+ j += 1;
43
+ }
44
+ }
45
+ }
46
+
47
+ return result;
16
48
  };
49
+
17
50
  export default pathToString;
package/src/index.ts CHANGED
@@ -1,53 +1,99 @@
1
1
  'use strict';
2
+ import CSSMatrix from '@thednp/dommatrix';
2
3
  import { PointTuple, PathArray, TransformObjectValues } from './types';
3
4
  import type { Options, TransformEntries, TransformObject } from './interface';
4
5
  export * from './types';
5
6
  export * from './interface';
6
7
  import defaultOptions from './options/options';
7
8
 
9
+ import pathToAbsolute from './convert/pathToAbsolute';
10
+ import pathToRelative from './convert/pathToRelative';
11
+ import pathToCurve from './convert/pathToCurve';
12
+ import pathToString from './convert/pathToString';
13
+ import * as arcTools from './math/arcTools';
14
+ import {
15
+ Cvalues,
16
+ Tvalues,
17
+ minmaxC,
18
+ minmaxQ,
19
+ getBezierLength,
20
+ bezierLength,
21
+ calculateBezier,
22
+ computeBezier,
23
+ deriveBezier,
24
+ CBEZIER_MINMAX_EPSILON,
25
+ } from './math/bezier';
26
+ import { getCubicLength, getCubicBBox, getPointAtCubicLength, getPointAtCubicSegmentLength } from './math/cubicTools';
27
+ import { getPointAtLineLength, getLineBBox, getLineLength } from './math/lineTools';
28
+ import { getPointAtQuadSegmentLength, getQuadLength, getQuadBBox, getPointAtQuadLength } from './math/quadTools';
29
+ import { polygonArea, polygonLength } from './math/polygonTools';
30
+
31
+ import distanceSquareRoot from './math/distanceSquareRoot';
32
+ import midPoint from './math/midPoint';
33
+ import rotateVector from './math/rotateVector';
34
+ import roundTo from './math/roundTo';
35
+
8
36
  import error from './parser/error';
9
37
  import parsePathString from './parser/parsePathString';
10
-
11
- import polygonArea from './math/polygonArea';
12
- import polygonLength from './math/polygonLength';
13
-
14
- import CSSMatrix from '@thednp/dommatrix';
15
- import getPathBBox from './util/getPathBBox';
16
- import getPathArea from './util/getPathArea';
17
- import getTotalLength from './util/getTotalLength';
38
+ import finalizeSegment from './parser/finalizeSegment';
39
+ import invalidPathValue from './parser/invalidPathValue';
40
+ import isArcCommand from './parser/isArcCommand';
41
+ import isDigit from './parser/isDigit';
42
+ import isDigitStart from './parser/isDigitStart';
43
+ import isMoveCommand from './parser/isMoveCommand';
44
+ import isPathCommand from './parser/isPathCommand';
45
+ import isSpace from './parser/isSpace';
46
+ import paramsCount from './parser/paramsCount';
47
+ import paramsParser from './parser/paramsParser';
48
+ import pathParser from './parser/pathParser';
49
+ import scanFlag from './parser/scanFlag';
50
+ import scanParam from './parser/scanParam';
51
+ import scanSegment from './parser/scanSegment';
52
+ import skipSpaces from './parser/skipSpaces';
53
+
54
+ import distanceEpsilon from './util/distanceEpsilon';
55
+ import getClosestPoint from './util/getClosestPoint';
18
56
  import getDrawDirection from './util/getDrawDirection';
57
+ import getPathArea from './util/getPathArea';
58
+ import getPathBBox from './util/getPathBBox';
19
59
  import getPointAtLength from './util/getPointAtLength';
20
-
21
60
  import getPropertiesAtLength from './util/getPropertiesAtLength';
22
61
  import getPropertiesAtPoint from './util/getPropertiesAtPoint';
23
- import getClosestPoint from './util/getClosestPoint';
24
- import getSegmentOfPoint from './util/getSegmentOfPoint';
25
62
  import getSegmentAtLength from './util/getSegmentAtLength';
26
- import isPointInStroke from './util/isPointInStroke';
63
+ import getSegmentOfPoint from './util/getSegmentOfPoint';
64
+ import getTotalLength from './util/getTotalLength';
27
65
 
28
- import isValidPath from './util/isValidPath';
29
- import isPathArray from './util/isPathArray';
30
66
  import isAbsoluteArray from './util/isAbsoluteArray';
31
- import isRelativeArray from './util/isRelativeArray';
32
67
  import isCurveArray from './util/isCurveArray';
33
68
  import isNormalizedArray from './util/isNormalizedArray';
34
- import shapeToPathArray from './util/shapeToPathArray';
69
+ import isPathArray from './util/isPathArray';
70
+ import isPointInStroke from './util/isPointInStroke';
71
+ import isRelativeArray from './util/isRelativeArray';
72
+ import isValidPath from './util/isValidPath';
73
+ import shapeParams from './util/shapeParams';
35
74
  import shapeToPath from './util/shapeToPath';
75
+ import shapeToPathArray from './util/shapeToPathArray';
36
76
 
37
- import roundPath from './process/roundPath';
38
- import splitPath from './process/splitPath';
77
+ import absolutizeSegment from './process/absolutizeSegment';
78
+ import arcToCubic from './process/arcToCubic';
39
79
  import getSVGMatrix from './process/getSVGMatrix';
80
+ import iterate from './process/iterate';
81
+ import lineToCubic from './process/lineToCubic';
82
+ import normalizePath from './process/normalizePath';
83
+ import normalizeSegment from './process/normalizeSegment';
40
84
  import optimizePath from './process/optimizePath';
85
+ import projection2d from './process/projection2d';
86
+ import quadToCubic from './process/quadToCubic';
87
+ import relativizeSegment from './process/relativizeSegment';
41
88
  import reverseCurve from './process/reverseCurve';
42
89
  import reversePath from './process/reversePath';
43
- import normalizePath from './process/normalizePath';
44
- import transformPath from './process/transformPath';
90
+ import roundPath from './process/roundPath';
91
+ import roundSegment from './process/roundSegment';
92
+ import segmentToCubic from './process/segmentToCubic';
93
+ import shortenSegment from './process/shortenSegment';
45
94
  import splitCubic from './process/splitCubic';
46
-
47
- import pathToAbsolute from './convert/pathToAbsolute';
48
- import pathToRelative from './convert/pathToRelative';
49
- import pathToCurve from './convert/pathToCurve';
50
- import pathToString from './convert/pathToString';
95
+ import splitPath from './process/splitPath';
96
+ import transformPath from './process/transformPath';
51
97
 
52
98
  /**
53
99
  * Creates a new SVGPathCommander instance with the following properties:
@@ -61,7 +107,47 @@ import pathToString from './convert/pathToString';
61
107
  */
62
108
  class SVGPathCommander {
63
109
  public static CSSMatrix = CSSMatrix;
64
- public static getSVGMatrix = getSVGMatrix;
110
+ public static pathToAbsolute = pathToAbsolute;
111
+ public static pathToRelative = pathToRelative;
112
+ public static pathToCurve = pathToCurve;
113
+ public static pathToString = pathToString;
114
+ public static arcTools = arcTools;
115
+ public static bezierTools = {
116
+ Cvalues,
117
+ Tvalues,
118
+ minmaxC,
119
+ minmaxQ,
120
+ getBezierLength,
121
+ bezierLength,
122
+ calculateBezier,
123
+ computeBezier,
124
+ deriveBezier,
125
+ CBEZIER_MINMAX_EPSILON,
126
+ };
127
+ public static cubicTools = { getCubicLength, getCubicBBox, getPointAtCubicLength, getPointAtCubicSegmentLength };
128
+ public static lineTools = { getPointAtLineLength, getLineBBox, getLineLength };
129
+ public static quadTools = { getPointAtQuadSegmentLength, getQuadLength, getQuadBBox, getPointAtQuadLength };
130
+ public static polygonTools = { polygonArea, polygonLength };
131
+ public static distanceSquareRoot = distanceSquareRoot;
132
+ public static distanceEpsilon = distanceEpsilon;
133
+ public static midPoint = midPoint;
134
+ public static rotateVector = rotateVector;
135
+ public static roundTo = roundTo;
136
+ public static finalizeSegment = finalizeSegment;
137
+ public static invalidPathValue = invalidPathValue;
138
+ public static isArcCommand = isArcCommand;
139
+ public static isDigit = isDigit;
140
+ public static isDigitStart = isDigitStart;
141
+ public static isMoveCommand = isMoveCommand;
142
+ public static isPathCommand = isPathCommand;
143
+ public static isSpace = isSpace;
144
+ public static paramsCount = paramsCount;
145
+ public static paramsParser = paramsParser;
146
+ public static pathParser = pathParser;
147
+ public static scanFlag = scanFlag;
148
+ public static scanParam = scanParam;
149
+ public static scanSegment = scanSegment;
150
+ public static skipSpaces = skipSpaces;
65
151
  public static getPathBBox = getPathBBox;
66
152
  public static getPathArea = getPathArea;
67
153
  public static getTotalLength = getTotalLength;
@@ -69,8 +155,6 @@ class SVGPathCommander {
69
155
  public static getPointAtLength = getPointAtLength;
70
156
  public static getPropertiesAtLength = getPropertiesAtLength;
71
157
  public static getPropertiesAtPoint = getPropertiesAtPoint;
72
- public static polygonLength = polygonLength;
73
- public static polygonArea = polygonArea;
74
158
  public static getClosestPoint = getClosestPoint;
75
159
  public static getSegmentOfPoint = getSegmentOfPoint;
76
160
  public static getSegmentAtLength = getSegmentAtLength;
@@ -83,19 +167,28 @@ class SVGPathCommander {
83
167
  public static isNormalizedArray = isNormalizedArray;
84
168
  public static shapeToPath = shapeToPath;
85
169
  public static shapeToPathArray = shapeToPathArray;
170
+ public static shapeParams = shapeParams;
86
171
  public static parsePathString = parsePathString;
87
- public static roundPath = roundPath;
88
- public static splitPath = splitPath;
89
- public static splitCubic = splitCubic;
172
+ public static absolutizeSegment = absolutizeSegment;
173
+ public static arcToCubic = arcToCubic;
174
+ public static getSVGMatrix = getSVGMatrix;
175
+ public static iterate = iterate;
176
+ public static lineToCubic = lineToCubic;
177
+ public static normalizePath = normalizePath;
178
+ public static normalizeSegment = normalizeSegment;
90
179
  public static optimizePath = optimizePath;
180
+ public static projection2d = projection2d;
181
+ public static quadToCubic = quadToCubic;
182
+ public static relativizeSegment = relativizeSegment;
91
183
  public static reverseCurve = reverseCurve;
92
184
  public static reversePath = reversePath;
93
- public static normalizePath = normalizePath;
185
+ public static roundPath = roundPath;
186
+ public static roundSegment = roundSegment;
187
+ public static segmentToCubic = segmentToCubic;
188
+ public static shortenSegment = shortenSegment;
189
+ public static splitCubic = splitCubic;
190
+ public static splitPath = splitPath;
94
191
  public static transformPath = transformPath;
95
- public static pathToAbsolute = pathToAbsolute;
96
- public static pathToRelative = pathToRelative;
97
- public static pathToCurve = pathToCurve;
98
- public static pathToString = pathToString;
99
192
  // declare class properties
100
193
  declare segments: PathArray;
101
194
  declare round: number | 'off';
@@ -114,8 +207,7 @@ class SVGPathCommander {
114
207
  throw TypeError(`${error}: "pathValue" is ${undefPath ? 'undefined' : 'empty'}`);
115
208
  }
116
209
 
117
- const segments = parsePathString(pathValue);
118
- this.segments = segments;
210
+ this.segments = parsePathString(pathValue);
119
211
 
120
212
  // // set instance options.round
121
213
  const { round: roundOption, origin: originOption } = instanceOptions;
@@ -274,8 +366,9 @@ class SVGPathCommander {
274
366
  */
275
367
  optimize() {
276
368
  const { segments } = this;
369
+ const round = this.round === 'off' ? 2 : this.round;
277
370
 
278
- this.segments = optimizePath(segments, this.round);
371
+ this.segments = optimizePath(segments, round);
279
372
  return this;
280
373
  }
281
374
 
package/src/interface.ts CHANGED
@@ -5,7 +5,8 @@ export type SegmentProperties = {
5
5
  index: number;
6
6
  length: number;
7
7
  lengthAtSegment: number;
8
- [key: string]: any;
8
+ // point: Point;
9
+ // [key: string]: any;
9
10
  };
10
11
 
11
12
  export type PointProperties = {