@iconify/tools 2.1.0-beta.6 → 2.1.0-beta.7
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/attribs.cjs +5 -0
- package/lib/colors/attribs.d.ts +7 -1
- package/lib/colors/attribs.mjs +5 -1
- package/lib/colors/parse.cjs +7 -1
- package/lib/colors/parse.mjs +8 -2
- package/lib/misc/keyword.cjs +1 -1
- package/lib/misc/keyword.mjs +1 -1
- package/lib/svg/cleanup/inline-style.cjs +4 -0
- package/lib/svg/cleanup/inline-style.mjs +5 -1
- package/lib/svg/data/attributes.cjs +4 -0
- package/lib/svg/data/attributes.d.ts +5 -1
- package/lib/svg/data/attributes.mjs +4 -1
- package/package.json +1 -1
package/lib/colors/attribs.cjs
CHANGED
|
@@ -22,7 +22,12 @@ const defaultColorValues = {
|
|
|
22
22
|
"stop-color": defaultBlackColor,
|
|
23
23
|
"flood-color": defaultBlackColor
|
|
24
24
|
};
|
|
25
|
+
const allowDefaultColorValue = {
|
|
26
|
+
"stop-color": true,
|
|
27
|
+
"flood-color": "flood-opacity"
|
|
28
|
+
};
|
|
25
29
|
|
|
30
|
+
exports.allowDefaultColorValue = allowDefaultColorValue;
|
|
26
31
|
exports.commonColorAttributes = commonColorAttributes;
|
|
27
32
|
exports.defaultBlackColor = defaultBlackColor;
|
|
28
33
|
exports.defaultColorValues = defaultColorValues;
|
package/lib/colors/attribs.d.ts
CHANGED
|
@@ -15,5 +15,11 @@ declare type ColorAttributes = CommonColorAttributes | ShapeColorAttributes | Sp
|
|
|
15
15
|
*/
|
|
16
16
|
declare const defaultBlackColor: Color;
|
|
17
17
|
declare const defaultColorValues: Record<ColorAttributes, Color>;
|
|
18
|
+
/**
|
|
19
|
+
* Ignore default color for some tags:
|
|
20
|
+
* - If value is true, allow default color
|
|
21
|
+
* - If value is attribute name, allow default color if attribute is set
|
|
22
|
+
*/
|
|
23
|
+
declare const allowDefaultColorValue: Partial<Record<ColorAttributes, string | true>>;
|
|
18
24
|
|
|
19
|
-
export { ColorAttributes, CommonColorAttributes, ShapeColorAttributes, SpecialColorAttributes, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
|
25
|
+
export { ColorAttributes, CommonColorAttributes, ShapeColorAttributes, SpecialColorAttributes, allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
package/lib/colors/attribs.mjs
CHANGED
|
@@ -18,5 +18,9 @@ const defaultColorValues = {
|
|
|
18
18
|
"stop-color": defaultBlackColor,
|
|
19
19
|
"flood-color": defaultBlackColor
|
|
20
20
|
};
|
|
21
|
+
const allowDefaultColorValue = {
|
|
22
|
+
"stop-color": true,
|
|
23
|
+
"flood-color": "flood-opacity"
|
|
24
|
+
};
|
|
21
25
|
|
|
22
|
-
export { commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
|
26
|
+
export { allowDefaultColorValue, commonColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, specialColorAttributes };
|
package/lib/colors/parse.cjs
CHANGED
|
@@ -54,12 +54,18 @@ async function parseColors(svg, options = {}) {
|
|
|
54
54
|
function getElementColor(prop, item, elements2) {
|
|
55
55
|
function find(prop2) {
|
|
56
56
|
let currentItem = item;
|
|
57
|
+
const allowDefaultColor = colors_attribs.allowDefaultColorValue[prop2];
|
|
57
58
|
while (currentItem) {
|
|
58
59
|
const element = elements2.get(currentItem.index);
|
|
59
60
|
const color = element._colors?.[prop2];
|
|
60
61
|
if (color !== void 0) {
|
|
61
62
|
return color;
|
|
62
63
|
}
|
|
64
|
+
if (allowDefaultColor) {
|
|
65
|
+
if (allowDefaultColor === true || element.attribs[allowDefaultColor]) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
63
69
|
currentItem = currentItem.parent;
|
|
64
70
|
if (currentItem?.usedAsMask) {
|
|
65
71
|
return colors_attribs.defaultColorValues[prop2];
|
|
@@ -68,7 +74,7 @@ async function parseColors(svg, options = {}) {
|
|
|
68
74
|
return colors_attribs.defaultColorValues[prop2];
|
|
69
75
|
}
|
|
70
76
|
let propColor = find(prop);
|
|
71
|
-
if (typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
|
|
77
|
+
if (propColor !== null && typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
|
|
72
78
|
propColor = find("color");
|
|
73
79
|
}
|
|
74
80
|
return propColor;
|
package/lib/colors/parse.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
|
|
2
2
|
import { animateTags, shapeTags } from '../svg/data/tags.mjs';
|
|
3
3
|
import { parseSVGStyle } from '../svg/parse-style.mjs';
|
|
4
|
-
import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes } from './attribs.mjs';
|
|
4
|
+
import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, allowDefaultColorValue } from './attribs.mjs';
|
|
5
5
|
import { tagSpecificPresentationalAttributes } from '../svg/data/attributes.mjs';
|
|
6
6
|
import { analyseSVGStructure } from '../svg/analyse.mjs';
|
|
7
7
|
import '../css/parse.mjs';
|
|
@@ -50,12 +50,18 @@ async function parseColors(svg, options = {}) {
|
|
|
50
50
|
function getElementColor(prop, item, elements2) {
|
|
51
51
|
function find(prop2) {
|
|
52
52
|
let currentItem = item;
|
|
53
|
+
const allowDefaultColor = allowDefaultColorValue[prop2];
|
|
53
54
|
while (currentItem) {
|
|
54
55
|
const element = elements2.get(currentItem.index);
|
|
55
56
|
const color = element._colors?.[prop2];
|
|
56
57
|
if (color !== void 0) {
|
|
57
58
|
return color;
|
|
58
59
|
}
|
|
60
|
+
if (allowDefaultColor) {
|
|
61
|
+
if (allowDefaultColor === true || element.attribs[allowDefaultColor]) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
59
65
|
currentItem = currentItem.parent;
|
|
60
66
|
if (currentItem?.usedAsMask) {
|
|
61
67
|
return defaultColorValues[prop2];
|
|
@@ -64,7 +70,7 @@ async function parseColors(svg, options = {}) {
|
|
|
64
70
|
return defaultColorValues[prop2];
|
|
65
71
|
}
|
|
66
72
|
let propColor = find(prop);
|
|
67
|
-
if (typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
|
|
73
|
+
if (propColor !== null && typeof propColor === "object" && propColor.type === "current" && prop !== "color") {
|
|
68
74
|
propColor = find("color");
|
|
69
75
|
}
|
|
70
76
|
return propColor;
|
package/lib/misc/keyword.cjs
CHANGED
|
@@ -6,7 +6,7 @@ function cleanupIconKeyword(keyword, convertCamelCase = false) {
|
|
|
6
6
|
if (convertCamelCase) {
|
|
7
7
|
keyword = keyword.replace(/[A-Z]+/g, (chars) => "_" + chars.toLowerCase());
|
|
8
8
|
}
|
|
9
|
-
keyword = keyword.toLowerCase().trim().replace(/[
|
|
9
|
+
keyword = keyword.toLowerCase().trim().replace(/[\s_.:]/g, "-").replace(/[^a-z0-9-]/g, "").replace(/[-]+/g, "-");
|
|
10
10
|
if (keyword.slice(0, 1) === "-") {
|
|
11
11
|
keyword = keyword.slice(1);
|
|
12
12
|
}
|
package/lib/misc/keyword.mjs
CHANGED
|
@@ -2,7 +2,7 @@ function cleanupIconKeyword(keyword, convertCamelCase = false) {
|
|
|
2
2
|
if (convertCamelCase) {
|
|
3
3
|
keyword = keyword.replace(/[A-Z]+/g, (chars) => "_" + chars.toLowerCase());
|
|
4
4
|
}
|
|
5
|
-
keyword = keyword.toLowerCase().trim().replace(/[
|
|
5
|
+
keyword = keyword.toLowerCase().trim().replace(/[\s_.:]/g, "-").replace(/[^a-z0-9-]/g, "").replace(/[-]+/g, "-");
|
|
6
6
|
if (keyword.slice(0, 1) === "-") {
|
|
7
7
|
keyword = keyword.slice(1);
|
|
8
8
|
}
|
|
@@ -33,6 +33,10 @@ async function cleanupInlineStyle(svg) {
|
|
|
33
33
|
$element.attr(prop, value);
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
+
if (svg_data_attributes.tagSpecificInlineStyles[tagName]?.has(prop)) {
|
|
37
|
+
newStyle[prop] = value;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
36
40
|
if (svg_data_attributes.insideClipPathAttributes.has(prop)) {
|
|
37
41
|
if (item.parents.find((item2) => item2.tagName === "clipPath")) {
|
|
38
42
|
$element.attr(prop, value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseInlineStyle } from '../../css/parse.mjs';
|
|
2
|
-
import { badAttributes, tagSpecificNonPresentationalAttributes, tagSpecificAnimatedAttributes, tagSpecificPresentationalAttributes, insideClipPathAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
|
|
2
|
+
import { badAttributes, tagSpecificNonPresentationalAttributes, tagSpecificAnimatedAttributes, tagSpecificPresentationalAttributes, tagSpecificInlineStyles, insideClipPathAttributes, badSoftwareAttributes, badAttributePrefixes } from '../data/attributes.mjs';
|
|
3
3
|
import { parseSVG } from '../parse.mjs';
|
|
4
4
|
import '../../css/parser/tokens.mjs';
|
|
5
5
|
import '../../css/parser/error.mjs';
|
|
@@ -29,6 +29,10 @@ async function cleanupInlineStyle(svg) {
|
|
|
29
29
|
$element.attr(prop, value);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
+
if (tagSpecificInlineStyles[tagName]?.has(prop)) {
|
|
33
|
+
newStyle[prop] = value;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
32
36
|
if (insideClipPathAttributes.has(prop)) {
|
|
33
37
|
if (item.parents.find((item2) => item2.tagName === "clipPath")) {
|
|
34
38
|
$element.attr(prop, value);
|
|
@@ -327,6 +327,9 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
327
327
|
"type"
|
|
328
328
|
])
|
|
329
329
|
};
|
|
330
|
+
const tagSpecificInlineStyles = {
|
|
331
|
+
mask: /* @__PURE__ */ new Set(["mask-type"])
|
|
332
|
+
};
|
|
330
333
|
|
|
331
334
|
exports.animationTimingAttributes = animationTimingAttributes;
|
|
332
335
|
exports.animationValueAttributes = animationValueAttributes;
|
|
@@ -349,6 +352,7 @@ exports.presentationalAttributes = presentationalAttributes;
|
|
|
349
352
|
exports.strokePresentationalAttributes = strokePresentationalAttributes;
|
|
350
353
|
exports.stylingAttributes = stylingAttributes;
|
|
351
354
|
exports.tagSpecificAnimatedAttributes = tagSpecificAnimatedAttributes;
|
|
355
|
+
exports.tagSpecificInlineStyles = tagSpecificInlineStyles;
|
|
352
356
|
exports.tagSpecificNonPresentationalAttributes = tagSpecificNonPresentationalAttributes;
|
|
353
357
|
exports.tagSpecificPresentationalAttributes = tagSpecificPresentationalAttributes;
|
|
354
358
|
exports.urlPresentationalAttributes = urlPresentationalAttributes;
|
|
@@ -69,5 +69,9 @@ declare const feFuncAttributes: Set<string>;
|
|
|
69
69
|
declare const tagSpecificAnimatedAttributes: Record<string, Set<string>>;
|
|
70
70
|
declare const tagSpecificPresentationalAttributes: Record<string, Set<string>>;
|
|
71
71
|
declare const tagSpecificNonPresentationalAttributes: Record<string, Set<string>>;
|
|
72
|
+
/**
|
|
73
|
+
* Styles to keep in tags
|
|
74
|
+
*/
|
|
75
|
+
declare const tagSpecificInlineStyles: Record<string, Set<string>>;
|
|
72
76
|
|
|
73
|
-
export { animationTimingAttributes, animationValueAttributes, badAttributePrefixes, badAttributes, badSoftwareAttributes, commonAttributes, commonColorPresentationalAttributes, commonFeAttributes, commonGradientAttributes, feFuncAttributes, fillPresentationalAttributes, insideClipPathAttributes, junkSVGAttributes, markerAttributes, otherAnimationAttributes, otherPresentationalAttributes, otherShapeAttributes, presentationalAttributes, strokePresentationalAttributes, stylingAttributes, tagSpecificAnimatedAttributes, tagSpecificNonPresentationalAttributes, tagSpecificPresentationalAttributes, urlPresentationalAttributes, visibilityPresentationalAttributes };
|
|
77
|
+
export { animationTimingAttributes, animationValueAttributes, badAttributePrefixes, badAttributes, badSoftwareAttributes, commonAttributes, commonColorPresentationalAttributes, commonFeAttributes, commonGradientAttributes, feFuncAttributes, fillPresentationalAttributes, insideClipPathAttributes, junkSVGAttributes, markerAttributes, otherAnimationAttributes, otherPresentationalAttributes, otherShapeAttributes, presentationalAttributes, strokePresentationalAttributes, stylingAttributes, tagSpecificAnimatedAttributes, tagSpecificInlineStyles, tagSpecificNonPresentationalAttributes, tagSpecificPresentationalAttributes, urlPresentationalAttributes, visibilityPresentationalAttributes };
|
|
@@ -323,5 +323,8 @@ const tagSpecificNonPresentationalAttributes = {
|
|
|
323
323
|
"type"
|
|
324
324
|
])
|
|
325
325
|
};
|
|
326
|
+
const tagSpecificInlineStyles = {
|
|
327
|
+
mask: /* @__PURE__ */ new Set(["mask-type"])
|
|
328
|
+
};
|
|
326
329
|
|
|
327
|
-
export { animationTimingAttributes, animationValueAttributes, badAttributePrefixes, badAttributes, badSoftwareAttributes, commonAttributes, commonColorPresentationalAttributes, commonFeAttributes, commonGradientAttributes, feFuncAttributes, fillPresentationalAttributes, insideClipPathAttributes, junkSVGAttributes, markerAttributes, otherAnimationAttributes, otherPresentationalAttributes, otherShapeAttributes, presentationalAttributes, strokePresentationalAttributes, stylingAttributes, tagSpecificAnimatedAttributes, tagSpecificNonPresentationalAttributes, tagSpecificPresentationalAttributes, urlPresentationalAttributes, visibilityPresentationalAttributes };
|
|
330
|
+
export { animationTimingAttributes, animationValueAttributes, badAttributePrefixes, badAttributes, badSoftwareAttributes, commonAttributes, commonColorPresentationalAttributes, commonFeAttributes, commonGradientAttributes, feFuncAttributes, fillPresentationalAttributes, insideClipPathAttributes, junkSVGAttributes, markerAttributes, otherAnimationAttributes, otherPresentationalAttributes, otherShapeAttributes, presentationalAttributes, strokePresentationalAttributes, stylingAttributes, tagSpecificAnimatedAttributes, tagSpecificInlineStyles, tagSpecificNonPresentationalAttributes, tagSpecificPresentationalAttributes, urlPresentationalAttributes, visibilityPresentationalAttributes };
|
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.1.0-beta.
|
|
6
|
+
"version": "2.1.0-beta.7",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/iconify/tools/issues",
|
|
9
9
|
"homepage": "https://github.com/iconify/tools",
|