Upload color.html with huggingface_hub
Browse files- color.html +126 -0
color.html
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
<title>color.convert β Hex, RGB, HSL with preview</title>
|
| 7 |
+
<style>
|
| 8 |
+
*{margin:0;padding:0;box-sizing:border-box}
|
| 9 |
+
body{background:#0d1117;color:#c9d1d9;font-family:-apple-system,'Segoe UI',monospace;min-height:100vh;padding:3rem 1rem;display:flex;flex-direction:column;align-items:center}
|
| 10 |
+
h1{font-size:2rem;color:#f0f6fc;margin-bottom:.25rem}
|
| 11 |
+
.sub{color:#484f58;margin-bottom:2rem}
|
| 12 |
+
.panel{width:100%;max-width:600px}
|
| 13 |
+
label{color:#8b949e;font-size:.85rem;display:block;margin-bottom:.35rem;margin-top:1.25rem}
|
| 14 |
+
input[type=text]{background:#161b22;border:1px solid #30363d;border-radius:6px;padding:.75rem 1rem;color:#f0f6fc;font-family:'Courier New',monospace;font-size:1.1rem;outline:none;width:100%}
|
| 15 |
+
input:focus{border-color:#58a6ff}
|
| 16 |
+
.preview-row{display:flex;gap:1rem;margin-top:1.25rem;align-items:stretch}
|
| 17 |
+
.swatch{width:120px;min-height:120px;border-radius:8px;border:1px solid #30363d}
|
| 18 |
+
.values{flex:1;background:#161b22;border:1px solid #30363d;border-radius:8px;padding:1rem}
|
| 19 |
+
.val-row{display:flex;justify-content:space-between;padding:.4rem 0;border-bottom:1px solid #21262d}
|
| 20 |
+
.val-row:last-child{border:none}
|
| 21 |
+
.val-label{color:#8b949e;font-size:.85rem}
|
| 22 |
+
.val-value{color:#f0f6fc;font-family:'Courier New',monospace;cursor:pointer;padding:.1rem .3rem;border-radius:3px}
|
| 23 |
+
.val-value:hover{background:#21262d}
|
| 24 |
+
.contrast{background:#161b22;border:1px solid #30363d;border-radius:8px;padding:1rem;margin-top:1rem}
|
| 25 |
+
.contrast h3{color:#8b949e;font-size:.8rem;text-transform:uppercase;margin-bottom:.5rem}
|
| 26 |
+
.contrast-demo{padding:.75rem;border-radius:4px;text-align:center;margin-top:.5rem;font-size:.9rem}
|
| 27 |
+
.ratio{font-size:.85rem;margin-top:.5rem}
|
| 28 |
+
.ratio.pass{color:#3fb950}
|
| 29 |
+
.ratio.fail{color:#f85149}
|
| 30 |
+
.footer{margin-top:3rem;color:#30363d;font-size:.75rem}
|
| 31 |
+
</style>
|
| 32 |
+
</head>
|
| 33 |
+
<body>
|
| 34 |
+
<h1>color.convert</h1>
|
| 35 |
+
<p class="sub">Hex β RGB β HSL with contrast check</p>
|
| 36 |
+
|
| 37 |
+
<div class="panel">
|
| 38 |
+
<label>Enter any color (hex, rgb, hsl, or name)</label>
|
| 39 |
+
<input id="input" type="text" placeholder="#58a6ff or rgb(88,166,255) or hsl(212,100%,67%) or cornflowerblue">
|
| 40 |
+
|
| 41 |
+
<div class="preview-row" id="preview" style="display:none">
|
| 42 |
+
<div class="swatch" id="swatch"></div>
|
| 43 |
+
<div class="values" id="values"></div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="contrast" id="contrast" style="display:none">
|
| 47 |
+
<h3>Contrast check</h3>
|
| 48 |
+
<div class="contrast-demo" id="onWhite">Text on white</div>
|
| 49 |
+
<div class="contrast-demo" id="onBlack">Text on black</div>
|
| 50 |
+
<div class="contrast-demo" id="whiteOn">White text on color</div>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
|
| 54 |
+
<div class="footer">Built by Atreus β dev.tools collection</div>
|
| 55 |
+
|
| 56 |
+
<script>
|
| 57 |
+
document.getElementById('input').addEventListener('input', convert);
|
| 58 |
+
|
| 59 |
+
function convert() {
|
| 60 |
+
const raw = document.getElementById('input').value.trim();
|
| 61 |
+
const preview = document.getElementById('preview');
|
| 62 |
+
const contrastEl = document.getElementById('contrast');
|
| 63 |
+
if (!raw) { preview.style.display='none'; contrastEl.style.display='none'; return; }
|
| 64 |
+
|
| 65 |
+
// Parse color using canvas
|
| 66 |
+
const ctx = document.createElement('canvas').getContext('2d');
|
| 67 |
+
ctx.fillStyle = '#000000';
|
| 68 |
+
ctx.fillStyle = raw;
|
| 69 |
+
const parsed = ctx.fillStyle;
|
| 70 |
+
|
| 71 |
+
// If it didn't change from black and input isn't black
|
| 72 |
+
if (parsed === '#000000' && raw.toLowerCase() !== '#000000' && raw.toLowerCase() !== 'black' && raw !== '#000' && raw !== 'rgb(0,0,0)' && raw !== 'rgb(0, 0, 0)') {
|
| 73 |
+
preview.style.display='none'; contrastEl.style.display='none'; return;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// Extract RGB
|
| 77 |
+
const hex = parsed;
|
| 78 |
+
const r = parseInt(hex.slice(1,3),16);
|
| 79 |
+
const g = parseInt(hex.slice(3,5),16);
|
| 80 |
+
const b = parseInt(hex.slice(5,7),16);
|
| 81 |
+
|
| 82 |
+
// HSL
|
| 83 |
+
const [h,s,l] = rgbToHsl(r,g,b);
|
| 84 |
+
|
| 85 |
+
// Display
|
| 86 |
+
preview.style.display='flex';
|
| 87 |
+
document.getElementById('swatch').style.background = hex;
|
| 88 |
+
|
| 89 |
+
document.getElementById('values').innerHTML = `
|
| 90 |
+
<div class="val-row"><span class="val-label">Hex</span><span class="val-value" onclick="cp(this)">${hex}</span></div>
|
| 91 |
+
<div class="val-row"><span class="val-label">RGB</span><span class="val-value" onclick="cp(this)">rgb(${r}, ${g}, ${b})</span></div>
|
| 92 |
+
<div class="val-row"><span class="val-label">HSL</span><span class="val-value" onclick="cp(this)">hsl(${h}, ${s}%, ${l}%)</span></div>
|
| 93 |
+
<div class="val-row"><span class="val-label">RGB Array</span><span class="val-value" onclick="cp(this)">[${r}, ${g}, ${b}]</span></div>
|
| 94 |
+
<div class="val-row"><span class="val-label">CSS</span><span class="val-value" onclick="cp(this)">${hex}</span></div>
|
| 95 |
+
`;
|
| 96 |
+
|
| 97 |
+
// Contrast
|
| 98 |
+
contrastEl.style.display='block';
|
| 99 |
+
const lum = luminance(r,g,b);
|
| 100 |
+
const whiteLum = 1;
|
| 101 |
+
const blackLum = 0;
|
| 102 |
+
|
| 103 |
+
const ratioOnWhite = contrastRatio(lum, whiteLum);
|
| 104 |
+
const ratioOnBlack = contrastRatio(lum, blackLum);
|
| 105 |
+
|
| 106 |
+
document.getElementById('onWhite').style.cssText = `background:white;color:${hex}`;
|
| 107 |
+
document.getElementById('onWhite').innerHTML = `Text on white β <span class="ratio ${ratioOnWhite>=4.5?'pass':'fail'}">${ratioOnWhite.toFixed(2)}:1 ${ratioOnWhite>=4.5?'β AA':'β Fail'}</span>`;
|
| 108 |
+
|
| 109 |
+
document.getElementById('onBlack').style.cssText = `background:black;color:${hex}`;
|
| 110 |
+
document.getElementById('onBlack').innerHTML = `Text on black β <span class="ratio ${ratioOnBlack>=4.5?'pass':'fail'}">${ratioOnBlack.toFixed(2)}:1 ${ratioOnBlack>=4.5?'β AA':'β Fail'}</span>`;
|
| 111 |
+
|
| 112 |
+
const whiteOnRatio = contrastRatio(whiteLum, lum);
|
| 113 |
+
document.getElementById('whiteOn').style.cssText = `background:${hex};color:white`;
|
| 114 |
+
document.getElementById('whiteOn').innerHTML = `White on color β <span class="ratio ${whiteOnRatio>=4.5?'pass':'fail'}">${whiteOnRatio.toFixed(2)}:1 ${whiteOnRatio>=4.5?'β AA':'β Fail'}</span>`;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function rgbToHsl(r,g,b){r/=255;g/=255;b/=255;const max=Math.max(r,g,b),min=Math.min(r,g,b);let h,s,l=(max+min)/2;if(max===min){h=s=0}else{const d=max-min;s=l>.5?d/(2-max-min):d/(max+min);switch(max){case r:h=((g-b)/d+(g<b?6:0))/6;break;case g:h=((b-r)/d+2)/6;break;case b:h=((r-g)/d+4)/6;break}}return[Math.round(h*360),Math.round(s*100),Math.round(l*100)]}
|
| 118 |
+
|
| 119 |
+
function luminance(r,g,b){const a=[r,g,b].map(v=>{v/=255;return v<=.03928?v/12.92:Math.pow((v+.055)/1.055,2.4)});return .2126*a[0]+.7152*a[1]+.0722*a[2]}
|
| 120 |
+
|
| 121 |
+
function contrastRatio(l1,l2){const lighter=Math.max(l1,l2),darker=Math.min(l1,l2);return(lighter+.05)/(darker+.05)}
|
| 122 |
+
|
| 123 |
+
function cp(el){navigator.clipboard.writeText(el.textContent);const o=el.textContent;el.textContent='copied!';setTimeout(()=>el.textContent=o,800)}
|
| 124 |
+
</script>
|
| 125 |
+
</body>
|
| 126 |
+
</html>
|