mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
round viewBox too
This commit is contained in:
@ -6,8 +6,7 @@ exports.active = false;
|
||||
|
||||
exports.description = 'removes viewBox attribute when possible (disabled by default)';
|
||||
|
||||
var regViewBox = /^0\s*[,\s]\s*0\s*[,\s]\s*([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s*[,\s]\s*([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)$/,
|
||||
viewBoxElems = ['svg', 'pattern'];
|
||||
var viewBoxElems = ['svg', 'pattern', 'symbol'];
|
||||
|
||||
/**
|
||||
* Remove viewBox attr which coincides with a width/height box.
|
||||
@ -33,15 +32,13 @@ exports.fn = function(item) {
|
||||
item.hasAttr('height')
|
||||
) {
|
||||
|
||||
var match = item.attr('viewBox').value.match(regViewBox);
|
||||
var nums = item.attr('viewBox').value.split(/[ ,]+/g);
|
||||
|
||||
if (match) {
|
||||
if (
|
||||
item.attr('width').value === match[1] &&
|
||||
item.attr('height').value === match[3]
|
||||
) {
|
||||
item.removeAttr('viewBox');
|
||||
}
|
||||
if (
|
||||
item.attr('width').value.replace(/px$/, '') === nums[2] && // could use parseFloat too
|
||||
item.attr('height').value.replace(/px$/, '') === nums[3]
|
||||
) {
|
||||
item.removeAttr('viewBox');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user