Skip to content

Commit ea95cb3

Browse files
committed
Use named exports for gradient parser types
1 parent 6f3df38 commit ea95cb3

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

packages/components/src/custom-gradient-picker/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
import classnames from 'classnames';
5-
import type gradientParser from 'gradient-parser';
5+
import type { LinearGradientNode } from 'gradient-parser';
66

77
/**
88
* WordPress dependencies
@@ -82,7 +82,7 @@ const GradientTypePicker = ( {
8282
? undefined
8383
: HORIZONTAL_GRADIENT_ORIENTATION,
8484
type: 'linear-gradient',
85-
} as gradientParser.LinearGradientNode )
85+
} as LinearGradientNode )
8686
);
8787
};
8888

packages/components/src/custom-gradient-picker/serializer.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/**
22
* External dependencies
33
*/
4-
import type gradientParser from 'gradient-parser';
4+
import type { ColorStop, GradientNode } from 'gradient-parser';
55

6-
export function serializeGradientColor( {
7-
type,
8-
value,
9-
}: gradientParser.ColorStop ) {
6+
export function serializeGradientColor( { type, value }: ColorStop ) {
107
if ( type === 'literal' ) {
118
return value;
129
}
@@ -16,9 +13,7 @@ export function serializeGradientColor( {
1613
return `${ type }(${ value.join( ',' ) })`;
1714
}
1815

19-
export function serializeGradientPosition(
20-
position: gradientParser.ColorStop[ 'length' ]
21-
) {
16+
export function serializeGradientPosition( position: ColorStop[ 'length' ] ) {
2217
if ( ! position ) {
2318
return '';
2419
}
@@ -30,15 +25,15 @@ export function serializeGradientColorStop( {
3025
type,
3126
value,
3227
length,
33-
}: gradientParser.ColorStop ) {
28+
}: ColorStop ) {
3429
return `${ serializeGradientColor( {
3530
type,
3631
value,
37-
} as gradientParser.ColorStop ) } ${ serializeGradientPosition( length ) }`;
32+
} as ColorStop ) } ${ serializeGradientPosition( length ) }`;
3833
}
3934

4035
export function serializeGradientOrientation(
41-
orientation: gradientParser.GradientNode[ 'orientation' ]
36+
orientation: GradientNode[ 'orientation' ]
4237
) {
4338
if (
4439
Array.isArray( orientation ) ||
@@ -54,13 +49,11 @@ export function serializeGradient( {
5449
type,
5550
orientation,
5651
colorStops,
57-
}: gradientParser.GradientNode ) {
52+
}: GradientNode ) {
5853
const serializedOrientation = serializeGradientOrientation( orientation );
5954
const serializedColorStops = colorStops
6055
.sort( ( colorStop1, colorStop2 ) => {
61-
const getNumericStopValue = (
62-
colorStop: gradientParser.ColorStop
63-
) => {
56+
const getNumericStopValue = ( colorStop: ColorStop ) => {
6457
return colorStop?.length?.value === undefined
6558
? 0
6659
: parseInt( colorStop.length.value );

packages/components/src/custom-gradient-picker/types.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/**
22
* External dependencies
33
*/
4-
import type gradientParser from 'gradient-parser';
4+
import type {
5+
LinearGradientNode,
6+
RepeatingLinearGradientNode,
7+
GradientNode,
8+
} from 'gradient-parser';
59

610
export type CustomGradientPickerProps = {
711
/**
@@ -33,15 +37,13 @@ export type CustomGradientPickerProps = {
3337
};
3438

3539
export type GradientAnglePickerProps = {
36-
gradientAST:
37-
| gradientParser.LinearGradientNode
38-
| gradientParser.RepeatingLinearGradientNode;
40+
gradientAST: LinearGradientNode | RepeatingLinearGradientNode;
3941
hasGradient: boolean;
4042
onChange: ( gradient: string ) => void;
4143
};
4244

4345
export type GradientTypePickerProps = {
44-
gradientAST: gradientParser.GradientNode;
46+
gradientAST: GradientNode;
4547
hasGradient: boolean;
4648
onChange: ( gradient: string ) => void;
4749
};

0 commit comments

Comments
 (0)