oslllo-svg-fixer 5.0.0 → 7.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/README.md CHANGED
@@ -1,110 +1,187 @@
1
+ ![SVG Fixer cover](docs/images/cover.png)
2
+
1
3
  # SVG Fixer
2
4
 
3
- ![Cover Image](docs/images/cover.png)
5
+ Convert SVG strokes and shapes into a single filled path for icon fonts and other tools that require path outlines.
4
6
 
5
7
  [![CI/Test](https://github.com/oslllo/svg-fixer/actions/workflows/ci.test.yml/badge.svg)](https://github.com/oslllo/svg-fixer/actions/workflows/ci.test.yml)
6
8
  [![npm](https://img.shields.io/npm/v/oslllo-svg-fixer)](https://www.npmjs.com/package/oslllo-svg-fixer)
7
- [![Coveralls github](https://img.shields.io/coveralls/github/oslllo/svg-fixer)](https://coveralls.io/github/oslllo/svg-fixer)
9
+ [![Coverage](https://img.shields.io/coveralls/github/oslllo/svg-fixer)](https://coveralls.io/github/oslllo/svg-fixer)
10
+
11
+ 🎉 v3.0.0 is now 11x faster thanks to [@ericfennis](https://github.com/ericfennis). See [PR #89](https://github.com/oslllo/svg-fixer/pull/89).
12
+
13
+ ![Stroke-to-fill conversion](docs/images/demo.gif)
14
+
15
+ ## Contents
16
+
17
+ - [Installation](#installation)
18
+ - [Quick start](#quick-start)
19
+ - [Files and directories](#files-and-directories)
20
+ - [SVG strings and Buffers](#svg-strings-and-buffers)
21
+ - [Options](#options)
22
+ - [Command line](#command-line)
23
+ - [How conversion works](#how-conversion-works)
24
+ - [Development](#development)
25
+ - [Changelog and license](#changelog-and-license)
26
+
27
+ ## Installation
28
+
29
+ **Requires Node.js 22.12 or later.** CI tests Node.js 22 and 24 on Linux, macOS, and Windows.
30
+
31
+ ```sh
32
+ npm install oslllo-svg-fixer
33
+ # Or:
34
+ yarn add oslllo-svg-fixer
35
+ ```
36
+
37
+ This README describes the current source on `master`. Check the release's requirements when using an older package version.
38
+
39
+ ## Quick start
8
40
 
9
- 🎉 v3.0.0 Is now 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89).
41
+ ```js
42
+ const fs = require("node:fs");
43
+ const SVGFixer = require("oslllo-svg-fixer");
10
44
 
11
- 🎉 v2.0.0 Removed `Canvas & JSDOM` no more slow `npm install` cycles.
45
+ async function main() {
46
+ fs.mkdirSync("fixed", { recursive: true });
47
+ await SVGFixer("icons", "fixed").fix();
48
+ console.log("Saved fixed icons");
49
+ }
12
50
 
13
- Attempts to fix your svg by turning it into a fill / single path (and making it font compatible as a bonus).
51
+ main().catch(console.error);
52
+ ```
53
+
54
+ The following examples use the same `SVGFixer` import. Examples containing `await` belong inside an async function.
55
+
56
+ ## Files and directories
14
57
 
15
- ## Convert SVG Strokes To Fills
58
+ `SVGFixer(source, destination, options?)` creates an instance, with or without `new`.
16
59
 
17
- ---
60
+ | Parameter | Meaning |
61
+ | --- | --- |
62
+ | `source` | Path to one `.svg` file or a directory containing `.svg` files |
63
+ | `destination` | Output directory; must already exist by default |
64
+ | `options` | Optional conversion settings described below |
18
65
 
19
- ![Strokes To Files Demo](docs/images/demo.gif)
66
+ Directory discovery processes lowercase `*.svg` files directly inside the source directory; it does not recurse into subdirectories. Output files keep their original basenames. Existing output files with the same names are overwritten, so choose a separate destination when retaining the originals.
20
67
 
21
- ---
68
+ ```js
69
+ // One file; destination is still a directory.
70
+ const fixer = await SVGFixer("icons/example.svg", "fixed").fix();
22
71
 
23
- ## Documentation, Installation, and Usage Instructions
72
+ // All SVGs immediately inside a directory.
73
+ await SVGFixer("icons", "fixed", { traceResolution: 1200 }).fix();
74
+ ```
24
75
 
25
- See the full installation and usage documentation [HERE](https://docs.oslllo.com/svg-fixer/master/).
76
+ `.fix()` returns a Promise resolving to the fixer instance. With a callback, it returns the instance immediately and calls `callback(err, fixer)` when processing finishes:
26
77
 
27
- ### The Objective
78
+ ```js
79
+ SVGFixer("icons", "fixed").fix((err, fixer) => {
80
+ if (err) {
81
+ console.error(err);
82
+ return;
83
+ }
84
+ console.log(`Saved ${fixer.source.length} icons`);
85
+ });
86
+ ```
28
87
 
29
- I wanted to convert some `svg icons` to `fonts` using tools like [icomoon.io](https://icomoon.io/app/#/select), [fontello.com](http://fontello.com) and [webfont](https://www.npmjs.com/package/webfont)
88
+ Constructor validation can throw synchronously, including when paths are invalid. Handle conversion failures through Promise rejections or callback errors.
30
89
 
31
- ### The Problem / Why
90
+ ## SVG strings and Buffers
32
91
 
33
- If your svg containts `strokes` or any tags besides a single `path` e.g `polygon` `rect` `line` etc, you will get these errors when trying to convert them into fonts.
92
+ `SVGFixer.fixString(svg, resolution = 600)` accepts SVG markup as a string or Buffer and returns a Promise resolving to fixed SVG markup. It does not read a file path, write files, or use a callback.
34
93
 
35
- ---
94
+ ```js
95
+ const source = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="black" stroke-width="2"/></svg>';
36
96
 
37
- ### Example
97
+ const fixed = await SVGFixer.fixString(source);
98
+ const higherResolution = await SVGFixer.fixString(Buffer.from(source), 1200);
99
+ ```
38
100
 
39
- ##### SVG
101
+ Invalid input types throw synchronously; rendering and tracing errors reject the returned Promise.
40
102
 
41
- `Icon` -> <small>we will be using in this example</small>
103
+ ## Options
42
104
 
43
- ![SVG Icon](docs/images/svg-icon.png)
105
+ | Option | Default | Meaning |
106
+ | --- | --- | --- |
107
+ | `showProgressBar` | `false` | Show progress while processing files |
108
+ | `throwIfDestinationDoesNotExist` | `true` | Throw when the output directory is missing |
109
+ | `traceResolution` | `600` | Width in pixels of the raster image used for tracing; height follows the original aspect ratio |
44
110
 
45
- `Code` -> <small>for the icon</small>
111
+ A larger trace resolution can improve detail at the cost of processing time and memory. Use a positive resolution. This value controls the intermediate image, not the final SVG's intended dimensions.
46
112
 
47
- ```xml
48
- <svg
49
- xmlns="http://www.w3.org/2000/svg"
50
- width="24"
51
- height="24"
52
- viewBox="0 0 24 24"
53
- fill="none"
54
- stroke="currentColor"
55
- stroke-width="2"
56
- stroke-linecap="round"
57
- stroke-linejoin="round">
58
- <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
59
- <line x1="9" y1="9" x2="15" y2="15" />
60
- <line x1="15" y1="9" x2="9" y2="15" />
61
- </svg>
113
+ ```js
114
+ await SVGFixer("icons", "fixed", {
115
+ showProgressBar: true,
116
+ throwIfDestinationDoesNotExist: false,
117
+ traceResolution: 600,
118
+ }).fix();
62
119
  ```
63
120
 
64
- ---
121
+ With `throwIfDestinationDoesNotExist: false`, the destination directory is created if missing. Its parent directory must already exist; creation is not recursive.
65
122
 
66
- ### Errors
123
+ ## Command line
67
124
 
68
- When we try to convert this `SVG` into a font using one of these `SVG To Font` conversion tools we get the following errors.
125
+ Use the locally installed binary:
69
126
 
70
- | [icomoon.io](https://icomoon.io/app/#/select) error | [fontello.com](http://fontello.com) error | [webfont](https://www.npmjs.com/package/webfont) error |
71
- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
72
- | [![Icomoon Error](docs/images/icomoon-error.png)](docs/images/icomoon-error.png) | [![Fontello Error](docs/images/fontello-error.png)](docs/images/fontello-error.png) | [![Webfont Error](docs/images/webfont-error.png)](docs/images/webfont-error.png) |
127
+ ```sh
128
+ npx oslllo-svg-fixer --source icons --destination fixed
129
+ npx oslllo-svg-fixer -s icons/example.svg -d fixed --trace-resolution 1200
130
+ npx oslllo-svg-fixer -s icons -d fixed --strict-destination=false --show-progress=false
131
+ npx oslllo-svg-fixer --help
132
+ ```
73
133
 
74
- <!-- ### WHAT HAPPENDS IF WE IGNORE THESE ERRORS? -->
134
+ Or install globally:
75
135
 
76
- ### Ignoring The Errors
136
+ ```sh
137
+ npm install --global oslllo-svg-fixer
138
+ oslllo-svg-fixer -s icons -d fixed
139
+ ```
77
140
 
78
- <!-- ### What Happends If We Ignore These Errors? -->
141
+ | Flag | Alias | Default | Meaning |
142
+ | --- | --- | --- | --- |
143
+ | `--source` | `-s` | Required | Source file or directory |
144
+ | `--destination` | `-d` | Required | Output directory |
145
+ | `--strict-destination` | `--sd` | `true` | Require the destination to exist |
146
+ | `--show-progress` | `--sp` | `true` | Show progress; enabled by default in the CLI |
147
+ | `--trace-resolution` | `--tr` | `600` | Intermediate raster width |
148
+ | `--help` | | | Show usage |
149
+ | `--version` | | | Show package version |
79
150
 
80
- What happends if you ignore these errors? well, the font pack with the icon(s) will come out `"corrupt/incorrect"`, `different than expected` or `not even render at all` (blank).
151
+ Pass source and destination as named flags. Exit code `0` means success; `1` means failure.
81
152
 
82
- ### Results From Ignoring The Errors
153
+ ## How conversion works
83
154
 
84
- > The icon not showning up or rendering in the font pack when we ignore the errors and just create the font anyway.
155
+ SVG Fixer uses **SVG2** to render an enlarged SVG as a PNG, then **Potrace** to trace the image into one path containing the outlines. File conversions run through a Piscina worker pool. `fixString()` calls the conversion pipeline directly.
85
156
 
86
- | [icomoon.io](https://icomoon.io/app/#/select) blank | [fontello.com](http://fontello.com) blank | [webfont](https://www.npmjs.com/package/webfont) blank <small style="color: #9a9a9a">using [fontdrop.info](https://fontdrop.info) to preview the font</small> |
87
- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
88
- | [![Icomoon Blank](docs/images/icomoon-blank.png)](docs/images/icomoon-blank.png) | [![Fontello Blank](docs/images/fontello-blank.png)](docs/images/fontello-blank.png) | [![Webfont Blank](docs/images/webfont-blank.png)](docs/images/webfont-blank.png) |
157
+ This is rasterization followed by tracing, so curves and fine details can change. The result is intended for monochrome icon outlines, rather than preserving multicolor artwork, text, filters, or SVG structure. The generated path uses `stroke="none"` and `fill-rule="evenodd"`.
89
158
 
90
- ### The Solution
159
+ The converter restores original root attributes and selected attributes from the first original path. It normalizes the root `viewBox` origin to `0 0`; do not assume every attribute or coordinate system is preserved exactly. Review the output for artwork with unusual fills, multiple colors, or offset view boxes.
91
160
 
92
- I created this `package` to solve this issue, now you can `"fix"` svg icons to make then font compatable by running them through `SVGFixer`.
161
+ The current package depends on the published **SVG2 v6** and **Potrace v6** releases, even though their sibling repositories may contain newer changes. Editing a sibling checkout does not automatically change the installed dependencies used here.
93
162
 
94
- ### Fixing The Icon
163
+ ## Development
95
164
 
96
- The icon in a font pack after we run it through [`SVGFixer()`](https://github.com/oslllo/svg-fixer).
165
+ CI runs on pull requests targeting `master`, pushes to `master`, and manual dispatch. Tests cover Node.js 22 and 24 on Linux, macOS, and Windows, plus Node.js 22.12.0 on Linux to verify the minimum supported version.
97
166
 
98
- | [icomoon.io](https://icomoon.io/app/#/select) fixed | [fontello.com](http://fontello.com) fixed | [webfont](https://www.npmjs.com/package/webfont) fixed <small style="color: #9a9a9a">using [fontdrop.info](https://fontdrop.info) to preview the font</small> |
99
- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100
- | [![Icomoon Fixed](docs/images/icomoon-fixed.png)](docs/images/icomoon-fixed.png) | [![Fontello Fixed](docs/images/fontello-fixed.png)](docs/images/fontello-fixed.png) | [![Webfont Fixed](docs/images/webfont-fixed.png)](docs/images/webfont-fixed.png) |
167
+ The dependency overrides select patched `glob` and `minimatch` versions for the test tooling. Keep these overrides until upstream dependencies adopt the patched versions.
101
168
 
102
- ---
169
+ ```sh
170
+ npm ci
171
+ npm test
172
+ ```
103
173
 
104
- ### Fixed SVG Code
174
+ `npm test` runs the main tests, output checks, and ESLint with coverage collection. Main tests include file and string conversion, options, paths, callbacks, progress, and the CLI. Output tests compare rendering and inspect paths and attributes.
105
175
 
106
- ```xml
107
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.620 2.025 C 4.212 2.105,4.087 2.139,3.870 2.227 C 2.989 2.585,2.321 3.364,2.076 4.320 C 1.993 4.647,1.992 19.351,2.076 19.677 C 2.357 20.776,3.117 21.553,4.260 21.915 C 4.439 21.971,5.243 21.979,11.820 21.990 C 16.818 21.998,19.268 21.989,19.453 21.960 C 20.643 21.777,21.620 20.876,21.924 19.680 C 22.007 19.352,22.008 4.648,21.924 4.323 C 21.617 3.126,20.660 2.233,19.480 2.043 C 19.234 2.003,4.819 1.986,4.620 2.025 M19.340 4.066 C 19.455 4.105,19.603 4.201,19.701 4.299 C 20.025 4.623,20.000 3.977,20.000 12.000 C 20.000 20.023,20.025 19.377,19.701 19.701 C 19.377 20.025,20.023 20.000,12.000 20.000 C 3.975 20.000,4.623 20.025,4.298 19.700 C 3.974 19.376,3.998 20.028,4.010 11.918 L 4.020 4.700 4.131 4.511 C 4.256 4.298,4.449 4.136,4.670 4.057 C 4.793 4.013,6.104 4.003,11.983 4.002 C 18.548 4.000,19.162 4.006,19.340 4.066 M8.643 8.069 C 8.291 8.193,8.000 8.614,8.000 9.000 C 8.000 9.080,8.030 9.234,8.066 9.343 C 8.123 9.517,8.276 9.685,9.354 10.770 L 10.577 12.000 9.354 13.230 C 8.276 14.315,8.123 14.483,8.066 14.657 C 7.936 15.046,8.021 15.423,8.299 15.701 C 8.577 15.979,8.954 16.064,9.343 15.934 C 9.517 15.877,9.685 15.724,10.770 14.646 L 12.000 13.423 13.230 14.646 C 14.315 15.724,14.483 15.877,14.657 15.934 C 15.046 16.064,15.423 15.979,15.701 15.701 C 15.979 15.423,16.064 15.046,15.934 14.657 C 15.877 14.483,15.724 14.315,14.646 13.230 L 13.423 12.000 14.646 10.770 C 15.724 9.685,15.877 9.517,15.934 9.343 C 16.064 8.954,15.979 8.577,15.701 8.299 C 15.423 8.021,15.046 7.936,14.657 8.066 C 14.483 8.123,14.315 8.276,13.230 9.354 L 12.000 10.577 10.770 9.354 C 9.685 8.276,9.517 8.123,9.343 8.066 C 9.102 7.985,8.877 7.986,8.643 8.069 " stroke="none" fill="black" fill-rule="evenodd"></path></svg>
176
+ ```sh
177
+ npm run test:all # Main tests followed by output checks, without lint
178
+ npm run test:cli # CLI tests only
179
+ npm run lint
180
+ npm run coverage # Generate LCOV after collecting coverage
108
181
  ```
109
182
 
110
- ---
183
+ ## Changelog and license
184
+
185
+ See [CHANGELOG.md](CHANGELOG.md) for release history and [LICENSE](LICENSE) for the MIT license of SVG Fixer. Its tracing dependency, `oslllo-potrace`, is licensed separately under GPL-2.0.
186
+
187
+ Created by [oslllo](https://github.com/oslllo). The project was built to prepare icons for tools such as IcoMoon, Fontello, and webfont. Conversion uses SVG2 and Potrace; worker processing uses Piscina.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-svg-fixer",
3
- "version": "5.0.0",
3
+ "version": "7.0.0",
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
  },
@@ -41,31 +42,32 @@
41
42
  "bugs": {
42
43
  "url": "https://github.com/oslllo/svg-fixer/issues"
43
44
  },
44
- "homepage": "https://docs.oslllo.com/svg-fixer/master",
45
45
  "dependencies": {
46
46
  "ansi-colors": "^4.1.3",
47
47
  "cli-progress": "^3.12.0",
48
48
  "fast-glob": "^3.3.1",
49
- "oslllo-potrace": "^3.0.0",
50
- "oslllo-svg2": "^3.0.0",
51
- "oslllo-validator": "^3.1.0",
52
- "piscina": "^4.1.0",
49
+ "oslllo-potrace": "^6.0.0",
50
+ "oslllo-svg2": "^6.0.0",
51
+ "oslllo-validator": "^4.0.0",
52
+ "piscina": "^4.9.4",
53
53
  "yargs": "^16.2.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "chai": "^4.3.8",
57
57
  "chai-as-promised": "^7.1.1",
58
- "coveralls": "^3.1.1",
59
58
  "eslint": "^7.32.0",
60
59
  "fs-extra": "^10.1.0",
61
60
  "inquirer": "^8.2.6",
62
61
  "looks-same": "^7.3.0",
63
- "mocha": "^9.2.2",
64
- "mocha-lcov-reporter": "^1.3.0",
65
- "nyc": "^15.1.0",
62
+ "mocha": "^12.0.3",
63
+ "nyc": "^18.0.0",
66
64
  "stopwatch-node": "^1.1.0"
67
65
  },
68
66
  "engines": {
69
- "node": ">=18.0.0"
67
+ "node": ">=22.12.0"
68
+ },
69
+ "overrides": {
70
+ "glob@^13.0.0": "^14.0.7",
71
+ "minimatch@^10.0.0": "^11.0.10"
70
72
  }
71
73
  }
package/src/cli.js CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  const SVGFixer = require("../");
6
6
  const colors = require("ansi-colors");
7
+ const fs = require("fs");
7
8
  var argvs = require("yargs/yargs")(process.argv.slice(2)); // eslint-disable-line no-magic-numbers
8
9
 
9
10
  argvs
@@ -55,8 +56,9 @@ const options = {
55
56
  await SVGFixer(source, destination, options).fix();
56
57
  process.exit(0); // eslint-disable-line no-process-exit, no-magic-numbers
57
58
  } catch (err) {
58
- console.log("\n" + colors.red("ERR: " + err.message + "\n")); // eslint-disable-line no-console
59
- console.log(colors.yellow("STACK: " + err.stack + "\n")); // eslint-disable-line no-console
59
+ const message = "\n" + colors.red("ERR: " + err.message + "\n") +
60
+ colors.yellow("STACK: " + err.stack + "\n");
61
+ fs.writeSync(process.stdout.fd, message);
60
62
  process.exit(1); // eslint-disable-line no-process-exit, no-magic-numbers
61
63
  }
62
64
  })();
@@ -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,392 +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
- ## [5.0.0](https://github.com/oslllo/svg-fixer/compare/v4.0.1...v5.0.0) (2024-07-21)
9
-
10
-
11
- ### Breaking Changes
12
-
13
- * Breaking changes will only affect users on node 21.x, as the security fixes will throw a deprication warning that might
14
- cause the fixer to exit if you are using it in a cli. See https://github.com/yarnpkg/yarn/issues/9005 for more details.
15
-
16
- ### Bug Fixes
17
-
18
- * security vulnerabilities ([0ade74b](https://github.com/oslllo/svg-fixer/commit/0ade74b4813387c5af448da815ed5f9e667f1c16))
19
-
20
- ## [4.0.1](https://github.com/oslllo/svg-fixer/compare/v4.0.0...v4.0.1) (2024-03-27)
21
-
22
-
23
- ### Bug Fixes
24
-
25
- * security vulnerabilities ([81cc6ac](https://github.com/oslllo/svg-fixer/commit/81cc6ac7e1ba5a446aad6c4206872ee6c3ca8e8b))
26
-
27
- ## [4.0.0](https://github.com/oslllo/svg-fixer/compare/v3.0.0...v4.0.0) (2024-03-26)
28
-
29
- ### Breaking
30
- * drop support for node 16
31
-
32
- ### Bug Fixes
33
-
34
- * node version ([8a45ad0](https://github.com/oslllo/svg-fixer/commit/8a45ad02df73759d99ef58a467edaf6697415292))
35
- * 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))
36
-
37
- ## [3.0.0](https://github.com/oslllo/svg-fixer/compare/v2.2.0...v3.0.0) (2023-09-16)
38
-
39
- ⚠️ Contains breaking changes.
40
-
41
- ### Breaking Changes
42
-
43
- * Dropped support for node `<16.0.0`
44
- * This version will not work with `<16.0.0`
45
-
46
- ### Features
47
-
48
- * Made the tool 11x faster thanks to @ericfennis, see [#89](https://github.com/oslllo/svg-fixer/pull/89)
49
-
50
- ### Bug Fixes
51
-
52
- * update release actions ([a1a66fe](https://github.com/oslllo/svg-fixer/commit/a1a66fe13539eb5e76c9cb6ac574e35da421636d))
53
-
54
- ## [2.2.0](https://www.github.com/oslllo/svg-fixer/compare/v2.1.2...v2.2.0) (2022-10-19)
55
-
56
-
57
- ### Features
58
-
59
- * 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))
60
-
61
- ### [2.1.2](https://www.github.com/oslllo/svg-fixer/compare/v2.1.0...v2.1.2) (2022-07-16)
62
-
63
-
64
- ### Miscellaneous Chores
65
-
66
- * release 2.1.2 ([fd8cdaf](https://www.github.com/oslllo/svg-fixer/commit/fd8cdaf08b4645fe3fad229fefa9a97ec9124c9e))
67
-
68
- ## 2.1.1 (2022-05-1)
69
-
70
- ### Chore
71
-
72
- - update dependencies
73
- - npm audit fix
74
-
75
-
76
- ## [2.1.0](https://www.github.com/oslllo/svg-fixer/compare/v2.0.1...v2.1.1) (2022-03-8)
77
-
78
- ### Added
79
-
80
- - add configurable trace resolution ([#72](https://github.com/oslllo/svg-fixer/pull/72))
81
-
82
- ### Updated
83
-
84
- - Updated dependencies
85
-
86
- ## [2.0.1](https://www.github.com/oslllo/svg-fixer/compare/v2.0.0...v2.0.1) (2022-01-21)
87
-
88
-
89
- ### Refactor
90
-
91
- - improve perfomance ([3b310aa](https://github.com/oslllo/svg-fixer/commit/3b310aaf3bf39f47b0bb56a722f03d40ad6a1b31))
92
-
93
- ## [2.0.0](https://www.github.com/oslllo/svg-fixer/compare/v1.4.1...v2.0.0) (2022-01-12)
94
-
95
- 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.
96
-
97
- ### Changed
98
-
99
- - Removed `Canvas & JSDOM` to fix very slow `npm install` cycles.
100
- - Switched from `Canvas` to `svg2png-wasm`.
101
-
102
- ### Updated
103
-
104
- - Updated dependencies
105
-
106
-
107
- ## [1.4.1](https://www.github.com/oslllo/svg-fixer/compare/v1.4.0...v1.4.1) (2021-09-05)
108
-
109
-
110
- ### Bug Fixes
111
-
112
- * vulnerabilities ([99621c6](https://www.github.com/oslllo/svg-fixer/commit/99621c6258e52836f0aaaf9876fe4b4859c81ab6))
113
-
114
- ## [1.4.0](https://www.github.com/oslllo/svg-fixer/compare/v1.3.2...v1.4.0) (2021-07-14)
115
-
116
-
117
- ### Features
118
-
119
- * add support for svgs with "ex", "ch", "cm", "mm", "q", "in", "pc", "pt" ([4d2c18e](https://www.github.com/oslllo/svg-fixer/commit/4d2c18ef496b9ce08cbc917e3fbb91d9f352c6ff))
120
- * add support for svgs with fill color in path style attribute ([1aeb079](https://www.github.com/oslllo/svg-fixer/commit/1aeb0794e9693079c79981616ea00e99379c863f))
121
- * support svgs without a set viewBox attribute ([17b876c](https://www.github.com/oslllo/svg-fixer/commit/17b876ce49ed0a047dedb098d47adcccb22ff0cf))
122
-
123
- ### [1.3.2](https://www.github.com/oslllo/svg-fixer/compare/v1.3.1...v1.3.2) (2021-06-26)
124
-
125
-
126
- ### Bug Fixes
127
-
128
- * security vulnerabilities ([372730b](https://www.github.com/oslllo/svg-fixer/commit/372730bef6cf761877961796635fc406a2ecc776))
129
-
130
- ### [1.3.1](https://www.github.com/oslllo/svg-fixer/compare/v1.3.0...v1.3.1) (2021-05-27)
131
-
132
-
133
- ### Bug Fixes
134
-
135
- * 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))
136
-
137
- ## [1.3.0](https://www.github.com/oslllo/svg-fixer/compare/v1.2.1...v1.3.0) (2021-05-15)
138
-
139
-
140
- ### Features
141
-
142
- * 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))
143
-
144
-
145
- ### Bug Fixes
146
-
147
- * **eslint:** script error ([d34780e](https://www.github.com/oslllo/svg-fixer/commit/d34780e1db64d350695f5be7c4713136f9c66331))
148
-
149
- ### [1.2.1](https://www.github.com/oslllo/svg-fixer/compare/v1.2.0...v1.2.1) (2021-05-06)
150
-
151
-
152
- ### Bug Fixes
153
-
154
- * drop yargs version to 16 ([7b4d9cc](https://www.github.com/oslllo/svg-fixer/commit/7b4d9ccb563027b24aefe59d394848b8937067b9))
155
- * package breaking when process.env.NODE_ENV env variable is set ([51c6318](https://www.github.com/oslllo/svg-fixer/commit/51c6318340b97d6840ab7d2c499c77aff27b6f10))
156
-
157
- ## [1.2.0] - 2021/4/1
158
-
159
- ### Fixed
160
-
161
- - Fixed bug in test.
162
-
163
- ### Updated
164
-
165
- - Updated dependencies.
166
-
167
- ## [1.1.2] - 2020/12/12
168
-
169
- ### Fixed
170
-
171
- - Fixed vulnerability.
172
-
173
- ### Updated
174
-
175
- - Updated dependencies.
176
-
177
- ## [1.1.1] - 2020/10/22
178
-
179
- ### Fixed
180
-
181
- - Fixed large npm package.
182
-
183
- ## [1.1.0] - 2020/10/22
184
-
185
- ### Fixed
186
-
187
- - Fixed bug that allowed you to update `options` that do not exist.
188
-
189
- ### Added
190
-
191
- - Added `CLI` functionality.
192
- - Added `callback` functionality to `SVGFixer.fix()`.
193
-
194
- ### Changed
195
-
196
- - Refactored `tests`.
197
- - Refactored `progress bar`.
198
-
199
- ## [1.0.2] - 2020/10/2
200
-
201
- ### Fixed
202
-
203
- - Fixed not being able to process SVGs with `%` dimensions.
204
-
205
- ### Added
206
-
207
- - SVG attribute tests.
208
-
209
- ## [1.0.1] - 2020/9/16
210
-
211
- ### Changed
212
-
213
- - Remove tests from npm `package` to help reduce unpacked `package` size.
214
-
215
- ## [1.0.0] - 2020/9/16
216
-
217
- ⚠️ Contains breaking changes.
218
-
219
- ### Breaking Changes
220
-
221
- - `svgfixer.fix(source, destination, options)` ***=>*** `SVGFixer(source, destination, options).fix()`.
222
- - It was changed from a wrapper function to a method function for `SVGFixer`.
223
- - It still returns a `Promise`.
224
- - `fix()` no more takes in `parameters`, those should be passed into `SVGFixer()`.
225
- - `svgfixer.SVGFixer()` class ***=>*** `SVGFixer()`.
226
- - The `.setOptions(options)` method has been removed, `options` should now be passed in class constructor as the 3rd `parameter`.
227
- - The `.setSourceAndDest()` method has been removed, `source` and `destination` should now be passed in class constructor as the 1st and 2nd `parameters`.
228
- - The `.process()` method has been removed, use `.fix()` instead.
229
- - `SVGFixer()` does not require the [`new`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) operator anymore.
230
- - `fixConcurrency` has been removed, might be reimplemented on later versions.
231
-
232
- ### Changed
233
-
234
- - Updated dependencies.
235
- - Refactored codebase.
236
- - Refactored progressbar.
237
-
238
- ## [0.6.0] - 2020/8/13
239
-
240
- ### Security
241
-
242
- - Updated dependencies. Fixes [Vulnerability](https://npmjs.com/advisories/1548)
243
-
244
- ### Changed
245
-
246
- - Updated image processor.
247
- - Updated `CHANGELOG.md` wording and formatting.
248
-
249
- ## [0.5.1] - 2020/7/7
250
-
251
- ### Changed
252
-
253
- - Updated `README.md`.
254
-
255
- ### Added
256
-
257
- - Documentation.
258
-
259
- ## [0.5.0] - 2020/6/13
260
-
261
- ### Changed
262
-
263
- - Changed image processing engine from Sharp to Jimp. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
264
- - Refactored async pools (fixConcurrency).
265
-
266
- ### Fixed
267
-
268
- - Fixed pathing issues on windows. Fixes [#8](https://github.com/oslllo/svg-fixer/issues/8)
269
-
270
- ## [0.4.4] - 2020/6/8
271
-
272
- ### Changed
273
-
274
- - Updated dependencies. Fixes [#7](https://github.com/oslllo/svg-fixer/issues/7)
275
-
276
- ## [0.4.3] - 2020/6/2
277
-
278
- ### Changed
279
-
280
- - Updated `package.json` description.
281
-
282
- ## [0.4.2] - 2020/5/24
283
-
284
- ### Fixed
285
-
286
- - 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))
287
-
288
- ## [0.4.1] - 2020/5/16
289
-
290
- ### Security
291
-
292
- - Fixed [Vulnerability](https://www.npmjs.com/advisories/1500)
293
-
294
- ## [0.4.0] - 2020/5/14
295
-
296
- ### Added
297
-
298
- - Added new parameter `fixConcurrency` to control how many svgs to fix at a given time.
299
- - Added new tests
300
- - Added an perfomance increase by ~67%
301
-
302
- |Version|completion (%)|Time (seconds)|Number of SVGs fixed|
303
- |------|------|-----|-----|
304
- |v0.4.0|100.00|~ 127|1315|
305
- |v0.3.3|100.00|~ 190|1315|
306
- |-|-|-|-|
307
- |**VPS**|**CPU**|**RAM**|||
308
- ||Intel(R) Xeon(R) E5-1650 v3 3.50GHz (2x) | 1548MiB|||
309
-
310
- ### Fixed
311
-
312
- - Fixed tests
313
-
314
- ### Changed
315
-
316
- - Reduceed npm package size.
317
- - Updated `README.md`.
318
-
319
- ## [0.3.3] - 2020/5/12
320
-
321
- ### Added
322
-
323
- - Added badge links to `README.md`.
324
- - Added new tags to `package.json`.
325
-
326
- ### Changed
327
-
328
- - Updated `README.md` content.
329
-
330
- ## [0.3.2] - 2020/5/10
331
-
332
- ### Changed
333
-
334
- - Updated README.md
335
-
336
- ## [0.3.1] - 2020/5/9
337
-
338
- ### Changed
339
-
340
- - Updated `README.md`
341
-
342
- ## [0.3.0] - 2020/5/8
343
-
344
- ### Changed
345
-
346
- - Refactored the whole codebase.
347
- - Updated README.md
348
-
349
- ### Added
350
-
351
- - Added tests
352
- - Added slight performance increase.
353
-
354
- ## [0.2.0] - 2020/4/18
355
-
356
- ### Added
357
-
358
- - Added progress bar
359
-
360
- ## [0.1.0] - 2020/4/17
361
-
362
- ### Added
363
-
364
- - Added [CHANGELOG.md](https://github.com/oslllo/svg-fixer/blob/master/CHANGELOG.md)
365
- - Create destination folder if it does not exist.
366
-
367
- ### Changed
368
-
369
- - Switched from `fs` to `fs-extra`
370
- - Changed `SvgFixer()` function name from `SvgFixer` to `svgFixer` because its a function not a class.
371
-
372
- ### Removed
373
-
374
- - Removed debug functions
375
-
376
- ## [0.0.3] - 2020/4/16
377
-
378
- ### Added
379
-
380
- - Added package.json description
381
-
382
- ## [0.0.2] - 2020/4/16
383
-
384
- ### Added
385
-
386
- - Added [README.md](https://github.com/oslllo/svg-fixer/blob/master/README.md)
387
-
388
- ## [0.0.1] - 2020/4/16
389
-
390
- ### Added
391
-
392
- - Added everything, initial release.