@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,20 @@
1
+ import { DocumentNotModified } from '../../download/types/modified.cjs';
2
+ import { FigmaIfModifiedSinceOption, FigmaImportOptions } from './types/options.cjs';
3
+ import { FigmaImportResult } from './types/result.cjs';
4
+ import '../../icon-set/index.cjs';
5
+ import '@iconify/types';
6
+ import '@iconify/utils/lib/customisations/defaults';
7
+ import '../../icon-set/types.cjs';
8
+ import '../../svg/index.cjs';
9
+ import 'cheerio';
10
+ import '@iconify/utils/lib/icon-set/tree';
11
+ import './types/nodes.cjs';
12
+ import './types/api.cjs';
13
+
14
+ /**
15
+ * Import icon set from Figma
16
+ */
17
+ declare function importFromFigma<T extends FigmaIfModifiedSinceOption & FigmaImportOptions>(options: T): Promise<FigmaImportResult | DocumentNotModified>;
18
+ declare function importFromFigma(options: FigmaImportOptions): Promise<FigmaImportResult>;
19
+
20
+ export { importFromFigma };
@@ -0,0 +1,20 @@
1
+ import { DocumentNotModified } from '../../download/types/modified.mjs';
2
+ import { FigmaIfModifiedSinceOption, FigmaImportOptions } from './types/options.mjs';
3
+ import { FigmaImportResult } from './types/result.mjs';
4
+ import '../../icon-set/index.mjs';
5
+ import '@iconify/types';
6
+ import '@iconify/utils/lib/customisations/defaults';
7
+ import '../../icon-set/types.mjs';
8
+ import '../../svg/index.mjs';
9
+ import 'cheerio';
10
+ import '@iconify/utils/lib/icon-set/tree';
11
+ import './types/nodes.mjs';
12
+ import './types/api.mjs';
13
+
14
+ /**
15
+ * Import icon set from Figma
16
+ */
17
+ declare function importFromFigma<T extends FigmaIfModifiedSinceOption & FigmaImportOptions>(options: T): Promise<FigmaImportResult | DocumentNotModified>;
18
+ declare function importFromFigma(options: FigmaImportOptions): Promise<FigmaImportResult>;
19
+
20
+ export { importFromFigma };
@@ -32,10 +32,13 @@ import '../../optimise/svgo.mjs';
32
32
  import 'svgo';
33
33
  import '@iconify/utils/lib/svg/id';
34
34
  import '../../download/api/index.mjs';
35
+ import 'axios';
35
36
  import '../../download/api/cache.mjs';
36
37
  import 'fs';
37
38
  import 'crypto';
38
39
  import '../../misc/scan.mjs';
40
+ import '../../download/api/config.mjs';
41
+ import '../../download/api/queue.mjs';
39
42
 
40
43
  async function importFromFigma(options) {
41
44
  const cacheOptions = options.cacheDir ? {
@@ -64,7 +64,7 @@ function getFigmaIconNodes(document, options) {
64
64
  const newParents = parents.concat([parentItem]);
65
65
  if (!parents.length && options.pages) {
66
66
  const allowedPages = options.pages;
67
- if (allowedPages.indexOf(node.id) === -1 && allowedPages.indexOf(node.name.trim()) === -1) {
67
+ if (!allowedPages.includes(node.id) && !allowedPages.includes(node.name.trim())) {
68
68
  return;
69
69
  }
70
70
  } else {
@@ -0,0 +1,18 @@
1
+ import { FigmaDocument } from './types/api.cjs';
2
+ import { FigmaGetIconNodesOptions } from './types/options.cjs';
3
+ import { FigmaNodesImportResult } from './types/result.cjs';
4
+ import '../../icon-set/index.cjs';
5
+ import '@iconify/types';
6
+ import '@iconify/utils/lib/customisations/defaults';
7
+ import '../../icon-set/types.cjs';
8
+ import '../../svg/index.cjs';
9
+ import 'cheerio';
10
+ import '@iconify/utils/lib/icon-set/tree';
11
+ import './types/nodes.cjs';
12
+
13
+ /**
14
+ * Get node ids for icons
15
+ */
16
+ declare function getFigmaIconNodes(document: FigmaDocument, options: FigmaGetIconNodesOptions): FigmaNodesImportResult;
17
+
18
+ export { getFigmaIconNodes };
@@ -0,0 +1,18 @@
1
+ import { FigmaDocument } from './types/api.mjs';
2
+ import { FigmaGetIconNodesOptions } from './types/options.mjs';
3
+ import { FigmaNodesImportResult } from './types/result.mjs';
4
+ import '../../icon-set/index.mjs';
5
+ import '@iconify/types';
6
+ import '@iconify/utils/lib/customisations/defaults';
7
+ import '../../icon-set/types.mjs';
8
+ import '../../svg/index.mjs';
9
+ import 'cheerio';
10
+ import '@iconify/utils/lib/icon-set/tree';
11
+ import './types/nodes.mjs';
12
+
13
+ /**
14
+ * Get node ids for icons
15
+ */
16
+ declare function getFigmaIconNodes(document: FigmaDocument, options: FigmaGetIconNodesOptions): FigmaNodesImportResult;
17
+
18
+ export { getFigmaIconNodes };
@@ -62,7 +62,7 @@ function getFigmaIconNodes(document, options) {
62
62
  const newParents = parents.concat([parentItem]);
63
63
  if (!parents.length && options.pages) {
64
64
  const allowedPages = options.pages;
65
- if (allowedPages.indexOf(node.id) === -1 && allowedPages.indexOf(node.name.trim()) === -1) {
65
+ if (!allowedPages.includes(node.id) && !allowedPages.includes(node.name.trim())) {
66
66
  return;
67
67
  }
68
68
  } else {
@@ -2,6 +2,9 @@
2
2
 
3
3
  const download_api_index = require('../../download/api/index.cjs');
4
4
  const download_api_cache = require('../../download/api/cache.cjs');
5
+ const download_api_queue = require('../../download/api/queue.cjs');
6
+ require('axios');
7
+ require('../../download/api/config.cjs');
5
8
  require('fs');
6
9
  require('crypto');
7
10
  require('../../misc/scan.cjs');
@@ -113,78 +116,92 @@ async function figmaImagesQuery(options, nodes, cache) {
113
116
  const uri = "https://api.figma.com/v1/images/" + options.file;
114
117
  const maxLength = 2048 - uri.length;
115
118
  const svgOptions = options.svgOptions || {};
116
- let ids = [];
117
- let idsLength = 0;
118
- let lastError;
119
- let found = 0;
120
- const query = async () => {
121
- const params = new URLSearchParams({
122
- ids: ids.join(","),
123
- format: "svg"
124
- });
125
- if (options.version) {
126
- params.set("version", options.version);
127
- }
128
- if (svgOptions.includeID) {
129
- params.set("svg_include_id", "true");
130
- }
131
- if (svgOptions.simplifyStroke) {
132
- params.set("svg_simplify_stroke", "true");
133
- }
134
- if (svgOptions.useAbsoluteBounds) {
135
- params.set("use_absolute_bounds", "true");
136
- }
137
- const data = await download_api_index.sendAPIQuery(
138
- {
139
- uri,
140
- params,
141
- headers: {
142
- "X-FIGMA-TOKEN": options.token
119
+ const query = (ids2) => {
120
+ return new Promise((resolve, reject) => {
121
+ const params = new URLSearchParams({
122
+ ids: ids2.join(","),
123
+ format: "svg"
124
+ });
125
+ if (options.version) {
126
+ params.set("version", options.version);
127
+ }
128
+ if (svgOptions.includeID) {
129
+ params.set("svg_include_id", "true");
130
+ }
131
+ if (svgOptions.simplifyStroke) {
132
+ params.set("svg_simplify_stroke", "true");
133
+ }
134
+ if (svgOptions.useAbsoluteBounds) {
135
+ params.set("use_absolute_bounds", "true");
136
+ }
137
+ download_api_index.sendAPIQuery(
138
+ {
139
+ uri,
140
+ params,
141
+ headers: {
142
+ "X-FIGMA-TOKEN": options.token
143
+ }
144
+ },
145
+ cache
146
+ ).then((data) => {
147
+ if (typeof data === "number") {
148
+ reject(data);
149
+ return;
143
150
  }
144
- },
145
- cache
146
- );
147
- if (typeof data === "number") {
148
- lastError = data;
149
- return;
150
- }
151
- try {
152
- const parsedData = JSON.parse(data);
153
- const images = parsedData.images;
154
- for (const id in images) {
155
- const node = nodes.icons[id];
156
- const target = images[id];
157
- if (node && target) {
158
- node.url = target;
159
- found++;
151
+ let parsedData;
152
+ try {
153
+ parsedData = JSON.parse(data);
154
+ } catch {
155
+ reject("Bad API response");
156
+ return;
160
157
  }
161
- }
162
- } catch (err) {
163
- return;
164
- }
158
+ resolve(parsedData);
159
+ }).catch(reject);
160
+ });
165
161
  };
162
+ let ids = [];
163
+ let idsLength = 0;
166
164
  const allKeys = Object.keys(nodes.icons);
165
+ const queue = [];
167
166
  for (let i = 0; i < allKeys.length; i++) {
168
167
  const id = allKeys[i];
169
168
  ids.push(id);
170
169
  idsLength += id.length + 1;
171
170
  if (idsLength >= maxLength) {
172
- await query();
171
+ queue.push(ids.slice(0));
173
172
  ids = [];
174
173
  idsLength = 0;
175
174
  }
176
175
  }
177
176
  if (idsLength) {
178
- await query();
177
+ queue.push(ids.slice(0));
179
178
  }
180
- if (!found) {
181
- if (lastError) {
182
- throw new Error(
183
- `Error retrieving image data from API${lastError ? ": " + lastError.toString() : ""}`
184
- );
185
- } else {
186
- throw new Error("No valid icon layers were found");
179
+ const queryParams = {
180
+ // Params
181
+ total: queue.length,
182
+ callback: (index) => query(queue[index]),
183
+ // Payload to identify failed items in onfail callback
184
+ function: "figmaImagesQuery",
185
+ payload: queue
186
+ };
187
+ const results = await download_api_queue.runConcurrentQueries(queryParams);
188
+ let found = 0;
189
+ results.forEach((data) => {
190
+ if (!data) {
191
+ return;
187
192
  }
193
+ const images = data.images;
194
+ for (const id in images) {
195
+ const node = nodes.icons[id];
196
+ const target = images[id];
197
+ if (node && target) {
198
+ node.url = target;
199
+ found++;
200
+ }
201
+ }
202
+ });
203
+ if (!found) {
204
+ throw new Error("No valid icon layers were found");
188
205
  }
189
206
  nodes.generatedIconsCount = found;
190
207
  return nodes;
@@ -193,32 +210,43 @@ async function figmaDownloadImages(nodes, cache) {
193
210
  const icons = nodes.icons;
194
211
  const ids = Object.keys(icons);
195
212
  let count = 0;
196
- let lastError;
213
+ const filtered = [];
197
214
  for (let i = 0; i < ids.length; i++) {
198
215
  const id = ids[i];
199
216
  const item = icons[id];
200
- if (!item.url) {
201
- continue;
202
- }
203
- const result = await download_api_index.sendAPIQuery(
204
- {
205
- uri: item.url
206
- },
207
- cache
208
- );
209
- if (typeof result === "number") {
210
- lastError = result;
211
- continue;
212
- }
213
- if (typeof result === "string") {
214
- count++;
215
- item.content = result;
217
+ if (item.url) {
218
+ filtered.push(item);
216
219
  }
217
220
  }
221
+ const params = {
222
+ // Params
223
+ total: filtered.length,
224
+ callback: (index) => {
225
+ return new Promise((resolve, reject) => {
226
+ const item = filtered[index];
227
+ download_api_index.sendAPIQuery(
228
+ {
229
+ uri: item.url
230
+ },
231
+ cache
232
+ ).then((data) => {
233
+ if (typeof data === "string") {
234
+ count++;
235
+ item.content = data;
236
+ resolve(void 0);
237
+ } else {
238
+ reject(data);
239
+ }
240
+ }).catch(reject);
241
+ });
242
+ },
243
+ // Payload to identify failed items in onfail callback
244
+ function: "figmaDownloadImages",
245
+ payload: filtered
246
+ };
247
+ await download_api_queue.runConcurrentQueries(params);
218
248
  if (!count) {
219
- throw new Error(
220
- `Error retrieving images${lastError ? ": " + lastError.toString() : ""}`
221
- );
249
+ throw new Error("Error retrieving images");
222
250
  }
223
251
  nodes.downloadedIconsCount = count;
224
252
  return nodes;
@@ -0,0 +1,42 @@
1
+ import { APICacheOptions } from '../../download/api/types.cjs';
2
+ import { DocumentNotModified } from '../../download/types/modified.cjs';
3
+ import { FigmaDocument } from './types/api.cjs';
4
+ import { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options.cjs';
5
+ import { FigmaNodesImportResult, FigmaIconNode } from './types/result.cjs';
6
+ import '../../icon-set/index.cjs';
7
+ import '@iconify/types';
8
+ import '@iconify/utils/lib/customisations/defaults';
9
+ import '../../icon-set/types.cjs';
10
+ import '../../svg/index.cjs';
11
+ import 'cheerio';
12
+ import '@iconify/utils/lib/icon-set/tree';
13
+ import './types/nodes.cjs';
14
+
15
+ /**
16
+ * Extra parameters added to runConcurrentQueries()
17
+ *
18
+ * Can be used to identify failed items in onfail callback
19
+ */
20
+ interface FigmaIconNodeWithURL extends FigmaIconNode {
21
+ url: string;
22
+ }
23
+ type FigmaConcurrentQueriesParamsFunction = 'figmaImagesQuery' | 'figmaDownloadImages';
24
+ interface FigmaConcurrentQueriesParams<T extends FigmaConcurrentQueriesParamsFunction> {
25
+ function: T;
26
+ payload: T extends 'figmaImagesQuery' ? string[][] : FigmaIconNodeWithURL[];
27
+ }
28
+ /**
29
+ * Get Figma files
30
+ */
31
+ declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
32
+ declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
33
+ /**
34
+ * Generate all images
35
+ */
36
+ declare function figmaImagesQuery(options: FigmaImagesQueryOptions, nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
37
+ /**
38
+ * Download all images
39
+ */
40
+ declare function figmaDownloadImages(nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
41
+
42
+ export { type FigmaConcurrentQueriesParams, type FigmaConcurrentQueriesParamsFunction, figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };
@@ -0,0 +1,42 @@
1
+ import { APICacheOptions } from '../../download/api/types.mjs';
2
+ import { DocumentNotModified } from '../../download/types/modified.mjs';
3
+ import { FigmaDocument } from './types/api.mjs';
4
+ import { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options.mjs';
5
+ import { FigmaNodesImportResult, FigmaIconNode } from './types/result.mjs';
6
+ import '../../icon-set/index.mjs';
7
+ import '@iconify/types';
8
+ import '@iconify/utils/lib/customisations/defaults';
9
+ import '../../icon-set/types.mjs';
10
+ import '../../svg/index.mjs';
11
+ import 'cheerio';
12
+ import '@iconify/utils/lib/icon-set/tree';
13
+ import './types/nodes.mjs';
14
+
15
+ /**
16
+ * Extra parameters added to runConcurrentQueries()
17
+ *
18
+ * Can be used to identify failed items in onfail callback
19
+ */
20
+ interface FigmaIconNodeWithURL extends FigmaIconNode {
21
+ url: string;
22
+ }
23
+ type FigmaConcurrentQueriesParamsFunction = 'figmaImagesQuery' | 'figmaDownloadImages';
24
+ interface FigmaConcurrentQueriesParams<T extends FigmaConcurrentQueriesParamsFunction> {
25
+ function: T;
26
+ payload: T extends 'figmaImagesQuery' ? string[][] : FigmaIconNodeWithURL[];
27
+ }
28
+ /**
29
+ * Get Figma files
30
+ */
31
+ declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
32
+ declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
33
+ /**
34
+ * Generate all images
35
+ */
36
+ declare function figmaImagesQuery(options: FigmaImagesQueryOptions, nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
37
+ /**
38
+ * Download all images
39
+ */
40
+ declare function figmaDownloadImages(nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
41
+
42
+ export { type FigmaConcurrentQueriesParams, type FigmaConcurrentQueriesParamsFunction, figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };
@@ -2,7 +2,7 @@ import { APICacheOptions } from '../../download/api/types.js';
2
2
  import { DocumentNotModified } from '../../download/types/modified.js';
3
3
  import { FigmaDocument } from './types/api.js';
4
4
  import { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options.js';
5
- import { FigmaNodesImportResult } from './types/result.js';
5
+ import { FigmaNodesImportResult, FigmaIconNode } from './types/result.js';
6
6
  import '../../icon-set/index.js';
7
7
  import '@iconify/types';
8
8
  import '@iconify/utils/lib/customisations/defaults';
@@ -12,6 +12,19 @@ import 'cheerio';
12
12
  import '@iconify/utils/lib/icon-set/tree';
13
13
  import './types/nodes.js';
14
14
 
15
+ /**
16
+ * Extra parameters added to runConcurrentQueries()
17
+ *
18
+ * Can be used to identify failed items in onfail callback
19
+ */
20
+ interface FigmaIconNodeWithURL extends FigmaIconNode {
21
+ url: string;
22
+ }
23
+ type FigmaConcurrentQueriesParamsFunction = 'figmaImagesQuery' | 'figmaDownloadImages';
24
+ interface FigmaConcurrentQueriesParams<T extends FigmaConcurrentQueriesParamsFunction> {
25
+ function: T;
26
+ payload: T extends 'figmaImagesQuery' ? string[][] : FigmaIconNodeWithURL[];
27
+ }
15
28
  /**
16
29
  * Get Figma files
17
30
  */
@@ -26,4 +39,4 @@ declare function figmaImagesQuery(options: FigmaImagesQueryOptions, nodes: Figma
26
39
  */
27
40
  declare function figmaDownloadImages(nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
28
41
 
29
- export { figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };
42
+ export { type FigmaConcurrentQueriesParams, type FigmaConcurrentQueriesParamsFunction, figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };