@yh-ui/theme 0.1.17 → 0.1.22
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 +248 -0
- package/dist/component-theme.d.ts +75 -0
- package/dist/theme.cjs +53 -29
- package/dist/theme.mjs +53 -29
- package/package.json +9 -2
- package/src/styles/mixins/mixins.scss +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @yh-ui/theme
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/1079161148/yh-ui/main/docs/public/logo.svg" width="100" height="100" alt="YH-UI Logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h3 align="center">YH-UI 行业领先主题系统</h3>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
12 种预设主题 · 4 种颜色算法 · 色盲友好模式 · 3 档密度配置 · 丝滑切换动画 · 跟随系统暗色
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/@yh-ui/theme">
|
|
15
|
+
<img src="https://img.shields.io/npm/v/@yh-ui/theme.svg?style=flat-square&colorB=409eff" alt="npm version">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://www.npmjs.com/package/@yh-ui/theme">
|
|
18
|
+
<img src="https://img.shields.io/npm/dm/@yh-ui/theme.svg?style=flat-square&colorB=409eff" alt="npm downloads">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://github.com/1079161148/yh-ui/blob/main/LICENSE">
|
|
21
|
+
<img src="https://img.shields.io/npm/l/@yh-ui/theme.svg?style=flat-square" alt="license">
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ✨ 为什么选择 YH-UI 主题系统?
|
|
28
|
+
|
|
29
|
+
| 能力 | YH-UI | Element Plus | Naive UI |
|
|
30
|
+
| ---------------- | ----------- | ------------ | -------- |
|
|
31
|
+
| 预设主题数 | **12 种** | 1 种 | 有限 |
|
|
32
|
+
| 颜色算法 | **4 种** | ❌ | ❌ |
|
|
33
|
+
| 色盲友好模式 | **4 种** ✅ | ❌ | ❌ |
|
|
34
|
+
| 密度配置 | **3 档** ✅ | ❌ | ❌ |
|
|
35
|
+
| 主题切换动画 | ✅ 丝滑 | ❌ | ❌ |
|
|
36
|
+
| 跟随系统暗色 | ✅ | 手动 | 手动 |
|
|
37
|
+
| 偏好持久化 | ✅ | ❌ | ❌ |
|
|
38
|
+
| CSS 变量设计令牌 | ✅ 完整 | 部分 | 部分 |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 📦 安装
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# pnpm(推荐)
|
|
46
|
+
pnpm add @yh-ui/theme
|
|
47
|
+
|
|
48
|
+
# npm
|
|
49
|
+
npm install @yh-ui/theme
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> **注意**:`@yh-ui/theme` 是 `@yh-ui/yh-ui` 的子包,通常无需单独安装。
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🔨 快速开始
|
|
57
|
+
|
|
58
|
+
### 在 Vue 应用中使用
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { createApp } from 'vue'
|
|
62
|
+
import { createYhTheme } from '@yh-ui/theme'
|
|
63
|
+
import App from './App.vue'
|
|
64
|
+
|
|
65
|
+
const app = createApp(App)
|
|
66
|
+
|
|
67
|
+
const theme = createYhTheme({
|
|
68
|
+
preset: 'purple', // 12 种预设主题
|
|
69
|
+
algorithm: 'vibrant', // 颜色算法
|
|
70
|
+
density: 'default', // 密度档位
|
|
71
|
+
followSystem: true, // 跟随系统暗色模式
|
|
72
|
+
transition: true, // 开启切换动画
|
|
73
|
+
persist: true // 持久化到 localStorage
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
app.use(theme)
|
|
77
|
+
app.mount('#app')
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 在组件中动态切换
|
|
81
|
+
|
|
82
|
+
```vue
|
|
83
|
+
<script setup lang="ts">
|
|
84
|
+
import { useTheme } from '@yh-ui/theme'
|
|
85
|
+
|
|
86
|
+
const { preset, isDark, density, setPreset, toggleDark, setDensity } = useTheme()
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<div>
|
|
91
|
+
<!-- 切换主题预设 -->
|
|
92
|
+
<button @click="setPreset('ocean')">Ocean 主题</button>
|
|
93
|
+
<button @click="setPreset('violet')">Violet 主题</button>
|
|
94
|
+
|
|
95
|
+
<!-- 切换暗色 -->
|
|
96
|
+
<button @click="toggleDark()">{{ isDark ? '切换亮色' : '切换暗色' }}</button>
|
|
97
|
+
|
|
98
|
+
<!-- 切换密度 -->
|
|
99
|
+
<button @click="setDensity('compact')">紧凑</button>
|
|
100
|
+
<button @click="setDensity('default')">默认</button>
|
|
101
|
+
<button @click="setDensity('comfortable')">宽松</button>
|
|
102
|
+
</div>
|
|
103
|
+
</template>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🎨 预设主题列表
|
|
109
|
+
|
|
110
|
+
| 主题名 | 说明 |
|
|
111
|
+
| ----------- | ------------------ |
|
|
112
|
+
| `default` | 科技蓝(默认) |
|
|
113
|
+
| `purple` | 优雅紫 |
|
|
114
|
+
| `ocean` | 深海蓝 |
|
|
115
|
+
| `violet` | 紫罗兰 |
|
|
116
|
+
| `rose` | 玫瑰红 |
|
|
117
|
+
| `amber` | 琥珀金 |
|
|
118
|
+
| `emerald` | 翡翠绿 |
|
|
119
|
+
| `slate` | 石板灰(极简中性) |
|
|
120
|
+
| `cyberpunk` | 赛博朋克(霓虹风) |
|
|
121
|
+
| `sakura` | 樱花粉 |
|
|
122
|
+
| `forest` | 深林绿 |
|
|
123
|
+
| `nordic` | 北欧冷色 |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## ⚙️ 配置项
|
|
128
|
+
|
|
129
|
+
### `createYhTheme(options)`
|
|
130
|
+
|
|
131
|
+
| 选项 | 类型 | 默认值 | 说明 |
|
|
132
|
+
| ---------------- | ------------------------------------------------------------------- | ----------- | ----------------------------------- |
|
|
133
|
+
| `preset` | `ThemePreset` | `'default'` | 预设主题名 |
|
|
134
|
+
| `algorithm` | `'default' \| 'vibrant' \| 'soft' \| 'dark'` | `'default'` | 颜色生成算法 |
|
|
135
|
+
| `density` | `'compact' \| 'default' \| 'comfortable'` | `'default'` | 密度档位 |
|
|
136
|
+
| `colorBlindMode` | `'protanopia' \| 'deuteranopia' \| 'tritanopia' \| 'achromatopsia'` | `undefined` | 色盲友好模式 |
|
|
137
|
+
| `followSystem` | `boolean` | `false` | 是否跟随系统暗色偏好 |
|
|
138
|
+
| `transition` | `boolean` | `true` | 是否开启主题切换 transition 动画 |
|
|
139
|
+
| `persist` | `boolean` | `false` | 是否将用户偏好持久化到 localStorage |
|
|
140
|
+
| `namespace` | `string` | `'yh'` | CSS 变量命名空间前缀 |
|
|
141
|
+
|
|
142
|
+
### `useTheme()` 返回值
|
|
143
|
+
|
|
144
|
+
| 属性/方法 | 类型 | 说明 |
|
|
145
|
+
| ------------------------- | --------------------- | ---------------- |
|
|
146
|
+
| `preset` | `Ref<ThemePreset>` | 当前主题预设 |
|
|
147
|
+
| `isDark` | `Ref<boolean>` | 是否为暗色模式 |
|
|
148
|
+
| `density` | `Ref<Density>` | 当前密度 |
|
|
149
|
+
| `algorithm` | `Ref<Algorithm>` | 当前颜色算法 |
|
|
150
|
+
| `colorBlindMode` | `Ref<ColorBlindMode>` | 当前色盲模式 |
|
|
151
|
+
| `setPreset(preset)` | `Function` | 切换主题预设 |
|
|
152
|
+
| `toggleDark()` | `Function` | 切换暗色/亮色 |
|
|
153
|
+
| `setDensity(density)` | `Function` | 设置密度档位 |
|
|
154
|
+
| `setAlgorithm(algorithm)` | `Function` | 设置颜色算法 |
|
|
155
|
+
| `setColorBlindMode(mode)` | `Function` | 设置色盲友好模式 |
|
|
156
|
+
| `resetTheme()` | `Function` | 重置为默认主题 |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🎨 CSS 设计令牌(Design Tokens)
|
|
161
|
+
|
|
162
|
+
主题系统通过 CSS 自定义属性(CSS Variables)实现,可在任意样式中使用:
|
|
163
|
+
|
|
164
|
+
```scss
|
|
165
|
+
// 主色系
|
|
166
|
+
--yh-color-primary
|
|
167
|
+
--yh-color-primary-light-3
|
|
168
|
+
--yh-color-primary-dark-2
|
|
169
|
+
|
|
170
|
+
// 文字颜色
|
|
171
|
+
--yh-text-color-primary
|
|
172
|
+
--yh-text-color-regular
|
|
173
|
+
--yh-text-color-secondary
|
|
174
|
+
--yh-text-color-placeholder
|
|
175
|
+
|
|
176
|
+
// 背景颜色
|
|
177
|
+
--yh-bg-color
|
|
178
|
+
--yh-bg-color-page
|
|
179
|
+
--yh-bg-color-overlay
|
|
180
|
+
|
|
181
|
+
// 边框
|
|
182
|
+
--yh-border-color
|
|
183
|
+
--yh-border-color-light
|
|
184
|
+
--yh-border-radius-base
|
|
185
|
+
|
|
186
|
+
// 间距(密度相关)
|
|
187
|
+
--yh-spacing-xs
|
|
188
|
+
--yh-spacing-sm
|
|
189
|
+
--yh-spacing-md
|
|
190
|
+
--yh-spacing-lg
|
|
191
|
+
|
|
192
|
+
// 组件尺寸
|
|
193
|
+
--yh-component-size-small
|
|
194
|
+
--yh-component-size-default
|
|
195
|
+
--yh-component-size-large
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
在自定义组件中使用:
|
|
199
|
+
|
|
200
|
+
```scss
|
|
201
|
+
.my-card {
|
|
202
|
+
background: var(--yh-bg-color);
|
|
203
|
+
border: 1px solid var(--yh-border-color);
|
|
204
|
+
border-radius: var(--yh-border-radius-base);
|
|
205
|
+
color: var(--yh-text-color-primary);
|
|
206
|
+
padding: var(--yh-spacing-md);
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## 🌙 暗色模式
|
|
213
|
+
|
|
214
|
+
YH-UI 主题系统提供两种暗色模式激活方式:
|
|
215
|
+
|
|
216
|
+
### 方式一:受控切换
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const { toggleDark, isDark } = useTheme()
|
|
220
|
+
toggleDark() // 手动切换
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 方式二:跟随系统(推荐)
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
createYhTheme({ followSystem: true })
|
|
227
|
+
// 自动响应 prefers-color-scheme: dark
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## ⚠️ 注意事项
|
|
233
|
+
|
|
234
|
+
1. **主题包含 CSS 文件**:需要在入口统一引入样式,`@yh-ui/yh-ui/css` 会自动包含主题样式
|
|
235
|
+
2. **SSR**:服务端不存在 `localStorage`,`persist: true` 时需配合 Nuxt Cookie 持久化
|
|
236
|
+
3. **色盲模式**:启用色盲模式后,颜色算法将强制切换以保证 WCAG 对比度合规
|
|
237
|
+
4. **命名空间**:自定义 `namespace` 时,CSS 变量前缀会相应变更,需同步修改样式引用
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 🔗 相关资源
|
|
242
|
+
|
|
243
|
+
- [📖 官方文档 — 主题系统](https://1079161148.github.io/yh-ui/guide/theming)
|
|
244
|
+
- [📦 GitHub 仓库](https://github.com/1079161148/yh-ui)
|
|
245
|
+
|
|
246
|
+
## 📄 开源协议
|
|
247
|
+
|
|
248
|
+
MIT License © 2024-present YH-UI Team
|
|
@@ -250,6 +250,71 @@ export interface AiPromptsThemeVars extends ComponentThemeVars {
|
|
|
250
250
|
itemHoverBgColor?: string;
|
|
251
251
|
itemActiveBorderColor?: string;
|
|
252
252
|
}
|
|
253
|
+
/** AiChat 组件主题变量 */
|
|
254
|
+
export interface AiChatThemeVars extends ComponentThemeVars {
|
|
255
|
+
chatPadding?: string;
|
|
256
|
+
messageGap?: string;
|
|
257
|
+
}
|
|
258
|
+
/** AiBubble 组件主题变量 */
|
|
259
|
+
export interface AiBubbleThemeVars extends ComponentThemeVars {
|
|
260
|
+
userBgColor?: string;
|
|
261
|
+
userTextColor?: string;
|
|
262
|
+
assistantBgColor?: string;
|
|
263
|
+
assistantTextColor?: string;
|
|
264
|
+
avatarSize?: string;
|
|
265
|
+
}
|
|
266
|
+
/** AiSender 组件主题变量 */
|
|
267
|
+
export interface AiSenderThemeVars extends ComponentThemeVars {
|
|
268
|
+
inputBgColor?: string;
|
|
269
|
+
focusBorderColor?: string;
|
|
270
|
+
}
|
|
271
|
+
/** AiCodeEditor 组件主题变量 */
|
|
272
|
+
export interface AiCodeEditorThemeVars extends ComponentThemeVars {
|
|
273
|
+
editorHeight?: string;
|
|
274
|
+
}
|
|
275
|
+
/** AiCodeRunner 组件主题变量 */
|
|
276
|
+
export interface AiCodeRunnerThemeVars extends ComponentThemeVars {
|
|
277
|
+
terminalHeight?: string;
|
|
278
|
+
terminalBgColor?: string;
|
|
279
|
+
terminalTextColor?: string;
|
|
280
|
+
}
|
|
281
|
+
/** AiFileCard 组件主题变量 */
|
|
282
|
+
export interface AiFileCardThemeVars extends ComponentThemeVars {
|
|
283
|
+
iconColor?: string;
|
|
284
|
+
imageRadius?: string;
|
|
285
|
+
}
|
|
286
|
+
/** AiAttachments 组件主题变量 */
|
|
287
|
+
export interface AiAttachmentsThemeVars extends ComponentThemeVars {
|
|
288
|
+
uploadBorderColor?: string;
|
|
289
|
+
uploadHoverBorderColor?: string;
|
|
290
|
+
progressColor?: string;
|
|
291
|
+
}
|
|
292
|
+
/** AiMermaid 组件主题变量 */
|
|
293
|
+
export interface AiMermaidThemeVars extends ComponentThemeVars {
|
|
294
|
+
headerBgColor?: string;
|
|
295
|
+
headerTextColor?: string;
|
|
296
|
+
codeBlockBgColor?: string;
|
|
297
|
+
codeBlockTextColor?: string;
|
|
298
|
+
}
|
|
299
|
+
/** Carousel 组件主题变量 */
|
|
300
|
+
export interface CarouselThemeVars extends ComponentThemeVars {
|
|
301
|
+
dotColor?: string;
|
|
302
|
+
dotActiveColor?: string;
|
|
303
|
+
dotSize?: string;
|
|
304
|
+
dotActiveWidth?: string;
|
|
305
|
+
arrowBg?: string;
|
|
306
|
+
arrowHoverBg?: string;
|
|
307
|
+
arrowColor?: string;
|
|
308
|
+
arrowSize?: string;
|
|
309
|
+
}
|
|
310
|
+
/** Scrollbar 组件主题变量 */
|
|
311
|
+
export interface ScrollbarThemeVars extends ComponentThemeVars {
|
|
312
|
+
width?: string;
|
|
313
|
+
thumbColor?: string;
|
|
314
|
+
thumbHoverColor?: string;
|
|
315
|
+
trackColor?: string;
|
|
316
|
+
thumbRadius?: string;
|
|
317
|
+
}
|
|
253
318
|
export interface AllComponentThemes {
|
|
254
319
|
button?: ButtonThemeVars;
|
|
255
320
|
input?: InputThemeVars;
|
|
@@ -268,8 +333,18 @@ export interface AllComponentThemes {
|
|
|
268
333
|
calendar?: CalendarThemeVars;
|
|
269
334
|
tree?: TreeThemeVars;
|
|
270
335
|
mention?: MentionThemeVars;
|
|
336
|
+
aiChat?: AiChatThemeVars;
|
|
337
|
+
aiBubble?: AiBubbleThemeVars;
|
|
338
|
+
aiSender?: AiSenderThemeVars;
|
|
339
|
+
aiCodeEditor?: AiCodeEditorThemeVars;
|
|
340
|
+
aiCodeRunner?: AiCodeRunnerThemeVars;
|
|
271
341
|
aiConversations?: AiConversationsThemeVars;
|
|
272
342
|
aiPrompts?: AiPromptsThemeVars;
|
|
343
|
+
aiFileCard?: AiFileCardThemeVars;
|
|
344
|
+
aiAttachments?: AiAttachmentsThemeVars;
|
|
345
|
+
aiMermaid?: AiMermaidThemeVars;
|
|
346
|
+
carousel?: CarouselThemeVars;
|
|
347
|
+
scrollbar?: ScrollbarThemeVars;
|
|
273
348
|
[key: string]: ComponentThemeVars | undefined;
|
|
274
349
|
}
|
|
275
350
|
/**
|
package/dist/theme.cjs
CHANGED
|
@@ -792,6 +792,57 @@ class ThemeManager {
|
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
794
|
});
|
|
795
|
+
Object.entries(_tokens.designTokens.textColors).forEach(([key, value]) => {
|
|
796
|
+
styles[`--yh-text-color-${key}`] = value;
|
|
797
|
+
});
|
|
798
|
+
Object.entries(_tokens.designTokens.borderColors).forEach(([key, value]) => {
|
|
799
|
+
const name = key === "DEFAULT" ? "--yh-border-color" : `--yh-border-color-${key}`;
|
|
800
|
+
styles[name] = value;
|
|
801
|
+
});
|
|
802
|
+
Object.entries(_tokens.designTokens.bgColors).forEach(([key, value]) => {
|
|
803
|
+
const name = key === "DEFAULT" ? "--yh-bg-color" : `--yh-bg-color-${key}`;
|
|
804
|
+
styles[name] = value;
|
|
805
|
+
});
|
|
806
|
+
Object.entries(_tokens.designTokens.radius).forEach(([key, value]) => {
|
|
807
|
+
styles[`--yh-radius-${key}`] = value;
|
|
808
|
+
});
|
|
809
|
+
Object.entries(_tokens.designTokens.zIndex).forEach(([key, value]) => {
|
|
810
|
+
styles[`--yh-z-index-${key}`] = value;
|
|
811
|
+
});
|
|
812
|
+
Object.entries(_tokens.designTokens.spacing).forEach(([key, value]) => {
|
|
813
|
+
styles[`--yh-spacing-${key}`] = value;
|
|
814
|
+
});
|
|
815
|
+
Object.entries(_tokens.designTokens.fontSize).forEach(([key, value]) => {
|
|
816
|
+
styles[`--yh-font-size-${key}`] = value;
|
|
817
|
+
});
|
|
818
|
+
Object.entries(_tokens.designTokens.lineHeight).forEach(([key, value]) => {
|
|
819
|
+
styles[`--yh-line-height-${key}`] = value;
|
|
820
|
+
});
|
|
821
|
+
Object.entries(_tokens.designTokens.fontWeight).forEach(([key, value]) => {
|
|
822
|
+
styles[`--yh-font-weight-${key}`] = value;
|
|
823
|
+
});
|
|
824
|
+
Object.entries(_tokens.designTokens.shadow).forEach(([key, value]) => {
|
|
825
|
+
styles[`--yh-shadow-${key}`] = value;
|
|
826
|
+
});
|
|
827
|
+
Object.entries(_tokens.designTokens.duration).forEach(([key, value]) => {
|
|
828
|
+
styles[`--yh-duration-${key}`] = value;
|
|
829
|
+
});
|
|
830
|
+
Object.entries(_tokens.designTokens.timing).forEach(([key, value]) => {
|
|
831
|
+
styles[`--yh-timing-${key}`] = value;
|
|
832
|
+
});
|
|
833
|
+
Object.entries(_tokens.designTokens.scrollbar).forEach(([key, value]) => {
|
|
834
|
+
const kebabKey = key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
835
|
+
styles[`--yh-scrollbar-${kebabKey}`] = value;
|
|
836
|
+
});
|
|
837
|
+
Object.entries(_tokens.designTokens.mask).forEach(([key, value]) => {
|
|
838
|
+
const name = key === "DEFAULT" ? "--yh-mask" : `--yh-mask-${key}`;
|
|
839
|
+
styles[name] = value;
|
|
840
|
+
});
|
|
841
|
+
Object.entries(this.componentOverrides).forEach(([component, overrides]) => {
|
|
842
|
+
Object.entries(overrides).forEach(([name, value]) => {
|
|
843
|
+
styles[`--yh-${component}-${name}`] = value;
|
|
844
|
+
});
|
|
845
|
+
});
|
|
795
846
|
return styles;
|
|
796
847
|
}
|
|
797
848
|
/** 获取 CSS 变量值 */
|
|
@@ -806,37 +857,10 @@ class ThemeManager {
|
|
|
806
857
|
applyTokens() {
|
|
807
858
|
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
808
859
|
if (!el) return;
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
setCssVar(`--yh-color-${type}`, colorObj.DEFAULT, el);
|
|
812
|
-
if (colorObj.light) {
|
|
813
|
-
Object.entries(colorObj.light).forEach(([level, value]) => {
|
|
814
|
-
setCssVar(`--yh-color-${type}-light-${level}`, value, el);
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
if (colorObj.dark) {
|
|
818
|
-
Object.entries(colorObj.dark).forEach(([level, value]) => {
|
|
819
|
-
setCssVar(`--yh-color-${type}-dark-${level}`, value, el);
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
Object.entries(_tokens.designTokens.textColors).forEach(([key, value]) => {
|
|
824
|
-
setCssVar(`--yh-text-color-${key}`, value, el);
|
|
825
|
-
});
|
|
826
|
-
Object.entries(_tokens.designTokens.borderColors).forEach(([key, value]) => {
|
|
827
|
-
const name = key === "DEFAULT" ? "--yh-border-color" : `--yh-border-color-${key}`;
|
|
828
|
-
setCssVar(name, value, el);
|
|
829
|
-
});
|
|
830
|
-
Object.entries(_tokens.designTokens.bgColors).forEach(([key, value]) => {
|
|
831
|
-
const name = key === "DEFAULT" ? "--yh-bg-color" : `--yh-bg-color-${key}`;
|
|
860
|
+
const styles = this.getThemeStyles();
|
|
861
|
+
Object.entries(styles).forEach(([name, value]) => {
|
|
832
862
|
setCssVar(name, value, el);
|
|
833
863
|
});
|
|
834
|
-
Object.entries(_tokens.designTokens.radius).forEach(([key, value]) => {
|
|
835
|
-
setCssVar(`--yh-radius-${key}`, value, el);
|
|
836
|
-
});
|
|
837
|
-
Object.entries(_tokens.designTokens.zIndex).forEach(([key, value]) => {
|
|
838
|
-
setCssVar(`--yh-z-index-${key}`, value, el);
|
|
839
|
-
});
|
|
840
864
|
}
|
|
841
865
|
// ==================== 持久化 ====================
|
|
842
866
|
/** 保存到存储 */
|
package/dist/theme.mjs
CHANGED
|
@@ -710,6 +710,57 @@ export class ThemeManager {
|
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
712
|
});
|
|
713
|
+
Object.entries(designTokens.textColors).forEach(([key, value]) => {
|
|
714
|
+
styles[`--yh-text-color-${key}`] = value;
|
|
715
|
+
});
|
|
716
|
+
Object.entries(designTokens.borderColors).forEach(([key, value]) => {
|
|
717
|
+
const name = key === "DEFAULT" ? "--yh-border-color" : `--yh-border-color-${key}`;
|
|
718
|
+
styles[name] = value;
|
|
719
|
+
});
|
|
720
|
+
Object.entries(designTokens.bgColors).forEach(([key, value]) => {
|
|
721
|
+
const name = key === "DEFAULT" ? "--yh-bg-color" : `--yh-bg-color-${key}`;
|
|
722
|
+
styles[name] = value;
|
|
723
|
+
});
|
|
724
|
+
Object.entries(designTokens.radius).forEach(([key, value]) => {
|
|
725
|
+
styles[`--yh-radius-${key}`] = value;
|
|
726
|
+
});
|
|
727
|
+
Object.entries(designTokens.zIndex).forEach(([key, value]) => {
|
|
728
|
+
styles[`--yh-z-index-${key}`] = value;
|
|
729
|
+
});
|
|
730
|
+
Object.entries(designTokens.spacing).forEach(([key, value]) => {
|
|
731
|
+
styles[`--yh-spacing-${key}`] = value;
|
|
732
|
+
});
|
|
733
|
+
Object.entries(designTokens.fontSize).forEach(([key, value]) => {
|
|
734
|
+
styles[`--yh-font-size-${key}`] = value;
|
|
735
|
+
});
|
|
736
|
+
Object.entries(designTokens.lineHeight).forEach(([key, value]) => {
|
|
737
|
+
styles[`--yh-line-height-${key}`] = value;
|
|
738
|
+
});
|
|
739
|
+
Object.entries(designTokens.fontWeight).forEach(([key, value]) => {
|
|
740
|
+
styles[`--yh-font-weight-${key}`] = value;
|
|
741
|
+
});
|
|
742
|
+
Object.entries(designTokens.shadow).forEach(([key, value]) => {
|
|
743
|
+
styles[`--yh-shadow-${key}`] = value;
|
|
744
|
+
});
|
|
745
|
+
Object.entries(designTokens.duration).forEach(([key, value]) => {
|
|
746
|
+
styles[`--yh-duration-${key}`] = value;
|
|
747
|
+
});
|
|
748
|
+
Object.entries(designTokens.timing).forEach(([key, value]) => {
|
|
749
|
+
styles[`--yh-timing-${key}`] = value;
|
|
750
|
+
});
|
|
751
|
+
Object.entries(designTokens.scrollbar).forEach(([key, value]) => {
|
|
752
|
+
const kebabKey = key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
753
|
+
styles[`--yh-scrollbar-${kebabKey}`] = value;
|
|
754
|
+
});
|
|
755
|
+
Object.entries(designTokens.mask).forEach(([key, value]) => {
|
|
756
|
+
const name = key === "DEFAULT" ? "--yh-mask" : `--yh-mask-${key}`;
|
|
757
|
+
styles[name] = value;
|
|
758
|
+
});
|
|
759
|
+
Object.entries(this.componentOverrides).forEach(([component, overrides]) => {
|
|
760
|
+
Object.entries(overrides).forEach(([name, value]) => {
|
|
761
|
+
styles[`--yh-${component}-${name}`] = value;
|
|
762
|
+
});
|
|
763
|
+
});
|
|
713
764
|
return styles;
|
|
714
765
|
}
|
|
715
766
|
/** 获取 CSS 变量值 */
|
|
@@ -724,37 +775,10 @@ export class ThemeManager {
|
|
|
724
775
|
applyTokens() {
|
|
725
776
|
const el = this.targetEl || (typeof document !== "undefined" ? document.documentElement : null);
|
|
726
777
|
if (!el) return;
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
setCssVar(`--yh-color-${type}`, colorObj.DEFAULT, el);
|
|
730
|
-
if (colorObj.light) {
|
|
731
|
-
Object.entries(colorObj.light).forEach(([level, value]) => {
|
|
732
|
-
setCssVar(`--yh-color-${type}-light-${level}`, value, el);
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
if (colorObj.dark) {
|
|
736
|
-
Object.entries(colorObj.dark).forEach(([level, value]) => {
|
|
737
|
-
setCssVar(`--yh-color-${type}-dark-${level}`, value, el);
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
Object.entries(designTokens.textColors).forEach(([key, value]) => {
|
|
742
|
-
setCssVar(`--yh-text-color-${key}`, value, el);
|
|
743
|
-
});
|
|
744
|
-
Object.entries(designTokens.borderColors).forEach(([key, value]) => {
|
|
745
|
-
const name = key === "DEFAULT" ? "--yh-border-color" : `--yh-border-color-${key}`;
|
|
746
|
-
setCssVar(name, value, el);
|
|
747
|
-
});
|
|
748
|
-
Object.entries(designTokens.bgColors).forEach(([key, value]) => {
|
|
749
|
-
const name = key === "DEFAULT" ? "--yh-bg-color" : `--yh-bg-color-${key}`;
|
|
778
|
+
const styles = this.getThemeStyles();
|
|
779
|
+
Object.entries(styles).forEach(([name, value]) => {
|
|
750
780
|
setCssVar(name, value, el);
|
|
751
781
|
});
|
|
752
|
-
Object.entries(designTokens.radius).forEach(([key, value]) => {
|
|
753
|
-
setCssVar(`--yh-radius-${key}`, value, el);
|
|
754
|
-
});
|
|
755
|
-
Object.entries(designTokens.zIndex).forEach(([key, value]) => {
|
|
756
|
-
setCssVar(`--yh-z-index-${key}`, value, el);
|
|
757
|
-
});
|
|
758
782
|
}
|
|
759
783
|
// ==================== 持久化 ====================
|
|
760
784
|
/** 保存到存储 */
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yh-ui/theme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "YH-UI theme and design tokens",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"**/*.css",
|
|
8
|
+
"**/*.scss",
|
|
9
|
+
"src/styles/**"
|
|
10
|
+
],
|
|
6
11
|
"main": "./dist/index.cjs",
|
|
7
12
|
"module": "./dist/index.mjs",
|
|
8
13
|
"types": "./dist/index.d.ts",
|
|
@@ -47,6 +52,8 @@
|
|
|
47
52
|
},
|
|
48
53
|
"scripts": {
|
|
49
54
|
"build": "unbuild",
|
|
50
|
-
"dev": "unbuild --stub"
|
|
55
|
+
"dev": "unbuild --stub",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"lint": "eslint ."
|
|
51
58
|
}
|
|
52
59
|
}
|