@vue/reactivity 3.2.47 → 3.3.0-alpha.2

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.
@@ -5,1266 +5,1211 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var shared = require('@vue/shared');
6
6
 
7
7
  function warn(msg, ...args) {
8
- console.warn(`[Vue warn] ${msg}`, ...args);
8
+ console.warn(`[Vue warn] ${msg}`, ...args);
9
9
  }
10
10
 
11
11
  let activeEffectScope;
12
12
  class EffectScope {
13
- constructor(detached = false) {
14
- this.detached = detached;
15
- /**
16
- * @internal
17
- */
18
- this._active = true;
19
- /**
20
- * @internal
21
- */
22
- this.effects = [];
23
- /**
24
- * @internal
25
- */
26
- this.cleanups = [];
27
- this.parent = activeEffectScope;
28
- if (!detached && activeEffectScope) {
29
- this.index =
30
- (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
31
- }
32
- }
33
- get active() {
34
- return this._active;
35
- }
36
- run(fn) {
37
- if (this._active) {
38
- const currentEffectScope = activeEffectScope;
39
- try {
40
- activeEffectScope = this;
41
- return fn();
42
- }
43
- finally {
44
- activeEffectScope = currentEffectScope;
45
- }
46
- }
47
- else {
48
- warn(`cannot run an inactive effect scope.`);
49
- }
50
- }
13
+ constructor(detached = false) {
14
+ this.detached = detached;
51
15
  /**
52
- * This should only be called on non-detached scopes
53
16
  * @internal
54
17
  */
55
- on() {
56
- activeEffectScope = this;
57
- }
18
+ this._active = true;
58
19
  /**
59
- * This should only be called on non-detached scopes
60
20
  * @internal
61
21
  */
62
- off() {
63
- activeEffectScope = this.parent;
64
- }
65
- stop(fromParent) {
66
- if (this._active) {
67
- let i, l;
68
- for (i = 0, l = this.effects.length; i < l; i++) {
69
- this.effects[i].stop();
70
- }
71
- for (i = 0, l = this.cleanups.length; i < l; i++) {
72
- this.cleanups[i]();
73
- }
74
- if (this.scopes) {
75
- for (i = 0, l = this.scopes.length; i < l; i++) {
76
- this.scopes[i].stop(true);
77
- }
78
- }
79
- // nested scope, dereference from parent to avoid memory leaks
80
- if (!this.detached && this.parent && !fromParent) {
81
- // optimized O(1) removal
82
- const last = this.parent.scopes.pop();
83
- if (last && last !== this) {
84
- this.parent.scopes[this.index] = last;
85
- last.index = this.index;
86
- }
87
- }
88
- this.parent = undefined;
89
- this._active = false;
22
+ this.effects = [];
23
+ /**
24
+ * @internal
25
+ */
26
+ this.cleanups = [];
27
+ this.parent = activeEffectScope;
28
+ if (!detached && activeEffectScope) {
29
+ this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
30
+ this
31
+ ) - 1;
32
+ }
33
+ }
34
+ get active() {
35
+ return this._active;
36
+ }
37
+ run(fn) {
38
+ if (this._active) {
39
+ const currentEffectScope = activeEffectScope;
40
+ try {
41
+ activeEffectScope = this;
42
+ return fn();
43
+ } finally {
44
+ activeEffectScope = currentEffectScope;
45
+ }
46
+ } else {
47
+ warn(`cannot run an inactive effect scope.`);
48
+ }
49
+ }
50
+ /**
51
+ * This should only be called on non-detached scopes
52
+ * @internal
53
+ */
54
+ on() {
55
+ activeEffectScope = this;
56
+ }
57
+ /**
58
+ * This should only be called on non-detached scopes
59
+ * @internal
60
+ */
61
+ off() {
62
+ activeEffectScope = this.parent;
63
+ }
64
+ stop(fromParent) {
65
+ if (this._active) {
66
+ let i, l;
67
+ for (i = 0, l = this.effects.length; i < l; i++) {
68
+ this.effects[i].stop();
69
+ }
70
+ for (i = 0, l = this.cleanups.length; i < l; i++) {
71
+ this.cleanups[i]();
72
+ }
73
+ if (this.scopes) {
74
+ for (i = 0, l = this.scopes.length; i < l; i++) {
75
+ this.scopes[i].stop(true);
90
76
  }
77
+ }
78
+ if (!this.detached && this.parent && !fromParent) {
79
+ const last = this.parent.scopes.pop();
80
+ if (last && last !== this) {
81
+ this.parent.scopes[this.index] = last;
82
+ last.index = this.index;
83
+ }
84
+ }
85
+ this.parent = void 0;
86
+ this._active = false;
91
87
  }
88
+ }
92
89
  }
93
90
  function effectScope(detached) {
94
- return new EffectScope(detached);
91
+ return new EffectScope(detached);
95
92
  }
96
93
  function recordEffectScope(effect, scope = activeEffectScope) {
97
- if (scope && scope.active) {
98
- scope.effects.push(effect);
99
- }
94
+ if (scope && scope.active) {
95
+ scope.effects.push(effect);
96
+ }
100
97
  }
101
98
  function getCurrentScope() {
102
- return activeEffectScope;
99
+ return activeEffectScope;
103
100
  }
104
101
  function onScopeDispose(fn) {
105
- if (activeEffectScope) {
106
- activeEffectScope.cleanups.push(fn);
107
- }
108
- else {
109
- warn(`onScopeDispose() is called when there is no active effect scope` +
110
- ` to be associated with.`);
111
- }
102
+ if (activeEffectScope) {
103
+ activeEffectScope.cleanups.push(fn);
104
+ } else {
105
+ warn(
106
+ `onScopeDispose() is called when there is no active effect scope to be associated with.`
107
+ );
108
+ }
112
109
  }
113
110
 
114
111
  const createDep = (effects) => {
115
- const dep = new Set(effects);
116
- dep.w = 0;
117
- dep.n = 0;
118
- return dep;
112
+ const dep = new Set(effects);
113
+ dep.w = 0;
114
+ dep.n = 0;
115
+ return dep;
119
116
  };
120
117
  const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
121
118
  const newTracked = (dep) => (dep.n & trackOpBit) > 0;
122
119
  const initDepMarkers = ({ deps }) => {
123
- if (deps.length) {
124
- for (let i = 0; i < deps.length; i++) {
125
- deps[i].w |= trackOpBit; // set was tracked
126
- }
120
+ if (deps.length) {
121
+ for (let i = 0; i < deps.length; i++) {
122
+ deps[i].w |= trackOpBit;
127
123
  }
124
+ }
128
125
  };
129
126
  const finalizeDepMarkers = (effect) => {
130
- const { deps } = effect;
131
- if (deps.length) {
132
- let ptr = 0;
133
- for (let i = 0; i < deps.length; i++) {
134
- const dep = deps[i];
135
- if (wasTracked(dep) && !newTracked(dep)) {
136
- dep.delete(effect);
137
- }
138
- else {
139
- deps[ptr++] = dep;
140
- }
141
- // clear bits
142
- dep.w &= ~trackOpBit;
143
- dep.n &= ~trackOpBit;
144
- }
145
- deps.length = ptr;
146
- }
127
+ const { deps } = effect;
128
+ if (deps.length) {
129
+ let ptr = 0;
130
+ for (let i = 0; i < deps.length; i++) {
131
+ const dep = deps[i];
132
+ if (wasTracked(dep) && !newTracked(dep)) {
133
+ dep.delete(effect);
134
+ } else {
135
+ deps[ptr++] = dep;
136
+ }
137
+ dep.w &= ~trackOpBit;
138
+ dep.n &= ~trackOpBit;
139
+ }
140
+ deps.length = ptr;
141
+ }
147
142
  };
148
143
 
149
- const targetMap = new WeakMap();
150
- // The number of effects currently being tracked recursively.
144
+ const targetMap = /* @__PURE__ */ new WeakMap();
151
145
  let effectTrackDepth = 0;
152
146
  let trackOpBit = 1;
153
- /**
154
- * The bitwise track markers support at most 30 levels of recursion.
155
- * This value is chosen to enable modern JS engines to use a SMI on all platforms.
156
- * When recursion depth is greater, fall back to using a full cleanup.
157
- */
158
147
  const maxMarkerBits = 30;
159
148
  let activeEffect;
160
- const ITERATE_KEY = Symbol('iterate' );
161
- const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
149
+ const ITERATE_KEY = Symbol("iterate" );
150
+ const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
162
151
  class ReactiveEffect {
163
- constructor(fn, scheduler = null, scope) {
164
- this.fn = fn;
165
- this.scheduler = scheduler;
166
- this.active = true;
167
- this.deps = [];
168
- this.parent = undefined;
169
- recordEffectScope(this, scope);
170
- }
171
- run() {
172
- if (!this.active) {
173
- return this.fn();
174
- }
175
- let parent = activeEffect;
176
- let lastShouldTrack = shouldTrack;
177
- while (parent) {
178
- if (parent === this) {
179
- return;
180
- }
181
- parent = parent.parent;
182
- }
183
- try {
184
- this.parent = activeEffect;
185
- activeEffect = this;
186
- shouldTrack = true;
187
- trackOpBit = 1 << ++effectTrackDepth;
188
- if (effectTrackDepth <= maxMarkerBits) {
189
- initDepMarkers(this);
190
- }
191
- else {
192
- cleanupEffect(this);
193
- }
194
- return this.fn();
195
- }
196
- finally {
197
- if (effectTrackDepth <= maxMarkerBits) {
198
- finalizeDepMarkers(this);
199
- }
200
- trackOpBit = 1 << --effectTrackDepth;
201
- activeEffect = this.parent;
202
- shouldTrack = lastShouldTrack;
203
- this.parent = undefined;
204
- if (this.deferStop) {
205
- this.stop();
206
- }
207
- }
208
- }
209
- stop() {
210
- // stopped while running itself - defer the cleanup
211
- if (activeEffect === this) {
212
- this.deferStop = true;
213
- }
214
- else if (this.active) {
215
- cleanupEffect(this);
216
- if (this.onStop) {
217
- this.onStop();
218
- }
219
- this.active = false;
220
- }
221
- }
222
- }
223
- function cleanupEffect(effect) {
224
- const { deps } = effect;
225
- if (deps.length) {
226
- for (let i = 0; i < deps.length; i++) {
227
- deps[i].delete(effect);
228
- }
229
- deps.length = 0;
230
- }
152
+ constructor(fn, scheduler = null, scope) {
153
+ this.fn = fn;
154
+ this.scheduler = scheduler;
155
+ this.active = true;
156
+ this.deps = [];
157
+ this.parent = void 0;
158
+ recordEffectScope(this, scope);
159
+ }
160
+ run() {
161
+ if (!this.active) {
162
+ return this.fn();
163
+ }
164
+ let parent = activeEffect;
165
+ let lastShouldTrack = shouldTrack;
166
+ while (parent) {
167
+ if (parent === this) {
168
+ return;
169
+ }
170
+ parent = parent.parent;
171
+ }
172
+ try {
173
+ this.parent = activeEffect;
174
+ activeEffect = this;
175
+ shouldTrack = true;
176
+ trackOpBit = 1 << ++effectTrackDepth;
177
+ if (effectTrackDepth <= maxMarkerBits) {
178
+ initDepMarkers(this);
179
+ } else {
180
+ cleanupEffect(this);
181
+ }
182
+ return this.fn();
183
+ } finally {
184
+ if (effectTrackDepth <= maxMarkerBits) {
185
+ finalizeDepMarkers(this);
186
+ }
187
+ trackOpBit = 1 << --effectTrackDepth;
188
+ activeEffect = this.parent;
189
+ shouldTrack = lastShouldTrack;
190
+ this.parent = void 0;
191
+ if (this.deferStop) {
192
+ this.stop();
193
+ }
194
+ }
195
+ }
196
+ stop() {
197
+ if (activeEffect === this) {
198
+ this.deferStop = true;
199
+ } else if (this.active) {
200
+ cleanupEffect(this);
201
+ if (this.onStop) {
202
+ this.onStop();
203
+ }
204
+ this.active = false;
205
+ }
206
+ }
207
+ }
208
+ function cleanupEffect(effect2) {
209
+ const { deps } = effect2;
210
+ if (deps.length) {
211
+ for (let i = 0; i < deps.length; i++) {
212
+ deps[i].delete(effect2);
213
+ }
214
+ deps.length = 0;
215
+ }
231
216
  }
232
217
  function effect(fn, options) {
233
- if (fn.effect) {
234
- fn = fn.effect.fn;
235
- }
236
- const _effect = new ReactiveEffect(fn);
237
- if (options) {
238
- shared.extend(_effect, options);
239
- if (options.scope)
240
- recordEffectScope(_effect, options.scope);
241
- }
242
- if (!options || !options.lazy) {
243
- _effect.run();
244
- }
245
- const runner = _effect.run.bind(_effect);
246
- runner.effect = _effect;
247
- return runner;
218
+ if (fn.effect) {
219
+ fn = fn.effect.fn;
220
+ }
221
+ const _effect = new ReactiveEffect(fn);
222
+ if (options) {
223
+ shared.extend(_effect, options);
224
+ if (options.scope)
225
+ recordEffectScope(_effect, options.scope);
226
+ }
227
+ if (!options || !options.lazy) {
228
+ _effect.run();
229
+ }
230
+ const runner = _effect.run.bind(_effect);
231
+ runner.effect = _effect;
232
+ return runner;
248
233
  }
249
234
  function stop(runner) {
250
- runner.effect.stop();
235
+ runner.effect.stop();
251
236
  }
252
237
  let shouldTrack = true;
253
238
  const trackStack = [];
254
239
  function pauseTracking() {
255
- trackStack.push(shouldTrack);
256
- shouldTrack = false;
240
+ trackStack.push(shouldTrack);
241
+ shouldTrack = false;
257
242
  }
258
243
  function enableTracking() {
259
- trackStack.push(shouldTrack);
260
- shouldTrack = true;
244
+ trackStack.push(shouldTrack);
245
+ shouldTrack = true;
261
246
  }
262
247
  function resetTracking() {
263
- const last = trackStack.pop();
264
- shouldTrack = last === undefined ? true : last;
248
+ const last = trackStack.pop();
249
+ shouldTrack = last === void 0 ? true : last;
265
250
  }
266
251
  function track(target, type, key) {
267
- if (shouldTrack && activeEffect) {
268
- let depsMap = targetMap.get(target);
269
- if (!depsMap) {
270
- targetMap.set(target, (depsMap = new Map()));
271
- }
272
- let dep = depsMap.get(key);
273
- if (!dep) {
274
- depsMap.set(key, (dep = createDep()));
275
- }
276
- const eventInfo = { effect: activeEffect, target, type, key }
277
- ;
278
- trackEffects(dep, eventInfo);
252
+ if (shouldTrack && activeEffect) {
253
+ let depsMap = targetMap.get(target);
254
+ if (!depsMap) {
255
+ targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
256
+ }
257
+ let dep = depsMap.get(key);
258
+ if (!dep) {
259
+ depsMap.set(key, dep = createDep());
279
260
  }
261
+ const eventInfo = { effect: activeEffect, target, type, key } ;
262
+ trackEffects(dep, eventInfo);
263
+ }
280
264
  }
281
265
  function trackEffects(dep, debuggerEventExtraInfo) {
282
- let shouldTrack = false;
283
- if (effectTrackDepth <= maxMarkerBits) {
284
- if (!newTracked(dep)) {
285
- dep.n |= trackOpBit; // set newly tracked
286
- shouldTrack = !wasTracked(dep);
287
- }
288
- }
289
- else {
290
- // Full cleanup mode.
291
- shouldTrack = !dep.has(activeEffect);
292
- }
293
- if (shouldTrack) {
294
- dep.add(activeEffect);
295
- activeEffect.deps.push(dep);
296
- if (activeEffect.onTrack) {
297
- activeEffect.onTrack({
298
- effect: activeEffect,
299
- ...debuggerEventExtraInfo
300
- });
301
- }
302
- }
266
+ let shouldTrack2 = false;
267
+ if (effectTrackDepth <= maxMarkerBits) {
268
+ if (!newTracked(dep)) {
269
+ dep.n |= trackOpBit;
270
+ shouldTrack2 = !wasTracked(dep);
271
+ }
272
+ } else {
273
+ shouldTrack2 = !dep.has(activeEffect);
274
+ }
275
+ if (shouldTrack2) {
276
+ dep.add(activeEffect);
277
+ activeEffect.deps.push(dep);
278
+ if (activeEffect.onTrack) {
279
+ activeEffect.onTrack(
280
+ shared.extend(
281
+ {
282
+ effect: activeEffect
283
+ },
284
+ debuggerEventExtraInfo
285
+ )
286
+ );
287
+ }
288
+ }
303
289
  }
304
290
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
305
- const depsMap = targetMap.get(target);
306
- if (!depsMap) {
307
- // never been tracked
308
- return;
309
- }
310
- let deps = [];
311
- if (type === "clear" /* TriggerOpTypes.CLEAR */) {
312
- // collection being cleared
313
- // trigger all effects for target
314
- deps = [...depsMap.values()];
315
- }
316
- else if (key === 'length' && shared.isArray(target)) {
317
- const newLength = Number(newValue);
318
- depsMap.forEach((dep, key) => {
319
- if (key === 'length' || key >= newLength) {
320
- deps.push(dep);
321
- }
322
- });
323
- }
324
- else {
325
- // schedule runs for SET | ADD | DELETE
326
- if (key !== void 0) {
327
- deps.push(depsMap.get(key));
291
+ const depsMap = targetMap.get(target);
292
+ if (!depsMap) {
293
+ return;
294
+ }
295
+ let deps = [];
296
+ if (type === "clear") {
297
+ deps = [...depsMap.values()];
298
+ } else if (key === "length" && shared.isArray(target)) {
299
+ const newLength = Number(newValue);
300
+ depsMap.forEach((dep, key2) => {
301
+ if (key2 === "length" || key2 >= newLength) {
302
+ deps.push(dep);
303
+ }
304
+ });
305
+ } else {
306
+ if (key !== void 0) {
307
+ deps.push(depsMap.get(key));
308
+ }
309
+ switch (type) {
310
+ case "add":
311
+ if (!shared.isArray(target)) {
312
+ deps.push(depsMap.get(ITERATE_KEY));
313
+ if (shared.isMap(target)) {
314
+ deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
315
+ }
316
+ } else if (shared.isIntegerKey(key)) {
317
+ deps.push(depsMap.get("length"));
328
318
  }
329
- // also run for iteration key on ADD | DELETE | Map.SET
330
- switch (type) {
331
- case "add" /* TriggerOpTypes.ADD */:
332
- if (!shared.isArray(target)) {
333
- deps.push(depsMap.get(ITERATE_KEY));
334
- if (shared.isMap(target)) {
335
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
336
- }
337
- }
338
- else if (shared.isIntegerKey(key)) {
339
- // new index added to array -> length changes
340
- deps.push(depsMap.get('length'));
341
- }
342
- break;
343
- case "delete" /* TriggerOpTypes.DELETE */:
344
- if (!shared.isArray(target)) {
345
- deps.push(depsMap.get(ITERATE_KEY));
346
- if (shared.isMap(target)) {
347
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
348
- }
349
- }
350
- break;
351
- case "set" /* TriggerOpTypes.SET */:
352
- if (shared.isMap(target)) {
353
- deps.push(depsMap.get(ITERATE_KEY));
354
- }
355
- break;
319
+ break;
320
+ case "delete":
321
+ if (!shared.isArray(target)) {
322
+ deps.push(depsMap.get(ITERATE_KEY));
323
+ if (shared.isMap(target)) {
324
+ deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
325
+ }
356
326
  }
357
- }
358
- const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
359
- ;
360
- if (deps.length === 1) {
361
- if (deps[0]) {
362
- {
363
- triggerEffects(deps[0], eventInfo);
364
- }
327
+ break;
328
+ case "set":
329
+ if (shared.isMap(target)) {
330
+ deps.push(depsMap.get(ITERATE_KEY));
365
331
  }
332
+ break;
366
333
  }
367
- else {
368
- const effects = [];
369
- for (const dep of deps) {
370
- if (dep) {
371
- effects.push(...dep);
372
- }
373
- }
374
- {
375
- triggerEffects(createDep(effects), eventInfo);
376
- }
334
+ }
335
+ const eventInfo = { target, type, key, newValue, oldValue, oldTarget } ;
336
+ if (deps.length === 1) {
337
+ if (deps[0]) {
338
+ {
339
+ triggerEffects(deps[0], eventInfo);
340
+ }
341
+ }
342
+ } else {
343
+ const effects = [];
344
+ for (const dep of deps) {
345
+ if (dep) {
346
+ effects.push(...dep);
347
+ }
377
348
  }
349
+ {
350
+ triggerEffects(createDep(effects), eventInfo);
351
+ }
352
+ }
378
353
  }
379
354
  function triggerEffects(dep, debuggerEventExtraInfo) {
380
- // spread into array for stabilization
381
- const effects = shared.isArray(dep) ? dep : [...dep];
382
- for (const effect of effects) {
383
- if (effect.computed) {
384
- triggerEffect(effect, debuggerEventExtraInfo);
385
- }
355
+ const effects = shared.isArray(dep) ? dep : [...dep];
356
+ for (const effect2 of effects) {
357
+ if (effect2.computed) {
358
+ triggerEffect(effect2, debuggerEventExtraInfo);
386
359
  }
387
- for (const effect of effects) {
388
- if (!effect.computed) {
389
- triggerEffect(effect, debuggerEventExtraInfo);
390
- }
360
+ }
361
+ for (const effect2 of effects) {
362
+ if (!effect2.computed) {
363
+ triggerEffect(effect2, debuggerEventExtraInfo);
391
364
  }
365
+ }
392
366
  }
393
- function triggerEffect(effect, debuggerEventExtraInfo) {
394
- if (effect !== activeEffect || effect.allowRecurse) {
395
- if (effect.onTrigger) {
396
- effect.onTrigger(shared.extend({ effect }, debuggerEventExtraInfo));
397
- }
398
- if (effect.scheduler) {
399
- effect.scheduler();
400
- }
401
- else {
402
- effect.run();
403
- }
367
+ function triggerEffect(effect2, debuggerEventExtraInfo) {
368
+ if (effect2 !== activeEffect || effect2.allowRecurse) {
369
+ if (effect2.onTrigger) {
370
+ effect2.onTrigger(shared.extend({ effect: effect2 }, debuggerEventExtraInfo));
371
+ }
372
+ if (effect2.scheduler) {
373
+ effect2.scheduler();
374
+ } else {
375
+ effect2.run();
404
376
  }
377
+ }
405
378
  }
406
379
  function getDepFromReactive(object, key) {
407
- var _a;
408
- return (_a = targetMap.get(object)) === null || _a === void 0 ? void 0 : _a.get(key);
380
+ var _a;
381
+ return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
409
382
  }
410
383
 
411
- const isNonTrackableKeys = /*#__PURE__*/ shared.makeMap(`__proto__,__v_isRef,__isVue`);
384
+ const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,__isVue`);
412
385
  const builtInSymbols = new Set(
413
- /*#__PURE__*/
414
- Object.getOwnPropertyNames(Symbol)
415
- // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
416
- // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
417
- // function
418
- .filter(key => key !== 'arguments' && key !== 'caller')
419
- .map(key => Symbol[key])
420
- .filter(shared.isSymbol));
421
- const get$1 = /*#__PURE__*/ createGetter();
422
- const shallowGet = /*#__PURE__*/ createGetter(false, true);
423
- const readonlyGet = /*#__PURE__*/ createGetter(true);
424
- const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
425
- const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
386
+ /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
387
+ );
388
+ const get$1 = /* @__PURE__ */ createGetter();
389
+ const shallowGet = /* @__PURE__ */ createGetter(false, true);
390
+ const readonlyGet = /* @__PURE__ */ createGetter(true);
391
+ const shallowReadonlyGet = /* @__PURE__ */ createGetter(true, true);
392
+ const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
426
393
  function createArrayInstrumentations() {
427
- const instrumentations = {};
428
- ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
429
- instrumentations[key] = function (...args) {
430
- const arr = toRaw(this);
431
- for (let i = 0, l = this.length; i < l; i++) {
432
- track(arr, "get" /* TrackOpTypes.GET */, i + '');
433
- }
434
- // we run the method using the original args first (which may be reactive)
435
- const res = arr[key](...args);
436
- if (res === -1 || res === false) {
437
- // if that didn't work, run it again using raw values.
438
- return arr[key](...args.map(toRaw));
439
- }
440
- else {
441
- return res;
442
- }
443
- };
444
- });
445
- ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
446
- instrumentations[key] = function (...args) {
447
- pauseTracking();
448
- const res = toRaw(this)[key].apply(this, args);
449
- resetTracking();
450
- return res;
451
- };
452
- });
453
- return instrumentations;
454
- }
455
- function hasOwnProperty(key) {
456
- const obj = toRaw(this);
457
- track(obj, "has" /* TrackOpTypes.HAS */, key);
458
- return obj.hasOwnProperty(key);
459
- }
460
- function createGetter(isReadonly = false, shallow = false) {
461
- return function get(target, key, receiver) {
462
- if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
463
- return !isReadonly;
464
- }
465
- else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
466
- return isReadonly;
467
- }
468
- else if (key === "__v_isShallow" /* ReactiveFlags.IS_SHALLOW */) {
469
- return shallow;
470
- }
471
- else if (key === "__v_raw" /* ReactiveFlags.RAW */ &&
472
- receiver ===
473
- (isReadonly
474
- ? shallow
475
- ? shallowReadonlyMap
476
- : readonlyMap
477
- : shallow
478
- ? shallowReactiveMap
479
- : reactiveMap).get(target)) {
480
- return target;
481
- }
482
- const targetIsArray = shared.isArray(target);
483
- if (!isReadonly) {
484
- if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) {
485
- return Reflect.get(arrayInstrumentations, key, receiver);
486
- }
487
- if (key === 'hasOwnProperty') {
488
- return hasOwnProperty;
489
- }
490
- }
491
- const res = Reflect.get(target, key, receiver);
492
- if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
493
- return res;
494
- }
495
- if (!isReadonly) {
496
- track(target, "get" /* TrackOpTypes.GET */, key);
497
- }
498
- if (shallow) {
499
- return res;
500
- }
501
- if (isRef(res)) {
502
- // ref unwrapping - skip unwrap for Array + integer key.
503
- return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
504
- }
505
- if (shared.isObject(res)) {
506
- // Convert returned value into a proxy as well. we do the isObject check
507
- // here to avoid invalid value warning. Also need to lazy access readonly
508
- // and reactive here to avoid circular dependency.
509
- return isReadonly ? readonly(res) : reactive(res);
510
- }
394
+ const instrumentations = {};
395
+ ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
396
+ instrumentations[key] = function(...args) {
397
+ const arr = toRaw(this);
398
+ for (let i = 0, l = this.length; i < l; i++) {
399
+ track(arr, "get", i + "");
400
+ }
401
+ const res = arr[key](...args);
402
+ if (res === -1 || res === false) {
403
+ return arr[key](...args.map(toRaw));
404
+ } else {
511
405
  return res;
406
+ }
512
407
  };
513
- }
514
- const set$1 = /*#__PURE__*/ createSetter();
515
- const shallowSet = /*#__PURE__*/ createSetter(true);
516
- function createSetter(shallow = false) {
517
- return function set(target, key, value, receiver) {
518
- let oldValue = target[key];
519
- if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
520
- return false;
521
- }
522
- if (!shallow) {
523
- if (!isShallow(value) && !isReadonly(value)) {
524
- oldValue = toRaw(oldValue);
525
- value = toRaw(value);
526
- }
527
- if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
528
- oldValue.value = value;
529
- return true;
530
- }
531
- }
532
- const hadKey = shared.isArray(target) && shared.isIntegerKey(key)
533
- ? Number(key) < target.length
534
- : shared.hasOwn(target, key);
535
- const result = Reflect.set(target, key, value, receiver);
536
- // don't trigger if target is something up in the prototype chain of original
537
- if (target === toRaw(receiver)) {
538
- if (!hadKey) {
539
- trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
540
- }
541
- else if (shared.hasChanged(value, oldValue)) {
542
- trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
543
- }
544
- }
545
- return result;
408
+ });
409
+ ["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
410
+ instrumentations[key] = function(...args) {
411
+ pauseTracking();
412
+ const res = toRaw(this)[key].apply(this, args);
413
+ resetTracking();
414
+ return res;
546
415
  };
416
+ });
417
+ return instrumentations;
547
418
  }
548
- function deleteProperty(target, key) {
549
- const hadKey = shared.hasOwn(target, key);
550
- const oldValue = target[key];
551
- const result = Reflect.deleteProperty(target, key);
552
- if (result && hadKey) {
553
- trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
419
+ function hasOwnProperty(key) {
420
+ const obj = toRaw(this);
421
+ track(obj, "has", key);
422
+ return obj.hasOwnProperty(key);
423
+ }
424
+ function createGetter(isReadonly2 = false, shallow = false) {
425
+ return function get2(target, key, receiver) {
426
+ if (key === "__v_isReactive") {
427
+ return !isReadonly2;
428
+ } else if (key === "__v_isReadonly") {
429
+ return isReadonly2;
430
+ } else if (key === "__v_isShallow") {
431
+ return shallow;
432
+ } else if (key === "__v_raw" && receiver === (isReadonly2 ? shallow ? shallowReadonlyMap : readonlyMap : shallow ? shallowReactiveMap : reactiveMap).get(target)) {
433
+ return target;
434
+ }
435
+ const targetIsArray = shared.isArray(target);
436
+ if (!isReadonly2) {
437
+ if (targetIsArray && shared.hasOwn(arrayInstrumentations, key)) {
438
+ return Reflect.get(arrayInstrumentations, key, receiver);
439
+ }
440
+ if (key === "hasOwnProperty") {
441
+ return hasOwnProperty;
442
+ }
443
+ }
444
+ const res = Reflect.get(target, key, receiver);
445
+ if (shared.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
446
+ return res;
447
+ }
448
+ if (!isReadonly2) {
449
+ track(target, "get", key);
450
+ }
451
+ if (shallow) {
452
+ return res;
453
+ }
454
+ if (isRef(res)) {
455
+ return targetIsArray && shared.isIntegerKey(key) ? res : res.value;
456
+ }
457
+ if (shared.isObject(res)) {
458
+ return isReadonly2 ? readonly(res) : reactive(res);
459
+ }
460
+ return res;
461
+ };
462
+ }
463
+ const set$1 = /* @__PURE__ */ createSetter();
464
+ const shallowSet = /* @__PURE__ */ createSetter(true);
465
+ function createSetter(shallow = false) {
466
+ return function set2(target, key, value, receiver) {
467
+ let oldValue = target[key];
468
+ if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
469
+ return false;
470
+ }
471
+ if (!shallow) {
472
+ if (!isShallow(value) && !isReadonly(value)) {
473
+ oldValue = toRaw(oldValue);
474
+ value = toRaw(value);
475
+ }
476
+ if (!shared.isArray(target) && isRef(oldValue) && !isRef(value)) {
477
+ oldValue.value = value;
478
+ return true;
479
+ }
480
+ }
481
+ const hadKey = shared.isArray(target) && shared.isIntegerKey(key) ? Number(key) < target.length : shared.hasOwn(target, key);
482
+ const result = Reflect.set(target, key, value, receiver);
483
+ if (target === toRaw(receiver)) {
484
+ if (!hadKey) {
485
+ trigger(target, "add", key, value);
486
+ } else if (shared.hasChanged(value, oldValue)) {
487
+ trigger(target, "set", key, value, oldValue);
488
+ }
554
489
  }
555
490
  return result;
491
+ };
492
+ }
493
+ function deleteProperty(target, key) {
494
+ const hadKey = shared.hasOwn(target, key);
495
+ const oldValue = target[key];
496
+ const result = Reflect.deleteProperty(target, key);
497
+ if (result && hadKey) {
498
+ trigger(target, "delete", key, void 0, oldValue);
499
+ }
500
+ return result;
556
501
  }
557
502
  function has$1(target, key) {
558
- const result = Reflect.has(target, key);
559
- if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
560
- track(target, "has" /* TrackOpTypes.HAS */, key);
561
- }
562
- return result;
503
+ const result = Reflect.has(target, key);
504
+ if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
505
+ track(target, "has", key);
506
+ }
507
+ return result;
563
508
  }
564
509
  function ownKeys(target) {
565
- track(target, "iterate" /* TrackOpTypes.ITERATE */, shared.isArray(target) ? 'length' : ITERATE_KEY);
566
- return Reflect.ownKeys(target);
510
+ track(target, "iterate", shared.isArray(target) ? "length" : ITERATE_KEY);
511
+ return Reflect.ownKeys(target);
567
512
  }
568
513
  const mutableHandlers = {
569
- get: get$1,
570
- set: set$1,
571
- deleteProperty,
572
- has: has$1,
573
- ownKeys
514
+ get: get$1,
515
+ set: set$1,
516
+ deleteProperty,
517
+ has: has$1,
518
+ ownKeys
574
519
  };
575
520
  const readonlyHandlers = {
576
- get: readonlyGet,
577
- set(target, key) {
578
- {
579
- warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
580
- }
581
- return true;
582
- },
583
- deleteProperty(target, key) {
584
- {
585
- warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
586
- }
587
- return true;
588
- }
521
+ get: readonlyGet,
522
+ set(target, key) {
523
+ {
524
+ warn(
525
+ `Set operation on key "${String(key)}" failed: target is readonly.`,
526
+ target
527
+ );
528
+ }
529
+ return true;
530
+ },
531
+ deleteProperty(target, key) {
532
+ {
533
+ warn(
534
+ `Delete operation on key "${String(key)}" failed: target is readonly.`,
535
+ target
536
+ );
537
+ }
538
+ return true;
539
+ }
589
540
  };
590
- const shallowReactiveHandlers = /*#__PURE__*/ shared.extend({}, mutableHandlers, {
541
+ const shallowReactiveHandlers = /* @__PURE__ */ shared.extend(
542
+ {},
543
+ mutableHandlers,
544
+ {
591
545
  get: shallowGet,
592
546
  set: shallowSet
593
- });
594
- // Props handlers are special in the sense that it should not unwrap top-level
595
- // refs (in order to allow refs to be explicitly passed down), but should
596
- // retain the reactivity of the normal readonly object.
597
- const shallowReadonlyHandlers = /*#__PURE__*/ shared.extend({}, readonlyHandlers, {
547
+ }
548
+ );
549
+ const shallowReadonlyHandlers = /* @__PURE__ */ shared.extend(
550
+ {},
551
+ readonlyHandlers,
552
+ {
598
553
  get: shallowReadonlyGet
599
- });
554
+ }
555
+ );
600
556
 
601
557
  const toShallow = (value) => value;
602
558
  const getProto = (v) => Reflect.getPrototypeOf(v);
603
559
  function get(target, key, isReadonly = false, isShallow = false) {
604
- // #1772: readonly(reactive(Map)) should return readonly + reactive version
605
- // of the value
606
- target = target["__v_raw" /* ReactiveFlags.RAW */];
607
- const rawTarget = toRaw(target);
608
- const rawKey = toRaw(key);
609
- if (!isReadonly) {
610
- if (key !== rawKey) {
611
- track(rawTarget, "get" /* TrackOpTypes.GET */, key);
612
- }
613
- track(rawTarget, "get" /* TrackOpTypes.GET */, rawKey);
614
- }
615
- const { has } = getProto(rawTarget);
616
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
617
- if (has.call(rawTarget, key)) {
618
- return wrap(target.get(key));
619
- }
620
- else if (has.call(rawTarget, rawKey)) {
621
- return wrap(target.get(rawKey));
622
- }
623
- else if (target !== rawTarget) {
624
- // #3602 readonly(reactive(Map))
625
- // ensure that the nested reactive `Map` can do tracking for itself
626
- target.get(key);
627
- }
560
+ target = target["__v_raw"];
561
+ const rawTarget = toRaw(target);
562
+ const rawKey = toRaw(key);
563
+ if (!isReadonly) {
564
+ if (key !== rawKey) {
565
+ track(rawTarget, "get", key);
566
+ }
567
+ track(rawTarget, "get", rawKey);
568
+ }
569
+ const { has: has2 } = getProto(rawTarget);
570
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
571
+ if (has2.call(rawTarget, key)) {
572
+ return wrap(target.get(key));
573
+ } else if (has2.call(rawTarget, rawKey)) {
574
+ return wrap(target.get(rawKey));
575
+ } else if (target !== rawTarget) {
576
+ target.get(key);
577
+ }
628
578
  }
629
579
  function has(key, isReadonly = false) {
630
- const target = this["__v_raw" /* ReactiveFlags.RAW */];
631
- const rawTarget = toRaw(target);
632
- const rawKey = toRaw(key);
633
- if (!isReadonly) {
634
- if (key !== rawKey) {
635
- track(rawTarget, "has" /* TrackOpTypes.HAS */, key);
636
- }
637
- track(rawTarget, "has" /* TrackOpTypes.HAS */, rawKey);
580
+ const target = this["__v_raw"];
581
+ const rawTarget = toRaw(target);
582
+ const rawKey = toRaw(key);
583
+ if (!isReadonly) {
584
+ if (key !== rawKey) {
585
+ track(rawTarget, "has", key);
638
586
  }
639
- return key === rawKey
640
- ? target.has(key)
641
- : target.has(key) || target.has(rawKey);
587
+ track(rawTarget, "has", rawKey);
588
+ }
589
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
642
590
  }
643
591
  function size(target, isReadonly = false) {
644
- target = target["__v_raw" /* ReactiveFlags.RAW */];
645
- !isReadonly && track(toRaw(target), "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
646
- return Reflect.get(target, 'size', target);
592
+ target = target["__v_raw"];
593
+ !isReadonly && track(toRaw(target), "iterate", ITERATE_KEY);
594
+ return Reflect.get(target, "size", target);
647
595
  }
648
596
  function add(value) {
649
- value = toRaw(value);
650
- const target = toRaw(this);
651
- const proto = getProto(target);
652
- const hadKey = proto.has.call(target, value);
653
- if (!hadKey) {
654
- target.add(value);
655
- trigger(target, "add" /* TriggerOpTypes.ADD */, value, value);
656
- }
657
- return this;
597
+ value = toRaw(value);
598
+ const target = toRaw(this);
599
+ const proto = getProto(target);
600
+ const hadKey = proto.has.call(target, value);
601
+ if (!hadKey) {
602
+ target.add(value);
603
+ trigger(target, "add", value, value);
604
+ }
605
+ return this;
658
606
  }
659
607
  function set(key, value) {
660
- value = toRaw(value);
661
- const target = toRaw(this);
662
- const { has, get } = getProto(target);
663
- let hadKey = has.call(target, key);
664
- if (!hadKey) {
665
- key = toRaw(key);
666
- hadKey = has.call(target, key);
667
- }
668
- else {
669
- checkIdentityKeys(target, has, key);
670
- }
671
- const oldValue = get.call(target, key);
672
- target.set(key, value);
673
- if (!hadKey) {
674
- trigger(target, "add" /* TriggerOpTypes.ADD */, key, value);
675
- }
676
- else if (shared.hasChanged(value, oldValue)) {
677
- trigger(target, "set" /* TriggerOpTypes.SET */, key, value, oldValue);
678
- }
679
- return this;
608
+ value = toRaw(value);
609
+ const target = toRaw(this);
610
+ const { has: has2, get: get2 } = getProto(target);
611
+ let hadKey = has2.call(target, key);
612
+ if (!hadKey) {
613
+ key = toRaw(key);
614
+ hadKey = has2.call(target, key);
615
+ } else {
616
+ checkIdentityKeys(target, has2, key);
617
+ }
618
+ const oldValue = get2.call(target, key);
619
+ target.set(key, value);
620
+ if (!hadKey) {
621
+ trigger(target, "add", key, value);
622
+ } else if (shared.hasChanged(value, oldValue)) {
623
+ trigger(target, "set", key, value, oldValue);
624
+ }
625
+ return this;
680
626
  }
681
627
  function deleteEntry(key) {
682
- const target = toRaw(this);
683
- const { has, get } = getProto(target);
684
- let hadKey = has.call(target, key);
685
- if (!hadKey) {
686
- key = toRaw(key);
687
- hadKey = has.call(target, key);
688
- }
689
- else {
690
- checkIdentityKeys(target, has, key);
691
- }
692
- const oldValue = get ? get.call(target, key) : undefined;
693
- // forward the operation before queueing reactions
694
- const result = target.delete(key);
695
- if (hadKey) {
696
- trigger(target, "delete" /* TriggerOpTypes.DELETE */, key, undefined, oldValue);
697
- }
698
- return result;
628
+ const target = toRaw(this);
629
+ const { has: has2, get: get2 } = getProto(target);
630
+ let hadKey = has2.call(target, key);
631
+ if (!hadKey) {
632
+ key = toRaw(key);
633
+ hadKey = has2.call(target, key);
634
+ } else {
635
+ checkIdentityKeys(target, has2, key);
636
+ }
637
+ const oldValue = get2 ? get2.call(target, key) : void 0;
638
+ const result = target.delete(key);
639
+ if (hadKey) {
640
+ trigger(target, "delete", key, void 0, oldValue);
641
+ }
642
+ return result;
699
643
  }
700
644
  function clear() {
701
- const target = toRaw(this);
702
- const hadItems = target.size !== 0;
703
- const oldTarget = shared.isMap(target)
704
- ? new Map(target)
705
- : new Set(target)
706
- ;
707
- // forward the operation before queueing reactions
708
- const result = target.clear();
709
- if (hadItems) {
710
- trigger(target, "clear" /* TriggerOpTypes.CLEAR */, undefined, undefined, oldTarget);
711
- }
712
- return result;
645
+ const target = toRaw(this);
646
+ const hadItems = target.size !== 0;
647
+ const oldTarget = shared.isMap(target) ? new Map(target) : new Set(target) ;
648
+ const result = target.clear();
649
+ if (hadItems) {
650
+ trigger(target, "clear", void 0, void 0, oldTarget);
651
+ }
652
+ return result;
713
653
  }
714
654
  function createForEach(isReadonly, isShallow) {
715
- return function forEach(callback, thisArg) {
716
- const observed = this;
717
- const target = observed["__v_raw" /* ReactiveFlags.RAW */];
718
- const rawTarget = toRaw(target);
719
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
720
- !isReadonly && track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, ITERATE_KEY);
721
- return target.forEach((value, key) => {
722
- // important: make sure the callback is
723
- // 1. invoked with the reactive map as `this` and 3rd arg
724
- // 2. the value received should be a corresponding reactive/readonly.
725
- return callback.call(thisArg, wrap(value), wrap(key), observed);
726
- });
727
- };
655
+ return function forEach(callback, thisArg) {
656
+ const observed = this;
657
+ const target = observed["__v_raw"];
658
+ const rawTarget = toRaw(target);
659
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
660
+ !isReadonly && track(rawTarget, "iterate", ITERATE_KEY);
661
+ return target.forEach((value, key) => {
662
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
663
+ });
664
+ };
728
665
  }
729
666
  function createIterableMethod(method, isReadonly, isShallow) {
730
- return function (...args) {
731
- const target = this["__v_raw" /* ReactiveFlags.RAW */];
732
- const rawTarget = toRaw(target);
733
- const targetIsMap = shared.isMap(rawTarget);
734
- const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
735
- const isKeyOnly = method === 'keys' && targetIsMap;
736
- const innerIterator = target[method](...args);
737
- const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
738
- !isReadonly &&
739
- track(rawTarget, "iterate" /* TrackOpTypes.ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
740
- // return a wrapped iterator which returns observed versions of the
741
- // values emitted from the real iterator
742
- return {
743
- // iterator protocol
744
- next() {
745
- const { value, done } = innerIterator.next();
746
- return done
747
- ? { value, done }
748
- : {
749
- value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
750
- done
751
- };
752
- },
753
- // iterable protocol
754
- [Symbol.iterator]() {
755
- return this;
756
- }
667
+ return function(...args) {
668
+ const target = this["__v_raw"];
669
+ const rawTarget = toRaw(target);
670
+ const targetIsMap = shared.isMap(rawTarget);
671
+ const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
672
+ const isKeyOnly = method === "keys" && targetIsMap;
673
+ const innerIterator = target[method](...args);
674
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
675
+ !isReadonly && track(
676
+ rawTarget,
677
+ "iterate",
678
+ isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
679
+ );
680
+ return {
681
+ // iterator protocol
682
+ next() {
683
+ const { value, done } = innerIterator.next();
684
+ return done ? { value, done } : {
685
+ value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
686
+ done
757
687
  };
688
+ },
689
+ // iterable protocol
690
+ [Symbol.iterator]() {
691
+ return this;
692
+ }
758
693
  };
694
+ };
759
695
  }
760
696
  function createReadonlyMethod(type) {
761
- return function (...args) {
762
- {
763
- const key = args[0] ? `on key "${args[0]}" ` : ``;
764
- console.warn(`${shared.capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
765
- }
766
- return type === "delete" /* TriggerOpTypes.DELETE */ ? false : this;
767
- };
697
+ return function(...args) {
698
+ {
699
+ const key = args[0] ? `on key "${args[0]}" ` : ``;
700
+ console.warn(
701
+ `${shared.capitalize(type)} operation ${key}failed: target is readonly.`,
702
+ toRaw(this)
703
+ );
704
+ }
705
+ return type === "delete" ? false : this;
706
+ };
768
707
  }
769
708
  function createInstrumentations() {
770
- const mutableInstrumentations = {
771
- get(key) {
772
- return get(this, key);
773
- },
774
- get size() {
775
- return size(this);
776
- },
777
- has,
778
- add,
779
- set,
780
- delete: deleteEntry,
781
- clear,
782
- forEach: createForEach(false, false)
783
- };
784
- const shallowInstrumentations = {
785
- get(key) {
786
- return get(this, key, false, true);
787
- },
788
- get size() {
789
- return size(this);
790
- },
791
- has,
792
- add,
793
- set,
794
- delete: deleteEntry,
795
- clear,
796
- forEach: createForEach(false, true)
797
- };
798
- const readonlyInstrumentations = {
799
- get(key) {
800
- return get(this, key, true);
801
- },
802
- get size() {
803
- return size(this, true);
804
- },
805
- has(key) {
806
- return has.call(this, key, true);
807
- },
808
- add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
809
- set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
810
- delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
811
- clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
812
- forEach: createForEach(true, false)
813
- };
814
- const shallowReadonlyInstrumentations = {
815
- get(key) {
816
- return get(this, key, true, true);
817
- },
818
- get size() {
819
- return size(this, true);
820
- },
821
- has(key) {
822
- return has.call(this, key, true);
823
- },
824
- add: createReadonlyMethod("add" /* TriggerOpTypes.ADD */),
825
- set: createReadonlyMethod("set" /* TriggerOpTypes.SET */),
826
- delete: createReadonlyMethod("delete" /* TriggerOpTypes.DELETE */),
827
- clear: createReadonlyMethod("clear" /* TriggerOpTypes.CLEAR */),
828
- forEach: createForEach(true, true)
829
- };
830
- const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
831
- iteratorMethods.forEach(method => {
832
- mutableInstrumentations[method] = createIterableMethod(method, false, false);
833
- readonlyInstrumentations[method] = createIterableMethod(method, true, false);
834
- shallowInstrumentations[method] = createIterableMethod(method, false, true);
835
- shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
836
- });
837
- return [
838
- mutableInstrumentations,
839
- readonlyInstrumentations,
840
- shallowInstrumentations,
841
- shallowReadonlyInstrumentations
842
- ];
843
- }
844
- const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
709
+ const mutableInstrumentations2 = {
710
+ get(key) {
711
+ return get(this, key);
712
+ },
713
+ get size() {
714
+ return size(this);
715
+ },
716
+ has,
717
+ add,
718
+ set,
719
+ delete: deleteEntry,
720
+ clear,
721
+ forEach: createForEach(false, false)
722
+ };
723
+ const shallowInstrumentations2 = {
724
+ get(key) {
725
+ return get(this, key, false, true);
726
+ },
727
+ get size() {
728
+ return size(this);
729
+ },
730
+ has,
731
+ add,
732
+ set,
733
+ delete: deleteEntry,
734
+ clear,
735
+ forEach: createForEach(false, true)
736
+ };
737
+ const readonlyInstrumentations2 = {
738
+ get(key) {
739
+ return get(this, key, true);
740
+ },
741
+ get size() {
742
+ return size(this, true);
743
+ },
744
+ has(key) {
745
+ return has.call(this, key, true);
746
+ },
747
+ add: createReadonlyMethod("add"),
748
+ set: createReadonlyMethod("set"),
749
+ delete: createReadonlyMethod("delete"),
750
+ clear: createReadonlyMethod("clear"),
751
+ forEach: createForEach(true, false)
752
+ };
753
+ const shallowReadonlyInstrumentations2 = {
754
+ get(key) {
755
+ return get(this, key, true, true);
756
+ },
757
+ get size() {
758
+ return size(this, true);
759
+ },
760
+ has(key) {
761
+ return has.call(this, key, true);
762
+ },
763
+ add: createReadonlyMethod("add"),
764
+ set: createReadonlyMethod("set"),
765
+ delete: createReadonlyMethod("delete"),
766
+ clear: createReadonlyMethod("clear"),
767
+ forEach: createForEach(true, true)
768
+ };
769
+ const iteratorMethods = ["keys", "values", "entries", Symbol.iterator];
770
+ iteratorMethods.forEach((method) => {
771
+ mutableInstrumentations2[method] = createIterableMethod(
772
+ method,
773
+ false,
774
+ false
775
+ );
776
+ readonlyInstrumentations2[method] = createIterableMethod(
777
+ method,
778
+ true,
779
+ false
780
+ );
781
+ shallowInstrumentations2[method] = createIterableMethod(
782
+ method,
783
+ false,
784
+ true
785
+ );
786
+ shallowReadonlyInstrumentations2[method] = createIterableMethod(
787
+ method,
788
+ true,
789
+ true
790
+ );
791
+ });
792
+ return [
793
+ mutableInstrumentations2,
794
+ readonlyInstrumentations2,
795
+ shallowInstrumentations2,
796
+ shallowReadonlyInstrumentations2
797
+ ];
798
+ }
799
+ const [
800
+ mutableInstrumentations,
801
+ readonlyInstrumentations,
802
+ shallowInstrumentations,
803
+ shallowReadonlyInstrumentations
804
+ ] = /* @__PURE__ */ createInstrumentations();
845
805
  function createInstrumentationGetter(isReadonly, shallow) {
846
- const instrumentations = shallow
847
- ? isReadonly
848
- ? shallowReadonlyInstrumentations
849
- : shallowInstrumentations
850
- : isReadonly
851
- ? readonlyInstrumentations
852
- : mutableInstrumentations;
853
- return (target, key, receiver) => {
854
- if (key === "__v_isReactive" /* ReactiveFlags.IS_REACTIVE */) {
855
- return !isReadonly;
856
- }
857
- else if (key === "__v_isReadonly" /* ReactiveFlags.IS_READONLY */) {
858
- return isReadonly;
859
- }
860
- else if (key === "__v_raw" /* ReactiveFlags.RAW */) {
861
- return target;
862
- }
863
- return Reflect.get(shared.hasOwn(instrumentations, key) && key in target
864
- ? instrumentations
865
- : target, key, receiver);
866
- };
806
+ const instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations;
807
+ return (target, key, receiver) => {
808
+ if (key === "__v_isReactive") {
809
+ return !isReadonly;
810
+ } else if (key === "__v_isReadonly") {
811
+ return isReadonly;
812
+ } else if (key === "__v_raw") {
813
+ return target;
814
+ }
815
+ return Reflect.get(
816
+ shared.hasOwn(instrumentations, key) && key in target ? instrumentations : target,
817
+ key,
818
+ receiver
819
+ );
820
+ };
867
821
  }
868
822
  const mutableCollectionHandlers = {
869
- get: /*#__PURE__*/ createInstrumentationGetter(false, false)
823
+ get: /* @__PURE__ */ createInstrumentationGetter(false, false)
870
824
  };
871
825
  const shallowCollectionHandlers = {
872
- get: /*#__PURE__*/ createInstrumentationGetter(false, true)
826
+ get: /* @__PURE__ */ createInstrumentationGetter(false, true)
873
827
  };
874
828
  const readonlyCollectionHandlers = {
875
- get: /*#__PURE__*/ createInstrumentationGetter(true, false)
829
+ get: /* @__PURE__ */ createInstrumentationGetter(true, false)
876
830
  };
877
831
  const shallowReadonlyCollectionHandlers = {
878
- get: /*#__PURE__*/ createInstrumentationGetter(true, true)
832
+ get: /* @__PURE__ */ createInstrumentationGetter(true, true)
879
833
  };
880
- function checkIdentityKeys(target, has, key) {
881
- const rawKey = toRaw(key);
882
- if (rawKey !== key && has.call(target, rawKey)) {
883
- const type = shared.toRawType(target);
884
- console.warn(`Reactive ${type} contains both the raw and reactive ` +
885
- `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
886
- `which can lead to inconsistencies. ` +
887
- `Avoid differentiating between the raw and reactive versions ` +
888
- `of an object and only use the reactive version if possible.`);
889
- }
834
+ function checkIdentityKeys(target, has2, key) {
835
+ const rawKey = toRaw(key);
836
+ if (rawKey !== key && has2.call(target, rawKey)) {
837
+ const type = shared.toRawType(target);
838
+ console.warn(
839
+ `Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
840
+ );
841
+ }
890
842
  }
891
843
 
892
- const reactiveMap = new WeakMap();
893
- const shallowReactiveMap = new WeakMap();
894
- const readonlyMap = new WeakMap();
895
- const shallowReadonlyMap = new WeakMap();
844
+ const reactiveMap = /* @__PURE__ */ new WeakMap();
845
+ const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
846
+ const readonlyMap = /* @__PURE__ */ new WeakMap();
847
+ const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
896
848
  function targetTypeMap(rawType) {
897
- switch (rawType) {
898
- case 'Object':
899
- case 'Array':
900
- return 1 /* TargetType.COMMON */;
901
- case 'Map':
902
- case 'Set':
903
- case 'WeakMap':
904
- case 'WeakSet':
905
- return 2 /* TargetType.COLLECTION */;
906
- default:
907
- return 0 /* TargetType.INVALID */;
908
- }
849
+ switch (rawType) {
850
+ case "Object":
851
+ case "Array":
852
+ return 1 /* COMMON */;
853
+ case "Map":
854
+ case "Set":
855
+ case "WeakMap":
856
+ case "WeakSet":
857
+ return 2 /* COLLECTION */;
858
+ default:
859
+ return 0 /* INVALID */;
860
+ }
909
861
  }
910
862
  function getTargetType(value) {
911
- return value["__v_skip" /* ReactiveFlags.SKIP */] || !Object.isExtensible(value)
912
- ? 0 /* TargetType.INVALID */
913
- : targetTypeMap(shared.toRawType(value));
863
+ return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(shared.toRawType(value));
914
864
  }
915
865
  function reactive(target) {
916
- // if trying to observe a readonly proxy, return the readonly version.
917
- if (isReadonly(target)) {
918
- return target;
919
- }
920
- return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
866
+ if (isReadonly(target)) {
867
+ return target;
868
+ }
869
+ return createReactiveObject(
870
+ target,
871
+ false,
872
+ mutableHandlers,
873
+ mutableCollectionHandlers,
874
+ reactiveMap
875
+ );
921
876
  }
922
- /**
923
- * Return a shallowly-reactive copy of the original object, where only the root
924
- * level properties are reactive. It also does not auto-unwrap refs (even at the
925
- * root level).
926
- */
927
877
  function shallowReactive(target) {
928
- return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
878
+ return createReactiveObject(
879
+ target,
880
+ false,
881
+ shallowReactiveHandlers,
882
+ shallowCollectionHandlers,
883
+ shallowReactiveMap
884
+ );
929
885
  }
930
- /**
931
- * Creates a readonly copy of the original object. Note the returned copy is not
932
- * made reactive, but `readonly` can be called on an already reactive object.
933
- */
934
886
  function readonly(target) {
935
- return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
936
- }
937
- /**
938
- * Returns a reactive-copy of the original object, where only the root level
939
- * properties are readonly, and does NOT unwrap refs nor recursively convert
940
- * returned properties.
941
- * This is used for creating the props proxy object for stateful components.
942
- */
943
- function shallowReadonly(target) {
944
- return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
887
+ return createReactiveObject(
888
+ target,
889
+ true,
890
+ readonlyHandlers,
891
+ readonlyCollectionHandlers,
892
+ readonlyMap
893
+ );
945
894
  }
946
- function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
947
- if (!shared.isObject(target)) {
948
- {
949
- console.warn(`value cannot be made reactive: ${String(target)}`);
950
- }
951
- return target;
952
- }
953
- // target is already a Proxy, return it.
954
- // exception: calling readonly() on a reactive object
955
- if (target["__v_raw" /* ReactiveFlags.RAW */] &&
956
- !(isReadonly && target["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */])) {
957
- return target;
958
- }
959
- // target already has corresponding Proxy
960
- const existingProxy = proxyMap.get(target);
961
- if (existingProxy) {
962
- return existingProxy;
963
- }
964
- // only specific value types can be observed.
965
- const targetType = getTargetType(target);
966
- if (targetType === 0 /* TargetType.INVALID */) {
967
- return target;
968
- }
969
- const proxy = new Proxy(target, targetType === 2 /* TargetType.COLLECTION */ ? collectionHandlers : baseHandlers);
970
- proxyMap.set(target, proxy);
971
- return proxy;
895
+ function shallowReadonly(target) {
896
+ return createReactiveObject(
897
+ target,
898
+ true,
899
+ shallowReadonlyHandlers,
900
+ shallowReadonlyCollectionHandlers,
901
+ shallowReadonlyMap
902
+ );
903
+ }
904
+ function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
905
+ if (!shared.isObject(target)) {
906
+ {
907
+ console.warn(`value cannot be made reactive: ${String(target)}`);
908
+ }
909
+ return target;
910
+ }
911
+ if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
912
+ return target;
913
+ }
914
+ const existingProxy = proxyMap.get(target);
915
+ if (existingProxy) {
916
+ return existingProxy;
917
+ }
918
+ const targetType = getTargetType(target);
919
+ if (targetType === 0 /* INVALID */) {
920
+ return target;
921
+ }
922
+ const proxy = new Proxy(
923
+ target,
924
+ targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
925
+ );
926
+ proxyMap.set(target, proxy);
927
+ return proxy;
972
928
  }
973
929
  function isReactive(value) {
974
- if (isReadonly(value)) {
975
- return isReactive(value["__v_raw" /* ReactiveFlags.RAW */]);
976
- }
977
- return !!(value && value["__v_isReactive" /* ReactiveFlags.IS_REACTIVE */]);
930
+ if (isReadonly(value)) {
931
+ return isReactive(value["__v_raw"]);
932
+ }
933
+ return !!(value && value["__v_isReactive"]);
978
934
  }
979
935
  function isReadonly(value) {
980
- return !!(value && value["__v_isReadonly" /* ReactiveFlags.IS_READONLY */]);
936
+ return !!(value && value["__v_isReadonly"]);
981
937
  }
982
938
  function isShallow(value) {
983
- return !!(value && value["__v_isShallow" /* ReactiveFlags.IS_SHALLOW */]);
939
+ return !!(value && value["__v_isShallow"]);
984
940
  }
985
941
  function isProxy(value) {
986
- return isReactive(value) || isReadonly(value);
942
+ return isReactive(value) || isReadonly(value);
987
943
  }
988
944
  function toRaw(observed) {
989
- const raw = observed && observed["__v_raw" /* ReactiveFlags.RAW */];
990
- return raw ? toRaw(raw) : observed;
945
+ const raw = observed && observed["__v_raw"];
946
+ return raw ? toRaw(raw) : observed;
991
947
  }
992
948
  function markRaw(value) {
993
- shared.def(value, "__v_skip" /* ReactiveFlags.SKIP */, true);
994
- return value;
949
+ shared.def(value, "__v_skip", true);
950
+ return value;
995
951
  }
996
952
  const toReactive = (value) => shared.isObject(value) ? reactive(value) : value;
997
953
  const toReadonly = (value) => shared.isObject(value) ? readonly(value) : value;
998
954
 
999
- function trackRefValue(ref) {
1000
- if (shouldTrack && activeEffect) {
1001
- ref = toRaw(ref);
1002
- {
1003
- trackEffects(ref.dep || (ref.dep = createDep()), {
1004
- target: ref,
1005
- type: "get" /* TrackOpTypes.GET */,
1006
- key: 'value'
1007
- });
1008
- }
1009
- }
1010
- }
1011
- function triggerRefValue(ref, newVal) {
1012
- ref = toRaw(ref);
1013
- const dep = ref.dep;
1014
- if (dep) {
1015
- {
1016
- triggerEffects(dep, {
1017
- target: ref,
1018
- type: "set" /* TriggerOpTypes.SET */,
1019
- key: 'value',
1020
- newValue: newVal
1021
- });
1022
- }
1023
- }
955
+ function trackRefValue(ref2) {
956
+ if (shouldTrack && activeEffect) {
957
+ ref2 = toRaw(ref2);
958
+ {
959
+ trackEffects(ref2.dep || (ref2.dep = createDep()), {
960
+ target: ref2,
961
+ type: "get",
962
+ key: "value"
963
+ });
964
+ }
965
+ }
966
+ }
967
+ function triggerRefValue(ref2, newVal) {
968
+ ref2 = toRaw(ref2);
969
+ const dep = ref2.dep;
970
+ if (dep) {
971
+ {
972
+ triggerEffects(dep, {
973
+ target: ref2,
974
+ type: "set",
975
+ key: "value",
976
+ newValue: newVal
977
+ });
978
+ }
979
+ }
1024
980
  }
1025
981
  function isRef(r) {
1026
- return !!(r && r.__v_isRef === true);
982
+ return !!(r && r.__v_isRef === true);
1027
983
  }
1028
984
  function ref(value) {
1029
- return createRef(value, false);
985
+ return createRef(value, false);
1030
986
  }
1031
987
  function shallowRef(value) {
1032
- return createRef(value, true);
988
+ return createRef(value, true);
1033
989
  }
1034
990
  function createRef(rawValue, shallow) {
1035
- if (isRef(rawValue)) {
1036
- return rawValue;
1037
- }
1038
- return new RefImpl(rawValue, shallow);
991
+ if (isRef(rawValue)) {
992
+ return rawValue;
993
+ }
994
+ return new RefImpl(rawValue, shallow);
1039
995
  }
1040
996
  class RefImpl {
1041
- constructor(value, __v_isShallow) {
1042
- this.__v_isShallow = __v_isShallow;
1043
- this.dep = undefined;
1044
- this.__v_isRef = true;
1045
- this._rawValue = __v_isShallow ? value : toRaw(value);
1046
- this._value = __v_isShallow ? value : toReactive(value);
1047
- }
1048
- get value() {
1049
- trackRefValue(this);
1050
- return this._value;
1051
- }
1052
- set value(newVal) {
1053
- const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1054
- newVal = useDirectValue ? newVal : toRaw(newVal);
1055
- if (shared.hasChanged(newVal, this._rawValue)) {
1056
- this._rawValue = newVal;
1057
- this._value = useDirectValue ? newVal : toReactive(newVal);
1058
- triggerRefValue(this, newVal);
1059
- }
1060
- }
1061
- }
1062
- function triggerRef(ref) {
1063
- triggerRefValue(ref, ref.value );
1064
- }
1065
- function unref(ref) {
1066
- return isRef(ref) ? ref.value : ref;
997
+ constructor(value, __v_isShallow) {
998
+ this.__v_isShallow = __v_isShallow;
999
+ this.dep = void 0;
1000
+ this.__v_isRef = true;
1001
+ this._rawValue = __v_isShallow ? value : toRaw(value);
1002
+ this._value = __v_isShallow ? value : toReactive(value);
1003
+ }
1004
+ get value() {
1005
+ trackRefValue(this);
1006
+ return this._value;
1007
+ }
1008
+ set value(newVal) {
1009
+ const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1010
+ newVal = useDirectValue ? newVal : toRaw(newVal);
1011
+ if (shared.hasChanged(newVal, this._rawValue)) {
1012
+ this._rawValue = newVal;
1013
+ this._value = useDirectValue ? newVal : toReactive(newVal);
1014
+ triggerRefValue(this, newVal);
1015
+ }
1016
+ }
1017
+ }
1018
+ function triggerRef(ref2) {
1019
+ triggerRefValue(ref2, ref2.value );
1020
+ }
1021
+ function unref(ref2) {
1022
+ return isRef(ref2) ? ref2.value : ref2;
1067
1023
  }
1068
1024
  const shallowUnwrapHandlers = {
1069
- get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
1070
- set: (target, key, value, receiver) => {
1071
- const oldValue = target[key];
1072
- if (isRef(oldValue) && !isRef(value)) {
1073
- oldValue.value = value;
1074
- return true;
1075
- }
1076
- else {
1077
- return Reflect.set(target, key, value, receiver);
1078
- }
1025
+ get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
1026
+ set: (target, key, value, receiver) => {
1027
+ const oldValue = target[key];
1028
+ if (isRef(oldValue) && !isRef(value)) {
1029
+ oldValue.value = value;
1030
+ return true;
1031
+ } else {
1032
+ return Reflect.set(target, key, value, receiver);
1079
1033
  }
1034
+ }
1080
1035
  };
1081
1036
  function proxyRefs(objectWithRefs) {
1082
- return isReactive(objectWithRefs)
1083
- ? objectWithRefs
1084
- : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1037
+ return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
1085
1038
  }
1086
1039
  class CustomRefImpl {
1087
- constructor(factory) {
1088
- this.dep = undefined;
1089
- this.__v_isRef = true;
1090
- const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
1091
- this._get = get;
1092
- this._set = set;
1093
- }
1094
- get value() {
1095
- return this._get();
1096
- }
1097
- set value(newVal) {
1098
- this._set(newVal);
1099
- }
1040
+ constructor(factory) {
1041
+ this.dep = void 0;
1042
+ this.__v_isRef = true;
1043
+ const { get, set } = factory(
1044
+ () => trackRefValue(this),
1045
+ () => triggerRefValue(this)
1046
+ );
1047
+ this._get = get;
1048
+ this._set = set;
1049
+ }
1050
+ get value() {
1051
+ return this._get();
1052
+ }
1053
+ set value(newVal) {
1054
+ this._set(newVal);
1055
+ }
1100
1056
  }
1101
1057
  function customRef(factory) {
1102
- return new CustomRefImpl(factory);
1058
+ return new CustomRefImpl(factory);
1103
1059
  }
1104
1060
  function toRefs(object) {
1105
- if (!isProxy(object)) {
1106
- console.warn(`toRefs() expects a reactive object but received a plain one.`);
1107
- }
1108
- const ret = shared.isArray(object) ? new Array(object.length) : {};
1109
- for (const key in object) {
1110
- ret[key] = toRef(object, key);
1111
- }
1112
- return ret;
1061
+ if (!isProxy(object)) {
1062
+ console.warn(`toRefs() expects a reactive object but received a plain one.`);
1063
+ }
1064
+ const ret = shared.isArray(object) ? new Array(object.length) : {};
1065
+ for (const key in object) {
1066
+ ret[key] = toRef(object, key);
1067
+ }
1068
+ return ret;
1113
1069
  }
1114
1070
  class ObjectRefImpl {
1115
- constructor(_object, _key, _defaultValue) {
1116
- this._object = _object;
1117
- this._key = _key;
1118
- this._defaultValue = _defaultValue;
1119
- this.__v_isRef = true;
1120
- }
1121
- get value() {
1122
- const val = this._object[this._key];
1123
- return val === undefined ? this._defaultValue : val;
1124
- }
1125
- set value(newVal) {
1126
- this._object[this._key] = newVal;
1127
- }
1128
- get dep() {
1129
- return getDepFromReactive(toRaw(this._object), this._key);
1130
- }
1071
+ constructor(_object, _key, _defaultValue) {
1072
+ this._object = _object;
1073
+ this._key = _key;
1074
+ this._defaultValue = _defaultValue;
1075
+ this.__v_isRef = true;
1076
+ }
1077
+ get value() {
1078
+ const val = this._object[this._key];
1079
+ return val === void 0 ? this._defaultValue : val;
1080
+ }
1081
+ set value(newVal) {
1082
+ this._object[this._key] = newVal;
1083
+ }
1084
+ get dep() {
1085
+ return getDepFromReactive(toRaw(this._object), this._key);
1086
+ }
1131
1087
  }
1132
1088
  function toRef(object, key, defaultValue) {
1133
- const val = object[key];
1134
- return isRef(val)
1135
- ? val
1136
- : new ObjectRefImpl(object, key, defaultValue);
1089
+ const val = object[key];
1090
+ return isRef(val) ? val : new ObjectRefImpl(object, key, defaultValue);
1137
1091
  }
1138
1092
 
1139
- var _a$1;
1140
1093
  class ComputedRefImpl {
1141
- constructor(getter, _setter, isReadonly, isSSR) {
1142
- this._setter = _setter;
1143
- this.dep = undefined;
1144
- this.__v_isRef = true;
1145
- this[_a$1] = false;
1094
+ constructor(getter, _setter, isReadonly, isSSR) {
1095
+ this._setter = _setter;
1096
+ this.dep = void 0;
1097
+ this.__v_isRef = true;
1098
+ this["__v_isReadonly"] = false;
1099
+ this._dirty = true;
1100
+ this.effect = new ReactiveEffect(getter, () => {
1101
+ if (!this._dirty) {
1146
1102
  this._dirty = true;
1147
- this.effect = new ReactiveEffect(getter, () => {
1148
- if (!this._dirty) {
1149
- this._dirty = true;
1150
- triggerRefValue(this);
1151
- }
1152
- });
1153
- this.effect.computed = this;
1154
- this.effect.active = this._cacheable = !isSSR;
1155
- this["__v_isReadonly" /* ReactiveFlags.IS_READONLY */] = isReadonly;
1156
- }
1157
- get value() {
1158
- // the computed ref may get wrapped by other proxies e.g. readonly() #3376
1159
- const self = toRaw(this);
1160
- trackRefValue(self);
1161
- if (self._dirty || !self._cacheable) {
1162
- self._dirty = false;
1163
- self._value = self.effect.run();
1164
- }
1165
- return self._value;
1166
- }
1167
- set value(newValue) {
1168
- this._setter(newValue);
1169
- }
1103
+ triggerRefValue(this);
1104
+ }
1105
+ });
1106
+ this.effect.computed = this;
1107
+ this.effect.active = this._cacheable = !isSSR;
1108
+ this["__v_isReadonly"] = isReadonly;
1109
+ }
1110
+ get value() {
1111
+ const self = toRaw(this);
1112
+ trackRefValue(self);
1113
+ if (self._dirty || !self._cacheable) {
1114
+ self._dirty = false;
1115
+ self._value = self.effect.run();
1116
+ }
1117
+ return self._value;
1118
+ }
1119
+ set value(newValue) {
1120
+ this._setter(newValue);
1121
+ }
1170
1122
  }
1171
- _a$1 = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
1172
1123
  function computed(getterOrOptions, debugOptions, isSSR = false) {
1173
- let getter;
1174
- let setter;
1175
- const onlyGetter = shared.isFunction(getterOrOptions);
1176
- if (onlyGetter) {
1177
- getter = getterOrOptions;
1178
- setter = () => {
1179
- console.warn('Write operation failed: computed value is readonly');
1180
- }
1181
- ;
1182
- }
1183
- else {
1184
- getter = getterOrOptions.get;
1185
- setter = getterOrOptions.set;
1186
- }
1187
- const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1188
- if (debugOptions && !isSSR) {
1189
- cRef.effect.onTrack = debugOptions.onTrack;
1190
- cRef.effect.onTrigger = debugOptions.onTrigger;
1191
- }
1192
- return cRef;
1124
+ let getter;
1125
+ let setter;
1126
+ const onlyGetter = shared.isFunction(getterOrOptions);
1127
+ if (onlyGetter) {
1128
+ getter = getterOrOptions;
1129
+ setter = () => {
1130
+ console.warn("Write operation failed: computed value is readonly");
1131
+ } ;
1132
+ } else {
1133
+ getter = getterOrOptions.get;
1134
+ setter = getterOrOptions.set;
1135
+ }
1136
+ const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1137
+ if (debugOptions && !isSSR) {
1138
+ cRef.effect.onTrack = debugOptions.onTrack;
1139
+ cRef.effect.onTrigger = debugOptions.onTrigger;
1140
+ }
1141
+ return cRef;
1193
1142
  }
1194
1143
 
1195
- var _a;
1196
- const tick = /*#__PURE__*/ Promise.resolve();
1144
+ const tick = /* @__PURE__ */ Promise.resolve();
1197
1145
  const queue = [];
1198
1146
  let queued = false;
1199
1147
  const scheduler = (fn) => {
1200
- queue.push(fn);
1201
- if (!queued) {
1202
- queued = true;
1203
- tick.then(flush);
1204
- }
1148
+ queue.push(fn);
1149
+ if (!queued) {
1150
+ queued = true;
1151
+ tick.then(flush);
1152
+ }
1205
1153
  };
1206
1154
  const flush = () => {
1207
- for (let i = 0; i < queue.length; i++) {
1208
- queue[i]();
1209
- }
1210
- queue.length = 0;
1211
- queued = false;
1155
+ for (let i = 0; i < queue.length; i++) {
1156
+ queue[i]();
1157
+ }
1158
+ queue.length = 0;
1159
+ queued = false;
1212
1160
  };
1213
1161
  class DeferredComputedRefImpl {
1214
- constructor(getter) {
1215
- this.dep = undefined;
1216
- this._dirty = true;
1217
- this.__v_isRef = true;
1218
- this[_a] = true;
1219
- let compareTarget;
1220
- let hasCompareTarget = false;
1221
- let scheduled = false;
1222
- this.effect = new ReactiveEffect(getter, (computedTrigger) => {
1223
- if (this.dep) {
1224
- if (computedTrigger) {
1225
- compareTarget = this._value;
1226
- hasCompareTarget = true;
1227
- }
1228
- else if (!scheduled) {
1229
- const valueToCompare = hasCompareTarget ? compareTarget : this._value;
1230
- scheduled = true;
1231
- hasCompareTarget = false;
1232
- scheduler(() => {
1233
- if (this.effect.active && this._get() !== valueToCompare) {
1234
- triggerRefValue(this);
1235
- }
1236
- scheduled = false;
1237
- });
1238
- }
1239
- // chained upstream computeds are notified synchronously to ensure
1240
- // value invalidation in case of sync access; normal effects are
1241
- // deferred to be triggered in scheduler.
1242
- for (const e of this.dep) {
1243
- if (e.computed instanceof DeferredComputedRefImpl) {
1244
- e.scheduler(true /* computedTrigger */);
1245
- }
1246
- }
1162
+ constructor(getter) {
1163
+ this.dep = void 0;
1164
+ this._dirty = true;
1165
+ this.__v_isRef = true;
1166
+ this["__v_isReadonly"] = true;
1167
+ let compareTarget;
1168
+ let hasCompareTarget = false;
1169
+ let scheduled = false;
1170
+ this.effect = new ReactiveEffect(getter, (computedTrigger) => {
1171
+ if (this.dep) {
1172
+ if (computedTrigger) {
1173
+ compareTarget = this._value;
1174
+ hasCompareTarget = true;
1175
+ } else if (!scheduled) {
1176
+ const valueToCompare = hasCompareTarget ? compareTarget : this._value;
1177
+ scheduled = true;
1178
+ hasCompareTarget = false;
1179
+ scheduler(() => {
1180
+ if (this.effect.active && this._get() !== valueToCompare) {
1181
+ triggerRefValue(this);
1247
1182
  }
1248
- this._dirty = true;
1249
- });
1250
- this.effect.computed = this;
1251
- }
1252
- _get() {
1253
- if (this._dirty) {
1254
- this._dirty = false;
1255
- return (this._value = this.effect.run());
1183
+ scheduled = false;
1184
+ });
1256
1185
  }
1257
- return this._value;
1258
- }
1259
- get value() {
1260
- trackRefValue(this);
1261
- // the computed ref may get wrapped by other proxies e.g. readonly() #3376
1262
- return toRaw(this)._get();
1263
- }
1186
+ for (const e of this.dep) {
1187
+ if (e.computed instanceof DeferredComputedRefImpl) {
1188
+ e.scheduler(
1189
+ true
1190
+ /* computedTrigger */
1191
+ );
1192
+ }
1193
+ }
1194
+ }
1195
+ this._dirty = true;
1196
+ });
1197
+ this.effect.computed = this;
1198
+ }
1199
+ _get() {
1200
+ if (this._dirty) {
1201
+ this._dirty = false;
1202
+ return this._value = this.effect.run();
1203
+ }
1204
+ return this._value;
1205
+ }
1206
+ get value() {
1207
+ trackRefValue(this);
1208
+ return toRaw(this)._get();
1209
+ }
1264
1210
  }
1265
- _a = "__v_isReadonly" /* ReactiveFlags.IS_READONLY */;
1266
1211
  function deferredComputed(getter) {
1267
- return new DeferredComputedRefImpl(getter);
1212
+ return new DeferredComputedRefImpl(getter);
1268
1213
  }
1269
1214
 
1270
1215
  exports.EffectScope = EffectScope;