Feature: Background Gradient Support#1580
Open
CaptainDario wants to merge 3 commits into
Open
Conversation
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.
I want to make this package render the following HTML correctly.
HTML
Comparison
This PR's goal
Parsing CSS background-image gradient.
What's supported
All six CSS gradient functions:
linear-gradient,radial-gradient,conic-gradient, and theirrepeating-*variants. Supports angle units (deg/rad/grad/turn),to <side/corner>directions,from <angle>/at <position>hints,circle/ellipseshape keywords, and color stops with%or angle positions. Colors delegate to existingtryParseColor(). Ellipse radial gradients and conic gradients apply aGradientTransformat paint time for correct CSS-spec sizing and coordinate alignment.linear-gradientto bottomlinear-gradient(to bottom, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:linear-gradient(to bottom,#e74c3c,#3498db)"></div>linear-gradientto rightlinear-gradient(to right, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:linear-gradient(to right,#e74c3c,#3498db)"></div>linear-gradient45deglinear-gradient(45deg, #e74c3c, #f39c12, #3498db)View
<div style="width:200px;height:100px;background:linear-gradient(45deg,#e74c3c,#f39c12,#3498db)"></div>linear-gradientto bottom rightlinear-gradient(to bottom right, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:linear-gradient(to bottom right,#e74c3c,#3498db)"></div>linear-gradientexplicit stopslinear-gradient(to right, #e74c3c 0%, #f39c12 50%, #3498db 100%)View
<div style="width:200px;height:100px;background:linear-gradient(to right,#e74c3c 0%,#f39c12 50%,#3498db 100%)"></div>linear-gradienttransparentlinear-gradient(to right, transparent, #3498db)View
<div style="width:200px;height:100px;background:linear-gradient(to right,transparent,#3498db)"></div>repeating-linear-gradientrepeating-linear-gradient(to right, #e74c3c 0%, #3498db 20%)View
<div style="width:200px;height:100px;background:repeating-linear-gradient(to right,#e74c3c 0%,#3498db 20%)"></div>radial-gradientdefault ellipseradial-gradient(#e74c3c, #3498db)View
<div style="width:200px;height:100px;background:radial-gradient(#e74c3c,#3498db)"></div>radial-gradientcircleradial-gradient(circle, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:radial-gradient(circle,#e74c3c,#3498db)"></div>radial-gradientcircle at top rightradial-gradient(circle at top right, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:radial-gradient(circle at top right,#e74c3c,#3498db)"></div>radial-gradientellipse at bottom leftradial-gradient(at bottom left, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:radial-gradient(at bottom left,#e74c3c,#3498db)"></div>repeating-radial-gradientrepeating-radial-gradient(circle, #e74c3c 0%, #3498db 20%)View
<div style="width:200px;height:100px;background:repeating-radial-gradient(circle,#e74c3c 0%,#3498db 20%)"></div>conic-gradientdefaultconic-gradient(#e74c3c, #f39c12, #2ecc71, #3498db)View
<div style="width:200px;height:100px;background:conic-gradient(#e74c3c,#f39c12,#2ecc71,#3498db)"></div>conic-gradientfrom 45degconic-gradient(from 45deg, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:conic-gradient(from 45deg,#e74c3c,#3498db)"></div>conic-gradientat top leftconic-gradient(at top left, #e74c3c, #3498db)View
<div style="width:200px;height:100px;background:conic-gradient(at top left,#e74c3c,#3498db)"></div>conic-gradientexplicit stopsconic-gradient(#e74c3c 0deg, #f39c12 90deg, #2ecc71 180deg, #3498db 360deg)View
<div style="width:200px;height:100px;background:conic-gradient(#e74c3c 0deg,#f39c12 90deg,#2ecc71 180deg,#3498db 360deg)"></div>repeating-conic-gradientrepeating-conic-gradient(from 0deg, #e74c3c 0%, #3498db 25%)View
<div style="width:200px;height:100px;background:repeating-conic-gradient(from 0deg,#e74c3c 0%,#3498db 25%)"></div>Limitations
px,em,rem, etc.) are not supported — only%and angle units. Stops using length units fall back to auto-distributed positions, which will produce wrong colors for gradients likeradial-gradient(purple 0.55em, black 1em).at <position>values (e.g.at 30% 70%) fall back tocenter.closest-side,closest-corner,farthest-sidesize keywords for radial gradients are ignored;farthest-cornersizing is always applied.Tests
43 unit tests covering every parser branch + 17 golden rendering tests (linear, radial, conic, each repeating variant) in a
200×100box.