@iconify/tools 3.0.6 → 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 (75) 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.d.ts +1 -0
  16. package/lib/icon-set/match.d.ts +1 -0
  17. package/lib/icon-set/merge.d.ts +1 -0
  18. package/lib/icon-set/modified.d.ts +1 -0
  19. package/lib/icon-set/tags.d.ts +1 -0
  20. package/lib/import/directory.d.ts +1 -0
  21. package/lib/import/figma/index.d.ts +1 -0
  22. package/lib/import/figma/nodes.d.ts +1 -0
  23. package/lib/import/figma/query.d.ts +1 -0
  24. package/lib/import/figma/types/nodes.d.ts +1 -0
  25. package/lib/import/figma/types/options.d.ts +1 -0
  26. package/lib/import/figma/types/result.d.ts +1 -0
  27. package/lib/index.cjs +0 -6
  28. package/lib/index.d.ts +5 -5
  29. package/lib/index.mjs +4 -5
  30. package/lib/misc/cheerio.d.ts +4 -2
  31. package/lib/optimise/figma.d.ts +1 -0
  32. package/lib/optimise/flags.cjs +2 -2
  33. package/lib/optimise/flags.d.ts +2 -1
  34. package/lib/optimise/flags.mjs +2 -2
  35. package/lib/optimise/global-style.cjs +6 -6
  36. package/lib/optimise/global-style.d.ts +2 -1
  37. package/lib/optimise/global-style.mjs +6 -6
  38. package/lib/optimise/mask.cjs +10 -10
  39. package/lib/optimise/mask.d.ts +1 -0
  40. package/lib/optimise/mask.mjs +11 -11
  41. package/lib/optimise/origin.d.ts +1 -0
  42. package/lib/optimise/scale.d.ts +1 -0
  43. package/lib/optimise/svgo.d.ts +1 -0
  44. package/lib/svg/analyse/error.d.ts +2 -0
  45. package/lib/svg/analyse/types.d.ts +4 -1
  46. package/lib/svg/analyse.cjs +1 -1
  47. package/lib/svg/analyse.d.ts +2 -0
  48. package/lib/svg/analyse.mjs +3 -3
  49. package/lib/svg/cleanup/attribs.cjs +1 -1
  50. package/lib/svg/cleanup/attribs.d.ts +1 -0
  51. package/lib/svg/cleanup/attribs.mjs +2 -2
  52. package/lib/svg/cleanup/bad-tags.cjs +1 -1
  53. package/lib/svg/cleanup/bad-tags.d.ts +1 -0
  54. package/lib/svg/cleanup/bad-tags.mjs +2 -2
  55. package/lib/svg/cleanup/inline-style.cjs +1 -1
  56. package/lib/svg/cleanup/inline-style.d.ts +1 -0
  57. package/lib/svg/cleanup/inline-style.mjs +2 -2
  58. package/lib/svg/cleanup/root-style.cjs +1 -1
  59. package/lib/svg/cleanup/root-style.d.ts +1 -0
  60. package/lib/svg/cleanup/root-style.mjs +2 -2
  61. package/lib/svg/cleanup/root-svg.d.ts +1 -0
  62. package/lib/svg/cleanup/svgo-style.cjs +1 -1
  63. package/lib/svg/cleanup/svgo-style.d.ts +1 -0
  64. package/lib/svg/cleanup/svgo-style.mjs +2 -2
  65. package/lib/svg/cleanup.d.ts +1 -0
  66. package/lib/svg/index.cjs +13 -3
  67. package/lib/svg/index.d.ts +2 -1
  68. package/lib/svg/index.mjs +1 -1
  69. package/lib/svg/parse-style.cjs +178 -235
  70. package/lib/svg/parse-style.d.ts +4 -9
  71. package/lib/svg/parse-style.mjs +180 -236
  72. package/lib/svg/parse.cjs +26 -58
  73. package/lib/svg/parse.d.ts +4 -10
  74. package/lib/svg/parse.mjs +27 -58
  75. package/package.json +12 -10
package/lib/svg/parse.mjs CHANGED
@@ -1,7 +1,9 @@
1
- function parse(svg, callback, done) {
2
- function checkNode(element, parents, done2) {
1
+ function parseSVG(svg, callback) {
2
+ const cheerio = svg.$svg;
3
+ const $root = svg.$svg(":root");
4
+ function checkNode(element, parents) {
3
5
  if (element.type !== "tag") {
4
- return done2();
6
+ return;
5
7
  }
6
8
  const $element = cheerio(element);
7
9
  const tagName = element.tagName;
@@ -14,62 +16,29 @@ function parse(svg, callback, done) {
14
16
  testChildren: true,
15
17
  removeNode: false
16
18
  };
17
- callback(item, () => {
18
- const newParents = parents.slice(0);
19
- newParents.unshift(item);
20
- let queue = [];
21
- if (tagName !== "style" && item.testChildren && !item.removeNode) {
22
- const children = $element.children().toArray();
23
- queue = children.slice(0);
24
- }
25
- const next = () => {
26
- const queueItem = queue.shift();
27
- if (!queueItem) {
28
- if (item.removeNode) {
29
- $element.remove();
30
- }
31
- return done2();
32
- }
33
- checkNode(queueItem, newParents, next);
34
- };
35
- next();
36
- });
37
- }
38
- const cheerio = svg.$svg;
39
- const $root = svg.$svg(":root");
40
- checkNode($root.get(0), [], done);
41
- }
42
- function parseSVG(svg, callback) {
43
- return new Promise((fulfill, reject) => {
44
- parse(
45
- svg,
46
- (item, next) => {
47
- const result = callback(item);
48
- if (result instanceof Promise) {
49
- result.then(next).catch(reject);
50
- } else {
51
- next();
52
- }
53
- },
54
- fulfill
55
- );
56
- });
57
- }
58
- function parseSVGSync(svg, callback) {
59
- let isSync = true;
60
- parse(
61
- svg,
62
- (item, next) => {
63
- callback(item);
64
- next();
65
- },
66
- () => {
67
- if (!isSync) {
68
- throw new Error("parseSVGSync callback was async");
19
+ const callbackResult = callback(item);
20
+ if (callbackResult instanceof Promise) {
21
+ throw new Error("parseSVG does not support async callbacks");
22
+ }
23
+ const newParents = parents.slice(0);
24
+ newParents.unshift(item);
25
+ let queue = [];
26
+ if (tagName !== "style" && item.testChildren && !item.removeNode) {
27
+ const children = $element.children().toArray();
28
+ queue = children.slice(0);
29
+ }
30
+ while (queue.length) {
31
+ const queueItem = queue.shift();
32
+ if (!queueItem || item.removeNode) {
33
+ break;
69
34
  }
35
+ checkNode(queueItem, newParents);
36
+ }
37
+ if (item.removeNode) {
38
+ $element.remove();
70
39
  }
71
- );
72
- isSync = false;
40
+ }
41
+ checkNode($root.get(0), []);
73
42
  }
74
43
 
75
- export { parseSVG, parseSVGSync };
44
+ export { parseSVG };
package/package.json CHANGED
@@ -3,7 +3,10 @@
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": "3.0.6",
6
+ "version": "4.0.0-beta.1",
7
+ "publishConfig": {
8
+ "tag": "next"
9
+ },
7
10
  "license": "MIT",
8
11
  "bugs": "https://github.com/iconify/tools/issues",
9
12
  "homepage": "https://github.com/iconify/tools",
@@ -16,23 +19,22 @@
16
19
  "types": "./lib/index.d.ts",
17
20
  "dependencies": {
18
21
  "@iconify/types": "^2.0.0",
19
- "@iconify/utils": "^2.1.10",
20
- "@types/cheerio": "^0.22.32",
21
- "@types/tar": "^6.1.6",
22
- "cheerio": "^1.0.0-rc.12",
22
+ "@iconify/utils": "^2.1.12",
23
+ "@types/tar": "^6.1.10",
24
+ "cheerio": "1.0.0-rc.12",
23
25
  "extract-zip": "^2.0.1",
24
26
  "local-pkg": "^0.4.3",
25
27
  "pathe": "^1.1.1",
26
- "svgo": "^3.0.2",
28
+ "svgo": "^3.0.4",
27
29
  "tar": "^6.2.0"
28
30
  },
29
31
  "devDependencies": {
30
- "@types/jest": "^29.5.5",
31
- "@types/node": "^18.18.0",
32
+ "@types/jest": "^29.5.10",
33
+ "@types/node": "^18.18.13",
32
34
  "@typescript-eslint/eslint-plugin": "^5.62.0",
33
35
  "@typescript-eslint/parser": "^5.62.0",
34
36
  "cross-env": "^7.0.3",
35
- "eslint": "^8.50.0",
37
+ "eslint": "^8.54.0",
36
38
  "eslint-config-prettier": "^8.10.0",
37
39
  "eslint-plugin-jasmine": "^4.1.3",
38
40
  "eslint-plugin-prettier": "^4.2.1",
@@ -41,7 +43,7 @@
41
43
  "prettier": "^2.8.8",
42
44
  "rimraf": "^5.0.5",
43
45
  "ts-jest": "^29.1.1",
44
- "typescript": "^5.2.2",
46
+ "typescript": "^5.3.2",
45
47
  "unbuild": "^1.2.1"
46
48
  },
47
49
  "exports": {