@iconify/tools 3.0.5 → 4.0.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 (79) hide show
  1. package/lib/colors/detect.cjs +1 -1
  2. package/lib/colors/detect.d.ts +1 -0
  3. package/lib/colors/detect.mjs +2 -2
  4. package/lib/colors/parse.cjs +131 -275
  5. package/lib/colors/parse.d.ts +8 -15
  6. package/lib/colors/parse.mjs +135 -278
  7. package/lib/colors/validate.cjs +2 -11
  8. package/lib/colors/validate.d.ts +5 -11
  9. package/lib/colors/validate.mjs +4 -12
  10. package/lib/export/directory.d.ts +1 -0
  11. package/lib/export/icon-package.d.ts +4 -1
  12. package/lib/export/json-package.cjs +1 -0
  13. package/lib/export/json-package.d.ts +2 -0
  14. package/lib/export/json-package.mjs +1 -0
  15. package/lib/icon-set/index.cjs +1 -1
  16. package/lib/icon-set/index.d.ts +2 -1
  17. package/lib/icon-set/index.mjs +1 -1
  18. package/lib/icon-set/match.d.ts +1 -0
  19. package/lib/icon-set/merge.d.ts +1 -0
  20. package/lib/icon-set/modified.d.ts +1 -0
  21. package/lib/icon-set/tags.d.ts +1 -0
  22. package/lib/import/directory.d.ts +1 -0
  23. package/lib/import/figma/index.d.ts +1 -0
  24. package/lib/import/figma/nodes.d.ts +1 -0
  25. package/lib/import/figma/query.d.ts +1 -0
  26. package/lib/import/figma/types/nodes.d.ts +1 -0
  27. package/lib/import/figma/types/options.d.ts +1 -0
  28. package/lib/import/figma/types/result.d.ts +1 -0
  29. package/lib/index.cjs +4 -6
  30. package/lib/index.d.ts +7 -5
  31. package/lib/index.mjs +6 -5
  32. package/lib/misc/cheerio.d.ts +4 -2
  33. package/lib/optimise/figma.cjs +175 -0
  34. package/lib/optimise/figma.d.ts +11 -0
  35. package/lib/optimise/figma.mjs +173 -0
  36. package/lib/optimise/flags.cjs +2 -2
  37. package/lib/optimise/flags.d.ts +2 -1
  38. package/lib/optimise/flags.mjs +2 -2
  39. package/lib/optimise/global-style.cjs +6 -6
  40. package/lib/optimise/global-style.d.ts +2 -1
  41. package/lib/optimise/global-style.mjs +6 -6
  42. package/lib/optimise/mask.cjs +110 -0
  43. package/lib/optimise/mask.d.ts +24 -0
  44. package/lib/optimise/mask.mjs +108 -0
  45. package/lib/optimise/origin.d.ts +1 -0
  46. package/lib/optimise/scale.d.ts +1 -0
  47. package/lib/optimise/svgo.d.ts +1 -0
  48. package/lib/svg/analyse/error.d.ts +2 -0
  49. package/lib/svg/analyse/types.d.ts +4 -1
  50. package/lib/svg/analyse.cjs +1 -1
  51. package/lib/svg/analyse.d.ts +2 -0
  52. package/lib/svg/analyse.mjs +3 -3
  53. package/lib/svg/cleanup/attribs.cjs +1 -1
  54. package/lib/svg/cleanup/attribs.d.ts +1 -0
  55. package/lib/svg/cleanup/attribs.mjs +2 -2
  56. package/lib/svg/cleanup/bad-tags.cjs +1 -1
  57. package/lib/svg/cleanup/bad-tags.d.ts +1 -0
  58. package/lib/svg/cleanup/bad-tags.mjs +2 -2
  59. package/lib/svg/cleanup/inline-style.cjs +1 -1
  60. package/lib/svg/cleanup/inline-style.d.ts +1 -0
  61. package/lib/svg/cleanup/inline-style.mjs +2 -2
  62. package/lib/svg/cleanup/root-style.cjs +1 -1
  63. package/lib/svg/cleanup/root-style.d.ts +1 -0
  64. package/lib/svg/cleanup/root-style.mjs +2 -2
  65. package/lib/svg/cleanup/root-svg.d.ts +1 -0
  66. package/lib/svg/cleanup/svgo-style.cjs +1 -1
  67. package/lib/svg/cleanup/svgo-style.d.ts +1 -0
  68. package/lib/svg/cleanup/svgo-style.mjs +2 -2
  69. package/lib/svg/cleanup.d.ts +1 -0
  70. package/lib/svg/index.cjs +13 -3
  71. package/lib/svg/index.d.ts +2 -1
  72. package/lib/svg/index.mjs +1 -1
  73. package/lib/svg/parse-style.cjs +178 -235
  74. package/lib/svg/parse-style.d.ts +4 -9
  75. package/lib/svg/parse-style.mjs +180 -236
  76. package/lib/svg/parse.cjs +26 -58
  77. package/lib/svg/parse.d.ts +4 -10
  78. package/lib/svg/parse.mjs +27 -58
  79. package/package.json +25 -13
@@ -15,11 +15,11 @@ function getClassList(value) {
15
15
  return value?.split(/\s+/);
16
16
  }
17
17
  const tempDataAttrbiute = "data-gstyle-temp";
18
- async function cleanupGlobalStyle(svg) {
18
+ function cleanupGlobalStyle(svg) {
19
19
  const backup = svg.toString();
20
20
  let containsTempAttr = false;
21
21
  const animatedClasses = /* @__PURE__ */ new Set();
22
- await svg_parse.parseSVG(svg, (item) => {
22
+ svg_parse.parseSVG(svg, (item) => {
23
23
  if (!svg_data_tags.animateTags.has(item.tagName)) {
24
24
  return;
25
25
  }
@@ -41,7 +41,7 @@ async function cleanupGlobalStyle(svg) {
41
41
  });
42
42
  const removeClasses = /* @__PURE__ */ new Set();
43
43
  try {
44
- await svg_parseStyle.parseSVGStyle(svg, async (styleItem) => {
44
+ svg_parseStyle.parseSVGStyle(svg, (styleItem) => {
45
45
  const returnValue = styleItem.value;
46
46
  if (styleItem.type !== "global") {
47
47
  return returnValue;
@@ -101,7 +101,7 @@ async function cleanupGlobalStyle(svg) {
101
101
  }
102
102
  return false;
103
103
  };
104
- await svg_parse.parseSVG(svg, (svgItem) => {
104
+ svg_parse.parseSVG(svg, (svgItem) => {
105
105
  const tagName = svgItem.tagName;
106
106
  const $element = svgItem.$element;
107
107
  if (!isMatch(tagName, $element)) {
@@ -130,7 +130,7 @@ async function cleanupGlobalStyle(svg) {
130
130
  }
131
131
  });
132
132
  });
133
- await svg_parse.parseSVG(svg, (svgItem) => {
133
+ svg_parse.parseSVG(svg, (svgItem) => {
134
134
  const $element = svgItem.$element;
135
135
  const classList = getClassList($element.attr("class"));
136
136
  if (!classList) {
@@ -146,7 +146,7 @@ async function cleanupGlobalStyle(svg) {
146
146
  }
147
147
  });
148
148
  if (containsTempAttr) {
149
- await svg_parse.parseSVG(svg, (item) => {
149
+ svg_parse.parseSVG(svg, (item) => {
150
150
  item.$element.removeAttr(tempDataAttrbiute);
151
151
  });
152
152
  }
@@ -1,10 +1,11 @@
1
1
  import { SVG } from '../svg/index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
5
6
  /**
6
7
  * Expand global style
7
8
  */
8
- declare function cleanupGlobalStyle(svg: SVG): Promise<void>;
9
+ declare function cleanupGlobalStyle(svg: SVG): void;
9
10
 
10
11
  export { cleanupGlobalStyle };
@@ -13,11 +13,11 @@ function getClassList(value) {
13
13
  return value?.split(/\s+/);
14
14
  }
15
15
  const tempDataAttrbiute = "data-gstyle-temp";
16
- async function cleanupGlobalStyle(svg) {
16
+ function cleanupGlobalStyle(svg) {
17
17
  const backup = svg.toString();
18
18
  let containsTempAttr = false;
19
19
  const animatedClasses = /* @__PURE__ */ new Set();
20
- await parseSVG(svg, (item) => {
20
+ parseSVG(svg, (item) => {
21
21
  if (!animateTags.has(item.tagName)) {
22
22
  return;
23
23
  }
@@ -39,7 +39,7 @@ async function cleanupGlobalStyle(svg) {
39
39
  });
40
40
  const removeClasses = /* @__PURE__ */ new Set();
41
41
  try {
42
- await parseSVGStyle(svg, async (styleItem) => {
42
+ parseSVGStyle(svg, (styleItem) => {
43
43
  const returnValue = styleItem.value;
44
44
  if (styleItem.type !== "global") {
45
45
  return returnValue;
@@ -99,7 +99,7 @@ async function cleanupGlobalStyle(svg) {
99
99
  }
100
100
  return false;
101
101
  };
102
- await parseSVG(svg, (svgItem) => {
102
+ parseSVG(svg, (svgItem) => {
103
103
  const tagName = svgItem.tagName;
104
104
  const $element = svgItem.$element;
105
105
  if (!isMatch(tagName, $element)) {
@@ -128,7 +128,7 @@ async function cleanupGlobalStyle(svg) {
128
128
  }
129
129
  });
130
130
  });
131
- await parseSVG(svg, (svgItem) => {
131
+ parseSVG(svg, (svgItem) => {
132
132
  const $element = svgItem.$element;
133
133
  const classList = getClassList($element.attr("class"));
134
134
  if (!classList) {
@@ -144,7 +144,7 @@ async function cleanupGlobalStyle(svg) {
144
144
  }
145
145
  });
146
146
  if (containsTempAttr) {
147
- await parseSVG(svg, (item) => {
147
+ parseSVG(svg, (item) => {
148
148
  item.$element.removeAttr(tempDataAttrbiute);
149
149
  });
150
150
  }
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ const colors_parse = require('../colors/parse.cjs');
4
+ const utils = require('@iconify/utils');
5
+ require('@iconify/utils/lib/colors');
6
+ require('../svg/data/tags.cjs');
7
+ require('../svg/parse-style.cjs');
8
+ require('../css/parse.cjs');
9
+ require('../css/parser/tokens.cjs');
10
+ require('../css/parser/error.cjs');
11
+ require('../css/parser/strings.cjs');
12
+ require('../css/parser/text.cjs');
13
+ require('../css/parser/export.cjs');
14
+ require('../css/parser/tree.cjs');
15
+ require('../svg/parse.cjs');
16
+ require('../colors/attribs.cjs');
17
+ require('../svg/data/attributes.cjs');
18
+ require('../svg/analyse.cjs');
19
+ require('../svg/analyse/error.cjs');
20
+
21
+ const defaultBlackColors = ["black", "#000", "#000000"];
22
+ const defaultWhiteColors = ["white", "#fff", "#ffffff"];
23
+ const defaultOptions = {
24
+ color: "currentColor",
25
+ solid: [...defaultBlackColors, "currentcolor"],
26
+ transparent: defaultWhiteColors,
27
+ force: false,
28
+ id: "mask"
29
+ };
30
+ function convertSVGToMask(svg, options = {}) {
31
+ const props = {
32
+ ...defaultOptions,
33
+ ...options
34
+ };
35
+ const check = (test, value, color) => {
36
+ if (typeof test === "string") {
37
+ return value.toLowerCase() === test;
38
+ }
39
+ if (test instanceof Array) {
40
+ return test.includes(value.toLowerCase());
41
+ }
42
+ return test(value, color);
43
+ };
44
+ let foundSolid = false;
45
+ let foundTransparent = false;
46
+ let failed = false;
47
+ let hasCustomValue = false;
48
+ const backup = svg.toString();
49
+ colors_parse.parseColors(svg, {
50
+ callback: (attr, colorStr, color) => {
51
+ if (!color || colors_parse.isEmptyColor(color)) {
52
+ return colorStr;
53
+ }
54
+ if (props.custom) {
55
+ let customValue = props.custom(colorStr.toLowerCase(), color);
56
+ if (typeof customValue === "number") {
57
+ const num = Math.max(
58
+ Math.min(Math.round(customValue * 255), 255),
59
+ 0
60
+ );
61
+ let str = num.toString(16);
62
+ if (str.length < 2) {
63
+ str = "0" + str;
64
+ }
65
+ if (str[0] === str[1]) {
66
+ str = str[0];
67
+ }
68
+ customValue = "#" + str + str + str;
69
+ }
70
+ if (typeof customValue === "string") {
71
+ if (defaultBlackColors.includes(customValue)) {
72
+ foundSolid = true;
73
+ } else if (defaultWhiteColors.includes(customValue)) {
74
+ foundTransparent = true;
75
+ } else {
76
+ hasCustomValue = true;
77
+ }
78
+ return customValue;
79
+ }
80
+ }
81
+ if (check(props.solid, colorStr, color)) {
82
+ foundSolid = true;
83
+ return "#fff";
84
+ }
85
+ if (check(props.transparent, colorStr, color)) {
86
+ foundTransparent = true;
87
+ return "#000";
88
+ }
89
+ failed = true;
90
+ console.warn("Unexpected color:", colorStr);
91
+ return color;
92
+ }
93
+ });
94
+ const hasColors = hasCustomValue || foundSolid && foundTransparent;
95
+ if (failed || !hasColors && !props.force) {
96
+ svg.load(backup);
97
+ return false;
98
+ }
99
+ const parsed = utils.parseSVGContent(svg.toString());
100
+ if (!parsed) {
101
+ return false;
102
+ }
103
+ const { defs, content } = utils.splitSVGDefs(parsed.body);
104
+ const newBody = `<defs>${defs}<mask id="${props.id}">${content}</mask></defs><rect mask="url(#${props.id})" ${svg.viewBox.left ? `x=${svg.viewBox.left} ` : ""}${svg.viewBox.top ? `y=${svg.viewBox.top} ` : ""}width="${svg.viewBox.width}" height="${svg.viewBox.height}" fill="${props.color}" />`;
105
+ const newContent = utils.iconToHTML(newBody, parsed.attribs);
106
+ svg.load(newContent);
107
+ return true;
108
+ }
109
+
110
+ exports.convertSVGToMask = convertSVGToMask;
@@ -0,0 +1,24 @@
1
+ import { Color } from '@iconify/utils/lib/colors/types';
2
+ import { SVG } from '../svg/index.js';
3
+ import 'cheerio';
4
+ import '@iconify/types';
5
+ import '@iconify/utils/lib/customisations/defaults';
6
+
7
+ type ColorCallback = (value: string, color: Color | null) => boolean;
8
+ type ColorCheck = string | string[] | ColorCallback;
9
+ interface SVGToMaskOptions {
10
+ color?: string;
11
+ solid?: ColorCheck;
12
+ transparent?: ColorCheck;
13
+ custom?: (value: string, color: Color | null) => string | number | undefined;
14
+ force?: boolean;
15
+ id?: string;
16
+ }
17
+ /**
18
+ * Converts SVG to mask
19
+ *
20
+ * Fixes badly designed icons, which use white shape where icon supposed to be transparent
21
+ */
22
+ declare function convertSVGToMask(svg: SVG, options?: SVGToMaskOptions): boolean;
23
+
24
+ export { convertSVGToMask };
@@ -0,0 +1,108 @@
1
+ import { parseColors, isEmptyColor } from '../colors/parse.mjs';
2
+ import { parseSVGContent, splitSVGDefs, iconToHTML } from '@iconify/utils';
3
+ import '@iconify/utils/lib/colors';
4
+ import '../svg/data/tags.mjs';
5
+ import '../svg/parse-style.mjs';
6
+ import '../css/parse.mjs';
7
+ import '../css/parser/tokens.mjs';
8
+ import '../css/parser/error.mjs';
9
+ import '../css/parser/strings.mjs';
10
+ import '../css/parser/text.mjs';
11
+ import '../css/parser/export.mjs';
12
+ import '../css/parser/tree.mjs';
13
+ import '../svg/parse.mjs';
14
+ import '../colors/attribs.mjs';
15
+ import '../svg/data/attributes.mjs';
16
+ import '../svg/analyse.mjs';
17
+ import '../svg/analyse/error.mjs';
18
+
19
+ const defaultBlackColors = ["black", "#000", "#000000"];
20
+ const defaultWhiteColors = ["white", "#fff", "#ffffff"];
21
+ const defaultOptions = {
22
+ color: "currentColor",
23
+ solid: [...defaultBlackColors, "currentcolor"],
24
+ transparent: defaultWhiteColors,
25
+ force: false,
26
+ id: "mask"
27
+ };
28
+ function convertSVGToMask(svg, options = {}) {
29
+ const props = {
30
+ ...defaultOptions,
31
+ ...options
32
+ };
33
+ const check = (test, value, color) => {
34
+ if (typeof test === "string") {
35
+ return value.toLowerCase() === test;
36
+ }
37
+ if (test instanceof Array) {
38
+ return test.includes(value.toLowerCase());
39
+ }
40
+ return test(value, color);
41
+ };
42
+ let foundSolid = false;
43
+ let foundTransparent = false;
44
+ let failed = false;
45
+ let hasCustomValue = false;
46
+ const backup = svg.toString();
47
+ parseColors(svg, {
48
+ callback: (attr, colorStr, color) => {
49
+ if (!color || isEmptyColor(color)) {
50
+ return colorStr;
51
+ }
52
+ if (props.custom) {
53
+ let customValue = props.custom(colorStr.toLowerCase(), color);
54
+ if (typeof customValue === "number") {
55
+ const num = Math.max(
56
+ Math.min(Math.round(customValue * 255), 255),
57
+ 0
58
+ );
59
+ let str = num.toString(16);
60
+ if (str.length < 2) {
61
+ str = "0" + str;
62
+ }
63
+ if (str[0] === str[1]) {
64
+ str = str[0];
65
+ }
66
+ customValue = "#" + str + str + str;
67
+ }
68
+ if (typeof customValue === "string") {
69
+ if (defaultBlackColors.includes(customValue)) {
70
+ foundSolid = true;
71
+ } else if (defaultWhiteColors.includes(customValue)) {
72
+ foundTransparent = true;
73
+ } else {
74
+ hasCustomValue = true;
75
+ }
76
+ return customValue;
77
+ }
78
+ }
79
+ if (check(props.solid, colorStr, color)) {
80
+ foundSolid = true;
81
+ return "#fff";
82
+ }
83
+ if (check(props.transparent, colorStr, color)) {
84
+ foundTransparent = true;
85
+ return "#000";
86
+ }
87
+ failed = true;
88
+ console.warn("Unexpected color:", colorStr);
89
+ return color;
90
+ }
91
+ });
92
+ const hasColors = hasCustomValue || foundSolid && foundTransparent;
93
+ if (failed || !hasColors && !props.force) {
94
+ svg.load(backup);
95
+ return false;
96
+ }
97
+ const parsed = parseSVGContent(svg.toString());
98
+ if (!parsed) {
99
+ return false;
100
+ }
101
+ const { defs, content } = splitSVGDefs(parsed.body);
102
+ const newBody = `<defs>${defs}<mask id="${props.id}">${content}</mask></defs><rect mask="url(#${props.id})" ${svg.viewBox.left ? `x=${svg.viewBox.left} ` : ""}${svg.viewBox.top ? `y=${svg.viewBox.top} ` : ""}width="${svg.viewBox.width}" height="${svg.viewBox.height}" fill="${props.color}" />`;
103
+ const newContent = iconToHTML(newBody, parsed.attribs);
104
+ svg.load(newContent);
105
+ return true;
106
+ }
107
+
108
+ export { convertSVGToMask };
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../svg/index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../svg/index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,5 +1,6 @@
1
1
  import { PluginConfig } from 'svgo';
2
2
  import { SVG } from '../svg/index.js';
3
+ import 'cheerio';
3
4
  import '@iconify/types';
4
5
  import '@iconify/utils/lib/customisations/defaults';
5
6
 
@@ -1,4 +1,6 @@
1
1
  import { ExtendedTagElement } from './types.js';
2
+ import '../../misc/cheerio.js';
3
+ import 'cheerio';
2
4
 
3
5
  /**
4
6
  * Get tag for error message
@@ -1,3 +1,6 @@
1
+ import { CheerioElement } from '../../misc/cheerio.js';
2
+ import 'cheerio';
3
+
1
4
  /**
2
5
  * Options
3
6
  */
@@ -50,7 +53,7 @@ interface ExtendedTagElementRelations {
50
53
  /**
51
54
  * Extended tag
52
55
  */
53
- interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagElementUses, ExtendedTagElementRelations {
56
+ interface ExtendedTagElement extends CheerioElement, ExtendedTagElementUses, ExtendedTagElementRelations {
54
57
  _index: number;
55
58
  _id?: string;
56
59
  _belongsTo?: ElementWithID[];
@@ -83,7 +83,7 @@ function analyseSVGStructure(svg, options = {}) {
83
83
  element._linksTo.push(link);
84
84
  }
85
85
  let index = 0;
86
- svg_parse.parseSVGSync(svg, (item) => {
86
+ svg_parse.parseSVG(svg, (item) => {
87
87
  const { tagName, parents } = item;
88
88
  if (svg_data_tags.styleTag.has(tagName)) {
89
89
  item.testChildren = false;
@@ -1,7 +1,9 @@
1
1
  import { SVG } from './index.js';
2
2
  import { AnalyseSVGStructureOptions, AnalyseSVGStructureResult } from './analyse/types.js';
3
+ import 'cheerio';
3
4
  import '@iconify/types';
4
5
  import '@iconify/utils/lib/customisations/defaults';
6
+ import '../misc/cheerio.js';
5
7
 
6
8
  /**
7
9
  * Find all IDs, links, which elements use palette, which items aren't used
@@ -1,6 +1,6 @@
1
- import { parseSVGSync } from './parse.mjs';
1
+ import { parseSVG } from './parse.mjs';
2
2
  import { tagSpecificNonPresentationalAttributes, urlPresentationalAttributes, commonColorPresentationalAttributes, markerAttributes } from './data/attributes.mjs';
3
- import { useTag, styleTag, maskTags, reusableElementsWithPalette, defsTag } from './data/tags.mjs';
3
+ import { styleTag, maskTags, reusableElementsWithPalette, defsTag, useTag } from './data/tags.mjs';
4
4
  import { analyseTagError } from './analyse/error.mjs';
5
5
 
6
6
  function analyseSVGStructure(svg, options = {}) {
@@ -81,7 +81,7 @@ function analyseSVGStructure(svg, options = {}) {
81
81
  element._linksTo.push(link);
82
82
  }
83
83
  let index = 0;
84
- parseSVGSync(svg, (item) => {
84
+ parseSVG(svg, (item) => {
85
85
  const { tagName, parents } = item;
86
86
  if (styleTag.has(tagName)) {
87
87
  item.testChildren = false;
@@ -5,7 +5,7 @@ const svg_data_tags = require('../data/tags.cjs');
5
5
  const svg_parse = require('../parse.cjs');
6
6
 
7
7
  function removeBadAttributes(svg) {
8
- svg_parse.parseSVGSync(svg, (item) => {
8
+ svg_parse.parseSVG(svg, (item) => {
9
9
  const tagName = item.tagName;
10
10
  const attribs = item.element.attribs;
11
11
  const $element = item.$element;
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,9 +1,9 @@
1
1
  import { badAttributes, badSoftwareAttributes, badAttributePrefixes, tagSpecificPresentationalAttributes } from '../data/attributes.mjs';
2
2
  import { defsTag } from '../data/tags.mjs';
3
- import { parseSVGSync } from '../parse.mjs';
3
+ import { parseSVG } from '../parse.mjs';
4
4
 
5
5
  function removeBadAttributes(svg) {
6
- parseSVGSync(svg, (item) => {
6
+ parseSVG(svg, (item) => {
7
7
  const tagName = item.tagName;
8
8
  const attribs = item.element.attribs;
9
9
  const $element = item.$element;
@@ -21,7 +21,7 @@ function checkBadTags(svg, options) {
21
21
  ...defaultOptions,
22
22
  ...options
23
23
  };
24
- svg_parse.parseSVGSync(svg, (item) => {
24
+ svg_parse.parseSVG(svg, (item) => {
25
25
  const tagName = item.tagName;
26
26
  const $element = item.$element;
27
27
  if (tagName === "svg") {
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,4 +1,4 @@
1
- import { parseSVGSync } from '../parse.mjs';
1
+ import { parseSVG } from '../parse.mjs';
2
2
  import { feComponentTransferChildTag, feMergeChildTags, feLightningTags, feLightningChildTags, filterTag, filterChildTags, gradientTags, gradientChildTags, animateMotionChildTags, unsupportedTags, badTags, allValidTags } from '../data/tags.mjs';
3
3
 
4
4
  const requiredParentTags = /* @__PURE__ */ new Map();
@@ -19,7 +19,7 @@ function checkBadTags(svg, options) {
19
19
  ...defaultOptions,
20
20
  ...options
21
21
  };
22
- parseSVGSync(svg, (item) => {
22
+ parseSVG(svg, (item) => {
23
23
  const tagName = item.tagName;
24
24
  const $element = item.$element;
25
25
  if (tagName === "svg") {
@@ -32,7 +32,7 @@ const knownIgnoredRules = /* @__PURE__ */ new Set([
32
32
  "stop-opacity"
33
33
  ]);
34
34
  function cleanupInlineStyle(svg) {
35
- svg_parse.parseSVGSync(svg, (item) => {
35
+ svg_parse.parseSVG(svg, (item) => {
36
36
  const $element = item.$element;
37
37
  const attribs = item.element.attribs;
38
38
  const tagName = item.tagName;
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,6 +1,6 @@
1
1
  import { parseInlineStyle } from '../../css/parse.mjs';
2
2
  import { badAttributes, tagSpecificNonPresentationalAttributes, tagSpecificAnimatedAttributes, tagSpecificPresentationalAttributes, tagSpecificInlineStyles, insideClipPathAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
3
- import { parseSVGSync } from '../parse.mjs';
3
+ import { parseSVG } from '../parse.mjs';
4
4
  import '../../css/parser/tokens.mjs';
5
5
  import '../../css/parser/error.mjs';
6
6
  import '../../css/parser/strings.mjs';
@@ -30,7 +30,7 @@ const knownIgnoredRules = /* @__PURE__ */ new Set([
30
30
  "stop-opacity"
31
31
  ]);
32
32
  function cleanupInlineStyle(svg) {
33
- parseSVGSync(svg, (item) => {
33
+ parseSVG(svg, (item) => {
34
34
  const $element = item.$element;
35
35
  const attribs = item.element.attribs;
36
36
  const tagName = item.tagName;
@@ -12,7 +12,7 @@ require('../parse.cjs');
12
12
 
13
13
  function cleanupRootStyle(svg) {
14
14
  const result = {};
15
- svg_parseStyle.parseSVGStyleSync(svg, (item) => {
15
+ svg_parseStyle.parseSVGStyle(svg, (item) => {
16
16
  switch (item.type) {
17
17
  case "inline":
18
18
  return item.value;
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,4 +1,4 @@
1
- import { parseSVGStyleSync } from '../parse-style.mjs';
1
+ import { parseSVGStyle } from '../parse-style.mjs';
2
2
  import '../../css/parse.mjs';
3
3
  import '../../css/parser/tokens.mjs';
4
4
  import '../../css/parser/error.mjs';
@@ -10,7 +10,7 @@ import '../parse.mjs';
10
10
 
11
11
  function cleanupRootStyle(svg) {
12
12
  const result = {};
13
- parseSVGStyleSync(svg, (item) => {
13
+ parseSVGStyle(svg, (item) => {
14
14
  switch (item.type) {
15
15
  case "inline":
16
16
  return item.value;
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -17,7 +17,7 @@ require('@iconify/utils/lib/svg/id');
17
17
 
18
18
  function convertStyleToAttrs(svg) {
19
19
  let hasStyle = false;
20
- svg_parseStyle.parseSVGStyleSync(svg, (item) => {
20
+ svg_parseStyle.parseSVGStyle(svg, (item) => {
21
21
  if (item.type !== "inline" && item.type !== "global") {
22
22
  return item.value;
23
23
  }
@@ -1,4 +1,5 @@
1
1
  import { SVG } from '../index.js';
2
+ import 'cheerio';
2
3
  import '@iconify/types';
3
4
  import '@iconify/utils/lib/customisations/defaults';
4
5
 
@@ -1,5 +1,5 @@
1
1
  import { badAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
2
- import { parseSVGStyleSync } from '../parse-style.mjs';
2
+ import { parseSVGStyle } from '../parse-style.mjs';
3
3
  import { runSVGO } from '../../optimise/svgo.mjs';
4
4
  import '../data/tags.mjs';
5
5
  import '../../css/parse.mjs';
@@ -15,7 +15,7 @@ import '@iconify/utils/lib/svg/id';
15
15
 
16
16
  function convertStyleToAttrs(svg) {
17
17
  let hasStyle = false;
18
- parseSVGStyleSync(svg, (item) => {
18
+ parseSVGStyle(svg, (item) => {
19
19
  if (item.type !== "inline" && item.type !== "global") {
20
20
  return item.value;
21
21
  }
@@ -1,5 +1,6 @@
1
1
  import { SVG } from './index.js';
2
2
  import { CheckBadTagsOptions } from './cleanup/bad-tags.js';
3
+ import 'cheerio';
3
4
  import '@iconify/types';
4
5
  import '@iconify/utils/lib/customisations/defaults';
5
6
 
package/lib/svg/index.cjs CHANGED
@@ -3,9 +3,19 @@
3
3
  const cheerio = require('cheerio');
4
4
  const utils = require('@iconify/utils');
5
5
 
6
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
6
+ function _interopNamespaceCompat(e) {
7
+ if (e && typeof e === 'object' && 'default' in e) return e;
8
+ const n = Object.create(null);
9
+ if (e) {
10
+ for (const k in e) {
11
+ n[k] = e[k];
12
+ }
13
+ }
14
+ n.default = e;
15
+ return n;
16
+ }
7
17
 
8
- const cheerio__default = /*#__PURE__*/_interopDefaultCompat(cheerio);
18
+ const cheerio__namespace = /*#__PURE__*/_interopNamespaceCompat(cheerio);
9
19
 
10
20
  class SVG {
11
21
  /**
@@ -108,7 +118,7 @@ class SVG {
108
118
  );
109
119
  remove('xml:space="preserve"', "", "");
110
120
  content = content.replace(/<g>\s*<\/g>/g, "");
111
- this.$svg = cheerio__default.load(content.trim(), {
121
+ this.$svg = cheerio__namespace.load(content.trim(), {
112
122
  lowerCaseAttributeNames: false,
113
123
  xmlMode: true
114
124
  });