feat: 系统设置添加主题动态切换

This commit is contained in:
郝先瑞
2022-03-01 23:45:07 +08:00
parent 108aeeb43a
commit a6882db1dd
9 changed files with 170 additions and 56 deletions

View File

@@ -27,4 +27,21 @@ export function removeClass(ele: HTMLElement, cls: string) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
ele.className = ele.className.replace(reg, ' ')
}
}
}
export function mix(color1: string, color2: string, weight: number) {
weight = Math.max(Math.min(Number(weight), 1), 0);
let r1 = parseInt(color1.substring(1, 3), 16);
let g1 = parseInt(color1.substring(3, 5), 16);
let b1 = parseInt(color1.substring(5, 7), 16);
let r2 = parseInt(color2.substring(1, 3), 16);
let g2 = parseInt(color2.substring(3, 5), 16);
let b2 = parseInt(color2.substring(5, 7), 16);
let r = Math.round(r1 * (1 - weight) + r2 * weight);
let g = Math.round(g1 * (1 - weight) + g2 * weight);
let b = Math.round(b1 * (1 - weight) + b2 * weight);
const rStr = ("0" + (r || 0).toString(16)).slice(-2);
const gStr = ("0" + (g || 0).toString(16)).slice(-2);
const bStr = ("0" + (b || 0).toString(16)).slice(-2);
return "#" + rStr + gStr + bStr;
};