@zl-ui-kit/theme 0.0.0-stage → 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vik05
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @zl-ui-kit/theme
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ZL UI 主题引擎(决策 D7):内置 5 套主题(light/dark/red-light/red-dark/blue),`body[data-theme]` 作用域 + `--zl-*`(业务层)/`--el-*`(Element Plus 层)变量体系,支持运行时自定义主题。
4
+
5
+ ## 快速上手
6
+
7
+ ```ts
8
+ import '@zl-ui-kit/theme/themes.css' // 或按需 '@zl-ui-kit/theme/light'
9
+ import { setTheme, defineTheme, useTheme } from '@zl-ui-kit/theme'
10
+
11
+ setTheme('dark')
12
+
13
+ defineTheme({ name: 'brand', base: 'light', colors: { primary: '#722ED1' }, apply: true })
14
+ ```
15
+
16
+ **自定义主题完整指南见根目录 `docs/主题定制指南.md`**(L1 变量直覆 / L2 运行时 defineTheme / L3 构建时生成)。
17
+
18
+ ## 入口
19
+
20
+ | 入口 | 内容 |
21
+ | --- | --- |
22
+ | `.` | 运行时 API(defineTheme/setTheme/useTheme/mix/generateElShades)+ 常量 |
23
+ | `/light` `/dark` `/red-light` `/red-dark` `/blue` `/themes.css` | 每主题/合集预编译 CSS(变量 + reset + overrides) |
24
+ | `/scss`(及 `/scss/*.scss`) | SCSS 工具(colorForEach/colorGradient/theme mixin/mapGet) |
25
+ | `/assets/*` | 主题背景图 |
26
+
27
+ ## 本地调试
28
+
29
+ - 改 `_json/*.json`(主题 token)→ `pnpm --filter @zl-ui-kit/theme gen` → playground `/theme` 页刷新
30
+ - `pnpm build` = gen + tsup;themegen 产物在 `src/generated/`(勿手改)
31
+
32
+ 详见 `docs/调试指南.md`;发布见 `docs/发布流程.md`。
@@ -0,0 +1,86 @@
1
+ import { ComputedRef } from 'vue';
2
+
3
+ declare const COLOR_TYPES: readonly ["primary", "success", "warning", "danger", "bg", "blue", "border", "cyan", "danger", "fill", "gold", "gray", "green", "lime", "link", "magenta", "modo", "neutral", "orange", "orangered", "pinkpurple", "primary", "purple", "red", "success", "text", "warning", "yellow"];
4
+ type ColorType = typeof COLOR_TYPES[number];
5
+
6
+ /**
7
+ * @zl-ui-kit/theme 运行时 API(需求 §7.2.3,D7)
8
+ * L2:defineTheme 运行时定义主题 + setTheme/getTheme/useTheme 切换(可选持久化)
9
+ * 自定义主题与内置主题变量完全同构(--zl-* + --el-*),components 无差别渲染
10
+ */
11
+
12
+ /** 各主题解析后的 token 值表(构建期由 themegen 生成) */
13
+ declare const themesData: Record<string, Record<string, string>>;
14
+ /** 内置主题清单(数据源与 generated/constants.ts 一致) */
15
+ declare const THEMES: ThemeName[];
16
+ type ThemeName = string;
17
+ interface DefineThemeColors {
18
+ /** 主色(EP primary + --zl-primary-6 联动派生) */
19
+ primary?: string;
20
+ success?: string;
21
+ warning?: string;
22
+ danger?: string;
23
+ info?: string;
24
+ /** 页面底色(覆盖 --zl-bg-1..5 / --el-bg-*) */
25
+ bg?: string;
26
+ }
27
+ interface DefineThemeOptions {
28
+ /** 主题名(切换时使用) */
29
+ name: string;
30
+ /** 以哪套内置主题为基线(默认 'light'),未指定的 token 全部继承 */
31
+ base?: string;
32
+ /** 少量语义色定制,其余自动派生 */
33
+ colors?: DefineThemeColors;
34
+ /** 任意 token 覆盖(键为原始 token 名,如 color-text-1 / color-modo-6) */
35
+ tokens?: Record<string, string>;
36
+ /** 是否立即切换到该主题 */
37
+ apply?: boolean;
38
+ }
39
+ /**
40
+ * 运行时定义主题(L2)
41
+ * 以某内置主题为基线,覆盖语义色后自动派生 EP 色阶与业务变量并注入样式
42
+ */
43
+ declare function defineTheme(options: DefineThemeOptions): void;
44
+ interface SetThemeOptions {
45
+ /** 本次切换是否持久化(需已启用持久化或显式指定) */
46
+ persist?: boolean;
47
+ }
48
+ /** 切换主题(内置/自定义均可;light 作用于 body 本身) */
49
+ declare function setTheme(name: string, options?: SetThemeOptions): void;
50
+ /** 当前主题名 */
51
+ declare function getTheme(): string;
52
+ /** 全部可用主题(内置 + 运行时自定义) */
53
+ declare function getThemes(): string[];
54
+ /** 开启主题持久化(同一浏览器记住所选主题) */
55
+ declare function enableThemePersistence(): void;
56
+ /** 主题变化监听 */
57
+ declare function onThemeChange(callback: (theme: string) => void): () => void;
58
+ interface UseThemeReturn {
59
+ /** 当前主题(只读 ref) */
60
+ theme: ComputedRef<string>;
61
+ /** 可用主题列表(只读) */
62
+ themes: ComputedRef<string[]>;
63
+ /** 切换主题 */
64
+ setTheme: (name: string, options?: SetThemeOptions) => void;
65
+ }
66
+ /** 主题 composable(配合 defineTheme 实现运行时换肤) */
67
+ declare function useTheme(): UseThemeReturn;
68
+
69
+ /** 混色:weight 为混入 color2 的百分比(与 EP mix 一致) */
70
+ declare function mix(color1: string, color2: string, weight: number): string;
71
+ interface ElColorShades {
72
+ 'light-1': string;
73
+ 'light-2': string;
74
+ 'light-3': string;
75
+ 'light-4': string;
76
+ 'light-5': string;
77
+ 'light-6': string;
78
+ 'light-7': string;
79
+ 'light-8': string;
80
+ 'light-9': string;
81
+ 'dark-2': string;
82
+ }
83
+ /** EP 主色色阶:light-n = mix(白, 主色, n*10%);dark-2 = mix(黑, 主色, 20%) */
84
+ declare function generateElShades(hex: string): ElColorShades;
85
+
86
+ export { COLOR_TYPES, type ColorType, type DefineThemeColors, type DefineThemeOptions, type SetThemeOptions, THEMES, type ThemeName, type UseThemeReturn, defineTheme, enableThemePersistence, generateElShades, getTheme, getThemes, mix, onThemeChange, setTheme, themesData, useTheme };