postcss-svgo
Advanced tools
Comparing version 2.0.4 to 2.1.0
@@ -0,1 +1,5 @@ | ||
# 2.1.0 | ||
* Adds `encode` option (thanks to @TrySound). | ||
# 2.0.4 | ||
@@ -2,0 +6,0 @@ |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -22,6 +26,8 @@ | ||
var dataURI = /data:image\/svg\+xml(;(charset=)?utf-8)?,/; | ||
var encode = encodeURIComponent; | ||
var encode = function encode(data) { | ||
return data.replace(/"/g, '\'').replace(/</g, '%3C').replace(/>/g, '%3E').replace(/&/g, '%26').replace(/#/g, '%23').replace(/\s+/g, ' '); | ||
}; | ||
var decode = decodeURIComponent; | ||
function minifyPromise(svgo, decl) { | ||
function minifyPromise(svgo, decl, opts) { | ||
var promises = []; | ||
@@ -34,12 +40,12 @@ | ||
var value = node.nodes[0].value; | ||
var isUriEncoded = undefined; | ||
try { | ||
var encodedUri = decode(value); | ||
isUriEncoded = encodedUri !== value; | ||
if (isUriEncoded) { | ||
value = encodedUri; | ||
} | ||
} catch (err) { | ||
isUriEncoded = false; | ||
var decodedUri = decode(value); | ||
var isUriEncoded = decodedUri !== value; | ||
if (isUriEncoded) { | ||
value = decodedUri; | ||
} | ||
if (opts.encode !== undefined) { | ||
isUriEncoded = opts.encode; | ||
} | ||
if (!dataURI.test(value) || !(0, _isSvg2['default'])(value)) { | ||
@@ -56,5 +62,4 @@ return; | ||
node.nodes[0].value = 'data:image/svg+xml;charset=utf-8,' + data; | ||
if (node.nodes[0].type === 'string') { | ||
node.nodes[0].quote = '\''; | ||
} | ||
node.nodes[0].quote = isUriEncoded ? '"' : '\''; | ||
node.nodes[0].type = 'string'; | ||
resolve(); | ||
@@ -72,3 +77,5 @@ }); | ||
module.exports = _postcss2['default'].plugin('postcss-svgo', function (opts) { | ||
exports['default'] = _postcss2['default'].plugin('postcss-svgo', function () { | ||
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var svgo = new _svgo2['default'](opts); | ||
@@ -80,3 +87,3 @@ return function (css) { | ||
if (dataURI.test(decl.value)) { | ||
promises.push(minifyPromise(svgo, decl)); | ||
promises.push(minifyPromise(svgo, decl, opts)); | ||
} | ||
@@ -87,2 +94,3 @@ }); | ||
}; | ||
}); | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-svgo", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Optimise inline SVG with PostCSS.", | ||
@@ -27,3 +27,3 @@ "main": "dist/index.js", | ||
"babel": "^5.8.21", | ||
"babel-tape-runner": "^1.2.0", | ||
"babel-tape-runner": "1.2.0", | ||
"pleeease-filters": "^2.0.0", | ||
@@ -30,0 +30,0 @@ "tap-spec": "^4.1.0", |
@@ -19,3 +19,3 @@ # [postcss][postcss]-svgo [![Build Status](https://travis-ci.org/ben-eb/postcss-svgo.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-svgo.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-svgo.svg)][deps] | ||
h1 { | ||
background: url('data:image/svg+xml;utf-8,<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"><circle cx="50" cy="50" r="40" fill="yellow" /></svg>'); | ||
background: url('data:image/svg+xml;charset=utf-8,<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"><circle cx="50" cy="50" r="40" fill="yellow" /></svg>'); | ||
} | ||
@@ -28,3 +28,3 @@ ``` | ||
h1 { | ||
background: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="#ff0"/></svg>'); | ||
background: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="#ff0"/></svg>'); | ||
} | ||
@@ -55,2 +55,11 @@ ``` | ||
##### encode | ||
Type: `boolean` | ||
Default: `undefined` | ||
If `true`, it will encode URL-unsafe characters such as `<`, `>` and `#`; | ||
`false` will decode these characters, and `undefined` will neither encode nor | ||
decode the original input. | ||
##### plugins | ||
@@ -57,0 +66,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
8831
70
116