1
0
mirror of https://github.com/svg/svgo.git synced 2025-05-04 18:24:45 +03:00
svgo/plugins/removeViewBox.js
2012-10-02 15:48:59 +04:00

43 lines
1.0 KiB
JavaScript

var regViewBox = /^0\s0\s(\d+)\s(\d+)$/,
viewBoxElems = ['svg', 'pattern'];
/**
* Remove viewBox attr which coincides with a width/height box.
*
* @see http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
*
* @example
* <svg width="100" height="50" viewBox="0 0 100 50">
* ⬇
* <svg width="100" height="50">
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.removeViewBox = function(item, params) {
if (
item.isElem(viewBoxElems) &&
item.hasAttr('viewBox') &&
item.hasAttr('width') &&
item.hasAttr('height')
) {
var match;
if (match = item.attr('viewBox').value.match(regViewBox)) {
if (
item.attr('width').value == match[1] &&
item.attr('height').value == match[2]
) {
item.removeAttr('viewBox');
}
}
}
};