fix(Util): preserve alpha of the named color "transparent"#2056
Open
spokodev wants to merge 1 commit into
Open
fix(Util): preserve alpha of the named color "transparent"#2056spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
Util.colorToRGBA('transparent') returned { r: 255, g: 255, b: 255, a: 1 }
instead of a: 0. The named-color table defines COLORS.transparent as
[255, 255, 255, 0], but _namedColorToRBA hard-coded a: 1 and ignored the
fourth element, unlike the hex and rgba parsers which both honor alpha.
As a result any tween to/from 'transparent' (the canonical fade in/out
idiom) computes an alpha delta of 0, so the shape never fades and instead
snaps to fully opaque white.
Contributor
Author
|
Heads-up: the failing |
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
Konva.Util.colorToRGBA('transparent')returns an opaque color:The named-color table already defines it correctly with a zero alpha:
but
_namedColorToRBAhard-codesa: 1and ignores the fourth element:Every other parser honors alpha —
#0000andrgba(0,0,0,0)both correctlyreturn
a: 0. Named colors are the only branch that drops it, andtransparentis the only named color that carries a non-1 alpha, so it is theone value this branch gets wrong.
Impact
colorToRGBAfeedsTweencolor interpolation (fill / stroke / shadowColor).Tweening to or from
'transparent'— the canonical fade in/out idiom —computes an alpha delta of
1 - 1 = 0, so the shape never fades; it snaps tofully opaque white
(255, 255, 255)instead of fading out.Fix
Honor the alpha in the color table, mirroring the hex/rgba parsers:
Test
Added a
colorToRGBA()case assertingtransparent → a: 0(andred → a: 1so the default-alpha path stays covered). Fails on
master, passes with the fix.