@varo-ui/theme 1.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/dist/index.d.mts +83 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +112 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +51 -0
- package/src/index.ts +4 -0
- package/src/provider.ts +34 -0
- package/src/theme.ts +107 -0
- package/src/types-runtime.ts +6 -0
- package/src/types.ts +62 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { App } from "vue";
|
|
2
|
+
|
|
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
|
+
//#region src/types-runtime.d.ts
|
|
63
|
+
interface ThemeConfig {
|
|
64
|
+
theme: ThemeDefinition;
|
|
65
|
+
overrides?: ThemeOverrides;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/provider.d.ts
|
|
69
|
+
declare function provideVaroTheme(config: ThemeConfig): void;
|
|
70
|
+
declare function useVaroTheme(): import("vue").ComputedRef<ThemeDefinition>;
|
|
71
|
+
declare const VaroConfigProvider: {
|
|
72
|
+
install(app: App, config: ThemeConfig): void;
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/theme.d.ts
|
|
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 };
|
|
83
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/types-runtime.ts","../src/provider.ts","../src/theme.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,WAAA;EACf,KAAA,EAAO,eAAA;EACP,SAAA,GAAY,cAAc;AAAA;;;iBCGZ,gBAAA,CAAiB,MAAmB,EAAX,WAAW;AAAA,iBAIpC,YAAA,kBAAY,WAAA,CAAA,eAAA;AAAA,cAkBf,kBAAA;eACE,GAAA,EAAG,MAAA,EAAU,WAAW;AAAA;;;iBCrBvB,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"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
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
|
+
//#region src/provider.ts
|
|
91
|
+
const ThemeKey = Symbol("varo-theme");
|
|
92
|
+
function provideVaroTheme(config) {
|
|
93
|
+
provide(ThemeKey, config);
|
|
94
|
+
}
|
|
95
|
+
function useVaroTheme() {
|
|
96
|
+
const config = inject(ThemeKey, void 0);
|
|
97
|
+
if (!config) return computed(() => createTheme({
|
|
98
|
+
primary: "#2563eb",
|
|
99
|
+
success: "#16a34a",
|
|
100
|
+
warning: "#d97706",
|
|
101
|
+
error: "#dc2626",
|
|
102
|
+
neutral: "#0f172a"
|
|
103
|
+
}));
|
|
104
|
+
return computed(() => config.theme);
|
|
105
|
+
}
|
|
106
|
+
const VaroConfigProvider = { install(app, config) {
|
|
107
|
+
app.provide(ThemeKey, config);
|
|
108
|
+
} };
|
|
109
|
+
//#endregion
|
|
110
|
+
export { VaroConfigProvider, createComponentTokens, createPalette, createSemanticTokens, createTheme, mergeThemeOverrides, provideVaroTheme, useVaroTheme };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/theme.ts","../src/provider.ts"],"sourcesContent":["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","import { computed, inject, provide, type App, type InjectionKey } from 'vue'\nimport { createTheme } from './theme'\nimport type { ThemeDefinition } from './types'\nimport type { ThemeConfig } from './types-runtime'\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 app.provide(ThemeKey, config)\n }\n}\n"],"mappings":";;AASA,SAAgB,cAAc,MAA+B;CAC3D,OAAO;EACL,SAAS;GACP,MAAM;GACN,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;EACA,SAAS;GACP,KAAK;GACL,MAAM;GACN,OAAO;GACP,OAAO;GACP,OAAO;GACP,QAAQ,KAAK;EACf;EACA,SAAS,EACP,OAAO,KAAK,QACd;EACA,SAAS,EACP,OAAO,KAAK,QACd;EACA,OAAO,EACL,OAAO,KAAK,MACd;CACF;AACF;AAEA,SAAgB,qBAAqB,SAAuC;CAC1E,OAAO;EACL,UAAU,QAAQ,QAAQ;EAC1B,WAAW,QAAQ,QAAQ;EAC3B,aAAa,QAAQ,QAAQ;EAC7B,iBAAiB,QAAQ,QAAQ;EACjC,YAAY,QAAQ,QAAQ;EAC5B,cAAc,QAAQ,QAAQ;EAC9B,aAAa,QAAQ,QAAQ;EAC7B,cAAc,QAAQ,QAAQ;EAC9B,YAAY,QAAQ,MAAM;CAC5B;AACF;AAEA,SAAgB,sBAAsB,UAA2C;CAC/E,OAAO;EACL,QAAQ;GACN,cAAc;GACd,UAAU;GACV,UAAU;GACV,UAAU;EACZ;EACA,QAAQ;GACN,cAAc;GACd,cAAc,SAAS;EACzB;EACA,OAAO;GACL,cAAc;GACd,UAAU;GACV,UAAU;GACV,UAAU;EACZ;CACF;AACF;AAEA,SAAgB,YAAY,MAAkC;CAC5D,MAAM,UAAU,cAAc,IAAI;CAClC,MAAM,WAAW,qBAAqB,OAAO;CAG7C,OAAO;EACL;EACA;EACA;EACA,YANiB,sBAAsB,QAM9B;CACX;AACF;AAEA,SAAgB,oBAAoB,OAAwB,YAA4B,CAAC,GAAoB;CAC3G,OAAO;EACL,GAAG;EACH,UAAU;GACR,GAAG,MAAM;GACT,GAAG,UAAU;EACf;EACA,YAAY;GACV,QAAQ;IACN,GAAG,MAAM,WAAW;IACpB,GAAG,UAAU,YAAY;GAC3B;GACA,QAAQ;IACN,GAAG,MAAM,WAAW;IACpB,GAAG,UAAU,YAAY;GAC3B;GACA,OAAO;IACL,GAAG,MAAM,WAAW;IACpB,GAAG,UAAU,YAAY;GAC3B;EACF;CACF;AACF;;;ACrGA,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,QAAqB;CACrC,IAAI,QAAQ,UAAU,MAAM;AAC9B,EACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@varo-ui/theme",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Token-driven themes and providers for Varo H5 and mini-program components.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://daguanren21.github.io/Varo/",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/daguanren21/Varo.git",
|
|
12
|
+
"directory": "packages/theme"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.mjs",
|
|
19
|
+
"module": "./dist/index.mjs",
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./source": {
|
|
31
|
+
"types": "./src/index.ts",
|
|
32
|
+
"import": "./src/index.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"clean": "rimraf dist",
|
|
38
|
+
"dev": "tsdown --watch",
|
|
39
|
+
"lint": "echo theme lint pending",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
41
|
+
"test": "vitest run --passWithNoTests",
|
|
42
|
+
"test:e2e": "echo theme has no e2e"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"vue": "^3.5.41"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/daguanren21/Varo/issues"
|
|
49
|
+
},
|
|
50
|
+
"author": "daguanren21 <1363917353@qq.com>"
|
|
51
|
+
}
|
package/src/index.ts
ADDED
package/src/provider.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { computed, inject, provide, type App, type InjectionKey } from 'vue'
|
|
2
|
+
import { createTheme } from './theme'
|
|
3
|
+
import type { ThemeDefinition } from './types'
|
|
4
|
+
import type { ThemeConfig } from './types-runtime'
|
|
5
|
+
|
|
6
|
+
const ThemeKey: InjectionKey<ThemeConfig> = Symbol('varo-theme')
|
|
7
|
+
|
|
8
|
+
export function provideVaroTheme(config: ThemeConfig) {
|
|
9
|
+
provide(ThemeKey, config)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useVaroTheme() {
|
|
13
|
+
const config = inject(ThemeKey, undefined)
|
|
14
|
+
|
|
15
|
+
if (!config) {
|
|
16
|
+
return computed<ThemeDefinition>(() =>
|
|
17
|
+
createTheme({
|
|
18
|
+
primary: '#2563eb',
|
|
19
|
+
success: '#16a34a',
|
|
20
|
+
warning: '#d97706',
|
|
21
|
+
error: '#dc2626',
|
|
22
|
+
neutral: '#0f172a'
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return computed(() => config.theme)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const VaroConfigProvider = {
|
|
31
|
+
install(app: App, config: ThemeConfig) {
|
|
32
|
+
app.provide(ThemeKey, config)
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ComponentTokens,
|
|
3
|
+
SemanticTokens,
|
|
4
|
+
ThemeDefinition,
|
|
5
|
+
ThemeOverrides,
|
|
6
|
+
ThemePalette,
|
|
7
|
+
ThemeSeed
|
|
8
|
+
} from './types'
|
|
9
|
+
|
|
10
|
+
export function createPalette(seed: ThemeSeed): ThemePalette {
|
|
11
|
+
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
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createSemanticTokens(palette: ThemePalette): SemanticTokens {
|
|
38
|
+
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']
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createComponentTokens(semantic: SemanticTokens): ComponentTokens {
|
|
52
|
+
return {
|
|
53
|
+
button: {
|
|
54
|
+
borderRadius: '12px',
|
|
55
|
+
heightSm: '32px',
|
|
56
|
+
heightMd: '40px',
|
|
57
|
+
heightLg: '48px'
|
|
58
|
+
},
|
|
59
|
+
dialog: {
|
|
60
|
+
borderRadius: '16px',
|
|
61
|
+
overlayColor: semantic.borderStrong
|
|
62
|
+
},
|
|
63
|
+
input: {
|
|
64
|
+
borderRadius: '12px',
|
|
65
|
+
heightSm: '32px',
|
|
66
|
+
heightMd: '40px',
|
|
67
|
+
heightLg: '48px'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createTheme(seed: ThemeSeed): ThemeDefinition {
|
|
73
|
+
const palette = createPalette(seed)
|
|
74
|
+
const semantic = createSemanticTokens(palette)
|
|
75
|
+
const components = createComponentTokens(semantic)
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
seed,
|
|
79
|
+
palette,
|
|
80
|
+
semantic,
|
|
81
|
+
components
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function mergeThemeOverrides(theme: ThemeDefinition, overrides: ThemeOverrides = {}): ThemeDefinition {
|
|
86
|
+
return {
|
|
87
|
+
...theme,
|
|
88
|
+
semantic: {
|
|
89
|
+
...theme.semantic,
|
|
90
|
+
...overrides.semantic
|
|
91
|
+
},
|
|
92
|
+
components: {
|
|
93
|
+
button: {
|
|
94
|
+
...theme.components.button,
|
|
95
|
+
...overrides.components?.button
|
|
96
|
+
},
|
|
97
|
+
dialog: {
|
|
98
|
+
...theme.components.dialog,
|
|
99
|
+
...overrides.components?.dialog
|
|
100
|
+
},
|
|
101
|
+
input: {
|
|
102
|
+
...theme.components.input,
|
|
103
|
+
...overrides.components?.input
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface ThemeSeed {
|
|
2
|
+
primary: string
|
|
3
|
+
success: string
|
|
4
|
+
warning: string
|
|
5
|
+
error: string
|
|
6
|
+
neutral: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export 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
|
+
|
|
17
|
+
export interface SemanticTokens {
|
|
18
|
+
textBase: string
|
|
19
|
+
textMuted: string
|
|
20
|
+
surfaceBase: string
|
|
21
|
+
surfaceElevated: string
|
|
22
|
+
borderBase: string
|
|
23
|
+
borderStrong: string
|
|
24
|
+
primaryBase: string
|
|
25
|
+
primaryHover: string
|
|
26
|
+
dangerBase: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export 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
|
+
|
|
48
|
+
export interface ThemeDefinition {
|
|
49
|
+
seed: ThemeSeed
|
|
50
|
+
palette: ThemePalette
|
|
51
|
+
semantic: SemanticTokens
|
|
52
|
+
components: ComponentTokens
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ThemeOverrides {
|
|
56
|
+
semantic?: Partial<SemanticTokens>
|
|
57
|
+
components?: Partial<{
|
|
58
|
+
button: Partial<ComponentTokens['button']>
|
|
59
|
+
dialog: Partial<ComponentTokens['dialog']>
|
|
60
|
+
input: Partial<ComponentTokens['input']>
|
|
61
|
+
}>
|
|
62
|
+
}
|