-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: type safe colour token parser #209
Comments
Thanks for the issue, our team will look into it as soon as possible! If you would like to work on this issue, please wait for a maintainer to decide if it is ready to be worked on. To claim an issue, please leave a comment that says ".take". If you have any questions, feel free to ping a maintainer. |
Default color spacesWhen parsing our colors we may want to omit properties like The |
Token parser now works as expected |
The other bug I'm facing is that channel values are being normalized like rgb even when the mode is not RGB. Working on it right now |
Inspiration
Previously (v2.x.x and below) the library exported different functions to convert colours from different types to a common format like hex.
However, v3 is focused on a more simplified API and therefore all the converter functions have been merged into one utility function
token()
How does it work
The function will be broken down into several steps:
Parsing
Because we are expecting colors in different types we first have to parse our colour to a widely accepted format. This helps ensure that we don't branch off our logic for no reason.
When an array is passed as a colour token it is converted to a colour object so that it can be passed to functions like
formatHex
orformatHex8
in the specifiedsrcMode
. The same can be said to all the other types which will be converted to plain objects as well.Conversion
If the
targetMode
option is specified and thekind
is set to'arr'
or'obj'
the colour will be converted to the specified colour space. This is also where we performnormalizeRGB
which will allow us to make [0,255] RGB channel ranges compatible with the [0,1] range supported by Culori.Output modification
This is the stage where we modify the final result to match the options that may be specified for example
This is a core function because it allows the parsing of any recognisable colour tokens throughout the library.
The text was updated successfully, but these errors were encountered: