aboutsummaryrefslogtreecommitdiff
path: root/node_modules/svgo/plugins/removeViewBox.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/svgo/plugins/removeViewBox.js')
-rw-r--r--node_modules/svgo/plugins/removeViewBox.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/node_modules/svgo/plugins/removeViewBox.js b/node_modules/svgo/plugins/removeViewBox.js
new file mode 100644
index 00000000..33595656
--- /dev/null
+++ b/node_modules/svgo/plugins/removeViewBox.js
@@ -0,0 +1,49 @@
+'use strict';
+
+exports.type = 'perItem';
+
+exports.active = false;
+
+exports.description = 'removes viewBox attribute when possible (disabled by default)';
+
+var regViewBox = /^0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]?\d*\.?\d+([eE][\-+]?\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
+ * @return {Boolean} if false, item will be filtered out
+ *
+ * @author Kir Belevich
+ */
+exports.fn = function(item) {
+
+ if (
+ item.isElem(viewBoxElems) &&
+ item.hasAttr('viewBox') &&
+ item.hasAttr('width') &&
+ item.hasAttr('height')
+ ) {
+
+ var match = item.attr('viewBox').value.match(regViewBox);
+
+ if (match) {
+ if (
+ item.attr('width').value === match[1] &&
+ item.attr('height').value === match[3]
+ ) {
+ item.removeAttr('viewBox');
+ }
+ }
+
+ }
+
+};