fix theme detection in color picker
This commit is contained in:
parent
6dc87d2a31
commit
06cc37cffa
|
@ -18,7 +18,7 @@ function colorMimicry(el, targets, dummyContainer = document.body) {
|
||||||
let numTotal = 0;
|
let numTotal = 0;
|
||||||
const rootStyle = getStyle(document.documentElement);
|
const rootStyle = getStyle(document.documentElement);
|
||||||
for (const k in targets) {
|
for (const k in targets) {
|
||||||
const base = {r: 255, g: 255, b: 255, a: 1};
|
const base = {r: 0, g: 0, b: 0, a: 0};
|
||||||
blend(base, rootStyle[targets[k]]);
|
blend(base, rootStyle[targets[k]]);
|
||||||
colors[k] = base;
|
colors[k] = base;
|
||||||
numTotal++;
|
numTotal++;
|
||||||
|
@ -45,6 +45,10 @@ function colorMimicry(el, targets, dummyContainer = document.body) {
|
||||||
el.remove();
|
el.remove();
|
||||||
}
|
}
|
||||||
for (const k in targets) {
|
for (const k in targets) {
|
||||||
|
const c = colors[k];
|
||||||
|
if (!isOpaque(c)) {
|
||||||
|
blend(colors[k] = {r: 255, g: 255, b: 255, a: 1}, c);
|
||||||
|
}
|
||||||
const {r, g, b, a} = colors[k];
|
const {r, g, b, a} = colors[k];
|
||||||
colors[k] = `rgba(${r}, ${g}, ${b}, ${a})`;
|
colors[k] = `rgba(${r}, ${g}, ${b}, ${a})`;
|
||||||
// https://www.w3.org/TR/AERT#color-contrast
|
// https://www.w3.org/TR/AERT#color-contrast
|
||||||
|
@ -69,7 +73,7 @@ function colorMimicry(el, targets, dummyContainer = document.body) {
|
||||||
base.b = Math.round(b * q1 + base.b * q2);
|
base.b = Math.round(b * q1 + base.b * q2);
|
||||||
base.a = mixedA;
|
base.a = mixedA;
|
||||||
}
|
}
|
||||||
return Math.abs(base.a - 1) < 1e-3;
|
return isOpaque(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
// speed-up for sequential invocations within the same event loop cycle
|
// speed-up for sequential invocations within the same event loop cycle
|
||||||
|
@ -86,4 +90,8 @@ function colorMimicry(el, targets, dummyContainer = document.body) {
|
||||||
function clearCache() {
|
function clearCache() {
|
||||||
styleCache.clear();
|
styleCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isOpaque({a}) {
|
||||||
|
return Math.abs(a - 1) < 1e-3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user