@iconify/tools 2.0.14 → 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +20 -21
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +40 -53
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +7 -10
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +3 -11
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +137 -0
  158. package/lib/index.d.ts +65 -44
  159. package/lib/index.mjs +83 -94
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +18 -15
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -14
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +99 -94
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findMatchingIcon = void 0;
4
- const icon_1 = require("@iconify/utils/lib/icon");
5
- // Maximum depth for looking for parent icons
6
- const maxIteration = 5;
7
- /**
8
- * Find matching icon in icon set
9
- */
10
- function findMatchingIcon(iconSet, icon) {
11
- const body = icon.body;
12
- let hiddenMatch = null;
13
- function isMatching(data) {
14
- for (const key in icon_1.iconDefaults) {
15
- const attr = key;
16
- if (data[attr] !== icon[attr]) {
17
- return false;
18
- }
19
- }
20
- return true;
21
- }
22
- /**
23
- * Check if icon matches
24
- */
25
- function test(name, iteration) {
26
- const data = iconSet.resolve(name, true);
27
- if (!data) {
28
- return null;
29
- }
30
- if (isMatching(data)) {
31
- if (data.hidden) {
32
- hiddenMatch = name;
33
- }
34
- else {
35
- return name;
36
- }
37
- }
38
- if (iteration > maxIteration) {
39
- return null;
40
- }
41
- // Check aliases
42
- for (const key in iconSet.entries) {
43
- const item = iconSet.entries[key];
44
- if (item.type === 'variation' && item.parent === name) {
45
- const result = test(key, iteration + 1);
46
- if (typeof result === 'string') {
47
- return result;
48
- }
49
- }
50
- }
51
- return null;
52
- }
53
- // Find icons that match
54
- for (const key in iconSet.entries) {
55
- const item = iconSet.entries[key];
56
- if (item.type === 'icon' && item.body === body) {
57
- // Possible match
58
- const result = test(key, 0);
59
- if (typeof result === 'string') {
60
- return result;
61
- }
62
- }
63
- }
64
- return hiddenMatch;
65
- }
66
- exports.findMatchingIcon = findMatchingIcon;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeIconSets = void 0;
4
- const _1 = require(".");
5
- const match_1 = require("./match");
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
- function assertNever(v) {
8
- //
9
- }
10
- /**
11
- * Merge icon sets
12
- */
13
- function mergeIconSets(oldIcons, newIcons) {
14
- const mergedIcons = new _1.IconSet(newIcons.export());
15
- const oldEntries = oldIcons.entries;
16
- const entries = mergedIcons.entries;
17
- function add(name) {
18
- if (entries[name]) {
19
- // Already exists
20
- return true;
21
- }
22
- const item = oldEntries[name];
23
- switch (item.type) {
24
- case 'icon': {
25
- // Attempt to find matching icon
26
- const fullIcon = oldIcons.resolve(name, true);
27
- const parent = fullIcon
28
- ? (0, match_1.findMatchingIcon)(mergedIcons, fullIcon)
29
- : null;
30
- if (parent !== null) {
31
- // Add as alias
32
- mergedIcons.setAlias(name, parent);
33
- return true;
34
- }
35
- // Add as is, duplicating props
36
- const props = item.props;
37
- mergedIcons.setItem(name, {
38
- ...item,
39
- props: {
40
- ...props,
41
- hidden: true,
42
- },
43
- categories: new Set(),
44
- });
45
- return true;
46
- }
47
- case 'variation':
48
- case 'alias': {
49
- // Add parent
50
- let parent = item.parent;
51
- if (!add(parent)) {
52
- return false;
53
- }
54
- const parentItem = entries[parent];
55
- if (parentItem.type === 'alias') {
56
- // Alias of alias - use parent
57
- parent = parentItem.parent;
58
- }
59
- if (item.type === 'variation') {
60
- // Hide variation and copy props
61
- const props = item.props;
62
- mergedIcons.setItem(name, {
63
- ...item,
64
- parent,
65
- props: {
66
- ...props,
67
- hidden: true,
68
- },
69
- });
70
- }
71
- else {
72
- mergedIcons.setItem(name, {
73
- ...item,
74
- parent,
75
- });
76
- }
77
- return true;
78
- }
79
- default:
80
- assertNever(item);
81
- return false;
82
- }
83
- }
84
- // Add old icons
85
- for (const name in oldEntries) {
86
- add(name);
87
- }
88
- return mergedIcons;
89
- }
90
- exports.mergeIconSets = mergeIconSets;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterProps = exports.defaultCommonProps = exports.extraDefaultProps = void 0;
4
- const icon_1 = require("@iconify/utils/lib/icon");
5
- /**
6
- * Default properties
7
- */
8
- exports.extraDefaultProps = {
9
- hidden: false,
10
- };
11
- exports.defaultCommonProps = {
12
- ...icon_1.iconDefaults,
13
- ...exports.extraDefaultProps,
14
- };
15
- /**
16
- * Properties to filter
17
- */
18
- const props = Object.keys(exports.defaultCommonProps);
19
- /**
20
- * Filter icon props: copies properties, removing undefined and default entries
21
- */
22
- function filterProps(data, compareDefaultValues) {
23
- const result = {};
24
- props.forEach((attr) => {
25
- const value = data[attr];
26
- if (value !== void 0 &&
27
- (!compareDefaultValues ||
28
- value !== exports.defaultCommonProps[attr])) {
29
- result[attr] = value;
30
- }
31
- });
32
- return result;
33
- }
34
- exports.filterProps = filterProps;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.importDirectory = void 0;
4
- const fs_1 = require("fs");
5
- const icon_set_1 = require("../icon-set");
6
- const keyword_1 = require("../misc/keyword");
7
- const scan_1 = require("../misc/scan");
8
- const svg_1 = require("../svg");
9
- const cleanup_1 = require("../svg/cleanup");
10
- /**
11
- * Import all icons from directory
12
- */
13
- async function importDirectory(path, options = {}) {
14
- // Find all files
15
- const files = await (0, scan_1.scanDirectory)(path, (ext, file, subdir, path) => {
16
- if (ext.toLowerCase() === '.svg') {
17
- const result = {
18
- file,
19
- ext,
20
- subdir,
21
- path,
22
- };
23
- return result;
24
- }
25
- return false;
26
- });
27
- // Create blank icon set
28
- const iconSet = (0, icon_set_1.blankIconSet)(options.prefix || '');
29
- // Import all files
30
- for (let i = 0; i < files.length; i++) {
31
- const file = files[i];
32
- // Get keyword
33
- const defaultKeyword = (0, keyword_1.cleanupIconKeyword)(file.file);
34
- let keyword = options.keyword
35
- ? options.keyword(file, defaultKeyword, iconSet)
36
- : defaultKeyword;
37
- if (keyword instanceof Promise) {
38
- keyword = await keyword;
39
- }
40
- // Check it
41
- if (typeof keyword !== 'string' || !keyword.length) {
42
- continue;
43
- }
44
- // Import icon, clean it up
45
- try {
46
- const content = await fs_1.promises.readFile(file.path + file.subdir + file.file + file.ext, 'utf8');
47
- const svg = new svg_1.SVG(content);
48
- await (0, cleanup_1.cleanupSVG)(svg);
49
- iconSet.fromSVG(keyword, svg);
50
- }
51
- catch (err) {
52
- if (options.ignoreImportErrors !== false) {
53
- throw err;
54
- }
55
- }
56
- }
57
- return iconSet;
58
- }
59
- exports.importDirectory = importDirectory;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.importFromFigma = void 0;
4
- const icon_set_1 = require("../../icon-set");
5
- const svg_1 = require("../../svg");
6
- const cleanup_1 = require("../../svg/cleanup");
7
- const nodes_1 = require("./nodes");
8
- const query_1 = require("./query");
9
- async function importFromFigma(options) {
10
- const cacheOptions = options.cacheDir
11
- ? {
12
- // 24 hours
13
- ttl: options.cacheAPITTL || 60 * 60 * 24,
14
- dir: options.cacheDir,
15
- }
16
- : void 0;
17
- const cacheSVGOptions = options.cacheDir
18
- ? {
19
- // 30 days
20
- ttl: options.cacheSVGTTL || 60 * 60 * 24 * 30,
21
- dir: options.cacheDir,
22
- }
23
- : void 0;
24
- // Get document
25
- const document = await (0, query_1.figmaFilesQuery)(options, cacheOptions);
26
- if (document === 'not_modified') {
27
- return document;
28
- }
29
- // Set version to make sure further queries get consistent data
30
- options.version = document.version;
31
- // Get nodes
32
- const nodes = await (0, nodes_1.getFigmaIconNodes)(document, options);
33
- // Get images
34
- await (0, query_1.figmaImagesQuery)(options, nodes, cacheOptions);
35
- // Download images
36
- await (0, query_1.figmaDownloadImages)(nodes, cacheSVGOptions);
37
- // Generate icon set
38
- const iconSet = (0, icon_set_1.blankIconSet)(options.prefix);
39
- const icons = nodes.icons;
40
- const missing = [];
41
- const iconIDs = Object.keys(icons);
42
- for (let i = 0; i < iconIDs.length; i++) {
43
- const id = iconIDs[i];
44
- const item = icons[id];
45
- if (typeof item.content !== 'string') {
46
- missing.push(item);
47
- continue;
48
- }
49
- // Callback before import (to change stuff, such as icon content)
50
- if (options.beforeImportingIcon) {
51
- const callbackResult = options.beforeImportingIcon(item, iconSet);
52
- if (callbackResult instanceof Promise) {
53
- await callbackResult;
54
- }
55
- }
56
- // Import SVG
57
- try {
58
- const svg = new svg_1.SVG(item.content);
59
- await (0, cleanup_1.cleanupSVG)(svg);
60
- iconSet.fromSVG(item.keyword, svg);
61
- }
62
- catch (err) {
63
- missing.push(item);
64
- continue;
65
- }
66
- // Callback after import (to add stuff, such as categories)
67
- if (options.afterImportingIcon) {
68
- const callbackResult = options.afterImportingIcon(item, iconSet);
69
- if (callbackResult instanceof Promise) {
70
- await callbackResult;
71
- }
72
- }
73
- }
74
- // Generate result
75
- const result = {
76
- // Document
77
- name: document.name,
78
- version: document.version,
79
- lastModified: document.lastModified,
80
- // Counters
81
- nodesCount: nodes.nodesCount,
82
- generatedIconsCount: nodes.generatedIconsCount,
83
- downloadedIconsCount: nodes.downloadedIconsCount,
84
- // Icon set
85
- iconSet,
86
- missing,
87
- };
88
- return result;
89
- }
90
- exports.importFromFigma = importFromFigma;
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFigmaIconNodes = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
- function assertNever(v) {
6
- //
7
- }
8
- /**
9
- * Get node ids for icons
10
- */
11
- async function getFigmaIconNodes(document, options) {
12
- const nodes = {
13
- icons: Object.create(null),
14
- };
15
- let found = 0;
16
- const check = (node, parents) => {
17
- // Check if node can be icon
18
- const iconNodeType = node.type;
19
- switch (iconNodeType) {
20
- case 'COMPONENT':
21
- case 'INSTANCE':
22
- case 'FRAME': {
23
- const iconNode = node;
24
- if (iconNode.absoluteBoundingBox) {
25
- const box = iconNode.absoluteBoundingBox;
26
- const item = {
27
- ...node,
28
- type: iconNodeType,
29
- width: box.width,
30
- height: box.height,
31
- parents,
32
- };
33
- const keyword = options.iconNameForNode(item, nodes, document);
34
- if (typeof keyword === 'string') {
35
- // Keyword
36
- found++;
37
- nodes.icons[node.id] = {
38
- id: node.id,
39
- name: node.name,
40
- keyword,
41
- };
42
- return;
43
- }
44
- if (keyword &&
45
- typeof keyword === 'object' &&
46
- typeof keyword.keyword === 'string') {
47
- // Full item, possibly with custom properties
48
- found++;
49
- nodes.icons[node.id] = {
50
- ...keyword,
51
- id: node.id,
52
- name: node.name,
53
- };
54
- return;
55
- }
56
- }
57
- break;
58
- }
59
- default:
60
- assertNever(iconNodeType);
61
- }
62
- // Check if node is a valid parent node
63
- if (!node.children) {
64
- return;
65
- }
66
- const parentNodeType = node.type;
67
- switch (parentNodeType) {
68
- case 'CANVAS':
69
- case 'FRAME':
70
- case 'GROUP': {
71
- const parentItem = {
72
- ...node,
73
- type: parentNodeType,
74
- };
75
- const newParents = parents.concat([parentItem]);
76
- if (!parents.length && options.pages) {
77
- // Check page against allowed pages list
78
- const allowedPages = options.pages;
79
- if (allowedPages.indexOf(node.id) === -1 &&
80
- allowedPages.indexOf(node.name.trim()) === -1) {
81
- return;
82
- }
83
- }
84
- else {
85
- // Use callback
86
- if (options.filterParentNode &&
87
- !options.filterParentNode(newParents, document)) {
88
- return;
89
- }
90
- }
91
- node.children.forEach((childNode) => {
92
- check(childNode, newParents);
93
- });
94
- break;
95
- }
96
- default:
97
- assertNever(parentNodeType);
98
- }
99
- };
100
- document.document.children.forEach((node) => {
101
- check(node, []);
102
- });
103
- nodes.nodesCount = found;
104
- return nodes;
105
- }
106
- exports.getFigmaIconNodes = getFigmaIconNodes;
@@ -1,244 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.figmaDownloadImages = exports.figmaImagesQuery = exports.figmaFilesQuery = void 0;
4
- const api_1 = require("../../download/api");
5
- const cache_1 = require("../../download/api/cache");
6
- /**
7
- * Compare last modified dates
8
- */
9
- function identicalDates(actual, expected) {
10
- if (typeof actual !== 'string') {
11
- return false;
12
- }
13
- if (actual === expected) {
14
- return true;
15
- }
16
- return new Date(actual).toString() === new Date(expected).toString();
17
- }
18
- async function figmaFilesQuery(options, cache) {
19
- // Check token
20
- if (!options.token) {
21
- throw new Error('Missing Figma API token');
22
- }
23
- // Generate parameters
24
- const params = new URLSearchParams();
25
- if (options.ids) {
26
- params.set('ids', options.ids.join(','));
27
- }
28
- if (options.version) {
29
- params.set('version', options.version);
30
- }
31
- if (options.depth) {
32
- params.set('depth', options.depth + '');
33
- }
34
- const queryParams = {
35
- uri: 'https://api.figma.com/v1/files/' + options.file,
36
- params,
37
- headers: {
38
- 'X-FIGMA-TOKEN': options.token,
39
- },
40
- };
41
- // Get latest version without cache if 'ifModifiedSince' is set
42
- const isModified = async () => {
43
- // Check cache
44
- if (!cache || !options.ifModifiedSince) {
45
- return true;
46
- }
47
- const cacheKey = (0, cache_1.apiCacheKey)(queryParams);
48
- const cachedData = await (0, cache_1.getAPICache)(cache.dir, cacheKey);
49
- if (!cachedData) {
50
- return true;
51
- }
52
- // Get time stamp for comparison
53
- let ifModifiedSince;
54
- if (options.ifModifiedSince === true) {
55
- try {
56
- const parsedData = JSON.parse(cachedData);
57
- if (typeof parsedData.lastModified !== 'string') {
58
- // Bad data
59
- await (0, cache_1.clearAPICache)(cache.dir);
60
- return true;
61
- }
62
- // Set ifModifiedSince to last cached time
63
- ifModifiedSince = parsedData.lastModified;
64
- }
65
- catch (err) {
66
- // Bad data
67
- await (0, cache_1.clearAPICache)(cache.dir);
68
- return true;
69
- }
70
- }
71
- else {
72
- ifModifiedSince = options.ifModifiedSince;
73
- }
74
- // Get shallow copy of tree to get last modification time
75
- const versionCheckParams = {
76
- ...queryParams,
77
- params: new URLSearchParams(params),
78
- };
79
- versionCheckParams.params.set('depth', '1');
80
- const data = await (0, api_1.sendAPIQuery)(versionCheckParams);
81
- try {
82
- if (typeof data === 'string') {
83
- const parsedData = JSON.parse(data);
84
- if (identicalDates(parsedData.lastModified, ifModifiedSince)) {
85
- return false;
86
- }
87
- }
88
- }
89
- catch (err) {
90
- //
91
- }
92
- // Reset cache
93
- await (0, cache_1.clearAPICache)(cache.dir);
94
- return true;
95
- };
96
- if (!(await isModified())) {
97
- return 'not_modified';
98
- }
99
- // Send query
100
- const data = await (0, api_1.sendAPIQuery)(queryParams, cache);
101
- if (typeof data === 'number') {
102
- throw new Error(`Error retrieving document from API: ${data}`);
103
- }
104
- // Parse JSON
105
- let parsedData;
106
- try {
107
- parsedData = JSON.parse(data);
108
- }
109
- catch (err) {
110
- throw new Error(`Error retrieving document from API: invalid data`);
111
- }
112
- if (typeof parsedData.status === 'number') {
113
- // Error
114
- const figmaError = parsedData;
115
- throw new Error(`Error retrieving document from API: ${figmaError.err}`);
116
- }
117
- const document = parsedData;
118
- if (document.editorType !== 'figma') {
119
- throw new Error(`Error retrieving document from API: document is for ${document.editorType}`);
120
- }
121
- // Check if document was modified
122
- if (identicalDates(options.ifModifiedSince, document.lastModified)) {
123
- return 'not_modified';
124
- }
125
- return document;
126
- }
127
- exports.figmaFilesQuery = figmaFilesQuery;
128
- /**
129
- * Generate all images
130
- */
131
- async function figmaImagesQuery(options, nodes, cache) {
132
- const uri = 'https://api.figma.com/v1/images/' + options.file;
133
- const maxLength = 2048 - uri.length;
134
- const svgOptions = options.svgOptions || {};
135
- let ids = [];
136
- let idsLength = 0;
137
- let lastError;
138
- let found = 0;
139
- // Send query
140
- const query = async () => {
141
- const params = new URLSearchParams({
142
- ids: ids.join(','),
143
- format: 'svg',
144
- });
145
- if (options.version) {
146
- params.set('version', options.version);
147
- }
148
- if (svgOptions.includeID) {
149
- params.set('svg_include_id', 'true');
150
- }
151
- if (svgOptions.simplifyStroke) {
152
- params.set('svg_simplify_stroke', 'true');
153
- }
154
- if (svgOptions.useAbsoluteBounds) {
155
- params.set('use_absolute_bounds', 'true');
156
- }
157
- const data = await (0, api_1.sendAPIQuery)({
158
- uri,
159
- params,
160
- headers: {
161
- 'X-FIGMA-TOKEN': options.token,
162
- },
163
- }, cache);
164
- if (typeof data === 'number') {
165
- lastError = data;
166
- return;
167
- }
168
- try {
169
- const parsedData = JSON.parse(data);
170
- const images = parsedData.images;
171
- for (const id in images) {
172
- const node = nodes.icons[id];
173
- const target = images[id];
174
- if (node && target) {
175
- node.url = target;
176
- found++;
177
- }
178
- }
179
- }
180
- catch (err) {
181
- return;
182
- }
183
- };
184
- // Loop all ids
185
- const allKeys = Object.keys(nodes.icons);
186
- for (let i = 0; i < allKeys.length; i++) {
187
- const id = allKeys[i];
188
- ids.push(id);
189
- idsLength += id.length + 1;
190
- if (idsLength >= maxLength) {
191
- await query();
192
- ids = [];
193
- idsLength = 0;
194
- }
195
- }
196
- if (idsLength) {
197
- await query();
198
- }
199
- // Check data
200
- if (!found) {
201
- if (lastError) {
202
- throw new Error(`Error retrieving image data from API${lastError ? ': ' + lastError : ''}`);
203
- }
204
- else {
205
- throw new Error('No valid icon layers were found');
206
- }
207
- }
208
- nodes.generatedIconsCount = found;
209
- return nodes;
210
- }
211
- exports.figmaImagesQuery = figmaImagesQuery;
212
- /**
213
- * Download all images
214
- */
215
- async function figmaDownloadImages(nodes, cache) {
216
- const icons = nodes.icons;
217
- const ids = Object.keys(icons);
218
- let count = 0;
219
- let lastError;
220
- for (let i = 0; i < ids.length; i++) {
221
- const id = ids[i];
222
- const item = icons[id];
223
- if (!item.url) {
224
- continue;
225
- }
226
- const result = await (0, api_1.sendAPIQuery)({
227
- uri: item.url,
228
- }, cache);
229
- if (typeof result === 'number') {
230
- lastError = result;
231
- continue;
232
- }
233
- if (typeof result === 'string') {
234
- count++;
235
- item.content = result;
236
- }
237
- }
238
- if (!count) {
239
- throw new Error(`Error retrieving images${lastError ? ': ' + lastError : ''}`);
240
- }
241
- nodes.downloadedIconsCount = count;
242
- return nodes;
243
- }
244
- exports.figmaDownloadImages = figmaDownloadImages;