@vue/reactivity 3.6.0-beta.1 → 3.6.0-beta.11

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