@zl-ui-kit/theme 0.5.0 → 0.6.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/README.md +7 -7
- package/dist/index.d.ts +10 -2
- package/dist/index.js +31 -13
- package/package.json +1 -1
- package/src/generated/theme-blue.css +51 -40
- package/src/generated/theme-dark.css +61 -50
- package/src/generated/theme-light.css +51 -40
- package/src/generated/theme-red-dark.css +61 -50
- package/src/generated/theme-red-light.css +51 -40
- package/src/generated/themes.css +275 -220
- package/src/runtime/api.ts +27 -17
- package/src/runtime/colors.ts +23 -8
package/src/runtime/colors.ts
CHANGED
|
@@ -8,8 +8,15 @@ export function parseColor(str: string): [number, number, number] | null {
|
|
|
8
8
|
if (s.startsWith('#')) {
|
|
9
9
|
let hex = s.slice(1)
|
|
10
10
|
if (hex.length === 3)
|
|
11
|
-
hex = hex
|
|
12
|
-
|
|
11
|
+
hex = hex
|
|
12
|
+
.split('')
|
|
13
|
+
.map((c) => c + c)
|
|
14
|
+
.join('')
|
|
15
|
+
return [
|
|
16
|
+
Number.parseInt(hex.slice(0, 2), 16),
|
|
17
|
+
Number.parseInt(hex.slice(2, 4), 16),
|
|
18
|
+
Number.parseInt(hex.slice(4, 6), 16),
|
|
19
|
+
]
|
|
13
20
|
}
|
|
14
21
|
const m = s.match(/rgba?\(([^)]+)\)/)
|
|
15
22
|
if (m) {
|
|
@@ -31,8 +38,7 @@ export function toHex([r, g, b]: [number, number, number]): string {
|
|
|
31
38
|
export function mix(color1: string, color2: string, weight: number): string {
|
|
32
39
|
const c1 = parseColor(color1)
|
|
33
40
|
const c2 = parseColor(color2)
|
|
34
|
-
if (!c1 || !c2)
|
|
35
|
-
return color1
|
|
41
|
+
if (!c1 || !c2) return color1
|
|
36
42
|
const w = weight / 100
|
|
37
43
|
return toHex([c1[0] * (1 - w) + c2[0] * w, c1[1] * (1 - w) + c2[1] * w, c1[2] * (1 - w) + c2[2] * w])
|
|
38
44
|
}
|
|
@@ -50,12 +56,21 @@ export interface ElColorShades {
|
|
|
50
56
|
'dark-2': string
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
59
|
+
/**
|
|
60
|
+
* EP 主色色阶:**light-n 中 n 越大越"靠背景"** ——
|
|
61
|
+
* 浅色主题往白走(light-9 ≈ 混 90% 白),深色主题往黑走(light-9 ≈ 混 90% 黑);
|
|
62
|
+
* dark-2 则相反:浅色下更深(混黑),深色下更浅(混白)。
|
|
63
|
+
*
|
|
64
|
+
* ⚠️ mix(c1, c2, w) 的 w 是"混入 c2 的比例",与 light-n 的 n 方向相反,
|
|
65
|
+
* 故必须用 (10 - i) * 10。写成 i * 10 会颠倒色阶,导致 el-tag / el-message /
|
|
66
|
+
* el-alert 的 light-9 背景变深、与同色系文字几乎同色("灰蒙蒙看不清")。
|
|
67
|
+
*/
|
|
68
|
+
export function generateElShades(hex: string, isDark = false): ElColorShades {
|
|
55
69
|
const shades = {} as ElColorShades
|
|
70
|
+
const toBg = isDark ? '#000000' : '#ffffff'
|
|
56
71
|
for (let i = 1; i <= 9; i++) {
|
|
57
|
-
shades[`light-${i}` as keyof ElColorShades] = mix(
|
|
72
|
+
shades[`light-${i}` as keyof ElColorShades] = mix(toBg, hex, (10 - i) * 10)
|
|
58
73
|
}
|
|
59
|
-
shades['dark-2'] = mix('#000000', hex, 20)
|
|
74
|
+
shades['dark-2'] = mix(isDark ? '#ffffff' : '#000000', hex, 20)
|
|
60
75
|
return shades
|
|
61
76
|
}
|