@varo-ui/theme 1.0.1 → 1.2.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 +53 -1
- package/dist/css-C3jlRHjz.d.mts +86 -0
- package/dist/css-C3jlRHjz.d.mts.map +1 -0
- package/dist/index.d.mts +4 -68
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -89
- package/dist/index.mjs.map +1 -1
- package/dist/theme-Dr7X-VMu.mjs +129 -0
- package/dist/theme-Dr7X-VMu.mjs.map +1 -0
- package/dist/theme-DwYvwHOu.d.mts +11 -0
- package/dist/theme-DwYvwHOu.d.mts.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 +24 -1
- package/src/css.ts +82 -0
- package/src/index.ts +1 -0
- package/src/provider.ts +9 -7
- package/src/weapp-vite.ts +30 -0
- package/src/weapp.ts +25 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Token-driven themes and providers for Varo H5 and mini-program components.
|
|
|
8
8
|
pnpm add @varo-ui/theme
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## H5 usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
import { createTheme, provideVaroTheme } from '@varo-ui/theme'
|
|
@@ -23,4 +23,56 @@ const theme = createTheme({
|
|
|
23
23
|
provideVaroTheme({ theme })
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## Weapp build-time theme
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { resolve } from 'node:path'
|
|
30
|
+
import { createVaroWeappThemePlugin } from '@varo-ui/theme/weapp-vite'
|
|
31
|
+
import { defineConfig } from 'weapp-vite/config'
|
|
32
|
+
import { theme } from './src/theme'
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [
|
|
36
|
+
createVaroWeappThemePlugin({
|
|
37
|
+
appStyle: resolve(import.meta.dirname, 'src/app.scss'),
|
|
38
|
+
theme
|
|
39
|
+
})
|
|
40
|
+
]
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The plugin appends `page { --varo-ui-* }` declarations to the app stylesheet.
|
|
45
|
+
|
|
46
|
+
## Weapp runtime theme switching
|
|
47
|
+
|
|
48
|
+
Install the editable provider:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm dlx @varo-ui/cli add --target weapp-vite components/theme-provider
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Bind a reactive theme at each page root:
|
|
55
|
+
|
|
56
|
+
```vue
|
|
57
|
+
<script setup lang="ts">
|
|
58
|
+
import { createTheme } from '@varo-ui/theme/weapp'
|
|
59
|
+
import { shallowRef } from 'wevu'
|
|
60
|
+
import VThemeProvider from '@/components/ui/v-theme-provider.vue'
|
|
61
|
+
|
|
62
|
+
const activeTheme = shallowRef(createTheme({
|
|
63
|
+
primary: '#3b82f6',
|
|
64
|
+
success: '#16a34a',
|
|
65
|
+
warning: '#d97706',
|
|
66
|
+
error: '#dc2626',
|
|
67
|
+
neutral: '#0f172a'
|
|
68
|
+
}))
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<template>
|
|
72
|
+
<VThemeProvider :theme="activeTheme">
|
|
73
|
+
<view>Page content</view>
|
|
74
|
+
</VThemeProvider>
|
|
75
|
+
</template>
|
|
76
|
+
```
|
|
77
|
+
|
|
26
78
|
[Theme documentation](https://daguanren21.github.io/Varo/guide/theme) · [Repository](https://github.com/daguanren21/Varo)
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-C3jlRHjz.d.mts","names":[],"sources":["../src/types.ts","../src/css.ts"],"mappings":";UAAiB,SAAA;EACf,OAAA;EACA,OAAA;EACA,OAAA;EACA,KAAA;EACA,OAAA;AAAA;AAAA,UAGe,YAAA;EACf,OAAA,EAAS,MAAA;EACT,OAAA,EAAS,MAAA;EACT,OAAA,EAAS,MAAA;EACT,OAAA,EAAS,MAAA;EACT,KAAA,EAAO,MAAA;AAAA;AAAA,UAGQ,cAAA;EACf,QAAA;EACA,SAAA;EACA,WAAA;EACA,eAAA;EACA,UAAA;EACA,YAAA;EACA,WAAA;EACA,YAAA;EACA,UAAA;AAAA;AAAA,UAGe,eAAA;EACf,MAAA;IACE,YAAA;IACA,QAAA;IACA,QAAA;IACA,QAAA;EAAA;EAEF,MAAA;IACE,YAAA;IACA,YAAA;EAAA;EAEF,KAAA;IACE,YAAA;IACA,QAAA;IACA,QAAA;IACA,QAAA;EAAA;AAAA;AAAA,UAIa,eAAA;EACf,IAAA,EAAM,SAAA;EACN,OAAA,EAAS,YAAA;EACT,QAAA,EAAU,cAAA;EACV,UAAA,EAAY,eAAA;AAAA;AAAA,UAGG,cAAA;EACf,QAAA,GAAW,OAAA,CAAQ,cAAA;EACnB,UAAA,GAAa,OAAA;IACX,MAAA,EAAQ,OAAA,CAAQ,eAAA;IAChB,MAAA,EAAQ,OAAA,CAAQ,eAAA;IAChB,KAAA,EAAO,OAAA,CAAQ,eAAA;EAAA;AAAA;;;UCzDF,iBAAA;EACf,cAAA;EACA,mBAAA;EACA,yBAAA;EACA,gBAAA;EACA,sBAAA;EACA,kBAAA;EACA,yBAAA;EACA,mBAAA;EACA,8BAAA;EACA,mBAAA;EACA,mBAAA;EACA,kBAAA;EACA,kBAAA;EACA,qBAAA;EACA,qBAAA;EACA,qBAAA;EACA,gBAAA;EAAA,CACC,IAAA;AAAA;AAAA,KAGS,yBAAA,GAA4B,OAAO,CAAC,iBAAA;AAAA,iBAkBhC,uBAAA,CACd,KAAA,EAAO,eAAA,EACP,SAAA,GAAW,yBAAA,GACV,iBAAA;AAAA,iBAuBa,uBAAA,CAAwB,QAAA,UAAkB,SAAA,EAAW,iBAAiB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,64 +1,7 @@
|
|
|
1
|
+
import { a as ComponentTokens, c as ThemeOverrides, i as renderThemeCssVariables, l as ThemePalette, n as ThemeCssVariables, o as SemanticTokens, r as createThemeCssVariables, s as ThemeDefinition, t as ThemeCssVariableOverrides, u as ThemeSeed } from "./css-C3jlRHjz.mjs";
|
|
2
|
+
import { a as mergeThemeOverrides, i as createTheme, n as createPalette, r as createSemanticTokens, t as createComponentTokens } from "./theme-DwYvwHOu.mjs";
|
|
1
3
|
import { App } from "vue";
|
|
2
4
|
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
interface ThemeSeed {
|
|
5
|
-
primary: string;
|
|
6
|
-
success: string;
|
|
7
|
-
warning: string;
|
|
8
|
-
error: string;
|
|
9
|
-
neutral: string;
|
|
10
|
-
}
|
|
11
|
-
interface ThemePalette {
|
|
12
|
-
primary: Record<string, string>;
|
|
13
|
-
neutral: Record<string, string>;
|
|
14
|
-
success: Record<string, string>;
|
|
15
|
-
warning: Record<string, string>;
|
|
16
|
-
error: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
interface SemanticTokens {
|
|
19
|
-
textBase: string;
|
|
20
|
-
textMuted: string;
|
|
21
|
-
surfaceBase: string;
|
|
22
|
-
surfaceElevated: string;
|
|
23
|
-
borderBase: string;
|
|
24
|
-
borderStrong: string;
|
|
25
|
-
primaryBase: string;
|
|
26
|
-
primaryHover: string;
|
|
27
|
-
dangerBase: string;
|
|
28
|
-
}
|
|
29
|
-
interface ComponentTokens {
|
|
30
|
-
button: {
|
|
31
|
-
borderRadius: string;
|
|
32
|
-
heightSm: string;
|
|
33
|
-
heightMd: string;
|
|
34
|
-
heightLg: string;
|
|
35
|
-
};
|
|
36
|
-
dialog: {
|
|
37
|
-
borderRadius: string;
|
|
38
|
-
overlayColor: string;
|
|
39
|
-
};
|
|
40
|
-
input: {
|
|
41
|
-
borderRadius: string;
|
|
42
|
-
heightSm: string;
|
|
43
|
-
heightMd: string;
|
|
44
|
-
heightLg: string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
interface ThemeDefinition {
|
|
48
|
-
seed: ThemeSeed;
|
|
49
|
-
palette: ThemePalette;
|
|
50
|
-
semantic: SemanticTokens;
|
|
51
|
-
components: ComponentTokens;
|
|
52
|
-
}
|
|
53
|
-
interface ThemeOverrides {
|
|
54
|
-
semantic?: Partial<SemanticTokens>;
|
|
55
|
-
components?: Partial<{
|
|
56
|
-
button: Partial<ComponentTokens['button']>;
|
|
57
|
-
dialog: Partial<ComponentTokens['dialog']>;
|
|
58
|
-
input: Partial<ComponentTokens['input']>;
|
|
59
|
-
}>;
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
5
|
//#region src/types-runtime.d.ts
|
|
63
6
|
interface ThemeConfig {
|
|
64
7
|
theme: ThemeDefinition;
|
|
@@ -69,15 +12,8 @@ interface ThemeConfig {
|
|
|
69
12
|
declare function provideVaroTheme(config: ThemeConfig): void;
|
|
70
13
|
declare function useVaroTheme(): import("vue").ComputedRef<ThemeDefinition>;
|
|
71
14
|
declare const VaroConfigProvider: {
|
|
72
|
-
install(app: App, config
|
|
15
|
+
install(app: App, config?: ThemeConfig): void;
|
|
73
16
|
};
|
|
74
17
|
//#endregion
|
|
75
|
-
|
|
76
|
-
declare function createPalette(seed: ThemeSeed): ThemePalette;
|
|
77
|
-
declare function createSemanticTokens(palette: ThemePalette): SemanticTokens;
|
|
78
|
-
declare function createComponentTokens(semantic: SemanticTokens): ComponentTokens;
|
|
79
|
-
declare function createTheme(seed: ThemeSeed): ThemeDefinition;
|
|
80
|
-
declare function mergeThemeOverrides(theme: ThemeDefinition, overrides?: ThemeOverrides): ThemeDefinition;
|
|
81
|
-
//#endregion
|
|
82
|
-
export { ComponentTokens, SemanticTokens, ThemeConfig, ThemeDefinition, ThemeOverrides, ThemePalette, ThemeSeed, VaroConfigProvider, createComponentTokens, createPalette, createSemanticTokens, createTheme, mergeThemeOverrides, provideVaroTheme, useVaroTheme };
|
|
18
|
+
export { ComponentTokens, SemanticTokens, ThemeConfig, ThemeCssVariableOverrides, ThemeCssVariables, ThemeDefinition, ThemeOverrides, ThemePalette, ThemeSeed, VaroConfigProvider, createComponentTokens, createPalette, createSemanticTokens, createTheme, createThemeCssVariables, mergeThemeOverrides, provideVaroTheme, renderThemeCssVariables, useVaroTheme };
|
|
83
19
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types-runtime.ts","../src/provider.ts"],"mappings":";;;;;UAEiB,WAAA;EACf,KAAA,EAAO,eAAA;EACP,SAAA,GAAY,cAAc;AAAA;;;iBCIZ,gBAAA,CAAiB,MAAmB,EAAX,WAAW;AAAA,iBAIpC,YAAA,kBAAY,WAAA,CAAA,eAAA;AAAA,cAkBf,kBAAA;eACE,GAAA,EAAG,MAAA,GAAW,WAAW;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,92 +1,5 @@
|
|
|
1
|
+
import { a as mergeThemeOverrides, i as createTheme, n as createPalette, o as createThemeCssVariables, r as createSemanticTokens, s as renderThemeCssVariables, t as createComponentTokens } from "./theme-Dr7X-VMu.mjs";
|
|
1
2
|
import { computed, inject, provide } from "vue";
|
|
2
|
-
//#region src/theme.ts
|
|
3
|
-
function createPalette(seed) {
|
|
4
|
-
return {
|
|
5
|
-
primary: {
|
|
6
|
-
"50": "#eff6ff",
|
|
7
|
-
"500": seed.primary,
|
|
8
|
-
"600": seed.primary
|
|
9
|
-
},
|
|
10
|
-
neutral: {
|
|
11
|
-
"0": "#ffffff",
|
|
12
|
-
"50": "#f8fafc",
|
|
13
|
-
"200": "#e2e8f0",
|
|
14
|
-
"500": "#64748b",
|
|
15
|
-
"900": "#0f172a",
|
|
16
|
-
"1000": seed.neutral
|
|
17
|
-
},
|
|
18
|
-
success: { "500": seed.success },
|
|
19
|
-
warning: { "500": seed.warning },
|
|
20
|
-
error: { "500": seed.error }
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function createSemanticTokens(palette) {
|
|
24
|
-
return {
|
|
25
|
-
textBase: palette.neutral["1000"],
|
|
26
|
-
textMuted: palette.neutral["500"],
|
|
27
|
-
surfaceBase: palette.neutral["0"],
|
|
28
|
-
surfaceElevated: palette.neutral["50"],
|
|
29
|
-
borderBase: palette.neutral["200"],
|
|
30
|
-
borderStrong: palette.neutral["900"],
|
|
31
|
-
primaryBase: palette.primary["500"],
|
|
32
|
-
primaryHover: palette.primary["600"],
|
|
33
|
-
dangerBase: palette.error["500"]
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function createComponentTokens(semantic) {
|
|
37
|
-
return {
|
|
38
|
-
button: {
|
|
39
|
-
borderRadius: "12px",
|
|
40
|
-
heightSm: "32px",
|
|
41
|
-
heightMd: "40px",
|
|
42
|
-
heightLg: "48px"
|
|
43
|
-
},
|
|
44
|
-
dialog: {
|
|
45
|
-
borderRadius: "16px",
|
|
46
|
-
overlayColor: semantic.borderStrong
|
|
47
|
-
},
|
|
48
|
-
input: {
|
|
49
|
-
borderRadius: "12px",
|
|
50
|
-
heightSm: "32px",
|
|
51
|
-
heightMd: "40px",
|
|
52
|
-
heightLg: "48px"
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function createTheme(seed) {
|
|
57
|
-
const palette = createPalette(seed);
|
|
58
|
-
const semantic = createSemanticTokens(palette);
|
|
59
|
-
return {
|
|
60
|
-
seed,
|
|
61
|
-
palette,
|
|
62
|
-
semantic,
|
|
63
|
-
components: createComponentTokens(semantic)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function mergeThemeOverrides(theme, overrides = {}) {
|
|
67
|
-
return {
|
|
68
|
-
...theme,
|
|
69
|
-
semantic: {
|
|
70
|
-
...theme.semantic,
|
|
71
|
-
...overrides.semantic
|
|
72
|
-
},
|
|
73
|
-
components: {
|
|
74
|
-
button: {
|
|
75
|
-
...theme.components.button,
|
|
76
|
-
...overrides.components?.button
|
|
77
|
-
},
|
|
78
|
-
dialog: {
|
|
79
|
-
...theme.components.dialog,
|
|
80
|
-
...overrides.components?.dialog
|
|
81
|
-
},
|
|
82
|
-
input: {
|
|
83
|
-
...theme.components.input,
|
|
84
|
-
...overrides.components?.input
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
3
|
//#region src/provider.ts
|
|
91
4
|
const ThemeKey = Symbol("varo-theme");
|
|
92
5
|
function provideVaroTheme(config) {
|
|
@@ -104,9 +17,10 @@ function useVaroTheme() {
|
|
|
104
17
|
return computed(() => config.theme);
|
|
105
18
|
}
|
|
106
19
|
const VaroConfigProvider = { install(app, config) {
|
|
20
|
+
if (!config) throw new Error("VaroConfigProvider requires a theme configuration.");
|
|
107
21
|
app.provide(ThemeKey, config);
|
|
108
22
|
} };
|
|
109
23
|
//#endregion
|
|
110
|
-
export { VaroConfigProvider, createComponentTokens, createPalette, createSemanticTokens, createTheme, mergeThemeOverrides, provideVaroTheme, useVaroTheme };
|
|
24
|
+
export { VaroConfigProvider, createComponentTokens, createPalette, createSemanticTokens, createTheme, createThemeCssVariables, mergeThemeOverrides, provideVaroTheme, renderThemeCssVariables, useVaroTheme };
|
|
111
25
|
|
|
112
26
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.ts"],"sourcesContent":["import type { App, InjectionKey, Plugin } from 'vue'\nimport type { ThemeDefinition } from './types'\nimport type { ThemeConfig } from './types-runtime'\nimport { computed, inject, provide } from 'vue'\nimport { createTheme } from './theme'\n\nconst ThemeKey: InjectionKey<ThemeConfig> = Symbol('varo-theme')\n\nexport function provideVaroTheme(config: ThemeConfig) {\n provide(ThemeKey, config)\n}\n\nexport function useVaroTheme() {\n const config = inject(ThemeKey, undefined)\n\n if (!config) {\n return computed<ThemeDefinition>(() =>\n createTheme({\n primary: '#2563eb',\n success: '#16a34a',\n warning: '#d97706',\n error: '#dc2626',\n neutral: '#0f172a',\n }),\n )\n }\n\n return computed(() => config.theme)\n}\n\nexport const VaroConfigProvider = {\n install(app: App, config?: ThemeConfig) {\n if (!config) { throw new Error('VaroConfigProvider requires a theme configuration.') }\n app.provide(ThemeKey, config)\n },\n} satisfies Plugin\n"],"mappings":";;;AAMA,MAAM,WAAsC,OAAO,YAAY;AAE/D,SAAgB,iBAAiB,QAAqB;CACpD,QAAQ,UAAU,MAAM;AAC1B;AAEA,SAAgB,eAAe;CAC7B,MAAM,SAAS,OAAO,UAAU,KAAA,CAAS;CAEzC,IAAI,CAAC,QACH,OAAO,eACL,YAAY;EACV,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;EACP,SAAS;CACX,CAAC,CACH;CAGF,OAAO,eAAe,OAAO,KAAK;AACpC;AAEA,MAAa,qBAAqB,EAChC,QAAQ,KAAU,QAAsB;CACtC,IAAI,CAAC,QAAU,MAAM,IAAI,MAAM,oDAAoD;CACnF,IAAI,QAAQ,UAAU,MAAM;AAC9B,EACF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { a as ComponentTokens, c as ThemeOverrides, l as ThemePalette, o as SemanticTokens, s as ThemeDefinition, u as ThemeSeed } from "./css-C3jlRHjz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/theme.d.ts
|
|
4
|
+
declare function createPalette(seed: ThemeSeed): ThemePalette;
|
|
5
|
+
declare function createSemanticTokens(palette: ThemePalette): SemanticTokens;
|
|
6
|
+
declare function createComponentTokens(semantic: SemanticTokens): ComponentTokens;
|
|
7
|
+
declare function createTheme(seed: ThemeSeed): ThemeDefinition;
|
|
8
|
+
declare function mergeThemeOverrides(theme: ThemeDefinition, overrides?: ThemeOverrides): ThemeDefinition;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { mergeThemeOverrides as a, createTheme as i, createPalette as n, createSemanticTokens as r, createComponentTokens as t };
|
|
11
|
+
//# sourceMappingURL=theme-DwYvwHOu.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-DwYvwHOu.d.mts","names":[],"sources":["../src/theme.ts"],"mappings":";;;iBASgB,aAAA,CAAc,IAAA,EAAM,SAAA,GAAY,YAAY;AAAA,iBA2B5C,oBAAA,CAAqB,OAAA,EAAS,YAAA,GAAe,cAAc;AAAA,iBAc3D,qBAAA,CAAsB,QAAA,EAAU,cAAA,GAAiB,eAAe;AAAA,iBAqBhE,WAAA,CAAY,IAAA,EAAM,SAAA,GAAY,eAAe;AAAA,iBAa7C,mBAAA,CAAoB,KAAA,EAAO,eAAA,EAAiB,SAAA,GAAW,cAAA,GAAsB,eAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { s as ThemeDefinition, t as ThemeCssVariableOverrides } from "./css-C3jlRHjz.mjs";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/weapp-vite.d.ts
|
|
5
|
+
interface VaroWeappThemePluginOptions {
|
|
6
|
+
appStyle: string;
|
|
7
|
+
theme: ThemeDefinition;
|
|
8
|
+
variables?: ThemeCssVariableOverrides;
|
|
9
|
+
}
|
|
10
|
+
declare function createVaroWeappThemePlugin(options: VaroWeappThemePluginOptions): Plugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { VaroWeappThemePluginOptions, createVaroWeappThemePlugin };
|
|
13
|
+
//# sourceMappingURL=weapp-vite.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weapp-vite.d.mts","names":[],"sources":["../src/weapp-vite.ts"],"mappings":";;;;UAMiB,2BAAA;EACf,QAAA;EACA,KAAA,EAAO,eAAA;EACP,SAAA,GAAY,yBAAyB;AAAA;AAAA,iBAGvB,0BAAA,CAA2B,OAAA,EAAS,2BAAA,GAA8B,MAAM"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { renderWeappThemeCss } from "./weapp.mjs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
//#region src/weapp-vite.ts
|
|
4
|
+
function createVaroWeappThemePlugin(options) {
|
|
5
|
+
const appStylePath = resolve(options.appStyle);
|
|
6
|
+
return {
|
|
7
|
+
name: "varo:weapp-theme",
|
|
8
|
+
enforce: "pre",
|
|
9
|
+
transform(source, id) {
|
|
10
|
+
if (resolve(id.split("?")[0]) !== appStylePath) return;
|
|
11
|
+
return {
|
|
12
|
+
code: `${source}\n${renderWeappThemeCss(options.theme, { variables: options.variables })}\n`,
|
|
13
|
+
map: null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createVaroWeappThemePlugin };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=weapp-vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weapp-vite.mjs","names":[],"sources":["../src/weapp-vite.ts"],"sourcesContent":["import type { Plugin } from 'vite'\nimport type { ThemeCssVariableOverrides } from './css.ts'\nimport type { ThemeDefinition } from './types.ts'\nimport { resolve } from 'node:path'\nimport { renderWeappThemeCss } from './weapp.ts'\n\nexport interface VaroWeappThemePluginOptions {\n appStyle: string\n theme: ThemeDefinition\n variables?: ThemeCssVariableOverrides\n}\n\nexport function createVaroWeappThemePlugin(options: VaroWeappThemePluginOptions): Plugin {\n const appStylePath = resolve(options.appStyle)\n\n return {\n name: 'varo:weapp-theme',\n enforce: 'pre',\n transform(source, id) {\n if (resolve(id.split('?')[0]) !== appStylePath) {\n return\n }\n\n return {\n code: `${source}\\n${renderWeappThemeCss(options.theme, { variables: options.variables })}\\n`,\n map: null,\n }\n },\n }\n}\n"],"mappings":";;;AAYA,SAAgB,2BAA2B,SAA8C;CACvF,MAAM,eAAe,QAAQ,QAAQ,QAAQ;CAE7C,OAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,QAAQ,IAAI;GACpB,IAAI,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,cAChC;GAGF,OAAO;IACL,MAAM,GAAG,OAAO,IAAI,oBAAoB,QAAQ,OAAO,EAAE,WAAW,QAAQ,UAAU,CAAC,EAAE;IACzF,KAAK;GACP;EACF;CACF;AACF"}
|
package/dist/weapp.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as ThemeCssVariables, s as ThemeDefinition, t as ThemeCssVariableOverrides } from "./css-C3jlRHjz.mjs";
|
|
2
|
+
import { a as mergeThemeOverrides, i as createTheme } from "./theme-DwYvwHOu.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/weapp.d.ts
|
|
5
|
+
interface WeappThemeCssOptions {
|
|
6
|
+
variables?: ThemeCssVariableOverrides;
|
|
7
|
+
}
|
|
8
|
+
declare function createWeappThemeStyle(theme: ThemeDefinition, options?: WeappThemeCssOptions): ThemeCssVariables;
|
|
9
|
+
declare function renderWeappThemeCss(theme: ThemeDefinition, options?: WeappThemeCssOptions): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { type ThemeCssVariableOverrides, type ThemeCssVariables, type ThemeDefinition, WeappThemeCssOptions, createTheme, createWeappThemeStyle, mergeThemeOverrides, renderWeappThemeCss };
|
|
12
|
+
//# sourceMappingURL=weapp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weapp.d.mts","names":[],"sources":["../src/weapp.ts"],"mappings":";;;;UAIiB,oBAAA;EACf,SAAA,GAAY,yBAAyB;AAAA;AAAA,iBAGvB,qBAAA,CACd,KAAA,EAAO,eAAA,EACP,OAAA,GAAS,oBAAA,GACR,iBAAA;AAAA,iBAIa,mBAAA,CACd,KAAA,EAAO,eAAA,EACP,OAAA,GAAS,oBAAyB"}
|
package/dist/weapp.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as mergeThemeOverrides, i as createTheme, o as createThemeCssVariables, s as renderThemeCssVariables } from "./theme-Dr7X-VMu.mjs";
|
|
2
|
+
//#region src/weapp.ts
|
|
3
|
+
function createWeappThemeStyle(theme, options = {}) {
|
|
4
|
+
return createThemeCssVariables(theme, options.variables);
|
|
5
|
+
}
|
|
6
|
+
function renderWeappThemeCss(theme, options = {}) {
|
|
7
|
+
return renderThemeCssVariables("page", createWeappThemeStyle(theme, options));
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { createTheme, createWeappThemeStyle, mergeThemeOverrides, renderWeappThemeCss };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=weapp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weapp.mjs","names":[],"sources":["../src/weapp.ts"],"sourcesContent":["import type { ThemeCssVariableOverrides, ThemeCssVariables } from './css.ts'\nimport type { ThemeDefinition } from './types.ts'\nimport { createThemeCssVariables, renderThemeCssVariables } from './css.ts'\n\nexport interface WeappThemeCssOptions {\n variables?: ThemeCssVariableOverrides\n}\n\nexport function createWeappThemeStyle(\n theme: ThemeDefinition,\n options: WeappThemeCssOptions = {},\n): ThemeCssVariables {\n return createThemeCssVariables(theme, options.variables)\n}\n\nexport function renderWeappThemeCss(\n theme: ThemeDefinition,\n options: WeappThemeCssOptions = {},\n): string {\n return renderThemeCssVariables('page', createWeappThemeStyle(theme, options))\n}\n\nexport type { ThemeCssVariableOverrides, ThemeCssVariables } from './css.ts'\nexport { createTheme, mergeThemeOverrides } from './theme.ts'\nexport type { ThemeDefinition } from './types.ts'\n"],"mappings":";;AAQA,SAAgB,sBACd,OACA,UAAgC,CAAC,GACd;CACnB,OAAO,wBAAwB,OAAO,QAAQ,SAAS;AACzD;AAEA,SAAgB,oBACd,OACA,UAAgC,CAAC,GACzB;CACR,OAAO,wBAAwB,QAAQ,sBAAsB,OAAO,OAAO,CAAC;AAC9E"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varo-ui/theme",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"description": "Token-driven themes and providers for Varo H5 and mini-program components.",
|
|
6
6
|
"author": "daguanren21 <1363917353@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,9 +24,29 @@
|
|
|
24
24
|
"types": "./dist/index.d.mts",
|
|
25
25
|
"import": "./dist/index.mjs"
|
|
26
26
|
},
|
|
27
|
+
"./weapp": {
|
|
28
|
+
"types": "./dist/weapp.d.mts",
|
|
29
|
+
"import": "./dist/weapp.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./weapp-vite": {
|
|
32
|
+
"types": "./dist/weapp-vite.d.mts",
|
|
33
|
+
"import": "./dist/weapp-vite.mjs"
|
|
34
|
+
},
|
|
27
35
|
"./source": {
|
|
28
36
|
"types": "./src/index.ts",
|
|
29
37
|
"import": "./src/index.ts"
|
|
38
|
+
},
|
|
39
|
+
"./source/theme": {
|
|
40
|
+
"types": "./src/theme.ts",
|
|
41
|
+
"import": "./src/theme.ts"
|
|
42
|
+
},
|
|
43
|
+
"./source/weapp": {
|
|
44
|
+
"types": "./src/weapp.ts",
|
|
45
|
+
"import": "./src/weapp.ts"
|
|
46
|
+
},
|
|
47
|
+
"./source/weapp-vite": {
|
|
48
|
+
"types": "./src/weapp-vite.ts",
|
|
49
|
+
"import": "./src/weapp-vite.ts"
|
|
30
50
|
}
|
|
31
51
|
},
|
|
32
52
|
"main": "./dist/index.mjs",
|
|
@@ -39,6 +59,9 @@
|
|
|
39
59
|
"dependencies": {
|
|
40
60
|
"vue": "^3.5.41"
|
|
41
61
|
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"vite": "8.2.2"
|
|
64
|
+
},
|
|
42
65
|
"scripts": {
|
|
43
66
|
"build": "tsdown",
|
|
44
67
|
"clean": "rimraf dist",
|
package/src/css.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ThemeDefinition } from './types'
|
|
2
|
+
|
|
3
|
+
export interface ThemeCssVariables {
|
|
4
|
+
'--varo-ui-bg': string
|
|
5
|
+
'--varo-ui-surface': string
|
|
6
|
+
'--varo-ui-surface-muted': string
|
|
7
|
+
'--varo-ui-text': string
|
|
8
|
+
'--varo-ui-text-muted': string
|
|
9
|
+
'--varo-ui-border': string
|
|
10
|
+
'--varo-ui-border-strong': string
|
|
11
|
+
'--varo-ui-primary': string
|
|
12
|
+
'--varo-ui-primary-foreground': string
|
|
13
|
+
'--varo-ui-success': string
|
|
14
|
+
'--varo-ui-warning': string
|
|
15
|
+
'--varo-ui-danger': string
|
|
16
|
+
'--varo-ui-radius': string
|
|
17
|
+
'--varo-ui-radius-sm': string
|
|
18
|
+
'--varo-ui-shadow-sm': string
|
|
19
|
+
'--varo-ui-shadow-md': string
|
|
20
|
+
'--varo-ui-ring': string
|
|
21
|
+
[name: `--${string}`]: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ThemeCssVariableOverrides = Partial<ThemeCssVariables>
|
|
25
|
+
|
|
26
|
+
function colorWithAlpha(color: string, alpha: number): string {
|
|
27
|
+
const value = color.slice(1)
|
|
28
|
+
const normalized = value.length === 3
|
|
29
|
+
? value.split('').map(part => `${part}${part}`).join('')
|
|
30
|
+
: value
|
|
31
|
+
|
|
32
|
+
if (!color.startsWith('#') || !/^[\da-f]{6}$/i.test(normalized)) {
|
|
33
|
+
return color
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const red = Number.parseInt(normalized.slice(0, 2), 16)
|
|
37
|
+
const green = Number.parseInt(normalized.slice(2, 4), 16)
|
|
38
|
+
const blue = Number.parseInt(normalized.slice(4, 6), 16)
|
|
39
|
+
return `rgb(${red} ${green} ${blue} / ${alpha}%)`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createThemeCssVariables(
|
|
43
|
+
theme: ThemeDefinition,
|
|
44
|
+
overrides: ThemeCssVariableOverrides = {},
|
|
45
|
+
): ThemeCssVariables {
|
|
46
|
+
return {
|
|
47
|
+
'--varo-ui-bg': theme.semantic.surfaceElevated,
|
|
48
|
+
'--varo-ui-surface': theme.semantic.surfaceBase,
|
|
49
|
+
'--varo-ui-surface-muted': theme.palette.neutral['50'],
|
|
50
|
+
'--varo-ui-text': theme.semantic.textBase,
|
|
51
|
+
'--varo-ui-text-muted': theme.semantic.textMuted,
|
|
52
|
+
'--varo-ui-border': theme.semantic.borderBase,
|
|
53
|
+
'--varo-ui-border-strong': theme.semantic.borderStrong,
|
|
54
|
+
'--varo-ui-primary': theme.semantic.primaryBase,
|
|
55
|
+
'--varo-ui-primary-foreground': theme.palette.neutral['0'],
|
|
56
|
+
'--varo-ui-success': theme.seed.success,
|
|
57
|
+
'--varo-ui-warning': theme.seed.warning,
|
|
58
|
+
'--varo-ui-danger': theme.semantic.dangerBase,
|
|
59
|
+
'--varo-ui-radius': theme.components.button.borderRadius,
|
|
60
|
+
'--varo-ui-radius-sm': theme.components.input.borderRadius,
|
|
61
|
+
'--varo-ui-shadow-sm': '0 1px 2px rgb(24 36 51 / 6%)',
|
|
62
|
+
'--varo-ui-shadow-md': '0 14px 34px rgb(24 36 51 / 12%)',
|
|
63
|
+
'--varo-ui-ring': colorWithAlpha(theme.semantic.primaryBase, 16),
|
|
64
|
+
...overrides,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function renderThemeCssVariables(selector: string, variables: ThemeCssVariables): string {
|
|
69
|
+
const normalizedSelector = selector.trim()
|
|
70
|
+
if (!normalizedSelector || /[{}]/.test(normalizedSelector)) {
|
|
71
|
+
throw new Error(`Invalid theme CSS selector: ${selector}`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const declarations = Object.entries(variables).map(([name, value]) => {
|
|
75
|
+
if (/[;{}\r\n]/.test(value)) {
|
|
76
|
+
throw new Error(`Invalid theme CSS variable value for ${name}`)
|
|
77
|
+
}
|
|
78
|
+
return ` ${name}: ${value};`
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return `${normalizedSelector} {\n${declarations.join('\n')}\n}`
|
|
82
|
+
}
|
package/src/index.ts
CHANGED
package/src/provider.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createTheme } from './theme'
|
|
1
|
+
import type { App, InjectionKey, Plugin } from 'vue'
|
|
3
2
|
import type { ThemeDefinition } from './types'
|
|
4
3
|
import type { ThemeConfig } from './types-runtime'
|
|
4
|
+
import { computed, inject, provide } from 'vue'
|
|
5
|
+
import { createTheme } from './theme'
|
|
5
6
|
|
|
6
7
|
const ThemeKey: InjectionKey<ThemeConfig> = Symbol('varo-theme')
|
|
7
8
|
|
|
@@ -19,8 +20,8 @@ export function useVaroTheme() {
|
|
|
19
20
|
success: '#16a34a',
|
|
20
21
|
warning: '#d97706',
|
|
21
22
|
error: '#dc2626',
|
|
22
|
-
neutral: '#0f172a'
|
|
23
|
-
})
|
|
23
|
+
neutral: '#0f172a',
|
|
24
|
+
}),
|
|
24
25
|
)
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -28,7 +29,8 @@ export function useVaroTheme() {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export const VaroConfigProvider = {
|
|
31
|
-
install(app: App, config
|
|
32
|
+
install(app: App, config?: ThemeConfig) {
|
|
33
|
+
if (!config) { throw new Error('VaroConfigProvider requires a theme configuration.') }
|
|
32
34
|
app.provide(ThemeKey, config)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
+
},
|
|
36
|
+
} satisfies Plugin
|
|
@@ -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,25 @@
|
|
|
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 { createTheme, mergeThemeOverrides } from './theme.ts'
|
|
25
|
+
export type { ThemeDefinition } from './types.ts'
|