Skip to content

Add an opt-in switch for CSSOM-compliant color serialization - #229

Merged
FlorianRappl merged 1 commit into
AngleSharp:develfrom
lahma:feature/#227
Sep 2, 2026
Merged

Add an opt-in switch for CSSOM-compliant color serialization#229
FlorianRappl merged 1 commit into
AngleSharp:develfrom
lahma:feature/#227

Conversation

@lahma

@lahma lahma commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

CssColorValue always serializes through rgba(), so an opaque color comes out as rgba(r, g, b, 1) where https://drafts.csswg.org/cssom/#serializing-css-values asks for rgb(r, g, b); since changing that by default would be breaking, this adds a static switch next to UseHex that is off by default and, when on, serializes an opaque color as rgb(r, g, b) while anything below full alpha keeps rgba(r, g, b, a) - UseHex still wins when both are active. I kept your placeholder name UseSpecSerialization as 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, OmitOpaqueAlpha reads well and I will rename. Reducing a color back to its named form is not part of this change, and the color FAQ in docs/tutorials/04-Questions.md documents the new switch (its existing snippets still used the pre-0.18 Color name, so they are updated too).

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

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@FlorianRappl
FlorianRappl merged commit 3beca43 into AngleSharp:devel Sep 2, 2026
4 checks passed
@lahma
lahma deleted the feature/#227 branch September 3, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants