1
1
import type { ConfigBase } from '@unocss/core' ;
2
2
import { createGenerator } from '@unocss/core' ;
3
3
import { presetTypography } from '@unocss/preset-typography' ;
4
- import { presetWind } from '@unocss/preset-wind ' ;
5
- import { presetUno } from '@unocss/preset-uno ' ;
4
+ import { presetWind3 } from '@unocss/preset-wind3 ' ;
5
+ import { presetWind4 } from '@unocss/preset-wind4 ' ;
6
6
import { presetRemToPx } from '@unocss/preset-rem-to-px' ;
7
7
import transformerCompileClass from '@unocss/transformer-compile-class' ;
8
8
import transformerVariantGroup from '@unocss/transformer-variant-group' ;
@@ -26,11 +26,19 @@ export interface TailwindProps {
26
26
'layers' | 'presets' | 'rules' | 'separators' | 'shortcuts' | 'theme' | 'variants'
27
27
> ;
28
28
production ?: boolean ;
29
+ version ?: '3' | '4' ;
30
+ }
31
+
32
+ interface GetUnoOptions {
33
+ config : ConfigBase ;
34
+ production : boolean ;
35
+ version : '3' | '4' ;
29
36
}
30
37
31
38
const debugProps = debug . elements . enabled ? { dataType : 'jsx-email/tailwind' } : { } ;
32
39
33
- const getUno = async ( config : ConfigBase , production : boolean ) => {
40
+ const getUno = async ( options : GetUnoOptions ) => {
41
+ const { config, production, version } = options ;
34
42
const transformers = [ transformerVariantGroup ( ) ] ;
35
43
36
44
if ( production )
@@ -55,8 +63,7 @@ const getUno = async (config: ConfigBase, production: boolean) => {
55
63
// Convert all `rem` values to `px`
56
64
presetRemToPx ( ) ,
57
65
presetTypography ( ) ,
58
- presetUno ( { dark : 'media' } ) ,
59
- presetWind ( )
66
+ version === '3' ? presetWind3 ( { dark : 'media' } ) : presetWind4 ( { dark : 'media' } )
60
67
] ;
61
68
const uno = await createGenerator ( {
62
69
...( config as any ) ,
@@ -70,9 +77,10 @@ const getUno = async (config: ConfigBase, production: boolean) => {
70
77
const render = async ( {
71
78
children,
72
79
config = { } ,
73
- production = false
80
+ production = false ,
81
+ version = '3'
74
82
} : React . PropsWithChildren < TailwindProps > ) => {
75
- const uno = await getUno ( config , production ) ;
83
+ const uno = await getUno ( { config, production, version } ) ;
76
84
const html = await jsxToString ( < > { children } </ > ) ;
77
85
const code = production ? html . replace ( / c l a s s = " / g, 'class=":jsx: ' ) : html ;
78
86
const s = new MagicString ( code ) ;
0 commit comments