@iconify/tools 2.0.16 → 2.1.0-beta.1

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 (73) hide show
  1. package/lib/colors/parse.d.ts +1 -1
  2. package/lib/colors/validate.d.ts +1 -1
  3. package/lib/download/git/branch.cjs +2 -3
  4. package/lib/download/git/branch.mjs +2 -3
  5. package/lib/download/git/hash.cjs +1 -0
  6. package/lib/download/git/hash.mjs +1 -0
  7. package/lib/download/git/index.cjs +4 -2
  8. package/lib/download/git/index.mjs +4 -2
  9. package/lib/download/git/reset.cjs +4 -2
  10. package/lib/download/git/reset.mjs +4 -2
  11. package/lib/download/index.cjs +4 -2
  12. package/lib/download/index.mjs +4 -2
  13. package/lib/download/npm/index.cjs +1 -0
  14. package/lib/download/npm/index.mjs +1 -0
  15. package/lib/download/npm/version.cjs +1 -0
  16. package/lib/download/npm/version.mjs +1 -0
  17. package/lib/export/directory.d.ts +4 -2
  18. package/lib/export/icon-package.d.ts +4 -2
  19. package/lib/export/json-package.cjs +2 -2
  20. package/lib/export/json-package.d.ts +4 -2
  21. package/lib/export/json-package.mjs +2 -2
  22. package/lib/icon-set/index.cjs +100 -106
  23. package/lib/icon-set/index.d.ts +24 -5
  24. package/lib/icon-set/index.mjs +101 -107
  25. package/lib/icon-set/match.cjs +5 -5
  26. package/lib/icon-set/match.d.ts +5 -3
  27. package/lib/icon-set/match.mjs +2 -2
  28. package/lib/icon-set/merge.cjs +10 -3
  29. package/lib/icon-set/merge.d.ts +4 -2
  30. package/lib/icon-set/merge.mjs +10 -3
  31. package/lib/icon-set/modified.cjs +27 -0
  32. package/lib/icon-set/modified.d.ts +16 -0
  33. package/lib/icon-set/modified.mjs +23 -0
  34. package/lib/icon-set/props.cjs +8 -18
  35. package/lib/icon-set/props.d.ts +5 -6
  36. package/lib/icon-set/props.mjs +9 -18
  37. package/lib/icon-set/types.d.ts +1 -1
  38. package/lib/import/directory.cjs +4 -3
  39. package/lib/import/directory.d.ts +7 -5
  40. package/lib/import/directory.mjs +4 -3
  41. package/lib/import/figma/index.cjs +4 -3
  42. package/lib/import/figma/index.d.ts +4 -2
  43. package/lib/import/figma/index.mjs +4 -3
  44. package/lib/import/figma/nodes.d.ts +4 -2
  45. package/lib/import/figma/query.d.ts +4 -2
  46. package/lib/import/figma/types/nodes.d.ts +4 -2
  47. package/lib/import/figma/types/options.d.ts +4 -2
  48. package/lib/import/figma/types/result.d.ts +4 -2
  49. package/lib/index.cjs +5 -2
  50. package/lib/index.d.ts +3 -1
  51. package/lib/index.mjs +5 -2
  52. package/lib/misc/exec.cjs +7 -2
  53. package/lib/misc/exec.mjs +7 -2
  54. package/lib/optimise/flags.d.ts +1 -1
  55. package/lib/optimise/global-style.d.ts +1 -1
  56. package/lib/optimise/scale.d.ts +1 -1
  57. package/lib/optimise/svgo.cjs +58 -56
  58. package/lib/optimise/svgo.d.ts +12 -7
  59. package/lib/optimise/svgo.mjs +58 -55
  60. package/lib/svg/analyse.d.ts +1 -1
  61. package/lib/svg/cleanup/attribs.d.ts +1 -1
  62. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  63. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  64. package/lib/svg/cleanup/root-svg.d.ts +1 -1
  65. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  66. package/lib/svg/cleanup.d.ts +1 -1
  67. package/lib/svg/index.cjs +7 -4
  68. package/lib/svg/index.d.ts +2 -2
  69. package/lib/svg/index.mjs +8 -5
  70. package/lib/svg/parse-style.d.ts +1 -1
  71. package/lib/svg/parse.d.ts +1 -1
  72. package/lib/types-f0980297.d.ts +258 -0
  73. package/package.json +6 -3
@@ -2,17 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const icon = require('@iconify/utils/lib/icon');
5
+ const defaults = require('@iconify/utils/lib/icon/defaults');
6
6
  const build = require('@iconify/utils/lib/svg/build');
7
- const customisations = require('@iconify/utils/lib/customisations');
7
+ const defaults$1 = require('@iconify/utils/lib/customisations/defaults');
8
8
  const minify = require('@iconify/utils/lib/icon-set/minify');
9
9
  const convertInfo = require('@iconify/utils/lib/icon-set/convert-info');
10
10
  const iconSet_props = require('./props.cjs');
11
11
  const svg_index = require('../svg/index.cjs');
12
+ const utils = require('@iconify/utils');
13
+ require('@iconify/utils/lib/misc/objects');
12
14
  require('cheerio');
13
- require('@iconify/utils');
14
15
 
15
- const maxIteration = 6;
16
16
  const themeKeys = ["prefixes", "suffixes"];
17
17
  function sortThemeKeys(keys) {
18
18
  return keys.sort((a, b) => a.length === b.length ? a.localeCompare(b) : b.length - a.length);
@@ -23,7 +23,7 @@ class IconSet {
23
23
  }
24
24
  load(data) {
25
25
  this.prefix = data.prefix;
26
- const defaultProps = iconSet_props.filterProps(data, true);
26
+ const defaultProps = iconSet_props.filterProps(data, defaults.defaultIconDimensions, true);
27
27
  this.entries = /* @__PURE__ */ Object.create(null);
28
28
  const entries = this.entries;
29
29
  for (const name in data.icons) {
@@ -34,7 +34,7 @@ class IconSet {
34
34
  props: iconSet_props.filterProps({
35
35
  ...defaultProps,
36
36
  ...item
37
- }, true),
37
+ }, iconSet_props.defaultCommonProps, true),
38
38
  chars: /* @__PURE__ */ new Set(),
39
39
  categories: /* @__PURE__ */ new Set()
40
40
  };
@@ -42,9 +42,12 @@ class IconSet {
42
42
  }
43
43
  if (data.aliases) {
44
44
  for (const name in data.aliases) {
45
+ if (entries[name]) {
46
+ continue;
47
+ }
45
48
  const item = data.aliases[name];
46
49
  const parent = item.parent;
47
- const props = iconSet_props.filterProps(item, false);
50
+ const props = iconSet_props.filterProps(item, iconSet_props.defaultCommonProps, false);
48
51
  const chars = /* @__PURE__ */ new Set();
49
52
  if (Object.keys(props).length) {
50
53
  const entry = {
@@ -121,6 +124,10 @@ class IconSet {
121
124
  }
122
125
  }
123
126
  });
127
+ this.lastModified = data.lastModified || 0;
128
+ }
129
+ updateLastModified(value) {
130
+ this.lastModified = value || Math.floor(Date.now() / 1e3);
124
131
  }
125
132
  list(types = ["icon", "variation"]) {
126
133
  return Object.keys(this.entries).filter((name) => {
@@ -144,60 +151,53 @@ class IconSet {
144
151
  }
145
152
  }
146
153
  }
147
- resolve(name, full = false) {
154
+ getTree(names) {
148
155
  const entries = this.entries;
149
- function getIcon(name2, iteration) {
150
- if (entries[name2] === void 0 || iteration > maxIteration) {
151
- return null;
156
+ const resolved = /* @__PURE__ */ Object.create(null);
157
+ function resolve(name) {
158
+ const item = entries[name];
159
+ if (!item) {
160
+ return resolved[name] = null;
152
161
  }
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;
162
+ if (item.type === "icon") {
163
+ return resolved[name] = [];
164
+ }
165
+ if (resolved[name] === void 0) {
166
+ resolved[name] = null;
167
+ const parent = item.parent;
168
+ const value = parent && resolve(parent);
169
+ if (value) {
170
+ resolved[name] = [parent].concat(value);
192
171
  }
193
- default:
194
- return null;
195
172
  }
173
+ return resolved[name];
196
174
  }
197
- const result = getIcon(name, 0);
198
- return result && full ? icon.fullIcon(result) : result;
175
+ (names || Object.keys(entries)).forEach(resolve);
176
+ return resolved;
199
177
  }
200
- toString(name, custommisations = {
178
+ resolve(name, full = false) {
179
+ const entries = this.entries;
180
+ const item = entries[name];
181
+ const tree = item && (item.type === "icon" ? [] : this.getTree([name])[name]);
182
+ if (!tree) {
183
+ return null;
184
+ }
185
+ let result = {};
186
+ function parse(name2) {
187
+ const item2 = entries[name2];
188
+ if (item2.type === "alias") {
189
+ return;
190
+ }
191
+ result = utils.mergeIconData(item2.props, result);
192
+ if (item2.type === "icon") {
193
+ result.body = item2.body;
194
+ }
195
+ }
196
+ parse(name);
197
+ tree.forEach(parse);
198
+ return result && full ? { ...defaults.defaultIconProps, ...result } : result;
199
+ }
200
+ toString(name, customisations = {
201
201
  width: "auto",
202
202
  height: "auto"
203
203
  }) {
@@ -206,8 +206,8 @@ class IconSet {
206
206
  return null;
207
207
  }
208
208
  const result = build.iconToSVG(item, {
209
- ...customisations.defaults,
210
- ...custommisations
209
+ ...defaults$1.defaultIconCustomisations,
210
+ ...customisations
211
211
  });
212
212
  const attributes = Object.keys(result.attributes).map((key) => ` ${key}="${result.attributes[key]}"`).join("");
213
213
  return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
@@ -219,6 +219,7 @@ class IconSet {
219
219
  export(validate = true) {
220
220
  const icons = /* @__PURE__ */ Object.create(null);
221
221
  const aliases = /* @__PURE__ */ Object.create(null);
222
+ const tree = validate ? this.getTree() : {};
222
223
  const names = Object.keys(this.entries);
223
224
  names.sort((a, b) => a.localeCompare(b));
224
225
  names.forEach((name) => {
@@ -234,7 +235,7 @@ class IconSet {
234
235
  }
235
236
  case "alias":
236
237
  case "variation": {
237
- if (validate && !this.resolve(name)) {
238
+ if (validate && !tree[name]) {
238
239
  break;
239
240
  }
240
241
  const props = item.type === "variation" ? item.props : {};
@@ -258,6 +259,9 @@ class IconSet {
258
259
  if (info) {
259
260
  result.info = info;
260
261
  }
262
+ if (this.lastModified) {
263
+ result.lastModified = this.lastModified;
264
+ }
261
265
  result.icons = icons;
262
266
  if (Object.keys(aliases).length) {
263
267
  result.aliases = aliases;
@@ -341,7 +345,7 @@ class IconSet {
341
345
  return true;
342
346
  }).length;
343
347
  }
344
- _findCategory(title, add) {
348
+ findCategory(title, add) {
345
349
  const categoryItem = Array.from(this.categories).find((item) => item.title === title);
346
350
  if (categoryItem) {
347
351
  return categoryItem;
@@ -357,7 +361,7 @@ class IconSet {
357
361
  return null;
358
362
  }
359
363
  listCategory(category) {
360
- const categoryItem = typeof category === "string" ? this._findCategory(category, false) : category;
364
+ const categoryItem = typeof category === "string" ? this.findCategory(category, false) : category;
361
365
  if (!categoryItem) {
362
366
  return null;
363
367
  }
@@ -380,51 +384,45 @@ class IconSet {
380
384
  }
381
385
  remove(name, removeDependencies = true) {
382
386
  const entries = this.entries;
383
- const names = /* @__PURE__ */ new Set();
384
387
  if (typeof removeDependencies === "string") {
385
- if (name === removeDependencies || !entries[removeDependencies]) {
388
+ const item2 = entries[removeDependencies];
389
+ if (name === removeDependencies || item2?.type !== "icon") {
386
390
  return 0;
387
391
  }
388
- names.add(removeDependencies);
389
392
  }
390
- function del(name2, iteration) {
391
- if (entries[name2] === void 0 || iteration > maxIteration || names.has(name2)) {
392
- return false;
393
- }
394
- names.add(name2);
395
- if (removeDependencies === true || !iteration && typeof removeDependencies === "string") {
396
- for (const key in entries) {
397
- const item = entries[key];
398
- switch (item.type) {
399
- case "icon":
400
- break;
401
- case "alias":
402
- case "variation":
403
- if (item.parent === name2) {
404
- if (removeDependencies === true) {
405
- if (!del(key, iteration + 1)) {
406
- return false;
407
- }
408
- break;
409
- }
410
- item.parent = removeDependencies;
411
- }
412
- break;
413
- }
414
- }
415
- }
416
- return true;
393
+ const item = entries[name];
394
+ if (!item) {
395
+ return 0;
417
396
  }
418
- if (del(name, 0)) {
419
- if (typeof removeDependencies === "string") {
420
- names.delete(removeDependencies);
397
+ this.updateLastModified();
398
+ if (typeof removeDependencies === "string") {
399
+ for (const key in entries) {
400
+ const item2 = entries[key];
401
+ if (item2.type !== "icon" && item2.parent === name) {
402
+ item2.parent = removeDependencies;
403
+ }
421
404
  }
422
- names.forEach((name2) => {
423
- delete entries[name2];
405
+ return 0;
406
+ }
407
+ delete entries[name];
408
+ let count = 1;
409
+ function remove(parent) {
410
+ const list = Object.keys(entries).filter((name2) => {
411
+ const item2 = entries[name2];
412
+ return item2.type !== "icon" && item2.parent === parent;
424
413
  });
425
- return names.size;
414
+ list.forEach((name2) => {
415
+ if (entries[name2]) {
416
+ delete entries[name2];
417
+ count++;
418
+ remove(name2);
419
+ }
420
+ });
421
+ }
422
+ if (removeDependencies === true) {
423
+ remove(name);
426
424
  }
427
- return 0;
425
+ return count;
428
426
  }
429
427
  rename(oldName, newName) {
430
428
  const entries = this.entries;
@@ -451,6 +449,7 @@ class IconSet {
451
449
  break;
452
450
  }
453
451
  }
452
+ this.updateLastModified();
454
453
  return true;
455
454
  }
456
455
  setItem(name, item) {
@@ -463,13 +462,14 @@ class IconSet {
463
462
  }
464
463
  }
465
464
  this.entries[name] = item;
465
+ this.updateLastModified();
466
466
  return true;
467
467
  }
468
468
  setIcon(name, icon) {
469
469
  return this.setItem(name, {
470
470
  type: "icon",
471
471
  body: icon.body,
472
- props: iconSet_props.filterProps(icon, true),
472
+ props: iconSet_props.filterProps(icon, iconSet_props.defaultCommonProps, true),
473
473
  chars: /* @__PURE__ */ new Set(),
474
474
  categories: /* @__PURE__ */ new Set()
475
475
  });
@@ -490,18 +490,12 @@ class IconSet {
490
490
  });
491
491
  }
492
492
  fromSVG(name, svg) {
493
- const props = svg.viewBox;
493
+ const props = { ...svg.viewBox };
494
494
  const body = svg.getBody();
495
495
  const item = this.entries[name];
496
496
  switch (item?.type) {
497
497
  case "icon":
498
498
  case "variation": {
499
- for (const key in iconSet_props.extraDefaultProps) {
500
- const prop = key;
501
- if (item.props[prop]) {
502
- props[prop] = item.props[prop];
503
- }
504
- }
505
499
  return this.setItem(name, {
506
500
  type: "icon",
507
501
  body,
@@ -529,7 +523,7 @@ class IconSet {
529
523
  }
530
524
  toggleCategory(iconName, category, add) {
531
525
  const item = this.entries[iconName];
532
- const categoryItem = this._findCategory(category, add);
526
+ const categoryItem = this.findCategory(category, add);
533
527
  if (!item || !categoryItem) {
534
528
  return false;
535
529
  }
@@ -1,7 +1,9 @@
1
- import { IconifyInfo, IconifyJSON } from '@iconify/types';
2
- import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations';
1
+ import { a as IconifyInfo, b as IconifyJSON } from '../types-f0980297.js';
2
+ import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations/defaults';
3
3
  import { IconSetIconEntry, IconCategory, IconSetIconType, IconSetAsyncForEachCallback, ResolvedIconifyIcon, CommonIconProps, CheckThemeResult } from './types.js';
4
4
  import { SVG } from '../svg/index.js';
5
+ import { ParentIconsTree } from '@iconify/utils/lib/icon-set/tree';
6
+ import '@iconify/utils/lib/customisations';
5
7
 
6
8
  /**
7
9
  * Sort theme keys: long keys first
@@ -18,6 +20,7 @@ declare class IconSet {
18
20
  * 'entries' and 'categories' properties, there are functions for that.
19
21
  */
20
22
  prefix: string;
23
+ lastModified: number;
21
24
  entries: Record<string, IconSetIconEntry>;
22
25
  info: IconifyInfo | undefined;
23
26
  categories: Set<IconCategory>;
@@ -31,6 +34,10 @@ declare class IconSet {
31
34
  * Load icon set
32
35
  */
33
36
  load(data: IconifyJSON): void;
37
+ /**
38
+ * Update last modification time
39
+ */
40
+ updateLastModified(value?: number): void;
34
41
  /**
35
42
  * List icons
36
43
  */
@@ -42,6 +49,18 @@ declare class IconSet {
42
49
  * Callback should return false to stop loop.
43
50
  */
44
51
  forEach(callback: IconSetAsyncForEachCallback, types?: IconSetIconType[]): Promise<void>;
52
+ /**
53
+ * Get parent icons tree
54
+ *
55
+ * Returns parent icons list for each icon, null if failed to resolve.
56
+ * In parent icons list, first element is a direct parent, last is icon. Does not include item.
57
+ *
58
+ * Examples:
59
+ * 'alias3': ['alias2', 'alias1', 'icon']
60
+ * 'icon': []
61
+ * 'bad-icon': null
62
+ */
63
+ getTree(names?: string[]): ParentIconsTree;
45
64
  /**
46
65
  * Resolve icon
47
66
  */
@@ -51,7 +70,7 @@ declare class IconSet {
51
70
  /**
52
71
  * Generate HTML
53
72
  */
54
- toString(name: string, custommisations?: IconifyIconCustomisations): string | null;
73
+ toString(name: string, customisations?: IconifyIconCustomisations): string | null;
55
74
  /**
56
75
  * Get SVG instance for icon
57
76
  */
@@ -75,7 +94,7 @@ declare class IconSet {
75
94
  /**
76
95
  * Find category by title
77
96
  */
78
- _findCategory(title: string, add: boolean): IconCategory | null;
97
+ findCategory(title: string, add: boolean): IconCategory | null;
79
98
  /**
80
99
  * Count icons in category, remove category if empty
81
100
  *
@@ -89,7 +108,7 @@ declare class IconSet {
89
108
  /**
90
109
  * Remove icons. Returns number of removed icons
91
110
  *
92
- * If removeDependencies is a string, it represents new parent for all aliases of removed icon.
111
+ * If removeDependencies is a string, it represents new parent for all aliases of removed icon. New parent cannot be alias or variation.
93
112
  */
94
113
  remove(name: string, removeDependencies?: boolean | string): number;
95
114
  /**