style: 全局代码格式化
Former-commit-id: bb50c8419b8fcdeb48c93fce9f399d901e8f5a52
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function hasClass(ele: HTMLElement, cls: string) {
|
||||
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
|
||||
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ export function hasClass(ele: HTMLElement, cls: string) {
|
||||
* @param {string} cls
|
||||
*/
|
||||
export function addClass(ele: HTMLElement, cls: string) {
|
||||
if (!hasClass(ele, cls)) ele.className += ' ' + cls
|
||||
if (!hasClass(ele, cls)) ele.className += ' ' + cls;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,25 +23,25 @@ export function addClass(ele: HTMLElement, cls: string) {
|
||||
* @param {string} cls
|
||||
*/
|
||||
export function removeClass(ele: HTMLElement, cls: string) {
|
||||
if (hasClass(ele, cls)) {
|
||||
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
|
||||
ele.className = ele.className.replace(reg, ' ')
|
||||
}
|
||||
if (hasClass(ele, cls)) {
|
||||
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);
|
||||
const r1 = parseInt(color1.substring(1, 3), 16);
|
||||
const g1 = parseInt(color1.substring(3, 5), 16);
|
||||
const b1 = parseInt(color1.substring(5, 7), 16);
|
||||
const r2 = parseInt(color2.substring(1, 3), 16);
|
||||
const g2 = parseInt(color2.substring(3, 5), 16);
|
||||
const b2 = parseInt(color2.substring(5, 7), 16);
|
||||
const r = Math.round(r1 * (1 - weight) + r2 * weight);
|
||||
const g = Math.round(g1 * (1 - weight) + g2 * weight);
|
||||
const 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;
|
||||
weight = Math.max(Math.min(Number(weight), 1), 0);
|
||||
const r1 = parseInt(color1.substring(1, 3), 16);
|
||||
const g1 = parseInt(color1.substring(3, 5), 16);
|
||||
const b1 = parseInt(color1.substring(5, 7), 16);
|
||||
const r2 = parseInt(color2.substring(1, 3), 16);
|
||||
const g2 = parseInt(color2.substring(3, 5), 16);
|
||||
const b2 = parseInt(color2.substring(5, 7), 16);
|
||||
const r = Math.round(r1 * (1 - weight) + r2 * weight);
|
||||
const g = Math.round(g1 * (1 - weight) + g2 * weight);
|
||||
const 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user