@iconify/tools 4.0.0-dev.1 → 4.0.1

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 (301) 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 +15 -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 +14 -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 +3 -3
  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 +55 -33
  212. package/lib/optimise/figma.d.cts +13 -0
  213. package/lib/optimise/figma.d.mts +13 -0
  214. package/lib/optimise/figma.d.ts +3 -1
  215. package/lib/optimise/figma.mjs +55 -33
  216. package/lib/optimise/flags.cjs +3 -3
  217. package/lib/optimise/flags.d.cts +11 -0
  218. package/lib/optimise/flags.d.mts +11 -0
  219. package/lib/optimise/flags.d.ts +1 -1
  220. package/lib/optimise/flags.mjs +3 -3
  221. package/lib/optimise/global-style.cjs +7 -7
  222. package/lib/optimise/global-style.d.cts +11 -0
  223. package/lib/optimise/global-style.d.mts +11 -0
  224. package/lib/optimise/global-style.d.ts +1 -1
  225. package/lib/optimise/global-style.mjs +7 -7
  226. package/lib/optimise/mask.cjs +1 -1
  227. package/lib/optimise/mask.d.cts +24 -0
  228. package/lib/optimise/mask.d.mts +24 -0
  229. package/lib/optimise/mask.mjs +2 -2
  230. package/lib/optimise/origin.d.cts +11 -0
  231. package/lib/optimise/origin.d.mts +11 -0
  232. package/lib/optimise/scale.d.cts +11 -0
  233. package/lib/optimise/scale.d.mts +11 -0
  234. package/lib/optimise/svgo.cjs +1 -1
  235. package/lib/optimise/svgo.d.cts +37 -0
  236. package/lib/optimise/svgo.d.mts +37 -0
  237. package/lib/optimise/svgo.mjs +1 -1
  238. package/lib/optimise/unwrap.cjs +31 -0
  239. package/lib/optimise/unwrap.d.cts +11 -0
  240. package/lib/optimise/unwrap.d.mts +11 -0
  241. package/lib/optimise/unwrap.d.ts +11 -0
  242. package/lib/optimise/unwrap.mjs +29 -0
  243. package/lib/svg/analyse/error.d.cts +10 -0
  244. package/lib/svg/analyse/error.d.mts +10 -0
  245. package/lib/svg/analyse/error.d.ts +1 -0
  246. package/lib/svg/analyse/types.d.cts +92 -0
  247. package/lib/svg/analyse/types.d.mts +92 -0
  248. package/lib/svg/analyse/types.d.ts +4 -3
  249. package/lib/svg/analyse.cjs +2 -2
  250. package/lib/svg/analyse.d.cts +15 -0
  251. package/lib/svg/analyse.d.mts +15 -0
  252. package/lib/svg/analyse.d.ts +1 -0
  253. package/lib/svg/analyse.mjs +4 -4
  254. package/lib/svg/cleanup/attribs.cjs +1 -1
  255. package/lib/svg/cleanup/attribs.d.cts +11 -0
  256. package/lib/svg/cleanup/attribs.d.mts +11 -0
  257. package/lib/svg/cleanup/attribs.mjs +2 -2
  258. package/lib/svg/cleanup/bad-tags.cjs +1 -1
  259. package/lib/svg/cleanup/bad-tags.d.cts +17 -0
  260. package/lib/svg/cleanup/bad-tags.d.mts +17 -0
  261. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  262. package/lib/svg/cleanup/bad-tags.mjs +2 -2
  263. package/lib/svg/cleanup/inline-style.cjs +1 -1
  264. package/lib/svg/cleanup/inline-style.d.cts +11 -0
  265. package/lib/svg/cleanup/inline-style.d.mts +11 -0
  266. package/lib/svg/cleanup/inline-style.mjs +2 -2
  267. package/lib/svg/cleanup/root-style.cjs +1 -1
  268. package/lib/svg/cleanup/root-style.d.cts +17 -0
  269. package/lib/svg/cleanup/root-style.d.mts +17 -0
  270. package/lib/svg/cleanup/root-style.mjs +2 -2
  271. package/lib/svg/cleanup/root-svg.cjs +3 -3
  272. package/lib/svg/cleanup/root-svg.d.cts +11 -0
  273. package/lib/svg/cleanup/root-svg.d.mts +11 -0
  274. package/lib/svg/cleanup/root-svg.mjs +3 -3
  275. package/lib/svg/cleanup/svgo-style.cjs +2 -2
  276. package/lib/svg/cleanup/svgo-style.d.cts +11 -0
  277. package/lib/svg/cleanup/svgo-style.d.mts +11 -0
  278. package/lib/svg/cleanup/svgo-style.mjs +3 -3
  279. package/lib/svg/cleanup.d.cts +16 -0
  280. package/lib/svg/cleanup.d.mts +16 -0
  281. package/lib/svg/cleanup.d.ts +1 -1
  282. package/lib/svg/data/attributes.d.cts +77 -0
  283. package/lib/svg/data/attributes.d.mts +77 -0
  284. package/lib/svg/data/tags.d.cts +95 -0
  285. package/lib/svg/data/tags.d.mts +95 -0
  286. package/lib/svg/index.cjs +18 -1
  287. package/lib/svg/index.d.cts +52 -0
  288. package/lib/svg/index.d.mts +52 -0
  289. package/lib/svg/index.d.ts +5 -1
  290. package/lib/svg/index.mjs +19 -2
  291. package/lib/svg/parse-style.cjs +178 -235
  292. package/lib/svg/parse-style.d.cts +58 -0
  293. package/lib/svg/parse-style.d.mts +58 -0
  294. package/lib/svg/parse-style.d.ts +3 -9
  295. package/lib/svg/parse-style.mjs +180 -236
  296. package/lib/svg/parse.cjs +27 -59
  297. package/lib/svg/parse.d.cts +30 -0
  298. package/lib/svg/parse.d.mts +30 -0
  299. package/lib/svg/parse.d.ts +3 -10
  300. package/lib/svg/parse.mjs +28 -59
  301. package/package.json +34 -24
package/lib/svg/parse.cjs CHANGED
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
- function parse(svg, callback, done) {
4
- function checkNode(element, parents, done2) {
3
+ function parseSVG(svg, callback) {
4
+ const cheerio = svg.$svg;
5
+ const $root = svg.$svg(":root");
6
+ function checkNode(element, parents) {
5
7
  if (element.type !== "tag") {
6
- return done2();
8
+ return;
7
9
  }
8
- const $element = cheerio2(element);
10
+ const $element = cheerio(element);
9
11
  const tagName = element.tagName;
10
12
  const item = {
11
13
  tagName,
@@ -16,63 +18,29 @@ function parse(svg, callback, done) {
16
18
  testChildren: true,
17
19
  removeNode: false
18
20
  };
19
- callback(item, () => {
20
- const newParents = parents.slice(0);
21
- newParents.unshift(item);
22
- let queue = [];
23
- if (tagName !== "style" && item.testChildren && !item.removeNode) {
24
- const children = $element.children().toArray();
25
- queue = children.slice(0);
26
- }
27
- const next = () => {
28
- const queueItem = queue.shift();
29
- if (!queueItem) {
30
- if (item.removeNode) {
31
- $element.remove();
32
- }
33
- return done2();
34
- }
35
- checkNode(queueItem, newParents, next);
36
- };
37
- next();
38
- });
39
- }
40
- const cheerio2 = svg.$svg;
41
- const $root = svg.$svg(":root");
42
- checkNode($root.get(0), [], done);
43
- }
44
- function parseSVG(svg, callback) {
45
- return new Promise((fulfill, reject) => {
46
- parse(
47
- svg,
48
- (item, next) => {
49
- const result = callback(item);
50
- if (result instanceof Promise) {
51
- result.then(next).catch(reject);
52
- } else {
53
- next();
54
- }
55
- },
56
- fulfill
57
- );
58
- });
59
- }
60
- function parseSVGSync(svg, callback) {
61
- let isSync = true;
62
- parse(
63
- svg,
64
- (item, next) => {
65
- callback(item);
66
- next();
67
- },
68
- () => {
69
- if (!isSync) {
70
- throw new Error("parseSVGSync callback was async");
21
+ const callbackResult = callback(item);
22
+ if (callbackResult instanceof Promise) {
23
+ throw new Error("parseSVG does not support async callbacks");
24
+ }
25
+ const newParents = parents.slice(0);
26
+ newParents.unshift(item);
27
+ let queue = [];
28
+ if (tagName !== "style" && item.testChildren && !item.removeNode) {
29
+ const children = $element.children().toArray();
30
+ queue = children.slice(0);
31
+ }
32
+ while (queue.length) {
33
+ const queueItem = queue.shift();
34
+ if (!queueItem || item.removeNode) {
35
+ break;
71
36
  }
37
+ checkNode(queueItem, newParents);
38
+ }
39
+ if (item.removeNode) {
40
+ $element.remove();
72
41
  }
73
- );
74
- isSync = false;
42
+ }
43
+ checkNode($root.get(0), []);
75
44
  }
76
45
 
77
46
  exports.parseSVG = parseSVG;
78
- exports.parseSVGSync = parseSVGSync;
@@ -0,0 +1,30 @@
1
+ import { CheerioElement, WrappedCheerioElement } from '../misc/cheerio.cjs';
2
+ import { SVG } from './index.cjs';
3
+ import 'cheerio';
4
+ import '@iconify/types';
5
+ import '@iconify/utils/lib/customisations/defaults';
6
+
7
+ /**
8
+ * Item in callback
9
+ */
10
+ interface ParseSVGCallbackItem {
11
+ tagName: string;
12
+ element: CheerioElement;
13
+ $element: WrappedCheerioElement;
14
+ svg: SVG;
15
+ parents: ParseSVGCallbackItem[];
16
+ testChildren: boolean;
17
+ removeNode: boolean;
18
+ }
19
+ /**
20
+ * Callback function
21
+ */
22
+ type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
23
+ /**
24
+ * Parse SVG
25
+ *
26
+ * This function finds all elements in SVG and calls callback for each element.
27
+ */
28
+ declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
29
+
30
+ export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
@@ -0,0 +1,30 @@
1
+ import { CheerioElement, WrappedCheerioElement } from '../misc/cheerio.mjs';
2
+ import { SVG } from './index.mjs';
3
+ import 'cheerio';
4
+ import '@iconify/types';
5
+ import '@iconify/utils/lib/customisations/defaults';
6
+
7
+ /**
8
+ * Item in callback
9
+ */
10
+ interface ParseSVGCallbackItem {
11
+ tagName: string;
12
+ element: CheerioElement;
13
+ $element: WrappedCheerioElement;
14
+ svg: SVG;
15
+ parents: ParseSVGCallbackItem[];
16
+ testChildren: boolean;
17
+ removeNode: boolean;
18
+ }
19
+ /**
20
+ * Callback function
21
+ */
22
+ type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
23
+ /**
24
+ * Parse SVG
25
+ *
26
+ * This function finds all elements in SVG and calls callback for each element.
27
+ */
28
+ declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
29
+
30
+ export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
@@ -19,19 +19,12 @@ interface ParseSVGCallbackItem {
19
19
  /**
20
20
  * Callback function
21
21
  */
22
- type Callback<T> = (item: ParseSVGCallbackItem) => T;
23
- type ParseSVGCallback = Callback<void | Promise<void>>;
24
- type ParseSVGCallbackSync = Callback<void>;
22
+ type ParseSVGCallback = (item: ParseSVGCallbackItem) => void;
25
23
  /**
26
24
  * Parse SVG
27
25
  *
28
26
  * This function finds all elements in SVG and calls callback for each element.
29
- * Callback can be asynchronous.
30
27
  */
31
- declare function parseSVG(svg: SVG, callback: ParseSVGCallback): Promise<void>;
32
- /**
33
- * Sync version
34
- */
35
- declare function parseSVGSync(svg: SVG, callback: ParseSVGCallbackSync): void;
28
+ declare function parseSVG(svg: SVG, callback: ParseSVGCallback): void;
36
29
 
37
- export { ParseSVGCallback, ParseSVGCallbackItem, ParseSVGCallbackSync, parseSVG, parseSVGSync };
30
+ export { type ParseSVGCallback, type ParseSVGCallbackItem, parseSVG };
package/lib/svg/parse.mjs CHANGED
@@ -1,9 +1,11 @@
1
- function parse(svg, callback, done) {
2
- function checkNode(element, parents, done2) {
1
+ function parseSVG(svg, callback) {
2
+ const cheerio = svg.$svg;
3
+ const $root = svg.$svg(":root");
4
+ function checkNode(element, parents) {
3
5
  if (element.type !== "tag") {
4
- return done2();
6
+ return;
5
7
  }
6
- const $element = cheerio2(element);
8
+ const $element = cheerio(element);
7
9
  const tagName = element.tagName;
8
10
  const item = {
9
11
  tagName,
@@ -14,62 +16,29 @@ function parse(svg, callback, done) {
14
16
  testChildren: true,
15
17
  removeNode: false
16
18
  };
17
- callback(item, () => {
18
- const newParents = parents.slice(0);
19
- newParents.unshift(item);
20
- let queue = [];
21
- if (tagName !== "style" && item.testChildren && !item.removeNode) {
22
- const children = $element.children().toArray();
23
- queue = children.slice(0);
24
- }
25
- const next = () => {
26
- const queueItem = queue.shift();
27
- if (!queueItem) {
28
- if (item.removeNode) {
29
- $element.remove();
30
- }
31
- return done2();
32
- }
33
- checkNode(queueItem, newParents, next);
34
- };
35
- next();
36
- });
37
- }
38
- const cheerio2 = svg.$svg;
39
- const $root = svg.$svg(":root");
40
- checkNode($root.get(0), [], done);
41
- }
42
- function parseSVG(svg, callback) {
43
- return new Promise((fulfill, reject) => {
44
- parse(
45
- svg,
46
- (item, next) => {
47
- const result = callback(item);
48
- if (result instanceof Promise) {
49
- result.then(next).catch(reject);
50
- } else {
51
- next();
52
- }
53
- },
54
- fulfill
55
- );
56
- });
57
- }
58
- function parseSVGSync(svg, callback) {
59
- let isSync = true;
60
- parse(
61
- svg,
62
- (item, next) => {
63
- callback(item);
64
- next();
65
- },
66
- () => {
67
- if (!isSync) {
68
- throw new Error("parseSVGSync callback was async");
19
+ const callbackResult = callback(item);
20
+ if (callbackResult instanceof Promise) {
21
+ throw new Error("parseSVG does not support async callbacks");
22
+ }
23
+ const newParents = parents.slice(0);
24
+ newParents.unshift(item);
25
+ let queue = [];
26
+ if (tagName !== "style" && item.testChildren && !item.removeNode) {
27
+ const children = $element.children().toArray();
28
+ queue = children.slice(0);
29
+ }
30
+ while (queue.length) {
31
+ const queueItem = queue.shift();
32
+ if (!queueItem || item.removeNode) {
33
+ break;
69
34
  }
35
+ checkNode(queueItem, newParents);
36
+ }
37
+ if (item.removeNode) {
38
+ $element.remove();
70
39
  }
71
- );
72
- isSync = false;
40
+ }
41
+ checkNode($root.get(0), []);
73
42
  }
74
43
 
75
- export { parseSVG, parseSVGSync };
44
+ export { parseSVG };
package/package.json CHANGED
@@ -3,10 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "4.0.0-dev.1",
7
- "publishConfig": {
8
- "tag": "next"
9
- },
6
+ "version": "4.0.1",
10
7
  "license": "MIT",
11
8
  "bugs": "https://github.com/iconify/tools/issues",
12
9
  "homepage": "https://github.com/iconify/tools",
@@ -19,32 +16,31 @@
19
16
  "types": "./lib/index.d.ts",
20
17
  "dependencies": {
21
18
  "@iconify/types": "^2.0.0",
22
- "@iconify/utils": "^2.1.12",
23
- "@types/tar": "^6.1.10",
19
+ "@iconify/utils": "^2.1.22",
20
+ "@types/tar": "^6.1.11",
21
+ "axios": "^1.6.7",
24
22
  "cheerio": "1.0.0-rc.12",
25
23
  "extract-zip": "^2.0.1",
26
- "local-pkg": "^0.4.3",
27
- "pathe": "^1.1.1",
28
- "svgo": "^3.0.4",
24
+ "local-pkg": "^0.5.0",
25
+ "pathe": "^1.1.2",
26
+ "svgo": "^3.2.0",
29
27
  "tar": "^6.2.0"
30
28
  },
31
29
  "devDependencies": {
32
- "@types/jest": "^29.5.10",
33
- "@types/node": "^18.18.13",
34
- "@typescript-eslint/eslint-plugin": "^5.62.0",
35
- "@typescript-eslint/parser": "^5.62.0",
30
+ "@types/jest": "^29.5.12",
31
+ "@types/node": "^20.11.17",
32
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
33
+ "@typescript-eslint/parser": "^6.21.0",
36
34
  "cross-env": "^7.0.3",
37
- "eslint": "^8.54.0",
38
- "eslint-config-prettier": "^8.10.0",
39
- "eslint-plugin-jasmine": "^4.1.3",
40
- "eslint-plugin-prettier": "^4.2.1",
41
- "jasmine": "^5.1.0",
35
+ "eslint": "^8.56.0",
36
+ "eslint-config-prettier": "^9.1.0",
37
+ "eslint-plugin-prettier": "^5.1.3",
42
38
  "jest": "^29.7.0",
43
- "prettier": "^2.8.8",
39
+ "prettier": "^3.2.5",
44
40
  "rimraf": "^5.0.5",
45
- "ts-jest": "^29.1.1",
46
- "typescript": "^5.3.2",
47
- "unbuild": "^1.2.1"
41
+ "ts-jest": "^29.1.2",
42
+ "typescript": "^5.3.3",
43
+ "unbuild": "^2.0.0"
48
44
  },
49
45
  "exports": {
50
46
  "./*": "./*",
@@ -118,6 +114,11 @@
118
114
  "require": "./lib/download/api/cache.cjs",
119
115
  "import": "./lib/download/api/cache.mjs"
120
116
  },
117
+ "./lib/download/api/config": {
118
+ "types": "./lib/download/api/config.d.ts",
119
+ "require": "./lib/download/api/config.cjs",
120
+ "import": "./lib/download/api/config.mjs"
121
+ },
121
122
  "./lib/download/api/download": {
122
123
  "types": "./lib/download/api/download.d.ts",
123
124
  "require": "./lib/download/api/download.cjs",
@@ -133,6 +134,11 @@
133
134
  "require": "./lib/download/api/index.cjs",
134
135
  "import": "./lib/download/api/index.mjs"
135
136
  },
137
+ "./lib/download/api/queue": {
138
+ "types": "./lib/download/api/queue.d.ts",
139
+ "require": "./lib/download/api/queue.cjs",
140
+ "import": "./lib/download/api/queue.mjs"
141
+ },
136
142
  "./lib/download/api/types": {
137
143
  "types": "./lib/download/api/types.d.ts",
138
144
  "require": "./lib/download/api/types.cjs",
@@ -448,6 +454,11 @@
448
454
  "require": "./lib/optimise/svgo.cjs",
449
455
  "import": "./lib/optimise/svgo.mjs"
450
456
  },
457
+ "./lib/optimise/unwrap": {
458
+ "types": "./lib/optimise/unwrap.d.ts",
459
+ "require": "./lib/optimise/unwrap.cjs",
460
+ "import": "./lib/optimise/unwrap.mjs"
461
+ },
451
462
  "./lib/svg/analyse": {
452
463
  "types": "./lib/svg/analyse.d.ts",
453
464
  "require": "./lib/svg/analyse.cjs",
@@ -541,8 +552,7 @@
541
552
  "build": "unbuild",
542
553
  "test:jest-cjs": "jest --clearCache --config=jest.config.cjs && jest --runInBand --config=jest.config.cjs",
543
554
  "test:jest-esm": "cross-env NODE_OPTIONS=--experimental-vm-modules TEST_REMOTE=false jest --clearCache --config=jest.config.mjs && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --config=jest.config.mjs",
544
- "test:jasmine": "cross-env NODE_OPTIONS='--experimental-vm-modules --experimental-json-modules' npx jasmine",
545
- "test": "npm run test:jest-cjs && npm run test:jest-esm && npm run test:jasmine",
555
+ "test": "npm run test:jest-cjs && npm run test:jest-esm",
546
556
  "test:ci": "cross-env TEST_REMOTE=false npm run test"
547
557
  }
548
558
  }