Add gradient position support for radial and conic gradients #3596
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.
Overview
This PR implements support for position keywords and percentage values in
radial-gradient()
andconic-gradient()
functions, addressing the limitation where gradients could only be centered at the default position.Problem
Previously, the gradient implementation only supported basic color stops but ignored position syntax like:
radial-gradient(ellipse at top, #ff0000, #0000ff)
radial-gradient(ellipse at 10%, #333333, #333333 50%, #eeeeee 75%, #333333 75%)
conic-gradient(from 45deg at bottom right, #ff0000, #0000ff)
The parser would skip over position parameters entirely, resulting in all gradients being centered at (0.5, 0.5).
Solution
New Position Parsing
Added a
parsePosition()
helper function that correctly handles:left
,top
,right
,bottom
25%
,50%
,75%
top left
,right bottom
,25% 75%
Enhanced Radial Gradients
Updated
convertRadialGradient()
to:at position
syntaxEnhanced Conic Gradients
Updated
convertConicGradient()
to:from angle
andat position
in the same gradientat position
without angle specificationExamples Now Supported
Technical Details
The implementation correctly maps CSS coordinate system to Figma's coordinate system:
at top
(50%, 0%) → Figma (0.5, 0)at left
(0%, 50%) → Figma (0, 0.5)Testing
Added comprehensive tests covering:
All existing tests continue to pass, ensuring no regressions.
Fixes
Closes #[issue-number]
Fixes #3595
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.