From 99d9c3c13af04ec48c13b32103c9095879cf4fba Mon Sep 17 00:00:00 2001 From: James Ross Date: Wed, 30 Oct 2019 00:20:08 +0000 Subject: [PATCH 01/10] Default `info` on SVGO.optimize API --- lib/svgo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/svgo.js b/lib/svgo.js index c91cfb89a..cd1569fdb 100755 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -22,6 +22,7 @@ var SVGO = function(config) { }; SVGO.prototype.optimize = function(svgstr, info) { + info = info || {}; return new Promise((resolve, reject) => { if (this.config.error) { reject(this.config.error); From d17c429c4f12467fa2beee2d7396bbcb1074bf05 Mon Sep 17 00:00:00 2001 From: Lev Solntsev Date: Wed, 30 Oct 2019 14:00:29 +0300 Subject: [PATCH 02/10] v1.3.2 --- CHANGELOG.md | 3 +++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71eecb830..ed12149fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### [ [>](https://github.com/svg/svgo/tree/v1.3.2) ] 1.3.2 / 30.10.2019 +* Fixed TypeError: Cannot set property 'multipassCount' of undefined + ### [ [>](https://github.com/svg/svgo/tree/v1.3.1) ] 1.3.1 / 29.10.2019 * Updated CSSO version to 4.0.2 fixing the issue with empty semicolons ";;" in styles (thanks to @strarsis and @lahmatiy). * `prefixIds` plugin now runs only once with `--multipass` option (by @strarsis). diff --git a/package-lock.json b/package-lock.json index a03fd67f8..b83f54d95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svgo", - "version": "1.3.1", + "version": "1.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 772f00e83..4f4f18267 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svgo", - "version": "1.3.1", + "version": "1.3.2", "description": "Nodejs-based tool for optimizing SVG vector graphics files", "keywords": [ "svgo", From 72db8ebbbf5aa3ac82a32c5b744cb09deeba5e35 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Thu, 31 Oct 2019 07:34:35 +0100 Subject: [PATCH 03/10] Change wording of API doc comment --- lib/svgo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svgo.js b/lib/svgo.js index cd1569fdb..7d6c2fa31 100755 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -76,7 +76,7 @@ SVGO.prototype._optimizeOnce = function(svgstr, info, callback) { /** * The factory that creates a content item with the helper methods. * - * @param {Object} data which passed to jsAPI constructor + * @param {Object} data which is passed to jsAPI constructor * @returns {JSAPI} content item */ SVGO.prototype.createContentItem = function(data) { From dfe649fa8ddf9ebd69c9ec9e38fd93db236307c7 Mon Sep 17 00:00:00 2001 From: jlherren Date: Tue, 5 Nov 2019 16:41:02 +0100 Subject: [PATCH 04/10] Fix collapsing of repeated commands in convertPathData plugin This fixes #1166 --- plugins/convertPathData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js index e0bcf8dad..986381b81 100644 --- a/plugins/convertPathData.js +++ b/plugins/convertPathData.js @@ -514,7 +514,7 @@ function filters(path, params) { instruction == prev.instruction.toLowerCase() && ( (instruction != 'h' && instruction != 'v') || - (prev.data[0] >= 0) == (item.data[0] >= 0) + (prev.data[0] >= 0) == (data[0] >= 0) )) { prev.data[0] += data[0]; if (instruction != 'h' && instruction != 'v') { From fdf9236d12b861cee926d7ba3f00284ff7884eab Mon Sep 17 00:00:00 2001 From: GreLI Date: Tue, 5 Nov 2019 19:32:02 +0300 Subject: [PATCH 05/10] Add test for collapsing of repeated commands --- test/plugins/convertPathData.04.svg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/plugins/convertPathData.04.svg b/test/plugins/convertPathData.04.svg index 0dae5fde3..c169d833a 100644 --- a/test/plugins/convertPathData.04.svg +++ b/test/plugins/convertPathData.04.svg @@ -5,6 +5,7 @@ + @@@ @@ -16,4 +17,5 @@ + From fafcbd7bd00de03d93ab55429e5841bc70681a14 Mon Sep 17 00:00:00 2001 From: Sviatoslav Bulbakha Date: Fri, 8 Nov 2019 18:36:45 +0300 Subject: [PATCH 06/10] Fix `prefixIds` plugin error with animations Fix #848 --- plugins/prefixIds.js | 31 +++++++++++++++++++++++++++++++ test/plugins/prefixIds.10.svg | 15 +++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/plugins/prefixIds.10.svg diff --git a/plugins/prefixIds.js b/plugins/prefixIds.js index 2222e7eb6..9aff8bf90 100755 --- a/plugins/prefixIds.js +++ b/plugins/prefixIds.js @@ -113,6 +113,35 @@ var addPrefixToUrlAttr = function(attr) { attr.value = 'url(' + idPrefixed + ')'; }; +// prefixes begin/end attribute value +var addPrefixToBeginEndAttr = function(attr) { + if (!attrNotEmpty(attr)) { + return; + } + + var parts = attr.value.split('; ').map(function(val) { + val = val.trim(); + + if (val.endsWith('.end') || val.endsWith('.start')) { + var idPostfix = val.split('.'), + id = idPostfix[0], + postfix = idPostfix[1]; + + var idPrefixed = prefixId(`#${id}`); + + if (!idPrefixed) { + return val; + } + + idPrefixed = idPrefixed.slice(1); + return `${idPrefixed}.${postfix}`; + } else { + return val; + } + }); + + attr.value = parts.join('; '); +}; /** * Prefixes identifiers @@ -238,6 +267,8 @@ exports.fn = function(node, opts, extra) { addPrefixToUrlAttr(node.attrs[referencesProp]); } + addPrefixToBeginEndAttr(node.attrs.begin); + addPrefixToBeginEndAttr(node.attrs.end); return node; }; diff --git a/test/plugins/prefixIds.10.svg b/test/plugins/prefixIds.10.svg new file mode 100644 index 000000000..2013210d1 --- /dev/null +++ b/test/plugins/prefixIds.10.svg @@ -0,0 +1,15 @@ + + + + + + + +@@@ + + + + + + + From 6db82a3323f787329a6fe6db25ae8b3aa63db0af Mon Sep 17 00:00:00 2001 From: GreLI Date: Fri, 8 Nov 2019 18:40:25 +0300 Subject: [PATCH 07/10] Correct test --- test/plugins/prefixIds.10.svg | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/plugins/prefixIds.10.svg b/test/plugins/prefixIds.10.svg index 2013210d1..7b4ce3188 100644 --- a/test/plugins/prefixIds.10.svg +++ b/test/plugins/prefixIds.10.svg @@ -1,15 +1,15 @@ - - - - + + + + @@@ - - - + + + From 1152257505fac490b29dd7e8eed0d7b3bdf8e557 Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Fri, 8 Nov 2019 20:58:43 +0100 Subject: [PATCH 08/10] Perform `cleanupIDs` optimization when style/script tag is empty cleanupIDs plugin is disabled when a script or style tag is present. I assume that this is because they might contain an id. If these tags are empty there is no point in not cleaning the id though. When running svgo with the option `multipass: true`, it allows us to first run `inlineStyles` plugin to empty the style tag. Then, we can run `cleanupIDs` plugin. --- plugins/cleanupIDs.js | 3 ++- test/plugins/cleanupIDs.02.svg | 4 ++-- test/plugins/cleanupIDs.19.svg | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/plugins/cleanupIDs.19.svg diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 918474a04..aebec0510 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -58,7 +58,8 @@ exports.fn = function(data, params) { // quit if @@ -9,7 +9,7 @@ diff --git a/test/plugins/cleanupIDs.19.svg b/test/plugins/cleanupIDs.19.svg new file mode 100644 index 000000000..b961e21bf --- /dev/null +++ b/test/plugins/cleanupIDs.19.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + +@@@ + + + + + + + + + + + From 77464801e7f38a62ca4542033c8099d38b90d5f0 Mon Sep 17 00:00:00 2001 From: alexpavlovich Date: Sat, 9 Nov 2019 21:41:17 +0300 Subject: [PATCH 09/10] Fix cleanupIDs if defs is last elem of svg --- plugins/cleanupIDs.js | 8 ++++--- test/plugins/cleanupIDs.20.svg | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/plugins/cleanupIDs.20.svg diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index aebec0510..71ffb5f93 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -63,11 +63,13 @@ exports.fn = function(data, params) { hasStyleOrScript = true; continue; } + // Don't remove IDs if the whole SVG consists only of defs. - if (item.isElem('defs') && item.parentNode.isElem('svg')) { + if (item.isElem('svg')) { var hasDefsOnly = true; - for (var j = i + 1; j < items.content.length; j++) { - if (items.content[j].isElem()) { + + for (var j = 0; j < item.content.length; j++) { + if (!item.content[j].isElem('defs')) { hasDefsOnly = false; break; } diff --git a/test/plugins/cleanupIDs.20.svg b/test/plugins/cleanupIDs.20.svg new file mode 100644 index 000000000..2fa086946 --- /dev/null +++ b/test/plugins/cleanupIDs.20.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + +@@@ + + + + + + + + + + + + + + + + + + + +@@@ + +{"prefix": "test__", "remove": "false"} From 07ca9764f71fb946adc23f4ea9f19070d335305d Mon Sep 17 00:00:00 2001 From: Eugene Chechuryn Date: Mon, 9 Dec 2019 22:15:47 +0200 Subject: [PATCH 10/10] Add Figma plugin link to Readme --- README.md | 1 + README.ru.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 3b676e0ba..bce6c91a4 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ Arguments: * as a Sketch plugin - [svgo-compressor](https://github.com/BohemianCoding/svgo-compressor) * as macOS app - [Image Shrinker](https://image-shrinker.com) * as a Rollup plugin - [rollup-plugin-svgo](https://github.com/porsager/rollup-plugin-svgo) +* as a Figma plugin - [Advanced SVG Export](https://www.figma.com/c/plugin/782713260363070260/Advanced-SVG-Export) ## Backers diff --git a/README.ru.md b/README.ru.md index 319e963ce..61fe57e21 100644 --- a/README.ru.md +++ b/README.ru.md @@ -197,6 +197,7 @@ $ [sudo] npm install -g svgo * как плагин для Sketch - [svgo-compressor](https://github.com/BohemianCoding/svgo-compressor) * в виде приложения macOS - [Image Shrinker](https://image-shrinker.com) * как плагин для Rollup - [rollup-plugin-svgo](https://github.com/porsager/rollup-plugin-svgo) +* как плагин для Figma - [Advanced SVG Export](https://www.figma.com/c/plugin/782713260363070260/Advanced-SVG-Export) ## Лицензия и копирайты