@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
@@ -0,0 +1,218 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const download_api_index = require('../../download/api/index.cjs');
6
+ const download_api_cache = require('../../download/api/cache.cjs');
7
+ require('node-fetch');
8
+ require('fs');
9
+ require('crypto');
10
+ require('../../misc/scan.cjs');
11
+
12
+ function identicalDates(actual, expected) {
13
+ if (typeof actual !== "string") {
14
+ return false;
15
+ }
16
+ if (actual === expected) {
17
+ return true;
18
+ }
19
+ return new Date(actual).toString() === new Date(expected).toString();
20
+ }
21
+ async function figmaFilesQuery(options, cache) {
22
+ if (!options.token) {
23
+ throw new Error("Missing Figma API token");
24
+ }
25
+ const params = new URLSearchParams();
26
+ if (options.ids) {
27
+ params.set("ids", options.ids.join(","));
28
+ }
29
+ if (options.version) {
30
+ params.set("version", options.version);
31
+ }
32
+ if (options.depth) {
33
+ params.set("depth", options.depth + "");
34
+ }
35
+ const queryParams = {
36
+ uri: "https://api.figma.com/v1/files/" + options.file,
37
+ params,
38
+ headers: {
39
+ "X-FIGMA-TOKEN": options.token
40
+ }
41
+ };
42
+ const isModified = async () => {
43
+ if (!cache || !options.ifModifiedSince) {
44
+ return true;
45
+ }
46
+ const cacheKey = download_api_cache.apiCacheKey(queryParams);
47
+ const cachedData = await download_api_cache.getAPICache(cache.dir, cacheKey);
48
+ if (!cachedData) {
49
+ return true;
50
+ }
51
+ let ifModifiedSince;
52
+ if (options.ifModifiedSince === true) {
53
+ try {
54
+ const parsedData2 = JSON.parse(cachedData);
55
+ if (typeof parsedData2.lastModified !== "string") {
56
+ await download_api_cache.clearAPICache(cache.dir);
57
+ return true;
58
+ }
59
+ ifModifiedSince = parsedData2.lastModified;
60
+ } catch (err) {
61
+ await download_api_cache.clearAPICache(cache.dir);
62
+ return true;
63
+ }
64
+ } else {
65
+ ifModifiedSince = options.ifModifiedSince;
66
+ }
67
+ const versionCheckParams = {
68
+ ...queryParams,
69
+ params: new URLSearchParams(params)
70
+ };
71
+ versionCheckParams.params.set("depth", "1");
72
+ const data2 = await download_api_index.sendAPIQuery(versionCheckParams);
73
+ try {
74
+ if (typeof data2 === "string") {
75
+ const parsedData2 = JSON.parse(data2);
76
+ if (identicalDates(parsedData2.lastModified, ifModifiedSince)) {
77
+ return false;
78
+ }
79
+ }
80
+ } catch (err) {
81
+ }
82
+ await download_api_cache.clearAPICache(cache.dir);
83
+ return true;
84
+ };
85
+ if (!await isModified()) {
86
+ return "not_modified";
87
+ }
88
+ const data = await download_api_index.sendAPIQuery(queryParams, cache);
89
+ if (typeof data === "number") {
90
+ throw new Error(`Error retrieving document from API: ${data}`);
91
+ }
92
+ let parsedData;
93
+ try {
94
+ parsedData = JSON.parse(data);
95
+ } catch (err) {
96
+ throw new Error(`Error retrieving document from API: invalid data`);
97
+ }
98
+ if (typeof parsedData.status === "number") {
99
+ const figmaError = parsedData;
100
+ throw new Error(`Error retrieving document from API: ${figmaError.err}`);
101
+ }
102
+ const document = parsedData;
103
+ if (document.editorType !== "figma") {
104
+ throw new Error(`Error retrieving document from API: document is for ${document.editorType}`);
105
+ }
106
+ if (identicalDates(options.ifModifiedSince, document.lastModified)) {
107
+ return "not_modified";
108
+ }
109
+ return document;
110
+ }
111
+ async function figmaImagesQuery(options, nodes, cache) {
112
+ const uri = "https://api.figma.com/v1/images/" + options.file;
113
+ const maxLength = 2048 - uri.length;
114
+ const svgOptions = options.svgOptions || {};
115
+ let ids = [];
116
+ let idsLength = 0;
117
+ let lastError;
118
+ let found = 0;
119
+ const query = async () => {
120
+ const params = new URLSearchParams({
121
+ ids: ids.join(","),
122
+ format: "svg"
123
+ });
124
+ if (options.version) {
125
+ params.set("version", options.version);
126
+ }
127
+ if (svgOptions.includeID) {
128
+ params.set("svg_include_id", "true");
129
+ }
130
+ if (svgOptions.simplifyStroke) {
131
+ params.set("svg_simplify_stroke", "true");
132
+ }
133
+ if (svgOptions.useAbsoluteBounds) {
134
+ params.set("use_absolute_bounds", "true");
135
+ }
136
+ const data = await download_api_index.sendAPIQuery({
137
+ uri,
138
+ params,
139
+ headers: {
140
+ "X-FIGMA-TOKEN": options.token
141
+ }
142
+ }, cache);
143
+ if (typeof data === "number") {
144
+ lastError = data;
145
+ return;
146
+ }
147
+ try {
148
+ const parsedData = JSON.parse(data);
149
+ const images = parsedData.images;
150
+ for (const id in images) {
151
+ const node = nodes.icons[id];
152
+ const target = images[id];
153
+ if (node && target) {
154
+ node.url = target;
155
+ found++;
156
+ }
157
+ }
158
+ } catch (err) {
159
+ return;
160
+ }
161
+ };
162
+ const allKeys = Object.keys(nodes.icons);
163
+ for (let i = 0; i < allKeys.length; i++) {
164
+ const id = allKeys[i];
165
+ ids.push(id);
166
+ idsLength += id.length + 1;
167
+ if (idsLength >= maxLength) {
168
+ await query();
169
+ ids = [];
170
+ idsLength = 0;
171
+ }
172
+ }
173
+ if (idsLength) {
174
+ await query();
175
+ }
176
+ if (!found) {
177
+ if (lastError) {
178
+ throw new Error(`Error retrieving image data from API${lastError ? ": " + lastError : ""}`);
179
+ } else {
180
+ throw new Error("No valid icon layers were found");
181
+ }
182
+ }
183
+ nodes.generatedIconsCount = found;
184
+ return nodes;
185
+ }
186
+ async function figmaDownloadImages(nodes, cache) {
187
+ const icons = nodes.icons;
188
+ const ids = Object.keys(icons);
189
+ let count = 0;
190
+ let lastError;
191
+ for (let i = 0; i < ids.length; i++) {
192
+ const id = ids[i];
193
+ const item = icons[id];
194
+ if (!item.url) {
195
+ continue;
196
+ }
197
+ const result = await download_api_index.sendAPIQuery({
198
+ uri: item.url
199
+ }, cache);
200
+ if (typeof result === "number") {
201
+ lastError = result;
202
+ continue;
203
+ }
204
+ if (typeof result === "string") {
205
+ count++;
206
+ item.content = result;
207
+ }
208
+ }
209
+ if (!count) {
210
+ throw new Error(`Error retrieving images${lastError ? ": " + lastError : ""}`);
211
+ }
212
+ nodes.downloadedIconsCount = count;
213
+ return nodes;
214
+ }
215
+
216
+ exports.figmaDownloadImages = figmaDownloadImages;
217
+ exports.figmaFilesQuery = figmaFilesQuery;
218
+ exports.figmaImagesQuery = figmaImagesQuery;
@@ -1,18 +1,27 @@
1
- import type { APICacheOptions } from '../../download/api/types';
2
- import type { DocumentNotModified } from '../../download/types/modified';
3
- import type { FigmaDocument } from './types/api';
4
- import type { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options';
5
- import type { FigmaNodesImportResult } from './types/result';
1
+ import { APICacheOptions } from '../../download/api/types.js';
2
+ import { DocumentNotModified } from '../../download/types/modified.js';
3
+ import { FigmaDocument } from './types/api.js';
4
+ import { FigmaIfModifiedSinceOption, FigmaFilesQueryOptions, FigmaImagesQueryOptions } from './types/options.js';
5
+ import { FigmaNodesImportResult } from './types/result.js';
6
+ import '../../icon-set/index.js';
7
+ import '@iconify/types';
8
+ import '@iconify/utils/lib/customisations';
9
+ import '../../icon-set/types.js';
10
+ import '../../svg/index.js';
11
+ import './types/nodes.js';
12
+
6
13
  /**
7
14
  * Get Figma files
8
15
  */
9
- export declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
10
- export declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
16
+ declare function figmaFilesQuery<T extends FigmaIfModifiedSinceOption & FigmaFilesQueryOptions>(options: T, cache?: APICacheOptions): Promise<FigmaDocument | DocumentNotModified>;
17
+ declare function figmaFilesQuery(options: FigmaFilesQueryOptions, cache?: APICacheOptions): Promise<FigmaDocument>;
11
18
  /**
12
19
  * Generate all images
13
20
  */
14
- export declare function figmaImagesQuery(options: FigmaImagesQueryOptions, nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
21
+ declare function figmaImagesQuery(options: FigmaImagesQueryOptions, nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
15
22
  /**
16
23
  * Download all images
17
24
  */
18
- export declare function figmaDownloadImages(nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
25
+ declare function figmaDownloadImages(nodes: FigmaNodesImportResult, cache?: APICacheOptions): Promise<FigmaNodesImportResult>;
26
+
27
+ export { figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };
@@ -1,10 +1,10 @@
1
- // src/import/figma/query.ts
2
- import { sendAPIQuery } from "../../download/api/index.mjs";
3
- import {
4
- apiCacheKey,
5
- clearAPICache,
6
- getAPICache
7
- } from "../../download/api/cache.mjs";
1
+ import { sendAPIQuery } from '../../download/api/index.mjs';
2
+ import { apiCacheKey, getAPICache, clearAPICache } from '../../download/api/cache.mjs';
3
+ import 'node-fetch';
4
+ import 'fs';
5
+ import 'crypto';
6
+ import '../../misc/scan.mjs';
7
+
8
8
  function identicalDates(actual, expected) {
9
9
  if (typeof actual !== "string") {
10
10
  return false;
@@ -208,8 +208,5 @@ async function figmaDownloadImages(nodes, cache) {
208
208
  nodes.downloadedIconsCount = count;
209
209
  return nodes;
210
210
  }
211
- export {
212
- figmaDownloadImages,
213
- figmaFilesQuery,
214
- figmaImagesQuery
215
- };
211
+
212
+ export { figmaDownloadImages, figmaFilesQuery, figmaImagesQuery };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -15,21 +15,21 @@ interface GenericFigmaNode extends BaseFigmaNode {
15
15
  type: string;
16
16
  children?: FigmaNode[];
17
17
  }
18
- export interface IconFigmaNode extends BaseFigmaNode {
18
+ interface IconFigmaNode extends BaseFigmaNode {
19
19
  type: 'FRAME' | 'COMPONENT' | 'INSTANCE';
20
20
  clipsContent?: boolean;
21
21
  absoluteBoundingBox?: FigmaBoundingBox;
22
22
  children: FigmaNode[];
23
23
  }
24
- export interface FigmaDocumentNode extends BaseFigmaNode {
24
+ interface FigmaDocumentNode extends BaseFigmaNode {
25
25
  type: 'DOCUMENT';
26
26
  children: FigmaNode[];
27
27
  }
28
- export declare type FigmaNode = GenericFigmaNode | IconFigmaNode;
28
+ declare type FigmaNode = GenericFigmaNode | IconFigmaNode;
29
29
  /**
30
30
  * Document response from API
31
31
  */
32
- export interface FigmaDocument {
32
+ interface FigmaDocument {
33
33
  document: FigmaDocumentNode;
34
34
  name: string;
35
35
  version: string;
@@ -38,15 +38,16 @@ export interface FigmaDocument {
38
38
  role: string;
39
39
  editorType: 'figma' | 'figjam';
40
40
  }
41
- export interface FigmaAPIError {
41
+ interface FigmaAPIError {
42
42
  status: number;
43
43
  err: string;
44
44
  }
45
45
  /**
46
46
  * Result for retrieved icons
47
47
  */
48
- export interface FigmaAPIImagesResponse {
48
+ interface FigmaAPIImagesResponse {
49
49
  err?: string | null;
50
50
  images: Record<string, string | null>;
51
51
  }
52
- export {};
52
+
53
+ export { FigmaAPIError, FigmaAPIImagesResponse, FigmaDocument, FigmaDocumentNode, FigmaNode, IconFigmaNode };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,16 +1,22 @@
1
- import type { FigmaDocument, IconFigmaNode } from './api';
2
- import type { FigmaIconNode, FigmaNodesImportResult } from './result';
3
- export declare type FigmaImportParentNodeType = 'CANVAS' | 'FRAME' | 'GROUP';
4
- export declare type FigmaImportIconNodeType = IconFigmaNode['type'];
1
+ import { IconFigmaNode, FigmaDocument } from './api.js';
2
+ import { FigmaNodesImportResult, FigmaIconNode } from './result.js';
3
+ import '../../../icon-set/index.js';
4
+ import '@iconify/types';
5
+ import '@iconify/utils/lib/customisations';
6
+ import '../../../icon-set/types.js';
7
+ import '../../../svg/index.js';
8
+
9
+ declare type FigmaImportParentNodeType = 'CANVAS' | 'FRAME' | 'GROUP';
10
+ declare type FigmaImportIconNodeType = IconFigmaNode['type'];
5
11
  /**
6
12
  * Node information passed to callback
7
13
  */
8
- export interface FigmaParentNodeData {
14
+ interface FigmaParentNodeData {
9
15
  id: string;
10
16
  type: FigmaImportParentNodeType;
11
17
  name: string;
12
18
  }
13
- export interface FigmaImportNodeData {
19
+ interface FigmaImportNodeData {
14
20
  id: string;
15
21
  type: FigmaImportIconNodeType;
16
22
  name: string;
@@ -23,7 +29,7 @@ export interface FigmaImportNodeData {
23
29
  *
24
30
  * Used to speed up processing by eleminating pages, frames and groups that do not need processing
25
31
  */
26
- export declare type FigmaImportParentNodeFilter = (node: FigmaParentNodeData[], document: FigmaDocument) => boolean;
32
+ declare type FigmaImportParentNodeFilter = (node: FigmaParentNodeData[], document: FigmaDocument) => boolean;
27
33
  /**
28
34
  * Check if node is an icon.
29
35
  *
@@ -31,5 +37,6 @@ export declare type FigmaImportParentNodeFilter = (node: FigmaParentNodeData[],
31
37
  * Function can also return FigmaIconNode object, where it can put extra properties that can be used later
32
38
  */
33
39
  declare type FigmaIconNodeWithKeyword = Partial<FigmaIconNode> & Pick<FigmaIconNode, 'keyword'>;
34
- export declare type FigmaImportNodeFilter = (node: FigmaImportNodeData, nodes: FigmaNodesImportResult, document: FigmaDocument) => string | FigmaIconNodeWithKeyword | null | undefined;
35
- export {};
40
+ declare type FigmaImportNodeFilter = (node: FigmaImportNodeData, nodes: FigmaNodesImportResult, document: FigmaDocument) => string | FigmaIconNodeWithKeyword | null | undefined;
41
+
42
+ export { FigmaImportIconNodeType, FigmaImportNodeData, FigmaImportNodeFilter, FigmaImportParentNodeFilter, FigmaImportParentNodeType, FigmaParentNodeData };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,10 +1,16 @@
1
- import type { IconSet } from '../../../icon-set';
2
- import type { FigmaImportNodeFilter, FigmaImportParentNodeFilter } from './nodes';
3
- import type { FigmaIconNode } from './result';
1
+ import { IconSet } from '../../../icon-set/index.js';
2
+ import { FigmaImportParentNodeFilter, FigmaImportNodeFilter } from './nodes.js';
3
+ import { FigmaIconNode } from './result.js';
4
+ import '@iconify/types';
5
+ import '@iconify/utils/lib/customisations';
6
+ import '../../../icon-set/types.js';
7
+ import '../../../svg/index.js';
8
+ import './api.js';
9
+
4
10
  /**
5
11
  * Options for importing SVG
6
12
  */
7
- export interface FigmaImportSVGOptions {
13
+ interface FigmaImportSVGOptions {
8
14
  includeID?: boolean;
9
15
  simplifyStroke?: boolean;
10
16
  useAbsoluteBounds?: boolean;
@@ -17,17 +23,17 @@ interface FigmaImportCommonOptions {
17
23
  file: string;
18
24
  version?: string;
19
25
  }
20
- export interface FigmaIfModifiedSinceOption {
26
+ interface FigmaIfModifiedSinceOption {
21
27
  ifModifiedSince: string | Date | true;
22
28
  }
23
- export interface FigmaFilesQueryOptions extends FigmaImportCommonOptions, Partial<FigmaIfModifiedSinceOption> {
29
+ interface FigmaFilesQueryOptions extends FigmaImportCommonOptions, Partial<FigmaIfModifiedSinceOption> {
24
30
  ids?: string[];
25
31
  depth?: number;
26
32
  }
27
- export interface FigmaImagesQueryOptions extends FigmaImportCommonOptions {
33
+ interface FigmaImagesQueryOptions extends FigmaImportCommonOptions {
28
34
  svgOptions?: FigmaImportSVGOptions;
29
35
  }
30
- export interface FigmaGetIconNodesOptions {
36
+ interface FigmaGetIconNodesOptions {
31
37
  pages?: string[];
32
38
  filterParentNode?: FigmaImportParentNodeFilter;
33
39
  iconNameForNode: FigmaImportNodeFilter;
@@ -39,7 +45,7 @@ declare type FigmaImportedIconCallback = (node: FigmaIconNode, iconSet: IconSet)
39
45
  /**
40
46
  * Options for main import function
41
47
  */
42
- export interface FigmaImportOptions extends FigmaFilesQueryOptions, FigmaImagesQueryOptions, FigmaGetIconNodesOptions {
48
+ interface FigmaImportOptions extends FigmaFilesQueryOptions, FigmaImagesQueryOptions, FigmaGetIconNodesOptions {
43
49
  prefix: string;
44
50
  cacheDir?: string;
45
51
  cacheAPITTL?: number;
@@ -47,4 +53,5 @@ export interface FigmaImportOptions extends FigmaFilesQueryOptions, FigmaImagesQ
47
53
  beforeImportingIcon?: FigmaImportedIconCallback;
48
54
  afterImportingIcon?: FigmaImportedIconCallback;
49
55
  }
50
- export {};
56
+
57
+ export { FigmaFilesQueryOptions, FigmaGetIconNodesOptions, FigmaIfModifiedSinceOption, FigmaImagesQueryOptions, FigmaImportOptions, FigmaImportSVGOptions };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,8 +1,13 @@
1
- import type { IconSet } from '../../../icon-set';
1
+ import { IconSet } from '../../../icon-set/index.js';
2
+ import '@iconify/types';
3
+ import '@iconify/utils/lib/customisations';
4
+ import '../../../icon-set/types.js';
5
+ import '../../../svg/index.js';
6
+
2
7
  /**
3
8
  * Result for found icons
4
9
  */
5
- export interface FigmaIconNode {
10
+ interface FigmaIconNode {
6
11
  id: string;
7
12
  name: string;
8
13
  keyword: string;
@@ -12,7 +17,7 @@ export interface FigmaIconNode {
12
17
  /**
13
18
  * Nodes count
14
19
  */
15
- export interface FigmaNodesCount {
20
+ interface FigmaNodesCount {
16
21
  nodesCount: number;
17
22
  generatedIconsCount: number;
18
23
  downloadedIconsCount: number;
@@ -20,16 +25,18 @@ export interface FigmaNodesCount {
20
25
  /**
21
26
  * Import result for icons
22
27
  */
23
- export interface FigmaNodesImportResult extends Partial<FigmaNodesCount> {
28
+ interface FigmaNodesImportResult extends Partial<FigmaNodesCount> {
24
29
  icons: Record<string, FigmaIconNode>;
25
30
  }
26
31
  /**
27
32
  * Import result
28
33
  */
29
- export interface FigmaImportResult extends FigmaNodesCount {
34
+ interface FigmaImportResult extends FigmaNodesCount {
30
35
  name: string;
31
36
  version: string;
32
37
  lastModified: string;
33
38
  iconSet: IconSet;
34
39
  missing: FigmaIconNode[];
35
40
  }
41
+
42
+ export { FigmaIconNode, FigmaImportResult, FigmaNodesCount, FigmaNodesImportResult };
@@ -0,0 +1 @@
1
+
package/lib/index.cjs ADDED
@@ -0,0 +1,137 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const svg_index = require('./svg/index.cjs');
6
+ const svg_parse = require('./svg/parse.cjs');
7
+ const svg_parseStyle = require('./svg/parse-style.cjs');
8
+ const svg_analyse = require('./svg/analyse.cjs');
9
+ const svg_cleanup = require('./svg/cleanup.cjs');
10
+ const svg_cleanup_attribs = require('./svg/cleanup/attribs.cjs');
11
+ const svg_cleanup_badTags = require('./svg/cleanup/bad-tags.cjs');
12
+ const svg_cleanup_inlineStyle = require('./svg/cleanup/inline-style.cjs');
13
+ const svg_cleanup_rootSvg = require('./svg/cleanup/root-svg.cjs');
14
+ const svg_cleanup_svgoStyle = require('./svg/cleanup/svgo-style.cjs');
15
+ const iconSet_index = require('./icon-set/index.cjs');
16
+ const iconSet_merge = require('./icon-set/merge.cjs');
17
+ const import_figma_index = require('./import/figma/index.cjs');
18
+ const import_directory = require('./import/directory.cjs');
19
+ const download_git_index = require('./download/git/index.cjs');
20
+ const download_git_hash = require('./download/git/hash.cjs');
21
+ const download_git_branch = require('./download/git/branch.cjs');
22
+ const download_git_reset = require('./download/git/reset.cjs');
23
+ const download_github_index = require('./download/github/index.cjs');
24
+ const download_github_hash = require('./download/github/hash.cjs');
25
+ const download_gitlab_index = require('./download/gitlab/index.cjs');
26
+ const download_gitlab_hash = require('./download/gitlab/hash.cjs');
27
+ const download_npm_index = require('./download/npm/index.cjs');
28
+ const download_npm_version = require('./download/npm/version.cjs');
29
+ const download_index = require('./download/index.cjs');
30
+ const colors_parse = require('./colors/parse.cjs');
31
+ const colors_validate = require('./colors/validate.cjs');
32
+ const optimise_svgo = require('./optimise/svgo.cjs');
33
+ const optimise_flags = require('./optimise/flags.cjs');
34
+ const optimise_scale = require('./optimise/scale.cjs');
35
+ const optimise_globalStyle = require('./optimise/global-style.cjs');
36
+ const export_directory = require('./export/directory.cjs');
37
+ const export_iconPackage = require('./export/icon-package.cjs');
38
+ const export_jsonPackage = require('./export/json-package.cjs');
39
+ const misc_writeJson = require('./misc/write-json.cjs');
40
+ const export_helpers_prepare = require('./export/helpers/prepare.cjs');
41
+ const misc_scan = require('./misc/scan.cjs');
42
+ const misc_compareDirs = require('./misc/compare-dirs.cjs');
43
+ const download_helpers_unzip = require('./download/helpers/unzip.cjs');
44
+ const download_helpers_untar = require('./download/helpers/untar.cjs');
45
+ const misc_exec = require('./misc/exec.cjs');
46
+ const misc_keyword = require('./misc/keyword.cjs');
47
+ const misc_bumpVersion = require('./misc/bump-version.cjs');
48
+ const download_api_index = require('./download/api/index.cjs');
49
+ require('cheerio');
50
+ require('@iconify/utils');
51
+ require('@iconify/utils/lib/icon');
52
+ require('./css/parse.cjs');
53
+ require('./css/parser/tokens.cjs');
54
+ require('./css/parser/error.cjs');
55
+ require('./css/parser/strings.cjs');
56
+ require('./css/parser/text.cjs');
57
+ require('./css/parser/export.cjs');
58
+ require('./css/parser/tree.cjs');
59
+ require('./svg/data/attributes.cjs');
60
+ require('./svg/data/tags.cjs');
61
+ require('./svg/analyse/error.cjs');
62
+ require('svgo');
63
+ require('@iconify/utils/lib/svg/build');
64
+ require('@iconify/utils/lib/customisations');
65
+ require('@iconify/utils/lib/icon-set/minify');
66
+ require('@iconify/utils/lib/icon-set/convert-info');
67
+ require('./icon-set/props.cjs');
68
+ require('./icon-set/match.cjs');
69
+ require('./import/figma/nodes.cjs');
70
+ require('./import/figma/query.cjs');
71
+ require('./download/api/cache.cjs');
72
+ require('fs');
73
+ require('crypto');
74
+ require('node-fetch');
75
+ require('pathe');
76
+ require('child_process');
77
+ require('./download/api/download.cjs');
78
+ require('util');
79
+ require('stream');
80
+ require('extract-zip');
81
+ require('tar');
82
+ require('@iconify/utils/lib/colors');
83
+ require('local-pkg');
84
+ require('./download/gitlab/types.cjs');
85
+ require('./colors/attribs.cjs');
86
+ require('./export/helpers/types-version.cjs');
87
+ require('./export/helpers/custom-files.cjs');
88
+
89
+
90
+
91
+ exports.SVG = svg_index.SVG;
92
+ exports.parseSVG = svg_parse.parseSVG;
93
+ exports.parseSVGStyle = svg_parseStyle.parseSVGStyle;
94
+ exports.analyseSVGStructure = svg_analyse.analyseSVGStructure;
95
+ exports.cleanupSVG = svg_cleanup.cleanupSVG;
96
+ exports.removeBadAttributes = svg_cleanup_attribs.removeBadAttributes;
97
+ exports.checkBadTags = svg_cleanup_badTags.checkBadTags;
98
+ exports.cleanupInlineStyle = svg_cleanup_inlineStyle.cleanupInlineStyle;
99
+ exports.cleanupSVGRoot = svg_cleanup_rootSvg.cleanupSVGRoot;
100
+ exports.convertStyleToAttrs = svg_cleanup_svgoStyle.convertStyleToAttrs;
101
+ exports.IconSet = iconSet_index.IconSet;
102
+ exports.blankIconSet = iconSet_index.blankIconSet;
103
+ exports.mergeIconSets = iconSet_merge.mergeIconSets;
104
+ exports.importFromFigma = import_figma_index.importFromFigma;
105
+ exports.importDirectory = import_directory.importDirectory;
106
+ exports.downloadGitRepo = download_git_index.downloadGitRepo;
107
+ exports.getGitRepoHash = download_git_hash.getGitRepoHash;
108
+ exports.getGitRepoBranch = download_git_branch.getGitRepoBranch;
109
+ exports.resetGitRepoContents = download_git_reset.resetGitRepoContents;
110
+ exports.downloadGitHubRepo = download_github_index.downloadGitHubRepo;
111
+ exports.getGitHubRepoHash = download_github_hash.getGitHubRepoHash;
112
+ exports.downloadGitLabRepo = download_gitlab_index.downloadGitLabRepo;
113
+ exports.getGitLabRepoHash = download_gitlab_hash.getGitLabRepoHash;
114
+ exports.downloadNPMPackage = download_npm_index.downloadNPMPackage;
115
+ exports.getNPMVersion = download_npm_version.getNPMVersion;
116
+ exports.getPackageVersion = download_npm_version.getPackageVersion;
117
+ exports.downloadPackage = download_index.downloadPackage;
118
+ exports.isEmptyColor = colors_parse.isEmptyColor;
119
+ exports.parseColors = colors_parse.parseColors;
120
+ exports.validateColors = colors_validate.validateColors;
121
+ exports.runSVGO = optimise_svgo.runSVGO;
122
+ exports.deOptimisePaths = optimise_flags.deOptimisePaths;
123
+ exports.scaleSVG = optimise_scale.scaleSVG;
124
+ exports.cleanupGlobalStyle = optimise_globalStyle.cleanupGlobalStyle;
125
+ exports.exportToDirectory = export_directory.exportToDirectory;
126
+ exports.exportIconPackage = export_iconPackage.exportIconPackage;
127
+ exports.exportJSONPackage = export_jsonPackage.exportJSONPackage;
128
+ exports.writeJSONFile = misc_writeJson.writeJSONFile;
129
+ exports.prepareDirectoryForExport = export_helpers_prepare.prepareDirectoryForExport;
130
+ exports.scanDirectory = misc_scan.scanDirectory;
131
+ exports.compareDirectories = misc_compareDirs.compareDirectories;
132
+ exports.unzip = download_helpers_unzip.unzip;
133
+ exports.untar = download_helpers_untar.untar;
134
+ exports.execAsync = misc_exec.execAsync;
135
+ exports.cleanupIconKeyword = misc_keyword.cleanupIconKeyword;
136
+ exports.bumpVersion = misc_bumpVersion.bumpVersion;
137
+ exports.sendAPIQuery = download_api_index.sendAPIQuery;