@iconify/tools 2.0.15 → 2.0.18

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.
@@ -42,6 +42,9 @@ 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
50
  const props = iconSet_props.filterProps(item, false);
@@ -281,7 +284,6 @@ class IconSet {
281
284
  const items = this[prop];
282
285
  const keys = Object.keys(items);
283
286
  if (keys.length) {
284
- sortThemeKeys(keys);
285
287
  const sortedTheme = /* @__PURE__ */ Object.create(null);
286
288
  const tested = this.checkTheme(prop === "prefixes");
287
289
  keys.forEach((key) => {
@@ -342,7 +344,7 @@ class IconSet {
342
344
  return true;
343
345
  }).length;
344
346
  }
345
- _findCategory(title, add) {
347
+ findCategory(title, add) {
346
348
  const categoryItem = Array.from(this.categories).find((item) => item.title === title);
347
349
  if (categoryItem) {
348
350
  return categoryItem;
@@ -358,7 +360,7 @@ class IconSet {
358
360
  return null;
359
361
  }
360
362
  listCategory(category) {
361
- const categoryItem = typeof category === "string" ? this._findCategory(category, false) : category;
363
+ const categoryItem = typeof category === "string" ? this.findCategory(category, false) : category;
362
364
  if (!categoryItem) {
363
365
  return null;
364
366
  }
@@ -530,7 +532,7 @@ class IconSet {
530
532
  }
531
533
  toggleCategory(iconName, category, add) {
532
534
  const item = this.entries[iconName];
533
- const categoryItem = this._findCategory(category, add);
535
+ const categoryItem = this.findCategory(category, add);
534
536
  if (!item || !categoryItem) {
535
537
  return false;
536
538
  }
@@ -75,7 +75,7 @@ declare class IconSet {
75
75
  /**
76
76
  * Find category by title
77
77
  */
78
- _findCategory(title: string, add: boolean): IconCategory | null;
78
+ findCategory(title: string, add: boolean): IconCategory | null;
79
79
  /**
80
80
  * Count icons in category, remove category if empty
81
81
  *
@@ -38,6 +38,9 @@ class IconSet {
38
38
  }
39
39
  if (data.aliases) {
40
40
  for (const name in data.aliases) {
41
+ if (entries[name]) {
42
+ continue;
43
+ }
41
44
  const item = data.aliases[name];
42
45
  const parent = item.parent;
43
46
  const props = filterProps(item, false);
@@ -277,7 +280,6 @@ class IconSet {
277
280
  const items = this[prop];
278
281
  const keys = Object.keys(items);
279
282
  if (keys.length) {
280
- sortThemeKeys(keys);
281
283
  const sortedTheme = /* @__PURE__ */ Object.create(null);
282
284
  const tested = this.checkTheme(prop === "prefixes");
283
285
  keys.forEach((key) => {
@@ -338,7 +340,7 @@ class IconSet {
338
340
  return true;
339
341
  }).length;
340
342
  }
341
- _findCategory(title, add) {
343
+ findCategory(title, add) {
342
344
  const categoryItem = Array.from(this.categories).find((item) => item.title === title);
343
345
  if (categoryItem) {
344
346
  return categoryItem;
@@ -354,7 +356,7 @@ class IconSet {
354
356
  return null;
355
357
  }
356
358
  listCategory(category) {
357
- const categoryItem = typeof category === "string" ? this._findCategory(category, false) : category;
359
+ const categoryItem = typeof category === "string" ? this.findCategory(category, false) : category;
358
360
  if (!categoryItem) {
359
361
  return null;
360
362
  }
@@ -526,7 +528,7 @@ class IconSet {
526
528
  }
527
529
  toggleCategory(iconName, category, add) {
528
530
  const item = this.entries[iconName];
529
- const categoryItem = this._findCategory(category, add);
531
+ const categoryItem = this.findCategory(category, add);
530
532
  if (!item || !categoryItem) {
531
533
  return false;
532
534
  }
@@ -7,7 +7,7 @@ import '../svg/index.js';
7
7
  /**
8
8
  * Entry for file
9
9
  */
10
- interface ImportDirectpryFileEntry {
10
+ interface ImportDirectoryFileEntry {
11
11
  path: string;
12
12
  subdir: string;
13
13
  file: string;
@@ -23,7 +23,7 @@ interface ImportDirectpryFileEntry {
23
23
  * Callback can be asynchronous
24
24
  */
25
25
  declare type ImportDirectoryKeywordCallbackResult = string | undefined;
26
- declare type ImportDirectoryKeywordCallback = (file: ImportDirectpryFileEntry, defaultKeyword: string, iconSet: IconSet) => ImportDirectoryKeywordCallbackResult | Promise<ImportDirectoryKeywordCallbackResult>;
26
+ declare type ImportDirectoryKeywordCallback = (file: ImportDirectoryFileEntry, defaultKeyword: string, iconSet: IconSet) => ImportDirectoryKeywordCallbackResult | Promise<ImportDirectoryKeywordCallbackResult>;
27
27
  /**
28
28
  * Options
29
29
  */
@@ -38,4 +38,4 @@ interface ImportDirectoryOptions {
38
38
  */
39
39
  declare function importDirectory(path: string, options?: ImportDirectoryOptions): Promise<IconSet>;
40
40
 
41
- export { ImportDirectoryKeywordCallback, ImportDirectpryFileEntry, importDirectory };
41
+ export { ImportDirectoryFileEntry, ImportDirectoryKeywordCallback, importDirectory };
package/lib/index.cjs CHANGED
@@ -27,6 +27,7 @@ const download_gitlab_hash = require('./download/gitlab/hash.cjs');
27
27
  const download_npm_index = require('./download/npm/index.cjs');
28
28
  const download_npm_version = require('./download/npm/version.cjs');
29
29
  const download_index = require('./download/index.cjs');
30
+ const download_api_download = require('./download/api/download.cjs');
30
31
  const colors_parse = require('./colors/parse.cjs');
31
32
  const colors_validate = require('./colors/validate.cjs');
32
33
  const optimise_svgo = require('./optimise/svgo.cjs');
@@ -74,7 +75,6 @@ require('crypto');
74
75
  require('node-fetch');
75
76
  require('pathe');
76
77
  require('child_process');
77
- require('./download/api/download.cjs');
78
78
  require('util');
79
79
  require('stream');
80
80
  require('extract-zip');
@@ -115,6 +115,7 @@ exports.downloadNPMPackage = download_npm_index.downloadNPMPackage;
115
115
  exports.getNPMVersion = download_npm_version.getNPMVersion;
116
116
  exports.getPackageVersion = download_npm_version.getPackageVersion;
117
117
  exports.downloadPackage = download_index.downloadPackage;
118
+ exports.downloadFile = download_api_download.downloadFile;
118
119
  exports.isEmptyColor = colors_parse.isEmptyColor;
119
120
  exports.parseColors = colors_parse.parseColors;
120
121
  exports.validateColors = colors_validate.validateColors;
package/lib/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export { getGitLabRepoHash } from './download/gitlab/hash.js';
23
23
  export { downloadNPMPackage } from './download/npm/index.js';
24
24
  export { getNPMVersion, getPackageVersion } from './download/npm/version.js';
25
25
  export { downloadPackage } from './download/index.js';
26
+ export { downloadFile } from './download/api/download.js';
26
27
  export { isEmptyColor, parseColors } from './colors/parse.js';
27
28
  export { validateColors } from './colors/validate.js';
28
29
  export { runSVGO } from './optimise/svgo.js';
@@ -56,10 +57,10 @@ import './download/types/sources.js';
56
57
  import './download/github/types.js';
57
58
  import './download/gitlab/types.js';
58
59
  import './download/npm/types.js';
60
+ import './download/api/types.js';
59
61
  import '@iconify/utils/lib/colors/types';
60
62
  import './colors/attribs.js';
61
63
  import 'svgo';
62
64
  import './export/helpers/custom-files.js';
63
65
  import 'fs';
64
66
  import 'child_process';
65
- import './download/api/types.js';
package/lib/index.mjs CHANGED
@@ -23,6 +23,7 @@ export { getGitLabRepoHash } from './download/gitlab/hash.mjs';
23
23
  export { downloadNPMPackage } from './download/npm/index.mjs';
24
24
  export { getNPMVersion, getPackageVersion } from './download/npm/version.mjs';
25
25
  export { downloadPackage } from './download/index.mjs';
26
+ export { downloadFile } from './download/api/download.mjs';
26
27
  export { isEmptyColor, parseColors } from './colors/parse.mjs';
27
28
  export { validateColors } from './colors/validate.mjs';
28
29
  export { runSVGO } from './optimise/svgo.mjs';
@@ -70,7 +71,6 @@ import 'crypto';
70
71
  import 'node-fetch';
71
72
  import 'pathe';
72
73
  import 'child_process';
73
- import './download/api/download.mjs';
74
74
  import 'util';
75
75
  import 'stream';
76
76
  import 'extract-zip';
@@ -4,48 +4,58 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const svgo = require('svgo');
6
6
 
7
- const defaultSVGOPlugins = [
8
- "cleanupAttrs",
9
- "mergeStyles",
10
- "inlineStyles",
11
- "removeComments",
12
- "removeUselessDefs",
13
- "removeEditorsNSData",
14
- "removeEmptyAttrs",
15
- "removeEmptyContainers",
16
- "convertStyleToAttrs",
17
- "convertColors",
18
- "convertTransform",
19
- "removeUnknownsAndDefaults",
20
- "removeNonInheritableGroupAttrs",
21
- "removeUselessStrokeAndFill",
22
- "removeUnusedNS",
23
- "cleanupNumericValues",
24
- "cleanupListOfValues",
25
- "moveElemsAttrsToGroup",
26
- "moveGroupAttrsToElems",
27
- "collapseGroups",
28
- "sortDefsChildren",
29
- "sortAttrs"
30
- ];
31
- const shapeModifiyingSVGOPlugins = [
32
- "removeHiddenElems",
33
- "convertShapeToPath",
34
- "convertEllipseToCircle",
35
- {
36
- name: "convertPathData",
37
- params: {
38
- noSpaceAfterFlags: true
39
- }
40
- },
41
- {
42
- name: "mergePaths",
43
- params: {
44
- noSpaceAfterFlags: true
45
- }
46
- },
47
- "reusePaths"
48
- ];
7
+ function getSVGOPlugins(options) {
8
+ return [
9
+ "cleanupAttrs",
10
+ "mergeStyles",
11
+ "inlineStyles",
12
+ "removeComments",
13
+ "removeUselessDefs",
14
+ "removeEditorsNSData",
15
+ "removeEmptyAttrs",
16
+ "removeEmptyContainers",
17
+ "convertStyleToAttrs",
18
+ "convertColors",
19
+ "convertTransform",
20
+ "removeUnknownsAndDefaults",
21
+ "removeNonInheritableGroupAttrs",
22
+ "removeUnusedNS",
23
+ "cleanupNumericValues",
24
+ "cleanupListOfValues",
25
+ "moveElemsAttrsToGroup",
26
+ "moveGroupAttrsToElems",
27
+ "collapseGroups",
28
+ "sortDefsChildren",
29
+ "sortAttrs",
30
+ ...options.animated ? [] : ["removeUselessStrokeAndFill"],
31
+ ...options.animated || options.keepShapes ? [] : [
32
+ "removeHiddenElems",
33
+ "convertShapeToPath",
34
+ "convertEllipseToCircle",
35
+ {
36
+ name: "convertPathData",
37
+ params: {
38
+ noSpaceAfterFlags: true
39
+ }
40
+ },
41
+ {
42
+ name: "mergePaths",
43
+ params: {
44
+ noSpaceAfterFlags: true
45
+ }
46
+ },
47
+ "reusePaths"
48
+ ],
49
+ ...options.cleanupIDs !== false ? [
50
+ {
51
+ name: "cleanupIDs",
52
+ params: {
53
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
54
+ }
55
+ }
56
+ ] : []
57
+ ];
58
+ }
49
59
  async function runSVGO(svg, options = {}) {
50
60
  const code = svg.toString();
51
61
  const multipass = options.multipass !== false;
@@ -53,18 +63,11 @@ async function runSVGO(svg, options = {}) {
53
63
  if (options.plugins) {
54
64
  plugins = options.plugins;
55
65
  } else {
56
- let keepShapes = options.keepShapes;
57
- if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
58
- keepShapes = true;
59
- }
60
- plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
61
- {
62
- name: "cleanupIDs",
63
- params: {
64
- prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
65
- }
66
- }
67
- ] : []);
66
+ const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
67
+ plugins = getSVGOPlugins({
68
+ ...options,
69
+ animated
70
+ });
68
71
  }
69
72
  const pluginOptions = {
70
73
  plugins,
@@ -78,6 +81,5 @@ async function runSVGO(svg, options = {}) {
78
81
  svg.load(content);
79
82
  }
80
83
 
81
- exports.defaultSVGOPlugins = defaultSVGOPlugins;
84
+ exports.getSVGOPlugins = getSVGOPlugins;
82
85
  exports.runSVGO = runSVGO;
83
- exports.shapeModifiyingSVGOPlugins = shapeModifiyingSVGOPlugins;
@@ -3,11 +3,17 @@ import { SVG } from '../svg/index.js';
3
3
  import '@iconify/types';
4
4
  import '@iconify/utils/lib/customisations';
5
5
 
6
- declare const defaultSVGOPlugins: Plugin[];
6
+ interface CleanupIDsOption {
7
+ cleanupIDs?: string | false;
8
+ }
9
+ interface GetSVGOPluingOptions extends CleanupIDsOption {
10
+ animated?: boolean;
11
+ keepShapes?: boolean;
12
+ }
7
13
  /**
8
- * Plugins that modify shapes. Added to plugins list, unless 'keepShapes' option is enabled
14
+ * Get list of plugins
9
15
  */
10
- declare const shapeModifiyingSVGOPlugins: Plugin[];
16
+ declare function getSVGOPlugins(options: GetSVGOPluingOptions): Plugin[];
11
17
  /**
12
18
  * Options
13
19
  */
@@ -17,10 +23,9 @@ interface SVGOCommonOptions {
17
23
  interface SVGOOptionsWithPlugin extends SVGOCommonOptions {
18
24
  plugins: Plugin[];
19
25
  }
20
- interface SVGOptionsWithoutPlugin extends SVGOCommonOptions {
26
+ interface SVGOptionsWithoutPlugin extends SVGOCommonOptions, CleanupIDsOption {
21
27
  plugins?: undefined;
22
28
  keepShapes?: boolean;
23
- cleanupIDs?: string | false;
24
29
  }
25
30
  declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
26
31
  /**
@@ -28,4 +33,4 @@ declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
28
33
  */
29
34
  declare function runSVGO(svg: SVG, options?: SVGOOptions): Promise<void>;
30
35
 
31
- export { defaultSVGOPlugins, runSVGO, shapeModifiyingSVGOPlugins };
36
+ export { getSVGOPlugins, runSVGO };
@@ -1,47 +1,57 @@
1
1
  import { optimize } from 'svgo';
2
2
 
3
- const defaultSVGOPlugins = [
4
- "cleanupAttrs",
5
- "mergeStyles",
6
- "inlineStyles",
7
- "removeComments",
8
- "removeUselessDefs",
9
- "removeEditorsNSData",
10
- "removeEmptyAttrs",
11
- "removeEmptyContainers",
12
- "convertStyleToAttrs",
13
- "convertColors",
14
- "convertTransform",
15
- "removeUnknownsAndDefaults",
16
- "removeNonInheritableGroupAttrs",
17
- "removeUselessStrokeAndFill",
18
- "removeUnusedNS",
19
- "cleanupNumericValues",
20
- "cleanupListOfValues",
21
- "moveElemsAttrsToGroup",
22
- "moveGroupAttrsToElems",
23
- "collapseGroups",
24
- "sortDefsChildren",
25
- "sortAttrs"
26
- ];
27
- const shapeModifiyingSVGOPlugins = [
28
- "removeHiddenElems",
29
- "convertShapeToPath",
30
- "convertEllipseToCircle",
31
- {
32
- name: "convertPathData",
33
- params: {
34
- noSpaceAfterFlags: true
35
- }
36
- },
37
- {
38
- name: "mergePaths",
39
- params: {
40
- noSpaceAfterFlags: true
41
- }
42
- },
43
- "reusePaths"
44
- ];
3
+ function getSVGOPlugins(options) {
4
+ return [
5
+ "cleanupAttrs",
6
+ "mergeStyles",
7
+ "inlineStyles",
8
+ "removeComments",
9
+ "removeUselessDefs",
10
+ "removeEditorsNSData",
11
+ "removeEmptyAttrs",
12
+ "removeEmptyContainers",
13
+ "convertStyleToAttrs",
14
+ "convertColors",
15
+ "convertTransform",
16
+ "removeUnknownsAndDefaults",
17
+ "removeNonInheritableGroupAttrs",
18
+ "removeUnusedNS",
19
+ "cleanupNumericValues",
20
+ "cleanupListOfValues",
21
+ "moveElemsAttrsToGroup",
22
+ "moveGroupAttrsToElems",
23
+ "collapseGroups",
24
+ "sortDefsChildren",
25
+ "sortAttrs",
26
+ ...options.animated ? [] : ["removeUselessStrokeAndFill"],
27
+ ...options.animated || options.keepShapes ? [] : [
28
+ "removeHiddenElems",
29
+ "convertShapeToPath",
30
+ "convertEllipseToCircle",
31
+ {
32
+ name: "convertPathData",
33
+ params: {
34
+ noSpaceAfterFlags: true
35
+ }
36
+ },
37
+ {
38
+ name: "mergePaths",
39
+ params: {
40
+ noSpaceAfterFlags: true
41
+ }
42
+ },
43
+ "reusePaths"
44
+ ],
45
+ ...options.cleanupIDs !== false ? [
46
+ {
47
+ name: "cleanupIDs",
48
+ params: {
49
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
50
+ }
51
+ }
52
+ ] : []
53
+ ];
54
+ }
45
55
  async function runSVGO(svg, options = {}) {
46
56
  const code = svg.toString();
47
57
  const multipass = options.multipass !== false;
@@ -49,18 +59,11 @@ async function runSVGO(svg, options = {}) {
49
59
  if (options.plugins) {
50
60
  plugins = options.plugins;
51
61
  } else {
52
- let keepShapes = options.keepShapes;
53
- if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
54
- keepShapes = true;
55
- }
56
- plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
57
- {
58
- name: "cleanupIDs",
59
- params: {
60
- prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
61
- }
62
- }
63
- ] : []);
62
+ const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
63
+ plugins = getSVGOPlugins({
64
+ ...options,
65
+ animated
66
+ });
64
67
  }
65
68
  const pluginOptions = {
66
69
  plugins,
@@ -74,4 +77,4 @@ async function runSVGO(svg, options = {}) {
74
77
  svg.load(content);
75
78
  }
76
79
 
77
- export { defaultSVGOPlugins, runSVGO, shapeModifiyingSVGOPlugins };
80
+ export { getSVGOPlugins, runSVGO };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "2.0.15",
6
+ "version": "2.0.18",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/iconify/tools/issues",
9
9
  "homepage": "https://github.com/iconify/tools",