Created
October 1, 2016 10:34
-
-
Save fyrebase/4604f540bc4a329ff3bfde225775d39e to your computer and use it in GitHub Desktop.
Convert dimensions to viewBox - SVGO Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins: | |
... | |
- convertDimensions | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.type = 'full'; | |
exports.active = false; | |
exports.description = 'removes width and height in presence of viewBox'; | |
/** | |
* Convert width/height to viewBox. Remove width/height attributes when a viewBox attribute converted. | |
* | |
* @author Kirk Bentley / Fyrebase | |
*/ | |
exports.fn = function(data) { | |
var svg = data.content[0]; | |
if (svg.isElem('svg')) { | |
svg.addAttr({ | |
name: 'viewBox', | |
value: '0 0 ' + svg.attr('width').value + ' ' + svg.attr('height').value, | |
prefix: '', | |
local: 'class' | |
}); | |
svg.removeAttr('width'); | |
svg.removeAttr('height'); | |
} | |
return data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment