@varo-ui/theme 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -10
- package/dist/css-D2jQSprg.d.mts +171 -0
- package/dist/css-D2jQSprg.d.mts.map +1 -0
- package/dist/index.d.mts +31 -71
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +85 -98
- package/dist/index.mjs.map +1 -1
- package/dist/theme-B7G19AEI.d.mts +11 -0
- package/dist/theme-B7G19AEI.d.mts.map +1 -0
- package/dist/theme-Bg24AjHw.mjs +371 -0
- package/dist/theme-Bg24AjHw.mjs.map +1 -0
- package/dist/weapp-vite.d.mts +13 -0
- package/dist/weapp-vite.d.mts.map +1 -0
- package/dist/weapp-vite.mjs +21 -0
- package/dist/weapp-vite.mjs.map +1 -0
- package/dist/weapp.d.mts +12 -0
- package/dist/weapp.d.mts.map +1 -0
- package/dist/weapp.mjs +12 -0
- package/dist/weapp.mjs.map +1 -0
- package/package.json +21 -2
- package/src/css.ts +244 -0
- package/src/index.ts +1 -0
- package/src/provider.ts +154 -22
- package/src/theme.ts +196 -47
- package/src/types-runtime.ts +4 -2
- package/src/types.ts +29 -0
- package/src/weapp-vite.ts +30 -0
- package/src/weapp.ts +26 -0
package/src/theme.ts
CHANGED
|
@@ -4,47 +4,196 @@ import type {
|
|
|
4
4
|
ThemeDefinition,
|
|
5
5
|
ThemeOverrides,
|
|
6
6
|
ThemePalette,
|
|
7
|
-
ThemeSeed
|
|
7
|
+
ThemeSeed,
|
|
8
8
|
} from './types'
|
|
9
9
|
|
|
10
|
+
interface ColorScale {
|
|
11
|
+
dark: string
|
|
12
|
+
base: string
|
|
13
|
+
light: string
|
|
14
|
+
soft: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const REFERENCE_SCALES: Record<string, Omit<ColorScale, 'base'>> = {
|
|
18
|
+
'#07c160': { dark: '#06ad56', light: '#38cd80', soft: '#e6f9ef' },
|
|
19
|
+
'#007dff': { dark: '#006ad9', light: '#3397ff', soft: '#e5f2ff' },
|
|
20
|
+
'#13b248': { dark: '#10973d', light: '#42c16d', soft: '#e7f7ec' },
|
|
21
|
+
'#fa9200': { dark: '#d57c00', light: '#fba833', soft: '#fef4e5' },
|
|
22
|
+
'#eb3437': { dark: '#c82c2f', light: '#ef5d5f', soft: '#fdeaeb' },
|
|
23
|
+
'#73767a': { dark: '#5c5e62', light: '#8f9195', soft: '#f1f1f2' },
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const DARK_SOFT_COLORS: Record<string, string> = {
|
|
27
|
+
'#07c160': '#122c1f',
|
|
28
|
+
'#007dff': '#112335',
|
|
29
|
+
'#13b248': '#142a1b',
|
|
30
|
+
'#fa9200': '#342611',
|
|
31
|
+
'#eb3437': '#321819',
|
|
32
|
+
'#73767a': '#212222',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function mixHex(base: string, target: string, targetWeight: number): string {
|
|
36
|
+
const normalizedBase = base.toLowerCase()
|
|
37
|
+
if (!/^#[\da-f]{6}$/.test(normalizedBase) || !/^#[\da-f]{6}$/.test(target)) {
|
|
38
|
+
return base
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const channels = [1, 3, 5].map((offset) => {
|
|
42
|
+
const baseChannel = Number.parseInt(normalizedBase.slice(offset, offset + 2), 16)
|
|
43
|
+
const targetChannel = Number.parseInt(target.slice(offset, offset + 2), 16)
|
|
44
|
+
return Math.round(baseChannel * (1 - targetWeight) + targetChannel * targetWeight)
|
|
45
|
+
.toString(16)
|
|
46
|
+
.padStart(2, '0')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return `#${channels.join('')}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createColorScale(base: string, mode: 'light' | 'dark'): Record<string, string> {
|
|
53
|
+
const normalized = base.toLowerCase()
|
|
54
|
+
const reference = REFERENCE_SCALES[normalized]
|
|
55
|
+
const lightScale: ColorScale = reference
|
|
56
|
+
? { base, ...reference }
|
|
57
|
+
: {
|
|
58
|
+
base,
|
|
59
|
+
dark: mixHex(base, '#000000', 0.15),
|
|
60
|
+
light: mixHex(base, '#ffffff', 0.2),
|
|
61
|
+
soft: mixHex(base, '#ffffff', 0.9),
|
|
62
|
+
}
|
|
63
|
+
const scale = mode === 'dark'
|
|
64
|
+
? {
|
|
65
|
+
...lightScale,
|
|
66
|
+
soft: DARK_SOFT_COLORS[normalized] ?? mixHex(base, '#141414', 0.86),
|
|
67
|
+
}
|
|
68
|
+
: lightScale
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...scale,
|
|
72
|
+
50: scale.soft,
|
|
73
|
+
500: scale.base,
|
|
74
|
+
600: scale.dark,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
10
78
|
export function createPalette(seed: ThemeSeed): ThemePalette {
|
|
79
|
+
const mode = seed.mode ?? 'light'
|
|
80
|
+
const neutral = mode === 'dark'
|
|
81
|
+
? {
|
|
82
|
+
'0': '#141414',
|
|
83
|
+
'50': '#1d1d1d',
|
|
84
|
+
'100': '#262727',
|
|
85
|
+
'200': '#4c4d4f',
|
|
86
|
+
'300': '#636466',
|
|
87
|
+
'400': '#8d9095',
|
|
88
|
+
'500': '#a3a6ad',
|
|
89
|
+
'600': '#cfd3dc',
|
|
90
|
+
'900': '#e5eaf3',
|
|
91
|
+
'1000': '#e5eaf3',
|
|
92
|
+
'white': '#ffffff',
|
|
93
|
+
'black': '#000000',
|
|
94
|
+
'text-primary': '#e5eaf3',
|
|
95
|
+
'text-regular': '#cfd3dc',
|
|
96
|
+
'text-secondary': '#a3a6ad',
|
|
97
|
+
'text-placeholder': '#8d9095',
|
|
98
|
+
'text-disabled': '#6c6e72',
|
|
99
|
+
'border-darker': '#636466',
|
|
100
|
+
'border-dark': '#58585a',
|
|
101
|
+
'border-base': '#4c4d4f',
|
|
102
|
+
'border-light': '#414243',
|
|
103
|
+
'border-lighter': '#363637',
|
|
104
|
+
'border-extra-light': '#2a2b2c',
|
|
105
|
+
'fill-darker': '#424243',
|
|
106
|
+
'fill-dark': '#39393a',
|
|
107
|
+
'fill-base': '#303030',
|
|
108
|
+
'fill-light': '#262727',
|
|
109
|
+
'fill-lighter': '#1d1d1d',
|
|
110
|
+
'fill-extra-light': '#191919',
|
|
111
|
+
'bg-page': '#0a0a0a',
|
|
112
|
+
'bg-base': '#141414',
|
|
113
|
+
'bg-overlay': '#1d1e1f',
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
116
|
+
'0': '#ffffff',
|
|
117
|
+
'50': '#fafafa',
|
|
118
|
+
'100': '#f5f7fa',
|
|
119
|
+
'200': '#dcdfe6',
|
|
120
|
+
'300': '#cdd0d6',
|
|
121
|
+
'400': '#a8abb2',
|
|
122
|
+
'500': '#909399',
|
|
123
|
+
'600': '#606266',
|
|
124
|
+
'900': seed.neutral,
|
|
125
|
+
'1000': seed.neutral,
|
|
126
|
+
'white': '#ffffff',
|
|
127
|
+
'black': '#000000',
|
|
128
|
+
'text-primary': seed.neutral,
|
|
129
|
+
'text-regular': '#606266',
|
|
130
|
+
'text-secondary': '#909399',
|
|
131
|
+
'text-placeholder': '#a8abb2',
|
|
132
|
+
'text-disabled': '#c0c4cc',
|
|
133
|
+
'border-darker': '#cdd0d6',
|
|
134
|
+
'border-dark': '#d4d7de',
|
|
135
|
+
'border-base': '#dcdfe6',
|
|
136
|
+
'border-light': '#e4e7ed',
|
|
137
|
+
'border-lighter': '#ebeef5',
|
|
138
|
+
'border-extra-light': '#f2f6fc',
|
|
139
|
+
'fill-darker': '#e6e8eb',
|
|
140
|
+
'fill-dark': '#ebedf0',
|
|
141
|
+
'fill-base': '#f0f2f5',
|
|
142
|
+
'fill-light': '#f5f7fa',
|
|
143
|
+
'fill-lighter': '#fafafa',
|
|
144
|
+
'fill-extra-light': '#fafcff',
|
|
145
|
+
'bg-page': '#f2f3f5',
|
|
146
|
+
'bg-base': '#ffffff',
|
|
147
|
+
'bg-overlay': '#ffffff',
|
|
148
|
+
}
|
|
149
|
+
|
|
11
150
|
return {
|
|
12
|
-
primary:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
neutral
|
|
18
|
-
'0': '#ffffff',
|
|
19
|
-
'50': '#f8fafc',
|
|
20
|
-
'200': '#e2e8f0',
|
|
21
|
-
'500': '#64748b',
|
|
22
|
-
'900': '#0f172a',
|
|
23
|
-
'1000': seed.neutral
|
|
24
|
-
},
|
|
25
|
-
success: {
|
|
26
|
-
'500': seed.success
|
|
27
|
-
},
|
|
28
|
-
warning: {
|
|
29
|
-
'500': seed.warning
|
|
30
|
-
},
|
|
31
|
-
error: {
|
|
32
|
-
'500': seed.error
|
|
33
|
-
}
|
|
151
|
+
primary: createColorScale(seed.primary, mode),
|
|
152
|
+
success: createColorScale(seed.success, mode),
|
|
153
|
+
warning: createColorScale(seed.warning, mode),
|
|
154
|
+
error: createColorScale(seed.error, mode),
|
|
155
|
+
info: createColorScale(seed.info ?? '#73767a', mode),
|
|
156
|
+
neutral,
|
|
34
157
|
}
|
|
35
158
|
}
|
|
36
159
|
|
|
37
160
|
export function createSemanticTokens(palette: ThemePalette): SemanticTokens {
|
|
38
161
|
return {
|
|
39
|
-
textBase: palette.neutral['
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
162
|
+
textBase: palette.neutral['text-primary'],
|
|
163
|
+
textRegular: palette.neutral['text-regular'],
|
|
164
|
+
textMuted: palette.neutral['text-secondary'],
|
|
165
|
+
textPlaceholder: palette.neutral['text-placeholder'],
|
|
166
|
+
textDisabled: palette.neutral['text-disabled'],
|
|
167
|
+
surfaceBase: palette.neutral['bg-base'],
|
|
168
|
+
surfaceElevated: palette.neutral['bg-page'],
|
|
169
|
+
surfaceOverlay: palette.neutral['bg-overlay'],
|
|
170
|
+
fillBase: palette.neutral['fill-base'],
|
|
171
|
+
fillLight: palette.neutral['fill-light'],
|
|
172
|
+
fillLighter: palette.neutral['fill-lighter'],
|
|
173
|
+
borderBase: palette.neutral['border-base'],
|
|
174
|
+
borderStrong: palette.neutral['border-darker'],
|
|
175
|
+
borderLight: palette.neutral['border-light'],
|
|
176
|
+
borderLighter: palette.neutral['border-lighter'],
|
|
177
|
+
primaryBase: palette.primary.base,
|
|
178
|
+
primaryDark: palette.primary.dark,
|
|
179
|
+
primaryHover: palette.primary.light,
|
|
180
|
+
primarySoft: palette.primary.soft,
|
|
181
|
+
successBase: palette.success.base,
|
|
182
|
+
successDark: palette.success.dark,
|
|
183
|
+
successHover: palette.success.light,
|
|
184
|
+
successSoft: palette.success.soft,
|
|
185
|
+
warningBase: palette.warning.base,
|
|
186
|
+
warningDark: palette.warning.dark,
|
|
187
|
+
warningHover: palette.warning.light,
|
|
188
|
+
warningSoft: palette.warning.soft,
|
|
189
|
+
dangerBase: palette.error.base,
|
|
190
|
+
dangerDark: palette.error.dark,
|
|
191
|
+
dangerHover: palette.error.light,
|
|
192
|
+
dangerSoft: palette.error.soft,
|
|
193
|
+
infoBase: palette.info.base,
|
|
194
|
+
infoDark: palette.info.dark,
|
|
195
|
+
infoHover: palette.info.light,
|
|
196
|
+
infoSoft: palette.info.soft,
|
|
48
197
|
}
|
|
49
198
|
}
|
|
50
199
|
|
|
@@ -52,20 +201,20 @@ export function createComponentTokens(semantic: SemanticTokens): ComponentTokens
|
|
|
52
201
|
return {
|
|
53
202
|
button: {
|
|
54
203
|
borderRadius: '12px',
|
|
55
|
-
heightSm: '
|
|
56
|
-
heightMd: '
|
|
57
|
-
heightLg: '48px'
|
|
204
|
+
heightSm: '36px',
|
|
205
|
+
heightMd: '44px',
|
|
206
|
+
heightLg: '48px',
|
|
58
207
|
},
|
|
59
208
|
dialog: {
|
|
60
209
|
borderRadius: '16px',
|
|
61
|
-
overlayColor: semantic.borderStrong
|
|
210
|
+
overlayColor: semantic.borderStrong,
|
|
62
211
|
},
|
|
63
212
|
input: {
|
|
64
213
|
borderRadius: '12px',
|
|
65
|
-
heightSm: '
|
|
66
|
-
heightMd: '
|
|
67
|
-
heightLg: '48px'
|
|
68
|
-
}
|
|
214
|
+
heightSm: '36px',
|
|
215
|
+
heightMd: '44px',
|
|
216
|
+
heightLg: '48px',
|
|
217
|
+
},
|
|
69
218
|
}
|
|
70
219
|
}
|
|
71
220
|
|
|
@@ -78,7 +227,7 @@ export function createTheme(seed: ThemeSeed): ThemeDefinition {
|
|
|
78
227
|
seed,
|
|
79
228
|
palette,
|
|
80
229
|
semantic,
|
|
81
|
-
components
|
|
230
|
+
components,
|
|
82
231
|
}
|
|
83
232
|
}
|
|
84
233
|
|
|
@@ -87,21 +236,21 @@ export function mergeThemeOverrides(theme: ThemeDefinition, overrides: ThemeOver
|
|
|
87
236
|
...theme,
|
|
88
237
|
semantic: {
|
|
89
238
|
...theme.semantic,
|
|
90
|
-
...overrides.semantic
|
|
239
|
+
...overrides.semantic,
|
|
91
240
|
},
|
|
92
241
|
components: {
|
|
93
242
|
button: {
|
|
94
243
|
...theme.components.button,
|
|
95
|
-
...overrides.components?.button
|
|
244
|
+
...overrides.components?.button,
|
|
96
245
|
},
|
|
97
246
|
dialog: {
|
|
98
247
|
...theme.components.dialog,
|
|
99
|
-
...overrides.components?.dialog
|
|
248
|
+
...overrides.components?.dialog,
|
|
100
249
|
},
|
|
101
250
|
input: {
|
|
102
251
|
...theme.components.input,
|
|
103
|
-
...overrides.components?.input
|
|
104
|
-
}
|
|
105
|
-
}
|
|
252
|
+
...overrides.components?.input,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
106
255
|
}
|
|
107
256
|
}
|
package/src/types-runtime.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
1
2
|
import type { ThemeDefinition, ThemeOverrides } from './types'
|
|
2
3
|
|
|
3
4
|
export interface ThemeConfig {
|
|
4
|
-
theme: ThemeDefinition
|
|
5
|
-
overrides?: ThemeOverrides
|
|
5
|
+
theme: MaybeRefOrGetter<ThemeDefinition>
|
|
6
|
+
overrides?: MaybeRefOrGetter<ThemeOverrides | undefined>
|
|
7
|
+
target?: HTMLElement
|
|
6
8
|
}
|
package/src/types.ts
CHANGED
|
@@ -4,6 +4,8 @@ export interface ThemeSeed {
|
|
|
4
4
|
warning: string
|
|
5
5
|
error: string
|
|
6
6
|
neutral: string
|
|
7
|
+
info?: string
|
|
8
|
+
mode?: 'light' | 'dark'
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export interface ThemePalette {
|
|
@@ -12,18 +14,45 @@ export interface ThemePalette {
|
|
|
12
14
|
success: Record<string, string>
|
|
13
15
|
warning: Record<string, string>
|
|
14
16
|
error: Record<string, string>
|
|
17
|
+
info: Record<string, string>
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export interface SemanticTokens {
|
|
18
21
|
textBase: string
|
|
22
|
+
textRegular: string
|
|
19
23
|
textMuted: string
|
|
24
|
+
textPlaceholder: string
|
|
25
|
+
textDisabled: string
|
|
20
26
|
surfaceBase: string
|
|
21
27
|
surfaceElevated: string
|
|
28
|
+
surfaceOverlay: string
|
|
29
|
+
fillBase: string
|
|
30
|
+
fillLight: string
|
|
31
|
+
fillLighter: string
|
|
22
32
|
borderBase: string
|
|
23
33
|
borderStrong: string
|
|
34
|
+
borderLight: string
|
|
35
|
+
borderLighter: string
|
|
24
36
|
primaryBase: string
|
|
37
|
+
primaryDark: string
|
|
25
38
|
primaryHover: string
|
|
39
|
+
primarySoft: string
|
|
40
|
+
successBase: string
|
|
41
|
+
successDark: string
|
|
42
|
+
successHover: string
|
|
43
|
+
successSoft: string
|
|
44
|
+
warningBase: string
|
|
45
|
+
warningDark: string
|
|
46
|
+
warningHover: string
|
|
47
|
+
warningSoft: string
|
|
26
48
|
dangerBase: string
|
|
49
|
+
dangerDark: string
|
|
50
|
+
dangerHover: string
|
|
51
|
+
dangerSoft: string
|
|
52
|
+
infoBase: string
|
|
53
|
+
infoDark: string
|
|
54
|
+
infoHover: string
|
|
55
|
+
infoSoft: string
|
|
27
56
|
}
|
|
28
57
|
|
|
29
58
|
export interface ComponentTokens {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Plugin } from 'vite'
|
|
2
|
+
import type { ThemeCssVariableOverrides } from './css.ts'
|
|
3
|
+
import type { ThemeDefinition } from './types.ts'
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import { renderWeappThemeCss } from './weapp.ts'
|
|
6
|
+
|
|
7
|
+
export interface VaroWeappThemePluginOptions {
|
|
8
|
+
appStyle: string
|
|
9
|
+
theme: ThemeDefinition
|
|
10
|
+
variables?: ThemeCssVariableOverrides
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createVaroWeappThemePlugin(options: VaroWeappThemePluginOptions): Plugin {
|
|
14
|
+
const appStylePath = resolve(options.appStyle)
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
name: 'varo:weapp-theme',
|
|
18
|
+
enforce: 'pre',
|
|
19
|
+
transform(source, id) {
|
|
20
|
+
if (resolve(id.split('?')[0]) !== appStylePath) {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
code: `${source}\n${renderWeappThemeCss(options.theme, { variables: options.variables })}\n`,
|
|
26
|
+
map: null,
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/weapp.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ThemeCssVariableOverrides, ThemeCssVariables } from './css.ts'
|
|
2
|
+
import type { ThemeDefinition } from './types.ts'
|
|
3
|
+
import { createThemeCssVariables, renderThemeCssVariables } from './css.ts'
|
|
4
|
+
|
|
5
|
+
export interface WeappThemeCssOptions {
|
|
6
|
+
variables?: ThemeCssVariableOverrides
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createWeappThemeStyle(
|
|
10
|
+
theme: ThemeDefinition,
|
|
11
|
+
options: WeappThemeCssOptions = {},
|
|
12
|
+
): ThemeCssVariables {
|
|
13
|
+
return createThemeCssVariables(theme, options.variables)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function renderWeappThemeCss(
|
|
17
|
+
theme: ThemeDefinition,
|
|
18
|
+
options: WeappThemeCssOptions = {},
|
|
19
|
+
): string {
|
|
20
|
+
return renderThemeCssVariables('page', createWeappThemeStyle(theme, options))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type { ThemeCssVariableOverrides, ThemeCssVariables } from './css.ts'
|
|
24
|
+
export { contrastSafeForeground } from './css.ts'
|
|
25
|
+
export { createTheme, mergeThemeOverrides } from './theme.ts'
|
|
26
|
+
export type { ThemeDefinition } from './types.ts'
|