| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="UTF-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 |
<link rel="help" href="https://drafts.csswg.org/css-color-adjust/#color-scheme-effect"> |
| 7 |
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7561"> |
| 8 |
<title>light-dark() color-scheme propagation</title> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<style> |
| 12 |
.box { |
| 13 |
min-width: 100px; |
| 14 |
min-height: 100px; |
| 15 |
margin: 10px; |
| 16 |
padding: 10px; |
| 17 |
border-width: 2px; |
| 18 |
border-style: solid; |
| 19 |
} |
| 20 |
</style> |
| 21 |
<div class="box" id="a"> |
| 22 |
<div class="box light" id="b"> |
| 23 |
<div class="box" id="c"> |
| 24 |
<div class="box dark" id="d"> |
| 25 |
<div class="box" id="e"></div> |
| 26 |
</div> |
| 27 |
</div> |
| 28 |
</div> |
| 29 |
</div> |
| 30 |
|
| 31 |
<div id="log"></div> |
| 32 |
<script type="module"> |
| 33 |
window.addEventListener('click', () => { |
| 34 |
window.runTest(); |
| 35 |
}); |
| 36 |
|
| 37 |
window.runTest = async function runTest() { |
| 38 |
const system_is_dark = matchMedia("(prefers-color-scheme: dark)").matches; |
| 39 |
|
| 40 |
function assert_equals(actual, expected, message) { |
| 41 |
if (actual !== expected) { |
| 42 |
log.innerHTML = message + ": expected " + expected + ", got " + actual; |
| 43 |
throw new Error(message + ": expected " + expected + ", got " + actual); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
{ |
| 48 |
const styleElement = document.createElement('style'); |
| 49 |
|
| 50 |
const testCaseStyle = await (fetch(`/test/styles.css`, { |
| 51 |
method: 'POST', |
| 52 |
body: ` |
| 53 |
:root { |
| 54 |
color-scheme: light dark; |
| 55 |
} |
| 56 |
|
| 57 |
.light { |
| 58 |
color-scheme: light; |
| 59 |
} |
| 60 |
|
| 61 |
.dark { |
| 62 |
color-scheme: dark; |
| 63 |
} |
| 64 |
|
| 65 |
#a { |
| 66 |
--color-a: light-dark(rgb(1, 0, 0), rgb(0, 1, 0)); |
| 67 |
color: light-dark(rgb(2, 0, 0), rgb(0, 2, 0)); |
| 68 |
} |
| 69 |
|
| 70 |
.box { |
| 71 |
border-color: var(--color-a); |
| 72 |
} |
| 73 |
`, |
| 74 |
}).then((response) => response.text())); |
| 75 |
|
| 76 |
styleElement.textContent = testCaseStyle; |
| 77 |
document.head.append(styleElement); |
| 78 |
|
| 79 |
const a = getComputedStyle(document.getElementById('a')); |
| 80 |
const b = getComputedStyle(document.getElementById('b')); |
| 81 |
const c = getComputedStyle(document.getElementById('c')); |
| 82 |
const d = getComputedStyle(document.getElementById('d')); |
| 83 |
const e = getComputedStyle(document.getElementById('e')); |
| 84 |
|
| 85 |
assert_equals(a.color, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'a color'); |
| 86 |
assert_equals(a.borderColor, system_is_dark ? 'rgb(0, 1, 0)' : 'rgb(1, 0, 0)', 'a border-color'); |
| 87 |
|
| 88 |
assert_equals(b.color, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'b color'); |
| 89 |
assert_equals(b.borderColor, 'rgb(1, 0, 0)', 'b border-color'); |
| 90 |
|
| 91 |
assert_equals(c.color, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'c color'); |
| 92 |
assert_equals(c.borderColor, 'rgb(1, 0, 0)', 'c border-color'); |
| 93 |
|
| 94 |
assert_equals(d.color, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'd color'); |
| 95 |
assert_equals(d.borderColor, 'rgb(0, 1, 0)', 'd border-color'); |
| 96 |
|
| 97 |
assert_equals(e.color, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'e color'); |
| 98 |
assert_equals(e.borderColor, 'rgb(0, 1, 0)', 'e border-color'); |
| 99 |
|
| 100 |
styleElement.remove(); |
| 101 |
} |
| 102 |
|
| 103 |
{ |
| 104 |
const styleElement = document.createElement('style'); |
| 105 |
|
| 106 |
const testCaseStyle = await (fetch(`/test/styles.css`, { |
| 107 |
method: 'POST', |
| 108 |
body: ` |
| 109 |
:root { |
| 110 |
color-scheme: light dark; |
| 111 |
} |
| 112 |
|
| 113 |
.light { |
| 114 |
color-scheme: light; |
| 115 |
} |
| 116 |
|
| 117 |
.dark { |
| 118 |
color-scheme: dark; |
| 119 |
} |
| 120 |
|
| 121 |
#a { |
| 122 |
--color-a: light-dark(rgb(1, 0, 0), rgb(0, 1, 0)); |
| 123 |
color: green; |
| 124 |
background-color: light-dark(rgb(2, 0, 0), rgb(0, 2, 0)); |
| 125 |
border-color: var(--color-a); |
| 126 |
} |
| 127 |
`, |
| 128 |
}).then((response) => response.text())); |
| 129 |
|
| 130 |
styleElement.textContent = testCaseStyle; |
| 131 |
document.head.append(styleElement); |
| 132 |
|
| 133 |
const a = getComputedStyle(document.getElementById('a')); |
| 134 |
const b = getComputedStyle(document.getElementById('b')); |
| 135 |
// const c = getComputedStyle(document.getElementById('c')); |
| 136 |
// const d = getComputedStyle(document.getElementById('d')); |
| 137 |
// const e = getComputedStyle(document.getElementById('e')); |
| 138 |
|
| 139 |
assert_equals(a.color, 'rgb(0, 128, 0)', 'a color'); |
| 140 |
assert_equals(a.backgroundColor, system_is_dark ? 'rgb(0, 2, 0)' : 'rgb(2, 0, 0)', 'a background-color'); |
| 141 |
assert_equals(a.borderColor, system_is_dark ? 'rgb(0, 1, 0)' : 'rgb(1, 0, 0)', 'a border-color'); |
| 142 |
|
| 143 |
assert_equals(b.color, 'rgb(0, 128, 0)', 'b color'); |
| 144 |
assert_equals(b.backgroundColor, 'rgba(0, 0, 0, 0)', 'b background-color'); |
| 145 |
assert_equals(b.borderColor, 'rgb(0, 128, 0)', 'b border-color'); |
| 146 |
|
| 147 |
styleElement.remove(); |
| 148 |
} |
| 149 |
|
| 150 |
{ |
| 151 |
const styleElement = document.createElement('style'); |
| 152 |
|
| 153 |
const testCaseStyle = await (fetch(`/test/styles.css`, { |
| 154 |
method: 'POST', |
| 155 |
body: ` |
| 156 |
.light { |
| 157 |
color-scheme: light; |
| 158 |
} |
| 159 |
|
| 160 |
.dark { |
| 161 |
color-scheme: dark; |
| 162 |
} |
| 163 |
|
| 164 |
#a { |
| 165 |
--color-a: light-dark(rgb(1, 0, 0), rgb(0, 1, 0)); |
| 166 |
color: green; |
| 167 |
background-color: light-dark(rgb(2, 0, 0), rgb(0, 2, 0)); |
| 168 |
border-color: var(--color-a); |
| 169 |
} |
| 170 |
`, |
| 171 |
}).then((response) => response.text())); |
| 172 |
|
| 173 |
styleElement.textContent = testCaseStyle; |
| 174 |
document.head.append(styleElement); |
| 175 |
|
| 176 |
const a = getComputedStyle(document.getElementById('a')); |
| 177 |
const b = getComputedStyle(document.getElementById('b')); |
| 178 |
// const c = getComputedStyle(document.getElementById('c')); |
| 179 |
// const d = getComputedStyle(document.getElementById('d')); |
| 180 |
// const e = getComputedStyle(document.getElementById('e')); |
| 181 |
|
| 182 |
assert_equals(a.color, 'rgb(0, 128, 0)', 'a color'); |
| 183 |
assert_equals(a.backgroundColor, 'rgb(2, 0, 0)', 'a background-color'); |
| 184 |
assert_equals(a.borderColor, 'rgb(1, 0, 0)', 'a border-color'); |
| 185 |
|
| 186 |
assert_equals(b.color, 'rgb(0, 128, 0)', 'b color'); |
| 187 |
assert_equals(b.backgroundColor, 'rgba(0, 0, 0, 0)', 'b background-color'); |
| 188 |
assert_equals(b.borderColor, 'rgb(0, 128, 0)', 'b border-color'); |
| 189 |
|
| 190 |
styleElement.remove(); |
| 191 |
} |
| 192 |
|
| 193 |
return true; |
| 194 |
} |
| 195 |
</script> |
| 196 |
</body> |
| 197 |
</html> |