@vue-mini/core 1.2.9 → 1.3.0-beta.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.9
2
+ * vue-mini v1.3.0-beta.1
3
3
  * https://github.com/vue-mini/vue-mini
4
4
  * (c) 2019-present Yang Mingshan
5
5
  * @license MIT
@@ -7,27 +7,30 @@
7
7
  'use strict';
8
8
 
9
9
  /**
10
- * @vue/shared v3.5.29
11
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
12
- * @license MIT
13
- **/
14
- // @__NO_SIDE_EFFECTS__
10
+ * @vue/shared v3.6.0-beta.7
11
+ * (c) 2018-present Yuxi (Evan) You and Vue contributors
12
+ * @license MIT
13
+ **/
14
+ //#region packages/shared/src/makeMap.ts
15
+ /**
16
+ * Make a map and return a function for checking if a key
17
+ * is in that map.
18
+ * IMPORTANT: all calls of this function must be prefixed with
19
+ * \/\*#\_\_PURE\_\_\*\/
20
+ * So that they can be tree-shaken if necessary.
21
+ */
22
+ /* @__NO_SIDE_EFFECTS__ */
15
23
  function makeMap(str) {
16
- const map = /* @__PURE__ */ Object.create(null);
17
- for (const key of str.split(",")) map[key] = 1;
18
- return (val) => val in map;
24
+ const map = Object.create(null);
25
+ for (const key of str.split(",")) map[key] = 1;
26
+ return (val) => val in map;
19
27
  }
20
28
 
29
+ //#endregion
30
+ //#region packages/shared/src/general.ts
21
31
  const EMPTY_OBJ$1 = Object.freeze({}) ;
22
- const NOOP = () => {
23
- };
32
+ const NOOP = () => {};
24
33
  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
34
  const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
32
35
  const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
33
36
  const isArray$1 = Array.isArray;
@@ -40,2069 +43,1966 @@ const isObject$1 = (val) => val !== null && typeof val === "object";
40
43
  const objectToString = Object.prototype.toString;
41
44
  const toTypeString = (value) => objectToString.call(value);
42
45
  const toRawType = (value) => {
43
- return toTypeString(value).slice(8, -1);
46
+ return toTypeString(value).slice(8, -1);
44
47
  };
45
48
  const isPlainObject$1 = (val) => toTypeString(val) === "[object Object]";
46
49
  const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
47
50
  const cacheStringFunction = (fn) => {
48
- const cache = /* @__PURE__ */ Object.create(null);
49
- return ((str) => {
50
- const hit = cache[str];
51
- return hit || (cache[str] = fn(str));
52
- });
51
+ const cache = Object.create(null);
52
+ return ((str) => {
53
+ return cache[str] || (cache[str] = fn(str));
54
+ });
53
55
  };
56
+ /**
57
+ * @private
58
+ */
54
59
  const capitalize = cacheStringFunction((str) => {
55
- return str.charAt(0).toUpperCase() + str.slice(1);
60
+ return str.charAt(0).toUpperCase() + str.slice(1);
56
61
  });
57
62
  const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
58
63
  const def = (obj, key, value, writable = false) => {
59
- Object.defineProperty(obj, key, {
60
- configurable: true,
61
- enumerable: false,
62
- writable,
63
- value
64
- });
64
+ Object.defineProperty(obj, key, {
65
+ configurable: true,
66
+ enumerable: false,
67
+ writable,
68
+ value
69
+ });
65
70
  };
66
71
 
67
72
  /**
68
- * @vue/reactivity v3.5.29
69
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
70
- * @license MIT
71
- **/
73
+ * @vue/reactivity v3.6.0-beta.7
74
+ * (c) 2018-present Yuxi (Evan) You and Vue contributors
75
+ * @license MIT
76
+ **/
72
77
 
73
- function warn(msg, ...args) {
74
- console.warn(`[Vue warn] ${msg}`, ...args);
78
+ //#region packages/reactivity/src/debug.ts
79
+ const triggerEventInfos = [];
80
+ function onTrack(sub, debugInfo) {
81
+ if (sub.onTrack) sub.onTrack(extend$1({ effect: sub }, debugInfo));
82
+ }
83
+ function onTrigger(sub) {
84
+ if (sub.onTrigger) {
85
+ const debugInfo = triggerEventInfos[triggerEventInfos.length - 1];
86
+ sub.onTrigger(extend$1({ effect: sub }, debugInfo));
87
+ }
88
+ }
89
+ function setupOnTrigger(target) {
90
+ Object.defineProperty(target.prototype, "onTrigger", {
91
+ get() {
92
+ return this._onTrigger;
93
+ },
94
+ set(val) {
95
+ if (val && !this._onTrigger) setupFlagsHandler(this);
96
+ this._onTrigger = val;
97
+ }
98
+ });
99
+ }
100
+ function setupFlagsHandler(target) {
101
+ target._flags = target.flags;
102
+ Object.defineProperty(target, "flags", {
103
+ get() {
104
+ return target._flags;
105
+ },
106
+ set(value) {
107
+ if (!(target._flags & 48) && !!(value & 48)) onTrigger(this);
108
+ target._flags = value;
109
+ }
110
+ });
75
111
  }
76
112
 
77
- let activeEffectScope;
78
- class EffectScope {
79
- // TODO isolatedDeclarations "__v_skip"
80
- constructor(detached = false) {
81
- this.detached = detached;
82
- /**
83
- * @internal
84
- */
85
- this._active = true;
86
- /**
87
- * @internal track `on` calls, allow `on` call multiple times
88
- */
89
- this._on = 0;
90
- /**
91
- * @internal
92
- */
93
- this.effects = [];
94
- /**
95
- * @internal
96
- */
97
- this.cleanups = [];
98
- this._isPaused = false;
99
- this.__v_skip = true;
100
- this.parent = activeEffectScope;
101
- if (!detached && activeEffectScope) {
102
- this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
103
- this
104
- ) - 1;
105
- }
106
- }
107
- get active() {
108
- return this._active;
109
- }
110
- pause() {
111
- if (this._active) {
112
- this._isPaused = true;
113
- let i, l;
114
- if (this.scopes) {
115
- for (i = 0, l = this.scopes.length; i < l; i++) {
116
- this.scopes[i].pause();
117
- }
118
- }
119
- for (i = 0, l = this.effects.length; i < l; i++) {
120
- this.effects[i].pause();
121
- }
122
- }
123
- }
124
- /**
125
- * Resumes the effect scope, including all child scopes and effects.
126
- */
127
- resume() {
128
- if (this._active) {
129
- if (this._isPaused) {
130
- this._isPaused = false;
131
- let i, l;
132
- if (this.scopes) {
133
- for (i = 0, l = this.scopes.length; i < l; i++) {
134
- this.scopes[i].resume();
135
- }
136
- }
137
- for (i = 0, l = this.effects.length; i < l; i++) {
138
- this.effects[i].resume();
139
- }
140
- }
141
- }
142
- }
143
- run(fn) {
144
- if (this._active) {
145
- const currentEffectScope = activeEffectScope;
146
- try {
147
- activeEffectScope = this;
148
- return fn();
149
- } finally {
150
- activeEffectScope = currentEffectScope;
151
- }
152
- } else {
153
- warn(`cannot run an inactive effect scope.`);
154
- }
155
- }
156
- /**
157
- * This should only be called on non-detached scopes
158
- * @internal
159
- */
160
- on() {
161
- if (++this._on === 1) {
162
- this.prevScope = activeEffectScope;
163
- activeEffectScope = this;
164
- }
165
- }
166
- /**
167
- * This should only be called on non-detached scopes
168
- * @internal
169
- */
170
- off() {
171
- if (this._on > 0 && --this._on === 0) {
172
- activeEffectScope = this.prevScope;
173
- this.prevScope = void 0;
174
- }
175
- }
176
- stop(fromParent) {
177
- if (this._active) {
178
- this._active = false;
179
- let i, l;
180
- for (i = 0, l = this.effects.length; i < l; i++) {
181
- this.effects[i].stop();
182
- }
183
- this.effects.length = 0;
184
- for (i = 0, l = this.cleanups.length; i < l; i++) {
185
- this.cleanups[i]();
186
- }
187
- this.cleanups.length = 0;
188
- if (this.scopes) {
189
- for (i = 0, l = this.scopes.length; i < l; i++) {
190
- this.scopes[i].stop(true);
191
- }
192
- this.scopes.length = 0;
193
- }
194
- if (!this.detached && this.parent && !fromParent) {
195
- const last = this.parent.scopes.pop();
196
- if (last && last !== this) {
197
- this.parent.scopes[this.index] = last;
198
- last.index = this.index;
199
- }
200
- }
201
- this.parent = void 0;
202
- }
203
- }
204
- }
205
- function effectScope(detached) {
206
- return new EffectScope(detached);
207
- }
208
- function getCurrentScope() {
209
- return activeEffectScope;
210
- }
211
- function onScopeDispose(fn, failSilently = false) {
212
- if (activeEffectScope) {
213
- activeEffectScope.cleanups.push(fn);
214
- } else if (!failSilently) {
215
- warn(
216
- `onScopeDispose() is called when there is no active effect scope to be associated with.`
217
- );
218
- }
113
+ //#endregion
114
+ //#region packages/reactivity/src/warning.ts
115
+ function warn(msg, ...args) {
116
+ console.warn(`[Vue warn] ${msg}`, ...args);
219
117
  }
220
118
 
221
- let activeSub;
222
- const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
223
- class ReactiveEffect {
224
- constructor(fn) {
225
- this.fn = fn;
226
- /**
227
- * @internal
228
- */
229
- this.deps = void 0;
230
- /**
231
- * @internal
232
- */
233
- this.depsTail = void 0;
234
- /**
235
- * @internal
236
- */
237
- this.flags = 1 | 4;
238
- /**
239
- * @internal
240
- */
241
- this.next = void 0;
242
- /**
243
- * @internal
244
- */
245
- this.cleanup = void 0;
246
- this.scheduler = void 0;
247
- if (activeEffectScope && activeEffectScope.active) {
248
- activeEffectScope.effects.push(this);
249
- }
250
- }
251
- pause() {
252
- this.flags |= 64;
253
- }
254
- resume() {
255
- if (this.flags & 64) {
256
- this.flags &= -65;
257
- if (pausedQueueEffects.has(this)) {
258
- pausedQueueEffects.delete(this);
259
- this.trigger();
260
- }
261
- }
262
- }
263
- /**
264
- * @internal
265
- */
266
- notify() {
267
- if (this.flags & 2 && !(this.flags & 32)) {
268
- return;
269
- }
270
- if (!(this.flags & 8)) {
271
- batch(this);
272
- }
273
- }
274
- run() {
275
- if (!(this.flags & 1)) {
276
- return this.fn();
277
- }
278
- this.flags |= 2;
279
- cleanupEffect(this);
280
- prepareDeps(this);
281
- const prevEffect = activeSub;
282
- const prevShouldTrack = shouldTrack;
283
- activeSub = this;
284
- shouldTrack = true;
285
- try {
286
- return this.fn();
287
- } finally {
288
- if (activeSub !== this) {
289
- warn(
290
- "Active effect was not restored correctly - this is likely a Vue internal bug."
291
- );
292
- }
293
- cleanupDeps(this);
294
- activeSub = prevEffect;
295
- shouldTrack = prevShouldTrack;
296
- this.flags &= -3;
297
- }
298
- }
299
- stop() {
300
- if (this.flags & 1) {
301
- for (let link = this.deps; link; link = link.nextDep) {
302
- removeSub(link);
303
- }
304
- this.deps = this.depsTail = void 0;
305
- cleanupEffect(this);
306
- this.onStop && this.onStop();
307
- this.flags &= -2;
308
- }
309
- }
310
- trigger() {
311
- if (this.flags & 64) {
312
- pausedQueueEffects.add(this);
313
- } else if (this.scheduler) {
314
- this.scheduler();
315
- } else {
316
- this.runIfDirty();
317
- }
318
- }
319
- /**
320
- * @internal
321
- */
322
- runIfDirty() {
323
- if (isDirty(this)) {
324
- this.run();
325
- }
326
- }
327
- get dirty() {
328
- return isDirty(this);
329
- }
330
- }
119
+ //#endregion
120
+ //#region packages/reactivity/src/system.ts
121
+ const ReactiveFlags$1 = {
122
+ "None": 0,
123
+ "Mutable": 1,
124
+ "Dirty": 16,
125
+ "Pending": 32};
126
+ const notifyBuffer = [];
331
127
  let batchDepth = 0;
332
- let batchedSub;
333
- let batchedComputed;
334
- function batch(sub, isComputed = false) {
335
- sub.flags |= 8;
336
- if (isComputed) {
337
- sub.next = batchedComputed;
338
- batchedComputed = sub;
339
- return;
340
- }
341
- sub.next = batchedSub;
342
- batchedSub = sub;
128
+ let activeSub = void 0;
129
+ let globalVersion = 0;
130
+ let notifyIndex = 0;
131
+ let notifyBufferLength = 0;
132
+ function setActiveSub(sub) {
133
+ try {
134
+ return activeSub;
135
+ } finally {
136
+ activeSub = sub;
137
+ }
343
138
  }
344
139
  function startBatch() {
345
- batchDepth++;
140
+ ++batchDepth;
346
141
  }
347
142
  function endBatch() {
348
- if (--batchDepth > 0) {
349
- return;
350
- }
351
- if (batchedComputed) {
352
- let e = batchedComputed;
353
- batchedComputed = void 0;
354
- while (e) {
355
- const next = e.next;
356
- e.next = void 0;
357
- e.flags &= -9;
358
- e = next;
359
- }
360
- }
361
- let error;
362
- while (batchedSub) {
363
- let e = batchedSub;
364
- batchedSub = void 0;
365
- while (e) {
366
- const next = e.next;
367
- e.next = void 0;
368
- e.flags &= -9;
369
- if (e.flags & 1) {
370
- try {
371
- ;
372
- e.trigger();
373
- } catch (err) {
374
- if (!error) error = err;
375
- }
376
- }
377
- e = next;
378
- }
379
- }
380
- if (error) throw error;
381
- }
382
- function prepareDeps(sub) {
383
- for (let link = sub.deps; link; link = link.nextDep) {
384
- link.version = -1;
385
- link.prevActiveLink = link.dep.activeLink;
386
- link.dep.activeLink = link;
387
- }
388
- }
389
- function cleanupDeps(sub) {
390
- let head;
391
- let tail = sub.depsTail;
392
- let link = tail;
393
- while (link) {
394
- const prev = link.prevDep;
395
- if (link.version === -1) {
396
- if (link === tail) tail = prev;
397
- removeSub(link);
398
- removeDep(link);
399
- } else {
400
- head = link;
401
- }
402
- link.dep.activeLink = link.prevActiveLink;
403
- link.prevActiveLink = void 0;
404
- link = prev;
405
- }
406
- sub.deps = head;
407
- sub.depsTail = tail;
408
- }
409
- function isDirty(sub) {
410
- for (let link = sub.deps; link; link = link.nextDep) {
411
- if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
412
- return true;
413
- }
414
- }
415
- if (sub._dirty) {
416
- return true;
417
- }
418
- return false;
419
- }
420
- function refreshComputed(computed) {
421
- if (computed.flags & 4 && !(computed.flags & 16)) {
422
- return;
423
- }
424
- computed.flags &= -17;
425
- if (computed.globalVersion === globalVersion) {
426
- return;
427
- }
428
- computed.globalVersion = globalVersion;
429
- if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
430
- return;
431
- }
432
- computed.flags |= 2;
433
- const dep = computed.dep;
434
- const prevSub = activeSub;
435
- const prevShouldTrack = shouldTrack;
436
- activeSub = computed;
437
- shouldTrack = true;
438
- try {
439
- prepareDeps(computed);
440
- const value = computed.fn(computed._value);
441
- if (dep.version === 0 || hasChanged(value, computed._value)) {
442
- computed.flags |= 128;
443
- computed._value = value;
444
- dep.version++;
445
- }
446
- } catch (err) {
447
- dep.version++;
448
- throw err;
449
- } finally {
450
- activeSub = prevSub;
451
- shouldTrack = prevShouldTrack;
452
- cleanupDeps(computed);
453
- computed.flags &= -3;
454
- }
455
- }
456
- function removeSub(link, soft = false) {
457
- const { dep, prevSub, nextSub } = link;
458
- if (prevSub) {
459
- prevSub.nextSub = nextSub;
460
- link.prevSub = void 0;
461
- }
462
- if (nextSub) {
463
- nextSub.prevSub = prevSub;
464
- link.nextSub = void 0;
465
- }
466
- if (dep.subsHead === link) {
467
- dep.subsHead = nextSub;
468
- }
469
- if (dep.subs === link) {
470
- dep.subs = prevSub;
471
- if (!prevSub && dep.computed) {
472
- dep.computed.flags &= -5;
473
- for (let l = dep.computed.deps; l; l = l.nextDep) {
474
- removeSub(l, true);
475
- }
476
- }
477
- }
478
- if (!soft && !--dep.sc && dep.map) {
479
- dep.map.delete(dep.key);
480
- }
481
- }
482
- function removeDep(link) {
483
- const { prevDep, nextDep } = link;
484
- if (prevDep) {
485
- prevDep.nextDep = nextDep;
486
- link.prevDep = void 0;
487
- }
488
- if (nextDep) {
489
- nextDep.prevDep = prevDep;
490
- link.nextDep = void 0;
491
- }
492
- }
493
- function effect(fn, options) {
494
- if (fn.effect instanceof ReactiveEffect) {
495
- fn = fn.effect.fn;
496
- }
497
- const e = new ReactiveEffect(fn);
498
- if (options) {
499
- extend$1(e, options);
500
- }
501
- try {
502
- e.run();
503
- } catch (err) {
504
- e.stop();
505
- throw err;
506
- }
507
- const runner = e.run.bind(e);
508
- runner.effect = e;
509
- return runner;
510
- }
511
- function stop(runner) {
512
- runner.effect.stop();
513
- }
514
- let shouldTrack = true;
515
- const trackStack = [];
516
- function pauseTracking() {
517
- trackStack.push(shouldTrack);
518
- shouldTrack = false;
519
- }
520
- function resetTracking() {
521
- const last = trackStack.pop();
522
- shouldTrack = last === void 0 ? true : last;
523
- }
524
- function cleanupEffect(e) {
525
- const { cleanup } = e;
526
- e.cleanup = void 0;
527
- if (cleanup) {
528
- const prevSub = activeSub;
529
- activeSub = void 0;
530
- try {
531
- cleanup();
532
- } finally {
533
- activeSub = prevSub;
534
- }
535
- }
143
+ if (!--batchDepth && notifyBufferLength) flush();
144
+ }
145
+ function link(dep, sub) {
146
+ const prevDep = sub.depsTail;
147
+ if (prevDep !== void 0 && prevDep.dep === dep) return;
148
+ const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
149
+ if (nextDep !== void 0 && nextDep.dep === dep) {
150
+ nextDep.version = globalVersion;
151
+ sub.depsTail = nextDep;
152
+ return;
153
+ }
154
+ const prevSub = dep.subsTail;
155
+ if (prevSub !== void 0 && prevSub.version === globalVersion && prevSub.sub === sub) return;
156
+ const newLink = sub.depsTail = dep.subsTail = {
157
+ version: globalVersion,
158
+ dep,
159
+ sub,
160
+ prevDep,
161
+ nextDep,
162
+ prevSub,
163
+ nextSub: void 0
164
+ };
165
+ if (nextDep !== void 0) nextDep.prevDep = newLink;
166
+ if (prevDep !== void 0) prevDep.nextDep = newLink;
167
+ else sub.deps = newLink;
168
+ if (prevSub !== void 0) prevSub.nextSub = newLink;
169
+ else dep.subs = newLink;
170
+ }
171
+ function unlink(link, sub = link.sub) {
172
+ const dep = link.dep;
173
+ const prevDep = link.prevDep;
174
+ const nextDep = link.nextDep;
175
+ const nextSub = link.nextSub;
176
+ const prevSub = link.prevSub;
177
+ if (nextDep !== void 0) nextDep.prevDep = prevDep;
178
+ else sub.depsTail = prevDep;
179
+ if (prevDep !== void 0) prevDep.nextDep = nextDep;
180
+ else sub.deps = nextDep;
181
+ if (nextSub !== void 0) nextSub.prevSub = prevSub;
182
+ else dep.subsTail = prevSub;
183
+ if (prevSub !== void 0) prevSub.nextSub = nextSub;
184
+ else if ((dep.subs = nextSub) === void 0) {
185
+ let toRemove = dep.deps;
186
+ if (toRemove !== void 0) {
187
+ do
188
+ toRemove = unlink(toRemove, dep);
189
+ while (toRemove !== void 0);
190
+ dep.flags |= 16;
191
+ }
192
+ }
193
+ return nextDep;
194
+ }
195
+ function propagate(link) {
196
+ let next = link.nextSub;
197
+ let stack;
198
+ top: do {
199
+ const sub = link.sub;
200
+ let flags = sub.flags;
201
+ if (flags & 3) {
202
+ if (!(flags & 60)) sub.flags = flags | 32;
203
+ else if (!(flags & 12)) flags = 0;
204
+ else if (!(flags & 4)) sub.flags = flags & -9 | 32;
205
+ else if (!(flags & 48) && isValidLink(link, sub)) {
206
+ sub.flags = flags | 40;
207
+ flags &= 1;
208
+ } else flags = 0;
209
+ if (flags & 2) notifyBuffer[notifyBufferLength++] = sub;
210
+ if (flags & 1) {
211
+ const subSubs = sub.subs;
212
+ if (subSubs !== void 0) {
213
+ link = subSubs;
214
+ if (subSubs.nextSub !== void 0) {
215
+ stack = {
216
+ value: next,
217
+ prev: stack
218
+ };
219
+ next = link.nextSub;
220
+ }
221
+ continue;
222
+ }
223
+ }
224
+ }
225
+ if ((link = next) !== void 0) {
226
+ next = link.nextSub;
227
+ continue;
228
+ }
229
+ while (stack !== void 0) {
230
+ link = stack.value;
231
+ stack = stack.prev;
232
+ if (link !== void 0) {
233
+ next = link.nextSub;
234
+ continue top;
235
+ }
236
+ }
237
+ break;
238
+ } while (true);
239
+ }
240
+ function startTracking(sub) {
241
+ ++globalVersion;
242
+ sub.depsTail = void 0;
243
+ sub.flags = sub.flags & -57 | 4;
244
+ return setActiveSub(sub);
245
+ }
246
+ function endTracking(sub, prevSub) {
247
+ if (activeSub !== sub) warn("Active effect was not restored correctly - this is likely a Vue internal bug.");
248
+ activeSub = prevSub;
249
+ const depsTail = sub.depsTail;
250
+ let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
251
+ while (toRemove !== void 0) toRemove = unlink(toRemove, sub);
252
+ sub.flags &= -5;
253
+ }
254
+ function flush() {
255
+ while (notifyIndex < notifyBufferLength) {
256
+ const effect = notifyBuffer[notifyIndex];
257
+ notifyBuffer[notifyIndex++] = void 0;
258
+ effect.notify();
259
+ }
260
+ notifyIndex = 0;
261
+ notifyBufferLength = 0;
262
+ }
263
+ function checkDirty(link, sub) {
264
+ let stack;
265
+ let checkDepth = 0;
266
+ top: do {
267
+ const dep = link.dep;
268
+ const depFlags = dep.flags;
269
+ let dirty = false;
270
+ if (sub.flags & 16) dirty = true;
271
+ else if ((depFlags & 17) === 17) {
272
+ if (dep.update()) {
273
+ const subs = dep.subs;
274
+ if (subs.nextSub !== void 0) shallowPropagate(subs);
275
+ dirty = true;
276
+ }
277
+ } else if ((depFlags & 33) === 33) {
278
+ if (link.nextSub !== void 0 || link.prevSub !== void 0) stack = {
279
+ value: link,
280
+ prev: stack
281
+ };
282
+ link = dep.deps;
283
+ sub = dep;
284
+ ++checkDepth;
285
+ continue;
286
+ }
287
+ if (!dirty && link.nextDep !== void 0) {
288
+ link = link.nextDep;
289
+ continue;
290
+ }
291
+ while (checkDepth) {
292
+ --checkDepth;
293
+ const firstSub = sub.subs;
294
+ const hasMultipleSubs = firstSub.nextSub !== void 0;
295
+ if (hasMultipleSubs) {
296
+ link = stack.value;
297
+ stack = stack.prev;
298
+ } else link = firstSub;
299
+ if (dirty) {
300
+ if (sub.update()) {
301
+ if (hasMultipleSubs) shallowPropagate(firstSub);
302
+ sub = link.sub;
303
+ continue;
304
+ }
305
+ } else sub.flags &= -33;
306
+ sub = link.sub;
307
+ if (link.nextDep !== void 0) {
308
+ link = link.nextDep;
309
+ continue top;
310
+ }
311
+ dirty = false;
312
+ }
313
+ return dirty;
314
+ } while (true);
315
+ }
316
+ function shallowPropagate(link) {
317
+ do {
318
+ const sub = link.sub;
319
+ const nextSub = link.nextSub;
320
+ const subFlags = sub.flags;
321
+ if ((subFlags & 48) === 32) sub.flags = subFlags | 16;
322
+ link = nextSub;
323
+ } while (link !== void 0);
324
+ }
325
+ function isValidLink(checkLink, sub) {
326
+ let link = sub.depsTail;
327
+ while (link !== void 0) {
328
+ if (link === checkLink) return true;
329
+ link = link.prevDep;
330
+ }
331
+ return false;
536
332
  }
537
333
 
538
- let globalVersion = 0;
539
- class Link {
540
- constructor(sub, dep) {
541
- this.sub = sub;
542
- this.dep = dep;
543
- this.version = dep.version;
544
- this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
545
- }
546
- }
547
- class Dep {
548
- // TODO isolatedDeclarations "__v_skip"
549
- constructor(computed) {
550
- this.computed = computed;
551
- this.version = 0;
552
- /**
553
- * Link between this dep and the current active effect
554
- */
555
- this.activeLink = void 0;
556
- /**
557
- * Doubly linked list representing the subscribing effects (tail)
558
- */
559
- this.subs = void 0;
560
- /**
561
- * For object property deps cleanup
562
- */
563
- this.map = void 0;
564
- this.key = void 0;
565
- /**
566
- * Subscriber counter
567
- */
568
- this.sc = 0;
569
- /**
570
- * @internal
571
- */
572
- this.__v_skip = true;
573
- {
574
- this.subsHead = void 0;
575
- }
576
- }
577
- track(debugInfo) {
578
- if (!activeSub || !shouldTrack || activeSub === this.computed) {
579
- return;
580
- }
581
- let link = this.activeLink;
582
- if (link === void 0 || link.sub !== activeSub) {
583
- link = this.activeLink = new Link(activeSub, this);
584
- if (!activeSub.deps) {
585
- activeSub.deps = activeSub.depsTail = link;
586
- } else {
587
- link.prevDep = activeSub.depsTail;
588
- activeSub.depsTail.nextDep = link;
589
- activeSub.depsTail = link;
590
- }
591
- addSub(link);
592
- } else if (link.version === -1) {
593
- link.version = this.version;
594
- if (link.nextDep) {
595
- const next = link.nextDep;
596
- next.prevDep = link.prevDep;
597
- if (link.prevDep) {
598
- link.prevDep.nextDep = next;
599
- }
600
- link.prevDep = activeSub.depsTail;
601
- link.nextDep = void 0;
602
- activeSub.depsTail.nextDep = link;
603
- activeSub.depsTail = link;
604
- if (activeSub.deps === link) {
605
- activeSub.deps = next;
606
- }
607
- }
608
- }
609
- if (activeSub.onTrack) {
610
- activeSub.onTrack(
611
- extend$1(
612
- {
613
- effect: activeSub
614
- },
615
- debugInfo
616
- )
617
- );
618
- }
619
- return link;
620
- }
621
- trigger(debugInfo) {
622
- this.version++;
623
- globalVersion++;
624
- this.notify(debugInfo);
625
- }
626
- notify(debugInfo) {
627
- startBatch();
628
- try {
629
- if (!!("development" !== "production")) {
630
- for (let head = this.subsHead; head; head = head.nextSub) {
631
- if (head.sub.onTrigger && !(head.sub.flags & 8)) {
632
- head.sub.onTrigger(
633
- extend$1(
634
- {
635
- effect: head.sub
636
- },
637
- debugInfo
638
- )
639
- );
640
- }
641
- }
642
- }
643
- for (let link = this.subs; link; link = link.prevSub) {
644
- if (link.sub.notify()) {
645
- ;
646
- link.sub.dep.notify();
647
- }
648
- }
649
- } finally {
650
- endBatch();
651
- }
652
- }
653
- }
654
- function addSub(link) {
655
- link.dep.sc++;
656
- if (link.sub.flags & 4) {
657
- const computed = link.dep.computed;
658
- if (computed && !link.dep.subs) {
659
- computed.flags |= 4 | 16;
660
- for (let l = computed.deps; l; l = l.nextDep) {
661
- addSub(l);
662
- }
663
- }
664
- const currentTail = link.dep.subs;
665
- if (currentTail !== link) {
666
- link.prevSub = currentTail;
667
- if (currentTail) currentTail.nextSub = link;
668
- }
669
- if (link.dep.subsHead === void 0) {
670
- link.dep.subsHead = link;
671
- }
672
- link.dep.subs = link;
673
- }
674
- }
334
+ //#endregion
335
+ //#region packages/reactivity/src/dep.ts
336
+ var Dep = class {
337
+ constructor(map, key) {
338
+ this.map = map;
339
+ this.key = key;
340
+ this._subs = void 0;
341
+ this.subsTail = void 0;
342
+ this.flags = 0;
343
+ }
344
+ get subs() {
345
+ return this._subs;
346
+ }
347
+ set subs(value) {
348
+ this._subs = value;
349
+ if (value === void 0) this.map.delete(this.key);
350
+ }
351
+ };
675
352
  const targetMap = /* @__PURE__ */ new WeakMap();
676
- const ITERATE_KEY = /* @__PURE__ */ Symbol(
677
- "Object iterate"
678
- );
679
- const MAP_KEY_ITERATE_KEY = /* @__PURE__ */ Symbol(
680
- "Map keys iterate"
681
- );
682
- const ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol(
683
- "Array iterate"
684
- );
353
+ const ITERATE_KEY = Symbol("Object iterate" );
354
+ const MAP_KEY_ITERATE_KEY = Symbol("Map keys iterate" );
355
+ const ARRAY_ITERATE_KEY = Symbol("Array iterate" );
356
+ /**
357
+ * Tracks access to a reactive property.
358
+ *
359
+ * This will check which effect is running at the moment and record it as dep
360
+ * which records all effects that depend on the reactive property.
361
+ *
362
+ * @param target - Object holding the reactive property.
363
+ * @param type - Defines the type of access to the reactive property.
364
+ * @param key - Identifier of the reactive property to track.
365
+ */
685
366
  function track(target, type, key) {
686
- if (shouldTrack && activeSub) {
687
- let depsMap = targetMap.get(target);
688
- if (!depsMap) {
689
- targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
690
- }
691
- let dep = depsMap.get(key);
692
- if (!dep) {
693
- depsMap.set(key, dep = new Dep());
694
- dep.map = depsMap;
695
- dep.key = key;
696
- }
697
- {
698
- dep.track({
699
- target,
700
- type,
701
- key
702
- });
703
- }
704
- }
367
+ if (activeSub !== void 0) {
368
+ let depsMap = targetMap.get(target);
369
+ if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
370
+ let dep = depsMap.get(key);
371
+ if (!dep) depsMap.set(key, dep = new Dep(depsMap, key));
372
+ onTrack(activeSub, {
373
+ target,
374
+ type,
375
+ key
376
+ });
377
+ link(dep, activeSub);
378
+ }
705
379
  }
380
+ /**
381
+ * Finds all deps associated with the target (or a specific property) and
382
+ * triggers the effects stored within.
383
+ *
384
+ * @param target - The reactive object.
385
+ * @param type - Defines the type of the operation that needs to trigger effects.
386
+ * @param key - Can be used to target a specific reactive property in the target object.
387
+ */
706
388
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
707
- const depsMap = targetMap.get(target);
708
- if (!depsMap) {
709
- globalVersion++;
710
- return;
711
- }
712
- const run = (dep) => {
713
- if (dep) {
714
- {
715
- dep.trigger({
716
- target,
717
- type,
718
- key,
719
- newValue,
720
- oldValue,
721
- oldTarget
722
- });
723
- }
724
- }
725
- };
726
- startBatch();
727
- if (type === "clear") {
728
- depsMap.forEach(run);
729
- } else {
730
- const targetIsArray = isArray$1(target);
731
- const isArrayIndex = targetIsArray && isIntegerKey(key);
732
- if (targetIsArray && key === "length") {
733
- const newLength = Number(newValue);
734
- depsMap.forEach((dep, key2) => {
735
- if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
736
- run(dep);
737
- }
738
- });
739
- } else {
740
- if (key !== void 0 || depsMap.has(void 0)) {
741
- run(depsMap.get(key));
742
- }
743
- if (isArrayIndex) {
744
- run(depsMap.get(ARRAY_ITERATE_KEY));
745
- }
746
- switch (type) {
747
- case "add":
748
- if (!targetIsArray) {
749
- run(depsMap.get(ITERATE_KEY));
750
- if (isMap(target)) {
751
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
752
- }
753
- } else if (isArrayIndex) {
754
- run(depsMap.get("length"));
755
- }
756
- break;
757
- case "delete":
758
- if (!targetIsArray) {
759
- run(depsMap.get(ITERATE_KEY));
760
- if (isMap(target)) {
761
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
762
- }
763
- }
764
- break;
765
- case "set":
766
- if (isMap(target)) {
767
- run(depsMap.get(ITERATE_KEY));
768
- }
769
- break;
770
- }
771
- }
772
- }
773
- endBatch();
389
+ const depsMap = targetMap.get(target);
390
+ if (!depsMap) return;
391
+ const run = (dep) => {
392
+ if (dep !== void 0 && dep.subs !== void 0) {
393
+ triggerEventInfos.push({
394
+ target,
395
+ type,
396
+ key,
397
+ newValue,
398
+ oldValue,
399
+ oldTarget
400
+ });
401
+ propagate(dep.subs);
402
+ shallowPropagate(dep.subs);
403
+ triggerEventInfos.pop();
404
+ }
405
+ };
406
+ startBatch();
407
+ if (type === "clear") depsMap.forEach(run);
408
+ else {
409
+ const targetIsArray = isArray$1(target);
410
+ const isArrayIndex = targetIsArray && isIntegerKey(key);
411
+ if (targetIsArray && key === "length") {
412
+ const newLength = Number(newValue);
413
+ depsMap.forEach((dep, key) => {
414
+ if (key === "length" || key === ARRAY_ITERATE_KEY || !isSymbol(key) && key >= newLength) run(dep);
415
+ });
416
+ } else {
417
+ if (key !== void 0 || depsMap.has(void 0)) run(depsMap.get(key));
418
+ if (isArrayIndex) run(depsMap.get(ARRAY_ITERATE_KEY));
419
+ switch (type) {
420
+ case "add":
421
+ if (!targetIsArray) {
422
+ run(depsMap.get(ITERATE_KEY));
423
+ if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
424
+ } else if (isArrayIndex) run(depsMap.get("length"));
425
+ break;
426
+ case "delete":
427
+ if (!targetIsArray) {
428
+ run(depsMap.get(ITERATE_KEY));
429
+ if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
430
+ }
431
+ break;
432
+ case "set":
433
+ if (isMap(target)) run(depsMap.get(ITERATE_KEY));
434
+ break;
435
+ }
436
+ }
437
+ }
438
+ endBatch();
774
439
  }
775
440
  function getDepFromReactive(object, key) {
776
- const depMap = targetMap.get(object);
777
- return depMap && depMap.get(key);
441
+ const depMap = targetMap.get(object);
442
+ return depMap && depMap.get(key);
778
443
  }
779
444
 
445
+ //#endregion
446
+ //#region packages/reactivity/src/arrayInstrumentations.ts
447
+ /**
448
+ * Track array iteration and return:
449
+ * - if input is reactive: a cloned raw array with reactive values
450
+ * - if input is non-reactive or shallowReactive: the original raw array
451
+ */
780
452
  function reactiveReadArray(array) {
781
- const raw = toRaw(array);
782
- if (raw === array) return raw;
783
- track(raw, "iterate", ARRAY_ITERATE_KEY);
784
- return isShallow(array) ? raw : raw.map(toReactive);
453
+ const raw = /* @__PURE__ */ toRaw(array);
454
+ if (raw === array) return raw;
455
+ track(raw, "iterate", ARRAY_ITERATE_KEY);
456
+ return /* @__PURE__ */ isShallow(array) ? raw : raw.map(toReactive);
785
457
  }
458
+ /**
459
+ * Track array iteration and return raw array
460
+ */
786
461
  function shallowReadArray(arr) {
787
- track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
788
- return arr;
462
+ track(arr = /* @__PURE__ */ toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
463
+ return arr;
789
464
  }
790
465
  function toWrapped(target, item) {
791
- if (isReadonly(target)) {
792
- return isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
793
- }
794
- return toReactive(item);
466
+ if (/* @__PURE__ */ isReadonly(target)) return /* @__PURE__ */ isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
467
+ return toReactive(item);
795
468
  }
796
469
  const arrayInstrumentations = {
797
- __proto__: null,
798
- [Symbol.iterator]() {
799
- return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
800
- },
801
- concat(...args) {
802
- return reactiveReadArray(this).concat(
803
- ...args.map((x) => isArray$1(x) ? reactiveReadArray(x) : x)
804
- );
805
- },
806
- entries() {
807
- return iterator(this, "entries", (value) => {
808
- value[1] = toWrapped(this, value[1]);
809
- return value;
810
- });
811
- },
812
- every(fn, thisArg) {
813
- return apply(this, "every", fn, thisArg, void 0, arguments);
814
- },
815
- filter(fn, thisArg) {
816
- return apply(
817
- this,
818
- "filter",
819
- fn,
820
- thisArg,
821
- (v) => v.map((item) => toWrapped(this, item)),
822
- arguments
823
- );
824
- },
825
- find(fn, thisArg) {
826
- return apply(
827
- this,
828
- "find",
829
- fn,
830
- thisArg,
831
- (item) => toWrapped(this, item),
832
- arguments
833
- );
834
- },
835
- findIndex(fn, thisArg) {
836
- return apply(this, "findIndex", fn, thisArg, void 0, arguments);
837
- },
838
- findLast(fn, thisArg) {
839
- return apply(
840
- this,
841
- "findLast",
842
- fn,
843
- thisArg,
844
- (item) => toWrapped(this, item),
845
- arguments
846
- );
847
- },
848
- findLastIndex(fn, thisArg) {
849
- return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
850
- },
851
- // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
852
- forEach(fn, thisArg) {
853
- return apply(this, "forEach", fn, thisArg, void 0, arguments);
854
- },
855
- includes(...args) {
856
- return searchProxy(this, "includes", args);
857
- },
858
- indexOf(...args) {
859
- return searchProxy(this, "indexOf", args);
860
- },
861
- join(separator) {
862
- return reactiveReadArray(this).join(separator);
863
- },
864
- // keys() iterator only reads `length`, no optimization required
865
- lastIndexOf(...args) {
866
- return searchProxy(this, "lastIndexOf", args);
867
- },
868
- map(fn, thisArg) {
869
- return apply(this, "map", fn, thisArg, void 0, arguments);
870
- },
871
- pop() {
872
- return noTracking(this, "pop");
873
- },
874
- push(...args) {
875
- return noTracking(this, "push", args);
876
- },
877
- reduce(fn, ...args) {
878
- return reduce(this, "reduce", fn, args);
879
- },
880
- reduceRight(fn, ...args) {
881
- return reduce(this, "reduceRight", fn, args);
882
- },
883
- shift() {
884
- return noTracking(this, "shift");
885
- },
886
- // slice could use ARRAY_ITERATE but also seems to beg for range tracking
887
- some(fn, thisArg) {
888
- return apply(this, "some", fn, thisArg, void 0, arguments);
889
- },
890
- splice(...args) {
891
- return noTracking(this, "splice", args);
892
- },
893
- toReversed() {
894
- return reactiveReadArray(this).toReversed();
895
- },
896
- toSorted(comparer) {
897
- return reactiveReadArray(this).toSorted(comparer);
898
- },
899
- toSpliced(...args) {
900
- return reactiveReadArray(this).toSpliced(...args);
901
- },
902
- unshift(...args) {
903
- return noTracking(this, "unshift", args);
904
- },
905
- values() {
906
- return iterator(this, "values", (item) => toWrapped(this, item));
907
- }
470
+ __proto__: null,
471
+ [Symbol.iterator]() {
472
+ return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
473
+ },
474
+ concat(...args) {
475
+ return reactiveReadArray(this).concat(...args.map((x) => isArray$1(x) ? reactiveReadArray(x) : x));
476
+ },
477
+ entries() {
478
+ return iterator(this, "entries", (value) => {
479
+ value[1] = toWrapped(this, value[1]);
480
+ return value;
481
+ });
482
+ },
483
+ every(fn, thisArg) {
484
+ return apply(this, "every", fn, thisArg, void 0, arguments);
485
+ },
486
+ filter(fn, thisArg) {
487
+ return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
488
+ },
489
+ find(fn, thisArg) {
490
+ return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
491
+ },
492
+ findIndex(fn, thisArg) {
493
+ return apply(this, "findIndex", fn, thisArg, void 0, arguments);
494
+ },
495
+ findLast(fn, thisArg) {
496
+ return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
497
+ },
498
+ findLastIndex(fn, thisArg) {
499
+ return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
500
+ },
501
+ forEach(fn, thisArg) {
502
+ return apply(this, "forEach", fn, thisArg, void 0, arguments);
503
+ },
504
+ includes(...args) {
505
+ return searchProxy(this, "includes", args);
506
+ },
507
+ indexOf(...args) {
508
+ return searchProxy(this, "indexOf", args);
509
+ },
510
+ join(separator) {
511
+ return reactiveReadArray(this).join(separator);
512
+ },
513
+ lastIndexOf(...args) {
514
+ return searchProxy(this, "lastIndexOf", args);
515
+ },
516
+ map(fn, thisArg) {
517
+ return apply(this, "map", fn, thisArg, void 0, arguments);
518
+ },
519
+ pop() {
520
+ return noTracking(this, "pop");
521
+ },
522
+ push(...args) {
523
+ return noTracking(this, "push", args);
524
+ },
525
+ reduce(fn, ...args) {
526
+ return reduce(this, "reduce", fn, args);
527
+ },
528
+ reduceRight(fn, ...args) {
529
+ return reduce(this, "reduceRight", fn, args);
530
+ },
531
+ shift() {
532
+ return noTracking(this, "shift");
533
+ },
534
+ some(fn, thisArg) {
535
+ return apply(this, "some", fn, thisArg, void 0, arguments);
536
+ },
537
+ splice(...args) {
538
+ return noTracking(this, "splice", args);
539
+ },
540
+ toReversed() {
541
+ return reactiveReadArray(this).toReversed();
542
+ },
543
+ toSorted(comparer) {
544
+ return reactiveReadArray(this).toSorted(comparer);
545
+ },
546
+ toSpliced(...args) {
547
+ return reactiveReadArray(this).toSpliced(...args);
548
+ },
549
+ unshift(...args) {
550
+ return noTracking(this, "unshift", args);
551
+ },
552
+ values() {
553
+ return iterator(this, "values", (item) => toWrapped(this, item));
554
+ }
908
555
  };
909
556
  function iterator(self, method, wrapValue) {
910
- const arr = shallowReadArray(self);
911
- const iter = arr[method]();
912
- if (arr !== self && !isShallow(self)) {
913
- iter._next = iter.next;
914
- iter.next = () => {
915
- const result = iter._next();
916
- if (!result.done) {
917
- result.value = wrapValue(result.value);
918
- }
919
- return result;
920
- };
921
- }
922
- return iter;
557
+ const arr = shallowReadArray(self);
558
+ const iter = arr[method]();
559
+ if (arr !== self && !/* @__PURE__ */ isShallow(self)) {
560
+ iter._next = iter.next;
561
+ iter.next = () => {
562
+ const result = iter._next();
563
+ if (!result.done) result.value = wrapValue(result.value);
564
+ return result;
565
+ };
566
+ }
567
+ return iter;
923
568
  }
924
569
  const arrayProto = Array.prototype;
925
570
  function apply(self, method, fn, thisArg, wrappedRetFn, args) {
926
- const arr = shallowReadArray(self);
927
- const needsWrap = arr !== self && !isShallow(self);
928
- const methodFn = arr[method];
929
- if (methodFn !== arrayProto[method]) {
930
- const result2 = methodFn.apply(self, args);
931
- return needsWrap ? toReactive(result2) : result2;
932
- }
933
- let wrappedFn = fn;
934
- if (arr !== self) {
935
- if (needsWrap) {
936
- wrappedFn = function(item, index) {
937
- return fn.call(this, toWrapped(self, item), index, self);
938
- };
939
- } else if (fn.length > 2) {
940
- wrappedFn = function(item, index) {
941
- return fn.call(this, item, index, self);
942
- };
943
- }
944
- }
945
- const result = methodFn.call(arr, wrappedFn, thisArg);
946
- return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
571
+ const arr = shallowReadArray(self);
572
+ const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
573
+ const methodFn = arr[method];
574
+ if (methodFn !== arrayProto[method]) {
575
+ const result = methodFn.apply(self, args);
576
+ return needsWrap ? toReactive(result) : result;
577
+ }
578
+ let wrappedFn = fn;
579
+ if (arr !== self) {
580
+ if (needsWrap) wrappedFn = function(item, index) {
581
+ return fn.call(this, toWrapped(self, item), index, self);
582
+ };
583
+ else if (fn.length > 2) wrappedFn = function(item, index) {
584
+ return fn.call(this, item, index, self);
585
+ };
586
+ }
587
+ const result = methodFn.call(arr, wrappedFn, thisArg);
588
+ return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
947
589
  }
948
590
  function reduce(self, method, fn, args) {
949
- const arr = shallowReadArray(self);
950
- let wrappedFn = fn;
951
- if (arr !== self) {
952
- if (!isShallow(self)) {
953
- wrappedFn = function(acc, item, index) {
954
- return fn.call(this, acc, toWrapped(self, item), index, self);
955
- };
956
- } else if (fn.length > 3) {
957
- wrappedFn = function(acc, item, index) {
958
- return fn.call(this, acc, item, index, self);
959
- };
960
- }
961
- }
962
- return arr[method](wrappedFn, ...args);
591
+ const arr = shallowReadArray(self);
592
+ let wrappedFn = fn;
593
+ if (arr !== self) {
594
+ if (!/* @__PURE__ */ isShallow(self)) wrappedFn = function(acc, item, index) {
595
+ return fn.call(this, acc, toWrapped(self, item), index, self);
596
+ };
597
+ else if (fn.length > 3) wrappedFn = function(acc, item, index) {
598
+ return fn.call(this, acc, item, index, self);
599
+ };
600
+ }
601
+ return arr[method](wrappedFn, ...args);
963
602
  }
964
603
  function searchProxy(self, method, args) {
965
- const arr = toRaw(self);
966
- track(arr, "iterate", ARRAY_ITERATE_KEY);
967
- const res = arr[method](...args);
968
- if ((res === -1 || res === false) && isProxy(args[0])) {
969
- args[0] = toRaw(args[0]);
970
- return arr[method](...args);
971
- }
972
- return res;
604
+ const arr = /* @__PURE__ */ toRaw(self);
605
+ track(arr, "iterate", ARRAY_ITERATE_KEY);
606
+ const res = arr[method](...args);
607
+ if ((res === -1 || res === false) && /* @__PURE__ */ isProxy(args[0])) {
608
+ args[0] = /* @__PURE__ */ toRaw(args[0]);
609
+ return arr[method](...args);
610
+ }
611
+ return res;
973
612
  }
974
613
  function noTracking(self, method, args = []) {
975
- pauseTracking();
976
- startBatch();
977
- const res = toRaw(self)[method].apply(self, args);
978
- endBatch();
979
- resetTracking();
980
- return res;
614
+ startBatch();
615
+ const prevSub = setActiveSub();
616
+ const res = (/* @__PURE__ */ toRaw(self))[method].apply(self, args);
617
+ setActiveSub(prevSub);
618
+ endBatch();
619
+ return res;
981
620
  }
982
621
 
622
+ //#endregion
623
+ //#region packages/reactivity/src/baseHandlers.ts
983
624
  const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
984
- const builtInSymbols = new Set(
985
- /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
986
- );
625
+ const builtInSymbols = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
987
626
  function hasOwnProperty(key) {
988
- if (!isSymbol(key)) key = String(key);
989
- const obj = toRaw(this);
990
- track(obj, "has", key);
991
- return obj.hasOwnProperty(key);
992
- }
993
- class BaseReactiveHandler {
994
- constructor(_isReadonly = false, _isShallow = false) {
995
- this._isReadonly = _isReadonly;
996
- this._isShallow = _isShallow;
997
- }
998
- get(target, key, receiver) {
999
- if (key === "__v_skip") return target["__v_skip"];
1000
- const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
1001
- if (key === "__v_isReactive") {
1002
- return !isReadonly2;
1003
- } else if (key === "__v_isReadonly") {
1004
- return isReadonly2;
1005
- } else if (key === "__v_isShallow") {
1006
- return isShallow2;
1007
- } else if (key === "__v_raw") {
1008
- if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
1009
- // this means the receiver is a user proxy of the reactive proxy
1010
- Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
1011
- return target;
1012
- }
1013
- return;
1014
- }
1015
- const targetIsArray = isArray$1(target);
1016
- if (!isReadonly2) {
1017
- let fn;
1018
- if (targetIsArray && (fn = arrayInstrumentations[key])) {
1019
- return fn;
1020
- }
1021
- if (key === "hasOwnProperty") {
1022
- return hasOwnProperty;
1023
- }
1024
- }
1025
- const res = Reflect.get(
1026
- target,
1027
- key,
1028
- // if this is a proxy wrapping a ref, return methods using the raw ref
1029
- // as receiver so that we don't have to call `toRaw` on the ref in all
1030
- // its class methods
1031
- isRef(target) ? target : receiver
1032
- );
1033
- if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
1034
- return res;
1035
- }
1036
- if (!isReadonly2) {
1037
- track(target, "get", key);
1038
- }
1039
- if (isShallow2) {
1040
- return res;
1041
- }
1042
- if (isRef(res)) {
1043
- const value = targetIsArray && isIntegerKey(key) ? res : res.value;
1044
- return isReadonly2 && isObject$1(value) ? readonly(value) : value;
1045
- }
1046
- if (isObject$1(res)) {
1047
- return isReadonly2 ? readonly(res) : reactive(res);
1048
- }
1049
- return res;
1050
- }
1051
- }
1052
- class MutableReactiveHandler extends BaseReactiveHandler {
1053
- constructor(isShallow2 = false) {
1054
- super(false, isShallow2);
1055
- }
1056
- set(target, key, value, receiver) {
1057
- let oldValue = target[key];
1058
- const isArrayWithIntegerKey = isArray$1(target) && isIntegerKey(key);
1059
- if (!this._isShallow) {
1060
- const isOldValueReadonly = isReadonly(oldValue);
1061
- if (!isShallow(value) && !isReadonly(value)) {
1062
- oldValue = toRaw(oldValue);
1063
- value = toRaw(value);
1064
- }
1065
- if (!isArrayWithIntegerKey && isRef(oldValue) && !isRef(value)) {
1066
- if (isOldValueReadonly) {
1067
- {
1068
- warn(
1069
- `Set operation on key "${String(key)}" failed: target is readonly.`,
1070
- target[key]
1071
- );
1072
- }
1073
- return true;
1074
- } else {
1075
- oldValue.value = value;
1076
- return true;
1077
- }
1078
- }
1079
- }
1080
- const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
1081
- const result = Reflect.set(
1082
- target,
1083
- key,
1084
- value,
1085
- isRef(target) ? target : receiver
1086
- );
1087
- if (target === toRaw(receiver)) {
1088
- if (!hadKey) {
1089
- trigger(target, "add", key, value);
1090
- } else if (hasChanged(value, oldValue)) {
1091
- trigger(target, "set", key, value, oldValue);
1092
- }
1093
- }
1094
- return result;
1095
- }
1096
- deleteProperty(target, key) {
1097
- const hadKey = hasOwn(target, key);
1098
- const oldValue = target[key];
1099
- const result = Reflect.deleteProperty(target, key);
1100
- if (result && hadKey) {
1101
- trigger(target, "delete", key, void 0, oldValue);
1102
- }
1103
- return result;
1104
- }
1105
- has(target, key) {
1106
- const result = Reflect.has(target, key);
1107
- if (!isSymbol(key) || !builtInSymbols.has(key)) {
1108
- track(target, "has", key);
1109
- }
1110
- return result;
1111
- }
1112
- ownKeys(target) {
1113
- track(
1114
- target,
1115
- "iterate",
1116
- isArray$1(target) ? "length" : ITERATE_KEY
1117
- );
1118
- return Reflect.ownKeys(target);
1119
- }
1120
- }
1121
- class ReadonlyReactiveHandler extends BaseReactiveHandler {
1122
- constructor(isShallow2 = false) {
1123
- super(true, isShallow2);
1124
- }
1125
- set(target, key) {
1126
- {
1127
- warn(
1128
- `Set operation on key "${String(key)}" failed: target is readonly.`,
1129
- target
1130
- );
1131
- }
1132
- return true;
1133
- }
1134
- deleteProperty(target, key) {
1135
- {
1136
- warn(
1137
- `Delete operation on key "${String(key)}" failed: target is readonly.`,
1138
- target
1139
- );
1140
- }
1141
- return true;
1142
- }
1143
- }
627
+ if (!isSymbol(key)) key = String(key);
628
+ const obj = /* @__PURE__ */ toRaw(this);
629
+ track(obj, "has", key);
630
+ return obj.hasOwnProperty(key);
631
+ }
632
+ var BaseReactiveHandler = class {
633
+ constructor(_isReadonly = false, _isShallow = false) {
634
+ this._isReadonly = _isReadonly;
635
+ this._isShallow = _isShallow;
636
+ }
637
+ get(target, key, receiver) {
638
+ if (key === "__v_skip") return target["__v_skip"];
639
+ const isReadonly = this._isReadonly, isShallow = this._isShallow;
640
+ if (key === "__v_isReactive") return !isReadonly;
641
+ else if (key === "__v_isReadonly") return isReadonly;
642
+ else if (key === "__v_isShallow") return isShallow;
643
+ else if (key === "__v_raw") {
644
+ if (receiver === (isReadonly ? isShallow ? shallowReadonlyMap : readonlyMap : isShallow ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
645
+ return;
646
+ }
647
+ const targetIsArray = isArray$1(target);
648
+ if (!isReadonly) {
649
+ let fn;
650
+ if (targetIsArray && (fn = arrayInstrumentations[key])) return fn;
651
+ if (key === "hasOwnProperty") return hasOwnProperty;
652
+ }
653
+ const wasRef = /* @__PURE__ */ isRef(target);
654
+ const res = Reflect.get(target, key, wasRef ? target : receiver);
655
+ if (wasRef && key !== "value") return res;
656
+ if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
657
+ if (!isReadonly) track(target, "get", key);
658
+ if (isShallow) return res;
659
+ if (/* @__PURE__ */ isRef(res)) {
660
+ const value = targetIsArray && isIntegerKey(key) ? res : res.value;
661
+ return isReadonly && isObject$1(value) ? /* @__PURE__ */ readonly(value) : value;
662
+ }
663
+ if (isObject$1(res)) return isReadonly ? /* @__PURE__ */ readonly(res) : /* @__PURE__ */ reactive(res);
664
+ return res;
665
+ }
666
+ };
667
+ var MutableReactiveHandler = class extends BaseReactiveHandler {
668
+ constructor(isShallow = false) {
669
+ super(false, isShallow);
670
+ }
671
+ set(target, key, value, receiver) {
672
+ let oldValue = target[key];
673
+ const isArrayWithIntegerKey = isArray$1(target) && isIntegerKey(key);
674
+ if (!this._isShallow) {
675
+ const isOldValueReadonly = /* @__PURE__ */ isReadonly(oldValue);
676
+ if (!/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) {
677
+ oldValue = /* @__PURE__ */ toRaw(oldValue);
678
+ value = /* @__PURE__ */ toRaw(value);
679
+ }
680
+ if (!isArrayWithIntegerKey && /* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) if (isOldValueReadonly) {
681
+ warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target[key]);
682
+ return true;
683
+ } else {
684
+ oldValue.value = value;
685
+ return true;
686
+ }
687
+ }
688
+ const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
689
+ const result = Reflect.set(target, key, value, /* @__PURE__ */ isRef(target) ? target : receiver);
690
+ if (target === /* @__PURE__ */ toRaw(receiver)) {
691
+ if (!hadKey) trigger(target, "add", key, value);
692
+ else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
693
+ }
694
+ return result;
695
+ }
696
+ deleteProperty(target, key) {
697
+ const hadKey = hasOwn(target, key);
698
+ const oldValue = target[key];
699
+ const result = Reflect.deleteProperty(target, key);
700
+ if (result && hadKey) trigger(target, "delete", key, void 0, oldValue);
701
+ return result;
702
+ }
703
+ has(target, key) {
704
+ const result = Reflect.has(target, key);
705
+ if (!isSymbol(key) || !builtInSymbols.has(key)) track(target, "has", key);
706
+ return result;
707
+ }
708
+ ownKeys(target) {
709
+ track(target, "iterate", isArray$1(target) ? "length" : ITERATE_KEY);
710
+ return Reflect.ownKeys(target);
711
+ }
712
+ };
713
+ var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
714
+ constructor(isShallow = false) {
715
+ super(true, isShallow);
716
+ }
717
+ set(target, key) {
718
+ warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
719
+ return true;
720
+ }
721
+ deleteProperty(target, key) {
722
+ warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
723
+ return true;
724
+ }
725
+ };
1144
726
  const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
1145
727
  const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
1146
728
  const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(true);
1147
729
  const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
1148
730
 
731
+ //#endregion
732
+ //#region packages/reactivity/src/collectionHandlers.ts
1149
733
  const toShallow = (value) => value;
1150
734
  const getProto = (v) => Reflect.getPrototypeOf(v);
1151
- function createIterableMethod(method, isReadonly2, isShallow2) {
1152
- return function(...args) {
1153
- const target = this["__v_raw"];
1154
- const rawTarget = toRaw(target);
1155
- const targetIsMap = isMap(rawTarget);
1156
- const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
1157
- const isKeyOnly = method === "keys" && targetIsMap;
1158
- const innerIterator = target[method](...args);
1159
- const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
1160
- !isReadonly2 && track(
1161
- rawTarget,
1162
- "iterate",
1163
- isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
1164
- );
1165
- return extend$1(
1166
- // inheriting all iterator properties
1167
- Object.create(innerIterator),
1168
- {
1169
- // iterator protocol
1170
- next() {
1171
- const { value, done } = innerIterator.next();
1172
- return done ? { value, done } : {
1173
- value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
1174
- done
1175
- };
1176
- }
1177
- }
1178
- );
1179
- };
735
+ function createIterableMethod(method, isReadonly, isShallow) {
736
+ return function(...args) {
737
+ const target = this["__v_raw"];
738
+ const rawTarget = /* @__PURE__ */ toRaw(target);
739
+ const targetIsMap = isMap(rawTarget);
740
+ const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
741
+ const isKeyOnly = method === "keys" && targetIsMap;
742
+ const innerIterator = target[method](...args);
743
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
744
+ !isReadonly && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
745
+ return extend$1(Object.create(innerIterator), { next() {
746
+ const { value, done } = innerIterator.next();
747
+ return done ? {
748
+ value,
749
+ done
750
+ } : {
751
+ value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
752
+ done
753
+ };
754
+ } });
755
+ };
1180
756
  }
1181
757
  function createReadonlyMethod(type) {
1182
- return function(...args) {
1183
- {
1184
- const key = args[0] ? `on key "${args[0]}" ` : ``;
1185
- warn(
1186
- `${capitalize(type)} operation ${key}failed: target is readonly.`,
1187
- toRaw(this)
1188
- );
1189
- }
1190
- return type === "delete" ? false : type === "clear" ? void 0 : this;
1191
- };
758
+ return function(...args) {
759
+ {
760
+ const key = args[0] ? `on key "${args[0]}" ` : ``;
761
+ warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, /* @__PURE__ */ toRaw(this));
762
+ }
763
+ return type === "delete" ? false : type === "clear" ? void 0 : this;
764
+ };
1192
765
  }
1193
766
  function createInstrumentations(readonly, shallow) {
1194
- const instrumentations = {
1195
- get(key) {
1196
- const target = this["__v_raw"];
1197
- const rawTarget = toRaw(target);
1198
- const rawKey = toRaw(key);
1199
- if (!readonly) {
1200
- if (hasChanged(key, rawKey)) {
1201
- track(rawTarget, "get", key);
1202
- }
1203
- track(rawTarget, "get", rawKey);
1204
- }
1205
- const { has } = getProto(rawTarget);
1206
- const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1207
- if (has.call(rawTarget, key)) {
1208
- return wrap(target.get(key));
1209
- } else if (has.call(rawTarget, rawKey)) {
1210
- return wrap(target.get(rawKey));
1211
- } else if (target !== rawTarget) {
1212
- target.get(key);
1213
- }
1214
- },
1215
- get size() {
1216
- const target = this["__v_raw"];
1217
- !readonly && track(toRaw(target), "iterate", ITERATE_KEY);
1218
- return target.size;
1219
- },
1220
- has(key) {
1221
- const target = this["__v_raw"];
1222
- const rawTarget = toRaw(target);
1223
- const rawKey = toRaw(key);
1224
- if (!readonly) {
1225
- if (hasChanged(key, rawKey)) {
1226
- track(rawTarget, "has", key);
1227
- }
1228
- track(rawTarget, "has", rawKey);
1229
- }
1230
- return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1231
- },
1232
- forEach(callback, thisArg) {
1233
- const observed = this;
1234
- const target = observed["__v_raw"];
1235
- const rawTarget = toRaw(target);
1236
- const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1237
- !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1238
- return target.forEach((value, key) => {
1239
- return callback.call(thisArg, wrap(value), wrap(key), observed);
1240
- });
1241
- }
1242
- };
1243
- extend$1(
1244
- instrumentations,
1245
- readonly ? {
1246
- add: createReadonlyMethod("add"),
1247
- set: createReadonlyMethod("set"),
1248
- delete: createReadonlyMethod("delete"),
1249
- clear: createReadonlyMethod("clear")
1250
- } : {
1251
- add(value) {
1252
- if (!shallow && !isShallow(value) && !isReadonly(value)) {
1253
- value = toRaw(value);
1254
- }
1255
- const target = toRaw(this);
1256
- const proto = getProto(target);
1257
- const hadKey = proto.has.call(target, value);
1258
- if (!hadKey) {
1259
- target.add(value);
1260
- trigger(target, "add", value, value);
1261
- }
1262
- return this;
1263
- },
1264
- set(key, value) {
1265
- if (!shallow && !isShallow(value) && !isReadonly(value)) {
1266
- value = toRaw(value);
1267
- }
1268
- const target = toRaw(this);
1269
- const { has, get } = getProto(target);
1270
- let hadKey = has.call(target, key);
1271
- if (!hadKey) {
1272
- key = toRaw(key);
1273
- hadKey = has.call(target, key);
1274
- } else {
1275
- checkIdentityKeys(target, has, key);
1276
- }
1277
- const oldValue = get.call(target, key);
1278
- target.set(key, value);
1279
- if (!hadKey) {
1280
- trigger(target, "add", key, value);
1281
- } else if (hasChanged(value, oldValue)) {
1282
- trigger(target, "set", key, value, oldValue);
1283
- }
1284
- return this;
1285
- },
1286
- delete(key) {
1287
- const target = toRaw(this);
1288
- const { has, get } = getProto(target);
1289
- let hadKey = has.call(target, key);
1290
- if (!hadKey) {
1291
- key = toRaw(key);
1292
- hadKey = has.call(target, key);
1293
- } else {
1294
- checkIdentityKeys(target, has, key);
1295
- }
1296
- const oldValue = get ? get.call(target, key) : void 0;
1297
- const result = target.delete(key);
1298
- if (hadKey) {
1299
- trigger(target, "delete", key, void 0, oldValue);
1300
- }
1301
- return result;
1302
- },
1303
- clear() {
1304
- const target = toRaw(this);
1305
- const hadItems = target.size !== 0;
1306
- const oldTarget = isMap(target) ? new Map(target) : new Set(target) ;
1307
- const result = target.clear();
1308
- if (hadItems) {
1309
- trigger(
1310
- target,
1311
- "clear",
1312
- void 0,
1313
- void 0,
1314
- oldTarget
1315
- );
1316
- }
1317
- return result;
1318
- }
1319
- }
1320
- );
1321
- const iteratorMethods = [
1322
- "keys",
1323
- "values",
1324
- "entries",
1325
- Symbol.iterator
1326
- ];
1327
- iteratorMethods.forEach((method) => {
1328
- instrumentations[method] = createIterableMethod(method, readonly, shallow);
1329
- });
1330
- return instrumentations;
1331
- }
1332
- function createInstrumentationGetter(isReadonly2, shallow) {
1333
- const instrumentations = createInstrumentations(isReadonly2, shallow);
1334
- return (target, key, receiver) => {
1335
- if (key === "__v_isReactive") {
1336
- return !isReadonly2;
1337
- } else if (key === "__v_isReadonly") {
1338
- return isReadonly2;
1339
- } else if (key === "__v_raw") {
1340
- return target;
1341
- }
1342
- return Reflect.get(
1343
- hasOwn(instrumentations, key) && key in target ? instrumentations : target,
1344
- key,
1345
- receiver
1346
- );
1347
- };
1348
- }
1349
- const mutableCollectionHandlers = {
1350
- get: /* @__PURE__ */ createInstrumentationGetter(false, false)
1351
- };
1352
- const shallowCollectionHandlers = {
1353
- get: /* @__PURE__ */ createInstrumentationGetter(false, true)
1354
- };
1355
- const readonlyCollectionHandlers = {
1356
- get: /* @__PURE__ */ createInstrumentationGetter(true, false)
1357
- };
1358
- const shallowReadonlyCollectionHandlers = {
1359
- get: /* @__PURE__ */ createInstrumentationGetter(true, true)
1360
- };
767
+ const instrumentations = {
768
+ get(key) {
769
+ const target = this["__v_raw"];
770
+ const rawTarget = /* @__PURE__ */ toRaw(target);
771
+ const rawKey = /* @__PURE__ */ toRaw(key);
772
+ if (!readonly) {
773
+ if (hasChanged(key, rawKey)) track(rawTarget, "get", key);
774
+ track(rawTarget, "get", rawKey);
775
+ }
776
+ const { has } = getProto(rawTarget);
777
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
778
+ if (has.call(rawTarget, key)) return wrap(target.get(key));
779
+ else if (has.call(rawTarget, rawKey)) return wrap(target.get(rawKey));
780
+ else if (target !== rawTarget) target.get(key);
781
+ },
782
+ get size() {
783
+ const target = this["__v_raw"];
784
+ !readonly && track(/* @__PURE__ */ toRaw(target), "iterate", ITERATE_KEY);
785
+ return target.size;
786
+ },
787
+ has(key) {
788
+ const target = this["__v_raw"];
789
+ const rawTarget = /* @__PURE__ */ toRaw(target);
790
+ const rawKey = /* @__PURE__ */ toRaw(key);
791
+ if (!readonly) {
792
+ if (hasChanged(key, rawKey)) track(rawTarget, "has", key);
793
+ track(rawTarget, "has", rawKey);
794
+ }
795
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
796
+ },
797
+ forEach(callback, thisArg) {
798
+ const observed = this;
799
+ const target = observed["__v_raw"];
800
+ const rawTarget = /* @__PURE__ */ toRaw(target);
801
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
802
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
803
+ return target.forEach((value, key) => {
804
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
805
+ });
806
+ }
807
+ };
808
+ extend$1(instrumentations, readonly ? {
809
+ add: createReadonlyMethod("add"),
810
+ set: createReadonlyMethod("set"),
811
+ delete: createReadonlyMethod("delete"),
812
+ clear: createReadonlyMethod("clear")
813
+ } : {
814
+ add(value) {
815
+ if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
816
+ const target = /* @__PURE__ */ toRaw(this);
817
+ if (!getProto(target).has.call(target, value)) {
818
+ target.add(value);
819
+ trigger(target, "add", value, value);
820
+ }
821
+ return this;
822
+ },
823
+ set(key, value) {
824
+ if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
825
+ const target = /* @__PURE__ */ toRaw(this);
826
+ const { has, get } = getProto(target);
827
+ let hadKey = has.call(target, key);
828
+ if (!hadKey) {
829
+ key = /* @__PURE__ */ toRaw(key);
830
+ hadKey = has.call(target, key);
831
+ } else checkIdentityKeys(target, has, key);
832
+ const oldValue = get.call(target, key);
833
+ target.set(key, value);
834
+ if (!hadKey) trigger(target, "add", key, value);
835
+ else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
836
+ return this;
837
+ },
838
+ delete(key) {
839
+ const target = /* @__PURE__ */ toRaw(this);
840
+ const { has, get } = getProto(target);
841
+ let hadKey = has.call(target, key);
842
+ if (!hadKey) {
843
+ key = /* @__PURE__ */ toRaw(key);
844
+ hadKey = has.call(target, key);
845
+ } else checkIdentityKeys(target, has, key);
846
+ const oldValue = get ? get.call(target, key) : void 0;
847
+ const result = target.delete(key);
848
+ if (hadKey) trigger(target, "delete", key, void 0, oldValue);
849
+ return result;
850
+ },
851
+ clear() {
852
+ const target = /* @__PURE__ */ toRaw(this);
853
+ const hadItems = target.size !== 0;
854
+ const oldTarget = isMap(target) ? new Map(target) : new Set(target) ;
855
+ const result = target.clear();
856
+ if (hadItems) trigger(target, "clear", void 0, void 0, oldTarget);
857
+ return result;
858
+ }
859
+ });
860
+ [
861
+ "keys",
862
+ "values",
863
+ "entries",
864
+ Symbol.iterator
865
+ ].forEach((method) => {
866
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
867
+ });
868
+ return instrumentations;
869
+ }
870
+ function createInstrumentationGetter(isReadonly, shallow) {
871
+ const instrumentations = createInstrumentations(isReadonly, shallow);
872
+ return (target, key, receiver) => {
873
+ if (key === "__v_isReactive") return !isReadonly;
874
+ else if (key === "__v_isReadonly") return isReadonly;
875
+ else if (key === "__v_raw") return target;
876
+ return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
877
+ };
878
+ }
879
+ const mutableCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, false) };
880
+ const shallowCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(false, true) };
881
+ const readonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, false) };
882
+ const shallowReadonlyCollectionHandlers = { get: /* @__PURE__ */ createInstrumentationGetter(true, true) };
1361
883
  function checkIdentityKeys(target, has, key) {
1362
- const rawKey = toRaw(key);
1363
- if (rawKey !== key && has.call(target, rawKey)) {
1364
- const type = toRawType(target);
1365
- warn(
1366
- `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.`
1367
- );
1368
- }
884
+ const rawKey = /* @__PURE__ */ toRaw(key);
885
+ if (rawKey !== key && has.call(target, rawKey)) {
886
+ const type = toRawType(target);
887
+ warn(`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.`);
888
+ }
1369
889
  }
1370
890
 
891
+ //#endregion
892
+ //#region packages/reactivity/src/reactive.ts
1371
893
  const reactiveMap = /* @__PURE__ */ new WeakMap();
1372
894
  const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
1373
895
  const readonlyMap = /* @__PURE__ */ new WeakMap();
1374
896
  const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
1375
897
  function targetTypeMap(rawType) {
1376
- switch (rawType) {
1377
- case "Object":
1378
- case "Array":
1379
- return 1 /* COMMON */;
1380
- case "Map":
1381
- case "Set":
1382
- case "WeakMap":
1383
- case "WeakSet":
1384
- return 2 /* COLLECTION */;
1385
- default:
1386
- return 0 /* INVALID */;
1387
- }
898
+ switch (rawType) {
899
+ case "Object":
900
+ case "Array": return 1;
901
+ case "Map":
902
+ case "Set":
903
+ case "WeakMap":
904
+ case "WeakSet": return 2;
905
+ default: return 0;
906
+ }
1388
907
  }
1389
908
  function getTargetType(value) {
1390
- return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(toRawType(value));
909
+ return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
1391
910
  }
1392
- // @__NO_SIDE_EFFECTS__
911
+ /* @__NO_SIDE_EFFECTS__ */
1393
912
  function reactive(target) {
1394
- if (/* @__PURE__ */ isReadonly(target)) {
1395
- return target;
1396
- }
1397
- return createReactiveObject(
1398
- target,
1399
- false,
1400
- mutableHandlers,
1401
- mutableCollectionHandlers,
1402
- reactiveMap
1403
- );
1404
- }
1405
- // @__NO_SIDE_EFFECTS__
913
+ if (/* @__PURE__ */ isReadonly(target)) return target;
914
+ return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
915
+ }
916
+ /**
917
+ * Shallow version of {@link reactive}.
918
+ *
919
+ * Unlike {@link reactive}, there is no deep conversion: only root-level
920
+ * properties are reactive for a shallow reactive object. Property values are
921
+ * stored and exposed as-is - this also means properties with ref values will
922
+ * not be automatically unwrapped.
923
+ *
924
+ * @example
925
+ * ```js
926
+ * const state = shallowReactive({
927
+ * foo: 1,
928
+ * nested: {
929
+ * bar: 2
930
+ * }
931
+ * })
932
+ *
933
+ * // mutating state's own properties is reactive
934
+ * state.foo++
935
+ *
936
+ * // ...but does not convert nested objects
937
+ * isReactive(state.nested) // false
938
+ *
939
+ * // NOT reactive
940
+ * state.nested.bar++
941
+ * ```
942
+ *
943
+ * @param target - The source object.
944
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreactive}
945
+ */
946
+ /* @__NO_SIDE_EFFECTS__ */
1406
947
  function shallowReactive(target) {
1407
- return createReactiveObject(
1408
- target,
1409
- false,
1410
- shallowReactiveHandlers,
1411
- shallowCollectionHandlers,
1412
- shallowReactiveMap
1413
- );
1414
- }
1415
- // @__NO_SIDE_EFFECTS__
948
+ return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
949
+ }
950
+ /**
951
+ * Takes an object (reactive or plain) or a ref and returns a readonly proxy to
952
+ * the original.
953
+ *
954
+ * A readonly proxy is deep: any nested property accessed will be readonly as
955
+ * well. It also has the same ref-unwrapping behavior as {@link reactive},
956
+ * except the unwrapped values will also be made readonly.
957
+ *
958
+ * @example
959
+ * ```js
960
+ * const original = reactive({ count: 0 })
961
+ *
962
+ * const copy = readonly(original)
963
+ *
964
+ * watchEffect(() => {
965
+ * // works for reactivity tracking
966
+ * console.log(copy.count)
967
+ * })
968
+ *
969
+ * // mutating original will trigger watchers relying on the copy
970
+ * original.count++
971
+ *
972
+ * // mutating the copy will fail and result in a warning
973
+ * copy.count++ // warning!
974
+ * ```
975
+ *
976
+ * @param target - The source object.
977
+ * @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
978
+ */
979
+ /* @__NO_SIDE_EFFECTS__ */
1416
980
  function readonly(target) {
1417
- return createReactiveObject(
1418
- target,
1419
- true,
1420
- readonlyHandlers,
1421
- readonlyCollectionHandlers,
1422
- readonlyMap
1423
- );
1424
- }
1425
- // @__NO_SIDE_EFFECTS__
981
+ return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
982
+ }
983
+ /**
984
+ * Shallow version of {@link readonly}.
985
+ *
986
+ * Unlike {@link readonly}, there is no deep conversion: only root-level
987
+ * properties are made readonly. Property values are stored and exposed as-is -
988
+ * this also means properties with ref values will not be automatically
989
+ * unwrapped.
990
+ *
991
+ * @example
992
+ * ```js
993
+ * const state = shallowReadonly({
994
+ * foo: 1,
995
+ * nested: {
996
+ * bar: 2
997
+ * }
998
+ * })
999
+ *
1000
+ * // mutating state's own properties will fail
1001
+ * state.foo++
1002
+ *
1003
+ * // ...but works on nested objects
1004
+ * isReadonly(state.nested) // false
1005
+ *
1006
+ * // works
1007
+ * state.nested.bar++
1008
+ * ```
1009
+ *
1010
+ * @param target - The source object.
1011
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowreadonly}
1012
+ */
1013
+ /* @__NO_SIDE_EFFECTS__ */
1426
1014
  function shallowReadonly(target) {
1427
- return createReactiveObject(
1428
- target,
1429
- true,
1430
- shallowReadonlyHandlers,
1431
- shallowReadonlyCollectionHandlers,
1432
- shallowReadonlyMap
1433
- );
1434
- }
1435
- function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
1436
- if (!isObject$1(target)) {
1437
- {
1438
- warn(
1439
- `value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(
1440
- target
1441
- )}`
1442
- );
1443
- }
1444
- return target;
1445
- }
1446
- if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
1447
- return target;
1448
- }
1449
- const targetType = getTargetType(target);
1450
- if (targetType === 0 /* INVALID */) {
1451
- return target;
1452
- }
1453
- const existingProxy = proxyMap.get(target);
1454
- if (existingProxy) {
1455
- return existingProxy;
1456
- }
1457
- const proxy = new Proxy(
1458
- target,
1459
- targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
1460
- );
1461
- proxyMap.set(target, proxy);
1462
- return proxy;
1463
- }
1464
- // @__NO_SIDE_EFFECTS__
1015
+ return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
1016
+ }
1017
+ function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
1018
+ if (!isObject$1(target)) {
1019
+ warn(`value cannot be made ${isReadonly ? "readonly" : "reactive"}: ${String(target)}`);
1020
+ return target;
1021
+ }
1022
+ if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) return target;
1023
+ const targetType = getTargetType(target);
1024
+ if (targetType === 0) return target;
1025
+ const existingProxy = proxyMap.get(target);
1026
+ if (existingProxy) return existingProxy;
1027
+ const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
1028
+ proxyMap.set(target, proxy);
1029
+ return proxy;
1030
+ }
1031
+ /**
1032
+ * Checks if an object is a proxy created by {@link reactive} or
1033
+ * {@link shallowReactive} (or {@link ref} in some cases).
1034
+ *
1035
+ * @example
1036
+ * ```js
1037
+ * isReactive(reactive({})) // => true
1038
+ * isReactive(readonly(reactive({}))) // => true
1039
+ * isReactive(ref({}).value) // => true
1040
+ * isReactive(readonly(ref({})).value) // => true
1041
+ * isReactive(ref(true)) // => false
1042
+ * isReactive(shallowRef({}).value) // => false
1043
+ * isReactive(shallowReactive({})) // => true
1044
+ * ```
1045
+ *
1046
+ * @param value - The value to check.
1047
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
1048
+ */
1049
+ /* @__NO_SIDE_EFFECTS__ */
1465
1050
  function isReactive(value) {
1466
- if (/* @__PURE__ */ isReadonly(value)) {
1467
- return /* @__PURE__ */ isReactive(value["__v_raw"]);
1468
- }
1469
- return !!(value && value["__v_isReactive"]);
1051
+ if (/* @__PURE__ */ isReadonly(value)) return /* @__PURE__ */ isReactive(value["__v_raw"]);
1052
+ return !!(value && value["__v_isReactive"]);
1470
1053
  }
1471
- // @__NO_SIDE_EFFECTS__
1054
+ /**
1055
+ * Checks whether the passed value is a readonly object. The properties of a
1056
+ * readonly object can change, but they can't be assigned directly via the
1057
+ * passed object.
1058
+ *
1059
+ * The proxies created by {@link readonly} and {@link shallowReadonly} are
1060
+ * both considered readonly, as is a computed ref without a set function.
1061
+ *
1062
+ * @param value - The value to check.
1063
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
1064
+ */
1065
+ /* @__NO_SIDE_EFFECTS__ */
1472
1066
  function isReadonly(value) {
1473
- return !!(value && value["__v_isReadonly"]);
1067
+ return !!(value && value["__v_isReadonly"]);
1474
1068
  }
1475
- // @__NO_SIDE_EFFECTS__
1069
+ /* @__NO_SIDE_EFFECTS__ */
1476
1070
  function isShallow(value) {
1477
- return !!(value && value["__v_isShallow"]);
1071
+ return !!(value && value["__v_isShallow"]);
1478
1072
  }
1479
- // @__NO_SIDE_EFFECTS__
1073
+ /**
1074
+ * Checks if an object is a proxy created by {@link reactive},
1075
+ * {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
1076
+ *
1077
+ * @param value - The value to check.
1078
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
1079
+ */
1080
+ /* @__NO_SIDE_EFFECTS__ */
1480
1081
  function isProxy(value) {
1481
- return value ? !!value["__v_raw"] : false;
1082
+ return value ? !!value["__v_raw"] : false;
1482
1083
  }
1483
- // @__NO_SIDE_EFFECTS__
1084
+ /**
1085
+ * Returns the raw, original object of a Vue-created proxy.
1086
+ *
1087
+ * `toRaw()` can return the original object from proxies created by
1088
+ * {@link reactive}, {@link readonly}, {@link shallowReactive} or
1089
+ * {@link shallowReadonly}.
1090
+ *
1091
+ * This is an escape hatch that can be used to temporarily read without
1092
+ * incurring proxy access / tracking overhead or write without triggering
1093
+ * changes. It is **not** recommended to hold a persistent reference to the
1094
+ * original object. Use with caution.
1095
+ *
1096
+ * @example
1097
+ * ```js
1098
+ * const foo = {}
1099
+ * const reactiveFoo = reactive(foo)
1100
+ *
1101
+ * console.log(toRaw(reactiveFoo) === foo) // true
1102
+ * ```
1103
+ *
1104
+ * @param observed - The object for which the "raw" value is requested.
1105
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
1106
+ */
1107
+ /* @__NO_SIDE_EFFECTS__ */
1484
1108
  function toRaw(observed) {
1485
- const raw = observed && observed["__v_raw"];
1486
- return raw ? /* @__PURE__ */ toRaw(raw) : observed;
1109
+ const raw = observed && observed["__v_raw"];
1110
+ return raw ? /* @__PURE__ */ toRaw(raw) : observed;
1487
1111
  }
1112
+ /**
1113
+ * Marks an object so that it will never be converted to a proxy. Returns the
1114
+ * object itself.
1115
+ *
1116
+ * @example
1117
+ * ```js
1118
+ * const foo = markRaw({})
1119
+ * console.log(isReactive(reactive(foo))) // false
1120
+ *
1121
+ * // also works when nested inside other reactive objects
1122
+ * const bar = reactive({ foo })
1123
+ * console.log(isReactive(bar.foo)) // false
1124
+ * ```
1125
+ *
1126
+ * **Warning:** `markRaw()` together with the shallow APIs such as
1127
+ * {@link shallowReactive} allow you to selectively opt-out of the default
1128
+ * deep reactive/readonly conversion and embed raw, non-proxied objects in your
1129
+ * state graph.
1130
+ *
1131
+ * @param value - The object to be marked as "raw".
1132
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#markraw}
1133
+ */
1488
1134
  function markRaw(value) {
1489
- if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) {
1490
- def(value, "__v_skip", true);
1491
- }
1492
- return value;
1135
+ if (!hasOwn(value, "__v_skip") && Object.isExtensible(value)) def(value, "__v_skip", true);
1136
+ return value;
1493
1137
  }
1138
+ /**
1139
+ * Returns a reactive proxy of the given value (if possible).
1140
+ *
1141
+ * If the given value is not an object, the original value itself is returned.
1142
+ *
1143
+ * @param value - The value for which a reactive proxy shall be created.
1144
+ */
1494
1145
  const toReactive = (value) => isObject$1(value) ? /* @__PURE__ */ reactive(value) : value;
1146
+ /**
1147
+ * Returns a readonly proxy of the given value (if possible).
1148
+ *
1149
+ * If the given value is not an object, the original value itself is returned.
1150
+ *
1151
+ * @param value - The value for which a readonly proxy shall be created.
1152
+ */
1495
1153
  const toReadonly = (value) => isObject$1(value) ? /* @__PURE__ */ readonly(value) : value;
1496
1154
 
1497
- // @__NO_SIDE_EFFECTS__
1155
+ //#endregion
1156
+ //#region packages/reactivity/src/ref.ts
1157
+ /* @__NO_SIDE_EFFECTS__ */
1498
1158
  function isRef(r) {
1499
- return r ? r["__v_isRef"] === true : false;
1159
+ return r ? r["__v_isRef"] === true : false;
1500
1160
  }
1501
- // @__NO_SIDE_EFFECTS__
1161
+ /* @__NO_SIDE_EFFECTS__ */
1502
1162
  function ref(value) {
1503
- return createRef(value, false);
1163
+ return createRef(value, toReactive);
1504
1164
  }
1505
- // @__NO_SIDE_EFFECTS__
1165
+ /* @__NO_SIDE_EFFECTS__ */
1506
1166
  function shallowRef(value) {
1507
- return createRef(value, true);
1508
- }
1509
- function createRef(rawValue, shallow) {
1510
- if (/* @__PURE__ */ isRef(rawValue)) {
1511
- return rawValue;
1512
- }
1513
- return new RefImpl(rawValue, shallow);
1514
- }
1515
- class RefImpl {
1516
- constructor(value, isShallow2) {
1517
- this.dep = new Dep();
1518
- this["__v_isRef"] = true;
1519
- this["__v_isShallow"] = false;
1520
- this._rawValue = isShallow2 ? value : toRaw(value);
1521
- this._value = isShallow2 ? value : toReactive(value);
1522
- this["__v_isShallow"] = isShallow2;
1523
- }
1524
- get value() {
1525
- {
1526
- this.dep.track({
1527
- target: this,
1528
- type: "get",
1529
- key: "value"
1530
- });
1531
- }
1532
- return this._value;
1533
- }
1534
- set value(newValue) {
1535
- const oldValue = this._rawValue;
1536
- const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
1537
- newValue = useDirectValue ? newValue : toRaw(newValue);
1538
- if (hasChanged(newValue, oldValue)) {
1539
- this._rawValue = newValue;
1540
- this._value = useDirectValue ? newValue : toReactive(newValue);
1541
- {
1542
- this.dep.trigger({
1543
- target: this,
1544
- type: "set",
1545
- key: "value",
1546
- newValue,
1547
- oldValue
1548
- });
1549
- }
1550
- }
1551
- }
1167
+ return createRef(value);
1552
1168
  }
1553
- function triggerRef(ref2) {
1554
- if (ref2.dep) {
1555
- {
1556
- ref2.dep.trigger({
1557
- target: ref2,
1558
- type: "set",
1559
- key: "value",
1560
- newValue: ref2._value
1561
- });
1562
- }
1563
- }
1169
+ function createRef(rawValue, wrap) {
1170
+ if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
1171
+ return new RefImpl(rawValue, wrap);
1564
1172
  }
1565
- function unref(ref2) {
1566
- return /* @__PURE__ */ isRef(ref2) ? ref2.value : ref2;
1173
+ /**
1174
+ * @internal
1175
+ */
1176
+ var RefImpl = class {
1177
+ constructor(value, wrap) {
1178
+ this.subs = void 0;
1179
+ this.subsTail = void 0;
1180
+ this.flags = ReactiveFlags$1.Mutable;
1181
+ this.__v_isRef = true;
1182
+ this.__v_isShallow = false;
1183
+ this._oldValue = this._rawValue = wrap ? /* @__PURE__ */ toRaw(value) : value;
1184
+ this._value = wrap ? wrap(value) : value;
1185
+ this._wrap = wrap;
1186
+ this["__v_isShallow"] = !wrap;
1187
+ }
1188
+ get dep() {
1189
+ return this;
1190
+ }
1191
+ get value() {
1192
+ trackRef(this);
1193
+ if (this.flags & ReactiveFlags$1.Dirty && this.update()) {
1194
+ const subs = this.subs;
1195
+ if (subs !== void 0) shallowPropagate(subs);
1196
+ }
1197
+ return this._value;
1198
+ }
1199
+ set value(newValue) {
1200
+ const oldValue = this._rawValue;
1201
+ const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
1202
+ newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
1203
+ if (hasChanged(newValue, oldValue)) {
1204
+ this.flags |= ReactiveFlags$1.Dirty;
1205
+ this._rawValue = newValue;
1206
+ this._value = !useDirectValue && this._wrap ? this._wrap(newValue) : newValue;
1207
+ const subs = this.subs;
1208
+ if (subs !== void 0) {
1209
+ triggerEventInfos.push({
1210
+ target: this,
1211
+ type: "set",
1212
+ key: "value",
1213
+ newValue,
1214
+ oldValue
1215
+ });
1216
+ propagate(subs);
1217
+ if (!batchDepth) flush();
1218
+ triggerEventInfos.pop();
1219
+ }
1220
+ }
1221
+ }
1222
+ update() {
1223
+ this.flags &= -17;
1224
+ return hasChanged(this._oldValue, this._oldValue = this._rawValue);
1225
+ }
1226
+ };
1227
+ /**
1228
+ * Force trigger effects that depends on a shallow ref. This is typically used
1229
+ * after making deep mutations to the inner value of a shallow ref.
1230
+ *
1231
+ * @example
1232
+ * ```js
1233
+ * const shallow = shallowRef({
1234
+ * greet: 'Hello, world'
1235
+ * })
1236
+ *
1237
+ * // Logs "Hello, world" once for the first run-through
1238
+ * watchEffect(() => {
1239
+ * console.log(shallow.value.greet)
1240
+ * })
1241
+ *
1242
+ * // This won't trigger the effect because the ref is shallow
1243
+ * shallow.value.greet = 'Hello, universe'
1244
+ *
1245
+ * // Logs "Hello, universe"
1246
+ * triggerRef(shallow)
1247
+ * ```
1248
+ *
1249
+ * @param ref - The ref whose tied effects shall be executed.
1250
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#triggerref}
1251
+ */
1252
+ function triggerRef(ref) {
1253
+ const dep = ref.dep;
1254
+ if (dep !== void 0 && dep.subs !== void 0) {
1255
+ propagate(dep.subs);
1256
+ shallowPropagate(dep.subs);
1257
+ if (!batchDepth) flush();
1258
+ }
1259
+ }
1260
+ function trackRef(dep) {
1261
+ if (activeSub !== void 0) {
1262
+ onTrack(activeSub, {
1263
+ target: dep,
1264
+ type: "get",
1265
+ key: "value"
1266
+ });
1267
+ link(dep, activeSub);
1268
+ }
1269
+ }
1270
+ /**
1271
+ * Returns the inner value if the argument is a ref, otherwise return the
1272
+ * argument itself. This is a sugar function for
1273
+ * `val = isRef(val) ? val.value : val`.
1274
+ *
1275
+ * @example
1276
+ * ```js
1277
+ * function useFoo(x: number | Ref<number>) {
1278
+ * const unwrapped = unref(x)
1279
+ * // unwrapped is guaranteed to be number now
1280
+ * }
1281
+ * ```
1282
+ *
1283
+ * @param ref - Ref or plain value to be converted into the plain value.
1284
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
1285
+ */
1286
+ function unref(ref) {
1287
+ return /* @__PURE__ */ isRef(ref) ? ref.value : ref;
1567
1288
  }
1289
+ /**
1290
+ * Normalizes values / refs / getters to values.
1291
+ * This is similar to {@link unref}, except that it also normalizes getters.
1292
+ * If the argument is a getter, it will be invoked and its return value will
1293
+ * be returned.
1294
+ *
1295
+ * @example
1296
+ * ```js
1297
+ * toValue(1) // 1
1298
+ * toValue(ref(1)) // 1
1299
+ * toValue(() => 1) // 1
1300
+ * ```
1301
+ *
1302
+ * @param source - A getter, an existing ref, or a non-function value.
1303
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
1304
+ */
1568
1305
  function toValue(source) {
1569
- return isFunction$1(source) ? source() : unref(source);
1306
+ return isFunction$1(source) ? source() : unref(source);
1570
1307
  }
1571
1308
  const shallowUnwrapHandlers = {
1572
- get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1573
- set: (target, key, value, receiver) => {
1574
- const oldValue = target[key];
1575
- if (/* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) {
1576
- oldValue.value = value;
1577
- return true;
1578
- } else {
1579
- return Reflect.set(target, key, value, receiver);
1580
- }
1581
- }
1309
+ get: (target, key, receiver) => key === "__v_raw" ? target : unref(Reflect.get(target, key, receiver)),
1310
+ set: (target, key, value, receiver) => {
1311
+ const oldValue = target[key];
1312
+ if (/* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) {
1313
+ oldValue.value = value;
1314
+ return true;
1315
+ } else return Reflect.set(target, key, value, receiver);
1316
+ }
1582
1317
  };
1318
+ /**
1319
+ * Returns a proxy for the given object that shallowly unwraps properties that
1320
+ * are refs. If the object already is reactive, it's returned as-is. If not, a
1321
+ * new reactive proxy is created.
1322
+ *
1323
+ * @param objectWithRefs - Either an already-reactive object or a simple object
1324
+ * that contains refs.
1325
+ */
1583
1326
  function proxyRefs(objectWithRefs) {
1584
- return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1585
- }
1586
- class CustomRefImpl {
1587
- constructor(factory) {
1588
- this["__v_isRef"] = true;
1589
- this._value = void 0;
1590
- const dep = this.dep = new Dep();
1591
- const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1592
- this._get = get;
1593
- this._set = set;
1594
- }
1595
- get value() {
1596
- return this._value = this._get();
1597
- }
1598
- set value(newVal) {
1599
- this._set(newVal);
1600
- }
1601
- }
1327
+ return /* @__PURE__ */ isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1328
+ }
1329
+ var CustomRefImpl = class {
1330
+ constructor(factory) {
1331
+ this.subs = void 0;
1332
+ this.subsTail = void 0;
1333
+ this.flags = ReactiveFlags$1.None;
1334
+ this["__v_isRef"] = true;
1335
+ this._value = void 0;
1336
+ const { get, set } = factory(() => trackRef(this), () => triggerRef(this));
1337
+ this._get = get;
1338
+ this._set = set;
1339
+ }
1340
+ get dep() {
1341
+ return this;
1342
+ }
1343
+ get value() {
1344
+ return this._value = this._get();
1345
+ }
1346
+ set value(newVal) {
1347
+ this._set(newVal);
1348
+ }
1349
+ };
1350
+ /**
1351
+ * Creates a customized ref with explicit control over its dependency tracking
1352
+ * and updates triggering.
1353
+ *
1354
+ * @param factory - The function that receives the `track` and `trigger` callbacks.
1355
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#customref}
1356
+ */
1602
1357
  function customRef(factory) {
1603
- return new CustomRefImpl(factory);
1358
+ return new CustomRefImpl(factory);
1604
1359
  }
1605
- // @__NO_SIDE_EFFECTS__
1360
+ /**
1361
+ * Converts a reactive object to a plain object where each property of the
1362
+ * resulting object is a ref pointing to the corresponding property of the
1363
+ * original object. Each individual ref is created using {@link toRef}.
1364
+ *
1365
+ * @param object - Reactive object to be made into an object of linked refs.
1366
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
1367
+ */
1368
+ /* @__NO_SIDE_EFFECTS__ */
1606
1369
  function toRefs(object) {
1607
- if (!isProxy(object)) {
1608
- warn(`toRefs() expects a reactive object but received a plain one.`);
1609
- }
1610
- const ret = isArray$1(object) ? new Array(object.length) : {};
1611
- for (const key in object) {
1612
- ret[key] = propertyToRef(object, key);
1613
- }
1614
- return ret;
1615
- }
1616
- class ObjectRefImpl {
1617
- constructor(_object, _key, _defaultValue) {
1618
- this._object = _object;
1619
- this._key = _key;
1620
- this._defaultValue = _defaultValue;
1621
- this["__v_isRef"] = true;
1622
- this._value = void 0;
1623
- this._raw = toRaw(_object);
1624
- let shallow = true;
1625
- let obj = _object;
1626
- if (!isArray$1(_object) || !isIntegerKey(String(_key))) {
1627
- do {
1628
- shallow = !isProxy(obj) || isShallow(obj);
1629
- } while (shallow && (obj = obj["__v_raw"]));
1630
- }
1631
- this._shallow = shallow;
1632
- }
1633
- get value() {
1634
- let val = this._object[this._key];
1635
- if (this._shallow) {
1636
- val = unref(val);
1637
- }
1638
- return this._value = val === void 0 ? this._defaultValue : val;
1639
- }
1640
- set value(newVal) {
1641
- if (this._shallow && /* @__PURE__ */ isRef(this._raw[this._key])) {
1642
- const nestedRef = this._object[this._key];
1643
- if (/* @__PURE__ */ isRef(nestedRef)) {
1644
- nestedRef.value = newVal;
1645
- return;
1646
- }
1647
- }
1648
- this._object[this._key] = newVal;
1649
- }
1650
- get dep() {
1651
- return getDepFromReactive(this._raw, this._key);
1652
- }
1653
- }
1654
- class GetterRefImpl {
1655
- constructor(_getter) {
1656
- this._getter = _getter;
1657
- this["__v_isRef"] = true;
1658
- this["__v_isReadonly"] = true;
1659
- this._value = void 0;
1660
- }
1661
- get value() {
1662
- return this._value = this._getter();
1663
- }
1664
- }
1665
- // @__NO_SIDE_EFFECTS__
1370
+ const ret = isArray$1(object) ? new Array(object.length) : {};
1371
+ for (const key in object) ret[key] = propertyToRef(object, key);
1372
+ return ret;
1373
+ }
1374
+ var ObjectRefImpl = class {
1375
+ constructor(_object, _key, _defaultValue) {
1376
+ this._object = _object;
1377
+ this._key = _key;
1378
+ this._defaultValue = _defaultValue;
1379
+ this["__v_isRef"] = true;
1380
+ this._value = void 0;
1381
+ this._raw = /* @__PURE__ */ toRaw(_object);
1382
+ let shallow = true;
1383
+ let obj = _object;
1384
+ if (!isArray$1(_object) || !isIntegerKey(String(_key))) do
1385
+ shallow = !/* @__PURE__ */ isProxy(obj) || /* @__PURE__ */ isShallow(obj);
1386
+ while (shallow && (obj = obj["__v_raw"]));
1387
+ this._shallow = shallow;
1388
+ }
1389
+ get value() {
1390
+ let val = this._object[this._key];
1391
+ if (this._shallow) val = unref(val);
1392
+ return this._value = val === void 0 ? this._defaultValue : val;
1393
+ }
1394
+ set value(newVal) {
1395
+ if (this._shallow && /* @__PURE__ */ isRef(this._raw[this._key])) {
1396
+ const nestedRef = this._object[this._key];
1397
+ if (/* @__PURE__ */ isRef(nestedRef)) {
1398
+ nestedRef.value = newVal;
1399
+ return;
1400
+ }
1401
+ }
1402
+ this._object[this._key] = newVal;
1403
+ }
1404
+ get dep() {
1405
+ return getDepFromReactive(this._raw, this._key);
1406
+ }
1407
+ };
1408
+ var GetterRefImpl = class {
1409
+ constructor(_getter) {
1410
+ this._getter = _getter;
1411
+ this["__v_isRef"] = true;
1412
+ this["__v_isReadonly"] = true;
1413
+ this._value = void 0;
1414
+ }
1415
+ get value() {
1416
+ return this._value = this._getter();
1417
+ }
1418
+ };
1419
+ /* @__NO_SIDE_EFFECTS__ */
1666
1420
  function toRef(source, key, defaultValue) {
1667
- if (/* @__PURE__ */ isRef(source)) {
1668
- return source;
1669
- } else if (isFunction$1(source)) {
1670
- return new GetterRefImpl(source);
1671
- } else if (isObject$1(source) && arguments.length > 1) {
1672
- return propertyToRef(source, key, defaultValue);
1673
- } else {
1674
- return /* @__PURE__ */ ref(source);
1675
- }
1421
+ if (/* @__PURE__ */ isRef(source)) return source;
1422
+ else if (isFunction$1(source)) return new GetterRefImpl(source);
1423
+ else if (isObject$1(source) && arguments.length > 1) return propertyToRef(source, key, defaultValue);
1424
+ else return /* @__PURE__ */ ref(source);
1676
1425
  }
1677
1426
  function propertyToRef(source, key, defaultValue) {
1678
- return new ObjectRefImpl(source, key, defaultValue);
1427
+ return new ObjectRefImpl(source, key, defaultValue);
1679
1428
  }
1680
1429
 
1681
- class ComputedRefImpl {
1682
- constructor(fn, setter, isSSR) {
1683
- this.fn = fn;
1684
- this.setter = setter;
1685
- /**
1686
- * @internal
1687
- */
1688
- this._value = void 0;
1689
- /**
1690
- * @internal
1691
- */
1692
- this.dep = new Dep(this);
1693
- /**
1694
- * @internal
1695
- */
1696
- this.__v_isRef = true;
1697
- // TODO isolatedDeclarations "__v_isReadonly"
1698
- // A computed is also a subscriber that tracks other deps
1699
- /**
1700
- * @internal
1701
- */
1702
- this.deps = void 0;
1703
- /**
1704
- * @internal
1705
- */
1706
- this.depsTail = void 0;
1707
- /**
1708
- * @internal
1709
- */
1710
- this.flags = 16;
1711
- /**
1712
- * @internal
1713
- */
1714
- this.globalVersion = globalVersion - 1;
1715
- /**
1716
- * @internal
1717
- */
1718
- this.next = void 0;
1719
- // for backwards compat
1720
- this.effect = this;
1721
- this["__v_isReadonly"] = !setter;
1722
- this.isSSR = isSSR;
1723
- }
1724
- /**
1725
- * @internal
1726
- */
1727
- notify() {
1728
- this.flags |= 16;
1729
- if (!(this.flags & 8) && // avoid infinite self recursion
1730
- activeSub !== this) {
1731
- batch(this, true);
1732
- return true;
1733
- }
1734
- }
1735
- get value() {
1736
- const link = this.dep.track({
1737
- target: this,
1738
- type: "get",
1739
- key: "value"
1740
- }) ;
1741
- refreshComputed(this);
1742
- if (link) {
1743
- link.version = this.dep.version;
1744
- }
1745
- return this._value;
1746
- }
1747
- set value(newValue) {
1748
- if (this.setter) {
1749
- this.setter(newValue);
1750
- } else {
1751
- warn("Write operation failed: computed value is readonly");
1752
- }
1753
- }
1430
+ //#endregion
1431
+ //#region packages/reactivity/src/effect.ts
1432
+ const EffectFlags = {
1433
+ "ALLOW_RECURSE": 128,
1434
+ "PAUSED": 256};
1435
+ var ReactiveEffect = class {
1436
+ fn() {}
1437
+ constructor(fn) {
1438
+ this.deps = void 0;
1439
+ this.depsTail = void 0;
1440
+ this.subs = void 0;
1441
+ this.subsTail = void 0;
1442
+ this.flags = 18;
1443
+ this.cleanups = [];
1444
+ this.cleanupsLength = 0;
1445
+ if (fn !== void 0) this.fn = fn;
1446
+ if (activeEffectScope) link(this, activeEffectScope);
1447
+ }
1448
+ get active() {
1449
+ return !(this.flags & 1024);
1450
+ }
1451
+ pause() {
1452
+ this.flags |= 256;
1453
+ }
1454
+ resume() {
1455
+ if ((this.flags &= -257) & 48) this.notify();
1456
+ }
1457
+ notify() {
1458
+ if (!(this.flags & 256) && this.dirty) this.run();
1459
+ }
1460
+ run() {
1461
+ if (!this.active) return this.fn();
1462
+ cleanup(this);
1463
+ const prevSub = startTracking(this);
1464
+ try {
1465
+ return this.fn();
1466
+ } finally {
1467
+ endTracking(this, prevSub);
1468
+ const flags = this.flags;
1469
+ if ((flags & 136) === 136) {
1470
+ this.flags = flags & -9;
1471
+ this.notify();
1472
+ }
1473
+ }
1474
+ }
1475
+ stop() {
1476
+ if (!this.active) return;
1477
+ this.flags = 1024;
1478
+ let dep = this.deps;
1479
+ while (dep !== void 0) dep = unlink(dep, this);
1480
+ const sub = this.subs;
1481
+ if (sub !== void 0) unlink(sub);
1482
+ cleanup(this);
1483
+ }
1484
+ get dirty() {
1485
+ const flags = this.flags;
1486
+ if (flags & 16) return true;
1487
+ if (flags & 32) if (checkDirty(this.deps, this)) {
1488
+ this.flags = flags | 16;
1489
+ return true;
1490
+ } else this.flags = flags & -33;
1491
+ return false;
1492
+ }
1493
+ };
1494
+ setupOnTrigger(ReactiveEffect);
1495
+ function effect(fn, options) {
1496
+ if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
1497
+ const e = new ReactiveEffect(fn);
1498
+ if (options) {
1499
+ const { onStop, scheduler } = options;
1500
+ if (onStop) {
1501
+ options.onStop = void 0;
1502
+ const stop = e.stop.bind(e);
1503
+ e.stop = () => {
1504
+ stop();
1505
+ onStop();
1506
+ };
1507
+ }
1508
+ if (scheduler) {
1509
+ options.scheduler = void 0;
1510
+ e.notify = () => {
1511
+ if (!(e.flags & 256)) scheduler();
1512
+ };
1513
+ }
1514
+ extend$1(e, options);
1515
+ }
1516
+ try {
1517
+ e.run();
1518
+ } catch (err) {
1519
+ e.stop();
1520
+ throw err;
1521
+ }
1522
+ const runner = e.run.bind(e);
1523
+ runner.effect = e;
1524
+ return runner;
1525
+ }
1526
+ /**
1527
+ * Stops the effect associated with the given runner.
1528
+ *
1529
+ * @param runner - Association with the effect to stop tracking.
1530
+ */
1531
+ function stop(runner) {
1532
+ runner.effect.stop();
1533
+ }
1534
+ function cleanup(sub) {
1535
+ const l = sub.cleanupsLength;
1536
+ if (l) {
1537
+ for (let i = 0; i < l; i++) sub.cleanups[i]();
1538
+ sub.cleanupsLength = 0;
1539
+ }
1540
+ }
1541
+
1542
+ //#endregion
1543
+ //#region packages/reactivity/src/effectScope.ts
1544
+ let activeEffectScope;
1545
+ var EffectScope = class {
1546
+ constructor(detached = false) {
1547
+ this.deps = void 0;
1548
+ this.depsTail = void 0;
1549
+ this.subs = void 0;
1550
+ this.subsTail = void 0;
1551
+ this.flags = 0;
1552
+ this.cleanups = [];
1553
+ this.cleanupsLength = 0;
1554
+ if (!detached && activeEffectScope) link(this, activeEffectScope);
1555
+ }
1556
+ get active() {
1557
+ return !(this.flags & 1024);
1558
+ }
1559
+ pause() {
1560
+ if (!(this.flags & 256)) {
1561
+ this.flags |= 256;
1562
+ for (let link = this.deps; link !== void 0; link = link.nextDep) {
1563
+ const dep = link.dep;
1564
+ if ("pause" in dep) dep.pause();
1565
+ }
1566
+ }
1567
+ }
1568
+ /**
1569
+ * Resumes the effect scope, including all child scopes and effects.
1570
+ */
1571
+ resume() {
1572
+ const flags = this.flags;
1573
+ if (flags & 256) {
1574
+ this.flags = flags & -257;
1575
+ for (let link = this.deps; link !== void 0; link = link.nextDep) {
1576
+ const dep = link.dep;
1577
+ if ("resume" in dep) dep.resume();
1578
+ }
1579
+ }
1580
+ }
1581
+ run(fn) {
1582
+ const prevScope = activeEffectScope;
1583
+ try {
1584
+ activeEffectScope = this;
1585
+ return fn();
1586
+ } finally {
1587
+ activeEffectScope = prevScope;
1588
+ }
1589
+ }
1590
+ stop() {
1591
+ if (!this.active) return;
1592
+ this.flags = 1024;
1593
+ this.reset();
1594
+ const sub = this.subs;
1595
+ if (sub !== void 0) unlink(sub);
1596
+ }
1597
+ /**
1598
+ * @internal
1599
+ */
1600
+ reset() {
1601
+ let dep = this.deps;
1602
+ while (dep !== void 0) {
1603
+ const node = dep.dep;
1604
+ if ("stop" in node) {
1605
+ dep = dep.nextDep;
1606
+ node.stop();
1607
+ } else dep = unlink(dep, this);
1608
+ }
1609
+ cleanup(this);
1610
+ }
1611
+ };
1612
+ /**
1613
+ * Creates an effect scope object which can capture the reactive effects (i.e.
1614
+ * computed and watchers) created within it so that these effects can be
1615
+ * disposed together. For detailed use cases of this API, please consult its
1616
+ * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
1617
+ *
1618
+ * @param detached - Can be used to create a "detached" effect scope.
1619
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
1620
+ */
1621
+ function effectScope(detached) {
1622
+ return new EffectScope(detached);
1623
+ }
1624
+ /**
1625
+ * Returns the current active effect scope if there is one.
1626
+ *
1627
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
1628
+ */
1629
+ function getCurrentScope() {
1630
+ return activeEffectScope;
1754
1631
  }
1755
- // @__NO_SIDE_EFFECTS__
1632
+ function setCurrentScope(scope) {
1633
+ try {
1634
+ return activeEffectScope;
1635
+ } finally {
1636
+ activeEffectScope = scope;
1637
+ }
1638
+ }
1639
+ /**
1640
+ * Registers a dispose callback on the current active effect scope. The
1641
+ * callback will be invoked when the associated effect scope is stopped.
1642
+ *
1643
+ * @param fn - The callback function to attach to the scope's cleanup.
1644
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
1645
+ */
1646
+ function onScopeDispose(fn, failSilently = false) {
1647
+ if (activeEffectScope !== void 0) activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
1648
+ else if (!failSilently) warn("onScopeDispose() is called when there is no active effect scope to be associated with.");
1649
+ }
1650
+
1651
+ //#endregion
1652
+ //#region packages/reactivity/src/computed.ts
1653
+ /**
1654
+ * @private exported by @vue/reactivity for Vue core use, but not exported from
1655
+ * the main vue package
1656
+ */
1657
+ var ComputedRefImpl = class {
1658
+ get effect() {
1659
+ return this;
1660
+ }
1661
+ get dep() {
1662
+ return this;
1663
+ }
1664
+ /**
1665
+ * @internal
1666
+ * for backwards compat
1667
+ */
1668
+ get _dirty() {
1669
+ const flags = this.flags;
1670
+ if (flags & ReactiveFlags$1.Dirty) return true;
1671
+ if (flags & ReactiveFlags$1.Pending) if (checkDirty(this.deps, this)) {
1672
+ this.flags = flags | ReactiveFlags$1.Dirty;
1673
+ return true;
1674
+ } else this.flags = flags & -33;
1675
+ return false;
1676
+ }
1677
+ /**
1678
+ * @internal
1679
+ * for backwards compat
1680
+ */
1681
+ set _dirty(v) {
1682
+ if (v) this.flags |= ReactiveFlags$1.Dirty;
1683
+ else this.flags &= -49;
1684
+ }
1685
+ constructor(fn, setter) {
1686
+ this.fn = fn;
1687
+ this.setter = setter;
1688
+ this._value = void 0;
1689
+ this.subs = void 0;
1690
+ this.subsTail = void 0;
1691
+ this.deps = void 0;
1692
+ this.depsTail = void 0;
1693
+ this.flags = ReactiveFlags$1.Mutable | ReactiveFlags$1.Dirty;
1694
+ this.__v_isRef = true;
1695
+ this["__v_isReadonly"] = !setter;
1696
+ }
1697
+ get value() {
1698
+ const flags = this.flags;
1699
+ if (flags & ReactiveFlags$1.Dirty || flags & ReactiveFlags$1.Pending && checkDirty(this.deps, this)) {
1700
+ if (this.update()) {
1701
+ const subs = this.subs;
1702
+ if (subs !== void 0) shallowPropagate(subs);
1703
+ }
1704
+ } else if (flags & ReactiveFlags$1.Pending) this.flags = flags & -33;
1705
+ if (activeSub !== void 0) {
1706
+ onTrack(activeSub, {
1707
+ target: this,
1708
+ type: "get",
1709
+ key: "value"
1710
+ });
1711
+ link(this, activeSub);
1712
+ } else if (activeEffectScope !== void 0) link(this, activeEffectScope);
1713
+ return this._value;
1714
+ }
1715
+ set value(newValue) {
1716
+ if (this.setter) this.setter(newValue);
1717
+ else warn("Write operation failed: computed value is readonly");
1718
+ }
1719
+ update() {
1720
+ const prevSub = startTracking(this);
1721
+ try {
1722
+ const oldValue = this._value;
1723
+ const newValue = this.fn(oldValue);
1724
+ if (hasChanged(oldValue, newValue)) {
1725
+ this._value = newValue;
1726
+ return true;
1727
+ }
1728
+ return false;
1729
+ } finally {
1730
+ endTracking(this, prevSub);
1731
+ }
1732
+ }
1733
+ };
1734
+ setupOnTrigger(ComputedRefImpl);
1735
+ /* @__NO_SIDE_EFFECTS__ */
1756
1736
  function computed(getterOrOptions, debugOptions, isSSR = false) {
1757
- let getter;
1758
- let setter;
1759
- if (isFunction$1(getterOrOptions)) {
1760
- getter = getterOrOptions;
1761
- } else {
1762
- getter = getterOrOptions.get;
1763
- setter = getterOrOptions.set;
1764
- }
1765
- const cRef = new ComputedRefImpl(getter, setter, isSSR);
1766
- if (debugOptions && !isSSR) {
1767
- cRef.onTrack = debugOptions.onTrack;
1768
- cRef.onTrigger = debugOptions.onTrigger;
1769
- }
1770
- return cRef;
1737
+ let getter;
1738
+ let setter;
1739
+ if (isFunction$1(getterOrOptions)) getter = getterOrOptions;
1740
+ else {
1741
+ getter = getterOrOptions.get;
1742
+ setter = getterOrOptions.set;
1743
+ }
1744
+ const cRef = new ComputedRefImpl(getter, setter);
1745
+ if (debugOptions && !isSSR) {
1746
+ cRef.onTrack = debugOptions.onTrack;
1747
+ cRef.onTrigger = debugOptions.onTrigger;
1748
+ }
1749
+ return cRef;
1771
1750
  }
1772
1751
 
1752
+ //#endregion
1753
+ //#region packages/reactivity/src/constants.ts
1773
1754
  const TrackOpTypes = {
1774
- "GET": "get",
1775
- "HAS": "has",
1776
- "ITERATE": "iterate"
1755
+ "GET": "get",
1756
+ "HAS": "has",
1757
+ "ITERATE": "iterate"
1777
1758
  };
1778
1759
  const TriggerOpTypes = {
1779
- "SET": "set",
1780
- "ADD": "add",
1781
- "DELETE": "delete",
1782
- "CLEAR": "clear"
1760
+ "SET": "set",
1761
+ "ADD": "add",
1762
+ "DELETE": "delete",
1763
+ "CLEAR": "clear"
1783
1764
  };
1784
1765
  const INITIAL_WATCHER_VALUE = {};
1785
- const cleanupMap = /* @__PURE__ */ new WeakMap();
1786
1766
  let activeWatcher = void 0;
1767
+ /**
1768
+ * Returns the current active effect if there is one.
1769
+ */
1787
1770
  function getCurrentWatcher() {
1788
- return activeWatcher;
1771
+ return activeWatcher;
1789
1772
  }
1773
+ /**
1774
+ * Registers a cleanup callback on the current active effect. This
1775
+ * registered cleanup callback will be invoked right before the
1776
+ * associated effect re-runs.
1777
+ *
1778
+ * @param cleanupFn - The callback function to attach to the effect's cleanup.
1779
+ * @param failSilently - if `true`, will not throw warning when called without
1780
+ * an active effect.
1781
+ * @param owner - The effect that this cleanup function should be attached to.
1782
+ * By default, the current active effect.
1783
+ */
1790
1784
  function onWatcherCleanup(cleanupFn, failSilently = false, owner = activeWatcher) {
1791
- if (owner) {
1792
- let cleanups = cleanupMap.get(owner);
1793
- if (!cleanups) cleanupMap.set(owner, cleanups = []);
1794
- cleanups.push(cleanupFn);
1795
- } else if (!failSilently) {
1796
- warn(
1797
- `onWatcherCleanup() was called when there was no active watcher to associate with.`
1798
- );
1799
- }
1800
- }
1801
- function watch$1(source, cb, options = EMPTY_OBJ$1) {
1802
- const { immediate, deep, once, scheduler, augmentJob, call } = options;
1803
- const warnInvalidSource = (s) => {
1804
- (options.onWarn || warn)(
1805
- `Invalid watch source: `,
1806
- s,
1807
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
1808
- );
1809
- };
1810
- const reactiveGetter = (source2) => {
1811
- if (deep) return source2;
1812
- if (isShallow(source2) || deep === false || deep === 0)
1813
- return traverse(source2, 1);
1814
- return traverse(source2);
1815
- };
1816
- let effect;
1817
- let getter;
1818
- let cleanup;
1819
- let boundCleanup;
1820
- let forceTrigger = false;
1821
- let isMultiSource = false;
1822
- if (isRef(source)) {
1823
- getter = () => source.value;
1824
- forceTrigger = isShallow(source);
1825
- } else if (isReactive(source)) {
1826
- getter = () => reactiveGetter(source);
1827
- forceTrigger = true;
1828
- } else if (isArray$1(source)) {
1829
- isMultiSource = true;
1830
- forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
1831
- getter = () => source.map((s) => {
1832
- if (isRef(s)) {
1833
- return s.value;
1834
- } else if (isReactive(s)) {
1835
- return reactiveGetter(s);
1836
- } else if (isFunction$1(s)) {
1837
- return call ? call(s, 2) : s();
1838
- } else {
1839
- warnInvalidSource(s);
1840
- }
1841
- });
1842
- } else if (isFunction$1(source)) {
1843
- if (cb) {
1844
- getter = call ? () => call(source, 2) : source;
1845
- } else {
1846
- getter = () => {
1847
- if (cleanup) {
1848
- pauseTracking();
1849
- try {
1850
- cleanup();
1851
- } finally {
1852
- resetTracking();
1853
- }
1854
- }
1855
- const currentEffect = activeWatcher;
1856
- activeWatcher = effect;
1857
- try {
1858
- return call ? call(source, 3, [boundCleanup]) : source(boundCleanup);
1859
- } finally {
1860
- activeWatcher = currentEffect;
1861
- }
1862
- };
1863
- }
1864
- } else {
1865
- getter = NOOP;
1866
- warnInvalidSource(source);
1867
- }
1868
- if (cb && deep) {
1869
- const baseGetter = getter;
1870
- const depth = deep === true ? Infinity : deep;
1871
- getter = () => traverse(baseGetter(), depth);
1872
- }
1873
- const scope = getCurrentScope();
1874
- const watchHandle = () => {
1875
- effect.stop();
1876
- if (scope && scope.active) {
1877
- remove(scope.effects, effect);
1878
- }
1879
- };
1880
- if (once && cb) {
1881
- const _cb = cb;
1882
- cb = (...args) => {
1883
- _cb(...args);
1884
- watchHandle();
1885
- };
1886
- }
1887
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1888
- const job = (immediateFirstRun) => {
1889
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1890
- return;
1891
- }
1892
- if (cb) {
1893
- const newValue = effect.run();
1894
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1895
- if (cleanup) {
1896
- cleanup();
1897
- }
1898
- const currentWatcher = activeWatcher;
1899
- activeWatcher = effect;
1900
- try {
1901
- const args = [
1902
- newValue,
1903
- // pass undefined as the old value when it's changed for the first time
1904
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1905
- boundCleanup
1906
- ];
1907
- oldValue = newValue;
1908
- call ? call(cb, 3, args) : (
1909
- // @ts-expect-error
1910
- cb(...args)
1911
- );
1912
- } finally {
1913
- activeWatcher = currentWatcher;
1914
- }
1915
- }
1916
- } else {
1917
- effect.run();
1918
- }
1919
- };
1920
- if (augmentJob) {
1921
- augmentJob(job);
1922
- }
1923
- effect = new ReactiveEffect(getter);
1924
- effect.scheduler = scheduler ? () => scheduler(job, false) : job;
1925
- boundCleanup = (fn) => onWatcherCleanup(fn, false, effect);
1926
- cleanup = effect.onStop = () => {
1927
- const cleanups = cleanupMap.get(effect);
1928
- if (cleanups) {
1929
- if (call) {
1930
- call(cleanups, 4);
1931
- } else {
1932
- for (const cleanup2 of cleanups) cleanup2();
1933
- }
1934
- cleanupMap.delete(effect);
1935
- }
1936
- };
1937
- {
1938
- effect.onTrack = options.onTrack;
1939
- effect.onTrigger = options.onTrigger;
1940
- }
1941
- if (cb) {
1942
- if (immediate) {
1943
- job(true);
1944
- } else {
1945
- oldValue = effect.run();
1946
- }
1947
- } else if (scheduler) {
1948
- scheduler(job.bind(null, true), true);
1949
- } else {
1950
- effect.run();
1951
- }
1952
- watchHandle.pause = effect.pause.bind(effect);
1953
- watchHandle.resume = effect.resume.bind(effect);
1954
- watchHandle.stop = watchHandle;
1955
- return watchHandle;
1956
- }
1957
- function traverse(value, depth = Infinity, seen) {
1958
- if (depth <= 0 || !isObject$1(value) || value["__v_skip"]) {
1959
- return value;
1960
- }
1961
- seen = seen || /* @__PURE__ */ new Map();
1962
- if ((seen.get(value) || 0) >= depth) {
1963
- return value;
1964
- }
1965
- seen.set(value, depth);
1966
- depth--;
1967
- if (isRef(value)) {
1968
- traverse(value.value, depth, seen);
1969
- } else if (isArray$1(value)) {
1970
- for (let i = 0; i < value.length; i++) {
1971
- traverse(value[i], depth, seen);
1972
- }
1973
- } else if (isSet(value) || isMap(value)) {
1974
- value.forEach((v) => {
1975
- traverse(v, depth, seen);
1976
- });
1977
- } else if (isPlainObject$1(value)) {
1978
- for (const key in value) {
1979
- traverse(value[key], depth, seen);
1980
- }
1981
- for (const key of Object.getOwnPropertySymbols(value)) {
1982
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
1983
- traverse(value[key], depth, seen);
1984
- }
1985
- }
1986
- }
1987
- return value;
1988
- }
1989
-
1990
- const EMPTY_OBJ = Object.freeze({}) ;
1991
- const isArray = Array.isArray;
1992
- const extend = Object.assign;
1993
- function exclude(obj, keys) {
1994
- const ret = {};
1995
- Object.keys(obj).forEach((key) => {
1996
- if (!keys.includes(key)) {
1997
- ret[key] = obj[key];
1998
- }
1999
- });
2000
- return ret;
2001
- }
2002
- function getType(x) {
2003
- return Object.prototype.toString.call(x).slice(8, -1);
2004
- }
2005
- function isSimpleValue(x) {
2006
- const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
2007
- return x === null || simpleTypes.has(typeof x);
2008
- }
2009
- function isObject(x) {
2010
- return x !== null && typeof x === 'object';
2011
- }
2012
- function isPlainObject(x) {
2013
- return getType(x) === 'Object';
1785
+ if (owner) {
1786
+ const { call } = owner.options;
1787
+ if (call) owner.cleanups[owner.cleanupsLength++] = () => call(cleanupFn, 4);
1788
+ else owner.cleanups[owner.cleanupsLength++] = cleanupFn;
1789
+ } else if (!failSilently) warn("onWatcherCleanup() was called when there was no active watcher to associate with.");
1790
+ }
1791
+ var WatcherEffect = class extends ReactiveEffect {
1792
+ constructor(source, cb, options = EMPTY_OBJ$1) {
1793
+ const { deep, once, call, onWarn } = options;
1794
+ let getter;
1795
+ let forceTrigger = false;
1796
+ let isMultiSource = false;
1797
+ if (/* @__PURE__ */ isRef(source)) {
1798
+ getter = () => source.value;
1799
+ forceTrigger = /* @__PURE__ */ isShallow(source);
1800
+ } else if (/* @__PURE__ */ isReactive(source)) {
1801
+ getter = () => reactiveGetter(source, deep);
1802
+ forceTrigger = true;
1803
+ } else if (isArray$1(source)) {
1804
+ isMultiSource = true;
1805
+ forceTrigger = source.some((s) => /* @__PURE__ */ isReactive(s) || /* @__PURE__ */ isShallow(s));
1806
+ getter = () => source.map((s) => {
1807
+ if (/* @__PURE__ */ isRef(s)) return s.value;
1808
+ else if (/* @__PURE__ */ isReactive(s)) return reactiveGetter(s, deep);
1809
+ else if (isFunction$1(s)) return call ? call(s, 2) : s();
1810
+ else warnInvalidSource(s, onWarn);
1811
+ });
1812
+ } else if (isFunction$1(source)) if (cb) getter = call ? () => call(source, 2) : source;
1813
+ else getter = () => {
1814
+ if (this.cleanupsLength) {
1815
+ const prevSub = setActiveSub();
1816
+ try {
1817
+ cleanup(this);
1818
+ } finally {
1819
+ setActiveSub(prevSub);
1820
+ }
1821
+ }
1822
+ const currentEffect = activeWatcher;
1823
+ activeWatcher = this;
1824
+ try {
1825
+ return call ? call(source, 3, [this.boundCleanup]) : source(this.boundCleanup);
1826
+ } finally {
1827
+ activeWatcher = currentEffect;
1828
+ }
1829
+ };
1830
+ else {
1831
+ getter = NOOP;
1832
+ warnInvalidSource(source, onWarn);
1833
+ }
1834
+ if (cb && deep) {
1835
+ const baseGetter = getter;
1836
+ const depth = deep === true ? Infinity : deep;
1837
+ getter = () => traverse(baseGetter(), depth);
1838
+ }
1839
+ super(getter);
1840
+ this.cb = cb;
1841
+ this.options = options;
1842
+ this.boundCleanup = (fn) => onWatcherCleanup(fn, false, this);
1843
+ this.forceTrigger = forceTrigger;
1844
+ this.isMultiSource = isMultiSource;
1845
+ if (once && cb) {
1846
+ const _cb = cb;
1847
+ cb = (...args) => {
1848
+ _cb(...args);
1849
+ this.stop();
1850
+ };
1851
+ }
1852
+ this.cb = cb;
1853
+ this.oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1854
+ {
1855
+ this.onTrack = options.onTrack;
1856
+ this.onTrigger = options.onTrigger;
1857
+ }
1858
+ }
1859
+ run(initialRun = false) {
1860
+ const oldValue = this.oldValue;
1861
+ const newValue = this.oldValue = super.run();
1862
+ if (!this.cb) return;
1863
+ const { immediate, deep, call } = this.options;
1864
+ if (initialRun && !immediate) return;
1865
+ if (deep || this.forceTrigger || (this.isMultiSource ? newValue.some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue))) {
1866
+ cleanup(this);
1867
+ const currentWatcher = activeWatcher;
1868
+ activeWatcher = this;
1869
+ try {
1870
+ const args = [
1871
+ newValue,
1872
+ oldValue === INITIAL_WATCHER_VALUE ? void 0 : this.isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
1873
+ this.boundCleanup
1874
+ ];
1875
+ call ? call(this.cb, 3, args) : this.cb(...args);
1876
+ } finally {
1877
+ activeWatcher = currentWatcher;
1878
+ }
1879
+ }
1880
+ }
1881
+ };
1882
+ function reactiveGetter(source, deep) {
1883
+ if (deep) return source;
1884
+ if (/* @__PURE__ */ isShallow(source) || deep === false || deep === 0) return traverse(source, 1);
1885
+ return traverse(source);
2014
1886
  }
2015
- function isFunction(x) {
2016
- return typeof x === 'function';
1887
+ function warnInvalidSource(s, onWarn) {
1888
+ (onWarn || warn)(`Invalid watch source: `, s, "A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.");
2017
1889
  }
2018
- function toHiddenField(name) {
2019
- return `__${name}__`;
1890
+ function traverse(value, depth = Infinity, seen) {
1891
+ if (depth <= 0 || !isObject$1(value) || value["__v_skip"]) return value;
1892
+ seen = seen || /* @__PURE__ */ new Map();
1893
+ if ((seen.get(value) || 0) >= depth) return value;
1894
+ seen.set(value, depth);
1895
+ depth--;
1896
+ if (/* @__PURE__ */ isRef(value)) traverse(value.value, depth, seen);
1897
+ else if (isArray$1(value)) for (let i = 0; i < value.length; i++) traverse(value[i], depth, seen);
1898
+ else if (isSet(value) || isMap(value)) value.forEach((v) => {
1899
+ traverse(v, depth, seen);
1900
+ });
1901
+ else if (isPlainObject$1(value)) {
1902
+ for (const key in value) traverse(value[key], depth, seen);
1903
+ for (const key of Object.getOwnPropertySymbols(value)) if (Object.prototype.propertyIsEnumerable.call(value, key)) traverse(value[key], depth, seen);
1904
+ }
1905
+ return value;
2020
1906
  }
2021
1907
 
2022
1908
  var SchedulerJobFlags;
2023
1909
  (function (SchedulerJobFlags) {
2024
1910
  SchedulerJobFlags[SchedulerJobFlags["QUEUED"] = 1] = "QUEUED";
2025
- SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 4] = "ALLOW_RECURSE";
1911
+ SchedulerJobFlags[SchedulerJobFlags["ALLOW_RECURSE"] = 2] = "ALLOW_RECURSE";
2026
1912
  })(SchedulerJobFlags || (SchedulerJobFlags = {}));
2027
- const queue = [];
2028
- let flushIndex = -1;
2029
- const pendingPostFlushCbs = [];
2030
- let activePostFlushCbs = null;
1913
+ const jobs = [];
1914
+ let postJobs = [];
1915
+ let activePostJobs = null;
1916
+ let currentFlushPromise = null;
1917
+ let jobsLength = 0;
1918
+ let flushIndex = 0;
2031
1919
  let postFlushIndex = 0;
2032
1920
  const resolvedPromise = /*@__PURE__*/ Promise.resolve();
2033
- let currentFlushPromise = null;
2034
1921
  const RECURSION_LIMIT = 100;
2035
1922
  function nextTick(fn) {
2036
1923
  const p = currentFlushPromise || resolvedPromise;
2037
1924
  return fn ? p.then(fn) : p;
2038
1925
  }
2039
1926
  function queueJob(job) {
2040
- if (!(job.flags & SchedulerJobFlags.QUEUED)) {
2041
- queue.push(job);
2042
- job.flags |= SchedulerJobFlags.QUEUED;
1927
+ if (queueJobWorker(job, jobs, jobsLength)) {
1928
+ jobsLength++;
2043
1929
  queueFlush();
2044
1930
  }
2045
1931
  }
1932
+ function queueJobWorker(job, queue, length) {
1933
+ const flags = job.flags;
1934
+ if (!(flags & SchedulerJobFlags.QUEUED)) {
1935
+ job.flags = flags | SchedulerJobFlags.QUEUED;
1936
+ queue[length] = job;
1937
+ return true;
1938
+ }
1939
+ return false;
1940
+ }
2046
1941
  function queueFlush() {
2047
1942
  if (!currentFlushPromise) {
1943
+ // We don't flush post jobs on flushJobs's finally block, so we don't need `doFlushJobs` here.
2048
1944
  currentFlushPromise = resolvedPromise.then(flushJobs);
2049
1945
  }
2050
1946
  }
2051
- function queuePostFlushCb(cb) {
2052
- if (!(cb.flags & SchedulerJobFlags.QUEUED)) {
2053
- pendingPostFlushCbs.push(cb);
2054
- cb.flags |= SchedulerJobFlags.QUEUED;
2055
- }
1947
+ function queuePostFlushCb(job) {
1948
+ queueJobWorker(job, postJobs, postJobs.length);
2056
1949
  }
2057
1950
  function flushPostFlushCbs() {
2058
- if (pendingPostFlushCbs.length > 0) {
2059
- activePostFlushCbs = [...new Set(pendingPostFlushCbs)];
2060
- pendingPostFlushCbs.length = 0;
2061
- for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
2062
- const cb = activePostFlushCbs[postFlushIndex];
1951
+ if (postJobs.length) {
1952
+ activePostJobs = postJobs;
1953
+ postJobs = [];
1954
+ while (postFlushIndex < activePostJobs.length) {
1955
+ const cb = activePostJobs[postFlushIndex++];
2063
1956
  if (cb.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2064
1957
  cb.flags &= ~SchedulerJobFlags.QUEUED;
2065
1958
  }
2066
- cb();
2067
- cb.flags &= ~SchedulerJobFlags.QUEUED;
1959
+ try {
1960
+ cb();
1961
+ }
1962
+ finally {
1963
+ cb.flags &= ~SchedulerJobFlags.QUEUED;
1964
+ }
2068
1965
  }
2069
- activePostFlushCbs = null;
1966
+ activePostJobs = null;
2070
1967
  postFlushIndex = 0;
2071
1968
  }
2072
1969
  }
2073
1970
  function flushJobs() {
2074
1971
  const seen = new Map() ;
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)
2080
- const check = (job) => checkRecursiveUpdates(seen, job)
2081
- ;
2082
1972
  try {
2083
- for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
2084
- const job = queue[flushIndex];
1973
+ while (flushIndex < jobsLength) {
1974
+ const job = jobs[flushIndex];
1975
+ jobs[flushIndex++] = undefined;
1976
+ // Conditional usage of checkRecursiveUpdate must be determined out of
1977
+ // try ... catch block since Rollup by default de-optimizes treeshaking
1978
+ // inside try-catch. This can leave all warning code unshaked. Although
1979
+ // they would get eventually shaken by a minifier like terser, some minifiers
1980
+ // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
2085
1981
  /* istanbul ignore if -- @preserve */
2086
- if (true && check(job)) {
1982
+ if (true && checkRecursiveUpdates(seen, job)) {
2087
1983
  continue;
2088
1984
  }
2089
1985
  if (job.flags & SchedulerJobFlags.ALLOW_RECURSE) {
2090
1986
  job.flags &= ~SchedulerJobFlags.QUEUED;
2091
1987
  }
2092
- job();
2093
- if (!(job.flags & SchedulerJobFlags.ALLOW_RECURSE)) {
2094
- job.flags &= ~SchedulerJobFlags.QUEUED;
1988
+ try {
1989
+ job();
1990
+ }
1991
+ finally {
1992
+ if (!(job.flags & SchedulerJobFlags.ALLOW_RECURSE)) {
1993
+ job.flags &= ~SchedulerJobFlags.QUEUED;
1994
+ }
2095
1995
  }
2096
1996
  }
2097
1997
  }
2098
1998
  finally {
2099
1999
  // If there was an error we still need to clear the QUEUED flags
2100
- for (; flushIndex < queue.length; flushIndex++) {
2101
- const job = queue[flushIndex];
2102
- job.flags &= ~SchedulerJobFlags.QUEUED;
2000
+ while (flushIndex < jobsLength) {
2001
+ jobs[flushIndex].flags &= ~SchedulerJobFlags.QUEUED;
2002
+ jobs[flushIndex++] = undefined;
2103
2003
  }
2104
- flushIndex = -1;
2105
- queue.length = 0;
2004
+ flushIndex = 0;
2005
+ jobsLength = 0;
2106
2006
  currentFlushPromise = null;
2107
2007
  }
2108
2008
  }
@@ -2119,6 +2019,38 @@ function checkRecursiveUpdates(seen, fn) {
2119
2019
  return false;
2120
2020
  }
2121
2021
 
2022
+ const EMPTY_OBJ = Object.freeze({}) ;
2023
+ const isArray = Array.isArray;
2024
+ const extend = Object.assign;
2025
+ function exclude(obj, keys) {
2026
+ const ret = {};
2027
+ Object.keys(obj).forEach((key) => {
2028
+ if (!keys.includes(key)) {
2029
+ ret[key] = obj[key];
2030
+ }
2031
+ });
2032
+ return ret;
2033
+ }
2034
+ function getType(x) {
2035
+ return Object.prototype.toString.call(x).slice(8, -1);
2036
+ }
2037
+ function isSimpleValue(x) {
2038
+ const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
2039
+ return x === null || simpleTypes.has(typeof x);
2040
+ }
2041
+ function isObject(x) {
2042
+ return x !== null && typeof x === 'object';
2043
+ }
2044
+ function isPlainObject(x) {
2045
+ return getType(x) === 'Object';
2046
+ }
2047
+ function isFunction(x) {
2048
+ return typeof x === 'function';
2049
+ }
2050
+ function toHiddenField(name) {
2051
+ return `__${name}__`;
2052
+ }
2053
+
2122
2054
  // Simple effect.
2123
2055
  function watchEffect(effect, options) {
2124
2056
  return doWatch(effect, null, options);
@@ -2140,8 +2072,42 @@ function watch(source, cb, options) {
2140
2072
  }
2141
2073
  return doWatch(source, cb, options);
2142
2074
  }
2075
+ class RenderWatcherEffect extends WatcherEffect {
2076
+ constructor(source, cb, options, flush) {
2077
+ super(source, cb, options);
2078
+ this.flush = flush;
2079
+ const job = () => {
2080
+ if (this.dirty) {
2081
+ this.run();
2082
+ }
2083
+ };
2084
+ // Important: mark the job as a watcher callback so that scheduler knows
2085
+ // it is allowed to self-trigger (#1727)
2086
+ if (cb) {
2087
+ this.flags |= EffectFlags.ALLOW_RECURSE;
2088
+ job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
2089
+ }
2090
+ this.job = job;
2091
+ }
2092
+ notify() {
2093
+ const flags = this.flags;
2094
+ if (!(flags & EffectFlags.PAUSED)) {
2095
+ const flush = this.flush;
2096
+ const job = this.job;
2097
+ if (flush === 'post') {
2098
+ queuePostFlushCb(job);
2099
+ }
2100
+ else if (flush === 'pre') {
2101
+ queueJob(job);
2102
+ }
2103
+ else {
2104
+ job();
2105
+ }
2106
+ }
2107
+ }
2108
+ }
2143
2109
  function doWatch(source, cb, options = EMPTY_OBJ) {
2144
- const { immediate, deep, flush, once } = options;
2110
+ const { immediate, deep, flush = 'pre', once } = options;
2145
2111
  if (!cb) {
2146
2112
  if (immediate !== undefined) {
2147
2113
  console.warn(`watch() "immediate" option is only respected when using the ` +
@@ -2157,32 +2123,22 @@ function doWatch(source, cb, options = EMPTY_OBJ) {
2157
2123
  }
2158
2124
  }
2159
2125
  const baseWatchOptions = extend({}, options);
2160
- // Scheduler
2161
- if (flush === 'post') {
2162
- baseWatchOptions.scheduler = (job) => {
2163
- queuePostFlushCb(job);
2164
- };
2126
+ const effect = new RenderWatcherEffect(source, cb, baseWatchOptions, flush);
2127
+ // Initial run
2128
+ if (cb) {
2129
+ effect.run(true);
2165
2130
  }
2166
- else if (flush !== 'sync') {
2167
- baseWatchOptions.scheduler = (job, isFirstRun) => {
2168
- if (isFirstRun) {
2169
- job();
2170
- }
2171
- else {
2172
- queueJob(job);
2173
- }
2174
- };
2131
+ else if (flush === 'post') {
2132
+ queuePostFlushCb(effect.job);
2175
2133
  }
2176
- // @ts-expect-error
2177
- baseWatchOptions.augmentJob = (job) => {
2178
- // Important: mark the job as a watcher callback so that scheduler knows
2179
- // it is allowed to self-trigger
2180
- if (cb) {
2181
- job.flags |= SchedulerJobFlags.ALLOW_RECURSE;
2182
- }
2183
- };
2184
- const watchHandle = watch$1(source, cb, baseWatchOptions);
2185
- return watchHandle;
2134
+ else {
2135
+ effect.run(true);
2136
+ }
2137
+ const stop = effect.stop.bind(effect);
2138
+ stop.pause = effect.pause.bind(effect);
2139
+ stop.resume = effect.resume.bind(effect);
2140
+ stop.stop = stop;
2141
+ return stop;
2186
2142
  }
2187
2143
 
2188
2144
  const provides = Object.create(null);
@@ -2219,28 +2175,18 @@ function unsetCurrentApp() {
2219
2175
  }
2220
2176
  function setCurrentPage(page) {
2221
2177
  currentPage = page;
2222
- // @ts-expect-error
2223
- page.__scope__.on();
2178
+ return setCurrentScope(page.__scope__);
2224
2179
  }
2225
- function unsetCurrentPage() {
2226
- /* istanbul ignore else -- @preserve */
2227
- if (currentPage) {
2228
- // @ts-expect-error
2229
- currentPage.__scope__.off();
2230
- }
2180
+ function unsetCurrentPage(scope) {
2181
+ setCurrentScope(scope);
2231
2182
  currentPage = null;
2232
2183
  }
2233
2184
  function setCurrentComponent(component) {
2234
2185
  currentComponent = component;
2235
- // @ts-expect-error
2236
- component.__scope__.on();
2186
+ return setCurrentScope(component.__scope__);
2237
2187
  }
2238
- function unsetCurrentComponent() {
2239
- /* istanbul ignore else -- @preserve */
2240
- if (currentComponent) {
2241
- // @ts-expect-error
2242
- currentComponent.__scope__.off();
2243
- }
2188
+ function unsetCurrentComponent(scope) {
2189
+ setCurrentScope(scope);
2244
2190
  currentComponent = null;
2245
2191
  }
2246
2192
 
@@ -2378,7 +2324,7 @@ function definePage(optionsOrSetup, config) {
2378
2324
  const originOnLoad = options[PageLifecycle.ON_LOAD];
2379
2325
  options[PageLifecycle.ON_LOAD] = function (query) {
2380
2326
  this.__scope__ = new EffectScope();
2381
- setCurrentPage(this);
2327
+ const scope = setCurrentPage(this);
2382
2328
  const context = {
2383
2329
  is: this.is,
2384
2330
  route: this.route,
@@ -2422,7 +2368,7 @@ function definePage(optionsOrSetup, config) {
2422
2368
  this.setData(data, flushPostFlushCbs);
2423
2369
  }
2424
2370
  }
2425
- unsetCurrentPage();
2371
+ unsetCurrentPage(scope);
2426
2372
  if (originOnLoad !== undefined) {
2427
2373
  originOnLoad.call(this, query);
2428
2374
  }
@@ -2551,7 +2497,7 @@ function defineComponent(optionsOrSetup, config) {
2551
2497
  options[ComponentLifecycle.ATTACHED];
2552
2498
  options.lifetimes[ComponentLifecycle.ATTACHED] = function () {
2553
2499
  this.__scope__ = new EffectScope();
2554
- setCurrentComponent(this);
2500
+ const scope = setCurrentComponent(this);
2555
2501
  const rawProps = {};
2556
2502
  if (properties) {
2557
2503
  properties.forEach((property) => {
@@ -2606,7 +2552,7 @@ function defineComponent(optionsOrSetup, config) {
2606
2552
  this.setData(data, flushPostFlushCbs);
2607
2553
  }
2608
2554
  }
2609
- unsetCurrentComponent();
2555
+ unsetCurrentComponent(scope);
2610
2556
  if (originAttached !== undefined) {
2611
2557
  originAttached.call(this);
2612
2558
  }