@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.
Files changed (308) 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 +42 -20
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +6 -0
  57. package/lib/download/git/reset.mjs +37 -0
  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 +24 -22
  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 +47 -57
  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 +9 -12
  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 +6 -16
  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 -43
  159. package/lib/index.mjs +83 -92
  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 +68 -47
  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 -11
  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 +102 -93
  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 -63
  251. package/lib/download/github/hash.js +0 -28
  252. package/lib/download/github/index.js +0 -116
  253. package/lib/download/github/types.js +0 -2
  254. package/lib/download/gitlab/hash.js +0 -27
  255. package/lib/download/gitlab/index.js +0 -115
  256. package/lib/download/gitlab/types.js +0 -7
  257. package/lib/download/helpers/untar.js +0 -14
  258. package/lib/download/helpers/unzip.js +0 -18
  259. package/lib/download/index.js +0 -27
  260. package/lib/download/npm/index.js +0 -91
  261. package/lib/download/npm/types.js +0 -2
  262. package/lib/download/npm/version.js +0 -27
  263. package/lib/download/types/modified.js +0 -2
  264. package/lib/download/types/sources.js +0 -2
  265. package/lib/export/directory.js +0 -52
  266. package/lib/export/helpers/custom-files.js +0 -32
  267. package/lib/export/helpers/prepare.js +0 -49
  268. package/lib/export/helpers/types-version.js +0 -12
  269. package/lib/export/icon-package.js +0 -77
  270. package/lib/export/json-package.js +0 -151
  271. package/lib/icon-set/index.js +0 -746
  272. package/lib/icon-set/match.js +0 -66
  273. package/lib/icon-set/merge.js +0 -90
  274. package/lib/icon-set/props.js +0 -33
  275. package/lib/icon-set/types.js +0 -2
  276. package/lib/import/directory.js +0 -59
  277. package/lib/import/figma/index.js +0 -90
  278. package/lib/import/figma/nodes.js +0 -108
  279. package/lib/import/figma/query.js +0 -244
  280. package/lib/import/figma/types/api.js +0 -12
  281. package/lib/import/figma/types/nodes.js +0 -2
  282. package/lib/import/figma/types/options.js +0 -2
  283. package/lib/import/figma/types/result.js +0 -2
  284. package/lib/index.js +0 -101
  285. package/lib/misc/bump-version.js +0 -19
  286. package/lib/misc/compare-dirs.js +0 -84
  287. package/lib/misc/exec.js +0 -26
  288. package/lib/misc/keyword.js +0 -31
  289. package/lib/misc/scan.js +0 -55
  290. package/lib/misc/write-json.js +0 -11
  291. package/lib/optimise/flags.js +0 -312
  292. package/lib/optimise/global-style.js +0 -158
  293. package/lib/optimise/scale.js +0 -42
  294. package/lib/optimise/svgo.js +0 -99
  295. package/lib/svg/analyse/error.js +0 -22
  296. package/lib/svg/analyse/types.js +0 -2
  297. package/lib/svg/analyse.js +0 -352
  298. package/lib/svg/cleanup/attribs.js +0 -51
  299. package/lib/svg/cleanup/bad-tags.js +0 -65
  300. package/lib/svg/cleanup/inline-style.js +0 -77
  301. package/lib/svg/cleanup/root-svg.js +0 -107
  302. package/lib/svg/cleanup/svgo-style.js +0 -35
  303. package/lib/svg/cleanup.js +0 -24
  304. package/lib/svg/data/attributes.js +0 -403
  305. package/lib/svg/data/tags.js +0 -188
  306. package/lib/svg/index.js +0 -125
  307. package/lib/svg/parse-style.js +0 -151
  308. package/lib/svg/parse.js +0 -49
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const commonColorAttributes = ["color"];
6
+ const shapeColorAttributes = ["fill", "stroke"];
7
+ const specialColorAttributes = [
8
+ "stop-color",
9
+ "flood-color"
10
+ ];
11
+ const defaultBlackColor = {
12
+ type: "rgb",
13
+ r: 0,
14
+ g: 0,
15
+ b: 0,
16
+ alpha: 1
17
+ };
18
+ const defaultColorValues = {
19
+ "color": { type: "current" },
20
+ "fill": defaultBlackColor,
21
+ "stroke": { type: "none" },
22
+ "stop-color": defaultBlackColor,
23
+ "flood-color": defaultBlackColor
24
+ };
25
+
26
+ exports.commonColorAttributes = commonColorAttributes;
27
+ exports.defaultBlackColor = defaultBlackColor;
28
+ exports.defaultColorValues = defaultColorValues;
29
+ exports.shapeColorAttributes = shapeColorAttributes;
30
+ exports.specialColorAttributes = specialColorAttributes;
@@ -1,16 +1,19 @@
1
- import type { Color } from '@iconify/utils/lib/colors/types';
1
+ import { Color } from '@iconify/utils/lib/colors/types';
2
+
2
3
  /**
3
4
  * Color attributes
4
5
  */
5
- export declare type CommonColorAttributes = 'color';
6
- export declare const commonColorAttributes: CommonColorAttributes[];
7
- export declare type ShapeColorAttributes = 'fill' | 'stroke';
8
- export declare const shapeColorAttributes: ShapeColorAttributes[];
9
- export declare type SpecialColorAttributes = 'stop-color' | 'flood-color';
10
- export declare const specialColorAttributes: SpecialColorAttributes[];
11
- export declare type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
6
+ declare type CommonColorAttributes = 'color';
7
+ declare const commonColorAttributes: CommonColorAttributes[];
8
+ declare type ShapeColorAttributes = 'fill' | 'stroke';
9
+ declare const shapeColorAttributes: ShapeColorAttributes[];
10
+ declare type SpecialColorAttributes = 'stop-color' | 'flood-color';
11
+ declare const specialColorAttributes: SpecialColorAttributes[];
12
+ declare type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | SpecialColorAttributes;
12
13
  /**
13
14
  * Default values
14
15
  */
15
- export declare const defaultBlackColor: Color;
16
- export declare const defaultColorValues: Record<ColorAttributes, Color>;
16
+ declare const defaultBlackColor: Color;
17
+ declare const defaultColorValues: Record<ColorAttributes, Color>;
18
+
19
+ export { ColorAttributes, CommonColorAttributes, ShapeColorAttributes, SpecialColorAttributes, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
@@ -1,28 +1,22 @@
1
- // src/colors/attribs.ts
2
- var commonColorAttributes = ["color"];
3
- var shapeColorAttributes = ["fill", "stroke"];
4
- var specialColorAttributes = [
1
+ const commonColorAttributes = ["color"];
2
+ const shapeColorAttributes = ["fill", "stroke"];
3
+ const specialColorAttributes = [
5
4
  "stop-color",
6
5
  "flood-color"
7
6
  ];
8
- var defaultBlackColor = {
7
+ const defaultBlackColor = {
9
8
  type: "rgb",
10
9
  r: 0,
11
10
  g: 0,
12
11
  b: 0,
13
12
  alpha: 1
14
13
  };
15
- var defaultColorValues = {
14
+ const defaultColorValues = {
16
15
  "color": { type: "current" },
17
16
  "fill": defaultBlackColor,
18
17
  "stroke": { type: "none" },
19
18
  "stop-color": defaultBlackColor,
20
19
  "flood-color": defaultBlackColor
21
20
  };
22
- export {
23
- commonColorAttributes,
24
- defaultBlackColor,
25
- defaultColorValues,
26
- shapeColorAttributes,
27
- specialColorAttributes
28
- };
21
+
22
+ export { commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
@@ -0,0 +1,269 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const colors = require('@iconify/utils/lib/colors');
6
+ const svg_data_tags = require('../svg/data/tags.cjs');
7
+ const svg_parseStyle = require('../svg/parse-style.cjs');
8
+ const colors_attribs = require('./attribs.cjs');
9
+ const svg_data_attributes = require('../svg/data/attributes.cjs');
10
+ const svg_analyse = require('../svg/analyse.cjs');
11
+ require('../css/parse.cjs');
12
+ require('../css/parser/tokens.cjs');
13
+ require('../css/parser/error.cjs');
14
+ require('../css/parser/strings.cjs');
15
+ require('../css/parser/text.cjs');
16
+ require('../css/parser/export.cjs');
17
+ require('../css/parser/tree.cjs');
18
+ require('../svg/parse.cjs');
19
+ require('../svg/analyse/error.cjs');
20
+
21
+ const propsToCheck = Object.keys(colors_attribs.defaultColorValues);
22
+ const animatePropsToCheck = ["from", "to", "values"];
23
+ async function parseColors(svg, options = {}) {
24
+ const result = {
25
+ colors: [],
26
+ hasUnsetColor: false,
27
+ hasGlobalStyle: false
28
+ };
29
+ const defaultColor = typeof options.defaultColor === "string" ? colors.stringToColor(options.defaultColor) : options.defaultColor;
30
+ function findColor(color, add = false) {
31
+ const isString = typeof color === "string";
32
+ for (let i = 0; i < result.colors.length; i++) {
33
+ const item = result.colors[i];
34
+ if (item === color) {
35
+ return item;
36
+ }
37
+ if (!isString && typeof item !== "string" && colors.compareColors(item, color)) {
38
+ return item;
39
+ }
40
+ }
41
+ if (add) {
42
+ result.colors.push(color);
43
+ return color;
44
+ }
45
+ return null;
46
+ }
47
+ function addColorToItem(prop, color, item, add = true) {
48
+ const addedColor = findColor(color, add !== false);
49
+ if (item) {
50
+ const itemColors = item._colors || (item._colors = {});
51
+ itemColors[prop] = addedColor === null ? color : addedColor;
52
+ }
53
+ }
54
+ function getElementColor(prop, item, elements2) {
55
+ function find(prop2) {
56
+ let currentItem = item;
57
+ while (currentItem) {
58
+ const element = elements2.get(currentItem.index);
59
+ const color = element._colors?.[prop2];
60
+ if (color !== void 0) {
61
+ return color;
62
+ }
63
+ currentItem = currentItem.parent;
64
+ if (currentItem?.usedAsMask) {
65
+ return colors_attribs.defaultColorValues[prop2];
66
+ }
67
+ }
68
+ return colors_attribs.defaultColorValues[prop2];
69
+ }
70
+ let propColor = find(prop);
71
+ if (typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
72
+ propColor = find("color");
73
+ }
74
+ return propColor;
75
+ }
76
+ async function checkColor(prop, value, item) {
77
+ switch (value.trim().toLowerCase()) {
78
+ case "":
79
+ case "inherit":
80
+ return;
81
+ }
82
+ const parsedColor = colors.stringToColor(value);
83
+ const defaultValue = parsedColor || value;
84
+ if (parsedColor?.type === "function" && parsedColor.func === "url") {
85
+ addColorToItem(prop, defaultValue, item, false);
86
+ return value;
87
+ }
88
+ if (!options.callback) {
89
+ addColorToItem(prop, defaultValue, item);
90
+ return value;
91
+ }
92
+ let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
93
+ callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
94
+ switch (callbackResult) {
95
+ case "remove": {
96
+ return item ? callbackResult : void 0;
97
+ }
98
+ case "unset":
99
+ return;
100
+ }
101
+ if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
102
+ addColorToItem(prop, defaultValue, item);
103
+ return value;
104
+ }
105
+ if (typeof callbackResult === "string") {
106
+ const newColor = colors.stringToColor(callbackResult);
107
+ addColorToItem(prop, newColor || callbackResult, item);
108
+ return callbackResult;
109
+ }
110
+ const newValue = colors.colorToString(callbackResult);
111
+ addColorToItem(prop, callbackResult, item);
112
+ return newValue;
113
+ }
114
+ await svg_parseStyle.parseSVGStyle(svg, async (item) => {
115
+ const prop = item.prop;
116
+ const value = item.value;
117
+ if (propsToCheck.indexOf(prop) === -1) {
118
+ return value;
119
+ }
120
+ const attr = prop;
121
+ const newValue = await checkColor(attr, value);
122
+ if (newValue === void 0) {
123
+ return newValue;
124
+ }
125
+ if (item.type === "global") {
126
+ result.hasGlobalStyle = true;
127
+ }
128
+ return newValue;
129
+ });
130
+ const iconData = await svg_analyse.analyseSVGStructure(svg, options);
131
+ const { elements, tree } = iconData;
132
+ const cheerio = svg.$svg;
133
+ const removedElements = /* @__PURE__ */ new Set();
134
+ const parsedElements = /* @__PURE__ */ new Set();
135
+ function removeElement(index, element) {
136
+ function removeChildren(element2) {
137
+ element2.children.forEach((item) => {
138
+ if (item.type !== "tag") {
139
+ return;
140
+ }
141
+ const element3 = item;
142
+ const index2 = element3._index;
143
+ if (index2 && !removedElements.has(index2)) {
144
+ element3._removed = true;
145
+ removedElements.add(index2);
146
+ removeChildren(element3);
147
+ }
148
+ });
149
+ }
150
+ element._removed = true;
151
+ removedElements.add(index);
152
+ removeChildren(element);
153
+ cheerio(element).remove();
154
+ }
155
+ async function parseTreeItem(item) {
156
+ const index = item.index;
157
+ if (removedElements.has(index) || parsedElements.has(index)) {
158
+ return;
159
+ }
160
+ parsedElements.add(index);
161
+ const element = elements.get(index);
162
+ if (element._removed) {
163
+ return;
164
+ }
165
+ const { tagName, attribs } = element;
166
+ if (item.parent) {
167
+ const parentIndex = item.parent.index;
168
+ const parentElement = elements.get(parentIndex);
169
+ if (parentElement._colors) {
170
+ element._colors = {
171
+ ...parentElement._colors
172
+ };
173
+ }
174
+ }
175
+ for (let i = 0; i < propsToCheck.length; i++) {
176
+ const prop = propsToCheck[i];
177
+ if (prop === "fill" && svg_data_tags.animateTags.has(tagName)) {
178
+ continue;
179
+ }
180
+ const value = attribs[prop];
181
+ if (value !== void 0) {
182
+ const newValue = await checkColor(prop, value, element);
183
+ if (newValue !== value) {
184
+ if (newValue === void 0) {
185
+ cheerio(element).removeAttr(prop);
186
+ if (element._colors) {
187
+ delete element._colors[prop];
188
+ }
189
+ } else if (newValue === "remove") {
190
+ removeElement(index, element);
191
+ return;
192
+ } else {
193
+ cheerio(element).attr(prop, newValue);
194
+ }
195
+ }
196
+ }
197
+ }
198
+ if (svg_data_tags.animateTags.has(tagName)) {
199
+ const attr = attribs.attributeName;
200
+ if (propsToCheck.indexOf(attr) !== -1) {
201
+ for (let i = 0; i < animatePropsToCheck.length; i++) {
202
+ const elementProp = animatePropsToCheck[i];
203
+ const fullValue = attribs[elementProp];
204
+ if (typeof fullValue !== "string") {
205
+ continue;
206
+ }
207
+ const splitValues = fullValue.split(";");
208
+ let updatedValues = false;
209
+ for (let j = 0; j < splitValues.length; j++) {
210
+ const value = splitValues[j];
211
+ if (value !== void 0) {
212
+ const newValue = await checkColor(elementProp, value);
213
+ if (newValue !== value) {
214
+ updatedValues = true;
215
+ splitValues[j] = typeof newValue === "string" ? newValue : "";
216
+ }
217
+ }
218
+ }
219
+ if (updatedValues) {
220
+ cheerio(element).attr(elementProp, splitValues.join(";"));
221
+ }
222
+ }
223
+ }
224
+ }
225
+ if (!result.hasGlobalStyle) {
226
+ let requiredProps;
227
+ if (svg_data_tags.shapeTags.has(tagName)) {
228
+ requiredProps = colors_attribs.shapeColorAttributes;
229
+ }
230
+ colors_attribs.specialColorAttributes.forEach((attr) => {
231
+ if (svg_data_attributes.tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
232
+ requiredProps = [attr];
233
+ }
234
+ });
235
+ if (requiredProps) {
236
+ const itemColors = element._colors || (element._colors = {});
237
+ for (let i = 0; i < requiredProps.length; i++) {
238
+ const prop = requiredProps[i];
239
+ const color = getElementColor(prop, item, elements);
240
+ if (color === colors_attribs.defaultBlackColor) {
241
+ if (defaultColor) {
242
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, element, item, iconData) : defaultColor;
243
+ findColor(defaultColorValue, true);
244
+ cheerio(element).attr(prop, colors.colorToString(defaultColorValue));
245
+ itemColors[prop] = defaultColorValue;
246
+ } else {
247
+ result.hasUnsetColor = true;
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ for (let i = 0; i < item.children.length; i++) {
254
+ const childItem = item.children[i];
255
+ if (!childItem.usedAsMask) {
256
+ await parseTreeItem(childItem);
257
+ }
258
+ }
259
+ }
260
+ await parseTreeItem(tree);
261
+ return result;
262
+ }
263
+ function isEmptyColor(color) {
264
+ const type = color.type;
265
+ return type === "none" || type === "transparent";
266
+ }
267
+
268
+ exports.isEmptyColor = isEmptyColor;
269
+ exports.parseColors = parseColors;
@@ -1,11 +1,14 @@
1
- import type { Color } from '@iconify/utils/lib/colors/types';
2
- import type { SVG } from '../svg';
3
- import { ColorAttributes } from './attribs';
4
- import type { AnalyseSVGStructureResult, ElementsTreeItem, ExtendedTagElement, AnalyseSVGStructureOptions } from '../svg/analyse/types';
1
+ import { Color } from '@iconify/utils/lib/colors/types';
2
+ import { SVG } from '../svg/index.js';
3
+ import { ColorAttributes } from './attribs.js';
4
+ import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.js';
5
+ import '@iconify/types';
6
+ import '@iconify/utils/lib/customisations';
7
+
5
8
  /**
6
9
  * Result
7
10
  */
8
- export interface FindColorsResult {
11
+ interface FindColorsResult {
9
12
  colors: (Color | string)[];
10
13
  hasUnsetColor: boolean;
11
14
  hasGlobalStyle: boolean;
@@ -24,11 +27,11 @@ declare type ParseColorsCallback = (attr: ColorAttributes, colorString: string,
24
27
  /**
25
28
  * Callback for default color
26
29
  */
27
- export declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
30
+ declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
28
31
  /**
29
32
  * Options
30
33
  */
31
- export interface ParseColorsOptions extends AnalyseSVGStructureOptions {
34
+ interface ParseColorsOptions extends AnalyseSVGStructureOptions {
32
35
  callback?: ParseColorsCallback;
33
36
  defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
34
37
  }
@@ -36,7 +39,7 @@ export interface ParseColorsOptions extends AnalyseSVGStructureOptions {
36
39
  * Extend properties for element
37
40
  */
38
41
  declare type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
39
- export interface ExtendedTagElementWithColors extends ExtendedTagElement {
42
+ interface ExtendedTagElementWithColors extends ExtendedTagElement {
40
43
  _colors?: ItemColors;
41
44
  _removed?: boolean;
42
45
  }
@@ -46,9 +49,10 @@ export interface ExtendedTagElementWithColors extends ExtendedTagElement {
46
49
  * Clean up icon before running this function to convert style to attributes using
47
50
  * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
48
51
  */
49
- export declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
52
+ declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
50
53
  /**
51
54
  * Check if color is empty, such as 'none' or 'transparent'
52
55
  */
53
- export declare function isEmptyColor(color: Color): boolean;
54
- export {};
56
+ declare function isEmptyColor(color: Color): boolean;
57
+
58
+ export { ExtendedTagElementWithColors, FindColorsResult, ParseColorOptionsDefaultColorCallback, ParseColorsOptions, isEmptyColor, parseColors };
@@ -1,21 +1,21 @@
1
- // src/colors/parse.ts
2
- import {
3
- compareColors,
4
- stringToColor,
5
- colorToString
6
- } from "@iconify/utils/lib/colors";
7
- import { animateTags, shapeTags } from "../svg/data/tags.mjs";
8
- import { parseSVGStyle } from "../svg/parse-style.mjs";
9
- import {
10
- defaultBlackColor,
11
- defaultColorValues,
12
- shapeColorAttributes,
13
- specialColorAttributes
14
- } from "./attribs.mjs";
15
- import { tagSpecificPresentationalAttributes } from "../svg/data/attributes.mjs";
16
- import { analyseSVGStructure } from "../svg/analyse.mjs";
17
- var propsToCheck = Object.keys(defaultColorValues);
18
- var animatePropsToCheck = ["from", "to", "values"];
1
+ import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
2
+ import { animateTags, shapeTags } from '../svg/data/tags.mjs';
3
+ import { parseSVGStyle } from '../svg/parse-style.mjs';
4
+ import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes } from './attribs.mjs';
5
+ import { tagSpecificPresentationalAttributes } from '../svg/data/attributes.mjs';
6
+ import { analyseSVGStructure } from '../svg/analyse.mjs';
7
+ import '../css/parse.mjs';
8
+ import '../css/parser/tokens.mjs';
9
+ import '../css/parser/error.mjs';
10
+ import '../css/parser/strings.mjs';
11
+ import '../css/parser/text.mjs';
12
+ import '../css/parser/export.mjs';
13
+ import '../css/parser/tree.mjs';
14
+ import '../svg/parse.mjs';
15
+ import '../svg/analyse/error.mjs';
16
+
17
+ const propsToCheck = Object.keys(defaultColorValues);
18
+ const animatePropsToCheck = ["from", "to", "values"];
19
19
  async function parseColors(svg, options = {}) {
20
20
  const result = {
21
21
  colors: [],
@@ -49,16 +49,15 @@ async function parseColors(svg, options = {}) {
49
49
  }
50
50
  function getElementColor(prop, item, elements2) {
51
51
  function find(prop2) {
52
- var _a;
53
52
  let currentItem = item;
54
53
  while (currentItem) {
55
54
  const element = elements2.get(currentItem.index);
56
- const color = (_a = element._colors) == null ? void 0 : _a[prop2];
55
+ const color = element._colors?.[prop2];
57
56
  if (color !== void 0) {
58
57
  return color;
59
58
  }
60
59
  currentItem = currentItem.parent;
61
- if (currentItem == null ? void 0 : currentItem.usedAsMask) {
60
+ if (currentItem?.usedAsMask) {
62
61
  return defaultColorValues[prop2];
63
62
  }
64
63
  }
@@ -78,7 +77,7 @@ async function parseColors(svg, options = {}) {
78
77
  }
79
78
  const parsedColor = stringToColor(value);
80
79
  const defaultValue = parsedColor || value;
81
- if ((parsedColor == null ? void 0 : parsedColor.type) === "function" && parsedColor.func === "url") {
80
+ if (parsedColor?.type === "function" && parsedColor.func === "url") {
82
81
  addColorToItem(prop, defaultValue, item, false);
83
82
  return value;
84
83
  }
@@ -86,7 +85,7 @@ async function parseColors(svg, options = {}) {
86
85
  addColorToItem(prop, defaultValue, item);
87
86
  return value;
88
87
  }
89
- let callbackResult = options.callback(prop, value, parsedColor, item == null ? void 0 : item.tagName, item);
88
+ let callbackResult = options.callback(prop, value, parsedColor, item?.tagName, item);
90
89
  callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
91
90
  switch (callbackResult) {
92
91
  case "remove": {
@@ -127,8 +126,8 @@ async function parseColors(svg, options = {}) {
127
126
  const iconData = await analyseSVGStructure(svg, options);
128
127
  const { elements, tree } = iconData;
129
128
  const cheerio = svg.$svg;
130
- const removedElements = new Set();
131
- const parsedElements = new Set();
129
+ const removedElements = /* @__PURE__ */ new Set();
130
+ const parsedElements = /* @__PURE__ */ new Set();
132
131
  function removeElement(index, element) {
133
132
  function removeChildren(element2) {
134
133
  element2.children.forEach((item) => {
@@ -225,8 +224,7 @@ async function parseColors(svg, options = {}) {
225
224
  requiredProps = shapeColorAttributes;
226
225
  }
227
226
  specialColorAttributes.forEach((attr) => {
228
- var _a;
229
- if ((_a = tagSpecificPresentationalAttributes[tagName]) == null ? void 0 : _a.has(attr)) {
227
+ if (tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
230
228
  requiredProps = [attr];
231
229
  }
232
230
  });
@@ -262,7 +260,5 @@ function isEmptyColor(color) {
262
260
  const type = color.type;
263
261
  return type === "none" || type === "transparent";
264
262
  }
265
- export {
266
- isEmptyColor,
267
- parseColors
268
- };
263
+
264
+ export { isEmptyColor, parseColors };
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const colors = require('@iconify/utils/lib/colors');
6
+ const colors_parse = require('./parse.cjs');
7
+ require('../svg/data/tags.cjs');
8
+ require('../svg/parse-style.cjs');
9
+ require('../css/parse.cjs');
10
+ require('../css/parser/tokens.cjs');
11
+ require('../css/parser/error.cjs');
12
+ require('../css/parser/strings.cjs');
13
+ require('../css/parser/text.cjs');
14
+ require('../css/parser/export.cjs');
15
+ require('../css/parser/tree.cjs');
16
+ require('../svg/parse.cjs');
17
+ require('./attribs.cjs');
18
+ require('../svg/data/attributes.cjs');
19
+ require('../svg/analyse.cjs');
20
+ require('../svg/analyse/error.cjs');
21
+
22
+ async function validateColors(svg, expectMonotone, options) {
23
+ const palette = await colors_parse.parseColors(svg, options);
24
+ palette.colors.forEach((color) => {
25
+ if (typeof color === "string") {
26
+ throw new Error("Unexpected color: " + color);
27
+ }
28
+ switch (color.type) {
29
+ case "none":
30
+ case "transparent":
31
+ return;
32
+ case "current":
33
+ if (!expectMonotone) {
34
+ throw new Error("Unexpected color: " + colors.colorToString(color));
35
+ }
36
+ return;
37
+ case "rgb":
38
+ case "hsl":
39
+ if (expectMonotone) {
40
+ throw new Error("Unexpected color: " + colors.colorToString(color));
41
+ }
42
+ return;
43
+ default:
44
+ if (color.type !== "function" || color.func !== "url") {
45
+ throw new Error("Unexpected color: " + colors.colorToString(color));
46
+ }
47
+ }
48
+ });
49
+ return palette;
50
+ }
51
+
52
+ exports.validateColors = validateColors;
@@ -1,6 +1,11 @@
1
- import type { SVG } from '../svg/index';
2
- import { ParseColorsOptions } from './parse';
3
- import type { FindColorsResult } from './parse';
1
+ import { SVG } from '../svg/index.js';
2
+ import { ParseColorsOptions, FindColorsResult } from './parse.js';
3
+ import '@iconify/types';
4
+ import '@iconify/utils/lib/customisations';
5
+ import '@iconify/utils/lib/colors/types';
6
+ import './attribs.js';
7
+ import '../svg/analyse/types.js';
8
+
4
9
  /**
5
10
  * Validate colors in icon
6
11
  *
@@ -8,4 +13,6 @@ import type { FindColorsResult } from './parse';
8
13
  *
9
14
  * Throws exception on error
10
15
  */
11
- export declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): Promise<FindColorsResult>;
16
+ declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): Promise<FindColorsResult>;
17
+
18
+ export { validateColors };
@@ -1,6 +1,20 @@
1
- // src/colors/validate.ts
2
- import { colorToString } from "@iconify/utils/lib/colors";
3
- import { parseColors } from "./parse.mjs";
1
+ import { colorToString } from '@iconify/utils/lib/colors';
2
+ import { parseColors } from './parse.mjs';
3
+ import '../svg/data/tags.mjs';
4
+ import '../svg/parse-style.mjs';
5
+ import '../css/parse.mjs';
6
+ import '../css/parser/tokens.mjs';
7
+ import '../css/parser/error.mjs';
8
+ import '../css/parser/strings.mjs';
9
+ import '../css/parser/text.mjs';
10
+ import '../css/parser/export.mjs';
11
+ import '../css/parser/tree.mjs';
12
+ import '../svg/parse.mjs';
13
+ import './attribs.mjs';
14
+ import '../svg/data/attributes.mjs';
15
+ import '../svg/analyse.mjs';
16
+ import '../svg/analyse/error.mjs';
17
+
4
18
  async function validateColors(svg, expectMonotone, options) {
5
19
  const palette = await parseColors(svg, options);
6
20
  palette.colors.forEach((color) => {
@@ -30,6 +44,5 @@ async function validateColors(svg, expectMonotone, options) {
30
44
  });
31
45
  return palette;
32
46
  }
33
- export {
34
- validateColors
35
- };
47
+
48
+ export { validateColors };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const css_parser_tokens = require('./parser/tokens.cjs');
6
+ require('./parser/error.cjs');
7
+ require('./parser/strings.cjs');
8
+ require('./parser/text.cjs');
9
+
10
+ function parseInlineStyle(style) {
11
+ const tokens = css_parser_tokens.getTokens(style);
12
+ if (!(tokens instanceof Array)) {
13
+ return null;
14
+ }
15
+ const results = /* @__PURE__ */ Object.create(null);
16
+ for (let i = 0; i < tokens.length; i++) {
17
+ const token = tokens[i];
18
+ if (token.type !== "rule") {
19
+ return null;
20
+ }
21
+ results[token.prop] = token.value;
22
+ }
23
+ return results;
24
+ }
25
+
26
+ exports.parseInlineStyle = parseInlineStyle;
@@ -1,4 +1,6 @@
1
1
  /**
2
2
  * Parse inline style
3
3
  */
4
- export declare function parseInlineStyle(style: string): Record<string, string> | null;
4
+ declare function parseInlineStyle(style: string): Record<string, string> | null;
5
+
6
+ export { parseInlineStyle };