@vlian/framework 1.2.59 → 1.2.60
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/index.cjs +1 -22
- package/dist/analytics.umd.js +1 -1
- package/dist/components/LocaleSwitch.cjs +1 -116
- package/dist/components/ThemeSwitch.cjs +1 -115
- package/dist/components/index.cjs +1 -20
- package/dist/components/persistence.cjs +1 -58
- package/dist/core/Test.cjs +1 -64
- package/dist/core/app/AppContext.cjs +1 -348
- package/dist/core/app/AppContext.types.cjs +1 -4
- package/dist/core/app/BasicLayout.cjs +1 -122
- package/dist/core/app/DefaultApp.cjs +1 -150
- package/dist/core/app/index.cjs +1 -41
- package/dist/core/config/AppConfig.cjs +1 -139
- package/dist/core/config/ConfigLoader.cjs +1 -323
- package/dist/core/config/ConfigValidator.cjs +2 -133
- package/dist/core/config/index.cjs +1 -28
- package/dist/core/dev/DevTools.cjs +1 -226
- package/dist/core/error/ErrorBoundary.cjs +1 -401
- package/dist/core/error/ErrorHandler.cjs +1 -275
- package/dist/core/error/index.cjs +1 -34
- package/dist/core/event/AppEventBus.cjs +1 -444
- package/dist/core/event/frameworkEvents.cjs +1 -141
- package/dist/core/event/hooks.cjs +1 -69
- package/dist/core/event/index.cjs +1 -41
- package/dist/core/event/types.cjs +1 -62
- package/dist/core/event/useEventBus.cjs +1 -25
- package/dist/core/index.cjs +1 -140
- package/dist/core/initialization/InitializationErrorThrower.cjs +1 -75
- package/dist/core/initialization/index.cjs +1 -26
- package/dist/core/initialization/initialization.cjs +1 -64
- package/dist/core/initialization/initializationErrorState.cjs +1 -66
- package/dist/core/kernel/defaultAdapters.cjs +1 -184
- package/dist/core/kernel/errors.cjs +1 -69
- package/dist/core/kernel/index.cjs +1 -20
- package/dist/core/kernel/startKernel.cjs +1 -200
- package/dist/core/kernel/types.cjs +1 -4
- package/dist/core/middleware.cjs +1 -73
- package/dist/core/plugin/PluginEventBus.cjs +1 -298
- package/dist/core/plugin/PluginSandbox.cjs +1 -137
- package/dist/core/plugin.cjs +1 -494
- package/dist/core/router/RouterManager.cjs +1 -286
- package/dist/core/router/adapter/AdapterManager.cjs +1 -235
- package/dist/core/router/adapter/index.cjs +1 -22
- package/dist/core/router/adapter/react-router/ReactRouterAdapter.cjs +1 -128
- package/dist/core/router/adapter/react-router/index.cjs +1 -20
- package/dist/core/router/adapter/types.cjs +1 -6
- package/dist/core/router/dev/RouterDevTools.cjs +1 -260
- package/dist/core/router/dev/index.cjs +1 -20
- package/dist/core/router/dynamic/DynamicRouteManager.cjs +1 -193
- package/dist/core/router/dynamic/index.cjs +1 -20
- package/dist/core/router/errors/RouterError.cjs +1 -61
- package/dist/core/router/errors/index.cjs +1 -20
- package/dist/core/router/index.cjs +1 -36
- package/dist/core/router/lifecycle/RouterLifecycleManager.cjs +1 -144
- package/dist/core/router/lifecycle/index.cjs +1 -20
- package/dist/core/router/middleware/RouterMiddlewareManager.cjs +1 -193
- package/dist/core/router/middleware/auth.cjs +1 -66
- package/dist/core/router/middleware/index.cjs +1 -22
- package/dist/core/router/middleware/types.cjs +1 -6
- package/dist/core/router/monitoring/RouterMonitoring.cjs +1 -227
- package/dist/core/router/monitoring/index.cjs +1 -20
- package/dist/core/router/navigation/RouterNavigation.cjs +1 -239
- package/dist/core/router/navigation/index.cjs +1 -20
- package/dist/core/router/performance/RouteCache.cjs +1 -305
- package/dist/core/router/performance/RoutePreloader.cjs +1 -292
- package/dist/core/router/performance/index.cjs +1 -21
- package/dist/core/router/plugin/RouterPluginManager.cjs +1 -262
- package/dist/core/router/plugin/index.cjs +1 -21
- package/dist/core/router/plugin/types.cjs +1 -39
- package/dist/core/router/types.cjs +1 -4
- package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +1 -129
- package/dist/core/router/utils/adapters/react-router/transform.cjs +1 -250
- package/dist/core/router/utils/transform.cjs +1 -780
- package/dist/core/router/validation/RouterConfigValidator.cjs +2 -83
- package/dist/core/router/validation/index.cjs +1 -21
- package/dist/core/router/validation/schema.cjs +1 -159
- package/dist/core/router/version/RouteVersionManager.cjs +1 -205
- package/dist/core/router/version/index.cjs +1 -20
- package/dist/core/splash/SplashScreen.cjs +1 -341
- package/dist/core/splash/index.cjs +1 -22
- package/dist/core/splash/splashScreenUtils.cjs +1 -38
- package/dist/core/startup/AppInstance.cjs +1 -239
- package/dist/core/startup/environment.cjs +1 -169
- package/dist/core/startup/index.cjs +1 -23
- package/dist/core/startup/initializeServices.cjs +1 -226
- package/dist/core/startup/performanceTracker.cjs +1 -179
- package/dist/core/startup/renderApp.cjs +1 -314
- package/dist/core/startup/startApp.cjs +1 -317
- package/dist/core/types.cjs +1 -4
- package/dist/index.cjs +1 -52
- package/dist/index.umd.cjs +1 -27
- package/dist/index.umd.js +1 -1
- package/dist/kernel/constants.cjs +1 -65
- package/dist/kernel/index.cjs +1 -38
- package/dist/kernel/kernel.cjs +1 -295
- package/dist/kernel/manager/cacheManager.cjs +1 -46
- package/dist/kernel/manager/i18n/I18nManager.cjs +1 -91
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +1 -60
- package/dist/kernel/manager/i18n/i18n.schema.cjs +1 -86
- package/dist/kernel/manager/i18n/index.cjs +1 -11
- package/dist/kernel/manager/i18nManager.cjs +1 -11
- package/dist/kernel/manager/index.cjs +1 -28
- package/dist/kernel/manager/logger/LoggerManager.cjs +1 -107
- package/dist/kernel/manager/logger/index.cjs +1 -11
- package/dist/kernel/manager/logger/logger.persistence.cjs +1 -62
- package/dist/kernel/manager/logger/logger.schema.cjs +1 -74
- package/dist/kernel/manager/loggerManager.cjs +1 -11
- package/dist/kernel/manager/theme/ThemeManager.cjs +1 -84
- package/dist/kernel/manager/theme/index.cjs +1 -11
- package/dist/kernel/manager/theme/theme.dom.cjs +1 -61
- package/dist/kernel/manager/theme/theme.persistence.cjs +1 -57
- package/dist/kernel/manager/theme/theme.schema.cjs +1 -122
- package/dist/kernel/manager/themeManager.cjs +1 -11
- package/dist/kernel/types.cjs +1 -4
- package/dist/library/index.cjs +1 -19
- package/dist/library/locale/index.cjs +1 -39
- package/dist/library/locale/langs/en-us/index.cjs +1 -32
- package/dist/library/locale/langs/zh-cn/index.cjs +1 -32
- package/dist/library/locale/types.cjs +1 -4
- package/dist/library/storage/cache.cjs +1 -243
- package/dist/library/storage/encryption.cjs +1 -147
- package/dist/library/storage/index.cjs +1 -124
- package/dist/state/StateManager.cjs +1 -166
- package/dist/state/adapters/AdapterFactory.cjs +1 -89
- package/dist/state/adapters/DefaultAdapter.cjs +1 -75
- package/dist/state/adapters/ReduxAdapter.cjs +1 -443
- package/dist/state/adapters/ZustandAdapter.cjs +1 -69
- package/dist/state/adapters/index.cjs +1 -44
- package/dist/state/adapters/types.cjs +1 -20
- package/dist/state/core/DerivedStateInstance.cjs +1 -174
- package/dist/state/core/StateInstance.cjs +1 -170
- package/dist/state/core/StateRegistry.cjs +1 -110
- package/dist/state/core/StateScope.cjs +1 -137
- package/dist/state/core/index.cjs +1 -30
- package/dist/state/index.cjs +1 -30
- package/dist/state/types.cjs +1 -12
- package/dist/state.umd.js +1 -1
- package/dist/types.cjs +1 -4
- package/dist/utils/analytics.cjs +1 -217
- package/dist/utils/configSecurity.cjs +3 -182
- package/dist/utils/csrf.cjs +1 -18
- package/dist/utils/errors/ErrorCodes.cjs +1 -25
- package/dist/utils/errors.cjs +1 -111
- package/dist/utils/index.cjs +1 -135
- package/dist/utils/logger.cjs +1 -25
- package/dist/utils/logger.types.cjs +1 -11
- package/dist/utils/monitoring.cjs +1 -18
- package/dist/utils/performance.cjs +1 -22
- package/dist/utils/resourceLoader.cjs +1 -22
- package/dist/utils/runtimeSecurity.cjs +1 -11
- package/dist/utils/security.cjs +1 -19
- package/dist/utils/traceId.cjs +1 -37
- package/dist/utils/validation.cjs +1 -19
- package/package.json +7 -3
|
@@ -1,341 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "SplashScreen", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return SplashScreen;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
13
|
-
const _logger = require("@vlian/logger");
|
|
14
|
-
const _initialization = require("../initialization");
|
|
15
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
-
if (typeof WeakMap !== "function") return null;
|
|
17
|
-
var cacheBabelInterop = new WeakMap();
|
|
18
|
-
var cacheNodeInterop = new WeakMap();
|
|
19
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
-
})(nodeInterop);
|
|
22
|
-
}
|
|
23
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
-
return {
|
|
29
|
-
default: obj
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
-
if (cache && cache.has(obj)) {
|
|
34
|
-
return cache.get(obj);
|
|
35
|
-
}
|
|
36
|
-
var newObj = {
|
|
37
|
-
__proto__: null
|
|
38
|
-
};
|
|
39
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
|
-
for(var key in obj){
|
|
41
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
43
|
-
if (desc && (desc.get || desc.set)) {
|
|
44
|
-
Object.defineProperty(newObj, key, desc);
|
|
45
|
-
} else {
|
|
46
|
-
newObj[key] = obj[key];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
newObj.default = obj;
|
|
51
|
-
if (cache) {
|
|
52
|
-
cache.set(obj, newObj);
|
|
53
|
-
}
|
|
54
|
-
return newObj;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 启动页组件
|
|
58
|
-
*
|
|
59
|
-
* 在启动页中执行初始化,并使用 Ant Design 5 的 Spin 和 Progress 组件展示启动进度
|
|
60
|
-
*/ const SplashScreen = /*#__PURE__*/ (0, _react.memo)(({ options, onComplete })=>{
|
|
61
|
-
const [progress, setProgress] = (0, _react.useState)(0);
|
|
62
|
-
const [currentStep, setCurrentStep] = (0, _react.useState)('准备初始化...');
|
|
63
|
-
const [isInitializing, setIsInitializing] = (0, _react.useState)(false);
|
|
64
|
-
const [estimatedTime, setEstimatedTime] = (0, _react.useState)(null);
|
|
65
|
-
const [isSystemDark, setIsSystemDark] = (0, _react.useState)(()=>{
|
|
66
|
-
if (typeof window === 'undefined') {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
70
|
-
});
|
|
71
|
-
const hasCompletedRef = (0, _react.useRef)(false);
|
|
72
|
-
const onCompleteRef = (0, _react.useRef)(onComplete);
|
|
73
|
-
const optionsRef = (0, _react.useRef)(options);
|
|
74
|
-
const startTimeRef = (0, _react.useRef)(Date.now());
|
|
75
|
-
const minDisplayTimeRef = (0, _react.useRef)(options.minSplashScreenTime ?? 500); // 最小显示时间,默认 500ms
|
|
76
|
-
const progressUpdateTimerRef = (0, _react.useRef)(null);
|
|
77
|
-
const rafRef = (0, _react.useRef)(null);
|
|
78
|
-
const lastProgressRef = (0, _react.useRef)(0);
|
|
79
|
-
const progressHistoryRef = (0, _react.useRef)([]);
|
|
80
|
-
// 保持引用最新
|
|
81
|
-
(0, _react.useEffect)(()=>{
|
|
82
|
-
onCompleteRef.current = onComplete;
|
|
83
|
-
optionsRef.current = options;
|
|
84
|
-
minDisplayTimeRef.current = options.minSplashScreenTime ?? 500;
|
|
85
|
-
}, [
|
|
86
|
-
onComplete,
|
|
87
|
-
options
|
|
88
|
-
]);
|
|
89
|
-
// 自适应防抖进度更新函数(使用 requestAnimationFrame 优化)
|
|
90
|
-
const debouncedProgressUpdate = (0, _react.useCallback)((progressValue, step)=>{
|
|
91
|
-
// 取消之前的更新
|
|
92
|
-
if (rafRef.current !== null) {
|
|
93
|
-
cancelAnimationFrame(rafRef.current);
|
|
94
|
-
}
|
|
95
|
-
// 记录进度历史用于时间预估
|
|
96
|
-
const now = Date.now();
|
|
97
|
-
progressHistoryRef.current.push({
|
|
98
|
-
progress: progressValue,
|
|
99
|
-
time: now
|
|
100
|
-
});
|
|
101
|
-
// 只保留最近10个记录
|
|
102
|
-
if (progressHistoryRef.current.length > 10) {
|
|
103
|
-
progressHistoryRef.current.shift();
|
|
104
|
-
}
|
|
105
|
-
// 计算预估时间
|
|
106
|
-
if (progressHistoryRef.current.length >= 2 && progressValue > 0) {
|
|
107
|
-
const history = progressHistoryRef.current;
|
|
108
|
-
const first = history[0];
|
|
109
|
-
const last = history[history.length - 1];
|
|
110
|
-
const progressDelta = last.progress - first.progress;
|
|
111
|
-
const timeDelta = last.time - first.time;
|
|
112
|
-
if (progressDelta > 0 && timeDelta > 0) {
|
|
113
|
-
const progressPerMs = progressDelta / timeDelta;
|
|
114
|
-
const remainingProgress = 100 - progressValue;
|
|
115
|
-
const estimatedMs = remainingProgress / progressPerMs;
|
|
116
|
-
setEstimatedTime(Math.max(0, Math.round(estimatedMs)));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// 使用 requestAnimationFrame 优化更新
|
|
120
|
-
rafRef.current = requestAnimationFrame(()=>{
|
|
121
|
-
setProgress(progressValue);
|
|
122
|
-
if (step) {
|
|
123
|
-
setCurrentStep(step);
|
|
124
|
-
}
|
|
125
|
-
lastProgressRef.current = progressValue;
|
|
126
|
-
rafRef.current = null;
|
|
127
|
-
});
|
|
128
|
-
}, []);
|
|
129
|
-
(0, _react.useEffect)(()=>{
|
|
130
|
-
if (hasCompletedRef.current) return;
|
|
131
|
-
hasCompletedRef.current = true;
|
|
132
|
-
startTimeRef.current = Date.now();
|
|
133
|
-
const performInitialization = async ()=>{
|
|
134
|
-
try {
|
|
135
|
-
setIsInitializing(true);
|
|
136
|
-
setProgress(0);
|
|
137
|
-
setCurrentStep('开始初始化...');
|
|
138
|
-
_logger.logger.info('启动页开始执行初始化');
|
|
139
|
-
// 执行初始化,传入防抖的进度回调
|
|
140
|
-
const context = await (0, _initialization.initialization)(optionsRef.current, (progressValue, step)=>{
|
|
141
|
-
debouncedProgressUpdate(progressValue, step);
|
|
142
|
-
});
|
|
143
|
-
_logger.logger.info('启动页初始化完成', context);
|
|
144
|
-
// 动态调整最小显示时间(如果初始化很快,减少最小显示时间)
|
|
145
|
-
const elapsedTime = Date.now() - startTimeRef.current;
|
|
146
|
-
const dynamicMinTime = elapsedTime < 200 ? Math.min(minDisplayTimeRef.current, 300) : minDisplayTimeRef.current;
|
|
147
|
-
const remainingTime = Math.max(0, dynamicMinTime - elapsedTime);
|
|
148
|
-
if (remainingTime > 0) {
|
|
149
|
-
await new Promise((resolve)=>setTimeout(resolve, remainingTime));
|
|
150
|
-
}
|
|
151
|
-
// 清理防抖定时器
|
|
152
|
-
if (progressUpdateTimerRef.current) {
|
|
153
|
-
clearTimeout(progressUpdateTimerRef.current);
|
|
154
|
-
progressUpdateTimerRef.current = null;
|
|
155
|
-
}
|
|
156
|
-
// 确保进度条显示 100%
|
|
157
|
-
setProgress(100);
|
|
158
|
-
setCurrentStep('初始化完成');
|
|
159
|
-
// 初始化完成,调用回调
|
|
160
|
-
onCompleteRef.current(context);
|
|
161
|
-
} catch (error) {
|
|
162
|
-
_logger.logger.error('启动页初始化失败:', error);
|
|
163
|
-
// 设置错误状态,让 ErrorBoundary 能够捕获
|
|
164
|
-
_initialization.initializationErrorState.setError(error);
|
|
165
|
-
setCurrentStep('初始化失败,请刷新页面重试');
|
|
166
|
-
// 即使失败也调用 onComplete,让应用能够处理错误
|
|
167
|
-
onCompleteRef.current({
|
|
168
|
-
config: {},
|
|
169
|
-
progress: 0,
|
|
170
|
-
isReady: false,
|
|
171
|
-
duration: 0
|
|
172
|
-
});
|
|
173
|
-
} finally{
|
|
174
|
-
setIsInitializing(false);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
performInitialization();
|
|
178
|
-
// 清理函数
|
|
179
|
-
return ()=>{
|
|
180
|
-
if (progressUpdateTimerRef.current) {
|
|
181
|
-
clearTimeout(progressUpdateTimerRef.current);
|
|
182
|
-
}
|
|
183
|
-
if (rafRef.current !== null) {
|
|
184
|
-
cancelAnimationFrame(rafRef.current);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}, [
|
|
188
|
-
debouncedProgressUpdate
|
|
189
|
-
]);
|
|
190
|
-
(0, _react.useEffect)(()=>{
|
|
191
|
-
if (typeof window === 'undefined') {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
195
|
-
const onSystemThemeChange = (event)=>{
|
|
196
|
-
setIsSystemDark(event.matches);
|
|
197
|
-
};
|
|
198
|
-
setIsSystemDark(mediaQuery.matches);
|
|
199
|
-
if (typeof mediaQuery.addEventListener === 'function') {
|
|
200
|
-
mediaQuery.addEventListener('change', onSystemThemeChange);
|
|
201
|
-
return ()=>mediaQuery.removeEventListener('change', onSystemThemeChange);
|
|
202
|
-
}
|
|
203
|
-
mediaQuery.addListener(onSystemThemeChange);
|
|
204
|
-
return ()=>mediaQuery.removeListener(onSystemThemeChange);
|
|
205
|
-
}, []);
|
|
206
|
-
const resolvedMode = _react.default.useMemo(()=>{
|
|
207
|
-
const mode = optionsRef.current.theme?.mode || 'light';
|
|
208
|
-
if (mode === 'system') {
|
|
209
|
-
return isSystemDark ? 'dark' : 'light';
|
|
210
|
-
}
|
|
211
|
-
return mode === 'dark' ? 'dark' : 'light';
|
|
212
|
-
}, [
|
|
213
|
-
isSystemDark
|
|
214
|
-
]);
|
|
215
|
-
const palette = _react.default.useMemo(()=>{
|
|
216
|
-
if (resolvedMode === 'dark') {
|
|
217
|
-
return {
|
|
218
|
-
background: '#0b1220',
|
|
219
|
-
text: '#e2e8f0',
|
|
220
|
-
subText: '#94a3b8',
|
|
221
|
-
track: '#1f2937',
|
|
222
|
-
spinnerTrack: '#334155'
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
background: '#f5f7fb',
|
|
227
|
-
text: '#51606f',
|
|
228
|
-
subText: '#94a3b8',
|
|
229
|
-
track: '#e9eff5',
|
|
230
|
-
spinnerTrack: '#d9e2ec'
|
|
231
|
-
};
|
|
232
|
-
}, [
|
|
233
|
-
resolvedMode
|
|
234
|
-
]);
|
|
235
|
-
// 如果提供了自定义启动屏组件,使用自定义组件
|
|
236
|
-
const CustomSplashScreen = optionsRef.current.splashScreen;
|
|
237
|
-
if (CustomSplashScreen) {
|
|
238
|
-
const customProps = {
|
|
239
|
-
progress,
|
|
240
|
-
currentStep,
|
|
241
|
-
isInitializing
|
|
242
|
-
};
|
|
243
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(CustomSplashScreen, {
|
|
244
|
-
...customProps
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
// 默认启动屏 UI
|
|
248
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
249
|
-
role: "status",
|
|
250
|
-
"aria-live": "polite",
|
|
251
|
-
"aria-label": "应用正在加载",
|
|
252
|
-
style: {
|
|
253
|
-
display: 'flex',
|
|
254
|
-
flexDirection: 'column',
|
|
255
|
-
alignItems: 'center',
|
|
256
|
-
justifyContent: 'center',
|
|
257
|
-
height: '100vh',
|
|
258
|
-
width: '100%',
|
|
259
|
-
gap: 24,
|
|
260
|
-
background: palette.background,
|
|
261
|
-
color: palette.text
|
|
262
|
-
},
|
|
263
|
-
children: [
|
|
264
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
265
|
-
"aria-label": "加载中",
|
|
266
|
-
style: {
|
|
267
|
-
width: 42,
|
|
268
|
-
height: 42,
|
|
269
|
-
border: `4px solid ${palette.spinnerTrack}`,
|
|
270
|
-
borderTopColor: 'var(--app-primary-color, #2f80ed)',
|
|
271
|
-
borderRadius: '50%',
|
|
272
|
-
animation: 'secra-spin 1s linear infinite'
|
|
273
|
-
}
|
|
274
|
-
}),
|
|
275
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
276
|
-
style: {
|
|
277
|
-
width: '300px'
|
|
278
|
-
},
|
|
279
|
-
children: [
|
|
280
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
281
|
-
"aria-label": `加载进度 ${progress}%`,
|
|
282
|
-
style: {
|
|
283
|
-
height: 12,
|
|
284
|
-
background: palette.track,
|
|
285
|
-
borderRadius: 999,
|
|
286
|
-
overflow: 'hidden'
|
|
287
|
-
},
|
|
288
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
289
|
-
style: {
|
|
290
|
-
width: `${Math.max(0, Math.min(100, progress))}%`,
|
|
291
|
-
height: '100%',
|
|
292
|
-
background: 'var(--app-primary-color, #2f80ed)',
|
|
293
|
-
transition: 'width 0.2s ease'
|
|
294
|
-
}
|
|
295
|
-
})
|
|
296
|
-
}),
|
|
297
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
298
|
-
style: {
|
|
299
|
-
marginTop: 8,
|
|
300
|
-
textAlign: 'right',
|
|
301
|
-
fontSize: 12,
|
|
302
|
-
color: palette.text
|
|
303
|
-
},
|
|
304
|
-
children: [
|
|
305
|
-
progress,
|
|
306
|
-
"%"
|
|
307
|
-
]
|
|
308
|
-
})
|
|
309
|
-
]
|
|
310
|
-
}),
|
|
311
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
312
|
-
role: "status",
|
|
313
|
-
"aria-live": "polite",
|
|
314
|
-
style: {
|
|
315
|
-
fontSize: 14,
|
|
316
|
-
color: palette.text,
|
|
317
|
-
textAlign: 'center'
|
|
318
|
-
},
|
|
319
|
-
children: [
|
|
320
|
-
currentStep,
|
|
321
|
-
estimatedTime !== null && estimatedTime > 0 && /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
322
|
-
style: {
|
|
323
|
-
fontSize: 12,
|
|
324
|
-
color: palette.subText,
|
|
325
|
-
marginTop: 8
|
|
326
|
-
},
|
|
327
|
-
children: [
|
|
328
|
-
"预计还需 ",
|
|
329
|
-
Math.ceil(estimatedTime / 1000),
|
|
330
|
-
" 秒"
|
|
331
|
-
]
|
|
332
|
-
})
|
|
333
|
-
]
|
|
334
|
-
}),
|
|
335
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("style", {
|
|
336
|
-
children: `@keyframes secra-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }`
|
|
337
|
-
})
|
|
338
|
-
]
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
SplashScreen.displayName = 'SplashScreen';
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"SplashScreen",{enumerable:true,get:function(){return SplashScreen}});const _jsxruntime=require("react/jsx-runtime");const _react=/*#__PURE__*/_interop_require_wildcard(require("react"));const _logger=require("@vlian/logger");const _initialization=require("../initialization");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}const SplashScreen=(0,_react.memo)(({options,onComplete})=>{const[progress,setProgress]=(0,_react.useState)(0);const[currentStep,setCurrentStep]=(0,_react.useState)("准备初始化...");const[isInitializing,setIsInitializing]=(0,_react.useState)(false);const[estimatedTime,setEstimatedTime]=(0,_react.useState)(null);const[isSystemDark,setIsSystemDark]=(0,_react.useState)(()=>{if(typeof window==="undefined"){return false}return window.matchMedia("(prefers-color-scheme: dark)").matches});const hasCompletedRef=(0,_react.useRef)(false);const onCompleteRef=(0,_react.useRef)(onComplete);const optionsRef=(0,_react.useRef)(options);const startTimeRef=(0,_react.useRef)(Date.now());const minDisplayTimeRef=(0,_react.useRef)(options.minSplashScreenTime??500);const progressUpdateTimerRef=(0,_react.useRef)(null);const rafRef=(0,_react.useRef)(null);const lastProgressRef=(0,_react.useRef)(0);const progressHistoryRef=(0,_react.useRef)([]);(0,_react.useEffect)(()=>{onCompleteRef.current=onComplete;optionsRef.current=options;minDisplayTimeRef.current=options.minSplashScreenTime??500},[onComplete,options]);const debouncedProgressUpdate=(0,_react.useCallback)((progressValue,step)=>{if(rafRef.current!==null){cancelAnimationFrame(rafRef.current)}const now=Date.now();progressHistoryRef.current.push({progress:progressValue,time:now});if(progressHistoryRef.current.length>10){progressHistoryRef.current.shift()}if(progressHistoryRef.current.length>=2&&progressValue>0){const history=progressHistoryRef.current;const first=history[0];const last=history[history.length-1];const progressDelta=last.progress-first.progress;const timeDelta=last.time-first.time;if(progressDelta>0&&timeDelta>0){const progressPerMs=progressDelta/timeDelta;const remainingProgress=100-progressValue;const estimatedMs=remainingProgress/progressPerMs;setEstimatedTime(Math.max(0,Math.round(estimatedMs)))}}rafRef.current=requestAnimationFrame(()=>{setProgress(progressValue);if(step){setCurrentStep(step)}lastProgressRef.current=progressValue;rafRef.current=null})},[]);(0,_react.useEffect)(()=>{if(hasCompletedRef.current)return;hasCompletedRef.current=true;startTimeRef.current=Date.now();const performInitialization=async()=>{try{setIsInitializing(true);setProgress(0);setCurrentStep("开始初始化...");_logger.logger.info("启动页开始执行初始化");const context=await (0,_initialization.initialization)(optionsRef.current,(progressValue,step)=>{debouncedProgressUpdate(progressValue,step)});_logger.logger.info("启动页初始化完成",context);const elapsedTime=Date.now()-startTimeRef.current;const dynamicMinTime=elapsedTime<200?Math.min(minDisplayTimeRef.current,300):minDisplayTimeRef.current;const remainingTime=Math.max(0,dynamicMinTime-elapsedTime);if(remainingTime>0){await new Promise(resolve=>setTimeout(resolve,remainingTime))}if(progressUpdateTimerRef.current){clearTimeout(progressUpdateTimerRef.current);progressUpdateTimerRef.current=null}setProgress(100);setCurrentStep("初始化完成");onCompleteRef.current(context)}catch(error){_logger.logger.error("启动页初始化失败:",error);_initialization.initializationErrorState.setError(error);setCurrentStep("初始化失败,请刷新页面重试");onCompleteRef.current({config:{},progress:0,isReady:false,duration:0})}finally{setIsInitializing(false)}};performInitialization();return()=>{if(progressUpdateTimerRef.current){clearTimeout(progressUpdateTimerRef.current)}if(rafRef.current!==null){cancelAnimationFrame(rafRef.current)}}},[debouncedProgressUpdate]);(0,_react.useEffect)(()=>{if(typeof window==="undefined"){return}const mediaQuery=window.matchMedia("(prefers-color-scheme: dark)");const onSystemThemeChange=event=>{setIsSystemDark(event.matches)};setIsSystemDark(mediaQuery.matches);if(typeof mediaQuery.addEventListener==="function"){mediaQuery.addEventListener("change",onSystemThemeChange);return()=>mediaQuery.removeEventListener("change",onSystemThemeChange)}mediaQuery.addListener(onSystemThemeChange);return()=>mediaQuery.removeListener(onSystemThemeChange)},[]);const resolvedMode=_react.default.useMemo(()=>{const mode=optionsRef.current.theme?.mode||"light";if(mode==="system"){return isSystemDark?"dark":"light"}return mode==="dark"?"dark":"light"},[isSystemDark]);const palette=_react.default.useMemo(()=>{if(resolvedMode==="dark"){return{background:"#0b1220",text:"#e2e8f0",subText:"#94a3b8",track:"#1f2937",spinnerTrack:"#334155"}}return{background:"#f5f7fb",text:"#51606f",subText:"#94a3b8",track:"#e9eff5",spinnerTrack:"#d9e2ec"}},[resolvedMode]);const CustomSplashScreen=optionsRef.current.splashScreen;if(CustomSplashScreen){const customProps={progress,currentStep,isInitializing};return(0,_jsxruntime.jsx)(CustomSplashScreen,{...customProps})}return(0,_jsxruntime.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"应用正在加载",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100vh",width:"100%",gap:24,background:palette.background,color:palette.text},children:[(0,_jsxruntime.jsx)("div",{"aria-label":"加载中",style:{width:42,height:42,border:`4px solid ${palette.spinnerTrack}`,borderTopColor:"var(--app-primary-color, #2f80ed)",borderRadius:"50%",animation:"secra-spin 1s linear infinite"}}),(0,_jsxruntime.jsxs)("div",{style:{width:"300px"},children:[(0,_jsxruntime.jsx)("div",{"aria-label":`加载进度 ${progress}%`,style:{height:12,background:palette.track,borderRadius:999,overflow:"hidden"},children:(0,_jsxruntime.jsx)("div",{style:{width:`${Math.max(0,Math.min(100,progress))}%`,height:"100%",background:"var(--app-primary-color, #2f80ed)",transition:"width 0.2s ease"}})}),(0,_jsxruntime.jsxs)("div",{style:{marginTop:8,textAlign:"right",fontSize:12,color:palette.text},children:[progress,"%"]})]}),(0,_jsxruntime.jsxs)("div",{role:"status","aria-live":"polite",style:{fontSize:14,color:palette.text,textAlign:"center"},children:[currentStep,estimatedTime!==null&&estimatedTime>0&&(0,_jsxruntime.jsxs)("div",{style:{fontSize:12,color:palette.subText,marginTop:8},children:["预计还需 ",Math.ceil(estimatedTime/1e3)," 秒"]})]}),(0,_jsxruntime.jsx)("style",{children:`@keyframes secra-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }`})]})});SplashScreen.displayName="SplashScreen";
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 启动页模块统一导出
|
|
3
|
-
*/ "use strict";
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
function _export(target, all) {
|
|
8
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
_export(exports, {
|
|
14
|
-
get SplashScreen () {
|
|
15
|
-
return _SplashScreen.SplashScreen;
|
|
16
|
-
},
|
|
17
|
-
get shouldShowSplashScreen () {
|
|
18
|
-
return _splashScreenUtils.shouldShowSplashScreen;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const _SplashScreen = require("./SplashScreen");
|
|
22
|
-
const _splashScreenUtils = require("./splashScreenUtils");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get SplashScreen(){return _SplashScreen.SplashScreen},get shouldShowSplashScreen(){return _splashScreenUtils.shouldShowSplashScreen}});const _SplashScreen=require("./SplashScreen");const _splashScreenUtils=require("./splashScreenUtils");
|
|
@@ -1,38 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 判断是否应该显示启动页
|
|
3
|
-
*
|
|
4
|
-
* @param showSplashScreen - 启动页显示策略
|
|
5
|
-
* @returns boolean
|
|
6
|
-
*/ "use strict";
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
Object.defineProperty(exports, "shouldShowSplashScreen", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return shouldShowSplashScreen;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
function shouldShowSplashScreen(showSplashScreen) {
|
|
17
|
-
// 明确指定不显示
|
|
18
|
-
if (showSplashScreen === 'never') {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
// 明确指定总是显示
|
|
22
|
-
if (showSplashScreen === 'always') {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
// 仅首次加载显示
|
|
26
|
-
if (showSplashScreen === 'first-time-only') {
|
|
27
|
-
const hasVisited = sessionStorage.getItem('__framework_visited__');
|
|
28
|
-
if (hasVisited) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
sessionStorage.setItem('__framework_visited__', 'true');
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
// 自动判断(默认策略)
|
|
35
|
-
// 这里可以根据实际情况添加更多判断逻辑
|
|
36
|
-
// 例如:根据启动时间、网络状况等
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"shouldShowSplashScreen",{enumerable:true,get:function(){return shouldShowSplashScreen}});function shouldShowSplashScreen(showSplashScreen){if(showSplashScreen==="never"){return false}if(showSplashScreen==="always"){return true}if(showSplashScreen==="first-time-only"){const hasVisited=sessionStorage.getItem("__framework_visited__");if(hasVisited){return false}sessionStorage.setItem("__framework_visited__","true");return true}return true}
|
|
@@ -1,239 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* 应用实例管理模块
|
|
3
|
-
* 支持多实例隔离
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
function _export(target, all) {
|
|
9
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
_export(exports, {
|
|
15
|
-
get AppInstance () {
|
|
16
|
-
return AppInstance;
|
|
17
|
-
},
|
|
18
|
-
get AppInstanceManager () {
|
|
19
|
-
return AppInstanceManager;
|
|
20
|
-
},
|
|
21
|
-
get getAppInstanceManager () {
|
|
22
|
-
return getAppInstanceManager;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const _renderApp = require("./renderApp");
|
|
26
|
-
const _performanceTracker = require("./performanceTracker");
|
|
27
|
-
function _define_property(obj, key, value) {
|
|
28
|
-
if (key in obj) {
|
|
29
|
-
Object.defineProperty(obj, key, {
|
|
30
|
-
value: value,
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
obj[key] = value;
|
|
37
|
-
}
|
|
38
|
-
return obj;
|
|
39
|
-
}
|
|
40
|
-
let AppInstance = class AppInstance {
|
|
41
|
-
/**
|
|
42
|
-
* 初始化应用实例
|
|
43
|
-
*
|
|
44
|
-
* @param container - React应用的挂载容器
|
|
45
|
-
* @param services - 服务实例
|
|
46
|
-
*/ initialize(container, services) {
|
|
47
|
-
if (this.initialized) {
|
|
48
|
-
throw new Error(`应用实例 ${this.id} 已经初始化`);
|
|
49
|
-
}
|
|
50
|
-
if (this.destroyed) {
|
|
51
|
-
throw new Error(`应用实例 ${this.id} 已销毁,无法重新初始化`);
|
|
52
|
-
}
|
|
53
|
-
this.services = services;
|
|
54
|
-
this.renderer.initialize(container, this.options.rootOptions);
|
|
55
|
-
this.performanceTracker = new _performanceTracker.PerformanceTracker(services.monitoring);
|
|
56
|
-
this.performanceTracker.collectWebVitals();
|
|
57
|
-
this.initialized = true;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 获取渲染器
|
|
61
|
-
*/ getRenderer() {
|
|
62
|
-
if (!this.initialized) {
|
|
63
|
-
throw new Error(`应用实例 ${this.id} 未初始化`);
|
|
64
|
-
}
|
|
65
|
-
return this.renderer;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 获取服务实例
|
|
69
|
-
*/ getServices() {
|
|
70
|
-
if (!this.services) {
|
|
71
|
-
throw new Error(`应用实例 ${this.id} 未初始化`);
|
|
72
|
-
}
|
|
73
|
-
return this.services;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 获取性能追踪器
|
|
77
|
-
*/ getPerformanceTracker() {
|
|
78
|
-
return this.performanceTracker;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 获取事件总线
|
|
82
|
-
*/ getEventBus() {
|
|
83
|
-
if (!this.services) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
return this.services.eventBus;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 获取启动配置
|
|
90
|
-
*/ getOptions() {
|
|
91
|
-
return this.options;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 是否已初始化
|
|
95
|
-
*/ isInitialized() {
|
|
96
|
-
return this.initialized;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* 是否已销毁
|
|
100
|
-
*/ isDestroyed() {
|
|
101
|
-
return this.destroyed;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* 销毁应用实例
|
|
105
|
-
*/ destroy() {
|
|
106
|
-
if (this.destroyed) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.renderer.destroy();
|
|
110
|
-
this.services = null;
|
|
111
|
-
this.performanceTracker = null;
|
|
112
|
-
this.destroyed = true;
|
|
113
|
-
}
|
|
114
|
-
constructor(id, options){
|
|
115
|
-
/**
|
|
116
|
-
* 实例ID
|
|
117
|
-
*/ _define_property(this, "id", void 0);
|
|
118
|
-
/**
|
|
119
|
-
* 应用渲染器
|
|
120
|
-
*/ _define_property(this, "renderer", void 0);
|
|
121
|
-
/**
|
|
122
|
-
* 服务实例
|
|
123
|
-
*/ _define_property(this, "services", null);
|
|
124
|
-
/**
|
|
125
|
-
* 性能追踪器
|
|
126
|
-
*/ _define_property(this, "performanceTracker", null);
|
|
127
|
-
/**
|
|
128
|
-
* 启动配置
|
|
129
|
-
*/ _define_property(this, "options", void 0);
|
|
130
|
-
/**
|
|
131
|
-
* 是否已初始化
|
|
132
|
-
*/ _define_property(this, "initialized", false);
|
|
133
|
-
/**
|
|
134
|
-
* 是否已销毁
|
|
135
|
-
*/ _define_property(this, "destroyed", false);
|
|
136
|
-
this.id = id;
|
|
137
|
-
this.options = options;
|
|
138
|
-
this.renderer = new _renderApp.AppRenderer();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
let AppInstanceManager = class AppInstanceManager {
|
|
142
|
-
/**
|
|
143
|
-
* 获取单例实例
|
|
144
|
-
*/ static getInstance() {
|
|
145
|
-
if (!AppInstanceManager.instance) {
|
|
146
|
-
AppInstanceManager.instance = new AppInstanceManager();
|
|
147
|
-
}
|
|
148
|
-
return AppInstanceManager.instance;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 创建应用实例
|
|
152
|
-
*
|
|
153
|
-
* @param id - 实例ID,如果不提供则自动生成
|
|
154
|
-
* @param options - 启动配置选项
|
|
155
|
-
* @returns 应用实例
|
|
156
|
-
*/ createInstance(id, options = {}) {
|
|
157
|
-
const instanceId = id || `app-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
158
|
-
if (this.instances.has(instanceId)) {
|
|
159
|
-
throw new Error(`应用实例 ${instanceId} 已存在`);
|
|
160
|
-
}
|
|
161
|
-
const instance = new AppInstance(instanceId, options);
|
|
162
|
-
this.instances.set(instanceId, instance);
|
|
163
|
-
// 如果没有默认实例,设置为默认实例
|
|
164
|
-
if (!this.defaultInstanceId) {
|
|
165
|
-
this.defaultInstanceId = instanceId;
|
|
166
|
-
}
|
|
167
|
-
return instance;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* 获取应用实例
|
|
171
|
-
*
|
|
172
|
-
* @param id - 实例ID,如果不提供则返回默认实例
|
|
173
|
-
* @returns 应用实例或undefined
|
|
174
|
-
*/ getInstance(id) {
|
|
175
|
-
const instanceId = id || this.defaultInstanceId;
|
|
176
|
-
if (!instanceId) {
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
return this.instances.get(instanceId);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* 销毁应用实例
|
|
183
|
-
*
|
|
184
|
-
* @param id - 实例ID,如果不提供则销毁默认实例
|
|
185
|
-
*/ destroyInstance(id) {
|
|
186
|
-
const instanceId = id || this.defaultInstanceId;
|
|
187
|
-
if (!instanceId) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const instance = this.instances.get(instanceId);
|
|
191
|
-
if (instance) {
|
|
192
|
-
instance.destroy();
|
|
193
|
-
this.instances.delete(instanceId);
|
|
194
|
-
// 如果销毁的是默认实例,重新设置默认实例
|
|
195
|
-
if (this.defaultInstanceId === instanceId) {
|
|
196
|
-
const remainingInstances = Array.from(this.instances.keys());
|
|
197
|
-
this.defaultInstanceId = remainingInstances.length > 0 ? remainingInstances[0] : null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* 获取所有实例
|
|
203
|
-
*/ getAllInstances() {
|
|
204
|
-
return Array.from(this.instances.values());
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* 设置默认实例
|
|
208
|
-
*
|
|
209
|
-
* @param id - 实例ID
|
|
210
|
-
*/ setDefaultInstance(id) {
|
|
211
|
-
if (!this.instances.has(id)) {
|
|
212
|
-
throw new Error(`应用实例 ${id} 不存在`);
|
|
213
|
-
}
|
|
214
|
-
this.defaultInstanceId = id;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* 获取默认实例ID
|
|
218
|
-
*/ getDefaultInstanceId() {
|
|
219
|
-
return this.defaultInstanceId;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* 清空所有实例
|
|
223
|
-
*/ clear() {
|
|
224
|
-
for (const instance of this.instances.values()){
|
|
225
|
-
instance.destroy();
|
|
226
|
-
}
|
|
227
|
-
this.instances.clear();
|
|
228
|
-
this.defaultInstanceId = null;
|
|
229
|
-
}
|
|
230
|
-
constructor(){
|
|
231
|
-
_define_property(this, "instances", new Map());
|
|
232
|
-
_define_property(this, "defaultInstanceId", null);
|
|
233
|
-
// 私有构造函数
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
_define_property(AppInstanceManager, "instance", null);
|
|
237
|
-
function getAppInstanceManager() {
|
|
238
|
-
return AppInstanceManager.getInstance();
|
|
239
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get AppInstance(){return AppInstance},get AppInstanceManager(){return AppInstanceManager},get getAppInstanceManager(){return getAppInstanceManager}});const _renderApp=require("./renderApp");const _performanceTracker=require("./performanceTracker");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let AppInstance=class AppInstance{initialize(container,services){if(this.initialized){throw new Error(`应用实例 ${this.id} 已经初始化`)}if(this.destroyed){throw new Error(`应用实例 ${this.id} 已销毁,无法重新初始化`)}this.services=services;this.renderer.initialize(container,this.options.rootOptions);this.performanceTracker=new _performanceTracker.PerformanceTracker(services.monitoring);this.performanceTracker.collectWebVitals();this.initialized=true}getRenderer(){if(!this.initialized){throw new Error(`应用实例 ${this.id} 未初始化`)}return this.renderer}getServices(){if(!this.services){throw new Error(`应用实例 ${this.id} 未初始化`)}return this.services}getPerformanceTracker(){return this.performanceTracker}getEventBus(){if(!this.services){return null}return this.services.eventBus}getOptions(){return this.options}isInitialized(){return this.initialized}isDestroyed(){return this.destroyed}destroy(){if(this.destroyed){return}this.renderer.destroy();this.services=null;this.performanceTracker=null;this.destroyed=true}constructor(id,options){_define_property(this,"id",void 0);_define_property(this,"renderer",void 0);_define_property(this,"services",null);_define_property(this,"performanceTracker",null);_define_property(this,"options",void 0);_define_property(this,"initialized",false);_define_property(this,"destroyed",false);this.id=id;this.options=options;this.renderer=new _renderApp.AppRenderer}};let AppInstanceManager=class AppInstanceManager{static getInstance(){if(!AppInstanceManager.instance){AppInstanceManager.instance=new AppInstanceManager}return AppInstanceManager.instance}createInstance(id,options={}){const instanceId=id||`app-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;if(this.instances.has(instanceId)){throw new Error(`应用实例 ${instanceId} 已存在`)}const instance=new AppInstance(instanceId,options);this.instances.set(instanceId,instance);if(!this.defaultInstanceId){this.defaultInstanceId=instanceId}return instance}getInstance(id){const instanceId=id||this.defaultInstanceId;if(!instanceId){return undefined}return this.instances.get(instanceId)}destroyInstance(id){const instanceId=id||this.defaultInstanceId;if(!instanceId){return}const instance=this.instances.get(instanceId);if(instance){instance.destroy();this.instances.delete(instanceId);if(this.defaultInstanceId===instanceId){const remainingInstances=Array.from(this.instances.keys());this.defaultInstanceId=remainingInstances.length>0?remainingInstances[0]:null}}}getAllInstances(){return Array.from(this.instances.values())}setDefaultInstance(id){if(!this.instances.has(id)){throw new Error(`应用实例 ${id} 不存在`)}this.defaultInstanceId=id}getDefaultInstanceId(){return this.defaultInstanceId}clear(){for(const instance of this.instances.values()){instance.destroy()}this.instances.clear();this.defaultInstanceId=null}constructor(){_define_property(this,"instances",new Map);_define_property(this,"defaultInstanceId",null)}};_define_property(AppInstanceManager,"instance",null);function getAppInstanceManager(){return AppInstanceManager.getInstance()}
|