Avoid implied color space dependencies for procedural usage#734
Conversation
✅ Deploy Preview for colorjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| return Math.max(parseFloat(`1e${order - 2}`), 1e-6); | ||
| } | ||
|
|
||
| const GMAPPRESET = { |
There was a problem hiding this comment.
Totally unrelated to this PR, but we shouldn't be having colorspace-specific stuff in a generic function like this. Especially for non-essential color spaces. This should live together with the HCT color space!
|
I need to look more closely but it seems that the oklch space is only used in the It's probably not a huge deal since most people do need oklch, and it's pretty small but thought I'd flag it and see what others think. That said, I'm not even sure we should have |
|
If my read of the code is accurate, |
I would like to see some kind of plugin system so that all of the gamut mapping methods aren't in a single file and additional gamut mapping methods could be added e.g. https://bottosson.github.io/posts/gamutclipping/ |
|
I haven't looked that closely but couldn't this PR be as simple as:
|
|
I generally agree that as the gamut mapping options grow, making gamut mapping methods into plugins probably makes more sense, though that is tangential to this PR. |
Updates utility functions to use color space objects directly rather than retrieving the color space by a string lookup, which infers a dependency that those color spaces are already registered.
This improves usability of the procedural API. Currently, if someone opts-in to the procedural API and wants to use these utilities, the consumer has to ensure that the color space is registered, which is not obvious.
Using the color space object directly ensures these functions are independently self-contained and don't have any implied dependencies.
I noticed similar implied dependencies in
lightenanddarkenfunctions, but given the "alternatives" fallbacks used there, it's less clear to me how best to handle those color spaces. I'm happy to update those functions as well if there's a direction that makes sense.