@finesoft/front 0.1.75 → 0.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +2 -411
  2. package/dist/browser.d.mts +2 -0
  3. package/dist/browser.mjs +1 -0
  4. package/dist/index.d.mts +2 -1248
  5. package/dist/index.mjs +54 -3557
  6. package/dist/server-data-DGbiKzMS.d.mts +1249 -0
  7. package/dist/start-app-BdXBCcor.mjs +2 -0
  8. package/docs/01-getting-started.md +230 -0
  9. package/docs/02-routing-and-controllers.md +197 -0
  10. package/docs/03-middleware.md +214 -0
  11. package/docs/04-rendering-and-hydration.md +271 -0
  12. package/docs/05-i18n.md +243 -0
  13. package/docs/06-http-client.md +286 -0
  14. package/docs/07-di-container.md +264 -0
  15. package/docs/08-observability.md +290 -0
  16. package/docs/09-server-and-deployment.md +242 -0
  17. package/docs/10-features-platform-pwa.md +238 -0
  18. package/docs/README.md +72 -0
  19. package/docs/advanced/custom-action-handler.md +248 -0
  20. package/docs/advanced/custom-adapter.md +264 -0
  21. package/docs/advanced/custom-event-recorder.md +318 -0
  22. package/docs/advanced/inline-proxy-codegen.md +200 -0
  23. package/docs/advanced/multi-tenant-scopes.md +330 -0
  24. package/docs/engineering/ci-release-flow.md +244 -0
  25. package/docs/engineering/project-structure.md +296 -0
  26. package/docs/engineering/testing.md +317 -0
  27. package/docs/pitfalls/container-scope-leak.md +215 -0
  28. package/docs/pitfalls/i18n-bundle-size.md +182 -0
  29. package/docs/pitfalls/proxy-binary-payloads.md +133 -0
  30. package/docs/pitfalls/redirect-vs-rewrite.md +147 -0
  31. package/docs/pitfalls/ssr-hydration-mismatch.md +163 -0
  32. package/docs/pitfalls/ssr-vs-csr-globals.md +176 -0
  33. package/docs/zh/01-getting-started.md +230 -0
  34. package/docs/zh/02-routing-and-controllers.md +197 -0
  35. package/docs/zh/03-middleware.md +214 -0
  36. package/docs/zh/04-rendering-and-hydration.md +271 -0
  37. package/docs/zh/05-i18n.md +243 -0
  38. package/docs/zh/06-http-client.md +286 -0
  39. package/docs/zh/07-di-container.md +264 -0
  40. package/docs/zh/08-observability.md +287 -0
  41. package/docs/zh/09-server-and-deployment.md +242 -0
  42. package/docs/zh/10-features-platform-pwa.md +238 -0
  43. package/docs/zh/README.md +72 -0
  44. package/docs/zh/advanced/custom-action-handler.md +248 -0
  45. package/docs/zh/advanced/custom-adapter.md +264 -0
  46. package/docs/zh/advanced/custom-event-recorder.md +318 -0
  47. package/docs/zh/advanced/inline-proxy-codegen.md +200 -0
  48. package/docs/zh/advanced/multi-tenant-scopes.md +330 -0
  49. package/docs/zh/engineering/ci-release-flow.md +244 -0
  50. package/docs/zh/engineering/project-structure.md +296 -0
  51. package/docs/zh/engineering/testing.md +317 -0
  52. package/docs/zh/pitfalls/container-scope-leak.md +215 -0
  53. package/docs/zh/pitfalls/i18n-bundle-size.md +182 -0
  54. package/docs/zh/pitfalls/proxy-binary-payloads.md +133 -0
  55. package/docs/zh/pitfalls/redirect-vs-rewrite.md +147 -0
  56. package/docs/zh/pitfalls/ssr-hydration-mismatch.md +163 -0
  57. package/docs/zh/pitfalls/ssr-vs-csr-globals.md +176 -0
  58. package/package.json +12 -3
package/dist/index.d.mts CHANGED
@@ -1,1254 +1,8 @@
1
+ import { $ as RenderMode, $t as Storage, A as IntersectionImpressionObserver, An as isCompoundAction, At as RouteAddOptions, B as buildUrl, Bt as RedirectResult, C as PluralRuleProvider, Cn as ActionDispatcher, Ct as Translator, D as WithFieldsRecorder, Dn as CompoundAction, Dt as ConsoleLoggerFactory, E as resolvePluralKey, En as Action, Et as ConsoleLogger, F as BrowserContextOptions, Ft as DenyResult, G as PWADisplayMode, Gt as rewrite, H as removeHost, Ht as deny, I as ServerContextOptions, It as MiddlewareResult, J as Optional, Jt as FeatureFlags, K as getPWADisplayMode, Kt as BasePage, L as createBrowserContext, Lt as NavigationContext, M as CompositeEventRecorder, Mn as isFlowAction, Mt as Router, N as runAfterLoadGuards, Nn as makeExternalUrlAction, Nt as AfterLoadGuard, O as VoidEventRecorder, On as ExternalUrlAction, Ot as CompositeLogger, P as runBeforeLoadGuards, Pn as makeFlowAction, Pt as BeforeLoadGuard, Q as DefineRoutesOptions, Qt as Net, R as createServerContext, Rt as NextResult, S as PluralCategory, Sn as Container, St as TextDirection, T as interpolate, Tn as ACTION_KINDS, Tt as shouldLog, U as removeQueryParams, Ut as next, V as getBaseUrl, Vt as RewriteResult, W as removeScheme, Wt as redirect, X as isSome, Xt as MakeDependenciesOptions, Y as isNone, Yt as FeatureFlagsProvider, Z as LruMap, Zt as MetricsRecorder, _ as getTextDirection, _n as Logger, _t as FrameworkConfig, a as BrowserAppConfig, an as resolveMessages, at as pipe, b as resolveLocaleFromUrl, bn as Intent, bt as LocaleAttributes, c as registerActionHandlers, cn as EventRecorder, ct as HttpClient, d as registerFlowActionHandler, dn as MetricsFieldsProvider, dt as RequestInterceptor, en as makeDependencies, et as RouteDefinition, f as ExternalUrlDependencies, fn as ReportCallback, ft as ResponseInterceptor, g as getLocaleAttributes, gn as BaseLogger, gt as Framework, h as SimpleTranslatorOptions, hn as ReportingLoggerOptions, ht as BaseShelf, i as History, in as resolveConfiguredMessages, it as mapEach, j as ConsoleEventRecorder, jn as isExternalUrlAction, jt as RouteMatch, k as ImpressionObserverOptions, kn as FlowAction, kt as CompositeLoggerFactory, l as FlowActionCallbacks, ln as ImpressionEntry, lt as HttpClientConfig, m as SimpleTranslator, mn as ReportingLoggerFactory, mt as BaseItem, n as deserializeServerData, nn as MessagesLoaderContext, nt as AsyncMapper, o as startBrowserApp, on as PlatformInfo, ot as pipeAsync, p as registerExternalUrlHandler, pn as ReportingLogger, pt as stableStringify, q as None, qt as DEP_KEYS, r as tryScroll, rn as TranslationMessages, rt as Mapper, s as ActionHandlerDependencies, sn as detectPlatform, st as BaseController, t as createPrefetchedIntentsFromDom, tn as MessagesLoader, tt as defineRoutes, u as FlowActionDependencies, un as ImpressionObserver, ut as HttpError, v as isRtl, vn as LoggerFactory, vt as PrefetchedIntent, w as englishPlural, wn as ActionHandler, wt as resetFilterCache, x as setHtmlLocaleAttributes, xn as IntentController, xt as LocaleInfo, y as makeLocaleInfo, yn as IntentDispatcher, yt as PrefetchedIntents, z as generateUuid, zt as PostLoadContext } from "./server-data-DGbiKzMS.mjs";
1
2
  import { Hono } from "hono";
2
3
  import * as _$node_fs0 from "node:fs";
3
4
  import { ViteDevServer } from "vite";
4
5
 
5
- //#region ../core/src/actions/types.d.ts
6
- /**
7
- * Action 类型定义
8
- *
9
- * FlowAction — SPA 内部导航
10
- * ExternalUrlAction — 打开外部链接
11
- * CompoundAction — 组合多个 Action
12
- */
13
- /** Action Kind 常量 */
14
- declare const ACTION_KINDS: {
15
- FLOW: "flow";
16
- EXTERNAL_URL: "externalUrl";
17
- COMPOUND: "compound";
18
- };
19
- /** FlowAction — SPA 导航 */
20
- interface FlowAction {
21
- kind: typeof ACTION_KINDS.FLOW;
22
- url: string;
23
- /** 展示方式: 默认 push,modal 弹窗 */
24
- presentationContext?: "default" | "modal";
25
- }
26
- /** ExternalUrlAction — 外部链接 */
27
- interface ExternalUrlAction {
28
- kind: typeof ACTION_KINDS.EXTERNAL_URL;
29
- url: string;
30
- }
31
- /** CompoundAction — 组合 Action */
32
- interface CompoundAction {
33
- kind: typeof ACTION_KINDS.COMPOUND;
34
- actions: Action[];
35
- }
36
- /** 所有 Action 的联合类型 */
37
- type Action = FlowAction | ExternalUrlAction | CompoundAction;
38
- declare function isFlowAction(action: Action): action is FlowAction;
39
- declare function isExternalUrlAction(action: Action): action is ExternalUrlAction;
40
- declare function isCompoundAction(action: Action): action is CompoundAction;
41
- declare function makeFlowAction(url: string, presentationContext?: FlowAction["presentationContext"]): FlowAction;
42
- declare function makeExternalUrlAction(url: string): ExternalUrlAction;
43
- //#endregion
44
- //#region ../core/src/actions/dispatcher.d.ts
45
- /** Action 处理器函数类型 */
46
- type ActionHandler<A extends Action = Action> = (action: A) => Promise<void> | void;
47
- declare class ActionDispatcher {
48
- private handlers;
49
- /**
50
- * 注册指定 kind 的 handler。
51
- *
52
- * 重复 kind 时保留第一个注册者并发出警告——这是有意设计:
53
- * framework 内部 handler 先注册,应用层意外覆盖会被记录而非静默生效。
54
- * 如需显式替换,先调用 removeAction(kind)。
55
- */
56
- onAction<A extends Action>(kind: string, handler: ActionHandler<A>): void;
57
- /** 移除指定 kind 的 handler(用于显式覆盖场景) */
58
- removeAction(kind: string): boolean;
59
- /** 执行一个 Action(CompoundAction 递归展开,有深度限制) */
60
- perform(action: Action, _depth?: number): Promise<void>;
61
- }
62
- //#endregion
63
- //#region ../core/src/dependencies/container.d.ts
64
- /**
65
- * Container — 通用的依赖注入容器
66
- */
67
- type Factory<T> = () => T;
68
- declare class Container {
69
- private registrations;
70
- private resolutionStack;
71
- private parent?;
72
- private children;
73
- /** 注册依赖(默认单例) */
74
- register<T>(key: string, factory: Factory<T>, singleton?: boolean): this;
75
- /** 解析依赖 — 当前容器未注册时回退到 parent */
76
- resolve<T>(key: string): T;
77
- /** 检查是否已注册(含 parent) */
78
- has(key: string): boolean;
79
- /**
80
- * 创建子容器(请求级 scope)
81
- *
82
- * 子容器可覆写父容器的依赖(如每请求的 locale、user),
83
- * 未覆写的 key 自动回退到父容器解析。子容器会被父容器跟踪,
84
- * 父容器 dispose 时一并销毁所有未独立 dispose 的子容器。
85
- */
86
- createScope(): Container;
87
- /**
88
- * 销毁容器,清除所有缓存。
89
- *
90
- * - 递归 dispose 所有 createScope() 创建的未 dispose 子容器
91
- * - 自身被 dispose 后从父容器移除引用,允许 GC
92
- * - 重复 dispose 安全(幂等)
93
- */
94
- dispose(): void;
95
- }
96
- //#endregion
97
- //#region ../core/src/intents/types.d.ts
98
- /** Intent — 描述一个用户意图 */
99
- interface Intent<T = unknown> {
100
- /** Intent 标识符(用于匹配 Controller) */
101
- id: string;
102
- /** 意图参数 */
103
- params?: Record<string, string>;
104
- /** 预期返回的数据(仅用于类型推断) */
105
- _returnType?: T;
106
- }
107
- /** Intent Controller — 处理特定 intentId 的业务逻辑 */
108
- interface IntentController<T = unknown> {
109
- /** Controller 对应的 Intent ID */
110
- intentId: string;
111
- /** 执行意图,返回页面数据 */
112
- perform(intent: Intent<T>, container: Container): Promise<T> | T;
113
- }
114
- //#endregion
115
- //#region ../core/src/intents/dispatcher.d.ts
116
- declare class IntentDispatcher {
117
- private controllers;
118
- /** 注册一个 IntentController */
119
- register(controller: IntentController): void;
120
- /** 分发 Intent 到对应 Controller */
121
- dispatch<T>(intent: Intent<T>, container: Container): Promise<T>;
122
- /** 检查是否已注册某个 Intent */
123
- has(intentId: string): boolean;
124
- }
125
- //#endregion
126
- //#region ../core/src/logger/types.d.ts
127
- /** 日志级别 */
128
- type Level = "debug" | "info" | "warn" | "error";
129
- /**
130
- * Logger 接口
131
- *
132
- * 所有方法返回空字符串,允许在模板中内联使用而不渲染文本。
133
- */
134
- interface Logger {
135
- debug(...args: unknown[]): string;
136
- info(...args: unknown[]): string;
137
- warn(...args: unknown[]): string;
138
- error(...args: unknown[]): string;
139
- }
140
- interface LoggerFactory {
141
- loggerFor(category: string): Logger;
142
- }
143
- //#endregion
144
- //#region ../core/src/logger/base.d.ts
145
- declare abstract class BaseLogger implements Logger {
146
- protected category: string;
147
- constructor(category: string);
148
- abstract debug(...args: unknown[]): string;
149
- abstract info(...args: unknown[]): string;
150
- abstract warn(...args: unknown[]): string;
151
- abstract error(...args: unknown[]): string;
152
- }
153
- //#endregion
154
- //#region ../core/src/logger/reporting.d.ts
155
- /** 日志上报回调 */
156
- interface ReportCallback {
157
- (level: Level, category: string, args: unknown[]): void;
158
- }
159
- /** 配置 */
160
- interface ReportingLoggerOptions {
161
- /** 最低上报级别(默认 "warn") */
162
- minLevel?: Level;
163
- /** 上报回调 */
164
- report: ReportCallback;
165
- }
166
- declare class ReportingLogger extends BaseLogger {
167
- private readonly minPriority;
168
- private readonly report;
169
- constructor(category: string, options: ReportingLoggerOptions);
170
- debug(...args: unknown[]): string;
171
- info(...args: unknown[]): string;
172
- warn(...args: unknown[]): string;
173
- error(...args: unknown[]): string;
174
- private maybeReport;
175
- }
176
- declare class ReportingLoggerFactory implements LoggerFactory {
177
- private readonly options;
178
- constructor(options: ReportingLoggerOptions);
179
- loggerFor(category: string): Logger;
180
- }
181
- //#endregion
182
- //#region ../core/src/metrics/types.d.ts
183
- /**
184
- * Metrics — 类型定义
185
- *
186
- * 框架级埋点基础设施的核心接口。
187
- */
188
- /** 事件记录器 — 所有 metrics 后端实现此接口 */
189
- interface EventRecorder {
190
- /** 记录一条事件 */
191
- record(type: string, fields?: Record<string, unknown>): void;
192
- /** 刷新待发送的事件队列 */
193
- flush?(): Promise<void>;
194
- /** 销毁记录器,释放资源 */
195
- destroy?(): void;
196
- }
197
- /** 字段提供者 — 每次记录前自动注入公共字段 */
198
- interface MetricsFieldsProvider {
199
- /** 返回需要附加到每条事件的字段 */
200
- getFields(): Record<string, unknown>;
201
- }
202
- /** Impression 条目 */
203
- interface ImpressionEntry {
204
- /** 被追踪元素的唯一标识 */
205
- id: string;
206
- /** 元素进入视口的时间戳 */
207
- timestamp: number;
208
- /** 附加数据 */
209
- metadata?: Record<string, unknown>;
210
- }
211
- /** Impression 观察器 — 追踪元素可见性 */
212
- interface ImpressionObserver {
213
- /** 开始追踪一个元素 */
214
- observe(element: Element, id: string, metadata?: Record<string, unknown>): void;
215
- /** 停止追踪一个元素 */
216
- unobserve(element: Element): void;
217
- /** 获取已捕获的曝光并清空 */
218
- consume(): ImpressionEntry[];
219
- /** 销毁观察器 */
220
- destroy(): void;
221
- }
222
- //#endregion
223
- //#region ../core/src/utils/platform.d.ts
224
- /**
225
- * Platform — UA 解析与平台检测
226
- *
227
- * 提供统一的平台/浏览器/OS 检测,避免在各处手写 UA 判断。
228
- */
229
- interface PlatformInfo {
230
- /** 操作系统 */
231
- os: "ios" | "android" | "macos" | "windows" | "linux" | "unknown";
232
- /** 浏览器 */
233
- browser: "safari" | "chrome" | "firefox" | "edge" | "opera" | "samsung" | "unknown";
234
- /** 渲染引擎 */
235
- engine: "webkit" | "blink" | "gecko" | "unknown";
236
- /** 是否为移动设备 */
237
- isMobile: boolean;
238
- /** 是否为触摸设备 */
239
- isTouch: boolean;
240
- }
241
- /**
242
- * 从 User-Agent 字符串解析平台信息
243
- *
244
- * @param ua - User-Agent 字符串(默认取 navigator.userAgent)
245
- */
246
- declare function detectPlatform(ua?: string): PlatformInfo;
247
- //#endregion
248
- //#region ../core/src/i18n/messages.d.ts
249
- /**
250
- * i18n message helpers shared by SSR and browser startup.
251
- */
252
- /** Flat translation table: key -> localized text */
253
- type FlatMessages = Record<string, string>;
254
- /** Nested translation value: plain text or pluralized text map */
255
- type NestedMessageValue = string | Record<string, string>;
256
- /** Locale-grouped translation table */
257
- type LocaleMessages = Record<string, Record<string, NestedMessageValue>>;
258
- /**
259
- * Translation message formats supported by the framework:
260
- * - flat messages for a single locale
261
- * - locale-grouped messages with optional plural subkeys
262
- */
263
- type TranslationMessages = FlatMessages | LocaleMessages;
264
- interface MessagesLoaderContext {
265
- readonly runtime: "server" | "browser";
266
- readonly fetch: typeof globalThis.fetch;
267
- readonly url: string;
268
- readonly request?: Request;
269
- }
270
- type MessagesLoader = (locale: string, context: MessagesLoaderContext) => TranslationMessages | Promise<TranslationMessages | undefined> | undefined;
271
- interface ResolveConfiguredMessagesOptions {
272
- locale?: string;
273
- loadMessages?: MessagesLoader;
274
- context?: MessagesLoaderContext;
275
- }
276
- /**
277
- * Resolve the effective translation source for a locale.
278
- */
279
- declare function resolveConfiguredMessages(options: ResolveConfiguredMessagesOptions): Promise<TranslationMessages | undefined>;
280
- /**
281
- * Resolve `TranslationMessages` into the flat map consumed by
282
- * `SimpleTranslator`.
283
- */
284
- declare function resolveMessages(messages: TranslationMessages, locale: string): Record<string, string> | undefined;
285
- //#endregion
286
- //#region ../core/src/dependencies/make-dependencies.d.ts
287
- /** 网络请求层 */
288
- interface Net {
289
- fetch(url: string, options?: RequestInit): Promise<Response>;
290
- }
291
- /** 存储接口 */
292
- interface Storage {
293
- get(key: string): string | undefined;
294
- set(key: string, value: string): void;
295
- delete(key: string): void;
296
- }
297
- /** Feature Flags */
298
- interface FeatureFlags {
299
- isEnabled(key: string): boolean;
300
- getString(key: string): string | undefined;
301
- getNumber(key: string): number | undefined;
302
- }
303
- /** Feature Flags Provider — 用于从远程/外部源加载 flags */
304
- interface FeatureFlagsProvider {
305
- isEnabled(key: string): boolean;
306
- getString?(key: string): string | undefined;
307
- getNumber?(key: string): number | undefined;
308
- }
309
- /** Metrics 记录器 */
310
- interface MetricsRecorder {
311
- /** 记录一条事件(通用方法) */
312
- record(type: string, fields?: Record<string, unknown>): void;
313
- /** 记录页面访问(便捷方法) */
314
- recordPageView(page: string, fields?: Record<string, unknown>): void;
315
- /** 记录自定义事件(便捷方法) */
316
- recordEvent(name: string, fields?: Record<string, unknown>): void;
317
- /** 刷新待发送队列 */
318
- flush?(): Promise<void>;
319
- /** 销毁记录器 */
320
- destroy?(): void;
321
- }
322
- declare const DEP_KEYS: {
323
- readonly LOGGER: "logger";
324
- readonly LOGGER_FACTORY: "loggerFactory";
325
- readonly NET: "net";
326
- readonly STORAGE: "storage";
327
- readonly FEATURE_FLAGS: "featureFlags";
328
- readonly METRICS: "metrics";
329
- readonly FETCH: "fetch";
330
- readonly EVENT_RECORDER: "eventRecorder";
331
- readonly LOCALE: "locale";
332
- readonly PLATFORM: "platform";
333
- readonly TRANSLATOR: "translator";
334
- };
335
- interface MakeDependenciesOptions {
336
- fetch?: typeof globalThis.fetch;
337
- featureFlags?: Record<string, boolean | string | number>;
338
- /** 外部 feature flags providers(远程配置、A/B 测试等) */
339
- featureFlagsProviders?: FeatureFlagsProvider[];
340
- /** 日志上报回调 — 提供后自动组合 ReportingLoggerFactory */
341
- reportCallback?: ReportCallback;
342
- /** 自定义 EventRecorder(默认 ConsoleEventRecorder) */
343
- eventRecorder?: EventRecorder;
344
- /** 语言代码(如 "zh-Hans"、"en-US"),用于注入 locale 信息 */
345
- locale?: string;
346
- /** 自定义 PlatformInfo(默认通过 UA 自动检测) */
347
- platform?: PlatformInfo;
348
- }
349
- declare function makeDependencies(container: Container, options?: MakeDependenciesOptions): void;
350
- //#endregion
351
- //#region ../core/src/models/page.d.ts
352
- /**
353
- * BasePage — 所有页面共享的基础属性
354
- *
355
- * 具体页面类型由应用层定义并扩展此接口。
356
- */
357
- interface BasePage {
358
- id: string;
359
- pageType: string;
360
- title: string;
361
- description?: string;
362
- url?: string;
363
- }
364
- //#endregion
365
- //#region ../core/src/middleware/types.d.ts
366
- /** 导航上下文(beforeLoad 阶段可用) */
367
- interface NavigationContext {
368
- /** 完整 URL(path + query) */
369
- readonly url: string;
370
- /** 仅路径部分 */
371
- readonly path: string;
372
- /** 路由参数 + 查询参数 */
373
- readonly params: Record<string, string>;
374
- /** 匹配的 Intent */
375
- readonly intent: Intent;
376
- /** 是否在服务端运行 */
377
- readonly isServer: boolean;
378
- /** DI 容器(可获取自定义服务) */
379
- readonly container: Container;
380
- /** 获取 Cookie 值(两端均可用) */
381
- getCookie(name: string): string | undefined;
382
- /** 获取请求头值(仅服务端有值,客户端始终返回 undefined) */
383
- getHeader(name: string): string | undefined;
384
- }
385
- /** 后置上下文(afterLoad 阶段,包含页面数据) */
386
- interface PostLoadContext extends NavigationContext {
387
- /** 控制器返回的页面数据 */
388
- readonly page: BasePage;
389
- }
390
- /** 继续执行下一个中间件 */
391
- interface NextResult {
392
- readonly kind: "next";
393
- }
394
- /** 重定向(服务端: HTTP 301/302,客户端: 触发新导航) */
395
- interface RedirectResult {
396
- readonly kind: "redirect";
397
- readonly url: string;
398
- readonly status: number;
399
- }
400
- /** URL 重写(服务端: HTTP 301,客户端: replaceState 仅更新地址栏) */
401
- interface RewriteResult {
402
- readonly kind: "rewrite";
403
- readonly url: string;
404
- }
405
- /** 拒绝访问 */
406
- interface DenyResult {
407
- readonly kind: "deny";
408
- readonly status: number;
409
- readonly message: string;
410
- }
411
- type MiddlewareResult = NextResult | RedirectResult | RewriteResult | DenyResult;
412
- /** 继续执行 */
413
- declare function next(): NextResult;
414
- /** 重定向到新 URL */
415
- declare function redirect(url: string, status?: 301 | 302): RedirectResult;
416
- /** URL 重写(不重新加载数据) */
417
- declare function rewrite(url: string): RewriteResult;
418
- /** 拒绝访问 */
419
- declare function deny(status?: number, message?: string): DenyResult;
420
- /** beforeLoad 守卫:路由匹配后、数据加载前 */
421
- type BeforeLoadGuard = (ctx: NavigationContext) => MiddlewareResult | Promise<MiddlewareResult>;
422
- /** afterLoad 守卫:数据加载后、渲染前 */
423
- type AfterLoadGuard = (ctx: PostLoadContext) => MiddlewareResult | Promise<MiddlewareResult>;
424
- //#endregion
425
- //#region ../core/src/router/router.d.ts
426
- /** 路由匹配结果 */
427
- interface RouteMatch {
428
- intent: Intent;
429
- action: FlowAction;
430
- renderMode?: string;
431
- /** 该路由绑定的 beforeLoad 守卫 */
432
- beforeGuards?: BeforeLoadGuard[];
433
- /** 该路由绑定的 afterLoad 守卫 */
434
- afterGuards?: AfterLoadGuard[];
435
- }
436
- /** 路由添加选项 */
437
- interface RouteAddOptions {
438
- renderMode?: string;
439
- beforeGuards?: BeforeLoadGuard[];
440
- afterGuards?: AfterLoadGuard[];
441
- }
442
- declare class Router {
443
- private routes;
444
- /** 添加路由规则 */
445
- add(pattern: string, intentId: string, renderModeOrOptions?: string | RouteAddOptions): this;
446
- /** 解析 URL → RouteMatch */
447
- resolve(urlOrPath: string): RouteMatch | null;
448
- /** 获取所有已注册的路由 */
449
- getRoutes(): string[];
450
- private parseUrl;
451
- }
452
- //#endregion
453
- //#region ../core/src/logger/composite.d.ts
454
- declare class CompositeLoggerFactory implements LoggerFactory {
455
- private readonly factories;
456
- constructor(factories: LoggerFactory[]);
457
- loggerFor(name: string): Logger;
458
- }
459
- declare class CompositeLogger implements Logger {
460
- private readonly loggers;
461
- constructor(loggers: Logger[]);
462
- debug(...args: unknown[]): string;
463
- info(...args: unknown[]): string;
464
- warn(...args: unknown[]): string;
465
- error(...args: unknown[]): string;
466
- private callAll;
467
- }
468
- //#endregion
469
- //#region ../core/src/logger/console.d.ts
470
- declare class ConsoleLogger extends BaseLogger {
471
- debug(...args: unknown[]): string;
472
- info(...args: unknown[]): string;
473
- warn(...args: unknown[]): string;
474
- error(...args: unknown[]): string;
475
- }
476
- declare class ConsoleLoggerFactory implements LoggerFactory {
477
- loggerFor(category: string): Logger;
478
- }
479
- //#endregion
480
- //#region ../core/src/logger/local-storage-filter.d.ts
481
- declare function shouldLog(name: string, level: Level): boolean;
482
- declare function resetFilterCache(): void;
483
- //#endregion
484
- //#region ../core/src/i18n/types.d.ts
485
- /**
486
- * i18n — 类型定义
487
- *
488
- * 框架级国际化基础设施。
489
- */
490
- /** 翻译函数 */
491
- interface Translator {
492
- /**
493
- * 翻译 key → 本地化字符串
494
- * @param key - 翻译 key
495
- * @param values - 插值参数
496
- */
497
- t(key: string, values?: Record<string, string | number>): string;
498
- /**
499
- * 复数形式翻译
500
- * @param key - 翻译 key 前缀
501
- * @param count - 数量
502
- * @param values - 附加插值
503
- */
504
- plural(key: string, count: number, values?: Record<string, string | number>): string;
505
- /** 当前 locale(如 "zh-Hans" / "en-US") */
506
- readonly locale: string;
507
- }
508
- /** 文本方向 */
509
- type TextDirection = "ltr" | "rtl";
510
- /** HTML 语言属性 */
511
- interface LocaleAttributes {
512
- /** BCP 47 语言标签 */
513
- lang: string;
514
- /** 文本方向 */
515
- dir: TextDirection;
516
- }
517
- /** Locale 信息 */
518
- interface LocaleInfo {
519
- /** 语言代码(如 "zh-Hans", "en") */
520
- language: string;
521
- /** 地区/Storefront 代码(如 "CN", "US") */
522
- region?: string;
523
- /** BCP 47 完整标签 */
524
- bcp47: string;
525
- /** 文本方向 */
526
- dir: TextDirection;
527
- }
528
- //#endregion
529
- //#region ../core/src/prefetched-intents/prefetched-intents.d.ts
530
- /** 预获取的 Intent-Data 对 */
531
- interface PrefetchedIntent {
532
- intent: Intent;
533
- data: unknown;
534
- }
535
- declare class PrefetchedIntents {
536
- private intents;
537
- private constructor();
538
- /** 从 PrefetchedIntent 数组创建缓存实例 */
539
- static fromArray(items: PrefetchedIntent[]): PrefetchedIntents;
540
- /** 创建空缓存实例 */
541
- static empty(): PrefetchedIntents;
542
- /**
543
- * 获取缓存的 Intent 结果(一次性使用)。
544
- * 命中后从缓存中删除。
545
- */
546
- get<T>(intent: Intent<T>): T | undefined;
547
- /** 检查缓存中是否有某个 Intent 的数据 */
548
- has(intent: Intent): boolean;
549
- /** 缓存中的条目数 */
550
- get size(): number;
551
- }
552
- //#endregion
553
- //#region ../core/src/framework.d.ts
554
- /** Framework 初始化配置 */
555
- interface FrameworkConfig extends MakeDependenciesOptions {
556
- setupRoutes?: (router: Router) => void;
557
- prefetchedIntents?: PrefetchedIntents;
558
- }
559
- declare class Framework {
560
- readonly container: Container;
561
- readonly intentDispatcher: IntentDispatcher;
562
- readonly actionDispatcher: ActionDispatcher;
563
- readonly router: Router;
564
- readonly prefetchedIntents: PrefetchedIntents;
565
- private readonly beforeGuards;
566
- private readonly afterGuards;
567
- private _logger?;
568
- private constructor();
569
- /** 创建并初始化 Framework 实例 */
570
- static create(config?: FrameworkConfig): Framework;
571
- private getLogger;
572
- /** 分发 Intent — 获取页面数据 */
573
- dispatch<T>(intent: Intent<T>): Promise<T>;
574
- /** 执行 Action — 处理用户交互 */
575
- perform(action: Action): Promise<void>;
576
- /** 路由 URL — 将 URL 解析为 Intent + Action */
577
- routeUrl(url: string): RouteMatch | null;
578
- /** 记录页面访问事件 */
579
- didEnterPage(page: BasePage): void;
580
- /** 获取 locale 信息(如果已配置) */
581
- getLocale(): LocaleAttributes | undefined;
582
- /** 获取翻译器(如果当前 locale 已经初始化了翻译字典) */
583
- getTranslator(): Translator | undefined;
584
- /** 获取平台信息 */
585
- getPlatform(): PlatformInfo;
586
- /** 注册 Action 处理器 */
587
- onAction<A extends Action>(kind: string, handler: ActionHandler<A>): void;
588
- /** 注册 Intent Controller */
589
- registerIntent(controller: IntentController): void;
590
- /** 注册 beforeLoad 守卫(路由匹配后、数据加载前) */
591
- beforeLoad(guard: BeforeLoadGuard): void;
592
- /** 注册 afterLoad 守卫(数据加载后、渲染前) */
593
- afterLoad(guard: AfterLoadGuard): void;
594
- /** 执行所有 beforeLoad 守卫(全局 → 路由级) */
595
- runBeforeLoad(ctx: NavigationContext, routeGuards?: BeforeLoadGuard[]): Promise<MiddlewareResult>;
596
- /** 执行所有 afterLoad 守卫(全局 → 路由级) */
597
- runAfterLoad(ctx: PostLoadContext, routeGuards?: AfterLoadGuard[]): Promise<MiddlewareResult>;
598
- /** 销毁 Framework 实例 */
599
- dispose(): void;
600
- }
601
- //#endregion
602
- //#region ../core/src/models/shelf.d.ts
603
- interface BaseShelf {
604
- id: string;
605
- shelfType: string;
606
- title?: string;
607
- subtitle?: string;
608
- seeAllAction?: Action;
609
- isHorizontal?: boolean;
610
- }
611
- interface BaseItem {
612
- id: string;
613
- itemType: string;
614
- clickAction?: Action;
615
- }
616
- //#endregion
617
- //#region ../core/src/prefetched-intents/stable-stringify.d.ts
618
- /**
619
- * stableStringify — 确定性 JSON 序列化(keys 按字母排序)
620
- *
621
- * 用作缓存 key:相同内容的对象始终产生相同字符串。
622
- */
623
- declare function stableStringify(obj: unknown): string;
624
- //#endregion
625
- //#region ../core/src/http/client.d.ts
626
- /**
627
- * HttpClient — 通用 HTTP 客户端基类
628
- *
629
- * 为 API Client 提供标准化的 HTTP 请求能力。
630
- * 子类继承后只需关注业务端点定义,不需要重复实现 fetch / JSON 解析 / 错误处理。
631
- */
632
- /** HTTP 请求错误 */
633
- declare class HttpError extends Error {
634
- readonly status: number;
635
- readonly statusText: string;
636
- readonly body?: string | undefined;
637
- constructor(status: number, statusText: string, body?: string | undefined);
638
- }
639
- /** 请求拦截器 — 在发送前修改请求 */
640
- interface RequestInterceptor {
641
- (url: string, init: RequestInit): RequestInit | Promise<RequestInit>;
642
- }
643
- /** 响应拦截器 — 在解析前修改响应 */
644
- interface ResponseInterceptor {
645
- (response: Response, url: string): Response | Promise<Response>;
646
- }
647
- /** HttpClient 构造配置 */
648
- interface HttpClientConfig {
649
- /** API base URL(如 "/api" 或 "https://example.com/api") */
650
- baseUrl: string;
651
- /** 默认请求头 */
652
- defaultHeaders?: Record<string, string>;
653
- /** 自定义 fetch 实现(便于测试或 SSR) */
654
- fetch?: typeof globalThis.fetch;
655
- /** 请求拦截器(按注册顺序执行) */
656
- requestInterceptors?: RequestInterceptor[];
657
- /** 响应拦截器(按注册顺序执行) */
658
- responseInterceptors?: ResponseInterceptor[];
659
- }
660
- /**
661
- * 通用 HTTP 客户端基类
662
- *
663
- * 使用方式: 创建子类继承 HttpClient,定义业务方法调用 this.get() / this.post() 等。
664
- *
665
- * @example
666
- * ```ts
667
- * class MyApiClient extends HttpClient {
668
- * async getUser(id: string) {
669
- * return this.get<User>(`/users/${id}`);
670
- * }
671
- * }
672
- * ```
673
- */
674
- declare abstract class HttpClient {
675
- protected readonly baseUrl: string;
676
- protected readonly defaultHeaders: Record<string, string>;
677
- protected readonly fetchFn: typeof globalThis.fetch;
678
- private readonly requestInterceptors;
679
- private readonly responseInterceptors;
680
- constructor(config: HttpClientConfig);
681
- /** 动态添加请求拦截器 */
682
- useRequestInterceptor(interceptor: RequestInterceptor): this;
683
- /** 动态添加响应拦截器 */
684
- useResponseInterceptor(interceptor: ResponseInterceptor): this;
685
- /** GET 请求,返回解析后的 JSON */
686
- protected get<T>(path: string, params?: Record<string, string>): Promise<T>;
687
- /** POST 请求,自动序列化 body 为 JSON */
688
- protected post<T>(path: string, body?: unknown, params?: Record<string, string>): Promise<T>;
689
- /** PUT 请求 */
690
- protected put<T>(path: string, body?: unknown, params?: Record<string, string>): Promise<T>;
691
- /** DELETE 请求 */
692
- protected del<T>(path: string, params?: Record<string, string>): Promise<T>;
693
- /**
694
- * 底层请求方法 — 子类可覆写以自定义行为
695
- *
696
- * 自动处理:
697
- * - URL 拼接 (baseUrl + path + params)
698
- * - 默认 headers 合并
699
- * - JSON body 序列化
700
- * - 响应 JSON 解析
701
- * - 非 2xx 状态码抛出 HttpError
702
- */
703
- protected request<T>(method: string, path: string, options?: {
704
- params?: Record<string, string>;
705
- body?: unknown;
706
- headers?: Record<string, string>;
707
- }): Promise<T>;
708
- /** 构建完整 URL — 子类可覆写以自定义 URL 拼接逻辑 */
709
- protected buildUrl(path: string, params?: Record<string, string>): string;
710
- }
711
- //#endregion
712
- //#region ../core/src/intents/base-controller.d.ts
713
- /**
714
- * 抽象 Controller 基类
715
- *
716
- * 统一处理:
717
- * - 类型安全的参数提取 (TParams)
718
- * - 返回类型约束 (TResult)
719
- * - try/catch 错误处理 + 可选 fallback
720
- *
721
- * @example
722
- * ```ts
723
- * class ProductController extends BaseController<{ productId: string }, ProductPage> {
724
- * readonly intentId = "product-page";
725
- *
726
- * async execute(params: { productId: string }, container: Container) {
727
- * const api = container.resolve<ApiClient>("api");
728
- * return api.getProduct(params.productId);
729
- * }
730
- *
731
- * fallback(params: { productId: string }, error: Error) {
732
- * return getMockProduct(params.productId);
733
- * }
734
- * }
735
- * ```
736
- */
737
- declare abstract class BaseController<TParams extends Record<string, string | undefined> = Record<string, string>, TResult = unknown> implements IntentController<TResult> {
738
- /** Controller 对应的 Intent ID */
739
- abstract readonly intentId: string;
740
- /**
741
- * 执行业务逻辑 — 子类必须实现
742
- *
743
- * @param params - Intent 参数(已类型化)
744
- * @param container - DI 容器
745
- * @returns 页面数据
746
- */
747
- abstract execute(params: TParams, container: Container): Promise<TResult> | TResult;
748
- /**
749
- * 错误回退 — 子类可选覆写
750
- *
751
- * 当 execute() 抛出异常时调用。
752
- * 默认行为: 重新抛出原始错误。
753
- *
754
- * @param params - Intent 参数
755
- * @param error - execute() 抛出的错误
756
- * @returns 回退数据
757
- */
758
- fallback(params: TParams, error: Error): Promise<TResult> | TResult;
759
- /**
760
- * IntentController.perform() 实现
761
- *
762
- * 自动 try/catch → fallback 模式。
763
- */
764
- perform(intent: Intent<TResult>, container: Container): Promise<TResult>;
765
- }
766
- //#endregion
767
- //#region ../core/src/data/mapper.d.ts
768
- /**
769
- * Mapper 类型工具 — 标准化数据转换管线
770
- *
771
- * 提供类型约定和组合函数,让 API 响应 → 页面模型 的转换有统一的签名模式。
772
- */
773
- /** 同步映射函数 */
774
- type Mapper<TInput, TOutput> = (input: TInput) => TOutput;
775
- /** 异步映射函数 */
776
- type AsyncMapper<TInput, TOutput> = (input: TInput) => TOutput | Promise<TOutput>;
777
- /**
778
- * 组合两个同步 Mapper: A → B → C
779
- */
780
- declare function pipe<A, B, C>(m1: Mapper<A, B>, m2: Mapper<B, C>): Mapper<A, C>;
781
- /**
782
- * 组合三个同步 Mapper: A → B → C → D
783
- */
784
- declare function pipe<A, B, C, D>(m1: Mapper<A, B>, m2: Mapper<B, C>, m3: Mapper<C, D>): Mapper<A, D>;
785
- /**
786
- * 组合四个同步 Mapper: A → B → C → D → E
787
- */
788
- declare function pipe<A, B, C, D, E>(m1: Mapper<A, B>, m2: Mapper<B, C>, m3: Mapper<C, D>, m4: Mapper<D, E>): Mapper<A, E>;
789
- /**
790
- * 组合任意数量的同步 Mapper
791
- */
792
- declare function pipe(...mappers: Mapper<unknown, unknown>[]): Mapper<unknown, unknown>;
793
- /**
794
- * 组合两个可能异步的 Mapper: A → B → C
795
- */
796
- declare function pipeAsync<A, B, C>(m1: AsyncMapper<A, B>, m2: AsyncMapper<B, C>): AsyncMapper<A, C>;
797
- /**
798
- * 组合三个可能异步的 Mapper
799
- */
800
- declare function pipeAsync<A, B, C, D>(m1: AsyncMapper<A, B>, m2: AsyncMapper<B, C>, m3: AsyncMapper<C, D>): AsyncMapper<A, D>;
801
- /**
802
- * 将一个 Mapper 应用到数组的每个元素
803
- */
804
- declare function mapEach<TInput, TOutput>(mapper: Mapper<TInput, TOutput>): Mapper<TInput[], TOutput[]>;
805
- //#endregion
806
- //#region ../core/src/bootstrap/define-routes.d.ts
807
- /** 渲染模式 */
808
- type RenderMode = "ssr" | "csr" | "prerender";
809
- /** 单条路由定义 */
810
- interface RouteDefinition {
811
- /** URL pattern (如 "/product/:productId") */
812
- path: string;
813
- /** Intent ID (如 "product-page") */
814
- intentId: string;
815
- /**
816
- * Controller 实例(可选)。
817
- * 同一个 intentId 的多条路由只需在第一条提供 controller。
818
- */
819
- controller?: IntentController;
820
- /**
821
- * 渲染模式(可选,默认 "ssr")。
822
- * - "ssr": 服务端渲染(默认)
823
- * - "csr": 客户端渲染(返回空壳 HTML,由客户端 JS 渲染)
824
- * - "prerender": 预渲染(构建时生成静态 HTML + ISR 缓存)
825
- */
826
- renderMode?: RenderMode;
827
- /**
828
- * 路由级 beforeLoad 守卫(可选)。
829
- * 在全局守卫之后执行,仅对匹配此路由的请求生效。
830
- */
831
- beforeLoad?: BeforeLoadGuard[];
832
- /**
833
- * 路由级 afterLoad 守卫(可选)。
834
- * 在全局守卫之后执行,仅对匹配此路由的请求生效。
835
- */
836
- afterLoad?: AfterLoadGuard[];
837
- }
838
- /** defineRoutes 选项 */
839
- interface DefineRoutesOptions {
840
- /**
841
- * 支持的 locale 列表。
842
- * 提供后,每条路由会额外注册 `/:locale/path` 版本,
843
- * `:locale` 参数自动出现在 `intent.params.locale` 中。
844
- * 原始无前缀路径保留作为备选路由。
845
- *
846
- * @example
847
- * ```ts
848
- * defineRoutes(framework, routes, { locales: ["zh", "en", "ja"] });
849
- * // "/about" → 注册 /about + /zh/about + /en/about + /ja/about
850
- * ```
851
- */
852
- locales?: string[];
853
- }
854
- /**
855
- * 声明式注册路由和 Controller
856
- *
857
- * - 自动去重: 同一 intentId 的 controller 只注册一次
858
- * - 路由和 controller 在同一个配置数组中,方便检查一致性
859
- *
860
- * @example
861
- * ```ts
862
- * defineRoutes(framework, [
863
- * { path: "/", intentId: "home", controller: new HomeController() },
864
- * { path: "/product/:id", intentId: "product", controller: new ProductController() },
865
- * { path: "/search", intentId: "search", controller: new SearchController() },
866
- * { path: "/charts/:type", intentId: "charts", controller: new ChartsController() },
867
- * { path: "/charts", intentId: "charts" }, // 同 intentId,不需要重复 controller
868
- * ]);
869
- * ```
870
- */
871
- declare function defineRoutes(framework: Framework, definitions: RouteDefinition[], options?: DefineRoutesOptions): void;
872
- //#endregion
873
- //#region ../core/src/utils/lru-map.d.ts
874
- /**
875
- * LruMap — 固定容量的 LRU 缓存
876
- */
877
- declare class LruMap<K, V> {
878
- private map;
879
- private readonly capacity;
880
- constructor(capacity: number);
881
- get(key: K): V | undefined;
882
- set(key: K, value: V): void;
883
- has(key: K): boolean;
884
- delete(key: K): boolean;
885
- get size(): number;
886
- clear(): void;
887
- }
888
- //#endregion
889
- //#region ../core/src/utils/optional.d.ts
890
- /**
891
- * Optional 类型工具
892
- */
893
- type None = null | undefined;
894
- type Optional<T> = T | None;
895
- declare function isSome<T>(value: Optional<T>): value is T;
896
- declare function isNone<T>(value: Optional<T>): value is None;
897
- //#endregion
898
- //#region ../core/src/utils/pwa.d.ts
899
- /**
900
- * PWA Display Mode 检测
901
- *
902
- * 检测当前应用是否以 PWA 模式运行。
903
- */
904
- type PWADisplayMode = "standalone" | "twa" | "browser";
905
- /**
906
- * 检测 PWA display mode
907
- *
908
- * - `standalone`: 已安装的 PWA(通过 Add to Home Screen)
909
- * - `twa`: Trusted Web Activity(Android 原生壳)
910
- * - `browser`: 普通浏览器标签页
911
- */
912
- declare function getPWADisplayMode(): PWADisplayMode;
913
- //#endregion
914
- //#region ../core/src/utils/url.d.ts
915
- /**
916
- * URL 工具函数
917
- */
918
- /** 移除 URL scheme (https://, http://) */
919
- declare function removeScheme(url: string): string;
920
- /** 移除 URL host 部分,保留路径 */
921
- declare function removeHost(url: string): string;
922
- /** 移除 query 参数 */
923
- declare function removeQueryParams(url: string): string;
924
- /** 获取 URL 的基础路径(无 query、hash) */
925
- declare function getBaseUrl(url: string): string;
926
- /** 构建 URL(路径 + query 参数) */
927
- declare function buildUrl(path: string, params?: Record<string, string | undefined>): string;
928
- //#endregion
929
- //#region ../core/src/utils/uuid.d.ts
930
- /**
931
- * UUID v4 生成器
932
- */
933
- declare function generateUuid(): string;
934
- //#endregion
935
- //#region ../core/src/middleware/context.d.ts
936
- interface ServerContextOptions {
937
- url: string;
938
- intent: Intent;
939
- container: Container;
940
- /** 原始 Request 对象(提取 cookie 和 header) */
941
- request?: Request;
942
- }
943
- /** 从 Request 对象构建服务端上下文 */
944
- declare function createServerContext(options: ServerContextOptions): NavigationContext;
945
- interface BrowserContextOptions {
946
- url: string;
947
- intent: Intent;
948
- container: Container;
949
- }
950
- /** 从 document.cookie 构建浏览器端上下文 */
951
- declare function createBrowserContext(options: BrowserContextOptions): NavigationContext;
952
- //#endregion
953
- //#region ../core/src/middleware/pipeline.d.ts
954
- /** 执行 beforeLoad 守卫链 */
955
- declare function runBeforeLoadGuards(guards: BeforeLoadGuard[], ctx: NavigationContext): Promise<MiddlewareResult>;
956
- /** 执行 afterLoad 守卫链 */
957
- declare function runAfterLoadGuards(guards: AfterLoadGuard[], ctx: PostLoadContext): Promise<MiddlewareResult>;
958
- //#endregion
959
- //#region ../core/src/metrics/composite-recorder.d.ts
960
- declare class CompositeEventRecorder implements EventRecorder {
961
- private readonly recorders;
962
- constructor(recorders: EventRecorder[]);
963
- record(type: string, fields?: Record<string, unknown>): void;
964
- flush(): Promise<void>;
965
- destroy(): void;
966
- }
967
- //#endregion
968
- //#region ../core/src/metrics/console-recorder.d.ts
969
- declare class ConsoleEventRecorder implements EventRecorder {
970
- private readonly prefix;
971
- constructor(prefix?: string);
972
- record(type: string, fields?: Record<string, unknown>): void;
973
- flush(): Promise<void>;
974
- destroy(): void;
975
- }
976
- //#endregion
977
- //#region ../core/src/metrics/impression-observer.d.ts
978
- interface ImpressionObserverOptions {
979
- /** 可见比例阈值(0~1),默认 0.5 */
980
- threshold?: number;
981
- /** 最小可见时长(毫秒),默认 1000 */
982
- minVisibleDuration?: number;
983
- }
984
- declare class IntersectionImpressionObserver implements ImpressionObserver {
985
- private readonly observer;
986
- private readonly tracked;
987
- private readonly captured;
988
- private readonly minDuration;
989
- constructor(options?: ImpressionObserverOptions);
990
- observe(element: Element, id: string, metadata?: Record<string, unknown>): void;
991
- unobserve(element: Element): void;
992
- consume(): ImpressionEntry[];
993
- destroy(): void;
994
- }
995
- //#endregion
996
- //#region ../core/src/metrics/void-recorder.d.ts
997
- declare class VoidEventRecorder implements EventRecorder {
998
- record(): void;
999
- flush(): Promise<void>;
1000
- destroy(): void;
1001
- }
1002
- //#endregion
1003
- //#region ../core/src/metrics/with-fields-recorder.d.ts
1004
- declare class WithFieldsRecorder implements EventRecorder {
1005
- private readonly inner;
1006
- private readonly providers;
1007
- constructor(inner: EventRecorder, providers: MetricsFieldsProvider[]);
1008
- record(type: string, fields?: Record<string, unknown>): void;
1009
- flush(): Promise<void>;
1010
- destroy(): void;
1011
- }
1012
- //#endregion
1013
- //#region ../core/src/i18n/interpolate.d.ts
1014
- /**
1015
- * ICU 消息格式插值
1016
- *
1017
- * 支持 `{name}` 占位符替换和基础复数规则。
1018
- */
1019
- /** 将 `{key}` 占位符替换为 values 中的对应值 */
1020
- declare function interpolate(template: string, values?: Record<string, string | number>): string;
1021
- /**
1022
- * CLDR 复数类别
1023
- *
1024
- * 简化版:覆盖 zero / one / two / few / many / other。
1025
- * 完整 CLDR 规则可通过 PluralRuleProvider 注入。
1026
- */
1027
- type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
1028
- /** 复数规则函数 — 给定数量返回复数类别 */
1029
- type PluralRuleProvider = (count: number) => PluralCategory;
1030
- /**
1031
- * 英语复数规则(默认)
1032
- * 0 → other, 1 → one, 2+ → other
1033
- */
1034
- declare function englishPlural(count: number): PluralCategory;
1035
- /**
1036
- * 解析带复数后缀的翻译 key
1037
- *
1038
- * 约定: `key.one`, `key.other`, `key.zero`, etc.
1039
- */
1040
- declare function resolvePluralKey(key: string, category: PluralCategory): string;
1041
- //#endregion
1042
- //#region ../core/src/i18n/locale.d.ts
1043
- /** 检测语言是否为 RTL */
1044
- declare function isRtl(language: string): boolean;
1045
- /** 获取文本方向 */
1046
- declare function getTextDirection(language: string): TextDirection;
1047
- /**
1048
- * 从语言代码生成 HTML lang/dir 属性
1049
- *
1050
- * @example
1051
- * ```ts
1052
- * getLocaleAttributes("ar-SA") // { lang: "ar-SA", dir: "rtl" }
1053
- * getLocaleAttributes("en-US") // { lang: "en-US", dir: "ltr" }
1054
- * ```
1055
- */
1056
- declare function getLocaleAttributes(language: string): LocaleAttributes;
1057
- /**
1058
- * 构建 LocaleInfo
1059
- *
1060
- * @param language - 语言代码(如 "zh-Hans")
1061
- * @param region - 地区代码(如 "CN"),可选
1062
- */
1063
- declare function makeLocaleInfo(language: string, region?: string): LocaleInfo;
1064
- /**
1065
- * 将 locale 属性应用到 `<html>` 元素
1066
- *
1067
- * 服务端渲染时可用于字符串拼接,浏览器端直接操作 DOM。
1068
- */
1069
- declare function setHtmlLocaleAttributes(attrs: LocaleAttributes): void;
1070
- /**
1071
- * 从 URL 前缀中提取 locale
1072
- *
1073
- * @param url - 请求 URL(如 "/zh/about")
1074
- * @param supportedLocales - 支持的 locale 列表(如 ["zh", "en", "ja"])
1075
- * @returns 匹配时返回 `{ locale, strippedUrl }`,不匹配返回 null
1076
- *
1077
- * @example
1078
- * ```ts
1079
- * resolveLocaleFromUrl("/zh/about", ["zh", "en"])
1080
- * // → { locale: "zh", strippedUrl: "/about" }
1081
- *
1082
- * resolveLocaleFromUrl("/about", ["zh", "en"])
1083
- * // → null
1084
- * ```
1085
- */
1086
- declare function resolveLocaleFromUrl(url: string, supportedLocales: string[]): {
1087
- locale: string;
1088
- strippedUrl: string;
1089
- } | null;
1090
- //#endregion
1091
- //#region ../core/src/i18n/translator.d.ts
1092
- interface SimpleTranslatorOptions {
1093
- /** 翻译映射 */
1094
- messages: Record<string, string>;
1095
- /** 当前 locale */
1096
- locale: string;
1097
- /** 复数规则函数(默认英语规则) */
1098
- pluralRule?: PluralRuleProvider;
1099
- /** 找不到翻译时的回退行为(默认返回 key) */
1100
- fallback?: (key: string) => string;
1101
- }
1102
- declare class SimpleTranslator implements Translator {
1103
- readonly locale: string;
1104
- private readonly messages;
1105
- private readonly pluralRule;
1106
- private readonly fallback;
1107
- constructor(options: SimpleTranslatorOptions);
1108
- t(key: string, values?: Record<string, string | number>): string;
1109
- plural(key: string, count: number, values?: Record<string, string | number>): string;
1110
- }
1111
- //#endregion
1112
- //#region ../browser/src/action-handlers/external-url-action.d.ts
1113
- interface ExternalUrlDependencies {
1114
- framework: Framework;
1115
- log: Logger;
1116
- }
1117
- declare function registerExternalUrlHandler(deps: ExternalUrlDependencies): void;
1118
- //#endregion
1119
- //#region ../browser/src/action-handlers/flow-action.d.ts
1120
- /** UI 框架回调 — 解耦 Svelte store 等依赖 */
1121
- interface FlowActionCallbacks {
1122
- /** 导航后更新当前路径(替代 currentPath.set()) */
1123
- onNavigate(pathname: string): void;
1124
- /** 模态页面展示(替代 openModal()) */
1125
- onModal(page: BasePage): void;
1126
- }
1127
- /** 注册 FlowAction handler 所需的依赖 */
1128
- interface FlowActionDependencies {
1129
- framework: Framework;
1130
- log: Logger;
1131
- callbacks: FlowActionCallbacks;
1132
- /** 更新应用 UI 的回调,page 可以是 Promise */
1133
- updateApp: (props: {
1134
- page: Promise<BasePage> | BasePage;
1135
- isFirstPage?: boolean;
1136
- }) => void;
1137
- /** 获取可滚动页面元素,用于滚动位置保存/恢复 */
1138
- getScrollablePageElement?: () => HTMLElement | null;
1139
- }
1140
- declare function registerFlowActionHandler(deps: FlowActionDependencies): void;
1141
- //#endregion
1142
- //#region ../browser/src/action-handlers/register.d.ts
1143
- interface ActionHandlerDependencies {
1144
- framework: Framework;
1145
- log: Logger;
1146
- callbacks: FlowActionCallbacks;
1147
- updateApp: (props: {
1148
- page: Promise<BasePage> | BasePage;
1149
- isFirstPage?: boolean;
1150
- }) => void;
1151
- /** 获取可滚动页面元素,用于滚动位置保存/恢复 */
1152
- getScrollablePageElement?: () => HTMLElement | null;
1153
- }
1154
- declare function registerActionHandlers(deps: ActionHandlerDependencies): void;
1155
- //#endregion
1156
- //#region ../browser/src/start-app.d.ts
1157
- interface BrowserAppConfig {
1158
- /** 注册 controllers 和路由的引导函数 */
1159
- bootstrap: (framework: Framework) => void;
1160
- /** DOM 挂载点 ID(默认 "app") */
1161
- mountId?: string;
1162
- /** 获取可滚动页面元素,用于滚动位置保存/恢复 */
1163
- getScrollablePageElement?: () => HTMLElement | null;
1164
- /**
1165
- * 启动前钩子 — 在 Framework 创建后、挂载前执行
1166
- *
1167
- * 用于初始化错误监控、埋点 SDK、i18n 等。
1168
- */
1169
- onBeforeStart?: (framework: Framework) => void | Promise<void>;
1170
- /**
1171
- * 启动后钩子 — 在初始页面触发后执行
1172
- *
1173
- * 用于启动后操作(如 service worker 注册、性能打点)。
1174
- */
1175
- onAfterStart?: (framework: Framework) => void | Promise<void>;
1176
- /**
1177
- * 挂载应用到 DOM
1178
- *
1179
- * 框架无关 — Svelte / React / Vue 均可通过此回调实现。
1180
- *
1181
- * @param target - DOM 挂载点
1182
- * @param context - Framework 实例 + 语言
1183
- * @returns 更新函数,用于后续页面切换
1184
- */
1185
- mount: (target: HTMLElement, context: {
1186
- framework: Framework;
1187
- }) => (props: {
1188
- page: Promise<BasePage> | BasePage;
1189
- isFirstPage?: boolean;
1190
- }) => void;
1191
- /** FlowAction / ExternalUrl 回调 */
1192
- callbacks: FlowActionCallbacks;
1193
- /**
1194
- * Framework 配置 — locale、reportCallback、eventRecorder 等
1195
- *
1196
- * 传入后会在 Framework.create() 时合并。
1197
- * prefetchedIntents 由框架自动从 DOM 提取,无需传入。
1198
- */
1199
- frameworkConfig?: Omit<FrameworkConfig, "prefetchedIntents">;
1200
- /**
1201
- * 异步加载当前 locale 的翻译字典。
1202
- *
1203
- * 显式传入时会覆盖 bootstrap / Vite 自动生成的 loader。
1204
- */
1205
- loadMessages?: MessagesLoader;
1206
- }
1207
- /**
1208
- * 启动客户端应用
1209
- *
1210
- * 自动执行 hydration 全流程。
1211
- */
1212
- declare function startBrowserApp(config: BrowserAppConfig): Promise<void>;
1213
- //#endregion
1214
- //#region ../browser/src/utils/history.d.ts
1215
- interface HistoryOptions {
1216
- getScrollablePageElement: () => HTMLElement | null;
1217
- }
1218
- declare class History<State> {
1219
- private readonly entries;
1220
- private readonly log;
1221
- private readonly getScrollablePageElement;
1222
- private currentStateId;
1223
- constructor(log: Logger, options: HistoryOptions, sizeLimit?: number);
1224
- replaceState(state: State, url: string): void;
1225
- pushState(state: State, url: string): void;
1226
- beforeTransition(): void;
1227
- onPopState(listener: (url: string, state?: State) => void | Promise<void>): void;
1228
- /** 仅推入 URL,不缓存页面状态(用于页面加载失败场景) */
1229
- pushUrl(url: string): void;
1230
- /** 仅替换 URL,不缓存页面状态(用于页面加载失败场景) */
1231
- replaceUrl(url: string): void;
1232
- updateState(update: (current?: State) => State): void;
1233
- private get scrollTop();
1234
- private set scrollTop(value);
1235
- }
1236
- //#endregion
1237
- //#region ../browser/src/utils/try-scroll.d.ts
1238
- declare function tryScroll(log: Logger, getScrollableElement: () => HTMLElement | null, scrollY: number): void;
1239
- //#endregion
1240
- //#region ../browser/src/server-data.d.ts
1241
- /**
1242
- * 从 DOM 反序列化服务端嵌入的数据。
1243
- * 读取 `<script id="serialized-server-data">` 的内容并移除标签。
1244
- */
1245
- declare function deserializeServerData(): PrefetchedIntent[] | undefined;
1246
- /**
1247
- * 从 DOM 提取 SSR 数据并构建 PrefetchedIntents 实例。
1248
- * 替代原来的 PrefetchedIntents.fromDom()。
1249
- */
1250
- declare function createPrefetchedIntentsFromDom(): PrefetchedIntents;
1251
- //#endregion
1252
6
  //#region ../ssr/src/render.d.ts
1253
7
  interface SSRRenderOptions {
1254
8
  /** 请求 URL */
@@ -1783,5 +537,5 @@ declare function finesoftFrontViteConfig(options?: FinesoftFrontViteOptions): {
1783
537
  closeBundle(): Promise<void>;
1784
538
  };
1785
539
  //#endregion
1786
- 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, MessagesLoader, MessagesLoaderContext, 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, type 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, resolveConfiguredMessages, resolveLocaleFromUrl, resolveMessages, resolvePluralKey, resolveRoot, rewrite, runAfterLoadGuards, runBeforeLoadGuards, serializeServerData, setHtmlLocaleAttributes, shouldLog, ssrRender, stableStringify, startBrowserApp, startServer, staticAdapter, tryScroll, vercelAdapter };
540
+ 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, Logger, Logger as LoggerInterface, LoggerFactory, LruMap, MakeDependenciesOptions, Mapper, MessagesLoader, MessagesLoaderContext, 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, resolveConfiguredMessages, resolveLocaleFromUrl, resolveMessages, resolvePluralKey, resolveRoot, rewrite, runAfterLoadGuards, runBeforeLoadGuards, serializeServerData, setHtmlLocaleAttributes, shouldLog, ssrRender, stableStringify, startBrowserApp, startServer, staticAdapter, tryScroll, vercelAdapter };
1787
541
  //# sourceMappingURL=index.d.mts.map