@minilo/utils 0.0.4 → 0.0.6

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.
Files changed (74) hide show
  1. package/dist/config/config.d.ts +3 -3
  2. package/dist/config/config.js +20 -20
  3. package/dist/config/guider.d.ts +51 -67
  4. package/dist/config/guider.js +55 -52
  5. package/dist/config/index.d.ts +6 -6
  6. package/dist/config/index.js +6 -6
  7. package/dist/config/storageManager.d.ts +41 -41
  8. package/dist/config/storageManager.js +100 -92
  9. package/dist/config/types.d.ts +18 -18
  10. package/dist/config/types.js +2 -2
  11. package/dist/config/updateCssVariables.d.ts +11 -14
  12. package/dist/config/updateCssVariables.js +77 -79
  13. package/dist/constrant/index.d.ts +5 -5
  14. package/dist/constrant/index.js +11 -11
  15. package/dist/func/color.d.ts +5 -5
  16. package/dist/func/color.js +10 -10
  17. package/dist/func/common.d.ts +8 -15
  18. package/dist/func/common.js +58 -54
  19. package/dist/func/index.d.ts +4 -4
  20. package/dist/func/index.js +4 -4
  21. package/dist/func/merge.d.ts +2 -2
  22. package/dist/func/merge.js +2 -2
  23. package/dist/hooks/helper.d.ts +6 -0
  24. package/dist/hooks/helper.d.ts.map +1 -0
  25. package/dist/hooks/helper.js +45 -0
  26. package/dist/hooks/helper.js.map +1 -0
  27. package/dist/hooks/index.d.ts +4 -4
  28. package/dist/hooks/index.d.ts.map +1 -1
  29. package/dist/hooks/index.js +4 -4
  30. package/dist/hooks/index.js.map +1 -1
  31. package/dist/hooks/useChartResize.d.ts +20 -0
  32. package/dist/hooks/useChartResize.d.ts.map +1 -0
  33. package/dist/hooks/useChartResize.js +67 -0
  34. package/dist/hooks/useChartResize.js.map +1 -0
  35. package/dist/hooks/useCountDown.d.ts +9 -0
  36. package/dist/hooks/useCountDown.d.ts.map +1 -0
  37. package/dist/hooks/useCountDown.js +42 -0
  38. package/dist/hooks/useCountDown.js.map +1 -0
  39. package/dist/hooks/useFormAutoSave.d.ts +2 -0
  40. package/dist/hooks/useFormAutoSave.d.ts.map +1 -0
  41. package/dist/hooks/useFormAutoSave.js +73 -0
  42. package/dist/hooks/useFormAutoSave.js.map +1 -0
  43. package/dist/hooks/useRouteCache.d.ts +2 -0
  44. package/dist/hooks/useRouteCache.d.ts.map +1 -0
  45. package/dist/hooks/useRouteCache.js +92 -0
  46. package/dist/hooks/useRouteCache.js.map +1 -0
  47. package/dist/hooks/useScroll.d.ts +15 -0
  48. package/dist/hooks/useScroll.d.ts.map +1 -0
  49. package/dist/hooks/useScroll.js +71 -0
  50. package/dist/hooks/useScroll.js.map +1 -0
  51. package/dist/hooks/useUpload.d.ts +17 -0
  52. package/dist/hooks/useUpload.d.ts.map +1 -0
  53. package/dist/hooks/useUpload.js +87 -0
  54. package/dist/hooks/useUpload.js.map +1 -0
  55. package/dist/index.d.ts +6 -6
  56. package/dist/index.js +6 -6
  57. package/dist/request/index.d.ts +34 -16
  58. package/dist/request/index.d.ts.map +1 -1
  59. package/dist/request/index.js +131 -132
  60. package/dist/request/index.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +8 -3
  63. package/dist/hooks/useButtonPermission.d.ts +0 -9
  64. package/dist/hooks/useButtonPermission.d.ts.map +0 -1
  65. package/dist/hooks/useButtonPermission.js +0 -38
  66. package/dist/hooks/useButtonPermission.js.map +0 -1
  67. package/dist/hooks/useGuider.d.ts +0 -2
  68. package/dist/hooks/useGuider.d.ts.map +0 -1
  69. package/dist/hooks/useGuider.js +0 -5
  70. package/dist/hooks/useGuider.js.map +0 -1
  71. package/dist/hooks/useInitGlobalStyle.d.ts +0 -2
  72. package/dist/hooks/useInitGlobalStyle.d.ts.map +0 -1
  73. package/dist/hooks/useInitGlobalStyle.js +0 -80
  74. package/dist/hooks/useInitGlobalStyle.js.map +0 -1
@@ -1,16 +1,13 @@
1
- import type { Config } from './types'
2
- declare function executeUpdateCSSVariables(
3
- variables: {
4
- [key: string]: string
5
- },
6
- id?: string
7
- ): void
1
+ import type { Config } from './types';
2
+ declare function executeUpdateCSSVariables(variables: {
3
+ [key: string]: string;
4
+ }, id?: string): void;
8
5
  interface ColorItem {
9
- alias?: string
10
- color?: string
11
- name?: string
6
+ alias?: string;
7
+ color?: string;
8
+ name?: string;
12
9
  }
13
- declare function generatorColorVariables(colorItems: ColorItem[]): Record<string, string>
14
- declare function updateCSSVariables(config: Config): void
15
- export { updateCSSVariables, executeUpdateCSSVariables, generatorColorVariables }
16
- //# sourceMappingURL=updateCssVariables.d.ts.map
10
+ declare function generatorColorVariables(colorItems: ColorItem[]): Record<string, string>;
11
+ declare function updateCSSVariables(config: Config): void;
12
+ export { updateCSSVariables, executeUpdateCSSVariables, generatorColorVariables };
13
+ //# sourceMappingURL=updateCssVariables.d.ts.map
@@ -1,91 +1,89 @@
1
- import { getColors } from 'theme-colors'
2
- import { convertToHsl, TinyColor } from '../func'
1
+ import { getColors } from 'theme-colors';
2
+ import { convertToHsl, TinyColor } from '../func';
3
3
  function executeUpdateCSSVariables(variables, id = '__minilo-styles__') {
4
- // 获取或创建内联样式表元素
5
- const styleElement = document.querySelector(`#${id}`) || document.createElement('style')
6
- styleElement.id = id
7
- // 构建要更新的 CSS 变量的样式文本
8
- let cssText = ':root {'
9
- for (const key in variables) {
10
- if (Object.prototype.hasOwnProperty.call(variables, key)) {
11
- cssText += `${key}: ${variables[key]};`
4
+ // 获取或创建内联样式表元素
5
+ const styleElement = document.querySelector(`#${id}`) || document.createElement('style');
6
+ styleElement.id = id;
7
+ // 构建要更新的 CSS 变量的样式文本
8
+ let cssText = ':root {';
9
+ for (const key in variables) {
10
+ if (Object.prototype.hasOwnProperty.call(variables, key)) {
11
+ cssText += `${key}: ${variables[key]};`;
12
+ }
13
+ }
14
+ cssText += '}';
15
+ // 将样式文本赋值给内联样式表
16
+ styleElement.textContent = cssText;
17
+ // 将内联样式表添加到文档头部
18
+ if (!document.querySelector(`#${id}`)) {
19
+ setTimeout(() => {
20
+ document.head.append(styleElement);
21
+ });
12
22
  }
13
- }
14
- cssText += '}'
15
- // 将样式文本赋值给内联样式表
16
- styleElement.textContent = cssText
17
- // 将内联样式表添加到文档头部
18
- if (!document.querySelector(`#${id}`)) {
19
- setTimeout(() => {
20
- document.head.append(styleElement)
21
- })
22
- }
23
23
  }
24
24
  // 根据某个色值生成色值阶梯对象,key=500时为其默认初始值,也就是默认参数
25
25
  function generatorColorVariables(colorItems) {
26
- const colorVariables = {}
27
- colorItems.forEach(({ alias, color, name }) => {
28
- if (color) {
29
- const colorsMap = getColors(new TinyColor(color).toHexString())
30
- let mainColor = colorsMap['500']
31
- const colorKeys = Object.keys(colorsMap)
32
- colorKeys.forEach((key) => {
33
- const colorValue = colorsMap[key]
34
- if (colorValue) {
35
- const hslColor = convertToHsl(colorValue)
36
- colorVariables[`--${name}-${key}`] = hslColor
37
- if (alias) {
38
- colorVariables[`--${alias}-${key}`] = hslColor
39
- }
40
- if (key === '500') {
41
- mainColor = hslColor
42
- }
26
+ const colorVariables = {};
27
+ colorItems.forEach(({ alias, color, name }) => {
28
+ if (color) {
29
+ const colorsMap = getColors(new TinyColor(color).toHexString());
30
+ let mainColor = colorsMap['500'];
31
+ const colorKeys = Object.keys(colorsMap);
32
+ colorKeys.forEach((key) => {
33
+ const colorValue = colorsMap[key];
34
+ if (colorValue) {
35
+ const hslColor = convertToHsl(colorValue);
36
+ colorVariables[`--${name}-${key}`] = hslColor;
37
+ if (alias) {
38
+ colorVariables[`--${alias}-${key}`] = hslColor;
39
+ }
40
+ if (key === '500') {
41
+ mainColor = hslColor;
42
+ }
43
+ }
44
+ });
45
+ if (alias && mainColor) {
46
+ colorVariables[`--${alias}`] = mainColor;
47
+ }
43
48
  }
44
- })
45
- if (alias && mainColor) {
46
- colorVariables[`--${alias}`] = mainColor
47
- }
48
- }
49
- })
50
- return colorVariables
49
+ });
50
+ return colorVariables;
51
51
  }
52
52
  function updateCSSVariables(config) {
53
- const theme = config?.theme ?? {}
54
- if (
55
- Reflect.has(theme, 'colorPrimary') ||
56
- Reflect.has(theme, 'colorDestructive') ||
57
- Reflect.has(theme, 'colorSuccess') ||
58
- Reflect.has(theme, 'colorWarning')
59
- ) {
60
- updateMainColorVariables(config)
61
- }
53
+ const theme = config?.theme ?? {};
54
+ if (Reflect.has(theme, 'colorPrimary') ||
55
+ Reflect.has(theme, 'colorDestructive') ||
56
+ Reflect.has(theme, 'colorSuccess') ||
57
+ Reflect.has(theme, 'colorWarning')) {
58
+ updateMainColorVariables(config);
59
+ }
62
60
  }
63
61
  function updateMainColorVariables(config) {
64
- if (!config.theme) {
65
- return
66
- }
67
- const { colorDestructive, colorPrimary, colorSuccess, colorWarning } = config.theme
68
- const colorVariables = generatorColorVariables([
69
- { color: colorPrimary, name: 'primary' },
70
- { alias: 'warning', color: colorWarning, name: 'yellow' },
71
- { alias: 'success', color: colorSuccess, name: 'green' },
72
- { alias: 'destructive', color: colorDestructive, name: 'red' }
73
- ])
74
- // 要设置的 CSS 变量映射
75
- const colorMappings = {
76
- '--green-500': '--success',
77
- '--primary-500': '--primary',
78
- '--red-500': '--destructive',
79
- '--yellow-500': '--warning'
80
- }
81
- // 统一处理颜色变量的更新
82
- Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => {
83
- const colorValue = colorVariables[sourceVar]
84
- if (colorValue) {
85
- document.documentElement.style.setProperty(targetVar, colorValue)
62
+ if (!config.theme) {
63
+ return;
86
64
  }
87
- })
88
- executeUpdateCSSVariables(colorVariables)
65
+ const { colorDestructive, colorPrimary, colorSuccess, colorWarning } = config.theme;
66
+ const colorVariables = generatorColorVariables([
67
+ { color: colorPrimary, name: 'primary' },
68
+ { alias: 'warning', color: colorWarning, name: 'yellow' },
69
+ { alias: 'success', color: colorSuccess, name: 'green' },
70
+ { alias: 'destructive', color: colorDestructive, name: 'red' }
71
+ ]);
72
+ // 要设置的 CSS 变量映射
73
+ const colorMappings = {
74
+ '--green-500': '--success',
75
+ '--primary-500': '--primary',
76
+ '--red-500': '--destructive',
77
+ '--yellow-500': '--warning'
78
+ };
79
+ // 统一处理颜色变量的更新
80
+ Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => {
81
+ const colorValue = colorVariables[sourceVar];
82
+ if (colorValue) {
83
+ document.documentElement.style.setProperty(targetVar, colorValue);
84
+ }
85
+ });
86
+ executeUpdateCSSVariables(colorVariables);
89
87
  }
90
- export { updateCSSVariables, executeUpdateCSSVariables, generatorColorVariables }
91
- //# sourceMappingURL=updateCssVariables.js.map
88
+ export { updateCSSVariables, executeUpdateCSSVariables, generatorColorVariables };
89
+ //# sourceMappingURL=updateCssVariables.js.map
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @zh_CN 登录页面 url 地址
3
3
  */
4
- export declare const LOGIN_PATH = '/auth/login'
4
+ export declare const LOGIN_PATH = "/auth/login";
5
5
  export interface LanguageOption {
6
- label: string
7
- value: 'en-US' | 'zh-CN'
6
+ label: string;
7
+ value: 'en-US' | 'zh-CN';
8
8
  }
9
9
  /**
10
10
  * Supported languages
11
11
  */
12
- export declare const SUPPORT_LANGUAGES: LanguageOption[]
13
- //# sourceMappingURL=index.d.ts.map
12
+ export declare const SUPPORT_LANGUAGES: LanguageOption[];
13
+ //# sourceMappingURL=index.d.ts.map
@@ -1,18 +1,18 @@
1
1
  /**
2
2
  * @zh_CN 登录页面 url 地址
3
3
  */
4
- export const LOGIN_PATH = '/auth/login'
4
+ export const LOGIN_PATH = '/auth/login';
5
5
  /**
6
6
  * Supported languages
7
7
  */
8
8
  export const SUPPORT_LANGUAGES = [
9
- {
10
- label: '简体中文',
11
- value: 'zh-CN'
12
- },
13
- {
14
- label: 'English',
15
- value: 'en-US'
16
- }
17
- ]
18
- //# sourceMappingURL=index.js.map
9
+ {
10
+ label: '简体中文',
11
+ value: 'zh-CN'
12
+ },
13
+ {
14
+ label: 'English',
15
+ value: 'en-US'
16
+ }
17
+ ];
18
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import { TinyColor } from '@ctrl/tinycolor'
2
- declare function convertToHsl(color: string): string
1
+ import { TinyColor } from '@ctrl/tinycolor';
2
+ declare function convertToHsl(color: string): string;
3
3
  /**
4
4
  * 将颜色转换为RGB颜色字符串
5
5
  * TinyColor无法处理hsl内包含'deg'、'grad'、'rad'或'turn'的字符串
@@ -8,6 +8,6 @@ declare function convertToHsl(color: string): string
8
8
  * @param str 表示HLS颜色值的字符串
9
9
  * @returns 如果颜色值有效,则返回对应的RGB颜色字符串;如果无效,则返回rgb(0, 0, 0)
10
10
  */
11
- declare function convertToRgb(str: string): string
12
- export { convertToHsl, convertToRgb, TinyColor }
13
- //# sourceMappingURL=color.d.ts.map
11
+ declare function convertToRgb(str: string): string;
12
+ export { convertToHsl, convertToRgb, TinyColor };
13
+ //# sourceMappingURL=color.d.ts.map
@@ -1,12 +1,12 @@
1
- import { TinyColor } from '@ctrl/tinycolor'
1
+ import { TinyColor } from '@ctrl/tinycolor';
2
2
  // 将颜色转换为HSL格式
3
3
  function convertToHsl(color) {
4
- // 使用TinyColor库将颜色转换为HSL格式
5
- const { a, h, l, s } = new TinyColor(color).toHsl()
6
- // 将HSL格式转换为字符串
7
- const hsl = `hsl(${Math.round(h)} ${Math.round(s * 100)}% ${Math.round(l * 100)}%)`
8
- // 如果颜色的透明度小于1,则返回带有透明度的HSL格式
9
- return a < 1 ? `${hsl} ${a}` : hsl
4
+ // 使用TinyColor库将颜色转换为HSL格式
5
+ const { a, h, l, s } = new TinyColor(color).toHsl();
6
+ // 将HSL格式转换为字符串
7
+ const hsl = `hsl(${Math.round(h)} ${Math.round(s * 100)}% ${Math.round(l * 100)}%)`;
8
+ // 如果颜色的透明度小于1,则返回带有透明度的HSL格式
9
+ return a < 1 ? `${hsl} ${a}` : hsl;
10
10
  }
11
11
  /**
12
12
  * 将颜色转换为RGB颜色字符串
@@ -17,7 +17,7 @@ function convertToHsl(color) {
17
17
  * @returns 如果颜色值有效,则返回对应的RGB颜色字符串;如果无效,则返回rgb(0, 0, 0)
18
18
  */
19
19
  function convertToRgb(str) {
20
- return new TinyColor(str.replaceAll(/deg|grad|rad|turn/g, '')).toRgbString()
20
+ return new TinyColor(str.replaceAll(/deg|grad|rad|turn/g, '')).toRgbString();
21
21
  }
22
- export { convertToHsl, convertToRgb, TinyColor }
23
- //# sourceMappingURL=color.js.map
22
+ export { convertToHsl, convertToRgb, TinyColor };
23
+ //# sourceMappingURL=color.js.map
@@ -1,4 +1,4 @@
1
- import type { MenuDataItem, BreadcrumbItem, OptionItem } from '@minilo/types'
1
+ import type { MenuDataItem, BreadcrumbItem, OptionItem } from '@minilo/types';
2
2
  /**
3
3
  * @description 判断url是否是http或https
4
4
  * @author xieshuhong
@@ -6,7 +6,7 @@ import type { MenuDataItem, BreadcrumbItem, OptionItem } from '@minilo/types'
6
6
  * @param {string} url
7
7
  * @return {*}
8
8
  */
9
- export declare function isHttp(url: string): boolean
9
+ export declare function isHttp(url: string): boolean;
10
10
  /**
11
11
  * @description 递归查找当前path对应的所有层级路由,为面包屑提供数据
12
12
  * @author xieshuhong
@@ -16,11 +16,7 @@ export declare function isHttp(url: string): boolean
16
16
  * @param {BreadcrumbItem[]} [parentPaths=[]]
17
17
  * @return {*} {BreadcrumbItem[]}
18
18
  */
19
- export declare function findLevelRoutes(
20
- menuList: MenuDataItem[],
21
- targetPath: string,
22
- parentPaths?: BreadcrumbItem[]
23
- ): BreadcrumbItem[]
19
+ export declare function findLevelRoutes(menuList: MenuDataItem[], targetPath: string, parentPaths?: BreadcrumbItem[]): BreadcrumbItem[];
24
20
  /**
25
21
  * @description 查找菜单栏中当前path对应的菜单项
26
22
  * @author xieshuhong
@@ -29,7 +25,7 @@ export declare function findLevelRoutes(
29
25
  * @param {string} targetPath
30
26
  * @return {*} {(MenuDataItem | null)}
31
27
  */
32
- export declare function findMenuItem(items: MenuDataItem[], targetPath: string): MenuDataItem | null
28
+ export declare function findMenuItem(items: MenuDataItem[], targetPath: string): MenuDataItem | null;
33
29
  /**
34
30
  * @description 将options数组转换为对象,渲染
35
31
  * @author xieshuhong
@@ -38,10 +34,7 @@ export declare function findMenuItem(items: MenuDataItem[], targetPath: string):
38
34
  * @param {false} inverse 是否反向转换
39
35
  * @return {*} {(Record<string | number, string>)}
40
36
  */
41
- export declare function transOptionsToObject(
42
- options: OptionItem[],
43
- inverse?: false
44
- ): Record<string | number, string>
37
+ export declare function transOptionsToObject(options: OptionItem[], inverse?: false): Record<string | number, string>;
45
38
  /**
46
39
  * @description 根据多层级键路径从对象中获取值
47
40
  * @author xieshuhong
@@ -50,7 +43,7 @@ export declare function transOptionsToObject(
50
43
  * @param {any} [defaultValue] - 可选,路径不存在时返回的默认值
51
44
  * @returns {any} 路径对应的 value 或 defaultValue
52
45
  */
53
- export declare function getNestedValue(obj: any, path: string, defaultValue?: any): any
46
+ export declare function getNestedValue(obj: any, path: string, defaultValue?: any): any;
54
47
  /**
55
48
  * @description 将驼峰命名法转换为连字符命名法
56
49
  * @author xieshuhong
@@ -58,5 +51,5 @@ export declare function getNestedValue(obj: any, path: string, defaultValue?: an
58
51
  * @param {string} key
59
52
  * @return {*}
60
53
  */
61
- export declare function kebabCase(key: string): string
62
- //# sourceMappingURL=common.d.ts.map
54
+ export declare function kebabCase(key: string): string;
55
+ //# sourceMappingURL=common.d.ts.map
@@ -6,8 +6,8 @@
6
6
  * @return {*}
7
7
  */
8
8
  export function isHttp(url) {
9
- const regex = /^https?:\/\//i
10
- return regex.test(url)
9
+ const regex = /^https?:\/\//i;
10
+ return regex.test(url);
11
11
  }
12
12
  /**
13
13
  * @description 递归查找当前path对应的所有层级路由,为面包屑提供数据
@@ -19,26 +19,27 @@ export function isHttp(url) {
19
19
  * @return {*} {BreadcrumbItem[]}
20
20
  */
21
21
  export function findLevelRoutes(menuList, targetPath, parentPaths = []) {
22
- for (const item of menuList) {
23
- // 当前项的完整路径(父级路径 + 当前path)
24
- const currentPaths = [
25
- ...parentPaths,
26
- {
27
- path: item.path,
28
- name: item.name
29
- }
30
- ]
31
- // 找到目标路径,返回完整层级
32
- if (item.path === targetPath) {
33
- return currentPaths
22
+ for (const item of menuList) {
23
+ // 当前项的完整路径(父级路径 + 当前path)
24
+ const currentPaths = [
25
+ ...parentPaths,
26
+ {
27
+ path: item.path,
28
+ name: item.name
29
+ }
30
+ ];
31
+ // 找到目标路径,返回完整层级
32
+ if (item.path === targetPath) {
33
+ return currentPaths;
34
+ }
35
+ // 有子菜单则递归查找
36
+ if (item.children && item.children.length) {
37
+ const result = findLevelRoutes(item.children, targetPath, currentPaths);
38
+ if (result.length)
39
+ return result;
40
+ }
34
41
  }
35
- // 有子菜单则递归查找
36
- if (item.children && item.children.length) {
37
- const result = findLevelRoutes(item.children, targetPath, currentPaths)
38
- if (result.length) return result
39
- }
40
- }
41
- return [] // 未找到
42
+ return []; // 未找到
42
43
  }
43
44
  /**
44
45
  * @description 查找菜单栏中当前path对应的菜单项
@@ -49,14 +50,16 @@ export function findLevelRoutes(menuList, targetPath, parentPaths = []) {
49
50
  * @return {*} {(MenuDataItem | null)}
50
51
  */
51
52
  export function findMenuItem(items, targetPath) {
52
- for (const item of items) {
53
- if (item.path === targetPath) return item
54
- if (item.children) {
55
- const found = findMenuItem(item.children, targetPath)
56
- if (found) return found
53
+ for (const item of items) {
54
+ if (item.path === targetPath)
55
+ return item;
56
+ if (item.children) {
57
+ const found = findMenuItem(item.children, targetPath);
58
+ if (found)
59
+ return found;
60
+ }
57
61
  }
58
- }
59
- return null
62
+ return null;
60
63
  }
61
64
  /**
62
65
  * @description 将options数组转换为对象,渲染
@@ -67,15 +70,16 @@ export function findMenuItem(items, targetPath) {
67
70
  * @return {*} {(Record<string | number, string>)}
68
71
  */
69
72
  export function transOptionsToObject(options, inverse) {
70
- const obj = {}
71
- options.forEach((item) => {
72
- if (!inverse) {
73
- obj[item.value] = item.label
74
- } else {
75
- obj[item.label] = item.value
76
- }
77
- })
78
- return obj
73
+ const obj = {};
74
+ options.forEach((item) => {
75
+ if (!inverse) {
76
+ obj[item.value] = item.label;
77
+ }
78
+ else {
79
+ obj[item.label] = item.value;
80
+ }
81
+ });
82
+ return obj;
79
83
  }
80
84
  /**
81
85
  * @description 根据多层级键路径从对象中获取值
@@ -86,21 +90,21 @@ export function transOptionsToObject(options, inverse) {
86
90
  * @returns {any} 路径对应的 value 或 defaultValue
87
91
  */
88
92
  export function getNestedValue(obj, path, defaultValue) {
89
- // 处理边界情况:如果obj不是对象或path为空,直接返回默认值
90
- if (typeof obj !== 'object' || obj === null || !path) {
91
- return defaultValue
92
- }
93
- // 将路径按 '.' 分割成数组(支持处理空字符串和连续点的情况)
94
- const keys = path.split('.').filter((key) => key !== '')
95
- // 逐层访问对象属性
96
- return keys.reduce((current, key) => {
97
- // 如果当前值不是对象,直接返回默认值(避免访问非对象的属性)
98
- if (typeof current !== 'object' || current === null) {
99
- return defaultValue
93
+ // 处理边界情况:如果obj不是对象或path为空,直接返回默认值
94
+ if (typeof obj !== 'object' || obj === null || !path) {
95
+ return defaultValue;
100
96
  }
101
- // 访问下一级属性
102
- return current[key] !== undefined ? current[key] : defaultValue
103
- }, obj)
97
+ // 将路径按 '.' 分割成数组(支持处理空字符串和连续点的情况)
98
+ const keys = path.split('.').filter((key) => key !== '');
99
+ // 逐层访问对象属性
100
+ return keys.reduce((current, key) => {
101
+ // 如果当前值不是对象,直接返回默认值(避免访问非对象的属性)
102
+ if (typeof current !== 'object' || current === null) {
103
+ return defaultValue;
104
+ }
105
+ // 访问下一级属性
106
+ return current[key] !== undefined ? current[key] : defaultValue;
107
+ }, obj);
104
108
  }
105
109
  /**
106
110
  * @description 将驼峰命名法转换为连字符命名法
@@ -110,7 +114,7 @@ export function getNestedValue(obj, path, defaultValue) {
110
114
  * @return {*}
111
115
  */
112
116
  export function kebabCase(key) {
113
- const result = key.replace(/([A-Z])/g, ' $1').trim()
114
- return result.split(' ').join('-').toLowerCase()
117
+ const result = key.replace(/([A-Z])/g, ' $1').trim();
118
+ return result.split(' ').join('-').toLowerCase();
115
119
  }
116
- //# sourceMappingURL=common.js.map
120
+ //# sourceMappingURL=common.js.map
@@ -1,4 +1,4 @@
1
- export * from './color'
2
- export * from './merge'
3
- export * from './common'
4
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './color';
2
+ export * from './merge';
3
+ export * from './common';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- export * from './color'
2
- export * from './merge'
3
- export * from './common'
4
- //# sourceMappingURL=index.js.map
1
+ export * from './color';
2
+ export * from './merge';
3
+ export * from './common';
4
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export { defu as merge } from 'defu'
2
- //# sourceMappingURL=merge.d.ts.map
1
+ export { defu as merge } from 'defu';
2
+ //# sourceMappingURL=merge.d.ts.map
@@ -1,2 +1,2 @@
1
- export { defu as merge } from 'defu'
2
- //# sourceMappingURL=merge.js.map
1
+ export { defu as merge } from 'defu';
2
+ //# sourceMappingURL=merge.js.map
@@ -0,0 +1,6 @@
1
+ export declare const compressImage: (file: File, options?: {
2
+ quality?: number;
3
+ maxWidth?: number;
4
+ maxHeight?: number;
5
+ }) => Promise<Blob | File>;
6
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../hooks/helper.ts"],"names":[],"mappings":"AAAA,eAOA,MAAM,aAAa,GACjB,MAAM,IAAI,EACV,UAAS;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,KACxE,OAAO,CAAC,IAAI,GAAG,IAAI,CA2CrB,CAAA"}
@@ -0,0 +1,45 @@
1
+ export /**
2
+ * @description
3
+ * @author xieshuhong
4
+ * @param {File} file 原始文件
5
+ * @param {{ quality?: number; maxWidth?: number; maxHeight?: number }} [options={}] 压缩选项
6
+ * @return {*} {(Promise<Blob | File>)} 压缩后的 Blob
7
+ */ const compressImage = (file, options = {}) => {
8
+ const { quality = 0.8, maxWidth, maxHeight } = options;
9
+ return new Promise((resolve, reject) => {
10
+ const reader = new FileReader();
11
+ reader.readAsDataURL(file);
12
+ reader.onload = (e) => {
13
+ const img = new Image();
14
+ img.src = e.target?.result;
15
+ img.onload = () => {
16
+ const canvas = document.createElement('canvas');
17
+ let width = img.width;
18
+ let height = img.height;
19
+ if (maxWidth && width > maxWidth) {
20
+ height = (maxWidth / width) * height;
21
+ width = maxWidth;
22
+ }
23
+ if (maxHeight && height > maxHeight) {
24
+ width = (maxHeight / height) * width;
25
+ height = maxHeight;
26
+ }
27
+ canvas.width = width;
28
+ canvas.height = height;
29
+ const ctx = canvas.getContext('2d');
30
+ ctx?.drawImage(img, 0, 0, width, height);
31
+ canvas.toBlob((blob) => {
32
+ if (blob) {
33
+ resolve(blob);
34
+ }
35
+ else {
36
+ reject(new Error('图片压缩失败'));
37
+ }
38
+ }, file.type, quality);
39
+ };
40
+ img.onerror = (err) => reject(err);
41
+ };
42
+ reader.onerror = (err) => reject(err);
43
+ });
44
+ };
45
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../hooks/helper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC;;;;;;GAMJ,CACH,MAAM,aAAa,GAAG,CACpB,IAAU,EACV,UAAuE,EAAE,EACnD,EAAE;IACxB,MAAM,EAAE,OAAO,GAAG,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAA;QAC/B,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;QAC1B,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE;YACpB,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAA;YACvB,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,MAAgB,CAAA;YACpC,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE;gBAChB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBAC/C,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAA;gBACrB,IAAI,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;gBAEvB,IAAI,QAAQ,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;oBACjC,MAAM,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,GAAG,MAAM,CAAA;oBACpC,KAAK,GAAG,QAAQ,CAAA;gBAClB,CAAC;gBACD,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,EAAE,CAAC;oBACpC,KAAK,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;oBACpC,MAAM,GAAG,SAAS,CAAA;gBACpB,CAAC;gBAED,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;gBACpB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;gBACtB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;gBACnC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;gBAExC,MAAM,CAAC,MAAM,CACX,CAAC,IAAI,EAAE,EAAE;oBACP,IAAI,IAAI,EAAE,CAAC;wBACT,OAAO,CAAC,IAAI,CAAC,CAAA;oBACf,CAAC;yBAAM,CAAC;wBACN,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;oBAC7B,CAAC;gBACH,CAAC,EACD,IAAI,CAAC,IAAI,EACT,OAAO,CACR,CAAA;YACH,CAAC,CAAA;YACD,GAAG,CAAC,OAAO,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACpC,CAAC,CAAA;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- export * from './useGuider'
2
- export * from './useInitGlobalStyle'
3
- export * from './useButtonPermission'
4
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './useChartResize';
2
+ export * from './useCountDown';
3
+ export * from './useScroll';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA"}
@@ -1,4 +1,4 @@
1
- export * from './useGuider'
2
- export * from './useInitGlobalStyle'
3
- export * from './useButtonPermission'
4
- //# sourceMappingURL=index.js.map
1
+ export * from './useChartResize';
2
+ export * from './useCountDown';
3
+ export * from './useScroll';
4
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA"}