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

Implement .get()/.getAll()/.set()/.setAll() syntax from Color API #111

Closed
LeaVerou opened this issue Nov 11, 2021 · 1 comment
Closed

Implement .get()/.getAll()/.set()/.setAll() syntax from Color API #111

LeaVerou opened this issue Nov 11, 2021 · 1 comment
Labels
color-api Parity with the Color API enhancement New feature or request

Comments

@LeaVerou
Copy link
Member

LeaVerou commented Nov 11, 2021

When @svgeesus and I defined the Color API instead of the exotic properties we use in Color.js we went with .get() and .set() methods that are more consistent with the rest of the Web Platform, since there's guidance to avoid exotic properties as they conflate object properties with data.

These methods have several advantages over the current syntax:

  • Object properties clearly separate from data
  • Ability to look up coordinates by ColorSpace object which allows for anonymous color spaces
  • Ability to set multiple coordinates at once, or even in a relative way
  • Properties hide the fact that these are actually performing conversion behind the scenes. It's easy for someone to use color.lch.lightness and then later on color.lch.chroma without ever thinking of caching color.lch. OTOH, we could cache it behind the scenes.
  • Currently color.to() to convert to another Color object is a method, but color.<colorspace> to get coordinates in another colorspace is a property. This is pretty weird, and I've often done things like color.lch expecting a color and not an array.

These methods should also be implemented in Color.js, so that it can be used as a polyfill of the Color API.

@LeaVerou
Copy link
Member Author

This is done after recent commits, not sure why this wasn't auto closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color-api Parity with the Color API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant