@reactive-vscode/reactivity 0.2.5 → 0.2.6

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.js CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
- * @vue/shared v3.4.27
2
+ * @vue/shared v3.5.12
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
6
  /*! #__NO_SIDE_EFFECTS__ */
7
7
  // @__NO_SIDE_EFFECTS__
8
- function makeMap(str, expectsLowerCase) {
9
- const set2 = new Set(str.split(","));
10
- return (val) => set2.has(val);
8
+ function makeMap(str) {
9
+ const map = /* @__PURE__ */ Object.create(null);
10
+ for (const key of str.split(",")) map[key] = 1;
11
+ return (val) => val in map;
11
12
  }
12
13
  const EMPTY_OBJ = !!(process.env.NODE_ENV !== "production") ? Object.freeze({}) : {};
13
14
  !!(process.env.NODE_ENV !== "production") ? Object.freeze([]) : [];
@@ -59,7 +60,7 @@ const def = (obj, key, value, writable = false) => {
59
60
  });
60
61
  };
61
62
  /**
62
- * @vue/reactivity v3.4.27
63
+ * @vue/reactivity v3.5.12
63
64
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
64
65
  * @license MIT
65
66
  **/
@@ -73,6 +74,7 @@ class EffectScope {
73
74
  this._active = true;
74
75
  this.effects = [];
75
76
  this.cleanups = [];
77
+ this._isPaused = false;
76
78
  this.parent = activeEffectScope;
77
79
  if (!detached && activeEffectScope) {
78
80
  this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
@@ -83,6 +85,39 @@ class EffectScope {
83
85
  get active() {
84
86
  return this._active;
85
87
  }
88
+ pause() {
89
+ if (this._active) {
90
+ this._isPaused = true;
91
+ let i, l;
92
+ if (this.scopes) {
93
+ for (i = 0, l = this.scopes.length; i < l; i++) {
94
+ this.scopes[i].pause();
95
+ }
96
+ }
97
+ for (i = 0, l = this.effects.length; i < l; i++) {
98
+ this.effects[i].pause();
99
+ }
100
+ }
101
+ }
102
+ /**
103
+ * Resumes the effect scope, including all child scopes and effects.
104
+ */
105
+ resume() {
106
+ if (this._active) {
107
+ if (this._isPaused) {
108
+ this._isPaused = false;
109
+ let i, l;
110
+ if (this.scopes) {
111
+ for (i = 0, l = this.scopes.length; i < l; i++) {
112
+ this.scopes[i].resume();
113
+ }
114
+ }
115
+ for (i = 0, l = this.effects.length; i < l; i++) {
116
+ this.effects[i].resume();
117
+ }
118
+ }
119
+ }
120
+ }
86
121
  run(fn) {
87
122
  if (this._active) {
88
123
  const currentEffectScope = activeEffectScope;
@@ -139,140 +174,313 @@ class EffectScope {
139
174
  function effectScope(detached) {
140
175
  return new EffectScope(detached);
141
176
  }
142
- function recordEffectScope(effect2, scope = activeEffectScope) {
143
- if (scope && scope.active) {
144
- scope.effects.push(effect2);
145
- }
146
- }
147
177
  function getCurrentScope() {
148
178
  return activeEffectScope;
149
179
  }
150
- function onScopeDispose(fn) {
180
+ function onScopeDispose(fn, failSilently = false) {
151
181
  if (activeEffectScope) {
152
182
  activeEffectScope.cleanups.push(fn);
153
- } else if (!!(process.env.NODE_ENV !== "production")) {
183
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
154
184
  warn$1(
155
185
  `onScopeDispose() is called when there is no active effect scope to be associated with.`
156
186
  );
157
187
  }
158
188
  }
159
- let activeEffect;
189
+ let activeSub;
190
+ const EffectFlags = {
191
+ "ACTIVE": 1,
192
+ "1": "ACTIVE",
193
+ "RUNNING": 2,
194
+ "2": "RUNNING",
195
+ "TRACKING": 4,
196
+ "4": "TRACKING",
197
+ "NOTIFIED": 8,
198
+ "8": "NOTIFIED",
199
+ "DIRTY": 16,
200
+ "16": "DIRTY",
201
+ "ALLOW_RECURSE": 32,
202
+ "32": "ALLOW_RECURSE",
203
+ "PAUSED": 64,
204
+ "64": "PAUSED"
205
+ };
206
+ const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
160
207
  class ReactiveEffect {
161
- constructor(fn, trigger2, scheduler, scope) {
208
+ constructor(fn) {
162
209
  this.fn = fn;
163
- this.trigger = trigger2;
164
- this.scheduler = scheduler;
165
- this.active = true;
166
- this.deps = [];
167
- this._dirtyLevel = 4;
168
- this._trackId = 0;
169
- this._runnings = 0;
170
- this._shouldSchedule = false;
171
- this._depsLength = 0;
172
- recordEffectScope(this, scope);
210
+ this.deps = void 0;
211
+ this.depsTail = void 0;
212
+ this.flags = 1 | 4;
213
+ this.next = void 0;
214
+ this.cleanup = void 0;
215
+ this.scheduler = void 0;
216
+ if (activeEffectScope && activeEffectScope.active) {
217
+ activeEffectScope.effects.push(this);
218
+ }
173
219
  }
174
- get dirty() {
175
- if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
176
- this._dirtyLevel = 1;
177
- pauseTracking();
178
- for (let i = 0; i < this._depsLength; i++) {
179
- const dep = this.deps[i];
180
- if (dep.computed) {
181
- triggerComputed(dep.computed);
182
- if (this._dirtyLevel >= 4) {
183
- break;
184
- }
185
- }
186
- }
187
- if (this._dirtyLevel === 1) {
188
- this._dirtyLevel = 0;
220
+ pause() {
221
+ this.flags |= 64;
222
+ }
223
+ resume() {
224
+ if (this.flags & 64) {
225
+ this.flags &= ~64;
226
+ if (pausedQueueEffects.has(this)) {
227
+ pausedQueueEffects.delete(this);
228
+ this.trigger();
189
229
  }
190
- resetTracking();
191
230
  }
192
- return this._dirtyLevel >= 4;
193
231
  }
194
- set dirty(v) {
195
- this._dirtyLevel = v ? 4 : 0;
232
+ /**
233
+ * @internal
234
+ */
235
+ notify() {
236
+ if (this.flags & 2 && !(this.flags & 32)) {
237
+ return;
238
+ }
239
+ if (!(this.flags & 8)) {
240
+ batch(this);
241
+ }
196
242
  }
197
243
  run() {
198
- this._dirtyLevel = 0;
199
- if (!this.active) {
244
+ if (!(this.flags & 1)) {
200
245
  return this.fn();
201
246
  }
202
- let lastShouldTrack = shouldTrack;
203
- let lastEffect = activeEffect;
247
+ this.flags |= 2;
248
+ cleanupEffect(this);
249
+ prepareDeps(this);
250
+ const prevEffect = activeSub;
251
+ const prevShouldTrack = shouldTrack;
252
+ activeSub = this;
253
+ shouldTrack = true;
204
254
  try {
205
- shouldTrack = true;
206
- activeEffect = this;
207
- this._runnings++;
208
- preCleanupEffect(this);
209
255
  return this.fn();
210
256
  } finally {
211
- postCleanupEffect(this);
212
- this._runnings--;
213
- activeEffect = lastEffect;
214
- shouldTrack = lastShouldTrack;
257
+ if (!!(process.env.NODE_ENV !== "production") && activeSub !== this) {
258
+ warn$1(
259
+ "Active effect was not restored correctly - this is likely a Vue internal bug."
260
+ );
261
+ }
262
+ cleanupDeps(this);
263
+ activeSub = prevEffect;
264
+ shouldTrack = prevShouldTrack;
265
+ this.flags &= ~2;
215
266
  }
216
267
  }
217
268
  stop() {
218
- if (this.active) {
219
- preCleanupEffect(this);
220
- postCleanupEffect(this);
269
+ if (this.flags & 1) {
270
+ for (let link = this.deps; link; link = link.nextDep) {
271
+ removeSub(link);
272
+ }
273
+ this.deps = this.depsTail = void 0;
274
+ cleanupEffect(this);
221
275
  this.onStop && this.onStop();
222
- this.active = false;
276
+ this.flags &= ~1;
277
+ }
278
+ }
279
+ trigger() {
280
+ if (this.flags & 64) {
281
+ pausedQueueEffects.add(this);
282
+ } else if (this.scheduler) {
283
+ this.scheduler();
284
+ } else {
285
+ this.runIfDirty();
286
+ }
287
+ }
288
+ /**
289
+ * @internal
290
+ */
291
+ runIfDirty() {
292
+ if (isDirty(this)) {
293
+ this.run();
223
294
  }
224
295
  }
296
+ get dirty() {
297
+ return isDirty(this);
298
+ }
225
299
  }
226
- function triggerComputed(computed2) {
227
- return computed2.value;
300
+ let batchDepth = 0;
301
+ let batchedSub;
302
+ let batchedComputed;
303
+ function batch(sub, isComputed = false) {
304
+ sub.flags |= 8;
305
+ if (isComputed) {
306
+ sub.next = batchedComputed;
307
+ batchedComputed = sub;
308
+ return;
309
+ }
310
+ sub.next = batchedSub;
311
+ batchedSub = sub;
228
312
  }
229
- function preCleanupEffect(effect2) {
230
- effect2._trackId++;
231
- effect2._depsLength = 0;
313
+ function startBatch() {
314
+ batchDepth++;
315
+ }
316
+ function endBatch() {
317
+ if (--batchDepth > 0) {
318
+ return;
319
+ }
320
+ if (batchedComputed) {
321
+ let e = batchedComputed;
322
+ batchedComputed = void 0;
323
+ while (e) {
324
+ const next = e.next;
325
+ e.next = void 0;
326
+ e.flags &= ~8;
327
+ e = next;
328
+ }
329
+ }
330
+ let error;
331
+ while (batchedSub) {
332
+ let e = batchedSub;
333
+ batchedSub = void 0;
334
+ while (e) {
335
+ const next = e.next;
336
+ e.next = void 0;
337
+ e.flags &= ~8;
338
+ if (e.flags & 1) {
339
+ try {
340
+ ;
341
+ e.trigger();
342
+ } catch (err) {
343
+ if (!error) error = err;
344
+ }
345
+ }
346
+ e = next;
347
+ }
348
+ }
349
+ if (error) throw error;
350
+ }
351
+ function prepareDeps(sub) {
352
+ for (let link = sub.deps; link; link = link.nextDep) {
353
+ link.version = -1;
354
+ link.prevActiveLink = link.dep.activeLink;
355
+ link.dep.activeLink = link;
356
+ }
357
+ }
358
+ function cleanupDeps(sub) {
359
+ let head;
360
+ let tail = sub.depsTail;
361
+ let link = tail;
362
+ while (link) {
363
+ const prev = link.prevDep;
364
+ if (link.version === -1) {
365
+ if (link === tail) tail = prev;
366
+ removeSub(link);
367
+ removeDep(link);
368
+ } else {
369
+ head = link;
370
+ }
371
+ link.dep.activeLink = link.prevActiveLink;
372
+ link.prevActiveLink = void 0;
373
+ link = prev;
374
+ }
375
+ sub.deps = head;
376
+ sub.depsTail = tail;
232
377
  }
233
- function postCleanupEffect(effect2) {
234
- if (effect2.deps.length > effect2._depsLength) {
235
- for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
236
- cleanupDepEffect(effect2.deps[i], effect2);
378
+ function isDirty(sub) {
379
+ for (let link = sub.deps; link; link = link.nextDep) {
380
+ if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
381
+ return true;
237
382
  }
238
- effect2.deps.length = effect2._depsLength;
239
383
  }
384
+ if (sub._dirty) {
385
+ return true;
386
+ }
387
+ return false;
240
388
  }
241
- function cleanupDepEffect(dep, effect2) {
242
- const trackId = dep.get(effect2);
243
- if (trackId !== void 0 && effect2._trackId !== trackId) {
244
- dep.delete(effect2);
245
- if (dep.size === 0) {
246
- dep.cleanup();
389
+ function refreshComputed(computed2) {
390
+ if (computed2.flags & 4 && !(computed2.flags & 16)) {
391
+ return;
392
+ }
393
+ computed2.flags &= ~16;
394
+ if (computed2.globalVersion === globalVersion) {
395
+ return;
396
+ }
397
+ computed2.globalVersion = globalVersion;
398
+ const dep = computed2.dep;
399
+ computed2.flags |= 2;
400
+ if (dep.version > 0 && !computed2.isSSR && computed2.deps && !isDirty(computed2)) {
401
+ computed2.flags &= ~2;
402
+ return;
403
+ }
404
+ const prevSub = activeSub;
405
+ const prevShouldTrack = shouldTrack;
406
+ activeSub = computed2;
407
+ shouldTrack = true;
408
+ try {
409
+ prepareDeps(computed2);
410
+ const value = computed2.fn(computed2._value);
411
+ if (dep.version === 0 || hasChanged(value, computed2._value)) {
412
+ computed2._value = value;
413
+ dep.version++;
414
+ }
415
+ } catch (err) {
416
+ dep.version++;
417
+ throw err;
418
+ } finally {
419
+ activeSub = prevSub;
420
+ shouldTrack = prevShouldTrack;
421
+ cleanupDeps(computed2);
422
+ computed2.flags &= ~2;
423
+ }
424
+ }
425
+ function removeSub(link, soft = false) {
426
+ const { dep, prevSub, nextSub } = link;
427
+ if (prevSub) {
428
+ prevSub.nextSub = nextSub;
429
+ link.prevSub = void 0;
430
+ }
431
+ if (nextSub) {
432
+ nextSub.prevSub = prevSub;
433
+ link.nextSub = void 0;
434
+ }
435
+ if (!!(process.env.NODE_ENV !== "production") && dep.subsHead === link) {
436
+ dep.subsHead = nextSub;
437
+ }
438
+ if (dep.subs === link) {
439
+ dep.subs = prevSub;
440
+ if (!prevSub && dep.computed) {
441
+ dep.computed.flags &= ~4;
442
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
443
+ removeSub(l, true);
444
+ }
247
445
  }
248
446
  }
447
+ if (!soft && !--dep.sc && dep.map) {
448
+ dep.map.delete(dep.key);
449
+ }
450
+ }
451
+ function removeDep(link) {
452
+ const { prevDep, nextDep } = link;
453
+ if (prevDep) {
454
+ prevDep.nextDep = nextDep;
455
+ link.prevDep = void 0;
456
+ }
457
+ if (nextDep) {
458
+ nextDep.prevDep = prevDep;
459
+ link.nextDep = void 0;
460
+ }
249
461
  }
250
462
  function effect(fn, options) {
251
463
  if (fn.effect instanceof ReactiveEffect) {
252
464
  fn = fn.effect.fn;
253
465
  }
254
- const _effect = new ReactiveEffect(fn, NOOP, () => {
255
- if (_effect.dirty) {
256
- _effect.run();
257
- }
258
- });
466
+ const e = new ReactiveEffect(fn);
259
467
  if (options) {
260
- extend(_effect, options);
261
- if (options.scope)
262
- recordEffectScope(_effect, options.scope);
468
+ extend(e, options);
263
469
  }
264
- if (!options || !options.lazy) {
265
- _effect.run();
470
+ try {
471
+ e.run();
472
+ } catch (err) {
473
+ e.stop();
474
+ throw err;
266
475
  }
267
- const runner = _effect.run.bind(_effect);
268
- runner.effect = _effect;
476
+ const runner = e.run.bind(e);
477
+ runner.effect = e;
269
478
  return runner;
270
479
  }
271
480
  function stop(runner) {
272
481
  runner.effect.stop();
273
482
  }
274
483
  let shouldTrack = true;
275
- let pauseScheduleStack = 0;
276
484
  const trackStack = [];
277
485
  function pauseTracking() {
278
486
  trackStack.push(shouldTrack);
@@ -286,192 +494,437 @@ function resetTracking() {
286
494
  const last = trackStack.pop();
287
495
  shouldTrack = last === void 0 ? true : last;
288
496
  }
289
- function pauseScheduling() {
290
- pauseScheduleStack++;
291
- }
292
- function resetScheduling() {
293
- pauseScheduleStack--;
294
- while (!pauseScheduleStack && queueEffectSchedulers.length) {
295
- queueEffectSchedulers.shift()();
497
+ function onEffectCleanup(fn, failSilently = false) {
498
+ if (activeSub instanceof ReactiveEffect) {
499
+ activeSub.cleanup = fn;
500
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
501
+ warn$1(
502
+ `onEffectCleanup() was called when there was no active effect to associate with.`
503
+ );
296
504
  }
297
505
  }
298
- function trackEffect(effect2, dep, debuggerEventExtraInfo) {
299
- var _a;
300
- if (dep.get(effect2) !== effect2._trackId) {
301
- dep.set(effect2, effect2._trackId);
302
- const oldDep = effect2.deps[effect2._depsLength];
303
- if (oldDep !== dep) {
304
- if (oldDep) {
305
- cleanupDepEffect(oldDep, effect2);
306
- }
307
- effect2.deps[effect2._depsLength++] = dep;
308
- } else {
309
- effect2._depsLength++;
506
+ function cleanupEffect(e) {
507
+ const { cleanup } = e;
508
+ e.cleanup = void 0;
509
+ if (cleanup) {
510
+ const prevSub = activeSub;
511
+ activeSub = void 0;
512
+ try {
513
+ cleanup();
514
+ } finally {
515
+ activeSub = prevSub;
310
516
  }
517
+ }
518
+ }
519
+ let globalVersion = 0;
520
+ class Link {
521
+ constructor(sub, dep) {
522
+ this.sub = sub;
523
+ this.dep = dep;
524
+ this.version = dep.version;
525
+ this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
526
+ }
527
+ }
528
+ class Dep {
529
+ constructor(computed2) {
530
+ this.computed = computed2;
531
+ this.version = 0;
532
+ this.activeLink = void 0;
533
+ this.subs = void 0;
534
+ this.map = void 0;
535
+ this.key = void 0;
536
+ this.sc = 0;
311
537
  if (!!(process.env.NODE_ENV !== "production")) {
312
- (_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
538
+ this.subsHead = void 0;
313
539
  }
314
540
  }
315
- }
316
- const queueEffectSchedulers = [];
317
- function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
318
- var _a;
319
- pauseScheduling();
320
- for (const effect2 of dep.keys()) {
321
- let tracking;
322
- if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
323
- effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
324
- effect2._dirtyLevel = dirtyLevel;
541
+ track(debugInfo) {
542
+ if (!activeSub || !shouldTrack || activeSub === this.computed) {
543
+ return;
325
544
  }
326
- if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
545
+ let link = this.activeLink;
546
+ if (link === void 0 || link.sub !== activeSub) {
547
+ link = this.activeLink = new Link(activeSub, this);
548
+ if (!activeSub.deps) {
549
+ activeSub.deps = activeSub.depsTail = link;
550
+ } else {
551
+ link.prevDep = activeSub.depsTail;
552
+ activeSub.depsTail.nextDep = link;
553
+ activeSub.depsTail = link;
554
+ }
555
+ addSub(link);
556
+ } else if (link.version === -1) {
557
+ link.version = this.version;
558
+ if (link.nextDep) {
559
+ const next = link.nextDep;
560
+ next.prevDep = link.prevDep;
561
+ if (link.prevDep) {
562
+ link.prevDep.nextDep = next;
563
+ }
564
+ link.prevDep = activeSub.depsTail;
565
+ link.nextDep = void 0;
566
+ activeSub.depsTail.nextDep = link;
567
+ activeSub.depsTail = link;
568
+ if (activeSub.deps === link) {
569
+ activeSub.deps = next;
570
+ }
571
+ }
572
+ }
573
+ if (!!(process.env.NODE_ENV !== "production") && activeSub.onTrack) {
574
+ activeSub.onTrack(
575
+ extend(
576
+ {
577
+ effect: activeSub
578
+ },
579
+ debugInfo
580
+ )
581
+ );
582
+ }
583
+ return link;
584
+ }
585
+ trigger(debugInfo) {
586
+ this.version++;
587
+ globalVersion++;
588
+ this.notify(debugInfo);
589
+ }
590
+ notify(debugInfo) {
591
+ startBatch();
592
+ try {
327
593
  if (!!(process.env.NODE_ENV !== "production")) {
328
- (_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
594
+ for (let head = this.subsHead; head; head = head.nextSub) {
595
+ if (head.sub.onTrigger && !(head.sub.flags & 8)) {
596
+ head.sub.onTrigger(
597
+ extend(
598
+ {
599
+ effect: head.sub
600
+ },
601
+ debugInfo
602
+ )
603
+ );
604
+ }
605
+ }
329
606
  }
330
- effect2.trigger();
331
- if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
332
- effect2._shouldSchedule = false;
333
- if (effect2.scheduler) {
334
- queueEffectSchedulers.push(effect2.scheduler);
607
+ for (let link = this.subs; link; link = link.prevSub) {
608
+ if (link.sub.notify()) {
609
+ ;
610
+ link.sub.dep.notify();
335
611
  }
336
612
  }
613
+ } finally {
614
+ endBatch();
337
615
  }
338
616
  }
339
- resetScheduling();
340
617
  }
341
- const createDep = (cleanup, computed2) => {
342
- const dep = /* @__PURE__ */ new Map();
343
- dep.cleanup = cleanup;
344
- dep.computed = computed2;
345
- return dep;
346
- };
618
+ function addSub(link) {
619
+ link.dep.sc++;
620
+ if (link.sub.flags & 4) {
621
+ const computed2 = link.dep.computed;
622
+ if (computed2 && !link.dep.subs) {
623
+ computed2.flags |= 4 | 16;
624
+ for (let l = computed2.deps; l; l = l.nextDep) {
625
+ addSub(l);
626
+ }
627
+ }
628
+ const currentTail = link.dep.subs;
629
+ if (currentTail !== link) {
630
+ link.prevSub = currentTail;
631
+ if (currentTail) currentTail.nextSub = link;
632
+ }
633
+ if (!!(process.env.NODE_ENV !== "production") && link.dep.subsHead === void 0) {
634
+ link.dep.subsHead = link;
635
+ }
636
+ link.dep.subs = link;
637
+ }
638
+ }
347
639
  const targetMap = /* @__PURE__ */ new WeakMap();
348
- const ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "iterate" : "");
349
- const MAP_KEY_ITERATE_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? "Map key iterate" : "");
640
+ const ITERATE_KEY = Symbol(
641
+ !!(process.env.NODE_ENV !== "production") ? "Object iterate" : ""
642
+ );
643
+ const MAP_KEY_ITERATE_KEY = Symbol(
644
+ !!(process.env.NODE_ENV !== "production") ? "Map keys iterate" : ""
645
+ );
646
+ const ARRAY_ITERATE_KEY = Symbol(
647
+ !!(process.env.NODE_ENV !== "production") ? "Array iterate" : ""
648
+ );
350
649
  function track(target, type, key) {
351
- if (shouldTrack && activeEffect) {
650
+ if (shouldTrack && activeSub) {
352
651
  let depsMap = targetMap.get(target);
353
652
  if (!depsMap) {
354
653
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
355
654
  }
356
655
  let dep = depsMap.get(key);
357
656
  if (!dep) {
358
- depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
657
+ depsMap.set(key, dep = new Dep());
658
+ dep.map = depsMap;
659
+ dep.key = key;
359
660
  }
360
- trackEffect(
361
- activeEffect,
362
- dep,
363
- !!(process.env.NODE_ENV !== "production") ? {
661
+ if (!!(process.env.NODE_ENV !== "production")) {
662
+ dep.track({
364
663
  target,
365
664
  type,
366
665
  key
367
- } : void 0
368
- );
666
+ });
667
+ } else {
668
+ dep.track();
669
+ }
369
670
  }
370
671
  }
371
672
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
372
673
  const depsMap = targetMap.get(target);
373
674
  if (!depsMap) {
675
+ globalVersion++;
374
676
  return;
375
677
  }
376
- let deps = [];
377
- if (type === "clear") {
378
- deps = [...depsMap.values()];
379
- } else if (key === "length" && isArray(target)) {
380
- const newLength = Number(newValue);
381
- depsMap.forEach((dep, key2) => {
382
- if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
383
- deps.push(dep);
384
- }
385
- });
386
- } else {
387
- if (key !== void 0) {
388
- deps.push(depsMap.get(key));
389
- }
390
- switch (type) {
391
- case "add":
392
- if (!isArray(target)) {
393
- deps.push(depsMap.get(ITERATE_KEY));
394
- if (isMap(target)) {
395
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
396
- }
397
- } else if (isIntegerKey(key)) {
398
- deps.push(depsMap.get("length"));
399
- }
400
- break;
401
- case "delete":
402
- if (!isArray(target)) {
403
- deps.push(depsMap.get(ITERATE_KEY));
404
- if (isMap(target)) {
405
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
406
- }
407
- }
408
- break;
409
- case "set":
410
- if (isMap(target)) {
411
- deps.push(depsMap.get(ITERATE_KEY));
412
- }
413
- break;
414
- }
415
- }
416
- pauseScheduling();
417
- for (const dep of deps) {
678
+ const run = (dep) => {
418
679
  if (dep) {
419
- triggerEffects(
420
- dep,
421
- 4,
422
- !!(process.env.NODE_ENV !== "production") ? {
680
+ if (!!(process.env.NODE_ENV !== "production")) {
681
+ dep.trigger({
423
682
  target,
424
683
  type,
425
684
  key,
426
685
  newValue,
427
686
  oldValue,
428
687
  oldTarget
429
- } : void 0
430
- );
688
+ });
689
+ } else {
690
+ dep.trigger();
691
+ }
692
+ }
693
+ };
694
+ startBatch();
695
+ if (type === "clear") {
696
+ depsMap.forEach(run);
697
+ } else {
698
+ const targetIsArray = isArray(target);
699
+ const isArrayIndex = targetIsArray && isIntegerKey(key);
700
+ if (targetIsArray && key === "length") {
701
+ const newLength = Number(newValue);
702
+ depsMap.forEach((dep, key2) => {
703
+ if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
704
+ run(dep);
705
+ }
706
+ });
707
+ } else {
708
+ if (key !== void 0 || depsMap.has(void 0)) {
709
+ run(depsMap.get(key));
710
+ }
711
+ if (isArrayIndex) {
712
+ run(depsMap.get(ARRAY_ITERATE_KEY));
713
+ }
714
+ switch (type) {
715
+ case "add":
716
+ if (!targetIsArray) {
717
+ run(depsMap.get(ITERATE_KEY));
718
+ if (isMap(target)) {
719
+ run(depsMap.get(MAP_KEY_ITERATE_KEY));
720
+ }
721
+ } else if (isArrayIndex) {
722
+ run(depsMap.get("length"));
723
+ }
724
+ break;
725
+ case "delete":
726
+ if (!targetIsArray) {
727
+ run(depsMap.get(ITERATE_KEY));
728
+ if (isMap(target)) {
729
+ run(depsMap.get(MAP_KEY_ITERATE_KEY));
730
+ }
731
+ }
732
+ break;
733
+ case "set":
734
+ if (isMap(target)) {
735
+ run(depsMap.get(ITERATE_KEY));
736
+ }
737
+ break;
738
+ }
431
739
  }
432
740
  }
433
- resetScheduling();
741
+ endBatch();
434
742
  }
435
743
  function getDepFromReactive(object, key) {
436
- const depsMap = targetMap.get(object);
437
- return depsMap && depsMap.get(key);
744
+ const depMap = targetMap.get(object);
745
+ return depMap && depMap.get(key);
746
+ }
747
+ function reactiveReadArray(array) {
748
+ const raw = toRaw(array);
749
+ if (raw === array) return raw;
750
+ track(raw, "iterate", ARRAY_ITERATE_KEY);
751
+ return isShallow(array) ? raw : raw.map(toReactive);
752
+ }
753
+ function shallowReadArray(arr) {
754
+ track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
755
+ return arr;
756
+ }
757
+ const arrayInstrumentations = {
758
+ __proto__: null,
759
+ [Symbol.iterator]() {
760
+ return iterator(this, Symbol.iterator, toReactive);
761
+ },
762
+ concat(...args) {
763
+ return reactiveReadArray(this).concat(
764
+ ...args.map((x) => isArray(x) ? reactiveReadArray(x) : x)
765
+ );
766
+ },
767
+ entries() {
768
+ return iterator(this, "entries", (value) => {
769
+ value[1] = toReactive(value[1]);
770
+ return value;
771
+ });
772
+ },
773
+ every(fn, thisArg) {
774
+ return apply(this, "every", fn, thisArg, void 0, arguments);
775
+ },
776
+ filter(fn, thisArg) {
777
+ return apply(this, "filter", fn, thisArg, (v) => v.map(toReactive), arguments);
778
+ },
779
+ find(fn, thisArg) {
780
+ return apply(this, "find", fn, thisArg, toReactive, arguments);
781
+ },
782
+ findIndex(fn, thisArg) {
783
+ return apply(this, "findIndex", fn, thisArg, void 0, arguments);
784
+ },
785
+ findLast(fn, thisArg) {
786
+ return apply(this, "findLast", fn, thisArg, toReactive, arguments);
787
+ },
788
+ findLastIndex(fn, thisArg) {
789
+ return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
790
+ },
791
+ // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
792
+ forEach(fn, thisArg) {
793
+ return apply(this, "forEach", fn, thisArg, void 0, arguments);
794
+ },
795
+ includes(...args) {
796
+ return searchProxy(this, "includes", args);
797
+ },
798
+ indexOf(...args) {
799
+ return searchProxy(this, "indexOf", args);
800
+ },
801
+ join(separator) {
802
+ return reactiveReadArray(this).join(separator);
803
+ },
804
+ // keys() iterator only reads `length`, no optimisation required
805
+ lastIndexOf(...args) {
806
+ return searchProxy(this, "lastIndexOf", args);
807
+ },
808
+ map(fn, thisArg) {
809
+ return apply(this, "map", fn, thisArg, void 0, arguments);
810
+ },
811
+ pop() {
812
+ return noTracking(this, "pop");
813
+ },
814
+ push(...args) {
815
+ return noTracking(this, "push", args);
816
+ },
817
+ reduce(fn, ...args) {
818
+ return reduce(this, "reduce", fn, args);
819
+ },
820
+ reduceRight(fn, ...args) {
821
+ return reduce(this, "reduceRight", fn, args);
822
+ },
823
+ shift() {
824
+ return noTracking(this, "shift");
825
+ },
826
+ // slice could use ARRAY_ITERATE but also seems to beg for range tracking
827
+ some(fn, thisArg) {
828
+ return apply(this, "some", fn, thisArg, void 0, arguments);
829
+ },
830
+ splice(...args) {
831
+ return noTracking(this, "splice", args);
832
+ },
833
+ toReversed() {
834
+ return reactiveReadArray(this).toReversed();
835
+ },
836
+ toSorted(comparer) {
837
+ return reactiveReadArray(this).toSorted(comparer);
838
+ },
839
+ toSpliced(...args) {
840
+ return reactiveReadArray(this).toSpliced(...args);
841
+ },
842
+ unshift(...args) {
843
+ return noTracking(this, "unshift", args);
844
+ },
845
+ values() {
846
+ return iterator(this, "values", toReactive);
847
+ }
848
+ };
849
+ function iterator(self, method, wrapValue) {
850
+ const arr = shallowReadArray(self);
851
+ const iter = arr[method]();
852
+ if (arr !== self && !isShallow(self)) {
853
+ iter._next = iter.next;
854
+ iter.next = () => {
855
+ const result = iter._next();
856
+ if (result.value) {
857
+ result.value = wrapValue(result.value);
858
+ }
859
+ return result;
860
+ };
861
+ }
862
+ return iter;
863
+ }
864
+ const arrayProto = Array.prototype;
865
+ function apply(self, method, fn, thisArg, wrappedRetFn, args) {
866
+ const arr = shallowReadArray(self);
867
+ const needsWrap = arr !== self && !isShallow(self);
868
+ const methodFn = arr[method];
869
+ if (methodFn !== arrayProto[method]) {
870
+ const result2 = methodFn.apply(self, args);
871
+ return needsWrap ? toReactive(result2) : result2;
872
+ }
873
+ let wrappedFn = fn;
874
+ if (arr !== self) {
875
+ if (needsWrap) {
876
+ wrappedFn = function(item, index) {
877
+ return fn.call(this, toReactive(item), index, self);
878
+ };
879
+ } else if (fn.length > 2) {
880
+ wrappedFn = function(item, index) {
881
+ return fn.call(this, item, index, self);
882
+ };
883
+ }
884
+ }
885
+ const result = methodFn.call(arr, wrappedFn, thisArg);
886
+ return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
887
+ }
888
+ function reduce(self, method, fn, args) {
889
+ const arr = shallowReadArray(self);
890
+ let wrappedFn = fn;
891
+ if (arr !== self) {
892
+ if (!isShallow(self)) {
893
+ wrappedFn = function(acc, item, index) {
894
+ return fn.call(this, acc, toReactive(item), index, self);
895
+ };
896
+ } else if (fn.length > 3) {
897
+ wrappedFn = function(acc, item, index) {
898
+ return fn.call(this, acc, item, index, self);
899
+ };
900
+ }
901
+ }
902
+ return arr[method](wrappedFn, ...args);
903
+ }
904
+ function searchProxy(self, method, args) {
905
+ const arr = toRaw(self);
906
+ track(arr, "iterate", ARRAY_ITERATE_KEY);
907
+ const res = arr[method](...args);
908
+ if ((res === -1 || res === false) && isProxy(args[0])) {
909
+ args[0] = toRaw(args[0]);
910
+ return arr[method](...args);
911
+ }
912
+ return res;
913
+ }
914
+ function noTracking(self, method, args = []) {
915
+ pauseTracking();
916
+ startBatch();
917
+ const res = toRaw(self)[method].apply(self, args);
918
+ endBatch();
919
+ resetTracking();
920
+ return res;
438
921
  }
439
922
  const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
440
923
  const builtInSymbols = new Set(
441
924
  /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
442
925
  );
443
- const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
444
- function createArrayInstrumentations() {
445
- const instrumentations = {};
446
- ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
447
- instrumentations[key] = function(...args) {
448
- const arr = toRaw(this);
449
- for (let i = 0, l = this.length; i < l; i++) {
450
- track(arr, "get", i + "");
451
- }
452
- const res = arr[key](...args);
453
- if (res === -1 || res === false) {
454
- return arr[key](...args.map(toRaw));
455
- } else {
456
- return res;
457
- }
458
- };
459
- });
460
- ["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
461
- instrumentations[key] = function(...args) {
462
- pauseTracking();
463
- pauseScheduling();
464
- const res = toRaw(this)[key].apply(this, args);
465
- resetScheduling();
466
- resetTracking();
467
- return res;
468
- };
469
- });
470
- return instrumentations;
471
- }
472
926
  function hasOwnProperty(key) {
473
- if (!isSymbol(key))
474
- key = String(key);
927
+ if (!isSymbol(key)) key = String(key);
475
928
  const obj = toRaw(this);
476
929
  track(obj, "has", key);
477
930
  return obj.hasOwnProperty(key);
@@ -491,7 +944,7 @@ class BaseReactiveHandler {
491
944
  return isShallow2;
492
945
  } else if (key === "__v_raw") {
493
946
  if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
494
- // this means the reciever is a user proxy of the reactive proxy
947
+ // this means the receiver is a user proxy of the reactive proxy
495
948
  Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
496
949
  return target;
497
950
  }
@@ -499,14 +952,22 @@ class BaseReactiveHandler {
499
952
  }
500
953
  const targetIsArray = isArray(target);
501
954
  if (!isReadonly2) {
502
- if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
503
- return Reflect.get(arrayInstrumentations, key, receiver);
955
+ let fn;
956
+ if (targetIsArray && (fn = arrayInstrumentations[key])) {
957
+ return fn;
504
958
  }
505
959
  if (key === "hasOwnProperty") {
506
960
  return hasOwnProperty;
507
961
  }
508
962
  }
509
- const res = Reflect.get(target, key, receiver);
963
+ const res = Reflect.get(
964
+ target,
965
+ key,
966
+ // if this is a proxy wrapping a ref, return methods using the raw ref
967
+ // as receiver so that we don't have to call `toRaw` on the ref in all
968
+ // its class methods
969
+ isRef(target) ? target : receiver
970
+ );
510
971
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
511
972
  return res;
512
973
  }
@@ -547,7 +1008,12 @@ class MutableReactiveHandler extends BaseReactiveHandler {
547
1008
  }
548
1009
  }
549
1010
  const hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
550
- const result = Reflect.set(target, key, value, receiver);
1011
+ const result = Reflect.set(
1012
+ target,
1013
+ key,
1014
+ value,
1015
+ isRef(target) ? target : receiver
1016
+ );
551
1017
  if (target === toRaw(receiver)) {
552
1018
  if (!hadKey) {
553
1019
  trigger(target, "add", key, value);
@@ -607,119 +1073,10 @@ class ReadonlyReactiveHandler extends BaseReactiveHandler {
607
1073
  }
608
1074
  const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
609
1075
  const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
610
- const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
611
- true
612
- );
1076
+ const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
613
1077
  const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
614
1078
  const toShallow = (value) => value;
615
1079
  const getProto = (v) => Reflect.getPrototypeOf(v);
616
- function get(target, key, isReadonly2 = false, isShallow2 = false) {
617
- target = target["__v_raw"];
618
- const rawTarget = toRaw(target);
619
- const rawKey = toRaw(key);
620
- if (!isReadonly2) {
621
- if (hasChanged(key, rawKey)) {
622
- track(rawTarget, "get", key);
623
- }
624
- track(rawTarget, "get", rawKey);
625
- }
626
- const { has: has2 } = getProto(rawTarget);
627
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
628
- if (has2.call(rawTarget, key)) {
629
- return wrap(target.get(key));
630
- } else if (has2.call(rawTarget, rawKey)) {
631
- return wrap(target.get(rawKey));
632
- } else if (target !== rawTarget) {
633
- target.get(key);
634
- }
635
- }
636
- function has(key, isReadonly2 = false) {
637
- const target = this["__v_raw"];
638
- const rawTarget = toRaw(target);
639
- const rawKey = toRaw(key);
640
- if (!isReadonly2) {
641
- if (hasChanged(key, rawKey)) {
642
- track(rawTarget, "has", key);
643
- }
644
- track(rawTarget, "has", rawKey);
645
- }
646
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
647
- }
648
- function size(target, isReadonly2 = false) {
649
- target = target["__v_raw"];
650
- !isReadonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
651
- return Reflect.get(target, "size", target);
652
- }
653
- function add(value) {
654
- value = toRaw(value);
655
- const target = toRaw(this);
656
- const proto = getProto(target);
657
- const hadKey = proto.has.call(target, value);
658
- if (!hadKey) {
659
- target.add(value);
660
- trigger(target, "add", value, value);
661
- }
662
- return this;
663
- }
664
- function set(key, value) {
665
- value = toRaw(value);
666
- const target = toRaw(this);
667
- const { has: has2, get: get2 } = getProto(target);
668
- let hadKey = has2.call(target, key);
669
- if (!hadKey) {
670
- key = toRaw(key);
671
- hadKey = has2.call(target, key);
672
- } else if (!!(process.env.NODE_ENV !== "production")) {
673
- checkIdentityKeys(target, has2, key);
674
- }
675
- const oldValue = get2.call(target, key);
676
- target.set(key, value);
677
- if (!hadKey) {
678
- trigger(target, "add", key, value);
679
- } else if (hasChanged(value, oldValue)) {
680
- trigger(target, "set", key, value, oldValue);
681
- }
682
- return this;
683
- }
684
- function deleteEntry(key) {
685
- const target = toRaw(this);
686
- const { has: has2, get: get2 } = getProto(target);
687
- let hadKey = has2.call(target, key);
688
- if (!hadKey) {
689
- key = toRaw(key);
690
- hadKey = has2.call(target, key);
691
- } else if (!!(process.env.NODE_ENV !== "production")) {
692
- checkIdentityKeys(target, has2, key);
693
- }
694
- const oldValue = get2 ? get2.call(target, key) : void 0;
695
- const result = target.delete(key);
696
- if (hadKey) {
697
- trigger(target, "delete", key, void 0, oldValue);
698
- }
699
- return result;
700
- }
701
- function clear() {
702
- const target = toRaw(this);
703
- const hadItems = target.size !== 0;
704
- const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0;
705
- const result = target.clear();
706
- if (hadItems) {
707
- trigger(target, "clear", void 0, void 0, oldTarget);
708
- }
709
- return result;
710
- }
711
- function createForEach(isReadonly2, isShallow2) {
712
- return function forEach(callback, thisArg) {
713
- const observed = this;
714
- const target = observed["__v_raw"];
715
- const rawTarget = toRaw(target);
716
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
717
- !isReadonly2 && track(rawTarget, "iterate", ITERATE_KEY);
718
- return target.forEach((value, key) => {
719
- return callback.call(thisArg, wrap(value), wrap(key), observed);
720
- });
721
- };
722
- }
723
1080
  function createIterableMethod(method, isReadonly2, isShallow2) {
724
1081
  return function(...args) {
725
1082
  const target = this["__v_raw"];
@@ -762,67 +1119,134 @@ function createReadonlyMethod(type) {
762
1119
  return type === "delete" ? false : type === "clear" ? void 0 : this;
763
1120
  };
764
1121
  }
765
- function createInstrumentations() {
766
- const mutableInstrumentations2 = {
767
- get(key) {
768
- return get(this, key);
769
- },
770
- get size() {
771
- return size(this);
772
- },
773
- has,
774
- add,
775
- set,
776
- delete: deleteEntry,
777
- clear,
778
- forEach: createForEach(false, false)
779
- };
780
- const shallowInstrumentations2 = {
781
- get(key) {
782
- return get(this, key, false, true);
783
- },
784
- get size() {
785
- return size(this);
786
- },
787
- has,
788
- add,
789
- set,
790
- delete: deleteEntry,
791
- clear,
792
- forEach: createForEach(false, true)
793
- };
794
- const readonlyInstrumentations2 = {
1122
+ function createInstrumentations(readonly2, shallow) {
1123
+ const instrumentations = {
795
1124
  get(key) {
796
- return get(this, key, true);
797
- },
798
- get size() {
799
- return size(this, true);
800
- },
801
- has(key) {
802
- return has.call(this, key, true);
803
- },
804
- add: createReadonlyMethod("add"),
805
- set: createReadonlyMethod("set"),
806
- delete: createReadonlyMethod("delete"),
807
- clear: createReadonlyMethod("clear"),
808
- forEach: createForEach(true, false)
809
- };
810
- const shallowReadonlyInstrumentations2 = {
811
- get(key) {
812
- return get(this, key, true, true);
1125
+ const target = this["__v_raw"];
1126
+ const rawTarget = toRaw(target);
1127
+ const rawKey = toRaw(key);
1128
+ if (!readonly2) {
1129
+ if (hasChanged(key, rawKey)) {
1130
+ track(rawTarget, "get", key);
1131
+ }
1132
+ track(rawTarget, "get", rawKey);
1133
+ }
1134
+ const { has } = getProto(rawTarget);
1135
+ const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive;
1136
+ if (has.call(rawTarget, key)) {
1137
+ return wrap(target.get(key));
1138
+ } else if (has.call(rawTarget, rawKey)) {
1139
+ return wrap(target.get(rawKey));
1140
+ } else if (target !== rawTarget) {
1141
+ target.get(key);
1142
+ }
813
1143
  },
814
1144
  get size() {
815
- return size(this, true);
1145
+ const target = this["__v_raw"];
1146
+ !readonly2 && track(toRaw(target), "iterate", ITERATE_KEY);
1147
+ return Reflect.get(target, "size", target);
816
1148
  },
817
1149
  has(key) {
818
- return has.call(this, key, true);
1150
+ const target = this["__v_raw"];
1151
+ const rawTarget = toRaw(target);
1152
+ const rawKey = toRaw(key);
1153
+ if (!readonly2) {
1154
+ if (hasChanged(key, rawKey)) {
1155
+ track(rawTarget, "has", key);
1156
+ }
1157
+ track(rawTarget, "has", rawKey);
1158
+ }
1159
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
819
1160
  },
820
- add: createReadonlyMethod("add"),
821
- set: createReadonlyMethod("set"),
822
- delete: createReadonlyMethod("delete"),
823
- clear: createReadonlyMethod("clear"),
824
- forEach: createForEach(true, true)
1161
+ forEach(callback, thisArg) {
1162
+ const observed = this;
1163
+ const target = observed["__v_raw"];
1164
+ const rawTarget = toRaw(target);
1165
+ const wrap = shallow ? toShallow : readonly2 ? toReadonly : toReactive;
1166
+ !readonly2 && track(rawTarget, "iterate", ITERATE_KEY);
1167
+ return target.forEach((value, key) => {
1168
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1169
+ });
1170
+ }
825
1171
  };
1172
+ extend(
1173
+ instrumentations,
1174
+ readonly2 ? {
1175
+ add: createReadonlyMethod("add"),
1176
+ set: createReadonlyMethod("set"),
1177
+ delete: createReadonlyMethod("delete"),
1178
+ clear: createReadonlyMethod("clear")
1179
+ } : {
1180
+ add(value) {
1181
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1182
+ value = toRaw(value);
1183
+ }
1184
+ const target = toRaw(this);
1185
+ const proto = getProto(target);
1186
+ const hadKey = proto.has.call(target, value);
1187
+ if (!hadKey) {
1188
+ target.add(value);
1189
+ trigger(target, "add", value, value);
1190
+ }
1191
+ return this;
1192
+ },
1193
+ set(key, value) {
1194
+ if (!shallow && !isShallow(value) && !isReadonly(value)) {
1195
+ value = toRaw(value);
1196
+ }
1197
+ const target = toRaw(this);
1198
+ const { has, get } = getProto(target);
1199
+ let hadKey = has.call(target, key);
1200
+ if (!hadKey) {
1201
+ key = toRaw(key);
1202
+ hadKey = has.call(target, key);
1203
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1204
+ checkIdentityKeys(target, has, key);
1205
+ }
1206
+ const oldValue = get.call(target, key);
1207
+ target.set(key, value);
1208
+ if (!hadKey) {
1209
+ trigger(target, "add", key, value);
1210
+ } else if (hasChanged(value, oldValue)) {
1211
+ trigger(target, "set", key, value, oldValue);
1212
+ }
1213
+ return this;
1214
+ },
1215
+ delete(key) {
1216
+ const target = toRaw(this);
1217
+ const { has, get } = getProto(target);
1218
+ let hadKey = has.call(target, key);
1219
+ if (!hadKey) {
1220
+ key = toRaw(key);
1221
+ hadKey = has.call(target, key);
1222
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1223
+ checkIdentityKeys(target, has, key);
1224
+ }
1225
+ const oldValue = get ? get.call(target, key) : void 0;
1226
+ const result = target.delete(key);
1227
+ if (hadKey) {
1228
+ trigger(target, "delete", key, void 0, oldValue);
1229
+ }
1230
+ return result;
1231
+ },
1232
+ clear() {
1233
+ const target = toRaw(this);
1234
+ const hadItems = target.size !== 0;
1235
+ const oldTarget = !!(process.env.NODE_ENV !== "production") ? isMap(target) ? new Map(target) : new Set(target) : void 0;
1236
+ const result = target.clear();
1237
+ if (hadItems) {
1238
+ trigger(
1239
+ target,
1240
+ "clear",
1241
+ void 0,
1242
+ void 0,
1243
+ oldTarget
1244
+ );
1245
+ }
1246
+ return result;
1247
+ }
1248
+ }
1249
+ );
826
1250
  const iteratorMethods = [
827
1251
  "keys",
828
1252
  "values",
@@ -830,30 +1254,12 @@ function createInstrumentations() {
830
1254
  Symbol.iterator
831
1255
  ];
832
1256
  iteratorMethods.forEach((method) => {
833
- mutableInstrumentations2[method] = createIterableMethod(method, false, false);
834
- readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
835
- shallowInstrumentations2[method] = createIterableMethod(method, false, true);
836
- shallowReadonlyInstrumentations2[method] = createIterableMethod(
837
- method,
838
- true,
839
- true
840
- );
1257
+ instrumentations[method] = createIterableMethod(method, readonly2, shallow);
841
1258
  });
842
- return [
843
- mutableInstrumentations2,
844
- readonlyInstrumentations2,
845
- shallowInstrumentations2,
846
- shallowReadonlyInstrumentations2
847
- ];
1259
+ return instrumentations;
848
1260
  }
849
- const [
850
- mutableInstrumentations,
851
- readonlyInstrumentations,
852
- shallowInstrumentations,
853
- shallowReadonlyInstrumentations
854
- ] = /* @__PURE__ */ createInstrumentations();
855
1261
  function createInstrumentationGetter(isReadonly2, shallow) {
856
- const instrumentations = shallow ? isReadonly2 ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly2 ? readonlyInstrumentations : mutableInstrumentations;
1262
+ const instrumentations = createInstrumentations(isReadonly2, shallow);
857
1263
  return (target, key, receiver) => {
858
1264
  if (key === "__v_isReactive") {
859
1265
  return !isReadonly2;
@@ -881,9 +1287,9 @@ const readonlyCollectionHandlers = {
881
1287
  const shallowReadonlyCollectionHandlers = {
882
1288
  get: /* @__PURE__ */ createInstrumentationGetter(true, true)
883
1289
  };
884
- function checkIdentityKeys(target, has2, key) {
1290
+ function checkIdentityKeys(target, has, key) {
885
1291
  const rawKey = toRaw(key);
886
- if (rawKey !== key && has2.call(target, rawKey)) {
1292
+ if (rawKey !== key && has.call(target, rawKey)) {
887
1293
  const type = toRawType(target);
888
1294
  warn$1(
889
1295
  `Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
@@ -953,7 +1359,11 @@ function shallowReadonly(target) {
953
1359
  function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
954
1360
  if (!isObject(target)) {
955
1361
  if (!!(process.env.NODE_ENV !== "production")) {
956
- warn$1(`value cannot be made reactive: ${String(target)}`);
1362
+ warn$1(
1363
+ `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
1364
+ target
1365
+ )}`
1366
+ );
957
1367
  }
958
1368
  return target;
959
1369
  }
@@ -995,116 +1405,15 @@ function toRaw(observed) {
995
1405
  return raw ? toRaw(raw) : observed;
996
1406
  }
997
1407
  function markRaw(value) {
998
- if (Object.isExtensible(value)) {
1408
+ if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
999
1409
  def(value, "__v_skip", true);
1000
1410
  }
1001
1411
  return value;
1002
1412
  }
1003
1413
  const toReactive = (value) => isObject(value) ? reactive(value) : value;
1004
1414
  const toReadonly = (value) => isObject(value) ? readonly(value) : value;
1005
- const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
1006
- class ComputedRefImpl {
1007
- constructor(getter, _setter, isReadonly2, isSSR) {
1008
- this.getter = getter;
1009
- this._setter = _setter;
1010
- this.dep = void 0;
1011
- this.__v_isRef = true;
1012
- this["__v_isReadonly"] = false;
1013
- this.effect = new ReactiveEffect(
1014
- () => getter(this._value),
1015
- () => triggerRefValue(
1016
- this,
1017
- this.effect._dirtyLevel === 2 ? 2 : 3
1018
- )
1019
- );
1020
- this.effect.computed = this;
1021
- this.effect.active = this._cacheable = !isSSR;
1022
- this["__v_isReadonly"] = isReadonly2;
1023
- }
1024
- get value() {
1025
- const self = toRaw(this);
1026
- if ((!self._cacheable || self.effect.dirty) && hasChanged(self._value, self._value = self.effect.run())) {
1027
- triggerRefValue(self, 4);
1028
- }
1029
- trackRefValue(self);
1030
- if (self.effect._dirtyLevel >= 2) {
1031
- if (!!(process.env.NODE_ENV !== "production") && this._warnRecursive) {
1032
- warn$1(COMPUTED_SIDE_EFFECT_WARN, `
1033
-
1034
- getter: `, this.getter);
1035
- }
1036
- triggerRefValue(self, 2);
1037
- }
1038
- return self._value;
1039
- }
1040
- set value(newValue) {
1041
- this._setter(newValue);
1042
- }
1043
- // #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
1044
- get _dirty() {
1045
- return this.effect.dirty;
1046
- }
1047
- set _dirty(v) {
1048
- this.effect.dirty = v;
1049
- }
1050
- // #endregion
1051
- }
1052
- function computed(getterOrOptions, debugOptions, isSSR = false) {
1053
- let getter;
1054
- let setter;
1055
- const onlyGetter = isFunction(getterOrOptions);
1056
- if (onlyGetter) {
1057
- getter = getterOrOptions;
1058
- setter = !!(process.env.NODE_ENV !== "production") ? () => {
1059
- warn$1("Write operation failed: computed value is readonly");
1060
- } : NOOP;
1061
- } else {
1062
- getter = getterOrOptions.get;
1063
- setter = getterOrOptions.set;
1064
- }
1065
- const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1066
- if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
1067
- cRef.effect.onTrack = debugOptions.onTrack;
1068
- cRef.effect.onTrigger = debugOptions.onTrigger;
1069
- }
1070
- return cRef;
1071
- }
1072
- function trackRefValue(ref2) {
1073
- var _a;
1074
- if (shouldTrack && activeEffect) {
1075
- ref2 = toRaw(ref2);
1076
- trackEffect(
1077
- activeEffect,
1078
- (_a = ref2.dep) != null ? _a : ref2.dep = createDep(
1079
- () => ref2.dep = void 0,
1080
- ref2 instanceof ComputedRefImpl ? ref2 : void 0
1081
- ),
1082
- !!(process.env.NODE_ENV !== "production") ? {
1083
- target: ref2,
1084
- type: "get",
1085
- key: "value"
1086
- } : void 0
1087
- );
1088
- }
1089
- }
1090
- function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
1091
- ref2 = toRaw(ref2);
1092
- const dep = ref2.dep;
1093
- if (dep) {
1094
- triggerEffects(
1095
- dep,
1096
- dirtyLevel,
1097
- !!(process.env.NODE_ENV !== "production") ? {
1098
- target: ref2,
1099
- type: "set",
1100
- key: "value",
1101
- newValue: newVal
1102
- } : void 0
1103
- );
1104
- }
1105
- }
1106
1415
  function isRef(r) {
1107
- return !!(r && r.__v_isRef === true);
1416
+ return r ? r["__v_isRef"] === true : false;
1108
1417
  }
1109
1418
  function ref(value) {
1110
1419
  return createRef(value, false);
@@ -1119,29 +1428,60 @@ function createRef(rawValue, shallow) {
1119
1428
  return new RefImpl(rawValue, shallow);
1120
1429
  }
1121
1430
  class RefImpl {
1122
- constructor(value, __v_isShallow) {
1123
- this.__v_isShallow = __v_isShallow;
1124
- this.dep = void 0;
1125
- this.__v_isRef = true;
1126
- this._rawValue = __v_isShallow ? value : toRaw(value);
1127
- this._value = __v_isShallow ? value : toReactive(value);
1431
+ constructor(value, isShallow2) {
1432
+ this.dep = new Dep();
1433
+ this["__v_isRef"] = true;
1434
+ this["__v_isShallow"] = false;
1435
+ this._rawValue = isShallow2 ? value : toRaw(value);
1436
+ this._value = isShallow2 ? value : toReactive(value);
1437
+ this["__v_isShallow"] = isShallow2;
1128
1438
  }
1129
1439
  get value() {
1130
- trackRefValue(this);
1440
+ if (!!(process.env.NODE_ENV !== "production")) {
1441
+ this.dep.track({
1442
+ target: this,
1443
+ type: "get",
1444
+ key: "value"
1445
+ });
1446
+ } else {
1447
+ this.dep.track();
1448
+ }
1131
1449
  return this._value;
1132
1450
  }
1133
- set value(newVal) {
1134
- const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1135
- newVal = useDirectValue ? newVal : toRaw(newVal);
1136
- if (hasChanged(newVal, this._rawValue)) {
1137
- this._rawValue = newVal;
1138
- this._value = useDirectValue ? newVal : toReactive(newVal);
1139
- triggerRefValue(this, 4, newVal);
1451
+ set value(newValue) {
1452
+ const oldValue = this._rawValue;
1453
+ const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1454
+ newValue = useDirectValue ? newValue : toRaw(newValue);
1455
+ if (hasChanged(newValue, oldValue)) {
1456
+ this._rawValue = newValue;
1457
+ this._value = useDirectValue ? newValue : toReactive(newValue);
1458
+ if (!!(process.env.NODE_ENV !== "production")) {
1459
+ this.dep.trigger({
1460
+ target: this,
1461
+ type: "set",
1462
+ key: "value",
1463
+ newValue,
1464
+ oldValue
1465
+ });
1466
+ } else {
1467
+ this.dep.trigger();
1468
+ }
1140
1469
  }
1141
1470
  }
1142
1471
  }
1143
1472
  function triggerRef(ref2) {
1144
- triggerRefValue(ref2, 4, !!(process.env.NODE_ENV !== "production") ? ref2.value : void 0);
1473
+ if (ref2.dep) {
1474
+ if (!!(process.env.NODE_ENV !== "production")) {
1475
+ ref2.dep.trigger({
1476
+ target: ref2,
1477
+ type: "set",
1478
+ key: "value",
1479
+ newValue: ref2._value
1480
+ });
1481
+ } else {
1482
+ ref2.dep.trigger();
1483
+ }
1484
+ }
1145
1485
  }
1146
1486
  function unref(ref2) {
1147
1487
  return isRef(ref2) ? ref2.value : ref2;
@@ -1150,7 +1490,7 @@ function toValue(source) {
1150
1490
  return isFunction(source) ? source() : unref(source);
1151
1491
  }
1152
1492
  const shallowUnwrapHandlers = {
1153
- get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
1493
+ get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1154
1494
  set: (target, key, value, receiver) => {
1155
1495
  const oldValue = target[key];
1156
1496
  if (isRef(oldValue) && !isRef(value)) {
@@ -1166,17 +1506,15 @@ function proxyRefs(objectWithRefs) {
1166
1506
  }
1167
1507
  class CustomRefImpl {
1168
1508
  constructor(factory) {
1169
- this.dep = void 0;
1170
- this.__v_isRef = true;
1171
- const { get: get2, set: set2 } = factory(
1172
- () => trackRefValue(this),
1173
- () => triggerRefValue(this)
1174
- );
1175
- this._get = get2;
1176
- this._set = set2;
1509
+ this["__v_isRef"] = true;
1510
+ this._value = void 0;
1511
+ const dep = this.dep = new Dep();
1512
+ const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1513
+ this._get = get;
1514
+ this._set = set;
1177
1515
  }
1178
1516
  get value() {
1179
- return this._get();
1517
+ return this._value = this._get();
1180
1518
  }
1181
1519
  set value(newVal) {
1182
1520
  this._set(newVal);
@@ -1200,11 +1538,12 @@ class ObjectRefImpl {
1200
1538
  this._object = _object;
1201
1539
  this._key = _key;
1202
1540
  this._defaultValue = _defaultValue;
1203
- this.__v_isRef = true;
1541
+ this["__v_isRef"] = true;
1542
+ this._value = void 0;
1204
1543
  }
1205
1544
  get value() {
1206
1545
  const val = this._object[this._key];
1207
- return val === void 0 ? this._defaultValue : val;
1546
+ return this._value = val === void 0 ? this._defaultValue : val;
1208
1547
  }
1209
1548
  set value(newVal) {
1210
1549
  this._object[this._key] = newVal;
@@ -1216,11 +1555,12 @@ class ObjectRefImpl {
1216
1555
  class GetterRefImpl {
1217
1556
  constructor(_getter) {
1218
1557
  this._getter = _getter;
1219
- this.__v_isRef = true;
1220
- this.__v_isReadonly = true;
1558
+ this["__v_isRef"] = true;
1559
+ this["__v_isReadonly"] = true;
1560
+ this._value = void 0;
1221
1561
  }
1222
1562
  get value() {
1223
- return this._getter();
1563
+ return this._value = this._getter();
1224
1564
  }
1225
1565
  }
1226
1566
  function toRef(source, key, defaultValue) {
@@ -1238,7 +1578,69 @@ function propertyToRef(source, key, defaultValue) {
1238
1578
  const val = source[key];
1239
1579
  return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1240
1580
  }
1241
- const deferredComputed = computed;
1581
+ class ComputedRefImpl {
1582
+ constructor(fn, setter, isSSR) {
1583
+ this.fn = fn;
1584
+ this.setter = setter;
1585
+ this._value = void 0;
1586
+ this.dep = new Dep(this);
1587
+ this.__v_isRef = true;
1588
+ this.deps = void 0;
1589
+ this.depsTail = void 0;
1590
+ this.flags = 16;
1591
+ this.globalVersion = globalVersion - 1;
1592
+ this.next = void 0;
1593
+ this.effect = this;
1594
+ this["__v_isReadonly"] = !setter;
1595
+ this.isSSR = isSSR;
1596
+ }
1597
+ /**
1598
+ * @internal
1599
+ */
1600
+ notify() {
1601
+ this.flags |= 16;
1602
+ if (!(this.flags & 8) && // avoid infinite self recursion
1603
+ activeSub !== this) {
1604
+ batch(this, true);
1605
+ return true;
1606
+ } else if (!!(process.env.NODE_ENV !== "production")) ;
1607
+ }
1608
+ get value() {
1609
+ const link = !!(process.env.NODE_ENV !== "production") ? this.dep.track({
1610
+ target: this,
1611
+ type: "get",
1612
+ key: "value"
1613
+ }) : this.dep.track();
1614
+ refreshComputed(this);
1615
+ if (link) {
1616
+ link.version = this.dep.version;
1617
+ }
1618
+ return this._value;
1619
+ }
1620
+ set value(newValue) {
1621
+ if (this.setter) {
1622
+ this.setter(newValue);
1623
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1624
+ warn$1("Write operation failed: computed value is readonly");
1625
+ }
1626
+ }
1627
+ }
1628
+ function computed(getterOrOptions, debugOptions, isSSR = false) {
1629
+ let getter;
1630
+ let setter;
1631
+ if (isFunction(getterOrOptions)) {
1632
+ getter = getterOrOptions;
1633
+ } else {
1634
+ getter = getterOrOptions.get;
1635
+ setter = getterOrOptions.set;
1636
+ }
1637
+ const cRef = new ComputedRefImpl(getter, setter, isSSR);
1638
+ if (!!(process.env.NODE_ENV !== "production") && debugOptions && !isSSR) {
1639
+ cRef.onTrack = debugOptions.onTrack;
1640
+ cRef.onTrigger = debugOptions.onTrigger;
1641
+ }
1642
+ return cRef;
1643
+ }
1242
1644
  const TrackOpTypes = {
1243
1645
  "GET": "get",
1244
1646
  "HAS": "has",
@@ -1255,8 +1657,222 @@ const ReactiveFlags = {
1255
1657
  "IS_REACTIVE": "__v_isReactive",
1256
1658
  "IS_READONLY": "__v_isReadonly",
1257
1659
  "IS_SHALLOW": "__v_isShallow",
1258
- "RAW": "__v_raw"
1660
+ "RAW": "__v_raw",
1661
+ "IS_REF": "__v_isRef"
1259
1662
  };
1663
+ const WatchErrorCodes = {
1664
+ "WATCH_GETTER": 2,
1665
+ "2": "WATCH_GETTER",
1666
+ "WATCH_CALLBACK": 3,
1667
+ "3": "WATCH_CALLBACK",
1668
+ "WATCH_CLEANUP": 4,
1669
+ "4": "WATCH_CLEANUP"
1670
+ };
1671
+ const INITIAL_WATCHER_VALUE = {};
1672
+ const cleanupMap = /* @__PURE__ */ new WeakMap();
1673
+ let activeWatcher = void 0;
1674
+ function getCurrentWatcher() {
1675
+ return activeWatcher;
1676
+ }
1677
+ function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1678
+ if (owner) {
1679
+ let cleanups = cleanupMap.get(owner);
1680
+ if (!cleanups) cleanupMap.set(owner, cleanups = []);
1681
+ cleanups.push(cleanupFn);
1682
+ } else if (!!(process.env.NODE_ENV !== "production") && !failSilently) {
1683
+ warn$1(
1684
+ `onWatcherCleanup() was called when there was no active watcher to associate with.`
1685
+ );
1686
+ }
1687
+ }
1688
+ function watch$1(source, cb, options = EMPTY_OBJ) {
1689
+ const { immediate, deep, once, scheduler, augmentJob, call } = options;
1690
+ const warnInvalidSource = (s) => {
1691
+ (options.onWarn || warn$1)(
1692
+ `Invalid watch source: `,
1693
+ s,
1694
+ `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1695
+ );
1696
+ };
1697
+ const reactiveGetter = (source2) => {
1698
+ if (deep) return source2;
1699
+ if (isShallow(source2) || deep === false || deep === 0)
1700
+ return traverse(source2, 1);
1701
+ return traverse(source2);
1702
+ };
1703
+ let effect2;
1704
+ let getter;
1705
+ let cleanup;
1706
+ let boundCleanup;
1707
+ let forceTrigger = false;
1708
+ let isMultiSource = false;
1709
+ if (isRef(source)) {
1710
+ getter = () => source.value;
1711
+ forceTrigger = isShallow(source);
1712
+ } else if (isReactive(source)) {
1713
+ getter = () => reactiveGetter(source);
1714
+ forceTrigger = true;
1715
+ } else if (isArray(source)) {
1716
+ isMultiSource = true;
1717
+ forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1718
+ getter = () => source.map((s) => {
1719
+ if (isRef(s)) {
1720
+ return s.value;
1721
+ } else if (isReactive(s)) {
1722
+ return reactiveGetter(s);
1723
+ } else if (isFunction(s)) {
1724
+ return call ? call(s, 2) : s();
1725
+ } else {
1726
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
1727
+ }
1728
+ });
1729
+ } else if (isFunction(source)) {
1730
+ if (cb) {
1731
+ getter = call ? () => call(source, 2) : source;
1732
+ } else {
1733
+ getter = () => {
1734
+ if (cleanup) {
1735
+ pauseTracking();
1736
+ try {
1737
+ cleanup();
1738
+ } finally {
1739
+ resetTracking();
1740
+ }
1741
+ }
1742
+ const currentEffect = activeWatcher;
1743
+ activeWatcher = effect2;
1744
+ try {
1745
+ return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1746
+ } finally {
1747
+ activeWatcher = currentEffect;
1748
+ }
1749
+ };
1750
+ }
1751
+ } else {
1752
+ getter = NOOP;
1753
+ !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
1754
+ }
1755
+ if (cb && deep) {
1756
+ const baseGetter = getter;
1757
+ const depth = deep === true ? Infinity : deep;
1758
+ getter = () => traverse(baseGetter(), depth);
1759
+ }
1760
+ const scope = getCurrentScope();
1761
+ const watchHandle = () => {
1762
+ effect2.stop();
1763
+ if (scope) {
1764
+ remove(scope.effects, effect2);
1765
+ }
1766
+ };
1767
+ if (once && cb) {
1768
+ const _cb = cb;
1769
+ cb = (...args) => {
1770
+ _cb(...args);
1771
+ watchHandle();
1772
+ };
1773
+ }
1774
+ let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1775
+ const job = (immediateFirstRun) => {
1776
+ if (!(effect2.flags & 1) || !effect2.dirty && !immediateFirstRun) {
1777
+ return;
1778
+ }
1779
+ if (cb) {
1780
+ const newValue = effect2.run();
1781
+ if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1782
+ if (cleanup) {
1783
+ cleanup();
1784
+ }
1785
+ const currentWatcher = activeWatcher;
1786
+ activeWatcher = effect2;
1787
+ try {
1788
+ const args = [
1789
+ newValue,
1790
+ // pass undefined as the old value when it's changed for the first time
1791
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1792
+ boundCleanup
1793
+ ];
1794
+ call ? call(cb, 3, args) : (
1795
+ // @ts-expect-error
1796
+ cb(...args)
1797
+ );
1798
+ oldValue = newValue;
1799
+ } finally {
1800
+ activeWatcher = currentWatcher;
1801
+ }
1802
+ }
1803
+ } else {
1804
+ effect2.run();
1805
+ }
1806
+ };
1807
+ if (augmentJob) {
1808
+ augmentJob(job);
1809
+ }
1810
+ effect2 = new ReactiveEffect(getter);
1811
+ effect2.scheduler = scheduler ? () => scheduler(job, false) : job;
1812
+ boundCleanup = (fn) => onWatcherCleanup(fn, false, effect2);
1813
+ cleanup = effect2.onStop = () => {
1814
+ const cleanups = cleanupMap.get(effect2);
1815
+ if (cleanups) {
1816
+ if (call) {
1817
+ call(cleanups, 4);
1818
+ } else {
1819
+ for (const cleanup2 of cleanups) cleanup2();
1820
+ }
1821
+ cleanupMap.delete(effect2);
1822
+ }
1823
+ };
1824
+ if (!!(process.env.NODE_ENV !== "production")) {
1825
+ effect2.onTrack = options.onTrack;
1826
+ effect2.onTrigger = options.onTrigger;
1827
+ }
1828
+ if (cb) {
1829
+ if (immediate) {
1830
+ job(true);
1831
+ } else {
1832
+ oldValue = effect2.run();
1833
+ }
1834
+ } else if (scheduler) {
1835
+ scheduler(job.bind(null, true), true);
1836
+ } else {
1837
+ effect2.run();
1838
+ }
1839
+ watchHandle.pause = effect2.pause.bind(effect2);
1840
+ watchHandle.resume = effect2.resume.bind(effect2);
1841
+ watchHandle.stop = watchHandle;
1842
+ return watchHandle;
1843
+ }
1844
+ function traverse(value, depth = Infinity, seen) {
1845
+ if (depth <= 0 || !isObject(value) || value["__v_skip"]) {
1846
+ return value;
1847
+ }
1848
+ seen = seen || /* @__PURE__ */ new Set();
1849
+ if (seen.has(value)) {
1850
+ return value;
1851
+ }
1852
+ seen.add(value);
1853
+ depth--;
1854
+ if (isRef(value)) {
1855
+ traverse(value.value, depth, seen);
1856
+ } else if (isArray(value)) {
1857
+ for (let i = 0; i < value.length; i++) {
1858
+ traverse(value[i], depth, seen);
1859
+ }
1860
+ } else if (isSet(value) || isMap(value)) {
1861
+ value.forEach((v) => {
1862
+ traverse(v, depth, seen);
1863
+ });
1864
+ } else if (isPlainObject(value)) {
1865
+ for (const key in value) {
1866
+ traverse(value[key], depth, seen);
1867
+ }
1868
+ for (const key of Object.getOwnPropertySymbols(value)) {
1869
+ if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1870
+ traverse(value[key], depth, seen);
1871
+ }
1872
+ }
1873
+ }
1874
+ return value;
1875
+ }
1260
1876
  function warn(msg, ...args) {
1261
1877
  pauseTracking();
1262
1878
  const warnArgs = [`[Vue warn]: ${msg}`, ...args];
@@ -1346,10 +1962,20 @@ function logError(err, type, contextVNode, throwInDev = true) {
1346
1962
  console.error(err);
1347
1963
  }
1348
1964
  }
1965
+ var SchedulerJobFlags = /* @__PURE__ */ ((SchedulerJobFlags2) => {
1966
+ SchedulerJobFlags2[SchedulerJobFlags2["QUEUED"] = 1] = "QUEUED";
1967
+ SchedulerJobFlags2[SchedulerJobFlags2["PRE"] = 2] = "PRE";
1968
+ SchedulerJobFlags2[SchedulerJobFlags2["ALLOW_RECURSE"] = 4] = "ALLOW_RECURSE";
1969
+ SchedulerJobFlags2[SchedulerJobFlags2["DISPOSED"] = 8] = "DISPOSED";
1970
+ return SchedulerJobFlags2;
1971
+ })(SchedulerJobFlags || {});
1349
1972
  let isFlushing = false;
1350
1973
  let isFlushPending = false;
1351
1974
  const queue = [];
1352
1975
  let flushIndex = 0;
1976
+ const pendingPostFlushCbs = [];
1977
+ let activePostFlushCbs = null;
1978
+ let postFlushIndex = 0;
1353
1979
  const resolvedPromise = /* @__PURE__ */ Promise.resolve();
1354
1980
  let currentFlushPromise = null;
1355
1981
  const RECURSION_LIMIT = 100;
@@ -1358,13 +1984,13 @@ function nextTick(fn) {
1358
1984
  return fn ? p.then(this ? fn.bind(this) : fn) : p;
1359
1985
  }
1360
1986
  function findInsertionIndex(id) {
1361
- let start = flushIndex + 1;
1987
+ let start = isFlushing ? flushIndex + 1 : 0;
1362
1988
  let end = queue.length;
1363
1989
  while (start < end) {
1364
1990
  const middle = start + end >>> 1;
1365
1991
  const middleJob = queue[middle];
1366
1992
  const middleJobId = getId(middleJob);
1367
- if (middleJobId < id || middleJobId === id && middleJob.pre) {
1993
+ if (middleJobId < id || middleJobId === id && middleJob.flags & 2) {
1368
1994
  start = middle + 1;
1369
1995
  } else {
1370
1996
  end = middle;
@@ -1373,15 +1999,16 @@ function findInsertionIndex(id) {
1373
1999
  return start;
1374
2000
  }
1375
2001
  function queueJob(job) {
1376
- if (!queue.length || !queue.includes(
1377
- job,
1378
- isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex
1379
- )) {
1380
- if (job.id == null) {
2002
+ if (!(job.flags & 1)) {
2003
+ const jobId = getId(job);
2004
+ const lastJob = queue[queue.length - 1];
2005
+ if (!lastJob || // fast path when the job id is larger than the tail
2006
+ !(job.flags & 2) && jobId >= getId(lastJob)) {
1381
2007
  queue.push(job);
1382
2008
  } else {
1383
- queue.splice(findInsertionIndex(job.id), 0, job);
2009
+ queue.splice(findInsertionIndex(jobId), 0, job);
1384
2010
  }
2011
+ job.flags |= 1;
1385
2012
  queueFlush();
1386
2013
  }
1387
2014
  }
@@ -1391,59 +2018,92 @@ function queueFlush() {
1391
2018
  currentFlushPromise = resolvedPromise.then(flushJobs);
1392
2019
  }
1393
2020
  }
1394
- const getId = (job) => job.id == null ? Infinity : job.id;
1395
- const comparator = (a, b) => {
1396
- const diff = getId(a) - getId(b);
1397
- if (diff === 0) {
1398
- if (a.pre && !b.pre) return -1;
1399
- if (b.pre && !a.pre) return 1;
2021
+ function flushPostFlushCbs(seen) {
2022
+ if (pendingPostFlushCbs.length) {
2023
+ const deduped = [...new Set(pendingPostFlushCbs)].sort(
2024
+ (a, b) => getId(a) - getId(b)
2025
+ );
2026
+ pendingPostFlushCbs.length = 0;
2027
+ if (activePostFlushCbs) {
2028
+ activePostFlushCbs.push(...deduped);
2029
+ return;
2030
+ }
2031
+ activePostFlushCbs = deduped;
2032
+ if (!!(process.env.NODE_ENV !== "production")) {
2033
+ seen = seen || /* @__PURE__ */ new Map();
2034
+ }
2035
+ for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
2036
+ const cb = activePostFlushCbs[postFlushIndex];
2037
+ if (!!(process.env.NODE_ENV !== "production") && checkRecursiveUpdates(seen, cb)) {
2038
+ continue;
2039
+ }
2040
+ if (cb.flags & 4) {
2041
+ cb.flags &= ~1;
2042
+ }
2043
+ if (!(cb.flags & 8)) cb();
2044
+ cb.flags &= ~1;
2045
+ }
2046
+ activePostFlushCbs = null;
2047
+ postFlushIndex = 0;
1400
2048
  }
1401
- return diff;
1402
- };
2049
+ }
2050
+ const getId = (job) => job.id == null ? job.flags & 2 ? -1 : Infinity : job.id;
1403
2051
  function flushJobs(seen) {
1404
2052
  isFlushPending = false;
1405
2053
  isFlushing = true;
1406
2054
  if (!!(process.env.NODE_ENV !== "production")) {
1407
2055
  seen = seen || /* @__PURE__ */ new Map();
1408
2056
  }
1409
- queue.sort(comparator);
1410
2057
  const check = !!(process.env.NODE_ENV !== "production") ? (job) => checkRecursiveUpdates(seen, job) : NOOP;
1411
2058
  try {
1412
2059
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
1413
2060
  const job = queue[flushIndex];
1414
- if (job && job.active !== false) {
2061
+ if (job && !(job.flags & 8)) {
1415
2062
  if (!!(process.env.NODE_ENV !== "production") && check(job)) {
1416
2063
  continue;
1417
2064
  }
1418
- callWithErrorHandling(job, null, ErrorCodes.SCHEDULER);
2065
+ if (job.flags & 4) {
2066
+ job.flags &= ~1;
2067
+ }
2068
+ callWithErrorHandling(
2069
+ job,
2070
+ null,
2071
+ ErrorCodes.SCHEDULER
2072
+ );
2073
+ if (!(job.flags & 4)) {
2074
+ job.flags &= ~1;
2075
+ }
1419
2076
  }
1420
2077
  }
1421
2078
  } finally {
2079
+ for (; flushIndex < queue.length; flushIndex++) {
2080
+ const job = queue[flushIndex];
2081
+ if (job) {
2082
+ job.flags &= ~1;
2083
+ }
2084
+ }
1422
2085
  flushIndex = 0;
1423
2086
  queue.length = 0;
2087
+ flushPostFlushCbs(seen);
1424
2088
  isFlushing = false;
1425
2089
  currentFlushPromise = null;
1426
- if (queue.length) {
2090
+ if (queue.length || pendingPostFlushCbs.length) {
1427
2091
  flushJobs(seen);
1428
2092
  }
1429
2093
  }
1430
2094
  }
1431
2095
  function checkRecursiveUpdates(seen, fn) {
1432
- if (!seen.has(fn)) {
1433
- seen.set(fn, 1);
1434
- } else {
1435
- const count = seen.get(fn);
1436
- if (count > RECURSION_LIMIT) {
1437
- handleError(
1438
- `Maximum recursive updates exceeded. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.`,
1439
- null,
1440
- ErrorCodes.APP_ERROR_HANDLER
1441
- );
1442
- return true;
1443
- } else {
1444
- seen.set(fn, count + 1);
1445
- }
2096
+ const count = seen.get(fn) || 0;
2097
+ if (count > RECURSION_LIMIT) {
2098
+ handleError(
2099
+ `Maximum recursive updates exceeded. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.`,
2100
+ null,
2101
+ ErrorCodes.APP_ERROR_HANDLER
2102
+ );
2103
+ return true;
1446
2104
  }
2105
+ seen.set(fn, count + 1);
2106
+ return false;
1447
2107
  }
1448
2108
  function watchEffect(effect2, options) {
1449
2109
  return doWatch(effect2, null, options);
@@ -1455,7 +2115,6 @@ function watchSyncEffect(effect2, options) {
1455
2115
  !!(process.env.NODE_ENV !== "production") ? extend({}, options, { flush: "sync" }) : { flush: "sync" }
1456
2116
  );
1457
2117
  }
1458
- const INITIAL_WATCHER_VALUE = {};
1459
2118
  function watch(source, cb, options) {
1460
2119
  if (!!(process.env.NODE_ENV !== "production") && !isFunction(cb)) {
1461
2120
  warn(
@@ -1464,26 +2123,8 @@ function watch(source, cb, options) {
1464
2123
  }
1465
2124
  return doWatch(source, cb, options);
1466
2125
  }
1467
- function doWatch(source, cb, {
1468
- immediate,
1469
- deep,
1470
- flush,
1471
- once,
1472
- onTrack,
1473
- onTrigger
1474
- } = EMPTY_OBJ) {
1475
- if (cb && once) {
1476
- const _cb = cb;
1477
- cb = (...args) => {
1478
- _cb(...args);
1479
- unwatch();
1480
- };
1481
- }
1482
- if (!!(process.env.NODE_ENV !== "production") && deep !== void 0 && typeof deep === "number") {
1483
- warn(
1484
- `watch() "deep" option with number value will be used as watch depth in future versions. Please use a boolean instead to avoid potential breakage.`
1485
- );
1486
- }
2126
+ function doWatch(source, cb, options = EMPTY_OBJ) {
2127
+ const { immediate, deep, flush, once } = options;
1487
2128
  if (!!(process.env.NODE_ENV !== "production") && !cb) {
1488
2129
  if (immediate !== void 0) {
1489
2130
  warn(
@@ -1501,172 +2142,49 @@ function doWatch(source, cb, {
1501
2142
  );
1502
2143
  }
1503
2144
  }
1504
- const warnInvalidSource = (s) => {
1505
- warn(
1506
- `Invalid watch source: `,
1507
- s,
1508
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1509
- );
1510
- };
1511
- const instance = null;
1512
- const reactiveGetter = (source2) => deep === true ? source2 : (
1513
- // for deep: false, only traverse root-level properties
1514
- traverse(source2, deep === false ? 1 : void 0)
1515
- );
1516
- let getter;
1517
- let forceTrigger = false;
1518
- let isMultiSource = false;
1519
- if (isRef(source)) {
1520
- getter = () => source.value;
1521
- forceTrigger = isShallow(source);
1522
- } else if (isReactive(source)) {
1523
- getter = () => reactiveGetter(source);
1524
- forceTrigger = true;
1525
- } else if (isArray(source)) {
1526
- isMultiSource = true;
1527
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1528
- getter = () => source.map((s) => {
1529
- if (isRef(s)) {
1530
- return s.value;
1531
- } else if (isReactive(s)) {
1532
- return reactiveGetter(s);
1533
- } else if (isFunction(s)) {
1534
- return callWithErrorHandling(s, instance, ErrorCodes.WATCH_GETTER);
2145
+ const baseWatchOptions = extend({}, options);
2146
+ if (!!(process.env.NODE_ENV !== "production")) baseWatchOptions.onWarn = warn;
2147
+ baseWatchOptions.call = (fn, type, args) => callWithAsyncErrorHandling(fn, type, args);
2148
+ let isPre = false;
2149
+ if (flush !== "sync") {
2150
+ isPre = true;
2151
+ baseWatchOptions.scheduler = (job, isFirstRun) => {
2152
+ if (isFirstRun) {
2153
+ job();
1535
2154
  } else {
1536
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(s);
2155
+ queueJob(job);
1537
2156
  }
1538
- });
1539
- } else if (isFunction(source)) {
1540
- if (cb) {
1541
- getter = () => callWithErrorHandling(source, instance, ErrorCodes.WATCH_GETTER);
1542
- } else {
1543
- getter = () => {
1544
- if (cleanup) {
1545
- cleanup();
1546
- }
1547
- return callWithAsyncErrorHandling(
1548
- source,
1549
- instance,
1550
- ErrorCodes.WATCH_CALLBACK,
1551
- [onCleanup]
1552
- );
1553
- };
1554
- }
1555
- } else {
1556
- getter = NOOP;
1557
- !!(process.env.NODE_ENV !== "production") && warnInvalidSource(source);
1558
- }
1559
- if (cb && deep) {
1560
- const baseGetter = getter;
1561
- getter = () => traverse(baseGetter());
1562
- }
1563
- let cleanup;
1564
- let onCleanup = (fn) => {
1565
- cleanup = effect2.onStop = () => {
1566
- callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP);
1567
- cleanup = effect2.onStop = void 0;
1568
2157
  };
1569
- };
1570
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1571
- const job = () => {
1572
- if (!effect2.active || !effect2.dirty) {
1573
- return;
1574
- }
2158
+ }
2159
+ baseWatchOptions.augmentJob = (job) => {
1575
2160
  if (cb) {
1576
- const newValue = effect2.run();
1577
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1578
- if (cleanup) {
1579
- cleanup();
1580
- }
1581
- callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
1582
- newValue,
1583
- // pass undefined as the old value when it's changed for the first time
1584
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1585
- onCleanup
1586
- ]);
1587
- oldValue = newValue;
1588
- }
1589
- } else {
1590
- effect2.run();
2161
+ job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
1591
2162
  }
1592
- };
1593
- job.allowRecurse = !!cb;
1594
- let scheduler;
1595
- if (flush === "sync") {
1596
- scheduler = job;
1597
- } else {
1598
- job.pre = true;
1599
- scheduler = () => queueJob(job);
1600
- }
1601
- const effect2 = new ReactiveEffect(getter, NOOP, scheduler);
1602
- const scope = getCurrentScope();
1603
- const unwatch = () => {
1604
- effect2.stop();
1605
- if (scope) {
1606
- remove(scope.effects, effect2);
2163
+ if (isPre) {
2164
+ job.flags |= SchedulerJobFlags.PRE;
1607
2165
  }
1608
2166
  };
1609
- if (!!(process.env.NODE_ENV !== "production")) {
1610
- effect2.onTrack = onTrack;
1611
- effect2.onTrigger = onTrigger;
1612
- }
1613
- if (cb) {
1614
- if (immediate) {
1615
- job();
1616
- } else {
1617
- oldValue = effect2.run();
1618
- }
1619
- } else {
1620
- effect2.run();
1621
- }
1622
- return unwatch;
1623
- }
1624
- function traverse(value, depth = Infinity, seen) {
1625
- if (depth <= 0 || !isObject(value) || value[ReactiveFlags.SKIP]) {
1626
- return value;
1627
- }
1628
- seen = seen || /* @__PURE__ */ new Set();
1629
- if (seen.has(value)) {
1630
- return value;
1631
- }
1632
- seen.add(value);
1633
- depth--;
1634
- if (isRef(value)) {
1635
- traverse(value.value, depth, seen);
1636
- } else if (isArray(value)) {
1637
- for (let i = 0; i < value.length; i++) {
1638
- traverse(value[i], depth, seen);
1639
- }
1640
- } else if (isSet(value) || isMap(value)) {
1641
- value.forEach((v) => {
1642
- traverse(v, depth, seen);
1643
- });
1644
- } else if (isPlainObject(value)) {
1645
- for (const key in value) {
1646
- traverse(value[key], depth, seen);
1647
- }
1648
- for (const key of Object.getOwnPropertySymbols(value)) {
1649
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1650
- traverse(value[key], depth, seen);
1651
- }
1652
- }
1653
- }
1654
- return value;
2167
+ const watchHandle = watch$1(source, cb, baseWatchOptions);
2168
+ return watchHandle;
1655
2169
  }
1656
2170
  export {
2171
+ ARRAY_ITERATE_KEY,
2172
+ EffectFlags,
1657
2173
  EffectScope,
1658
2174
  ITERATE_KEY,
2175
+ MAP_KEY_ITERATE_KEY,
1659
2176
  ReactiveEffect,
1660
2177
  ReactiveFlags,
1661
2178
  TrackOpTypes,
1662
2179
  TriggerOpTypes,
2180
+ WatchErrorCodes,
1663
2181
  computed,
1664
2182
  customRef,
1665
- deferredComputed,
1666
2183
  effect,
1667
2184
  effectScope,
1668
2185
  enableTracking,
1669
2186
  getCurrentScope,
2187
+ getCurrentWatcher,
1670
2188
  isProxy,
1671
2189
  isReactive,
1672
2190
  isReadonly,
@@ -1674,24 +2192,29 @@ export {
1674
2192
  isShallow,
1675
2193
  markRaw,
1676
2194
  nextTick,
2195
+ onEffectCleanup,
1677
2196
  onScopeDispose,
1678
- pauseScheduling,
2197
+ onWatcherCleanup,
1679
2198
  pauseTracking,
1680
2199
  proxyRefs,
1681
2200
  reactive,
2201
+ reactiveReadArray,
1682
2202
  readonly,
1683
2203
  ref,
1684
- resetScheduling,
1685
2204
  resetTracking,
1686
2205
  shallowReactive,
2206
+ shallowReadArray,
1687
2207
  shallowReadonly,
1688
2208
  shallowRef,
1689
2209
  stop,
1690
2210
  toRaw,
2211
+ toReactive,
2212
+ toReadonly,
1691
2213
  toRef,
1692
2214
  toRefs,
1693
2215
  toValue,
1694
2216
  track,
2217
+ traverse,
1695
2218
  trigger,
1696
2219
  triggerRef,
1697
2220
  unref,