@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.
Files changed (309) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +20 -21
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +40 -53
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +7 -10
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +3 -11
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +137 -0
  158. package/lib/index.d.ts +65 -44
  159. package/lib/index.mjs +83 -94
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +18 -15
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -14
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +99 -94
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -1,5 +1,4 @@
1
- // src/svg/data/tags.ts
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
- var unsupportedTags = new Set(["metadata", "desc", "title"]);
23
- var styleTag = new Set(["style"]);
24
- var defsTag = new Set(["defs"]);
25
- var maskTags = new Set(["clipPath", "mask"]);
26
- var symbolTag = new Set(["symbol"]);
27
- var shapeTags = new Set([
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
- var useTag = new Set(["use"]);
37
- var groupTag = new Set(["g"]);
38
- var markerTag = new Set(["marker"]);
39
- var animateTags = new Set([
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
- var animateMotionChildTags = new Set(["mpath"]);
47
- var gradientTags = new Set(["linearGradient", "radialGradient"]);
48
- var gradientChildTags = new Set(["stop"]);
49
- var patternTag = new Set(["pattern"]);
50
- var filterTag = new Set(["filter"]);
51
- var feLightningTags = new Set([
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
- var filterChildTags = new Set([
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
- var feComponentTransferChildTag = new Set([
71
+ const feComponentTransferChildTag = /* @__PURE__ */ new Set([
73
72
  "feFuncR",
74
73
  "feFuncG",
75
74
  "feFuncB",
76
75
  "feFuncA"
77
76
  ]);
78
- var feLightningChildTags = new Set([
77
+ const feLightningChildTags = /* @__PURE__ */ new Set([
79
78
  "feSpotLight",
80
79
  "fePointLight",
81
80
  "feDistantLight"
82
81
  ]);
83
- var feMergeChildTags = new Set(["feMergeNode"]);
84
- var reusableElementsWithPalette = new Set([
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
- var allValidTags = new Set([
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
- export {
112
- allValidTags,
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;
@@ -1,14 +1,19 @@
1
- /// <reference types="cheerio" />
2
- export interface ViewBox {
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
- export declare class SVG {
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
- // src/svg/index.ts
2
- import cheerio from "cheerio";
3
- function minify(str) {
4
- return str.replace(/(["';{}}><])\s*\n\s*/g, "$1").replace(/\s*\n\s*/g, " ").trim();
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 minify(this.toString());
41
+ toMinifiedString(customisations) {
42
+ return trimSVG(this.toString(customisations));
26
43
  }
27
44
  getBody() {
28
- return minify(this.$svg("svg").html());
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
- export {
87
- SVG
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;
@@ -1,6 +1,9 @@
1
- import type { SVG } from '.';
2
- import type { CSSRuleToken, CSSToken } from '../css/parser/types';
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
- export declare type ParseSVGStyleCallbackItem = ParseSVGStyleCallbackItemInline | ParseSVGStyleCallbackItemGlobal;
26
+ declare type ParseSVGStyleCallbackItem = ParseSVGStyleCallbackItemInline | ParseSVGStyleCallbackItemGlobal;
24
27
  /**
25
28
  * Result: undefined to remove item, string to change/keep item
26
29
  */
27
- export declare type ParseSVGStyleCallbackResult = string | undefined;
30
+ declare type ParseSVGStyleCallbackResult = string | undefined;
28
31
  /**
29
32
  * Callback function
30
33
  */
31
- export declare type ParseSVGStyleCallback = (item: ParseSVGStyleCallbackItem) => ParseSVGStyleCallbackResult | Promise<ParseSVGStyleCallbackResult>;
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
- export declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): Promise<void>;
40
- export {};
42
+ declare function parseSVGStyle(svg: SVG, callback: ParseSVGStyleCallback): Promise<void>;
43
+
44
+ export { ParseSVGStyleCallback, ParseSVGStyleCallbackItem, ParseSVGStyleCallbackResult, parseSVGStyle };
@@ -1,9 +1,12 @@
1
- // src/svg/parse-style.ts
2
- import { parseInlineStyle } from "../css/parse.mjs";
3
- import { tokensToString } from "../css/parser/export.mjs";
4
- import { getTokens } from "../css/parser/tokens.mjs";
5
- import { tokensTree } from "../css/parser/tree.mjs";
6
- import { parseSVG } from "./parse.mjs";
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
- export {
127
- parseSVGStyle
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;
@@ -1,14 +1,16 @@
1
- /// <reference types="cheerio" />
2
- import type { SVG } from './';
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
- export declare type CheerioElement = cheerio.TagElement;
7
- export declare type WrappedCheerioElement = cheerio.Cheerio;
8
+ declare type CheerioElement = cheerio.TagElement;
9
+ declare type WrappedCheerioElement = cheerio.Cheerio;
8
10
  /**
9
11
  * Item in callback
10
12
  */
11
- export interface ParseSVGCallbackItem {
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
- export declare type ParseSVGCallback = (item: ParseSVGCallbackItem) => void | Promise<void>;
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
- export declare function parseSVG(svg: SVG, callback: ParseSVGCallback): Promise<void>;
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
- export {
39
- parseSVG
40
- };
37
+
38
+ export { parseSVG };