@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
package/lib/svg/data/tags.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var badTags = new Set([
|
|
1
|
+
const badTags = /* @__PURE__ */ new Set([
|
|
3
2
|
"foreignObject",
|
|
4
3
|
"script",
|
|
5
4
|
"image",
|
|
@@ -19,12 +18,12 @@ var badTags = new Set([
|
|
|
19
18
|
"view",
|
|
20
19
|
"a"
|
|
21
20
|
]);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const unsupportedTags = /* @__PURE__ */ new Set(["metadata", "desc", "title"]);
|
|
22
|
+
const styleTag = /* @__PURE__ */ new Set(["style"]);
|
|
23
|
+
const defsTag = /* @__PURE__ */ new Set(["defs"]);
|
|
24
|
+
const maskTags = /* @__PURE__ */ new Set(["clipPath", "mask"]);
|
|
25
|
+
const symbolTag = /* @__PURE__ */ new Set(["symbol"]);
|
|
26
|
+
const shapeTags = /* @__PURE__ */ new Set([
|
|
28
27
|
"circle",
|
|
29
28
|
"ellipse",
|
|
30
29
|
"line",
|
|
@@ -33,26 +32,26 @@ var shapeTags = new Set([
|
|
|
33
32
|
"polyline",
|
|
34
33
|
"rect"
|
|
35
34
|
]);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const useTag = /* @__PURE__ */ new Set(["use"]);
|
|
36
|
+
const groupTag = /* @__PURE__ */ new Set(["g"]);
|
|
37
|
+
const markerTag = /* @__PURE__ */ new Set(["marker"]);
|
|
38
|
+
const animateTags = /* @__PURE__ */ new Set([
|
|
40
39
|
"animate",
|
|
41
40
|
"animateMotion",
|
|
42
41
|
"animateTransform",
|
|
43
42
|
"discard",
|
|
44
43
|
"set"
|
|
45
44
|
]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const animateMotionChildTags = /* @__PURE__ */ new Set(["mpath"]);
|
|
46
|
+
const gradientTags = /* @__PURE__ */ new Set(["linearGradient", "radialGradient"]);
|
|
47
|
+
const gradientChildTags = /* @__PURE__ */ new Set(["stop"]);
|
|
48
|
+
const patternTag = /* @__PURE__ */ new Set(["pattern"]);
|
|
49
|
+
const filterTag = /* @__PURE__ */ new Set(["filter"]);
|
|
50
|
+
const feLightningTags = /* @__PURE__ */ new Set([
|
|
52
51
|
"feDiffuseLighting",
|
|
53
52
|
"feSpecularLighting"
|
|
54
53
|
]);
|
|
55
|
-
|
|
54
|
+
const filterChildTags = /* @__PURE__ */ new Set([
|
|
56
55
|
"feBlend",
|
|
57
56
|
"feColorMatrix",
|
|
58
57
|
"feComponentTransfer",
|
|
@@ -69,26 +68,26 @@ var filterChildTags = new Set([
|
|
|
69
68
|
"feTurbulence",
|
|
70
69
|
...feLightningTags
|
|
71
70
|
]);
|
|
72
|
-
|
|
71
|
+
const feComponentTransferChildTag = /* @__PURE__ */ new Set([
|
|
73
72
|
"feFuncR",
|
|
74
73
|
"feFuncG",
|
|
75
74
|
"feFuncB",
|
|
76
75
|
"feFuncA"
|
|
77
76
|
]);
|
|
78
|
-
|
|
77
|
+
const feLightningChildTags = /* @__PURE__ */ new Set([
|
|
79
78
|
"feSpotLight",
|
|
80
79
|
"fePointLight",
|
|
81
80
|
"feDistantLight"
|
|
82
81
|
]);
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const feMergeChildTags = /* @__PURE__ */ new Set(["feMergeNode"]);
|
|
83
|
+
const reusableElementsWithPalette = /* @__PURE__ */ new Set([
|
|
85
84
|
...gradientTags,
|
|
86
85
|
...patternTag,
|
|
87
86
|
...markerTag,
|
|
88
87
|
...symbolTag,
|
|
89
88
|
...filterTag
|
|
90
89
|
]);
|
|
91
|
-
|
|
90
|
+
const allValidTags = /* @__PURE__ */ new Set([
|
|
92
91
|
...styleTag,
|
|
93
92
|
...defsTag,
|
|
94
93
|
...maskTags,
|
|
@@ -108,28 +107,5 @@ var allValidTags = new Set([
|
|
|
108
107
|
...feLightningChildTags,
|
|
109
108
|
...feMergeChildTags
|
|
110
109
|
]);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
animateMotionChildTags,
|
|
114
|
-
animateTags,
|
|
115
|
-
badTags,
|
|
116
|
-
defsTag,
|
|
117
|
-
feComponentTransferChildTag,
|
|
118
|
-
feLightningChildTags,
|
|
119
|
-
feLightningTags,
|
|
120
|
-
feMergeChildTags,
|
|
121
|
-
filterChildTags,
|
|
122
|
-
filterTag,
|
|
123
|
-
gradientChildTags,
|
|
124
|
-
gradientTags,
|
|
125
|
-
groupTag,
|
|
126
|
-
markerTag,
|
|
127
|
-
maskTags,
|
|
128
|
-
patternTag,
|
|
129
|
-
reusableElementsWithPalette,
|
|
130
|
-
shapeTags,
|
|
131
|
-
styleTag,
|
|
132
|
-
symbolTag,
|
|
133
|
-
unsupportedTags,
|
|
134
|
-
useTag
|
|
135
|
-
};
|
|
110
|
+
|
|
111
|
+
export { allValidTags, animateMotionChildTags, animateTags, badTags, defsTag, feComponentTransferChildTag, feLightningChildTags, feLightningTags, feMergeChildTags, filterChildTags, filterTag, gradientChildTags, gradientTags, groupTag, markerTag, maskTags, patternTag, reusableElementsWithPalette, shapeTags, styleTag, symbolTag, unsupportedTags, useTag };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const cheerio = require('cheerio');
|
|
6
|
+
const utils = require('@iconify/utils');
|
|
7
|
+
const icon = require('@iconify/utils/lib/icon');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
10
|
+
|
|
11
|
+
const cheerio__default = /*#__PURE__*/_interopDefaultLegacy(cheerio);
|
|
12
|
+
|
|
13
|
+
class SVG {
|
|
14
|
+
constructor(content) {
|
|
15
|
+
this.load(content);
|
|
16
|
+
}
|
|
17
|
+
toString(customisations) {
|
|
18
|
+
if (customisations) {
|
|
19
|
+
const data = utils.iconToSVG(icon.fullIcon(this.getIcon()), {
|
|
20
|
+
...utils.defaultCustomisations,
|
|
21
|
+
...customisations
|
|
22
|
+
});
|
|
23
|
+
let svgAttributes = ' xmlns="http://www.w3.org/2000/svg"';
|
|
24
|
+
if (data.body.indexOf("xlink:") !== -1) {
|
|
25
|
+
svgAttributes += ' xmlns:xlink="http://www.w3.org/1999/xlink"';
|
|
26
|
+
}
|
|
27
|
+
for (const key in data.attributes) {
|
|
28
|
+
const value = data.attributes[key];
|
|
29
|
+
svgAttributes += " " + key + '="' + value + '"';
|
|
30
|
+
}
|
|
31
|
+
if (data.inline) {
|
|
32
|
+
svgAttributes += ' style="vertical-align: -0.125em;"';
|
|
33
|
+
}
|
|
34
|
+
return "<svg" + svgAttributes + ">" + data.body + "</svg>";
|
|
35
|
+
}
|
|
36
|
+
const $root = this.$svg(":root");
|
|
37
|
+
const box = this.viewBox;
|
|
38
|
+
if ($root.attr("viewBox") === void 0) {
|
|
39
|
+
$root.attr("viewBox", box.left + " " + box.top + " " + box.width + " " + box.height);
|
|
40
|
+
}
|
|
41
|
+
if ($root.attr("width") === void 0) {
|
|
42
|
+
$root.attr("width", box.width + "");
|
|
43
|
+
}
|
|
44
|
+
if ($root.attr("height") === void 0) {
|
|
45
|
+
$root.attr("height", box.height + "");
|
|
46
|
+
}
|
|
47
|
+
return this.$svg.html();
|
|
48
|
+
}
|
|
49
|
+
toMinifiedString(customisations) {
|
|
50
|
+
return utils.trimSVG(this.toString(customisations));
|
|
51
|
+
}
|
|
52
|
+
getBody() {
|
|
53
|
+
const $root = this.$svg(":root");
|
|
54
|
+
const attribs = $root.get(0).attribs;
|
|
55
|
+
for (const key in attribs) {
|
|
56
|
+
switch (key.split("-").shift()) {
|
|
57
|
+
case "fill":
|
|
58
|
+
case "stroke":
|
|
59
|
+
case "opacity":
|
|
60
|
+
throw new Error(`Cannot use getBody() on icon that was not cleaned up with cleanupSVGRoot(). Icon has attribute ${key}="${attribs[key]}"`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return utils.trimSVG(this.$svg("svg").html());
|
|
64
|
+
}
|
|
65
|
+
getIcon() {
|
|
66
|
+
const props = this.viewBox;
|
|
67
|
+
const body = this.getBody();
|
|
68
|
+
return {
|
|
69
|
+
...props,
|
|
70
|
+
body
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
load(content) {
|
|
74
|
+
function remove(str1, str2, append) {
|
|
75
|
+
let start = 0;
|
|
76
|
+
while ((start = content.indexOf(str1, start)) !== -1) {
|
|
77
|
+
const end = content.indexOf(str2, start + str1.length);
|
|
78
|
+
if (end === -1) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
content = content.slice(0, start) + append + content.slice(end + str2.length);
|
|
82
|
+
start = start + append.length;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
remove("<!--", "-->", "");
|
|
86
|
+
remove("<?xml", "?>", "");
|
|
87
|
+
remove("<!DOCTYPE svg", "<svg", "<svg");
|
|
88
|
+
remove('xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"', "", "");
|
|
89
|
+
remove('xml:space="preserve"', "", "");
|
|
90
|
+
content = content.replace(/<g>\s*<\/g>/g, "");
|
|
91
|
+
this.$svg = cheerio__default.load(content.trim(), {
|
|
92
|
+
lowerCaseAttributeNames: false,
|
|
93
|
+
xmlMode: true
|
|
94
|
+
});
|
|
95
|
+
const $root = this.$svg(":root");
|
|
96
|
+
if ($root.length > 1 || $root.get(0).tagName !== "svg") {
|
|
97
|
+
throw new Error("Invalid SVG file: bad root tag");
|
|
98
|
+
}
|
|
99
|
+
const viewBox = $root.attr("viewBox");
|
|
100
|
+
if (viewBox !== void 0) {
|
|
101
|
+
const list = viewBox.split(" ");
|
|
102
|
+
this.viewBox = {
|
|
103
|
+
left: parseFloat(list[0]),
|
|
104
|
+
top: parseFloat(list[1]),
|
|
105
|
+
width: parseFloat(list[2]),
|
|
106
|
+
height: parseFloat(list[3])
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
const width = $root.attr("width");
|
|
110
|
+
const height = $root.attr("height");
|
|
111
|
+
if (!width || !height) {
|
|
112
|
+
throw new Error("Invalid SVG file: missing dimensions");
|
|
113
|
+
}
|
|
114
|
+
this.viewBox = {
|
|
115
|
+
left: 0,
|
|
116
|
+
top: 0,
|
|
117
|
+
width: parseFloat(width),
|
|
118
|
+
height: parseFloat(height)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
Object.keys(this.viewBox).forEach((key) => {
|
|
122
|
+
const attr = key;
|
|
123
|
+
if (isNaN(this.viewBox[attr])) {
|
|
124
|
+
throw new Error(`Invalid SVG file: invalid ${attr}`);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
exports.SVG = SVG;
|
package/lib/svg/index.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { IconifyIcon } from '@iconify/types';
|
|
2
|
+
export { IconifyIcon } from '@iconify/types';
|
|
3
|
+
import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations';
|
|
4
|
+
export { IconifyIconCustomisations } from '@iconify/utils/lib/customisations';
|
|
5
|
+
|
|
6
|
+
interface ViewBox {
|
|
3
7
|
left: number;
|
|
4
8
|
top: number;
|
|
5
9
|
width: number;
|
|
6
10
|
height: number;
|
|
7
11
|
}
|
|
12
|
+
|
|
8
13
|
/**
|
|
9
14
|
* SVG class, used to manipulate icon content.
|
|
10
15
|
*/
|
|
11
|
-
|
|
16
|
+
declare class SVG {
|
|
12
17
|
$svg: cheerio.Root;
|
|
13
18
|
viewBox: ViewBox;
|
|
14
19
|
/**
|
|
@@ -18,15 +23,19 @@ export declare class SVG {
|
|
|
18
23
|
/**
|
|
19
24
|
* Get SVG as string
|
|
20
25
|
*/
|
|
21
|
-
toString(): string;
|
|
26
|
+
toString(customisations?: IconifyIconCustomisations): string;
|
|
22
27
|
/**
|
|
23
28
|
* Get SVG as string without whitespaces
|
|
24
29
|
*/
|
|
25
|
-
toMinifiedString(): string;
|
|
30
|
+
toMinifiedString(customisations?: IconifyIconCustomisations): string;
|
|
26
31
|
/**
|
|
27
32
|
* Get body
|
|
28
33
|
*/
|
|
29
34
|
getBody(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Get icon as IconifyIcon
|
|
37
|
+
*/
|
|
38
|
+
getIcon(): IconifyIcon;
|
|
30
39
|
/**
|
|
31
40
|
* Load SVG
|
|
32
41
|
*
|
|
@@ -34,3 +43,5 @@ export declare class SVG {
|
|
|
34
43
|
*/
|
|
35
44
|
load(content: string): void;
|
|
36
45
|
}
|
|
46
|
+
|
|
47
|
+
export { SVG, ViewBox };
|
package/lib/svg/index.mjs
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var SVG = class {
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import { iconToSVG, defaultCustomisations, trimSVG } from '@iconify/utils';
|
|
3
|
+
import { fullIcon } from '@iconify/utils/lib/icon';
|
|
4
|
+
|
|
5
|
+
class SVG {
|
|
7
6
|
constructor(content) {
|
|
8
7
|
this.load(content);
|
|
9
8
|
}
|
|
10
|
-
toString() {
|
|
9
|
+
toString(customisations) {
|
|
10
|
+
if (customisations) {
|
|
11
|
+
const data = iconToSVG(fullIcon(this.getIcon()), {
|
|
12
|
+
...defaultCustomisations,
|
|
13
|
+
...customisations
|
|
14
|
+
});
|
|
15
|
+
let svgAttributes = ' xmlns="http://www.w3.org/2000/svg"';
|
|
16
|
+
if (data.body.indexOf("xlink:") !== -1) {
|
|
17
|
+
svgAttributes += ' xmlns:xlink="http://www.w3.org/1999/xlink"';
|
|
18
|
+
}
|
|
19
|
+
for (const key in data.attributes) {
|
|
20
|
+
const value = data.attributes[key];
|
|
21
|
+
svgAttributes += " " + key + '="' + value + '"';
|
|
22
|
+
}
|
|
23
|
+
if (data.inline) {
|
|
24
|
+
svgAttributes += ' style="vertical-align: -0.125em;"';
|
|
25
|
+
}
|
|
26
|
+
return "<svg" + svgAttributes + ">" + data.body + "</svg>";
|
|
27
|
+
}
|
|
11
28
|
const $root = this.$svg(":root");
|
|
12
29
|
const box = this.viewBox;
|
|
13
30
|
if ($root.attr("viewBox") === void 0) {
|
|
@@ -21,11 +38,29 @@ var SVG = class {
|
|
|
21
38
|
}
|
|
22
39
|
return this.$svg.html();
|
|
23
40
|
}
|
|
24
|
-
toMinifiedString() {
|
|
25
|
-
return
|
|
41
|
+
toMinifiedString(customisations) {
|
|
42
|
+
return trimSVG(this.toString(customisations));
|
|
26
43
|
}
|
|
27
44
|
getBody() {
|
|
28
|
-
|
|
45
|
+
const $root = this.$svg(":root");
|
|
46
|
+
const attribs = $root.get(0).attribs;
|
|
47
|
+
for (const key in attribs) {
|
|
48
|
+
switch (key.split("-").shift()) {
|
|
49
|
+
case "fill":
|
|
50
|
+
case "stroke":
|
|
51
|
+
case "opacity":
|
|
52
|
+
throw new Error(`Cannot use getBody() on icon that was not cleaned up with cleanupSVGRoot(). Icon has attribute ${key}="${attribs[key]}"`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return trimSVG(this.$svg("svg").html());
|
|
56
|
+
}
|
|
57
|
+
getIcon() {
|
|
58
|
+
const props = this.viewBox;
|
|
59
|
+
const body = this.getBody();
|
|
60
|
+
return {
|
|
61
|
+
...props,
|
|
62
|
+
body
|
|
63
|
+
};
|
|
29
64
|
}
|
|
30
65
|
load(content) {
|
|
31
66
|
function remove(str1, str2, append) {
|
|
@@ -82,7 +117,6 @@ var SVG = class {
|
|
|
82
117
|
}
|
|
83
118
|
});
|
|
84
119
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { SVG };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const css_parse = require('../css/parse.cjs');
|
|
6
|
+
const css_parser_export = require('../css/parser/export.cjs');
|
|
7
|
+
const css_parser_tokens = require('../css/parser/tokens.cjs');
|
|
8
|
+
const css_parser_tree = require('../css/parser/tree.cjs');
|
|
9
|
+
const svg_parse = require('./parse.cjs');
|
|
10
|
+
require('../css/parser/error.cjs');
|
|
11
|
+
require('../css/parser/strings.cjs');
|
|
12
|
+
require('../css/parser/text.cjs');
|
|
13
|
+
|
|
14
|
+
async function parseSVGStyle(svg, callback) {
|
|
15
|
+
return svg_parse.parseSVG(svg, async (item) => {
|
|
16
|
+
const tagName = item.tagName;
|
|
17
|
+
const $element = item.$element;
|
|
18
|
+
if (tagName === "style") {
|
|
19
|
+
const content = $element.html();
|
|
20
|
+
if (typeof content !== "string") {
|
|
21
|
+
$element.remove();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const tokens = css_parser_tokens.getTokens(content);
|
|
25
|
+
if (!(tokens instanceof Array)) {
|
|
26
|
+
throw new Error("Error parsing style");
|
|
27
|
+
}
|
|
28
|
+
let changed2 = false;
|
|
29
|
+
const selectorStart = [];
|
|
30
|
+
const newTokens = [];
|
|
31
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
32
|
+
const token = tokens[i];
|
|
33
|
+
switch (token.type) {
|
|
34
|
+
case "selector":
|
|
35
|
+
case "at-rule":
|
|
36
|
+
selectorStart.push(newTokens.length);
|
|
37
|
+
break;
|
|
38
|
+
case "close":
|
|
39
|
+
selectorStart.pop();
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if (token.type !== "rule") {
|
|
43
|
+
newTokens.push(token);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const value = token.value;
|
|
47
|
+
const selectorTokens = selectorStart.map((index) => newTokens[index]).filter((item2) => item2 !== null);
|
|
48
|
+
let result = callback({
|
|
49
|
+
type: "global",
|
|
50
|
+
prop: token.prop,
|
|
51
|
+
value,
|
|
52
|
+
token,
|
|
53
|
+
selectorTokens,
|
|
54
|
+
selectors: selectorTokens.reduce((prev, current) => {
|
|
55
|
+
switch (current.type) {
|
|
56
|
+
case "selector": {
|
|
57
|
+
return prev.concat(current.selectors);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return prev;
|
|
61
|
+
}, []),
|
|
62
|
+
prevTokens: newTokens,
|
|
63
|
+
nextTokens: tokens.slice(i + 1)
|
|
64
|
+
});
|
|
65
|
+
if (result instanceof Promise) {
|
|
66
|
+
result = await result;
|
|
67
|
+
}
|
|
68
|
+
if (result !== void 0) {
|
|
69
|
+
if (result !== value) {
|
|
70
|
+
changed2 = true;
|
|
71
|
+
token.value = result;
|
|
72
|
+
}
|
|
73
|
+
newTokens.push(token);
|
|
74
|
+
} else {
|
|
75
|
+
changed2 = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!changed2) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const tree = css_parser_tree.tokensTree(newTokens.filter((token) => token !== null));
|
|
82
|
+
if (!tree.length) {
|
|
83
|
+
$element.remove();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const newContent = css_parser_export.tokensToString(tree);
|
|
87
|
+
item.$element.text(newContent);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const attribs = item.element.attribs;
|
|
91
|
+
if (attribs.style === void 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const parsedStyle = css_parse.parseInlineStyle(attribs.style);
|
|
95
|
+
if (parsedStyle === null) {
|
|
96
|
+
$element.removeAttr("style");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const props = Object.keys(parsedStyle);
|
|
100
|
+
let changed = false;
|
|
101
|
+
for (let i = 0; i < props.length; i++) {
|
|
102
|
+
const prop = props[i];
|
|
103
|
+
const value = parsedStyle[prop];
|
|
104
|
+
let result = callback({
|
|
105
|
+
type: "inline",
|
|
106
|
+
prop,
|
|
107
|
+
value,
|
|
108
|
+
item
|
|
109
|
+
});
|
|
110
|
+
if (result instanceof Promise) {
|
|
111
|
+
result = await result;
|
|
112
|
+
}
|
|
113
|
+
if (result !== value) {
|
|
114
|
+
changed = true;
|
|
115
|
+
if (result === void 0) {
|
|
116
|
+
delete parsedStyle[prop];
|
|
117
|
+
} else {
|
|
118
|
+
parsedStyle[prop] = result;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!changed) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const newStyle = Object.keys(parsedStyle).map((key) => key + ":" + parsedStyle[key] + ";").join("");
|
|
126
|
+
if (!newStyle.length) {
|
|
127
|
+
$element.removeAttr("style");
|
|
128
|
+
} else {
|
|
129
|
+
$element.attr("style", newStyle);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
exports.parseSVGStyle = parseSVGStyle;
|
package/lib/svg/parse-style.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { ParseSVGCallbackItem } from './parse';
|
|
1
|
+
import { SVG } from './index.js';
|
|
2
|
+
import { CSSRuleToken, CSSToken } from '../css/parser/types.js';
|
|
3
|
+
import { ParseSVGCallbackItem } from './parse.js';
|
|
4
|
+
import '@iconify/types';
|
|
5
|
+
import '@iconify/utils/lib/customisations';
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* Item in callback
|
|
6
9
|
*/
|
|
@@ -20,15 +23,15 @@ interface ParseSVGStyleCallbackItemGlobal extends ParseSVGStyleCallbackItemCommo
|
|
|
20
23
|
prevTokens: (CSSToken | null)[];
|
|
21
24
|
nextTokens: CSSToken[];
|
|
22
25
|
}
|
|
23
|
-
|
|
26
|
+
declare type ParseSVGStyleCallbackItem = ParseSVGStyleCallbackItemInline | ParseSVGStyleCallbackItemGlobal;
|
|
24
27
|
/**
|
|
25
28
|
* Result: undefined to remove item, string to change/keep item
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
declare type ParseSVGStyleCallbackResult = string | undefined;
|
|
28
31
|
/**
|
|
29
32
|
* Callback function
|
|
30
33
|
*/
|
|
31
|
-
|
|
34
|
+
declare type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult | Promise<ParseSVGStyleCallbackResult>;
|
|
32
35
|
/**
|
|
33
36
|
* Parse styles in SVG
|
|
34
37
|
*
|
|
@@ -36,5 +39,6 @@ export declare type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) =>
|
|
|
36
39
|
* Callback should return new value (string) or undefined to remove rule.
|
|
37
40
|
* Callback can be asynchronous.
|
|
38
41
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): Promise<void>;
|
|
43
|
+
|
|
44
|
+
export { ParseSVGStyleCallback, ParseSVGStyleCallbackItem, ParseSVGStyleCallbackResult, parseSVGStyle };
|
package/lib/svg/parse-style.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
1
|
+
import { parseInlineStyle } from '../css/parse.mjs';
|
|
2
|
+
import { tokensToString } from '../css/parser/export.mjs';
|
|
3
|
+
import { getTokens } from '../css/parser/tokens.mjs';
|
|
4
|
+
import { tokensTree } from '../css/parser/tree.mjs';
|
|
5
|
+
import { parseSVG } from './parse.mjs';
|
|
6
|
+
import '../css/parser/error.mjs';
|
|
7
|
+
import '../css/parser/strings.mjs';
|
|
8
|
+
import '../css/parser/text.mjs';
|
|
9
|
+
|
|
7
10
|
async function parseSVGStyle(svg, callback) {
|
|
8
11
|
return parseSVG(svg, async (item) => {
|
|
9
12
|
const tagName = item.tagName;
|
|
@@ -123,6 +126,5 @@ async function parseSVGStyle(svg, callback) {
|
|
|
123
126
|
}
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
+
|
|
130
|
+
export { parseSVGStyle };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
async function parseSVG(svg, callback) {
|
|
6
|
+
async function checkNode(element, parents) {
|
|
7
|
+
if (element.type !== "tag") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const $element = cheerio(element);
|
|
11
|
+
const tagName = element.tagName;
|
|
12
|
+
const item = {
|
|
13
|
+
tagName,
|
|
14
|
+
element,
|
|
15
|
+
$element,
|
|
16
|
+
svg,
|
|
17
|
+
parents,
|
|
18
|
+
testChildren: true,
|
|
19
|
+
removeNode: false
|
|
20
|
+
};
|
|
21
|
+
const result = callback(item);
|
|
22
|
+
if (result instanceof Promise) {
|
|
23
|
+
await result;
|
|
24
|
+
}
|
|
25
|
+
const newParents = parents.slice(0);
|
|
26
|
+
newParents.unshift(item);
|
|
27
|
+
if (tagName !== "style" && item.testChildren && !item.removeNode) {
|
|
28
|
+
const children = $element.children().toArray();
|
|
29
|
+
for (let i = 0; i < children.length; i++) {
|
|
30
|
+
await checkNode(children[i], newParents);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (item.removeNode) {
|
|
34
|
+
$element.remove();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const cheerio = svg.$svg;
|
|
38
|
+
const $root = svg.$svg(":root");
|
|
39
|
+
await checkNode($root.get(0), []);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.parseSVG = parseSVG;
|
package/lib/svg/parse.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { SVG } from './index.js';
|
|
2
|
+
import '@iconify/types';
|
|
3
|
+
import '@iconify/utils/lib/customisations';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Shortcuts for Cheerio elements
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
declare type CheerioElement = cheerio.TagElement;
|
|
9
|
+
declare type WrappedCheerioElement = cheerio.Cheerio;
|
|
8
10
|
/**
|
|
9
11
|
* Item in callback
|
|
10
12
|
*/
|
|
11
|
-
|
|
13
|
+
interface ParseSVGCallbackItem {
|
|
12
14
|
tagName: string;
|
|
13
15
|
element: CheerioElement;
|
|
14
16
|
$element: WrappedCheerioElement;
|
|
@@ -20,11 +22,13 @@ export interface ParseSVGCallbackItem {
|
|
|
20
22
|
/**
|
|
21
23
|
* Callback function
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
declare type ParseSVGCallback = (item: ParseSVGCallbackItem) => void | Promise<void>;
|
|
24
26
|
/**
|
|
25
27
|
* Parse SVG
|
|
26
28
|
*
|
|
27
29
|
* This function finds all elements in SVG and calls callback for each element.
|
|
28
30
|
* Callback can be asynchronous.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
declare function parseSVG(svg: SVG, callback: ParseSVGCallback): Promise<void>;
|
|
33
|
+
|
|
34
|
+
export { CheerioElement, ParseSVGCallback, ParseSVGCallbackItem, WrappedCheerioElement, parseSVG };
|
package/lib/svg/parse.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/svg/parse.ts
|
|
2
1
|
async function parseSVG(svg, callback) {
|
|
3
2
|
async function checkNode(element, parents) {
|
|
4
3
|
if (element.type !== "tag") {
|
|
@@ -35,6 +34,5 @@ async function parseSVG(svg, callback) {
|
|
|
35
34
|
const $root = svg.$svg(":root");
|
|
36
35
|
await checkNode($root.get(0), []);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
37
|
+
|
|
38
|
+
export { parseSVG };
|