oslllo-svg-fixer 4.0.1 → 6.0.1

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 CHANGED
@@ -22,7 +22,7 @@ Attempts to fix your svg by turning it into a fill / single path (and making it
22
22
 
23
23
  ## Documentation, Installation, and Usage Instructions
24
24
 
25
- See the full installation and usage documentation [HERE](https://docs.oslllo.com/svg-fixer/master/).
25
+ See the full installation and usage documentation [HERE](https://docs-oslllo-com.onrender.com/svg-fixer/master/).
26
26
 
27
27
  ### The Objective
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-svg-fixer",
3
- "version": "4.0.1",
3
+ "version": "6.0.1",
4
4
  "description": "Converts SVG Strokes To Fill.",
5
5
  "bin": "src/cli.js",
6
6
  "main": "src/index.js",
@@ -13,7 +13,8 @@
13
13
  "lint": "eslint -- src test ./",
14
14
  "lint:fix": "eslint --fix src test ./",
15
15
  "test:only": "nyc mocha test/main.test.js && mocha test/output.test.js",
16
- "test": "nyc mocha test/main.test.js && mocha test/output.test.js && npm run lint",
16
+ "test": "nyc npm run test:all && npm run lint",
17
+ "test:all": "mocha test/main.test.js && mocha test/output.test.js",
17
18
  "test:cli": "mocha test/src/test.cli.js",
18
19
  "coverage": "nyc report --reporter=lcovonly"
19
20
  },
@@ -46,8 +47,8 @@
46
47
  "ansi-colors": "^4.1.3",
47
48
  "cli-progress": "^3.12.0",
48
49
  "fast-glob": "^3.3.1",
49
- "oslllo-potrace": "^2.0.1",
50
- "oslllo-svg2": "^2.0.2",
50
+ "oslllo-potrace": "^3.0.0",
51
+ "oslllo-svg2": "^3.0.0",
51
52
  "oslllo-validator": "^3.1.0",
52
53
  "piscina": "^4.1.0",
53
54
  "yargs": "^16.2.0"
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ DEFAULT_TRACE_RESOLUTION: 600,
5
+ };
package/src/fixer.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ const Svg = require("./svg");
4
+
5
+ module.exports = ({ source, resolution }) => {
6
+ const svg = new Svg(source, resolution);
7
+
8
+ return svg.process();
9
+ };
package/src/index.js CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  const SVGFixer = require("./constructor");
4
4
 
5
+ SVGFixer.fixString = require("./string-fixer");
6
+
5
7
  module.exports = SVGFixer;
package/src/option.js CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  const error = require("./error");
4
4
  const is = require("oslllo-validator");
5
+ const { DEFAULT_TRACE_RESOLUTION } = require("./constants");
5
6
 
6
7
  const Option = function (options) {
7
8
  this.data = {
8
9
  showProgressBar: false,
9
10
  throwIfDestinationDoesNotExist: true,
10
- traceResolution: 600,
11
+ traceResolution: DEFAULT_TRACE_RESOLUTION,
11
12
  };
12
13
  if (!is.object(options)) {
13
14
  throw error.invalidParameterError("options", "object", options);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const is = require("oslllo-validator");
4
+
5
+ const { DEFAULT_TRACE_RESOLUTION } = require("./constants");
6
+ const fix = require("./fixer");
7
+ const error = require("./error");
8
+
9
+ module.exports = (svg, resolution = DEFAULT_TRACE_RESOLUTION) => {
10
+ if (is.buffer(svg)) {
11
+ return fix({ source: svg, resolution });
12
+ }
13
+
14
+ if (!is.string(svg)) {
15
+ throw error.invalidParameterError("svg", "string or buffer", svg);
16
+ }
17
+
18
+ return fix({ source: Buffer.from(svg), resolution });
19
+ };
package/src/svg.js CHANGED
@@ -3,13 +3,12 @@
3
3
  const Svg2 = require("oslllo-svg2");
4
4
  const Potrace = require("oslllo-potrace");
5
5
 
6
- const Svg = function (path, traceResolution) {
6
+ const Svg = function (pathOrBuffer, traceResolution) {
7
7
  this.filled = false;
8
- this.path = path;
9
8
  this.traceResolution = traceResolution;
10
9
  this.png = new Object();
11
10
  this.resized = new Object();
12
- this.svg2 = Svg2(this.path);
11
+ this.svg2 = Svg2(pathOrBuffer);
13
12
  this.element = this.svg2.toElement();
14
13
  this.outerHTML = this.element.outerHTML;
15
14
  this.original = this.getOriginal();
package/src/tracer.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require("fs/promises");
4
- const Svg = require("./svg");
4
+
5
+ const fix = require("./fixer");
5
6
 
6
7
  module.exports = async ({ source, destination, resolution }) => {
7
- const svg = new Svg(source, resolution);
8
- const fixed = await svg.process();
8
+ const fixed = await fix({ source, resolution });
9
9
  await fs.writeFile(destination, fixed);
10
10
  };
package/CHANGELOG.md DELETED
@@ -1,380 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [4.0.1](https://github.com/oslllo/svg-fixer/compare/v4.0.0...v4.0.1) (2024-03-27)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * security vulnerabilities ([81cc6ac](https://github.com/oslllo/svg-fixer/commit/81cc6ac7e1ba5a446aad6c4206872ee6c3ca8e8b))
14
-
15
- ## [4.0.0](https://github.com/oslllo/svg-fixer/compare/v3.0.0...v4.0.0) (2024-03-26)
16
-
17
- ### Breaking
18
- * drop support for node 16
19
-
20
- ### Bug Fixes
21
-
22
- * node version ([8a45ad0](https://github.com/oslllo/svg-fixer/commit/8a45ad02df73759d99ef58a467edaf6697415292))
23
- * Process never ends on error when use promise [#98](https://github.com/oslllo/svg-fixer/issues/98) ([9cacc5c](https://github.com/oslllo/svg-fixer/commit/9cacc5c08016a4882a745009221ae51f55769d0c))
24
-
25
- ## [3.0.0](https://github.com/oslllo/svg-fixer/compare/v2.2.0...v3.0.0) (2023-09-16)
26
-
27
- ⚠️ Contains breaking changes.
28
-
29
- ### Breaking Changes
30
-
31
- * Dropped support for node `<16.0.0`
32
- * This version will not work with `<16.0.0`
33
-
34
- ### Features
35
-
36
- * Made the tool 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89)
37
-
38
- ### Bug Fixes
39
-
40
- * update release actions ([a1a66fe](https://github.com/oslllo/svg-fixer/commit/a1a66fe13539eb5e76c9cb6ac574e35da421636d))
41
-
42
- ## [2.2.0](https://www.github.com/oslllo/svg-fixer/compare/v2.1.2...v2.2.0) (2022-10-19)
43
-
44
-
45
- ### Features
46
-
47
- * closes [#82](https://www.github.com/oslllo/svg-fixer/issues/82) - fix negative viewBox min-x min-y bug ([b64aa75](https://www.github.com/oslllo/svg-fixer/commit/b64aa75b4ea8d3b7a0378cc1f9ce27c92b4f606f))
48
-
49
- ### [2.1.2](https://www.github.com/oslllo/svg-fixer/compare/v2.1.0...v2.1.2) (2022-07-16)
50
-
51
-
52
- ### Miscellaneous Chores
53
-
54
- * release 2.1.2 ([fd8cdaf](https://www.github.com/oslllo/svg-fixer/commit/fd8cdaf08b4645fe3fad229fefa9a97ec9124c9e))
55
-
56
- ## 2.1.1 (2022-05-1)
57
-
58
- ### Chore
59
-
60
- - update dependencies
61
- - npm audit fix
62
-
63
-
64
- ## [2.1.0](https://www.github.com/oslllo/svg-fixer/compare/v2.0.1...v2.1.1) (2022-03-8)
65
-
66
- ### Added
67
-
68
- - add configurable trace resolution ([#72](https://github.com/oslllo/svg-fixer/pull/72))
69
-
70
- ### Updated
71
-
72
- - Updated dependencies
73
-
74
- ## [2.0.1](https://www.github.com/oslllo/svg-fixer/compare/v2.0.0...v2.0.1) (2022-01-21)
75
-
76
-
77
- ### Refactor
78
-
79
- - improve perfomance ([3b310aa](https://github.com/oslllo/svg-fixer/commit/3b310aaf3bf39f47b0bb56a722f03d40ad6a1b31))
80
-
81
- ## [2.0.0](https://www.github.com/oslllo/svg-fixer/compare/v1.4.1...v2.0.0) (2022-01-12)
82
-
83
- This version did not break the api so upgrading from `v1.0.0` without any changes should be fine. The reason for the major version change is just in case something did break.
84
-
85
- ### Changed
86
-
87
- - Removed `Canvas & JSDOM` to fix very slow `npm install` cycles.
88
- - Switched from `Canvas` to `svg2png-wasm`.
89
-
90
- ### Updated
91
-
92
- - Updated dependencies
93
-
94
-
95
- ## [1.4.1](https://www.github.com/oslllo/svg-fixer/compare/v1.4.0...v1.4.1) (2021-09-05)
96
-
97
-
98
- ### Bug Fixes
99
-
100
- * vulnerabilities ([99621c6](https://www.github.com/oslllo/svg-fixer/commit/99621c6258e52836f0aaaf9876fe4b4859c81ab6))
101
-
102
- ## [1.4.0](https://www.github.com/oslllo/svg-fixer/compare/v1.3.2...v1.4.0) (2021-07-14)
103
-
104
-
105
- ### Features
106
-
107
- * add support for svgs with "ex", "ch", "cm", "mm", "q", "in", "pc", "pt" ([4d2c18e](https://www.github.com/oslllo/svg-fixer/commit/4d2c18ef496b9ce08cbc917e3fbb91d9f352c6ff))
108
- * add support for svgs with fill color in path style attribute ([1aeb079](https://www.github.com/oslllo/svg-fixer/commit/1aeb0794e9693079c79981616ea00e99379c863f))
109
- * support svgs without a set viewBox attribute ([17b876c](https://www.github.com/oslllo/svg-fixer/commit/17b876ce49ed0a047dedb098d47adcccb22ff0cf))
110
-
111
- ### [1.3.2](https://www.github.com/oslllo/svg-fixer/compare/v1.3.1...v1.3.2) (2021-06-26)
112
-
113
-
114
- ### Bug Fixes
115
-
116
- * security vulnerabilities ([372730b](https://www.github.com/oslllo/svg-fixer/commit/372730bef6cf761877961796635fc406a2ecc776))
117
-
118
- ### [1.3.1](https://www.github.com/oslllo/svg-fixer/compare/v1.3.0...v1.3.1) (2021-05-27)
119
-
120
-
121
- ### Bug Fixes
122
-
123
- * output svg being smaller than viewBox ([#48](https://www.github.com/oslllo/svg-fixer/issues/48)) ([f658614](https://www.github.com/oslllo/svg-fixer/commit/f65861448802b9b7c6cd6c889207b5f1a7c66592))
124
-
125
- ## [1.3.0](https://www.github.com/oslllo/svg-fixer/compare/v1.2.1...v1.3.0) (2021-05-15)
126
-
127
-
128
- ### Features
129
-
130
- * add support for svgs with light colored fill ([#45](https://www.github.com/oslllo/svg-fixer/issues/45)) ([47aa95d](https://www.github.com/oslllo/svg-fixer/commit/47aa95da9e7054b84f3b2d36528784c5dbe6663d))
131
-
132
-
133
- ### Bug Fixes
134
-
135
- * **eslint:** script error ([d34780e](https://www.github.com/oslllo/svg-fixer/commit/d34780e1db64d350695f5be7c4713136f9c66331))
136
-
137
- ### [1.2.1](https://www.github.com/oslllo/svg-fixer/compare/v1.2.0...v1.2.1) (2021-05-06)
138
-
139
-
140
- ### Bug Fixes
141
-
142
- * drop yargs version to 16 ([7b4d9cc](https://www.github.com/oslllo/svg-fixer/commit/7b4d9ccb563027b24aefe59d394848b8937067b9))
143
- * package breaking when process.env.NODE_ENV env variable is set ([51c6318](https://www.github.com/oslllo/svg-fixer/commit/51c6318340b97d6840ab7d2c499c77aff27b6f10))
144
-
145
- ## [1.2.0] - 2021/4/1
146
-
147
- ### Fixed
148
-
149
- - Fixed bug in test.
150
-
151
- ### Updated
152
-
153
- - Updated dependencies.
154
-
155
- ## [1.1.2] - 2020/12/12
156
-
157
- ### Fixed
158
-
159
- - Fixed vulnerability.
160
-
161
- ### Updated
162
-
163
- - Updated dependencies.
164
-
165
- ## [1.1.1] - 2020/10/22
166
-
167
- ### Fixed
168
-
169
- - Fixed large npm package.
170
-
171
- ## [1.1.0] - 2020/10/22
172
-
173
- ### Fixed
174
-
175
- - Fixed bug that allowed you to update `options` that do not exist.
176
-
177
- ### Added
178
-
179
- - Added `CLI` functionality.
180
- - Added `callback` functionality to `SVGFixer.fix()`.
181
-
182
- ### Changed
183
-
184
- - Refactored `tests`.
185
- - Refactored `progress bar`.
186
-
187
- ## [1.0.2] - 2020/10/2
188
-
189
- ### Fixed
190
-
191
- - Fixed not being able to process SVGs with `%` dimensions.
192
-
193
- ### Added
194
-
195
- - SVG attribute tests.
196
-
197
- ## [1.0.1] - 2020/9/16
198
-
199
- ### Changed
200
-
201
- - Remove tests from npm `package` to help reduce unpacked `package` size.
202
-
203
- ## [1.0.0] - 2020/9/16
204
-
205
- ⚠️ Contains breaking changes.
206
-
207
- ### Breaking Changes
208
-
209
- - `svgfixer.fix(source, destination, options)` ***=>*** `SVGFixer(source, destination, options).fix()`.
210
- - It was changed from a wrapper function to a method function for `SVGFixer`.
211
- - It still returns a `Promise`.
212
- - `fix()` no more takes in `parameters`, those should be passed into `SVGFixer()`.
213
- - `svgfixer.SVGFixer()` class ***=>*** `SVGFixer()`.
214
- - The `.setOptions(options)` method has been removed, `options` should now be passed in class constructor as the 3rd `parameter`.
215
- - The `.setSourceAndDest()` method has been removed, `source` and `destination` should now be passed in class constructor as the 1st and 2nd `parameters`.
216
- - The `.process()` method has been removed, use `.fix()` instead.
217
- - `SVGFixer()` does not require the [`new`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) operator anymore.
218
- - `fixConcurrency` has been removed, might be reimplemented on later versions.
219
-
220
- ### Changed
221
-
222
- - Updated dependencies.
223
- - Refactored codebase.
224
- - Refactored progressbar.
225
-
226
- ## [0.6.0] - 2020/8/13
227
-
228
- ### Security
229
-
230
- - Updated dependencies. Fixes [Vulnerability](https://npmjs.com/advisories/1548)
231
-
232
- ### Changed
233
-
234
- - Updated image processor.
235
- - Updated `CHANGELOG.md` wording and formatting.
236
-
237
- ## [0.5.1] - 2020/7/7
238
-
239
- ### Changed
240
-
241
- - Updated `README.md`.
242
-
243
- ### Added
244
-
245
- - Documentation.
246
-
247
- ## [0.5.0] - 2020/6/13
248
-
249
- ### Changed
250
-
251
- - Changed image processing engine from Sharp to Jimp. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
252
- - Refactored async pools (fixConcurrency).
253
-
254
- ### Fixed
255
-
256
- - Fixed pathing issues on windows. Fixes [#8](https://github.com/oslllo/svg-fixer/issues/8)
257
-
258
- ## [0.4.4] - 2020/6/8
259
-
260
- ### Changed
261
-
262
- - Updated dependencies. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
263
-
264
- ## [0.4.3] - 2020/6/2
265
-
266
- ### Changed
267
-
268
- - Updated `package.json` description.
269
-
270
- ## [0.4.2] - 2020/5/24
271
-
272
- ### Fixed
273
-
274
- - Fixed incorrect svg data when source svg has 'px', 'rem' or 'em' on height and width attributes as a unit of measurement. See ([#5](https://github.com/oslllo/svg-fixer/issues/5))
275
-
276
- ## [0.4.1] - 2020/5/16
277
-
278
- ### Security
279
-
280
- - Fixed [Vulnerability](https://www.npmjs.com/advisories/1500)
281
-
282
- ## [0.4.0] - 2020/5/14
283
-
284
- ### Added
285
-
286
- - Added new parameter `fixConcurrency` to control how many svgs to fix at a given time.
287
- - Added new tests
288
- - Added an perfomance increase by ~67%
289
-
290
- |Version|completion (%)|Time (seconds)|Number of SVGs fixed|
291
- |------|------|-----|-----|
292
- |v0.4.0|100.00|~ 127|1315|
293
- |v0.3.3|100.00|~ 190|1315|
294
- |-|-|-|-|
295
- |**VPS**|**CPU**|**RAM**|||
296
- ||Intel(R) Xeon(R) E5-1650 v3 3.50GHz (2x) | 1548MiB|||
297
-
298
- ### Fixed
299
-
300
- - Fixed tests
301
-
302
- ### Changed
303
-
304
- - Reduceed npm package size.
305
- - Updated `README.md`.
306
-
307
- ## [0.3.3] - 2020/5/12
308
-
309
- ### Added
310
-
311
- - Added badge links to `README.md`.
312
- - Added new tags to `package.json`.
313
-
314
- ### Changed
315
-
316
- - Updated `README.md` content.
317
-
318
- ## [0.3.2] - 2020/5/10
319
-
320
- ### Changed
321
-
322
- - Updated README.md
323
-
324
- ## [0.3.1] - 2020/5/9
325
-
326
- ### Changed
327
-
328
- - Updated `README.md`
329
-
330
- ## [0.3.0] - 2020/5/8
331
-
332
- ### Changed
333
-
334
- - Refactored the whole codebase.
335
- - Updated README.md
336
-
337
- ### Added
338
-
339
- - Added tests
340
- - Added slight performance increase.
341
-
342
- ## [0.2.0] - 2020/4/18
343
-
344
- ### Added
345
-
346
- - Added progress bar
347
-
348
- ## [0.1.0] - 2020/4/17
349
-
350
- ### Added
351
-
352
- - Added [CHANGELOG.md](https://github.com/oslllo/svg-fixer/blob/master/CHANGELOG.md)
353
- - Create destination folder if it does not exist.
354
-
355
- ### Changed
356
-
357
- - Switched from `fs` to `fs-extra`
358
- - Changed `SvgFixer()` function name from `SvgFixer` to `svgFixer` because its a function not a class.
359
-
360
- ### Removed
361
-
362
- - Removed debug functions
363
-
364
- ## [0.0.3] - 2020/4/16
365
-
366
- ### Added
367
-
368
- - Added package.json description
369
-
370
- ## [0.0.2] - 2020/4/16
371
-
372
- ### Added
373
-
374
- - Added [README.md](https://github.com/oslllo/svg-fixer/blob/master/README.md)
375
-
376
- ## [0.0.1] - 2020/4/16
377
-
378
- ### Added
379
-
380
- - Added everything, initial release.