@@ -1228,6 +1228,8 @@ export function parseUnparsed(
12281228 builder ,
12291229 property ,
12301230 ) ;
1231+ case "color-mix" :
1232+ return parseColorMix ( tokenOrValue . value . arguments , builder , property ) ;
12311233 default : {
12321234 builder . addWarning ( "value" , `${ tokenOrValue . value . name } ()` ) ;
12331235 return ;
@@ -2633,6 +2635,100 @@ export function parseCalcFn(
26332635 return ;
26342636}
26352637
2638+ export function parseColorMix (
2639+ tokens : TokenOrValue [ ] ,
2640+ builder : StylesheetBuilder ,
2641+ property : string ,
2642+ ) : StyleDescriptor {
2643+ const [ inToken , whitespace , colorSpace , comma , ...rest ] = tokens ;
2644+ if (
2645+ typeof inToken !== "object" ||
2646+ inToken . type !== "token" ||
2647+ inToken . value . type !== "ident" ||
2648+ inToken . value . value !== "in"
2649+ ) {
2650+ return ;
2651+ }
2652+
2653+ if (
2654+ typeof whitespace !== "object" ||
2655+ whitespace . type !== "token" ||
2656+ whitespace . value . type !== "white-space"
2657+ ) {
2658+ return ;
2659+ }
2660+
2661+ if (
2662+ typeof comma !== "object" ||
2663+ comma . type !== "token" ||
2664+ comma . value . type !== "comma"
2665+ ) {
2666+ return ;
2667+ }
2668+
2669+ const colorSpaceArg = parseUnparsed ( colorSpace , builder , property ) ;
2670+ if ( typeof colorSpaceArg !== "string" ) {
2671+ return ;
2672+ }
2673+
2674+ let nextToken = rest . shift ( ) ;
2675+
2676+ const leftColorArg = parseUnparsed ( nextToken , builder , property ) ;
2677+
2678+ if ( ! leftColorArg ) {
2679+ return ;
2680+ }
2681+
2682+ nextToken = rest . shift ( ) ;
2683+
2684+ let leftColorPercentage : StyleDescriptor | undefined ;
2685+ if ( nextToken ?. type !== "token" || nextToken . value . type !== "comma" ) {
2686+ leftColorPercentage = parseUnparsed ( nextToken , builder , property ) ;
2687+ nextToken = rest . shift ( ) ;
2688+ }
2689+
2690+ if (
2691+ typeof nextToken !== "object" ||
2692+ nextToken . type !== "token" ||
2693+ nextToken . value . type !== "comma"
2694+ ) {
2695+ return ;
2696+ }
2697+
2698+ nextToken = rest . shift ( ) ;
2699+
2700+ const rightColorArg = parseUnparsed ( nextToken , builder , property ) ;
2701+
2702+ if ( rightColorArg === "transparent" ) {
2703+ // Ignore the rest, treat as single color with alpha
2704+ return [ { } , "colorMix" , [ colorSpaceArg , leftColorArg , leftColorPercentage ] ] ;
2705+ }
2706+
2707+ nextToken = rest . shift ( ) ;
2708+ let rightColorPercentage : StyleDescriptor | undefined ;
2709+ if ( nextToken ?. type !== "token" || nextToken . value . type !== "comma" ) {
2710+ rightColorPercentage = parseUnparsed ( nextToken , builder , property ) ;
2711+ nextToken = rest . shift ( ) ;
2712+ }
2713+
2714+ // We should have expired all tokens now
2715+ if ( nextToken ) {
2716+ return ;
2717+ }
2718+
2719+ return [
2720+ { } ,
2721+ "colorMix" ,
2722+ [
2723+ colorSpaceArg ,
2724+ leftColorArg ,
2725+ leftColorPercentage ,
2726+ rightColorArg ,
2727+ rightColorPercentage ,
2728+ ] ,
2729+ ] ;
2730+ }
2731+
26362732export function parseCalcArguments (
26372733 [ ...args ] : TokenOrValue [ ] ,
26382734 builder : StylesheetBuilder ,
0 commit comments