-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor-palette.html
More file actions
177 lines (165 loc) · 8.94 KB
/
Copy pathcolor-palette.html
File metadata and controls
177 lines (165 loc) · 8.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Color Palette | tools.eliana.lol</title>
<link rel="stylesheet" href="../global.css" />
<link rel="icon" type="image/x-icon" href="../favicon.svg" />
<style>
.tool-layout { display: flex; flex-direction: column; gap: 24px; }
.action-bar { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
label { display: block; font-size: 0.7rem; text-transform: uppercase; font-weight: bold; color: var(--puny); margin-bottom: 5px; }
.card { border: 1px solid var(--puny); padding: 14px; }
.card h2 { font-size: 0.9rem; text-transform: uppercase; margin: 0 0 12px 0; padding-bottom: 6px; border-bottom: 1px solid var(--puny); }
.swatch-row { display: flex; gap: 0; height: 60px; margin: 10px 0; cursor: pointer; }
.swatch { flex: 1; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; font-size: 0.65rem; font-family: monospace; transition: flex 0.2s; }
.swatch:hover { flex: 2; }
.color-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 8px; font-size: 0.8rem; }
.info-row { border: 1px solid var(--puny); padding: 8px; }
.info-row .key { color: var(--puny); font-size: 0.7rem; text-transform: uppercase; }
.info-row .val { font-family: monospace; font-weight: bold; cursor: pointer; }
.info-row .val:hover { background: var(--hover); }
input[type=color] { width: 60px; height: 40px; padding: 2px; border: 1px solid var(--puny); background: var(--bg); cursor: pointer; }
select { background: var(--bg); color: var(--text); border: 1px solid var(--puny); font-family: monospace; padding: 4px 8px; }
#contrast-result { font-size: 0.9rem; font-weight: bold; }
.pass { color: green; }
.fail { color: var(--accent); }
input[type=range] { accent-color: var(--accent); }
</style>
</head>
<body>
<nav>
<div class="left"><a href="../index.html">home</a> | <a href="../extra.html">extra</a> | <a href="../credits.html">credits</a> | <a href="../changelog.html">logs</a></div>
<div class="right"><button id="theme-toggle">[theme]</button> | <a href="https://eliana.lol">site</a></div>
</nav>
<main>
<h1>Color Palette</h1>
<p class="puny">Explore colors, generate palettes, check contrast ratios.</p>
<div class="tool-layout">
<div class="card">
<h2>Color picker</h2>
<div style="display:flex;gap:12px;align-items:center;flex-wrap:wrap">
<input type="color" id="main-color" value="#ff6600" oninput="updateColor()" />
<input type="text" id="hex-in" value="#ff6600" style="width:100px;font-family:monospace" oninput="hexChanged()" placeholder="#rrggbb" />
</div>
<div class="color-info" id="color-info" style="margin-top:12px"></div>
</div>
<div class="card">
<h2>Generate palette</h2>
<div style="display:flex;gap:10px;align-items:flex-end;flex-wrap:wrap">
<div><label>Mode</label>
<select id="palette-mode" onchange="generatePalette()">
<option value="complementary">Complementary</option>
<option value="analogous">Analogous</option>
<option value="triadic">Triadic</option>
<option value="tetradic">Tetradic</option>
<option value="tints">Tints</option>
<option value="shades">Shades</option>
</select></div>
<button onclick="generatePalette()">Generate</button>
<button onclick="copyPalette()">Copy HEX list</button>
</div>
<div class="swatch-row" id="palette-swatches"></div>
<div id="palette-hex" style="font-family:monospace;font-size:0.8rem;color:var(--puny)"></div>
</div>
<div class="card">
<h2>Contrast checker</h2>
<div style="display:flex;gap:12px;flex-wrap:wrap;align-items:flex-end">
<div><label>Foreground</label><input type="color" id="fg-col" value="#000000" oninput="checkContrast()" /></div>
<div><label>Background</label><input type="color" id="bg-col" value="#ffffff" oninput="checkContrast()" /></div>
</div>
<div id="contrast-preview" style="margin:12px 0;padding:16px;border:1px solid var(--puny);font-size:1.1rem;font-weight:bold">Sample text on this background</div>
<div id="contrast-result"></div>
</div>
</div>
</main>
<footer style="margin-top:4rem;text-align:center" class="puny">© 2026 eliana.lol • <a href="../credits.html">credits</a></footer>
<script src="https://cdn.jsdelivr.net/npm/chroma-js@2.4.2/chroma.min.js"></script>
<script>
const htmlEl = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
htmlEl.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) toggle.onclick = () => { const now = htmlEl.getAttribute('data-theme'); const next = now==='dark'?'light':'dark'; htmlEl.setAttribute('data-theme',next); localStorage.setItem('theme',next); toggle.innerText=next==='dark'?'[light]':'[dark]'; };
function updateColor() {
const hex = document.getElementById('main-color').value;
document.getElementById('hex-in').value = hex;
showColorInfo(hex);
generatePalette();
}
function hexChanged() {
const hex = document.getElementById('hex-in').value.trim();
try {
const c = chroma(hex);
document.getElementById('main-color').value = c.hex();
showColorInfo(hex);
generatePalette();
} catch(e) {}
}
function showColorInfo(hex) {
try {
const c = chroma(hex);
const [h,s,l] = c.hsl();
const [r,g,b] = c.rgb();
const [cy,m,y,k] = c.cmyk().map(v=>Math.round(v*100));
const items = [
['HEX', c.hex()],
['RGB', `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`],
['HSL', `hsl(${Math.round(h||0)}, ${Math.round(s*100)}%, ${Math.round(l*100)}%)`],
['CMYK', `cmyk(${cy}%, ${m}%, ${y}%, ${k}%)`],
['Luminance', c.luminance().toFixed(4)],
['Temperature', c.temperature ? Math.round(c.temperature())+'K' : '—'],
];
document.getElementById('color-info').innerHTML = items.map(([k,v]) =>
`<div class="info-row"><div class="key">${k}</div><div class="val" onclick="navigator.clipboard.writeText('${v}')" title="Click to copy">${v}</div></div>`
).join('');
} catch(e) {}
}
function generatePalette() {
const hex = document.getElementById('main-color').value;
const mode = document.getElementById('palette-mode').value;
let colors = [];
try {
const c = chroma(hex);
const [h,s,l] = c.hsl();
if (mode==='complementary') colors = [hex, chroma.hsl((h+180)%360,s,l).hex()];
else if (mode==='analogous') colors = [-30,0,30].map(d => chroma.hsl((h+d+360)%360,s,l).hex());
else if (mode==='triadic') colors = [0,120,240].map(d => chroma.hsl((h+d)%360,s,l).hex());
else if (mode==='tetradic') colors = [0,90,180,270].map(d => chroma.hsl((h+d)%360,s,l).hex());
else if (mode==='tints') colors = [0,1,2,3,4,5].map(i => chroma.mix(hex,'white',i/5).hex());
else if (mode==='shades') colors = [0,1,2,3,4,5].map(i => chroma.mix(hex,'black',i/5).hex());
renderSwatches(colors);
} catch(e) {}
}
function renderSwatches(colors) {
const wrap = document.getElementById('palette-swatches');
wrap.innerHTML = colors.map(c => {
const textColor = chroma(c).luminance() > 0.4 ? '#000' : '#fff';
return `<div class="swatch" style="background:${c};color:${textColor}" onclick="navigator.clipboard.writeText('${c}')" title="${c}">${c}</div>`;
}).join('');
document.getElementById('palette-hex').textContent = colors.join(' ');
}
function copyPalette() {
navigator.clipboard.writeText(document.getElementById('palette-hex').textContent);
}
function checkContrast() {
const fg = document.getElementById('fg-col').value;
const bg = document.getElementById('bg-col').value;
const ratio = chroma.contrast(fg, bg);
const preview = document.getElementById('contrast-preview');
preview.style.color = fg;
preview.style.background = bg;
const aa = ratio >= 4.5, aaa = ratio >= 7, aaLarge = ratio >= 3;
document.getElementById('contrast-result').innerHTML = `
<strong>Ratio: ${ratio.toFixed(2)}:1</strong><br>
<span class="${aaa?'pass':'fail'}">AAA (7:1): ${aaa?'✓ Pass':'✗ Fail'}</span>
<span class="${aa?'pass':'fail'}">AA (4.5:1): ${aa?'✓ Pass':'✗ Fail'}</span>
<span class="${aaLarge?'pass':'fail'}">AA Large (3:1): ${aaLarge?'✓ Pass':'✗ Fail'}</span>`;
}
updateColor();
checkContrast();
</script>
</body>
</html>