Comparing version 0.6.2 to 0.6.3
@@ -0,1 +1,18 @@ | ||
### [ [>](https://github.com/svg/svgo/tree/v0.6.3) ] 0.6.3 / 20.03.2016 | ||
* Smart rounding (introduced in 0.4.5) now applies only when rounding is needed, thus making subsequent passes more stable. | ||
* Fixed regression in converting curves to arcs. | ||
* `xlink:href` references are now being checked by local name `href`, thus correctly working with another namespace prefix. | ||
* Fixed `id` removing with disabled `plugins/convertStyleToAttrs.js`. | ||
### [ [>](https://github.com/svg/svgo/tree/v0.6.2) ] 0.6.2 / 08.03.2016 | ||
* Better error handling and messaging improvements. | ||
* SVG files with XML entities (e.g. from Adobe Illustrator) are now correctly being parsed. | ||
* Fixed error on converting curves to arcs. | ||
* Corrected rounding in subsequent passes with `--multipass` option. | ||
* Data URI option now handles charset (by @holymonson) | ||
* Tranformations are no longer moved to group if there is a mask (`plugins/moveElemsAttrsToGroup.js`). | ||
* Fixed matrix decomposition losing sign in case like `[1, 0, 0, -1, 0, 0]` (`scale(1 -1)`). | ||
* Fixed crash on uppercased color name. | ||
* Paths with `id` and without `stroke-width` aren't being trasformed now since `stroke-width` may be applied later. | ||
### [ [>](https://github.com/svg/svgo/tree/v0.6.1) ] 0.6.1 / 21.11.2015 | ||
@@ -2,0 +19,0 @@ * Added option `--quiet` to suppress output (by @phihag). |
@@ -136,2 +136,45 @@ 'use strict'; | ||
/** | ||
* Determine if element has an attribute by local name | ||
* (any, or by name or by name + value). | ||
* | ||
* @param {String} [localName] local attribute name | ||
* @param {Number|String|RegExp|Function} [val] attribute value (will be toString()'ed or executed, otherwise ignored) | ||
* @return {Boolean} | ||
*/ | ||
JSAPI.prototype.hasAttrLocal = function(localName, val) { | ||
if (!this.attrs || !Object.keys(this.attrs).length) return false; | ||
if (!arguments.length) return !!this.attrs; | ||
var callback; | ||
switch (val != null && val.constructor && val.constructor.name) { | ||
case 'Number': // same as String | ||
case 'String': callback = stringValueTest; break; | ||
case 'RegExp': callback = regexpValueTest; break; | ||
case 'Function': callback = funcValueTest; break; | ||
default: callback = nameTest; | ||
} | ||
return this.someAttr(callback); | ||
function nameTest(attr) { | ||
return attr.local === localName; | ||
} | ||
function stringValueTest(attr) { | ||
return attr.local === localName && val == attr.value; | ||
} | ||
function regexpValueTest(attr) { | ||
return attr.local === localName && val.test(attr.value); | ||
} | ||
function funcValueTest(attr) { | ||
return attr.local === localName && val(attr.value); | ||
} | ||
}; | ||
/** | ||
* Get a specific attribute from an element | ||
@@ -138,0 +181,0 @@ * (by name or name + value). |
{ | ||
"name": "svgo", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Nodejs-based tool for optimizing SVG vector graphics files", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -2295,3 +2295,4 @@ 'use strict'; | ||
'mask', | ||
'stroke' | ||
'stroke', | ||
'style' | ||
]; | ||
@@ -2298,0 +2299,0 @@ |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var referencesProps = require('./_collections').referencesProps, | ||
regReferencesUrl = /^url\(("|')?#(.+?)\1\)$/, | ||
regReferencesUrl = /\burl\(("|')?#(.+?)\1\)/, | ||
regReferencesHref = /^#(.+?)$/, | ||
@@ -95,3 +95,3 @@ regReferencesBegin = /^(\w+?)\./, | ||
else if ( | ||
attr.name === 'xlink:href' && (match = attr.value.match(regReferencesHref)) || | ||
attr.local === 'href' && (match = attr.value.match(regReferencesHref)) || | ||
attr.name === 'begin' && (match = attr.value.match(regReferencesBegin)) | ||
@@ -98,0 +98,0 @@ ) { |
@@ -62,3 +62,3 @@ 'use strict'; | ||
error = precision !== false ? +Math.pow(.1, precision).toFixed(precision) : 1e-2; | ||
roundData = precision > 0 ? strongRound : round; | ||
roundData = precision > 0 && precision < 20 ? strongRound : round; | ||
if (params.makeArcs) { | ||
@@ -331,3 +331,9 @@ arcThreshold = params.makeArcs.threshold; | ||
arc.data[6] = arc.coords[1] - arc.base[1]; | ||
angle += findArcAngle(prev.instruction == 'a' ? prev.sdata : prev.data, relCircle); | ||
var prevData = prev.instruction == 'a' ? prev.sdata : prev.data; | ||
angle += findArcAngle(prevData, | ||
{ | ||
center: [prevData[4] + relCenter[0], prevData[5] + relCenter[1]], | ||
radius: circle.radius | ||
} | ||
); | ||
if (angle > Math.PI) arc.data[3] = 1; | ||
@@ -754,3 +760,4 @@ hasPrev = 1; | ||
* in path data keeping a specified number of decimals. | ||
* Smart rounds values like 2.349 to 2.35. | ||
* Smart rounds values like 2.3491 to 2.35 instead of 2.349. | ||
* Doesn't apply "smartness" if the number precision fits already. | ||
* | ||
@@ -762,6 +769,8 @@ * @param {Array} data input data array | ||
for (var i = data.length; i-- > 0;) { | ||
var rounded = +data[i].toFixed(precision - 1); | ||
data[i] = +Math.abs(rounded - data[i]).toFixed(precision) > error ? | ||
+data[i].toFixed(precision) : | ||
rounded; | ||
if (data[i].toFixed(precision) != data[i]) { | ||
var rounded = +data[i].toFixed(precision - 1); | ||
data[i] = +Math.abs(rounded - data[i]).toFixed(precision + 1) >= error ? | ||
+data[i].toFixed(precision) : | ||
rounded; | ||
} | ||
} | ||
@@ -768,0 +777,0 @@ return data; |
@@ -135,5 +135,11 @@ 'use strict'; | ||
floatRound = params.floatPrecision >= 1 ? smartRound.bind(this, params.floatPrecision) : round; | ||
degRound = params.degPrecision >= 1 ? smartRound.bind(this, params.degPrecision) : round; | ||
transformRound = params.transformPrecision >= 1 ? smartRound.bind(this, params.transformPrecision) : round; | ||
floatRound = params.floatPrecision >= 1 && params.floatPrecision < 20 ? | ||
smartRound.bind(this, params.floatPrecision) : | ||
round; | ||
degRound = params.degPrecision >= 1 && params.floatPrecision < 20 ? | ||
smartRound.bind(this, params.degPrecision) : | ||
round; | ||
transformRound = params.transformPrecision >= 1 && params.floatPrecision < 20 ? | ||
smartRound.bind(this, params.transformPrecision) : | ||
round; | ||
@@ -350,9 +356,11 @@ return params; | ||
function smartRound(precision, data) { | ||
for (var i = data.length, tolerance = Math.pow(.1, precision); i--;) { | ||
var rounded = +data[i].toFixed(precision - 1); | ||
data[i] = +Math.abs(rounded - data[i]).toFixed(precision) >= tolerance ? | ||
+data[i].toFixed(precision) : | ||
rounded; | ||
for (var i = data.length, tolerance = +Math.pow(.1, precision).toFixed(precision); i--;) { | ||
if (data[i].toFixed(precision) != data[i]) { | ||
var rounded = +data[i].toFixed(precision - 1); | ||
data[i] = +Math.abs(rounded - data[i]).toFixed(precision + 1) >= tolerance ? | ||
+data[i].toFixed(precision) : | ||
rounded; | ||
} | ||
} | ||
return data; | ||
} |
@@ -30,4 +30,4 @@ 'use strict'; | ||
return !(item.isElem(container) && !item.isElem('svg') && item.isEmpty() && | ||
(!item.isElem('pattern') || !item.hasAttr('xlink:href'))); | ||
(!item.isElem('pattern') || !item.hasAttrLocal('href'))); | ||
}; |
@@ -56,5 +56,5 @@ 'use strict'; | ||
item.isElem('tref') && | ||
!item.hasAttr('xlink:href') | ||
!item.hasAttrLocal('href') | ||
) return false; | ||
}; |
@@ -23,4 +23,3 @@ 'use strict'; | ||
item.isElem('image') && | ||
item.hasAttr('xlink:href') && | ||
/(\.|image\/)(jpg|png|gif)/.test(item.attr('xlink:href').value) | ||
item.hasAttrLocal('href', /(\.|image\/)(jpg|png|gif)/) | ||
) { | ||
@@ -27,0 +26,0 @@ return false; |
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
325774
8564