@vlian/framework 1.2.19 → 1.2.37
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/analytics.umd.js +208 -2395
- package/dist/analytics.umd.js.map +1 -1
- package/dist/core/error/ErrorHandler.cjs.map +1 -1
- package/dist/core/error/ErrorHandler.d.ts +1 -1
- package/dist/core/error/ErrorHandler.js.map +1 -1
- package/dist/core/index.cjs +0 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +0 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/initialization/index.cjs.map +1 -1
- package/dist/core/initialization/index.d.ts +1 -1
- package/dist/core/initialization/index.js.map +1 -1
- package/dist/core/initialization/initialization.cjs +2 -147
- package/dist/core/initialization/initialization.cjs.map +1 -1
- package/dist/core/initialization/initialization.d.ts +0 -57
- package/dist/core/initialization/initialization.js +2 -148
- package/dist/core/initialization/initialization.js.map +1 -1
- package/dist/core/kernel/startKernel.cjs +1 -2
- package/dist/core/kernel/startKernel.cjs.map +1 -1
- package/dist/core/kernel/startKernel.js +1 -2
- package/dist/core/kernel/startKernel.js.map +1 -1
- package/dist/core/plugin.cjs +16 -16
- package/dist/core/plugin.cjs.map +1 -1
- package/dist/core/plugin.d.ts +5 -1
- package/dist/core/plugin.js +17 -17
- package/dist/core/plugin.js.map +1 -1
- package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -1
- package/dist/core/router/monitoring/RouterMonitoring.cjs.map +1 -1
- package/dist/core/router/monitoring/RouterMonitoring.js +1 -1
- package/dist/core/router/monitoring/RouterMonitoring.js.map +1 -1
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +13 -8
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs.map +1 -1
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js +13 -8
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js.map +1 -1
- package/dist/core/router/utils/adapters/react-router/transform.cjs +4 -0
- package/dist/core/router/utils/adapters/react-router/transform.cjs.map +1 -1
- package/dist/core/router/utils/adapters/react-router/transform.js +4 -0
- package/dist/core/router/utils/adapters/react-router/transform.js.map +1 -1
- package/dist/core/startup/initializeServices.cjs +1 -1
- package/dist/core/startup/initializeServices.cjs.map +1 -1
- package/dist/core/startup/initializeServices.d.ts +1 -1
- package/dist/core/startup/initializeServices.js +1 -1
- package/dist/core/startup/initializeServices.js.map +1 -1
- package/dist/core/startup/performanceTracker.cjs.map +1 -1
- package/dist/core/startup/performanceTracker.d.ts +1 -1
- package/dist/core/startup/performanceTracker.js.map +1 -1
- package/dist/core/startup/renderApp.cjs +1 -1
- package/dist/core/startup/renderApp.cjs.map +1 -1
- package/dist/core/startup/renderApp.d.ts +1 -1
- package/dist/core/startup/renderApp.js +1 -1
- package/dist/core/startup/renderApp.js.map +1 -1
- package/dist/core/startup/startApp.cjs +2 -4
- package/dist/core/startup/startApp.cjs.map +1 -1
- package/dist/core/startup/startApp.js +3 -5
- package/dist/core/startup/startApp.js.map +1 -1
- package/dist/core/types.d.ts +2 -6
- package/dist/core/types.js.map +1 -1
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +11758 -32895
- package/dist/index.umd.js.map +1 -1
- package/dist/kernel/constants.cjs +67 -0
- package/dist/kernel/constants.cjs.map +1 -0
- package/dist/kernel/constants.d.ts +5 -0
- package/dist/kernel/constants.js +43 -0
- package/dist/kernel/constants.js.map +1 -0
- package/dist/kernel/index.cjs +40 -0
- package/dist/kernel/index.cjs.map +1 -0
- package/dist/kernel/index.d.ts +3 -0
- package/dist/kernel/index.js +4 -0
- package/dist/kernel/index.js.map +1 -0
- package/dist/kernel/kernel.cjs +296 -0
- package/dist/kernel/kernel.cjs.map +1 -0
- package/dist/kernel/kernel.d.ts +40 -0
- package/dist/kernel/kernel.js +272 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/kernel/manager/cacheManager.cjs +46 -0
- package/dist/kernel/manager/cacheManager.cjs.map +1 -0
- package/dist/kernel/manager/cacheManager.d.ts +6 -0
- package/dist/kernel/manager/cacheManager.js +36 -0
- package/dist/kernel/manager/cacheManager.js.map +1 -0
- package/dist/kernel/manager/i18nManager.cjs +68 -0
- package/dist/kernel/manager/i18nManager.cjs.map +1 -0
- package/dist/kernel/manager/i18nManager.d.ts +8 -0
- package/dist/kernel/manager/i18nManager.js +58 -0
- package/dist/kernel/manager/i18nManager.js.map +1 -0
- package/dist/kernel/manager/index.cjs +30 -0
- package/dist/kernel/manager/index.cjs.map +1 -0
- package/dist/kernel/manager/index.d.ts +4 -0
- package/dist/kernel/manager/index.js +6 -0
- package/dist/kernel/manager/index.js.map +1 -0
- package/dist/kernel/manager/loggerManager.cjs +70 -0
- package/dist/kernel/manager/loggerManager.cjs.map +1 -0
- package/dist/kernel/manager/loggerManager.d.ts +14 -0
- package/dist/kernel/manager/loggerManager.js +60 -0
- package/dist/kernel/manager/loggerManager.js.map +1 -0
- package/dist/kernel/manager/persistence.cjs +93 -0
- package/dist/kernel/manager/persistence.cjs.map +1 -0
- package/dist/kernel/manager/persistence.d.ts +3 -0
- package/dist/kernel/manager/persistence.js +75 -0
- package/dist/kernel/manager/persistence.js.map +1 -0
- package/dist/kernel/manager/themeManager.cjs +85 -0
- package/dist/kernel/manager/themeManager.cjs.map +1 -0
- package/dist/kernel/manager/themeManager.d.ts +9 -0
- package/dist/kernel/manager/themeManager.js +75 -0
- package/dist/kernel/manager/themeManager.js.map +1 -0
- package/dist/kernel/types.cjs.map +1 -0
- package/dist/kernel/types.d.ts +72 -0
- package/dist/kernel/types.js.map +1 -0
- package/dist/library/storage/index.cjs +1 -1
- package/dist/library/storage/index.cjs.map +1 -1
- package/dist/library/storage/index.d.ts +1 -0
- package/dist/library/storage/index.js +1 -1
- package/dist/library/storage/index.js.map +1 -1
- package/dist/request/adapter.d.ts +1 -0
- package/dist/request/core.d.ts +1 -0
- package/dist/request/index.d.ts +1 -42
- package/dist/request/plugin/csrfPlugin.d.ts +2 -2
- package/dist/request/plugin/queue.d.ts +2 -2
- package/dist/request/plugin.d.ts +1 -0
- package/dist/request/runtime.d.ts +1 -0
- package/dist/request/types.d.ts +1 -394
- package/dist/request/utils.d.ts +1 -0
- package/dist/state.umd.js +1 -1
- package/dist/utils/csrf.cjs +13 -152
- package/dist/utils/csrf.cjs.map +1 -1
- package/dist/utils/csrf.d.ts +1 -72
- package/dist/utils/csrf.js +1 -142
- package/dist/utils/csrf.js.map +1 -1
- package/dist/utils/errors/ErrorCodes.cjs +6 -76
- package/dist/utils/errors/ErrorCodes.cjs.map +1 -1
- package/dist/utils/errors/ErrorCodes.d.ts +1 -45
- package/dist/utils/errors/ErrorCodes.js +1 -84
- package/dist/utils/errors/ErrorCodes.js.map +1 -1
- package/dist/utils/errors.cjs +15 -344
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.ts +1 -183
- package/dist/utils/errors.js +1 -352
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/logger.cjs +5 -374
- package/dist/utils/logger.cjs.map +1 -1
- package/dist/utils/logger.d.ts +2 -189
- package/dist/utils/logger.js +1 -379
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/logger.types.cjs +3 -12
- package/dist/utils/logger.types.cjs.map +1 -1
- package/dist/utils/logger.types.d.ts +2 -57
- package/dist/utils/logger.types.js +1 -10
- package/dist/utils/logger.types.js.map +1 -1
- package/dist/utils/monitoring.cjs +11 -302
- package/dist/utils/monitoring.cjs.map +1 -1
- package/dist/utils/monitoring.d.ts +1 -163
- package/dist/utils/monitoring.js +1 -294
- package/dist/utils/monitoring.js.map +1 -1
- package/dist/utils/performance.cjs +5 -352
- package/dist/utils/performance.cjs.map +1 -1
- package/dist/utils/performance.d.ts +2 -246
- package/dist/utils/performance.js +1 -354
- package/dist/utils/performance.js.map +1 -1
- package/dist/utils/resourceLoader.cjs +5 -303
- package/dist/utils/resourceLoader.cjs.map +1 -1
- package/dist/utils/resourceLoader.d.ts +2 -130
- package/dist/utils/resourceLoader.js +1 -305
- package/dist/utils/resourceLoader.js.map +1 -1
- package/dist/utils/runtimeSecurity.cjs +2 -140
- package/dist/utils/runtimeSecurity.cjs.map +1 -1
- package/dist/utils/runtimeSecurity.d.ts +2 -104
- package/dist/utils/runtimeSecurity.js +1 -141
- package/dist/utils/runtimeSecurity.js.map +1 -1
- package/dist/utils/security.cjs +3 -314
- package/dist/utils/security.cjs.map +1 -1
- package/dist/utils/security.d.ts +2 -80
- package/dist/utils/security.js +1 -311
- package/dist/utils/security.js.map +1 -1
- package/dist/utils/traceId.cjs +10 -111
- package/dist/utils/traceId.cjs.map +1 -1
- package/dist/utils/traceId.d.ts +1 -63
- package/dist/utils/traceId.js +1 -116
- package/dist/utils/traceId.js.map +1 -1
- package/dist/utils/validation.cjs +3 -173
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.ts +2 -110
- package/dist/utils/validation.js +1 -175
- package/dist/utils/validation.js.map +1 -1
- package/package.json +98 -13
- package/dist/core/ui-adapter/adapters.cjs +0 -45
- package/dist/core/ui-adapter/adapters.cjs.map +0 -1
- package/dist/core/ui-adapter/adapters.d.ts +0 -4
- package/dist/core/ui-adapter/adapters.js +0 -27
- package/dist/core/ui-adapter/adapters.js.map +0 -1
- package/dist/core/ui-adapter/index.cjs +0 -21
- package/dist/core/ui-adapter/index.cjs.map +0 -1
- package/dist/core/ui-adapter/index.d.ts +0 -2
- package/dist/core/ui-adapter/index.js +0 -3
- package/dist/core/ui-adapter/index.js.map +0 -1
- package/dist/core/ui-adapter/types.cjs.map +0 -1
- package/dist/core/ui-adapter/types.d.ts +0 -24
- package/dist/core/ui-adapter/types.js.map +0 -1
- package/dist/request/adapter/RequestAdapter.cjs +0 -78
- package/dist/request/adapter/RequestAdapter.cjs.map +0 -1
- package/dist/request/adapter/axiosAdapter.cjs +0 -164
- package/dist/request/adapter/axiosAdapter.cjs.map +0 -1
- package/dist/request/adapter/fetchAdapter.cjs +0 -134
- package/dist/request/adapter/fetchAdapter.cjs.map +0 -1
- package/dist/request/adapter/index.cjs +0 -80
- package/dist/request/adapter/index.cjs.map +0 -1
- package/dist/request/adapter/kyAdapter.cjs +0 -191
- package/dist/request/adapter/kyAdapter.cjs.map +0 -1
- package/dist/request/adapter/undiciAdapter.cjs +0 -213
- package/dist/request/adapter/undiciAdapter.cjs.map +0 -1
- package/dist/request/core/RequestClient.cjs +0 -558
- package/dist/request/core/RequestClient.cjs.map +0 -1
- package/dist/request/core/index.cjs +0 -15
- package/dist/request/core/index.cjs.map +0 -1
- package/dist/request/index.cjs +0 -149
- package/dist/request/index.cjs.map +0 -1
- package/dist/request/plugin/RequestPlugin.cjs +0 -218
- package/dist/request/plugin/RequestPlugin.cjs.map +0 -1
- package/dist/request/plugin/cache.cjs +0 -269
- package/dist/request/plugin/cache.cjs.map +0 -1
- package/dist/request/plugin/csrfPlugin.cjs +0 -40
- package/dist/request/plugin/csrfPlugin.cjs.map +0 -1
- package/dist/request/plugin/index.cjs +0 -53
- package/dist/request/plugin/index.cjs.map +0 -1
- package/dist/request/plugin/monitoring.cjs +0 -216
- package/dist/request/plugin/monitoring.cjs.map +0 -1
- package/dist/request/plugin/queue.cjs +0 -140
- package/dist/request/plugin/queue.cjs.map +0 -1
- package/dist/request/plugin/retry.cjs +0 -98
- package/dist/request/plugin/retry.cjs.map +0 -1
- package/dist/request/plugin/validation.cjs +0 -121
- package/dist/request/plugin/validation.cjs.map +0 -1
- package/dist/request/runtime/RequestContext.cjs +0 -77
- package/dist/request/runtime/RequestContext.cjs.map +0 -1
- package/dist/request/runtime/index.cjs +0 -32
- package/dist/request/runtime/index.cjs.map +0 -1
- package/dist/request/types.cjs +0 -112
- package/dist/request/types.cjs.map +0 -1
- package/dist/request/utils/RequestQueueManager.cjs +0 -168
- package/dist/request/utils/RequestQueueManager.cjs.map +0 -1
- package/dist/request/utils/dependencyCheck.cjs +0 -237
- package/dist/request/utils/dependencyCheck.cjs.map +0 -1
- package/dist/request/utils/index.cjs +0 -30
- package/dist/request/utils/index.cjs.map +0 -1
- package/dist/request.umd.js +0 -5392
- package/dist/request.umd.js.map +0 -1
- /package/dist/{core/ui-adapter → kernel}/types.cjs +0 -0
- /package/dist/{core/ui-adapter → kernel}/types.js +0 -0
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* 资源类型
|
|
3
|
-
*/ "use strict";
|
|
1
|
+
"use strict";
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
3
|
value: true
|
|
6
4
|
});
|
|
@@ -12,311 +10,15 @@ function _export(target, all) {
|
|
|
12
10
|
}
|
|
13
11
|
_export(exports, {
|
|
14
12
|
get ResourceLoader () {
|
|
15
|
-
return ResourceLoader;
|
|
13
|
+
return _utils.ResourceLoader;
|
|
16
14
|
},
|
|
17
15
|
get ResourcePriority () {
|
|
18
|
-
return ResourcePriority;
|
|
16
|
+
return _utils.ResourcePriority;
|
|
19
17
|
},
|
|
20
18
|
get resourceLoader () {
|
|
21
|
-
return resourceLoader;
|
|
19
|
+
return _utils.resourceLoader;
|
|
22
20
|
}
|
|
23
21
|
});
|
|
24
|
-
|
|
25
|
-
if (key in obj) {
|
|
26
|
-
Object.defineProperty(obj, key, {
|
|
27
|
-
value: value,
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
obj[key] = value;
|
|
34
|
-
}
|
|
35
|
-
return obj;
|
|
36
|
-
}
|
|
37
|
-
var ResourcePriority = /*#__PURE__*/ function(ResourcePriority) {
|
|
38
|
-
/**
|
|
39
|
-
* 高优先级 - 关键资源
|
|
40
|
-
*/ ResourcePriority["HIGH"] = "high";
|
|
41
|
-
/**
|
|
42
|
-
* 中优先级 - 重要资源
|
|
43
|
-
*/ ResourcePriority["MEDIUM"] = "medium";
|
|
44
|
-
/**
|
|
45
|
-
* 低优先级 - 非关键资源
|
|
46
|
-
*/ ResourcePriority["LOW"] = "low";
|
|
47
|
-
/**
|
|
48
|
-
* 自动 - 由浏览器决定
|
|
49
|
-
*/ ResourcePriority["AUTO"] = "auto";
|
|
50
|
-
return ResourcePriority;
|
|
51
|
-
}({});
|
|
52
|
-
let ResourceLoader = class ResourceLoader {
|
|
53
|
-
/**
|
|
54
|
-
* 获取动态并发数(基于网络状况)
|
|
55
|
-
*/ getDynamicConcurrency() {
|
|
56
|
-
if (typeof navigator === 'undefined' || !('connection' in navigator)) {
|
|
57
|
-
return this.maxConcurrentLoads;
|
|
58
|
-
}
|
|
59
|
-
const connection = navigator.connection;
|
|
60
|
-
if (!connection) {
|
|
61
|
-
return this.maxConcurrentLoads;
|
|
62
|
-
}
|
|
63
|
-
// 根据网络类型调整并发数
|
|
64
|
-
const effectiveType = connection.effectiveType;
|
|
65
|
-
switch(effectiveType){
|
|
66
|
-
case 'slow-2g':
|
|
67
|
-
case '2g':
|
|
68
|
-
return 2;
|
|
69
|
-
case '3g':
|
|
70
|
-
return 4;
|
|
71
|
-
case '4g':
|
|
72
|
-
default:
|
|
73
|
-
return this.maxConcurrentLoads;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* 加载脚本
|
|
78
|
-
*/ async loadScript(options) {
|
|
79
|
-
const { url, ...rest } = options;
|
|
80
|
-
return this.loadResource({
|
|
81
|
-
...rest,
|
|
82
|
-
type: 'script',
|
|
83
|
-
url
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 加载样式
|
|
88
|
-
*/ async loadStyle(options) {
|
|
89
|
-
const { url, ...rest } = options;
|
|
90
|
-
return this.loadResource({
|
|
91
|
-
...rest,
|
|
92
|
-
type: 'style',
|
|
93
|
-
url
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 预加载资源
|
|
98
|
-
*/ preload(options) {
|
|
99
|
-
if (typeof document === 'undefined') {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const link = document.createElement('link');
|
|
103
|
-
link.rel = 'preload';
|
|
104
|
-
link.href = options.url;
|
|
105
|
-
link.as = this.getResourceAs(options.type);
|
|
106
|
-
if (options.priority) {
|
|
107
|
-
link.setAttribute('fetchpriority', options.priority);
|
|
108
|
-
}
|
|
109
|
-
if (options.crossOrigin) {
|
|
110
|
-
link.crossOrigin = options.crossOrigin;
|
|
111
|
-
}
|
|
112
|
-
if (options.integrity) {
|
|
113
|
-
link.integrity = options.integrity;
|
|
114
|
-
}
|
|
115
|
-
document.head.appendChild(link);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* 预取资源
|
|
119
|
-
*/ prefetch(options) {
|
|
120
|
-
if (typeof document === 'undefined') {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const link = document.createElement('link');
|
|
124
|
-
link.rel = 'prefetch';
|
|
125
|
-
link.href = options.url;
|
|
126
|
-
if (options.priority) {
|
|
127
|
-
link.setAttribute('fetchpriority', options.priority);
|
|
128
|
-
}
|
|
129
|
-
document.head.appendChild(link);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* 加载资源
|
|
133
|
-
*/ async loadResource(options) {
|
|
134
|
-
const { url, type, onLoad, onError } = options;
|
|
135
|
-
// 如果已经加载过,直接返回
|
|
136
|
-
if (this.loadedResources.has(url)) {
|
|
137
|
-
onLoad?.();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// 如果正在加载,等待加载完成
|
|
141
|
-
if (this.loadingResources.has(url)) {
|
|
142
|
-
await this.loadingResources.get(url);
|
|
143
|
-
onLoad?.();
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
// 创建加载 Promise
|
|
147
|
-
const loadPromise = this.doLoadResource({
|
|
148
|
-
...options,
|
|
149
|
-
type,
|
|
150
|
-
url
|
|
151
|
-
});
|
|
152
|
-
// 保存加载 Promise
|
|
153
|
-
this.loadingResources.set(url, loadPromise);
|
|
154
|
-
try {
|
|
155
|
-
await loadPromise;
|
|
156
|
-
this.loadedResources.add(url);
|
|
157
|
-
onLoad?.();
|
|
158
|
-
} catch (error) {
|
|
159
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
160
|
-
onError?.(err);
|
|
161
|
-
throw err;
|
|
162
|
-
} finally{
|
|
163
|
-
this.loadingResources.delete(url);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 执行资源加载
|
|
168
|
-
*/ doLoadResource(options) {
|
|
169
|
-
return new Promise((resolve, reject)=>{
|
|
170
|
-
if (typeof document === 'undefined') {
|
|
171
|
-
reject(new Error('资源加载需要在浏览器环境中执行'));
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const { url, type, async = true, defer, crossOrigin, integrity } = options;
|
|
175
|
-
if (type === 'script') {
|
|
176
|
-
const script = document.createElement('script');
|
|
177
|
-
script.src = url;
|
|
178
|
-
script.async = async;
|
|
179
|
-
if (defer !== undefined) {
|
|
180
|
-
script.defer = defer;
|
|
181
|
-
}
|
|
182
|
-
if (crossOrigin) {
|
|
183
|
-
script.crossOrigin = crossOrigin;
|
|
184
|
-
}
|
|
185
|
-
if (integrity) {
|
|
186
|
-
script.integrity = integrity;
|
|
187
|
-
}
|
|
188
|
-
script.onload = ()=>resolve();
|
|
189
|
-
script.onerror = ()=>reject(new Error(`Failed to load script: ${url}`));
|
|
190
|
-
document.head.appendChild(script);
|
|
191
|
-
} else if (type === 'style') {
|
|
192
|
-
const link = document.createElement('link');
|
|
193
|
-
link.rel = 'stylesheet';
|
|
194
|
-
link.href = url;
|
|
195
|
-
if (crossOrigin) {
|
|
196
|
-
link.crossOrigin = crossOrigin;
|
|
197
|
-
}
|
|
198
|
-
if (integrity) {
|
|
199
|
-
link.integrity = integrity;
|
|
200
|
-
}
|
|
201
|
-
link.onload = ()=>resolve();
|
|
202
|
-
link.onerror = ()=>reject(new Error(`Failed to load stylesheet: ${url}`));
|
|
203
|
-
document.head.appendChild(link);
|
|
204
|
-
} else {
|
|
205
|
-
reject(new Error(`Unsupported resource type: ${type}`));
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* 获取资源 as 属性值
|
|
211
|
-
*/ getResourceAs(type) {
|
|
212
|
-
const asMap = {
|
|
213
|
-
script: 'script',
|
|
214
|
-
style: 'style',
|
|
215
|
-
image: 'image',
|
|
216
|
-
font: 'font',
|
|
217
|
-
prefetch: 'fetch',
|
|
218
|
-
preload: 'fetch'
|
|
219
|
-
};
|
|
220
|
-
return asMap[type] || 'fetch';
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 使用 requestIdleCallback 加载低优先级资源
|
|
224
|
-
*/ loadWhenIdle(options, timeout) {
|
|
225
|
-
if (typeof requestIdleCallback !== 'undefined') {
|
|
226
|
-
requestIdleCallback(()=>{
|
|
227
|
-
this.loadResource(options).catch((error)=>{
|
|
228
|
-
console.warn('Idle resource load failed:', error);
|
|
229
|
-
});
|
|
230
|
-
}, {
|
|
231
|
-
timeout
|
|
232
|
-
});
|
|
233
|
-
} else {
|
|
234
|
-
// 降级方案:延迟加载
|
|
235
|
-
setTimeout(()=>{
|
|
236
|
-
this.loadResource(options).catch((error)=>{
|
|
237
|
-
console.warn('Delayed resource load failed:', error);
|
|
238
|
-
});
|
|
239
|
-
}, 1000);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* 批量加载资源(按优先级)
|
|
244
|
-
*/ async loadResources(resources) {
|
|
245
|
-
// 按优先级排序
|
|
246
|
-
const sortedResources = this.sortByPriority(resources);
|
|
247
|
-
// 按优先级分组
|
|
248
|
-
const highPriority = sortedResources.filter((r)=>r.priority === "high" || !r.priority);
|
|
249
|
-
const mediumPriority = sortedResources.filter((r)=>r.priority === "medium");
|
|
250
|
-
const lowPriority = sortedResources.filter((r)=>r.priority === "low");
|
|
251
|
-
const results = [];
|
|
252
|
-
// 先加载高优先级资源(并行,但限制并发数)
|
|
253
|
-
if (highPriority.length > 0) {
|
|
254
|
-
const highResults = await this.loadResourcesWithConcurrencyLimit(highPriority);
|
|
255
|
-
results.push(...highResults);
|
|
256
|
-
}
|
|
257
|
-
// 然后加载中优先级资源
|
|
258
|
-
if (mediumPriority.length > 0) {
|
|
259
|
-
const mediumResults = await this.loadResourcesWithConcurrencyLimit(mediumPriority);
|
|
260
|
-
results.push(...mediumResults);
|
|
261
|
-
}
|
|
262
|
-
// 最后加载低优先级资源(使用空闲时间)
|
|
263
|
-
if (lowPriority.length > 0) {
|
|
264
|
-
// 低优先级资源在空闲时加载
|
|
265
|
-
for (const resource of lowPriority){
|
|
266
|
-
this.loadWhenIdle(resource);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return results;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* 按优先级排序资源
|
|
273
|
-
*/ sortByPriority(resources) {
|
|
274
|
-
const priorityOrder = {
|
|
275
|
-
["high"]: 0,
|
|
276
|
-
["medium"]: 1,
|
|
277
|
-
["low"]: 2,
|
|
278
|
-
["auto"]: 3
|
|
279
|
-
};
|
|
280
|
-
return [
|
|
281
|
-
...resources
|
|
282
|
-
].sort((a, b)=>{
|
|
283
|
-
const aPriority = priorityOrder[a.priority || "auto"] ?? 3;
|
|
284
|
-
const bPriority = priorityOrder[b.priority || "auto"] ?? 3;
|
|
285
|
-
return aPriority - bPriority;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* 限制并发数的资源加载(优化版本)
|
|
290
|
-
*/ async loadResourcesWithConcurrencyLimit(resources, concurrency) {
|
|
291
|
-
const maxConcurrency = concurrency ?? this.getDynamicConcurrency();
|
|
292
|
-
const results = [];
|
|
293
|
-
const executing = new Set();
|
|
294
|
-
for (const resource of resources){
|
|
295
|
-
// 如果达到并发限制,等待一个任务完成
|
|
296
|
-
if (executing.size >= maxConcurrency) {
|
|
297
|
-
await Promise.race(executing);
|
|
298
|
-
}
|
|
299
|
-
const promise = this.loadResource(resource).finally(()=>{
|
|
300
|
-
executing.delete(promise);
|
|
301
|
-
});
|
|
302
|
-
executing.add(promise);
|
|
303
|
-
results.push(promise);
|
|
304
|
-
}
|
|
305
|
-
// 等待所有任务完成
|
|
306
|
-
await Promise.all(results);
|
|
307
|
-
return [];
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* 检查资源是否已加载
|
|
311
|
-
*/ isLoaded(url) {
|
|
312
|
-
return this.loadedResources.has(url);
|
|
313
|
-
}
|
|
314
|
-
constructor(){
|
|
315
|
-
_define_property(this, "loadedResources", new Set());
|
|
316
|
-
_define_property(this, "loadingResources", new Map());
|
|
317
|
-
_define_property(this, "maxConcurrentLoads", 6); // 最大并发加载数(默认值)
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
const resourceLoader = new ResourceLoader();
|
|
22
|
+
const _utils = require("@vlian/utils");
|
|
321
23
|
|
|
322
24
|
//# sourceMappingURL=resourceLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/resourceLoader.ts"],"sourcesContent":["/**\n * 资源类型\n */\nexport type ResourceType = 'script' | 'style' | 'image' | 'font' | 'prefetch' | 'preload';\n\n/**\n * 资源优先级\n */\nexport enum ResourcePriority {\n /**\n * 高优先级 - 关键资源\n */\n HIGH = 'high',\n /**\n * 中优先级 - 重要资源\n */\n MEDIUM = 'medium',\n /**\n * 低优先级 - 非关键资源\n */\n LOW = 'low',\n /**\n * 自动 - 由浏览器决定\n */\n AUTO = 'auto',\n}\n\n/**\n * 资源加载选项\n */\nexport interface ResourceLoadOptions {\n /**\n * 资源类型\n */\n type: ResourceType;\n /**\n * 资源 URL\n */\n url: string;\n /**\n * 优先级\n */\n priority?: ResourcePriority;\n /**\n * 是否异步加载\n */\n async?: boolean;\n /**\n * 是否延迟加载\n */\n defer?: boolean;\n /**\n * 跨域设置\n */\n crossOrigin?: 'anonymous' | 'use-credentials';\n /**\n * 完整性校验(SRI)\n */\n integrity?: string;\n /**\n * 加载完成回调\n */\n onLoad?: () => void;\n /**\n * 加载失败回调\n */\n onError?: (error: Error) => void;\n}\n\n/**\n * 资源加载器类\n */\nexport class ResourceLoader {\n private loadedResources: Set<string> = new Set();\n private loadingResources: Map<string, Promise<void>> = new Map();\n private maxConcurrentLoads: number = 6; // 最大并发加载数(默认值)\n\n /**\n * 获取动态并发数(基于网络状况)\n */\n private getDynamicConcurrency(): number {\n if (typeof navigator === 'undefined' || !('connection' in navigator)) {\n return this.maxConcurrentLoads;\n }\n\n const connection = (navigator as any).connection;\n if (!connection) {\n return this.maxConcurrentLoads;\n }\n\n // 根据网络类型调整并发数\n const effectiveType = connection.effectiveType;\n switch (effectiveType) {\n case 'slow-2g':\n case '2g':\n return 2;\n case '3g':\n return 4;\n case '4g':\n default:\n return this.maxConcurrentLoads;\n }\n }\n\n /**\n * 加载脚本\n */\n async loadScript(options: Omit<ResourceLoadOptions, 'type'>): Promise<void> {\n const { url, ...rest } = options;\n return this.loadResource({ ...rest, type: 'script', url });\n }\n\n /**\n * 加载样式\n */\n async loadStyle(options: Omit<ResourceLoadOptions, 'type'>): Promise<void> {\n const { url, ...rest } = options;\n return this.loadResource({ ...rest, type: 'style', url });\n }\n\n /**\n * 预加载资源\n */\n preload(options: ResourceLoadOptions): void {\n if (typeof document === 'undefined') {\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'preload';\n link.href = options.url;\n link.as = this.getResourceAs(options.type);\n\n if (options.priority) {\n link.setAttribute('fetchpriority', options.priority);\n }\n\n if (options.crossOrigin) {\n link.crossOrigin = options.crossOrigin;\n }\n\n if (options.integrity) {\n link.integrity = options.integrity;\n }\n\n document.head.appendChild(link);\n }\n\n /**\n * 预取资源\n */\n prefetch(options: Omit<ResourceLoadOptions, 'type'>): void {\n if (typeof document === 'undefined') {\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'prefetch';\n link.href = options.url;\n\n if (options.priority) {\n link.setAttribute('fetchpriority', options.priority);\n }\n\n document.head.appendChild(link);\n }\n\n /**\n * 加载资源\n */\n async loadResource(options: ResourceLoadOptions): Promise<void> {\n const { url, type, onLoad, onError } = options;\n\n // 如果已经加载过,直接返回\n if (this.loadedResources.has(url)) {\n onLoad?.();\n return;\n }\n\n // 如果正在加载,等待加载完成\n if (this.loadingResources.has(url)) {\n await this.loadingResources.get(url);\n onLoad?.();\n return;\n }\n\n // 创建加载 Promise\n const loadPromise = this.doLoadResource({ ...options, type, url });\n\n // 保存加载 Promise\n this.loadingResources.set(url, loadPromise);\n\n try {\n await loadPromise;\n this.loadedResources.add(url);\n onLoad?.();\n } catch (error) {\n const err = error instanceof Error ? error : new Error(String(error));\n onError?.(err);\n throw err;\n } finally {\n this.loadingResources.delete(url);\n }\n }\n\n /**\n * 执行资源加载\n */\n private doLoadResource(options: ResourceLoadOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof document === 'undefined') {\n reject(new Error('资源加载需要在浏览器环境中执行'));\n return;\n }\n\n const { url, type, async = true, defer, crossOrigin, integrity } = options;\n\n if (type === 'script') {\n const script = document.createElement('script');\n script.src = url;\n script.async = async;\n if (defer !== undefined) {\n script.defer = defer;\n }\n if (crossOrigin) {\n script.crossOrigin = crossOrigin;\n }\n if (integrity) {\n script.integrity = integrity;\n }\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load script: ${url}`));\n document.head.appendChild(script);\n } else if (type === 'style') {\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n if (crossOrigin) {\n link.crossOrigin = crossOrigin;\n }\n if (integrity) {\n link.integrity = integrity;\n }\n link.onload = () => resolve();\n link.onerror = () => reject(new Error(`Failed to load stylesheet: ${url}`));\n document.head.appendChild(link);\n } else {\n reject(new Error(`Unsupported resource type: ${type}`));\n }\n });\n }\n\n /**\n * 获取资源 as 属性值\n */\n private getResourceAs(type: ResourceType): string {\n const asMap: Record<ResourceType, string> = {\n script: 'script',\n style: 'style',\n image: 'image',\n font: 'font',\n prefetch: 'fetch',\n preload: 'fetch',\n };\n return asMap[type] || 'fetch';\n }\n\n /**\n * 使用 requestIdleCallback 加载低优先级资源\n */\n loadWhenIdle(options: ResourceLoadOptions, timeout?: number): void {\n if (typeof requestIdleCallback !== 'undefined') {\n requestIdleCallback(\n () => {\n this.loadResource(options).catch((error) => {\n console.warn('Idle resource load failed:', error);\n });\n },\n { timeout }\n );\n } else {\n // 降级方案:延迟加载\n setTimeout(() => {\n this.loadResource(options).catch((error) => {\n console.warn('Delayed resource load failed:', error);\n });\n }, 1000);\n }\n }\n\n /**\n * 批量加载资源(按优先级)\n */\n async loadResources(resources: ResourceLoadOptions[]): Promise<void[]> {\n // 按优先级排序\n const sortedResources = this.sortByPriority(resources);\n \n // 按优先级分组\n const highPriority = sortedResources.filter(r => r.priority === ResourcePriority.HIGH || !r.priority);\n const mediumPriority = sortedResources.filter(r => r.priority === ResourcePriority.MEDIUM);\n const lowPriority = sortedResources.filter(r => r.priority === ResourcePriority.LOW);\n\n const results: void[] = [];\n\n // 先加载高优先级资源(并行,但限制并发数)\n if (highPriority.length > 0) {\n const highResults = await this.loadResourcesWithConcurrencyLimit(highPriority);\n results.push(...highResults);\n }\n\n // 然后加载中优先级资源\n if (mediumPriority.length > 0) {\n const mediumResults = await this.loadResourcesWithConcurrencyLimit(mediumPriority);\n results.push(...mediumResults);\n }\n\n // 最后加载低优先级资源(使用空闲时间)\n if (lowPriority.length > 0) {\n // 低优先级资源在空闲时加载\n for (const resource of lowPriority) {\n this.loadWhenIdle(resource);\n }\n }\n\n return results;\n }\n\n /**\n * 按优先级排序资源\n */\n private sortByPriority(resources: ResourceLoadOptions[]): ResourceLoadOptions[] {\n const priorityOrder = {\n [ResourcePriority.HIGH]: 0,\n [ResourcePriority.MEDIUM]: 1,\n [ResourcePriority.LOW]: 2,\n [ResourcePriority.AUTO]: 3,\n };\n\n return [...resources].sort((a, b) => {\n const aPriority = priorityOrder[a.priority || ResourcePriority.AUTO] ?? 3;\n const bPriority = priorityOrder[b.priority || ResourcePriority.AUTO] ?? 3;\n return aPriority - bPriority;\n });\n }\n\n /**\n * 限制并发数的资源加载(优化版本)\n */\n private async loadResourcesWithConcurrencyLimit(\n resources: ResourceLoadOptions[],\n concurrency?: number\n ): Promise<void[]> {\n const maxConcurrency = concurrency ?? this.getDynamicConcurrency();\n const results: Promise<void>[] = [];\n const executing = new Set<Promise<void>>();\n\n for (const resource of resources) {\n // 如果达到并发限制,等待一个任务完成\n if (executing.size >= maxConcurrency) {\n await Promise.race(executing);\n }\n\n const promise = this.loadResource(resource).finally(() => {\n executing.delete(promise);\n });\n\n executing.add(promise);\n results.push(promise);\n }\n\n // 等待所有任务完成\n await Promise.all(results);\n return [];\n }\n\n /**\n * 检查资源是否已加载\n */\n isLoaded(url: string): boolean {\n return this.loadedResources.has(url);\n }\n}\n\n/**\n * 默认资源加载器实例\n */\nexport const resourceLoader = new ResourceLoader();\n"],"names":["ResourceLoader","ResourcePriority","resourceLoader","getDynamicConcurrency","navigator","maxConcurrentLoads","connection","effectiveType","loadScript","options","url","rest","loadResource","type","loadStyle","preload","document","link","createElement","rel","href","as","getResourceAs","priority","setAttribute","crossOrigin","integrity","head","appendChild","prefetch","onLoad","onError","loadedResources","has","loadingResources","get","loadPromise","doLoadResource","set","add","error","err","Error","String","delete","Promise","resolve","reject","async","defer","script","src","undefined","onload","onerror","asMap","style","image","font","loadWhenIdle","timeout","requestIdleCallback","catch","console","warn","setTimeout","loadResources","resources","sortedResources","sortByPriority","highPriority","filter","r","mediumPriority","lowPriority","results","length","highResults","loadResourcesWithConcurrencyLimit","push","mediumResults","resource","priorityOrder","sort","a","b","aPriority","bPriority","concurrency","maxConcurrency","executing","Set","size","race","promise","finally","all","isLoaded","Map"],"mappings":"AAAA;;CAEC;;;;;;;;;;;QA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AAG,CAACrB;QAClB,OAAO,EAAE;IACX;IAEA;;GAEC,GACDsB,SAASvF,GAAW,EAAW;QAC7B,OAAO,IAAI,CAACsB,eAAe,CAACC,GAAG,CAACvB;IAClC;;QAnTA,uBAAQsB,mBAA+B,IAAI2D;QAC3C,uBAAQzD,oBAA+C,IAAIgE;QAC3D,uBAAQ7F,sBAA6B,IAAG,eAAe;;AAkTzD;AAKO,MAAMH,iBAAiB,IAAIF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/resourceLoader.ts"],"sourcesContent":["export { ResourceLoader, ResourcePriority, resourceLoader } from '@vlian/utils';\nexport type { ResourceLoadOptions, ResourceType } from '@vlian/utils';\n"],"names":["ResourceLoader","ResourcePriority","resourceLoader"],"mappings":";;;;;;;;;;;QAASA;eAAAA,qBAAc;;QAAEC;eAAAA,uBAAgB;;QAAEC;eAAAA,qBAAc;;;uBAAQ"}
|
|
@@ -1,130 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
export type ResourceType = 'script' | 'style' | 'image' | 'font' | 'prefetch' | 'preload';
|
|
5
|
-
/**
|
|
6
|
-
* 资源优先级
|
|
7
|
-
*/
|
|
8
|
-
export declare enum ResourcePriority {
|
|
9
|
-
/**
|
|
10
|
-
* 高优先级 - 关键资源
|
|
11
|
-
*/
|
|
12
|
-
HIGH = "high",
|
|
13
|
-
/**
|
|
14
|
-
* 中优先级 - 重要资源
|
|
15
|
-
*/
|
|
16
|
-
MEDIUM = "medium",
|
|
17
|
-
/**
|
|
18
|
-
* 低优先级 - 非关键资源
|
|
19
|
-
*/
|
|
20
|
-
LOW = "low",
|
|
21
|
-
/**
|
|
22
|
-
* 自动 - 由浏览器决定
|
|
23
|
-
*/
|
|
24
|
-
AUTO = "auto"
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 资源加载选项
|
|
28
|
-
*/
|
|
29
|
-
export interface ResourceLoadOptions {
|
|
30
|
-
/**
|
|
31
|
-
* 资源类型
|
|
32
|
-
*/
|
|
33
|
-
type: ResourceType;
|
|
34
|
-
/**
|
|
35
|
-
* 资源 URL
|
|
36
|
-
*/
|
|
37
|
-
url: string;
|
|
38
|
-
/**
|
|
39
|
-
* 优先级
|
|
40
|
-
*/
|
|
41
|
-
priority?: ResourcePriority;
|
|
42
|
-
/**
|
|
43
|
-
* 是否异步加载
|
|
44
|
-
*/
|
|
45
|
-
async?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* 是否延迟加载
|
|
48
|
-
*/
|
|
49
|
-
defer?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* 跨域设置
|
|
52
|
-
*/
|
|
53
|
-
crossOrigin?: 'anonymous' | 'use-credentials';
|
|
54
|
-
/**
|
|
55
|
-
* 完整性校验(SRI)
|
|
56
|
-
*/
|
|
57
|
-
integrity?: string;
|
|
58
|
-
/**
|
|
59
|
-
* 加载完成回调
|
|
60
|
-
*/
|
|
61
|
-
onLoad?: () => void;
|
|
62
|
-
/**
|
|
63
|
-
* 加载失败回调
|
|
64
|
-
*/
|
|
65
|
-
onError?: (error: Error) => void;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 资源加载器类
|
|
69
|
-
*/
|
|
70
|
-
export declare class ResourceLoader {
|
|
71
|
-
private loadedResources;
|
|
72
|
-
private loadingResources;
|
|
73
|
-
private maxConcurrentLoads;
|
|
74
|
-
/**
|
|
75
|
-
* 获取动态并发数(基于网络状况)
|
|
76
|
-
*/
|
|
77
|
-
private getDynamicConcurrency;
|
|
78
|
-
/**
|
|
79
|
-
* 加载脚本
|
|
80
|
-
*/
|
|
81
|
-
loadScript(options: Omit<ResourceLoadOptions, 'type'>): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* 加载样式
|
|
84
|
-
*/
|
|
85
|
-
loadStyle(options: Omit<ResourceLoadOptions, 'type'>): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* 预加载资源
|
|
88
|
-
*/
|
|
89
|
-
preload(options: ResourceLoadOptions): void;
|
|
90
|
-
/**
|
|
91
|
-
* 预取资源
|
|
92
|
-
*/
|
|
93
|
-
prefetch(options: Omit<ResourceLoadOptions, 'type'>): void;
|
|
94
|
-
/**
|
|
95
|
-
* 加载资源
|
|
96
|
-
*/
|
|
97
|
-
loadResource(options: ResourceLoadOptions): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* 执行资源加载
|
|
100
|
-
*/
|
|
101
|
-
private doLoadResource;
|
|
102
|
-
/**
|
|
103
|
-
* 获取资源 as 属性值
|
|
104
|
-
*/
|
|
105
|
-
private getResourceAs;
|
|
106
|
-
/**
|
|
107
|
-
* 使用 requestIdleCallback 加载低优先级资源
|
|
108
|
-
*/
|
|
109
|
-
loadWhenIdle(options: ResourceLoadOptions, timeout?: number): void;
|
|
110
|
-
/**
|
|
111
|
-
* 批量加载资源(按优先级)
|
|
112
|
-
*/
|
|
113
|
-
loadResources(resources: ResourceLoadOptions[]): Promise<void[]>;
|
|
114
|
-
/**
|
|
115
|
-
* 按优先级排序资源
|
|
116
|
-
*/
|
|
117
|
-
private sortByPriority;
|
|
118
|
-
/**
|
|
119
|
-
* 限制并发数的资源加载(优化版本)
|
|
120
|
-
*/
|
|
121
|
-
private loadResourcesWithConcurrencyLimit;
|
|
122
|
-
/**
|
|
123
|
-
* 检查资源是否已加载
|
|
124
|
-
*/
|
|
125
|
-
isLoaded(url: string): boolean;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* 默认资源加载器实例
|
|
129
|
-
*/
|
|
130
|
-
export declare const resourceLoader: ResourceLoader;
|
|
1
|
+
export { ResourceLoader, ResourcePriority, resourceLoader } from '@vlian/utils';
|
|
2
|
+
export type { ResourceLoadOptions, ResourceType } from '@vlian/utils';
|