@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,341 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEmptyColor = exports.parseColors = void 0;
4
- const colors_1 = require("@iconify/utils/lib/colors");
5
- const tags_1 = require("../svg/data/tags");
6
- const parse_style_1 = require("../svg/parse-style");
7
- const attribs_1 = require("./attribs");
8
- const attributes_1 = require("../svg/data/attributes");
9
- const analyse_1 = require("../svg/analyse");
10
- /**
11
- * Properties to check
12
- */
13
- const propsToCheck = Object.keys(attribs_1.defaultColorValues);
14
- const animatePropsToCheck = ['from', 'to', 'values'];
15
- /**
16
- * Find colors in icon
17
- *
18
- * Clean up icon before running this function to convert style to attributes using
19
- * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
20
- */
21
- async function parseColors(svg, options = {}) {
22
- const result = {
23
- colors: [],
24
- hasUnsetColor: false,
25
- hasGlobalStyle: false,
26
- };
27
- // Default color
28
- const defaultColor = typeof options.defaultColor === 'string'
29
- ? (0, colors_1.stringToColor)(options.defaultColor)
30
- : options.defaultColor;
31
- /**
32
- * Find matching color in results
33
- */
34
- function findColor(color, add = false) {
35
- const isString = typeof color === 'string';
36
- for (let i = 0; i < result.colors.length; i++) {
37
- const item = result.colors[i];
38
- if (item === color) {
39
- return item;
40
- }
41
- if (!isString &&
42
- typeof item !== 'string' &&
43
- (0, colors_1.compareColors)(item, color)) {
44
- return item;
45
- }
46
- }
47
- if (add) {
48
- result.colors.push(color);
49
- return color;
50
- }
51
- return null;
52
- }
53
- /**
54
- * Add color to item and to results
55
- */
56
- function addColorToItem(prop, color, item, add = true) {
57
- const addedColor = findColor(color, add !== false);
58
- if (item) {
59
- const itemColors = item._colors || (item._colors = {});
60
- itemColors[prop] = addedColor === null ? color : addedColor;
61
- }
62
- }
63
- /**
64
- * Get element color
65
- */
66
- function getElementColor(prop, item, elements) {
67
- function find(prop) {
68
- var _a;
69
- let currentItem = item;
70
- while (currentItem) {
71
- const element = elements.get(currentItem.index);
72
- const color = (_a = element._colors) === null || _a === void 0 ? void 0 : _a[prop];
73
- if (color !== void 0) {
74
- return color;
75
- }
76
- currentItem = currentItem.parent;
77
- if (currentItem === null || currentItem === void 0 ? void 0 : currentItem.usedAsMask) {
78
- // Used as mask: color from parent item is irrelevant
79
- return attribs_1.defaultColorValues[prop];
80
- }
81
- }
82
- return attribs_1.defaultColorValues[prop];
83
- }
84
- let propColor = find(prop);
85
- if (typeof propColor === 'object' &&
86
- propColor.type === 'current' &&
87
- prop !== 'color') {
88
- // currentColor: get color
89
- propColor = find('color');
90
- }
91
- return propColor;
92
- }
93
- /**
94
- * Change color
95
- */
96
- async function checkColor(prop, value, item) {
97
- // Ignore empty values
98
- switch (value.trim().toLowerCase()) {
99
- case '':
100
- case 'inherit':
101
- return;
102
- }
103
- // Resolve color
104
- const parsedColor = (0, colors_1.stringToColor)(value);
105
- const defaultValue = parsedColor || value;
106
- // Ignore url()
107
- if ((parsedColor === null || parsedColor === void 0 ? void 0 : parsedColor.type) === 'function' && parsedColor.func === 'url') {
108
- // Add to item, so it won't be treated as missing, but do not add to results
109
- addColorToItem(prop, defaultValue, item, false);
110
- return value;
111
- }
112
- // Check if callback exists
113
- if (!options.callback) {
114
- addColorToItem(prop, defaultValue, item);
115
- return value;
116
- }
117
- // Call callback
118
- let callbackResult = options.callback(prop, value, parsedColor, item === null || item === void 0 ? void 0 : item.tagName, item);
119
- callbackResult =
120
- callbackResult instanceof Promise
121
- ? await callbackResult
122
- : callbackResult;
123
- // Remove entry
124
- switch (callbackResult) {
125
- case 'remove': {
126
- return item ? callbackResult : void 0;
127
- }
128
- case 'unset':
129
- return;
130
- }
131
- if (callbackResult === value ||
132
- (parsedColor && callbackResult === parsedColor)) {
133
- // Not changed
134
- addColorToItem(prop, defaultValue, item);
135
- return value;
136
- }
137
- if (typeof callbackResult === 'string') {
138
- const newColor = (0, colors_1.stringToColor)(callbackResult);
139
- addColorToItem(prop, newColor || callbackResult, item);
140
- return callbackResult;
141
- }
142
- // Color
143
- const newValue = (0, colors_1.colorToString)(callbackResult);
144
- addColorToItem(prop, callbackResult, item);
145
- return newValue;
146
- }
147
- // Parse colors in style
148
- await (0, parse_style_1.parseSVGStyle)(svg, async (item) => {
149
- const prop = item.prop;
150
- const value = item.value;
151
- if (propsToCheck.indexOf(prop) === -1) {
152
- return value;
153
- }
154
- // Color
155
- const attr = prop;
156
- const newValue = await checkColor(attr, value);
157
- if (newValue === void 0) {
158
- return newValue;
159
- }
160
- // Got color
161
- if (item.type === 'global') {
162
- result.hasGlobalStyle = true;
163
- }
164
- return newValue;
165
- });
166
- // Analyse SVG
167
- const iconData = await (0, analyse_1.analyseSVGStructure)(svg, options);
168
- const { elements, tree } = iconData;
169
- const cheerio = svg.$svg;
170
- const removedElements = new Set();
171
- const parsedElements = new Set();
172
- // Remove element
173
- function removeElement(index, element) {
174
- // Mark all children as removed (direct children as in DOM)
175
- function removeChildren(element) {
176
- element.children.forEach((item) => {
177
- if (item.type !== 'tag') {
178
- return;
179
- }
180
- const element = item;
181
- const index = element._index;
182
- if (index && !removedElements.has(index)) {
183
- element._removed = true;
184
- removedElements.add(index);
185
- removeChildren(element);
186
- }
187
- });
188
- }
189
- // Remove element
190
- element._removed = true;
191
- removedElements.add(index);
192
- removeChildren(element);
193
- cheerio(element).remove();
194
- }
195
- // Parse tree item
196
- async function parseTreeItem(item) {
197
- const index = item.index;
198
- if (removedElements.has(index) || parsedElements.has(index)) {
199
- return;
200
- }
201
- parsedElements.add(index);
202
- const element = elements.get(index);
203
- if (element._removed) {
204
- return;
205
- }
206
- const { tagName, attribs } = element;
207
- // Copy colors from parent item
208
- if (item.parent) {
209
- const parentIndex = item.parent.index;
210
- const parentElement = elements.get(parentIndex);
211
- if (parentElement._colors) {
212
- element._colors = {
213
- ...parentElement._colors,
214
- };
215
- }
216
- }
217
- // Check common properties
218
- for (let i = 0; i < propsToCheck.length; i++) {
219
- const prop = propsToCheck[i];
220
- if (prop === 'fill' && tags_1.animateTags.has(tagName)) {
221
- // 'fill' has different meaning in animations
222
- continue;
223
- }
224
- const value = attribs[prop];
225
- if (value !== void 0) {
226
- const newValue = await checkColor(prop, value, element);
227
- if (newValue !== value) {
228
- if (newValue === void 0) {
229
- // Unset
230
- cheerio(element).removeAttr(prop);
231
- if (element._colors) {
232
- delete element._colors[prop];
233
- }
234
- }
235
- else if (newValue === 'remove') {
236
- // Remove element
237
- removeElement(index, element);
238
- return;
239
- }
240
- else {
241
- // Change attribute
242
- // Value in element._colors is changed in checkColor()
243
- cheerio(element).attr(prop, newValue);
244
- }
245
- }
246
- }
247
- }
248
- // Check animations
249
- if (tags_1.animateTags.has(tagName)) {
250
- const attr = attribs.attributeName;
251
- if (propsToCheck.indexOf(attr) !== -1) {
252
- // Valid property
253
- for (let i = 0; i < animatePropsToCheck.length; i++) {
254
- const elementProp = animatePropsToCheck[i];
255
- const fullValue = attribs[elementProp];
256
- if (typeof fullValue !== 'string') {
257
- continue;
258
- }
259
- // Split values
260
- const splitValues = fullValue.split(';');
261
- let updatedValues = false;
262
- for (let j = 0; j < splitValues.length; j++) {
263
- const value = splitValues[j];
264
- if (value !== void 0) {
265
- const newValue = await checkColor(elementProp, value
266
- // Do not pass third parameter
267
- );
268
- if (newValue !== value) {
269
- updatedValues = true;
270
- splitValues[j] =
271
- typeof newValue === 'string'
272
- ? newValue
273
- : '';
274
- }
275
- }
276
- }
277
- // Merge values back
278
- if (updatedValues) {
279
- cheerio(element).attr(elementProp, splitValues.join(';'));
280
- }
281
- }
282
- }
283
- }
284
- // Check shape for default colors
285
- if (!result.hasGlobalStyle) {
286
- // Get list of properties required to render element
287
- let requiredProps;
288
- if (tags_1.shapeTags.has(tagName)) {
289
- requiredProps = attribs_1.shapeColorAttributes;
290
- }
291
- attribs_1.specialColorAttributes.forEach((attr) => {
292
- var _a;
293
- if ((_a = attributes_1.tagSpecificPresentationalAttributes[tagName]) === null || _a === void 0 ? void 0 : _a.has(attr)) {
294
- requiredProps = [attr];
295
- }
296
- });
297
- // Check colors
298
- if (requiredProps) {
299
- const itemColors = element._colors || (element._colors = {});
300
- for (let i = 0; i < requiredProps.length; i++) {
301
- const prop = requiredProps[i];
302
- const color = getElementColor(prop, item, elements);
303
- if (color === attribs_1.defaultBlackColor) {
304
- // Default black color: change it
305
- if (defaultColor) {
306
- const defaultColorValue = typeof defaultColor === 'function'
307
- ? defaultColor(prop, element, item, iconData)
308
- : defaultColor;
309
- // Add color to results and change attribute
310
- findColor(defaultColorValue, true);
311
- cheerio(element).attr(prop, (0, colors_1.colorToString)(defaultColorValue));
312
- itemColors[prop] = defaultColorValue;
313
- }
314
- else {
315
- result.hasUnsetColor = true;
316
- }
317
- }
318
- }
319
- }
320
- }
321
- // Parse child elements
322
- for (let i = 0; i < item.children.length; i++) {
323
- const childItem = item.children[i];
324
- if (!childItem.usedAsMask) {
325
- await parseTreeItem(childItem);
326
- }
327
- }
328
- }
329
- // Parse tree, starting with <svg>
330
- await parseTreeItem(tree);
331
- return result;
332
- }
333
- exports.parseColors = parseColors;
334
- /**
335
- * Check if color is empty, such as 'none' or 'transparent'
336
- */
337
- function isEmptyColor(color) {
338
- const type = color.type;
339
- return type === 'none' || type === 'transparent';
340
- }
341
- exports.isEmptyColor = isEmptyColor;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateColors = void 0;
4
- const colors_1 = require("@iconify/utils/lib/colors");
5
- const parse_1 = require("./parse");
6
- /**
7
- * Validate colors in icon
8
- *
9
- * If icon is monotone,
10
- *
11
- * Throws exception on error
12
- */
13
- async function validateColors(svg, expectMonotone, options) {
14
- // Parse colors
15
- const palette = await (0, parse_1.parseColors)(svg, options);
16
- // Check palette
17
- palette.colors.forEach((color) => {
18
- if (typeof color === 'string') {
19
- throw new Error('Unexpected color: ' + color);
20
- }
21
- switch (color.type) {
22
- case 'none':
23
- case 'transparent':
24
- return;
25
- // Monotone
26
- case 'current':
27
- if (!expectMonotone) {
28
- throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
29
- }
30
- return;
31
- // Palette
32
- case 'rgb':
33
- case 'hsl':
34
- if (expectMonotone) {
35
- throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
36
- }
37
- return;
38
- default:
39
- // Allow url()
40
- if (color.type !== 'function' || color.func !== 'url') {
41
- // Do not allow other colors
42
- throw new Error('Unexpected color: ' + (0, colors_1.colorToString)(color));
43
- }
44
- }
45
- });
46
- return palette;
47
- }
48
- exports.validateColors = validateColors;
package/lib/css/parse.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseInlineStyle = void 0;
4
- const tokens_1 = require("./parser/tokens");
5
- /**
6
- * Parse inline style
7
- */
8
- function parseInlineStyle(style) {
9
- const tokens = (0, tokens_1.getTokens)(style);
10
- if (!(tokens instanceof Array)) {
11
- return null;
12
- }
13
- const results = Object.create(null);
14
- for (let i = 0; i < tokens.length; i++) {
15
- const token = tokens[i];
16
- if (token.type !== 'rule') {
17
- return null;
18
- }
19
- results[token.prop] = token.value;
20
- }
21
- return results;
22
- }
23
- exports.parseInlineStyle = parseInlineStyle;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.styleParseError = void 0;
4
- /**
5
- * Create error message
6
- */
7
- function styleParseError(message, code, index) {
8
- let fullMessage = message;
9
- if (typeof index === 'number' && index !== -1) {
10
- const start = index;
11
- // Check for space on left side of remaining code to calculate line start correctly
12
- const remaining = code.slice(index) + '!';
13
- const trimmed = remaining.trim();
14
- const end = start + remaining.length - trimmed.length;
15
- const code2 = code.slice(0, end);
16
- const line = code2.length - code2.replace(/\n/g, '').length + 1;
17
- fullMessage = message + ' on line ' + line;
18
- }
19
- return {
20
- type: 'style-parse-error',
21
- message,
22
- code,
23
- index,
24
- fullMessage,
25
- };
26
- }
27
- exports.styleParseError = styleParseError;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tokensToString = void 0;
4
- const tab = '\t';
5
- const nl = '\n';
6
- /**
7
- * Convert tokens tree to string
8
- */
9
- function tokensToString(tree) {
10
- let compact = true;
11
- for (let i = 0; i < tree.length; i++) {
12
- if (tree[i].type !== 'rule') {
13
- compact = false;
14
- break;
15
- }
16
- }
17
- return tree
18
- .map((token) => {
19
- return parseToken(token, compact, 0);
20
- })
21
- .join('');
22
- }
23
- exports.tokensToString = tokensToString;
24
- /**
25
- * Old code
26
- */
27
- function parseToken(token, compact, depth) {
28
- let content;
29
- switch (token.type) {
30
- case 'rule': {
31
- return ((compact ? '' : tab.repeat(depth)) +
32
- token.prop +
33
- (compact ? ':' : ': ') +
34
- token.value +
35
- ';' +
36
- (compact ? '' : nl));
37
- }
38
- case 'at-rule': {
39
- content =
40
- '@' + token.atRule + joinAtValues(token.atValues, compact);
41
- break;
42
- }
43
- case 'selector': {
44
- content = token.selectors.join(compact ? ',' : ', ');
45
- }
46
- }
47
- const children = token.children.map((item) => {
48
- return parseToken(item, compact, depth + 1);
49
- });
50
- return ((compact ? '' : tab.repeat(depth)) +
51
- content +
52
- (compact ? '{' : ' {' + nl) +
53
- children.join('') +
54
- (compact ? '}' : tab.repeat(depth) + '}' + nl));
55
- }
56
- /**
57
- * Join at-rule values
58
- */
59
- function joinAtValues(values, compact) {
60
- return values
61
- .map((item) => {
62
- const value = typeof item === 'string' ? item : joinAtValues(item, compact);
63
- if (value.slice(0, 1) === '(' || value.slice(-1) === ')') {
64
- return value;
65
- }
66
- return '(' + value + ')';
67
- })
68
- .join(compact ? ',' : ', ');
69
- }
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findEndOfURL = exports.findEndOfQuotedString = void 0;
4
- const error_1 = require("./error");
5
- /**
6
- * Find end of quoted string
7
- *
8
- * Returns index of character after quote
9
- */
10
- function findEndOfQuotedString(code, quote, start) {
11
- let nextEscape = code.indexOf('\\', start + 1);
12
- let end = code.indexOf(quote, start + 1);
13
- if (end === -1) {
14
- // Invalid string
15
- return null;
16
- }
17
- while (nextEscape !== -1 && nextEscape < end) {
18
- if (end === nextEscape + 1) {
19
- end = code.indexOf(quote, end + 1);
20
- if (end === -1) {
21
- // Invalid string
22
- return null;
23
- }
24
- }
25
- nextEscape = code.indexOf('\\', nextEscape + 2);
26
- }
27
- return end + 1;
28
- }
29
- exports.findEndOfQuotedString = findEndOfQuotedString;
30
- /**
31
- * Find end of url
32
- *
33
- * Returns index of character after end of URL
34
- */
35
- function findEndOfURL(code, start) {
36
- let index = (start || 0) + 4;
37
- const length = code.length;
38
- // eslint-disable-next-line no-constant-condition
39
- while (true) {
40
- if (index >= length) {
41
- return (0, error_1.styleParseError)('Cannot find end of URL', code, start);
42
- }
43
- let next = code.charAt(index);
44
- switch (next) {
45
- case '"':
46
- case "'": {
47
- // quoted url
48
- let end = findEndOfQuotedString(code, next, index);
49
- if (end === null) {
50
- return (0, error_1.styleParseError)('Incomplete string', code, index);
51
- }
52
- end = code.indexOf(')', end);
53
- return end === -1
54
- ? (0, error_1.styleParseError)('Cannot find end of URL', code, start)
55
- : end + 1;
56
- }
57
- case ' ':
58
- case '\t':
59
- case '\r':
60
- case '\n':
61
- // skip whitespace
62
- index++;
63
- break;
64
- default:
65
- // unquoted url
66
- // eslint-disable-next-line no-constant-condition
67
- while (true) {
68
- switch (next) {
69
- case ')':
70
- return index + 1;
71
- case '"':
72
- case "'":
73
- case '(':
74
- case ' ':
75
- case '\t':
76
- case '\r':
77
- case '\n':
78
- return (0, error_1.styleParseError)('Invalid URL', code, start);
79
- default:
80
- if (code.charCodeAt(index) < 32) {
81
- return (0, error_1.styleParseError)('Invalid URL', code, start);
82
- }
83
- }
84
- index++;
85
- if (index >= length) {
86
- return (0, error_1.styleParseError)('Cannot find end of URL', code, start);
87
- }
88
- next = code.charAt(index);
89
- }
90
- }
91
- }
92
- }
93
- exports.findEndOfURL = findEndOfURL;