1
1
import { readFileSync } from 'node:fs' ;
2
2
import { env } from 'node:process' ;
3
- import { parse } from 'css-variables-parser ' ;
3
+ import { parse } from 'postcss ' ;
4
4
5
5
const isProduction = env . NODE_ENV !== 'development' ;
6
6
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
+
7
26
export default {
8
27
prefix : 'tw-' ,
9
28
important : true , // the frameworks are mixed together, so tailwind needs to override other framework's styles
@@ -23,15 +42,10 @@ export default {
23
42
theme : {
24
43
colors : {
25
44
// 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
+ } ) ) ,
35
49
inherit : 'inherit' ,
36
50
current : 'currentcolor' ,
37
51
transparent : 'transparent' ,
0 commit comments