@iconify/tools 5.0.9 → 5.0.11
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/css/parse.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isBadSVGColor, isSVGColorAttribute } from "../svg/data/colors.js";
|
|
1
2
|
import { getTokens } from "./parser/tokens.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -10,6 +11,7 @@ function parseInlineStyle(style) {
|
|
|
10
11
|
for (let i = 0; i < tokens.length; i++) {
|
|
11
12
|
const token = tokens[i];
|
|
12
13
|
if (token.type !== "rule") return null;
|
|
14
|
+
if (isSVGColorAttribute(token.prop) && isBadSVGColor(token.value)) continue;
|
|
13
15
|
results[token.prop] = token.value;
|
|
14
16
|
}
|
|
15
17
|
return results;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseSVG } from "../svg/parse.js";
|
|
2
|
+
import { isBadSVGColor, isSVGColorAttribute } from "../svg/data/colors.js";
|
|
2
3
|
import { parseSVGStyle } from "../svg/parse-style.js";
|
|
3
4
|
import { allValidTags, animateTags } from "../svg/data/tags.js";
|
|
4
5
|
import { splitClassName } from "@cyberalien/svg-utils";
|
|
@@ -82,6 +83,7 @@ function cleanupGlobalStyle(svg) {
|
|
|
82
83
|
const tempDataValue = attribs[tempDataAttrbiute];
|
|
83
84
|
const addedAttributes = new Set(typeof tempDataValue === "string" ? splitClassName(tempDataValue) : []);
|
|
84
85
|
const prop = styleItem.prop;
|
|
86
|
+
if (isSVGColorAttribute(prop) && isBadSVGColor(styleItem.value)) return;
|
|
85
87
|
attribs[prop] = styleItem.value;
|
|
86
88
|
addedAttributes.add(prop);
|
|
87
89
|
attribs[tempDataAttrbiute] = Array.from(addedAttributes).join(" ");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check for color attribute
|
|
3
|
+
*/
|
|
4
|
+
function isSVGColorAttribute(prop) {
|
|
5
|
+
return prop === "fill" || prop === "stroke" || prop.endsWith("color");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check for color that cannot be parsed
|
|
9
|
+
*/
|
|
10
|
+
function isBadSVGColor(value) {
|
|
11
|
+
return value.startsWith("color(") || value.startsWith("device-color(") || value.startsWith("var(");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { isBadSVGColor, isSVGColorAttribute };
|
package/lib/svg/parse-style.js
CHANGED
|
@@ -23,11 +23,12 @@ function parseSVGStyle(svg, callback) {
|
|
|
23
23
|
const node = item.node;
|
|
24
24
|
const tagName = node.tag;
|
|
25
25
|
function parseStyleItem() {
|
|
26
|
-
|
|
26
|
+
let content = stringifyXMLContent(node.children);
|
|
27
27
|
if (!content) {
|
|
28
28
|
item.removeNode = true;
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
+
content = content.replace("<![CDATA[", "").replace("]]>", "");
|
|
31
32
|
const tokens = getTokens(content);
|
|
32
33
|
if (!(tokens instanceof Array)) throw new Error("Error parsing style. This parser can handle only basic CSS");
|
|
33
34
|
let changed = false;
|
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": "5.0.
|
|
6
|
+
"version": "5.0.11",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|