Add an opt-in switch for CSSOM-compliant color serialization - #229
Merged
Conversation
CssColorValue always serializes through rgba(), so an opaque color comes out as rgba(r, g, b, 1) where the CSSOM serialization rules ask for rgb(r, g, b). Changing that by default would be breaking, so this adds UseSpecSerialization next to UseHex: off by default, and when switched on an opaque color serializes as rgb(r, g, b) while anything with an alpha below 1 keeps rgba(r, g, b, a). UseHex still wins when both are active. Reducing a color that was written as a named color back to its name is a separate step and is not part of this change. Closes AngleSharp#227. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NqCcJrL3MJecCPRBMQsZyC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CssColorValuealways serializes throughrgba(), so an opaque color comes out asrgba(r, g, b, 1)where https://drafts.csswg.org/cssom/#serializing-css-values asks forrgb(r, g, b); since changing that by default would be breaking, this adds a static switch next toUseHexthat is off by default and, when on, serializes an opaque color asrgb(r, g, b)while anything below full alpha keepsrgba(r, g, b, a)-UseHexstill wins when both are active. I kept your placeholder nameUseSpecSerializationas the proposal because the deferred named-color reduction fits behind the same switch and it stays a single opt-in; if you would rather the name describe only what it does today,OmitOpaqueAlphareads well and I will rename. Reducing a color back to its named form is not part of this change, and the color FAQ indocs/tutorials/04-Questions.mddocuments the new switch (its existing snippets still used the pre-0.18Colorname, so they are updated too).