@vue/reactivity 3.2.46 → 3.3.0-alpha.1

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