Repository navigation
Fix RGB channels drifting when only alpha is changed - #234
Merged
Merged
Conversation
omgovich
force-pushed
the
fix/alpha-rgb-drift
branch
from
September 1, 2026 15:49
6f99919 to
b0945d1
Compare
|
Size Change: -2 B (-0.04%) Total Size: 4.91 kB 📦 View Changed
|
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.
Fixes #163. Alternative to #184.
Why
Moving only the alpha slider changed the RGB channels too:
{ r: 200, g: 120, b: 35, a: 0.5 }became{ r: 199, g: 119, b: 34 }after an alpha-only interaction. The root cause is thatrgbaToHsvaroundsh/s/vto integers, so the internal HSVA representation loses precision andfromHsva(toHsva(color))doesn't round-trip.What changed
rgbaToHsvano longer rounds its result — the internal HSVA state keeps full precision. All output conversions (hsvaToRgba,hsvaToHex, etc.) still round, so the values emitted byonChangeare unchanged in format.RgbaColorPicker,RgbaStringColorPickerandHexAlphaColorPickerin one place, with no new API and no size cost (unlike Fix RGBA calc error when change alpha #184, which added anupdateAlphamethod to every color model and went over the size limit).RgbaColorPicker) and the hex color (HexAlphaColorPicker) intact.tests/utils.test.jsthat asserted rounded values from input converters — they now compare viaroundHsva, same semantics.Verified exhaustively outside the test suite: with rounding removed,
hsvaToRgba(rgbaToHsva(c))round-trips exactly for all 16.7M RGB values.How to review
The production change is only
rgbaToHsvainsrc/utils/convert.ts— threeround()calls removed. Worth double-checking that nothing user-visible relies on the internal HSVA being integers: the UI components already round foraria-*output, andhslaToHsvanever rounded to begin with. Bundle size is neutral (±1 B gzip noise).