@mc-markets/ui 1.0.59 → 1.0.60
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/package.json
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// 导入所有 Element Plus 样式
|
|
9
|
-
// 自定义 Element Plus 变量
|
|
10
9
|
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
|
|
11
10
|
// 自定义颜色变量
|
|
12
11
|
$colors: (
|
|
@@ -73,7 +72,7 @@
|
|
|
73
72
|
)
|
|
74
73
|
);
|
|
75
74
|
@use "element-plus/theme-chalk/src/index.scss" as *;
|
|
76
|
-
@use 'element-plus/theme-chalk/src/dark/css-vars.scss'
|
|
75
|
+
@use 'element-plus/theme-chalk/src/dark/css-vars.scss' as *;
|
|
77
76
|
|
|
78
77
|
// 导入项目变量
|
|
79
78
|
@use './variables/border-mode.css';
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @mc-markets/ui - 主题配置工具
|
|
3
|
-
*
|
|
4
|
-
* 基于 Element Plus 官方主题定制指南
|
|
5
|
-
* @see https://element-plus.org/zh-CN/guide/theming.html
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export class ThemeConfigManager {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.currentTheme = { name: 'default', dark: false }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static getInstance() {
|
|
14
|
-
if (!ThemeConfigManager.instance) {
|
|
15
|
-
ThemeConfigManager.instance = new ThemeConfigManager()
|
|
16
|
-
}
|
|
17
|
-
return ThemeConfigManager.instance
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** 设置主题 */
|
|
21
|
-
setTheme(theme) {
|
|
22
|
-
this.currentTheme = { ...this.currentTheme, ...theme }
|
|
23
|
-
this.applyTheme()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** 获取当前主题 */
|
|
27
|
-
getTheme() {
|
|
28
|
-
return { ...this.currentTheme }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 切换暗色主题 */
|
|
32
|
-
toggleDark() {
|
|
33
|
-
this.currentTheme.dark = !this.currentTheme.dark
|
|
34
|
-
this.applyTheme()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** 设置主色调 */
|
|
38
|
-
setPrimaryColor(color) {
|
|
39
|
-
this.setCssVar('--el-color-primary', color)
|
|
40
|
-
this.generateColorPalette(color, 'primary')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 设置成功色 */
|
|
44
|
-
setSuccessColor(color) {
|
|
45
|
-
this.setCssVar('--el-color-success', color)
|
|
46
|
-
this.generateColorPalette(color, 'success')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** 设置警告色 */
|
|
50
|
-
setWarningColor(color) {
|
|
51
|
-
this.setCssVar('--el-color-warning', color)
|
|
52
|
-
this.generateColorPalette(color, 'warning')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** 设置危险色 */
|
|
56
|
-
setDangerColor(color) {
|
|
57
|
-
this.setCssVar('--el-color-danger', color)
|
|
58
|
-
this.generateColorPalette(color, 'danger')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** 设置信息色 */
|
|
62
|
-
setInfoColor(color) {
|
|
63
|
-
this.setCssVar('--el-color-info', color)
|
|
64
|
-
this.generateColorPalette(color, 'info')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** 设置CSS变量 */
|
|
68
|
-
setCssVar(name, value) {
|
|
69
|
-
const root = document.documentElement
|
|
70
|
-
root.style.setProperty(name, value)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** 获取CSS变量 */
|
|
74
|
-
getCssVar(name) {
|
|
75
|
-
const root = document.documentElement
|
|
76
|
-
return getComputedStyle(root).getPropertyValue(name).trim()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** 生成颜色调色板 */
|
|
80
|
-
generateColorPalette(color, type) {
|
|
81
|
-
const root = document.documentElement
|
|
82
|
-
const baseColor = this.hexToRgb(color)
|
|
83
|
-
|
|
84
|
-
if (!baseColor) return
|
|
85
|
-
|
|
86
|
-
// 生成不同亮度的颜色
|
|
87
|
-
const lightColors = this.generateLightColors(baseColor)
|
|
88
|
-
const darkColors = this.generateDarkColors(baseColor)
|
|
89
|
-
|
|
90
|
-
// 设置CSS变量
|
|
91
|
-
root.style.setProperty(`--el-color-${type}`, color)
|
|
92
|
-
root.style.setProperty(`--el-color-${type}-light-3`, lightColors[3])
|
|
93
|
-
root.style.setProperty(`--el-color-${type}-light-5`, lightColors[5])
|
|
94
|
-
root.style.setProperty(`--el-color-${type}-light-7`, lightColors[7])
|
|
95
|
-
root.style.setProperty(`--el-color-${type}-light-8`, lightColors[8])
|
|
96
|
-
root.style.setProperty(`--el-color-${type}-light-9`, lightColors[9])
|
|
97
|
-
root.style.setProperty(`--el-color-${type}-dark-2`, darkColors[2])
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** 应用主题 */
|
|
101
|
-
applyTheme() {
|
|
102
|
-
const root = document.documentElement
|
|
103
|
-
|
|
104
|
-
// 应用暗色主题
|
|
105
|
-
if (this.currentTheme.dark) {
|
|
106
|
-
root.classList.add('dark')
|
|
107
|
-
} else {
|
|
108
|
-
root.classList.remove('dark')
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// 应用自定义类名
|
|
112
|
-
if (this.currentTheme.customClass) {
|
|
113
|
-
root.classList.add(this.currentTheme.customClass)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 应用自定义CSS变量
|
|
117
|
-
if (this.currentTheme.cssVars) {
|
|
118
|
-
Object.entries(this.currentTheme.cssVars).forEach(([key, value]) => {
|
|
119
|
-
root.style.setProperty(key, value)
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 应用预设颜色
|
|
124
|
-
if (this.currentTheme.primaryColor) {
|
|
125
|
-
this.setPrimaryColor(this.currentTheme.primaryColor)
|
|
126
|
-
}
|
|
127
|
-
if (this.currentTheme.successColor) {
|
|
128
|
-
this.setSuccessColor(this.currentTheme.successColor)
|
|
129
|
-
}
|
|
130
|
-
if (this.currentTheme.warningColor) {
|
|
131
|
-
this.setWarningColor(this.currentTheme.warningColor)
|
|
132
|
-
}
|
|
133
|
-
if (this.currentTheme.dangerColor) {
|
|
134
|
-
this.setDangerColor(this.currentTheme.dangerColor)
|
|
135
|
-
}
|
|
136
|
-
if (this.currentTheme.infoColor) {
|
|
137
|
-
this.setInfoColor(this.currentTheme.infoColor)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** 十六进制颜色转RGB */
|
|
142
|
-
hexToRgb(hex) {
|
|
143
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
144
|
-
return result ? {
|
|
145
|
-
r: parseInt(result[1], 16),
|
|
146
|
-
g: parseInt(result[2], 16),
|
|
147
|
-
b: parseInt(result[3], 16)
|
|
148
|
-
} : null
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** RGB转十六进制 */
|
|
152
|
-
rgbToHex(r, g, b) {
|
|
153
|
-
return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** 生成浅色变体 */
|
|
157
|
-
generateLightColors(rgb) {
|
|
158
|
-
const colors = {}
|
|
159
|
-
|
|
160
|
-
for (let i = 1; i <= 9; i++) {
|
|
161
|
-
const factor = (10 - i) / 10
|
|
162
|
-
const r = Math.round(255 - (255 - rgb.r) * factor)
|
|
163
|
-
const g = Math.round(255 - (255 - rgb.g) * factor)
|
|
164
|
-
const b = Math.round(255 - (255 - rgb.b) * factor)
|
|
165
|
-
colors[i] = this.rgbToHex(r, g, b)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return colors
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** 生成深色变体 */
|
|
172
|
-
generateDarkColors(rgb) {
|
|
173
|
-
const colors = {}
|
|
174
|
-
|
|
175
|
-
for (let i = 1; i <= 2; i++) {
|
|
176
|
-
const factor = i / 10
|
|
177
|
-
const r = Math.round(rgb.r * (1 - factor))
|
|
178
|
-
const g = Math.round(rgb.g * (1 - factor))
|
|
179
|
-
const b = Math.round(rgb.b * (1 - factor))
|
|
180
|
-
colors[i] = this.rgbToHex(r, g, b)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return colors
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** 重置主题 */
|
|
187
|
-
resetTheme() {
|
|
188
|
-
const root = document.documentElement
|
|
189
|
-
root.className = ''
|
|
190
|
-
root.style.cssText = ''
|
|
191
|
-
this.currentTheme = { name: 'default', dark: false }
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** 导出主题配置 */
|
|
195
|
-
exportTheme() {
|
|
196
|
-
const root = document.documentElement
|
|
197
|
-
const computedStyle = getComputedStyle(root)
|
|
198
|
-
const cssVars = {}
|
|
199
|
-
|
|
200
|
-
// 获取所有CSS变量
|
|
201
|
-
for (let i = 0; i < computedStyle.length; i++) {
|
|
202
|
-
const property = computedStyle[i]
|
|
203
|
-
if (property.startsWith('--el-')) {
|
|
204
|
-
cssVars[property] = computedStyle.getPropertyValue(property).trim()
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return JSON.stringify({
|
|
209
|
-
...this.currentTheme,
|
|
210
|
-
cssVars
|
|
211
|
-
}, null, 2)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** 导入主题配置 */
|
|
215
|
-
importTheme(config) {
|
|
216
|
-
try {
|
|
217
|
-
const themeConfig = JSON.parse(config)
|
|
218
|
-
this.setTheme(themeConfig)
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.error('导入主题配置失败:', error)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// 导出主题管理器实例
|
|
226
|
-
export const themeConfigManager = ThemeConfigManager.getInstance()
|
|
227
|
-
|
|
228
|
-
// 导出便捷方法
|
|
229
|
-
export const setTheme = (theme) => themeConfigManager.setTheme(theme)
|
|
230
|
-
export const getTheme = () => themeConfigManager.getTheme()
|
|
231
|
-
export const toggleDark = () => themeConfigManager.toggleDark()
|
|
232
|
-
export const setPrimaryColor = (color) => themeConfigManager.setPrimaryColor(color)
|
|
233
|
-
export const setSuccessColor = (color) => themeConfigManager.setSuccessColor(color)
|
|
234
|
-
export const setWarningColor = (color) => themeConfigManager.setWarningColor(color)
|
|
235
|
-
export const setDangerColor = (color) => themeConfigManager.setDangerColor(color)
|
|
236
|
-
export const setInfoColor = (color) => themeConfigManager.setInfoColor(color)
|
|
237
|
-
export const setCssVar = (name, value) => themeConfigManager.setCssVar(name, value)
|
|
238
|
-
export const getCssVar = (name) => themeConfigManager.getCssVar(name)
|
|
239
|
-
export const resetTheme = () => themeConfigManager.resetTheme()
|
|
240
|
-
export const exportTheme = () => themeConfigManager.exportTheme()
|
|
241
|
-
export const importTheme = (config) => themeConfigManager.importTheme(config)
|