@finesoft/front 0.1.53 → 0.1.55
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/README.md +253 -0
- package/dist/index.d.mts +492 -16
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +633 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -60,12 +60,20 @@ type Factory<T> = () => T;
|
|
|
60
60
|
declare class Container {
|
|
61
61
|
private registrations;
|
|
62
62
|
private resolutionStack;
|
|
63
|
+
private parent?;
|
|
63
64
|
/** 注册依赖(默认单例) */
|
|
64
65
|
register<T>(key: string, factory: Factory<T>, singleton?: boolean): this;
|
|
65
|
-
/** 解析依赖 */
|
|
66
|
+
/** 解析依赖 — 当前容器未注册时回退到 parent */
|
|
66
67
|
resolve<T>(key: string): T;
|
|
67
|
-
/**
|
|
68
|
+
/** 检查是否已注册(含 parent) */
|
|
68
69
|
has(key: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* 创建子容器(请求级 scope)
|
|
72
|
+
*
|
|
73
|
+
* 子容器可覆写父容器的依赖(如每请求的 locale、user),
|
|
74
|
+
* 未覆写的 key 自动回退到父容器解析。
|
|
75
|
+
*/
|
|
76
|
+
createScope(): Container;
|
|
69
77
|
/** 销毁容器,清除所有缓存 */
|
|
70
78
|
dispose(): void;
|
|
71
79
|
}
|
|
@@ -117,6 +125,110 @@ interface LoggerFactory {
|
|
|
117
125
|
loggerFor(category: string): Logger;
|
|
118
126
|
}
|
|
119
127
|
//#endregion
|
|
128
|
+
//#region ../core/src/logger/base.d.ts
|
|
129
|
+
declare abstract class BaseLogger implements Logger {
|
|
130
|
+
protected category: string;
|
|
131
|
+
constructor(category: string);
|
|
132
|
+
abstract debug(...args: unknown[]): string;
|
|
133
|
+
abstract info(...args: unknown[]): string;
|
|
134
|
+
abstract warn(...args: unknown[]): string;
|
|
135
|
+
abstract error(...args: unknown[]): string;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../core/src/logger/reporting.d.ts
|
|
139
|
+
/** 日志上报回调 */
|
|
140
|
+
interface ReportCallback {
|
|
141
|
+
(level: Level, category: string, args: unknown[]): void;
|
|
142
|
+
}
|
|
143
|
+
/** 配置 */
|
|
144
|
+
interface ReportingLoggerOptions {
|
|
145
|
+
/** 最低上报级别(默认 "warn") */
|
|
146
|
+
minLevel?: Level;
|
|
147
|
+
/** 上报回调 */
|
|
148
|
+
report: ReportCallback;
|
|
149
|
+
}
|
|
150
|
+
declare class ReportingLogger extends BaseLogger {
|
|
151
|
+
private readonly minPriority;
|
|
152
|
+
private readonly report;
|
|
153
|
+
constructor(category: string, options: ReportingLoggerOptions);
|
|
154
|
+
debug(...args: unknown[]): string;
|
|
155
|
+
info(...args: unknown[]): string;
|
|
156
|
+
warn(...args: unknown[]): string;
|
|
157
|
+
error(...args: unknown[]): string;
|
|
158
|
+
private maybeReport;
|
|
159
|
+
}
|
|
160
|
+
declare class ReportingLoggerFactory implements LoggerFactory {
|
|
161
|
+
private readonly options;
|
|
162
|
+
constructor(options: ReportingLoggerOptions);
|
|
163
|
+
loggerFor(category: string): Logger;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region ../core/src/metrics/types.d.ts
|
|
167
|
+
/**
|
|
168
|
+
* Metrics — 类型定义
|
|
169
|
+
*
|
|
170
|
+
* 框架级埋点基础设施的核心接口。
|
|
171
|
+
*/
|
|
172
|
+
/** 事件记录器 — 所有 metrics 后端实现此接口 */
|
|
173
|
+
interface EventRecorder {
|
|
174
|
+
/** 记录一条事件 */
|
|
175
|
+
record(type: string, fields?: Record<string, unknown>): void;
|
|
176
|
+
/** 刷新待发送的事件队列 */
|
|
177
|
+
flush?(): Promise<void>;
|
|
178
|
+
/** 销毁记录器,释放资源 */
|
|
179
|
+
destroy?(): void;
|
|
180
|
+
}
|
|
181
|
+
/** 字段提供者 — 每次记录前自动注入公共字段 */
|
|
182
|
+
interface MetricsFieldsProvider {
|
|
183
|
+
/** 返回需要附加到每条事件的字段 */
|
|
184
|
+
getFields(): Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
/** Impression 条目 */
|
|
187
|
+
interface ImpressionEntry {
|
|
188
|
+
/** 被追踪元素的唯一标识 */
|
|
189
|
+
id: string;
|
|
190
|
+
/** 元素进入视口的时间戳 */
|
|
191
|
+
timestamp: number;
|
|
192
|
+
/** 附加数据 */
|
|
193
|
+
metadata?: Record<string, unknown>;
|
|
194
|
+
}
|
|
195
|
+
/** Impression 观察器 — 追踪元素可见性 */
|
|
196
|
+
interface ImpressionObserver {
|
|
197
|
+
/** 开始追踪一个元素 */
|
|
198
|
+
observe(element: Element, id: string, metadata?: Record<string, unknown>): void;
|
|
199
|
+
/** 停止追踪一个元素 */
|
|
200
|
+
unobserve(element: Element): void;
|
|
201
|
+
/** 获取已捕获的曝光并清空 */
|
|
202
|
+
consume(): ImpressionEntry[];
|
|
203
|
+
/** 销毁观察器 */
|
|
204
|
+
destroy(): void;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region ../core/src/utils/platform.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Platform — UA 解析与平台检测
|
|
210
|
+
*
|
|
211
|
+
* 提供统一的平台/浏览器/OS 检测,避免在各处手写 UA 判断。
|
|
212
|
+
*/
|
|
213
|
+
interface PlatformInfo {
|
|
214
|
+
/** 操作系统 */
|
|
215
|
+
os: "ios" | "android" | "macos" | "windows" | "linux" | "unknown";
|
|
216
|
+
/** 浏览器 */
|
|
217
|
+
browser: "safari" | "chrome" | "firefox" | "edge" | "opera" | "samsung" | "unknown";
|
|
218
|
+
/** 渲染引擎 */
|
|
219
|
+
engine: "webkit" | "blink" | "gecko" | "unknown";
|
|
220
|
+
/** 是否为移动设备 */
|
|
221
|
+
isMobile: boolean;
|
|
222
|
+
/** 是否为触摸设备 */
|
|
223
|
+
isTouch: boolean;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 从 User-Agent 字符串解析平台信息
|
|
227
|
+
*
|
|
228
|
+
* @param ua - User-Agent 字符串(默认取 navigator.userAgent)
|
|
229
|
+
*/
|
|
230
|
+
declare function detectPlatform(ua?: string): PlatformInfo;
|
|
231
|
+
//#endregion
|
|
120
232
|
//#region ../core/src/dependencies/make-dependencies.d.ts
|
|
121
233
|
/** 网络请求层 */
|
|
122
234
|
interface Net {
|
|
@@ -134,10 +246,24 @@ interface FeatureFlags {
|
|
|
134
246
|
getString(key: string): string | undefined;
|
|
135
247
|
getNumber(key: string): number | undefined;
|
|
136
248
|
}
|
|
249
|
+
/** Feature Flags Provider — 用于从远程/外部源加载 flags */
|
|
250
|
+
interface FeatureFlagsProvider {
|
|
251
|
+
isEnabled(key: string): boolean;
|
|
252
|
+
getString?(key: string): string | undefined;
|
|
253
|
+
getNumber?(key: string): number | undefined;
|
|
254
|
+
}
|
|
137
255
|
/** Metrics 记录器 */
|
|
138
256
|
interface MetricsRecorder {
|
|
257
|
+
/** 记录一条事件(通用方法) */
|
|
258
|
+
record(type: string, fields?: Record<string, unknown>): void;
|
|
259
|
+
/** 记录页面访问(便捷方法) */
|
|
139
260
|
recordPageView(page: string, fields?: Record<string, unknown>): void;
|
|
261
|
+
/** 记录自定义事件(便捷方法) */
|
|
140
262
|
recordEvent(name: string, fields?: Record<string, unknown>): void;
|
|
263
|
+
/** 刷新待发送队列 */
|
|
264
|
+
flush?(): Promise<void>;
|
|
265
|
+
/** 销毁记录器 */
|
|
266
|
+
destroy?(): void;
|
|
141
267
|
}
|
|
142
268
|
declare const DEP_KEYS: {
|
|
143
269
|
readonly LOGGER: "logger";
|
|
@@ -147,10 +273,47 @@ declare const DEP_KEYS: {
|
|
|
147
273
|
readonly FEATURE_FLAGS: "featureFlags";
|
|
148
274
|
readonly METRICS: "metrics";
|
|
149
275
|
readonly FETCH: "fetch";
|
|
276
|
+
readonly EVENT_RECORDER: "eventRecorder";
|
|
277
|
+
readonly LOCALE: "locale";
|
|
278
|
+
readonly PLATFORM: "platform";
|
|
279
|
+
readonly TRANSLATOR: "translator";
|
|
150
280
|
};
|
|
281
|
+
/** 扁平格式消息:key → 翻译字符串 */
|
|
282
|
+
type FlatMessages = Record<string, string>;
|
|
283
|
+
/** 嵌套格式消息值:字符串 或 复数表 */
|
|
284
|
+
type NestedMessageValue = string | Record<string, string>;
|
|
285
|
+
/** 按 locale 分组的嵌套消息 */
|
|
286
|
+
type LocaleMessages = Record<string, Record<string, NestedMessageValue>>;
|
|
287
|
+
/**
|
|
288
|
+
* 翻译消息映射
|
|
289
|
+
*
|
|
290
|
+
* - 扁平格式: `{ "greeting": "Hello", "itemCount.one": "1 item" }`
|
|
291
|
+
* - 按 locale 分组: `{ "en": { "greeting": "Hello", "itemCount": { "one": "1 item" } } }`
|
|
292
|
+
*/
|
|
293
|
+
type TranslationMessages = FlatMessages | LocaleMessages;
|
|
151
294
|
interface MakeDependenciesOptions {
|
|
152
295
|
fetch?: typeof globalThis.fetch;
|
|
153
296
|
featureFlags?: Record<string, boolean | string | number>;
|
|
297
|
+
/** 外部 feature flags providers(远程配置、A/B 测试等) */
|
|
298
|
+
featureFlagsProviders?: FeatureFlagsProvider[];
|
|
299
|
+
/** 日志上报回调 — 提供后自动组合 ReportingLoggerFactory */
|
|
300
|
+
reportCallback?: ReportCallback;
|
|
301
|
+
/** 自定义 EventRecorder(默认 ConsoleEventRecorder) */
|
|
302
|
+
eventRecorder?: EventRecorder;
|
|
303
|
+
/** 语言代码(如 "zh-Hans"、"en-US"),用于注入 locale 信息 */
|
|
304
|
+
locale?: string;
|
|
305
|
+
/** 自定义 PlatformInfo(默认通过 UA 自动检测) */
|
|
306
|
+
platform?: PlatformInfo;
|
|
307
|
+
/**
|
|
308
|
+
* 翻译消息映射 — 与 locale 同时提供时自动创建 SimpleTranslator 注册到容器。
|
|
309
|
+
*
|
|
310
|
+
* 支持两种格式:
|
|
311
|
+
* 1. 扁平格式(直接用于当前 locale):
|
|
312
|
+
* `{ "greeting": "Hello", "itemCount.one": "1 item" }`
|
|
313
|
+
* 2. 按 locale 分组 + 复数嵌套(自动提取当前 locale 并展平):
|
|
314
|
+
* `{ "en": { "greeting": "Hello", "itemCount": { "one": "1 item", "other": "{count} items" } } }`
|
|
315
|
+
*/
|
|
316
|
+
messages?: TranslationMessages;
|
|
154
317
|
}
|
|
155
318
|
declare function makeDependencies(container: Container, options?: MakeDependenciesOptions): void;
|
|
156
319
|
//#endregion
|
|
@@ -256,16 +419,6 @@ declare class Router {
|
|
|
256
419
|
private parseUrl;
|
|
257
420
|
}
|
|
258
421
|
//#endregion
|
|
259
|
-
//#region ../core/src/logger/base.d.ts
|
|
260
|
-
declare abstract class BaseLogger implements Logger {
|
|
261
|
-
protected category: string;
|
|
262
|
-
constructor(category: string);
|
|
263
|
-
abstract debug(...args: unknown[]): string;
|
|
264
|
-
abstract info(...args: unknown[]): string;
|
|
265
|
-
abstract warn(...args: unknown[]): string;
|
|
266
|
-
abstract error(...args: unknown[]): string;
|
|
267
|
-
}
|
|
268
|
-
//#endregion
|
|
269
422
|
//#region ../core/src/logger/composite.d.ts
|
|
270
423
|
declare class CompositeLoggerFactory implements LoggerFactory {
|
|
271
424
|
private readonly factories;
|
|
@@ -297,6 +450,51 @@ declare class ConsoleLoggerFactory implements LoggerFactory {
|
|
|
297
450
|
declare function shouldLog(name: string, level: Level): boolean;
|
|
298
451
|
declare function resetFilterCache(): void;
|
|
299
452
|
//#endregion
|
|
453
|
+
//#region ../core/src/i18n/types.d.ts
|
|
454
|
+
/**
|
|
455
|
+
* i18n — 类型定义
|
|
456
|
+
*
|
|
457
|
+
* 框架级国际化基础设施。
|
|
458
|
+
*/
|
|
459
|
+
/** 翻译函数 */
|
|
460
|
+
interface Translator {
|
|
461
|
+
/**
|
|
462
|
+
* 翻译 key → 本地化字符串
|
|
463
|
+
* @param key - 翻译 key
|
|
464
|
+
* @param values - 插值参数
|
|
465
|
+
*/
|
|
466
|
+
t(key: string, values?: Record<string, string | number>): string;
|
|
467
|
+
/**
|
|
468
|
+
* 复数形式翻译
|
|
469
|
+
* @param key - 翻译 key 前缀
|
|
470
|
+
* @param count - 数量
|
|
471
|
+
* @param values - 附加插值
|
|
472
|
+
*/
|
|
473
|
+
plural(key: string, count: number, values?: Record<string, string | number>): string;
|
|
474
|
+
/** 当前 locale(如 "zh-Hans" / "en-US") */
|
|
475
|
+
readonly locale: string;
|
|
476
|
+
}
|
|
477
|
+
/** 文本方向 */
|
|
478
|
+
type TextDirection = "ltr" | "rtl";
|
|
479
|
+
/** HTML 语言属性 */
|
|
480
|
+
interface LocaleAttributes {
|
|
481
|
+
/** BCP 47 语言标签 */
|
|
482
|
+
lang: string;
|
|
483
|
+
/** 文本方向 */
|
|
484
|
+
dir: TextDirection;
|
|
485
|
+
}
|
|
486
|
+
/** Locale 信息 */
|
|
487
|
+
interface LocaleInfo {
|
|
488
|
+
/** 语言代码(如 "zh-Hans", "en") */
|
|
489
|
+
language: string;
|
|
490
|
+
/** 地区/Storefront 代码(如 "CN", "US") */
|
|
491
|
+
region?: string;
|
|
492
|
+
/** BCP 47 完整标签 */
|
|
493
|
+
bcp47: string;
|
|
494
|
+
/** 文本方向 */
|
|
495
|
+
dir: TextDirection;
|
|
496
|
+
}
|
|
497
|
+
//#endregion
|
|
300
498
|
//#region ../core/src/prefetched-intents/prefetched-intents.d.ts
|
|
301
499
|
/** 预获取的 Intent-Data 对 */
|
|
302
500
|
interface PrefetchedIntent {
|
|
@@ -348,6 +546,12 @@ declare class Framework {
|
|
|
348
546
|
routeUrl(url: string): RouteMatch | null;
|
|
349
547
|
/** 记录页面访问事件 */
|
|
350
548
|
didEnterPage(page: BasePage): void;
|
|
549
|
+
/** 获取 locale 信息(如果已配置) */
|
|
550
|
+
getLocale(): LocaleAttributes | undefined;
|
|
551
|
+
/** 获取翻译器(如果已通过 messages + locale 配置) */
|
|
552
|
+
getTranslator(): Translator | undefined;
|
|
553
|
+
/** 获取平台信息 */
|
|
554
|
+
getPlatform(): PlatformInfo;
|
|
351
555
|
/** 注册 Action 处理器 */
|
|
352
556
|
onAction<A extends Action>(kind: string, handler: ActionHandler<A>): void;
|
|
353
557
|
/** 注册 Intent Controller */
|
|
@@ -401,6 +605,14 @@ declare class HttpError extends Error {
|
|
|
401
605
|
readonly body?: string | undefined;
|
|
402
606
|
constructor(status: number, statusText: string, body?: string | undefined);
|
|
403
607
|
}
|
|
608
|
+
/** 请求拦截器 — 在发送前修改请求 */
|
|
609
|
+
interface RequestInterceptor {
|
|
610
|
+
(url: string, init: RequestInit): RequestInit | Promise<RequestInit>;
|
|
611
|
+
}
|
|
612
|
+
/** 响应拦截器 — 在解析前修改响应 */
|
|
613
|
+
interface ResponseInterceptor {
|
|
614
|
+
(response: Response, url: string): Response | Promise<Response>;
|
|
615
|
+
}
|
|
404
616
|
/** HttpClient 构造配置 */
|
|
405
617
|
interface HttpClientConfig {
|
|
406
618
|
/** API base URL(如 "/api" 或 "https://example.com/api") */
|
|
@@ -409,6 +621,10 @@ interface HttpClientConfig {
|
|
|
409
621
|
defaultHeaders?: Record<string, string>;
|
|
410
622
|
/** 自定义 fetch 实现(便于测试或 SSR) */
|
|
411
623
|
fetch?: typeof globalThis.fetch;
|
|
624
|
+
/** 请求拦截器(按注册顺序执行) */
|
|
625
|
+
requestInterceptors?: RequestInterceptor[];
|
|
626
|
+
/** 响应拦截器(按注册顺序执行) */
|
|
627
|
+
responseInterceptors?: ResponseInterceptor[];
|
|
412
628
|
}
|
|
413
629
|
/**
|
|
414
630
|
* 通用 HTTP 客户端基类
|
|
@@ -428,7 +644,13 @@ declare abstract class HttpClient {
|
|
|
428
644
|
protected readonly baseUrl: string;
|
|
429
645
|
protected readonly defaultHeaders: Record<string, string>;
|
|
430
646
|
protected readonly fetchFn: typeof globalThis.fetch;
|
|
647
|
+
private readonly requestInterceptors;
|
|
648
|
+
private readonly responseInterceptors;
|
|
431
649
|
constructor(config: HttpClientConfig);
|
|
650
|
+
/** 动态添加请求拦截器 */
|
|
651
|
+
useRequestInterceptor(interceptor: RequestInterceptor): this;
|
|
652
|
+
/** 动态添加响应拦截器 */
|
|
653
|
+
useResponseInterceptor(interceptor: ResponseInterceptor): this;
|
|
432
654
|
/** GET 请求,返回解析后的 JSON */
|
|
433
655
|
protected get<T>(path: string, params?: Record<string, string>): Promise<T>;
|
|
434
656
|
/** POST 请求,自动序列化 body 为 JSON */
|
|
@@ -582,6 +804,22 @@ interface RouteDefinition {
|
|
|
582
804
|
*/
|
|
583
805
|
afterLoad?: AfterLoadGuard[];
|
|
584
806
|
}
|
|
807
|
+
/** defineRoutes 选项 */
|
|
808
|
+
interface DefineRoutesOptions {
|
|
809
|
+
/**
|
|
810
|
+
* 支持的 locale 列表。
|
|
811
|
+
* 提供后,每条路由会额外注册 `/:locale/path` 版本,
|
|
812
|
+
* `:locale` 参数自动出现在 `intent.params.locale` 中。
|
|
813
|
+
* 原始无前缀路径保留作为备选路由。
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* defineRoutes(framework, routes, { locales: ["zh", "en", "ja"] });
|
|
818
|
+
* // "/about" → 注册 /about + /zh/about + /en/about + /ja/about
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
821
|
+
locales?: string[];
|
|
822
|
+
}
|
|
585
823
|
/**
|
|
586
824
|
* 声明式注册路由和 Controller
|
|
587
825
|
*
|
|
@@ -599,7 +837,7 @@ interface RouteDefinition {
|
|
|
599
837
|
* ]);
|
|
600
838
|
* ```
|
|
601
839
|
*/
|
|
602
|
-
declare function defineRoutes(framework: Framework, definitions: RouteDefinition[]): void;
|
|
840
|
+
declare function defineRoutes(framework: Framework, definitions: RouteDefinition[], options?: DefineRoutesOptions): void;
|
|
603
841
|
//#endregion
|
|
604
842
|
//#region ../core/src/utils/lru-map.d.ts
|
|
605
843
|
/**
|
|
@@ -626,6 +864,22 @@ type Optional<T> = T | None;
|
|
|
626
864
|
declare function isSome<T>(value: Optional<T>): value is T;
|
|
627
865
|
declare function isNone<T>(value: Optional<T>): value is None;
|
|
628
866
|
//#endregion
|
|
867
|
+
//#region ../core/src/utils/pwa.d.ts
|
|
868
|
+
/**
|
|
869
|
+
* PWA Display Mode 检测
|
|
870
|
+
*
|
|
871
|
+
* 检测当前应用是否以 PWA 模式运行。
|
|
872
|
+
*/
|
|
873
|
+
type PWADisplayMode = "standalone" | "twa" | "browser";
|
|
874
|
+
/**
|
|
875
|
+
* 检测 PWA display mode
|
|
876
|
+
*
|
|
877
|
+
* - `standalone`: 已安装的 PWA(通过 Add to Home Screen)
|
|
878
|
+
* - `twa`: Trusted Web Activity(Android 原生壳)
|
|
879
|
+
* - `browser`: 普通浏览器标签页
|
|
880
|
+
*/
|
|
881
|
+
declare function getPWADisplayMode(): PWADisplayMode;
|
|
882
|
+
//#endregion
|
|
629
883
|
//#region ../core/src/utils/url.d.ts
|
|
630
884
|
/**
|
|
631
885
|
* URL 工具函数
|
|
@@ -671,6 +925,159 @@ declare function runBeforeLoadGuards(guards: BeforeLoadGuard[], ctx: NavigationC
|
|
|
671
925
|
/** 执行 afterLoad 守卫链 */
|
|
672
926
|
declare function runAfterLoadGuards(guards: AfterLoadGuard[], ctx: PostLoadContext): Promise<MiddlewareResult>;
|
|
673
927
|
//#endregion
|
|
928
|
+
//#region ../core/src/metrics/composite-recorder.d.ts
|
|
929
|
+
declare class CompositeEventRecorder implements EventRecorder {
|
|
930
|
+
private readonly recorders;
|
|
931
|
+
constructor(recorders: EventRecorder[]);
|
|
932
|
+
record(type: string, fields?: Record<string, unknown>): void;
|
|
933
|
+
flush(): Promise<void>;
|
|
934
|
+
destroy(): void;
|
|
935
|
+
}
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region ../core/src/metrics/console-recorder.d.ts
|
|
938
|
+
declare class ConsoleEventRecorder implements EventRecorder {
|
|
939
|
+
private readonly prefix;
|
|
940
|
+
constructor(prefix?: string);
|
|
941
|
+
record(type: string, fields?: Record<string, unknown>): void;
|
|
942
|
+
flush(): Promise<void>;
|
|
943
|
+
destroy(): void;
|
|
944
|
+
}
|
|
945
|
+
//#endregion
|
|
946
|
+
//#region ../core/src/metrics/impression-observer.d.ts
|
|
947
|
+
interface ImpressionObserverOptions {
|
|
948
|
+
/** 可见比例阈值(0~1),默认 0.5 */
|
|
949
|
+
threshold?: number;
|
|
950
|
+
/** 最小可见时长(毫秒),默认 1000 */
|
|
951
|
+
minVisibleDuration?: number;
|
|
952
|
+
}
|
|
953
|
+
declare class IntersectionImpressionObserver implements ImpressionObserver {
|
|
954
|
+
private readonly observer;
|
|
955
|
+
private readonly tracked;
|
|
956
|
+
private readonly captured;
|
|
957
|
+
private readonly minDuration;
|
|
958
|
+
constructor(options?: ImpressionObserverOptions);
|
|
959
|
+
observe(element: Element, id: string, metadata?: Record<string, unknown>): void;
|
|
960
|
+
unobserve(element: Element): void;
|
|
961
|
+
consume(): ImpressionEntry[];
|
|
962
|
+
destroy(): void;
|
|
963
|
+
}
|
|
964
|
+
//#endregion
|
|
965
|
+
//#region ../core/src/metrics/void-recorder.d.ts
|
|
966
|
+
declare class VoidEventRecorder implements EventRecorder {
|
|
967
|
+
record(): void;
|
|
968
|
+
flush(): Promise<void>;
|
|
969
|
+
destroy(): void;
|
|
970
|
+
}
|
|
971
|
+
//#endregion
|
|
972
|
+
//#region ../core/src/metrics/with-fields-recorder.d.ts
|
|
973
|
+
declare class WithFieldsRecorder implements EventRecorder {
|
|
974
|
+
private readonly inner;
|
|
975
|
+
private readonly providers;
|
|
976
|
+
constructor(inner: EventRecorder, providers: MetricsFieldsProvider[]);
|
|
977
|
+
record(type: string, fields?: Record<string, unknown>): void;
|
|
978
|
+
flush(): Promise<void>;
|
|
979
|
+
destroy(): void;
|
|
980
|
+
}
|
|
981
|
+
//#endregion
|
|
982
|
+
//#region ../core/src/i18n/interpolate.d.ts
|
|
983
|
+
/**
|
|
984
|
+
* ICU 消息格式插值
|
|
985
|
+
*
|
|
986
|
+
* 支持 `{name}` 占位符替换和基础复数规则。
|
|
987
|
+
*/
|
|
988
|
+
/** 将 `{key}` 占位符替换为 values 中的对应值 */
|
|
989
|
+
declare function interpolate(template: string, values?: Record<string, string | number>): string;
|
|
990
|
+
/**
|
|
991
|
+
* CLDR 复数类别
|
|
992
|
+
*
|
|
993
|
+
* 简化版:覆盖 zero / one / two / few / many / other。
|
|
994
|
+
* 完整 CLDR 规则可通过 PluralRuleProvider 注入。
|
|
995
|
+
*/
|
|
996
|
+
type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
997
|
+
/** 复数规则函数 — 给定数量返回复数类别 */
|
|
998
|
+
type PluralRuleProvider = (count: number) => PluralCategory;
|
|
999
|
+
/**
|
|
1000
|
+
* 英语复数规则(默认)
|
|
1001
|
+
* 0 → other, 1 → one, 2+ → other
|
|
1002
|
+
*/
|
|
1003
|
+
declare function englishPlural(count: number): PluralCategory;
|
|
1004
|
+
/**
|
|
1005
|
+
* 解析带复数后缀的翻译 key
|
|
1006
|
+
*
|
|
1007
|
+
* 约定: `key.one`, `key.other`, `key.zero`, etc.
|
|
1008
|
+
*/
|
|
1009
|
+
declare function resolvePluralKey(key: string, category: PluralCategory): string;
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region ../core/src/i18n/locale.d.ts
|
|
1012
|
+
/** 检测语言是否为 RTL */
|
|
1013
|
+
declare function isRtl(language: string): boolean;
|
|
1014
|
+
/** 获取文本方向 */
|
|
1015
|
+
declare function getTextDirection(language: string): TextDirection;
|
|
1016
|
+
/**
|
|
1017
|
+
* 从语言代码生成 HTML lang/dir 属性
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* getLocaleAttributes("ar-SA") // { lang: "ar-SA", dir: "rtl" }
|
|
1022
|
+
* getLocaleAttributes("en-US") // { lang: "en-US", dir: "ltr" }
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
declare function getLocaleAttributes(language: string): LocaleAttributes;
|
|
1026
|
+
/**
|
|
1027
|
+
* 构建 LocaleInfo
|
|
1028
|
+
*
|
|
1029
|
+
* @param language - 语言代码(如 "zh-Hans")
|
|
1030
|
+
* @param region - 地区代码(如 "CN"),可选
|
|
1031
|
+
*/
|
|
1032
|
+
declare function makeLocaleInfo(language: string, region?: string): LocaleInfo;
|
|
1033
|
+
/**
|
|
1034
|
+
* 将 locale 属性应用到 `<html>` 元素
|
|
1035
|
+
*
|
|
1036
|
+
* 服务端渲染时可用于字符串拼接,浏览器端直接操作 DOM。
|
|
1037
|
+
*/
|
|
1038
|
+
declare function setHtmlLocaleAttributes(attrs: LocaleAttributes): void;
|
|
1039
|
+
/**
|
|
1040
|
+
* 从 URL 前缀中提取 locale
|
|
1041
|
+
*
|
|
1042
|
+
* @param url - 请求 URL(如 "/zh/about")
|
|
1043
|
+
* @param supportedLocales - 支持的 locale 列表(如 ["zh", "en", "ja"])
|
|
1044
|
+
* @returns 匹配时返回 `{ locale, strippedUrl }`,不匹配返回 null
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```ts
|
|
1048
|
+
* resolveLocaleFromUrl("/zh/about", ["zh", "en"])
|
|
1049
|
+
* // → { locale: "zh", strippedUrl: "/about" }
|
|
1050
|
+
*
|
|
1051
|
+
* resolveLocaleFromUrl("/about", ["zh", "en"])
|
|
1052
|
+
* // → null
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
declare function resolveLocaleFromUrl(url: string, supportedLocales: string[]): {
|
|
1056
|
+
locale: string;
|
|
1057
|
+
strippedUrl: string;
|
|
1058
|
+
} | null;
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region ../core/src/i18n/translator.d.ts
|
|
1061
|
+
interface SimpleTranslatorOptions {
|
|
1062
|
+
/** 翻译映射 */
|
|
1063
|
+
messages: Record<string, string>;
|
|
1064
|
+
/** 当前 locale */
|
|
1065
|
+
locale: string;
|
|
1066
|
+
/** 复数规则函数(默认英语规则) */
|
|
1067
|
+
pluralRule?: PluralRuleProvider;
|
|
1068
|
+
/** 找不到翻译时的回退行为(默认返回 key) */
|
|
1069
|
+
fallback?: (key: string) => string;
|
|
1070
|
+
}
|
|
1071
|
+
declare class SimpleTranslator implements Translator {
|
|
1072
|
+
readonly locale: string;
|
|
1073
|
+
private readonly messages;
|
|
1074
|
+
private readonly pluralRule;
|
|
1075
|
+
private readonly fallback;
|
|
1076
|
+
constructor(options: SimpleTranslatorOptions);
|
|
1077
|
+
t(key: string, values?: Record<string, string | number>): string;
|
|
1078
|
+
plural(key: string, count: number, values?: Record<string, string | number>): string;
|
|
1079
|
+
}
|
|
1080
|
+
//#endregion
|
|
674
1081
|
//#region ../browser/src/action-handlers/external-url-action.d.ts
|
|
675
1082
|
interface ExternalUrlDependencies {
|
|
676
1083
|
framework: Framework;
|
|
@@ -723,6 +1130,18 @@ interface BrowserAppConfig {
|
|
|
723
1130
|
mountId?: string;
|
|
724
1131
|
/** 获取可滚动页面元素,用于滚动位置保存/恢复 */
|
|
725
1132
|
getScrollablePageElement?: () => HTMLElement | null;
|
|
1133
|
+
/**
|
|
1134
|
+
* 启动前钩子 — 在 Framework 创建后、挂载前执行
|
|
1135
|
+
*
|
|
1136
|
+
* 用于初始化错误监控、埋点 SDK、i18n 等。
|
|
1137
|
+
*/
|
|
1138
|
+
onBeforeStart?: (framework: Framework) => void | Promise<void>;
|
|
1139
|
+
/**
|
|
1140
|
+
* 启动后钩子 — 在初始页面触发后执行
|
|
1141
|
+
*
|
|
1142
|
+
* 用于启动后操作(如 service worker 注册、性能打点)。
|
|
1143
|
+
*/
|
|
1144
|
+
onAfterStart?: (framework: Framework) => void | Promise<void>;
|
|
726
1145
|
/**
|
|
727
1146
|
* 挂载应用到 DOM
|
|
728
1147
|
*
|
|
@@ -740,6 +1159,13 @@ interface BrowserAppConfig {
|
|
|
740
1159
|
}) => void;
|
|
741
1160
|
/** FlowAction / ExternalUrl 回调 */
|
|
742
1161
|
callbacks: FlowActionCallbacks;
|
|
1162
|
+
/**
|
|
1163
|
+
* Framework 配置 — locale、reportCallback、eventRecorder 等
|
|
1164
|
+
*
|
|
1165
|
+
* 传入后会在 Framework.create() 时合并。
|
|
1166
|
+
* prefetchedIntents 由框架自动从 DOM 提取,无需传入。
|
|
1167
|
+
*/
|
|
1168
|
+
frameworkConfig?: Omit<FrameworkConfig, "prefetchedIntents">;
|
|
743
1169
|
}
|
|
744
1170
|
/**
|
|
745
1171
|
* 启动客户端应用
|
|
@@ -800,6 +1226,11 @@ interface SSRRenderOptions {
|
|
|
800
1226
|
renderApp: (page: BasePage, framework: Framework) => SSRAppResult | Promise<SSRAppResult>;
|
|
801
1227
|
/** 可选的 SSR 请求上下文(如自定义 fetch) */
|
|
802
1228
|
ssrContext?: SSRContext;
|
|
1229
|
+
/** 解析请求 locale 的回调(返回 lang + dir 用于 <html> 属性) */
|
|
1230
|
+
resolveLocale?: (url: string, request?: Request) => {
|
|
1231
|
+
lang: string;
|
|
1232
|
+
dir: string;
|
|
1233
|
+
} | undefined;
|
|
803
1234
|
}
|
|
804
1235
|
/** SSR 请求级上下文 */
|
|
805
1236
|
interface SSRContext {
|
|
@@ -829,6 +1260,11 @@ interface SSRRenderResult {
|
|
|
829
1260
|
};
|
|
830
1261
|
/** 自定义 slot 替换 */
|
|
831
1262
|
slots?: Record<string, string>;
|
|
1263
|
+
/** 解析出的 locale 属性(用于 <html lang="" dir="">) */
|
|
1264
|
+
locale?: {
|
|
1265
|
+
lang: string;
|
|
1266
|
+
dir: string;
|
|
1267
|
+
};
|
|
832
1268
|
}
|
|
833
1269
|
declare function ssrRender(options: SSRRenderOptions): Promise<SSRRenderResult>;
|
|
834
1270
|
//#endregion
|
|
@@ -842,11 +1278,17 @@ interface SSRRenderConfig {
|
|
|
842
1278
|
* 应用层渲染函数
|
|
843
1279
|
*
|
|
844
1280
|
* @param page - 当前页面数据
|
|
1281
|
+
* @param framework - Framework 实例(可用于获取 translator、locale 等)
|
|
845
1282
|
* @returns SSR 渲染结果 { html, head, css, slots? }
|
|
846
1283
|
*/
|
|
847
|
-
renderApp: (page: BasePage) => SSRAppResult | Promise<SSRAppResult>;
|
|
1284
|
+
renderApp: (page: BasePage, framework: Framework) => SSRAppResult | Promise<SSRAppResult>;
|
|
848
1285
|
/** Framework 构造配置(可选) */
|
|
849
1286
|
frameworkConfig?: FrameworkConfig;
|
|
1287
|
+
/** 解析请求 locale 的回调(返回 lang + dir 用于 <html> 属性) */
|
|
1288
|
+
resolveLocale?: (url: string, request?: Request) => {
|
|
1289
|
+
lang: string;
|
|
1290
|
+
dir: string;
|
|
1291
|
+
} | undefined;
|
|
850
1292
|
}
|
|
851
1293
|
/**
|
|
852
1294
|
* 创建 render 函数
|
|
@@ -873,13 +1315,23 @@ interface InjectSSROptions {
|
|
|
873
1315
|
serializedData: string;
|
|
874
1316
|
/** 自定义 slot 替换:`{ "my-slot": "<div>content</div>" }` 会替换 `<!--ssr-my-slot-->`(含 `<!--ssr-lang-->`) */
|
|
875
1317
|
slots?: Record<string, string>;
|
|
1318
|
+
/** Locale 属性,自动注入到 <html> 标签 */
|
|
1319
|
+
locale?: {
|
|
1320
|
+
lang: string;
|
|
1321
|
+
dir: string;
|
|
1322
|
+
};
|
|
876
1323
|
}
|
|
877
1324
|
declare function injectSSRContent(options: InjectSSROptions): string;
|
|
878
1325
|
/**
|
|
879
1326
|
* CSR 空壳注入 — 清空所有占位符
|
|
880
1327
|
* 用于 renderMode === "csr" 的路由
|
|
1328
|
+
*
|
|
1329
|
+
* @param locale - 可选的 locale 属性,注入到 `<html lang="" dir="">`
|
|
881
1330
|
*/
|
|
882
|
-
declare function injectCSRShell(template: string
|
|
1331
|
+
declare function injectCSRShell(template: string, locale?: {
|
|
1332
|
+
lang: string;
|
|
1333
|
+
dir: string;
|
|
1334
|
+
}): string;
|
|
883
1335
|
//#endregion
|
|
884
1336
|
//#region ../ssr/src/server-data.d.ts
|
|
885
1337
|
declare function serializeServerData(data: PrefetchedIntent[]): string;
|
|
@@ -942,6 +1394,10 @@ interface AdapterContext {
|
|
|
942
1394
|
renderModes?: Record<string, string>;
|
|
943
1395
|
/** 声明式代理路由配置 */
|
|
944
1396
|
proxies?: ProxyRouteConfig[];
|
|
1397
|
+
/** 支持的 locale 列表(用于预渲染 locale 矩阵) */
|
|
1398
|
+
locales?: string[];
|
|
1399
|
+
/** 默认 locale(CSR shell 使用) */
|
|
1400
|
+
defaultLocale?: string;
|
|
945
1401
|
vite: any;
|
|
946
1402
|
fs: typeof node_fs0;
|
|
947
1403
|
path: {
|
|
@@ -1058,6 +1514,10 @@ interface SSRModule {
|
|
|
1058
1514
|
status: number;
|
|
1059
1515
|
};
|
|
1060
1516
|
slots?: Record<string, string>;
|
|
1517
|
+
locale?: {
|
|
1518
|
+
lang: string;
|
|
1519
|
+
dir: string;
|
|
1520
|
+
};
|
|
1061
1521
|
}>;
|
|
1062
1522
|
serializeServerData: (data: unknown) => string;
|
|
1063
1523
|
}
|
|
@@ -1083,6 +1543,11 @@ interface SSRAppOptions {
|
|
|
1083
1543
|
* 优先级高于路由级 renderMode。
|
|
1084
1544
|
*/
|
|
1085
1545
|
renderModes?: Record<string, string>;
|
|
1546
|
+
/**
|
|
1547
|
+
* 默认 locale(如 "zh-Hans"、"en-US")。
|
|
1548
|
+
* 用于 CSR 早退场景(配置级 renderMode=csr,未调用 render)将 lang/dir 注入 `<html>` 属性。
|
|
1549
|
+
*/
|
|
1550
|
+
defaultLocale?: string;
|
|
1086
1551
|
}
|
|
1087
1552
|
declare function createSSRApp(options: SSRAppOptions): Hono;
|
|
1088
1553
|
//#endregion
|
|
@@ -1212,6 +1677,17 @@ interface FinesoftFrontViteOptions {
|
|
|
1212
1677
|
* 如果项目不使用声明式路由定义,可以不设置。
|
|
1213
1678
|
*/
|
|
1214
1679
|
bootstrapEntry?: string;
|
|
1680
|
+
/**
|
|
1681
|
+
* 默认 locale(如 "zh-Hans"、"en-US")。
|
|
1682
|
+
* 用于 CSR 壳注入 `<html lang="" dir="">`,以及预渲染时的默认语言。
|
|
1683
|
+
*/
|
|
1684
|
+
defaultLocale?: string;
|
|
1685
|
+
/**
|
|
1686
|
+
* 预渲染支持的语言列表。
|
|
1687
|
+
* 提供后,每个 prerender 路由会与每个 locale 组合生成 `/:locale/path` 版本。
|
|
1688
|
+
* `defaultLocale` 的路由同时输出无前缀版本。
|
|
1689
|
+
*/
|
|
1690
|
+
locales?: string[];
|
|
1215
1691
|
}
|
|
1216
1692
|
declare function finesoftFrontViteConfig(options?: FinesoftFrontViteOptions): {
|
|
1217
1693
|
name: string;
|
|
@@ -1246,5 +1722,5 @@ declare function finesoftFrontViteConfig(options?: FinesoftFrontViteOptions): {
|
|
|
1246
1722
|
closeBundle(): Promise<void>;
|
|
1247
1723
|
};
|
|
1248
1724
|
//#endregion
|
|
1249
|
-
export { ACTION_KINDS, Action, ActionDispatcher, ActionHandler, type ActionHandlerDependencies, type Adapter, type AdapterContext, AfterLoadGuard, AsyncMapper, BaseController, BaseItem, BaseLogger, BasePage, BaseShelf, BeforeLoadGuard, type BrowserAppConfig, BrowserContextOptions, CompositeLogger, CompositeLoggerFactory, CompoundAction, ConsoleLogger, ConsoleLoggerFactory, Container, DEP_KEYS, DenyResult, ExternalUrlAction, type ExternalUrlDependencies, FeatureFlags, type FinesoftFrontViteOptions, FlowAction, type FlowActionCallbacks, type FlowActionDependencies, Framework, FrameworkConfig, History, HttpClient, HttpClientConfig, HttpError, type InjectSSROptions, Intent, IntentController, IntentDispatcher, type Logger, Logger as LoggerInterface, type LoggerFactory, LruMap, Mapper, MetricsRecorder, MiddlewareResult, NavigationContext, Net, NextResult, None, Optional, PostLoadContext, PrefetchedIntent, PrefetchedIntents, type ProxyAuthConfig, type ProxyRouteConfig, RedirectResult, RenderMode, RewriteResult, RouteAddOptions, RouteDefinition, RouteMatch, Router, type RuntimeInfo, type SSRAppOptions, type SSRContext, type SSRModule, type SSRRenderConfig, type SSRRenderOptions, type SSRRenderResult, SSR_PLACEHOLDERS, type ServerConfig, ServerContextOptions, type ServerInstance, type StartServerOptions, Storage, autoAdapter, buildUrl, cloudflareAdapter, createBrowserContext, createPrefetchedIntentsFromDom, createSSRApp, createSSRRender, createServer, createServerContext, defineRoutes, deny, deserializeServerData, detectRuntime, finesoftFrontViteConfig, generateProxyCode, generateUuid, getBaseUrl, injectCSRShell, injectSSRContent, isCompoundAction, isExternalUrlAction, isFlowAction, isNone, isSome, makeDependencies, makeExternalUrlAction, makeFlowAction, mapEach, netlifyAdapter, next, nodeAdapter, parseAcceptLanguage, pipe, pipeAsync, redirect, registerActionHandlers, registerExternalUrlHandler, registerFlowActionHandler, registerProxyRoutes, removeHost, removeQueryParams, removeScheme, resetFilterCache, resolveAdapter, resolveRoot, rewrite, runAfterLoadGuards, runBeforeLoadGuards, serializeServerData, shouldLog, ssrRender, stableStringify, startBrowserApp, startServer, staticAdapter, tryScroll, vercelAdapter };
|
|
1725
|
+
export { ACTION_KINDS, Action, ActionDispatcher, ActionHandler, type ActionHandlerDependencies, type Adapter, type AdapterContext, AfterLoadGuard, AsyncMapper, BaseController, BaseItem, BaseLogger, BasePage, BaseShelf, BeforeLoadGuard, type BrowserAppConfig, BrowserContextOptions, CompositeEventRecorder, CompositeLogger, CompositeLoggerFactory, CompoundAction, ConsoleEventRecorder, ConsoleLogger, ConsoleLoggerFactory, Container, DEP_KEYS, DefineRoutesOptions, DenyResult, EventRecorder, ExternalUrlAction, type ExternalUrlDependencies, FeatureFlags, FeatureFlagsProvider, type FinesoftFrontViteOptions, FlowAction, type FlowActionCallbacks, type FlowActionDependencies, Framework, FrameworkConfig, History, HttpClient, HttpClientConfig, HttpError, ImpressionEntry, ImpressionObserver, ImpressionObserverOptions, type InjectSSROptions, Intent, IntentController, IntentDispatcher, IntersectionImpressionObserver, LocaleAttributes, LocaleInfo, type Logger, Logger as LoggerInterface, type LoggerFactory, LruMap, MakeDependenciesOptions, Mapper, MetricsFieldsProvider, MetricsRecorder, MiddlewareResult, NavigationContext, Net, NextResult, None, Optional, PWADisplayMode, PlatformInfo, PluralCategory, PluralRuleProvider, PostLoadContext, PrefetchedIntent, PrefetchedIntents, type ProxyAuthConfig, type ProxyRouteConfig, RedirectResult, RenderMode, ReportCallback, ReportingLogger, ReportingLoggerFactory, ReportingLoggerOptions, RequestInterceptor, ResponseInterceptor, RewriteResult, RouteAddOptions, RouteDefinition, RouteMatch, Router, type RuntimeInfo, type SSRAppOptions, type SSRContext, type SSRModule, type SSRRenderConfig, type SSRRenderOptions, type SSRRenderResult, SSR_PLACEHOLDERS, type ServerConfig, ServerContextOptions, type ServerInstance, SimpleTranslator, SimpleTranslatorOptions, type StartServerOptions, Storage, TextDirection, TranslationMessages, Translator, VoidEventRecorder, WithFieldsRecorder, autoAdapter, buildUrl, cloudflareAdapter, createBrowserContext, createPrefetchedIntentsFromDom, createSSRApp, createSSRRender, createServer, createServerContext, defineRoutes, deny, deserializeServerData, detectPlatform, detectRuntime, englishPlural, finesoftFrontViteConfig, generateProxyCode, generateUuid, getBaseUrl, getLocaleAttributes, getPWADisplayMode, getTextDirection, injectCSRShell, injectSSRContent, interpolate, isCompoundAction, isExternalUrlAction, isFlowAction, isNone, isRtl, isSome, makeDependencies, makeExternalUrlAction, makeFlowAction, makeLocaleInfo, mapEach, netlifyAdapter, next, nodeAdapter, parseAcceptLanguage, pipe, pipeAsync, redirect, registerActionHandlers, registerExternalUrlHandler, registerFlowActionHandler, registerProxyRoutes, removeHost, removeQueryParams, removeScheme, resetFilterCache, resolveAdapter, resolveLocaleFromUrl, resolvePluralKey, resolveRoot, rewrite, runAfterLoadGuards, runBeforeLoadGuards, serializeServerData, setHtmlLocaleAttributes, shouldLog, ssrRender, stableStringify, startBrowserApp, startServer, staticAdapter, tryScroll, vercelAdapter };
|
|
1250
1726
|
//# sourceMappingURL=index.d.mts.map
|