Skip to content

Commit

Permalink
Replace SVG attribute names in custom/element.json (#998)
Browse files Browse the repository at this point in the history
Replace SVG attribte names in custom/element.json
  • Loading branch information
Elchi3 authored Dec 21, 2023
1 parent c08c004 commit 96ddb16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
45 changes: 26 additions & 19 deletions custom/elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,11 @@
"circle": ["cx", "cy", "r"],
"clipPath": ["clipPathUnits"],
"ellipse": ["cx", "cy", "rx", "ry"],
"feBlend": ["in", "in2", "mode"],
"feColorMatrix": ["in", "type", "values"],
"feComponentTransfer": ["in"],
"feBlend": [{"in": "in1"}, "in2", "mode"],
"feColorMatrix": [{"in": "in1"}, "type", "values"],
"feComponentTransfer": [{"in": "in1"}],
"feComposite": [
"in",
{"in": "in1"},
"in2",
"k1",
"k2",
Expand All @@ -595,39 +595,46 @@
"bias",
"divisor",
"edgeMode",
"in",
{
"in": "in1",
"kernelUnitLength": "kernelUnitLengthX",
"order": "orderX"
},
"kernelMatrix",
"kernelUnitLength",
"order",
"preserveAlpha",
"targetX",
"targetY"
],
"feDiffuseLighting": [
"diffuseConstant",
"in",
"kernelUnitLength",
{"in": "in1", "kernelUnitLength": "kernelUnitLengthX"},
"surfaceScale"
],
"feDisplacementMap": [
"in",
{"in": "in1"},
"in2",
"scale",
"xChannelSelector",
"yChannelSelector"
],
"feDistantLight": ["azimuth", "elevation"],
"feDropShadow": ["dx", "dy", "in", "stdDeviation"],
"feDropShadow": [
"dx",
"dy",
{"in": "in1", "stdDeviation": "stdDeviationX"}
],
"feFlood": ["flood-color", "flood-opacity"],
"feGaussianBlur": ["edgeMode", "in", "stdDeviation"],
"feGaussianBlur": [
"edgeMode",
{"in": "in1", "stdDeviation": "stdDeviationX"}
],
"feImage": ["crossorigin", "href", "preserveAspectRatio", "xlink_href"],
"feMergeNode": ["in"],
"feMorphology": ["in", "operator", "radius"],
"feOffset": ["dx", "dy", "in"],
"feMergeNode": [{"in": "in1"}],
"feMorphology": [{"in": "in1", "radius": "radiusX"}, "operator"],
"feOffset": ["dx", "dy", {"in": "in1"}],
"fePointLight": ["x", "y", "z"],
"feSpecularLighting": [
"in",
"kernelUnitLength",
{"in": "in1", "kernelUnitLength": "kernelUnitLengthX"},
"specularConstant",
"specularExponent",
"surfaceScale"
Expand All @@ -642,9 +649,9 @@
"y",
"z"
],
"feTile": ["in"],
"feTile": [{"in": "in1"}],
"feTurbulence": [
"baseFrequency",
{"baseFrequency": "baseFrequencyX"},
"numOctaves",
"seed",
"stitchTiles",
Expand Down
27 changes: 4 additions & 23 deletions test-builder/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,14 @@ const build = async (specElements, customElements) => {
return !!instance && '${attrProp}' in instance;
})()`;

// Some SVG attribute names are reflected differently in SVGOM
if (category === "svg") {
const replacements = {
baseFrequency: "baseFrequencyX",
in: "in1",
kernelUnitLength: "kernelUnitLengthX",
order: "orderX",
radius: "radiusX",
stdDeviation: "stdDeviationX",
};

if (attrProp in replacements) {
attrCode = attrCode.replace(
`'${attrProp}'`,
`'${replacements[attrProp]}'`,
);
}

// All xlink attributes need special handling
if (attrProp.startsWith("xlink_")) {
const xlinkAttr = attrProp.replace("xlink_", "");
attrCode = `(function() {
// All xlink attributes need special handling
if (attrProp.startsWith("xlink_")) {
const xlinkAttr = attrProp.replace("xlink_", "");
attrCode = `(function() {
var instance = ${defaultConstructCode};
instance.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:${xlinkAttr}', 'test');
return !!instance && instance.getAttributeNS('http://www.w3.org/1999/xlink', '${xlinkAttr}') === 'test';
})()`;
}
}

tests[`${bcdPath}.${attrName}`] = compileTest({
Expand Down

0 comments on commit 96ddb16

Please sign in to comment.