11import { readFileSync } from 'node:fs' ;
22import { env } from 'node:process' ;
3- import { parse } from 'css-variables-parser ' ;
3+ import { parse } from 'postcss ' ;
44
55const isProduction = env . NODE_ENV !== 'development' ;
66
7+ function extractRootVars ( css ) {
8+ const root = parse ( css ) ;
9+ const vars = new Set ( ) ;
10+ root . walkRules ( ( rule ) => {
11+ if ( rule . selector !== ':root' ) return ;
12+ rule . each ( ( decl ) => {
13+ if ( decl . value && decl . prop . startsWith ( '--' ) ) {
14+ vars . add ( decl . prop . substring ( 2 ) ) ;
15+ }
16+ } ) ;
17+ } ) ;
18+ return Array . from ( vars ) ;
19+ }
20+
21+ const vars = extractRootVars ( [
22+ readFileSync ( new URL ( 'web_src/css/themes/theme-gitea-light.css' , import . meta. url ) , 'utf8' ) ,
23+ readFileSync ( new URL ( 'web_src/css/themes/theme-gitea-dark.css' , import . meta. url ) , 'utf8' ) ,
24+ ] . join ( '\n' ) ) ;
25+
726export default {
827 prefix : 'tw-' ,
928 important : true , // the frameworks are mixed together, so tailwind needs to override other framework's styles
@@ -23,15 +42,10 @@ export default {
2342 theme : {
2443 colors : {
2544 // make `tw-bg-red` etc work with our CSS variables
26- ...Object . fromEntries (
27- Object . keys ( parse ( [
28- readFileSync ( new URL ( 'web_src/css/themes/theme-gitea-light.css' , import . meta. url ) , 'utf8' ) ,
29- readFileSync ( new URL ( 'web_src/css/themes/theme-gitea-dark.css' , import . meta. url ) , 'utf8' ) ,
30- ] . join ( '\n' ) , { } ) ) . filter ( ( prop ) => prop . startsWith ( 'color-' ) ) . map ( ( prop ) => {
31- const color = prop . substring ( 6 ) ;
32- return [ color , `var(--color-${ color } )` ] ;
33- } )
34- ) ,
45+ ...Object . fromEntries ( vars . filter ( ( prop ) => prop . startsWith ( 'color-' ) ) . map ( ( prop ) => {
46+ const color = prop . substring ( 6 ) ;
47+ return [ color , `var(--color-${ color } )` ] ;
48+ } ) ) ,
3549 inherit : 'inherit' ,
3650 current : 'currentcolor' ,
3751 transparent : 'transparent' ,
0 commit comments