CaptainCodeman / svelte-color-select

Okhsv color select for Svelte
https://captaincodeman.github.io/svelte-color-select/
Other
30 stars 1 forks source link

Accept and return Oklab colors #3

Closed CaptainCodeman closed 1 year ago

CaptainCodeman commented 2 years ago

Allow staying in Oklab world

drwpow commented 1 year ago

First of all, this is a fantastic library—thank you for building it 🙂

What would you imagine the API would look like? One idea could be to accept a Culori color object instead as a color prop, e.g.:

<script>
let rgb = { mode: 'rgb', r: 0, g: 1, b: 0 };
let oklab = { mode: 'oklab', l: 0.86, a: -0.233888, b: 0.179498 };
let oklch = { mode: 'oklch', l: 0.86, c: 0.294827, h: 142.495339 };
</script>

<ColorSelect bind:color={rgb} />
<ColorSelect bind:color={oklab} />
<ColorSelect bind:color={oklch} />

This would not only allow expanding to the Oklab space; it would open up the component to allow for more colorspaces (within reason, though—I don’t think everything should be supported). This would be a breaking change, though, so happy to hear your thoughts on that.

I realize this would also imply using Culori under the hood to achieve this, but I’d argue that would be a maintenance and performance win. Also as someone who implemented Björn’s code manually myself in another library, I’ve been impressed by Culori’s performance and accuracy—it’s not only significantly faster than Björn’s code, it’s also implemented perfectly, at least as far as I can tell, and a lot of color scientists rely on that library and report issues immediately. Using the ESM build only shakes out to a few kB at most—around the same footprint as Björn’s code—so it wouldn’t be unnecessarily burdening this lightweight component.

I’d be happy to assist with a PR if you’re open to this general direction.

CaptainCodeman commented 1 year ago

Thanks, hadn't seen that lib - I initially looked at https://colorjs.io/ but the packaging was a bit messed up when I did, sounds like that one may be better. If it's faster code, it's worth using for that alone.

I'm not sure this component should ever support non OKLab color directly though - this can be the callers responsibility allowing them to use whatever lib they like, and should avoid bundling too much into the component.

drwpow commented 1 year ago

Yeah I’m not confident in the current state or future of colorjs.io, either.

And that’s a fair point. Off the top of my head I can’t think of any “must-have” colorspaces other than RGB & Oklab/Oklch. Just pointing out it keeps the possibility open in the future if needed.

drwpow commented 1 year ago

Hope it’s OK I opened up a PR that takes the direction of implementing Culori. Open to feedback or discussion if this is a good direction!