@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
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.5",
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,32 +19,31 @@
16
19
  "types": "./lib/index.d.ts",
17
20
  "dependencies": {
18
21
  "@iconify/types": "^2.0.0",
19
- "@iconify/utils": "^2.1.7",
20
- "@types/cheerio": "^0.22.31",
21
- "@types/tar": "^6.1.5",
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",
27
- "tar": "^6.1.15"
28
+ "svgo": "^3.0.4",
29
+ "tar": "^6.2.0"
28
30
  },
29
31
  "devDependencies": {
30
- "@types/jest": "^29.5.3",
31
- "@types/node": "^18.17.3",
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.46.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",
39
41
  "jasmine": "^5.1.0",
40
- "jest": "^29.6.2",
42
+ "jest": "^29.7.0",
41
43
  "prettier": "^2.8.8",
42
- "rimraf": "^5.0.1",
44
+ "rimraf": "^5.0.5",
43
45
  "ts-jest": "^29.1.1",
44
- "typescript": "^5.1.6",
46
+ "typescript": "^5.3.2",
45
47
  "unbuild": "^1.2.1"
46
48
  },
47
49
  "exports": {
@@ -411,6 +413,11 @@
411
413
  "require": "./lib/misc/write-json.cjs",
412
414
  "import": "./lib/misc/write-json.mjs"
413
415
  },
416
+ "./lib/optimise/figma": {
417
+ "types": "./lib/optimise/figma.d.ts",
418
+ "require": "./lib/optimise/figma.cjs",
419
+ "import": "./lib/optimise/figma.mjs"
420
+ },
414
421
  "./lib/optimise/flags": {
415
422
  "types": "./lib/optimise/flags.d.ts",
416
423
  "require": "./lib/optimise/flags.cjs",
@@ -421,6 +428,11 @@
421
428
  "require": "./lib/optimise/global-style.cjs",
422
429
  "import": "./lib/optimise/global-style.mjs"
423
430
  },
431
+ "./lib/optimise/mask": {
432
+ "types": "./lib/optimise/mask.d.ts",
433
+ "require": "./lib/optimise/mask.cjs",
434
+ "import": "./lib/optimise/mask.mjs"
435
+ },
424
436
  "./lib/optimise/origin": {
425
437
  "types": "./lib/optimise/origin.d.ts",
426
438
  "require": "./lib/optimise/origin.cjs",