@@ -2,12 +2,10 @@ import type {LogLevel} from 'remotion';
22import { Internals } from 'remotion' ;
33import type { BorderRadiusCorners } from './border-radius' ;
44import { drawRoundedRectPath } from './draw-rounded' ;
5+ import type { ShadowBase } from './parse-shadow' ;
6+ import { parseShadowValues } from './parse-shadow' ;
57
6- interface BoxShadow {
7- offsetX : number ;
8- offsetY : number ;
9- blurRadius : number ;
10- color : string ;
8+ interface BoxShadow extends ShadowBase {
119 inset : boolean ;
1210}
1311
@@ -16,57 +14,18 @@ export const parseBoxShadow = (boxShadowValue: string): BoxShadow[] => {
1614 return [ ] ;
1715 }
1816
19- const shadows : BoxShadow [ ] = [ ] ;
17+ const baseShadows = parseShadowValues (
18+ // Remove 'inset' before parsing shared values
19+ boxShadowValue ,
20+ ) ;
2021
21- // Split by comma, but respect rgba() colors
22+ // Split by comma to check for inset on each shadow
2223 const shadowStrings = boxShadowValue . split ( / , (? ! [ ^ ( ] * \) ) / ) ;
2324
24- for ( const shadowStr of shadowStrings ) {
25- const trimmed = shadowStr . trim ( ) ;
26- if ( ! trimmed || trimmed === 'none' ) {
27- continue ;
28- }
29-
30- const shadow : BoxShadow = {
31- offsetX : 0 ,
32- offsetY : 0 ,
33- blurRadius : 0 ,
34- color : 'rgba(0, 0, 0, 0.5)' ,
35- inset : false ,
36- } ;
37-
38- // Check for inset
39- shadow . inset = / \b i n s e t \b / i. test ( trimmed ) ;
40-
41- // Remove 'inset' keyword
42- let remaining = trimmed . replace ( / \b i n s e t \b / gi, '' ) . trim ( ) ;
43-
44- // Extract color (can be rgb(), rgba(), hsl(), hsla(), hex, or named color)
45- const colorMatch = remaining . match (
46- / ( r g b a ? \( [ ^ ) ] + \) | h s l a ? \( [ ^ ) ] + \) | # [ 0 - 9 a - f ] { 3 , 8 } | [ a - z ] + ) / i,
47- ) ;
48- if ( colorMatch ) {
49- shadow . color = colorMatch [ 0 ] ;
50- remaining = remaining . replace ( colorMatch [ 0 ] , '' ) . trim ( ) ;
51- }
52-
53- // Parse remaining numeric values (offset-x offset-y blur spread)
54- const numbers = remaining . match ( / [ + - ] ? \d * \. ? \d + (?: p x | e m | r e m | % ) ? / gi) || [ ] ;
55- const values = numbers . map ( ( n ) => parseFloat ( n ) || 0 ) ;
56-
57- if ( values . length >= 2 ) {
58- shadow . offsetX = values [ 0 ] ;
59- shadow . offsetY = values [ 1 ] ;
60-
61- if ( values . length >= 3 ) {
62- shadow . blurRadius = Math . max ( 0 , values [ 2 ] ) ; // Blur cannot be negative
63- }
64- }
65-
66- shadows . push ( shadow ) ;
67- }
68-
69- return shadows ;
25+ return baseShadows . map ( ( base , i ) => ( {
26+ ...base ,
27+ inset : / \b i n s e t \b / i. test ( shadowStrings [ i ] || '' ) ,
28+ } ) ) ;
7029} ;
7130
7231export const drawBorderRadius = ( {
0 commit comments