postcss-svgo
Advanced tools
Comparing version 5.0.0-rc.1 to 5.0.0-rc.2
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-svgo@5.0.0-rc.1...postcss-svgo@5.0.0-rc.2) (2021-03-15) | ||
### Bug Fixes | ||
* update SVGO ([aa07cfd](https://github.com/cssnano/cssnano/commit/aa07cfd62c82ed4b1e87219eea8d0ed99635e4ca)) | ||
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-svgo@5.0.0-rc.0...postcss-svgo@5.0.0-rc.1) (2021-03-04) | ||
@@ -8,0 +19,0 @@ |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _svgo = _interopRequireDefault(require("svgo")); | ||
var _svgo = require("svgo"); | ||
@@ -23,4 +23,3 @@ var _isSvg = _interopRequireDefault(require("is-svg")); | ||
function minifyPromise(decl, getSvgo, opts) { | ||
const promises = []; | ||
function minify(decl, opts) { | ||
const parsed = (0, _postcssValueParser.default)(decl.value); | ||
@@ -68,44 +67,42 @@ decl.value = parsed.walk(node => { | ||
promises.push(getSvgo().optimize(svg).then(result => { | ||
let data, optimizedValue; | ||
let result; | ||
if (isBase64) { | ||
data = Buffer.from(result.data).toString('base64'); | ||
optimizedValue = 'data:image/svg+xml;base64,' + data + url.hash; | ||
} else { | ||
data = isUriEncoded ? (0, _url.encode)(result.data) : result.data; // Should always encode # otherwise we yield a broken SVG | ||
// in Firefox (works in Chrome however). See this issue: | ||
// https://github.com/cssnano/cssnano/issues/245 | ||
try { | ||
result = (0, _svgo.optimize)(svg, opts); | ||
data = data.replace(/#/g, '%23'); | ||
optimizedValue = 'data:image/svg+xml;charset=utf-8,' + data; | ||
quote = isUriEncoded ? '"' : "'"; | ||
if (result.error) { | ||
throw new Error(`${PLUGIN}: ${result.error}`); | ||
} | ||
} catch (error) { | ||
throw new Error(`${PLUGIN}: ${error}`); | ||
} | ||
node.nodes[0] = Object.assign({}, node.nodes[0], { | ||
value: optimizedValue, | ||
quote: quote, | ||
type: 'string', | ||
before: '', | ||
after: '' | ||
}); | ||
}).catch(error => { | ||
throw new Error(`${PLUGIN}: ${error}`); | ||
})); | ||
let data, optimizedValue; | ||
if (isBase64) { | ||
data = Buffer.from(result.data).toString('base64'); | ||
optimizedValue = 'data:image/svg+xml;base64,' + data + url.hash; | ||
} else { | ||
data = isUriEncoded ? (0, _url.encode)(result.data) : result.data; // Should always encode # otherwise we yield a broken SVG | ||
// in Firefox (works in Chrome however). See this issue: | ||
// https://github.com/cssnano/cssnano/issues/245 | ||
data = data.replace(/#/g, '%23'); | ||
optimizedValue = 'data:image/svg+xml;charset=utf-8,' + data; | ||
quote = isUriEncoded ? '"' : "'"; | ||
} | ||
node.nodes[0] = Object.assign({}, node.nodes[0], { | ||
value: optimizedValue, | ||
quote: quote, | ||
type: 'string', | ||
before: '', | ||
after: '' | ||
}); | ||
return false; | ||
}); | ||
return Promise.all(promises).then(() => decl.value = decl.value.toString()); | ||
decl.value = decl.value.toString(); | ||
} | ||
function pluginCreator(opts = {}) { | ||
let svgo = null; | ||
const getSvgo = () => { | ||
if (!svgo) { | ||
svgo = new _svgo.default(opts); | ||
} | ||
return svgo; | ||
}; | ||
return { | ||
@@ -115,12 +112,8 @@ postcssPlugin: PLUGIN, | ||
OnceExit(css) { | ||
return new Promise((resolve, reject) => { | ||
const svgoQueue = []; | ||
css.walkDecls(decl => { | ||
if (!dataURI.test(decl.value)) { | ||
return; | ||
} | ||
css.walkDecls(decl => { | ||
if (!dataURI.test(decl.value)) { | ||
return; | ||
} | ||
svgoQueue.push(minifyPromise(decl, getSvgo, opts)); | ||
}); | ||
return Promise.all(svgoQueue).then(resolve, reject); | ||
minify(decl, opts); | ||
}); | ||
@@ -127,0 +120,0 @@ } |
{ | ||
"name": "postcss-svgo", | ||
"version": "5.0.0-rc.1", | ||
"version": "5.0.0-rc.2", | ||
"description": "Optimise inline SVG with PostCSS.", | ||
@@ -35,3 +35,3 @@ "main": "dist/index.js", | ||
"postcss-value-parser": "^4.1.0", | ||
"svgo": "^1.3.2" | ||
"svgo": "^2.2.2" | ||
}, | ||
@@ -50,3 +50,3 @@ "bugs": { | ||
}, | ||
"gitHead": "114efb0092fff944dd4c8a28d184add24d8fde3e" | ||
"gitHead": "5ba19ca54892f76ba6b2b698b4d88adcabd4451b" | ||
} |
@@ -46,18 +46,2 @@ # [postcss][postcss]-svgo | ||
Note that postcss-svgo is an *asynchronous* processor. It cannot be used | ||
like this: | ||
```js | ||
var result = postcss([ svgo() ]).process(css).css; | ||
console.log(result); | ||
``` | ||
Instead make sure your PostCSS runner uses the asynchronous API: | ||
```js | ||
postcss([ svgo() ]).process(css).then(function (result) { | ||
console.log(result.css); | ||
}); | ||
``` | ||
#### options | ||
@@ -64,0 +48,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10895
107
111
+ Added@trysound/sax@0.2.0(transitive)
+ Addedcommander@7.2.0(transitive)
+ Addedcss-select@4.3.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomhandler@4.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedsvgo@2.8.0(transitive)
- Removed@types/q@1.5.8(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedarray-buffer-byte-length@1.0.1(transitive)
- Removedarray.prototype.reduce@1.0.7(transitive)
- Removedarraybuffer.prototype.slice@1.0.3(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcoa@2.0.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcss-select@2.1.0(transitive)
- Removedcss-select-base-adapter@0.1.1(transitive)
- Removedcss-tree@1.0.0-alpha.37(transitive)
- Removedcss-what@3.4.2(transitive)
- Removeddata-view-buffer@1.0.1(transitive)
- Removeddata-view-byte-length@1.0.1(transitive)
- Removeddata-view-byte-offset@1.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedes-abstract@1.23.5(transitive)
- Removedes-array-method-boxes-properly@1.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.2.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesprima@4.0.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.6(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-symbol-description@1.0.2(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-bigints@1.0.2(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinternal-slot@1.0.7(transitive)
- Removedis-array-buffer@3.0.4(transitive)
- Removedis-bigint@1.0.4(transitive)
- Removedis-boolean-object@1.1.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-data-view@1.0.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-negative-zero@2.0.3(transitive)
- Removedis-number-object@1.0.7(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedis-shared-array-buffer@1.0.3(transitive)
- Removedis-string@1.0.7(transitive)
- Removedis-symbol@1.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedis-weakref@1.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedmdn-data@2.0.4(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednth-check@1.0.2(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedobject.getownpropertydescriptors@2.1.8(transitive)
- Removedobject.values@1.2.0(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedq@1.5.1(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsafe-array-concat@1.1.2(transitive)
- Removedsafe-regex-test@1.0.3(transitive)
- Removedsax@1.2.4(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring.prototype.trim@1.2.9(transitive)
- Removedstring.prototype.trimend@1.0.8(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsvgo@1.3.2(transitive)
- Removedtyped-array-buffer@1.0.2(transitive)
- Removedtyped-array-byte-length@1.0.1(transitive)
- Removedtyped-array-byte-offset@1.0.2(transitive)
- Removedtyped-array-length@1.0.6(transitive)
- Removedunbox-primitive@1.0.2(transitive)
- Removedunquote@1.1.1(transitive)
- Removedutil.promisify@1.0.1(transitive)
- Removedwhich-boxed-primitive@1.0.2(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
Updatedsvgo@^2.2.2