@blocklet/pages-kit 0.6.98 → 0.6.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ export const isBrowserEnv = () => {
8
8
  */
9
9
  export function isMuiColorKey(value) {
10
10
  // special case
11
- if (value === 'transparent' || value === 'divider') {
11
+ if (value === 'transparent' || value === 'divider' || value === 'auto') {
12
12
  return true;
13
13
  }
14
14
  return /^(primary|secondary|error|warning|info|success|grey|background|text|action|common)\.[a-zA-Z0-9]+$/.test(value);
@@ -38,7 +38,7 @@ export function isColorString(color) {
38
38
  if (typeof color !== 'string') {
39
39
  return false;
40
40
  }
41
- if (isGradient(color)) {
41
+ if (isGradient(color) || color === 'auto') {
42
42
  return true;
43
43
  }
44
44
  const currentColor = tinycolor(color);
@@ -128,6 +128,19 @@ export function parseColor(color = '') {
128
128
  }
129
129
  return color;
130
130
  }
131
+ export const gradientFromPrimary = (opts = {}) => (theme) => {
132
+ const { angle = '135deg', hueShift = 35 } = opts;
133
+ // 取 primary.main -> HSL(tinycolor 的 s/l 为 0~1)
134
+ const base = tinycolor(theme.palette.primary.main).toHsl();
135
+ const clampHue = (h) => ((h % 360) + 360) % 360;
136
+ const h1 = clampHue(base.h);
137
+ const h2 = clampHue(base.h - hueShift);
138
+ const alpha = theme.palette.mode === 'light' ? 0.12 : 0.24;
139
+ // 生成两端色(只改 H,S/L 不变;统一用目标 alpha)
140
+ const c1 = tinycolor({ h: h1, s: base.s, l: base.l, a: alpha }).toHslString(); // hsla(h, s%, l%, a)
141
+ const c2 = tinycolor({ h: h2, s: base.s, l: base.l, a: alpha }).toHslString();
142
+ return `linear-gradient(${angle}, ${c1} 0%, ${c2} 100%)`;
143
+ };
131
144
  /**
132
145
  * 转换颜色
133
146
  * @param color - 颜色字符串
@@ -23,4 +23,17 @@ export declare function useMuiColorPalette(): {
23
23
  * React Hook,用于实时转换颜色值(包括MUI主题色键)
24
24
  */
25
25
  export declare function useColorConvert(): (color?: string) => string;
26
+ export declare function useBackgroundColorStyle(): {
27
+ getBackgroundColorStyle: (color?: string) => {
28
+ backgroundImage: (theme: import("@mui/material/styles").Theme) => string;
29
+ bgcolor?: undefined;
30
+ } | {
31
+ backgroundImage: string;
32
+ bgcolor?: undefined;
33
+ } | {
34
+ bgcolor: string;
35
+ backgroundImage?: undefined;
36
+ };
37
+ getBackgroundColor: (color?: string) => string | ((theme: import("@mui/material/styles").Theme) => string);
38
+ };
26
39
  export {};