@iconify/tools 2.0.14 → 2.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +20 -21
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +40 -53
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +7 -10
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +3 -11
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +137 -0
  158. package/lib/index.d.ts +65 -44
  159. package/lib/index.mjs +83 -94
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +18 -15
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -14
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +99 -94
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -0,0 +1,589 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const icon = require('@iconify/utils/lib/icon');
6
+ const build = require('@iconify/utils/lib/svg/build');
7
+ const customisations = require('@iconify/utils/lib/customisations');
8
+ const minify = require('@iconify/utils/lib/icon-set/minify');
9
+ const convertInfo = require('@iconify/utils/lib/icon-set/convert-info');
10
+ const iconSet_props = require('./props.cjs');
11
+ const svg_index = require('../svg/index.cjs');
12
+ require('cheerio');
13
+ require('@iconify/utils');
14
+
15
+ const maxIteration = 6;
16
+ const themeKeys = ["prefixes", "suffixes"];
17
+ function sortThemeKeys(keys) {
18
+ return keys.sort((a, b) => a.length === b.length ? a.localeCompare(b) : b.length - a.length);
19
+ }
20
+ class IconSet {
21
+ constructor(data) {
22
+ this.load(data);
23
+ }
24
+ load(data) {
25
+ this.prefix = data.prefix;
26
+ const defaultProps = iconSet_props.filterProps(data, true);
27
+ this.entries = /* @__PURE__ */ Object.create(null);
28
+ const entries = this.entries;
29
+ for (const name in data.icons) {
30
+ const item = data.icons[name];
31
+ const entry = {
32
+ type: "icon",
33
+ body: item.body,
34
+ props: iconSet_props.filterProps({
35
+ ...defaultProps,
36
+ ...item
37
+ }, true),
38
+ chars: /* @__PURE__ */ new Set(),
39
+ categories: /* @__PURE__ */ new Set()
40
+ };
41
+ entries[name] = entry;
42
+ }
43
+ if (data.aliases) {
44
+ for (const name in data.aliases) {
45
+ const item = data.aliases[name];
46
+ const parent = item.parent;
47
+ const props = iconSet_props.filterProps(item, false);
48
+ const chars = /* @__PURE__ */ new Set();
49
+ if (Object.keys(props).length) {
50
+ const entry = {
51
+ type: "variation",
52
+ parent,
53
+ props,
54
+ chars
55
+ };
56
+ entries[name] = entry;
57
+ } else {
58
+ const entry = {
59
+ type: "alias",
60
+ parent,
61
+ chars
62
+ };
63
+ entries[name] = entry;
64
+ }
65
+ }
66
+ }
67
+ const info = data.info && convertInfo.convertIconSetInfo(data.info);
68
+ this.info = info || void 0;
69
+ if (data.chars) {
70
+ for (const char in data.chars) {
71
+ const name = data.chars[char];
72
+ const icon = entries[name];
73
+ if (icon) {
74
+ icon.chars.add(char);
75
+ }
76
+ }
77
+ }
78
+ this.categories = /* @__PURE__ */ new Set();
79
+ if (data.categories) {
80
+ for (const category in data.categories) {
81
+ const item = {
82
+ title: category,
83
+ count: 0
84
+ };
85
+ data.categories[category].forEach((iconName) => {
86
+ const icon = entries[iconName];
87
+ switch (icon?.type) {
88
+ case "icon":
89
+ icon.categories.add(item);
90
+ }
91
+ });
92
+ this.categories.add(item);
93
+ this.listCategory(item);
94
+ }
95
+ }
96
+ const prefixes = this.prefixes = /* @__PURE__ */ Object.create(null);
97
+ const suffixes = this.suffixes = /* @__PURE__ */ Object.create(null);
98
+ if (data.themes) {
99
+ for (const key in data.themes) {
100
+ const item = data.themes[key];
101
+ if (typeof item.prefix === "string") {
102
+ const prefix = item.prefix;
103
+ if (prefix.slice(-1) === "-") {
104
+ prefixes[prefix.slice(0, -1)] = item.title;
105
+ }
106
+ }
107
+ if (typeof item.suffix === "string") {
108
+ const suffix = item.suffix;
109
+ if (suffix.slice(0, 1) === "-") {
110
+ suffixes[suffix.slice(1)] = item.title;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ themeKeys.forEach((prop) => {
116
+ const items = data[prop];
117
+ if (items) {
118
+ this[prop] = /* @__PURE__ */ Object.create(null);
119
+ for (const key in items) {
120
+ this[prop][key] = items[key];
121
+ }
122
+ }
123
+ });
124
+ }
125
+ list(types = ["icon", "variation"]) {
126
+ return Object.keys(this.entries).filter((name) => {
127
+ const type = this.entries[name].type;
128
+ return types.indexOf(type) !== -1;
129
+ });
130
+ }
131
+ async forEach(callback, types = ["icon", "variation", "alias"]) {
132
+ const names = this.list(types);
133
+ for (let i = 0; i < names.length; i++) {
134
+ const name = names[i];
135
+ const item = this.entries[name];
136
+ if (item) {
137
+ let result = callback(name, item.type);
138
+ if (result instanceof Promise) {
139
+ result = await result;
140
+ }
141
+ if (result === false) {
142
+ return;
143
+ }
144
+ }
145
+ }
146
+ }
147
+ resolve(name, full = false) {
148
+ const entries = this.entries;
149
+ function getIcon(name2, iteration) {
150
+ if (entries[name2] === void 0 || iteration > maxIteration) {
151
+ return null;
152
+ }
153
+ const item = entries[name2];
154
+ switch (item.type) {
155
+ case "icon": {
156
+ const result2 = {
157
+ body: item.body,
158
+ ...item.props
159
+ };
160
+ return result2;
161
+ }
162
+ case "alias":
163
+ return getIcon(item.parent, iteration + 1);
164
+ case "variation": {
165
+ const parent = getIcon(item.parent, iteration + 1);
166
+ if (!parent) {
167
+ return null;
168
+ }
169
+ for (const key in item.props) {
170
+ const attr = key;
171
+ const value = item.props[attr];
172
+ if (value) {
173
+ if (parent[attr] === void 0) {
174
+ parent[attr] = value;
175
+ } else {
176
+ switch (attr) {
177
+ case "rotate":
178
+ parent[attr] = (parent[attr] + value) % 4;
179
+ break;
180
+ case "hFlip":
181
+ case "vFlip":
182
+ parent[attr] = !parent[attr];
183
+ break;
184
+ default:
185
+ parent[attr] = value;
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ }
191
+ return parent;
192
+ }
193
+ default:
194
+ return null;
195
+ }
196
+ }
197
+ const result = getIcon(name, 0);
198
+ return result && full ? icon.fullIcon(result) : result;
199
+ }
200
+ toString(name, custommisations = {
201
+ width: "auto",
202
+ height: "auto"
203
+ }) {
204
+ const item = this.resolve(name, true);
205
+ if (!item) {
206
+ return null;
207
+ }
208
+ const result = build.iconToSVG(item, {
209
+ ...customisations.defaults,
210
+ ...custommisations
211
+ });
212
+ const attributes = Object.keys(result.attributes).map((key) => ` ${key}="${result.attributes[key]}"`).join("");
213
+ return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
214
+ }
215
+ toSVG(name) {
216
+ const html = this.toString(name);
217
+ return html ? new svg_index.SVG(html) : null;
218
+ }
219
+ export(validate = true) {
220
+ const icons = /* @__PURE__ */ Object.create(null);
221
+ const aliases = /* @__PURE__ */ Object.create(null);
222
+ const names = Object.keys(this.entries);
223
+ names.sort((a, b) => a.localeCompare(b));
224
+ names.forEach((name) => {
225
+ const item = this.entries[name];
226
+ switch (item.type) {
227
+ case "icon": {
228
+ const icon = {
229
+ body: item.body,
230
+ ...item.props
231
+ };
232
+ icons[name] = icon;
233
+ break;
234
+ }
235
+ case "alias":
236
+ case "variation": {
237
+ if (validate && !this.resolve(name)) {
238
+ break;
239
+ }
240
+ const props = item.type === "variation" ? item.props : {};
241
+ const alias = {
242
+ parent: item.parent,
243
+ ...props
244
+ };
245
+ aliases[name] = alias;
246
+ break;
247
+ }
248
+ }
249
+ });
250
+ let info;
251
+ if (this.info) {
252
+ this.info.total = this.count();
253
+ info = JSON.parse(JSON.stringify(this.info));
254
+ }
255
+ const result = {
256
+ prefix: this.prefix
257
+ };
258
+ if (info) {
259
+ result.info = info;
260
+ }
261
+ result.icons = icons;
262
+ if (Object.keys(aliases).length) {
263
+ result.aliases = aliases;
264
+ }
265
+ const chars = this.chars(Object.keys(icons).concat(Object.keys(aliases)));
266
+ if (Object.keys(chars).length) {
267
+ result.chars = chars;
268
+ }
269
+ const categories = /* @__PURE__ */ Object.create(null);
270
+ Array.from(this.categories).sort((a, b) => a.title.localeCompare(b.title)).forEach((item) => {
271
+ const names2 = this.listCategory(item);
272
+ if (names2) {
273
+ names2.sort((a, b) => a.localeCompare(b));
274
+ categories[item.title] = names2;
275
+ }
276
+ });
277
+ if (Object.keys(categories).length) {
278
+ result.categories = categories;
279
+ }
280
+ themeKeys.forEach((prop) => {
281
+ const items = this[prop];
282
+ const keys = Object.keys(items);
283
+ if (keys.length) {
284
+ sortThemeKeys(keys);
285
+ const sortedTheme = /* @__PURE__ */ Object.create(null);
286
+ const tested = this.checkTheme(prop === "prefixes");
287
+ keys.forEach((key) => {
288
+ if (tested.valid[key].length) {
289
+ sortedTheme[key] = items[key];
290
+ }
291
+ });
292
+ if (Object.keys(sortedTheme).length) {
293
+ result[prop] = sortedTheme;
294
+ }
295
+ }
296
+ });
297
+ minify.minifyIconSet(result);
298
+ return result;
299
+ }
300
+ chars(names) {
301
+ const chars = /* @__PURE__ */ Object.create(null);
302
+ if (!names) {
303
+ names = Object.keys(this.entries);
304
+ }
305
+ for (let i = 0; i < names.length; i++) {
306
+ const name = names[i];
307
+ const item = this.entries[name];
308
+ item.chars.forEach((char) => {
309
+ chars[char] = name;
310
+ });
311
+ }
312
+ return chars;
313
+ }
314
+ _filter(callback) {
315
+ const names = [];
316
+ for (const key in this.entries) {
317
+ const item = this.entries[key];
318
+ switch (item.type) {
319
+ case "icon": {
320
+ if (callback(key, item)) {
321
+ names.push(key);
322
+ }
323
+ break;
324
+ }
325
+ case "variation":
326
+ case "alias": {
327
+ const icon = this.resolve(key);
328
+ if (icon && callback(key, item, icon)) {
329
+ names.push(key);
330
+ }
331
+ break;
332
+ }
333
+ }
334
+ }
335
+ return names;
336
+ }
337
+ count() {
338
+ return this._filter((_key, item, icon) => {
339
+ if (item.type === "alias" || item.props.hidden || icon?.hidden) {
340
+ return false;
341
+ }
342
+ return true;
343
+ }).length;
344
+ }
345
+ _findCategory(title, add) {
346
+ const categoryItem = Array.from(this.categories).find((item) => item.title === title);
347
+ if (categoryItem) {
348
+ return categoryItem;
349
+ }
350
+ if (add) {
351
+ const newItem = {
352
+ title,
353
+ count: 0
354
+ };
355
+ this.categories.add(newItem);
356
+ return newItem;
357
+ }
358
+ return null;
359
+ }
360
+ listCategory(category) {
361
+ const categoryItem = typeof category === "string" ? this._findCategory(category, false) : category;
362
+ if (!categoryItem) {
363
+ return null;
364
+ }
365
+ const icons = this._filter((_key, item) => {
366
+ if (item.type !== "icon" || item.props.hidden) {
367
+ return false;
368
+ }
369
+ return item.categories.has(categoryItem);
370
+ });
371
+ const count = icons.length;
372
+ categoryItem.count = count;
373
+ if (!count) {
374
+ this.categories.delete(categoryItem);
375
+ return null;
376
+ }
377
+ return icons;
378
+ }
379
+ exists(name) {
380
+ return !!this.entries[name];
381
+ }
382
+ remove(name, removeDependencies = true) {
383
+ const entries = this.entries;
384
+ const names = /* @__PURE__ */ new Set();
385
+ if (typeof removeDependencies === "string") {
386
+ if (name === removeDependencies || !entries[removeDependencies]) {
387
+ return 0;
388
+ }
389
+ names.add(removeDependencies);
390
+ }
391
+ function del(name2, iteration) {
392
+ if (entries[name2] === void 0 || iteration > maxIteration || names.has(name2)) {
393
+ return false;
394
+ }
395
+ names.add(name2);
396
+ if (removeDependencies === true || !iteration && typeof removeDependencies === "string") {
397
+ for (const key in entries) {
398
+ const item = entries[key];
399
+ switch (item.type) {
400
+ case "icon":
401
+ break;
402
+ case "alias":
403
+ case "variation":
404
+ if (item.parent === name2) {
405
+ if (removeDependencies === true) {
406
+ if (!del(key, iteration + 1)) {
407
+ return false;
408
+ }
409
+ break;
410
+ }
411
+ item.parent = removeDependencies;
412
+ }
413
+ break;
414
+ }
415
+ }
416
+ }
417
+ return true;
418
+ }
419
+ if (del(name, 0)) {
420
+ if (typeof removeDependencies === "string") {
421
+ names.delete(removeDependencies);
422
+ }
423
+ names.forEach((name2) => {
424
+ delete entries[name2];
425
+ });
426
+ return names.size;
427
+ }
428
+ return 0;
429
+ }
430
+ rename(oldName, newName) {
431
+ const entries = this.entries;
432
+ if (entries[newName]) {
433
+ if (!this.remove(newName)) {
434
+ return false;
435
+ }
436
+ }
437
+ if (!entries[oldName]) {
438
+ return false;
439
+ }
440
+ entries[newName] = entries[oldName];
441
+ delete entries[oldName];
442
+ for (const key in entries) {
443
+ const item = entries[key];
444
+ switch (item.type) {
445
+ case "icon":
446
+ break;
447
+ case "alias":
448
+ case "variation":
449
+ if (item.parent === oldName) {
450
+ item.parent = newName;
451
+ }
452
+ break;
453
+ }
454
+ }
455
+ return true;
456
+ }
457
+ setItem(name, item) {
458
+ switch (item.type) {
459
+ case "alias":
460
+ case "variation": {
461
+ if (!this.entries[item.parent]) {
462
+ return false;
463
+ }
464
+ }
465
+ }
466
+ this.entries[name] = item;
467
+ return true;
468
+ }
469
+ setIcon(name, icon) {
470
+ return this.setItem(name, {
471
+ type: "icon",
472
+ body: icon.body,
473
+ props: iconSet_props.filterProps(icon, true),
474
+ chars: /* @__PURE__ */ new Set(),
475
+ categories: /* @__PURE__ */ new Set()
476
+ });
477
+ }
478
+ setAlias(name, parent) {
479
+ return this.setItem(name, {
480
+ type: "alias",
481
+ parent,
482
+ chars: /* @__PURE__ */ new Set()
483
+ });
484
+ }
485
+ setVariation(name, parent, props) {
486
+ return this.setItem(name, {
487
+ type: "variation",
488
+ parent,
489
+ props,
490
+ chars: /* @__PURE__ */ new Set()
491
+ });
492
+ }
493
+ fromSVG(name, svg) {
494
+ const props = svg.viewBox;
495
+ const body = svg.getBody();
496
+ const item = this.entries[name];
497
+ switch (item?.type) {
498
+ case "icon":
499
+ case "variation": {
500
+ for (const key in iconSet_props.extraDefaultProps) {
501
+ const prop = key;
502
+ if (item.props[prop]) {
503
+ props[prop] = item.props[prop];
504
+ }
505
+ }
506
+ return this.setItem(name, {
507
+ type: "icon",
508
+ body,
509
+ props,
510
+ chars: item.chars,
511
+ categories: item.type === "icon" ? item.categories : /* @__PURE__ */ new Set()
512
+ });
513
+ }
514
+ }
515
+ return this.setIcon(name, {
516
+ body,
517
+ ...props
518
+ });
519
+ }
520
+ toggleCharacter(iconName, char, add) {
521
+ const item = this.entries[iconName];
522
+ if (!item) {
523
+ return false;
524
+ }
525
+ if (item.chars.has(char) !== add) {
526
+ item.chars[add ? "add" : "delete"](char);
527
+ return true;
528
+ }
529
+ return false;
530
+ }
531
+ toggleCategory(iconName, category, add) {
532
+ const item = this.entries[iconName];
533
+ const categoryItem = this._findCategory(category, add);
534
+ if (!item || !categoryItem) {
535
+ return false;
536
+ }
537
+ switch (item.type) {
538
+ case "icon":
539
+ if (item.categories.has(categoryItem) !== add) {
540
+ categoryItem.count += add ? 1 : -1;
541
+ item.categories[add ? "add" : "delete"](categoryItem);
542
+ return true;
543
+ }
544
+ }
545
+ return false;
546
+ }
547
+ checkTheme(prefix) {
548
+ const themes = prefix ? this.prefixes : this.suffixes;
549
+ const keys = sortThemeKeys(Object.keys(themes));
550
+ const results = {
551
+ valid: /* @__PURE__ */ Object.create(null),
552
+ invalid: []
553
+ };
554
+ keys.forEach((key) => {
555
+ results.valid[key] = [];
556
+ });
557
+ results.invalid = this._filter((name, item, icon) => {
558
+ if (item.type === "alias" || item.props.hidden || icon?.hidden) {
559
+ return false;
560
+ }
561
+ for (let i = 0; i < keys.length; i++) {
562
+ const search = keys[i];
563
+ if (search === "") {
564
+ results.valid[search].push(name);
565
+ return false;
566
+ }
567
+ const match = prefix ? search + "-" : "-" + search;
568
+ const length = match.length;
569
+ const test = prefix ? name.slice(0, length) : name.slice(0 - length);
570
+ if (test === match) {
571
+ results.valid[search].push(name);
572
+ return false;
573
+ }
574
+ }
575
+ return true;
576
+ });
577
+ return results;
578
+ }
579
+ }
580
+ function blankIconSet(prefix) {
581
+ return new IconSet({
582
+ prefix,
583
+ icons: {}
584
+ });
585
+ }
586
+
587
+ exports.IconSet = IconSet;
588
+ exports.blankIconSet = blankIconSet;
589
+ exports.sortThemeKeys = sortThemeKeys;
@@ -1,17 +1,18 @@
1
- import type { IconifyJSON, IconifyInfo } from '@iconify/types';
1
+ import { IconifyInfo, IconifyJSON } from '@iconify/types';
2
2
  import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations';
3
- import type { CheckThemeResult, CommonIconProps, IconCategory, IconSetAsyncForEachCallback, IconSetIconEntry, IconSetIconType, ResolvedIconifyIcon } from './types';
4
- import { SVG } from '../svg';
3
+ import { IconSetIconEntry, IconCategory, IconSetIconType, IconSetAsyncForEachCallback, ResolvedIconifyIcon, CommonIconProps, CheckThemeResult } from './types.js';
4
+ import { SVG } from '../svg/index.js';
5
+
5
6
  /**
6
7
  * Sort theme keys: long keys first
7
8
  *
8
9
  * Applies changes to parameter, but also returns it
9
10
  */
10
- export declare function sortThemeKeys(keys: string[]): string[];
11
+ declare function sortThemeKeys(keys: string[]): string[];
11
12
  /**
12
13
  * Export icon set
13
14
  */
14
- export declare class IconSet {
15
+ declare class IconSet {
15
16
  /**
16
17
  * Properties. You can write directly to almost any property, but avoid writing to
17
18
  * 'entries' and 'categories' properties, there are functions for that.
@@ -131,4 +132,6 @@ export declare class IconSet {
131
132
  /**
132
133
  * Create blank icon set
133
134
  */
134
- export declare function blankIconSet(prefix: string): IconSet;
135
+ declare function blankIconSet(prefix: string): IconSet;
136
+
137
+ export { IconSet, blankIconSet, sortThemeKeys };