@vue-mini/core 1.2.7 → 1.3.0-alpha.1

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-mini v1.2.7
2
+ * vue-mini v1.3.0-alpha.1
3
3
  * https://github.com/vue-mini/vue-mini
4
4
  * (c) 2019-present Yang Mingshan
5
5
  * @license MIT
@@ -7,7 +7,7 @@
7
7
  'use strict';
8
8
 
9
9
  /**
10
- * @vue/shared v3.5.24
10
+ * @vue/shared v3.6.0-alpha.5
11
11
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
12
12
  * @license MIT
13
13
  **/
@@ -22,12 +22,6 @@ const EMPTY_OBJ$1 = Object.freeze({}) ;
22
22
  const NOOP = () => {
23
23
  };
24
24
  const extend$1 = Object.assign;
25
- const remove = (arr, el) => {
26
- const i = arr.indexOf(el);
27
- if (i > -1) {
28
- arr.splice(i, 1);
29
- }
30
- };
31
25
  const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
32
26
  const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
33
27
  const isArray$1 = Array.isArray;
@@ -65,7 +59,7 @@ const def = (obj, key, value, writable = false) => {
65
59
  };
66
60
 
67
61
  /**
68
- * @vue/reactivity v3.5.24
62
+ * @vue/reactivity v3.6.0-alpha.5
69
63
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
70
64
  * @license MIT
71
65
  **/
@@ -74,600 +68,338 @@ function warn(msg, ...args) {
74
68
  console.warn(`[Vue warn] ${msg}`, ...args);
75
69
  }
76
70
 
77
- let activeEffectScope;
78
- class EffectScope {
79
- constructor(detached = false) {
80
- this.detached = detached;
81
- /**
82
- * @internal
83
- */
84
- this._active = true;
85
- /**
86
- * @internal track `on` calls, allow `on` call multiple times
87
- */
88
- this._on = 0;
89
- /**
90
- * @internal
91
- */
92
- this.effects = [];
93
- /**
94
- * @internal
95
- */
96
- this.cleanups = [];
97
- this._isPaused = false;
98
- this.parent = activeEffectScope;
99
- if (!detached && activeEffectScope) {
100
- this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
101
- this
102
- ) - 1;
103
- }
104
- }
105
- get active() {
106
- return this._active;
107
- }
108
- pause() {
109
- if (this._active) {
110
- this._isPaused = true;
111
- let i, l;
112
- if (this.scopes) {
113
- for (i = 0, l = this.scopes.length; i < l; i++) {
114
- this.scopes[i].pause();
115
- }
116
- }
117
- for (i = 0, l = this.effects.length; i < l; i++) {
118
- this.effects[i].pause();
119
- }
120
- }
121
- }
122
- /**
123
- * Resumes the effect scope, including all child scopes and effects.
124
- */
125
- resume() {
126
- if (this._active) {
127
- if (this._isPaused) {
128
- this._isPaused = false;
129
- let i, l;
130
- if (this.scopes) {
131
- for (i = 0, l = this.scopes.length; i < l; i++) {
132
- this.scopes[i].resume();
133
- }
134
- }
135
- for (i = 0, l = this.effects.length; i < l; i++) {
136
- this.effects[i].resume();
137
- }
138
- }
139
- }
140
- }
141
- run(fn) {
142
- if (this._active) {
143
- const currentEffectScope = activeEffectScope;
144
- try {
145
- activeEffectScope = this;
146
- return fn();
147
- } finally {
148
- activeEffectScope = currentEffectScope;
149
- }
150
- } else {
151
- warn(`cannot run an inactive effect scope.`);
152
- }
153
- }
154
- /**
155
- * This should only be called on non-detached scopes
156
- * @internal
157
- */
158
- on() {
159
- if (++this._on === 1) {
160
- this.prevScope = activeEffectScope;
161
- activeEffectScope = this;
162
- }
163
- }
164
- /**
165
- * This should only be called on non-detached scopes
166
- * @internal
167
- */
168
- off() {
169
- if (this._on > 0 && --this._on === 0) {
170
- activeEffectScope = this.prevScope;
171
- this.prevScope = void 0;
172
- }
173
- }
174
- stop(fromParent) {
175
- if (this._active) {
176
- this._active = false;
177
- let i, l;
178
- for (i = 0, l = this.effects.length; i < l; i++) {
179
- this.effects[i].stop();
180
- }
181
- this.effects.length = 0;
182
- for (i = 0, l = this.cleanups.length; i < l; i++) {
183
- this.cleanups[i]();
184
- }
185
- this.cleanups.length = 0;
186
- if (this.scopes) {
187
- for (i = 0, l = this.scopes.length; i < l; i++) {
188
- this.scopes[i].stop(true);
189
- }
190
- this.scopes.length = 0;
191
- }
192
- if (!this.detached && this.parent && !fromParent) {
193
- const last = this.parent.scopes.pop();
194
- if (last && last !== this) {
195
- this.parent.scopes[this.index] = last;
196
- last.index = this.index;
197
- }
198
- }
199
- this.parent = void 0;
200
- }
201
- }
202
- }
203
- function effectScope(detached) {
204
- return new EffectScope(detached);
205
- }
206
- function getCurrentScope() {
207
- return activeEffectScope;
208
- }
209
- function onScopeDispose(fn, failSilently = false) {
210
- if (activeEffectScope) {
211
- activeEffectScope.cleanups.push(fn);
212
- } else if (!failSilently) {
213
- warn(
214
- `onScopeDispose() is called when there is no active effect scope to be associated with.`
215
- );
216
- }
217
- }
218
-
219
- let activeSub;
220
- const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
221
- class ReactiveEffect {
222
- constructor(fn) {
223
- this.fn = fn;
224
- /**
225
- * @internal
226
- */
227
- this.deps = void 0;
228
- /**
229
- * @internal
230
- */
231
- this.depsTail = void 0;
232
- /**
233
- * @internal
234
- */
235
- this.flags = 1 | 4;
236
- /**
237
- * @internal
238
- */
239
- this.next = void 0;
240
- /**
241
- * @internal
242
- */
243
- this.cleanup = void 0;
244
- this.scheduler = void 0;
245
- if (activeEffectScope && activeEffectScope.active) {
246
- activeEffectScope.effects.push(this);
247
- }
248
- }
249
- pause() {
250
- this.flags |= 64;
251
- }
252
- resume() {
253
- if (this.flags & 64) {
254
- this.flags &= -65;
255
- if (pausedQueueEffects.has(this)) {
256
- pausedQueueEffects.delete(this);
257
- this.trigger();
258
- }
259
- }
260
- }
261
- /**
262
- * @internal
263
- */
264
- notify() {
265
- if (this.flags & 2 && !(this.flags & 32)) {
266
- return;
267
- }
268
- if (!(this.flags & 8)) {
269
- batch(this);
270
- }
271
- }
272
- run() {
273
- if (!(this.flags & 1)) {
274
- return this.fn();
275
- }
276
- this.flags |= 2;
277
- cleanupEffect(this);
278
- prepareDeps(this);
279
- const prevEffect = activeSub;
280
- const prevShouldTrack = shouldTrack;
281
- activeSub = this;
282
- shouldTrack = true;
283
- try {
284
- return this.fn();
285
- } finally {
286
- if (activeSub !== this) {
287
- warn(
288
- "Active effect was not restored correctly - this is likely a Vue internal bug."
289
- );
290
- }
291
- cleanupDeps(this);
292
- activeSub = prevEffect;
293
- shouldTrack = prevShouldTrack;
294
- this.flags &= -3;
295
- }
296
- }
297
- stop() {
298
- if (this.flags & 1) {
299
- for (let link = this.deps; link; link = link.nextDep) {
300
- removeSub(link);
301
- }
302
- this.deps = this.depsTail = void 0;
303
- cleanupEffect(this);
304
- this.onStop && this.onStop();
305
- this.flags &= -2;
306
- }
307
- }
308
- trigger() {
309
- if (this.flags & 64) {
310
- pausedQueueEffects.add(this);
311
- } else if (this.scheduler) {
312
- this.scheduler();
313
- } else {
314
- this.runIfDirty();
315
- }
316
- }
317
- /**
318
- * @internal
319
- */
320
- runIfDirty() {
321
- if (isDirty(this)) {
322
- this.run();
323
- }
324
- }
325
- get dirty() {
326
- return isDirty(this);
327
- }
328
- }
71
+ var ReactiveFlags$1 = /* @__PURE__ */ ((ReactiveFlags2) => {
72
+ ReactiveFlags2[ReactiveFlags2["None"] = 0] = "None";
73
+ ReactiveFlags2[ReactiveFlags2["Mutable"] = 1] = "Mutable";
74
+ ReactiveFlags2[ReactiveFlags2["Watching"] = 2] = "Watching";
75
+ ReactiveFlags2[ReactiveFlags2["RecursedCheck"] = 4] = "RecursedCheck";
76
+ ReactiveFlags2[ReactiveFlags2["Recursed"] = 8] = "Recursed";
77
+ ReactiveFlags2[ReactiveFlags2["Dirty"] = 16] = "Dirty";
78
+ ReactiveFlags2[ReactiveFlags2["Pending"] = 32] = "Pending";
79
+ return ReactiveFlags2;
80
+ })(ReactiveFlags$1 || {});
81
+ const notifyBuffer = [];
329
82
  let batchDepth = 0;
330
- let batchedSub;
331
- let batchedComputed;
332
- function batch(sub, isComputed = false) {
333
- sub.flags |= 8;
334
- if (isComputed) {
335
- sub.next = batchedComputed;
336
- batchedComputed = sub;
337
- return;
83
+ let activeSub = void 0;
84
+ let globalVersion = 0;
85
+ let notifyIndex = 0;
86
+ let notifyBufferLength = 0;
87
+ function setActiveSub(sub) {
88
+ try {
89
+ return activeSub;
90
+ } finally {
91
+ activeSub = sub;
338
92
  }
339
- sub.next = batchedSub;
340
- batchedSub = sub;
341
93
  }
342
94
  function startBatch() {
343
- batchDepth++;
95
+ ++batchDepth;
344
96
  }
345
97
  function endBatch() {
346
- if (--batchDepth > 0) {
347
- return;
348
- }
349
- if (batchedComputed) {
350
- let e = batchedComputed;
351
- batchedComputed = void 0;
352
- while (e) {
353
- const next = e.next;
354
- e.next = void 0;
355
- e.flags &= -9;
356
- e = next;
357
- }
358
- }
359
- let error;
360
- while (batchedSub) {
361
- let e = batchedSub;
362
- batchedSub = void 0;
363
- while (e) {
364
- const next = e.next;
365
- e.next = void 0;
366
- e.flags &= -9;
367
- if (e.flags & 1) {
368
- try {
369
- ;
370
- e.trigger();
371
- } catch (err) {
372
- if (!error) error = err;
373
- }
374
- }
375
- e = next;
376
- }
98
+ if (!--batchDepth && notifyBufferLength) {
99
+ flush();
377
100
  }
378
- if (error) throw error;
379
101
  }
380
- function prepareDeps(sub) {
381
- for (let link = sub.deps; link; link = link.nextDep) {
382
- link.version = -1;
383
- link.prevActiveLink = link.dep.activeLink;
384
- link.dep.activeLink = link;
385
- }
386
- }
387
- function cleanupDeps(sub) {
388
- let head;
389
- let tail = sub.depsTail;
390
- let link = tail;
391
- while (link) {
392
- const prev = link.prevDep;
393
- if (link.version === -1) {
394
- if (link === tail) tail = prev;
395
- removeSub(link);
396
- removeDep(link);
397
- } else {
398
- head = link;
399
- }
400
- link.dep.activeLink = link.prevActiveLink;
401
- link.prevActiveLink = void 0;
402
- link = prev;
403
- }
404
- sub.deps = head;
405
- sub.depsTail = tail;
406
- }
407
- function isDirty(sub) {
408
- for (let link = sub.deps; link; link = link.nextDep) {
409
- if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
410
- return true;
411
- }
412
- }
413
- if (sub._dirty) {
414
- return true;
415
- }
416
- return false;
417
- }
418
- function refreshComputed(computed) {
419
- if (computed.flags & 4 && !(computed.flags & 16)) {
102
+ function link(dep, sub) {
103
+ const prevDep = sub.depsTail;
104
+ if (prevDep !== void 0 && prevDep.dep === dep) {
420
105
  return;
421
106
  }
422
- computed.flags &= -17;
423
- if (computed.globalVersion === globalVersion) {
107
+ const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
108
+ if (nextDep !== void 0 && nextDep.dep === dep) {
109
+ nextDep.version = globalVersion;
110
+ sub.depsTail = nextDep;
424
111
  return;
425
112
  }
426
- computed.globalVersion = globalVersion;
427
- if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
113
+ const prevSub = dep.subsTail;
114
+ if (prevSub !== void 0 && prevSub.version === globalVersion && prevSub.sub === sub) {
428
115
  return;
429
116
  }
430
- computed.flags |= 2;
431
- const dep = computed.dep;
432
- const prevSub = activeSub;
433
- const prevShouldTrack = shouldTrack;
434
- activeSub = computed;
435
- shouldTrack = true;
436
- try {
437
- prepareDeps(computed);
438
- const value = computed.fn(computed._value);
439
- if (dep.version === 0 || hasChanged(value, computed._value)) {
440
- computed.flags |= 128;
441
- computed._value = value;
442
- dep.version++;
443
- }
444
- } catch (err) {
445
- dep.version++;
446
- throw err;
447
- } finally {
448
- activeSub = prevSub;
449
- shouldTrack = prevShouldTrack;
450
- cleanupDeps(computed);
451
- computed.flags &= -3;
452
- }
453
- }
454
- function removeSub(link, soft = false) {
455
- const { dep, prevSub, nextSub } = link;
456
- if (prevSub) {
457
- prevSub.nextSub = nextSub;
458
- link.prevSub = void 0;
459
- }
460
- if (nextSub) {
461
- nextSub.prevSub = prevSub;
462
- link.nextSub = void 0;
463
- }
464
- if (dep.subsHead === link) {
465
- dep.subsHead = nextSub;
117
+ const newLink = sub.depsTail = dep.subsTail = {
118
+ version: globalVersion,
119
+ dep,
120
+ sub,
121
+ prevDep,
122
+ nextDep,
123
+ prevSub,
124
+ nextSub: void 0
125
+ };
126
+ if (nextDep !== void 0) {
127
+ nextDep.prevDep = newLink;
466
128
  }
467
- if (dep.subs === link) {
468
- dep.subs = prevSub;
469
- if (!prevSub && dep.computed) {
470
- dep.computed.flags &= -5;
471
- for (let l = dep.computed.deps; l; l = l.nextDep) {
472
- removeSub(l, true);
473
- }
474
- }
129
+ if (prevDep !== void 0) {
130
+ prevDep.nextDep = newLink;
131
+ } else {
132
+ sub.deps = newLink;
475
133
  }
476
- if (!soft && !--dep.sc && dep.map) {
477
- dep.map.delete(dep.key);
134
+ if (prevSub !== void 0) {
135
+ prevSub.nextSub = newLink;
136
+ } else {
137
+ dep.subs = newLink;
478
138
  }
479
139
  }
480
- function removeDep(link) {
481
- const { prevDep, nextDep } = link;
482
- if (prevDep) {
483
- prevDep.nextDep = nextDep;
484
- link.prevDep = void 0;
485
- }
486
- if (nextDep) {
140
+ function unlink(link2, sub = link2.sub) {
141
+ const dep = link2.dep;
142
+ const prevDep = link2.prevDep;
143
+ const nextDep = link2.nextDep;
144
+ const nextSub = link2.nextSub;
145
+ const prevSub = link2.prevSub;
146
+ if (nextDep !== void 0) {
487
147
  nextDep.prevDep = prevDep;
488
- link.nextDep = void 0;
489
- }
490
- }
491
- function effect(fn, options) {
492
- if (fn.effect instanceof ReactiveEffect) {
493
- fn = fn.effect.fn;
494
- }
495
- const e = new ReactiveEffect(fn);
496
- if (options) {
497
- extend$1(e, options);
498
- }
499
- try {
500
- e.run();
501
- } catch (err) {
502
- e.stop();
503
- throw err;
504
- }
505
- const runner = e.run.bind(e);
506
- runner.effect = e;
507
- return runner;
508
- }
509
- function stop(runner) {
510
- runner.effect.stop();
511
- }
512
- let shouldTrack = true;
513
- const trackStack = [];
514
- function pauseTracking() {
515
- trackStack.push(shouldTrack);
516
- shouldTrack = false;
517
- }
518
- function resetTracking() {
519
- const last = trackStack.pop();
520
- shouldTrack = last === void 0 ? true : last;
521
- }
522
- function cleanupEffect(e) {
523
- const { cleanup } = e;
524
- e.cleanup = void 0;
525
- if (cleanup) {
526
- const prevSub = activeSub;
527
- activeSub = void 0;
528
- try {
529
- cleanup();
530
- } finally {
531
- activeSub = prevSub;
532
- }
148
+ } else {
149
+ sub.depsTail = prevDep;
533
150
  }
534
- }
535
-
536
- let globalVersion = 0;
537
- class Link {
538
- constructor(sub, dep) {
539
- this.sub = sub;
540
- this.dep = dep;
541
- this.version = dep.version;
542
- this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
151
+ if (prevDep !== void 0) {
152
+ prevDep.nextDep = nextDep;
153
+ } else {
154
+ sub.deps = nextDep;
543
155
  }
544
- }
545
- class Dep {
546
- // TODO isolatedDeclarations "__v_skip"
547
- constructor(computed) {
548
- this.computed = computed;
549
- this.version = 0;
550
- /**
551
- * Link between this dep and the current active effect
552
- */
553
- this.activeLink = void 0;
554
- /**
555
- * Doubly linked list representing the subscribing effects (tail)
556
- */
557
- this.subs = void 0;
558
- /**
559
- * For object property deps cleanup
560
- */
561
- this.map = void 0;
562
- this.key = void 0;
563
- /**
564
- * Subscriber counter
565
- */
566
- this.sc = 0;
567
- /**
568
- * @internal
569
- */
570
- this.__v_skip = true;
571
- {
572
- this.subsHead = void 0;
573
- }
156
+ if (nextSub !== void 0) {
157
+ nextSub.prevSub = prevSub;
158
+ } else {
159
+ dep.subsTail = prevSub;
574
160
  }
575
- track(debugInfo) {
576
- if (!activeSub || !shouldTrack || activeSub === this.computed) {
577
- return;
578
- }
579
- let link = this.activeLink;
580
- if (link === void 0 || link.sub !== activeSub) {
581
- link = this.activeLink = new Link(activeSub, this);
582
- if (!activeSub.deps) {
583
- activeSub.deps = activeSub.depsTail = link;
161
+ if (prevSub !== void 0) {
162
+ prevSub.nextSub = nextSub;
163
+ } else if ((dep.subs = nextSub) === void 0) {
164
+ let toRemove = dep.deps;
165
+ if (toRemove !== void 0) {
166
+ do {
167
+ toRemove = unlink(toRemove, dep);
168
+ } while (toRemove !== void 0);
169
+ dep.flags |= 16 /* Dirty */;
170
+ }
171
+ }
172
+ return nextDep;
173
+ }
174
+ function propagate(link2) {
175
+ let next = link2.nextSub;
176
+ let stack;
177
+ top: do {
178
+ const sub = link2.sub;
179
+ let flags = sub.flags;
180
+ if (flags & (1 /* Mutable */ | 2 /* Watching */)) {
181
+ if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */ | 16 /* Dirty */ | 32 /* Pending */))) {
182
+ sub.flags = flags | 32 /* Pending */;
183
+ } else if (!(flags & (4 /* RecursedCheck */ | 8 /* Recursed */))) {
184
+ flags = 0 /* None */;
185
+ } else if (!(flags & 4 /* RecursedCheck */)) {
186
+ sub.flags = flags & -9 /* Recursed */ | 32 /* Pending */;
187
+ } else if (!(flags & (16 /* Dirty */ | 32 /* Pending */)) && isValidLink(link2, sub)) {
188
+ sub.flags = flags | 8 /* Recursed */ | 32 /* Pending */;
189
+ flags &= 1 /* Mutable */;
584
190
  } else {
585
- link.prevDep = activeSub.depsTail;
586
- activeSub.depsTail.nextDep = link;
587
- activeSub.depsTail = link;
191
+ flags = 0 /* None */;
588
192
  }
589
- addSub(link);
590
- } else if (link.version === -1) {
591
- link.version = this.version;
592
- if (link.nextDep) {
593
- const next = link.nextDep;
594
- next.prevDep = link.prevDep;
595
- if (link.prevDep) {
596
- link.prevDep.nextDep = next;
597
- }
598
- link.prevDep = activeSub.depsTail;
599
- link.nextDep = void 0;
600
- activeSub.depsTail.nextDep = link;
601
- activeSub.depsTail = link;
602
- if (activeSub.deps === link) {
603
- activeSub.deps = next;
193
+ if (flags & 2 /* Watching */) {
194
+ notifyBuffer[notifyBufferLength++] = sub;
195
+ }
196
+ if (flags & 1 /* Mutable */) {
197
+ const subSubs = sub.subs;
198
+ if (subSubs !== void 0) {
199
+ link2 = subSubs;
200
+ if (subSubs.nextSub !== void 0) {
201
+ stack = { value: next, prev: stack };
202
+ next = link2.nextSub;
203
+ }
204
+ continue;
604
205
  }
605
206
  }
606
207
  }
607
- if (activeSub.onTrack) {
608
- activeSub.onTrack(
609
- extend$1(
610
- {
611
- effect: activeSub
612
- },
613
- debugInfo
614
- )
615
- );
208
+ if ((link2 = next) !== void 0) {
209
+ next = link2.nextSub;
210
+ continue;
616
211
  }
617
- return link;
618
- }
619
- trigger(debugInfo) {
620
- this.version++;
621
- globalVersion++;
622
- this.notify(debugInfo);
212
+ while (stack !== void 0) {
213
+ link2 = stack.value;
214
+ stack = stack.prev;
215
+ if (link2 !== void 0) {
216
+ next = link2.nextSub;
217
+ continue top;
218
+ }
219
+ }
220
+ break;
221
+ } while (true);
222
+ }
223
+ function startTracking(sub) {
224
+ ++globalVersion;
225
+ sub.depsTail = void 0;
226
+ sub.flags = sub.flags & -57 | 4 /* RecursedCheck */;
227
+ return setActiveSub(sub);
228
+ }
229
+ function endTracking(sub, prevSub) {
230
+ if (activeSub !== sub) {
231
+ warn(
232
+ "Active effect was not restored correctly - this is likely a Vue internal bug."
233
+ );
623
234
  }
624
- notify(debugInfo) {
625
- startBatch();
626
- try {
627
- if (!!("development" !== "production")) {
628
- for (let head = this.subsHead; head; head = head.nextSub) {
629
- if (head.sub.onTrigger && !(head.sub.flags & 8)) {
630
- head.sub.onTrigger(
631
- extend$1(
632
- {
633
- effect: head.sub
634
- },
635
- debugInfo
636
- )
637
- );
235
+ activeSub = prevSub;
236
+ const depsTail = sub.depsTail;
237
+ let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
238
+ while (toRemove !== void 0) {
239
+ toRemove = unlink(toRemove, sub);
240
+ }
241
+ sub.flags &= -5 /* RecursedCheck */;
242
+ }
243
+ function flush() {
244
+ while (notifyIndex < notifyBufferLength) {
245
+ const effect = notifyBuffer[notifyIndex];
246
+ notifyBuffer[notifyIndex++] = void 0;
247
+ effect.notify();
248
+ }
249
+ notifyIndex = 0;
250
+ notifyBufferLength = 0;
251
+ }
252
+ function checkDirty(link2, sub) {
253
+ let stack;
254
+ let checkDepth = 0;
255
+ top: do {
256
+ const dep = link2.dep;
257
+ const depFlags = dep.flags;
258
+ let dirty = false;
259
+ if (sub.flags & 16 /* Dirty */) {
260
+ dirty = true;
261
+ } else if ((depFlags & (1 /* Mutable */ | 16 /* Dirty */)) === (1 /* Mutable */ | 16 /* Dirty */)) {
262
+ if (dep.update()) {
263
+ const subs = dep.subs;
264
+ if (subs.nextSub !== void 0) {
265
+ shallowPropagate(subs);
266
+ }
267
+ dirty = true;
268
+ }
269
+ } else if ((depFlags & (1 /* Mutable */ | 32 /* Pending */)) === (1 /* Mutable */ | 32 /* Pending */)) {
270
+ if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
271
+ stack = { value: link2, prev: stack };
272
+ }
273
+ link2 = dep.deps;
274
+ sub = dep;
275
+ ++checkDepth;
276
+ continue;
277
+ }
278
+ if (!dirty && link2.nextDep !== void 0) {
279
+ link2 = link2.nextDep;
280
+ continue;
281
+ }
282
+ while (checkDepth) {
283
+ --checkDepth;
284
+ const firstSub = sub.subs;
285
+ const hasMultipleSubs = firstSub.nextSub !== void 0;
286
+ if (hasMultipleSubs) {
287
+ link2 = stack.value;
288
+ stack = stack.prev;
289
+ } else {
290
+ link2 = firstSub;
291
+ }
292
+ if (dirty) {
293
+ if (sub.update()) {
294
+ if (hasMultipleSubs) {
295
+ shallowPropagate(firstSub);
638
296
  }
297
+ sub = link2.sub;
298
+ continue;
639
299
  }
300
+ } else {
301
+ sub.flags &= -33 /* Pending */;
640
302
  }
641
- for (let link = this.subs; link; link = link.prevSub) {
642
- if (link.sub.notify()) {
643
- ;
644
- link.sub.dep.notify();
645
- }
303
+ sub = link2.sub;
304
+ if (link2.nextDep !== void 0) {
305
+ link2 = link2.nextDep;
306
+ continue top;
646
307
  }
647
- } finally {
648
- endBatch();
308
+ dirty = false;
309
+ }
310
+ return dirty;
311
+ } while (true);
312
+ }
313
+ function shallowPropagate(link2) {
314
+ do {
315
+ const sub = link2.sub;
316
+ const nextSub = link2.nextSub;
317
+ const subFlags = sub.flags;
318
+ if ((subFlags & (32 /* Pending */ | 16 /* Dirty */)) === 32 /* Pending */) {
319
+ sub.flags = subFlags | 16 /* Dirty */;
320
+ }
321
+ link2 = nextSub;
322
+ } while (link2 !== void 0);
323
+ }
324
+ function isValidLink(checkLink, sub) {
325
+ let link2 = sub.depsTail;
326
+ while (link2 !== void 0) {
327
+ if (link2 === checkLink) {
328
+ return true;
649
329
  }
330
+ link2 = link2.prevDep;
650
331
  }
332
+ return false;
651
333
  }
652
- function addSub(link) {
653
- link.dep.sc++;
654
- if (link.sub.flags & 4) {
655
- const computed = link.dep.computed;
656
- if (computed && !link.dep.subs) {
657
- computed.flags |= 4 | 16;
658
- for (let l = computed.deps; l; l = l.nextDep) {
659
- addSub(l);
660
- }
334
+
335
+ const triggerEventInfos = [];
336
+ function onTrack(sub, debugInfo) {
337
+ if (sub.onTrack) {
338
+ sub.onTrack(
339
+ extend$1(
340
+ {
341
+ effect: sub
342
+ },
343
+ debugInfo
344
+ )
345
+ );
346
+ }
347
+ }
348
+ function onTrigger(sub) {
349
+ if (sub.onTrigger) {
350
+ const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
351
+ sub.onTrigger(
352
+ extend$1(
353
+ {
354
+ effect: sub
355
+ },
356
+ debugInfo
357
+ )
358
+ );
359
+ }
360
+ }
361
+ function setupOnTrigger(target) {
362
+ Object.defineProperty(target.prototype, "onTrigger", {
363
+ get() {
364
+ return this._onTrigger;
365
+ },
366
+ set(val) {
367
+ if (val && !this._onTrigger) setupFlagsHandler(this);
368
+ this._onTrigger = val;
661
369
  }
662
- const currentTail = link.dep.subs;
663
- if (currentTail !== link) {
664
- link.prevSub = currentTail;
665
- if (currentTail) currentTail.nextSub = link;
370
+ });
371
+ }
372
+ function setupFlagsHandler(target) {
373
+ target._flags = target.flags;
374
+ Object.defineProperty(target, "flags", {
375
+ get() {
376
+ return target._flags;
377
+ },
378
+ set(value) {
379
+ if (!(target._flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) && !!(value & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending))) {
380
+ onTrigger(this);
381
+ }
382
+ target._flags = value;
666
383
  }
667
- if (link.dep.subsHead === void 0) {
668
- link.dep.subsHead = link;
384
+ });
385
+ }
386
+
387
+ class Dep {
388
+ constructor(map, key) {
389
+ this.map = map;
390
+ this.key = key;
391
+ this._subs = void 0;
392
+ this.subsTail = void 0;
393
+ this.flags = ReactiveFlags$1.None;
394
+ }
395
+ get subs() {
396
+ return this._subs;
397
+ }
398
+ set subs(value) {
399
+ this._subs = value;
400
+ if (value === void 0) {
401
+ this.map.delete(this.key);
669
402
  }
670
- link.dep.subs = link;
671
403
  }
672
404
  }
673
405
  const targetMap = /* @__PURE__ */ new WeakMap();
@@ -681,36 +413,34 @@ const ARRAY_ITERATE_KEY = Symbol(
681
413
  "Array iterate"
682
414
  );
683
415
  function track(target, type, key) {
684
- if (shouldTrack && activeSub) {
416
+ if (activeSub !== void 0) {
685
417
  let depsMap = targetMap.get(target);
686
418
  if (!depsMap) {
687
419
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
688
420
  }
689
421
  let dep = depsMap.get(key);
690
422
  if (!dep) {
691
- depsMap.set(key, dep = new Dep());
692
- dep.map = depsMap;
693
- dep.key = key;
423
+ depsMap.set(key, dep = new Dep(depsMap, key));
694
424
  }
695
425
  {
696
- dep.track({
426
+ onTrack(activeSub, {
697
427
  target,
698
428
  type,
699
429
  key
700
430
  });
701
431
  }
432
+ link(dep, activeSub);
702
433
  }
703
434
  }
704
435
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
705
436
  const depsMap = targetMap.get(target);
706
437
  if (!depsMap) {
707
- globalVersion++;
708
438
  return;
709
439
  }
710
440
  const run = (dep) => {
711
- if (dep) {
441
+ if (dep !== void 0 && dep.subs !== void 0) {
712
442
  {
713
- dep.trigger({
443
+ triggerEventInfos.push({
714
444
  target,
715
445
  type,
716
446
  key,
@@ -719,6 +449,11 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
719
449
  oldTarget
720
450
  });
721
451
  }
452
+ propagate(dep.subs);
453
+ shallowPropagate(dep.subs);
454
+ {
455
+ triggerEventInfos.pop();
456
+ }
722
457
  }
723
458
  };
724
459
  startBatch();
@@ -785,10 +520,16 @@ function shallowReadArray(arr) {
785
520
  track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
786
521
  return arr;
787
522
  }
523
+ function toWrapped(target, item) {
524
+ if (isReadonly(target)) {
525
+ return isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
526
+ }
527
+ return toReactive(item);
528
+ }
788
529
  const arrayInstrumentations = {
789
530
  __proto__: null,
790
531
  [Symbol.iterator]() {
791
- return iterator(this, Symbol.iterator, toReactive);
532
+ return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
792
533
  },
793
534
  concat(...args) {
794
535
  return reactiveReadArray(this).concat(
@@ -797,7 +538,7 @@ const arrayInstrumentations = {
797
538
  },
798
539
  entries() {
799
540
  return iterator(this, "entries", (value) => {
800
- value[1] = toReactive(value[1]);
541
+ value[1] = toWrapped(this, value[1]);
801
542
  return value;
802
543
  });
803
544
  },
@@ -805,16 +546,37 @@ const arrayInstrumentations = {
805
546
  return apply(this, "every", fn, thisArg, void 0, arguments);
806
547
  },
807
548
  filter(fn, thisArg) {
808
- return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
549
+ return apply(
550
+ this,
551
+ "filter",
552
+ fn,
553
+ thisArg,
554
+ (v) => v.map((item) => toWrapped(this, item)),
555
+ arguments
556
+ );
809
557
  },
810
558
  find(fn, thisArg) {
811
- return apply(this, "find", fn, thisArg, toReactive, arguments);
559
+ return apply(
560
+ this,
561
+ "find",
562
+ fn,
563
+ thisArg,
564
+ (item) => toWrapped(this, item),
565
+ arguments
566
+ );
812
567
  },
813
568
  findIndex(fn, thisArg) {
814
569
  return apply(this, "findIndex", fn, thisArg, void 0, arguments);
815
570
  },
816
571
  findLast(fn, thisArg) {
817
- return apply(this, "findLast", fn, thisArg, toReactive, arguments);
572
+ return apply(
573
+ this,
574
+ "findLast",
575
+ fn,
576
+ thisArg,
577
+ (item) => toWrapped(this, item),
578
+ arguments
579
+ );
818
580
  },
819
581
  findLastIndex(fn, thisArg) {
820
582
  return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
@@ -874,7 +636,7 @@ const arrayInstrumentations = {
874
636
  return noTracking(this, "unshift", args);
875
637
  },
876
638
  values() {
877
- return iterator(this, "values", toReactive);
639
+ return iterator(this, "values", (item) => toWrapped(this, item));
878
640
  }
879
641
  };
880
642
  function iterator(self, method, wrapValue) {
@@ -905,7 +667,7 @@ function apply(self, method, fn, thisArg, wrappedRetFn, args) {
905
667
  if (arr !== self) {
906
668
  if (needsWrap) {
907
669
  wrappedFn = function(item, index) {
908
- return fn.call(this, toReactive(item), index, self);
670
+ return fn.call(this, toWrapped(self, item), index, self);
909
671
  };
910
672
  } else if (fn.length > 2) {
911
673
  wrappedFn = function(item, index) {
@@ -922,7 +684,7 @@ function reduce(self, method, fn, args) {
922
684
  if (arr !== self) {
923
685
  if (!isShallow(self)) {
924
686
  wrappedFn = function(acc, item, index) {
925
- return fn.call(this, acc, toReactive(item), index, self);
687
+ return fn.call(this, acc, toWrapped(self, item), index, self);
926
688
  };
927
689
  } else if (fn.length > 3) {
928
690
  wrappedFn = function(acc, item, index) {
@@ -943,11 +705,11 @@ function searchProxy(self, method, args) {
943
705
  return res;
944
706
  }
945
707
  function noTracking(self, method, args = []) {
946
- pauseTracking();
947
708
  startBatch();
709
+ const prevSub = setActiveSub();
948
710
  const res = toRaw(self)[method].apply(self, args);
711
+ setActiveSub(prevSub);
949
712
  endBatch();
950
- resetTracking();
951
713
  return res;
952
714
  }
953
715
 
@@ -993,14 +755,18 @@ class BaseReactiveHandler {
993
755
  return hasOwnProperty;
994
756
  }
995
757
  }
758
+ const wasRef = isRef(target);
996
759
  const res = Reflect.get(
997
760
  target,
998
761
  key,
999
762
  // if this is a proxy wrapping a ref, return methods using the raw ref
1000
763
  // as receiver so that we don't have to call `toRaw` on the ref in all
1001
764
  // its class methods
1002
- isRef(target) ? target : receiver
765
+ wasRef ? target : receiver
1003
766
  );
767
+ if (wasRef && key !== "value") {
768
+ return res;
769
+ }
1004
770
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
1005
771
  return res;
1006
772
  }
@@ -1026,13 +792,14 @@ class MutableReactiveHandler extends BaseReactiveHandler {
1026
792
  }
1027
793
  set(target, key, value, receiver) {
1028
794
  let oldValue = target[key];
795
+ const isArrayWithIntegerKey = isArray$1(target) && isIntegerKey(key);
1029
796
  if (!this._isShallow) {
1030
797
  const isOldValueReadonly = isReadonly(oldValue);
1031
798
  if (!isShallow(value) && !isReadonly(value)) {
1032
799
  oldValue = toRaw(oldValue);
1033
800
  value = toRaw(value);
1034
801
  }
1035
- if (!isArray$1(target) && isRef(oldValue) && !isRef(value)) {
802
+ if (!isArrayWithIntegerKey && isRef(oldValue) && !isRef(value)) {
1036
803
  if (isOldValueReadonly) {
1037
804
  {
1038
805
  warn(
@@ -1047,7 +814,7 @@ class MutableReactiveHandler extends BaseReactiveHandler {
1047
814
  }
1048
815
  }
1049
816
  }
1050
- const hadKey = isArray$1(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
817
+ const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
1051
818
  const result = Reflect.set(
1052
819
  target,
1053
820
  key,
@@ -1459,33 +1226,47 @@ function isRef(r) {
1459
1226
  return r ? r["__v_isRef"] === true : false;
1460
1227
  }
1461
1228
  function ref(value) {
1462
- return createRef(value, false);
1229
+ return createRef(value, toReactive);
1463
1230
  }
1464
1231
  function shallowRef(value) {
1465
- return createRef(value, true);
1232
+ return createRef(value);
1466
1233
  }
1467
- function createRef(rawValue, shallow) {
1234
+ function createRef(rawValue, wrap) {
1468
1235
  if (isRef(rawValue)) {
1469
1236
  return rawValue;
1470
1237
  }
1471
- return new RefImpl(rawValue, shallow);
1238
+ return new RefImpl(rawValue, wrap);
1472
1239
  }
1473
1240
  class RefImpl {
1474
- constructor(value, isShallow2) {
1475
- this.dep = new Dep();
1476
- this["__v_isRef"] = true;
1477
- this["__v_isShallow"] = false;
1478
- this._rawValue = isShallow2 ? value : toRaw(value);
1479
- this._value = isShallow2 ? value : toReactive(value);
1480
- this["__v_isShallow"] = isShallow2;
1241
+ // TODO isolatedDeclarations "__v_isShallow"
1242
+ constructor(value, wrap) {
1243
+ this.subs = void 0;
1244
+ this.subsTail = void 0;
1245
+ this.flags = ReactiveFlags$1.Mutable;
1246
+ /**
1247
+ * @internal
1248
+ */
1249
+ this.__v_isRef = true;
1250
+ // TODO isolatedDeclarations "__v_isRef"
1251
+ /**
1252
+ * @internal
1253
+ */
1254
+ this.__v_isShallow = false;
1255
+ this._oldValue = this._rawValue = wrap ? toRaw(value) : value;
1256
+ this._value = wrap ? wrap(value) : value;
1257
+ this._wrap = wrap;
1258
+ this["__v_isShallow"] = !wrap;
1259
+ }
1260
+ get dep() {
1261
+ return this;
1481
1262
  }
1482
1263
  get value() {
1483
- {
1484
- this.dep.track({
1485
- target: this,
1486
- type: "get",
1487
- key: "value"
1488
- });
1264
+ trackRef(this);
1265
+ if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
1266
+ const subs = this.subs;
1267
+ if (subs !== void 0) {
1268
+ shallowPropagate(subs);
1269
+ }
1489
1270
  }
1490
1271
  return this._value;
1491
1272
  }
@@ -1494,30 +1275,55 @@ class RefImpl {
1494
1275
  const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1495
1276
  newValue = useDirectValue ? newValue : toRaw(newValue);
1496
1277
  if (hasChanged(newValue, oldValue)) {
1278
+ this.flags |= ReactiveFlags$1.Dirty;
1497
1279
  this._rawValue = newValue;
1498
- this._value = useDirectValue ? newValue : toReactive(newValue);
1499
- {
1500
- this.dep.trigger({
1501
- target: this,
1502
- type: "set",
1503
- key: "value",
1504
- newValue,
1505
- oldValue
1506
- });
1280
+ this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
1281
+ const subs = this.subs;
1282
+ if (subs !== void 0) {
1283
+ {
1284
+ triggerEventInfos.push({
1285
+ target: this,
1286
+ type: "set",
1287
+ key: "value",
1288
+ newValue,
1289
+ oldValue
1290
+ });
1291
+ }
1292
+ propagate(subs);
1293
+ if (!batchDepth) {
1294
+ flush();
1295
+ }
1296
+ {
1297
+ triggerEventInfos.pop();
1298
+ }
1507
1299
  }
1508
1300
  }
1509
1301
  }
1302
+ update() {
1303
+ this.flags &= ~ReactiveFlags$1.Dirty;
1304
+ return hasChanged(this._oldValue, this._oldValue = this._rawValue);
1305
+ }
1510
1306
  }
1511
1307
  function triggerRef(ref2) {
1512
- if (ref2.dep) {
1308
+ const dep = ref2.dep;
1309
+ if (dep !== void 0 && dep.subs !== void 0) {
1310
+ propagate(dep.subs);
1311
+ shallowPropagate(dep.subs);
1312
+ if (!batchDepth) {
1313
+ flush();
1314
+ }
1315
+ }
1316
+ }
1317
+ function trackRef(dep) {
1318
+ if (activeSub !== void 0) {
1513
1319
  {
1514
- ref2.dep.trigger({
1515
- target: ref2,
1516
- type: "set",
1517
- key: "value",
1518
- newValue: ref2._value
1320
+ onTrack(activeSub, {
1321
+ target: dep,
1322
+ type: "get",
1323
+ key: "value"
1519
1324
  });
1520
1325
  }
1326
+ link(dep, activeSub);
1521
1327
  }
1522
1328
  }
1523
1329
  function unref(ref2) {
@@ -1543,13 +1349,21 @@ function proxyRefs(objectWithRefs) {
1543
1349
  }
1544
1350
  class CustomRefImpl {
1545
1351
  constructor(factory) {
1352
+ this.subs = void 0;
1353
+ this.subsTail = void 0;
1354
+ this.flags = ReactiveFlags$1.None;
1546
1355
  this["__v_isRef"] = true;
1547
1356
  this._value = void 0;
1548
- const dep = this.dep = new Dep();
1549
- const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1357
+ const { get, set } = factory(
1358
+ () => trackRef(this),
1359
+ () => triggerRef(this)
1360
+ );
1550
1361
  this._get = get;
1551
1362
  this._set = set;
1552
1363
  }
1364
+ get dep() {
1365
+ return this;
1366
+ }
1553
1367
  get value() {
1554
1368
  return this._value = this._get();
1555
1369
  }
@@ -1561,9 +1375,6 @@ function customRef(factory) {
1561
1375
  return new CustomRefImpl(factory);
1562
1376
  }
1563
1377
  function toRefs(object) {
1564
- if (!isProxy(object)) {
1565
- warn(`toRefs() expects a reactive object but received a plain one.`);
1566
- }
1567
1378
  const ret = isArray$1(object) ? new Array(object.length) : {};
1568
1379
  for (const key in object) {
1569
1380
  ret[key] = propertyToRef(object, key);
@@ -1577,108 +1388,391 @@ class ObjectRefImpl {
1577
1388
  this._defaultValue = _defaultValue;
1578
1389
  this["__v_isRef"] = true;
1579
1390
  this._value = void 0;
1391
+ this._raw = toRaw(_object);
1392
+ let shallow = true;
1393
+ let obj = _object;
1394
+ if (!isArray$1(_object) || !isIntegerKey(String(_key))) {
1395
+ do {
1396
+ shallow = !isProxy(obj) || isShallow(obj);
1397
+ } while (shallow && (obj = obj["__v_raw"]));
1398
+ }
1399
+ this._shallow = shallow;
1580
1400
  }
1581
1401
  get value() {
1582
- const val = this._object[this._key];
1402
+ let val = this._object[this._key];
1403
+ if (this._shallow) {
1404
+ val = unref(val);
1405
+ }
1583
1406
  return this._value = val === void 0 ? this._defaultValue : val;
1584
1407
  }
1585
1408
  set value(newVal) {
1409
+ if (this._shallow && isRef(this._raw[this._key])) {
1410
+ const nestedRef = this._object[this._key];
1411
+ if (isRef(nestedRef)) {
1412
+ nestedRef.value = newVal;
1413
+ return;
1414
+ }
1415
+ }
1586
1416
  this._object[this._key] = newVal;
1587
1417
  }
1588
- get dep() {
1589
- return getDepFromReactive(toRaw(this._object), this._key);
1418
+ get dep() {
1419
+ return getDepFromReactive(this._raw, this._key);
1420
+ }
1421
+ }
1422
+ class GetterRefImpl {
1423
+ constructor(_getter) {
1424
+ this._getter = _getter;
1425
+ this["__v_isRef"] = true;
1426
+ this["__v_isReadonly"] = true;
1427
+ this._value = void 0;
1428
+ }
1429
+ get value() {
1430
+ return this._value = this._getter();
1431
+ }
1432
+ }
1433
+ function toRef(source, key, defaultValue) {
1434
+ if (isRef(source)) {
1435
+ return source;
1436
+ } else if (isFunction$1(source)) {
1437
+ return new GetterRefImpl(source);
1438
+ } else if (isObject$1(source) && arguments.length > 1) {
1439
+ return propertyToRef(source, key, defaultValue);
1440
+ } else {
1441
+ return ref(source);
1442
+ }
1443
+ }
1444
+ function propertyToRef(source, key, defaultValue) {
1445
+ return new ObjectRefImpl(source, key, defaultValue);
1446
+ }
1447
+
1448
+ const EffectFlags = {
1449
+ "ALLOW_RECURSE": 128,
1450
+ "PAUSED": 256};
1451
+ class ReactiveEffect {
1452
+ constructor(fn) {
1453
+ this.deps = void 0;
1454
+ this.depsTail = void 0;
1455
+ this.subs = void 0;
1456
+ this.subsTail = void 0;
1457
+ this.flags = ReactiveFlags$1.Watching | ReactiveFlags$1.Dirty;
1458
+ /**
1459
+ * @internal
1460
+ */
1461
+ this.cleanups = [];
1462
+ /**
1463
+ * @internal
1464
+ */
1465
+ this.cleanupsLength = 0;
1466
+ if (fn !== void 0) {
1467
+ this.fn = fn;
1468
+ }
1469
+ if (activeEffectScope) {
1470
+ link(this, activeEffectScope);
1471
+ }
1472
+ }
1473
+ // @ts-expect-error
1474
+ fn() {
1475
+ }
1476
+ get active() {
1477
+ return !(this.flags & 1024);
1478
+ }
1479
+ pause() {
1480
+ this.flags |= 256;
1481
+ }
1482
+ resume() {
1483
+ const flags = this.flags &= -257;
1484
+ if (flags & (ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending)) {
1485
+ this.notify();
1486
+ }
1487
+ }
1488
+ notify() {
1489
+ if (!(this.flags & 256) && this.dirty) {
1490
+ this.run();
1491
+ }
1492
+ }
1493
+ run() {
1494
+ if (!this.active) {
1495
+ return this.fn();
1496
+ }
1497
+ cleanup(this);
1498
+ const prevSub = startTracking(this);
1499
+ try {
1500
+ return this.fn();
1501
+ } finally {
1502
+ endTracking(this, prevSub);
1503
+ const flags = this.flags;
1504
+ if ((flags & (ReactiveFlags$1.Recursed | 128)) === (ReactiveFlags$1.Recursed | 128)) {
1505
+ this.flags = flags & ~ReactiveFlags$1.Recursed;
1506
+ this.notify();
1507
+ }
1508
+ }
1509
+ }
1510
+ stop() {
1511
+ if (!this.active) {
1512
+ return;
1513
+ }
1514
+ this.flags = 1024;
1515
+ let dep = this.deps;
1516
+ while (dep !== void 0) {
1517
+ dep = unlink(dep, this);
1518
+ }
1519
+ const sub = this.subs;
1520
+ if (sub !== void 0) {
1521
+ unlink(sub);
1522
+ }
1523
+ cleanup(this);
1524
+ }
1525
+ get dirty() {
1526
+ const flags = this.flags;
1527
+ if (flags & ReactiveFlags$1.Dirty) {
1528
+ return true;
1529
+ }
1530
+ if (flags & ReactiveFlags$1.Pending) {
1531
+ if (checkDirty(this.deps, this)) {
1532
+ this.flags = flags | ReactiveFlags$1.Dirty;
1533
+ return true;
1534
+ } else {
1535
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1536
+ }
1537
+ }
1538
+ return false;
1539
+ }
1540
+ }
1541
+ {
1542
+ setupOnTrigger(ReactiveEffect);
1543
+ }
1544
+ function effect(fn, options) {
1545
+ if (fn.effect instanceof ReactiveEffect) {
1546
+ fn = fn.effect.fn;
1547
+ }
1548
+ const e = new ReactiveEffect(fn);
1549
+ if (options) {
1550
+ const { onStop, scheduler } = options;
1551
+ if (onStop) {
1552
+ options.onStop = void 0;
1553
+ const stop2 = e.stop.bind(e);
1554
+ e.stop = () => {
1555
+ stop2();
1556
+ onStop();
1557
+ };
1558
+ }
1559
+ if (scheduler) {
1560
+ options.scheduler = void 0;
1561
+ e.notify = () => {
1562
+ if (!(e.flags & 256)) {
1563
+ scheduler();
1564
+ }
1565
+ };
1566
+ }
1567
+ extend$1(e, options);
1568
+ }
1569
+ try {
1570
+ e.run();
1571
+ } catch (err) {
1572
+ e.stop();
1573
+ throw err;
1574
+ }
1575
+ const runner = e.run.bind(e);
1576
+ runner.effect = e;
1577
+ return runner;
1578
+ }
1579
+ function stop(runner) {
1580
+ runner.effect.stop();
1581
+ }
1582
+ function cleanup(sub) {
1583
+ const l = sub.cleanupsLength;
1584
+ if (l) {
1585
+ for (let i = 0; i < l; i++) {
1586
+ sub.cleanups[i]();
1587
+ }
1588
+ sub.cleanupsLength = 0;
1589
+ }
1590
+ }
1591
+
1592
+ let activeEffectScope;
1593
+ class EffectScope {
1594
+ constructor(detached = false) {
1595
+ this.deps = void 0;
1596
+ this.depsTail = void 0;
1597
+ this.subs = void 0;
1598
+ this.subsTail = void 0;
1599
+ this.flags = 0;
1600
+ /**
1601
+ * @internal
1602
+ */
1603
+ this.cleanups = [];
1604
+ /**
1605
+ * @internal
1606
+ */
1607
+ this.cleanupsLength = 0;
1608
+ if (!detached && activeEffectScope) {
1609
+ link(this, activeEffectScope);
1610
+ }
1611
+ }
1612
+ get active() {
1613
+ return !(this.flags & 1024);
1614
+ }
1615
+ pause() {
1616
+ if (!(this.flags & 256)) {
1617
+ this.flags |= 256;
1618
+ for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
1619
+ const dep = link2.dep;
1620
+ if ("pause" in dep) {
1621
+ dep.pause();
1622
+ }
1623
+ }
1624
+ }
1625
+ }
1626
+ /**
1627
+ * Resumes the effect scope, including all child scopes and effects.
1628
+ */
1629
+ resume() {
1630
+ const flags = this.flags;
1631
+ if (flags & 256) {
1632
+ this.flags = flags & -257;
1633
+ for (let link2 = this.deps; link2 !== void 0; link2 = link2.nextDep) {
1634
+ const dep = link2.dep;
1635
+ if ("resume" in dep) {
1636
+ dep.resume();
1637
+ }
1638
+ }
1639
+ }
1640
+ }
1641
+ run(fn) {
1642
+ const prevScope = activeEffectScope;
1643
+ try {
1644
+ activeEffectScope = this;
1645
+ return fn();
1646
+ } finally {
1647
+ activeEffectScope = prevScope;
1648
+ }
1649
+ }
1650
+ stop() {
1651
+ if (!this.active) {
1652
+ return;
1653
+ }
1654
+ this.flags = 1024;
1655
+ let dep = this.deps;
1656
+ while (dep !== void 0) {
1657
+ const node = dep.dep;
1658
+ if ("stop" in node) {
1659
+ dep = dep.nextDep;
1660
+ node.stop();
1661
+ } else {
1662
+ dep = unlink(dep, this);
1663
+ }
1664
+ }
1665
+ const sub = this.subs;
1666
+ if (sub !== void 0) {
1667
+ unlink(sub);
1668
+ }
1669
+ cleanup(this);
1590
1670
  }
1591
1671
  }
1592
- class GetterRefImpl {
1593
- constructor(_getter) {
1594
- this._getter = _getter;
1595
- this["__v_isRef"] = true;
1596
- this["__v_isReadonly"] = true;
1597
- this._value = void 0;
1598
- }
1599
- get value() {
1600
- return this._value = this._getter();
1601
- }
1672
+ function effectScope(detached) {
1673
+ return new EffectScope(detached);
1602
1674
  }
1603
- function toRef(source, key, defaultValue) {
1604
- if (isRef(source)) {
1605
- return source;
1606
- } else if (isFunction$1(source)) {
1607
- return new GetterRefImpl(source);
1608
- } else if (isObject$1(source) && arguments.length > 1) {
1609
- return propertyToRef(source, key, defaultValue);
1610
- } else {
1611
- return ref(source);
1675
+ function getCurrentScope() {
1676
+ return activeEffectScope;
1677
+ }
1678
+ function setCurrentScope(scope) {
1679
+ try {
1680
+ return activeEffectScope;
1681
+ } finally {
1682
+ activeEffectScope = scope;
1612
1683
  }
1613
1684
  }
1614
- function propertyToRef(source, key, defaultValue) {
1615
- const val = source[key];
1616
- return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1685
+ function onScopeDispose(fn, failSilently = false) {
1686
+ if (activeEffectScope !== void 0) {
1687
+ activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
1688
+ } else if (!failSilently) {
1689
+ warn(
1690
+ `onScopeDispose() is called when there is no active effect scope to be associated with.`
1691
+ );
1692
+ }
1617
1693
  }
1618
1694
 
1619
1695
  class ComputedRefImpl {
1620
- constructor(fn, setter, isSSR) {
1696
+ constructor(fn, setter) {
1621
1697
  this.fn = fn;
1622
1698
  this.setter = setter;
1623
1699
  /**
1624
1700
  * @internal
1625
1701
  */
1626
1702
  this._value = void 0;
1627
- /**
1628
- * @internal
1629
- */
1630
- this.dep = new Dep(this);
1631
- /**
1632
- * @internal
1633
- */
1634
- this.__v_isRef = true;
1635
- // TODO isolatedDeclarations "__v_isReadonly"
1636
- // A computed is also a subscriber that tracks other deps
1637
- /**
1638
- * @internal
1639
- */
1703
+ this.subs = void 0;
1704
+ this.subsTail = void 0;
1640
1705
  this.deps = void 0;
1641
- /**
1642
- * @internal
1643
- */
1644
1706
  this.depsTail = void 0;
1707
+ this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
1645
1708
  /**
1646
1709
  * @internal
1647
1710
  */
1648
- this.flags = 16;
1649
- /**
1650
- * @internal
1651
- */
1652
- this.globalVersion = globalVersion - 1;
1653
- /**
1654
- * @internal
1655
- */
1656
- this.next = void 0;
1657
- // for backwards compat
1658
- this.effect = this;
1711
+ this.__v_isRef = true;
1659
1712
  this["__v_isReadonly"] = !setter;
1660
- this.isSSR = isSSR;
1713
+ }
1714
+ // TODO isolatedDeclarations "__v_isReadonly"
1715
+ // for backwards compat
1716
+ get effect() {
1717
+ return this;
1718
+ }
1719
+ // for backwards compat
1720
+ get dep() {
1721
+ return this;
1661
1722
  }
1662
1723
  /**
1663
1724
  * @internal
1725
+ * for backwards compat
1664
1726
  */
1665
- notify() {
1666
- this.flags |= 16;
1667
- if (!(this.flags & 8) && // avoid infinite self recursion
1668
- activeSub !== this) {
1669
- batch(this, true);
1727
+ get _dirty() {
1728
+ const flags = this.flags;
1729
+ if (flags & ReactiveFlags$1.Dirty) {
1670
1730
  return true;
1671
1731
  }
1732
+ if (flags & ReactiveFlags$1.Pending) {
1733
+ if (checkDirty(this.deps, this)) {
1734
+ this.flags = flags | ReactiveFlags$1.Dirty;
1735
+ return true;
1736
+ } else {
1737
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1738
+ }
1739
+ }
1740
+ return false;
1741
+ }
1742
+ /**
1743
+ * @internal
1744
+ * for backwards compat
1745
+ */
1746
+ set _dirty(v) {
1747
+ if (v) {
1748
+ this.flags |= ReactiveFlags$1.Dirty;
1749
+ } else {
1750
+ this.flags &= ~(ReactiveFlags$1.Dirty | ReactiveFlags$1.Pending);
1751
+ }
1672
1752
  }
1673
1753
  get value() {
1674
- const link = this.dep.track({
1675
- target: this,
1676
- type: "get",
1677
- key: "value"
1678
- }) ;
1679
- refreshComputed(this);
1680
- if (link) {
1681
- link.version = this.dep.version;
1754
+ const flags = this.flags;
1755
+ if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
1756
+ if (this.update()) {
1757
+ const subs = this.subs;
1758
+ if (subs !== void 0) {
1759
+ shallowPropagate(subs);
1760
+ }
1761
+ }
1762
+ } else if (flags & ReactiveFlags$1.Pending) {
1763
+ this.flags = flags & ~ReactiveFlags$1.Pending;
1764
+ }
1765
+ if (activeSub !== void 0) {
1766
+ {
1767
+ onTrack(activeSub, {
1768
+ target: this,
1769
+ type: "get",
1770
+ key: "value"
1771
+ });
1772
+ }
1773
+ link(this, activeSub);
1774
+ } else if (activeEffectScope !== void 0) {
1775
+ link(this, activeEffectScope);
1682
1776
  }
1683
1777
  return this._value;
1684
1778
  }
@@ -1689,6 +1783,23 @@ class ComputedRefImpl {
1689
1783
  warn("Write operation failed: computed value is readonly");
1690
1784
  }
1691
1785
  }
1786
+ update() {
1787
+ const prevSub = startTracking(this);
1788
+ try {
1789
+ const oldValue = this._value;
1790
+ const newValue = this.fn(oldValue);
1791
+ if (hasChanged(oldValue, newValue)) {
1792
+ this._value = newValue;
1793
+ return true;
1794
+ }
1795
+ return false;
1796
+ } finally {
1797
+ endTracking(this, prevSub);
1798
+ }
1799
+ }
1800
+ }
1801
+ {
1802
+ setupOnTrigger(ComputedRefImpl);
1692
1803
  }
1693
1804
  function computed(getterOrOptions, debugOptions, isSSR = false) {
1694
1805
  let getter;
@@ -1699,7 +1810,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
1699
1810
  getter = getterOrOptions.get;
1700
1811
  setter = getterOrOptions.set;
1701
1812
  }
1702
- const cRef = new ComputedRefImpl(getter, setter, isSSR);
1813
+ const cRef = new ComputedRefImpl(getter, setter);
1703
1814
  if (debugOptions && !isSSR) {
1704
1815
  cRef.onTrack = debugOptions.onTrack;
1705
1816
  cRef.onTrigger = debugOptions.onTrigger;
@@ -1719,177 +1830,146 @@ const TriggerOpTypes = {
1719
1830
  "CLEAR": "clear"
1720
1831
  };
1721
1832
  const INITIAL_WATCHER_VALUE = {};
1722
- const cleanupMap = /* @__PURE__ */ new WeakMap();
1723
1833
  let activeWatcher = void 0;
1724
1834
  function getCurrentWatcher() {
1725
1835
  return activeWatcher;
1726
1836
  }
1727
1837
  function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1728
1838
  if (owner) {
1729
- let cleanups = cleanupMap.get(owner);
1730
- if (!cleanups) cleanupMap.set(owner, cleanups = []);
1731
- cleanups.push(cleanupFn);
1839
+ const { call } = owner.options;
1840
+ if (call) {
1841
+ owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
1842
+ } else {
1843
+ owner.cleanups[owner.cleanupsLength++] = cleanupFn;
1844
+ }
1732
1845
  } else if (!failSilently) {
1733
1846
  warn(
1734
1847
  `onWatcherCleanup() was called when there was no active watcher to associate with.`
1735
1848
  );
1736
1849
  }
1737
1850
  }
1738
- function watch$1(source, cb, options = EMPTY_OBJ$1) {
1739
- const { immediate, deep, once, scheduler, augmentJob, call } = options;
1740
- const warnInvalidSource = (s) => {
1741
- (options.onWarn || warn)(
1742
- `Invalid watch source: `,
1743
- s,
1744
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1745
- );
1746
- };
1747
- const reactiveGetter = (source2) => {
1748
- if (deep) return source2;
1749
- if (isShallow(source2) || deep === false || deep === 0)
1750
- return traverse(source2, 1);
1751
- return traverse(source2);
1752
- };
1753
- let effect;
1754
- let getter;
1755
- let cleanup;
1756
- let boundCleanup;
1757
- let forceTrigger = false;
1758
- let isMultiSource = false;
1759
- if (isRef(source)) {
1760
- getter = () => source.value;
1761
- forceTrigger = isShallow(source);
1762
- } else if (isReactive(source)) {
1763
- getter = () => reactiveGetter(source);
1764
- forceTrigger = true;
1765
- } else if (isArray$1(source)) {
1766
- isMultiSource = true;
1767
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1768
- getter = () => source.map((s) => {
1769
- if (isRef(s)) {
1770
- return s.value;
1771
- } else if (isReactive(s)) {
1772
- return reactiveGetter(s);
1773
- } else if (isFunction$1(s)) {
1774
- return call ? call(s, 2) : s();
1851
+ class WatcherEffect extends ReactiveEffect {
1852
+ constructor(source, cb, options = EMPTY_OBJ$1) {
1853
+ const { deep, once, call, onWarn } = options;
1854
+ let getter;
1855
+ let forceTrigger = false;
1856
+ let isMultiSource = false;
1857
+ if (isRef(source)) {
1858
+ getter = () => source.value;
1859
+ forceTrigger = isShallow(source);
1860
+ } else if (isReactive(source)) {
1861
+ getter = () => reactiveGetter(source, deep);
1862
+ forceTrigger = true;
1863
+ } else if (isArray$1(source)) {
1864
+ isMultiSource = true;
1865
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1866
+ getter = () => source.map((s) => {
1867
+ if (isRef(s)) {
1868
+ return s.value;
1869
+ } else if (isReactive(s)) {
1870
+ return reactiveGetter(s, deep);
1871
+ } else if (isFunction$1(s)) {
1872
+ return call ? call(s, 2) : s();
1873
+ } else {
1874
+ warnInvalidSource(s, onWarn);
1875
+ }
1876
+ });
1877
+ } else if (isFunction$1(source)) {
1878
+ if (cb) {
1879
+ getter = call ? () => call(source, 2) : source;
1775
1880
  } else {
1776
- warnInvalidSource(s);
1777
- }
1778
- });
1779
- } else if (isFunction$1(source)) {
1780
- if (cb) {
1781
- getter = call ? () => call(source, 2) : source;
1782
- } else {
1783
- getter = () => {
1784
- if (cleanup) {
1785
- pauseTracking();
1881
+ getter = () => {
1882
+ if (this.cleanupsLength) {
1883
+ const prevSub = setActiveSub();
1884
+ try {
1885
+ cleanup(this);
1886
+ } finally {
1887
+ setActiveSub(prevSub);
1888
+ }
1889
+ }
1890
+ const currentEffect = activeWatcher;
1891
+ activeWatcher = this;
1786
1892
  try {
1787
- cleanup();
1893
+ return call ? call(source, 3, [
1894
+ this.boundCleanup
1895
+ ]) : source(this.boundCleanup);
1788
1896
  } finally {
1789
- resetTracking();
1897
+ activeWatcher = currentEffect;
1790
1898
  }
1791
- }
1792
- const currentEffect = activeWatcher;
1793
- activeWatcher = effect;
1794
- try {
1795
- return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1796
- } finally {
1797
- activeWatcher = currentEffect;
1798
- }
1899
+ };
1900
+ }
1901
+ } else {
1902
+ getter = NOOP;
1903
+ warnInvalidSource(source, onWarn);
1904
+ }
1905
+ if (cb && deep) {
1906
+ const baseGetter = getter;
1907
+ const depth = deep === true ? Infinity : deep;
1908
+ getter = () => traverse(baseGetter(), depth);
1909
+ }
1910
+ super(getter);
1911
+ this.cb = cb;
1912
+ this.options = options;
1913
+ this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
1914
+ this.forceTrigger = forceTrigger;
1915
+ this.isMultiSource = isMultiSource;
1916
+ if (once && cb) {
1917
+ const _cb = cb;
1918
+ cb = (...args) => {
1919
+ _cb(...args);
1920
+ this.stop();
1799
1921
  };
1800
1922
  }
1801
- } else {
1802
- getter = NOOP;
1803
- warnInvalidSource(source);
1804
- }
1805
- if (cb && deep) {
1806
- const baseGetter = getter;
1807
- const depth = deep === true ? Infinity : deep;
1808
- getter = () => traverse(baseGetter(), depth);
1809
- }
1810
- const scope = getCurrentScope();
1811
- const watchHandle = () => {
1812
- effect.stop();
1813
- if (scope && scope.active) {
1814
- remove(scope.effects, effect);
1923
+ this.cb = cb;
1924
+ this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1925
+ {
1926
+ this.onTrack = options.onTrack;
1927
+ this.onTrigger = options.onTrigger;
1815
1928
  }
1816
- };
1817
- if (once && cb) {
1818
- const _cb = cb;
1819
- cb = (...args) => {
1820
- _cb(...args);
1821
- watchHandle();
1822
- };
1823
1929
  }
1824
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1825
- const job = (immediateFirstRun) => {
1826
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1930
+ run(initialRun = false) {
1931
+ const oldValue = this.oldValue;
1932
+ const newValue = this.oldValue = super.run();
1933
+ if (!this.cb) {
1827
1934
  return;
1828
1935
  }
1829
- if (cb) {
1830
- const newValue = effect.run();
1831
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1832
- if (cleanup) {
1833
- cleanup();
1834
- }
1835
- const currentWatcher = activeWatcher;
1836
- activeWatcher = effect;
1837
- try {
1838
- const args = [
1839
- newValue,
1840
- // pass undefined as the old value when it's changed for the first time
1841
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1842
- boundCleanup
1843
- ];
1844
- oldValue = newValue;
1845
- call ? call(cb, 3, args) : (
1846
- // @ts-expect-error
1847
- cb(...args)
1848
- );
1849
- } finally {
1850
- activeWatcher = currentWatcher;
1851
- }
1852
- }
1853
- } else {
1854
- effect.run();
1936
+ const { immediate, deep, call } = this.options;
1937
+ if (initialRun && !immediate) {
1938
+ return;
1855
1939
  }
1856
- };
1857
- if (augmentJob) {
1858
- augmentJob(job);
1859
- }
1860
- effect = new ReactiveEffect(getter);
1861
- effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1862
- boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1863
- cleanup = effect.onStop = () => {
1864
- const cleanups = cleanupMap.get(effect);
1865
- if (cleanups) {
1866
- if (call) {
1867
- call(cleanups, 4);
1868
- } else {
1869
- for (const cleanup2 of cleanups) cleanup2();
1940
+ if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1941
+ cleanup(this);
1942
+ const currentWatcher = activeWatcher;
1943
+ activeWatcher = this;
1944
+ try {
1945
+ const args = [
1946
+ newValue,
1947
+ // pass undefined as the old value when it's changed for the first time
1948
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1949
+ this.boundCleanup
1950
+ ];
1951
+ call ? call(this.cb, 3, args) : (
1952
+ // @ts-expect-error
1953
+ this.cb(...args)
1954
+ );
1955
+ } finally {
1956
+ activeWatcher = currentWatcher;
1870
1957
  }
1871
- cleanupMap.delete(effect);
1872
- }
1873
- };
1874
- {
1875
- effect.onTrack = options.onTrack;
1876
- effect.onTrigger = options.onTrigger;
1877
- }
1878
- if (cb) {
1879
- if (immediate) {
1880
- job(true);
1881
- } else {
1882
- oldValue = effect.run();
1883
1958
  }
1884
- } else if (scheduler) {
1885
- scheduler(job.bind(null, true), true);
1886
- } else {
1887
- effect.run();
1888
1959
  }
1889
- watchHandle.pause = effect.pause.bind(effect);
1890
- watchHandle.resume = effect.resume.bind(effect);
1891
- watchHandle.stop = watchHandle;
1892
- return watchHandle;
1960
+ }
1961
+ function reactiveGetter(source, deep) {
1962
+ if (deep) return source;
1963
+ if (isShallow(source) || deep === false || deep === 0)
1964
+ return traverse(source, 1);
1965
+ return traverse(source);
1966
+ }
1967
+ function warnInvalidSource(s, onWarn) {
1968
+ (onWarn || warn)(
1969
+ `Invalid watch source: `,
1970
+ s,
1971
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1972
+ );
1893
1973
  }
1894
1974
  function traverse(value, depth = Infinity, seen) {
1895
1975
  if (depth <= 0 || !isObject$1(value) || value["__v_skip"]) {
@@ -1924,122 +2004,104 @@ function traverse(value, depth = Infinity, seen) {
1924
2004
  return value;
1925
2005
  }
1926
2006
 
1927
- const EMPTY_OBJ = Object.freeze({}) ;
1928
- const isArray = Array.isArray;
1929
- const extend = Object.assign;
1930
- function exclude(obj, keys) {
1931
- const ret = {};
1932
- Object.keys(obj).forEach((key) => {
1933
- if (!keys.includes(key)) {
1934
- ret[key] = obj[key];
1935
- }
1936
- });
1937
- return ret;
1938
- }
1939
- function getType(x) {
1940
- return Object.prototype.toString.call(x).slice(8, -1);
1941
- }
1942
- function isSimpleValue(x) {
1943
- const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
1944
- return x === null || simpleTypes.has(typeof x);
1945
- }
1946
- function isObject(x) {
1947
- return x !== null && typeof x === 'object';
1948
- }
1949
- function isPlainObject(x) {
1950
- return getType(x) === 'Object';
1951
- }
1952
- function isFunction(x) {
1953
- return typeof x === 'function';
1954
- }
1955
- function toHiddenField(name) {
1956
- return `__${name}__`;
1957
- }
1958
-
1959
2007
  var SchedulerJobFlags;
1960
2008
  (function (SchedulerJobFlags) {
1961
2009
  SchedulerJobFlags[SchedulerJobFlags["QUEUED"] = 1] = "QUEUED";
1962
- SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 4] = "ALLOW_RECURSE";
2010
+ SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 2] = "ALLOW_RECURSE";
1963
2011
  })(SchedulerJobFlags || (SchedulerJobFlags = {}));
1964
- const queue = [];
1965
- let flushIndex = -1;
1966
- const pendingPostFlushCbs = [];
1967
- let activePostFlushCbs = null;
2012
+ const jobs = [];
2013
+ let postJobs = [];
2014
+ let activePostJobs = null;
2015
+ let currentFlushPromise = null;
2016
+ let jobsLength = 0;
2017
+ let flushIndex = 0;
1968
2018
  let postFlushIndex = 0;
1969
2019
  const resolvedPromise = /*@__PURE__*/ Promise.resolve();
1970
- let currentFlushPromise = null;
1971
2020
  const RECURSION_LIMIT = 100;
1972
2021
  function nextTick(fn) {
1973
2022
  const p = currentFlushPromise || resolvedPromise;
1974
2023
  return fn ? p.then(fn) : p;
1975
2024
  }
1976
2025
  function queueJob(job) {
1977
- if (!(job.flags & SchedulerJobFlags.QUEUED)) {
1978
- queue.push(job);
1979
- job.flags |= SchedulerJobFlags.QUEUED;
2026
+ if (queueJobWorker(job, jobs, jobsLength)) {
2027
+ jobsLength++;
1980
2028
  queueFlush();
1981
2029
  }
1982
2030
  }
2031
+ function queueJobWorker(job, queue, length) {
2032
+ const flags = job.flags;
2033
+ if (!(flags & SchedulerJobFlags.QUEUED)) {
2034
+ job.flags = flags | SchedulerJobFlags.QUEUED;
2035
+ queue[length] = job;
2036
+ return true;
2037
+ }
2038
+ return false;
2039
+ }
1983
2040
  function queueFlush() {
1984
2041
  if (!currentFlushPromise) {
2042
+ // We don't flush post jobs on flushJobs's finally block, so we don't need `doFlushJobs` here.
1985
2043
  currentFlushPromise = resolvedPromise.then(flushJobs);
1986
2044
  }
1987
2045
  }
1988
- function queuePostFlushCb(cb) {
1989
- if (!(cb.flags & SchedulerJobFlags.QUEUED)) {
1990
- pendingPostFlushCbs.push(cb);
1991
- cb.flags |= SchedulerJobFlags.QUEUED;
1992
- }
2046
+ function queuePostFlushCb(job) {
2047
+ queueJobWorker(job, postJobs, postJobs.length);
1993
2048
  }
1994
2049
  function flushPostFlushCbs() {
1995
- if (pendingPostFlushCbs.length > 0) {
1996
- activePostFlushCbs = [...new Set(pendingPostFlushCbs)];
1997
- pendingPostFlushCbs.length = 0;
1998
- for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
1999
- const cb = activePostFlushCbs[postFlushIndex];
2050
+ if (postJobs.length) {
2051
+ activePostJobs = postJobs;
2052
+ postJobs = [];
2053
+ while (postFlushIndex < activePostJobs.length) {
2054
+ const cb = activePostJobs[postFlushIndex++];
2000
2055
  if (cb.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2001
2056
  cb.flags &= ~SchedulerJobFlags.QUEUED;
2002
2057
  }
2003
- cb();
2004
- cb.flags &= ~SchedulerJobFlags.QUEUED;
2058
+ try {
2059
+ cb();
2060
+ }
2061
+ finally {
2062
+ cb.flags &= ~SchedulerJobFlags.QUEUED;
2063
+ }
2005
2064
  }
2006
- activePostFlushCbs = null;
2065
+ activePostJobs = null;
2007
2066
  postFlushIndex = 0;
2008
2067
  }
2009
2068
  }
2010
2069
  function flushJobs() {
2011
2070
  const seen = new Map() ;
2012
- // Conditional usage of checkRecursiveUpdate must be determined out of
2013
- // try ... catch block since Rollup by default de-optimizes treeshaking
2014
- // inside try-catch. This can leave all warning code unshaked. Although
2015
- // they would get eventually shaken by a minifier like terser, some minifiers
2016
- // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
2017
- const check = (job) => checkRecursiveUpdates(seen, job)
2018
- ;
2019
2071
  try {
2020
- for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
2021
- const job = queue[flushIndex];
2072
+ while (flushIndex < jobsLength) {
2073
+ const job = jobs[flushIndex];
2074
+ jobs[flushIndex++] = undefined;
2075
+ // Conditional usage of checkRecursiveUpdate must be determined out of
2076
+ // try ... catch block since Rollup by default de-optimizes treeshaking
2077
+ // inside try-catch. This can leave all warning code unshaked. Although
2078
+ // they would get eventually shaken by a minifier like terser, some minifiers
2079
+ // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
2022
2080
  /* istanbul ignore if -- @preserve */
2023
- if (true && check(job)) {
2081
+ if (true && checkRecursiveUpdates(seen, job)) {
2024
2082
  continue;
2025
2083
  }
2026
2084
  if (job.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2027
2085
  job.flags &= ~SchedulerJobFlags.QUEUED;
2028
2086
  }
2029
- job();
2030
- if (!(job.flags & SchedulerJobFlags.ALLOW_RECURSE)) {
2031
- job.flags &= ~SchedulerJobFlags.QUEUED;
2087
+ try {
2088
+ job();
2089
+ }
2090
+ finally {
2091
+ if (!(job.flags & SchedulerJobFlags.ALLOW_RECURSE)) {
2092
+ job.flags &= ~SchedulerJobFlags.QUEUED;
2093
+ }
2032
2094
  }
2033
2095
  }
2034
2096
  }
2035
2097
  finally {
2036
2098
  // If there was an error we still need to clear the QUEUED flags
2037
- for (; flushIndex < queue.length; flushIndex++) {
2038
- const job = queue[flushIndex];
2039
- job.flags &= ~SchedulerJobFlags.QUEUED;
2099
+ while (flushIndex < jobsLength) {
2100
+ jobs[flushIndex].flags &= ~SchedulerJobFlags.QUEUED;
2101
+ jobs[flushIndex++] = undefined;
2040
2102
  }
2041
- flushIndex = -1;
2042
- queue.length = 0;
2103
+ flushIndex = 0;
2104
+ jobsLength = 0;
2043
2105
  currentFlushPromise = null;
2044
2106
  }
2045
2107
  }
@@ -2056,6 +2118,38 @@ function checkRecursiveUpdates(seen, fn) {
2056
2118
  return false;
2057
2119
  }
2058
2120
 
2121
+ const EMPTY_OBJ = Object.freeze({}) ;
2122
+ const isArray = Array.isArray;
2123
+ const extend = Object.assign;
2124
+ function exclude(obj, keys) {
2125
+ const ret = {};
2126
+ Object.keys(obj).forEach((key) => {
2127
+ if (!keys.includes(key)) {
2128
+ ret[key] = obj[key];
2129
+ }
2130
+ });
2131
+ return ret;
2132
+ }
2133
+ function getType(x) {
2134
+ return Object.prototype.toString.call(x).slice(8, -1);
2135
+ }
2136
+ function isSimpleValue(x) {
2137
+ const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
2138
+ return x === null || simpleTypes.has(typeof x);
2139
+ }
2140
+ function isObject(x) {
2141
+ return x !== null && typeof x === 'object';
2142
+ }
2143
+ function isPlainObject(x) {
2144
+ return getType(x) === 'Object';
2145
+ }
2146
+ function isFunction(x) {
2147
+ return typeof x === 'function';
2148
+ }
2149
+ function toHiddenField(name) {
2150
+ return `__${name}__`;
2151
+ }
2152
+
2059
2153
  // Simple effect.
2060
2154
  function watchEffect(effect, options) {
2061
2155
  return doWatch(effect, null, options);
@@ -2077,8 +2171,46 @@ function watch(source, cb, options) {
2077
2171
  }
2078
2172
  return doWatch(source, cb, options);
2079
2173
  }
2080
- function doWatch(source, cb, options = EMPTY_OBJ) {
2081
- const { immediate, deep, flush, once } = options;
2174
+ class RenderWatcherEffect extends WatcherEffect {
2175
+ constructor(
2176
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
2177
+ source, cb, options, flush) {
2178
+ super(source, cb, options);
2179
+ this.flush = flush;
2180
+ const job = () => {
2181
+ if (this.dirty) {
2182
+ this.run();
2183
+ }
2184
+ };
2185
+ // Important: mark the job as a watcher callback so that scheduler knows
2186
+ // it is allowed to self-trigger (#1727)
2187
+ if (cb) {
2188
+ this.flags |= EffectFlags.ALLOW_RECURSE;
2189
+ job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
2190
+ }
2191
+ this.job = job;
2192
+ }
2193
+ notify() {
2194
+ const flags = this.flags;
2195
+ if (!(flags & EffectFlags.PAUSED)) {
2196
+ const flush = this.flush;
2197
+ const job = this.job;
2198
+ if (flush === 'post') {
2199
+ queuePostFlushCb(job);
2200
+ }
2201
+ else if (flush === 'pre') {
2202
+ queueJob(job);
2203
+ }
2204
+ else {
2205
+ job();
2206
+ }
2207
+ }
2208
+ }
2209
+ }
2210
+ function doWatch(
2211
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
2212
+ source, cb, options = EMPTY_OBJ) {
2213
+ const { immediate, deep, flush = 'pre', once } = options;
2082
2214
  if (!cb) {
2083
2215
  if (immediate !== undefined) {
2084
2216
  console.warn(`watch() "immediate" option is only respected when using the ` +
@@ -2094,32 +2226,22 @@ function doWatch(source, cb, options = EMPTY_OBJ) {
2094
2226
  }
2095
2227
  }
2096
2228
  const baseWatchOptions = extend({}, options);
2097
- // Scheduler
2098
- if (flush === 'post') {
2099
- baseWatchOptions.scheduler = (job) => {
2100
- queuePostFlushCb(job);
2101
- };
2229
+ const effect = new RenderWatcherEffect(source, cb, baseWatchOptions, flush);
2230
+ // Initial run
2231
+ if (cb) {
2232
+ effect.run(true);
2102
2233
  }
2103
- else if (flush !== 'sync') {
2104
- baseWatchOptions.scheduler = (job, isFirstRun) => {
2105
- if (isFirstRun) {
2106
- job();
2107
- }
2108
- else {
2109
- queueJob(job);
2110
- }
2111
- };
2234
+ else if (flush === 'post') {
2235
+ queuePostFlushCb(effect.job);
2112
2236
  }
2113
- // @ts-expect-error
2114
- baseWatchOptions.augmentJob = (job) => {
2115
- // Important: mark the job as a watcher callback so that scheduler knows
2116
- // it is allowed to self-trigger
2117
- if (cb) {
2118
- job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
2119
- }
2120
- };
2121
- const watchHandle = watch$1(source, cb, baseWatchOptions);
2122
- return watchHandle;
2237
+ else {
2238
+ effect.run(true);
2239
+ }
2240
+ const stop = effect.stop.bind(effect);
2241
+ stop.pause = effect.pause.bind(effect);
2242
+ stop.resume = effect.resume.bind(effect);
2243
+ stop.stop = stop;
2244
+ return stop;
2123
2245
  }
2124
2246
 
2125
2247
  const provides = Object.create(null);
@@ -2156,28 +2278,18 @@ function unsetCurrentApp() {
2156
2278
  }
2157
2279
  function setCurrentPage(page) {
2158
2280
  currentPage = page;
2159
- // @ts-expect-error
2160
- page.__scope__.on();
2281
+ return setCurrentScope(page.__scope__);
2161
2282
  }
2162
- function unsetCurrentPage() {
2163
- /* istanbul ignore else -- @preserve */
2164
- if (currentPage) {
2165
- // @ts-expect-error
2166
- currentPage.__scope__.off();
2167
- }
2283
+ function unsetCurrentPage(scope) {
2284
+ setCurrentScope(scope);
2168
2285
  currentPage = null;
2169
2286
  }
2170
2287
  function setCurrentComponent(component) {
2171
2288
  currentComponent = component;
2172
- // @ts-expect-error
2173
- component.__scope__.on();
2289
+ return setCurrentScope(component.__scope__);
2174
2290
  }
2175
- function unsetCurrentComponent() {
2176
- /* istanbul ignore else -- @preserve */
2177
- if (currentComponent) {
2178
- // @ts-expect-error
2179
- currentComponent.__scope__.off();
2180
- }
2291
+ function unsetCurrentComponent(scope) {
2292
+ setCurrentScope(scope);
2181
2293
  currentComponent = null;
2182
2294
  }
2183
2295
 
@@ -2315,7 +2427,7 @@ function definePage(optionsOrSetup, config) {
2315
2427
  const originOnLoad = options[PageLifecycle.ON_LOAD];
2316
2428
  options[PageLifecycle.ON_LOAD] = function (query) {
2317
2429
  this.__scope__ = new EffectScope();
2318
- setCurrentPage(this);
2430
+ const scope = setCurrentPage(this);
2319
2431
  const context = {
2320
2432
  is: this.is,
2321
2433
  route: this.route,
@@ -2359,7 +2471,7 @@ function definePage(optionsOrSetup, config) {
2359
2471
  this.setData(data, flushPostFlushCbs);
2360
2472
  }
2361
2473
  }
2362
- unsetCurrentPage();
2474
+ unsetCurrentPage(scope);
2363
2475
  if (originOnLoad !== undefined) {
2364
2476
  originOnLoad.call(this, query);
2365
2477
  }
@@ -2488,7 +2600,7 @@ function defineComponent(optionsOrSetup, config) {
2488
2600
  options[ComponentLifecycle.ATTACHED];
2489
2601
  options.lifetimes[ComponentLifecycle.ATTACHED] = function () {
2490
2602
  this.__scope__ = new EffectScope();
2491
- setCurrentComponent(this);
2603
+ const scope = setCurrentComponent(this);
2492
2604
  const rawProps = {};
2493
2605
  if (properties) {
2494
2606
  properties.forEach((property) => {
@@ -2543,7 +2655,7 @@ function defineComponent(optionsOrSetup, config) {
2543
2655
  this.setData(data, flushPostFlushCbs);
2544
2656
  }
2545
2657
  }
2546
- unsetCurrentComponent();
2658
+ unsetCurrentComponent(scope);
2547
2659
  if (originAttached !== undefined) {
2548
2660
  originAttached.call(this);
2549
2661
  }