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

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