@@ -19,6 +19,13 @@ const valid = [
1919 'conic-gradient(from 0deg at 0% 100% in oklab,#fff, 2%, #f00 0%, 8%, #fff 0%, 13%, #f00 0%, 18%, #fff 0%, 21%, #f00 0%, 24%, #fff 0%)' ,
2020 'linear-gradient(to right in oklab,#0ff 12%, #111 0% 24%, #ff0 0% 36%, #111 0% 48%, #f0f 0% 60%, #111 0% 72%, #0ff 0%, #111 0% 100%)' ,
2121 'radial-gradient(farthest-corner circle at 0% 0% in oklch,oklch(95% .25 160), 26%, oklch(75% .5 180) 0%, 46%, oklch(75% .5 210) 0%, 60%, oklch(75% .5 230) 0%, 82%, oklch(75% .5 260) 0%)' ,
22+ // Multi-line gradient with semicolon and directional keyword
23+ `linear-gradient(
24+ to right in oklab,
25+ oklch(70% 0.5 340),
26+ oklch(80% 0.3 89) 64%,
27+ oklch(90% 0.5 200)
28+ );` ,
2229]
2330
2431const invalid = [
@@ -64,5 +71,34 @@ describe('parseGradient', () => {
6471 expect ( stopsB [ 1 ] . position1 ) . toBeNull ( )
6572 expect ( stopsB [ 1 ] . position2 ) . toBeNull ( )
6673 } )
74+
75+ it ( 'strips trailing semicolons and correctly parses directional keywords' , ( ) => {
76+ const withSemi = parseGradient ( 'linear-gradient(to right, red, blue);' )
77+ expect ( withSemi . type ) . toBe ( 'linear' )
78+ expect ( withSemi . linear ?. angleKeyword ) . toBe ( 'to right' )
79+ expect ( withSemi . stops . length ) . toBeGreaterThanOrEqual ( 2 )
80+
81+ const multiline = parseGradient ( `linear-gradient(
82+ to right in oklab,
83+ oklch(70% 0.5 340),
84+ oklch(80% 0.3 89) 64%,
85+ oklch(90% 0.5 200)
86+ );` )
87+ expect ( multiline . type ) . toBe ( 'linear' )
88+ expect ( multiline . linear ?. angleKeyword ) . toBe ( 'to right' )
89+ expect ( multiline . space ) . toBe ( 'oklab' )
90+ expect ( multiline . stops . length ) . toBe ( 3 )
91+ } )
92+
93+ it ( 'correctly parses all directional keywords' , ( ) => {
94+ const keywords = [
95+ 'to top' , 'to top right' , 'to right' , 'to bottom right' ,
96+ 'to bottom' , 'to bottom left' , 'to left' , 'to top left'
97+ ]
98+ keywords . forEach ( kw => {
99+ const parsed = parseGradient ( `linear-gradient(${ kw } , red, blue)` )
100+ expect ( parsed . linear ?. angleKeyword ) . toBe ( kw )
101+ } )
102+ } )
67103} )
68104
0 commit comments