Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

deserialize() returns types any #11

Open
skorphil opened this issue Dec 30, 2024 · 2 comments
Open

deserialize() returns types any #11

skorphil opened this issue Dec 30, 2024 · 2 comments

Comments

@skorphil
Copy link

skorphil commented Dec 30, 2024

const { coords, id } = deserialize(colorStr); 
// coords: any, id: any

BTW its is not very convenient, that id returns lowercase color space instead of keyof typeof import("@texel/color") like "OKLCH" | "OKLab" | "sRGB" | "OKLab_to" ... because i try to use it like:

const { coords, id } = deserialize(color)
...
const convertedColor = convert(
      coords,
      colorSpace[id] // cant just use id here, have to write additional logic to convert srgb => sRGB, oklch => OKLCH etc.
      colorSpace[targetSpace]
    );
@mattdesl
Copy link
Member

Thanks. I’ll look into the type def.

The string is an alias, mostly to match with CSS spec (for example ‘display-p3’ for color serialization, which would be a very awkward identifier name for the color space).

For now, you’ll have to use listColorSpaces().find(c => c.id === id) to find the actual color space object from the string id.

The serialization API could be improved; I’m open to ideas as to how it could look. The goal would be to do it in a way that doesn’t bloat bundle size for all users of the library.

@skorphil
Copy link
Author

Thanks. I’ll look into the type def.

The string is an alias, mostly to match with CSS spec (for example ‘display-p3’ for color serialization, which would be a very awkward identifier name for the color space).

For now, you’ll have to use listColorSpaces().find(c => c.id === id) to find the actual color space object from the string id.

The serialization API could be improved; I’m open to ideas as to how it could look. The goal would be to do it in a way that doesn’t bloat bundle size for all users of the library.

Thanks, didnt know about listColorSpaces()

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants