fix(hwb): normalize whiteness + blackness over 100% to gray#138
Open
spokodev wants to merge 1 commit into
Open
fix(hwb): normalize whiteness + blackness over 100% to gray#138spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
Per CSS Color 4, when whiteness + blackness reaches 100% an HWB color is
an achromatic gray with value white / (white + black). `hwbaToRgba` was
missing this step, so over-specified inputs produced wrong colors:
colord({ h: 120, w: 70, b: 70 }).toHex() // was "#b34db3", now "#808080"
For w + b > 100 the existing path fed a negative saturation into HSV; the
`b === 100` special case also returned black instead of gray. Both are now
covered by the spec normalization, so the special case is removed.
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.
Problem
When an HWB color's
whiteness + blacknessis>= 100%, the result should be an achromatic gray, but the HWB plugin produces wrong colors:These are valid CSS inputs that every browser renders as gray.
Cause
hwbaToRgbaconverted via HSV without thew + b >= 100%normalization:w + b > 100,100 - (w / (100 - b)) * 100is negative, feeding a negative saturation into HSV → garbage.b === 100special case returneds: 0, v: 0(black) instead of gray.Fix
Per CSS Color 4 §8.1, when
white + black >= 100%the color is gray with valuewhite / (white + black):The
b === 100special case is removed because everyb === 100input hasw + b >= 100and is now handled by the new branch. At the exactw + b === 100boundary the new branch yields the same value the old HSV path did, so nothing else changes.Verification
tests/plugins.test.ts; fails before, passes after. Full suite: 78 passing.15°×5%×5%grid plus 500,000 random inputs: 0 divergences (>1 LSB). This also confirms the untouchedw + b < 100path already matches the spec.