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

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