From 40ab77680a9dc4fe6b848fc576995c86c6c34f5d Mon Sep 17 00:00:00 2001 From: deepsweet Date: Mon, 17 Dec 2012 22:26:06 +0200 Subject: [PATCH] plugins/cleanupIDs: renamed from removeUnusedIDs; minify used IDs (fix #7) --- .svgo.yml | 5 +- plugins/cleanupIDs.js | 194 ++++++++++++++++ plugins/removeUnusedIDs.js | 147 ------------ ...IDs.01.orig.svg => cleanupIDs.01.orig.svg} | 3 + ...01.should.svg => cleanupIDs.01.should.svg} | 11 +- ...IDs.02.orig.svg => cleanupIDs.02.orig.svg} | 0 ...02.should.svg => cleanupIDs.02.should.svg} | 0 ...IDs.03.orig.svg => cleanupIDs.03.orig.svg} | 0 ...03.should.svg => cleanupIDs.03.should.svg} | 0 test/plugins/cleanupIDs.04.orig.svg | 218 ++++++++++++++++++ test/plugins/cleanupIDs.04.should.svg | 218 ++++++++++++++++++ 11 files changed, 644 insertions(+), 152 deletions(-) create mode 100644 plugins/cleanupIDs.js delete mode 100644 plugins/removeUnusedIDs.js rename test/plugins/{removeUnusedIDs.01.orig.svg => cleanupIDs.01.orig.svg} (89%) rename test/plugins/{removeUnusedIDs.01.should.svg => cleanupIDs.01.should.svg} (61%) rename test/plugins/{removeUnusedIDs.02.orig.svg => cleanupIDs.02.orig.svg} (100%) rename test/plugins/{removeUnusedIDs.02.should.svg => cleanupIDs.02.should.svg} (100%) rename test/plugins/{removeUnusedIDs.03.orig.svg => cleanupIDs.03.orig.svg} (100%) rename test/plugins/{removeUnusedIDs.03.should.svg => cleanupIDs.03.should.svg} (100%) create mode 100644 test/plugins/cleanupIDs.04.orig.svg create mode 100644 test/plugins/cleanupIDs.04.should.svg diff --git a/.svgo.yml b/.svgo.yml index f317693d..f3b65083 100644 --- a/.svgo.yml +++ b/.svgo.yml @@ -150,9 +150,12 @@ plugins: active: true type: full - - name: removeUnusedIDs + - name: cleanupIDs active: true type: full + params: + remove: true + minify: true svg2js: diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js new file mode 100644 index 00000000..dba8037f --- /dev/null +++ b/plugins/cleanupIDs.js @@ -0,0 +1,194 @@ +'use strict'; + +var referencesProps = require('./_collections').referencesProps, + regReferencesUrl = /^url\(#(.+?)\)$/, + regReferencesHref = /^#(.+?)$/, + styleOrScript = ['style', 'script'], + generateIDchars = [ + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' + ], + maxIDindex = generateIDchars.length - 1; + +/** + * Remove unused and minify used IDs + * (only if there are no any