GithubHelp home page GithubHelp logo

Comments (2)

kbabbitt avatar kbabbitt commented on September 18, 2024

The spec goes on to state:

The serialization of the result of a relative color function depends on whether the keyword currentColor is the origin color. If so, the result is serialized as the declared value. This allows the correct value to be used on child elements whose color property has a different value. Otherwise, it is the resolved value, which is a <color>, as defined in CSS Color 4 ยงโ€ฏ 15. Serializing <color> Values.

I understand this to mean:

  1. If the origin color is currentColor, then serialize the spelling as declared. (We don't know the origin color and thus cannot canonicalize it.)
  2. If the origin color is not currentColor, then resolve the relative color and serialize canonically as described in Color 4.

There are few tests with examples for how canonicalization happens in case 2: color-valid.html, color-valid-rgb.html, color-valid-hsl.html. Notably:

  • hsla(...) canonicalizes to equivalent rgba(...), and hsl(...) canonicalizes to equivalent rgb(...)
  • rgb(...) is used if the clamped alpha is exactly 1, otherwise rgba(...) is used

cc @svgeesus to confirm.

from csswg-drafts.

weinig avatar weinig commented on September 18, 2024

I filed a separate issue on the ambiguity here - #10305, as I don't think the current spec text is clear on what the rules are.

Regardless of that however, the question posed here remains, as you can just set currentColor as the origin:

That is, should:

rgb(from currentcolor r g b)

and

rgba(from currentcolor r g b)

serializations maintain the exact spelling of function name.

@kbabbitt, the tests you mention, notably, cover the absolute case, which has clear rules about which spelling to do, and those rules are not about what spelling was used at the declaration site, but rather about the resolved value of the alpha channel. As you might not know the value of the alpha channel in a relative color, the exact same rules can't be followed.

from csswg-drafts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.