wevu 0.0.0 → 0.0.2-alpha.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.
package/dist/index.d.mts CHANGED
@@ -1,97 +1,557 @@
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-DHBSC7mS.mjs";
2
+
3
+ //#region src/reactivity/computed.d.ts
4
+ type ComputedGetter<T$1> = () => T$1;
5
+ type ComputedSetter<T$1> = (value: T$1) => void;
6
+ interface ComputedRef<T$1> {
7
+ readonly value: T$1;
8
+ }
9
+ interface WritableComputedRef<T$1> {
10
+ value: T$1;
11
+ }
12
+ interface WritableComputedOptions<T$1> {
13
+ get: ComputedGetter<T$1>;
14
+ set: ComputedSetter<T$1>;
15
+ }
16
+ declare function computed<T$1>(getter: ComputedGetter<T$1>): ComputedRef<T$1>;
17
+ declare function computed<T$1>(options: WritableComputedOptions<T$1>): WritableComputedRef<T$1>;
18
+ //#endregion
19
+ //#region src/scheduler.d.ts
20
+ declare function nextTick<T$1>(fn?: () => T$1): Promise<T$1>;
21
+ //#endregion
22
+ //#region src/reactivity/core.d.ts
1
23
  type EffectScheduler = () => void;
2
24
  type Dep = Set<ReactiveEffect>;
3
- interface ReactiveEffect<T = any> {
4
- (): T;
5
- deps: Dep[];
6
- scheduler?: EffectScheduler;
7
- active: boolean;
8
- _fn: () => T;
9
- onStop?: () => void;
25
+ interface ReactiveEffect<T$1 = any> {
26
+ (): T$1;
27
+ deps: Dep[];
28
+ scheduler?: EffectScheduler;
29
+ active: boolean;
30
+ _fn: () => T$1;
31
+ onStop?: () => void;
10
32
  }
11
33
  interface EffectOptions {
12
- scheduler?: EffectScheduler;
13
- lazy?: boolean;
14
- onStop?: () => void;
34
+ scheduler?: EffectScheduler;
35
+ lazy?: boolean;
36
+ onStop?: () => void;
15
37
  }
16
- declare function effect<T = any>(fn: () => T, options?: EffectOptions): ReactiveEffect<T>;
38
+ declare function effect<T$1 = any>(fn: () => T$1, options?: EffectOptions): ReactiveEffect<T$1>;
17
39
  declare function stop(runner: ReactiveEffect): void;
18
- declare function reactive<T extends object>(target: T): T;
40
+ //#endregion
41
+ //#region src/reactivity/reactive.d.ts
42
+ declare function reactive<T$1 extends object>(target: T$1): T$1;
19
43
  declare function isReactive(value: unknown): boolean;
20
- declare function toRaw<T>(observed: T): T;
21
- interface Ref<T = any> {
22
- value: T;
23
- }
24
- declare function isRef(value: unknown): value is Ref<any>;
25
- declare function ref<T>(value: T): Ref<T>;
26
- declare function unref<T>(value: T | Ref<T>): T;
27
- type ComputedGetter<T> = () => T;
28
- type ComputedSetter<T> = (value: T) => void;
29
- interface ComputedRef<T> {
30
- readonly value: T;
31
- }
32
- interface WritableComputedRef<T> {
33
- value: T;
34
- }
35
- interface WritableComputedOptions<T> {
36
- get: ComputedGetter<T>;
37
- set: ComputedSetter<T>;
38
- }
39
- declare function computed<T>(getter: ComputedGetter<T>): ComputedRef<T>;
40
- declare function computed<T>(options: WritableComputedOptions<T>): WritableComputedRef<T>;
44
+ declare function toRaw<T$1>(observed: T$1): T$1;
45
+ /**
46
+ * Establish a dependency on the whole reactive object "version".
47
+ * 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
48
+ */
49
+ declare function touchReactive(target: object): void;
50
+ /**
51
+ * 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
52
+ *
53
+ * @param target 待转换的对象
54
+ * @returns 浅层响应式代理
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const state = shallowReactive({ nested: { count: 0 } })
59
+ *
60
+ * state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
61
+ * state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
62
+ * ```
63
+ */
64
+ declare function shallowReactive<T$1 extends object>(target: T$1): T$1;
65
+ /**
66
+ * Checks if a value is a shallow reactive object
67
+ */
68
+ declare function isShallowReactive(value: unknown): boolean;
69
+ /**
70
+ * 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
71
+ *
72
+ * @param value 需要标记的对象
73
+ * @returns 带有跳过标记的原对象
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const foo = markRaw({
78
+ * nested: {}
79
+ * })
80
+ *
81
+ * const state = reactive({
82
+ * foo
83
+ * })
84
+ *
85
+ * state.foo // 不是响应式对象
86
+ * ```
87
+ */
88
+ declare function markRaw<T$1 extends object>(value: T$1): T$1;
89
+ /**
90
+ * 判断某个值是否被标记为原始(即不应转换为响应式)。
91
+ *
92
+ * @param value 待检测的值
93
+ * @returns 若含有跳过标记则返回 true
94
+ */
95
+ declare function isRaw(value: unknown): boolean;
96
+ //#endregion
97
+ //#region src/reactivity/readonly.d.ts
98
+ /**
99
+ * readonly 会为对象/数组创建一个“浅层”只读代理,并为 Ref 创建只读包装。
100
+ * 选择浅层而非深层递归,是为了在小程序环境中保持实现和运行时开销最小,
101
+ * 仅阻止直接属性写入/删除,嵌套对象仍按原样透传。
102
+ */
103
+ declare function readonly<T$1 extends object>(target: T$1): T$1;
104
+ declare function readonly<T$1>(target: Ref<T$1>): Readonly<Ref<T$1>>;
105
+ //#endregion
106
+ //#region src/reactivity/shallowRef.d.ts
107
+ /**
108
+ * 创建一个“浅层” ref:它只在 .value 被整体替换时触发依赖,不会对内部对象做深层响应式处理。
109
+ *
110
+ * @param value 初始值
111
+ * @param defaultValue 传递给 customRef 的默认值,可用于兜底
112
+ * @returns 仅跟踪自身 .value 变更的浅层 ref
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const state = shallowRef({ count: 0 })
117
+ * state.value = { count: 1 } // 会触发依赖
118
+ * state.value.count++ // 不会触发依赖(内部属性未被深度代理)
119
+ * ```
120
+ */
121
+ declare function shallowRef<T$1>(value: T$1): Ref<T$1>;
122
+ declare function shallowRef<T$1>(value: T$1, defaultValue: T$1): Ref<T$1>;
123
+ /**
124
+ * 判断传入值是否为浅层 ref。
125
+ *
126
+ * @param r 待判断的值
127
+ * @returns 若为浅层 ref 则返回 true
128
+ */
129
+ declare function isShallowRef(r: any): r is Ref<any>;
130
+ /**
131
+ * 主动触发一次浅层 ref 的更新(无需深度比较)。
132
+ *
133
+ * @param ref 需要触发的 ref
134
+ */
135
+ declare function triggerRef<T$1>(ref: Ref<T$1>): void;
136
+ //#endregion
137
+ //#region src/reactivity/toRefs.d.ts
138
+ /**
139
+ * 将一个响应式对象转换成“同结构的普通对象”,其中每个字段都是指向原对象对应属性的 ref。
140
+ *
141
+ * @param object 待转换的响应式对象
142
+ * @returns 包含若干 ref 的普通对象
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const state = reactive({ foo: 1, bar: 2 })
147
+ * const stateAsRefs = toRefs(state)
148
+ *
149
+ * stateAsRefs.foo.value++ // 2
150
+ * state.foo // 2
151
+ * ```
152
+ */
153
+ declare function toRefs<T$1 extends object>(object: T$1): ToRefs<T$1>;
154
+ /**
155
+ * 为源响应式对象的单个属性创建 ref,可读可写并与原属性保持同步。
156
+ *
157
+ * @param object 源响应式对象
158
+ * @param key 属性名
159
+ * @returns 指向该属性的 ref
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const state = reactive({ foo: 1 })
164
+ * const fooRef = toRef(state, 'foo')
165
+ *
166
+ * fooRef.value++
167
+ * console.log(state.foo) // 2
168
+ * ```
169
+ */
170
+ declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1): Ref<T$1[K$1]>;
171
+ declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1, defaultValue: T$1[K$1]): Ref<T$1[K$1]>;
172
+ /**
173
+ * toRefs 返回值的类型辅助
174
+ */
175
+ type ToRefs<T$1 extends object> = { [K in keyof T$1]: Ref<T$1[K]> };
176
+ //#endregion
177
+ //#region src/reactivity/traverse.d.ts
178
+ declare function traverse(value: any, seen?: Set<object>): any;
179
+ //#endregion
180
+ //#region src/reactivity/watch.d.ts
41
181
  interface WatchOptions {
42
- immediate?: boolean;
43
- deep?: boolean;
182
+ immediate?: boolean;
183
+ deep?: boolean;
44
184
  }
45
- type WatchSource<T = any> = (() => T) | Ref<T> | object;
185
+ type WatchSource<T$1 = any> = (() => T$1) | Ref<T$1> | object;
46
186
  type WatchStopHandle = () => void;
47
- declare function traverse(value: any, seen?: Set<object>): any;
48
- declare function watch<T>(source: WatchSource<T>, cb: (value: T, oldValue: T, onCleanup: (cleanupFn: () => void) => void) => void, options?: WatchOptions): WatchStopHandle;
49
-
187
+ type DeepWatchStrategy = 'version' | 'traverse';
188
+ declare function setDeepWatchStrategy(strategy: DeepWatchStrategy): void;
189
+ declare function getDeepWatchStrategy(): DeepWatchStrategy;
190
+ declare function watch<T$1>(source: WatchSource<T$1>, cb: (value: T$1, oldValue: T$1, onCleanup: (cleanupFn: () => void) => void) => void, options?: WatchOptions): WatchStopHandle;
191
+ /**
192
+ * watchEffect 注册一个响应式副作用,可选清理函数。
193
+ * 副作用会立即执行,并在依赖变化时重新运行。
194
+ */
195
+ declare function watchEffect(effectFn: (onCleanup: (cleanupFn: () => void) => void) => void): WatchStopHandle;
196
+ //#endregion
197
+ //#region src/runtime/types.d.ts
50
198
  type ComputedDefinitions = Record<string, ComputedGetter<any> | WritableComputedOptions<any>>;
51
199
  type MethodDefinitions = Record<string, (...args: any[]) => any>;
52
- type ExtractComputed<C extends ComputedDefinitions> = {
53
- [K in keyof C]: C[K] extends ComputedGetter<infer R> ? R : C[K] extends WritableComputedOptions<infer R> ? R : never;
54
- };
55
- type ExtractMethods<M extends MethodDefinitions> = {
56
- [K in keyof M]: M[K] extends (...args: infer P) => infer R ? (...args: P) => R : never;
57
- };
200
+ type ExtractComputed<C extends ComputedDefinitions> = { [K in keyof C]: C[K] extends ComputedGetter<infer R> ? R : C[K] extends WritableComputedOptions<infer R> ? R : never };
201
+ type ExtractMethods<M extends MethodDefinitions> = { [K in keyof M]: M[K] extends ((...args: infer P) => infer R) ? (...args: P) => R : never };
58
202
  type ComponentPublicInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> = D & ExtractComputed<C> & ExtractMethods<M>;
59
203
  interface MiniProgramAdapter {
60
- setData?: (payload: Record<string, any>) => void | Promise<void>;
204
+ setData?: (payload: Record<string, any>) => void | Promise<void>;
61
205
  }
62
- interface ModelBindingOptions<T = any> {
63
- event?: string;
64
- valueProp?: string;
65
- parser?: (payload: any) => T;
66
- formatter?: (value: T) => any;
206
+ interface ModelBindingOptions<T$1 = any> {
207
+ event?: string;
208
+ valueProp?: string;
209
+ parser?: (payload: any) => T$1;
210
+ formatter?: (value: T$1) => any;
67
211
  }
68
- interface ModelBinding<T = any> {
69
- value: T;
70
- update: (value: T) => void;
71
- model: (options?: ModelBindingOptions<T>) => Record<string, any>;
212
+ interface ModelBinding<T$1 = any> {
213
+ value: T$1;
214
+ update: (value: T$1) => void;
215
+ model: (options?: ModelBindingOptions<T$1>) => Record<string, any>;
72
216
  }
73
- interface CreateAppOptions<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> {
74
- data?: () => D;
75
- computed?: C;
76
- methods?: M;
217
+ interface AppConfig {
218
+ globalProperties: Record<string, any>;
77
219
  }
220
+ type WevuPlugin = ((app: RuntimeApp<any, any, any>, ...options: any[]) => any) | {
221
+ install: (app: RuntimeApp<any, any, any>, ...options: any[]) => any;
222
+ };
78
223
  interface RuntimeApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> {
79
- mount: (adapter?: MiniProgramAdapter) => RuntimeInstance<D, C, M>;
224
+ mount: (adapter?: MiniProgramAdapter) => RuntimeInstance<D, C, M>;
225
+ use: (plugin: WevuPlugin, ...options: any[]) => RuntimeApp<D, C, M>;
226
+ config: AppConfig;
80
227
  }
81
228
  interface RuntimeInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> {
82
- readonly state: D;
83
- readonly proxy: ComponentPublicInstance<D, C, M>;
84
- readonly methods: ExtractMethods<M>;
85
- readonly computed: Readonly<ExtractComputed<C>>;
86
- readonly adapter?: MiniProgramAdapter;
87
- bindModel: <T = any>(path: string, options?: ModelBindingOptions<T>) => ModelBinding<T>;
88
- watch: <T>(source: (() => T) | Record<string, any>, cb: (value: T, oldValue: T) => void, options?: WatchOptions) => WatchStopHandle;
89
- snapshot: () => Record<string, any>;
90
- unmount: () => void;
229
+ readonly state: D;
230
+ readonly proxy: ComponentPublicInstance<D, C, M>;
231
+ readonly methods: ExtractMethods<M>;
232
+ readonly computed: Readonly<ExtractComputed<C>>;
233
+ readonly adapter?: MiniProgramAdapter;
234
+ bindModel: <T$1 = any>(path: string, options?: ModelBindingOptions<T$1>) => ModelBinding<T$1>;
235
+ watch: <T$1>(source: (() => T$1) | Record<string, any>, cb: (value: T$1, oldValue: T$1) => void, options?: WatchOptions) => WatchStopHandle;
236
+ snapshot: () => Record<string, any>;
237
+ unmount: () => void;
238
+ }
239
+ type PropMethod<T$1, TConstructor = any> = [T$1] extends [((...args: any) => any) | undefined] ? {
240
+ new (): TConstructor;
241
+ (): T$1;
242
+ readonly prototype: TConstructor;
243
+ } : never;
244
+ type PropConstructor<T$1 = any> = {
245
+ new (...args: any[]): T$1 & object;
246
+ } | {
247
+ (): T$1;
248
+ } | PropMethod<T$1>;
249
+ type PropType<T$1> = PropConstructor<T$1> | PropConstructor<T$1>[];
250
+ type ComponentPropsOptions = Record<string, PropOptions<any> | PropType<any> | null>;
251
+ interface PropOptions<T$1 = any> {
252
+ type?: PropType<T$1> | true | null;
253
+ /**
254
+ * Default value (mirrors Vue `default`; will be assigned to mini-program property `value`)
255
+ */
256
+ default?: T$1 | (() => T$1);
257
+ /**
258
+ * Alias for mini-program `value`
259
+ */
260
+ value?: T$1 | (() => T$1);
261
+ required?: boolean;
91
262
  }
263
+ type HasDefault<T$1> = T$1 extends {
264
+ default: infer D;
265
+ } ? D extends (() => undefined) | undefined ? false : true : T$1 extends {
266
+ value: infer V;
267
+ } ? V extends (() => undefined) | undefined ? false : true : false;
268
+ type IsBooleanProp<T$1> = T$1 extends {
269
+ type?: infer U;
270
+ } ? IsBooleanProp<U> : T$1 extends readonly any[] ? true extends IsBooleanProp<T$1[number]> ? true : false : T$1 extends BooleanConstructor ? true : false;
271
+ type RequiredKeys<T$1> = { [K in keyof T$1]: T$1[K] extends {
272
+ required: true;
273
+ } ? K : HasDefault<T$1[K]> extends true ? K : IsBooleanProp<T$1[K]> extends true ? K : never }[keyof T$1];
274
+ type OptionalKeys<T$1> = Exclude<keyof T$1, RequiredKeys<T$1>>;
275
+ type InferPropType<O> = O extends null ? any : O extends {
276
+ type?: infer T;
277
+ } ? InferPropConstructor<T> : O extends PropType<infer V> ? V : InferPropConstructor<O>;
278
+ type InferPropConstructor<T$1> = T$1 extends readonly any[] ? InferPropConstructor<T$1[number]> : T$1 extends undefined ? any : T$1 extends null ? any : T$1 extends BooleanConstructor ? boolean : T$1 extends NumberConstructor ? number : T$1 extends StringConstructor ? string : T$1 extends DateConstructor ? Date : T$1 extends ArrayConstructor ? any[] : T$1 extends ObjectConstructor ? Record<string, any> : T$1 extends PropConstructor<infer V> ? V : any;
279
+ type InferProps<P$1 extends ComponentPropsOptions = ComponentPropsOptions> = { [K in keyof Pick<P$1, RequiredKeys<P$1>>]: HasDefault<P$1[K]> extends true ? Exclude<InferPropType<P$1[K]>, undefined> : InferPropType<P$1[K]> } & { [K in keyof Pick<P$1, OptionalKeys<P$1>>]?: InferPropType<P$1[K]> };
280
+ type SetupFunction<P$1 extends ComponentPropsOptions, D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> = (props: InferProps<P$1>, ctx: SetupContext<D, C, M, P$1>) => Record<string, any> | void;
281
+ interface SetupContext<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions, P$1 extends ComponentPropsOptions = ComponentPropsOptions> {
282
+ /**
283
+ * Component props (from mini-program properties)
284
+ */
285
+ props: InferProps<P$1>;
286
+ /**
287
+ * Runtime instance
288
+ */
289
+ runtime: RuntimeInstance<D, C, M>;
290
+ /**
291
+ * Reactive state
292
+ */
293
+ state: D;
294
+ /**
295
+ * Public instance proxy
296
+ */
297
+ proxy: ComponentPublicInstance<D, C, M>;
298
+ /**
299
+ * Model binding helper
300
+ */
301
+ bindModel: RuntimeInstance<D, C, M>['bindModel'];
302
+ /**
303
+ * Watch helper
304
+ */
305
+ watch: RuntimeInstance<D, C, M>['watch'];
306
+ /**
307
+ * Internal mini-program instance
308
+ */
309
+ instance: InternalRuntimeState;
310
+ /**
311
+ * Vue 3 compatible: emit events
312
+ */
313
+ emit: (event: string, ...args: any[]) => void;
314
+ /**
315
+ * Vue 3 compatible: expose public properties
316
+ */
317
+ expose?: (exposed: Record<string, any>) => void;
318
+ /**
319
+ * Vue 3 compatible: attrs (fallback to empty object for mini-programs)
320
+ */
321
+ attrs?: Record<string, any>;
322
+ }
323
+ interface InternalRuntimeState {
324
+ __wevu?: RuntimeInstance<any, any, any>;
325
+ __wevuWatchStops?: WatchStopHandle[];
326
+ $wevu?: RuntimeInstance<any, any, any>;
327
+ __wevuHooks?: Record<string, any>;
328
+ __wevuExposed?: Record<string, any>;
329
+ }
330
+ interface DefineComponentOptions<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends Omit<CreateAppOptions<D, C, M>, 'setup'> {
331
+ /**
332
+ * Vue-like props definition (will be normalized to mini-program `properties`)
333
+ */
334
+ props?: P$1;
335
+ watch?: Record<string, any>;
336
+ setup?: SetupFunction<P$1, D, C, M>;
337
+ [key: string]: any;
338
+ }
339
+ interface DefineAppOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> {
340
+ watch?: Record<string, any>;
341
+ setup?: (ctx: SetupContext<D, C, M>) => Record<string, any> | void;
342
+ [key: string]: any;
343
+ }
344
+ interface CreateAppOptions<D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> {
345
+ data?: () => D;
346
+ computed?: C;
347
+ methods?: M;
348
+ watch?: Record<string, any>;
349
+ setup?: (ctx: SetupContext<D, C, M>) => Record<string, any> | void;
350
+ [key: string]: any;
351
+ }
352
+ interface PageFeatures {
353
+ listenPageScroll?: boolean;
354
+ enableShareAppMessage?: boolean;
355
+ enableShareTimeline?: boolean;
356
+ enableAddToFavorites?: boolean;
357
+ }
358
+ //#endregion
359
+ //#region src/runtime/app.d.ts
92
360
  declare function createApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: CreateAppOptions<D, C, M>): RuntimeApp<D, C, M>;
93
-
94
- declare function nextTick<T>(fn?: () => T): Promise<T>;
95
-
96
- export { computed, createApp, effect, isReactive, isRef, nextTick, reactive, ref, stop, toRaw, traverse, unref, watch };
97
- export type { ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, EffectOptions, EffectScheduler, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, ReactiveEffect, Ref, RuntimeApp, RuntimeInstance, WatchOptions, WatchStopHandle, WritableComputedOptions, WritableComputedRef };
361
+ //#endregion
362
+ //#region src/runtime/define.d.ts
363
+ /**
364
+ * defineComponent 返回的组件定义描述,用于手动注册或高级用法。
365
+ */
366
+ interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions> {
367
+ /**
368
+ * 内部 runtime app(高级能力使用),不对外暴露正式 API。
369
+ * @internal
370
+ */
371
+ __wevu_runtime: RuntimeApp<D, C, M>;
372
+ /**
373
+ * 内部选项快照(高级能力使用),包含 data/computed/methods 等。
374
+ * @internal
375
+ */
376
+ __wevu_options: {
377
+ data: () => D;
378
+ computed: C;
379
+ methods: M;
380
+ watch: Record<string, any> | undefined;
381
+ setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'];
382
+ mpOptions: Record<string, any>;
383
+ };
384
+ }
385
+ /**
386
+ * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
387
+ *
388
+ * @param options 组件定义项
389
+ * @returns 可手动注册的组件定义
390
+ *
391
+ * @example
392
+ * ```ts
393
+ * defineComponent({
394
+ * data: () => ({ count: 0 }),
395
+ * setup() {
396
+ * onMounted(() => console.log('mounted'))
397
+ * }
398
+ * })
399
+ * ```
400
+ */
401
+ declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
402
+ /**
403
+ * 按 Vue 3 风格定义一个小程序页面
404
+ *
405
+ * @param options 页面定义
406
+ * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
407
+ * @returns 页面定义
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * definePage({
412
+ * data: () => ({ count: 0 }),
413
+ * setup() {
414
+ * const count = ref(0)
415
+ * onMounted(() => console.log('page mounted'))
416
+ * return { count }
417
+ * }
418
+ * }, {
419
+ * listenPageScroll: true,
420
+ * enableShareAppMessage: true
421
+ * })
422
+ * ```
423
+ */
424
+ declare function definePage<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: Omit<DefineComponentOptions<P$1, D, C, M>, 'type'>, features?: PageFeatures): ComponentDefinition<D, C, M>;
425
+ /**
426
+ * 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
427
+ *
428
+ * @param options 组件选项,可能包含小程序特有的 properties
429
+ */
430
+ declare function createWevuComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(options: DefineComponentOptions<ComponentPropsOptions, D, C, M> & {
431
+ properties?: Record<string, any>;
432
+ }): void;
433
+ //#endregion
434
+ //#region src/runtime/hooks.d.ts
435
+ declare function getCurrentInstance(): any;
436
+ declare function setCurrentInstance(inst: InternalRuntimeState | undefined): void;
437
+ declare function callHookList(target: InternalRuntimeState, name: string, args?: any[]): void;
438
+ declare function callHookReturn(target: InternalRuntimeState, name: string, args?: any[]): any;
439
+ declare function onAppShow(handler: () => void): void;
440
+ declare function onAppHide(handler: () => void): void;
441
+ declare function onAppError(handler: (err?: any) => void): void;
442
+ declare function onShow(handler: () => void): void;
443
+ declare function onHide(handler: () => void): void;
444
+ declare function onUnload(handler: () => void): void;
445
+ declare function onReady(handler: () => void): void;
446
+ declare function onPageScroll(handler: (opt: any) => void): void;
447
+ declare function onRouteDone(handler: (opt?: any) => void): void;
448
+ declare function onTabItemTap(handler: (opt: any) => void): void;
449
+ declare function onSaveExitState(handler: () => any): void;
450
+ declare function onShareAppMessage(handler: (...args: any[]) => any): void;
451
+ declare function onShareTimeline(handler: (...args: any[]) => any): void;
452
+ declare function onAddToFavorites(handler: (...args: any[]) => any): void;
453
+ /**
454
+ * Vue 3 对齐:组件/页面已挂载,映射小程序 onReady
455
+ */
456
+ declare function onMounted(handler: () => void): void;
457
+ /**
458
+ * Vue 3 对齐:组件/页面更新后触发。
459
+ * 小程序没有专用 update 生命周期,这里在每次 setData 完成后调用。
460
+ */
461
+ declare function onUpdated(handler: () => void): void;
462
+ /**
463
+ * Vue 3 对齐:卸载前触发。
464
+ * 小程序无 before-unload 生命周期,setup 时同步执行以保持语义。
465
+ */
466
+ declare function onBeforeUnmount(handler: () => void): void;
467
+ /**
468
+ * Vue 3 对齐:组件/页面卸载;映射到页面 onUnload 或组件 detached
469
+ */
470
+ declare function onUnmounted(handler: () => void): void;
471
+ /**
472
+ * Vue 3 对齐:挂载前;setup 时同步触发以模拟 beforeMount 语义
473
+ */
474
+ declare function onBeforeMount(handler: () => void): void;
475
+ /**
476
+ * Vue 3 对齐:更新前;在每次 setData 前触发
477
+ */
478
+ declare function onBeforeUpdate(handler: () => void): void;
479
+ /**
480
+ * Vue 3 对齐:错误捕获;映射到小程序 onError
481
+ */
482
+ declare function onErrorCaptured(handler: (err: any, instance: any, info: string) => void): void;
483
+ /**
484
+ * Vue 3 对齐:组件激活;映射到小程序 onShow
485
+ */
486
+ declare function onActivated(handler: () => void): void;
487
+ /**
488
+ * Vue 3 对齐:组件失活;映射到小程序 onHide
489
+ */
490
+ declare function onDeactivated(handler: () => void): void;
491
+ /**
492
+ * Vue 3 对齐:服务端渲染前置钩子。
493
+ * 小程序无此场景,保留空实现以保持 API 兼容。
494
+ */
495
+ declare function onServerPrefetch(_handler: () => void): void;
496
+ declare function callUpdateHooks(target: InternalRuntimeState, phase: 'before' | 'after'): void;
497
+ //#endregion
498
+ //#region src/runtime/provide.d.ts
499
+ /**
500
+ * 在组件上下文中向后代注入值(与 Vue 3 行为兼容),若没有当前实例则回落到全局存储。
501
+ *
502
+ * @param key 注入键,可为字符串、Symbol 或对象
503
+ * @param value 提供的值
504
+ *
505
+ * @example
506
+ * ```ts
507
+ * defineComponent({
508
+ * setup() {
509
+ * provide(TOKEN_KEY, { data: 'value' })
510
+ * }
511
+ * })
512
+ * ```
513
+ */
514
+ declare function provide<T$1>(key: any, value: T$1): void;
515
+ /**
516
+ * 从祖先组件(或全局存储)读取提供的值。
517
+ *
518
+ * @param key 注入键,需与 provide 使用的键保持一致
519
+ * @param defaultValue 未找到提供者时的默认值
520
+ * @returns 匹配到的值或默认值
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * defineComponent({
525
+ * setup() {
526
+ * const data = inject(TOKEN_KEY)
527
+ * const value = inject('key', 'default')
528
+ * }
529
+ * })
530
+ * ```
531
+ */
532
+ declare function inject<T$1>(key: any, defaultValue?: T$1): T$1;
533
+ /**
534
+ * 全局注入值,适用于组件外部调用场景。
535
+ */
536
+ declare function provideGlobal<T$1>(key: any, value: T$1): void;
537
+ /**
538
+ * 从全局存储读取值,适用于组件外部调用场景。
539
+ */
540
+ declare function injectGlobal<T$1>(key: any, defaultValue?: T$1): T$1;
541
+ //#endregion
542
+ //#region src/runtime/register.d.ts
543
+ type WatchHandler = (this: any, value: any, oldValue: any) => void;
544
+ type WatchDescriptor = WatchHandler | string | {
545
+ handler: WatchHandler | string;
546
+ immediate?: boolean;
547
+ deep?: boolean;
548
+ };
549
+ type WatchMap = Record<string, WatchDescriptor>;
550
+ declare function runSetupFunction(setup: ((...args: any[]) => any) | undefined, props: Record<string, any>, context: any): any;
551
+ declare function mountRuntimeInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(target: InternalRuntimeState, runtimeApp: RuntimeApp<D, C, M>, watchMap: WatchMap | undefined, setup?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']): RuntimeInstance<D, C, M>;
552
+ declare function teardownRuntimeInstance(target: InternalRuntimeState): void;
553
+ declare function registerApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineAppOptions<D, C, M>['setup'], mpOptions: Record<string, any>): void;
554
+ declare function registerPage<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
555
+ declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>): void;
556
+ //#endregion
557
+ export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, definePage, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, registerPage, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };