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.mjs CHANGED
@@ -1,699 +1,1290 @@
1
- const resolvedPromise = Promise.resolve();
2
- const jobQueue = /* @__PURE__ */ new Set();
3
- let isFlushing = false;
4
- function flushJobs() {
5
- isFlushing = true;
6
- try {
7
- jobQueue.forEach((job) => job());
8
- } finally {
9
- jobQueue.clear();
10
- isFlushing = false;
11
- }
12
- }
13
- function queueJob(job) {
14
- jobQueue.add(job);
15
- if (!isFlushing) {
16
- resolvedPromise.then(flushJobs);
17
- }
18
- }
19
- function nextTick(fn) {
20
- return fn ? resolvedPromise.then(fn) : resolvedPromise;
1
+ import { _ as computed, a as isRef, b as nextTick, c as isObject, d as isShallowReactive, f as markRaw, g as touchReactive, h as toRaw, i as customRef, l as isRaw, m as shallowReactive, n as defineStore, o as ref, p as reactive, r as createStore, s as unref, t as storeToRefs, u as isReactive, v as effect, x as queueJob, y as stop } from "./store-BcU7YVhB.mjs";
2
+
3
+ //#region src/reactivity/readonly.ts
4
+ function readonly(target) {
5
+ if (isRef(target)) {
6
+ const source = target;
7
+ return {
8
+ get value() {
9
+ return source.value;
10
+ },
11
+ set value(_v) {
12
+ throw new Error("Cannot assign to a readonly ref");
13
+ }
14
+ };
15
+ }
16
+ if (!isObject(target)) return target;
17
+ return new Proxy(target, {
18
+ set() {
19
+ throw new Error("Cannot set property on readonly object");
20
+ },
21
+ deleteProperty() {
22
+ throw new Error("Cannot delete property on readonly object");
23
+ },
24
+ defineProperty() {
25
+ throw new Error("Cannot define property on readonly object");
26
+ },
27
+ get(target$1, key, receiver) {
28
+ return Reflect.get(target$1, key, receiver);
29
+ }
30
+ });
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/reactivity/shallowRef.ts
35
+ function shallowRef(value, defaultValue) {
36
+ return customRef((track, trigger) => ({
37
+ get() {
38
+ track();
39
+ return value;
40
+ },
41
+ set(newValue) {
42
+ if (Object.is(value, newValue)) return;
43
+ value = newValue;
44
+ trigger();
45
+ }
46
+ }), defaultValue);
47
+ }
48
+ /**
49
+ * 判断传入值是否为浅层 ref。
50
+ *
51
+ * @param r 待判断的值
52
+ * @returns 若为浅层 ref 则返回 true
53
+ */
54
+ function isShallowRef(r) {
55
+ return r && typeof r === "object" && "value" in r && typeof r.value !== "function";
56
+ }
57
+ /**
58
+ * 主动触发一次浅层 ref 的更新(无需深度比较)。
59
+ *
60
+ * @param ref 需要触发的 ref
61
+ */
62
+ function triggerRef(ref$1) {
63
+ if (ref$1 && typeof ref$1 === "object" && "value" in ref$1) ref$1.value = ref$1.value;
21
64
  }
22
65
 
23
- const targetMap = /* @__PURE__ */ new WeakMap();
24
- let activeEffect = null;
25
- const effectStack = [];
26
- function cleanupEffect(effect2) {
27
- const { deps } = effect2;
28
- for (let i = 0; i < deps.length; i++) {
29
- deps[i].delete(effect2);
30
- }
31
- deps.length = 0;
32
- }
33
- function createReactiveEffect(fn, options = {}) {
34
- const effect2 = function reactiveEffect() {
35
- if (!effect2.active) {
36
- return fn();
37
- }
38
- if (effectStack.includes(effect2)) {
39
- return fn();
40
- }
41
- cleanupEffect(effect2);
42
- try {
43
- effectStack.push(effect2);
44
- activeEffect = effect2;
45
- return fn();
46
- } finally {
47
- effectStack.pop();
48
- activeEffect = effectStack[effectStack.length - 1] ?? null;
49
- }
50
- };
51
- effect2.deps = [];
52
- effect2.scheduler = options.scheduler;
53
- effect2.onStop = options.onStop;
54
- effect2.active = true;
55
- effect2._fn = fn;
56
- return effect2;
57
- }
58
- function effect(fn, options = {}) {
59
- const _effect = createReactiveEffect(fn, options);
60
- if (!options.lazy) {
61
- _effect();
62
- }
63
- return _effect;
64
- }
65
- function stop(runner) {
66
- if (!runner.active) {
67
- return;
68
- }
69
- runner.active = false;
70
- cleanupEffect(runner);
71
- runner.onStop?.();
72
- }
73
- function track(target, key) {
74
- if (!activeEffect) {
75
- return;
76
- }
77
- let depsMap = targetMap.get(target);
78
- if (!depsMap) {
79
- depsMap = /* @__PURE__ */ new Map();
80
- targetMap.set(target, depsMap);
81
- }
82
- let dep = depsMap.get(key);
83
- if (!dep) {
84
- dep = /* @__PURE__ */ new Set();
85
- depsMap.set(key, dep);
86
- }
87
- if (!dep.has(activeEffect)) {
88
- dep.add(activeEffect);
89
- activeEffect.deps.push(dep);
90
- }
91
- }
92
- function trigger(target, key) {
93
- const depsMap = targetMap.get(target);
94
- if (!depsMap) {
95
- return;
96
- }
97
- const effects = depsMap.get(key);
98
- if (!effects) {
99
- return;
100
- }
101
- const effectsToRun = /* @__PURE__ */ new Set();
102
- effects.forEach((effect2) => {
103
- if (effect2 !== activeEffect) {
104
- effectsToRun.add(effect2);
105
- }
106
- });
107
- effectsToRun.forEach((effect2) => {
108
- if (effect2.scheduler) {
109
- effect2.scheduler();
110
- } else {
111
- effect2();
112
- }
113
- });
114
- }
115
- const reactiveMap = /* @__PURE__ */ new WeakMap();
116
- const rawMap = /* @__PURE__ */ new WeakMap();
117
- function isObject(value) {
118
- return typeof value === "object" && value !== null;
119
- }
120
- const mutableHandlers = {
121
- get(target, key, receiver) {
122
- if (key === "__r_isReactive" /* IS_REACTIVE */) {
123
- return true;
124
- }
125
- if (key === "__r_raw" /* RAW */) {
126
- return target;
127
- }
128
- const res = Reflect.get(target, key, receiver);
129
- track(target, key);
130
- if (isObject(res)) {
131
- return reactive(res);
132
- }
133
- return res;
134
- },
135
- set(target, key, value, receiver) {
136
- const oldValue = Reflect.get(target, key, receiver);
137
- const result = Reflect.set(target, key, value, receiver);
138
- if (!Object.is(oldValue, value)) {
139
- trigger(target, key);
140
- }
141
- return result;
142
- },
143
- deleteProperty(target, key) {
144
- const hadKey = Object.prototype.hasOwnProperty.call(target, key);
145
- const result = Reflect.deleteProperty(target, key);
146
- if (hadKey && result) {
147
- trigger(target, key);
148
- }
149
- return result;
150
- },
151
- ownKeys(target) {
152
- track(target, Symbol.iterator);
153
- return Reflect.ownKeys(target);
154
- }
155
- };
156
- function reactive(target) {
157
- if (!isObject(target)) {
158
- return target;
159
- }
160
- const existingProxy = reactiveMap.get(target);
161
- if (existingProxy) {
162
- return existingProxy;
163
- }
164
- if (target["__r_isReactive" /* IS_REACTIVE */]) {
165
- return target;
166
- }
167
- const proxy = new Proxy(target, mutableHandlers);
168
- reactiveMap.set(target, proxy);
169
- rawMap.set(proxy, target);
170
- return proxy;
171
- }
172
- function isReactive(value) {
173
- return Boolean(value && value["__r_isReactive" /* IS_REACTIVE */]);
174
- }
175
- function toRaw(observed) {
176
- return observed?.["__r_raw" /* RAW */] ?? observed;
177
- }
178
- function convertToReactive(value) {
179
- return isObject(value) ? reactive(value) : value;
180
- }
181
- function isRef(value) {
182
- return Boolean(value && typeof value === "object" && "value" in value);
183
- }
184
- function trackEffects(dep) {
185
- if (!activeEffect) {
186
- return;
187
- }
188
- if (!dep.has(activeEffect)) {
189
- dep.add(activeEffect);
190
- activeEffect.deps.push(dep);
191
- }
192
- }
193
- function triggerEffects(dep) {
194
- dep.forEach((effect2) => {
195
- if (effect2.scheduler) {
196
- effect2.scheduler();
197
- } else {
198
- effect2();
199
- }
200
- });
201
- }
202
- function trackRefValue(refImpl) {
203
- if (activeEffect) {
204
- refImpl.dep = refImpl.dep || /* @__PURE__ */ new Set();
205
- trackEffects(refImpl.dep);
206
- }
207
- }
208
- class RefImpl {
209
- _value;
210
- _rawValue;
211
- dep;
212
- constructor(value) {
213
- this._rawValue = value;
214
- this._value = convertToReactive(value);
215
- }
216
- get value() {
217
- trackRefValue(this);
218
- return this._value;
219
- }
220
- set value(newValue) {
221
- if (!Object.is(newValue, this._rawValue)) {
222
- this._rawValue = newValue;
223
- this._value = convertToReactive(newValue);
224
- this.dep && triggerEffects(this.dep);
225
- }
226
- }
227
- }
228
- function ref(value) {
229
- if (isRef(value)) {
230
- return value;
231
- }
232
- return new RefImpl(value);
233
- }
234
- function unref(value) {
235
- return isRef(value) ? value.value : value;
236
- }
237
- function computed(getterOrOptions) {
238
- let getter;
239
- let setter;
240
- const onlyGetter = typeof getterOrOptions === "function";
241
- if (onlyGetter) {
242
- getter = getterOrOptions;
243
- setter = () => {
244
- throw new Error("Computed value is readonly");
245
- };
246
- } else {
247
- getter = getterOrOptions.get;
248
- setter = getterOrOptions.set;
249
- }
250
- let value;
251
- let dirty = true;
252
- let runner;
253
- const obj = {
254
- get value() {
255
- if (dirty) {
256
- value = runner();
257
- dirty = false;
258
- }
259
- track(obj, "value");
260
- return value;
261
- },
262
- set value(newValue) {
263
- setter(newValue);
264
- }
265
- };
266
- runner = effect(getter, {
267
- lazy: true,
268
- scheduler: () => {
269
- if (!dirty) {
270
- dirty = true;
271
- trigger(obj, "value");
272
- }
273
- }
274
- });
275
- return onlyGetter ? obj : obj;
66
+ //#endregion
67
+ //#region src/reactivity/toRefs.ts
68
+ /**
69
+ * 将一个响应式对象转换成“同结构的普通对象”,其中每个字段都是指向原对象对应属性的 ref。
70
+ *
71
+ * @param object 待转换的响应式对象
72
+ * @returns 包含若干 ref 的普通对象
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const state = reactive({ foo: 1, bar: 2 })
77
+ * const stateAsRefs = toRefs(state)
78
+ *
79
+ * stateAsRefs.foo.value++ // 2
80
+ * state.foo // 2
81
+ * ```
82
+ */
83
+ function toRefs(object) {
84
+ if (!isReactive(object)) console.warn(`toRefs() expects a reactive object but received a plain one.`);
85
+ const result = Array.isArray(object) ? Array.from({ length: object.length }) : {};
86
+ for (const key in object) result[key] = toRef(object, key);
87
+ return result;
88
+ }
89
+ function toRef(object, key, defaultValue) {
90
+ const value = object[key];
91
+ if (isRef(value)) return value;
92
+ return customRef((track, trigger) => ({
93
+ get() {
94
+ track();
95
+ return object[key];
96
+ },
97
+ set(newValue) {
98
+ object[key] = newValue;
99
+ trigger();
100
+ }
101
+ }), defaultValue);
276
102
  }
103
+
104
+ //#endregion
105
+ //#region src/reactivity/traverse.ts
277
106
  function traverse(value, seen = /* @__PURE__ */ new Set()) {
278
- if (!isObject(value) || seen.has(value)) {
279
- return value;
280
- }
281
- seen.add(value);
282
- for (const key in value) {
283
- traverse(value[key], seen);
284
- }
285
- return value;
107
+ if (!isObject(value) || seen.has(value)) return value;
108
+ seen.add(value);
109
+ for (const key in value) traverse(value[key], seen);
110
+ return value;
111
+ }
112
+
113
+ //#endregion
114
+ //#region src/reactivity/watch.ts
115
+ let __deepWatchStrategy = "version";
116
+ function setDeepWatchStrategy(strategy) {
117
+ __deepWatchStrategy = strategy;
118
+ }
119
+ function getDeepWatchStrategy() {
120
+ return __deepWatchStrategy;
286
121
  }
287
122
  function watch(source, cb, options = {}) {
288
- let getter;
289
- if (typeof source === "function") {
290
- getter = source;
291
- } else if (isRef(source)) {
292
- getter = () => source.value;
293
- } else if (isReactive(source)) {
294
- getter = () => source;
295
- } else {
296
- throw new Error("Invalid watch source");
297
- }
298
- if (options.deep) {
299
- const baseGetter = getter;
300
- getter = () => traverse(baseGetter());
301
- }
302
- let cleanup;
303
- const onCleanup = (fn) => {
304
- cleanup = fn;
305
- };
306
- let oldValue;
307
- let runner;
308
- const job = () => {
309
- if (!runner.active) {
310
- return;
311
- }
312
- const newValue = runner();
313
- cleanup?.();
314
- cb(newValue, oldValue, onCleanup);
315
- oldValue = newValue;
316
- };
317
- runner = effect(() => getter(), {
318
- scheduler: () => queueJob(job),
319
- lazy: true
320
- });
321
- if (options.immediate) {
322
- job();
323
- } else {
324
- oldValue = runner();
325
- }
326
- return () => {
327
- cleanup?.();
328
- stop(runner);
329
- };
123
+ let getter;
124
+ if (typeof source === "function") getter = source;
125
+ else if (isRef(source)) getter = () => source.value;
126
+ else if (isReactive(source)) getter = () => source;
127
+ else throw new Error("Invalid watch source");
128
+ if (options.deep) {
129
+ const baseGetter = getter;
130
+ getter = () => {
131
+ const val = baseGetter();
132
+ if (__deepWatchStrategy === "version" && isReactive(val)) {
133
+ touchReactive(val);
134
+ return val;
135
+ }
136
+ return traverse(val);
137
+ };
138
+ }
139
+ let cleanup;
140
+ const onCleanup = (fn) => {
141
+ cleanup = fn;
142
+ };
143
+ let oldValue;
144
+ let runner;
145
+ const job = () => {
146
+ if (!runner.active) return;
147
+ const newValue = runner();
148
+ cleanup?.();
149
+ cb(newValue, oldValue, onCleanup);
150
+ oldValue = newValue;
151
+ };
152
+ runner = effect(() => getter(), {
153
+ scheduler: () => queueJob(job),
154
+ lazy: true
155
+ });
156
+ if (options.immediate) job();
157
+ else oldValue = runner();
158
+ return () => {
159
+ cleanup?.();
160
+ stop(runner);
161
+ };
162
+ }
163
+ /**
164
+ * watchEffect 注册一个响应式副作用,可选清理函数。
165
+ * 副作用会立即执行,并在依赖变化时重新运行。
166
+ */
167
+ function watchEffect(effectFn) {
168
+ let cleanup;
169
+ const onCleanup = (fn) => {
170
+ cleanup = fn;
171
+ };
172
+ const runner = effect(() => {
173
+ cleanup?.();
174
+ cleanup = void 0;
175
+ effectFn(onCleanup);
176
+ }, { scheduler: () => queueJob(() => {
177
+ if (runner.active) runner();
178
+ }) });
179
+ runner();
180
+ return () => {
181
+ cleanup?.();
182
+ stop(runner);
183
+ };
330
184
  }
331
185
 
186
+ //#endregion
187
+ //#region src/utils.ts
332
188
  function capitalize(str) {
333
- if (!str) {
334
- return "";
335
- }
336
- return str.charAt(0).toUpperCase() + str.slice(1);
189
+ if (!str) return "";
190
+ return str.charAt(0).toUpperCase() + str.slice(1);
337
191
  }
338
192
  function toPathSegments(path) {
339
- if (!path) {
340
- return [];
341
- }
342
- return path.split(".").map((segment) => segment.trim()).filter(Boolean);
193
+ if (!path) return [];
194
+ return path.split(".").map((segment) => segment.trim()).filter(Boolean);
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/runtime/bindModel.ts
199
+ function setComputedValue$1(setters, key, value) {
200
+ const setter = setters[key];
201
+ if (!setter) throw new Error(`Computed property "${key}" is readonly`);
202
+ setter(value);
203
+ }
204
+ function setWithSegments(target, segments, value) {
205
+ let current = target;
206
+ for (let i = 0; i < segments.length - 1; i++) {
207
+ const key = segments[i];
208
+ if (current[key] == null || typeof current[key] !== "object") current[key] = {};
209
+ current = current[key];
210
+ }
211
+ current[segments[segments.length - 1]] = value;
212
+ }
213
+ function setByPath(state, computedRefs, computedSetters, segments, value) {
214
+ if (!segments.length) return;
215
+ const [head, ...rest] = segments;
216
+ if (!rest.length) {
217
+ if (computedRefs[head]) setComputedValue$1(computedSetters, head, value);
218
+ else state[head] = value;
219
+ return;
220
+ }
221
+ if (computedRefs[head]) {
222
+ setComputedValue$1(computedSetters, head, value);
223
+ return;
224
+ }
225
+ if (state[head] == null || typeof state[head] !== "object") state[head] = {};
226
+ setWithSegments(state[head], rest, value);
227
+ }
228
+ function getFromPath(target, segments) {
229
+ return segments.reduce((acc, segment) => {
230
+ if (acc == null) return acc;
231
+ return acc[segment];
232
+ }, target);
233
+ }
234
+ function defaultParser(event) {
235
+ if (event == null) return event;
236
+ if (typeof event === "object") {
237
+ if ("detail" in event && event.detail && "value" in event.detail) return event.detail.value;
238
+ if ("target" in event && event.target && "value" in event.target) return event.target.value;
239
+ }
240
+ return event;
241
+ }
242
+ function createBindModel(publicInstance, state, computedRefs, computedSetters) {
243
+ const bindModel = (path, bindingOptions) => {
244
+ const segments = toPathSegments(path);
245
+ if (!segments.length) throw new Error("bindModel requires a non-empty path");
246
+ const resolveValue = () => getFromPath(publicInstance, segments);
247
+ const assignValue = (value) => {
248
+ setByPath(state, computedRefs, computedSetters, segments, value);
249
+ };
250
+ const defaultOptions = {
251
+ event: "input",
252
+ valueProp: "value",
253
+ parser: defaultParser,
254
+ formatter: (value) => value,
255
+ ...bindingOptions
256
+ };
257
+ return {
258
+ get value() {
259
+ return resolveValue();
260
+ },
261
+ set value(nextValue) {
262
+ assignValue(nextValue);
263
+ },
264
+ update(nextValue) {
265
+ assignValue(nextValue);
266
+ },
267
+ model(modelOptions) {
268
+ const merged = {
269
+ ...defaultOptions,
270
+ ...modelOptions
271
+ };
272
+ const handlerKey = `on${capitalize(merged.event)}`;
273
+ const payload = { [merged.valueProp]: merged.formatter(resolveValue()) };
274
+ payload[handlerKey] = (event) => {
275
+ assignValue(merged.parser(event));
276
+ };
277
+ return payload;
278
+ }
279
+ };
280
+ };
281
+ return bindModel;
343
282
  }
344
283
 
284
+ //#endregion
285
+ //#region src/runtime/diff.ts
345
286
  function isPlainObject(value) {
346
- if (Object.prototype.toString.call(value) !== "[object Object]") {
347
- return false;
348
- }
349
- const proto = Object.getPrototypeOf(value);
350
- return proto === null || proto === Object.prototype;
287
+ if (Object.prototype.toString.call(value) !== "[object Object]") return false;
288
+ const proto = Object.getPrototypeOf(value);
289
+ return proto === null || proto === Object.prototype;
351
290
  }
352
291
  function toPlain(value, seen = /* @__PURE__ */ new WeakMap()) {
353
- const unwrapped = unref(value);
354
- if (typeof unwrapped !== "object" || unwrapped === null) {
355
- return unwrapped;
356
- }
357
- const raw = isReactive(unwrapped) ? toRaw(unwrapped) : unwrapped;
358
- if (seen.has(raw)) {
359
- return seen.get(raw);
360
- }
361
- if (Array.isArray(raw)) {
362
- const arr = [];
363
- seen.set(raw, arr);
364
- raw.forEach((item, index) => {
365
- arr[index] = toPlain(item, seen);
366
- });
367
- return arr;
368
- }
369
- const output = {};
370
- seen.set(raw, output);
371
- Object.keys(raw).forEach((key) => {
372
- output[key] = toPlain(raw[key], seen);
373
- });
374
- return output;
292
+ const unwrapped = unref(value);
293
+ if (typeof unwrapped !== "object" || unwrapped === null) return unwrapped;
294
+ const raw = isReactive(unwrapped) ? toRaw(unwrapped) : unwrapped;
295
+ if (seen.has(raw)) return seen.get(raw);
296
+ if (Array.isArray(raw)) {
297
+ const arr = [];
298
+ seen.set(raw, arr);
299
+ raw.forEach((item, index) => {
300
+ arr[index] = toPlain(item, seen);
301
+ });
302
+ return arr;
303
+ }
304
+ const output = {};
305
+ seen.set(raw, output);
306
+ Object.keys(raw).forEach((key) => {
307
+ output[key] = toPlain(raw[key], seen);
308
+ });
309
+ return output;
375
310
  }
376
- function getFromPath(target, segments) {
377
- return segments.reduce((acc, segment) => {
378
- if (acc == null) {
379
- return acc;
380
- }
381
- return acc[segment];
382
- }, target);
311
+ function isDeepEqual(a, b) {
312
+ if (Object.is(a, b)) return true;
313
+ if (Array.isArray(a) && Array.isArray(b)) return isArrayEqual(a, b);
314
+ if (isPlainObject(a) && isPlainObject(b)) return isPlainObjectEqual(a, b);
315
+ return false;
383
316
  }
384
- function setWithSegments(target, segments, value) {
385
- let current = target;
386
- for (let i = 0; i < segments.length - 1; i++) {
387
- const key = segments[i];
388
- if (current[key] == null || typeof current[key] !== "object") {
389
- current[key] = {};
390
- }
391
- current = current[key];
392
- }
393
- current[segments[segments.length - 1]] = value;
317
+ function isArrayEqual(a, b) {
318
+ if (a.length !== b.length) return false;
319
+ for (let i = 0; i < a.length; i++) if (!isDeepEqual(a[i], b[i])) return false;
320
+ return true;
394
321
  }
395
- function setComputedValue(setters, key, value) {
396
- const setter = setters[key];
397
- if (!setter) {
398
- throw new Error(`Computed property "${key}" is readonly`);
399
- }
400
- setter(value);
322
+ function isPlainObjectEqual(a, b) {
323
+ const aKeys = Object.keys(a);
324
+ const bKeys = Object.keys(b);
325
+ if (aKeys.length !== bKeys.length) return false;
326
+ for (const key of aKeys) {
327
+ if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
328
+ if (!isDeepEqual(a[key], b[key])) return false;
329
+ }
330
+ return true;
401
331
  }
402
- function setByPath(state, computedRefs, computedSetters, segments, value) {
403
- if (!segments.length) {
404
- return;
405
- }
406
- const [head, ...rest] = segments;
407
- if (!rest.length) {
408
- if (computedRefs[head]) {
409
- setComputedValue(computedSetters, head, value);
410
- } else {
411
- state[head] = value;
412
- }
413
- return;
414
- }
415
- if (computedRefs[head]) {
416
- setComputedValue(computedSetters, head, value);
417
- return;
418
- }
419
- if (state[head] == null || typeof state[head] !== "object") {
420
- state[head] = {};
421
- }
422
- setWithSegments(state[head], rest, value);
332
+ function normalizeSetDataValue(value) {
333
+ return value === void 0 ? null : value;
423
334
  }
424
- function defaultParser(event) {
425
- if (event == null) {
426
- return event;
427
- }
428
- if (typeof event === "object") {
429
- if ("detail" in event && event.detail && "value" in event.detail) {
430
- return event.detail.value;
431
- }
432
- if ("target" in event && event.target && "value" in event.target) {
433
- return event.target.value;
434
- }
435
- }
436
- return event;
335
+ function assignNestedDiff(prev, next, path, output) {
336
+ if (isDeepEqual(prev, next)) return;
337
+ if (isPlainObject(prev) && isPlainObject(next)) {
338
+ new Set([...Object.keys(prev), ...Object.keys(next)]).forEach((key) => {
339
+ if (!Object.prototype.hasOwnProperty.call(next, key)) {
340
+ output[`${path}.${key}`] = null;
341
+ return;
342
+ }
343
+ assignNestedDiff(prev[key], next[key], `${path}.${key}`, output);
344
+ });
345
+ return;
346
+ }
347
+ if (Array.isArray(prev) && Array.isArray(next)) {
348
+ if (!isArrayEqual(prev, next)) output[path] = normalizeSetDataValue(next);
349
+ return;
350
+ }
351
+ output[path] = normalizeSetDataValue(next);
352
+ }
353
+ function diffSnapshots(prev, next) {
354
+ const diff = {};
355
+ new Set([...Object.keys(prev), ...Object.keys(next)]).forEach((key) => {
356
+ if (!Object.prototype.hasOwnProperty.call(next, key)) {
357
+ diff[key] = null;
358
+ return;
359
+ }
360
+ assignNestedDiff(prev[key], next[key], key, diff);
361
+ });
362
+ return diff;
363
+ }
364
+
365
+ //#endregion
366
+ //#region src/runtime/hooks.ts
367
+ let __currentInstance;
368
+ function getCurrentInstance() {
369
+ return __currentInstance;
370
+ }
371
+ function setCurrentInstance(inst) {
372
+ __currentInstance = inst;
373
+ }
374
+ function ensureHookBucket(target) {
375
+ if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
376
+ return target.__wevuHooks;
377
+ }
378
+ function pushHook(target, name, handler, { single = false } = {}) {
379
+ const bucket = ensureHookBucket(target);
380
+ if (single) bucket[name] = handler;
381
+ else (bucket[name] ?? (bucket[name] = [])).push(handler);
382
+ }
383
+ function callHookList(target, name, args = []) {
384
+ const hooks = target.__wevuHooks;
385
+ if (!hooks) return;
386
+ const list = hooks[name];
387
+ if (!list) return;
388
+ const ctx = target.__wevu?.proxy ?? target;
389
+ if (Array.isArray(list)) for (const fn of list) try {
390
+ fn.apply(ctx, args);
391
+ } catch {}
392
+ else if (typeof list === "function") try {
393
+ list.apply(ctx, args);
394
+ } catch {}
395
+ }
396
+ function callHookReturn(target, name, args = []) {
397
+ const hooks = target.__wevuHooks;
398
+ if (!hooks) return;
399
+ const entry = hooks[name];
400
+ if (!entry) return;
401
+ const ctx = target.__wevu?.proxy ?? target;
402
+ if (typeof entry === "function") try {
403
+ return entry.apply(ctx, args);
404
+ } catch {
405
+ return;
406
+ }
407
+ if (Array.isArray(entry)) {
408
+ let out;
409
+ for (const fn of entry) try {
410
+ out = fn.apply(ctx, args);
411
+ } catch {}
412
+ return out;
413
+ }
414
+ }
415
+ function onAppShow(handler) {
416
+ if (!__currentInstance) throw new Error("onAppShow() must be called synchronously inside setup()");
417
+ pushHook(__currentInstance, "onAppShow", handler);
418
+ }
419
+ function onAppHide(handler) {
420
+ if (!__currentInstance) throw new Error("onAppHide() must be called synchronously inside setup()");
421
+ pushHook(__currentInstance, "onAppHide", handler);
422
+ }
423
+ function onAppError(handler) {
424
+ if (!__currentInstance) throw new Error("onAppError() must be called synchronously inside setup()");
425
+ pushHook(__currentInstance, "onAppError", handler);
426
+ }
427
+ function onShow(handler) {
428
+ if (!__currentInstance) throw new Error("onShow() must be called synchronously inside setup()");
429
+ pushHook(__currentInstance, "onShow", handler);
430
+ }
431
+ function onHide(handler) {
432
+ if (!__currentInstance) throw new Error("onHide() must be called synchronously inside setup()");
433
+ pushHook(__currentInstance, "onHide", handler);
434
+ }
435
+ function onUnload(handler) {
436
+ if (!__currentInstance) throw new Error("onUnload() must be called synchronously inside setup()");
437
+ pushHook(__currentInstance, "onUnload", handler);
438
+ }
439
+ function onReady(handler) {
440
+ if (!__currentInstance) throw new Error("onReady() must be called synchronously inside setup()");
441
+ pushHook(__currentInstance, "onReady", handler);
437
442
  }
443
+ function onPageScroll(handler) {
444
+ if (!__currentInstance) throw new Error("onPageScroll() must be called synchronously inside setup()");
445
+ pushHook(__currentInstance, "onPageScroll", handler);
446
+ }
447
+ function onRouteDone(handler) {
448
+ if (!__currentInstance) throw new Error("onRouteDone() must be called synchronously inside setup()");
449
+ pushHook(__currentInstance, "onRouteDone", handler);
450
+ }
451
+ function onTabItemTap(handler) {
452
+ if (!__currentInstance) throw new Error("onTabItemTap() must be called synchronously inside setup()");
453
+ pushHook(__currentInstance, "onTabItemTap", handler);
454
+ }
455
+ function onSaveExitState(handler) {
456
+ if (!__currentInstance) throw new Error("onSaveExitState() must be called synchronously inside setup()");
457
+ pushHook(__currentInstance, "onSaveExitState", handler, { single: true });
458
+ }
459
+ function onShareAppMessage(handler) {
460
+ if (!__currentInstance) throw new Error("onShareAppMessage() must be called synchronously inside setup()");
461
+ pushHook(__currentInstance, "onShareAppMessage", handler, { single: true });
462
+ }
463
+ function onShareTimeline(handler) {
464
+ if (!__currentInstance) throw new Error("onShareTimeline() must be called synchronously inside setup()");
465
+ pushHook(__currentInstance, "onShareTimeline", handler, { single: true });
466
+ }
467
+ function onAddToFavorites(handler) {
468
+ if (!__currentInstance) throw new Error("onAddToFavorites() must be called synchronously inside setup()");
469
+ pushHook(__currentInstance, "onAddToFavorites", handler, { single: true });
470
+ }
471
+ /**
472
+ * Vue 3 对齐:组件/页面已挂载,映射小程序 onReady
473
+ */
474
+ function onMounted(handler) {
475
+ if (!__currentInstance) throw new Error("onMounted() must be called synchronously inside setup()");
476
+ pushHook(__currentInstance, "onReady", handler);
477
+ }
478
+ /**
479
+ * Vue 3 对齐:组件/页面更新后触发。
480
+ * 小程序没有专用 update 生命周期,这里在每次 setData 完成后调用。
481
+ */
482
+ function onUpdated(handler) {
483
+ if (!__currentInstance) throw new Error("onUpdated() must be called synchronously inside setup()");
484
+ pushHook(__currentInstance, "__wevuOnUpdated", handler);
485
+ }
486
+ /**
487
+ * Vue 3 对齐:卸载前触发。
488
+ * 小程序无 before-unload 生命周期,setup 时同步执行以保持语义。
489
+ */
490
+ function onBeforeUnmount(handler) {
491
+ if (!__currentInstance) throw new Error("onBeforeUnmount() must be called synchronously inside setup()");
492
+ handler();
493
+ }
494
+ /**
495
+ * Vue 3 对齐:组件/页面卸载;映射到页面 onUnload 或组件 detached
496
+ */
497
+ function onUnmounted(handler) {
498
+ if (!__currentInstance) throw new Error("onUnmounted() must be called synchronously inside setup()");
499
+ pushHook(__currentInstance, "onUnload", handler);
500
+ }
501
+ /**
502
+ * Vue 3 对齐:挂载前;setup 时同步触发以模拟 beforeMount 语义
503
+ */
504
+ function onBeforeMount(handler) {
505
+ if (!__currentInstance) throw new Error("onBeforeMount() must be called synchronously inside setup()");
506
+ handler();
507
+ }
508
+ /**
509
+ * Vue 3 对齐:更新前;在每次 setData 前触发
510
+ */
511
+ function onBeforeUpdate(handler) {
512
+ if (!__currentInstance) throw new Error("onBeforeUpdate() must be called synchronously inside setup()");
513
+ pushHook(__currentInstance, "__wevuOnBeforeUpdate", handler);
514
+ }
515
+ /**
516
+ * Vue 3 对齐:错误捕获;映射到小程序 onError
517
+ */
518
+ function onErrorCaptured(handler) {
519
+ if (!__currentInstance) throw new Error("onErrorCaptured() must be called synchronously inside setup()");
520
+ pushHook(__currentInstance, "onAppError", (err) => handler(err, __currentInstance, ""));
521
+ }
522
+ /**
523
+ * Vue 3 对齐:组件激活;映射到小程序 onShow
524
+ */
525
+ function onActivated(handler) {
526
+ if (!__currentInstance) throw new Error("onActivated() must be called synchronously inside setup()");
527
+ pushHook(__currentInstance, "onShow", handler);
528
+ }
529
+ /**
530
+ * Vue 3 对齐:组件失活;映射到小程序 onHide
531
+ */
532
+ function onDeactivated(handler) {
533
+ if (!__currentInstance) throw new Error("onDeactivated() must be called synchronously inside setup()");
534
+ pushHook(__currentInstance, "onHide", handler);
535
+ }
536
+ /**
537
+ * Vue 3 对齐:服务端渲染前置钩子。
538
+ * 小程序无此场景,保留空实现以保持 API 兼容。
539
+ */
540
+ function onServerPrefetch(_handler) {
541
+ if (!__currentInstance) throw new Error("onServerPrefetch() must be called synchronously inside setup()");
542
+ }
543
+ function callUpdateHooks(target, phase) {
544
+ callHookList(target, phase === "before" ? "__wevuOnBeforeUpdate" : "__wevuOnUpdated");
545
+ }
546
+
547
+ //#endregion
548
+ //#region src/runtime/register.ts
549
+ function runSetupFunction(setup, props, context) {
550
+ if (typeof setup !== "function") return;
551
+ const runtimeContext = context?.runtime ?? {
552
+ methods: Object.create(null),
553
+ state: {},
554
+ proxy: {},
555
+ watch: () => () => {},
556
+ bindModel: () => {}
557
+ };
558
+ if (context) context.runtime = runtimeContext;
559
+ const finalContext = {
560
+ ...context ?? {},
561
+ runtime: runtimeContext
562
+ };
563
+ return setup.length >= 2 ? setup(props, finalContext) : setup(finalContext);
564
+ }
565
+ function normalizeWatchDescriptor(descriptor, runtime, instance) {
566
+ if (typeof descriptor === "function") return {
567
+ handler: descriptor.bind(runtime.proxy),
568
+ options: {}
569
+ };
570
+ if (typeof descriptor === "string") {
571
+ const method = runtime.methods?.[descriptor] ?? instance[descriptor];
572
+ if (typeof method === "function") return {
573
+ handler: method.bind(runtime.proxy),
574
+ options: {}
575
+ };
576
+ return;
577
+ }
578
+ if (!descriptor || typeof descriptor !== "object") return;
579
+ const base = normalizeWatchDescriptor(descriptor.handler, runtime, instance);
580
+ if (!base) return;
581
+ const options = { ...base.options };
582
+ if (descriptor.immediate !== void 0) options.immediate = descriptor.immediate;
583
+ if (descriptor.deep !== void 0) options.deep = descriptor.deep;
584
+ return {
585
+ handler: base.handler,
586
+ options
587
+ };
588
+ }
589
+ function createPathGetter(target, path) {
590
+ const segments = path.split(".").map((segment) => segment.trim()).filter(Boolean);
591
+ if (!segments.length) return () => target;
592
+ return () => {
593
+ let current = target;
594
+ for (const segment of segments) {
595
+ if (current == null) return current;
596
+ current = current[segment];
597
+ }
598
+ return current;
599
+ };
600
+ }
601
+ function registerWatches(runtime, watchMap, instance) {
602
+ const stops = [];
603
+ const proxy = runtime.proxy;
604
+ for (const [expression, descriptor] of Object.entries(watchMap)) {
605
+ const normalized = normalizeWatchDescriptor(descriptor, runtime, instance);
606
+ if (!normalized) continue;
607
+ const getter = createPathGetter(proxy, expression);
608
+ const stop$1 = runtime.watch(getter, normalized.handler, normalized.options);
609
+ stops.push(stop$1);
610
+ }
611
+ return stops;
612
+ }
613
+ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
614
+ const runtime = runtimeApp.mount({ setData(payload) {
615
+ if (typeof target.setData === "function") target.setData(payload);
616
+ } });
617
+ const runtimeProxy = runtime?.proxy ?? {};
618
+ const runtimeState = runtime?.state ?? {};
619
+ if (!runtime?.methods) try {
620
+ runtime.methods = Object.create(null);
621
+ } catch {}
622
+ const runtimeMethods = runtime?.methods ?? Object.create(null);
623
+ const runtimeWatch = runtime?.watch ?? (() => () => {});
624
+ const runtimeBindModel = runtime?.bindModel ?? (() => {});
625
+ const runtimeWithDefaults = {
626
+ ...runtime ?? {},
627
+ state: runtimeState,
628
+ proxy: runtimeProxy,
629
+ methods: runtimeMethods,
630
+ watch: runtimeWatch,
631
+ bindModel: runtimeBindModel
632
+ };
633
+ Object.defineProperty(target, "$wevu", {
634
+ value: runtimeWithDefaults,
635
+ configurable: true,
636
+ enumerable: false,
637
+ writable: false
638
+ });
639
+ target.__wevu = runtimeWithDefaults;
640
+ if (watchMap) {
641
+ const stops = registerWatches(runtimeWithDefaults, watchMap, target);
642
+ if (stops.length) target.__wevuWatchStops = stops;
643
+ }
644
+ if (setup) {
645
+ const props = target.properties || {};
646
+ const context = {
647
+ props,
648
+ runtime: runtimeWithDefaults,
649
+ state: runtimeState,
650
+ proxy: runtimeProxy,
651
+ bindModel: runtimeBindModel.bind(runtimeWithDefaults),
652
+ watch: runtimeWatch.bind(runtimeWithDefaults),
653
+ instance: target,
654
+ emit: (event, ...args) => {
655
+ if (typeof target.triggerEvent === "function") target.triggerEvent(event, ...args);
656
+ },
657
+ expose: (exposed) => {
658
+ target.__wevuExposed = exposed;
659
+ },
660
+ attrs: {}
661
+ };
662
+ setCurrentInstance(target);
663
+ try {
664
+ const result = runSetupFunction(setup, props, context);
665
+ if (result && typeof result === "object") Object.keys(result).forEach((key) => {
666
+ const val = result[key];
667
+ if (typeof val === "function") runtime.methods[key] = (...args) => val.apply(runtime.proxy, args);
668
+ else runtime.state[key] = val;
669
+ });
670
+ } finally {
671
+ setCurrentInstance(void 0);
672
+ }
673
+ }
674
+ try {
675
+ const methods = runtime.methods;
676
+ for (const name of Object.keys(methods)) if (typeof target[name] !== "function") target[name] = function bridged(...args) {
677
+ const bound = (this.$wevu?.methods)?.[name];
678
+ if (typeof bound === "function") return bound.apply(this.$wevu.proxy, args);
679
+ };
680
+ } catch {}
681
+ return runtime;
682
+ }
683
+ function teardownRuntimeInstance(target) {
684
+ const runtime = target.__wevu;
685
+ if (target.__wevuHooks) target.__wevuHooks = void 0;
686
+ const stops = target.__wevuWatchStops;
687
+ if (Array.isArray(stops)) for (const stop$1 of stops) try {
688
+ stop$1();
689
+ } catch {}
690
+ target.__wevuWatchStops = void 0;
691
+ if (runtime) runtime.unmount();
692
+ delete target.__wevu;
693
+ if ("$wevu" in target) delete target.$wevu;
694
+ }
695
+ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
696
+ if (typeof App !== "function") throw new TypeError("createApp requires the global App constructor to be available");
697
+ const methodNames = Object.keys(methods ?? {});
698
+ const appOptions = { ...mpOptions };
699
+ appOptions.globalData = appOptions.globalData ?? {};
700
+ const userOnLaunch = appOptions.onLaunch;
701
+ appOptions.onLaunch = function onLaunch(...args) {
702
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup);
703
+ callHookList(this, "onAppLaunch", args);
704
+ if (typeof userOnLaunch === "function") userOnLaunch.apply(this, args);
705
+ };
706
+ const userOnShow = appOptions.onShow;
707
+ appOptions.onShow = function onShow$1(...args) {
708
+ callHookList(this, "onAppShow", args);
709
+ if (typeof userOnShow === "function") userOnShow.apply(this, args);
710
+ };
711
+ const userOnHide = appOptions.onHide;
712
+ appOptions.onHide = function onHide$1(...args) {
713
+ callHookList(this, "onAppHide", args);
714
+ if (typeof userOnHide === "function") userOnHide.apply(this, args);
715
+ };
716
+ const userOnError = appOptions.onError;
717
+ appOptions.onError = function onError(...args) {
718
+ callHookList(this, "onAppError", args);
719
+ if (typeof userOnError === "function") userOnError.apply(this, args);
720
+ };
721
+ for (const methodName of methodNames) {
722
+ const userMethod = appOptions[methodName];
723
+ appOptions[methodName] = function runtimeMethod(...args) {
724
+ const runtime = this.__wevu;
725
+ let result;
726
+ const bound = runtime?.methods?.[methodName];
727
+ if (bound) result = bound.apply(runtime.proxy, args);
728
+ if (typeof userMethod === "function") return userMethod.apply(this, args);
729
+ return result;
730
+ };
731
+ }
732
+ App(appOptions);
733
+ }
734
+ function registerPage(runtimeApp, methods, watch$1, setup, mpOptions, features) {
735
+ if (typeof Page !== "function") throw new TypeError("definePage requires the global Page constructor to be available");
736
+ const methodNames = Object.keys(methods ?? {});
737
+ const pageOptions = { ...mpOptions };
738
+ const userOnLoad = mpOptions.onLoad;
739
+ pageOptions.onLoad = function onLoad(...args) {
740
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup);
741
+ callHookList(this, "onShow", args);
742
+ if (typeof userOnLoad === "function") userOnLoad.apply(this, args);
743
+ };
744
+ const userOnUnload = mpOptions.onUnload;
745
+ pageOptions.onUnload = function onUnload$1(...args) {
746
+ teardownRuntimeInstance(this);
747
+ if (typeof userOnUnload === "function") userOnUnload.apply(this, args);
748
+ };
749
+ const userOnShow = mpOptions.onShow;
750
+ pageOptions.onShow = function onShow$1(...args) {
751
+ callHookList(this, "onShow", args);
752
+ if (typeof userOnShow === "function") userOnShow.apply(this, args);
753
+ };
754
+ const userOnHide = mpOptions.onHide;
755
+ pageOptions.onHide = function onHide$1(...args) {
756
+ callHookList(this, "onHide", args);
757
+ if (typeof userOnHide === "function") userOnHide.apply(this, args);
758
+ };
759
+ const userOnReady = mpOptions.onReady;
760
+ pageOptions.onReady = function onReady$1(...args) {
761
+ callHookList(this, "onReady", args);
762
+ if (typeof userOnReady === "function") return userOnReady.apply(this, args);
763
+ };
764
+ const userOnSaveExitState = mpOptions.onSaveExitState;
765
+ pageOptions.onSaveExitState = function onSaveExitState$1(...args) {
766
+ const ret = callHookReturn(this, "onSaveExitState", args);
767
+ if (ret !== void 0) return ret;
768
+ if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
769
+ };
770
+ if (features?.listenPageScroll) {
771
+ const userOnPageScroll = mpOptions.onPageScroll;
772
+ pageOptions.onPageScroll = function onPageScroll$1(...args) {
773
+ callHookList(this, "onPageScroll", args);
774
+ if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
775
+ };
776
+ }
777
+ if (features?.enableShareAppMessage) {
778
+ const userOnShare = mpOptions.onShareAppMessage;
779
+ pageOptions.onShareAppMessage = function pageOnShareAppMessage(...args) {
780
+ const ret = callHookReturn(this, "onShareAppMessage", args);
781
+ if (ret !== void 0) return ret;
782
+ if (typeof userOnShare === "function") return userOnShare.apply(this, args);
783
+ };
784
+ }
785
+ if (features?.enableShareTimeline) {
786
+ const userOnShareTimeline = mpOptions.onShareTimeline;
787
+ pageOptions.onShareTimeline = function pageOnShareTimeline(...args) {
788
+ const ret = callHookReturn(this, "onShareTimeline", args);
789
+ if (ret !== void 0) return ret;
790
+ if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
791
+ };
792
+ }
793
+ if (features?.enableAddToFavorites) {
794
+ const userOnAddToFavorites = mpOptions.onAddToFavorites;
795
+ pageOptions.onAddToFavorites = function pageOnAddToFavorites(...args) {
796
+ const ret = callHookReturn(this, "onAddToFavorites", args);
797
+ if (ret !== void 0) return ret;
798
+ if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
799
+ };
800
+ }
801
+ for (const methodName of methodNames) {
802
+ const userMethod = mpOptions[methodName];
803
+ pageOptions[methodName] = function runtimeMethod(...args) {
804
+ const runtime = this.__wevu;
805
+ let result;
806
+ const bound = runtime?.methods?.[methodName];
807
+ if (bound) result = bound.apply(runtime.proxy, args);
808
+ if (typeof userMethod === "function") return userMethod.apply(this, args);
809
+ return result;
810
+ };
811
+ }
812
+ Page(pageOptions);
813
+ }
814
+ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
815
+ const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, ...rest } = mpOptions;
816
+ const finalMethods = { ...userMethods };
817
+ const methodNames = Object.keys(methods ?? {});
818
+ for (const methodName of methodNames) {
819
+ const userMethod = finalMethods[methodName];
820
+ finalMethods[methodName] = function componentMethod(...args) {
821
+ const runtime = this.__wevu;
822
+ let result;
823
+ const bound = runtime?.methods?.[methodName];
824
+ if (bound) result = bound.apply(runtime.proxy, args);
825
+ if (typeof userMethod === "function") return userMethod.apply(this, args);
826
+ return result;
827
+ };
828
+ }
829
+ const wrapSpecial = (name) => {
830
+ const user = userLifetimes[name] ?? userPageLifetimes[name];
831
+ finalMethods[name] = function wrapped(...args) {
832
+ callHookList(this, name, args);
833
+ if (typeof user === "function") return user.apply(this, args);
834
+ };
835
+ };
836
+ wrapSpecial("onTabItemTap");
837
+ wrapSpecial("onRouteDone");
838
+ Component({
839
+ ...rest,
840
+ lifetimes: {
841
+ ...userLifetimes,
842
+ attached: function attached(...args) {
843
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup);
844
+ if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
845
+ },
846
+ ready: function ready(...args) {
847
+ callHookList(this, "onReady", args);
848
+ if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
849
+ },
850
+ detached: function detached(...args) {
851
+ teardownRuntimeInstance(this);
852
+ if (typeof userLifetimes.detached === "function") userLifetimes.detached.apply(this, args);
853
+ }
854
+ },
855
+ pageLifetimes: {
856
+ ...userPageLifetimes,
857
+ show: function show(...args) {
858
+ callHookList(this, "onShow", args);
859
+ if (typeof userPageLifetimes.show === "function") userPageLifetimes.show.apply(this, args);
860
+ },
861
+ hide: function hide(...args) {
862
+ callHookList(this, "onHide", args);
863
+ if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
864
+ }
865
+ },
866
+ methods: finalMethods
867
+ });
868
+ }
869
+
870
+ //#endregion
871
+ //#region src/runtime/app.ts
438
872
  function createApp(options) {
439
- return {
440
- mount(adapter) {
441
- const dataFn = options.data ?? (() => ({}));
442
- const rawState = dataFn();
443
- if (!isReactive(rawState) && !isPlainObject(rawState)) {
444
- throw new Error("data() must return a plain object");
445
- }
446
- const state = reactive(rawState);
447
- const computedDefs = options.computed ?? {};
448
- const methodDefs = options.methods ?? {};
449
- const computedRefs = /* @__PURE__ */ Object.create(null);
450
- const computedSetters = /* @__PURE__ */ Object.create(null);
451
- const boundMethods = {};
452
- let mounted = true;
453
- let latestSnapshot = {};
454
- const stopHandles = [];
455
- const computedProxy = new Proxy(
456
- {},
457
- {
458
- get(_target, key) {
459
- if (typeof key === "string" && computedRefs[key]) {
460
- return computedRefs[key].value;
461
- }
462
- return void 0;
463
- },
464
- has(_target, key) {
465
- return typeof key === "string" && Boolean(computedRefs[key]);
466
- },
467
- ownKeys() {
468
- return Object.keys(computedRefs);
469
- },
470
- getOwnPropertyDescriptor(_target, key) {
471
- if (typeof key === "string" && computedRefs[key]) {
472
- return {
473
- configurable: true,
474
- enumerable: true,
475
- value: computedRefs[key].value
476
- };
477
- }
478
- return void 0;
479
- }
480
- }
481
- );
482
- const publicInstance = new Proxy(state, {
483
- get(target, key, receiver) {
484
- if (typeof key === "string") {
485
- if (key === "$state") {
486
- return state;
487
- }
488
- if (key === "$computed") {
489
- return computedProxy;
490
- }
491
- if (Object.prototype.hasOwnProperty.call(boundMethods, key)) {
492
- return boundMethods[key];
493
- }
494
- if (computedRefs[key]) {
495
- return computedRefs[key].value;
496
- }
497
- }
498
- return Reflect.get(target, key, receiver);
499
- },
500
- set(target, key, value, receiver) {
501
- if (typeof key === "string" && computedRefs[key]) {
502
- setComputedValue(computedSetters, key, value);
503
- return true;
504
- }
505
- return Reflect.set(target, key, value, receiver);
506
- },
507
- has(target, key) {
508
- if (typeof key === "string" && (computedRefs[key] || Object.prototype.hasOwnProperty.call(boundMethods, key))) {
509
- return true;
510
- }
511
- return Reflect.has(target, key);
512
- },
513
- ownKeys(target) {
514
- const keys = /* @__PURE__ */ new Set();
515
- Reflect.ownKeys(target).forEach((key) => {
516
- keys.add(key);
517
- });
518
- Object.keys(boundMethods).forEach((key) => keys.add(key));
519
- Object.keys(computedRefs).forEach((key) => keys.add(key));
520
- return Array.from(keys);
521
- },
522
- getOwnPropertyDescriptor(target, key) {
523
- if (Reflect.has(target, key)) {
524
- return Object.getOwnPropertyDescriptor(target, key);
525
- }
526
- if (typeof key === "string") {
527
- if (computedRefs[key]) {
528
- return {
529
- configurable: true,
530
- enumerable: true,
531
- get() {
532
- return computedRefs[key].value;
533
- },
534
- set(value) {
535
- setComputedValue(computedSetters, key, value);
536
- }
537
- };
538
- }
539
- if (Object.prototype.hasOwnProperty.call(boundMethods, key)) {
540
- return {
541
- configurable: true,
542
- enumerable: false,
543
- value: boundMethods[key]
544
- };
545
- }
546
- }
547
- return void 0;
548
- }
549
- });
550
- Object.keys(methodDefs).forEach((key) => {
551
- const handler = methodDefs[key];
552
- if (typeof handler === "function") {
553
- boundMethods[key] = ((...args) => handler.apply(publicInstance, args));
554
- }
555
- });
556
- Object.keys(computedDefs).forEach((key) => {
557
- const definition = computedDefs[key];
558
- if (typeof definition === "function") {
559
- computedRefs[key] = computed(() => definition.call(publicInstance));
560
- } else {
561
- const getter = definition.get?.bind(publicInstance);
562
- if (!getter) {
563
- throw new Error(`Computed property "${key}" requires a getter`);
564
- }
565
- const setter = definition.set?.bind(publicInstance);
566
- if (setter) {
567
- computedSetters[key] = setter;
568
- computedRefs[key] = computed({
569
- get: getter,
570
- set: setter
571
- });
572
- } else {
573
- computedRefs[key] = computed(getter);
574
- }
575
- }
576
- });
577
- const currentAdapter = adapter ?? { setData: () => {
578
- } };
579
- const collectSnapshot = () => {
580
- const plain = toPlain(state);
581
- Object.keys(computedRefs).forEach((key) => {
582
- plain[key] = toPlain(computedRefs[key].value);
583
- });
584
- return plain;
585
- };
586
- const job = () => {
587
- if (!mounted) {
588
- return;
589
- }
590
- const snapshot = collectSnapshot();
591
- latestSnapshot = snapshot;
592
- if (typeof currentAdapter.setData === "function") {
593
- currentAdapter.setData(snapshot);
594
- }
595
- };
596
- const tracker = effect(
597
- () => {
598
- traverse(state);
599
- Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
600
- },
601
- {
602
- scheduler: () => queueJob(job)
603
- }
604
- );
605
- job();
606
- stopHandles.push(() => stop(tracker));
607
- function registerWatch(source, cb, watchOptions) {
608
- const stopHandle = watch(source, (value, oldValue) => cb(value, oldValue), watchOptions);
609
- stopHandles.push(stopHandle);
610
- return () => {
611
- stopHandle();
612
- const index = stopHandles.indexOf(stopHandle);
613
- if (index >= 0) {
614
- stopHandles.splice(index, 1);
615
- }
616
- };
617
- }
618
- const bindModel = (path, bindingOptions) => {
619
- const segments = toPathSegments(path);
620
- if (!segments.length) {
621
- throw new Error("bindModel requires a non-empty path");
622
- }
623
- const resolveValue = () => getFromPath(publicInstance, segments);
624
- const assignValue = (value) => {
625
- setByPath(state, computedRefs, computedSetters, segments, value);
626
- };
627
- const defaultOptions = {
628
- event: "input",
629
- valueProp: "value",
630
- parser: defaultParser,
631
- formatter: (value) => value,
632
- ...bindingOptions
633
- };
634
- return {
635
- get value() {
636
- return resolveValue();
637
- },
638
- set value(nextValue) {
639
- assignValue(nextValue);
640
- },
641
- update(nextValue) {
642
- assignValue(nextValue);
643
- },
644
- model(modelOptions) {
645
- const merged = {
646
- ...defaultOptions,
647
- ...modelOptions
648
- };
649
- const handlerKey = `on${capitalize(merged.event)}`;
650
- const payload = {
651
- [merged.valueProp]: merged.formatter(resolveValue())
652
- };
653
- payload[handlerKey] = (event) => {
654
- const parsed = merged.parser(event);
655
- assignValue(parsed);
656
- };
657
- return payload;
658
- }
659
- };
660
- };
661
- const unmount = () => {
662
- if (!mounted) {
663
- return;
664
- }
665
- mounted = false;
666
- stopHandles.forEach((handle) => {
667
- try {
668
- handle();
669
- } catch {
670
- }
671
- });
672
- stopHandles.length = 0;
673
- };
674
- return {
675
- get state() {
676
- return state;
677
- },
678
- get proxy() {
679
- return publicInstance;
680
- },
681
- get methods() {
682
- return boundMethods;
683
- },
684
- get computed() {
685
- return computedProxy;
686
- },
687
- get adapter() {
688
- return currentAdapter;
689
- },
690
- bindModel,
691
- watch: registerWatch,
692
- snapshot: () => ({ ...latestSnapshot }),
693
- unmount
694
- };
695
- }
696
- };
873
+ const { data, computed: computedOptions, methods, watch: appWatch, setup: appSetup, ...mpOptions } = options;
874
+ const resolvedMethods = methods ?? {};
875
+ const resolvedComputed = computedOptions ?? {};
876
+ const installedPlugins = /* @__PURE__ */ new Set();
877
+ const appConfig = { globalProperties: {} };
878
+ const runtimeApp = {
879
+ mount(adapter) {
880
+ const state = reactive((data ?? (() => ({})))());
881
+ const computedDefs = resolvedComputed;
882
+ const methodDefs = resolvedMethods;
883
+ const computedRefs = Object.create(null);
884
+ const computedSetters = Object.create(null);
885
+ const boundMethods = {};
886
+ let mounted = true;
887
+ let latestSnapshot = {};
888
+ const stopHandles = [];
889
+ const computedProxy = new Proxy({}, {
890
+ get(_target, key) {
891
+ if (typeof key === "string" && computedRefs[key]) return computedRefs[key].value;
892
+ },
893
+ has(_target, key) {
894
+ return typeof key === "string" && Boolean(computedRefs[key]);
895
+ },
896
+ ownKeys() {
897
+ return Object.keys(computedRefs);
898
+ },
899
+ getOwnPropertyDescriptor(_target, key) {
900
+ if (typeof key === "string" && computedRefs[key]) return {
901
+ configurable: true,
902
+ enumerable: true,
903
+ value: computedRefs[key].value
904
+ };
905
+ }
906
+ });
907
+ const publicInstance = new Proxy(state, {
908
+ get(target, key, receiver) {
909
+ if (typeof key === "string") {
910
+ if (key === "$state") return state;
911
+ if (key === "$computed") return computedProxy;
912
+ if (Object.prototype.hasOwnProperty.call(boundMethods, key)) return boundMethods[key];
913
+ if (computedRefs[key]) return computedRefs[key].value;
914
+ if (Object.prototype.hasOwnProperty.call(appConfig.globalProperties, key)) return appConfig.globalProperties[key];
915
+ }
916
+ return Reflect.get(target, key, receiver);
917
+ },
918
+ set(target, key, value, receiver) {
919
+ if (typeof key === "string" && computedRefs[key]) {
920
+ setComputedValue(computedSetters, key, value);
921
+ return true;
922
+ }
923
+ return Reflect.set(target, key, value, receiver);
924
+ },
925
+ has(target, key) {
926
+ if (typeof key === "string" && (computedRefs[key] || Object.prototype.hasOwnProperty.call(boundMethods, key))) return true;
927
+ return Reflect.has(target, key);
928
+ },
929
+ ownKeys(target) {
930
+ const keys = /* @__PURE__ */ new Set();
931
+ Reflect.ownKeys(target).forEach((key) => {
932
+ keys.add(key);
933
+ });
934
+ Object.keys(boundMethods).forEach((key) => keys.add(key));
935
+ Object.keys(computedRefs).forEach((key) => keys.add(key));
936
+ return Array.from(keys);
937
+ },
938
+ getOwnPropertyDescriptor(target, key) {
939
+ if (Reflect.has(target, key)) return Object.getOwnPropertyDescriptor(target, key);
940
+ if (typeof key === "string") {
941
+ if (computedRefs[key]) return {
942
+ configurable: true,
943
+ enumerable: true,
944
+ get() {
945
+ return computedRefs[key].value;
946
+ },
947
+ set(value) {
948
+ setComputedValue(computedSetters, key, value);
949
+ }
950
+ };
951
+ if (Object.prototype.hasOwnProperty.call(boundMethods, key)) return {
952
+ configurable: true,
953
+ enumerable: false,
954
+ value: boundMethods[key]
955
+ };
956
+ }
957
+ }
958
+ });
959
+ Object.keys(methodDefs).forEach((key) => {
960
+ const handler = methodDefs[key];
961
+ if (typeof handler === "function") boundMethods[key] = (...args) => handler.apply(publicInstance, args);
962
+ });
963
+ Object.keys(computedDefs).forEach((key) => {
964
+ const definition = computedDefs[key];
965
+ if (typeof definition === "function") computedRefs[key] = computed(() => definition.call(publicInstance));
966
+ else {
967
+ const getter = definition.get?.bind(publicInstance);
968
+ if (!getter) throw new Error(`Computed property "${key}" requires a getter`);
969
+ const setter = definition.set?.bind(publicInstance);
970
+ if (setter) {
971
+ computedSetters[key] = setter;
972
+ computedRefs[key] = computed({
973
+ get: getter,
974
+ set: setter
975
+ });
976
+ } else computedRefs[key] = computed(getter);
977
+ }
978
+ });
979
+ const currentAdapter = adapter ?? { setData: () => {} };
980
+ const collectSnapshot = () => {
981
+ const plain = toPlain(state);
982
+ Object.keys(computedRefs).forEach((key) => {
983
+ plain[key] = toPlain(computedRefs[key].value);
984
+ });
985
+ return plain;
986
+ };
987
+ const job = () => {
988
+ if (!mounted) return;
989
+ const snapshot = collectSnapshot();
990
+ const diff = diffSnapshots(latestSnapshot, snapshot);
991
+ latestSnapshot = snapshot;
992
+ if (!Object.keys(diff).length) return;
993
+ if (typeof currentAdapter.setData === "function") {
994
+ const result = currentAdapter.setData(diff);
995
+ if (result && typeof result.then === "function") result.catch(() => {});
996
+ }
997
+ };
998
+ const tracker = effect(() => {
999
+ touchReactive(state);
1000
+ Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
1001
+ }, { scheduler: () => queueJob(job) });
1002
+ job();
1003
+ stopHandles.push(() => stop(tracker));
1004
+ function registerWatch(source, cb, watchOptions) {
1005
+ const stopHandle = watch(source, (value, oldValue) => cb(value, oldValue), watchOptions);
1006
+ stopHandles.push(stopHandle);
1007
+ return () => {
1008
+ stopHandle();
1009
+ const index = stopHandles.indexOf(stopHandle);
1010
+ if (index >= 0) stopHandles.splice(index, 1);
1011
+ };
1012
+ }
1013
+ const bindModel = createBindModel(publicInstance, state, computedRefs, computedSetters);
1014
+ const unmount = () => {
1015
+ if (!mounted) return;
1016
+ mounted = false;
1017
+ stopHandles.forEach((handle) => {
1018
+ try {
1019
+ handle();
1020
+ } catch {}
1021
+ });
1022
+ stopHandles.length = 0;
1023
+ };
1024
+ return {
1025
+ get state() {
1026
+ return state;
1027
+ },
1028
+ get proxy() {
1029
+ return publicInstance;
1030
+ },
1031
+ get methods() {
1032
+ return boundMethods;
1033
+ },
1034
+ get computed() {
1035
+ return computedProxy;
1036
+ },
1037
+ get adapter() {
1038
+ return currentAdapter;
1039
+ },
1040
+ bindModel,
1041
+ watch: registerWatch,
1042
+ snapshot: () => ({ ...latestSnapshot }),
1043
+ unmount
1044
+ };
1045
+ },
1046
+ use(plugin, ...options$1) {
1047
+ if (!plugin || installedPlugins.has(plugin)) return runtimeApp;
1048
+ installedPlugins.add(plugin);
1049
+ if (typeof plugin === "function") plugin(runtimeApp, ...options$1);
1050
+ else if (typeof plugin.install === "function") plugin.install(runtimeApp, ...options$1);
1051
+ else throw new TypeError("A plugin must be a function or an object with an install method");
1052
+ return runtimeApp;
1053
+ },
1054
+ config: appConfig
1055
+ };
1056
+ if (typeof globalThis.App === "function") registerApp(runtimeApp, methods ?? {}, appWatch, appSetup, mpOptions);
1057
+ return runtimeApp;
1058
+ }
1059
+ function setComputedValue(setters, key, value) {
1060
+ const setter = setters[key];
1061
+ if (!setter) throw new Error(`Computed property "${key}" is readonly`);
1062
+ setter(value);
1063
+ }
1064
+
1065
+ //#endregion
1066
+ //#region src/runtime/define.ts
1067
+ /**
1068
+ * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
1069
+ *
1070
+ * @param options 组件定义项
1071
+ * @returns 可手动注册的组件定义
1072
+ *
1073
+ * @example
1074
+ * ```ts
1075
+ * defineComponent({
1076
+ * data: () => ({ count: 0 }),
1077
+ * setup() {
1078
+ * onMounted(() => console.log('mounted'))
1079
+ * }
1080
+ * })
1081
+ * ```
1082
+ */
1083
+ function defineComponent(options) {
1084
+ const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1085
+ const mpOptionsWithProps = normalizeProps(mpOptions, props);
1086
+ const runtimeApp = createApp({
1087
+ data,
1088
+ computed: computed$1,
1089
+ methods
1090
+ });
1091
+ const setupWrapper = (ctx) => {
1092
+ const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1093
+ if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1094
+ };
1095
+ const componentOptions = {
1096
+ data,
1097
+ computed: computed$1,
1098
+ methods,
1099
+ watch: watch$1,
1100
+ setup: setupWrapper,
1101
+ mpOptions: mpOptionsWithProps
1102
+ };
1103
+ registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
1104
+ return {
1105
+ __wevu_runtime: runtimeApp,
1106
+ __wevu_options: componentOptions
1107
+ };
1108
+ }
1109
+ /**
1110
+ * 按 Vue 3 风格定义一个小程序页面
1111
+ *
1112
+ * @param options 页面定义
1113
+ * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
1114
+ * @returns 页面定义
1115
+ *
1116
+ * @example
1117
+ * ```ts
1118
+ * definePage({
1119
+ * data: () => ({ count: 0 }),
1120
+ * setup() {
1121
+ * const count = ref(0)
1122
+ * onMounted(() => console.log('page mounted'))
1123
+ * return { count }
1124
+ * }
1125
+ * }, {
1126
+ * listenPageScroll: true,
1127
+ * enableShareAppMessage: true
1128
+ * })
1129
+ * ```
1130
+ */
1131
+ function definePage(options, features) {
1132
+ const { data, computed: computed$1, methods, watch: watch$1, setup, props: _props, ...mpOptions } = options;
1133
+ const runtimeApp = createApp({
1134
+ data,
1135
+ computed: computed$1,
1136
+ methods
1137
+ });
1138
+ const setupWrapper = (ctx) => {
1139
+ const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1140
+ if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1141
+ };
1142
+ const componentOptions = {
1143
+ type: "page",
1144
+ data,
1145
+ computed: computed$1,
1146
+ methods,
1147
+ watch: watch$1,
1148
+ setup: setupWrapper,
1149
+ mpOptions,
1150
+ features
1151
+ };
1152
+ registerPage(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptions, features);
1153
+ return {
1154
+ mount: () => {},
1155
+ __wevu_runtime: runtimeApp,
1156
+ __wevu_options: componentOptions
1157
+ };
1158
+ }
1159
+ function applySetupResult(runtime, _target, result) {
1160
+ const methods = runtime?.methods ?? Object.create(null);
1161
+ const state = runtime?.state ?? Object.create(null);
1162
+ if (runtime && !runtime.methods) try {
1163
+ runtime.methods = methods;
1164
+ } catch {}
1165
+ if (runtime && !runtime.state) try {
1166
+ runtime.state = state;
1167
+ } catch {}
1168
+ Object.keys(result).forEach((key) => {
1169
+ const val = result[key];
1170
+ if (typeof val === "function") methods[key] = (...args) => val.apply(runtime?.proxy ?? runtime, args);
1171
+ else state[key] = val;
1172
+ });
1173
+ if (runtime) {
1174
+ runtime.methods = runtime.methods ?? methods;
1175
+ runtime.state = runtime.state ?? state;
1176
+ }
1177
+ }
1178
+ /**
1179
+ * 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
1180
+ *
1181
+ * @param options 组件选项,可能包含小程序特有的 properties
1182
+ */
1183
+ function createWevuComponent(options) {
1184
+ const { properties, props, ...restOptions } = options;
1185
+ defineComponent(normalizeProps(restOptions, props, properties));
1186
+ }
1187
+ function normalizeProps(baseOptions, props, explicitProperties) {
1188
+ if (explicitProperties || !props) return {
1189
+ ...baseOptions,
1190
+ ...explicitProperties ? { properties: explicitProperties } : {}
1191
+ };
1192
+ const properties = {};
1193
+ Object.entries(props).forEach(([key, definition]) => {
1194
+ if (definition === null || definition === void 0) return;
1195
+ if (Array.isArray(definition) || typeof definition === "function") {
1196
+ properties[key] = { type: definition };
1197
+ return;
1198
+ }
1199
+ if (typeof definition === "object") {
1200
+ const propOptions = {};
1201
+ if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
1202
+ const defaultValue = "default" in definition ? definition.default : definition.value;
1203
+ if (defaultValue !== void 0) propOptions.value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
1204
+ properties[key] = propOptions;
1205
+ }
1206
+ });
1207
+ return {
1208
+ ...baseOptions,
1209
+ properties
1210
+ };
1211
+ }
1212
+
1213
+ //#endregion
1214
+ //#region src/runtime/provide.ts
1215
+ const PROVIDE_SCOPE_KEY = Symbol("wevu.provideScope");
1216
+ const __wevuGlobalProvideStore = /* @__PURE__ */ new Map();
1217
+ /**
1218
+ * 在组件上下文中向后代注入值(与 Vue 3 行为兼容),若没有当前实例则回落到全局存储。
1219
+ *
1220
+ * @param key 注入键,可为字符串、Symbol 或对象
1221
+ * @param value 提供的值
1222
+ *
1223
+ * @example
1224
+ * ```ts
1225
+ * defineComponent({
1226
+ * setup() {
1227
+ * provide(TOKEN_KEY, { data: 'value' })
1228
+ * }
1229
+ * })
1230
+ * ```
1231
+ */
1232
+ function provide(key, value) {
1233
+ const instance = getCurrentInstance();
1234
+ if (instance) {
1235
+ let scope = instance[PROVIDE_SCOPE_KEY];
1236
+ if (!scope) {
1237
+ scope = /* @__PURE__ */ new Map();
1238
+ instance[PROVIDE_SCOPE_KEY] = scope;
1239
+ }
1240
+ scope.set(key, value);
1241
+ } else __wevuGlobalProvideStore.set(key, value);
1242
+ }
1243
+ /**
1244
+ * 从祖先组件(或全局存储)读取提供的值。
1245
+ *
1246
+ * @param key 注入键,需与 provide 使用的键保持一致
1247
+ * @param defaultValue 未找到提供者时的默认值
1248
+ * @returns 匹配到的值或默认值
1249
+ *
1250
+ * @example
1251
+ * ```ts
1252
+ * defineComponent({
1253
+ * setup() {
1254
+ * const data = inject(TOKEN_KEY)
1255
+ * const value = inject('key', 'default')
1256
+ * }
1257
+ * })
1258
+ * ```
1259
+ */
1260
+ function inject(key, defaultValue) {
1261
+ const instance = getCurrentInstance();
1262
+ if (instance) {
1263
+ let current = instance;
1264
+ while (current) {
1265
+ const scope = current[PROVIDE_SCOPE_KEY];
1266
+ if (scope && scope.has(key)) return scope.get(key);
1267
+ current = null;
1268
+ }
1269
+ }
1270
+ if (__wevuGlobalProvideStore.has(key)) return __wevuGlobalProvideStore.get(key);
1271
+ if (arguments.length >= 2) return defaultValue;
1272
+ throw new Error(`wevu.inject: no value found for key`);
1273
+ }
1274
+ /**
1275
+ * 全局注入值,适用于组件外部调用场景。
1276
+ */
1277
+ function provideGlobal(key, value) {
1278
+ __wevuGlobalProvideStore.set(key, value);
1279
+ }
1280
+ /**
1281
+ * 从全局存储读取值,适用于组件外部调用场景。
1282
+ */
1283
+ function injectGlobal(key, defaultValue) {
1284
+ if (__wevuGlobalProvideStore.has(key)) return __wevuGlobalProvideStore.get(key);
1285
+ if (arguments.length >= 2) return defaultValue;
1286
+ throw new Error(`injectGlobal() no matching provider for key: ${String(key)}`);
697
1287
  }
698
1288
 
699
- export { computed, createApp, effect, isReactive, isRef, nextTick, reactive, ref, stop, toRaw, traverse, unref, watch };
1289
+ //#endregion
1290
+ export { 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 };