Files
cashier_app/uni_modules/lime-style/token/shared.uts
2025-12-03 10:13:55 +08:00

25 lines
961 B
Plaintext

import { TinyColor, generate } from '@/uni_modules/lime-color';
import { LGenerateOptions } from '@/uni_modules/lime-color/utssdk/interface';
export const getAlphaColor = (baseColor : string, alpha : number) : string =>
new TinyColor(baseColor).setAlpha(alpha).toRgbString();
export const getSolidColor = (baseColor : string, brightness : number) : string => {
const instance = new TinyColor(baseColor);
return instance.lighten(brightness).toHexString();
};
export function generateColorPalettes(baseColor : string | null, name : string, theme: string = 'default') : UTSJSONObject {
if (baseColor == null) return {}
const colors = generate(baseColor, { theme } as LGenerateOptions);
const colorPalettes = colors.reduce((prev:UTSJSONObject, color:string, index:number) : UTSJSONObject => {
prev[`${name}${index + 1}`] = color;
return prev
}, {})
// 默认为中间色
colorPalettes[name] = colorPalettes[`${name}${6}`]
return colorPalettes
}