Skip to content

Commit

Permalink
fix: support radial-gradient with unspecified <ending-shape> (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan authored Feb 3, 2023
1 parent d727919 commit 6ae34e5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/vendor/gradient-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ GradientParser.parse = (function () {
if (input.length > 0) {
error('Invalid input not EOF')
}

return ast
}

Expand Down Expand Up @@ -168,7 +167,6 @@ GradientParser.parse = (function () {

function matchRadialOrientation() {
var radialType = matchCircle() || matchEllipse()

if (radialType) {
radialType.at = matchAtPosition()
} else {
Expand All @@ -180,11 +178,21 @@ GradientParser.parse = (function () {
radialType.at = positionAt
}
} else {
var defaultPosition = matchPositioning()
if (defaultPosition) {
// If unspecified, it defaults to ellipse.
var positionAt = matchAtPosition()
if (positionAt) {
radialType = {
type: 'default-radial',
at: defaultPosition,
type: 'shape',
value: 'ellipse',
at: positionAt
}
} else {
var defaultPosition = matchPositioning()
if (defaultPosition) {
radialType = {
type: 'default-radial',
at: defaultPosition,
}
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions test/gradient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,35 @@ describe('Gradient', () => {
)
expect(toImage(svg, 100)).toMatchImageSnapshot()
})

it('should support radial-gradient with unspecified <ending-shape>', async () => {
const svg = await satori(
<div
style={{
height: '100%',
width: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
backgroundColor: "rgb(225, 168, 211)",
height: "100%",
width: '100%',
backgroundImage: "radial-gradient(at 3% 42%, rgb(228, 105, 236) 0px, transparent 50%)",
}}
></div>
</div>,
{
width: 100,
height: 100,
fonts,
}
)
expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

it('should support advanced usage', async () => {
Expand Down

1 comment on commit 6ae34e5

@vercel
Copy link

@vercel vercel bot commented on 6ae34e5 Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.