@vue/reactivity 3.6.0-beta.4 → 3.6.0-beta.6

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