@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.
- package/lib/colors/detect.cjs +1 -1
- package/lib/colors/detect.d.ts +1 -0
- package/lib/colors/detect.mjs +2 -2
- package/lib/colors/parse.cjs +131 -275
- package/lib/colors/parse.d.ts +8 -15
- package/lib/colors/parse.mjs +135 -278
- package/lib/colors/validate.cjs +2 -11
- package/lib/colors/validate.d.ts +5 -11
- package/lib/colors/validate.mjs +4 -12
- package/lib/export/directory.d.ts +1 -0
- package/lib/export/icon-package.d.ts +4 -1
- package/lib/export/json-package.cjs +1 -0
- package/lib/export/json-package.d.ts +2 -0
- package/lib/export/json-package.mjs +1 -0
- package/lib/icon-set/index.d.ts +1 -0
- package/lib/icon-set/match.d.ts +1 -0
- package/lib/icon-set/merge.d.ts +1 -0
- package/lib/icon-set/modified.d.ts +1 -0
- package/lib/icon-set/tags.d.ts +1 -0
- package/lib/import/directory.d.ts +1 -0
- package/lib/import/figma/index.d.ts +1 -0
- package/lib/import/figma/nodes.d.ts +1 -0
- package/lib/import/figma/query.d.ts +1 -0
- package/lib/import/figma/types/nodes.d.ts +1 -0
- package/lib/import/figma/types/options.d.ts +1 -0
- package/lib/import/figma/types/result.d.ts +1 -0
- package/lib/index.cjs +0 -6
- package/lib/index.d.ts +5 -5
- package/lib/index.mjs +4 -5
- package/lib/misc/cheerio.d.ts +4 -2
- package/lib/optimise/figma.d.ts +1 -0
- package/lib/optimise/flags.cjs +2 -2
- package/lib/optimise/flags.d.ts +2 -1
- package/lib/optimise/flags.mjs +2 -2
- package/lib/optimise/global-style.cjs +6 -6
- package/lib/optimise/global-style.d.ts +2 -1
- package/lib/optimise/global-style.mjs +6 -6
- package/lib/optimise/mask.cjs +10 -10
- package/lib/optimise/mask.d.ts +1 -0
- package/lib/optimise/mask.mjs +11 -11
- package/lib/optimise/origin.d.ts +1 -0
- package/lib/optimise/scale.d.ts +1 -0
- package/lib/optimise/svgo.d.ts +1 -0
- package/lib/svg/analyse/error.d.ts +2 -0
- package/lib/svg/analyse/types.d.ts +4 -1
- package/lib/svg/analyse.cjs +1 -1
- package/lib/svg/analyse.d.ts +2 -0
- package/lib/svg/analyse.mjs +3 -3
- package/lib/svg/cleanup/attribs.cjs +1 -1
- package/lib/svg/cleanup/attribs.d.ts +1 -0
- package/lib/svg/cleanup/attribs.mjs +2 -2
- package/lib/svg/cleanup/bad-tags.cjs +1 -1
- package/lib/svg/cleanup/bad-tags.d.ts +1 -0
- package/lib/svg/cleanup/bad-tags.mjs +2 -2
- package/lib/svg/cleanup/inline-style.cjs +1 -1
- package/lib/svg/cleanup/inline-style.d.ts +1 -0
- package/lib/svg/cleanup/inline-style.mjs +2 -2
- package/lib/svg/cleanup/root-style.cjs +1 -1
- package/lib/svg/cleanup/root-style.d.ts +1 -0
- package/lib/svg/cleanup/root-style.mjs +2 -2
- package/lib/svg/cleanup/root-svg.d.ts +1 -0
- package/lib/svg/cleanup/svgo-style.cjs +1 -1
- package/lib/svg/cleanup/svgo-style.d.ts +1 -0
- package/lib/svg/cleanup/svgo-style.mjs +2 -2
- package/lib/svg/cleanup.d.ts +1 -0
- package/lib/svg/index.cjs +13 -3
- package/lib/svg/index.d.ts +2 -1
- package/lib/svg/index.mjs +1 -1
- package/lib/svg/parse-style.cjs +178 -235
- package/lib/svg/parse-style.d.ts +4 -9
- package/lib/svg/parse-style.mjs +180 -236
- package/lib/svg/parse.cjs +26 -58
- package/lib/svg/parse.d.ts +4 -10
- package/lib/svg/parse.mjs +27 -58
- package/package.json +12 -10
package/lib/svg/parse.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
40
|
+
}
|
|
41
|
+
checkNode($root.get(0), []);
|
|
73
42
|
}
|
|
74
43
|
|
|
75
|
-
export { parseSVG
|
|
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": "
|
|
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.
|
|
20
|
-
"@types/
|
|
21
|
-
"
|
|
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.
|
|
28
|
+
"svgo": "^3.0.4",
|
|
27
29
|
"tar": "^6.2.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"@types/jest": "^29.5.
|
|
31
|
-
"@types/node": "^18.18.
|
|
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.
|
|
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.
|
|
46
|
+
"typescript": "^5.3.2",
|
|
45
47
|
"unbuild": "^1.2.1"
|
|
46
48
|
},
|
|
47
49
|
"exports": {
|