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.
Files changed (97) hide show
  1. package/README.md +4 -4
  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 +755 -849
  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 +947 -611
  8. package/dist/svg-path-commander.mjs.map +1 -1
  9. package/package.json +14 -22
  10. package/.eslintrc.cjs +0 -225
  11. package/.prettierrc.json +0 -15
  12. package/dts.config.ts +0 -15
  13. package/src/convert/pathToAbsolute.ts +0 -18
  14. package/src/convert/pathToCurve.ts +0 -43
  15. package/src/convert/pathToRelative.ts +0 -18
  16. package/src/convert/pathToString.ts +0 -50
  17. package/src/index.ts +0 -454
  18. package/src/interface.ts +0 -130
  19. package/src/math/arcTools.ts +0 -396
  20. package/src/math/bezier.ts +0 -261
  21. package/src/math/cubicTools.ts +0 -124
  22. package/src/math/distanceSquareRoot.ts +0 -15
  23. package/src/math/lineTools.ts +0 -69
  24. package/src/math/midPoint.ts +0 -18
  25. package/src/math/polygonTools.ts +0 -48
  26. package/src/math/quadTools.ts +0 -100
  27. package/src/math/rotateVector.ts +0 -17
  28. package/src/math/roundTo.ts +0 -7
  29. package/src/options/options.ts +0 -9
  30. package/src/parser/error.ts +0 -2
  31. package/src/parser/finalizeSegment.ts +0 -35
  32. package/src/parser/invalidPathValue.ts +0 -2
  33. package/src/parser/isArcCommand.ts +0 -11
  34. package/src/parser/isDigit.ts +0 -12
  35. package/src/parser/isDigitStart.ts +0 -14
  36. package/src/parser/isMoveCommand.ts +0 -17
  37. package/src/parser/isPathCommand.ts +0 -28
  38. package/src/parser/isSpace.ts +0 -23
  39. package/src/parser/paramsCount.ts +0 -16
  40. package/src/parser/paramsParser.ts +0 -14
  41. package/src/parser/parsePathString.ts +0 -33
  42. package/src/parser/pathParser.ts +0 -29
  43. package/src/parser/scanFlag.ts +0 -29
  44. package/src/parser/scanParam.ts +0 -102
  45. package/src/parser/scanSegment.ts +0 -84
  46. package/src/parser/skipSpaces.ts +0 -17
  47. package/src/process/absolutizeSegment.ts +0 -63
  48. package/src/process/arcToCubic.ts +0 -128
  49. package/src/process/getSVGMatrix.ts +0 -70
  50. package/src/process/iterate.ts +0 -58
  51. package/src/process/lineToCubic.ts +0 -17
  52. package/src/process/normalizePath.ts +0 -33
  53. package/src/process/normalizeSegment.ts +0 -84
  54. package/src/process/optimizePath.ts +0 -63
  55. package/src/process/projection2d.ts +0 -52
  56. package/src/process/quadToCubic.ts +0 -31
  57. package/src/process/relativizeSegment.ts +0 -59
  58. package/src/process/reverseCurve.ts +0 -24
  59. package/src/process/reversePath.ts +0 -114
  60. package/src/process/roundPath.ts +0 -33
  61. package/src/process/roundSegment.ts +0 -9
  62. package/src/process/segmentToCubic.ts +0 -48
  63. package/src/process/shortenSegment.ts +0 -71
  64. package/src/process/splitCubic.ts +0 -29
  65. package/src/process/splitPath.ts +0 -63
  66. package/src/process/transformPath.ts +0 -110
  67. package/src/types.ts +0 -228
  68. package/src/util/distanceEpsilon.ts +0 -3
  69. package/src/util/getClosestPoint.ts +0 -15
  70. package/src/util/getDrawDirection.ts +0 -16
  71. package/src/util/getPathArea.ts +0 -70
  72. package/src/util/getPathBBox.ts +0 -98
  73. package/src/util/getPointAtLength.ts +0 -110
  74. package/src/util/getPropertiesAtLength.ts +0 -67
  75. package/src/util/getPropertiesAtPoint.ts +0 -84
  76. package/src/util/getSegmentAtLength.ts +0 -15
  77. package/src/util/getSegmentOfPoint.ts +0 -18
  78. package/src/util/getTotalLength.ts +0 -68
  79. package/src/util/isAbsoluteArray.ts +0 -18
  80. package/src/util/isCurveArray.ts +0 -15
  81. package/src/util/isNormalizedArray.ts +0 -16
  82. package/src/util/isPathArray.ts +0 -24
  83. package/src/util/isPointInStroke.ts +0 -16
  84. package/src/util/isRelativeArray.ts +0 -18
  85. package/src/util/isValidPath.ts +0 -27
  86. package/src/util/shapeParams.ts +0 -16
  87. package/src/util/shapeToPath.ts +0 -86
  88. package/src/util/shapeToPathArray.ts +0 -183
  89. package/test/class.test.ts +0 -504
  90. package/test/fixtures/getMarkup.ts +0 -17
  91. package/test/fixtures/shapeObjects.ts +0 -11
  92. package/test/fixtures/shapes.js +0 -104
  93. package/test/fixtures/simpleShapes.js +0 -75
  94. package/test/static.test.ts +0 -330
  95. package/vite.config.mts +0 -41
  96. package/vitest.config-ui.mts +0 -26
  97. package/vitest.config.mts +0 -26
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "svg-path-commander",
3
3
  "author": "thednp",
4
4
  "license": "MIT",
5
- "version": "2.1.2",
6
- "description": "Modern TypeScript tools for SVG",
5
+ "version": "2.1.5",
6
+ "description": "🛹 Modern TypeScript tools for SVG",
7
7
  "source": "./src/index.ts",
8
8
  "main": "./dist/svg-path-commander.js",
9
9
  "module": "./dist/svg-path-commander.mjs",
@@ -38,21 +38,14 @@
38
38
  },
39
39
  "homepage": "http://thednp.github.io/svg-path-commander",
40
40
  "devDependencies": {
41
- "@typescript-eslint/eslint-plugin": "^5.62.0",
42
- "@typescript-eslint/parser": "^5.62.0",
43
- "@vitest/browser": "^2.1.3",
44
- "@vitest/coverage-istanbul": "^2.1.3",
45
- "@vitest/ui": "^2.1.3",
46
- "dts-bundle-generator": "^9.5.1",
47
- "eslint": "^8.57.1",
48
- "eslint-plugin-jsdoc": "^46.10.1",
49
- "eslint-plugin-prefer-arrow": "^1.2.3",
50
- "eslint-plugin-prettier": "^4.2.1",
51
- "playwright": "^1.48.1",
52
- "prettier": "^2.8.8",
41
+ "@vitest/browser": "^2.1.4",
42
+ "@vitest/coverage-istanbul": "^2.1.4",
43
+ "@vitest/ui": "^2.1.4",
44
+ "playwright": "^1.48.2",
53
45
  "typescript": "^5.6.3",
54
- "vite": "^5.4.9",
55
- "vitest": "^2.1.3"
46
+ "vite": "^5.4.10",
47
+ "vite-plugin-dts": "^4.3.0",
48
+ "vitest": "^2.1.4"
56
49
  },
57
50
  "dependencies": {
58
51
  "@thednp/dommatrix": "^2.0.8"
@@ -63,19 +56,18 @@
63
56
  },
64
57
  "scripts": {
65
58
  "pre-test": "pnpm clean-coverage",
66
- "badges": "npx -p dependency-version-badge update-badge typescript eslint prettier vitest vite",
59
+ "badges": "npx -p dependency-version-badge update-badge typescript vitest vite",
67
60
  "dev": "vite serve docs --port 3000",
68
61
  "test": "pnpm pre-test && vitest --config vitest.config.mts",
69
62
  "test-ui": "pnpm pre-test && vitest --config vitest.config-ui.mts --browser=chrome",
70
63
  "clean-coverage": "rm -rf coverage .nyc_output",
71
- "format": "prettier --write \"src/**/*.ts\"",
64
+ "format": "deno fmt src",
72
65
  "lint": "pnpm lint:ts && pnpm check:ts",
73
- "fix:ts": "eslint src --config .eslintrc.cjs --fix",
74
- "lint:ts": "eslint src --config .eslintrc.cjs",
66
+ "fix:ts": "deno lint --fix src",
67
+ "lint:ts": "deno lint src",
75
68
  "check:ts": "tsc --noEmit",
76
- "build": "pnpm lint && pnpm build-vite && pnpm build-ts",
69
+ "build": "pnpm build-vite",
77
70
  "build-vite": "vite build && pnpm copy-docs",
78
- "build-ts": "dts-bundle-generator --config ./dts.config.ts",
79
71
  "copy-docs": "cp dist/svg-path-commander.js docs/svg-path-commander.js && cp dist/svg-path-commander.js.map docs/svg-path-commander.js.map"
80
72
  }
81
73
  }
package/.eslintrc.cjs DELETED
@@ -1,225 +0,0 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es6": true
5
- },
6
- "extends": [
7
- "plugin:@typescript-eslint/recommended",
8
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
9
- ],
10
- "parser": "@typescript-eslint/parser",
11
- "parserOptions": {
12
- "project": "tsconfig.json",
13
- "sourceType": "module"
14
- },
15
- "plugins": [
16
- "eslint-plugin-jsdoc",
17
- "eslint-plugin-prefer-arrow",
18
- // "eslint-plugin-react",
19
- "@typescript-eslint",
20
- "prettier"
21
- ],
22
- "root": true,
23
- "rules": {
24
- "prettier/prettier": "error",
25
- "@typescript-eslint/adjacent-overload-signatures": "error",
26
- "@typescript-eslint/array-type": [
27
- "error",
28
- {
29
- "default": "array"
30
- }
31
- ],
32
- "@typescript-eslint/ban-types": [
33
- "error",
34
- {
35
- "types": {
36
- "Object": {
37
- "message": "Avoid using the `Object` type. Did you mean `object`?"
38
- },
39
- "Function": {
40
- "message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
41
- },
42
- "Boolean": {
43
- "message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
44
- },
45
- "Number": {
46
- "message": "Avoid using the `Number` type. Did you mean `number`?"
47
- },
48
- "String": {
49
- "message": "Avoid using the `String` type. Did you mean `string`?"
50
- },
51
- "Symbol": {
52
- "message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
53
- }
54
- }
55
- }
56
- ],
57
- "@typescript-eslint/consistent-type-assertions": "error",
58
- "@typescript-eslint/dot-notation": "error",
59
- "@typescript-eslint/explicit-function-return-type": "off",
60
- "@typescript-eslint/explicit-module-boundary-types": "off",
61
- "@typescript-eslint/indent": "off",
62
- "@typescript-eslint/member-delimiter-style": [
63
- "off",
64
- {
65
- "multiline": {
66
- "delimiter": "none",
67
- "requireLast": true
68
- },
69
- "singleline": {
70
- "delimiter": "semi",
71
- "requireLast": false
72
- }
73
- }
74
- ],
75
- // "@typescript-eslint/naming-convention": "error",
76
- "@typescript-eslint/no-empty-function": "error",
77
- "@typescript-eslint/no-empty-interface": "error",
78
- "@typescript-eslint/no-explicit-any": "off",
79
- "@typescript-eslint/no-misused-new": "error",
80
- "@typescript-eslint/no-namespace": "error",
81
- "@typescript-eslint/no-parameter-properties": "off",
82
- "@typescript-eslint/no-shadow": [
83
- "error",
84
- {
85
- "hoist": "all"
86
- }
87
- ],
88
- "@typescript-eslint/no-loss-of-precision": "off",
89
- "@typescript-eslint/no-unused-expressions": "error",
90
- "@typescript-eslint/no-use-before-define": "off",
91
- "@typescript-eslint/no-var-requires": "error",
92
- "@typescript-eslint/prefer-for-of": "error",
93
- "@typescript-eslint/prefer-function-type": "error",
94
- "@typescript-eslint/prefer-namespace-keyword": "error",
95
- "@typescript-eslint/quotes": "off",
96
- "@typescript-eslint/semi": [
97
- "off",
98
- null
99
- ],
100
- "@typescript-eslint/triple-slash-reference": [
101
- "error",
102
- {
103
- "path": "always",
104
- "types": "prefer-import",
105
- "lib": "always"
106
- }
107
- ],
108
- "@typescript-eslint/type-annotation-spacing": "off",
109
- "@typescript-eslint/typedef": "off",
110
- "@typescript-eslint/unified-signatures": "error",
111
- "arrow-parens": [
112
- "off",
113
- "always"
114
- ],
115
- "brace-style": [
116
- "off",
117
- "off"
118
- ],
119
- "comma-dangle": "off",
120
- "complexity": "off",
121
- "constructor-super": "error",
122
- "dot-notation": "off",
123
- "eol-last": "off",
124
- "eqeqeq": [
125
- "error",
126
- "smart"
127
- ],
128
- "guard-for-in": "error",
129
- "id-denylist": [
130
- "error",
131
- "any",
132
- "Number",
133
- "number",
134
- "String",
135
- "string",
136
- "Boolean",
137
- "boolean",
138
- "Undefined",
139
- "undefined"
140
- ],
141
- "id-match": "error",
142
- "indent": "off",
143
- "jsdoc/check-alignment": "error",
144
- "jsdoc/check-indentation": "error",
145
- // "jsdoc/newline-after-description": "error",
146
- "linebreak-style": "off",
147
- "max-classes-per-file": [
148
- "error",
149
- 1
150
- ],
151
- "max-len": "off",
152
- "new-parens": "off",
153
- "newline-per-chained-call": "off",
154
- "no-bitwise": "error",
155
- "no-caller": "error",
156
- "no-cond-assign": "error",
157
- "no-console": "error",
158
- "no-debugger": "error",
159
- "no-empty": "error",
160
- "no-empty-function": "off",
161
- "no-eval": "error",
162
- "no-extra-semi": "off",
163
- "no-fallthrough": "off",
164
- "no-invalid-this": "off",
165
- "no-irregular-whitespace": "off",
166
- "no-multiple-empty-lines": "off",
167
- "no-new-wrappers": "error",
168
- "no-shadow": "off",
169
- "no-throw-literal": "error",
170
- "no-trailing-spaces": "off",
171
- "no-undef-init": "error",
172
- "no-underscore-dangle": "off",
173
- "no-unsafe-finally": "error",
174
- "no-unused-expressions": "off",
175
- "no-unused-labels": "error",
176
- "no-use-before-define": "off",
177
- "no-var": "error",
178
- "object-shorthand": "error",
179
- "one-var": [
180
- "error",
181
- "never"
182
- ],
183
- "padded-blocks": [
184
- "off",
185
- {
186
- "blocks": "never"
187
- },
188
- {
189
- "allowSingleLineBlocks": true
190
- }
191
- ],
192
- "prefer-arrow/prefer-arrow-functions": "error",
193
- "prefer-const": "error",
194
- "quote-props": "off",
195
- "quotes": "off",
196
- "radix": "error",
197
- // "react/jsx-curly-spacing": "off",
198
- // "react/jsx-equals-spacing": "off",
199
- // "react/jsx-tag-spacing": [
200
- // "off",
201
- // {
202
- // "afterOpening": "allow",
203
- // "closingSlash": "allow"
204
- // }
205
- // ],
206
- // "react/jsx-wrap-multilines": "off",
207
- "semi": "off",
208
- "space-before-function-paren": "off",
209
- "space-in-parens": [
210
- "off",
211
- "never"
212
- ],
213
- "spaced-comment": [
214
- "error",
215
- "always",
216
- {
217
- "markers": [
218
- "/"
219
- ]
220
- }
221
- ],
222
- "use-isnan": "error",
223
- "valid-typeof": "off"
224
- }
225
- };
package/.prettierrc.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "arrowParens": "avoid",
3
- "bracketSpacing": true,
4
- "endOfLine": "lf",
5
- "bracketSameLine": false,
6
- "jsxSingleQuote": false,
7
- "printWidth": 120,
8
- "proseWrap": "preserve",
9
- "quoteProps": "as-needed",
10
- "semi": true,
11
- "singleQuote": true,
12
- "tabWidth": 2,
13
- "trailingComma": "all",
14
- "useTabs": false
15
- }
package/dts.config.ts DELETED
@@ -1,15 +0,0 @@
1
- const config = {
2
- entries: [
3
- {
4
- filePath: "./src/index.ts",
5
- outFile: "./dist/svg-path-commander.d.ts",
6
- noCheck: false,
7
- output: {
8
- umdModuleName: 'SVGPathCommander',
9
- noBanner: true,
10
- }
11
- },
12
- ],
13
- };
14
-
15
- module.exports = config;
@@ -1,18 +0,0 @@
1
- import parsePathString from '../parser/parsePathString';
2
- import absolutizeSegment from '../process/absolutizeSegment';
3
- import type { AbsoluteArray, PathArray } from '../types';
4
- import iterate from '../process/iterate';
5
-
6
- /**
7
- * Parses a path string value or object and returns an array
8
- * of segments, all converted to absolute values.
9
- *
10
- * @param pathInput the path string | object
11
- * @returns the resulted `pathArray` with absolute values
12
- */
13
- const pathToAbsolute = (pathInput: string | PathArray) => {
14
- const path = parsePathString(pathInput);
15
-
16
- return iterate<AbsoluteArray>(path, absolutizeSegment);
17
- };
18
- export default pathToAbsolute;
@@ -1,43 +0,0 @@
1
- import segmentToCubic from '../process/segmentToCubic';
2
- import { AbsoluteCommand, CSegment, CurveArray, PathArray } from '../types';
3
- import iterate from '../process/iterate';
4
- import parsePathString from '../parser/parsePathString';
5
- import normalizeSegment from '../process/normalizeSegment';
6
- import paramsParser from '../parser/paramsParser';
7
-
8
- /**
9
- * Parses a path string value or 'pathArray' and returns a new one
10
- * in which all segments are converted to cubic-bezier.
11
- *
12
- * In addition, un-necessary `Z` segment is removed if previous segment
13
- * extends to the `M` segment.
14
- *
15
- * @param pathInput the string to be parsed or 'pathArray'
16
- * @returns the resulted `pathArray` converted to cubic-bezier
17
- */
18
- const pathToCurve = (pathInput: string | PathArray): CurveArray => {
19
- const params = { ...paramsParser };
20
- const path = parsePathString(pathInput);
21
-
22
- return iterate<CurveArray>(path, (seg, index, lastX, lastY) => {
23
- params.x = lastX;
24
- params.y = lastY;
25
- const normalSegment = normalizeSegment(seg, params);
26
- let result = segmentToCubic(normalSegment, params);
27
- const isLongArc = result[0] === 'C' && result.length > 7;
28
-
29
- if (isLongArc) {
30
- path.splice(index + 1, 0, ['C' as AbsoluteCommand | number].concat(result.slice(7)) as CSegment);
31
- result = result.slice(0, 7) as CSegment;
32
- }
33
-
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;
39
-
40
- return result;
41
- });
42
- };
43
- export default pathToCurve;
@@ -1,18 +0,0 @@
1
- import type { PathArray, RelativeArray } from '../types';
2
- import parsePathString from '../parser/parsePathString';
3
- import iterate from '../process/iterate';
4
- import relativizeSegment from '../process/relativizeSegment';
5
-
6
- /**
7
- * Parses a path string value or object and returns an array
8
- * of segments, all converted to relative values.
9
- *
10
- * @param pathInput the path string | object
11
- * @returns the resulted `pathArray` with relative values
12
- */
13
- const pathToRelative = (pathInput: string | PathArray): RelativeArray => {
14
- const path = parsePathString(pathInput);
15
-
16
- return iterate<RelativeArray>(path, relativizeSegment);
17
- };
18
- export default pathToRelative;
@@ -1,50 +0,0 @@
1
- import type { PathArray, PathSegment } from '../types';
2
- import defaultOptions from '../options/options';
3
- import roundTo from '../math/roundTo';
4
-
5
- /**
6
- * Returns a valid `d` attribute string value created
7
- * by rounding values and concatenating the `pathArray` segments.
8
- *
9
- * @param path the `pathArray` object
10
- * @param roundOption amount of decimals to round values to
11
- * @returns the concatenated path string
12
- */
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;
48
- };
49
-
50
- export default pathToString;