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

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