@@ -21,94 +21,95 @@ const creator: PluginCreator<Partial<ExtractOption>> = (opts) => {
21
21
filter : ( ) => true ,
22
22
remove : true
23
23
} )
24
- const result : CvaParamsSet = {
25
- base : new Set < string > ( ) ,
26
- variants : { } ,
27
- compoundVariants : [ ] ,
28
- defaultVariants : { } ,
29
- meta : { }
30
- }
31
- const prefix = _prefix ?? ''
32
- const hashMap = new Map < string , CvaParamsSet [ 'compoundVariants' ] [ number ] > ( )
33
- const weakMap = new WeakMap ( )
34
-
35
- function addBase ( value : string | string [ ] ) {
36
- setAdd ( result . base , value )
37
- }
38
24
39
- function addVariant (
40
- value : string | string [ ] ,
41
- entries : [
42
- string ,
43
- {
44
- value : string
25
+ return {
26
+ postcssPlugin : 'postcss-icestack-extract-cva-params-plugin' ,
27
+ prepare ( res ) {
28
+ const result : CvaParamsSet = {
29
+ base : new Set < string > ( ) ,
30
+ variants : { } ,
31
+ compoundVariants : [ ] ,
32
+ defaultVariants : { } ,
33
+ meta : { }
45
34
}
46
- ] [ ]
47
- ) {
48
- for ( const [ p1 , { value : p2 } ] of entries ) {
49
- const p = `${ p1 } .${ p2 } `
50
- const arr = get ( result . variants , p )
51
-
52
- if ( arr instanceof Set ) {
53
- setAdd ( arr , value )
54
- } else {
55
- const st = new Set < string > ( )
56
- setAdd ( st , value )
57
- set ( result . variants , p , st )
35
+ const prefix = _prefix ?? ''
36
+ const hashMap = new Map < string , CvaParamsSet [ 'compoundVariants' ] [ number ] > ( )
37
+ const weakMap = new WeakMap ( )
38
+
39
+ function addBase ( value : string | string [ ] ) {
40
+ setAdd ( result . base , value )
58
41
}
59
- }
60
- }
61
42
62
- function addDefaultVariant (
63
- entries : [
64
- string ,
65
- {
66
- value : string
43
+ function addVariant (
44
+ value : string | string [ ] ,
45
+ entries : [
46
+ string ,
47
+ {
48
+ value : string
49
+ }
50
+ ] [ ]
51
+ ) {
52
+ for ( const [ p1 , { value : p2 } ] of entries ) {
53
+ const p = `${ p1 } .${ p2 } `
54
+ const arr = get ( result . variants , p )
55
+
56
+ if ( arr instanceof Set ) {
57
+ setAdd ( arr , value )
58
+ } else {
59
+ const st = new Set < string > ( )
60
+ setAdd ( st , value )
61
+ set ( result . variants , p , st )
62
+ }
63
+ }
67
64
}
68
- ] [ ]
69
- ) {
70
- for ( const [ key , { value } ] of entries ) {
71
- set ( result . defaultVariants , key , value )
72
- }
73
- }
74
65
75
- function addCompoundVariant (
76
- value : string | string [ ] ,
77
- entries : [
78
- string ,
79
- {
80
- value : string
66
+ function addDefaultVariant (
67
+ entries : [
68
+ string ,
69
+ {
70
+ value : string
71
+ }
72
+ ] [ ]
73
+ ) {
74
+ for ( const [ key , { value } ] of entries ) {
75
+ set ( result . defaultVariants , key , value )
76
+ }
81
77
}
82
- ] [ ] ,
83
- hashCode : string
84
- ) {
85
- const item = hashMap . get ( hashCode )
86
- if ( item ) {
87
- item . class && setAdd ( item . class , value )
88
- } else {
89
- const set = new Set < string > ( )
90
- setAdd ( set , value )
91
-
92
- hashMap . set (
93
- hashCode ,
94
- // @ts -ignore
95
- entries . reduce (
96
- ( acc , [ k , { value } ] ) => {
97
- // @ts -ignore
98
- acc [ k ] = value
99
- return acc
100
- } ,
78
+
79
+ function addCompoundVariant (
80
+ value : string | string [ ] ,
81
+ entries : [
82
+ string ,
101
83
{
102
- class : set
84
+ value : string
103
85
}
104
- )
105
- )
106
- }
107
- }
86
+ ] [ ] ,
87
+ hashCode : string
88
+ ) {
89
+ const item = hashMap . get ( hashCode )
90
+ if ( item ) {
91
+ item . class && setAdd ( item . class , value )
92
+ } else {
93
+ const set = new Set < string > ( )
94
+ setAdd ( set , value )
95
+
96
+ hashMap . set (
97
+ hashCode ,
98
+ // @ts -ignore
99
+ entries . reduce (
100
+ ( acc , [ k , { value } ] ) => {
101
+ // @ts -ignore
102
+ acc [ k ] = value
103
+ return acc
104
+ } ,
105
+ {
106
+ class : set
107
+ }
108
+ )
109
+ )
110
+ }
111
+ }
108
112
109
- return {
110
- postcssPlugin : 'postcss-icestack-extract-cva-params-plugin' ,
111
- prepare ( res ) {
112
113
const filename = res . root . source ?. input . file
113
114
if ( filename ) {
114
115
const skip = ! filter ( filename )
0 commit comments