@iconify/tools 2.0.18 → 2.1.0-beta.3

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 (88) hide show
  1. package/lib/colors/parse.d.ts +2 -2
  2. package/lib/colors/validate.d.ts +2 -2
  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 -3
  8. package/lib/download/git/index.mjs +4 -3
  9. package/lib/download/git/reset.cjs +4 -3
  10. package/lib/download/git/reset.mjs +4 -3
  11. package/lib/download/index.cjs +4 -3
  12. package/lib/download/index.mjs +4 -3
  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 +3 -2
  18. package/lib/export/helpers/types-version.cjs +3 -13
  19. package/lib/export/helpers/types-version.mjs +3 -13
  20. package/lib/export/icon-package.cjs +1 -3
  21. package/lib/export/icon-package.d.ts +3 -2
  22. package/lib/export/icon-package.mjs +1 -3
  23. package/lib/export/json-package.cjs +3 -5
  24. package/lib/export/json-package.d.ts +3 -2
  25. package/lib/export/json-package.mjs +3 -5
  26. package/lib/icon-set/index.cjs +94 -103
  27. package/lib/icon-set/index.d.ts +22 -4
  28. package/lib/icon-set/index.mjs +95 -104
  29. package/lib/icon-set/match.cjs +5 -5
  30. package/lib/icon-set/match.d.ts +4 -3
  31. package/lib/icon-set/match.mjs +2 -2
  32. package/lib/icon-set/merge.cjs +10 -3
  33. package/lib/icon-set/merge.d.ts +3 -2
  34. package/lib/icon-set/merge.mjs +10 -3
  35. package/lib/icon-set/modified.cjs +27 -0
  36. package/lib/icon-set/modified.d.ts +15 -0
  37. package/lib/icon-set/modified.mjs +23 -0
  38. package/lib/icon-set/props.cjs +8 -18
  39. package/lib/icon-set/props.d.ts +5 -6
  40. package/lib/icon-set/props.mjs +9 -18
  41. package/lib/icon-set/types.d.ts +1 -1
  42. package/lib/import/directory.cjs +4 -3
  43. package/lib/import/directory.d.ts +3 -2
  44. package/lib/import/directory.mjs +4 -3
  45. package/lib/import/figma/index.cjs +4 -3
  46. package/lib/import/figma/index.d.ts +3 -2
  47. package/lib/import/figma/index.mjs +4 -3
  48. package/lib/import/figma/nodes.d.ts +3 -2
  49. package/lib/import/figma/query.d.ts +3 -2
  50. package/lib/import/figma/types/nodes.d.ts +3 -2
  51. package/lib/import/figma/types/options.d.ts +3 -2
  52. package/lib/import/figma/types/result.d.ts +3 -2
  53. package/lib/index.cjs +5 -4
  54. package/lib/index.d.ts +4 -2
  55. package/lib/index.mjs +5 -4
  56. package/lib/misc/bump-version.cjs +2 -2
  57. package/lib/misc/bump-version.mjs +2 -2
  58. package/lib/misc/cheerio.cjs +2 -0
  59. package/lib/misc/cheerio.d.ts +7 -0
  60. package/lib/misc/cheerio.mjs +1 -0
  61. package/lib/misc/exec.cjs +7 -2
  62. package/lib/misc/exec.mjs +7 -2
  63. package/lib/optimise/flags.cjs +8 -8
  64. package/lib/optimise/flags.d.ts +2 -2
  65. package/lib/optimise/flags.mjs +8 -8
  66. package/lib/optimise/global-style.d.ts +2 -2
  67. package/lib/optimise/scale.cjs +3 -3
  68. package/lib/optimise/scale.d.ts +3 -3
  69. package/lib/optimise/scale.mjs +3 -3
  70. package/lib/optimise/svgo.cjs +1 -1
  71. package/lib/optimise/svgo.d.ts +3 -3
  72. package/lib/optimise/svgo.mjs +1 -1
  73. package/lib/svg/analyse.d.ts +2 -2
  74. package/lib/svg/cleanup/attribs.d.ts +2 -2
  75. package/lib/svg/cleanup/bad-tags.d.ts +2 -2
  76. package/lib/svg/cleanup/inline-style.d.ts +2 -2
  77. package/lib/svg/cleanup/root-svg.d.ts +2 -2
  78. package/lib/svg/cleanup/svgo-style.cjs +1 -1
  79. package/lib/svg/cleanup/svgo-style.d.ts +2 -2
  80. package/lib/svg/cleanup/svgo-style.mjs +1 -1
  81. package/lib/svg/cleanup.d.ts +2 -2
  82. package/lib/svg/index.cjs +9 -9
  83. package/lib/svg/index.d.ts +4 -4
  84. package/lib/svg/index.mjs +10 -10
  85. package/lib/svg/parse-style.d.ts +3 -2
  86. package/lib/svg/parse.d.ts +4 -8
  87. package/lib/types-f0980297.d.ts +258 -0
  88. package/package.json +10 -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
  };
@@ -47,7 +47,7 @@ class IconSet {
47
47
  }
48
48
  const item = data.aliases[name];
49
49
  const parent = item.parent;
50
- const props = iconSet_props.filterProps(item, false);
50
+ const props = iconSet_props.filterProps(item, iconSet_props.defaultCommonProps, false);
51
51
  const chars = /* @__PURE__ */ new Set();
52
52
  if (Object.keys(props).length) {
53
53
  const entry = {
@@ -124,6 +124,10 @@ class IconSet {
124
124
  }
125
125
  }
126
126
  });
127
+ this.lastModified = data.lastModified || 0;
128
+ }
129
+ updateLastModified(value) {
130
+ this.lastModified = value || Math.floor(Date.now() / 1e3);
127
131
  }
128
132
  list(types = ["icon", "variation"]) {
129
133
  return Object.keys(this.entries).filter((name) => {
@@ -147,60 +151,53 @@ class IconSet {
147
151
  }
148
152
  }
149
153
  }
150
- resolve(name, full = false) {
154
+ getTree(names) {
151
155
  const entries = this.entries;
152
- function getIcon(name2, iteration) {
153
- if (entries[name2] === void 0 || iteration > maxIteration) {
154
- 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;
155
161
  }
156
- const item = entries[name2];
157
- switch (item.type) {
158
- case "icon": {
159
- const result2 = {
160
- body: item.body,
161
- ...item.props
162
- };
163
- return result2;
164
- }
165
- case "alias":
166
- return getIcon(item.parent, iteration + 1);
167
- case "variation": {
168
- const parent = getIcon(item.parent, iteration + 1);
169
- if (!parent) {
170
- return null;
171
- }
172
- for (const key in item.props) {
173
- const attr = key;
174
- const value = item.props[attr];
175
- if (value) {
176
- if (parent[attr] === void 0) {
177
- parent[attr] = value;
178
- } else {
179
- switch (attr) {
180
- case "rotate":
181
- parent[attr] = (parent[attr] + value) % 4;
182
- break;
183
- case "hFlip":
184
- case "vFlip":
185
- parent[attr] = !parent[attr];
186
- break;
187
- default:
188
- parent[attr] = value;
189
- break;
190
- }
191
- }
192
- }
193
- }
194
- 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);
195
171
  }
196
- default:
197
- return null;
172
+ }
173
+ return resolved[name];
174
+ }
175
+ (names || Object.keys(entries)).forEach(resolve);
176
+ return resolved;
177
+ }
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;
198
194
  }
199
195
  }
200
- const result = getIcon(name, 0);
201
- return result && full ? icon.fullIcon(result) : result;
196
+ parse(name);
197
+ tree.forEach(parse);
198
+ return result && full ? { ...defaults.defaultIconProps, ...result } : result;
202
199
  }
203
- toString(name, custommisations = {
200
+ toString(name, customisations = {
204
201
  width: "auto",
205
202
  height: "auto"
206
203
  }) {
@@ -209,8 +206,8 @@ class IconSet {
209
206
  return null;
210
207
  }
211
208
  const result = build.iconToSVG(item, {
212
- ...customisations.defaults,
213
- ...custommisations
209
+ ...defaults$1.defaultIconCustomisations,
210
+ ...customisations
214
211
  });
215
212
  const attributes = Object.keys(result.attributes).map((key) => ` ${key}="${result.attributes[key]}"`).join("");
216
213
  return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${attributes}>${result.body}</svg>`;
@@ -222,6 +219,7 @@ class IconSet {
222
219
  export(validate = true) {
223
220
  const icons = /* @__PURE__ */ Object.create(null);
224
221
  const aliases = /* @__PURE__ */ Object.create(null);
222
+ const tree = validate ? this.getTree() : /* @__PURE__ */ Object.create(null);
225
223
  const names = Object.keys(this.entries);
226
224
  names.sort((a, b) => a.localeCompare(b));
227
225
  names.forEach((name) => {
@@ -237,7 +235,7 @@ class IconSet {
237
235
  }
238
236
  case "alias":
239
237
  case "variation": {
240
- if (validate && !this.resolve(name)) {
238
+ if (validate && !tree[name]) {
241
239
  break;
242
240
  }
243
241
  const props = item.type === "variation" ? item.props : {};
@@ -261,6 +259,9 @@ class IconSet {
261
259
  if (info) {
262
260
  result.info = info;
263
261
  }
262
+ if (this.lastModified) {
263
+ result.lastModified = this.lastModified;
264
+ }
264
265
  result.icons = icons;
265
266
  if (Object.keys(aliases).length) {
266
267
  result.aliases = aliases;
@@ -383,51 +384,45 @@ class IconSet {
383
384
  }
384
385
  remove(name, removeDependencies = true) {
385
386
  const entries = this.entries;
386
- const names = /* @__PURE__ */ new Set();
387
387
  if (typeof removeDependencies === "string") {
388
- if (name === removeDependencies || !entries[removeDependencies]) {
388
+ const item2 = entries[removeDependencies];
389
+ if (name === removeDependencies || item2?.type !== "icon") {
389
390
  return 0;
390
391
  }
391
- names.add(removeDependencies);
392
392
  }
393
- function del(name2, iteration) {
394
- if (entries[name2] === void 0 || iteration > maxIteration || names.has(name2)) {
395
- return false;
396
- }
397
- names.add(name2);
398
- if (removeDependencies === true || !iteration && typeof removeDependencies === "string") {
399
- for (const key in entries) {
400
- const item = entries[key];
401
- switch (item.type) {
402
- case "icon":
403
- break;
404
- case "alias":
405
- case "variation":
406
- if (item.parent === name2) {
407
- if (removeDependencies === true) {
408
- if (!del(key, iteration + 1)) {
409
- return false;
410
- }
411
- break;
412
- }
413
- item.parent = removeDependencies;
414
- }
415
- break;
416
- }
417
- }
418
- }
419
- return true;
393
+ const item = entries[name];
394
+ if (!item) {
395
+ return 0;
420
396
  }
421
- if (del(name, 0)) {
422
- if (typeof removeDependencies === "string") {
423
- 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
+ }
424
404
  }
425
- names.forEach((name2) => {
426
- 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;
427
413
  });
428
- 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);
429
424
  }
430
- return 0;
425
+ return count;
431
426
  }
432
427
  rename(oldName, newName) {
433
428
  const entries = this.entries;
@@ -454,6 +449,7 @@ class IconSet {
454
449
  break;
455
450
  }
456
451
  }
452
+ this.updateLastModified();
457
453
  return true;
458
454
  }
459
455
  setItem(name, item) {
@@ -466,13 +462,14 @@ class IconSet {
466
462
  }
467
463
  }
468
464
  this.entries[name] = item;
465
+ this.updateLastModified();
469
466
  return true;
470
467
  }
471
468
  setIcon(name, icon) {
472
469
  return this.setItem(name, {
473
470
  type: "icon",
474
471
  body: icon.body,
475
- props: iconSet_props.filterProps(icon, true),
472
+ props: iconSet_props.filterProps(icon, iconSet_props.defaultCommonProps, true),
476
473
  chars: /* @__PURE__ */ new Set(),
477
474
  categories: /* @__PURE__ */ new Set()
478
475
  });
@@ -493,18 +490,12 @@ class IconSet {
493
490
  });
494
491
  }
495
492
  fromSVG(name, svg) {
496
- const props = svg.viewBox;
493
+ const props = { ...svg.viewBox };
497
494
  const body = svg.getBody();
498
495
  const item = this.entries[name];
499
496
  switch (item?.type) {
500
497
  case "icon":
501
498
  case "variation": {
502
- for (const key in iconSet_props.extraDefaultProps) {
503
- const prop = key;
504
- if (item.props[prop]) {
505
- props[prop] = item.props[prop];
506
- }
507
- }
508
499
  return this.setItem(name, {
509
500
  type: "icon",
510
501
  body,
@@ -1,7 +1,8 @@
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';
5
6
 
6
7
  /**
7
8
  * Sort theme keys: long keys first
@@ -18,6 +19,7 @@ declare class IconSet {
18
19
  * 'entries' and 'categories' properties, there are functions for that.
19
20
  */
20
21
  prefix: string;
22
+ lastModified: number;
21
23
  entries: Record<string, IconSetIconEntry>;
22
24
  info: IconifyInfo | undefined;
23
25
  categories: Set<IconCategory>;
@@ -31,6 +33,10 @@ declare class IconSet {
31
33
  * Load icon set
32
34
  */
33
35
  load(data: IconifyJSON): void;
36
+ /**
37
+ * Update last modification time
38
+ */
39
+ updateLastModified(value?: number): void;
34
40
  /**
35
41
  * List icons
36
42
  */
@@ -42,6 +48,18 @@ declare class IconSet {
42
48
  * Callback should return false to stop loop.
43
49
  */
44
50
  forEach(callback: IconSetAsyncForEachCallback, types?: IconSetIconType[]): Promise<void>;
51
+ /**
52
+ * Get parent icons tree
53
+ *
54
+ * Returns parent icons list for each icon, null if failed to resolve.
55
+ * In parent icons list, first element is a direct parent, last is icon. Does not include item.
56
+ *
57
+ * Examples:
58
+ * 'alias3': ['alias2', 'alias1', 'icon']
59
+ * 'icon': []
60
+ * 'bad-icon': null
61
+ */
62
+ getTree(names?: string[]): ParentIconsTree;
45
63
  /**
46
64
  * Resolve icon
47
65
  */
@@ -51,7 +69,7 @@ declare class IconSet {
51
69
  /**
52
70
  * Generate HTML
53
71
  */
54
- toString(name: string, custommisations?: IconifyIconCustomisations): string | null;
72
+ toString(name: string, customisations?: IconifyIconCustomisations): string | null;
55
73
  /**
56
74
  * Get SVG instance for icon
57
75
  */
@@ -89,7 +107,7 @@ declare class IconSet {
89
107
  /**
90
108
  * Remove icons. Returns number of removed icons
91
109
  *
92
- * If removeDependencies is a string, it represents new parent for all aliases of removed icon.
110
+ * If removeDependencies is a string, it represents new parent for all aliases of removed icon. New parent cannot be alias or variation.
93
111
  */
94
112
  remove(name: string, removeDependencies?: boolean | string): number;
95
113
  /**