Skip to content

Commit

Permalink
Update color.js and run benchmark
Browse files Browse the repository at this point in the history
# dom/get-computed-style/getComputedStyle() on document.body #
jsdom  x 28,467 ops/sec ±1.05% (89 runs sampled)

# dom/get-computed-style/getComputedStyle() on element with non-rgb color #
jsdom  x 29,178 ops/sec ±0.91% (91 runs sampled)

# dom/get-computed-style/getComputedStyle() on element with rgb color #
jsdom  x 13,822 ops/sec ±2.08% (84 runs sampled)
  • Loading branch information
asamuzaK committed Jan 27, 2024
1 parent ab9c439 commit 001a58e
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit 001a58e

Please sign in to comment.