shared.uts 961 B

123456789101112131415161718192021222324
  1. import { TinyColor, generate } from '@/uni_modules/lime-color';
  2. import { LGenerateOptions } from '@/uni_modules/lime-color/utssdk/interface';
  3. export const getAlphaColor = (baseColor : string, alpha : number) : string =>
  4. new TinyColor(baseColor).setAlpha(alpha).toRgbString();
  5. export const getSolidColor = (baseColor : string, brightness : number) : string => {
  6. const instance = new TinyColor(baseColor);
  7. return instance.lighten(brightness).toHexString();
  8. };
  9. export function generateColorPalettes(baseColor : string | null, name : string, theme: string = 'default') : UTSJSONObject {
  10. if (baseColor == null) return {}
  11. const colors = generate(baseColor, { theme } as LGenerateOptions);
  12. const colorPalettes = colors.reduce((prev:UTSJSONObject, color:string, index:number) : UTSJSONObject => {
  13. prev[`${name}${index + 1}`] = color;
  14. return prev
  15. }, {})
  16. // 默认为中间色
  17. colorPalettes[name] = colorPalettes[`${name}${6}`]
  18. return colorPalettes
  19. }