Skip to content

Commit ffb2cb4

Browse files
committed
chore: support CSS Color Level 4 syntax for semi-transparent colors in test-contrast script
1 parent dcf63e9 commit ffb2cb4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/test-contrast.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ const selfAndBackground = async(el, parent) => {
281281

282282
// If background is semi-transparent, blend it with the parent background
283283
// to get the actual solid background color
284-
if (background.indexOf('rgba') > -1 && background !== 'rgba(255, 255, 255, 1)') {
284+
if ((background.indexOf('rgba') > -1 && background !== 'rgba(255, 255, 255, 1)') ||
285+
(background.includes('color(srgb') && background.includes('/'))) {
285286
let parentParent = await (par || parent).findElement(By.xpath('..'));
286287
let parentBackground = await parentParent.getCssValue('backgroundColor');
287288

@@ -296,11 +297,11 @@ const selfAndBackground = async(el, parent) => {
296297

297298
// If element background is semi-transparent, blend it with the background
298299
// to get the actual solid element background color
299-
if (self.indexOf('rgba') > -1 && self !== 'rgba(255, 255, 255, 1)') {
300+
if ((self.indexOf('rgba') > -1 && self !== 'rgba(255, 255, 255, 1)') ||
301+
(self.includes('color(srgb') && self.includes('/'))) {
300302
decomposed = getRGBFromRGBA(decomposeColor(self), decomposeColor(background));
301303
self = 'rgb(' + decomposed.r + ', ' + decomposed.g + ', ' + decomposed.b + ')';
302304
}
303-
304305
// If element background is fully transparent, use the background color
305306
// of the parent element instead
306307
if (self === 'rgba(0, 0, 0, 0)') {

0 commit comments

Comments
 (0)