Skip to content

Commit 810ea34

Browse files
author
Adam Argyle
committed
Merge branch 'master' of https://github.com/w3c/csswg-drafts
2 parents 85ddc91 + 046d9c2 commit 810ea34

File tree

2 files changed

+62
-44
lines changed

2 files changed

+62
-44
lines changed

css-color-4/contrast.html

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,62 @@
1-
<html>
2-
<script src="math.js"></script>
3-
<script src="conversions.js"></script>
4-
<script src="utilities.js"></script>
5-
<script>
6-
// read the foreground abd background colors
7-
// then use the contrast() utility function
8-
// to compute WCAG contrast.
9-
10-
var back, fore, bgcol, fgcol;
11-
window.addEventListener("load", startup, false);
12-
13-
function startup() {
14-
back=document.querySelector(#fg);
15-
fore=document.querySelector(#bg);
16-
back.addEventListener("input", watchpickers, false);
17-
fore.addEventListener("input", watchpickers, false);
18-
}
19-
20-
function watchpickers(event) {
21-
// if either picker changes, update the two colors
22-
// and output the contrast ratio
23-
24-
var contrast = document.querySelector("result>span");
25-
bgcol = event.target.value;
26-
fgcol =
27-
}
28-
</script>
29-
<style>
30-
body {background-color: rgb(46.6346021727084%, 46.6346021727084%, 46.6346021727084%); padding: 20px;}
31-
h2 {color: rgb(243, 235, 166);}
32-
</style>
33-
<h2>Contrast ratio of two colors</h2>
34-
<p>Pick a foreground and background color</p>
35-
<input type="color" id="fg" value="#B7C9A3">
36-
<label for="fg">Foreground</label>
37-
<input type="color" id="fg" value="#104425">
38-
<label for="fg">Background</label>
39-
40-
<div id="result">
41-
Contrast ratio <span></span>.
42-
</div>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
<script src="math.js"></script>
6+
<script src="conversions.js"></script>
7+
<script src="utilities.js"></script>
8+
9+
<style>
10+
body {background-color: rgb(46.6346021727084%, 46.6346021727084%, 46.6346021727084%); padding: 20px;}
11+
h2 {color: rgb(243, 235, 166);}
12+
</style>
13+
14+
</head>
15+
<body>
16+
17+
<h2>Contrast ratio of two colors</h2>
18+
<p>Pick a foreground and background color</p>
19+
20+
<input type="color" id="fg" value="#B7C9A3">
21+
<label for="fg">Foreground</label>
22+
<input type="color" id="bg" value="#104425">
23+
<label for="bg">Background</label>
24+
25+
<div id="result">
26+
Contrast ratio <output id="contrastResult"></output>.
27+
</div>
28+
29+
30+
<script>
31+
// read the foreground and background colors
32+
// then use the contrast() utility function
33+
// to compute WCAG contrast.
34+
35+
var fgInput = document.querySelector("#fg");
36+
var bgInput = document.querySelector("#bg");
37+
var contrastOutput = document.querySelector("#contrastResult");
38+
var bgColor, fgColor;
39+
40+
// if any picker changes, update the color
41+
// and output the contrast ratio
42+
(fgInput.oninput = bgInput.oninput = function (event) {
43+
bgColor = hexToArray(bgInput.value);
44+
fgColor = hexToArray(fgInput.value);
45+
console.log("watch", bgColor, fgColor);
46+
contrastOutput.value = contrast(bgColor, fgColor);
47+
// convert from string to array of number
48+
// compute contrast
49+
// update span
50+
})();
51+
52+
53+
54+
function hexToArray(hex) {
55+
return hex.match(/[\dA-F]{2}/ig).map(x => parseInt(x, 16) / 255);
56+
}
57+
58+
</script>
59+
60+
</body>
4361

4462
</html>

css-color-4/utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// utility functions for color conversions
2-
// needs conversions.js nd math.js (not Math)
2+
// needs conversions.js and math.js (not Math)
33

44
function sRGB_to_luminance(RGB) {
55
// convert an array of gamma-corrected sRGB values
@@ -46,5 +46,5 @@ function LCH_to_sRGB(LCH) {
4646
// or components greater than 1.0
4747
// so check for that :)
4848

49-
return gam(sRGB(XYZ_to_lin_sRGB(Lab_to_XYZ(D50_to_D65(LCH_to_Lab(LCH))))));
49+
return gam_sRGB(XYZ_to_lin_sRGB(Lab_to_XYZ(D50_to_D65(LCH_to_Lab(LCH)))));
5050
}

0 commit comments

Comments
 (0)