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