|
1 | 1 | <script lang="ts"> |
2 | | - import type { Rgb } from 'culori' |
| 2 | + import { formatCss, type Rgb } from 'culori/fn' |
3 | 3 | import ColorSelect from '$lib' |
4 | 4 |
|
5 | 5 | // https://medium.com/@valgaze/the-hidden-purple-memorial-in-your-web-browser-7d84813bb416 |
6 | | - let r = 102 |
7 | | - let g = 51 |
8 | | - let b = 153 |
9 | | -
|
10 | | - $: color = { mode: 'rgb', r: r / 255, g: g / 255, b: b / 255 } as Rgb |
| 6 | + let color: Rgb = { mode: 'rgb', r: 0.4, g: 0.2, b: 0.6 } |
11 | 7 | </script> |
12 | 8 |
|
13 | 9 | <svelte:head> |
|
17 | 13 | <h1 class="text-zinc-100 mx-8 mt-16 font-extrabold text-3xl">Okhsv Color Select</h1> |
18 | 14 | <p class="text-zinc-400 mx-8 mt-2">HSV style color select using OKLab perceptual color space.</p> |
19 | 15 |
|
20 | | -<ColorSelect class="m-8 bg-zinc-600" {color} on:change={(e) => console.log(e.detail)} /> |
| 16 | +<ColorSelect class="m-8 bg-zinc-600" bind:color /> |
21 | 17 |
|
22 | 18 | <p class="text-zinc-400 mx-8 mt-2">Use left / right arrow keys to adjust Saturation, up / down to adjust Brightness.</p> |
23 | 19 | <p class="text-zinc-400 mx-8 mt-2">Hold shift for larger steps and alt / option key to adjust Hue.</p> |
24 | 20 |
|
25 | 21 | <div class="m-12"> |
26 | 22 | <div class="flex items-center mt-2"> |
27 | 23 | <label class="w-24 text-red-700" for="red">Red</label> |
28 | | - <input id="red" type="range" min="0" max="255" step="1" bind:value={r} /> |
29 | | - <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(r)}</span> |
| 24 | + <input id="red" type="range" min="0" max="1" step={1/255} bind:value={color.r} /> |
| 25 | + <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(255 * color.r)}</span> |
30 | 26 | </div> |
31 | 27 |
|
32 | 28 | <div class="flex items-center mt-2"> |
33 | 29 | <label class="w-24 text-green-600" for="green">Green</label> |
34 | | - <input id="green" type="range" min="0" max="255" step="1" bind:value={g} /> |
35 | | - <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(g)}</span> |
| 30 | + <input id="green" type="range" min="0" max="1" step={1/255} bind:value={color.g} /> |
| 31 | + <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(255 * color.g)}</span> |
36 | 32 | </div> |
37 | 33 |
|
38 | 34 | <div class="flex items-center mt-2"> |
39 | 35 | <label class="w-24 text-blue-600" for="blue">Blue</label> |
40 | | - <input id="blue" type="range" min="0" max="255" step="1" bind:value={b} /> |
41 | | - <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(b)}</span> |
| 36 | + <input id="blue" type="range" min="0" max="1" step={1/255} bind:value={color.b} /> |
| 37 | + <span class="text-sm font-semibold text-zinc-300 w-12 ml-2 pl-2 py-0.5 pr-0 text-right">{Math.round(255 * color.b)}</span> |
42 | 38 | </div> |
43 | 39 |
|
44 | 40 | <div class="bg-white inline-block ml-24 my-6 rounded-[10px]"> |
45 | | - <div class="w-48 h-12 m-1 rounded-[6px]" style:background-color="rgb({r},{g},{b})" /> |
| 41 | + <div class="w-48 h-12 m-1 rounded-[6px]" style:background-color={formatCss(color)} /> |
46 | 42 | </div> |
47 | 43 |
|
48 | 44 | <p class="text-white">See <a class="text-blue-300" href="https://bottosson.github.io/posts/colorpicker/">Okhsv and Okhsl by Björn Ottosson</a></p> |
|
0 commit comments