@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,749 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blankIconSet = exports.IconSet = exports.sortThemeKeys = void 0;
4
- const icon_1 = require("@iconify/utils/lib/icon");
5
- const build_1 = require("@iconify/utils/lib/svg/build");
6
- const customisations_1 = require("@iconify/utils/lib/customisations");
7
- const minify_1 = require("@iconify/utils/lib/icon-set/minify");
8
- const convert_info_1 = require("@iconify/utils/lib/icon-set/convert-info");
9
- const props_1 = require("./props");
10
- const svg_1 = require("../svg");
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
- function assertNever(v) {
13
- //
14
- }
15
- // Maximum depth for looking for parent icons
16
- // Must match depth limit in Iconify Utils (tested in unit tests by parsing same icon set with deep aliases)
17
- const maxIteration = 6;
18
- // Theme keys
19
- const themeKeys = ['prefixes', 'suffixes'];
20
- /**
21
- * Sort theme keys: long keys first
22
- *
23
- * Applies changes to parameter, but also returns it
24
- */
25
- function sortThemeKeys(keys) {
26
- return keys.sort((a, b) => a.length === b.length ? a.localeCompare(b) : b.length - a.length);
27
- }
28
- exports.sortThemeKeys = sortThemeKeys;
29
- /**
30
- * Export icon set
31
- */
32
- class IconSet {
33
- /**
34
- * Load icon set
35
- */
36
- constructor(data) {
37
- this.load(data);
38
- }
39
- /**
40
- * Load icon set
41
- */
42
- load(data) {
43
- this.prefix = data.prefix;
44
- // Defaults
45
- const defaultProps = (0, props_1.filterProps)(data, true);
46
- // Add icons
47
- this.entries = Object.create(null);
48
- const entries = this.entries;
49
- for (const name in data.icons) {
50
- const item = data.icons[name];
51
- const entry = {
52
- type: 'icon',
53
- body: item.body,
54
- props: (0, props_1.filterProps)({
55
- ...defaultProps,
56
- ...item,
57
- }, true),
58
- chars: new Set(),
59
- categories: new Set(),
60
- };
61
- entries[name] = entry;
62
- }
63
- // Add aliases
64
- if (data.aliases) {
65
- for (const name in data.aliases) {
66
- const item = data.aliases[name];
67
- const parent = item.parent;
68
- const props = (0, props_1.filterProps)(item, false);
69
- const chars = new Set();
70
- if (Object.keys(props).length) {
71
- // Variation
72
- const entry = {
73
- type: 'variation',
74
- parent,
75
- props,
76
- chars,
77
- };
78
- entries[name] = entry;
79
- }
80
- else {
81
- // Alias
82
- const entry = {
83
- type: 'alias',
84
- parent,
85
- chars,
86
- };
87
- entries[name] = entry;
88
- }
89
- }
90
- }
91
- // Info
92
- const info = data.info && (0, convert_info_1.convertIconSetInfo)(data.info);
93
- this.info = info || void 0;
94
- // Characters map
95
- if (data.chars) {
96
- for (const char in data.chars) {
97
- const name = data.chars[char];
98
- const icon = entries[name];
99
- if (icon) {
100
- icon.chars.add(char);
101
- }
102
- }
103
- }
104
- // Categories
105
- this.categories = new Set();
106
- if (data.categories) {
107
- for (const category in data.categories) {
108
- const item = {
109
- title: category,
110
- count: 0,
111
- };
112
- data.categories[category].forEach((iconName) => {
113
- const icon = entries[iconName];
114
- switch (icon === null || icon === void 0 ? void 0 : icon.type) {
115
- case 'icon':
116
- icon.categories.add(item);
117
- }
118
- });
119
- this.categories.add(item);
120
- this.listCategory(item);
121
- }
122
- }
123
- // Themes
124
- const prefixes = (this.prefixes = Object.create(null));
125
- const suffixes = (this.suffixes = Object.create(null));
126
- if (data.themes) {
127
- // Import legacy format
128
- for (const key in data.themes) {
129
- const item = data.themes[key];
130
- if (typeof item.prefix === 'string') {
131
- // Prefix ending with with '-'
132
- const prefix = item.prefix;
133
- if (prefix.slice(-1) === '-') {
134
- prefixes[prefix.slice(0, -1)] = item.title;
135
- }
136
- }
137
- if (typeof item.suffix === 'string') {
138
- // Suffix starting with with '-'
139
- const suffix = item.suffix;
140
- if (suffix.slice(0, 1) === '-') {
141
- suffixes[suffix.slice(1)] = item.title;
142
- }
143
- }
144
- }
145
- }
146
- themeKeys.forEach((prop) => {
147
- // Copy data, overwriting imported legacy format
148
- const items = data[prop];
149
- if (items) {
150
- this[prop] = Object.create(null);
151
- for (const key in items) {
152
- this[prop][key] = items[key];
153
- }
154
- }
155
- });
156
- }
157
- /**
158
- * List icons
159
- */
160
- list(types = ['icon', 'variation']) {
161
- return Object.keys(this.entries).filter((name) => {
162
- const type = this.entries[name].type;
163
- return types.indexOf(type) !== -1;
164
- });
165
- }
166
- /**
167
- * forEach function to loop through all entries.
168
- * Supports asynchronous callbacks.
169
- *
170
- * Callback should return false to stop loop.
171
- */
172
- async forEach(callback, types = ['icon', 'variation', 'alias']) {
173
- const names = this.list(types);
174
- for (let i = 0; i < names.length; i++) {
175
- const name = names[i];
176
- const item = this.entries[name];
177
- if (item) {
178
- let result = callback(name, item.type);
179
- if (result instanceof Promise) {
180
- result = await result;
181
- }
182
- if (result === false) {
183
- return;
184
- }
185
- }
186
- }
187
- }
188
- resolve(name, full = false) {
189
- const entries = this.entries;
190
- function getIcon(name, iteration) {
191
- if (entries[name] === void 0 || iteration > maxIteration) {
192
- // Missing or loop is too deep
193
- return null;
194
- }
195
- const item = entries[name];
196
- switch (item.type) {
197
- case 'icon': {
198
- const result = {
199
- body: item.body,
200
- ...item.props,
201
- };
202
- return result;
203
- }
204
- case 'alias':
205
- return getIcon(item.parent, iteration + 1);
206
- case 'variation': {
207
- const parent = getIcon(item.parent, iteration + 1);
208
- if (!parent) {
209
- return null;
210
- }
211
- for (const key in item.props) {
212
- const attr = key;
213
- const value = item.props[attr];
214
- if (value) {
215
- if (parent[attr] === void 0) {
216
- parent[attr] = value;
217
- }
218
- else {
219
- // Merge props
220
- switch (attr) {
221
- case 'rotate':
222
- parent[attr] =
223
- (parent[attr] +
224
- value) %
225
- 4;
226
- break;
227
- case 'hFlip':
228
- case 'vFlip':
229
- parent[attr] = !parent[attr];
230
- break;
231
- default:
232
- parent[attr] = value;
233
- break;
234
- }
235
- }
236
- }
237
- }
238
- return parent;
239
- }
240
- default:
241
- assertNever(item);
242
- return null;
243
- }
244
- }
245
- const result = getIcon(name, 0);
246
- // Return icon
247
- return result && full ? (0, icon_1.fullIcon)(result) : result;
248
- }
249
- /**
250
- * Generate HTML
251
- */
252
- toString(name, custommisations = {
253
- width: 'auto',
254
- height: 'auto',
255
- }) {
256
- const item = this.resolve(name, true);
257
- if (!item) {
258
- return null;
259
- }
260
- const result = (0, build_1.iconToSVG)(item, {
261
- ...customisations_1.defaults,
262
- ...custommisations,
263
- });
264
- const attributes = Object.keys(result.attributes)
265
- .map((key) => ` ${key}="${result.attributes[key]}"`)
266
- .join('');
267
- return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
268
- }
269
- /**
270
- * Get SVG instance for icon
271
- */
272
- toSVG(name) {
273
- const html = this.toString(name);
274
- return html ? new svg_1.SVG(html) : null;
275
- }
276
- /**
277
- * Export icon set
278
- */
279
- export(validate = true) {
280
- const icons = Object.create(null);
281
- const aliases = Object.create(null);
282
- // Add icons
283
- const names = Object.keys(this.entries);
284
- names.sort((a, b) => a.localeCompare(b));
285
- names.forEach((name) => {
286
- const item = this.entries[name];
287
- switch (item.type) {
288
- case 'icon': {
289
- const icon = {
290
- body: item.body,
291
- ...item.props,
292
- };
293
- icons[name] = icon;
294
- break;
295
- }
296
- case 'alias':
297
- case 'variation': {
298
- if (validate && !this.resolve(name)) {
299
- break;
300
- }
301
- const props = item.type === 'variation' ? item.props : {};
302
- const alias = {
303
- parent: item.parent,
304
- ...props,
305
- };
306
- aliases[name] = alias;
307
- break;
308
- }
309
- default: {
310
- assertNever(item);
311
- }
312
- }
313
- });
314
- // Add info
315
- let info;
316
- if (this.info) {
317
- // Update icons count and clone object
318
- this.info.total = this.count();
319
- info = JSON.parse(JSON.stringify(this.info));
320
- }
321
- // Generate result
322
- const result = {
323
- prefix: this.prefix,
324
- };
325
- if (info) {
326
- result.info = info;
327
- }
328
- result.icons = icons;
329
- if (Object.keys(aliases).length) {
330
- result.aliases = aliases;
331
- }
332
- // Add characters
333
- const chars = this.chars(Object.keys(icons).concat(Object.keys(aliases)));
334
- if (Object.keys(chars).length) {
335
- result.chars = chars;
336
- }
337
- // Get categories
338
- const categories = Object.create(null);
339
- Array.from(this.categories)
340
- // Sort
341
- .sort((a, b) => a.title.localeCompare(b.title))
342
- // Get list of icons
343
- .forEach((item) => {
344
- const names = this.listCategory(item);
345
- if (names) {
346
- names.sort((a, b) => a.localeCompare(b));
347
- categories[item.title] = names;
348
- }
349
- });
350
- if (Object.keys(categories).length) {
351
- result.categories = categories;
352
- }
353
- // Add themes
354
- themeKeys.forEach((prop) => {
355
- const items = this[prop];
356
- const keys = Object.keys(items);
357
- if (keys.length) {
358
- // Sort theme and get matching icon names
359
- sortThemeKeys(keys);
360
- const sortedTheme = Object.create(null);
361
- const tested = this.checkTheme(prop === 'prefixes');
362
- // Add all themes that aren't empty
363
- keys.forEach((key) => {
364
- if (tested.valid[key].length) {
365
- sortedTheme[key] = items[key];
366
- }
367
- });
368
- // Make sure themes do exist
369
- if (Object.keys(sortedTheme).length) {
370
- result[prop] = sortedTheme;
371
- }
372
- }
373
- });
374
- // Minify icon set
375
- (0, minify_1.minifyIconSet)(result);
376
- return result;
377
- }
378
- /**
379
- * Get characters map
380
- */
381
- chars(names) {
382
- const chars = Object.create(null);
383
- if (!names) {
384
- names = Object.keys(this.entries);
385
- }
386
- for (let i = 0; i < names.length; i++) {
387
- const name = names[i];
388
- const item = this.entries[name];
389
- item.chars.forEach((char) => {
390
- chars[char] = name;
391
- });
392
- }
393
- return chars;
394
- }
395
- /**
396
- * Filter icons
397
- */
398
- _filter(callback) {
399
- const names = [];
400
- for (const key in this.entries) {
401
- const item = this.entries[key];
402
- switch (item.type) {
403
- case 'icon': {
404
- if (callback(key, item)) {
405
- names.push(key);
406
- }
407
- break;
408
- }
409
- case 'variation':
410
- case 'alias': {
411
- // Resolve alias to make sure parent icon is not hidden
412
- const icon = this.resolve(key);
413
- if (icon && callback(key, item, icon)) {
414
- names.push(key);
415
- }
416
- break;
417
- }
418
- }
419
- }
420
- return names;
421
- }
422
- /**
423
- * Count icons
424
- */
425
- count() {
426
- return this._filter((_key, item, icon) => {
427
- if (item.type === 'alias' || item.props.hidden || (icon === null || icon === void 0 ? void 0 : icon.hidden)) {
428
- return false;
429
- }
430
- return true;
431
- }).length;
432
- }
433
- /**
434
- * Find category by title
435
- */
436
- _findCategory(title, add) {
437
- const categoryItem = Array.from(this.categories).find((item) => item.title === title);
438
- if (categoryItem) {
439
- return categoryItem;
440
- }
441
- if (add) {
442
- const newItem = {
443
- title,
444
- count: 0,
445
- };
446
- this.categories.add(newItem);
447
- return newItem;
448
- }
449
- return null;
450
- }
451
- /**
452
- * Count icons in category, remove category if empty
453
- *
454
- * Hidden icons and aliases do not count
455
- */
456
- listCategory(category) {
457
- // Find item
458
- const categoryItem = typeof category === 'string'
459
- ? this._findCategory(category, false)
460
- : category;
461
- if (!categoryItem) {
462
- return null;
463
- }
464
- // Find icons
465
- const icons = this._filter((_key, item) => {
466
- if (item.type !== 'icon' || item.props.hidden) {
467
- return false;
468
- }
469
- return item.categories.has(categoryItem);
470
- });
471
- // Update count, remove category if empty
472
- const count = icons.length;
473
- categoryItem.count = count;
474
- if (!count) {
475
- this.categories.delete(categoryItem);
476
- return null;
477
- }
478
- return icons;
479
- }
480
- /**
481
- * Check if icon exists
482
- */
483
- exists(name) {
484
- return !!this.entries[name];
485
- }
486
- /**
487
- * Remove icons. Returns number of removed icons
488
- *
489
- * If removeDependencies is a string, it represents new parent for all aliases of removed icon.
490
- */
491
- remove(name, removeDependencies = true) {
492
- const entries = this.entries;
493
- const names = new Set();
494
- // Check if new parent exists
495
- if (typeof removeDependencies === 'string') {
496
- if (name === removeDependencies || !entries[removeDependencies]) {
497
- return 0;
498
- }
499
- names.add(removeDependencies);
500
- }
501
- function del(name, iteration) {
502
- if (entries[name] === void 0 ||
503
- iteration > maxIteration ||
504
- names.has(name)) {
505
- // Missing or loop is too deep
506
- return false;
507
- }
508
- names.add(name);
509
- if (removeDependencies === true ||
510
- (!iteration && typeof removeDependencies === 'string')) {
511
- // Find icons that have this icon as parent
512
- for (const key in entries) {
513
- const item = entries[key];
514
- switch (item.type) {
515
- case 'icon':
516
- break;
517
- case 'alias':
518
- case 'variation':
519
- if (item.parent === name) {
520
- if (removeDependencies === true) {
521
- if (!del(key, iteration + 1)) {
522
- return false;
523
- }
524
- break;
525
- }
526
- // Change parent
527
- item.parent = removeDependencies;
528
- }
529
- break;
530
- default:
531
- assertNever(item);
532
- }
533
- }
534
- }
535
- return true;
536
- }
537
- if (del(name, 0)) {
538
- if (typeof removeDependencies === 'string') {
539
- names.delete(removeDependencies);
540
- }
541
- names.forEach((name) => {
542
- delete entries[name];
543
- });
544
- return names.size;
545
- }
546
- return 0;
547
- }
548
- /**
549
- * Remove icon
550
- */
551
- rename(oldName, newName) {
552
- const entries = this.entries;
553
- // Remove existing item with new name
554
- if (entries[newName]) {
555
- if (!this.remove(newName)) {
556
- return false;
557
- }
558
- }
559
- // Rename icon
560
- if (!entries[oldName]) {
561
- return false;
562
- }
563
- entries[newName] = entries[oldName];
564
- delete entries[oldName];
565
- // Find aliases
566
- for (const key in entries) {
567
- const item = entries[key];
568
- switch (item.type) {
569
- case 'icon':
570
- break;
571
- case 'alias':
572
- case 'variation':
573
- if (item.parent === oldName) {
574
- item.parent = newName;
575
- }
576
- break;
577
- default:
578
- assertNever(item);
579
- }
580
- }
581
- return true;
582
- }
583
- /**
584
- * Add/update item
585
- */
586
- setItem(name, item) {
587
- switch (item.type) {
588
- case 'alias':
589
- case 'variation': {
590
- if (!this.entries[item.parent]) {
591
- return false;
592
- }
593
- }
594
- }
595
- this.entries[name] = item;
596
- return true;
597
- }
598
- /**
599
- * Add/update icon
600
- */
601
- setIcon(name, icon) {
602
- return this.setItem(name, {
603
- type: 'icon',
604
- body: icon.body,
605
- props: (0, props_1.filterProps)(icon, true),
606
- chars: new Set(),
607
- categories: new Set(),
608
- });
609
- }
610
- /**
611
- * Add/update alias without props
612
- */
613
- setAlias(name, parent) {
614
- return this.setItem(name, {
615
- type: 'alias',
616
- parent,
617
- chars: new Set(),
618
- });
619
- }
620
- /**
621
- * Add/update alias with props
622
- */
623
- setVariation(name, parent, props) {
624
- return this.setItem(name, {
625
- type: 'variation',
626
- parent,
627
- props,
628
- chars: new Set(),
629
- });
630
- }
631
- /**
632
- * Icon from SVG. Updates old icon if it exists
633
- */
634
- fromSVG(name, svg) {
635
- const props = svg.viewBox;
636
- const body = svg.getBody();
637
- const item = this.entries[name];
638
- switch (item === null || item === void 0 ? void 0 : item.type) {
639
- case 'icon':
640
- case 'variation': {
641
- // Copy extra properties
642
- for (const key in props_1.extraDefaultProps) {
643
- const prop = key;
644
- if (item.props[prop]) {
645
- props[prop] = item.props[prop];
646
- }
647
- }
648
- // Set icon
649
- return this.setItem(name, {
650
- type: 'icon',
651
- body,
652
- props,
653
- chars: item.chars,
654
- categories: item.type === 'icon' ? item.categories : new Set(),
655
- });
656
- }
657
- }
658
- // Create new entry
659
- return this.setIcon(name, {
660
- body,
661
- ...props,
662
- });
663
- }
664
- /**
665
- * Add or remove character for icon
666
- */
667
- toggleCharacter(iconName, char, add) {
668
- const item = this.entries[iconName];
669
- if (!item) {
670
- return false;
671
- }
672
- if (item.chars.has(char) !== add) {
673
- item.chars[add ? 'add' : 'delete'](char);
674
- return true;
675
- }
676
- return false;
677
- }
678
- /**
679
- * Add or remove category for icon
680
- */
681
- toggleCategory(iconName, category, add) {
682
- const item = this.entries[iconName];
683
- const categoryItem = this._findCategory(category, add);
684
- if (!item || !categoryItem) {
685
- return false;
686
- }
687
- switch (item.type) {
688
- case 'icon':
689
- if (item.categories.has(categoryItem) !== add) {
690
- categoryItem.count += add ? 1 : -1;
691
- item.categories[add ? 'add' : 'delete'](categoryItem);
692
- return true;
693
- }
694
- }
695
- return false;
696
- }
697
- /**
698
- * Find icons that belong to theme
699
- */
700
- checkTheme(prefix) {
701
- const themes = prefix ? this.prefixes : this.suffixes;
702
- const keys = sortThemeKeys(Object.keys(themes));
703
- const results = {
704
- valid: Object.create(null),
705
- invalid: [],
706
- };
707
- keys.forEach((key) => {
708
- results.valid[key] = [];
709
- });
710
- results.invalid = this._filter((name, item, icon) => {
711
- if (item.type === 'alias' || item.props.hidden || (icon === null || icon === void 0 ? void 0 : icon.hidden)) {
712
- return false;
713
- }
714
- // Check if icon belongs to theme
715
- for (let i = 0; i < keys.length; i++) {
716
- const search = keys[i];
717
- if (search === '') {
718
- // Last item: matches all icons that do not belong to other themes
719
- results.valid[search].push(name);
720
- return false;
721
- }
722
- const match = prefix ? search + '-' : '-' + search;
723
- const length = match.length;
724
- const test = prefix
725
- ? name.slice(0, length)
726
- : name.slice(0 - length);
727
- if (test === match) {
728
- // Icon belongs to theme
729
- results.valid[search].push(name);
730
- return false;
731
- }
732
- }
733
- // Icon does not belong to any theme
734
- return true;
735
- });
736
- return results;
737
- }
738
- }
739
- exports.IconSet = IconSet;
740
- /**
741
- * Create blank icon set
742
- */
743
- function blankIconSet(prefix) {
744
- return new IconSet({
745
- prefix,
746
- icons: {},
747
- });
748
- }
749
- exports.blankIconSet = blankIconSet;