@iconify/tools 2.0.12 → 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 +42 -20
- package/lib/download/git/reset.cjs +41 -0
- package/lib/download/git/reset.d.ts +6 -0
- package/lib/download/git/reset.mjs +37 -0
- 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 +24 -22
- package/lib/icon-set/index.cjs +589 -0
- package/lib/icon-set/index.d.ts +9 -6
- package/lib/icon-set/index.mjs +47 -57
- 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 +9 -12
- 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 +6 -16
- 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 -43
- package/lib/index.mjs +83 -92
- 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 +68 -47
- 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 -11
- 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 +102 -93
- 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 -63
- 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 -151
- package/lib/icon-set/index.js +0 -746
- package/lib/icon-set/match.js +0 -66
- package/lib/icon-set/merge.js +0 -90
- package/lib/icon-set/props.js +0 -33
- 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 -108
- 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 -101
- 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 -158
- 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 -125
- package/lib/svg/parse-style.js +0 -151
- package/lib/svg/parse.js +0 -49
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { allValidTags, animateTags } from '../svg/data/tags.mjs';
|
|
2
|
+
import { parseSVG } from '../svg/parse.mjs';
|
|
3
|
+
import { parseSVGStyle } from '../svg/parse-style.mjs';
|
|
4
|
+
import '../css/parse.mjs';
|
|
5
|
+
import '../css/parser/tokens.mjs';
|
|
6
|
+
import '../css/parser/error.mjs';
|
|
7
|
+
import '../css/parser/strings.mjs';
|
|
8
|
+
import '../css/parser/text.mjs';
|
|
9
|
+
import '../css/parser/export.mjs';
|
|
10
|
+
import '../css/parser/tree.mjs';
|
|
11
|
+
|
|
6
12
|
function getClassList(value) {
|
|
7
|
-
return value
|
|
13
|
+
return value?.split(/\s+/);
|
|
8
14
|
}
|
|
9
|
-
|
|
15
|
+
const tempDataAttrbiute = "data-gstyle-temp";
|
|
10
16
|
async function cleanupGlobalStyle(svg) {
|
|
11
17
|
const backup = svg.toString();
|
|
12
18
|
let containsTempAttr = false;
|
|
13
|
-
const animatedClasses = new Set();
|
|
19
|
+
const animatedClasses = /* @__PURE__ */ new Set();
|
|
14
20
|
await parseSVG(svg, (item) => {
|
|
15
21
|
if (!animateTags.has(item.tagName)) {
|
|
16
22
|
return;
|
|
@@ -33,57 +39,72 @@ async function cleanupGlobalStyle(svg) {
|
|
|
33
39
|
});
|
|
34
40
|
try {
|
|
35
41
|
await parseSVGStyle(svg, async (styleItem) => {
|
|
36
|
-
var _a;
|
|
37
42
|
const returnValue = styleItem.value;
|
|
38
43
|
if (styleItem.type !== "global") {
|
|
39
44
|
return returnValue;
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const selector = styleItem.selectors[0];
|
|
49
|
-
const firstChar = selector.charAt(0);
|
|
50
|
-
let matchType;
|
|
51
|
-
if (firstChar === ".") {
|
|
52
|
-
matchType = "class";
|
|
53
|
-
} else if (firstChar === "#") {
|
|
54
|
-
matchType = "id";
|
|
55
|
-
} else if (allValidTags.has(selector)) {
|
|
56
|
-
matchType = "tag";
|
|
57
|
-
} else {
|
|
58
|
-
return returnValue;
|
|
46
|
+
const selectorTokens = styleItem.selectorTokens;
|
|
47
|
+
for (let i = 0; i < selectorTokens.length; i++) {
|
|
48
|
+
const selectorToken = selectorTokens[i];
|
|
49
|
+
if (selectorToken.type !== "selector") {
|
|
50
|
+
return returnValue;
|
|
51
|
+
}
|
|
59
52
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
const selectors = styleItem.selectors;
|
|
54
|
+
const matches = [];
|
|
55
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
56
|
+
const selector = styleItem.selectors[i];
|
|
57
|
+
const firstChar = selector.charAt(0);
|
|
58
|
+
let matchType;
|
|
59
|
+
if (firstChar === ".") {
|
|
60
|
+
matchType = "class";
|
|
61
|
+
} else if (firstChar === "#") {
|
|
62
|
+
matchType = "id";
|
|
63
|
+
} else if (allValidTags.has(selector)) {
|
|
64
|
+
matchType = "tag";
|
|
65
|
+
} else {
|
|
66
|
+
return returnValue;
|
|
67
|
+
}
|
|
68
|
+
const valueMatch = matchType === "tag" ? selector : selector.slice(1);
|
|
69
|
+
if (matchType === "class" && animatedClasses.has(valueMatch)) {
|
|
70
|
+
return returnValue;
|
|
71
|
+
}
|
|
72
|
+
matches.push({
|
|
73
|
+
type: matchType,
|
|
74
|
+
value: valueMatch
|
|
75
|
+
});
|
|
63
76
|
}
|
|
64
77
|
const isMatch = (tagName, $element) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
for (let i = 0; i < matches.length; i++) {
|
|
79
|
+
const { type, value } = matches[i];
|
|
80
|
+
switch (type) {
|
|
81
|
+
case "id":
|
|
82
|
+
if ($element.attr("id") === value) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case "tag":
|
|
87
|
+
if (tagName === value) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
case "class": {
|
|
92
|
+
const className = $element.attr("class");
|
|
93
|
+
if (className && getClassList(className).indexOf(value) !== -1) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
74
96
|
}
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
|
-
return
|
|
99
|
+
return false;
|
|
78
100
|
};
|
|
79
101
|
await parseSVG(svg, (svgItem) => {
|
|
80
|
-
var _a2;
|
|
81
102
|
const tagName = svgItem.tagName;
|
|
82
103
|
const $element = svgItem.$element;
|
|
83
104
|
if (!isMatch(tagName, $element)) {
|
|
84
105
|
return;
|
|
85
106
|
}
|
|
86
|
-
const addedAttributes = new Set(
|
|
107
|
+
const addedAttributes = new Set($element.attr(tempDataAttrbiute)?.split(/\s+/));
|
|
87
108
|
const prop = styleItem.prop;
|
|
88
109
|
if ($element.attr(prop) !== void 0) {
|
|
89
110
|
if (addedAttributes.has(prop)) {
|
|
@@ -95,7 +116,8 @@ async function cleanupGlobalStyle(svg) {
|
|
|
95
116
|
$element.attr(tempDataAttrbiute, Array.from(addedAttributes).join(" "));
|
|
96
117
|
containsTempAttr = true;
|
|
97
118
|
});
|
|
98
|
-
|
|
119
|
+
const classMatches = matches.filter((item) => item.type === "class").map((item) => item.value);
|
|
120
|
+
if (classMatches.length && styleItem.nextTokens[0]?.type === "close") {
|
|
99
121
|
await parseSVG(svg, (svgItem) => {
|
|
100
122
|
const $element = svgItem.$element;
|
|
101
123
|
if (!isMatch("", $element)) {
|
|
@@ -105,7 +127,7 @@ async function cleanupGlobalStyle(svg) {
|
|
|
105
127
|
if (!classList) {
|
|
106
128
|
return;
|
|
107
129
|
}
|
|
108
|
-
const filtered = classList.filter((item) => item
|
|
130
|
+
const filtered = classList.filter((item) => classMatches.indexOf(item) === -1);
|
|
109
131
|
if (!filtered.length) {
|
|
110
132
|
$element.removeAttr("class");
|
|
111
133
|
} else {
|
|
@@ -124,6 +146,5 @@ async function cleanupGlobalStyle(svg) {
|
|
|
124
146
|
svg.load(backup);
|
|
125
147
|
}
|
|
126
148
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
};
|
|
149
|
+
|
|
150
|
+
export { cleanupGlobalStyle };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const optimise_svgo = require('./svgo.cjs');
|
|
6
|
+
require('svgo');
|
|
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="' + width + '" height="' + height + '" viewBox="' + left + " " + top + " " + width + " " + height + '"><g transform="scale(' + scale + ')">' + svg.getBody() + "</g></svg>";
|
|
15
|
+
svg.load(content);
|
|
16
|
+
await optimise_svgo.runSVGO(svg, {
|
|
17
|
+
plugins: [
|
|
18
|
+
"collapseGroups",
|
|
19
|
+
"convertTransform",
|
|
20
|
+
"convertPathData",
|
|
21
|
+
"sortAttrs"
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.scaleSVG = scaleSVG;
|
package/lib/optimise/scale.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SVG } from '../svg/index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Scale icon
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
declare function scaleSVG(svg: SVG, scale: number): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { scaleSVG };
|
package/lib/optimise/scale.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { runSVGO } from './svgo.mjs';
|
|
2
|
+
import 'svgo';
|
|
3
|
+
|
|
3
4
|
async function scaleSVG(svg, scale) {
|
|
4
5
|
const viewBox = svg.viewBox;
|
|
5
6
|
const width = viewBox.width * scale;
|
|
@@ -17,6 +18,5 @@ async function scaleSVG(svg, scale) {
|
|
|
17
18
|
]
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
21
|
+
|
|
22
|
+
export { scaleSVG };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const svgo = require('svgo');
|
|
6
|
+
|
|
7
|
+
const defaultSVGOPlugins = [
|
|
8
|
+
"cleanupAttrs",
|
|
9
|
+
"mergeStyles",
|
|
10
|
+
"inlineStyles",
|
|
11
|
+
"removeComments",
|
|
12
|
+
"removeUselessDefs",
|
|
13
|
+
"removeEditorsNSData",
|
|
14
|
+
"removeEmptyAttrs",
|
|
15
|
+
"removeEmptyContainers",
|
|
16
|
+
"convertStyleToAttrs",
|
|
17
|
+
"convertColors",
|
|
18
|
+
"convertTransform",
|
|
19
|
+
"removeUnknownsAndDefaults",
|
|
20
|
+
"removeNonInheritableGroupAttrs",
|
|
21
|
+
"removeUselessStrokeAndFill",
|
|
22
|
+
"removeUnusedNS",
|
|
23
|
+
"cleanupNumericValues",
|
|
24
|
+
"cleanupListOfValues",
|
|
25
|
+
"moveElemsAttrsToGroup",
|
|
26
|
+
"moveGroupAttrsToElems",
|
|
27
|
+
"collapseGroups",
|
|
28
|
+
"sortDefsChildren",
|
|
29
|
+
"sortAttrs"
|
|
30
|
+
];
|
|
31
|
+
const shapeModifiyingSVGOPlugins = [
|
|
32
|
+
"removeHiddenElems",
|
|
33
|
+
"convertShapeToPath",
|
|
34
|
+
"convertEllipseToCircle",
|
|
35
|
+
{
|
|
36
|
+
name: "convertPathData",
|
|
37
|
+
params: {
|
|
38
|
+
noSpaceAfterFlags: true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "mergePaths",
|
|
43
|
+
params: {
|
|
44
|
+
noSpaceAfterFlags: true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"reusePaths"
|
|
48
|
+
];
|
|
49
|
+
async function runSVGO(svg, options = {}) {
|
|
50
|
+
const code = svg.toString();
|
|
51
|
+
const multipass = options.multipass !== false;
|
|
52
|
+
let plugins;
|
|
53
|
+
if (options.plugins) {
|
|
54
|
+
plugins = options.plugins;
|
|
55
|
+
} else {
|
|
56
|
+
let keepShapes = options.keepShapes;
|
|
57
|
+
if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
|
|
58
|
+
keepShapes = true;
|
|
59
|
+
}
|
|
60
|
+
plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
|
|
61
|
+
{
|
|
62
|
+
name: "cleanupIDs",
|
|
63
|
+
params: {
|
|
64
|
+
prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
] : []);
|
|
68
|
+
}
|
|
69
|
+
const pluginOptions = {
|
|
70
|
+
plugins,
|
|
71
|
+
multipass
|
|
72
|
+
};
|
|
73
|
+
const result = svgo.optimize(code, pluginOptions);
|
|
74
|
+
if (typeof result.error === "string") {
|
|
75
|
+
throw new Error(result.error);
|
|
76
|
+
}
|
|
77
|
+
const content = result.data.replace(/<defs\/>/g, "");
|
|
78
|
+
svg.load(content);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.defaultSVGOPlugins = defaultSVGOPlugins;
|
|
82
|
+
exports.runSVGO = runSVGO;
|
|
83
|
+
exports.shapeModifiyingSVGOPlugins = shapeModifiyingSVGOPlugins;
|
package/lib/optimise/svgo.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { Plugin } from 'svgo';
|
|
2
|
+
import { SVG } from '../svg/index.js';
|
|
3
|
+
import '@iconify/types';
|
|
4
|
+
import '@iconify/utils/lib/customisations';
|
|
5
|
+
|
|
6
|
+
declare const defaultSVGOPlugins: Plugin[];
|
|
4
7
|
/**
|
|
5
8
|
* Plugins that modify shapes. Added to plugins list, unless 'keepShapes' option is enabled
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
declare const shapeModifiyingSVGOPlugins: Plugin[];
|
|
8
11
|
/**
|
|
9
12
|
* Options
|
|
10
13
|
*/
|
|
@@ -23,5 +26,6 @@ declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
|
|
|
23
26
|
/**
|
|
24
27
|
* Run SVGO on icon
|
|
25
28
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
declare function runSVGO(svg: SVG, options?: SVGOOptions): Promise<void>;
|
|
30
|
+
|
|
31
|
+
export { defaultSVGOPlugins, runSVGO, shapeModifiyingSVGOPlugins };
|
package/lib/optimise/svgo.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { optimize } from 'svgo';
|
|
2
|
+
|
|
3
|
+
const defaultSVGOPlugins = [
|
|
4
4
|
"cleanupAttrs",
|
|
5
5
|
"mergeStyles",
|
|
6
6
|
"inlineStyles",
|
|
@@ -24,7 +24,7 @@ var defaultSVGOPlugins = [
|
|
|
24
24
|
"sortDefsChildren",
|
|
25
25
|
"sortAttrs"
|
|
26
26
|
];
|
|
27
|
-
|
|
27
|
+
const shapeModifiyingSVGOPlugins = [
|
|
28
28
|
"removeHiddenElems",
|
|
29
29
|
"convertShapeToPath",
|
|
30
30
|
"convertEllipseToCircle",
|
|
@@ -73,8 +73,5 @@ async function runSVGO(svg, options = {}) {
|
|
|
73
73
|
const content = result.data.replace(/<defs\/>/g, "");
|
|
74
74
|
svg.load(content);
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
runSVGO,
|
|
79
|
-
shapeModifiyingSVGOPlugins
|
|
80
|
-
};
|
|
76
|
+
|
|
77
|
+
export { defaultSVGOPlugins, runSVGO, shapeModifiyingSVGOPlugins };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function analyseTagError(element) {
|
|
6
|
+
let result = "<" + element.tagName;
|
|
7
|
+
if (element._id) {
|
|
8
|
+
result += ' id="' + element._id + '"';
|
|
9
|
+
}
|
|
10
|
+
const attribs = element.attribs;
|
|
11
|
+
if (attribs["d"]) {
|
|
12
|
+
const value = attribs["d"];
|
|
13
|
+
result += ' d="' + (value.length > 16 ? value.slice(0, 12) + "..." : value) + '"';
|
|
14
|
+
}
|
|
15
|
+
return result + ">";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.analyseTagError = analyseTagError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtendedTagElement } from './types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Get tag for error message
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function analyseTagError(element: ExtendedTagElement): string;
|
|
7
|
+
|
|
8
|
+
export { analyseTagError };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/svg/analyse/error.ts
|
|
2
1
|
function analyseTagError(element) {
|
|
3
2
|
let result = "<" + element.tagName;
|
|
4
3
|
if (element._id) {
|
|
@@ -11,6 +10,5 @@ function analyseTagError(element) {
|
|
|
11
10
|
}
|
|
12
11
|
return result + ">";
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
13
|
+
|
|
14
|
+
export { analyseTagError };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="cheerio" />
|
|
2
1
|
/**
|
|
3
2
|
* Options
|
|
4
3
|
*/
|
|
5
|
-
|
|
4
|
+
interface AnalyseSVGStructureOptions {
|
|
6
5
|
fixErrors?: boolean;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
@@ -11,7 +10,7 @@ export interface AnalyseSVGStructureOptions {
|
|
|
11
10
|
/**
|
|
12
11
|
* Link to element
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
interface LinkToElementWithID {
|
|
15
14
|
id: string;
|
|
16
15
|
usedAsMask: boolean;
|
|
17
16
|
usedByIndex: number;
|
|
@@ -19,7 +18,7 @@ export interface LinkToElementWithID {
|
|
|
19
18
|
/**
|
|
20
19
|
* How element is used by parent elements
|
|
21
20
|
*/
|
|
22
|
-
|
|
21
|
+
interface ExtendedTagElementUses {
|
|
23
22
|
_usedAsMask: boolean;
|
|
24
23
|
_usedAsPaint: boolean;
|
|
25
24
|
}
|
|
@@ -36,7 +35,7 @@ interface ReusableElement {
|
|
|
36
35
|
*
|
|
37
36
|
* Similar to ReusableElement, but not necessary a definition - any element with id. Also contains list of child elements
|
|
38
37
|
*/
|
|
39
|
-
|
|
38
|
+
interface ElementWithID {
|
|
40
39
|
id: string;
|
|
41
40
|
isMask: boolean;
|
|
42
41
|
indexes: Set<number>;
|
|
@@ -51,7 +50,7 @@ interface ExtendedTagElementRelations {
|
|
|
51
50
|
/**
|
|
52
51
|
* Extended tag
|
|
53
52
|
*/
|
|
54
|
-
|
|
53
|
+
interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagElementUses, ExtendedTagElementRelations {
|
|
55
54
|
_index: number;
|
|
56
55
|
_id?: string;
|
|
57
56
|
_belongsTo?: ElementWithID[];
|
|
@@ -61,13 +60,13 @@ export interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagEleme
|
|
|
61
60
|
/**
|
|
62
61
|
* Additional stuff for <svg>
|
|
63
62
|
*/
|
|
64
|
-
|
|
63
|
+
interface ExtendedRootTagElement extends ExtendedTagElement {
|
|
65
64
|
_parsed?: boolean;
|
|
66
65
|
}
|
|
67
66
|
/**
|
|
68
67
|
* Tree
|
|
69
68
|
*/
|
|
70
|
-
|
|
69
|
+
interface ElementsTreeItem {
|
|
71
70
|
index: number;
|
|
72
71
|
usedAsMask: boolean;
|
|
73
72
|
parent?: ElementsTreeItem;
|
|
@@ -76,14 +75,15 @@ export interface ElementsTreeItem {
|
|
|
76
75
|
/**
|
|
77
76
|
* Elements map
|
|
78
77
|
*/
|
|
79
|
-
|
|
78
|
+
declare type ElementsMap = Map<number, ExtendedTagElement>;
|
|
80
79
|
/**
|
|
81
80
|
* Result
|
|
82
81
|
*/
|
|
83
|
-
|
|
82
|
+
interface AnalyseSVGStructureResult {
|
|
84
83
|
elements: ElementsMap;
|
|
85
84
|
ids: Record<string, number>;
|
|
86
85
|
links: LinkToElementWithID[];
|
|
87
86
|
tree: ElementsTreeItem;
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
|
|
89
|
+
export { AnalyseSVGStructureOptions, AnalyseSVGStructureResult, ElementWithID, ElementsMap, ElementsTreeItem, ExtendedRootTagElement, ExtendedTagElement, ExtendedTagElementUses, LinkToElementWithID };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|