@lytjs/component 6.7.0 → 6.8.0

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.
@@ -0,0 +1,841 @@
1
+ import { VNode } from '@lytjs/vdom';
2
+ import { BaseAppContext, InternalSlots, ComponentPublicInstance, DebuggerEvent } from '@lytjs/shared-types';
3
+ export { ComponentPublicInstance, InternalSlots, SlotFunction } from '@lytjs/shared-types';
4
+ import { VNode as VNode$1 } from '@lytjs/common-vnode';
5
+ import { ComputedSignal, Signal, EffectScope } from '@lytjs/reactivity';
6
+
7
+ /** Prop 类型构造器 */
8
+ type PropType<T> = {
9
+ new (...args: unknown[]): T & {};
10
+ } | {
11
+ (): T;
12
+ };
13
+ type PropConstructor<T> = PropType<T> | true;
14
+ interface PropOptions<T = unknown> {
15
+ type?: PropConstructor<T>;
16
+ required?: boolean;
17
+ default?: T;
18
+ validator?: (value: unknown) => boolean;
19
+ }
20
+ interface SetupContext {
21
+ attrs: Record<string, unknown>;
22
+ slots: InternalSlots;
23
+ emit: (event: string, ...args: unknown[]) => void;
24
+ expose?: (exposed?: Record<string, unknown>) => void;
25
+ }
26
+ type RenderFunction = (ctx: ComponentPublicInstance) => VNode;
27
+ interface ComponentOptions<Props = Record<string, unknown>, RawBindings = Record<string, unknown>, D = Record<string, unknown>, C extends Record<string, unknown> = Record<string, unknown>> {
28
+ name?: string;
29
+ props?: Record<string, PropOptions<unknown>> & Props;
30
+ emits?: string[] | Record<string, (...args: unknown[]) => void>;
31
+ setup?: (props: Props, ctx: SetupContext) => RawBindings | RenderFunction | void;
32
+ render?: RenderFunction;
33
+ data?: () => D;
34
+ computed?: C;
35
+ watch?: Record<string, (...args: unknown[]) => void>;
36
+ methods?: Record<string, (...args: unknown[]) => unknown>;
37
+ provide?: Record<string, unknown> | (() => Record<string, unknown>);
38
+ inject?: Record<string, unknown>;
39
+ mixins?: ComponentOptions[];
40
+ extends?: ComponentOptions;
41
+ beforeCreate?(): void;
42
+ created?(): void;
43
+ beforeMount?(): void;
44
+ mounted?(): void;
45
+ beforeUpdate?(): void;
46
+ updated?(): void;
47
+ beforeUnmount?(): void;
48
+ unmounted?(): void;
49
+ activated?(): void;
50
+ deactivated?(): void;
51
+ errorCaptured?(err: Error, instance: ComponentPublicInstance | null, info: string): boolean | void;
52
+ renderTracked?(e: DebuggerEvent): void;
53
+ renderTriggered?(e: DebuggerEvent): void;
54
+ inheritAttrs?: boolean;
55
+ }
56
+ interface AppContextConfig {
57
+ /** 全局属性,可通过组件实例的 $ 访问 */
58
+ globalProperties?: Record<string, unknown>;
59
+ /** 全局错误处理器 */
60
+ errorHandler?: (err: Error, instance: unknown, info: string) => void;
61
+ /** 全局警告处理器 */
62
+ warnHandler?: (msg: string, instance: unknown, trace: string) => void;
63
+ /** 是否为原生标签 */
64
+ isNativeTag?: (tag: string) => boolean;
65
+ /** 自定义配置字段 */
66
+ [key: string]: unknown;
67
+ }
68
+ interface AppContext extends BaseAppContext<AppContextConfig> {
69
+ components: Record<string, ComponentOptions>;
70
+ directives: Record<string, unknown>;
71
+ mixins: ComponentOptions[];
72
+ provides: Record<string | symbol, unknown>;
73
+ }
74
+ /** 组件身份标识:type、name、uid 等 */
75
+ interface ComponentIdentity {
76
+ uid: number;
77
+ type: ComponentOptions;
78
+ }
79
+ /** 组件生命周期状态:挂载/卸载标记、生命周期钩子等 */
80
+ interface ComponentLifecycleState {
81
+ isMounted: boolean;
82
+ isUnmounted: boolean;
83
+ isDeactivated: boolean;
84
+ isKeepingAlive: boolean;
85
+ refs: Record<string, unknown>;
86
+ lifecycle: {
87
+ beforeMount: Set<(...args: unknown[]) => void>;
88
+ mounted: Set<(...args: unknown[]) => void>;
89
+ beforeUpdate: Set<(...args: unknown[]) => void>;
90
+ updated: Set<(...args: unknown[]) => void>;
91
+ beforeUnmount: Set<(...args: unknown[]) => void>;
92
+ unmounted: Set<(...args: unknown[]) => void>;
93
+ };
94
+ errorCapturedHooks?: Array<(err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void>;
95
+ activatedHooks?: Array<() => void>;
96
+ deactivatedHooks?: Array<() => void>;
97
+ renderTrackedHooks?: Array<(e: DebuggerEvent) => void>;
98
+ renderTriggeredHooks?: Array<(e: DebuggerEvent) => void>;
99
+ }
100
+ /** 组件渲染状态:render、subTree、update 等 */
101
+ interface ComponentRenderState {
102
+ vnode: VNode | null;
103
+ subTree: VNode | null;
104
+ render?: RenderFunction;
105
+ effects?: Array<{
106
+ stop(): void;
107
+ }>;
108
+ update?: () => void;
109
+ }
110
+ /** 组件上下文状态:props、slots、attrs、emit、provides 等 */
111
+ interface ComponentContextState {
112
+ props: Record<string, unknown>;
113
+ slots: InternalSlots;
114
+ ctx: ComponentPublicInstance;
115
+ setupState: Record<string, unknown>;
116
+ data: Record<string, unknown>;
117
+ propsOptions: Record<string, PropOptions>;
118
+ emitsOptions: Record<string, unknown> | null;
119
+ emit: (event: string, ...args: unknown[]) => void;
120
+ provides: Record<string | symbol, unknown>;
121
+ exposed?: Record<string, unknown> | null;
122
+ attrs: Record<string, unknown>;
123
+ accessCache: Record<string, number> | null;
124
+ }
125
+ /** 组件层级关系:parent、root、appContext 等 */
126
+ interface ComponentParentState {
127
+ parent: ComponentInternalInstance | null;
128
+ root: ComponentInternalInstance;
129
+ appContext: AppContext;
130
+ }
131
+ interface ComponentInternalInstance extends ComponentIdentity, ComponentLifecycleState, ComponentRenderState, ComponentContextState, ComponentParentState {
132
+ }
133
+
134
+ /**
135
+ * 从 vnode 创建组件内部实例。
136
+ *
137
+ * 错误处理:实例创建包裹在 try-catch 中,防止
138
+ * 组件初始化期间的未捕获异常导致应用崩溃。
139
+ * 错误会传播到最近的 ErrorBoundary。
140
+ */
141
+ declare function createComponentInstance(vnode: VNode$1, parent: ComponentInternalInstance | null): ComponentInternalInstance;
142
+ /**
143
+ * 设置组件实例:运行 setup、初始化 props、初始化 slots。
144
+ */
145
+ declare function setupComponent(instance: ComponentInternalInstance): void;
146
+ /**
147
+ * 初始化并验证组件实例的 props。
148
+ */
149
+ declare function initProps(instance: ComponentInternalInstance, rawProps: Record<string, unknown> | null): void;
150
+
151
+ /**
152
+ * 完成组件 setup:处理 data、methods、computed、render。
153
+ *
154
+ * 错误处理:整个 setup 过程包裹在 try-catch 中,
155
+ * 优雅地处理 data/methods/computed/watch 初始化期间的错误。
156
+ * 错误会传播到最近的 ErrorBoundary。
157
+ */
158
+ declare function finishComponentSetup(instance: ComponentInternalInstance): void;
159
+
160
+ /**
161
+ * 公共属性名到 accessCache 位掩码的映射。
162
+ * 用于快速判断一个 key 是否是 Vue 内置公共属性($data, $props 等)。
163
+ */
164
+ declare const PUBLIC_PROPERTIES_MAP: Record<string, number>;
165
+ /**
166
+ * Create the public instance proxy ($data, $props, $el, etc.).
167
+ * Uses a Proxy so that Options API `this` correctly resolves properties
168
+ * from setupState, data, props, and public instance fields ($el, $emit, etc.).
169
+ */
170
+ declare function createComponentPublicInstance(instance: ComponentInternalInstance): ComponentPublicInstance;
171
+
172
+ /**
173
+ * defineComponent 是一个恒等函数,直接返回选项对象。
174
+ * 它为组件选项提供 TypeScript 类型推断。
175
+ */
176
+ declare function defineComponent(options: ComponentOptions): ComponentOptions;
177
+ /**
178
+ * 定义函数式组件。
179
+ * 函数式组件没有实例、没有生命周期钩子、没有响应式状态。
180
+ * 它接收 props 并直接返回渲染函数。
181
+ *
182
+ * FIX: P1-22 使用精确类型替代 Record<string, any>,
183
+ * render 参数明确为返回 VNode 的函数,props 参数使用 Record<string, unknown>
184
+ */
185
+ declare function defineFunctionalComponent(render: (props: Record<string, unknown>) => VNode$1 | VNode$1[] | null, props?: Record<string, unknown>): ComponentOptions;
186
+ /**
187
+ * 创建基础应用上下文对象。
188
+ * 导出供 @lytjs/core 扩展运行时字段。
189
+ */
190
+ declare function createAppContext(): AppContext;
191
+
192
+ interface InjectionKey<T> {
193
+ /** 类型标志,用于类型推断,不运行时使用 */
194
+ __injectKey__?: T;
195
+ }
196
+ /**
197
+ * Inject 选项接口(改进版)
198
+ * 支持更精确的类型推断
199
+ */
200
+ interface InjectOptions<T = unknown> {
201
+ /** 如果为 true,将 defaultValue 视为工厂函数,调用它来生成默认值 */
202
+ factory?: boolean;
203
+ /** 从特定的祖先 key 查找值,而非注入的 key */
204
+ from?: InjectionKey<T> | string | symbol;
205
+ /** 如果为 true,仅从当前实例自身的 provides 中查找值(不向上查找祖先) */
206
+ local?: boolean;
207
+ }
208
+ /**
209
+ * 向后代组件提供值。
210
+ * FIX: P1-9 COMPONENT-NEW-03 - 改进类型定义,支持 InjectionKey 类型推断
211
+ */
212
+ declare function provide<T>(key: InjectionKey<T> | string | symbol, value: T): void;
213
+ /**
214
+ * 从祖先组件注入值。
215
+ * FIX: P1-9 COMPONENT-NEW-03 - 改进类型定义,支持更精确的类型推断
216
+ *
217
+ * Supported forms:
218
+ * - `inject('key')` - basic lookup
219
+ * - `inject('key', defaultValue)` - with default value
220
+ * - `inject('key', () => createDefault(), { factory: true })` - factory function default
221
+ * - `inject('key', undefined, { from: 'optionalSourceKey' })` - from modifier
222
+ * - `inject('key', undefined, { local: true })` - local only (no ancestor lookup)
223
+ * - `inject(injectionKey)` - with InjectionKey for type-safe lookup
224
+ */
225
+ declare function inject<T>(key: InjectionKey<T> | string | symbol, defaultValue?: T | (() => T), options?: InjectOptions<T>): T | undefined;
226
+
227
+ /**
228
+ * 将 props 定义规范化为统一的 Record<string, PropOptions> 格式。
229
+ * 处理数组形式的 props(如 ['a', 'b'])和对象形式的 props。
230
+ */
231
+ declare function normalizePropsOptions(rawProps?: Record<string, PropOptions> | string[]): Record<string, PropOptions>;
232
+ /**
233
+ * 解析 prop 值,处理默认值和类型检查。
234
+ * 处理缺失 prop 的布尔类型转换。
235
+ */
236
+ declare function resolvePropValue<T = unknown>(propOptions: PropOptions, value: unknown, _instance?: ComponentInternalInstance, key?: string): T | undefined;
237
+ /**
238
+ * 根据类型或类型数组验证值。
239
+ */
240
+ declare function validateType(value: unknown, type: unknown, key?: string): boolean;
241
+
242
+ /**
243
+ * Normalize emits definition into a consistent Record<string, any> format.
244
+ */
245
+ declare function normalizeEmitsOptions(emits?: string[] | Record<string, (...args: unknown[]) => unknown>): Record<string, unknown> | null;
246
+ /**
247
+ * Emit an event on a component instance.
248
+ * Looks for `onXxx` handler in props and attrs (camelCase conversion).
249
+ */
250
+ declare function emit(instance: ComponentInternalInstance, event: string, ...args: unknown[]): void;
251
+ /**
252
+ * 检查事件是否在 emits 选项中声明。
253
+ * 使用与 emit() 相同的规范化(kebab-case -> camelCase)以确保
254
+ * 一致的事件名匹配。
255
+ */
256
+ declare function isEmitValid(instance: ComponentInternalInstance, event: string): boolean;
257
+
258
+ /**
259
+ * 从 children 初始化 slots。
260
+ * Children 可以是:
261
+ * - 插槽函数对象(命名插槽)
262
+ * - 单个函数(默认插槽)
263
+ * - null/undefined(无插槽)
264
+ *
265
+ * FIX: P2-20 动态 slot 缓存策略:
266
+ * slots 在初始化时被规范化并存储在 instance.slots 中。
267
+ * 如果需要动态更新 slots(如通过 scoped slots),应通过
268
+ * 组件更新机制触发重新初始化,而非直接修改 instance.slots。
269
+ */
270
+ declare function initSlots(instance: ComponentInternalInstance, children: unknown): void;
271
+ /**
272
+ * 将插槽返回值规范化为数组。
273
+ * 确保插槽函数始终返回数组,以保持渲染一致性。
274
+ */
275
+ declare function normalizeSlotValue(value: unknown): VNode$1[];
276
+
277
+ /**
278
+ * 设置当前实例(在 setup 期间使用)。
279
+ */
280
+ declare function setCurrentInstance(instance: ComponentInternalInstance | null): void;
281
+ /**
282
+ * 获取当前实例。
283
+ */
284
+ declare function getCurrentInstance(): ComponentInternalInstance | null;
285
+ /**
286
+ * 注册组件挂载完成后调用的回调。
287
+ */
288
+ declare function onMounted(fn: () => void): void;
289
+ /**
290
+ * 注册组件更新完成后调用的回调。
291
+ */
292
+ declare function onUpdated(fn: () => void): void;
293
+ /**
294
+ * 注册组件卸载后调用的回调。
295
+ */
296
+ declare function onUnmounted(fn: () => void): void;
297
+ /**
298
+ * Register a callback to be called before the component is mounted.
299
+ */
300
+ declare function onBeforeMount(fn: () => void): void;
301
+ /**
302
+ * 注册组件更新前调用的回调。
303
+ */
304
+ declare function onBeforeUpdate(fn: () => void): void;
305
+ /**
306
+ * 注册组件卸载前调用的回调。
307
+ */
308
+ declare function onBeforeUnmount(fn: () => void): void;
309
+ /**
310
+ * 注册错误捕获回调。
311
+ * 使用数组收集每个实例的多个回调。
312
+ */
313
+ declare function onErrorCaptured(fn: (err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void): void;
314
+ /**
315
+ * 注册组件被 KeepAlive 激活时调用的回调。
316
+ */
317
+ declare function onActivated(fn: () => void): void;
318
+ /**
319
+ * 注册组件被 KeepAlive 停用时调用的回调。
320
+ */
321
+ declare function onDeactivated(fn: () => void): void;
322
+ /**
323
+ * 注册渲染期间追踪响应式依赖时调用的回调。
324
+ * 仅在开发模式下生效。
325
+ */
326
+ declare function onRenderTracked(fn: (e: DebuggerEvent) => void): void;
327
+ /**
328
+ * 注册渲染期间触发响应式依赖时调用的回调。
329
+ * 仅在开发模式下生效。
330
+ */
331
+ declare function onRenderTriggered(fn: (e: DebuggerEvent) => void): void;
332
+ /**
333
+ * Call all registered hooks for a given lifecycle phase.
334
+ */
335
+ declare function callLifecycleHook(instance: ComponentInternalInstance, hookName: 'beforeMount' | 'mounted' | 'beforeUpdate' | 'updated' | 'beforeUnmount' | 'unmounted'): void;
336
+ /**
337
+ * 调用 beforeCreate 和 created 生命周期钩子(选项式 API)。
338
+ */
339
+ declare function callCreatedHook(instance: ComponentInternalInstance): void;
340
+ /**
341
+ * 调用 beforeMount 和 mounted 生命周期钩子(选项式 API)。
342
+ */
343
+ declare function callMountedHook(instance: ComponentInternalInstance): void;
344
+ /**
345
+ * 调用 beforeUpdate 和 updated 生命周期钩子(选项式 API)。
346
+ */
347
+ declare function callUpdatedHook(instance: ComponentInternalInstance): void;
348
+ /**
349
+ * 调用 beforeUnmount 和 unmounted 生命周期钩子(选项式 API)。
350
+ */
351
+ declare function callUnmountedHook(instance: ComponentInternalInstance): void;
352
+ /**
353
+ * 处理错误捕获传播。
354
+ * 调用当前实例上所有通过 onErrorCaptured() 注册的 errorCapturedHooks(从内到外),
355
+ * 然后传播到父组件。如果错误被处理则返回 true。
356
+ */
357
+ declare function handleError(err: Error, instance: ComponentInternalInstance | null, info: string): boolean;
358
+
359
+ interface KeepAliveProps {
360
+ include?: string | RegExp | (string | RegExp)[];
361
+ exclude?: string | RegExp | (string | RegExp)[];
362
+ /** FIX: P2-17 缓存大小限制配置(默认 10) */
363
+ max?: number;
364
+ /** 自定义缓存 key 函数:接收一个 vnode,返回字符串或数字作为缓存 key */
365
+ onCacheKey?: (vnode: VNode) => string | number;
366
+ }
367
+ declare const KeepAlive: ComponentOptions;
368
+ /**
369
+ * 创建 KeepAlive 组件实例。
370
+ */
371
+ declare function createKeepAliveInstance(props?: KeepAliveProps, parent?: ComponentInternalInstance | null): ComponentInternalInstance;
372
+ /**
373
+ * 检查组件名是否匹配 include/exclude 模式。
374
+ */
375
+ declare function matchesPattern(name: string | undefined, pattern: string | RegExp | (string | RegExp)[] | undefined): boolean;
376
+ /**
377
+ * 获取 KeepAlive 上下文中 vnode 的缓存 key。
378
+ *
379
+ * 如果 KeepAlive 实例有 `onCacheKey` prop(自定义函数),
380
+ * 则使用该函数计算缓存 key。
381
+ * 否则,默认 key 从 `vnode.type`(组件构造函数或标签名)派生。
382
+ *
383
+ * @param keepAlive - KeepAlive 组件实例
384
+ * @param vnode - 需要计算缓存 key 的 vnode
385
+ * @returns 字符串形式的缓存 key
386
+ */
387
+ declare function getCacheKey(keepAlive: ComponentInternalInstance, vnode: VNode): string;
388
+ /**
389
+ * 在 KeepAlive 中缓存组件实例。
390
+ * FIX: P2-8 COMPONENT-NEW-05 - LRU 缓存自动处理容量限制
391
+ */
392
+ declare function cacheInstance(keepAlive: ComponentInternalInstance, key: string, instance: ComponentInternalInstance): void;
393
+ /**
394
+ * Get a cached instance from KeepAlive.
395
+ */
396
+ declare function getCachedInstance(keepAlive: ComponentInternalInstance, key: string): ComponentInternalInstance | undefined;
397
+ /**
398
+ * 从 KeepAlive 移除缓存的实例。
399
+ */
400
+ declare function removeCachedInstance(keepAlive: ComponentInternalInstance, key: string): boolean;
401
+ /**
402
+ * 激活缓存的组件实例。
403
+ */
404
+ declare function activateInstance(instance: ComponentInternalInstance): void;
405
+ /**
406
+ * 停用组件实例。
407
+ */
408
+ declare function deactivateInstance(instance: ComponentInternalInstance): void;
409
+
410
+ interface SuspenseProps {
411
+ timeout?: number;
412
+ onResolve?: () => void;
413
+ onPending?: () => void;
414
+ onError?: (error: Error) => void;
415
+ }
416
+ interface SuspenseAsyncState {
417
+ isPending: boolean;
418
+ error: Error | null;
419
+ /** @deprecated 使用 pendingPromises 代替 */
420
+ promise: Promise<unknown> | null;
421
+ pendingPromises: Set<Promise<unknown>>;
422
+ onResolve: (() => void)[];
423
+ onPending: (() => void)[];
424
+ onError: ((error: Error) => void)[];
425
+ aborted: boolean;
426
+ /**
427
+ * 关联的 vdom 层 SuspenseBoundary 引用。
428
+ * 当异步状态变化时,通过此引用驱动 DOM 切换。
429
+ */
430
+ vnodeBoundary?: {
431
+ vnode: VNode$1;
432
+ container: unknown;
433
+ anchor: unknown;
434
+ parentComponent: ComponentInternalInstance | null;
435
+ isSVG: boolean;
436
+ isInFallback: boolean;
437
+ activeBranch: VNode$1 | null;
438
+ pendingBranch: VNode$1 | null;
439
+ };
440
+ /**
441
+ * DOM 切换函数,由 vdom 层的 patch 函数提供。
442
+ * 用于在 pending/resolve 状态变化时执行实际的 DOM 操作。
443
+ */
444
+ domSwitch?: (boundary: SuspenseAsyncState, toFallback: boolean) => void;
445
+ }
446
+ declare const Suspense: ComponentOptions;
447
+ /**
448
+ * 创建 Suspense 组件实例。
449
+ */
450
+ declare function createSuspenseInstance(props?: SuspenseProps, parent?: ComponentInternalInstance | null): ComponentInternalInstance;
451
+ /**
452
+ * 创建 suspense boundary 用于管理异步子组件。
453
+ */
454
+ declare function createSuspenseBoundary(): SuspenseAsyncState;
455
+ /**
456
+ * Register an async child with the suspense boundary.
457
+ * Returns true if this is the first pending child (transition to pending).
458
+ */
459
+ declare function registerAsyncChild(boundary: SuspenseAsyncState, promise: Promise<unknown>): boolean;
460
+ /**
461
+ * 检查 suspense boundary 当前是否处于 pending 状态。
462
+ */
463
+ declare function isSuspensePending(boundary: SuspenseAsyncState): boolean;
464
+ /**
465
+ * Get the error from a suspense boundary (if any).
466
+ */
467
+ declare function getSuspenseError(boundary: SuspenseAsyncState): Error | null;
468
+ /**
469
+ * 将 vdom 层的 SuspenseBoundary 与 component 层的 SuspenseAsyncState 关联。
470
+ * 由 vdom 的 mountSuspense 调用,使异步状态变化能驱动 DOM 切换。
471
+ */
472
+ declare function linkSuspenseBoundary(asyncState: SuspenseAsyncState, vnodeBoundary: SuspenseAsyncState['vnodeBoundary'], domSwitch: SuspenseAsyncState['domSwitch']): void;
473
+ /**
474
+ * 手动解决 suspense boundary。
475
+ *
476
+ * FIX: P1-20 添加语义注释:
477
+ * resolveSuspense 用于手动将 suspense 边界标记为已解决状态。
478
+ * 调用后,所有 pending 的 Promise 将被忽略(通过设置 aborted = true),
479
+ * onResolve 回调将被触发,DOM 将从 fallback 切回默认内容。
480
+ * 注意:此方法不会等待正在进行的异步操作完成,而是立即强制解决。
481
+ * 适用场景:用户手动取消等待、路由切换等需要立即恢复的场景。
482
+ */
483
+ declare function resolveSuspense(boundary: SuspenseAsyncState): void;
484
+ /**
485
+ * 中止 suspense boundary(例如在卸载时)。
486
+ * 拒绝所有 pending 的 Promise 以防止内存泄漏,并允许
487
+ * 下游消费者通过 .catch() 处理中止。
488
+ *
489
+ * FIX: P1-20 添加语义注释:
490
+ * abortSuspense 用于在组件卸载等场景下中止 suspense 边界。
491
+ * 与 resolveSuspense 不同,abortSuspense 不会触发 onResolve 回调,
492
+ * 而是清空所有回调数组以防止后续调用。所有 pending 的 Promise
493
+ * 将尝试通过 abort 方法取消(如果是自定义 thenable)。
494
+ * 适用场景:组件卸载、路由切换导致组件树销毁等。
495
+ */
496
+ declare function abortSuspense(boundary: SuspenseAsyncState): void;
497
+ /**
498
+ * useSuspense Hook
499
+ * 将 Promise 注册到当前 Suspense 边界
500
+ */
501
+ declare function useSuspense<T>(promise: Promise<T>, _key?: string): T;
502
+ /**
503
+ * startTransition 函数
504
+ * 标记更新为过渡更新,不会立即触发 Suspense fallback
505
+ */
506
+ declare function startTransition(callback: () => void): void;
507
+ /**
508
+ * SuspenseResource 类
509
+ * 用于管理可缓存的异步资源
510
+ */
511
+ declare class SuspenseResource<T> {
512
+ private status;
513
+ private value;
514
+ private error;
515
+ private promise;
516
+ constructor(factory: () => Promise<T>);
517
+ private load;
518
+ read(): T;
519
+ refresh(factory: () => Promise<T>): void;
520
+ }
521
+ /**
522
+ * 创建 Suspense 资源
523
+ */
524
+ declare function createSuspenseResource<T>(factory: () => Promise<T>): SuspenseResource<T>;
525
+
526
+ /**
527
+ * Transition 组件属性(泛型版本)。
528
+ * @template HE - 宿主元素类型
529
+ */
530
+ interface TransitionComponentProps<HE = unknown> {
531
+ name?: string;
532
+ appear?: boolean;
533
+ mode?: 'in-out' | 'out-in' | 'default';
534
+ enterFromClass?: string;
535
+ enterActiveClass?: string;
536
+ enterToClass?: string;
537
+ leaveFromClass?: string;
538
+ leaveActiveClass?: string;
539
+ leaveToClass?: string;
540
+ onBeforeEnter?: (el: HE) => void;
541
+ onEnter?: (el: HE, done: () => void) => void;
542
+ onAfterEnter?: (el: HE) => void;
543
+ onEnterCancelled?: (el: HE) => void;
544
+ onBeforeLeave?: (el: HE) => void;
545
+ onLeave?: (el: HE, done: () => void) => void;
546
+ onAfterLeave?: (el: HE) => void;
547
+ onLeaveCancelled?: (el: HE) => void;
548
+ }
549
+ /**
550
+ * @deprecated 使用 TransitionComponentProps<HE> 代替。
551
+ * 保留此类型别名以确保向后兼容。
552
+ */
553
+ type TransitionComponentPropsLegacy = TransitionComponentProps<Element>;
554
+ declare const Transition: ComponentOptions;
555
+
556
+ /**
557
+ * TransitionGroup 组件属性(泛型版本)。
558
+ * @template HE - 宿主元素类型
559
+ */
560
+ interface TransitionGroupComponentProps<HE = unknown> {
561
+ name?: string;
562
+ appear?: boolean;
563
+ tag?: string | false;
564
+ moveClass?: string;
565
+ enterFromClass?: string;
566
+ enterActiveClass?: string;
567
+ enterToClass?: string;
568
+ leaveFromClass?: string;
569
+ leaveActiveClass?: string;
570
+ leaveToClass?: string;
571
+ onBeforeEnter?: (el: HE) => void;
572
+ onEnter?: (el: HE, done: () => void) => void;
573
+ onAfterEnter?: (el: HE) => void;
574
+ onEnterCancelled?: (el: HE) => void;
575
+ onBeforeLeave?: (el: HE) => void;
576
+ onLeave?: (el: HE, done: () => void) => void;
577
+ onAfterLeave?: (el: HE) => void;
578
+ onLeaveCancelled?: (el: HE) => void;
579
+ }
580
+ /**
581
+ * @deprecated 使用 TransitionGroupComponentProps<HE> 代替。
582
+ * 保留此类型别名以确保向后兼容。
583
+ */
584
+ type TransitionGroupComponentPropsLegacy = TransitionGroupComponentProps<Element>;
585
+ declare const TransitionGroup: ComponentOptions;
586
+
587
+ interface TeleportProps {
588
+ to: string | Element;
589
+ disabled?: boolean;
590
+ }
591
+ declare const Teleport: ComponentOptions;
592
+
593
+ interface ErrorBoundaryProps {
594
+ onError?: (error: Error, info: string) => void;
595
+ fallback?: ComponentOptions;
596
+ }
597
+ declare const ErrorBoundary: ComponentOptions;
598
+
599
+ /**
600
+ * 创建与组件协作的 Signal State
601
+ */
602
+ declare function createSignalState<T>(initialValue: T): Signal<T>;
603
+ /**
604
+ * 创建与组件协作的 Computed Signal State
605
+ */
606
+ declare function createComputedState<T>(getter: () => T): ComputedSignal<T>;
607
+
608
+ /**
609
+ * 异步组件加载器函数类型
610
+ */
611
+ type AsyncComponentLoader<T = unknown> = () => Promise<T>;
612
+ /**
613
+ * 定义异步组件的选项
614
+ */
615
+ interface AsyncComponentOptions {
616
+ /**
617
+ * 返回 Promise 解析为组件的加载器函数
618
+ */
619
+ loader: AsyncComponentLoader<ComponentOptions>;
620
+ /**
621
+ * 异步组件加载时显示的组件
622
+ */
623
+ loadingComponent?: ComponentOptions;
624
+ /**
625
+ * 异步组件加载失败时显示的组件
626
+ */
627
+ errorComponent?: ComponentOptions;
628
+ /**
629
+ * 显示加载组件前的延迟时间(毫秒)
630
+ * @default 200
631
+ */
632
+ delay?: number;
633
+ /**
634
+ * 异步组件加载的超时时间(毫秒)
635
+ */
636
+ timeout?: number;
637
+ /**
638
+ * 是否挂起组件渲染直到加载完成
639
+ * @default false
640
+ */
641
+ suspensible?: boolean;
642
+ /**
643
+ * 异步组件加载失败时的错误处理器
644
+ */
645
+ onError?: (error: Error) => void;
646
+ }
647
+ /**
648
+ * 异步组件加载的内部状态
649
+ */
650
+ interface AsyncComponentState {
651
+ loadedComponent: ComponentOptions | null;
652
+ error: Error | null;
653
+ isLoading: boolean;
654
+ isLoaded: boolean;
655
+ isError: boolean;
656
+ loadingPromise: Promise<void> | null;
657
+ }
658
+ /**
659
+ * 定义一个异步组件,支持加载、错误和预加载功能。
660
+ *
661
+ * @example
662
+ * ```ts
663
+ * const AsyncComp = defineAsyncComponent({
664
+ * loader: () => import('./MyComponent.vue'),
665
+ * loadingComponent: LoadingSpinner,
666
+ * errorComponent: ErrorDisplay,
667
+ * delay: 200,
668
+ * timeout: 3000,
669
+ * });
670
+ *
671
+ * // Preload the component before it's needed
672
+ * AsyncComp.preload();
673
+ * ```
674
+ */
675
+ declare function defineAsyncComponent(options: AsyncComponentOptions | AsyncComponentLoader<ComponentOptions>): ComponentOptions & {
676
+ preload: () => Promise<void>;
677
+ };
678
+ /**
679
+ * 一次性预加载多个异步组件。
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * preloadComponents([
684
+ * () => import('./CompA.vue'),
685
+ * () => import('./CompB.vue'),
686
+ * () => import('./CompC.vue'),
687
+ * ]);
688
+ * ```
689
+ */
690
+ declare function preloadComponents(loaders: AsyncComponentLoader[]): Promise<void>;
691
+ /**
692
+ * 通过加载器函数预加载单个组件。
693
+ */
694
+ declare function preloadComponent(loader: AsyncComponentLoader): Promise<void>;
695
+ /**
696
+ * 检查组件是否已被预加载。
697
+ */
698
+ declare function isComponentPreloaded(loader: AsyncComponentLoader): boolean;
699
+ /**
700
+ * 清除特定加载器或所有加载器的预加载缓存。
701
+ */
702
+ declare function clearPreloadCache(loader?: AsyncComponentLoader): void;
703
+
704
+ /**
705
+ * InjectionToken - 类型安全的注入令牌
706
+ *
707
+ * 与 InjectionKey 不同,InjectionToken 是一个类实例,
708
+ * 可以携带更多元数据(如描述、工厂函数、生命周期等)
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * const API_URL = new InjectionToken<string>('api-url');
713
+ * const Database = new InjectionToken<Database>('database', {
714
+ * factory: () => new Database(),
715
+ * lifecycle: 'singleton',
716
+ * });
717
+ * ```
718
+ */
719
+ declare class InjectionToken<T> {
720
+ /** 令牌描述 */
721
+ readonly description: string;
722
+ /** 令牌唯一标识 */
723
+ readonly __token: symbol;
724
+ /** 工厂函数 */
725
+ readonly factory?: () => T;
726
+ /** 生命周期 */
727
+ readonly lifecycle?: ProviderLifecycle;
728
+ constructor(description: string, options?: {
729
+ factory?: () => T;
730
+ lifecycle?: ProviderLifecycle;
731
+ });
732
+ toString(): string;
733
+ }
734
+ /**
735
+ * 判断是否是 InjectionToken
736
+ */
737
+ declare function isInjectionToken(value: unknown): value is InjectionToken<unknown>;
738
+ /** Provider 生命周期类型 */
739
+ type ProviderLifecycle = 'singleton' | 'scoped' | 'transient';
740
+ /** Provider 配置 */
741
+ interface ProviderConfig<T = unknown> {
742
+ /** 提供的值 */
743
+ provide?: T;
744
+ /** 工厂函数 */
745
+ useFactory?: () => T;
746
+ /** 现有令牌别名 */
747
+ useExisting?: InjectionToken<T> | string | symbol;
748
+ /** 生命周期 */
749
+ lifecycle?: ProviderLifecycle;
750
+ /** 是否可选 */
751
+ optional?: boolean;
752
+ }
753
+ /** Provider 记录 */
754
+ interface ProviderRecord {
755
+ value: unknown;
756
+ lifecycle: ProviderLifecycle;
757
+ scope?: EffectScope;
758
+ instanceId?: symbol;
759
+ }
760
+ /**
761
+ * Provider 树节点
762
+ * 支持嵌套的 Provider 层级结构
763
+ */
764
+ interface ProviderNode {
765
+ /** 唯一标识 */
766
+ id: symbol;
767
+ /** 父节点 */
768
+ parent: ProviderNode | null;
769
+ /** 子节点 */
770
+ children: Set<ProviderNode>;
771
+ /** 提供的值 */
772
+ providers: Map<string | symbol, ProviderRecord>;
773
+ /** 作用域 */
774
+ scope: EffectScope;
775
+ }
776
+ /**
777
+ * 获取或创建全局 Provider 根节点
778
+ */
779
+ declare function getProviderRoot(): ProviderNode;
780
+ /**
781
+ * 进入新的 Provider 作用域
782
+ */
783
+ declare function enterProviderScope(): ProviderNode;
784
+ /**
785
+ * 退出当前 Provider 作用域
786
+ */
787
+ declare function exitProviderScope(): void;
788
+ /**
789
+ * 获取当前 Provider 节点
790
+ */
791
+ declare function getCurrentProviderNode(): ProviderNode | null;
792
+ /**
793
+ * 增强的 Inject 选项
794
+ */
795
+ interface EnhancedInjectOptions<T = unknown> {
796
+ /** 是否可选(找不到时不报错) */
797
+ optional?: boolean;
798
+ /** 默认值 */
799
+ default?: T | (() => T);
800
+ /** 从特定祖先查找 */
801
+ from?: InjectionToken<T> | string | symbol;
802
+ /** 是否仅查找当前层级 */
803
+ local?: boolean;
804
+ /** 是否跳过自身(仅查找祖先) */
805
+ skipSelf?: boolean;
806
+ }
807
+ /**
808
+ * 注入错误
809
+ */
810
+ declare class InjectionError extends Error {
811
+ token: string | symbol;
812
+ constructor(token: string | symbol, message: string);
813
+ }
814
+ /**
815
+ * 创建并注册一个单例 Provider
816
+ */
817
+ declare function provideSingleton<T>(key: InjectionToken<T> | string | symbol, factory: () => T): void;
818
+ /**
819
+ * 创建并注册一个作用域 Provider
820
+ */
821
+ declare function provideScoped<T>(key: InjectionToken<T> | string | symbol, factory: () => T): void;
822
+ /**
823
+ * 创建并注册一个临时 Provider
824
+ */
825
+ declare function provideTransient<T>(key: InjectionToken<T> | string | symbol, factory: () => T): void;
826
+ /**
827
+ * 批量注册 Providers
828
+ */
829
+ declare function provideAll(providers: Array<{
830
+ provide: InjectionToken<unknown> | string | symbol;
831
+ useValue?: unknown;
832
+ useFactory?: () => unknown;
833
+ useExisting?: InjectionToken<unknown> | string | symbol;
834
+ lifecycle?: ProviderLifecycle;
835
+ }>): void;
836
+ /**
837
+ * 创建一个 Provider 作用域并执行回调
838
+ */
839
+ declare function withProviderScope<T>(fn: () => T): T;
840
+
841
+ export { type AppContext, type AsyncComponentLoader, type AsyncComponentOptions, type AsyncComponentState, type ComponentContextState, type ComponentIdentity, type ComponentInternalInstance, type ComponentLifecycleState, type ComponentOptions, type ComponentParentState, type ComponentRenderState, type EnhancedInjectOptions, ErrorBoundary, type ErrorBoundaryProps, type InjectOptions, InjectionError, InjectionToken, KeepAlive, type KeepAliveProps, PUBLIC_PROPERTIES_MAP, type PropOptions, type PropType, type ProviderConfig, type ProviderLifecycle, type ProviderNode, type RenderFunction, type SetupContext, Suspense, type SuspenseAsyncState, type SuspenseProps, SuspenseResource, Teleport, type TeleportProps, Transition, type TransitionComponentProps, type TransitionComponentPropsLegacy, TransitionGroup, type TransitionGroupComponentProps, type TransitionGroupComponentPropsLegacy, abortSuspense, activateInstance, cacheInstance, callCreatedHook, callLifecycleHook, callMountedHook, callUnmountedHook, callUpdatedHook, clearPreloadCache, createAppContext, createComponentInstance, createComponentPublicInstance, createComputedState, createKeepAliveInstance, createSignalState, createSuspenseBoundary, createSuspenseInstance, createSuspenseResource, deactivateInstance, defineAsyncComponent, defineComponent, defineFunctionalComponent, emit, enterProviderScope, exitProviderScope, finishComponentSetup, getCacheKey, getCachedInstance, getCurrentInstance, getCurrentProviderNode, getProviderRoot, getSuspenseError, handleError, initProps, initSlots, inject, isComponentPreloaded, isEmitValid, isInjectionToken, isSuspensePending, linkSuspenseBoundary, matchesPattern, normalizeEmitsOptions, normalizePropsOptions, normalizeSlotValue, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, preloadComponent, preloadComponents, provide, provideAll, provideScoped, provideSingleton, provideTransient, registerAsyncChild, removeCachedInstance, resolvePropValue, resolveSuspense, setCurrentInstance, setupComponent, startTransition, useSuspense, validateType, withProviderScope };