oslllo-svg-fixer 1.3.1 → 2.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 CHANGED
@@ -5,6 +5,41 @@ 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
+ ## [2.0.0](https://www.github.com/oslllo/svg-fixer/compare/v1.4.1...v2.0.0) (2022-01-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **security:** audit fix ([6047ad8](https://www.github.com/oslllo/svg-fixer/commit/6047ad88645d9f4cb251ca9bac04f278c902aa85))
14
+
15
+
16
+ ### Miscellaneous Chores
17
+
18
+ * release 2.0.0 ([7abe789](https://www.github.com/oslllo/svg-fixer/commit/7abe789afc9ba6ff04c4f32a284561cf497f0c48))
19
+
20
+ ### [1.4.1](https://www.github.com/oslllo/svg-fixer/compare/v1.4.0...v1.4.1) (2021-09-05)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * vulnerabilities ([99621c6](https://www.github.com/oslllo/svg-fixer/commit/99621c6258e52836f0aaaf9876fe4b4859c81ab6))
26
+
27
+ ## [1.4.0](https://www.github.com/oslllo/svg-fixer/compare/v1.3.2...v1.4.0) (2021-07-14)
28
+
29
+
30
+ ### Features
31
+
32
+ * add support for svgs with "ex", "ch", "cm", "mm", "q", "in", "pc", "pt" ([4d2c18e](https://www.github.com/oslllo/svg-fixer/commit/4d2c18ef496b9ce08cbc917e3fbb91d9f352c6ff))
33
+ * add support for svgs with fill color in path style attribute ([1aeb079](https://www.github.com/oslllo/svg-fixer/commit/1aeb0794e9693079c79981616ea00e99379c863f))
34
+ * support svgs without a set viewBox attribute ([17b876c](https://www.github.com/oslllo/svg-fixer/commit/17b876ce49ed0a047dedb098d47adcccb22ff0cf))
35
+
36
+ ### [1.3.2](https://www.github.com/oslllo/svg-fixer/compare/v1.3.1...v1.3.2) (2021-06-26)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * security vulnerabilities ([372730b](https://www.github.com/oslllo/svg-fixer/commit/372730bef6cf761877961796635fc406a2ecc776))
42
+
8
43
  ### [1.3.1](https://www.github.com/oslllo/svg-fixer/compare/v1.3.0...v1.3.1) (2021-05-27)
9
44
 
10
45
 
package/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  [![npm](https://img.shields.io/npm/v/oslllo-svg-fixer)](https://www.npmjs.com/package/oslllo-svg-fixer)
7
7
  [![Coveralls github](https://img.shields.io/coveralls/github/oslllo/svg-fixer)](https://coveralls.io/github/oslllo/svg-fixer)
8
8
 
9
+ 🎉 v2.0.0 Removed `Canvas & JSDOM` no more slow `npm install` cycles.
10
+
9
11
  Attempts to fix your svg by turning it into a fill / single path (and making it font compatible as a bonus).
10
12
 
11
13
  ## Convert SVG Strokes To Fills
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-svg-fixer",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "Converts SVG Strokes To Fill.",
5
5
  "bin": "src/cli.js",
6
6
  "main": "src/index.js",
@@ -42,24 +42,24 @@
42
42
  },
43
43
  "homepage": "https://docs.oslllo.com/svg-fixer/master",
44
44
  "dependencies": {
45
- "cli-progress": "^3.9.0",
46
- "colors": "^1.4.0",
47
- "fast-glob": "^3.2.5",
48
- "oslllo-potrace": "^1.1.3",
49
- "oslllo-svg2": "^0.2.4",
50
- "oslllo-validator": "^2.0.0",
51
- "yargs": "^16.0.2"
45
+ "ansi-colors": "^4.1.1",
46
+ "cli-progress": "^3.10.0",
47
+ "fast-glob": "^3.2.10",
48
+ "oslllo-potrace": "^2.0.0",
49
+ "oslllo-svg2": "^1.0.0",
50
+ "oslllo-validator": "^3.0.0",
51
+ "yargs": "^16.2.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "capture-console": "^1.0.1",
55
55
  "chai": "^4.3.4",
56
56
  "chai-as-promised": "^7.1.1",
57
- "coveralls": "^3.1.0",
58
- "eslint": "^7.25.0",
57
+ "coveralls": "^3.1.1",
58
+ "eslint": "^7.32.0",
59
59
  "fs-extra": "^10.0.0",
60
- "inquirer": "^8.0.0",
60
+ "inquirer": "^8.2.0",
61
61
  "looks-same": "^7.3.0",
62
- "mocha": "^8.3.2",
62
+ "mocha": "^9.1.3",
63
63
  "mocha-lcov-reporter": "^1.3.0",
64
64
  "nyc": "^15.1.0",
65
65
  "stopwatch-node": "^1.1.0"
package/src/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  "use strict";
4
4
 
5
5
  const SVGFixer = require("../");
6
- const colors = require("colors");
6
+ const colors = require("ansi-colors");
7
7
  var argvs = require("yargs/yargs")(process.argv.slice(2)); // eslint-disable-line no-magic-numbers
8
8
 
9
9
  argvs
package/src/progress.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- const colors = require("colors");
3
+ const colors = require("ansi-colors");
4
4
  const cliprogress = require("cli-progress");
5
5
 
6
6
  const Progress = function (source, max) {
package/src/svg.js CHANGED
@@ -51,7 +51,7 @@ Svg.prototype = {
51
51
  /**
52
52
  * Ignore <path></path> "d" attribute.
53
53
  */
54
- if (attribute.name !== "d") {
54
+ if (attribute && attribute.name && attribute.name !== "d") {
55
55
  return { name: attribute.name, value: attribute.value };
56
56
  }
57
57
 
@@ -100,10 +100,28 @@ Svg.prototype = {
100
100
  });
101
101
 
102
102
  if (!this.filled) {
103
- element.setAttribute("fill", "black");
103
+ const pathColor = this.getPathStyleFillColor();
104
+ const fill = pathColor ? pathColor : "black";
105
+ element.setAttribute("fill", fill);
104
106
  }
105
107
  }
106
108
  },
109
+ getPathStyleFillColor() {
110
+ var path = this.getFirstPathElement(this.original.element);
111
+ var style = path.getAttribute("style");
112
+ if (!style) {
113
+ return false;
114
+ }
115
+ var fill = style.split(";").find((e) => e.includes("fill:"));
116
+ if (fill && !fill.includes("none")) {
117
+ const splits = fill.split(":");
118
+
119
+ // eslint-disable-next-line no-magic-numbers
120
+ return splits[splits.length - 1];
121
+ }
122
+
123
+ return false;
124
+ },
107
125
  toOriginal: function (outerHTML) {
108
126
  var element = Svg2(outerHTML).toElement();
109
127
  this.resetAttributes(element, this.original.attributes);
@@ -142,6 +160,9 @@ Svg.prototype = {
142
160
  },
143
161
  process: async function () {
144
162
  var element = this.checkFillState(this.resized.element.cloneNode(true));
163
+ if (!element.getAttribute("viewBox")) {
164
+ element.setAttribute("viewBox", `0 0 ${this.original.dimensions.width} ${this.original.dimensions.height}`);
165
+ }
145
166
  var pngBuffer = await Svg2(element.outerHTML).png({ transparent: false }).toBuffer();
146
167
  var traced = await Potrace(pngBuffer, { svgSize: this.scale }).trace();
147
168
  traced = this.toOriginal(traced);