resource-preloader 2.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/types/index.d.ts +73 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resource-preloader",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "浏览器端资源预加载工具,支持依赖处理、并行/顺序加载、自定义加载器",
5
5
  "keywords": [
6
6
  "preload",
@@ -37,6 +37,7 @@
37
37
  "src",
38
38
  "dist",
39
39
  "package.json",
40
+ "types",
40
41
  "README.md"
41
42
  ],
42
43
  "devDependencies": {
@@ -0,0 +1,73 @@
1
+ // 资源配置类型
2
+ export type ResourceConfig = {
3
+ /** 资源名称/ID */
4
+ name: string;
5
+ /** 资源类型 (js, css, 等) */
6
+ type: string;
7
+ /** 资源URL数组,按优先级顺序 */
8
+ urls: string[];
9
+ /** 依赖的其他资源ID数组 */
10
+ dependencies?: string[];
11
+ } | string| string[];
12
+
13
+ // 加载结果类型
14
+ export interface LoadResult {
15
+ /** 资源URL */
16
+ url: string;
17
+ /** 是否加载成功 */
18
+ success: boolean;
19
+ /** 加载的数据 */
20
+ data: any;
21
+ /** 错误信息 */
22
+ error: Error | null;
23
+ }
24
+
25
+ // 资源加载结果类型
26
+ export interface ResourceLoadResult {
27
+ /** 资源ID */
28
+ resourceId: string;
29
+ /** 原始配置 */
30
+ config: ResourceConfig;
31
+ /** 加载结果 */
32
+ loadResult: LoadResult;
33
+ /** 加载状态 */
34
+ status: 'success' | 'failed';
35
+ /** 错误信息 */
36
+ error: Error | null;
37
+ }
38
+
39
+ // 全局配置类型
40
+ export interface GlobalConfig {
41
+ /** 超时时间(毫秒) */
42
+ timeout: number;
43
+ /** 重试次数 */
44
+ retry: number;
45
+ }
46
+
47
+ // 加载器函数类型
48
+ export type LoaderHandler = (url: string) => Promise<any>;
49
+
50
+ // 核心API类型定义
51
+
52
+ /**
53
+ * 预加载资源的核心方法
54
+ * @param configList - 资源配置数组
55
+ * @returns 加载结果数组的Promise
56
+ */
57
+ export function resourceLoader(configList: ResourceConfig[]): Promise<ResourceLoadResult[]>;
58
+
59
+ /**
60
+ * 注册自定义加载器
61
+ * @param type - 资源类型标识
62
+ * @param handler - 加载处理函数
63
+ */
64
+ export function resourcePreloader(type: string, handler: LoaderHandler): void;
65
+
66
+ /**
67
+ * 设置全局配置
68
+ * @param config - 配置对象
69
+ * @returns 合并后的全局配置
70
+ */
71
+ export function setGlobalConfig(config: Partial<GlobalConfig>): GlobalConfig;
72
+
73
+ export default resourcePreloader;