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