/
v0_v2.ts
90 lines (82 loc) · 2.12 KB
/
v0_v2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {defaultThemeConfig} from '../defaults/config'
import {RootTheme, RootTheme_v2} from '../system'
import {themeColor_v0_v2} from './themeColor_v0_v2'
const cache = new WeakMap<RootTheme, RootTheme_v2>()
/** @internal */
export function v0_v2(v0: RootTheme): RootTheme_v2 {
if (v0.v2) return v0.v2
const cached_v2 = cache.get(v0)
if (cached_v2) return cached_v2
const {
avatar,
button,
color,
container,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
focusRing: _unused_focusRing,
fonts: font,
input,
layer,
media,
radius,
shadows: shadow,
space,
styles: style,
} = v0
const v2: RootTheme_v2 = {
_version: 2,
avatar: {
...defaultThemeConfig.avatar,
...avatar,
},
button: {
...defaultThemeConfig.button,
...button,
},
card: defaultThemeConfig.card,
color: {
light: {
transparent: themeColor_v0_v2(color.light.transparent),
default: themeColor_v0_v2(color.light.default),
primary: themeColor_v0_v2(color.light.primary),
positive: themeColor_v0_v2(color.light.positive),
caution: themeColor_v0_v2(color.light.caution),
critical: themeColor_v0_v2(color.light.critical),
},
dark: {
transparent: themeColor_v0_v2(color.dark.transparent),
default: themeColor_v0_v2(color.dark.default),
primary: themeColor_v0_v2(color.dark.primary),
positive: themeColor_v0_v2(color.dark.positive),
caution: themeColor_v0_v2(color.dark.caution),
critical: themeColor_v0_v2(color.dark.critical),
},
},
container,
font,
input: {
...defaultThemeConfig.input,
...input,
checkbox: {
...defaultThemeConfig.input.checkbox,
...input.checkbox,
},
radio: {
...defaultThemeConfig.input.radio,
...input.radio,
},
switch: {
...defaultThemeConfig.input.switch,
...input.switch,
},
},
layer: layer ?? defaultThemeConfig.layer,
media,
radius,
shadow,
space,
style,
}
cache.set(v0, v2)
return v2
}