Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use css-color module #3674

Closed
wants to merge 12 commits into from
Closed
48 changes: 48 additions & 0 deletions benchmark/dom/get-computed-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";
const suite = require("../document-suite");

exports["getComputedStyle() on document.body"] = () => {
let window, document;

return suite({
setup(doc) {
window = doc.defaultView;
document = doc;
},
fn() {
window.getComputedStyle(document.body);
}
});
};

exports["getComputedStyle() on element with rgb color"] = () => {
let window, node;

return suite({
setup(doc) {
window = doc.defaultView;
node = doc.createElement("div");
node.style.color = "rgb(128, 0, 128)";
doc.body.appendChild(node);
},
fn() {
window.getComputedStyle(node);
}
});
};

exports["getComputedStyle() on element with non-rgb color"] = () => {
let window, node;

return suite({
setup(doc) {
window = doc.defaultView;
node = doc.createElement("div");
node.style.color = "color-mix(in srgb, red, blue)";
doc.body.appendChild(node);
},
fn() {
window.getComputedStyle(node);
}
});
};
3 changes: 2 additions & 1 deletion benchmark/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
"tree-modification": require("./tree-modification"),
"compare-document-position": require("./compare-document-position"),
"named-properties": require("./named-properties"),
"inner-html": require("./inner-html")
"inner-html": require("./inner-html"),
"get-computed-style": require("./get-computed-style")
};
6 changes: 4 additions & 2 deletions lib/jsdom/living/helpers/colors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const { resolve: getResolvedValueForColor } = require("@asamuzakjp/css-color");

// https://drafts.csswg.org/css-color-4/#named-color
const namedColors = {
__proto__: null,
Expand Down Expand Up @@ -193,11 +195,11 @@ function sharedSpecifiedAndComputedAndUsed(color) {
return hexToRGBA(color.slice(1));
}

if (/^rgba?\(/.test(color)) {
if (/^rgba?\(/.test(color) && color.includes(",")) {
return color.split(",").map(s => s.trim()).join(", ");
}

return color;
return getResolvedValueForColor(color);
}

function hexToRGB(color) {
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"license": "MIT",
"repository": "jsdom/jsdom",
"dependencies": {
"@asamuzakjp/css-color": "^1.0.1",
"cssstyle": "^4.0.1",
"data-urls": "^5.0.0",
"decimal.js": "^10.4.3",
Expand Down