oslllo-svg-fixer 2.1.2 → 3.0.0
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/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/package.json +13 -8
- package/src/cli.js +1 -0
- package/src/processor.js +18 -19
- package/src/svg.js +11 -1
- package/src/tracer.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.0.0](https://github.com/oslllo/svg-fixer/compare/v2.2.0...v3.0.0) (2023-09-16)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Made the tool 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* update release actions ([a1a66fe](https://github.com/oslllo/svg-fixer/commit/a1a66fe13539eb5e76c9cb6ac574e35da421636d))
|
|
17
|
+
|
|
18
|
+
## [2.2.0](https://www.github.com/oslllo/svg-fixer/compare/v2.1.2...v2.2.0) (2022-10-19)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* 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))
|
|
24
|
+
|
|
8
25
|
### [2.1.2](https://www.github.com/oslllo/svg-fixer/compare/v2.1.0...v2.1.2) (2022-07-16)
|
|
9
26
|
|
|
10
27
|
|
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/oslllo-svg-fixer)
|
|
7
7
|
[](https://coveralls.io/github/oslllo/svg-fixer)
|
|
8
8
|
|
|
9
|
+
🎉 v3.0.0 Is now 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89).
|
|
10
|
+
|
|
9
11
|
🎉 v2.0.0 Removed `Canvas & JSDOM` no more slow `npm install` cycles.
|
|
10
12
|
|
|
11
13
|
Attempts to fix your svg by turning it into a fill / single path (and making it font compatible as a bonus).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oslllo-svg-fixer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Converts SVG Strokes To Fill.",
|
|
5
5
|
"bin": "src/cli.js",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"debug": "node scripts/debug.js",
|
|
13
|
-
"lint": "
|
|
14
|
-
"lint:fix": "
|
|
13
|
+
"lint": "eslint -- src test ./",
|
|
14
|
+
"lint:fix": "eslint --fix src test ./",
|
|
15
15
|
"test:only": "nyc mocha test/main.test.js && mocha test/output.test.js",
|
|
16
16
|
"test": "nyc mocha test/main.test.js && mocha test/output.test.js && npm run lint",
|
|
17
|
-
"
|
|
17
|
+
"test:cli": "mocha test/src/test.cli.js",
|
|
18
|
+
"coverage": "nyc report --reporter=lcovonly"
|
|
18
19
|
},
|
|
19
20
|
"repository": {
|
|
20
21
|
"type": "git",
|
|
@@ -43,24 +44,28 @@
|
|
|
43
44
|
"homepage": "https://docs.oslllo.com/svg-fixer/master",
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"ansi-colors": "^4.1.3",
|
|
46
|
-
"cli-progress": "^3.
|
|
47
|
-
"fast-glob": "^3.
|
|
47
|
+
"cli-progress": "^3.12.0",
|
|
48
|
+
"fast-glob": "^3.3.1",
|
|
48
49
|
"oslllo-potrace": "^2.0.1",
|
|
49
50
|
"oslllo-svg2": "^2.0.2",
|
|
50
51
|
"oslllo-validator": "^3.1.0",
|
|
52
|
+
"piscina": "^4.1.0",
|
|
51
53
|
"yargs": "^16.2.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"chai": "^4.3.
|
|
56
|
+
"chai": "^4.3.8",
|
|
55
57
|
"chai-as-promised": "^7.1.1",
|
|
56
58
|
"coveralls": "^3.1.1",
|
|
57
59
|
"eslint": "^7.32.0",
|
|
58
60
|
"fs-extra": "^10.1.0",
|
|
59
|
-
"inquirer": "^8.2.
|
|
61
|
+
"inquirer": "^8.2.6",
|
|
60
62
|
"looks-same": "^7.3.0",
|
|
61
63
|
"mocha": "^9.2.2",
|
|
62
64
|
"mocha-lcov-reporter": "^1.3.0",
|
|
63
65
|
"nyc": "^15.1.0",
|
|
64
66
|
"stopwatch-node": "^1.1.0"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=16.0.0"
|
|
65
70
|
}
|
|
66
71
|
}
|
package/src/cli.js
CHANGED
|
@@ -53,6 +53,7 @@ const options = {
|
|
|
53
53
|
(async () => {
|
|
54
54
|
try {
|
|
55
55
|
await SVGFixer(source, destination, options).fix();
|
|
56
|
+
process.exit(0); // eslint-disable-line no-process-exit, no-magic-numbers
|
|
56
57
|
} catch (err) {
|
|
57
58
|
console.log("\n" + colors.red("ERR: " + err.message + "\n")); // eslint-disable-line no-console
|
|
58
59
|
console.log(colors.yellow("STACK: " + err.stack + "\n")); // eslint-disable-line no-console
|
package/src/processor.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const fs = require("fs");
|
|
4
3
|
const path = require("path");
|
|
5
|
-
const Svg = require("./svg");
|
|
6
4
|
const is = require("oslllo-validator");
|
|
7
5
|
const Progress = require("./progress");
|
|
6
|
+
const Piscina = require("piscina");
|
|
7
|
+
|
|
8
|
+
const workerPool = new Piscina({
|
|
9
|
+
filename: path.resolve(__dirname, "tracer.js")
|
|
10
|
+
});
|
|
8
11
|
|
|
9
12
|
const Processor = function (fixer) {
|
|
10
13
|
this.fixer = fixer;
|
|
@@ -34,14 +37,23 @@ Processor.prototype = {
|
|
|
34
37
|
try {
|
|
35
38
|
this.setup();
|
|
36
39
|
var svgs = this.source;
|
|
40
|
+
|
|
41
|
+
const resolution = this.fixer.options.get("traceResolution");
|
|
42
|
+
|
|
37
43
|
svgs = svgs.map((source) => {
|
|
38
44
|
var destination = path.join(this.destination, path.basename(source));
|
|
39
45
|
|
|
40
|
-
return { source, destination };
|
|
46
|
+
return { source, destination, resolution };
|
|
41
47
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
|
|
49
|
+
const workerPromises = svgs.map(async (svg) => {
|
|
50
|
+
await workerPool.run(svg);
|
|
51
|
+
// eslint-disable-next-line no-empty-function
|
|
52
|
+
this.tick(() => {});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await Promise.all(workerPromises);
|
|
56
|
+
|
|
45
57
|
this.teardown();
|
|
46
58
|
resolve(this.fixer);
|
|
47
59
|
} catch (err) {
|
|
@@ -68,19 +80,6 @@ Processor.prototype = {
|
|
|
68
80
|
this.progress.stop();
|
|
69
81
|
}
|
|
70
82
|
},
|
|
71
|
-
instance: function ({ source, destination }) {
|
|
72
|
-
return new Promise(async (resolve, reject) => {
|
|
73
|
-
try {
|
|
74
|
-
var resolution = this.fixer.options.get("traceResolution");
|
|
75
|
-
var svg = new Svg(source, resolution);
|
|
76
|
-
var fixed = await svg.process();
|
|
77
|
-
fs.writeFileSync(destination, fixed);
|
|
78
|
-
this.tick(() => resolve());
|
|
79
|
-
} catch (err) {
|
|
80
|
-
reject(err);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
83
|
};
|
|
85
84
|
|
|
86
85
|
module.exports = Processor;
|
package/src/svg.js
CHANGED
|
@@ -78,7 +78,17 @@ Svg.prototype = {
|
|
|
78
78
|
setAttributes(element, attributes) {
|
|
79
79
|
attributes.forEach((attribute) => {
|
|
80
80
|
if (attribute) {
|
|
81
|
-
if (
|
|
81
|
+
if (attribute.name === "viewBox") {
|
|
82
|
+
const value = attribute.value.split(" ");
|
|
83
|
+
const x = 2;
|
|
84
|
+
for (var i = 0; i < x; i++) {
|
|
85
|
+
/**
|
|
86
|
+
* Set min-x & min-y to 0
|
|
87
|
+
*/
|
|
88
|
+
value[i] = "0";
|
|
89
|
+
}
|
|
90
|
+
element.setAttribute(attribute.name, value.join(" "));
|
|
91
|
+
} else if (element.tagName.toLowerCase() === "path") {
|
|
82
92
|
if (
|
|
83
93
|
(attribute.name === "stroke" && this.valueIsNotBlack(attribute.value)) ||
|
|
84
94
|
(attribute.name === "fill" && this.valueIsNotBlack(attribute.value))
|
package/src/tracer.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs/promises");
|
|
4
|
+
const Svg = require("./svg");
|
|
5
|
+
|
|
6
|
+
module.exports = async ({ source, destination, resolution }) => {
|
|
7
|
+
const svg = new Svg(source, resolution);
|
|
8
|
+
const fixed = await svg.process();
|
|
9
|
+
await fs.writeFile(destination, fixed);
|
|
10
|
+
};
|