wevu 1.0.0-alpha.2 → 1.0.0-alpha.4

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,5 +1,485 @@
1
- import { C as onScopeDispose, D as queueJob, E as nextTick, S as getCurrentScope, T as stop, _ as computed, a as isRef, b as effectScope, 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 batch, w as startBatch, x as endBatch, y as effect } from "./store-2q4qcdBi.mjs";
1
+ //#region src/scheduler.ts
2
+ const resolvedPromise = Promise.resolve();
3
+ const jobQueue = /* @__PURE__ */ new Set();
4
+ let isFlushing = false;
5
+ function flushJobs() {
6
+ isFlushing = true;
7
+ try {
8
+ jobQueue.forEach((job) => job());
9
+ } finally {
10
+ jobQueue.clear();
11
+ isFlushing = false;
12
+ }
13
+ }
14
+ function queueJob(job) {
15
+ jobQueue.add(job);
16
+ if (!isFlushing) resolvedPromise.then(flushJobs);
17
+ }
18
+ function nextTick(fn) {
19
+ return fn ? resolvedPromise.then(fn) : resolvedPromise;
20
+ }
21
+
22
+ //#endregion
23
+ //#region src/reactivity/core.ts
24
+ const targetMap = /* @__PURE__ */ new WeakMap();
25
+ let activeEffect = null;
26
+ const effectStack = [];
27
+ let batchDepth = 0;
28
+ const batchedEffects = /* @__PURE__ */ new Set();
29
+ function startBatch() {
30
+ batchDepth++;
31
+ }
32
+ function endBatch() {
33
+ if (batchDepth === 0) return;
34
+ batchDepth--;
35
+ if (batchDepth === 0) flushBatchedEffects();
36
+ }
37
+ function batch(fn) {
38
+ startBatch();
39
+ try {
40
+ return fn();
41
+ } finally {
42
+ endBatch();
43
+ }
44
+ }
45
+ function flushBatchedEffects() {
46
+ while (batchedEffects.size) {
47
+ const effects = Array.from(batchedEffects);
48
+ batchedEffects.clear();
49
+ for (const ef of effects) ef();
50
+ }
51
+ }
52
+ let activeEffectScope;
53
+ var EffectScopeImpl = class {
54
+ active = true;
55
+ effects = [];
56
+ cleanups = [];
57
+ parent;
58
+ scopes;
59
+ constructor(detached = false) {
60
+ this.detached = detached;
61
+ if (!detached && activeEffectScope) {
62
+ this.parent = activeEffectScope;
63
+ (activeEffectScope.scopes ||= []).push(this);
64
+ }
65
+ }
66
+ run(fn) {
67
+ if (!this.active) return;
68
+ const prev = activeEffectScope;
69
+ activeEffectScope = this;
70
+ try {
71
+ return fn();
72
+ } finally {
73
+ activeEffectScope = prev;
74
+ }
75
+ }
76
+ stop() {
77
+ if (!this.active) return;
78
+ this.active = false;
79
+ for (const effect$1 of this.effects) stop(effect$1);
80
+ this.effects.length = 0;
81
+ for (const cleanup of this.cleanups) cleanup();
82
+ this.cleanups.length = 0;
83
+ if (this.scopes) {
84
+ for (const scope of this.scopes) scope.stop();
85
+ this.scopes.length = 0;
86
+ }
87
+ if (this.parent?.scopes) {
88
+ const index = this.parent.scopes.indexOf(this);
89
+ if (index >= 0) this.parent.scopes.splice(index, 1);
90
+ }
91
+ this.parent = void 0;
92
+ }
93
+ };
94
+ function effectScope(detached = false) {
95
+ return new EffectScopeImpl(detached);
96
+ }
97
+ function getCurrentScope() {
98
+ return activeEffectScope;
99
+ }
100
+ function onScopeDispose(fn) {
101
+ if (activeEffectScope?.active) activeEffectScope.cleanups.push(fn);
102
+ }
103
+ function recordEffectScope(effect$1) {
104
+ if (activeEffectScope?.active) activeEffectScope.effects.push(effect$1);
105
+ }
106
+ function cleanupEffect(effect$1) {
107
+ const { deps } = effect$1;
108
+ for (let i = 0; i < deps.length; i++) deps[i].delete(effect$1);
109
+ deps.length = 0;
110
+ }
111
+ function createReactiveEffect(fn, options = {}) {
112
+ const effect$1 = function reactiveEffect() {
113
+ if (!effect$1.active) return fn();
114
+ if (effect$1._running) return fn();
115
+ cleanupEffect(effect$1);
116
+ try {
117
+ effect$1._running = true;
118
+ effectStack.push(effect$1);
119
+ activeEffect = effect$1;
120
+ return fn();
121
+ } finally {
122
+ effectStack.pop();
123
+ activeEffect = effectStack[effectStack.length - 1] ?? null;
124
+ effect$1._running = false;
125
+ }
126
+ };
127
+ effect$1.deps = [];
128
+ effect$1.scheduler = options.scheduler;
129
+ effect$1.onStop = options.onStop;
130
+ effect$1.active = true;
131
+ effect$1._running = false;
132
+ effect$1._fn = fn;
133
+ return effect$1;
134
+ }
135
+ function effect(fn, options = {}) {
136
+ const _effect = createReactiveEffect(fn, options);
137
+ recordEffectScope(_effect);
138
+ if (!options.lazy) _effect();
139
+ return _effect;
140
+ }
141
+ function stop(runner) {
142
+ if (!runner.active) return;
143
+ runner.active = false;
144
+ cleanupEffect(runner);
145
+ runner.onStop?.();
146
+ }
147
+ function track(target, key) {
148
+ if (!activeEffect) return;
149
+ let depsMap = targetMap.get(target);
150
+ if (!depsMap) {
151
+ depsMap = /* @__PURE__ */ new Map();
152
+ targetMap.set(target, depsMap);
153
+ }
154
+ let dep = depsMap.get(key);
155
+ if (!dep) {
156
+ dep = /* @__PURE__ */ new Set();
157
+ depsMap.set(key, dep);
158
+ }
159
+ if (!dep.has(activeEffect)) {
160
+ dep.add(activeEffect);
161
+ activeEffect.deps.push(dep);
162
+ }
163
+ }
164
+ function trigger(target, key) {
165
+ const depsMap = targetMap.get(target);
166
+ if (!depsMap) return;
167
+ const effects = depsMap.get(key);
168
+ if (!effects) return;
169
+ const effectsToRun = /* @__PURE__ */ new Set();
170
+ effects.forEach((ef) => {
171
+ if (ef !== activeEffect) effectsToRun.add(ef);
172
+ });
173
+ effectsToRun.forEach(scheduleEffect);
174
+ }
175
+ function trackEffects(dep) {
176
+ if (!activeEffect) return;
177
+ if (!dep.has(activeEffect)) {
178
+ dep.add(activeEffect);
179
+ activeEffect.deps.push(dep);
180
+ }
181
+ }
182
+ function triggerEffects(dep) {
183
+ dep.forEach(scheduleEffect);
184
+ }
185
+ function scheduleEffect(ef) {
186
+ if (ef.scheduler) {
187
+ ef.scheduler();
188
+ return;
189
+ }
190
+ if (batchDepth > 0) {
191
+ batchedEffects.add(ef);
192
+ return;
193
+ }
194
+ ef();
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/reactivity/computed.ts
199
+ function computed(getterOrOptions) {
200
+ let getter;
201
+ let setter;
202
+ const onlyGetter = typeof getterOrOptions === "function";
203
+ if (onlyGetter) {
204
+ getter = getterOrOptions;
205
+ setter = () => {
206
+ throw new Error("Computed value is readonly");
207
+ };
208
+ } else {
209
+ getter = getterOrOptions.get;
210
+ setter = getterOrOptions.set;
211
+ }
212
+ let value;
213
+ let dirty = true;
214
+ let runner;
215
+ const obj = {
216
+ get value() {
217
+ if (dirty) {
218
+ value = runner();
219
+ dirty = false;
220
+ }
221
+ track(obj, "value");
222
+ return value;
223
+ },
224
+ set value(newValue) {
225
+ setter(newValue);
226
+ }
227
+ };
228
+ runner = effect(getter, {
229
+ lazy: true,
230
+ scheduler: () => {
231
+ if (!dirty) {
232
+ dirty = true;
233
+ trigger(obj, "value");
234
+ }
235
+ }
236
+ });
237
+ return onlyGetter ? obj : obj;
238
+ }
239
+
240
+ //#endregion
241
+ //#region src/reactivity/reactive.ts
242
+ const reactiveMap = /* @__PURE__ */ new WeakMap();
243
+ const rawMap = /* @__PURE__ */ new WeakMap();
244
+ const rawRootMap = /* @__PURE__ */ new WeakMap();
245
+ let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags$1) {
246
+ ReactiveFlags$1["IS_REACTIVE"] = "__r_isReactive";
247
+ ReactiveFlags$1["RAW"] = "__r_raw";
248
+ ReactiveFlags$1["SKIP"] = "__r_skip";
249
+ return ReactiveFlags$1;
250
+ }({});
251
+ function isObject$1(value) {
252
+ return typeof value === "object" && value !== null;
253
+ }
254
+ const VERSION_KEY = Symbol("wevu.version");
255
+ const mutableHandlers = {
256
+ get(target, key, receiver) {
257
+ if (key === ReactiveFlags.IS_REACTIVE) return true;
258
+ if (key === ReactiveFlags.RAW) return target;
259
+ const res = Reflect.get(target, key, receiver);
260
+ track(target, key);
261
+ if (isObject$1(res)) {
262
+ if (res[ReactiveFlags.SKIP]) return res;
263
+ const child = res;
264
+ const parentRoot = rawRootMap.get(target) ?? target;
265
+ if (!rawRootMap.has(child)) rawRootMap.set(child, parentRoot);
266
+ return reactive(res);
267
+ }
268
+ return res;
269
+ },
270
+ set(target, key, value, receiver) {
271
+ const oldValue = Reflect.get(target, key, receiver);
272
+ const result = Reflect.set(target, key, value, receiver);
273
+ if (!Object.is(oldValue, value)) {
274
+ trigger(target, key);
275
+ trigger(target, VERSION_KEY);
276
+ const root = rawRootMap.get(target);
277
+ if (root && root !== target) trigger(root, VERSION_KEY);
278
+ }
279
+ return result;
280
+ },
281
+ deleteProperty(target, key) {
282
+ const hadKey = Object.prototype.hasOwnProperty.call(target, key);
283
+ const result = Reflect.deleteProperty(target, key);
284
+ if (hadKey && result) {
285
+ trigger(target, key);
286
+ trigger(target, VERSION_KEY);
287
+ const root = rawRootMap.get(target);
288
+ if (root && root !== target) trigger(root, VERSION_KEY);
289
+ }
290
+ return result;
291
+ },
292
+ ownKeys(target) {
293
+ track(target, Symbol.iterator);
294
+ track(target, VERSION_KEY);
295
+ return Reflect.ownKeys(target);
296
+ }
297
+ };
298
+ function reactive(target) {
299
+ if (!isObject$1(target)) return target;
300
+ const existingProxy = reactiveMap.get(target);
301
+ if (existingProxy) return existingProxy;
302
+ if (target[ReactiveFlags.IS_REACTIVE]) return target;
303
+ const proxy = new Proxy(target, mutableHandlers);
304
+ reactiveMap.set(target, proxy);
305
+ rawMap.set(proxy, target);
306
+ if (!rawRootMap.has(target)) rawRootMap.set(target, target);
307
+ return proxy;
308
+ }
309
+ function isReactive(value) {
310
+ return Boolean(value && value[ReactiveFlags.IS_REACTIVE]);
311
+ }
312
+ function toRaw(observed) {
313
+ return observed?.[ReactiveFlags.RAW] ?? observed;
314
+ }
315
+ function convertToReactive(value) {
316
+ return isObject$1(value) ? reactive(value) : value;
317
+ }
318
+ /**
319
+ * 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
320
+ */
321
+ function touchReactive(target) {
322
+ track(toRaw(target), VERSION_KEY);
323
+ }
324
+ const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
325
+ const shallowHandlers = {
326
+ get(target, key, receiver) {
327
+ if (key === ReactiveFlags.IS_REACTIVE) return true;
328
+ if (key === ReactiveFlags.RAW) return target;
329
+ const res = Reflect.get(target, key, receiver);
330
+ track(target, key);
331
+ return res;
332
+ },
333
+ set(target, key, value, receiver) {
334
+ const oldValue = Reflect.get(target, key, receiver);
335
+ const result = Reflect.set(target, key, value, receiver);
336
+ if (!Object.is(oldValue, value)) {
337
+ trigger(target, key);
338
+ trigger(target, VERSION_KEY);
339
+ }
340
+ return result;
341
+ },
342
+ deleteProperty(target, key) {
343
+ const hadKey = Object.prototype.hasOwnProperty.call(target, key);
344
+ const result = Reflect.deleteProperty(target, key);
345
+ if (hadKey && result) {
346
+ trigger(target, key);
347
+ trigger(target, VERSION_KEY);
348
+ }
349
+ return result;
350
+ },
351
+ ownKeys(target) {
352
+ track(target, Symbol.iterator);
353
+ track(target, VERSION_KEY);
354
+ return Reflect.ownKeys(target);
355
+ }
356
+ };
357
+ /**
358
+ * 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
359
+ *
360
+ * @param target 待转换的对象
361
+ * @returns 浅层响应式代理
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * const state = shallowReactive({ nested: { count: 0 } })
366
+ *
367
+ * state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
368
+ * state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
369
+ * ```
370
+ */
371
+ function shallowReactive(target) {
372
+ if (!isObject$1(target)) return target;
373
+ const existingProxy = shallowReactiveMap.get(target);
374
+ if (existingProxy) return existingProxy;
375
+ if (target[ReactiveFlags.IS_REACTIVE]) return target;
376
+ const proxy = new Proxy(target, shallowHandlers);
377
+ shallowReactiveMap.set(target, proxy);
378
+ rawMap.set(proxy, target);
379
+ return proxy;
380
+ }
381
+ /**
382
+ * 判断一个值是否为 shallowReactive 创建的浅层响应式对象
383
+ */
384
+ function isShallowReactive(value) {
385
+ const raw = toRaw(value);
386
+ return shallowReactiveMap.has(raw);
387
+ }
388
+ /**
389
+ * 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
390
+ *
391
+ * @param value 需要标记的对象
392
+ * @returns 带有跳过标记的原对象
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const foo = markRaw({
397
+ * nested: {}
398
+ * })
399
+ *
400
+ * const state = reactive({
401
+ * foo
402
+ * })
403
+ *
404
+ * state.foo // 不是响应式对象
405
+ * ```
406
+ */
407
+ function markRaw(value) {
408
+ if (!isObject$1(value)) return value;
409
+ Object.defineProperty(value, ReactiveFlags.SKIP, {
410
+ value: true,
411
+ configurable: true,
412
+ enumerable: false,
413
+ writable: true
414
+ });
415
+ return value;
416
+ }
417
+ /**
418
+ * 判断某个值是否被标记为原始(即不应转换为响应式)。
419
+ *
420
+ * @param value 待检测的值
421
+ * @returns 若含有跳过标记则返回 true
422
+ */
423
+ function isRaw(value) {
424
+ return isObject$1(value) && ReactiveFlags.SKIP in value;
425
+ }
426
+
427
+ //#endregion
428
+ //#region src/reactivity/ref.ts
429
+ function isRef(value) {
430
+ return Boolean(value && typeof value === "object" && "value" in value);
431
+ }
432
+ var RefImpl = class {
433
+ _value;
434
+ _rawValue;
435
+ dep;
436
+ constructor(value) {
437
+ this._rawValue = value;
438
+ this._value = convertToReactive(value);
439
+ }
440
+ get value() {
441
+ if (!this.dep) this.dep = /* @__PURE__ */ new Set();
442
+ trackEffects(this.dep);
443
+ return this._value;
444
+ }
445
+ set value(newValue) {
446
+ if (!Object.is(newValue, this._rawValue)) {
447
+ this._rawValue = newValue;
448
+ this._value = convertToReactive(newValue);
449
+ if (this.dep) triggerEffects(this.dep);
450
+ }
451
+ }
452
+ };
453
+ function ref(value) {
454
+ if (isRef(value)) return value;
455
+ return markRaw(new RefImpl(value));
456
+ }
457
+ function unref(value) {
458
+ return isRef(value) ? value.value : value;
459
+ }
460
+ var CustomRefImpl = class {
461
+ _value;
462
+ _factory;
463
+ dep;
464
+ constructor(factory, defaultValue) {
465
+ this._factory = factory;
466
+ this._value = defaultValue;
467
+ }
468
+ get value() {
469
+ if (!this.dep) this.dep = /* @__PURE__ */ new Set();
470
+ trackEffects(this.dep);
471
+ return this._factory.get();
472
+ }
473
+ set value(newValue) {
474
+ this._factory.set(newValue);
475
+ if (this.dep) triggerEffects(this.dep);
476
+ }
477
+ };
478
+ function customRef(factory, defaultValue) {
479
+ return markRaw(new CustomRefImpl(factory, defaultValue));
480
+ }
2
481
 
482
+ //#endregion
3
483
  //#region src/reactivity/readonly.ts
4
484
  function readonly(target) {
5
485
  if (isRef(target)) {
@@ -13,7 +493,7 @@ function readonly(target) {
13
493
  }
14
494
  };
15
495
  }
16
- if (!isObject(target)) return target;
496
+ if (!isObject$1(target)) return target;
17
497
  return new Proxy(target, {
18
498
  set() {
19
499
  throw new Error("Cannot set property on readonly object");
@@ -33,15 +513,15 @@ function readonly(target) {
33
513
  //#endregion
34
514
  //#region src/reactivity/shallowRef.ts
35
515
  function shallowRef(value, defaultValue) {
36
- return customRef((track, trigger) => ({
516
+ return customRef((track$1, trigger$1) => ({
37
517
  get() {
38
- track();
518
+ track$1();
39
519
  return value;
40
520
  },
41
521
  set(newValue) {
42
522
  if (Object.is(value, newValue)) return;
43
523
  value = newValue;
44
- trigger();
524
+ trigger$1();
45
525
  }
46
526
  }), defaultValue);
47
527
  }
@@ -89,14 +569,14 @@ function toRefs(object) {
89
569
  function toRef(object, key, defaultValue) {
90
570
  const value = object[key];
91
571
  if (isRef(value)) return value;
92
- return customRef((track, trigger) => ({
572
+ return customRef((track$1, trigger$1) => ({
93
573
  get() {
94
- track();
574
+ track$1();
95
575
  return object[key];
96
576
  },
97
577
  set(newValue) {
98
578
  object[key] = newValue;
99
- trigger();
579
+ trigger$1();
100
580
  }
101
581
  }), defaultValue);
102
582
  }
@@ -104,7 +584,7 @@ function toRef(object, key, defaultValue) {
104
584
  //#endregion
105
585
  //#region src/reactivity/traverse.ts
106
586
  function traverse(value, seen = /* @__PURE__ */ new Set()) {
107
- if (!isObject(value) || seen.has(value)) return value;
587
+ if (!isObject$1(value) || seen.has(value)) return value;
108
588
  seen.add(value);
109
589
  for (const key in value) traverse(value[key], seen);
110
590
  return value;
@@ -374,12 +854,19 @@ function diffSnapshots(prev, next) {
374
854
  //#endregion
375
855
  //#region src/runtime/hooks.ts
376
856
  let __currentInstance;
857
+ let __currentSetupContext;
377
858
  function getCurrentInstance() {
378
859
  return __currentInstance;
379
860
  }
380
861
  function setCurrentInstance(inst) {
381
862
  __currentInstance = inst;
382
863
  }
864
+ function getCurrentSetupContext() {
865
+ return __currentSetupContext;
866
+ }
867
+ function setCurrentSetupContext(ctx) {
868
+ __currentSetupContext = ctx;
869
+ }
383
870
  function ensureHookBucket(target) {
384
871
  if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
385
872
  return target.__wevuHooks;
@@ -437,6 +924,10 @@ function onShow(handler) {
437
924
  if (!__currentInstance) throw new Error("onShow() must be called synchronously inside setup()");
438
925
  pushHook(__currentInstance, "onShow", handler);
439
926
  }
927
+ function onLoad(handler) {
928
+ if (!__currentInstance) throw new Error("onLoad() must be called synchronously inside setup()");
929
+ pushHook(__currentInstance, "onLoad", handler);
930
+ }
440
931
  function onHide(handler) {
441
932
  if (!__currentInstance) throw new Error("onHide() must be called synchronously inside setup()");
442
933
  pushHook(__currentInstance, "onHide", handler);
@@ -449,6 +940,14 @@ function onReady(handler) {
449
940
  if (!__currentInstance) throw new Error("onReady() must be called synchronously inside setup()");
450
941
  pushHook(__currentInstance, "onReady", handler);
451
942
  }
943
+ function onPullDownRefresh(handler) {
944
+ if (!__currentInstance) throw new Error("onPullDownRefresh() must be called synchronously inside setup()");
945
+ pushHook(__currentInstance, "onPullDownRefresh", handler);
946
+ }
947
+ function onReachBottom(handler) {
948
+ if (!__currentInstance) throw new Error("onReachBottom() must be called synchronously inside setup()");
949
+ pushHook(__currentInstance, "onReachBottom", handler);
950
+ }
452
951
  function onPageScroll(handler) {
453
952
  if (!__currentInstance) throw new Error("onPageScroll() must be called synchronously inside setup()");
454
953
  pushHook(__currentInstance, "onPageScroll", handler);
@@ -461,6 +960,18 @@ function onTabItemTap(handler) {
461
960
  if (!__currentInstance) throw new Error("onTabItemTap() must be called synchronously inside setup()");
462
961
  pushHook(__currentInstance, "onTabItemTap", handler);
463
962
  }
963
+ function onResize(handler) {
964
+ if (!__currentInstance) throw new Error("onResize() must be called synchronously inside setup()");
965
+ pushHook(__currentInstance, "onResize", handler);
966
+ }
967
+ function onMoved(handler) {
968
+ if (!__currentInstance) throw new Error("onMoved() must be called synchronously inside setup()");
969
+ pushHook(__currentInstance, "onMoved", handler);
970
+ }
971
+ function onError(handler) {
972
+ if (!__currentInstance) throw new Error("onError() must be called synchronously inside setup()");
973
+ pushHook(__currentInstance, "onError", handler);
974
+ }
464
975
  function onSaveExitState(handler) {
465
976
  if (!__currentInstance) throw new Error("onSaveExitState() must be called synchronously inside setup()");
466
977
  pushHook(__currentInstance, "onSaveExitState", handler, { single: true });
@@ -633,11 +1144,35 @@ function registerWatches(runtime, watchMap, instance) {
633
1144
  }
634
1145
  return stops;
635
1146
  }
636
- function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
1147
+ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
637
1148
  if (target.__wevu) return target.__wevu;
638
- const runtime = runtimeApp.mount({ setData(payload) {
639
- if (typeof target.setData === "function") target.setData(payload);
640
- } });
1149
+ const createDeferredAdapter = (instance) => {
1150
+ let pending;
1151
+ let enabled = false;
1152
+ const adapter$1 = { setData(payload) {
1153
+ if (!enabled) {
1154
+ pending = {
1155
+ ...pending ?? {},
1156
+ ...payload
1157
+ };
1158
+ return;
1159
+ }
1160
+ if (typeof instance.setData === "function") return instance.setData(payload);
1161
+ } };
1162
+ adapter$1.__wevu_enableSetData = () => {
1163
+ enabled = true;
1164
+ if (pending && Object.keys(pending).length && typeof instance.setData === "function") {
1165
+ const payload = pending;
1166
+ pending = void 0;
1167
+ instance.setData(payload);
1168
+ }
1169
+ };
1170
+ return adapter$1;
1171
+ };
1172
+ const adapter = options?.deferSetData ? createDeferredAdapter(target) : { setData(payload) {
1173
+ if (typeof target.setData === "function") return target.setData(payload);
1174
+ } };
1175
+ const runtime = runtimeApp.mount({ ...adapter });
641
1176
  const runtimeProxy = runtime?.proxy ?? {};
642
1177
  const runtimeState = runtime?.state ?? {};
643
1178
  if (!runtime?.methods) try {
@@ -675,15 +1210,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
675
1210
  bindModel: runtimeBindModel.bind(runtimeWithDefaults),
676
1211
  watch: runtimeWatch.bind(runtimeWithDefaults),
677
1212
  instance: target,
678
- emit: (event, ...args) => {
679
- if (typeof target.triggerEvent === "function") target.triggerEvent(event, ...args);
1213
+ emit: (event, detail, options$1) => {
1214
+ if (typeof target.triggerEvent === "function") target.triggerEvent(event, detail, options$1);
680
1215
  },
681
1216
  expose: (exposed) => {
682
1217
  target.__wevuExposed = exposed;
683
1218
  },
684
- attrs: {}
1219
+ attrs: {},
1220
+ slots: Object.create(null)
685
1221
  };
686
1222
  setCurrentInstance(target);
1223
+ setCurrentSetupContext(context);
687
1224
  try {
688
1225
  const result = runSetupFunction(setup, props, context);
689
1226
  if (result && typeof result === "object") Object.keys(result).forEach((key) => {
@@ -692,6 +1229,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
692
1229
  else runtime.state[key] = val;
693
1230
  });
694
1231
  } finally {
1232
+ setCurrentSetupContext(void 0);
695
1233
  setCurrentInstance(void 0);
696
1234
  }
697
1235
  }
@@ -704,6 +1242,10 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
704
1242
  } catch {}
705
1243
  return runtime;
706
1244
  }
1245
+ function enableDeferredSetData(target) {
1246
+ const adapter = target.__wevu?.adapter;
1247
+ if (adapter && typeof adapter.__wevu_enableSetData === "function") adapter.__wevu_enableSetData();
1248
+ }
707
1249
  function teardownRuntimeInstance(target) {
708
1250
  const runtime = target.__wevu;
709
1251
  if (runtime && target.__wevuHooks) callHookList(target, "onUnload", []);
@@ -743,7 +1285,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
743
1285
  if (typeof userOnHide === "function") userOnHide.apply(this, args);
744
1286
  };
745
1287
  const userOnError = appOptions.onError;
746
- appOptions.onError = function onError(...args) {
1288
+ appOptions.onError = function onError$1(...args) {
747
1289
  callHookList(this, "onAppError", args);
748
1290
  if (typeof userOnError === "function") userOnError.apply(this, args);
749
1291
  };
@@ -760,7 +1302,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
760
1302
  }
761
1303
  App(appOptions);
762
1304
  }
763
- function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, features) {
1305
+ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
764
1306
  const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, options: userOptions = {}, ...rest } = mpOptions;
765
1307
  const userOnLoad = rest.onLoad;
766
1308
  const userOnUnload = rest.onUnload;
@@ -768,21 +1310,68 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
768
1310
  const userOnHide = rest.onHide;
769
1311
  const userOnReady = rest.onReady;
770
1312
  const userOnSaveExitState = rest.onSaveExitState;
1313
+ const userOnPullDownRefresh = rest.onPullDownRefresh;
1314
+ const userOnReachBottom = rest.onReachBottom;
771
1315
  const userOnPageScroll = rest.onPageScroll;
1316
+ const userOnRouteDone = rest.onRouteDone;
1317
+ const userOnTabItemTap = rest.onTabItemTap;
1318
+ const userOnResize = rest.onResize;
772
1319
  const userOnShareAppMessage = rest.onShareAppMessage;
773
1320
  const userOnShareTimeline = rest.onShareTimeline;
774
1321
  const userOnAddToFavorites = rest.onAddToFavorites;
1322
+ const features = rest.features ?? {};
775
1323
  const restOptions = { ...rest };
1324
+ const legacyCreated = restOptions.created;
1325
+ delete restOptions.features;
1326
+ delete restOptions.created;
776
1327
  delete restOptions.onLoad;
777
1328
  delete restOptions.onUnload;
778
1329
  delete restOptions.onShow;
779
1330
  delete restOptions.onHide;
780
1331
  delete restOptions.onReady;
781
- delete restOptions.onSaveExitState;
782
- delete restOptions.onPageScroll;
783
- delete restOptions.onShareAppMessage;
784
- delete restOptions.onShareTimeline;
785
- delete restOptions.onAddToFavorites;
1332
+ const enableOnPullDownRefresh = typeof userOnPullDownRefresh === "function" || Boolean(features.enableOnPullDownRefresh);
1333
+ const enableOnReachBottom = typeof userOnReachBottom === "function" || Boolean(features.enableOnReachBottom);
1334
+ const enableOnPageScroll = typeof userOnPageScroll === "function" || Boolean(features.enableOnPageScroll);
1335
+ const enableOnRouteDone = typeof userOnRouteDone === "function" || Boolean(features.enableOnRouteDone);
1336
+ const enableOnTabItemTap = typeof userOnTabItemTap === "function" || Boolean(features.enableOnTabItemTap);
1337
+ const enableOnResize = typeof userOnResize === "function" || Boolean(features.enableOnResize);
1338
+ const enableOnShareAppMessage = typeof userOnShareAppMessage === "function" || Boolean(features.enableOnShareAppMessage);
1339
+ const enableOnShareTimeline = typeof userOnShareTimeline === "function" || Boolean(features.enableOnShareTimeline);
1340
+ const enableOnAddToFavorites = typeof userOnAddToFavorites === "function" || Boolean(features.enableOnAddToFavorites);
1341
+ const enableOnSaveExitState = typeof userOnSaveExitState === "function" || Boolean(features.enableOnSaveExitState);
1342
+ const fallbackNoop = () => {};
1343
+ const fallbackShareContent = () => ({});
1344
+ const fallbackTimelineContent = () => ({});
1345
+ const effectiveOnSaveExitState = typeof userOnSaveExitState === "function" ? userOnSaveExitState : (() => ({ data: void 0 }));
1346
+ const effectiveOnPullDownRefresh = typeof userOnPullDownRefresh === "function" ? userOnPullDownRefresh : fallbackNoop;
1347
+ const effectiveOnReachBottom = typeof userOnReachBottom === "function" ? userOnReachBottom : fallbackNoop;
1348
+ const effectiveOnPageScroll = typeof userOnPageScroll === "function" ? userOnPageScroll : fallbackNoop;
1349
+ const effectiveOnRouteDone = typeof userOnRouteDone === "function" ? userOnRouteDone : fallbackNoop;
1350
+ const effectiveOnTabItemTap = typeof userOnTabItemTap === "function" ? userOnTabItemTap : fallbackNoop;
1351
+ const effectiveOnResize = typeof userOnResize === "function" ? userOnResize : fallbackNoop;
1352
+ const effectiveOnShareAppMessage = typeof userOnShareAppMessage === "function" ? userOnShareAppMessage : fallbackShareContent;
1353
+ const effectiveOnShareTimeline = typeof userOnShareTimeline === "function" ? userOnShareTimeline : fallbackTimelineContent;
1354
+ const effectiveOnAddToFavorites = typeof userOnAddToFavorites === "function" ? userOnAddToFavorites : (() => ({}));
1355
+ const hasHook = (target, name) => {
1356
+ const hooks = target.__wevuHooks;
1357
+ if (!hooks) return false;
1358
+ const entry = hooks[name];
1359
+ if (!entry) return false;
1360
+ if (Array.isArray(entry)) return entry.length > 0;
1361
+ return typeof entry === "function";
1362
+ };
1363
+ {
1364
+ const userExport = restOptions.export;
1365
+ restOptions.export = function __wevu_export() {
1366
+ const exposed = this.__wevuExposed ?? {};
1367
+ const base = typeof userExport === "function" ? userExport.call(this) : {};
1368
+ if (base && typeof base === "object" && !Array.isArray(base)) return {
1369
+ ...exposed,
1370
+ ...base
1371
+ };
1372
+ return base ?? exposed;
1373
+ };
1374
+ }
786
1375
  const finalOptions = {
787
1376
  multipleSlots: userOptions.multipleSlots ?? true,
788
1377
  ...userOptions
@@ -804,18 +1393,11 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
804
1393
  return result;
805
1394
  };
806
1395
  }
807
- const wrapSpecial = (name) => {
808
- const user = userLifetimes[name] ?? userPageLifetimes[name];
809
- finalMethods[name] = function wrapped(...args) {
810
- callHookList(this, name, args);
811
- if (typeof user === "function") return user.apply(this, args);
812
- };
813
- };
814
- wrapSpecial("onTabItemTap");
815
- wrapSpecial("onRouteDone");
816
1396
  const pageLifecycleHooks = {
817
1397
  onLoad(...args) {
818
1398
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
1399
+ enableDeferredSetData(this);
1400
+ callHookList(this, "onLoad", args);
819
1401
  if (typeof userOnLoad === "function") return userOnLoad.apply(this, args);
820
1402
  },
821
1403
  onUnload(...args) {
@@ -836,39 +1418,69 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
836
1418
  callHookList(this, "onReady", args);
837
1419
  }
838
1420
  if (typeof userOnReady === "function") return userOnReady.apply(this, args);
839
- },
840
- onSaveExitState(...args) {
841
- const ret = callHookReturn(this, "onSaveExitState", args);
842
- if (ret !== void 0) return ret;
843
- if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
844
1421
  }
845
1422
  };
846
- if (features?.listenPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
1423
+ if (enableOnSaveExitState) pageLifecycleHooks.onSaveExitState = function onSaveExitState$1(...args) {
1424
+ const ret = callHookReturn(this, "onSaveExitState", args);
1425
+ if (ret !== void 0) return ret;
1426
+ return effectiveOnSaveExitState.apply(this, args);
1427
+ };
1428
+ if (enableOnPullDownRefresh) pageLifecycleHooks.onPullDownRefresh = function onPullDownRefresh$1(...args) {
1429
+ callHookList(this, "onPullDownRefresh", args);
1430
+ if (!hasHook(this, "onPullDownRefresh")) return effectiveOnPullDownRefresh.apply(this, args);
1431
+ };
1432
+ if (enableOnReachBottom) pageLifecycleHooks.onReachBottom = function onReachBottom$1(...args) {
1433
+ callHookList(this, "onReachBottom", args);
1434
+ if (!hasHook(this, "onReachBottom")) return effectiveOnReachBottom.apply(this, args);
1435
+ };
1436
+ if (enableOnPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
847
1437
  callHookList(this, "onPageScroll", args);
848
- if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
1438
+ if (!hasHook(this, "onPageScroll")) return effectiveOnPageScroll.apply(this, args);
1439
+ };
1440
+ if (enableOnRouteDone) pageLifecycleHooks.onRouteDone = function onRouteDone$1(...args) {
1441
+ callHookList(this, "onRouteDone", args);
1442
+ if (!hasHook(this, "onRouteDone")) return effectiveOnRouteDone.apply(this, args);
1443
+ };
1444
+ if (enableOnTabItemTap) pageLifecycleHooks.onTabItemTap = function onTabItemTap$1(...args) {
1445
+ callHookList(this, "onTabItemTap", args);
1446
+ if (!hasHook(this, "onTabItemTap")) return effectiveOnTabItemTap.apply(this, args);
849
1447
  };
850
- if (features?.enableShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
1448
+ if (enableOnResize) pageLifecycleHooks.onResize = function onResize$1(...args) {
1449
+ callHookList(this, "onResize", args);
1450
+ if (!hasHook(this, "onResize")) return effectiveOnResize.apply(this, args);
1451
+ };
1452
+ if (enableOnShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
851
1453
  const ret = callHookReturn(this, "onShareAppMessage", args);
852
1454
  if (ret !== void 0) return ret;
853
- if (typeof userOnShareAppMessage === "function") return userOnShareAppMessage.apply(this, args);
1455
+ return effectiveOnShareAppMessage.apply(this, args);
854
1456
  };
855
- if (features?.enableShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
1457
+ if (enableOnShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
856
1458
  const ret = callHookReturn(this, "onShareTimeline", args);
857
1459
  if (ret !== void 0) return ret;
858
- if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
1460
+ return effectiveOnShareTimeline.apply(this, args);
859
1461
  };
860
- if (features?.enableAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
1462
+ if (enableOnAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
861
1463
  const ret = callHookReturn(this, "onAddToFavorites", args);
862
1464
  if (ret !== void 0) return ret;
863
- if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
1465
+ return effectiveOnAddToFavorites.apply(this, args);
864
1466
  };
865
1467
  Component({
866
1468
  ...restOptions,
867
1469
  ...pageLifecycleHooks,
868
1470
  lifetimes: {
869
1471
  ...userLifetimes,
1472
+ created: function created(...args) {
1473
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
1474
+ if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
1475
+ if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
1476
+ },
1477
+ moved: function moved(...args) {
1478
+ callHookList(this, "onMoved", args);
1479
+ if (typeof userLifetimes.moved === "function") userLifetimes.moved.apply(this, args);
1480
+ },
870
1481
  attached: function attached(...args) {
871
1482
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
1483
+ enableDeferredSetData(this);
872
1484
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
873
1485
  },
874
1486
  ready: function ready(...args) {
@@ -881,6 +1493,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
881
1493
  detached: function detached(...args) {
882
1494
  teardownRuntimeInstance(this);
883
1495
  if (typeof userLifetimes.detached === "function") userLifetimes.detached.apply(this, args);
1496
+ },
1497
+ error: function error(...args) {
1498
+ callHookList(this, "onError", args);
1499
+ if (typeof userLifetimes.error === "function") userLifetimes.error.apply(this, args);
884
1500
  }
885
1501
  },
886
1502
  pageLifetimes: {
@@ -892,6 +1508,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
892
1508
  hide: function hide(...args) {
893
1509
  callHookList(this, "onHide", args);
894
1510
  if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
1511
+ },
1512
+ resize: function resize(...args) {
1513
+ callHookList(this, "onResize", args);
1514
+ if (typeof userPageLifetimes.resize === "function") userPageLifetimes.resize.apply(this, args);
895
1515
  }
896
1516
  },
897
1517
  methods: finalMethods,
@@ -1126,7 +1746,6 @@ function setComputedValue(setters, key, value) {
1126
1746
  * @example
1127
1747
  * ```ts
1128
1748
  * defineComponent({
1129
- * features: { listenPageScroll: true },
1130
1749
  * setup() {
1131
1750
  * onPageScroll(() => {})
1132
1751
  * }
@@ -1134,7 +1753,7 @@ function setComputedValue(setters, key, value) {
1134
1753
  * ```
1135
1754
  */
1136
1755
  function defineComponent(options) {
1137
- const { features, data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1756
+ const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1138
1757
  const runtimeApp = createApp({
1139
1758
  data,
1140
1759
  computed: computed$1,
@@ -1151,10 +1770,9 @@ function defineComponent(options) {
1151
1770
  methods,
1152
1771
  watch: watch$1,
1153
1772
  setup: setupWrapper,
1154
- mpOptions: mpOptionsWithProps,
1155
- features
1773
+ mpOptions: mpOptionsWithProps
1156
1774
  };
1157
- registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps, features);
1775
+ registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
1158
1776
  return {
1159
1777
  __wevu_runtime: runtimeApp,
1160
1778
  __wevu_options: componentOptions
@@ -1224,6 +1842,13 @@ function normalizeProps(baseOptions, props, explicitProperties) {
1224
1842
  return;
1225
1843
  }
1226
1844
  if (typeof definition === "object") {
1845
+ if (key.endsWith("Modifiers") && Object.keys(definition).length === 0) {
1846
+ properties[key] = {
1847
+ type: Object,
1848
+ value: {}
1849
+ };
1850
+ return;
1851
+ }
1227
1852
  const propOptions = {};
1228
1853
  if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
1229
1854
  const defaultValue = "default" in definition ? definition.default : definition.value;
@@ -1314,4 +1939,281 @@ function injectGlobal(key, defaultValue) {
1314
1939
  }
1315
1940
 
1316
1941
  //#endregion
1317
- export { batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, 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, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
1942
+ //#region src/runtime/vueCompat.ts
1943
+ function useAttrs() {
1944
+ const ctx = getCurrentSetupContext();
1945
+ if (!ctx) throw new Error("useAttrs() must be called synchronously inside setup()");
1946
+ return ctx.attrs ?? {};
1947
+ }
1948
+ function useSlots() {
1949
+ const ctx = getCurrentSetupContext();
1950
+ if (!ctx) throw new Error("useSlots() must be called synchronously inside setup()");
1951
+ return ctx.slots ?? Object.create(null);
1952
+ }
1953
+ function useModel(props, name) {
1954
+ const ctx = getCurrentSetupContext();
1955
+ if (!ctx) throw new Error("useModel() must be called synchronously inside setup()");
1956
+ const emit = ctx.emit;
1957
+ const eventName = `update:${name}`;
1958
+ return customRef({
1959
+ get: () => props?.[name],
1960
+ set: (value) => {
1961
+ emit?.(eventName, value);
1962
+ }
1963
+ });
1964
+ }
1965
+ function mergeModels(a, b) {
1966
+ if (a == null) return b;
1967
+ if (b == null) return a;
1968
+ if (Array.isArray(a) && Array.isArray(b)) return Array.from(new Set([...a, ...b]));
1969
+ if (typeof a === "object" && typeof b === "object") return {
1970
+ ...a,
1971
+ ...b
1972
+ };
1973
+ return b;
1974
+ }
1975
+
1976
+ //#endregion
1977
+ //#region src/store/actions.ts
1978
+ function wrapAction(store, name, action, actionSubs) {
1979
+ return function wrapped(...args) {
1980
+ const afterCbs = [];
1981
+ const errorCbs = [];
1982
+ const after = (cb) => afterCbs.push(cb);
1983
+ const onError$1 = (cb) => errorCbs.push(cb);
1984
+ actionSubs.forEach((sub) => {
1985
+ try {
1986
+ sub({
1987
+ name,
1988
+ store,
1989
+ args,
1990
+ after,
1991
+ onError: onError$1
1992
+ });
1993
+ } catch {}
1994
+ });
1995
+ let res;
1996
+ try {
1997
+ res = action.apply(store, args);
1998
+ } catch (e) {
1999
+ errorCbs.forEach((cb) => cb(e));
2000
+ throw e;
2001
+ }
2002
+ const finalize = (r) => {
2003
+ afterCbs.forEach((cb) => cb(r));
2004
+ return r;
2005
+ };
2006
+ if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
2007
+ errorCbs.forEach((cb) => cb(e));
2008
+ return Promise.reject(e);
2009
+ });
2010
+ return finalize(res);
2011
+ };
2012
+ }
2013
+
2014
+ //#endregion
2015
+ //#region src/store/utils.ts
2016
+ function isObject(val) {
2017
+ return typeof val === "object" && val !== null;
2018
+ }
2019
+ function mergeShallow(target, patch) {
2020
+ for (const k in patch) target[k] = patch[k];
2021
+ }
2022
+
2023
+ //#endregion
2024
+ //#region src/store/base.ts
2025
+ function createBaseApi(id, stateObj, notify, resetImpl) {
2026
+ const api = { $id: id };
2027
+ Object.defineProperty(api, "$state", {
2028
+ get() {
2029
+ return stateObj;
2030
+ },
2031
+ set(v) {
2032
+ if (stateObj && isObject(v)) {
2033
+ mergeShallow(stateObj, v);
2034
+ notify("patch object");
2035
+ }
2036
+ }
2037
+ });
2038
+ api.$patch = (patch) => {
2039
+ if (!stateObj) {
2040
+ if (typeof patch === "function") {
2041
+ patch(api);
2042
+ notify("patch function");
2043
+ } else {
2044
+ mergeShallow(api, patch);
2045
+ notify("patch object");
2046
+ }
2047
+ return;
2048
+ }
2049
+ if (typeof patch === "function") {
2050
+ patch(stateObj);
2051
+ notify("patch function");
2052
+ } else {
2053
+ mergeShallow(stateObj, patch);
2054
+ notify("patch object");
2055
+ }
2056
+ };
2057
+ if (resetImpl) api.$reset = () => resetImpl();
2058
+ const subs = /* @__PURE__ */ new Set();
2059
+ api.$subscribe = (cb, _opts) => {
2060
+ subs.add(cb);
2061
+ return () => subs.delete(cb);
2062
+ };
2063
+ const actionSubs = /* @__PURE__ */ new Set();
2064
+ api.$onAction = (cb) => {
2065
+ actionSubs.add(cb);
2066
+ return () => actionSubs.delete(cb);
2067
+ };
2068
+ return {
2069
+ api,
2070
+ subs,
2071
+ actionSubs
2072
+ };
2073
+ }
2074
+
2075
+ //#endregion
2076
+ //#region src/store/manager.ts
2077
+ function createStore() {
2078
+ const manager = {
2079
+ _stores: /* @__PURE__ */ new Map(),
2080
+ _plugins: [],
2081
+ install(_app) {},
2082
+ use(plugin) {
2083
+ if (typeof plugin === "function") manager._plugins.push(plugin);
2084
+ return manager;
2085
+ }
2086
+ };
2087
+ createStore._instance = manager;
2088
+ return manager;
2089
+ }
2090
+
2091
+ //#endregion
2092
+ //#region src/store/define.ts
2093
+ function defineStore(id, setupOrOptions) {
2094
+ let instance;
2095
+ let created = false;
2096
+ const manager = createStore._instance;
2097
+ return function useStore() {
2098
+ if (created && instance) return instance;
2099
+ created = true;
2100
+ if (typeof setupOrOptions === "function") {
2101
+ const result = setupOrOptions();
2102
+ let notify$1 = () => {};
2103
+ const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
2104
+ notify$1 = (type) => {
2105
+ base$1.subs.forEach((cb) => {
2106
+ try {
2107
+ cb({
2108
+ type,
2109
+ storeId: id
2110
+ }, instance);
2111
+ } catch {}
2112
+ });
2113
+ };
2114
+ instance = Object.assign({}, result);
2115
+ for (const key of Object.getOwnPropertyNames(base$1.api)) {
2116
+ const d = Object.getOwnPropertyDescriptor(base$1.api, key);
2117
+ if (d) Object.defineProperty(instance, key, d);
2118
+ }
2119
+ Object.keys(result).forEach((k) => {
2120
+ const val = result[k];
2121
+ if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
2122
+ });
2123
+ const plugins$1 = manager?._plugins ?? [];
2124
+ for (const plugin of plugins$1) try {
2125
+ plugin({ store: instance });
2126
+ } catch {}
2127
+ return instance;
2128
+ }
2129
+ const options = setupOrOptions;
2130
+ const rawState = options.state ? options.state() : {};
2131
+ const state = reactive(rawState);
2132
+ const initialSnapshot = { ...toRaw(rawState) };
2133
+ let notify = () => {};
2134
+ const base = createBaseApi(id, state, (t) => notify(t), () => {
2135
+ mergeShallow(state, initialSnapshot);
2136
+ notify("patch object");
2137
+ });
2138
+ notify = (type) => {
2139
+ base.subs.forEach((cb) => {
2140
+ try {
2141
+ cb({
2142
+ type,
2143
+ storeId: id
2144
+ }, state);
2145
+ } catch {}
2146
+ });
2147
+ };
2148
+ const store = {};
2149
+ for (const key of Object.getOwnPropertyNames(base.api)) {
2150
+ const d = Object.getOwnPropertyDescriptor(base.api, key);
2151
+ if (d) Object.defineProperty(store, key, d);
2152
+ }
2153
+ const getterDefs = options.getters ?? {};
2154
+ const computedMap = {};
2155
+ Object.keys(getterDefs).forEach((key) => {
2156
+ const getter = getterDefs[key];
2157
+ if (typeof getter === "function") {
2158
+ const c = computed(() => getter.call(store, state));
2159
+ computedMap[key] = c;
2160
+ Object.defineProperty(store, key, {
2161
+ enumerable: true,
2162
+ configurable: true,
2163
+ get() {
2164
+ return c.value;
2165
+ }
2166
+ });
2167
+ }
2168
+ });
2169
+ const actionDefs = options.actions ?? {};
2170
+ Object.keys(actionDefs).forEach((key) => {
2171
+ const act = actionDefs[key];
2172
+ if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
2173
+ return act.apply(store, args);
2174
+ }, base.actionSubs);
2175
+ });
2176
+ Object.keys(state).forEach((k) => {
2177
+ Object.defineProperty(store, k, {
2178
+ enumerable: true,
2179
+ configurable: true,
2180
+ get() {
2181
+ return state[k];
2182
+ },
2183
+ set(v) {
2184
+ state[k] = v;
2185
+ }
2186
+ });
2187
+ });
2188
+ instance = store;
2189
+ const plugins = manager?._plugins ?? [];
2190
+ for (const plugin of plugins) try {
2191
+ plugin({ store: instance });
2192
+ } catch {}
2193
+ return instance;
2194
+ };
2195
+ }
2196
+
2197
+ //#endregion
2198
+ //#region src/store/storeToRefs.ts
2199
+ function storeToRefs(store) {
2200
+ const result = {};
2201
+ for (const key in store) {
2202
+ const value = store[key];
2203
+ if (typeof value === "function") {
2204
+ result[key] = value;
2205
+ continue;
2206
+ }
2207
+ if (isRef(value)) result[key] = value;
2208
+ else result[key] = computed({
2209
+ get: () => store[key],
2210
+ set: (v) => {
2211
+ store[key] = v;
2212
+ }
2213
+ });
2214
+ }
2215
+ return result;
2216
+ }
2217
+
2218
+ //#endregion
2219
+ export { batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mergeModels, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLoad, onMounted, onMoved, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setCurrentSetupContext, setDeepWatchStrategy, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, useAttrs, useModel, useSlots, watch, watchEffect };