1
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
type RGBA = { r : number, g : number, b : number, a : number }
|
||||
export function hexToRgb(sColors : string) : RGBA | null {
|
||||
if (sColors == "") {
|
||||
return null
|
||||
}
|
||||
let reg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/;
|
||||
let sColor : string = sColors.toLowerCase();
|
||||
|
||||
if (sColor != '' && reg.test(sColor)) {
|
||||
if (sColor.length == 4) {
|
||||
let sColorNew = "#";
|
||||
for (let i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
||||
}
|
||||
sColor = sColorNew;
|
||||
}
|
||||
|
||||
//处理六位的颜色值
|
||||
let sColorChange : number[] = [];
|
||||
sColorChange.push(parseInt(sColor.substring(1, 3), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(3, 5), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(5, 7), 16));
|
||||
if (sColor.length == 9) {
|
||||
sColorChange.push(parseInt(sColor.substring(7, 9), 16) / 255);
|
||||
}
|
||||
return {
|
||||
r: sColorChange[0],
|
||||
g: sColorChange[1],
|
||||
b: sColorChange[2],
|
||||
a: sColorChange.length == 4 ? sColorChange[3] : 1
|
||||
} as RGBA
|
||||
} else if (/^(rgb|RGB|rgba|RGBA)/.test(sColor)) {
|
||||
let arr : string[] = sColor.replace(/(?:\(|\)|rgba|rgb|RGB|RGBA)*/g, "").split(",")
|
||||
let p : number[] = arr.map((val : string) : number => parseInt(val));
|
||||
|
||||
if (p.length < 3) {
|
||||
return {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1
|
||||
} as RGBA
|
||||
}
|
||||
if (p.length == 3) {
|
||||
p.add(1)
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
r: p[0],
|
||||
g: p[1],
|
||||
b: p[2],
|
||||
a: arr.length==3?p[3]:parseFloat(arr[3])
|
||||
} as RGBA
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { XLOADINGS_TYPE, XLOADINGS_TYPE_PRIVATE } from "../interface.uts"
|
||||
export const defaultConfig = {
|
||||
iconColor:'rgb(5,121,255)',
|
||||
contentBgColor:'rgba(255,255,255,1)',
|
||||
maskBgColor:'rgba(0,0,0,0.6)',
|
||||
iconSize:36,
|
||||
iconCode:'EEC4',
|
||||
title:'',
|
||||
titleSize:12,
|
||||
titleColor:'#a0a1a7',
|
||||
size:100
|
||||
} as XLOADINGS_TYPE_PRIVATE
|
||||
|
||||
export function configCover(opts : XLOADINGS_TYPE) : XLOADINGS_TYPE_PRIVATE {
|
||||
let iconColor = opts.iconColor != null ? (opts.iconColor!) : defaultConfig.iconColor;
|
||||
let contentBgColor = opts.contentBgColor != null ? (opts.contentBgColor!) : defaultConfig.contentBgColor;
|
||||
let maskBgColor = opts.maskBgColor != null ? (opts.maskBgColor!) : defaultConfig.maskBgColor;
|
||||
let iconSize = opts.iconSize != null ? (opts.iconSize!) : defaultConfig.iconSize;
|
||||
let iconCode = opts.iconCode != null ? (opts.iconCode!) : defaultConfig.iconCode;
|
||||
let title = opts.title != null ? (opts.title!) : defaultConfig.title;
|
||||
let titleSize = opts.titleSize != null ? (opts.titleSize!) : defaultConfig.titleSize;
|
||||
let titleColor = opts.titleColor != null ? (opts.titleColor!) : defaultConfig.titleColor;
|
||||
let size = opts.size != null ? (opts.size!) : defaultConfig.size;
|
||||
|
||||
return {
|
||||
iconColor,
|
||||
contentBgColor,
|
||||
maskBgColor,
|
||||
iconSize,
|
||||
iconCode,title,titleSize,titleColor,size
|
||||
} as XLOADINGS_TYPE_PRIVATE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user