@@ -40,11 +40,16 @@ function extractColors(colors, name, ast) {
4040 }
4141 }
4242
43- colors [ name ] [ '--base-size-8' ] = '8px' ;
44- colors [ name ] [ '--base-size-16' ] = '16px' ;
45- colors [ name ] [ '--base-text-weight-normal' ] = '400' ;
46- colors [ name ] [ '--base-text-weight-medium' ] = '500' ;
47- colors [ name ] [ '--base-text-weight-semibold' ] = '600' ;
43+ function addDeclaration ( property , value ) {
44+ colors [ name ] . push ( { type : 'declaration' , property, value} ) ;
45+ colors [ name ] [ property ] = value ;
46+ }
47+
48+ addDeclaration ( '--base-size-8' , '8px' ) ;
49+ addDeclaration ( '--base-size-16' , '16px' ) ;
50+ addDeclaration ( '--base-text-weight-normal' , '400' ) ;
51+ addDeclaration ( '--base-text-weight-medium' , '500' ) ;
52+ addDeclaration ( '--base-text-weight-semibold' , '600' ) ;
4853}
4954
5055// https://github.com/gjtorikian/html-pipeline/blob/main/lib/html_pipeline/sanitization_filter.rb
@@ -322,7 +327,7 @@ function applyColors(colors, rules) {
322327 return colors [ name ] ;
323328 }
324329
325- return match [ 0 ] ;
330+ return match ;
326331 } ) ;
327332 }
328333 }
@@ -446,12 +451,17 @@ export default async function getCSS({
446451
447452 // Find all variables used across all styles
448453 const usedVariables = new Set ( rules . flatMap ( rule => rule . declarations . flatMap ( ( { value} ) => {
449- let match = / v a r \( (?< name > [ - \w ] + ?) \) / . exec ( value ) ?. groups . name ;
450- if ( match === '--color-text-primary' ) {
451- match = '--color-fg-default' ;
452- }
454+ const matches = [ ] ;
455+ const re = / v a r \( (?< name > [ - \w ] + ?) [ , ) ] / g;
456+ let match = null ;
457+ do {
458+ match = re . exec ( value ) ;
459+ if ( match ) {
460+ matches . push ( match . groups . name ) ;
461+ }
462+ } while ( match ) ;
453463
454- return match ? [ match ] : [ ] ;
464+ return matches ;
455465 } ) ) ) ;
456466
457467 const colorSchemeLight = { type : 'declaration' , property : 'color-scheme' , value : 'light' } ;
0 commit comments