@varo-ui/theme 1.2.0 → 2.1.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/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
- '50': '#eff6ff',
14
- '500': seed.primary,
15
- '600': seed.primary
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['1000'],
40
- textMuted: palette.neutral['500'],
41
- surfaceBase: palette.neutral['0'],
42
- surfaceElevated: palette.neutral['50'],
43
- borderBase: palette.neutral['200'],
44
- borderStrong: palette.neutral['900'],
45
- primaryBase: palette.primary['500'],
46
- primaryHover: palette.primary['600'],
47
- dangerBase: palette.error['500']
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: '32px',
56
- heightMd: '40px',
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: '32px',
66
- heightMd: '40px',
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
  }
@@ -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 {
package/src/weapp-vite.ts CHANGED
@@ -12,19 +12,42 @@ export interface VaroWeappThemePluginOptions {
12
12
 
13
13
  export function createVaroWeappThemePlugin(options: VaroWeappThemePluginOptions): Plugin {
14
14
  const appStylePath = resolve(options.appStyle)
15
+ const themeCss = () => renderWeappThemeCss(options.theme, { variables: options.variables })
15
16
 
16
17
  return {
17
18
  name: 'varo:weapp-theme',
18
19
  enforce: 'pre',
19
20
  transform(source, id) {
20
- if (resolve(id.split('?')[0]) !== appStylePath) {
21
+ const [pathname, query = ''] = id.split('?')
22
+ if (resolve(pathname) !== appStylePath) {
23
+ return
24
+ }
25
+ if (query.includes('weapp-vite-sidecar') || /(?:^|&)lang\.(?:js|ts|jsx|tsx)(?:&|$)/.test(query)) {
21
26
  return
22
27
  }
23
28
 
24
29
  return {
25
- code: `${source}\n${renderWeappThemeCss(options.theme, { variables: options.variables })}\n`,
30
+ code: `${source}\n${themeCss()}\n`,
26
31
  map: null,
27
32
  }
28
33
  },
34
+ generateBundle: {
35
+ order: 'post',
36
+ handler(_outputOptions, bundle) {
37
+ const appStyle = Object.values(bundle).find(output => output.type === 'asset' && output.fileName === 'app.wxss')
38
+ if (!appStyle || appStyle.type !== 'asset') {
39
+ return
40
+ }
41
+
42
+ const source = typeof appStyle.source === 'string'
43
+ ? appStyle.source
44
+ : new TextDecoder().decode(appStyle.source)
45
+ const extra = themeCss()
46
+ if (source.includes(extra)) {
47
+ return
48
+ }
49
+ appStyle.source = `${source}\n${extra}\n`
50
+ },
51
+ },
29
52
  }
30
53
  }
package/src/weapp.ts CHANGED
@@ -21,5 +21,6 @@ export function renderWeappThemeCss(
21
21
  }
22
22
 
23
23
  export type { ThemeCssVariableOverrides, ThemeCssVariables } from './css.ts'
24
+ export { contrastSafeForeground } from './css.ts'
24
25
  export { createTheme, mergeThemeOverrides } from './theme.ts'
25
26
  export type { ThemeDefinition } from './types.ts'
@@ -1,86 +0,0 @@
1
- //#region src/types.d.ts
2
- interface ThemeSeed {
3
- primary: string;
4
- success: string;
5
- warning: string;
6
- error: string;
7
- neutral: string;
8
- }
9
- interface ThemePalette {
10
- primary: Record<string, string>;
11
- neutral: Record<string, string>;
12
- success: Record<string, string>;
13
- warning: Record<string, string>;
14
- error: Record<string, string>;
15
- }
16
- interface SemanticTokens {
17
- textBase: string;
18
- textMuted: string;
19
- surfaceBase: string;
20
- surfaceElevated: string;
21
- borderBase: string;
22
- borderStrong: string;
23
- primaryBase: string;
24
- primaryHover: string;
25
- dangerBase: string;
26
- }
27
- interface ComponentTokens {
28
- button: {
29
- borderRadius: string;
30
- heightSm: string;
31
- heightMd: string;
32
- heightLg: string;
33
- };
34
- dialog: {
35
- borderRadius: string;
36
- overlayColor: string;
37
- };
38
- input: {
39
- borderRadius: string;
40
- heightSm: string;
41
- heightMd: string;
42
- heightLg: string;
43
- };
44
- }
45
- interface ThemeDefinition {
46
- seed: ThemeSeed;
47
- palette: ThemePalette;
48
- semantic: SemanticTokens;
49
- components: ComponentTokens;
50
- }
51
- interface ThemeOverrides {
52
- semantic?: Partial<SemanticTokens>;
53
- components?: Partial<{
54
- button: Partial<ComponentTokens['button']>;
55
- dialog: Partial<ComponentTokens['dialog']>;
56
- input: Partial<ComponentTokens['input']>;
57
- }>;
58
- }
59
- //#endregion
60
- //#region src/css.d.ts
61
- interface ThemeCssVariables {
62
- '--varo-ui-bg': string;
63
- '--varo-ui-surface': string;
64
- '--varo-ui-surface-muted': string;
65
- '--varo-ui-text': string;
66
- '--varo-ui-text-muted': string;
67
- '--varo-ui-border': string;
68
- '--varo-ui-border-strong': string;
69
- '--varo-ui-primary': string;
70
- '--varo-ui-primary-foreground': string;
71
- '--varo-ui-success': string;
72
- '--varo-ui-warning': string;
73
- '--varo-ui-danger': string;
74
- '--varo-ui-radius': string;
75
- '--varo-ui-radius-sm': string;
76
- '--varo-ui-shadow-sm': string;
77
- '--varo-ui-shadow-md': string;
78
- '--varo-ui-ring': string;
79
- [name: `--${string}`]: string;
80
- }
81
- type ThemeCssVariableOverrides = Partial<ThemeCssVariables>;
82
- declare function createThemeCssVariables(theme: ThemeDefinition, overrides?: ThemeCssVariableOverrides): ThemeCssVariables;
83
- declare function renderThemeCssVariables(selector: string, variables: ThemeCssVariables): string;
84
- //#endregion
85
- export { ComponentTokens as a, ThemeOverrides as c, renderThemeCssVariables as i, ThemePalette as l, ThemeCssVariables as n, SemanticTokens as o, createThemeCssVariables as r, ThemeDefinition as s, ThemeCssVariableOverrides as t, ThemeSeed as u };
86
- //# sourceMappingURL=css-C3jlRHjz.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-C3jlRHjz.d.mts","names":[],"sources":["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AAA;AAAA,iBAuBa,uBAAA,CAAwB,QAAA,UAAkB,SAAA,EAAW,iBAAiB"}
@@ -1,129 +0,0 @@
1
- //#region src/css.ts
2
- function colorWithAlpha(color, alpha) {
3
- const value = color.slice(1);
4
- const normalized = value.length === 3 ? value.split("").map((part) => `${part}${part}`).join("") : value;
5
- if (!color.startsWith("#") || !/^[\da-f]{6}$/i.test(normalized)) return color;
6
- return `rgb(${Number.parseInt(normalized.slice(0, 2), 16)} ${Number.parseInt(normalized.slice(2, 4), 16)} ${Number.parseInt(normalized.slice(4, 6), 16)} / ${alpha}%)`;
7
- }
8
- function createThemeCssVariables(theme, overrides = {}) {
9
- return {
10
- "--varo-ui-bg": theme.semantic.surfaceElevated,
11
- "--varo-ui-surface": theme.semantic.surfaceBase,
12
- "--varo-ui-surface-muted": theme.palette.neutral["50"],
13
- "--varo-ui-text": theme.semantic.textBase,
14
- "--varo-ui-text-muted": theme.semantic.textMuted,
15
- "--varo-ui-border": theme.semantic.borderBase,
16
- "--varo-ui-border-strong": theme.semantic.borderStrong,
17
- "--varo-ui-primary": theme.semantic.primaryBase,
18
- "--varo-ui-primary-foreground": theme.palette.neutral["0"],
19
- "--varo-ui-success": theme.seed.success,
20
- "--varo-ui-warning": theme.seed.warning,
21
- "--varo-ui-danger": theme.semantic.dangerBase,
22
- "--varo-ui-radius": theme.components.button.borderRadius,
23
- "--varo-ui-radius-sm": theme.components.input.borderRadius,
24
- "--varo-ui-shadow-sm": "0 1px 2px rgb(24 36 51 / 6%)",
25
- "--varo-ui-shadow-md": "0 14px 34px rgb(24 36 51 / 12%)",
26
- "--varo-ui-ring": colorWithAlpha(theme.semantic.primaryBase, 16),
27
- ...overrides
28
- };
29
- }
30
- function renderThemeCssVariables(selector, variables) {
31
- const normalizedSelector = selector.trim();
32
- if (!normalizedSelector || /[{}]/.test(normalizedSelector)) throw new Error(`Invalid theme CSS selector: ${selector}`);
33
- return `${normalizedSelector} {\n${Object.entries(variables).map(([name, value]) => {
34
- if (/[;{}\r\n]/.test(value)) throw new Error(`Invalid theme CSS variable value for ${name}`);
35
- return ` ${name}: ${value};`;
36
- }).join("\n")}\n}`;
37
- }
38
- //#endregion
39
- //#region src/theme.ts
40
- function createPalette(seed) {
41
- return {
42
- primary: {
43
- "50": "#eff6ff",
44
- "500": seed.primary,
45
- "600": seed.primary
46
- },
47
- neutral: {
48
- "0": "#ffffff",
49
- "50": "#f8fafc",
50
- "200": "#e2e8f0",
51
- "500": "#64748b",
52
- "900": "#0f172a",
53
- "1000": seed.neutral
54
- },
55
- success: { "500": seed.success },
56
- warning: { "500": seed.warning },
57
- error: { "500": seed.error }
58
- };
59
- }
60
- function createSemanticTokens(palette) {
61
- return {
62
- textBase: palette.neutral["1000"],
63
- textMuted: palette.neutral["500"],
64
- surfaceBase: palette.neutral["0"],
65
- surfaceElevated: palette.neutral["50"],
66
- borderBase: palette.neutral["200"],
67
- borderStrong: palette.neutral["900"],
68
- primaryBase: palette.primary["500"],
69
- primaryHover: palette.primary["600"],
70
- dangerBase: palette.error["500"]
71
- };
72
- }
73
- function createComponentTokens(semantic) {
74
- return {
75
- button: {
76
- borderRadius: "12px",
77
- heightSm: "32px",
78
- heightMd: "40px",
79
- heightLg: "48px"
80
- },
81
- dialog: {
82
- borderRadius: "16px",
83
- overlayColor: semantic.borderStrong
84
- },
85
- input: {
86
- borderRadius: "12px",
87
- heightSm: "32px",
88
- heightMd: "40px",
89
- heightLg: "48px"
90
- }
91
- };
92
- }
93
- function createTheme(seed) {
94
- const palette = createPalette(seed);
95
- const semantic = createSemanticTokens(palette);
96
- return {
97
- seed,
98
- palette,
99
- semantic,
100
- components: createComponentTokens(semantic)
101
- };
102
- }
103
- function mergeThemeOverrides(theme, overrides = {}) {
104
- return {
105
- ...theme,
106
- semantic: {
107
- ...theme.semantic,
108
- ...overrides.semantic
109
- },
110
- components: {
111
- button: {
112
- ...theme.components.button,
113
- ...overrides.components?.button
114
- },
115
- dialog: {
116
- ...theme.components.dialog,
117
- ...overrides.components?.dialog
118
- },
119
- input: {
120
- ...theme.components.input,
121
- ...overrides.components?.input
122
- }
123
- }
124
- };
125
- }
126
- //#endregion
127
- export { mergeThemeOverrides as a, createTheme as i, createPalette as n, createThemeCssVariables as o, createSemanticTokens as r, renderThemeCssVariables as s, createComponentTokens as t };
128
-
129
- //# sourceMappingURL=theme-Dr7X-VMu.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme-Dr7X-VMu.mjs","names":[],"sources":["../src/css.ts","../src/theme.ts"],"sourcesContent":["import type { ThemeDefinition } from './types'\n\nexport interface ThemeCssVariables {\n '--varo-ui-bg': string\n '--varo-ui-surface': string\n '--varo-ui-surface-muted': string\n '--varo-ui-text': string\n '--varo-ui-text-muted': string\n '--varo-ui-border': string\n '--varo-ui-border-strong': string\n '--varo-ui-primary': string\n '--varo-ui-primary-foreground': string\n '--varo-ui-success': string\n '--varo-ui-warning': string\n '--varo-ui-danger': string\n '--varo-ui-radius': string\n '--varo-ui-radius-sm': string\n '--varo-ui-shadow-sm': string\n '--varo-ui-shadow-md': string\n '--varo-ui-ring': string\n [name: `--${string}`]: string\n}\n\nexport type ThemeCssVariableOverrides = Partial<ThemeCssVariables>\n\nfunction colorWithAlpha(color: string, alpha: number): string {\n const value = color.slice(1)\n const normalized = value.length === 3\n ? value.split('').map(part => `${part}${part}`).join('')\n : value\n\n if (!color.startsWith('#') || !/^[\\da-f]{6}$/i.test(normalized)) {\n return color\n }\n\n const red = Number.parseInt(normalized.slice(0, 2), 16)\n const green = Number.parseInt(normalized.slice(2, 4), 16)\n const blue = Number.parseInt(normalized.slice(4, 6), 16)\n return `rgb(${red} ${green} ${blue} / ${alpha}%)`\n}\n\nexport function createThemeCssVariables(\n theme: ThemeDefinition,\n overrides: ThemeCssVariableOverrides = {},\n): ThemeCssVariables {\n return {\n '--varo-ui-bg': theme.semantic.surfaceElevated,\n '--varo-ui-surface': theme.semantic.surfaceBase,\n '--varo-ui-surface-muted': theme.palette.neutral['50'],\n '--varo-ui-text': theme.semantic.textBase,\n '--varo-ui-text-muted': theme.semantic.textMuted,\n '--varo-ui-border': theme.semantic.borderBase,\n '--varo-ui-border-strong': theme.semantic.borderStrong,\n '--varo-ui-primary': theme.semantic.primaryBase,\n '--varo-ui-primary-foreground': theme.palette.neutral['0'],\n '--varo-ui-success': theme.seed.success,\n '--varo-ui-warning': theme.seed.warning,\n '--varo-ui-danger': theme.semantic.dangerBase,\n '--varo-ui-radius': theme.components.button.borderRadius,\n '--varo-ui-radius-sm': theme.components.input.borderRadius,\n '--varo-ui-shadow-sm': '0 1px 2px rgb(24 36 51 / 6%)',\n '--varo-ui-shadow-md': '0 14px 34px rgb(24 36 51 / 12%)',\n '--varo-ui-ring': colorWithAlpha(theme.semantic.primaryBase, 16),\n ...overrides,\n }\n}\n\nexport function renderThemeCssVariables(selector: string, variables: ThemeCssVariables): string {\n const normalizedSelector = selector.trim()\n if (!normalizedSelector || /[{}]/.test(normalizedSelector)) {\n throw new Error(`Invalid theme CSS selector: ${selector}`)\n }\n\n const declarations = Object.entries(variables).map(([name, value]) => {\n if (/[;{}\\r\\n]/.test(value)) {\n throw new Error(`Invalid theme CSS variable value for ${name}`)\n }\n return ` ${name}: ${value};`\n })\n\n return `${normalizedSelector} {\\n${declarations.join('\\n')}\\n}`\n}\n","import type {\n ComponentTokens,\n SemanticTokens,\n ThemeDefinition,\n ThemeOverrides,\n ThemePalette,\n ThemeSeed\n} from './types'\n\nexport function createPalette(seed: ThemeSeed): ThemePalette {\n return {\n primary: {\n '50': '#eff6ff',\n '500': seed.primary,\n '600': seed.primary\n },\n neutral: {\n '0': '#ffffff',\n '50': '#f8fafc',\n '200': '#e2e8f0',\n '500': '#64748b',\n '900': '#0f172a',\n '1000': seed.neutral\n },\n success: {\n '500': seed.success\n },\n warning: {\n '500': seed.warning\n },\n error: {\n '500': seed.error\n }\n }\n}\n\nexport function createSemanticTokens(palette: ThemePalette): SemanticTokens {\n return {\n textBase: palette.neutral['1000'],\n textMuted: palette.neutral['500'],\n surfaceBase: palette.neutral['0'],\n surfaceElevated: palette.neutral['50'],\n borderBase: palette.neutral['200'],\n borderStrong: palette.neutral['900'],\n primaryBase: palette.primary['500'],\n primaryHover: palette.primary['600'],\n dangerBase: palette.error['500']\n }\n}\n\nexport function createComponentTokens(semantic: SemanticTokens): ComponentTokens {\n return {\n button: {\n borderRadius: '12px',\n heightSm: '32px',\n heightMd: '40px',\n heightLg: '48px'\n },\n dialog: {\n borderRadius: '16px',\n overlayColor: semantic.borderStrong\n },\n input: {\n borderRadius: '12px',\n heightSm: '32px',\n heightMd: '40px',\n heightLg: '48px'\n }\n }\n}\n\nexport function createTheme(seed: ThemeSeed): ThemeDefinition {\n const palette = createPalette(seed)\n const semantic = createSemanticTokens(palette)\n const components = createComponentTokens(semantic)\n\n return {\n seed,\n palette,\n semantic,\n components\n }\n}\n\nexport function mergeThemeOverrides(theme: ThemeDefinition, overrides: ThemeOverrides = {}): ThemeDefinition {\n return {\n ...theme,\n semantic: {\n ...theme.semantic,\n ...overrides.semantic\n },\n components: {\n button: {\n ...theme.components.button,\n ...overrides.components?.button\n },\n dialog: {\n ...theme.components.dialog,\n ...overrides.components?.dialog\n },\n input: {\n ...theme.components.input,\n ...overrides.components?.input\n }\n }\n }\n}\n"],"mappings":";AAyBA,SAAS,eAAe,OAAe,OAAuB;CAC5D,MAAM,QAAQ,MAAM,MAAM,CAAC;CAC3B,MAAM,aAAa,MAAM,WAAW,IAChC,MAAM,MAAM,EAAE,CAAC,CAAC,KAAI,SAAQ,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,EAAE,IACrD;CAEJ,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,KAAK,UAAU,GAC5D,OAAO;CAMT,OAAO,OAHK,OAAO,SAAS,WAAW,MAAM,GAAG,CAAC,GAAG,EAGpC,EAAE,GAFJ,OAAO,SAAS,WAAW,MAAM,GAAG,CAAC,GAAG,EAE7B,EAAE,GADd,OAAO,SAAS,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