starry-sky-ui 0.1.1 → 0.3.1
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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/event.d.ts +51 -0
- package/dist/utils/event.d.ts.map +1 -0
- package/dist/utils/event.js +88 -0
- package/dist/utils/event.js.map +1 -0
- package/dist/utils/file.d.ts +69 -0
- package/dist/utils/file.d.ts.map +1 -0
- package/dist/utils/file.js +137 -0
- package/dist/utils/file.js.map +1 -0
- package/dist/utils/image.d.ts +60 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +203 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/types.d.ts +28 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +3 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +14 -2
package/dist/index.d.ts
CHANGED
|
@@ -19,4 +19,6 @@ export type { ContentRendererProps } from './ContentRenderer';
|
|
|
19
19
|
export { default as ChatInput } from './ChatInput';
|
|
20
20
|
export type { ChatInputProps } from './ChatInput';
|
|
21
21
|
export type { MessageInstance as MessageType, SelectOption as SelectOptionType, ModalProps as ModalPropsType } from './types';
|
|
22
|
+
import * as adUtils from './utils';
|
|
23
|
+
export { adUtils };
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEl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E,MAAM,aAAa,CAAC;AAElD,YAAY,EAAE,eAAe,IAAI,WAAW,EAAE,YAAY,IAAI,gBAAgB,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9H,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,4 +8,7 @@ export { default as Input } from './Input';
|
|
|
8
8
|
export { default as Textarea } from './Input/Textarea';
|
|
9
9
|
export { default as ContentRenderer } from './ContentRenderer';
|
|
10
10
|
export { default as ChatInput } from './ChatInput';
|
|
11
|
+
// 工具函数统一导出
|
|
12
|
+
import * as adUtils from './utils';
|
|
13
|
+
export { adUtils };
|
|
11
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAKnD,WAAW;AACX,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ThrottleOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 防抖函数
|
|
4
|
+
*
|
|
5
|
+
* 在指定延迟内连续调用只执行最后一次。
|
|
6
|
+
*
|
|
7
|
+
* @param fn - 需要防抖的函数
|
|
8
|
+
* @param delay - 延迟时间(ms),默认 300
|
|
9
|
+
* @returns 防抖后的函数
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const handleSearch = debounce((value: string) => {
|
|
14
|
+
* fetchResults(value);
|
|
15
|
+
* }, 500);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function debounce<T extends (...args: any[]) => any>(fn: T, delay?: number): (...args: Parameters<T>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* 节流函数
|
|
21
|
+
*
|
|
22
|
+
* 在指定时间间隔内最多执行一次。
|
|
23
|
+
*
|
|
24
|
+
* @param fn - 需要节流的函数
|
|
25
|
+
* @param interval - 间隔时间(ms),默认 300
|
|
26
|
+
* @param options - 节流选项
|
|
27
|
+
* @returns 节流后的函数
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // trailing 模式(默认):停止触发后还会执行一次
|
|
32
|
+
* const handleScroll = throttle(() => console.log('scroll'), 200);
|
|
33
|
+
*
|
|
34
|
+
* // leading 模式:立即执行第一次
|
|
35
|
+
* const handleClick = throttle(fn, 1000, { leading: true, trailing: false });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, interval?: number, options?: ThrottleOptions): (...args: Parameters<T>) => void;
|
|
39
|
+
/**
|
|
40
|
+
* 异步延迟
|
|
41
|
+
*
|
|
42
|
+
* @param ms - 延迟毫秒数
|
|
43
|
+
* @returns Promise
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* await sleep(1000); // 等待 1 秒
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
51
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/utils/event.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,GAAE,MAAY,GAClB,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAUlC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,QAAQ,GAAE,MAAY,EACtB,OAAO,GAAE,eAAoB,GAC5B,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CA2BlC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// ---- 事件/异步工具函数 ----
|
|
2
|
+
/**
|
|
3
|
+
* 防抖函数
|
|
4
|
+
*
|
|
5
|
+
* 在指定延迟内连续调用只执行最后一次。
|
|
6
|
+
*
|
|
7
|
+
* @param fn - 需要防抖的函数
|
|
8
|
+
* @param delay - 延迟时间(ms),默认 300
|
|
9
|
+
* @returns 防抖后的函数
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const handleSearch = debounce((value: string) => {
|
|
14
|
+
* fetchResults(value);
|
|
15
|
+
* }, 500);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function debounce(fn, delay = 300) {
|
|
19
|
+
let timer = null;
|
|
20
|
+
return (...args) => {
|
|
21
|
+
if (timer !== null)
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timer = setTimeout(() => {
|
|
24
|
+
fn(...args);
|
|
25
|
+
timer = null;
|
|
26
|
+
}, delay);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 节流函数
|
|
31
|
+
*
|
|
32
|
+
* 在指定时间间隔内最多执行一次。
|
|
33
|
+
*
|
|
34
|
+
* @param fn - 需要节流的函数
|
|
35
|
+
* @param interval - 间隔时间(ms),默认 300
|
|
36
|
+
* @param options - 节流选项
|
|
37
|
+
* @returns 节流后的函数
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // trailing 模式(默认):停止触发后还会执行一次
|
|
42
|
+
* const handleScroll = throttle(() => console.log('scroll'), 200);
|
|
43
|
+
*
|
|
44
|
+
* // leading 模式:立即执行第一次
|
|
45
|
+
* const handleClick = throttle(fn, 1000, { leading: true, trailing: false });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function throttle(fn, interval = 300, options = {}) {
|
|
49
|
+
const { leading = false, trailing = true } = options;
|
|
50
|
+
let lastTime = 0;
|
|
51
|
+
let timer = null;
|
|
52
|
+
return (...args) => {
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
if (!lastTime && !leading)
|
|
55
|
+
lastTime = now;
|
|
56
|
+
const remaining = interval - (now - lastTime);
|
|
57
|
+
if (remaining <= 0) {
|
|
58
|
+
if (timer) {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
timer = null;
|
|
61
|
+
}
|
|
62
|
+
fn(...args);
|
|
63
|
+
lastTime = now;
|
|
64
|
+
}
|
|
65
|
+
else if (trailing && !timer) {
|
|
66
|
+
timer = setTimeout(() => {
|
|
67
|
+
fn(...args);
|
|
68
|
+
lastTime = Date.now();
|
|
69
|
+
timer = null;
|
|
70
|
+
}, remaining);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 异步延迟
|
|
76
|
+
*
|
|
77
|
+
* @param ms - 延迟毫秒数
|
|
78
|
+
* @returns Promise
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* await sleep(1000); // 等待 1 秒
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function sleep(ms) {
|
|
86
|
+
return new Promise((resolve) => setTim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d;YACD,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACZ,QAAQ,GAAG,GAAG,CAAC;SAChB;aAAM,IAAI,QAAQ,IAAI,CAAC,KAAK,EAAE;YAC7B,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;gBACZ,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACtB,KAAK,GAAG,IAAI,CAAC;YACf,CAAC,EAAE,SAAS,CAAC,CAAC;SACf;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DownloadOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 将 Blob 转换为 base64 data URL
|
|
4
|
+
*
|
|
5
|
+
* @param blob - 源 Blob
|
|
6
|
+
* @returns base64 data URL
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const dataUrl = await blobToDataURL(blob);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function blobToDataURL(blob: Blob): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* 将 base64 data URL 转换为 Blob
|
|
16
|
+
*
|
|
17
|
+
* @param dataURL - base64 data URL
|
|
18
|
+
* @returns 转换后的 Blob
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const blob = dataURLToBlob('data:image/png;base64,...');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function dataURLToBlob(dataURL: string): Blob;
|
|
26
|
+
/**
|
|
27
|
+
* 触发文件下载
|
|
28
|
+
*
|
|
29
|
+
* @param source - 文件 URL 或 Blob
|
|
30
|
+
* @param options - 下载选项
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // 通过 URL 下载
|
|
35
|
+
* await downloadFile('/api/export/file.xlsx');
|
|
36
|
+
*
|
|
37
|
+
* // 通过 Blob 下载
|
|
38
|
+
* const blob = new Blob([data], { type: 'text/plain' });
|
|
39
|
+
* await downloadFile(blob, { filename: 'data.txt' });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function downloadFile(source: string | Blob, options?: DownloadOptions): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* 读取 File 为 DataURL
|
|
45
|
+
*
|
|
46
|
+
* @param file - 文件对象
|
|
47
|
+
* @returns base64 data URL
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const dataUrl = await readFileAsDataURL(fileInput.files[0]);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function readFileAsDataURL(file: File): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* 格式化文件大小为可读字符串
|
|
57
|
+
*
|
|
58
|
+
* @param bytes - 字节数
|
|
59
|
+
* @param decimals - 小数位数,默认 2
|
|
60
|
+
* @returns 格式化后的文件大小,如 "1.5 MB"
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* formatFileSize(1536); // "1.50 KB"
|
|
65
|
+
* formatFileSize(1048576, 0); // "1 MB"
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function formatFileSize(bytes: number, decimals?: number): string;
|
|
69
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAYnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAO7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAQ1E"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// ---- 文件/Blob 工具函数 ----
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 将 Blob 转换为 base64 data URL
|
|
13
|
+
*
|
|
14
|
+
* @param blob - 源 Blob
|
|
15
|
+
* @returns base64 data URL
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const dataUrl = await blobToDataURL(blob);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function blobToDataURL(blob) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const reader = new FileReader();
|
|
25
|
+
reader.onload = () => resolve(reader.result);
|
|
26
|
+
reader.onerror = () => reject(new Error('Blob 读取失败'));
|
|
27
|
+
reader.readAsDataURL(blob);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 将 base64 data URL 转换为 Blob
|
|
32
|
+
*
|
|
33
|
+
* @param dataURL - base64 data URL
|
|
34
|
+
* @returns 转换后的 Blob
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const blob = dataURLToBlob('data:image/png;base64,...');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function dataURLToBlob(dataURL) {
|
|
42
|
+
var _a;
|
|
43
|
+
const [header, base64] = dataURL.split(',');
|
|
44
|
+
const mime = ((_a = header.match(/:(.*?);/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
45
|
+
const byteStr = atob(base64);
|
|
46
|
+
const len = byteStr.length;
|
|
47
|
+
const bytes = new Uint8Array(len);
|
|
48
|
+
for (let i = 0; i < len; i++) {
|
|
49
|
+
bytes[i] = byteStr.charCodeAt(i);
|
|
50
|
+
}
|
|
51
|
+
return new Blob([bytes], { type: mime });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 触发文件下载
|
|
55
|
+
*
|
|
56
|
+
* @param source - 文件 URL 或 Blob
|
|
57
|
+
* @param options - 下载选项
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // 通过 URL 下载
|
|
62
|
+
* await downloadFile('/api/export/file.xlsx');
|
|
63
|
+
*
|
|
64
|
+
* // 通过 Blob 下载
|
|
65
|
+
* const blob = new Blob([data], { type: 'text/plain' });
|
|
66
|
+
* await downloadFile(blob, { filename: 'data.txt' });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function downloadFile(source, options = {}) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const { filename = 'download', openInNewWindow = false } = options;
|
|
72
|
+
let url;
|
|
73
|
+
if (source instanceof Blob) {
|
|
74
|
+
url = URL.createObjectURL(source);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
url = source;
|
|
78
|
+
}
|
|
79
|
+
const anchor = document.createElement('a');
|
|
80
|
+
anchor.href = url;
|
|
81
|
+
anchor.download = filename;
|
|
82
|
+
anchor.style.display = 'none';
|
|
83
|
+
if (openInNewWindow && typeof source === 'string') {
|
|
84
|
+
window.open(source, '_blank');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
document.body.appendChild(anchor);
|
|
88
|
+
anchor.click();
|
|
89
|
+
document.body.removeChild(anchor);
|
|
90
|
+
// 如果是临时 Blob URL,释放内存
|
|
91
|
+
if (source instanceof Blob) {
|
|
92
|
+
// 给浏览器一点时间处理下载,再释放
|
|
93
|
+
setTimeout(() => URL.revokeObjectURL(url), 10000);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 读取 File 为 DataURL
|
|
99
|
+
*
|
|
100
|
+
* @param file - 文件对象
|
|
101
|
+
* @returns base64 data URL
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const dataUrl = await readFileAsDataURL(fileInput.files[0]);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function readFileAsDataURL(file) {
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const reader = new FileReader();
|
|
111
|
+
reader.onload = () => resolve(reader.result);
|
|
112
|
+
reader.onerror = () => reject(new Error('文件读取失败'));
|
|
113
|
+
reader.readAsDataURL(file);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 格式化文件大小为可读字符串
|
|
118
|
+
*
|
|
119
|
+
* @param bytes - 字节数
|
|
120
|
+
* @param decimals - 小数位数,默认 2
|
|
121
|
+
* @returns 格式化后的文件大小,如 "1.5 MB"
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* formatFileSize(1536); // "1.50 KB"
|
|
126
|
+
* formatFileSize(1048576, 0); // "1 MB"
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function formatFileSize(bytes, decimals = 2) {
|
|
130
|
+
if (bytes === 0)
|
|
131
|
+
return '0 B';
|
|
132
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
133
|
+
const k = 1024;
|
|
134
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
135
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(decimals))} ${units[i]}`;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":"AAAA,yBAAyB;;;;;;;;;;AAIzB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAU;IACtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAgB,CAAC,CAAC;QACvD,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;;I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KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,OAAO,GAAG,UAAU,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ImageCompressOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 获取图片原始尺寸与类型信息
|
|
4
|
+
*
|
|
5
|
+
* 仅读取图片元数据,不进行缩放或编码,适用于上传前预览。
|
|
6
|
+
*
|
|
7
|
+
* @param file - 图片文件
|
|
8
|
+
* @returns 图片信息(宽、高、类型)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const info = await getImageInfo(file);
|
|
13
|
+
* // { width: 1920, height: 1080, type: 'image/jpeg' }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function getImageInfo(file: File | Blob): Promise<{
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
type: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* 压缩/转换图片
|
|
23
|
+
*
|
|
24
|
+
* 支持缩放、格式转换、质量调节,自动检测 WebP 支持并降级。
|
|
25
|
+
*
|
|
26
|
+
* @param file - 源图片文件或 Blob
|
|
27
|
+
* @param options - 压缩选项
|
|
28
|
+
* @returns 压缩后的 Blob
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // 默认压缩(质量 0.75,最大边 1024px,自动选择 webp/jpeg)
|
|
33
|
+
* const blob = await compressImage(file);
|
|
34
|
+
*
|
|
35
|
+
* // 指定质量与尺寸
|
|
36
|
+
* const blob = await compressImage(file, { quality: 0.5, maxDimension: 800 });
|
|
37
|
+
*
|
|
38
|
+
* // 指定输出格式
|
|
39
|
+
* const blob = await compressImage(file, { format: 'image/png', forceFormat: true });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function compressImage(file: File | Blob, options?: ImageCompressOptions): Promise<Blob>;
|
|
43
|
+
/**
|
|
44
|
+
* 纯格式转换(不缩放)
|
|
45
|
+
*
|
|
46
|
+
* 仅改变图片编码格式,保持原始尺寸不变。
|
|
47
|
+
*
|
|
48
|
+
* @param file - 源图片文件或 Blob
|
|
49
|
+
* @param targetFormat - 目标格式
|
|
50
|
+
* @param quality - 质量 (0-1),默认 0.92
|
|
51
|
+
* @returns 转换后的 Blob
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const webpBlob = await convertImageFormat(file, 'image/webp');
|
|
56
|
+
* const jpegBlob = await convertImageFormat(file, 'image/jpeg', 0.8);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function convertImageFormat(file: File | Blob, targetFormat: 'image/webp' | 'image/jpeg' | 'image/png', quality?: number): Promise<Blob>;
|
|
60
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAuIpD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,GAAG,IAAI,GAChB,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAS1D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CA4Bf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,YAAY,EAAE,YAAY,GAAG,YAAY,GAAG,WAAW,EACvD,OAAO,GAAE,MAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// ---- 图片处理工具函数 ----
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
// ==================== WebP 检测(缓存结果) ====================
|
|
12
|
+
/** WebP 支持状态缓存 */
|
|
13
|
+
let _webpSupported = null;
|
|
14
|
+
/**
|
|
15
|
+
* 检测浏览器是否支持 WebP 格式
|
|
16
|
+
*
|
|
17
|
+
* 结果会在首次调用后缓存,避免重复创建 Canvas。
|
|
18
|
+
*/
|
|
19
|
+
function isWebPSupported() {
|
|
20
|
+
if (_webpSupported !== null)
|
|
21
|
+
return _webpSupported;
|
|
22
|
+
const canvas = document.createElement('canvas');
|
|
23
|
+
canvas.width = 1;
|
|
24
|
+
canvas.height = 1;
|
|
25
|
+
const ctx = canvas.getContext('2d');
|
|
26
|
+
if (!ctx) {
|
|
27
|
+
_webpSupported = false;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
ctx.fillStyle = '#fff';
|
|
31
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
32
|
+
_webpSupported = canvas.toDataURL('image/webp').startsWith('data:image/webp');
|
|
33
|
+
return _webpSupported;
|
|
34
|
+
}
|
|
35
|
+
// ==================== 内部辅助 ====================
|
|
36
|
+
/**
|
|
37
|
+
* 将图片 URL 加载为 HTMLImageElement
|
|
38
|
+
*
|
|
39
|
+
* @param url - 图片 URL(支持 blob: data: 等)
|
|
40
|
+
* @returns 加载完成的 Image 对象
|
|
41
|
+
*/
|
|
42
|
+
function loadImage(url) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const img = new Image();
|
|
45
|
+
img.onload = () => resolve(img);
|
|
46
|
+
img.onerror = () => reject(new Error('图片加载失败,请检查文件是否损坏'));
|
|
47
|
+
img.src = url;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 确定最终的输出图片格式
|
|
52
|
+
*
|
|
53
|
+
* - 未指定格式时,优先 webp(若浏览器支持),否则 jpeg
|
|
54
|
+
* - 指定了 webp 但浏览器不支持且未强制格式时,自动降级为 jpeg
|
|
55
|
+
*/
|
|
56
|
+
function resolveOutputFormat(format, forceFormat) {
|
|
57
|
+
if (format) {
|
|
58
|
+
if (!forceFormat && format === 'image/webp' && !isWebPSupported()) {
|
|
59
|
+
console.warn('[compressImage] 浏览器不支持 WebP,降级为 JPEG');
|
|
60
|
+
return 'image/jpeg';
|
|
61
|
+
}
|
|
62
|
+
return format;
|
|
63
|
+
}
|
|
64
|
+
return isWebPSupported() ? 'image/webp' : 'image/jpeg';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 计算缩放后的目标尺寸
|
|
68
|
+
*
|
|
69
|
+
* @returns 缩放后的宽高(整数)
|
|
70
|
+
*/
|
|
71
|
+
function calcDimensions(width, height, maxDimension) {
|
|
72
|
+
if (maxDimension === false || maxDimension <= 0) {
|
|
73
|
+
return { width, height };
|
|
74
|
+
}
|
|
75
|
+
if (width > maxDimension || height > maxDimension) {
|
|
76
|
+
const ratio = Math.min(maxDimension / width, maxDimension / height);
|
|
77
|
+
return {
|
|
78
|
+
width: Math.round(width * ratio),
|
|
79
|
+
height: Math.round(height * ratio),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { width, height };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 将图像绘制到 Canvas 并编码为 Blob
|
|
86
|
+
*/
|
|
87
|
+
function drawToBlob(img, width, height, outputFormat, quality) {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const canvas = document.createElement('canvas');
|
|
90
|
+
canvas.width = width;
|
|
91
|
+
canvas.height = height;
|
|
92
|
+
const ctx = canvas.getContext('2d');
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
reject(new Error('无法获取 Canvas 2D 上下文'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
ctx.imageSmoothingEnabled = true;
|
|
98
|
+
// TS 类型严格模式下需要断言
|
|
99
|
+
ctx.imageSmoothingQuality = 'high';
|
|
100
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
101
|
+
canvas.toBlob((blob) => {
|
|
102
|
+
if (blob) {
|
|
103
|
+
resolve(blob);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(new Error('Canvas 编码失败'));
|
|
107
|
+
}
|
|
108
|
+
}, outputFormat, quality);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// ==================== 公开 API ====================
|
|
112
|
+
/**
|
|
113
|
+
* 获取图片原始尺寸与类型信息
|
|
114
|
+
*
|
|
115
|
+
* 仅读取图片元数据,不进行缩放或编码,适用于上传前预览。
|
|
116
|
+
*
|
|
117
|
+
* @param file - 图片文件
|
|
118
|
+
* @returns 图片信息(宽、高、类型)
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const info = await getImageInfo(file);
|
|
123
|
+
* // { width: 1920, height: 1080, type: 'image/jpeg' }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function getImageInfo(file) {
|
|
127
|
+
const objectURL = URL.createObjectURL(file);
|
|
128
|
+
return loadImage(objectURL)
|
|
129
|
+
.then((img) => ({
|
|
130
|
+
width: img.naturalWidth,
|
|
131
|
+
height: img.naturalHeight,
|
|
132
|
+
type: file.type || 'image/png',
|
|
133
|
+
}))
|
|
134
|
+
.finally(() => URL.revokeObjectURL(objectURL));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 压缩/转换图片
|
|
138
|
+
*
|
|
139
|
+
* 支持缩放、格式转换、质量调节,自动检测 WebP 支持并降级。
|
|
140
|
+
*
|
|
141
|
+
* @param file - 源图片文件或 Blob
|
|
142
|
+
* @param options - 压缩选项
|
|
143
|
+
* @returns 压缩后的 Blob
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* // 默认压缩(质量 0.75,最大边 1024px,自动选择 webp/jpeg)
|
|
148
|
+
* const blob = await compressImage(file);
|
|
149
|
+
*
|
|
150
|
+
* // 指定质量与尺寸
|
|
151
|
+
* const blob = await compressImage(file, { quality: 0.5, maxDimension: 800 });
|
|
152
|
+
*
|
|
153
|
+
* // 指定输出格式
|
|
154
|
+
* const blob = await compressImage(file, { format: 'image/png', forceFormat: true });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function compressImage(file, options = {}) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const { quality = 0.75, maxDimension = 1024, format, forceFormat = false, } = options;
|
|
160
|
+
// 确定输出格式
|
|
161
|
+
const outputFormat = resolveOutputFormat(format, forceFormat);
|
|
162
|
+
const objectURL = URL.createObjectURL(file);
|
|
163
|
+
try {
|
|
164
|
+
const img = yield loadImage(objectURL);
|
|
165
|
+
const { width, height } = calcDimensions(img.naturalWidth, img.naturalHeight, maxDimension);
|
|
166
|
+
return yield drawToBlob(img, width, height, outputFormat, quality);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
170
|
+
throw new Error(`图片处理失败: ${msg}`);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
URL.revokeObjectURL(objectURL);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 纯格式转换(不缩放)
|
|
179
|
+
*
|
|
180
|
+
* 仅改变图片编码格式,保持原始尺寸不变。
|
|
181
|
+
*
|
|
182
|
+
* @param file - 源图片文件或 Blob
|
|
183
|
+
* @param targetFormat - 目标格式
|
|
184
|
+
* @param quality - 质量 (0-1),默认 0.92
|
|
185
|
+
* @returns 转换后的 Blob
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const webpBlob = await convertImageFormat(file, 'image/webp');
|
|
190
|
+
* const jpegBlob = await convertImageFormat(file, 'image/jpeg', 0.8);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export function convertImageFormat(file, targetFormat, quality = 0.92) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
return compressImage(file, {
|
|
196
|
+
format: targetFormat,
|
|
197
|
+
maxDimension: false,
|
|
198
|
+
quality,
|
|
199
|
+
forceFormat: true,
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AAAA,qBAAqB;;;;;;;;;;AAIrB,0DAA0D;AAE1D,kBAAkB;AAClB,IAAI,cAAc,GAAmB,IAAI,CAAC;AAE1C;;;;GAIG;AACH,SAAS,eAAe;IACtB,IAAI,cAAc,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC;IAEnD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAA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G,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;YACvC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,cAAc,CACtC,GAAG,CAAC,YAAY,EAChB,GAAG,CAAC,aAAa,EACjB,YAAY,CACb,CAAC;YAEF,OAAO,MAAM,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;SACpE;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;SACnC;gBAAS;YACR,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;SAChC;IACH,CAAC;CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAgB,kBAAkB,CACtC,IAAiB,EACjB,YAAuD,EACvD,UAAkB,IAAI;;QAEtB,OAAO,aAAa,CAAC,IAAI,EAAE;YACzB,MAAM,EAAE,YAAY;YACpB,YAAY,EAAE,KAAK;YACnB,OAAO;YACP,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { blobToDataURL, dataURLToBlob, downloadFile, readFileAsDataURL, formatFileSize, } from './file';
|
|
2
|
+
export type { DownloadOptions } from './types';
|
|
3
|
+
export { getImageInfo, compressImage, convertImageFormat, } from './image';
|
|
4
|
+
export type { ImageCompressOptions } from './types';
|
|
5
|
+
export { debounce, throttle, sleep, } from './event';
|
|
6
|
+
export type { ThrottleOptions } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,GACf,MAAM,QAAQ,CAAC;AAChB,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpD,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// ---- AdUI 通用工具函数统一导出 ----
|
|
2
|
+
// 文件工具
|
|
3
|
+
export { blobToDataURL, dataURLToBlob, downloadFile, readFileAsDataURL, formatFileSize, } from './file';
|
|
4
|
+
// 图片工具
|
|
5
|
+
export { getImageInfo, compressImage, convertImageFormat, } from './image';
|
|
6
|
+
// 事件工具
|
|
7
|
+
export { debounce, throttle, sleep, } from './event';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAE5B,OAAO;AACP,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,GACf,MAAM,QAAQ,CAAC;AAGhB,OAAO;AACP,OAAO,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO;AACP,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** 可选的回调函数 */
|
|
2
|
+
export type Callback = () => void;
|
|
3
|
+
/** 防抖/节流选项 */
|
|
4
|
+
export interface ThrottleOptions {
|
|
5
|
+
/** 是否在首次调用时立即执行,默认 false */
|
|
6
|
+
leading?: boolean;
|
|
7
|
+
/** 是否在最后一次调用后延迟执行,默认 false */
|
|
8
|
+
trailing?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** 文件下载选项 */
|
|
11
|
+
export interface DownloadOptions {
|
|
12
|
+
/** 保存的文件名(含扩展名) */
|
|
13
|
+
filename?: string;
|
|
14
|
+
/** 是否在新窗口打开,默认 false(仅 URL 下载时有效) */
|
|
15
|
+
openInNewWindow?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 图片压缩/转换选项 */
|
|
18
|
+
export interface ImageCompressOptions {
|
|
19
|
+
/** 压缩质量 (0-1),默认 0.75 */
|
|
20
|
+
quality?: number;
|
|
21
|
+
/** 最大宽/高尺寸(px),设为 false 不缩放,默认 1024 */
|
|
22
|
+
maxDimension?: number | false;
|
|
23
|
+
/** 输出格式,默认根据浏览器支持自动选择 webp/jpeg */
|
|
24
|
+
format?: 'image/webp' | 'image/jpeg' | 'image/png';
|
|
25
|
+
/** 是否强制使用指定格式(不降级),默认 false */
|
|
26
|
+
forceFormat?: boolean;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAEA,cAAc;AACd,MAAM,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC;AAElC,cAAc;AACd,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,aAAa;AACb,MAAM,WAAW,eAAe;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9B,mCAAmC;IACnC,MAAM,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;IACnD,+BAA+B;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,0BAA0B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starry-sky-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "starry-sky-ui — 轻量级 React UI 组件库",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,10 +8,22 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://gitee.com/qqqsdx/starry-sky-ui.git"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react",
|
|
13
|
+
"ui",
|
|
14
|
+
"components",
|
|
15
|
+
"typescript"
|
|
16
|
+
],
|
|
12
17
|
"main": "dist/index.js",
|
|
13
18
|
"module": "dist/index.js",
|
|
14
19
|
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
15
27
|
"files": [
|
|
16
28
|
"dist",
|
|
17
29
|
"README.md"
|