@zc-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.
@@ -0,0 +1,185 @@
1
+ import { PaletteInput } from './color-generator';
2
+ /**
3
+ * A collection of CSS variable key-value pairs.
4
+ * Keys are CSS custom property names (e.g. '--color-zc-primary-500').
5
+ */
6
+ export interface ThemeVariables {
7
+ [cssVarName: string]: string;
8
+ }
9
+ /**
10
+ * Component-level override token map.
11
+ * Each key is a component name (e.g. 'Button'), and the value is
12
+ * a set of CSS variables scoped to that component.
13
+ *
14
+ * Supports two key formats:
15
+ * 1. **CSS variable names** (prefixed with `--`): `'--zc-button-border-radius': '8px'`
16
+ * 2. **CamelCase shorthand** (auto-prefixed): `'borderRadius': '8px'`
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * {
21
+ * Button: {
22
+ * '--zc-button-border-radius': '8px',
23
+ * '--zc-button-font-weight': '600',
24
+ * },
25
+ * Input: {
26
+ * '--zc-input-border-color': '#d9d9d9',
27
+ * },
28
+ * }
29
+ * ```
30
+ */
31
+ export interface ComponentThemeOverrides {
32
+ [componentName: string]: ThemeVariables;
33
+ }
34
+ /**
35
+ * Shorthand component override map using camelCase keys.
36
+ * Each key is converted to `--zc-{componentName}-{kebab-case-key}`.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * {
41
+ * button: { bgColor: 'red', textColor: '#fff' },
42
+ * input: { borderColor: '#d9d9d9' },
43
+ * }
44
+ * // Generates:
45
+ * // Button: { '--zc-button-bg-color': 'red', '--zc-button-text-color': '#fff' }
46
+ * // Input: { '--zc-input-border-color': '#d9d9d9' }
47
+ * ```
48
+ */
49
+ export type ComponentShorthandOverrides = {
50
+ [componentName: string]: Record<string, string>;
51
+ };
52
+ /**
53
+ * A complete theme preset.
54
+ */
55
+ export interface ThemePreset {
56
+ /** Unique name for identification */
57
+ name: string;
58
+ /** 'light' or 'dark' — determines base background and text colors */
59
+ mode: 'light' | 'dark';
60
+ /** Global CSS variables (colors, spacing, typography, etc.) */
61
+ variables: ThemeVariables;
62
+ /** Per-component CSS variable overrides */
63
+ componentOverrides?: ComponentThemeOverrides;
64
+ /** Optional metadata */
65
+ meta?: {
66
+ author?: string;
67
+ version?: string;
68
+ description?: string;
69
+ };
70
+ }
71
+ /**
72
+ * Options for creating a custom theme preset.
73
+ */
74
+ export interface CreateThemeOptions {
75
+ /** Theme name */
76
+ name?: string;
77
+ /** Color mode (default: 'light') */
78
+ mode?: 'light' | 'dark';
79
+ /**
80
+ * Brand colors — generates full 50–950 scales automatically.
81
+ * Any omitted color keeps the default.
82
+ */
83
+ brandColors?: PaletteInput;
84
+ /** Additional CSS variables to set or override */
85
+ variables?: ThemeVariables;
86
+ /**
87
+ * Per-component overrides using full CSS variable names.
88
+ * @example
89
+ * ```ts
90
+ * componentOverrides: {
91
+ * Button: { '--zc-button-border-radius': '8px' },
92
+ * }
93
+ * ```
94
+ */
95
+ componentOverrides?: ComponentThemeOverrides;
96
+ /**
97
+ * Per-component overrides using camelCase shorthand.
98
+ * Each key is auto-converted to `--zc-{component}-{kebab-case-key}`.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * components: {
103
+ * button: { bgColor: 'red', textColor: '#fff' },
104
+ * }
105
+ * // Generates: --zc-button-bg-color: red; --zc-button-text-color: #fff;
106
+ * ```
107
+ */
108
+ components?: ComponentShorthandOverrides;
109
+ /** Base on an existing preset (default: lightTheme) */
110
+ extends?: ThemePreset;
111
+ /** Metadata */
112
+ meta?: ThemePreset['meta'];
113
+ }
114
+ /**
115
+ * Convert a shorthand component override map to full CSS variable names.
116
+ *
117
+ * Keys that already start with `--` are kept as-is.
118
+ * CamelCase keys are converted to `--zc-{component}-{kebab-case}`.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * componentShorthandToCssVars('button', { bgColor: 'red', '--zc-button-font-size': '16px' })
123
+ * // => { '--zc-button-bg-color': 'red', '--zc-button-font-size': '16px' }
124
+ * ```
125
+ */
126
+ export declare function componentShorthandToCssVars(componentName: string, shorthand: Record<string, string>): ThemeVariables;
127
+ /**
128
+ * The built-in light theme preset.
129
+ * Contains all default color scales, semantic tokens, and design tokens.
130
+ *
131
+ * Accessing this returns a cached instance — do not mutate it directly.
132
+ * Use `createTheme({ extends: lightTheme, ... })` to customize.
133
+ */
134
+ export declare const lightTheme: ThemePreset;
135
+ /**
136
+ * The built-in dark theme preset.
137
+ * Contains dark-adapted color scales and semantic tokens.
138
+ */
139
+ export declare const darkTheme: ThemePreset;
140
+ /**
141
+ * Create a custom theme preset.
142
+ *
143
+ * This function lets you build a theme from brand colors with automatic
144
+ * color scale generation, while also supporting fine-grained overrides.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const purpleTheme = createTheme({
149
+ * name: 'purple-brand',
150
+ * brandColors: { primary: '#722ed1' },
151
+ * componentOverrides: {
152
+ * Button: { '--zc-button-border-radius': '8px' },
153
+ * },
154
+ * })
155
+ * ```
156
+ */
157
+ export declare function createTheme(options?: CreateThemeOptions): ThemePreset;
158
+ /**
159
+ * Merge multiple theme presets into one.
160
+ * Later presets take precedence over earlier ones.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const customDark = mergeThemes(darkTheme, brandOverride)
165
+ * ```
166
+ */
167
+ export declare function mergeThemes(...presets: ThemePreset[]): ThemePreset;
168
+ /**
169
+ * Get a specific component's override variables from a theme preset.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const buttonVars = getComponentOverrides(theme, 'Button')
174
+ * ```
175
+ */
176
+ export declare function getComponentOverrides(theme: ThemePreset, componentName: string): ThemeVariables;
177
+ /**
178
+ * Convert a theme preset's global variables to a CSS string.
179
+ *
180
+ * @param theme The theme preset
181
+ * @param selector CSS selector (default: ':root')
182
+ * @returns CSS text with variable declarations
183
+ */
184
+ export declare function themeToCssText(theme: ThemePreset, selector?: string): string;
185
+ //# sourceMappingURL=presets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":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;;OAWG;IACH,UAAU,CAAC,EAAE,2BAA2B,CAAA;IACxC,uDAAuD;IACvD,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,eAAe;IACf,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAC3B;AAyBD;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,cAAc,CAgBhB;AAwJD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,WAWxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,WAWvB,CAAA;AAkCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CA4CzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,CAuBlE;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,MAAM,GACpB,cAAc,CAEhB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,QAAQ,SAAU,GACjB,MAAM,CAMR"}
@@ -0,0 +1,162 @@
1
+ import { PaletteInput } from './color-generator';
2
+ import { ColorName } from './colors';
3
+ import { ThemePreset, ThemeVariables } from './presets';
4
+ /** Options for runtime theme application */
5
+ export interface ApplyThemeOptions {
6
+ /** Element to apply variables to (default: document.documentElement) */
7
+ target?: HTMLElement | null;
8
+ /** CSS variable prefix (default: '--color-zc') */
9
+ prefix?: string;
10
+ }
11
+ /**
12
+ * Register a theme preset by name for later use with `switchTheme()`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * registerTheme('brand', createTheme({ brandColors: { primary: '#722ed1' } }))
17
+ * registerTheme('dark', darkTheme)
18
+ *
19
+ * // Later...
20
+ * switchTheme('brand')
21
+ * switchTheme('dark')
22
+ * ```
23
+ */
24
+ export declare function registerTheme(name: string, preset: ThemePreset): void;
25
+ /**
26
+ * Unregister a theme preset.
27
+ */
28
+ export declare function unregisterTheme(name: string): void;
29
+ /**
30
+ * Get a registered theme preset by name.
31
+ */
32
+ export declare function getRegisteredTheme(name: string): ThemePreset | undefined;
33
+ /**
34
+ * List all registered theme names.
35
+ */
36
+ export declare function listRegisteredThemes(): string[];
37
+ /**
38
+ * Switch to a previously registered theme by name.
39
+ *
40
+ * @throws Error if the theme is not registered
41
+ */
42
+ export declare function switchTheme(name: string, options?: ApplyThemeOptions): void;
43
+ /**
44
+ * Get the name of the currently applied theme (if set via switchTheme).
45
+ */
46
+ export declare function getCurrentThemeName(): string | null;
47
+ /**
48
+ * Apply a complete theme preset to the document.
49
+ *
50
+ * Sets all CSS variables from the preset on the target element
51
+ * and toggles the dark mode class.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { applyTheme, darkTheme } from '@zc-ui/theme'
56
+ * applyTheme(darkTheme)
57
+ * ```
58
+ */
59
+ export declare function applyTheme(preset: ThemePreset, options?: ApplyThemeOptions): void;
60
+ /**
61
+ * Set a single brand color at runtime.
62
+ * Automatically generates the full 50–950 color scale.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * setBrandColor('primary', '#722ed1')
67
+ * setBrandColor('danger', '#ff4d4f')
68
+ * ```
69
+ */
70
+ export declare function setBrandColor(name: ColorName, hex: string, options?: ApplyThemeOptions): void;
71
+ /**
72
+ * Set multiple brand colors at runtime.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * setBrandColors({
77
+ * primary: '#722ed1',
78
+ * success: '#52c41a',
79
+ * danger: '#ff4d4f',
80
+ * })
81
+ * ```
82
+ */
83
+ export declare function setBrandColors(palette: PaletteInput, options?: ApplyThemeOptions): void;
84
+ /**
85
+ * Set or update a single CSS variable at runtime.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * setThemeVariable('--color-zc-primary-500', '#722ed1')
90
+ * setThemeVariable('--radius-zc-base', '8px')
91
+ * ```
92
+ */
93
+ export declare function setThemeVariable(name: string, value: string, options?: ApplyThemeOptions): void;
94
+ /**
95
+ * Remove a CSS variable that was set at runtime.
96
+ */
97
+ export declare function removeThemeVariable(name: string, options?: ApplyThemeOptions): void;
98
+ /**
99
+ * Apply or remove the dark mode class on an element.
100
+ *
101
+ * @param isDark Whether to enable dark mode
102
+ * @param target Target element (default: document.documentElement)
103
+ */
104
+ export declare function applyDarkMode(isDark: boolean, target?: HTMLElement | null): void;
105
+ /**
106
+ * Remove all runtime theme overrides from an element.
107
+ * Cleans up any CSS variables with the specified prefix.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * clearThemeOverrides() // removes all --color-zc-* inline overrides
112
+ * ```
113
+ */
114
+ export declare function clearThemeOverrides(options?: ApplyThemeOptions & {
115
+ prefix?: string;
116
+ }): void;
117
+ /**
118
+ * Apply a component-level override to a specific element.
119
+ *
120
+ * This is used internally by ConfigProvider to scope overrides,
121
+ * but can also be called directly.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * applyComponentOverrides(document.querySelector('.my-section'), 'Button', {
126
+ * '--zc-button-border-radius': '8px',
127
+ * })
128
+ * ```
129
+ */
130
+ export declare function applyComponentOverrides(element: HTMLElement, componentName: string, overrides: ThemeVariables): void;
131
+ /**
132
+ * Remove component-level overrides from an element.
133
+ */
134
+ export declare function removeComponentOverrides(element: HTMLElement, componentName: string, overrides: ThemeVariables): void;
135
+ /**
136
+ * Create a reactive theme controller.
137
+ * Useful for Vue components that need reactive theme switching.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const controller = createThemeController()
142
+ * controller.apply(darkTheme)
143
+ * controller.toggleDark()
144
+ * controller.setBrandColor('primary', '#722ed1')
145
+ */
146
+ export declare function createThemeController(options?: ApplyThemeOptions): {
147
+ /** Get the currently applied preset (null if none) */
148
+ readonly current: ThemePreset | null;
149
+ /** Apply a full theme preset */
150
+ apply(preset: ThemePreset): void;
151
+ /** Set a single brand color */
152
+ setBrandColor(name: ColorName, hex: string): void;
153
+ /** Set multiple brand colors */
154
+ setBrandColors(palette: PaletteInput): void;
155
+ /** Set a single CSS variable */
156
+ setVariable(name: string, value: string): void;
157
+ /** Toggle dark mode */
158
+ toggleDark(): boolean;
159
+ /** Clear all runtime overrides */
160
+ clear(): void;
161
+ };
162
+ //# sourceMappingURL=runtime-theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-theme.d.ts","sourceRoot":"","sources":["../../src/runtime-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAM5D,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC3B,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAsBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAErE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGlD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAExE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAS3E;AAED;;GAEG;AACH,wBAAg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CAAC,OAAO,CAAC,EAAE,iBAAiB;IAI7D,sDAAsD;sBACvC,WAAW,GAAG,IAAI;IAIjC,gCAAgC;kBAClB,WAAW;IAKzB,+BAA+B;wBACX,SAAS,OAAO,MAAM;IAI1C,gCAAgC;4BACR,YAAY;IAIpC,gCAAgC;sBACd,MAAM,SAAS,MAAM;IAIvC,uBAAuB;kBACT,OAAO;IAQrB,kCAAkC;;EAMrC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@zc-ui/theme",
3
+ "version": "1.0.0",
4
+ "description": "ZC UI theme tokens and design variables",
5
+ "license": "MIT",
6
+ "author": "ZC UI Team",
7
+ "homepage": "https://zc-ui.github.io/zc-ui",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zc-ui/zc-ui.git",
11
+ "directory": "packages/theme"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/zc-ui/zc-ui/issues"
15
+ },
16
+ "keywords": [
17
+ "vue",
18
+ "ui",
19
+ "theme",
20
+ "design-tokens",
21
+ "css-variables",
22
+ "zc-ui"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/types/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/index.mjs",
32
+ "require": "./dist/index.cjs"
33
+ },
34
+ "./styles": "./src/styles.css"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src/styles.css"
39
+ ],
40
+ "sideEffects": [
41
+ "**/*.css"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "registry": "https://registry.npmjs.org"
46
+ },
47
+ "scripts": {
48
+ "build": "vite build",
49
+ "typecheck": "vue-tsc --noEmit -p tsconfig.json"
50
+ }
51
+ }