aboutsummaryrefslogtreecommitdiff
path: root/node_modules/svgo/plugins/removeAttrs.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/svgo/plugins/removeAttrs.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/svgo/plugins/removeAttrs.js')
-rw-r--r--node_modules/svgo/plugins/removeAttrs.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/node_modules/svgo/plugins/removeAttrs.js b/node_modules/svgo/plugins/removeAttrs.js
new file mode 100644
index 00000000..bd2fca62
--- /dev/null
+++ b/node_modules/svgo/plugins/removeAttrs.js
@@ -0,0 +1,119 @@
+'use strict';
+
+var ELEM_SEP = ':';
+
+exports.type = 'perItem';
+
+exports.active = false;
+
+exports.description = 'removes specified attributes';
+
+exports.params = {
+ attrs: []
+};
+
+/**
+ * Remove attributes
+ *
+ * @param attrs:
+ *
+ * format: [ element* : attribute* ]
+ *
+ * element : regexp (wrapped into ^...$), single * or omitted > all elements
+ * attribute : regexp (wrapped into ^...$)
+ *
+ * examples:
+ *
+ * > basic: remove fill attribute
+ * ---
+ * removeAttrs:
+ * attrs: 'fill'
+ *
+ * > remove fill attribute on path element
+ * ---
+ * attrs: 'path:fill'
+ *
+ *
+ * > remove all fill and stroke attribute
+ * ---
+ * attrs:
+ * - 'fill'
+ * - 'stroke'
+ *
+ * [is same as]
+ *
+ * attrs: '(fill|stroke)'
+ *
+ * [is same as]
+ *
+ * attrs: '*:(fill|stroke)'
+ *
+ * [is same as]
+ *
+ * attrs: '.*:(fill|stroke)'
+ *
+ *
+ * > remove all stroke related attributes
+ * ----
+ * attrs: 'stroke.*'
+ *
+ *
+ * @param {Object} item current iteration item
+ * @param {Object} params plugin params
+ * @return {Boolean} if false, item will be filtered out
+ *
+ * @author Benny Schudel
+ */
+exports.fn = function(item, params) {
+
+ // wrap into an array if params is not
+ if (!Array.isArray(params.attrs)) {
+ params.attrs = [params.attrs];
+ }
+
+ if (item.isElem()) {
+
+ // prepare patterns
+ var patterns = params.attrs.map(function(pattern) {
+
+ // apply to all elements if specifc element is omitted
+ if (pattern.indexOf(ELEM_SEP) === -1) {
+ pattern = ['.*', ELEM_SEP, pattern].join('');
+ }
+
+ // create regexps for element and attribute name
+ return pattern.split(ELEM_SEP)
+ .map(function(value) {
+
+ // adjust single * to match anything
+ if (value === '*') { value = '.*'; }
+
+ return new RegExp(['^', value, '$'].join(''), 'i');
+ });
+
+ });
+
+ // loop patterns
+ patterns.forEach(function(pattern) {
+
+ // matches element
+ if (pattern[0].test(item.elem)) {
+
+ // loop attributes
+ item.eachAttr(function(attr) {
+ var name = attr.name;
+
+ // matches attribute name
+ if (pattern[1].test(name)) {
+ item.removeAttr(name);
+ }
+
+ });
+
+ }
+
+ });
+
+ }
+
+};