@iconify/tools 4.0.0-dev.1 → 4.0.0

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 (295) hide show
  1. package/lib/colors/attribs.d.cts +27 -0
  2. package/lib/colors/attribs.d.mts +27 -0
  3. package/lib/colors/attribs.d.ts +1 -1
  4. package/lib/colors/detect.cjs +2 -2
  5. package/lib/colors/detect.d.cts +16 -0
  6. package/lib/colors/detect.d.mts +16 -0
  7. package/lib/colors/detect.mjs +3 -3
  8. package/lib/colors/parse.cjs +132 -276
  9. package/lib/colors/parse.d.cts +60 -0
  10. package/lib/colors/parse.d.mts +60 -0
  11. package/lib/colors/parse.d.ts +7 -15
  12. package/lib/colors/parse.mjs +136 -279
  13. package/lib/colors/validate.cjs +2 -11
  14. package/lib/colors/validate.d.cts +20 -0
  15. package/lib/colors/validate.d.mts +20 -0
  16. package/lib/colors/validate.d.ts +4 -11
  17. package/lib/colors/validate.mjs +4 -12
  18. package/lib/css/parse.d.cts +6 -0
  19. package/lib/css/parse.d.mts +6 -0
  20. package/lib/css/parser/error.d.cts +13 -0
  21. package/lib/css/parser/error.d.mts +13 -0
  22. package/lib/css/parser/error.d.ts +1 -1
  23. package/lib/css/parser/export.d.cts +8 -0
  24. package/lib/css/parser/export.d.mts +8 -0
  25. package/lib/css/parser/strings.d.cts +16 -0
  26. package/lib/css/parser/strings.d.mts +16 -0
  27. package/lib/css/parser/text.d.cts +20 -0
  28. package/lib/css/parser/text.d.mts +20 -0
  29. package/lib/css/parser/tokens.d.cts +9 -0
  30. package/lib/css/parser/tokens.d.mts +9 -0
  31. package/lib/css/parser/tree.d.cts +8 -0
  32. package/lib/css/parser/tree.d.mts +8 -0
  33. package/lib/css/parser/types.d.cts +52 -0
  34. package/lib/css/parser/types.d.mts +52 -0
  35. package/lib/css/parser/types.d.ts +1 -1
  36. package/lib/download/api/cache.d.cts +20 -0
  37. package/lib/download/api/cache.d.mts +20 -0
  38. package/lib/download/api/config.cjs +11 -0
  39. package/lib/download/api/config.d.cts +18 -0
  40. package/lib/download/api/config.d.mts +18 -0
  41. package/lib/download/api/config.d.ts +18 -0
  42. package/lib/download/api/config.mjs +8 -0
  43. package/lib/download/api/download.cjs +15 -7
  44. package/lib/download/api/download.d.cts +8 -0
  45. package/lib/download/api/download.d.mts +8 -0
  46. package/lib/download/api/download.mjs +11 -7
  47. package/lib/download/api/index.cjs +23 -7
  48. package/lib/download/api/index.d.cts +8 -0
  49. package/lib/download/api/index.d.mts +8 -0
  50. package/lib/download/api/index.mjs +19 -7
  51. package/lib/download/api/queue.cjs +104 -0
  52. package/lib/download/api/queue.d.cts +32 -0
  53. package/lib/download/api/queue.d.mts +32 -0
  54. package/lib/download/api/queue.d.ts +32 -0
  55. package/lib/download/api/queue.mjs +101 -0
  56. package/lib/download/api/types.d.cts +17 -0
  57. package/lib/download/api/types.d.mts +17 -0
  58. package/lib/download/api/types.d.ts +1 -1
  59. package/lib/download/git/branch.d.cts +8 -0
  60. package/lib/download/git/branch.d.mts +8 -0
  61. package/lib/download/git/hash.d.cts +8 -0
  62. package/lib/download/git/hash.d.mts +8 -0
  63. package/lib/download/git/index.cjs +2 -4
  64. package/lib/download/git/index.d.cts +29 -0
  65. package/lib/download/git/index.d.mts +29 -0
  66. package/lib/download/git/index.d.ts +1 -1
  67. package/lib/download/git/index.mjs +2 -4
  68. package/lib/download/git/reset.cjs +2 -4
  69. package/lib/download/git/reset.d.cts +6 -0
  70. package/lib/download/git/reset.d.mts +6 -0
  71. package/lib/download/git/reset.mjs +2 -4
  72. package/lib/download/github/hash.cjs +2 -0
  73. package/lib/download/github/hash.d.cts +8 -0
  74. package/lib/download/github/hash.d.mts +8 -0
  75. package/lib/download/github/hash.mjs +2 -0
  76. package/lib/download/github/index.cjs +2 -2
  77. package/lib/download/github/index.d.cts +31 -0
  78. package/lib/download/github/index.d.mts +31 -0
  79. package/lib/download/github/index.d.ts +1 -1
  80. package/lib/download/github/index.mjs +2 -2
  81. package/lib/download/github/types.d.cts +11 -0
  82. package/lib/download/github/types.d.mts +11 -0
  83. package/lib/download/github/types.d.ts +1 -1
  84. package/lib/download/gitlab/hash.cjs +2 -0
  85. package/lib/download/gitlab/hash.d.cts +8 -0
  86. package/lib/download/gitlab/hash.d.mts +8 -0
  87. package/lib/download/gitlab/hash.mjs +2 -0
  88. package/lib/download/gitlab/index.cjs +2 -2
  89. package/lib/download/gitlab/index.d.cts +31 -0
  90. package/lib/download/gitlab/index.d.mts +31 -0
  91. package/lib/download/gitlab/index.d.ts +1 -1
  92. package/lib/download/gitlab/index.mjs +2 -2
  93. package/lib/download/gitlab/types.d.cts +15 -0
  94. package/lib/download/gitlab/types.d.mts +15 -0
  95. package/lib/download/gitlab/types.d.ts +1 -1
  96. package/lib/download/helpers/untar.d.cts +6 -0
  97. package/lib/download/helpers/untar.d.mts +6 -0
  98. package/lib/download/helpers/unzip.d.cts +6 -0
  99. package/lib/download/helpers/unzip.d.mts +6 -0
  100. package/lib/download/index.cjs +2 -2
  101. package/lib/download/index.d.cts +48 -0
  102. package/lib/download/index.d.mts +48 -0
  103. package/lib/download/index.d.ts +1 -1
  104. package/lib/download/index.mjs +2 -2
  105. package/lib/download/npm/index.cjs +2 -2
  106. package/lib/download/npm/index.d.cts +30 -0
  107. package/lib/download/npm/index.d.mts +30 -0
  108. package/lib/download/npm/index.d.ts +1 -1
  109. package/lib/download/npm/index.mjs +2 -2
  110. package/lib/download/npm/types.d.cts +9 -0
  111. package/lib/download/npm/types.d.mts +9 -0
  112. package/lib/download/npm/types.d.ts +1 -1
  113. package/lib/download/npm/version.d.cts +16 -0
  114. package/lib/download/npm/version.d.mts +16 -0
  115. package/lib/download/npm/version.d.ts +1 -1
  116. package/lib/download/types/modified.d.cts +6 -0
  117. package/lib/download/types/modified.d.mts +6 -0
  118. package/lib/download/types/modified.d.ts +1 -1
  119. package/lib/download/types/sources.d.cts +12 -0
  120. package/lib/download/types/sources.d.mts +12 -0
  121. package/lib/download/types/sources.d.ts +1 -1
  122. package/lib/export/directory.d.cts +26 -0
  123. package/lib/export/directory.d.mts +26 -0
  124. package/lib/export/directory.d.ts +1 -1
  125. package/lib/export/helpers/custom-files.d.cts +12 -0
  126. package/lib/export/helpers/custom-files.d.mts +12 -0
  127. package/lib/export/helpers/custom-files.d.ts +1 -1
  128. package/lib/export/helpers/prepare.d.cts +19 -0
  129. package/lib/export/helpers/prepare.d.mts +19 -0
  130. package/lib/export/helpers/prepare.d.ts +1 -1
  131. package/lib/export/helpers/types-version.d.cts +6 -0
  132. package/lib/export/helpers/types-version.d.mts +6 -0
  133. package/lib/export/icon-package.d.cts +26 -0
  134. package/lib/export/icon-package.d.mts +26 -0
  135. package/lib/export/icon-package.d.ts +2 -2
  136. package/lib/export/json-package.cjs +1 -0
  137. package/lib/export/json-package.d.cts +25 -0
  138. package/lib/export/json-package.d.mts +25 -0
  139. package/lib/export/json-package.d.ts +2 -1
  140. package/lib/export/json-package.mjs +1 -0
  141. package/lib/icon-set/index.cjs +25 -4
  142. package/lib/icon-set/index.d.cts +162 -0
  143. package/lib/icon-set/index.d.mts +162 -0
  144. package/lib/icon-set/index.mjs +25 -4
  145. package/lib/icon-set/match.d.cts +15 -0
  146. package/lib/icon-set/match.d.mts +15 -0
  147. package/lib/icon-set/merge.d.cts +14 -0
  148. package/lib/icon-set/merge.d.mts +14 -0
  149. package/lib/icon-set/modified.d.cts +16 -0
  150. package/lib/icon-set/modified.d.mts +16 -0
  151. package/lib/icon-set/props.d.cts +13 -0
  152. package/lib/icon-set/props.d.mts +13 -0
  153. package/lib/icon-set/tags.d.cts +23 -0
  154. package/lib/icon-set/tags.d.mts +23 -0
  155. package/lib/icon-set/types.d.cts +75 -0
  156. package/lib/icon-set/types.d.mts +75 -0
  157. package/lib/icon-set/types.d.ts +1 -1
  158. package/lib/import/directory.d.cts +52 -0
  159. package/lib/import/directory.d.mts +52 -0
  160. package/lib/import/directory.d.ts +1 -1
  161. package/lib/import/figma/index.cjs +3 -0
  162. package/lib/import/figma/index.d.cts +20 -0
  163. package/lib/import/figma/index.d.mts +20 -0
  164. package/lib/import/figma/index.mjs +3 -0
  165. package/lib/import/figma/nodes.cjs +1 -1
  166. package/lib/import/figma/nodes.d.cts +18 -0
  167. package/lib/import/figma/nodes.d.mts +18 -0
  168. package/lib/import/figma/nodes.mjs +1 -1
  169. package/lib/import/figma/query.cjs +104 -76
  170. package/lib/import/figma/query.d.cts +42 -0
  171. package/lib/import/figma/query.d.mts +42 -0
  172. package/lib/import/figma/query.d.ts +15 -2
  173. package/lib/import/figma/query.mjs +106 -78
  174. package/lib/import/figma/types/api.d.cts +53 -0
  175. package/lib/import/figma/types/api.d.mts +53 -0
  176. package/lib/import/figma/types/api.d.ts +1 -1
  177. package/lib/import/figma/types/nodes.d.cts +44 -0
  178. package/lib/import/figma/types/nodes.d.mts +44 -0
  179. package/lib/import/figma/types/nodes.d.ts +1 -1
  180. package/lib/import/figma/types/options.d.cts +59 -0
  181. package/lib/import/figma/types/options.d.mts +59 -0
  182. package/lib/import/figma/types/options.d.ts +1 -1
  183. package/lib/import/figma/types/result.d.cts +44 -0
  184. package/lib/import/figma/types/result.d.mts +44 -0
  185. package/lib/import/figma/types/result.d.ts +1 -1
  186. package/lib/index.cjs +14 -13
  187. package/lib/index.d.cts +78 -0
  188. package/lib/index.d.mts +78 -0
  189. package/lib/index.d.ts +8 -5
  190. package/lib/index.mjs +13 -12
  191. package/lib/misc/bump-version.d.cts +6 -0
  192. package/lib/misc/bump-version.d.mts +6 -0
  193. package/lib/misc/cheerio.d.cts +9 -0
  194. package/lib/misc/cheerio.d.mts +9 -0
  195. package/lib/misc/cheerio.d.ts +1 -1
  196. package/lib/misc/compare-dirs.cjs +3 -3
  197. package/lib/misc/compare-dirs.d.cts +11 -0
  198. package/lib/misc/compare-dirs.d.mts +11 -0
  199. package/lib/misc/compare-dirs.d.ts +1 -1
  200. package/lib/misc/compare-dirs.mjs +3 -3
  201. package/lib/misc/exec.d.cts +12 -0
  202. package/lib/misc/exec.d.mts +12 -0
  203. package/lib/misc/exec.d.ts +1 -1
  204. package/lib/misc/keyword.d.cts +6 -0
  205. package/lib/misc/keyword.d.mts +6 -0
  206. package/lib/misc/scan.d.cts +33 -0
  207. package/lib/misc/scan.d.mts +33 -0
  208. package/lib/misc/scan.d.ts +1 -1
  209. package/lib/misc/write-json.d.cts +6 -0
  210. package/lib/misc/write-json.d.mts +6 -0
  211. package/lib/optimise/figma.cjs +5 -5
  212. package/lib/optimise/figma.d.cts +11 -0
  213. package/lib/optimise/figma.d.mts +11 -0
  214. package/lib/optimise/figma.mjs +5 -5
  215. package/lib/optimise/flags.cjs +3 -3
  216. package/lib/optimise/flags.d.cts +11 -0
  217. package/lib/optimise/flags.d.mts +11 -0
  218. package/lib/optimise/flags.d.ts +1 -1
  219. package/lib/optimise/flags.mjs +3 -3
  220. package/lib/optimise/global-style.cjs +7 -7
  221. package/lib/optimise/global-style.d.cts +11 -0
  222. package/lib/optimise/global-style.d.mts +11 -0
  223. package/lib/optimise/global-style.d.ts +1 -1
  224. package/lib/optimise/global-style.mjs +7 -7
  225. package/lib/optimise/mask.cjs +1 -1
  226. package/lib/optimise/mask.d.cts +24 -0
  227. package/lib/optimise/mask.d.mts +24 -0
  228. package/lib/optimise/mask.mjs +2 -2
  229. package/lib/optimise/origin.d.cts +11 -0
  230. package/lib/optimise/origin.d.mts +11 -0
  231. package/lib/optimise/scale.d.cts +11 -0
  232. package/lib/optimise/scale.d.mts +11 -0
  233. package/lib/optimise/svgo.cjs +1 -1
  234. package/lib/optimise/svgo.d.cts +37 -0
  235. package/lib/optimise/svgo.d.mts +37 -0
  236. package/lib/optimise/svgo.mjs +1 -1
  237. package/lib/svg/analyse/error.d.cts +10 -0
  238. package/lib/svg/analyse/error.d.mts +10 -0
  239. package/lib/svg/analyse/error.d.ts +1 -0
  240. package/lib/svg/analyse/types.d.cts +92 -0
  241. package/lib/svg/analyse/types.d.mts +92 -0
  242. package/lib/svg/analyse/types.d.ts +4 -3
  243. package/lib/svg/analyse.cjs +2 -2
  244. package/lib/svg/analyse.d.cts +15 -0
  245. package/lib/svg/analyse.d.mts +15 -0
  246. package/lib/svg/analyse.d.ts +1 -0
  247. package/lib/svg/analyse.mjs +4 -4
  248. package/lib/svg/cleanup/attribs.cjs +1 -1
  249. package/lib/svg/cleanup/attribs.d.cts +11 -0
  250. package/lib/svg/cleanup/attribs.d.mts +11 -0
  251. package/lib/svg/cleanup/attribs.mjs +2 -2
  252. package/lib/svg/cleanup/bad-tags.cjs +1 -1
  253. package/lib/svg/cleanup/bad-tags.d.cts +17 -0
  254. package/lib/svg/cleanup/bad-tags.d.mts +17 -0
  255. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  256. package/lib/svg/cleanup/bad-tags.mjs +2 -2
  257. package/lib/svg/cleanup/inline-style.cjs +1 -1
  258. package/lib/svg/cleanup/inline-style.d.cts +11 -0
  259. package/lib/svg/cleanup/inline-style.d.mts +11 -0
  260. package/lib/svg/cleanup/inline-style.mjs +2 -2
  261. package/lib/svg/cleanup/root-style.cjs +1 -1
  262. package/lib/svg/cleanup/root-style.d.cts +17 -0
  263. package/lib/svg/cleanup/root-style.d.mts +17 -0
  264. package/lib/svg/cleanup/root-style.mjs +2 -2
  265. package/lib/svg/cleanup/root-svg.cjs +3 -3
  266. package/lib/svg/cleanup/root-svg.d.cts +11 -0
  267. package/lib/svg/cleanup/root-svg.d.mts +11 -0
  268. package/lib/svg/cleanup/root-svg.mjs +3 -3
  269. package/lib/svg/cleanup/svgo-style.cjs +2 -2
  270. package/lib/svg/cleanup/svgo-style.d.cts +11 -0
  271. package/lib/svg/cleanup/svgo-style.d.mts +11 -0
  272. package/lib/svg/cleanup/svgo-style.mjs +3 -3
  273. package/lib/svg/cleanup.d.cts +16 -0
  274. package/lib/svg/cleanup.d.mts +16 -0
  275. package/lib/svg/cleanup.d.ts +1 -1
  276. package/lib/svg/data/attributes.d.cts +77 -0
  277. package/lib/svg/data/attributes.d.mts +77 -0
  278. package/lib/svg/data/tags.d.cts +95 -0
  279. package/lib/svg/data/tags.d.mts +95 -0
  280. package/lib/svg/index.cjs +18 -1
  281. package/lib/svg/index.d.cts +52 -0
  282. package/lib/svg/index.d.mts +52 -0
  283. package/lib/svg/index.d.ts +5 -1
  284. package/lib/svg/index.mjs +19 -2
  285. package/lib/svg/parse-style.cjs +178 -235
  286. package/lib/svg/parse-style.d.cts +58 -0
  287. package/lib/svg/parse-style.d.mts +58 -0
  288. package/lib/svg/parse-style.d.ts +3 -9
  289. package/lib/svg/parse-style.mjs +180 -236
  290. package/lib/svg/parse.cjs +27 -59
  291. package/lib/svg/parse.d.cts +30 -0
  292. package/lib/svg/parse.d.mts +30 -0
  293. package/lib/svg/parse.d.ts +3 -10
  294. package/lib/svg/parse.mjs +28 -59
  295. package/package.json +26 -21
@@ -0,0 +1,60 @@
1
+ import { Color } from '@iconify/utils/lib/colors/types';
2
+ import { SVG } from '../svg/index.cjs';
3
+ import { ColorAttributes } from './attribs.cjs';
4
+ import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.cjs';
5
+ import 'cheerio';
6
+ import '@iconify/types';
7
+ import '@iconify/utils/lib/customisations/defaults';
8
+ import '../misc/cheerio.cjs';
9
+
10
+ /**
11
+ * Result
12
+ */
13
+ interface FindColorsResult {
14
+ colors: (Color | string)[];
15
+ hasUnsetColor: boolean;
16
+ hasGlobalStyle: boolean;
17
+ }
18
+ /**
19
+ * Callback to call for each found color
20
+ *
21
+ * Callback should return:
22
+ * - new color value to change color
23
+ * - first parameter to keep old value
24
+ * - 'unset' to delete old value
25
+ * - 'remove' to remove shape or rule
26
+ */
27
+ type ParseColorsCallbackResult = Color | string | 'remove' | 'unset';
28
+ type ParseColorsCallback = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string, item?: ExtendedTagElementWithColors) => ParseColorsCallbackResult;
29
+ /**
30
+ * Callback for default color
31
+ */
32
+ type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
33
+ /**
34
+ * Options
35
+ */
36
+ interface ParseColorsOptions extends AnalyseSVGStructureOptions {
37
+ callback?: ParseColorsCallback;
38
+ defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
39
+ }
40
+ /**
41
+ * Extend properties for element
42
+ */
43
+ type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
44
+ interface ExtendedTagElementWithColors extends ExtendedTagElement {
45
+ _colors?: ItemColors;
46
+ _removed?: boolean;
47
+ }
48
+ /**
49
+ * Find colors in icon
50
+ *
51
+ * Clean up icon before running this function to convert style to attributes using
52
+ * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
53
+ */
54
+ declare function parseColors(svg: SVG, options?: ParseColorsOptions): FindColorsResult;
55
+ /**
56
+ * Check if color is empty, such as 'none' or 'transparent'
57
+ */
58
+ declare function isEmptyColor(color: Color): boolean;
59
+
60
+ export { type ExtendedTagElementWithColors, type FindColorsResult, type ParseColorOptionsDefaultColorCallback, type ParseColorsOptions, isEmptyColor, parseColors };
@@ -0,0 +1,60 @@
1
+ import { Color } from '@iconify/utils/lib/colors/types';
2
+ import { SVG } from '../svg/index.mjs';
3
+ import { ColorAttributes } from './attribs.mjs';
4
+ import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.mjs';
5
+ import 'cheerio';
6
+ import '@iconify/types';
7
+ import '@iconify/utils/lib/customisations/defaults';
8
+ import '../misc/cheerio.mjs';
9
+
10
+ /**
11
+ * Result
12
+ */
13
+ interface FindColorsResult {
14
+ colors: (Color | string)[];
15
+ hasUnsetColor: boolean;
16
+ hasGlobalStyle: boolean;
17
+ }
18
+ /**
19
+ * Callback to call for each found color
20
+ *
21
+ * Callback should return:
22
+ * - new color value to change color
23
+ * - first parameter to keep old value
24
+ * - 'unset' to delete old value
25
+ * - 'remove' to remove shape or rule
26
+ */
27
+ type ParseColorsCallbackResult = Color | string | 'remove' | 'unset';
28
+ type ParseColorsCallback = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string, item?: ExtendedTagElementWithColors) => ParseColorsCallbackResult;
29
+ /**
30
+ * Callback for default color
31
+ */
32
+ type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
33
+ /**
34
+ * Options
35
+ */
36
+ interface ParseColorsOptions extends AnalyseSVGStructureOptions {
37
+ callback?: ParseColorsCallback;
38
+ defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
39
+ }
40
+ /**
41
+ * Extend properties for element
42
+ */
43
+ type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
44
+ interface ExtendedTagElementWithColors extends ExtendedTagElement {
45
+ _colors?: ItemColors;
46
+ _removed?: boolean;
47
+ }
48
+ /**
49
+ * Find colors in icon
50
+ *
51
+ * Clean up icon before running this function to convert style to attributes using
52
+ * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
53
+ */
54
+ declare function parseColors(svg: SVG, options?: ParseColorsOptions): FindColorsResult;
55
+ /**
56
+ * Check if color is empty, such as 'none' or 'transparent'
57
+ */
58
+ declare function isEmptyColor(color: Color): boolean;
59
+
60
+ export { type ExtendedTagElementWithColors, type FindColorsResult, type ParseColorOptionsDefaultColorCallback, type ParseColorsOptions, isEmptyColor, parseColors };
@@ -1,10 +1,11 @@
1
1
  import { Color } from '@iconify/utils/lib/colors/types';
2
2
  import { SVG } from '../svg/index.js';
3
3
  import { ColorAttributes } from './attribs.js';
4
- import { ElementsTreeItem, AnalyseSVGStructureResult, ExtendedTagElement, AnalyseSVGStructureOptions } from '../svg/analyse/types.js';
4
+ import { ElementsTreeItem, AnalyseSVGStructureResult, AnalyseSVGStructureOptions, ExtendedTagElement } from '../svg/analyse/types.js';
5
5
  import 'cheerio';
6
6
  import '@iconify/types';
7
7
  import '@iconify/utils/lib/customisations/defaults';
8
+ import '../misc/cheerio.js';
8
9
 
9
10
  /**
10
11
  * Result
@@ -24,7 +25,7 @@ interface FindColorsResult {
24
25
  * - 'remove' to remove shape or rule
25
26
  */
26
27
  type ParseColorsCallbackResult = Color | string | 'remove' | 'unset';
27
- type ParseColorsCallback<T> = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string, item?: ExtendedTagElementWithColors) => T;
28
+ type ParseColorsCallback = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string, item?: ExtendedTagElementWithColors) => ParseColorsCallbackResult;
28
29
  /**
29
30
  * Callback for default color
30
31
  */
@@ -32,12 +33,10 @@ type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagEle
32
33
  /**
33
34
  * Options
34
35
  */
35
- interface Options<T> extends AnalyseSVGStructureOptions {
36
- callback?: T;
36
+ interface ParseColorsOptions extends AnalyseSVGStructureOptions {
37
+ callback?: ParseColorsCallback;
37
38
  defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
38
39
  }
39
- type ParseColorsOptions = Options<ParseColorsCallback<ParseColorsCallbackResult | Promise<ParseColorsCallbackResult>>>;
40
- type ParseColorsSyncOptions = Options<ParseColorsCallback<ParseColorsCallbackResult>>;
41
40
  /**
42
41
  * Extend properties for element
43
42
  */
@@ -52,17 +51,10 @@ interface ExtendedTagElementWithColors extends ExtendedTagElement {
52
51
  * Clean up icon before running this function to convert style to attributes using
53
52
  * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
54
53
  */
55
- declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
56
- /**
57
- * Find colors in icon, synchronous version
58
- *
59
- * Clean up icon before running this function to convert style to attributes using
60
- * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
61
- */
62
- declare function parseColorsSync(svg: SVG, options?: ParseColorsSyncOptions): FindColorsResult;
54
+ declare function parseColors(svg: SVG, options?: ParseColorsOptions): FindColorsResult;
63
55
  /**
64
56
  * Check if color is empty, such as 'none' or 'transparent'
65
57
  */
66
58
  declare function isEmptyColor(color: Color): boolean;
67
59
 
68
- export { ExtendedTagElementWithColors, FindColorsResult, ParseColorOptionsDefaultColorCallback, ParseColorsOptions, ParseColorsSyncOptions, isEmptyColor, parseColors, parseColorsSync };
60
+ export { type ExtendedTagElementWithColors, type FindColorsResult, type ParseColorOptionsDefaultColorCallback, type ParseColorsOptions, isEmptyColor, parseColors };
@@ -1,7 +1,7 @@
1
- import { stringToColor, compareColors, colorToString } from '@iconify/utils/lib/colors';
1
+ import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
2
2
  import { animateTags, shapeTags } from '../svg/data/tags.mjs';
3
- import { parseSVGStyle, parseSVGStyleSync } from '../svg/parse-style.mjs';
4
- import { defaultColorValues, allowDefaultColorValue, specialColorAttributes, defaultBlackColor, shapeColorAttributes } from './attribs.mjs';
3
+ import { parseSVGStyle } from '../svg/parse-style.mjs';
4
+ import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, allowDefaultColorValue } from './attribs.mjs';
5
5
  import { tagSpecificPresentationalAttributes } from '../svg/data/attributes.mjs';
6
6
  import { analyseSVGStructure } from '../svg/analyse.mjs';
7
7
  import '../css/parse.mjs';
@@ -16,7 +16,7 @@ import '../svg/analyse/error.mjs';
16
16
 
17
17
  const propsToCheck = Object.keys(defaultColorValues);
18
18
  const animatePropsToCheck = ["from", "to", "values"];
19
- function createContext(options, callback) {
19
+ function parseColors(svg, options = {}) {
20
20
  const result = {
21
21
  colors: [],
22
22
  hasUnsetColor: false,
@@ -47,12 +47,12 @@ function createContext(options, callback) {
47
47
  itemColors[prop] = addedColor === null ? color : addedColor;
48
48
  }
49
49
  }
50
- function getElementColor(prop, item, elements) {
50
+ function getElementColor(prop, item, elements2) {
51
51
  function find(prop2) {
52
52
  let currentItem = item;
53
53
  const allowDefaultColor = allowDefaultColorValue[prop2];
54
54
  while (currentItem) {
55
- const element = elements.get(
55
+ const element = elements2.get(
56
56
  currentItem.index
57
57
  );
58
58
  const color = element._colors?.[prop2];
@@ -77,81 +77,69 @@ function createContext(options, callback) {
77
77
  }
78
78
  return propColor;
79
79
  }
80
- function checkColor(done, prop, value, item) {
80
+ function checkColor(prop, value, item) {
81
81
  switch (value.trim().toLowerCase()) {
82
82
  case "":
83
83
  case "inherit":
84
- return done();
84
+ return;
85
85
  }
86
86
  const parsedColor = stringToColor(value);
87
87
  const defaultValue = parsedColor || value;
88
88
  if (parsedColor?.type === "function" && parsedColor.func === "url") {
89
89
  addColorToItem(prop, defaultValue, item, false);
90
- return done(value);
90
+ return value;
91
91
  }
92
- if (!callback) {
92
+ if (!options.callback) {
93
93
  addColorToItem(prop, defaultValue, item);
94
- return done(value);
94
+ return value;
95
95
  }
96
- callback(
97
- [prop, value, parsedColor, item?.tagName, item],
98
- (callbackResult) => {
99
- switch (callbackResult) {
100
- case "remove": {
101
- return done(item ? callbackResult : void 0);
102
- }
103
- case "unset":
104
- return done();
105
- }
106
- if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
107
- addColorToItem(prop, defaultValue, item);
108
- return done(value);
109
- }
110
- if (typeof callbackResult === "string") {
111
- const newColor = stringToColor(callbackResult);
112
- addColorToItem(prop, newColor || callbackResult, item);
113
- return done(callbackResult);
114
- }
115
- const newValue = colorToString(callbackResult);
116
- addColorToItem(prop, callbackResult, item);
117
- return done(newValue);
118
- }
96
+ const callbackResult = options.callback(
97
+ prop,
98
+ value,
99
+ parsedColor,
100
+ item?.tagName,
101
+ item
119
102
  );
103
+ if (callbackResult instanceof Promise) {
104
+ throw new Error("parseColors does not support async callbacks");
105
+ }
106
+ switch (callbackResult) {
107
+ case "remove": {
108
+ return item ? callbackResult : void 0;
109
+ }
110
+ case "unset":
111
+ return;
112
+ }
113
+ if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
114
+ addColorToItem(prop, defaultValue, item);
115
+ return value;
116
+ }
117
+ if (typeof callbackResult === "string") {
118
+ const newColor = stringToColor(callbackResult);
119
+ addColorToItem(prop, newColor || callbackResult, item);
120
+ return callbackResult;
121
+ }
122
+ const newValue = colorToString(callbackResult);
123
+ addColorToItem(prop, callbackResult, item);
124
+ return newValue;
120
125
  }
121
- function parseStyleItem(item, done) {
126
+ parseSVGStyle(svg, (item) => {
122
127
  const prop = item.prop;
123
128
  const value = item.value;
124
- if (propsToCheck.indexOf(prop) === -1) {
125
- return done(value);
129
+ if (!propsToCheck.includes(prop)) {
130
+ return value;
126
131
  }
127
132
  const attr = prop;
128
- checkColor(
129
- (newValue) => {
130
- if (newValue === void 0) {
131
- return done(newValue);
132
- }
133
- if (item.type === "global") {
134
- result.hasGlobalStyle = true;
135
- }
136
- return done(newValue);
137
- },
138
- attr,
139
- value
140
- );
141
- }
142
- return {
143
- result,
144
- defaultColor,
145
- rawOptions: options,
146
- findColor,
147
- addColorToItem,
148
- getElementColor,
149
- checkColor,
150
- parseStyleItem
151
- };
152
- }
153
- function analyseSVG(svg, context, done) {
154
- const iconData = analyseSVGStructure(svg, context.rawOptions);
133
+ const newValue = checkColor(attr, value);
134
+ if (newValue === void 0) {
135
+ return newValue;
136
+ }
137
+ if (item.type === "global") {
138
+ result.hasGlobalStyle = true;
139
+ }
140
+ return newValue;
141
+ });
142
+ const iconData = analyseSVGStructure(svg, options);
155
143
  const { elements, tree } = iconData;
156
144
  const cheerio = svg.$svg;
157
145
  const removedElements = /* @__PURE__ */ new Set();
@@ -176,15 +164,15 @@ function analyseSVG(svg, context, done) {
176
164
  removeChildren(element);
177
165
  cheerio(element).remove();
178
166
  }
179
- function parseTreeItem(item, done2) {
167
+ function parseTreeItem(item) {
180
168
  const index = item.index;
181
169
  if (removedElements.has(index) || parsedElements.has(index)) {
182
- return done2();
170
+ return;
183
171
  }
184
172
  parsedElements.add(index);
185
173
  const element = elements.get(index);
186
174
  if (element._removed) {
187
- return done2();
175
+ return;
188
176
  }
189
177
  const { tagName, attribs } = element;
190
178
  if (item.parent) {
@@ -198,243 +186,112 @@ function analyseSVG(svg, context, done) {
198
186
  };
199
187
  }
200
188
  }
201
- function parseCommonProps(done3) {
202
- const propsQueue = [];
203
- for (let i = 0; i < propsToCheck.length; i++) {
204
- const prop = propsToCheck[i];
205
- if (prop === "fill" && animateTags.has(tagName)) {
206
- continue;
207
- }
208
- const value = attribs[prop];
209
- if (value !== void 0) {
210
- propsQueue.push([prop, value]);
211
- }
189
+ for (let i = 0; i < propsToCheck.length; i++) {
190
+ const prop = propsToCheck[i];
191
+ if (prop === "fill" && animateTags.has(tagName)) {
192
+ continue;
212
193
  }
213
- const parsePropsQueue = () => {
214
- const queueItem = propsQueue.shift();
215
- if (!queueItem) {
216
- return done3();
217
- }
218
- const [prop, value] = queueItem;
219
- context.checkColor(
220
- (newValue) => {
221
- if (newValue !== value) {
222
- if (newValue === void 0) {
223
- cheerio(element).removeAttr(prop);
224
- if (element._colors) {
225
- delete element._colors[prop];
226
- }
227
- } else if (newValue === "remove") {
228
- removeElement(index, element);
229
- } else {
230
- cheerio(element).attr(prop, newValue);
231
- }
232
- }
233
- return parsePropsQueue();
234
- },
235
- prop,
236
- value,
237
- element
238
- );
239
- };
240
- parsePropsQueue();
241
- }
242
- function checkAnimations(done3) {
243
- const propsQueue = [];
244
- if (animateTags.has(tagName)) {
245
- const attr = attribs.attributeName;
246
- if (propsToCheck.indexOf(attr) !== -1) {
247
- for (let i = 0; i < animatePropsToCheck.length; i++) {
248
- const elementProp = animatePropsToCheck[i];
249
- const fullValue = attribs[elementProp];
250
- if (typeof fullValue !== "string") {
251
- continue;
194
+ const value = attribs[prop];
195
+ if (value !== void 0) {
196
+ const newValue = checkColor(prop, value, element);
197
+ if (newValue !== value) {
198
+ if (newValue === void 0) {
199
+ cheerio(element).removeAttr(prop);
200
+ if (element._colors) {
201
+ delete element._colors[prop];
252
202
  }
253
- propsQueue.push([elementProp, fullValue]);
203
+ } else if (newValue === "remove") {
204
+ removeElement(index, element);
205
+ return;
206
+ } else {
207
+ cheerio(element).attr(prop, newValue);
254
208
  }
255
209
  }
256
210
  }
257
- const parsePropsQueue = () => {
258
- const queueItem = propsQueue.shift();
259
- if (!queueItem) {
260
- return done3();
261
- }
262
- const [elementProp, fullValue] = queueItem;
263
- const splitValues = fullValue.split(";");
264
- let updatedValues = false;
265
- const parsedAllItems = () => {
211
+ }
212
+ if (animateTags.has(tagName)) {
213
+ const attr = attribs.attributeName;
214
+ if (propsToCheck.includes(attr)) {
215
+ for (let i = 0; i < animatePropsToCheck.length; i++) {
216
+ const elementProp = animatePropsToCheck[i];
217
+ const fullValue = attribs[elementProp];
218
+ if (typeof fullValue !== "string") {
219
+ continue;
220
+ }
221
+ const splitValues = fullValue.split(";");
222
+ let updatedValues = false;
223
+ for (let j = 0; j < splitValues.length; j++) {
224
+ const value = splitValues[j];
225
+ if (value !== void 0) {
226
+ const newValue = checkColor(
227
+ elementProp,
228
+ value
229
+ // Do not pass third parameter
230
+ );
231
+ if (newValue !== value) {
232
+ updatedValues = true;
233
+ splitValues[j] = typeof newValue === "string" ? newValue : "";
234
+ }
235
+ }
236
+ }
266
237
  if (updatedValues) {
267
238
  cheerio(element).attr(
268
239
  elementProp,
269
240
  splitValues.join(";")
270
241
  );
271
242
  }
272
- return parsePropsQueue();
273
- };
274
- const parseItem = (index2) => {
275
- if (index2 >= splitValues.length) {
276
- return parsedAllItems();
277
- }
278
- const value = splitValues[index2];
279
- if (value === void 0) {
280
- return parseItem(index2 + 1);
281
- }
282
- context.checkColor(
283
- (newValue) => {
284
- if (newValue !== value) {
285
- updatedValues = true;
286
- splitValues[index2] = typeof newValue === "string" ? newValue : "";
287
- }
288
- parseItem(index2 + 1);
289
- },
290
- elementProp,
291
- value
292
- // Do not pass third parameter
293
- );
294
- };
295
- parseItem(0);
296
- };
297
- parsePropsQueue();
243
+ }
244
+ }
298
245
  }
299
- parseCommonProps(() => {
300
- checkAnimations(() => {
301
- if (!context.result.hasGlobalStyle) {
302
- let requiredProps;
303
- if (shapeTags.has(tagName)) {
304
- requiredProps = shapeColorAttributes;
305
- }
306
- specialColorAttributes.forEach((attr) => {
307
- if (tagSpecificPresentationalAttributes[tagName]?.has(
308
- attr
309
- )) {
310
- requiredProps = [attr];
311
- }
312
- });
313
- if (requiredProps) {
314
- const itemColors = element._colors || (element._colors = {});
315
- for (let i = 0; i < requiredProps.length; i++) {
316
- const prop = requiredProps[i];
317
- const color = context.getElementColor(
246
+ if (!result.hasGlobalStyle) {
247
+ let requiredProps;
248
+ if (shapeTags.has(tagName)) {
249
+ requiredProps = shapeColorAttributes;
250
+ }
251
+ specialColorAttributes.forEach((attr) => {
252
+ if (tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
253
+ requiredProps = [attr];
254
+ }
255
+ });
256
+ if (requiredProps) {
257
+ const itemColors = element._colors || (element._colors = {});
258
+ for (let i = 0; i < requiredProps.length; i++) {
259
+ const prop = requiredProps[i];
260
+ const color = getElementColor(prop, item, elements);
261
+ if (color === defaultBlackColor) {
262
+ if (defaultColor) {
263
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
318
264
  prop,
265
+ element,
319
266
  item,
320
- elements
267
+ iconData
268
+ ) : defaultColor;
269
+ findColor(defaultColorValue, true);
270
+ cheerio(element).attr(
271
+ prop,
272
+ colorToString(defaultColorValue)
321
273
  );
322
- if (color === defaultBlackColor) {
323
- const defaultColor = context.defaultColor;
324
- if (defaultColor) {
325
- const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
326
- prop,
327
- element,
328
- item,
329
- iconData
330
- ) : defaultColor;
331
- context.findColor(defaultColorValue, true);
332
- cheerio(element).attr(
333
- prop,
334
- colorToString(defaultColorValue)
335
- );
336
- itemColors[prop] = defaultColorValue;
337
- } else {
338
- context.result.hasUnsetColor = true;
339
- }
340
- }
341
- }
342
- }
343
- }
344
- let index2 = 0;
345
- const parseChildItem = () => {
346
- if (index2 >= item.children.length) {
347
- return done2();
348
- }
349
- const childItem = item.children[index2];
350
- index2++;
351
- if (!childItem.usedAsMask) {
352
- parseTreeItem(childItem, parseChildItem);
353
- } else {
354
- parseChildItem();
355
- }
356
- };
357
- parseChildItem();
358
- });
359
- });
360
- }
361
- parseTreeItem(tree, done);
362
- }
363
- function parseColors(svg, options = {}) {
364
- const callback = options.callback;
365
- return new Promise((fulfill, reject) => {
366
- let context;
367
- try {
368
- context = createContext(
369
- options,
370
- callback ? (params, done) => {
371
- try {
372
- const result = callback(...params);
373
- if (result instanceof Promise) {
374
- result.then(done).catch(reject);
274
+ itemColors[prop] = defaultColorValue;
375
275
  } else {
376
- done(result);
276
+ result.hasUnsetColor = true;
377
277
  }
378
- } catch (err) {
379
- reject(err);
380
278
  }
381
- } : void 0
382
- );
383
- } catch (err) {
384
- reject(err);
385
- return;
386
- }
387
- parseSVGStyle(svg, (item) => {
388
- return new Promise((fulfill2, reject2) => {
389
- try {
390
- context.parseStyleItem(item, fulfill2);
391
- } catch (err) {
392
- reject2(err);
393
279
  }
394
- });
395
- }).then(() => {
396
- try {
397
- analyseSVG(svg, context, () => {
398
- fulfill(context.result);
399
- });
400
- } catch (err) {
401
- reject(err);
402
280
  }
403
- }).catch(reject);
404
- });
405
- }
406
- function parseColorsSync(svg, options = {}) {
407
- const callback = options.callback;
408
- const context = createContext(
409
- options,
410
- callback ? (params, done) => {
411
- done(callback(...params));
412
- } : void 0
413
- );
414
- parseSVGStyleSync(svg, (item) => {
415
- let isSync2 = true;
416
- let result;
417
- context.parseStyleItem(item, (value) => {
418
- if (!isSync2) {
419
- throw new Error("parseStyleItem callback supposed to be sync");
281
+ }
282
+ for (let i = 0; i < item.children.length; i++) {
283
+ const childItem = item.children[i];
284
+ if (!childItem.usedAsMask) {
285
+ parseTreeItem(childItem);
420
286
  }
421
- result = value;
422
- });
423
- isSync2 = false;
424
- return result;
425
- });
426
- let isSync = true;
427
- analyseSVG(svg, context, () => {
428
- if (!isSync) {
429
- throw new Error("analyseSVG callback supposed to be sync");
430
287
  }
431
- });
432
- isSync = false;
433
- return context.result;
288
+ }
289
+ parseTreeItem(tree);
290
+ return result;
434
291
  }
435
292
  function isEmptyColor(color) {
436
293
  const type = color.type;
437
294
  return type === "none" || type === "transparent";
438
295
  }
439
296
 
440
- export { isEmptyColor, parseColors, parseColorsSync };
297
+ export { isEmptyColor, parseColors };