@iconify/tools 2.0.14 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/colors/attribs.cjs +30 -0
- package/lib/colors/attribs.d.ts +13 -10
- package/lib/colors/attribs.mjs +7 -13
- package/lib/colors/parse.cjs +269 -0
- package/lib/colors/parse.d.ts +15 -11
- package/lib/colors/parse.mjs +27 -31
- package/lib/colors/validate.cjs +52 -0
- package/lib/colors/validate.d.ts +11 -4
- package/lib/colors/validate.mjs +19 -6
- package/lib/css/parse.cjs +26 -0
- package/lib/css/parse.d.ts +3 -1
- package/lib/css/parse.mjs +8 -6
- package/lib/css/parser/error.cjs +25 -0
- package/lib/css/parser/error.d.ts +4 -2
- package/lib/css/parser/error.mjs +2 -4
- package/lib/css/parser/export.cjs +48 -0
- package/lib/css/parser/export.d.ts +5 -2
- package/lib/css/parser/export.mjs +4 -6
- package/lib/css/parser/strings.cjs +77 -0
- package/lib/css/parser/strings.d.ts +6 -3
- package/lib/css/parser/strings.mjs +4 -6
- package/lib/css/parser/text.cjs +135 -0
- package/lib/css/parser/text.d.ts +8 -5
- package/lib/css/parser/text.mjs +3 -8
- package/lib/css/parser/tokens.cjs +184 -0
- package/lib/css/parser/tokens.d.ts +6 -3
- package/lib/css/parser/tokens.mjs +7 -13
- package/lib/css/parser/tree.cjs +42 -0
- package/lib/css/parser/tree.d.ts +5 -2
- package/lib/css/parser/tree.mjs +2 -4
- package/lib/css/parser/types.cjs +2 -0
- package/lib/css/parser/types.d.ts +13 -11
- package/lib/css/parser/types.mjs +1 -0
- package/lib/download/api/cache.cjs +86 -0
- package/lib/download/api/cache.d.ts +8 -5
- package/lib/download/api/cache.mjs +14 -19
- package/lib/download/api/download.cjs +28 -0
- package/lib/download/api/download.d.ts +5 -2
- package/lib/download/api/download.mjs +8 -9
- package/lib/download/api/index.cjs +51 -0
- package/lib/download/api/index.d.ts +5 -2
- package/lib/download/api/index.mjs +8 -6
- package/lib/download/api/types.cjs +2 -0
- package/lib/download/api/types.d.ts +4 -2
- package/lib/download/api/types.mjs +1 -0
- package/lib/download/git/branch.cjs +22 -0
- package/lib/download/git/branch.d.ts +5 -2
- package/lib/download/git/branch.mjs +5 -5
- package/lib/download/git/hash.cjs +15 -0
- package/lib/download/git/hash.d.ts +5 -2
- package/lib/download/git/hash.mjs +5 -5
- package/lib/download/git/index.cjs +76 -0
- package/lib/download/git/index.d.ts +10 -8
- package/lib/download/git/index.mjs +41 -26
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +3 -1
- package/lib/download/git/reset.mjs +29 -5
- package/lib/download/github/hash.cjs +32 -0
- package/lib/download/github/hash.d.ts +5 -2
- package/lib/download/github/hash.mjs +10 -7
- package/lib/download/github/index.cjs +98 -0
- package/lib/download/github/index.d.ts +11 -9
- package/lib/download/github/index.mjs +23 -17
- package/lib/download/github/types.cjs +2 -0
- package/lib/download/github/types.d.ts +3 -1
- package/lib/download/github/types.mjs +1 -0
- package/lib/download/gitlab/hash.cjs +32 -0
- package/lib/download/gitlab/hash.d.ts +5 -2
- package/lib/download/gitlab/hash.mjs +10 -6
- package/lib/download/gitlab/index.cjs +98 -0
- package/lib/download/gitlab/index.d.ts +11 -9
- package/lib/download/gitlab/index.mjs +24 -18
- package/lib/download/gitlab/types.cjs +7 -0
- package/lib/download/gitlab/types.d.ts +4 -2
- package/lib/download/gitlab/types.mjs +3 -5
- package/lib/download/helpers/untar.cjs +14 -0
- package/lib/download/helpers/untar.d.ts +3 -1
- package/lib/download/helpers/untar.mjs +4 -5
- package/lib/download/helpers/unzip.cjs +19 -0
- package/lib/download/helpers/unzip.d.ts +3 -1
- package/lib/download/helpers/unzip.mjs +6 -7
- package/lib/download/index.cjs +64 -0
- package/lib/download/index.d.ts +18 -13
- package/lib/download/index.mjs +46 -19
- package/lib/download/npm/index.cjs +82 -0
- package/lib/download/npm/index.d.ts +10 -8
- package/lib/download/npm/index.mjs +16 -13
- package/lib/download/npm/types.cjs +2 -0
- package/lib/download/npm/types.d.ts +3 -1
- package/lib/download/npm/types.mjs +1 -0
- package/lib/download/npm/version.cjs +23 -0
- package/lib/download/npm/version.d.ts +7 -4
- package/lib/download/npm/version.mjs +8 -10
- package/lib/download/types/modified.cjs +2 -0
- package/lib/download/types/modified.d.ts +3 -1
- package/lib/download/types/modified.mjs +1 -0
- package/lib/download/types/sources.cjs +2 -0
- package/lib/download/types/sources.d.ts +4 -2
- package/lib/download/types/sources.mjs +1 -0
- package/lib/export/directory.cjs +45 -0
- package/lib/export/directory.d.ts +11 -4
- package/lib/export/directory.mjs +8 -8
- package/lib/export/helpers/custom-files.cjs +28 -0
- package/lib/export/helpers/custom-files.d.ts +4 -2
- package/lib/export/helpers/custom-files.mjs +8 -9
- package/lib/export/helpers/prepare.cjs +36 -0
- package/lib/export/helpers/prepare.d.ts +5 -3
- package/lib/export/helpers/prepare.mjs +7 -9
- package/lib/export/helpers/types-version.cjs +22 -0
- package/lib/export/helpers/types-version.d.ts +3 -1
- package/lib/export/helpers/types-version.mjs +15 -37
- package/lib/export/icon-package.cjs +59 -0
- package/lib/export/icon-package.d.ts +12 -5
- package/lib/export/icon-package.mjs +15 -16
- package/lib/export/json-package.cjs +133 -0
- package/lib/export/json-package.d.ts +12 -5
- package/lib/export/json-package.mjs +20 -21
- package/lib/icon-set/index.cjs +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +40 -53
- package/lib/icon-set/match.cjs +58 -0
- package/lib/icon-set/match.d.ts +10 -3
- package/lib/icon-set/match.mjs +5 -6
- package/lib/icon-set/merge.cjs +83 -0
- package/lib/icon-set/merge.d.ts +9 -2
- package/lib/icon-set/merge.mjs +15 -10
- package/lib/icon-set/props.cjs +28 -0
- package/lib/icon-set/props.d.ts +8 -4
- package/lib/icon-set/props.mjs +7 -10
- package/lib/icon-set/types.cjs +2 -0
- package/lib/icon-set/types.d.ts +19 -17
- package/lib/icon-set/types.mjs +1 -0
- package/lib/import/directory.cjs +76 -0
- package/lib/import/directory.d.ts +11 -5
- package/lib/import/directory.mjs +36 -11
- package/lib/import/figma/index.cjs +105 -0
- package/lib/import/figma/index.d.ts +15 -5
- package/lib/import/figma/index.mjs +40 -13
- package/lib/import/figma/nodes.cjs +86 -0
- package/lib/import/figma/nodes.d.ts +13 -4
- package/lib/import/figma/nodes.mjs +3 -11
- package/lib/import/figma/query.cjs +218 -0
- package/lib/import/figma/query.d.ts +18 -9
- package/lib/import/figma/query.mjs +9 -12
- package/lib/import/figma/types/api.cjs +2 -0
- package/lib/import/figma/types/api.d.ts +8 -7
- package/lib/import/figma/types/api.mjs +1 -0
- package/lib/import/figma/types/nodes.cjs +2 -0
- package/lib/import/figma/types/nodes.d.ts +16 -9
- package/lib/import/figma/types/nodes.mjs +1 -0
- package/lib/import/figma/types/options.cjs +2 -0
- package/lib/import/figma/types/options.d.ts +17 -10
- package/lib/import/figma/types/options.mjs +1 -0
- package/lib/import/figma/types/result.cjs +2 -0
- package/lib/import/figma/types/result.d.ts +12 -5
- package/lib/import/figma/types/result.mjs +1 -0
- package/lib/index.cjs +137 -0
- package/lib/index.d.ts +65 -44
- package/lib/index.mjs +83 -94
- package/lib/misc/bump-version.cjs +17 -0
- package/lib/misc/bump-version.d.ts +3 -1
- package/lib/misc/bump-version.mjs +2 -4
- package/lib/misc/compare-dirs.cjs +75 -0
- package/lib/misc/compare-dirs.d.ts +4 -2
- package/lib/misc/compare-dirs.mjs +12 -12
- package/lib/misc/exec.cjs +25 -0
- package/lib/misc/exec.d.ts +6 -4
- package/lib/misc/exec.mjs +4 -5
- package/lib/misc/keyword.cjs +19 -0
- package/lib/misc/keyword.d.ts +3 -1
- package/lib/misc/keyword.mjs +2 -4
- package/lib/misc/scan.cjs +51 -0
- package/lib/misc/scan.d.ts +7 -6
- package/lib/misc/scan.mjs +6 -7
- package/lib/misc/write-json.cjs +11 -0
- package/lib/misc/write-json.d.ts +3 -1
- package/lib/misc/write-json.mjs +5 -6
- package/lib/optimise/flags.cjs +252 -0
- package/lib/optimise/flags.d.ts +7 -2
- package/lib/optimise/flags.mjs +18 -19
- package/lib/optimise/global-style.cjs +154 -0
- package/lib/optimise/global-style.d.ts +7 -2
- package/lib/optimise/global-style.mjs +18 -15
- package/lib/optimise/scale.cjs +26 -0
- package/lib/optimise/scale.d.ts +7 -2
- package/lib/optimise/scale.mjs +5 -5
- package/lib/optimise/svgo.cjs +83 -0
- package/lib/optimise/svgo.d.ts +10 -6
- package/lib/optimise/svgo.mjs +6 -9
- package/lib/svg/analyse/error.cjs +18 -0
- package/lib/svg/analyse/error.d.ts +5 -2
- package/lib/svg/analyse/error.mjs +2 -4
- package/lib/svg/analyse/types.cjs +2 -0
- package/lib/svg/analyse/types.d.ts +11 -11
- package/lib/svg/analyse/types.mjs +1 -0
- package/lib/svg/analyse.cjs +291 -0
- package/lib/svg/analyse.d.ts +8 -3
- package/lib/svg/analyse.mjs +15 -30
- package/lib/svg/cleanup/attribs.cjs +41 -0
- package/lib/svg/cleanup/attribs.d.ts +7 -2
- package/lib/svg/cleanup/attribs.mjs +6 -12
- package/lib/svg/cleanup/bad-tags.cjs +51 -0
- package/lib/svg/cleanup/bad-tags.d.ts +7 -2
- package/lib/svg/cleanup/bad-tags.mjs +10 -25
- package/lib/svg/cleanup/inline-style.cjs +64 -0
- package/lib/svg/cleanup/inline-style.d.ts +7 -2
- package/lib/svg/cleanup/inline-style.mjs +14 -19
- package/lib/svg/cleanup/root-svg.cjs +81 -0
- package/lib/svg/cleanup/root-svg.d.ts +7 -2
- package/lib/svg/cleanup/root-svg.mjs +7 -18
- package/lib/svg/cleanup/svgo-style.cjs +38 -0
- package/lib/svg/cleanup/svgo-style.d.ts +7 -2
- package/lib/svg/cleanup/svgo-style.mjs +16 -11
- package/lib/svg/cleanup.cjs +32 -0
- package/lib/svg/cleanup.d.ts +7 -2
- package/lib/svg/cleanup.mjs +21 -9
- package/lib/svg/data/attributes.cjs +355 -0
- package/lib/svg/data/attributes.d.ts +27 -25
- package/lib/svg/data/attributes.mjs +90 -115
- package/lib/svg/data/tags.cjs +137 -0
- package/lib/svg/data/tags.d.ts +25 -23
- package/lib/svg/data/tags.mjs +25 -49
- package/lib/svg/index.cjs +130 -0
- package/lib/svg/index.d.ts +16 -5
- package/lib/svg/index.mjs +48 -14
- package/lib/svg/parse-style.cjs +134 -0
- package/lib/svg/parse-style.d.ts +12 -8
- package/lib/svg/parse-style.mjs +11 -9
- package/lib/svg/parse.cjs +42 -0
- package/lib/svg/parse.d.ts +11 -7
- package/lib/svg/parse.mjs +2 -4
- package/package.json +99 -94
- package/lib/colors/attribs.js +0 -26
- package/lib/colors/parse.js +0 -341
- package/lib/colors/validate.js +0 -48
- package/lib/css/parse.js +0 -23
- package/lib/css/parser/error.js +0 -27
- package/lib/css/parser/export.js +0 -69
- package/lib/css/parser/strings.js +0 -93
- package/lib/css/parser/text.js +0 -171
- package/lib/css/parser/tokens.js +0 -200
- package/lib/css/parser/tree.js +0 -44
- package/lib/css/parser/types.js +0 -2
- package/lib/download/api/cache.js +0 -108
- package/lib/download/api/download.js +0 -27
- package/lib/download/api/index.js +0 -52
- package/lib/download/api/types.js +0 -2
- package/lib/download/git/branch.js +0 -22
- package/lib/download/git/hash.js +0 -14
- package/lib/download/git/index.js +0 -75
- package/lib/download/git/reset.js +0 -16
- package/lib/download/github/hash.js +0 -28
- package/lib/download/github/index.js +0 -116
- package/lib/download/github/types.js +0 -2
- package/lib/download/gitlab/hash.js +0 -27
- package/lib/download/gitlab/index.js +0 -115
- package/lib/download/gitlab/types.js +0 -7
- package/lib/download/helpers/untar.js +0 -14
- package/lib/download/helpers/unzip.js +0 -18
- package/lib/download/index.js +0 -27
- package/lib/download/npm/index.js +0 -91
- package/lib/download/npm/types.js +0 -2
- package/lib/download/npm/version.js +0 -27
- package/lib/download/types/modified.js +0 -2
- package/lib/download/types/sources.js +0 -2
- package/lib/export/directory.js +0 -52
- package/lib/export/helpers/custom-files.js +0 -32
- package/lib/export/helpers/prepare.js +0 -49
- package/lib/export/helpers/types-version.js +0 -12
- package/lib/export/icon-package.js +0 -77
- package/lib/export/json-package.js +0 -156
- package/lib/icon-set/index.js +0 -749
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -34
- package/lib/icon-set/types.js +0 -2
- package/lib/import/directory.js +0 -59
- package/lib/import/figma/index.js +0 -90
- package/lib/import/figma/nodes.js +0 -106
- package/lib/import/figma/query.js +0 -244
- package/lib/import/figma/types/api.js +0 -12
- package/lib/import/figma/types/nodes.js +0 -2
- package/lib/import/figma/types/options.js +0 -2
- package/lib/import/figma/types/result.js +0 -2
- package/lib/index.js +0 -103
- package/lib/misc/bump-version.js +0 -19
- package/lib/misc/compare-dirs.js +0 -84
- package/lib/misc/exec.js +0 -26
- package/lib/misc/keyword.js +0 -31
- package/lib/misc/scan.js +0 -55
- package/lib/misc/write-json.js +0 -11
- package/lib/optimise/flags.js +0 -312
- package/lib/optimise/global-style.js +0 -185
- package/lib/optimise/scale.js +0 -42
- package/lib/optimise/svgo.js +0 -99
- package/lib/svg/analyse/error.js +0 -22
- package/lib/svg/analyse/types.js +0 -2
- package/lib/svg/analyse.js +0 -352
- package/lib/svg/cleanup/attribs.js +0 -51
- package/lib/svg/cleanup/bad-tags.js +0 -65
- package/lib/svg/cleanup/inline-style.js +0 -77
- package/lib/svg/cleanup/root-svg.js +0 -107
- package/lib/svg/cleanup/svgo-style.js +0 -35
- package/lib/svg/cleanup.js +0 -24
- package/lib/svg/data/attributes.js +0 -403
- package/lib/svg/data/tags.js +0 -188
- package/lib/svg/index.js +0 -134
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanupGlobalStyle = void 0;
|
|
4
|
-
require("../svg/data/attributes");
|
|
5
|
-
const tags_1 = require("../svg/data/tags");
|
|
6
|
-
const parse_1 = require("../svg/parse");
|
|
7
|
-
const parse_style_1 = require("../svg/parse-style");
|
|
8
|
-
function getClassList(value) {
|
|
9
|
-
return value === null || value === void 0 ? void 0 : value.split(/\s+/);
|
|
10
|
-
}
|
|
11
|
-
const tempDataAttrbiute = 'data-gstyle-temp';
|
|
12
|
-
/**
|
|
13
|
-
* Expand global style
|
|
14
|
-
*/
|
|
15
|
-
async function cleanupGlobalStyle(svg) {
|
|
16
|
-
const backup = svg.toString();
|
|
17
|
-
let containsTempAttr = false;
|
|
18
|
-
// Find all animated classes
|
|
19
|
-
const animatedClasses = new Set();
|
|
20
|
-
await (0, parse_1.parseSVG)(svg, (item) => {
|
|
21
|
-
if (!tags_1.animateTags.has(item.tagName)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const $element = item.$element;
|
|
25
|
-
if ($element.attr('attributeName') !== 'class') {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
['from', 'to', 'values'].forEach((attr) => {
|
|
29
|
-
const value = $element.attr(attr);
|
|
30
|
-
if (typeof value !== 'string') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
value.split(';').forEach((item) => {
|
|
34
|
-
getClassList(item).forEach((className) => {
|
|
35
|
-
animatedClasses.add(className);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
// Parse style
|
|
41
|
-
try {
|
|
42
|
-
await (0, parse_style_1.parseSVGStyle)(svg, async (styleItem) => {
|
|
43
|
-
var _a;
|
|
44
|
-
const returnValue = styleItem.value;
|
|
45
|
-
if (styleItem.type !== 'global') {
|
|
46
|
-
return returnValue;
|
|
47
|
-
}
|
|
48
|
-
// Handle only simple selectors
|
|
49
|
-
/*
|
|
50
|
-
if (
|
|
51
|
-
styleItem.selectors.length !== 1 ||
|
|
52
|
-
styleItem.selectorTokens.length !== 1
|
|
53
|
-
) {
|
|
54
|
-
return returnValue;
|
|
55
|
-
}
|
|
56
|
-
*/
|
|
57
|
-
// Do not handle media queries
|
|
58
|
-
const selectorTokens = styleItem.selectorTokens;
|
|
59
|
-
for (let i = 0; i < selectorTokens.length; i++) {
|
|
60
|
-
const selectorToken = selectorTokens[i];
|
|
61
|
-
if (selectorToken.type !== 'selector') {
|
|
62
|
-
return returnValue;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Parse each selectors
|
|
66
|
-
const selectors = styleItem.selectors;
|
|
67
|
-
const matches = [];
|
|
68
|
-
for (let i = 0; i < selectors.length; i++) {
|
|
69
|
-
const selector = styleItem.selectors[i];
|
|
70
|
-
const firstChar = selector.charAt(0);
|
|
71
|
-
let matchType;
|
|
72
|
-
if (firstChar === '.') {
|
|
73
|
-
matchType = 'class';
|
|
74
|
-
}
|
|
75
|
-
else if (firstChar === '#') {
|
|
76
|
-
matchType = 'id';
|
|
77
|
-
}
|
|
78
|
-
else if (tags_1.allValidTags.has(selector)) {
|
|
79
|
-
matchType = 'tag';
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return returnValue;
|
|
83
|
-
}
|
|
84
|
-
const valueMatch = matchType === 'tag' ? selector : selector.slice(1);
|
|
85
|
-
if (matchType === 'class' && animatedClasses.has(valueMatch)) {
|
|
86
|
-
// Class name is used in animations
|
|
87
|
-
return returnValue;
|
|
88
|
-
}
|
|
89
|
-
matches.push({
|
|
90
|
-
type: matchType,
|
|
91
|
-
value: valueMatch,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
// Check if element is a match
|
|
95
|
-
const isMatch = (tagName, $element) => {
|
|
96
|
-
for (let i = 0; i < matches.length; i++) {
|
|
97
|
-
const { type, value } = matches[i];
|
|
98
|
-
switch (type) {
|
|
99
|
-
case 'id':
|
|
100
|
-
if ($element.attr('id') === value) {
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
case 'tag':
|
|
105
|
-
if (tagName === value) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
case 'class': {
|
|
110
|
-
const className = $element.attr('class');
|
|
111
|
-
if (className &&
|
|
112
|
-
getClassList(className).indexOf(value) !== -1) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
};
|
|
120
|
-
// Parse all elements
|
|
121
|
-
await (0, parse_1.parseSVG)(svg, (svgItem) => {
|
|
122
|
-
var _a;
|
|
123
|
-
const tagName = svgItem.tagName;
|
|
124
|
-
const $element = svgItem.$element;
|
|
125
|
-
if (!isMatch(tagName, $element)) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// Transfer attribute
|
|
129
|
-
const addedAttributes = new Set((_a = $element.attr(tempDataAttrbiute)) === null || _a === void 0 ? void 0 : _a.split(/\s+/));
|
|
130
|
-
const prop = styleItem.prop;
|
|
131
|
-
if ($element.attr(prop) !== void 0) {
|
|
132
|
-
// Previously added attribute?
|
|
133
|
-
if (addedAttributes.has(prop)) {
|
|
134
|
-
// Two CSS rules are applied to same element: abort parsing and restore content from backup.
|
|
135
|
-
// This parse is very basic, it does not account for specificity.
|
|
136
|
-
throw new Error('Duplicate attribute');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
$element.attr(prop, styleItem.value);
|
|
140
|
-
addedAttributes.add(prop);
|
|
141
|
-
$element.attr(tempDataAttrbiute, Array.from(addedAttributes).join(' '));
|
|
142
|
-
containsTempAttr = true;
|
|
143
|
-
});
|
|
144
|
-
// Remove class attribute
|
|
145
|
-
const classMatches = matches
|
|
146
|
-
.filter((item) => item.type === 'class')
|
|
147
|
-
.map((item) => item.value);
|
|
148
|
-
if (classMatches.length &&
|
|
149
|
-
((_a = styleItem.nextTokens[0]) === null || _a === void 0 ? void 0 : _a.type) === 'close') {
|
|
150
|
-
// Can remove class
|
|
151
|
-
await (0, parse_1.parseSVG)(svg, (svgItem) => {
|
|
152
|
-
const $element = svgItem.$element;
|
|
153
|
-
if (!isMatch('', $element)) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
// Remove class
|
|
157
|
-
const classList = getClassList($element.attr('class'));
|
|
158
|
-
if (!classList) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const filtered = classList.filter((item) => classMatches.indexOf(item) === -1);
|
|
162
|
-
if (!filtered.length) {
|
|
163
|
-
$element.removeAttr('class');
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
$element.attr('class', filtered.join(' '));
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
// Remove rule
|
|
171
|
-
return;
|
|
172
|
-
});
|
|
173
|
-
// Remove temporary attributes
|
|
174
|
-
if (containsTempAttr) {
|
|
175
|
-
await (0, parse_1.parseSVG)(svg, (item) => {
|
|
176
|
-
item.$element.removeAttr(tempDataAttrbiute);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
// Failed: restore from backup
|
|
182
|
-
svg.load(backup);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
exports.cleanupGlobalStyle = cleanupGlobalStyle;
|
package/lib/optimise/scale.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scaleSVG = void 0;
|
|
4
|
-
const svgo_1 = require("./svgo");
|
|
5
|
-
/**
|
|
6
|
-
* Scale icon
|
|
7
|
-
*/
|
|
8
|
-
async function scaleSVG(svg, scale) {
|
|
9
|
-
const viewBox = svg.viewBox;
|
|
10
|
-
const width = viewBox.width * scale;
|
|
11
|
-
const height = viewBox.height * scale;
|
|
12
|
-
const left = viewBox.left * scale;
|
|
13
|
-
const top = viewBox.top * scale;
|
|
14
|
-
const content = '<svg width="' +
|
|
15
|
-
width +
|
|
16
|
-
'" height="' +
|
|
17
|
-
height +
|
|
18
|
-
'" viewBox="' +
|
|
19
|
-
left +
|
|
20
|
-
' ' +
|
|
21
|
-
top +
|
|
22
|
-
' ' +
|
|
23
|
-
width +
|
|
24
|
-
' ' +
|
|
25
|
-
height +
|
|
26
|
-
'">' +
|
|
27
|
-
'<g transform="scale(' +
|
|
28
|
-
scale +
|
|
29
|
-
')">' +
|
|
30
|
-
svg.getBody() +
|
|
31
|
-
'</g></svg>';
|
|
32
|
-
svg.load(content);
|
|
33
|
-
await (0, svgo_1.runSVGO)(svg, {
|
|
34
|
-
plugins: [
|
|
35
|
-
'collapseGroups',
|
|
36
|
-
'convertTransform',
|
|
37
|
-
'convertPathData',
|
|
38
|
-
'sortAttrs',
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
exports.scaleSVG = scaleSVG;
|
package/lib/optimise/svgo.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runSVGO = exports.shapeModifiyingSVGOPlugins = exports.defaultSVGOPlugins = void 0;
|
|
4
|
-
const svgo_1 = require("svgo");
|
|
5
|
-
exports.defaultSVGOPlugins = [
|
|
6
|
-
'cleanupAttrs',
|
|
7
|
-
'mergeStyles',
|
|
8
|
-
'inlineStyles',
|
|
9
|
-
'removeComments',
|
|
10
|
-
'removeUselessDefs',
|
|
11
|
-
'removeEditorsNSData',
|
|
12
|
-
'removeEmptyAttrs',
|
|
13
|
-
'removeEmptyContainers',
|
|
14
|
-
'convertStyleToAttrs',
|
|
15
|
-
'convertColors',
|
|
16
|
-
'convertTransform',
|
|
17
|
-
'removeUnknownsAndDefaults',
|
|
18
|
-
'removeNonInheritableGroupAttrs',
|
|
19
|
-
'removeUselessStrokeAndFill',
|
|
20
|
-
'removeUnusedNS',
|
|
21
|
-
'cleanupNumericValues',
|
|
22
|
-
'cleanupListOfValues',
|
|
23
|
-
'moveElemsAttrsToGroup',
|
|
24
|
-
'moveGroupAttrsToElems',
|
|
25
|
-
'collapseGroups',
|
|
26
|
-
'sortDefsChildren',
|
|
27
|
-
'sortAttrs',
|
|
28
|
-
];
|
|
29
|
-
/**
|
|
30
|
-
* Plugins that modify shapes. Added to plugins list, unless 'keepShapes' option is enabled
|
|
31
|
-
*/
|
|
32
|
-
exports.shapeModifiyingSVGOPlugins = [
|
|
33
|
-
'removeHiddenElems',
|
|
34
|
-
'convertShapeToPath',
|
|
35
|
-
'convertEllipseToCircle',
|
|
36
|
-
{
|
|
37
|
-
name: 'convertPathData',
|
|
38
|
-
params: {
|
|
39
|
-
noSpaceAfterFlags: true,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'mergePaths',
|
|
44
|
-
params: {
|
|
45
|
-
noSpaceAfterFlags: true,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
// 'removeOffCanvasPaths', // bugged for some icons
|
|
49
|
-
'reusePaths',
|
|
50
|
-
];
|
|
51
|
-
/**
|
|
52
|
-
* Run SVGO on icon
|
|
53
|
-
*/
|
|
54
|
-
async function runSVGO(svg, options = {}) {
|
|
55
|
-
// Code
|
|
56
|
-
const code = svg.toString();
|
|
57
|
-
// Options
|
|
58
|
-
const multipass = options.multipass !== false;
|
|
59
|
-
// Plugins list
|
|
60
|
-
let plugins;
|
|
61
|
-
if (options.plugins) {
|
|
62
|
-
plugins = options.plugins;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
|
|
66
|
-
let keepShapes = options.keepShapes;
|
|
67
|
-
if (keepShapes === void 0 &&
|
|
68
|
-
(code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1)) {
|
|
69
|
-
// Do not check animations: just assume they might break
|
|
70
|
-
keepShapes = true;
|
|
71
|
-
}
|
|
72
|
-
plugins = exports.defaultSVGOPlugins.concat(keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
|
|
73
|
-
? [
|
|
74
|
-
{
|
|
75
|
-
name: 'cleanupIDs',
|
|
76
|
-
params: {
|
|
77
|
-
prefix: typeof options.cleanupIDs === 'string'
|
|
78
|
-
? options.cleanupIDs
|
|
79
|
-
: 'svgID',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
]
|
|
83
|
-
: []);
|
|
84
|
-
}
|
|
85
|
-
// Run SVGO
|
|
86
|
-
const pluginOptions = {
|
|
87
|
-
plugins,
|
|
88
|
-
multipass,
|
|
89
|
-
};
|
|
90
|
-
// Load data (changing type because SVGO types do not include error ?????)
|
|
91
|
-
const result = (0, svgo_1.optimize)(code, pluginOptions);
|
|
92
|
-
if (typeof result.error === 'string') {
|
|
93
|
-
throw new Error(result.error);
|
|
94
|
-
}
|
|
95
|
-
// Sometimes empty definitions are not removed: remove them
|
|
96
|
-
const content = result.data.replace(/<defs\/>/g, '');
|
|
97
|
-
svg.load(content);
|
|
98
|
-
}
|
|
99
|
-
exports.runSVGO = runSVGO;
|
package/lib/svg/analyse/error.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyseTagError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Get tag for error message
|
|
6
|
-
*/
|
|
7
|
-
function analyseTagError(element) {
|
|
8
|
-
let result = '<' + element.tagName;
|
|
9
|
-
if (element._id) {
|
|
10
|
-
result += ' id="' + element._id + '"';
|
|
11
|
-
}
|
|
12
|
-
const attribs = element.attribs;
|
|
13
|
-
if (attribs['d']) {
|
|
14
|
-
const value = attribs['d'];
|
|
15
|
-
result +=
|
|
16
|
-
' d="' +
|
|
17
|
-
(value.length > 16 ? value.slice(0, 12) + '...' : value) +
|
|
18
|
-
'"';
|
|
19
|
-
}
|
|
20
|
-
return result + '>';
|
|
21
|
-
}
|
|
22
|
-
exports.analyseTagError = analyseTagError;
|
package/lib/svg/analyse/types.js
DELETED