Skip to content

Commit 5d4706f

Browse files
committed
chore: release postcss-cva 0.2.5
1 parent 3ea7dac commit 5d4706f

File tree

2 files changed

+80
-79
lines changed

2 files changed

+80
-79
lines changed

plugins/postcss-cva/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "postcss-cva",
33
"description": "generate cva functions by css comment",
4-
"version": "0.2.4",
4+
"version": "0.2.5",
55
"scripts": {
66
"dev": "unbuild --sourcemap",
77
"build": "unbuild",

plugins/postcss-cva/src/extract.ts

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,94 +21,95 @@ const creator: PluginCreator<Partial<ExtractOption>> = (opts) => {
2121
filter: () => true,
2222
remove: true
2323
})
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-
}
3824

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: {}
4534
}
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)
5841
}
59-
}
60-
}
6142

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+
}
6764
}
68-
][]
69-
) {
70-
for (const [key, { value }] of entries) {
71-
set(result.defaultVariants, key, value)
72-
}
73-
}
7465

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+
}
8177
}
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,
10183
{
102-
class: set
84+
value: string
10385
}
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+
}
108112

109-
return {
110-
postcssPlugin: 'postcss-icestack-extract-cva-params-plugin',
111-
prepare(res) {
112113
const filename = res.root.source?.input.file
113114
if (filename) {
114115
const skip = !filter(filename)

0 commit comments

Comments
 (0)