@iconify/tools 2.2.5 → 3.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 (85) hide show
  1. package/README.md +8 -2
  2. package/lib/colors/detect.cjs +4 -4
  3. package/lib/colors/detect.d.ts +1 -1
  4. package/lib/colors/detect.mjs +5 -5
  5. package/lib/colors/parse.cjs +275 -129
  6. package/lib/colors/parse.d.ts +14 -5
  7. package/lib/colors/parse.mjs +278 -133
  8. package/lib/colors/validate.cjs +11 -2
  9. package/lib/colors/validate.d.ts +10 -2
  10. package/lib/colors/validate.mjs +12 -4
  11. package/lib/download/api/download.cjs +4 -4
  12. package/lib/download/api/download.mjs +4 -4
  13. package/lib/download/api/index.cjs +0 -1
  14. package/lib/download/api/index.mjs +0 -1
  15. package/lib/download/git/index.cjs +1 -1
  16. package/lib/download/git/index.mjs +1 -1
  17. package/lib/download/git/reset.cjs +1 -1
  18. package/lib/download/git/reset.mjs +1 -1
  19. package/lib/download/github/hash.cjs +0 -1
  20. package/lib/download/github/hash.mjs +0 -1
  21. package/lib/download/github/index.cjs +1 -1
  22. package/lib/download/github/index.mjs +1 -1
  23. package/lib/download/gitlab/hash.cjs +0 -1
  24. package/lib/download/gitlab/hash.mjs +0 -1
  25. package/lib/download/gitlab/index.cjs +1 -1
  26. package/lib/download/gitlab/index.mjs +1 -1
  27. package/lib/download/helpers/unzip.cjs +5 -1
  28. package/lib/download/index.cjs +1 -1
  29. package/lib/download/index.mjs +1 -1
  30. package/lib/download/npm/index.cjs +1 -1
  31. package/lib/download/npm/index.mjs +1 -1
  32. package/lib/icon-set/index.cjs +18 -0
  33. package/lib/icon-set/index.d.ts +7 -1
  34. package/lib/icon-set/index.mjs +18 -0
  35. package/lib/icon-set/tags.cjs +2 -2
  36. package/lib/icon-set/tags.d.ts +1 -1
  37. package/lib/icon-set/tags.mjs +2 -2
  38. package/lib/icon-set/types.d.ts +5 -4
  39. package/lib/import/directory.cjs +101 -28
  40. package/lib/import/directory.d.ts +12 -5
  41. package/lib/import/directory.mjs +103 -31
  42. package/lib/import/figma/index.cjs +1 -2
  43. package/lib/import/figma/index.mjs +1 -2
  44. package/lib/import/figma/query.cjs +0 -1
  45. package/lib/import/figma/query.mjs +0 -1
  46. package/lib/index.cjs +9 -1
  47. package/lib/index.d.ts +7 -6
  48. package/lib/index.mjs +8 -7
  49. package/lib/misc/scan.cjs +61 -8
  50. package/lib/misc/scan.d.ts +12 -6
  51. package/lib/misc/scan.mjs +62 -10
  52. package/lib/optimise/origin.cjs +23 -0
  53. package/lib/optimise/origin.d.ts +10 -0
  54. package/lib/optimise/origin.mjs +21 -0
  55. package/lib/optimise/scale.cjs +17 -15
  56. package/lib/optimise/scale.mjs +17 -15
  57. package/lib/svg/analyse.cjs +2 -2
  58. package/lib/svg/analyse.d.ts +1 -1
  59. package/lib/svg/analyse.mjs +4 -4
  60. package/lib/svg/cleanup/attribs.cjs +2 -2
  61. package/lib/svg/cleanup/attribs.d.ts +1 -1
  62. package/lib/svg/cleanup/attribs.mjs +3 -3
  63. package/lib/svg/cleanup/bad-tags.cjs +2 -2
  64. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  65. package/lib/svg/cleanup/bad-tags.mjs +3 -3
  66. package/lib/svg/cleanup/inline-style.cjs +2 -2
  67. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  68. package/lib/svg/cleanup/inline-style.mjs +3 -3
  69. package/lib/svg/cleanup/root-style.cjs +1 -1
  70. package/lib/svg/cleanup/root-style.d.ts +1 -5
  71. package/lib/svg/cleanup/root-style.mjs +2 -2
  72. package/lib/svg/cleanup/svgo-style.cjs +2 -2
  73. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  74. package/lib/svg/cleanup/svgo-style.mjs +3 -3
  75. package/lib/svg/cleanup.cjs +6 -6
  76. package/lib/svg/cleanup.d.ts +1 -1
  77. package/lib/svg/cleanup.mjs +6 -6
  78. package/lib/svg/index.cjs +5 -1
  79. package/lib/svg/parse-style.cjs +149 -89
  80. package/lib/svg/parse-style.d.ts +6 -1
  81. package/lib/svg/parse-style.mjs +150 -91
  82. package/lib/svg/parse.cjs +56 -18
  83. package/lib/svg/parse.d.ts +8 -2
  84. package/lib/svg/parse.mjs +56 -19
  85. package/package.json +23 -20
package/lib/svg/parse.mjs CHANGED
@@ -1,7 +1,7 @@
1
- async function parseSVG(svg, callback) {
2
- async function checkNode(element, parents) {
1
+ function parse(svg, callback, done) {
2
+ function checkNode(element, parents, done2) {
3
3
  if (element.type !== "tag") {
4
- return;
4
+ return done2();
5
5
  }
6
6
  const $element = cheerio(element);
7
7
  const tagName = element.tagName;
@@ -14,25 +14,62 @@ async function parseSVG(svg, callback) {
14
14
  testChildren: true,
15
15
  removeNode: false
16
16
  };
17
- const result = callback(item);
18
- if (result instanceof Promise) {
19
- await result;
20
- }
21
- const newParents = parents.slice(0);
22
- newParents.unshift(item);
23
- if (tagName !== "style" && item.testChildren && !item.removeNode) {
24
- const children = $element.children().toArray();
25
- for (let i = 0; i < children.length; i++) {
26
- await checkNode(children[i], newParents);
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);
27
24
  }
28
- }
29
- if (item.removeNode) {
30
- $element.remove();
31
- }
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
+ });
32
37
  }
33
38
  const cheerio = svg.$svg;
34
39
  const $root = svg.$svg(":root");
35
- await checkNode($root.get(0), []);
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");
69
+ }
70
+ }
71
+ );
72
+ isSync = false;
36
73
  }
37
74
 
38
- export { parseSVG };
75
+ export { parseSVG, parseSVGSync };
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.2.5",
6
+ "version": "3.0.0-beta.1",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/iconify/tools/issues",
9
9
  "homepage": "https://github.com/iconify/tools",
@@ -16,35 +16,33 @@
16
16
  "types": "./lib/index.d.ts",
17
17
  "dependencies": {
18
18
  "@iconify/types": "^2.0.0",
19
- "@iconify/utils": "^2.1.0",
19
+ "@iconify/utils": "^2.1.5",
20
20
  "@types/cheerio": "^0.22.31",
21
- "@types/node-fetch": "^2.6.2",
22
- "@types/tar": "^6.1.3",
21
+ "@types/tar": "^6.1.4",
23
22
  "cheerio": "^1.0.0-rc.12",
24
23
  "extract-zip": "^2.0.1",
25
- "local-pkg": "^0.4.2",
26
- "node-fetch": "^2.6.8",
27
- "pathe": "^1.0.0",
24
+ "local-pkg": "^0.4.3",
25
+ "pathe": "^1.1.0",
28
26
  "svgo": "^3.0.2",
29
27
  "tar": "^6.1.13"
30
28
  },
31
29
  "devDependencies": {
32
- "@types/jest": "^29.2.5",
33
- "@types/node": "^18.11.18",
34
- "@typescript-eslint/eslint-plugin": "^5.48.1",
35
- "@typescript-eslint/parser": "^5.48.1",
30
+ "@types/jest": "^29.5.0",
31
+ "@types/node": "^18.15.11",
32
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
33
+ "@typescript-eslint/parser": "^5.58.0",
36
34
  "cross-env": "^7.0.3",
37
- "eslint": "^8.32.0",
38
- "eslint-config-prettier": "^8.6.0",
35
+ "eslint": "^8.38.0",
36
+ "eslint-config-prettier": "^8.8.0",
39
37
  "eslint-plugin-jasmine": "^4.1.3",
40
38
  "eslint-plugin-prettier": "^4.2.1",
41
- "jasmine": "^4.5.0",
42
- "jest": "^29.3.1",
43
- "prettier": "^2.8.3",
44
- "rimraf": "^3.0.2",
45
- "ts-jest": "^29.0.5",
46
- "typescript": "^4.9.4",
47
- "unbuild": "^1.1.1"
39
+ "jasmine": "^4.6.0",
40
+ "jest": "^29.5.0",
41
+ "prettier": "^2.8.7",
42
+ "rimraf": "^5.0.0",
43
+ "ts-jest": "^29.1.0",
44
+ "typescript": "^5.0.4",
45
+ "unbuild": "^1.2.1"
48
46
  },
49
47
  "exports": {
50
48
  "./*": "./*",
@@ -423,6 +421,11 @@
423
421
  "import": "./lib/optimise/global-style.mjs",
424
422
  "types": "./lib/optimise/global-style.d.ts"
425
423
  },
424
+ "./lib/optimise/origin": {
425
+ "require": "./lib/optimise/origin.cjs",
426
+ "import": "./lib/optimise/origin.mjs",
427
+ "types": "./lib/optimise/origin.d.ts"
428
+ },
426
429
  "./lib/optimise/scale": {
427
430
  "require": "./lib/optimise/scale.cjs",
428
431
  "import": "./lib/optimise/scale.mjs",