Skip to content

[Color.parse()] What is the space of accepted CSS color strings? #39

Description

@LeaVerou

What happens if authors try to parse things like

  1. "oklch(50% 10% var(--hue))
  2. "oklch(50% 10% calc(0 + 20))
  3. "color-mix(in oklab, currentColor, red)"

The Color API is not Typed OM, so the internal representation of the color needs to be concrete numbers.
However, it can still accept color strings that are not just a color space function with specific coords, and resolve them to numbers.

Each of these examples brings up different questions around this:

  1. Should the API provide some way to specify what the context is, so that variables and things like currentColor or system colors are resolved? (an object literal, or even a DOM element)
  2. Should the API follow calculations in calc() if they can be resolved?
  3. Should color functions like color-mix() be accepted if they can be resolved?

And when a color is valid CSS, but not something the Color API can handle, what should happen? We throw an error or do something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions