Skip to content
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

Alpha should not be set if it is not defined #27

Open
bbugh opened this issue Nov 3, 2023 · 0 comments
Open

Alpha should not be set if it is not defined #27

bbugh opened this issue Nov 3, 2023 · 0 comments

Comments

@bbugh
Copy link

bbugh commented Nov 3, 2023

Hello. 👋 For a project, I'm reviewing over a dozen color parsing libraries, all of which have various problems. Yours is one of the closest to correctness, only having this one issue. Nice!

The alpha is incorrectly being set to a default value when it is actually undefined. For example:

parse('#00f')
//> { type: 'rgb', values: [0, 0, 255], alpha: 1 }

While this alpha can be inferred as 1, for tokenization and parsing, alpha is not set, and should not be included in the parsed results. By forcing a default alpha, it removes the ability to know what the actual input was and precisely convert it.

For example, should converting #00f to rgb color mode be rgb(0 0 255) or rgb(0 0 255 / 1)? It's indeterminate from the result of parse. While it is true that they are equivalent in an rgb color model, at a parsing level they are not equivalent. To be a perfect 1:1 conversion in a parsing scenario, the output result must be rgb(0 0 255), but there's no way to infer that from the parsing result.

Expectation:

parse('#00f')
//> { type: 'rgb', values: [0, 0, 255], alpha: undefined }
parse('#00ff')
//> { type: 'rgb', values: [0, 0, 255], alpha: 1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant