@@ -184,11 +184,24 @@ const brandColorBundle = (
184184 "/* color variables from _brand.yml */" ,
185185 '// quarto-scss-analysis-annotation { "action": "push", "origin": "_brand.yml color" }' ,
186186 ] ;
187+ const colorCssVariables : string [ ] = [
188+ "/* color CSS variables from _brand.yml */" ,
189+ '// quarto-scss-analysis-annotation { "action": "push", "origin": "_brand.yml color" }' ,
190+ ":root {" ,
191+ ] ;
192+
193+ // Create `brand-` prefixed Sass and CSS variables from color.palette
187194 for ( const colorKey of Object . keys ( brand . data ?. color ?. palette ?? { } ) ) {
195+ const colorVar = colorKey . replace ( / [ ^ a - z A - Z 0 - 9 _ - ] + / , "-" ) ;
188196 colorVariables . push (
189- `$${ colorKey } : ${ brand . getColor ( colorKey ) } !default;` ,
197+ `$brand- ${ colorVar } : ${ brand . getColor ( colorKey ) } !default;` ,
190198 ) ;
199+ colorCssVariables . push (
200+ ` --brand-${ colorVar } : ${ brand . getColor ( colorKey ) } ;` ,
201+ )
191202 }
203+
204+ // Map theme colors directly to Sass variables
192205 for ( const colorKey of Object . keys ( brand . data . color ?? { } ) ) {
193206 if ( colorKey === "palette" ) {
194207 continue ;
@@ -197,6 +210,7 @@ const brandColorBundle = (
197210 `$${ colorKey } : ${ brand . getColor ( colorKey ) } !default;` ,
198211 ) ;
199212 }
213+
200214 // format-specific name mapping
201215 for ( const [ key , value ] of Object . entries ( nameMap ) ) {
202216 const resolvedValue = brand . getColor ( value ) ;
@@ -208,6 +222,7 @@ const brandColorBundle = (
208222 }
209223 // const colorEntries = Object.keys(brand.color);
210224 colorVariables . push ( '// quarto-scss-analysis-annotation { "action": "pop" }' ) ;
225+ colorCssVariables . push ( "}" , '// quarto-scss-analysis-annotation { "action": "pop" }' ) ;
211226 const colorBundle : SassBundleLayers = {
212227 key,
213228 // dependency: "bootstrap",
@@ -216,7 +231,7 @@ const brandColorBundle = (
216231 uses : "" ,
217232 functions : "" ,
218233 mixins : "" ,
219- rules : "" ,
234+ rules : colorCssVariables . join ( "\n" ) ,
220235 } ,
221236 } ;
222237 return colorBundle ;
0 commit comments