Repository navigation
Switched to the official gradient-parser types #84582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ciampo
merged 4 commits into
WordPress:trunk
from
joshualip-plaudit:fix/switch-to-official-gradient-parser-types
Oct 13, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c0a0e9f
Switched to the official gradient-parser types
joshualip-plaudit e657db8
Added a changelog entry
joshualip-plaudit 1c3bd17
Updated dependencies to hopefully get the build process working
joshualip-plaudit e3c97d6
CustomGradientPicker: Fix gradient-parser integration
ciampo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
packages/components/src/custom-gradient-picker/test/utils.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { describe, expect, test } from 'vitest'; | ||
| import { DEFAULT_GRADIENT } from '../constants'; | ||
| import { | ||
| getGradientAstWithDefault, | ||
| getGradientAstWithControlPoints, | ||
| getStopCssColor, | ||
| } from '../utils'; | ||
| import { serializeGradient } from '../serializer'; | ||
|
|
||
| describe( 'CustomGradientPicker gradient parsing', () => { | ||
| test.each( [ | ||
| '90deg', | ||
| '0.25turn', | ||
| '100grad', | ||
| `${ Math.PI / 2 }rad`, | ||
| 'to right', | ||
| ] )( 'preserves the angle of %s when editing a color stop', ( angle ) => { | ||
| const { gradientAST, hasGradient } = getGradientAstWithDefault( | ||
| `linear-gradient(${ angle },red 0%,blue 100%)` | ||
| ); | ||
|
|
||
| expect( hasGradient ).toBe( true ); | ||
| expect( gradientAST.orientation ).toEqual( { | ||
| type: 'angular', | ||
| value: '90', | ||
| unit: 'deg', | ||
| } ); | ||
| expect( | ||
| serializeGradient( | ||
| getGradientAstWithControlPoints( gradientAST, [ | ||
| { color: 'red', position: 10 }, | ||
| { color: 'blue', position: 100 }, | ||
| ] ) | ||
| ) | ||
| ).toBe( 'linear-gradient(90deg,rgb(255,0,0) 10%,rgb(0,0,255) 100%)' ); | ||
| } ); | ||
|
|
||
| test( 'preserves an opaque HSLA color when editing a stop', () => { | ||
| const { gradientAST, hasGradient } = getGradientAstWithDefault( | ||
| 'linear-gradient(90deg,hsla(0 100% 50%) 0%,blue 100%)' | ||
| ); | ||
| const controlPoints = gradientAST.colorStops.map( ( stop ) => ( { | ||
| color: getStopCssColor( stop ), | ||
| position: Number( stop.length?.value ), | ||
| } ) ); | ||
| controlPoints[ 0 ].position = 10; | ||
|
|
||
| expect( hasGradient ).toBe( true ); | ||
| expect( serializeGradient( gradientAST ) ).toBe( | ||
| 'linear-gradient(90deg,hsla(0,100%,50%,1) 0%,blue 100%)' | ||
| ); | ||
| expect( | ||
| serializeGradient( | ||
| getGradientAstWithControlPoints( gradientAST, controlPoints ) | ||
| ) | ||
| ).toBe( 'linear-gradient(90deg,rgb(255,0,0) 10%,rgb(0,0,255) 100%)' ); | ||
| } ); | ||
|
|
||
| test.each( [ | ||
| 'conic-gradient(from 90deg at 25% 25%,red 0%,blue 100%)', | ||
| 'repeating-conic-gradient(red 0%,blue 100%)', | ||
| 'linear-gradient(90deg,red 0% 50%,blue 100%)', | ||
| ] )( 'uses the unselected fallback for unsupported %s', ( gradient ) => { | ||
| const result = getGradientAstWithDefault( gradient ); | ||
| const fallback = getGradientAstWithDefault( DEFAULT_GRADIENT ); | ||
|
|
||
| expect( result.hasGradient ).toBe( false ); | ||
| expect( result.gradientAST ).toEqual( fallback.gradientAST ); | ||
| } ); | ||
| } ); |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gradient-parser@1.1.1has no bundled declarations, and the lockfile still installs it, so removing@types/gradient-parserbreaks type checking. Could we requiregradient-parser@^1.2.0, update the lockfile, and make any changes needed for its types in this PR?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I missed that the lockfile was important for this in my initial commit (I was trying to minimize the change count)