@vueuse/shared 6.3.2 → 6.5.3
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.
- package/index.cjs +1008 -1005
- package/index.d.ts +40 -6
- package/index.iife.js +1009 -1006
- package/index.iife.min.js +1 -1
- package/index.mjs +1007 -1006
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -4,1102 +4,1103 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* @see https://vueuse.org/and
|
|
11
|
-
*/
|
|
12
|
-
function and(...args) {
|
|
13
|
-
return vueDemi.computed(() => args.every(i => vueDemi.unref(i)));
|
|
7
|
+
function and(...args) {
|
|
8
|
+
return vueDemi.computed(() => args.every((i) => vueDemi.unref(i)));
|
|
14
9
|
}
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
immediate: true,
|
|
35
|
-
});
|
|
36
|
-
return () => {
|
|
37
|
-
stop1();
|
|
38
|
-
stop2();
|
|
39
|
-
};
|
|
11
|
+
function biSyncRef(a, b) {
|
|
12
|
+
const flush = "sync";
|
|
13
|
+
const stop1 = vueDemi.watch(a, (newValue) => {
|
|
14
|
+
b.value = newValue;
|
|
15
|
+
}, {
|
|
16
|
+
flush,
|
|
17
|
+
immediate: true
|
|
18
|
+
});
|
|
19
|
+
const stop2 = vueDemi.watch(b, (newValue) => {
|
|
20
|
+
a.value = newValue;
|
|
21
|
+
}, {
|
|
22
|
+
flush,
|
|
23
|
+
immediate: true
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
stop1();
|
|
27
|
+
stop2();
|
|
28
|
+
};
|
|
40
29
|
}
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return v;
|
|
68
|
-
},
|
|
69
|
-
set() { },
|
|
70
|
-
};
|
|
71
|
-
});
|
|
31
|
+
function controlledComputed(source, fn) {
|
|
32
|
+
let v = void 0;
|
|
33
|
+
let track;
|
|
34
|
+
let trigger;
|
|
35
|
+
const dirty = vueDemi.ref(true);
|
|
36
|
+
vueDemi.watch(source, () => {
|
|
37
|
+
dirty.value = true;
|
|
38
|
+
trigger();
|
|
39
|
+
}, { flush: "sync" });
|
|
40
|
+
return vueDemi.customRef((_track, _trigger) => {
|
|
41
|
+
track = _track;
|
|
42
|
+
trigger = _trigger;
|
|
43
|
+
return {
|
|
44
|
+
get() {
|
|
45
|
+
if (dirty.value) {
|
|
46
|
+
v = fn();
|
|
47
|
+
dirty.value = false;
|
|
48
|
+
}
|
|
49
|
+
track();
|
|
50
|
+
return v;
|
|
51
|
+
},
|
|
52
|
+
set() {
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
72
56
|
}
|
|
73
57
|
|
|
74
|
-
function __onlyVue3(name =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
function __onlyVue3(name = "this function") {
|
|
59
|
+
if (vueDemi.isVue3)
|
|
60
|
+
return;
|
|
61
|
+
throw new Error(`[VueUse] ${name} is only works on Vue 3.`);
|
|
78
62
|
}
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
return ref;
|
|
64
|
+
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
65
|
+
__onlyVue3();
|
|
66
|
+
for (const [key, value] of Object.entries(extend)) {
|
|
67
|
+
if (key === "value")
|
|
68
|
+
continue;
|
|
69
|
+
if (vueDemi.isRef(value) && unwrap) {
|
|
70
|
+
Object.defineProperty(ref, key, {
|
|
71
|
+
get() {
|
|
72
|
+
return value.value;
|
|
73
|
+
},
|
|
74
|
+
set(v) {
|
|
75
|
+
value.value = v;
|
|
76
|
+
},
|
|
77
|
+
enumerable
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
Object.defineProperty(ref, key, { value, enumerable });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return ref;
|
|
102
84
|
}
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*/
|
|
150
|
-
const silentSet = (v) => set(v, false);
|
|
151
|
-
/**
|
|
152
|
-
* Get the value without tracked in the reactivity system.
|
|
153
|
-
*
|
|
154
|
-
* Alias for `untrackedGet()`
|
|
155
|
-
*/
|
|
156
|
-
const peek = () => get(false);
|
|
157
|
-
/**
|
|
158
|
-
* Set the value without triggering the reactivity system
|
|
159
|
-
*
|
|
160
|
-
* Alias for `silentSet(v)`
|
|
161
|
-
*/
|
|
162
|
-
const lay = (v) => set(v, false);
|
|
163
|
-
return extendRef(ref, {
|
|
164
|
-
get,
|
|
165
|
-
set,
|
|
166
|
-
untrackedGet,
|
|
167
|
-
silentSet,
|
|
168
|
-
peek,
|
|
169
|
-
lay,
|
|
170
|
-
}, { enumerable: true });
|
|
86
|
+
function controlledRef(initial, options = {}) {
|
|
87
|
+
let source = initial;
|
|
88
|
+
let track;
|
|
89
|
+
let trigger;
|
|
90
|
+
const ref = vueDemi.customRef((_track, _trigger) => {
|
|
91
|
+
track = _track;
|
|
92
|
+
trigger = _trigger;
|
|
93
|
+
return {
|
|
94
|
+
get() {
|
|
95
|
+
return get();
|
|
96
|
+
},
|
|
97
|
+
set(v) {
|
|
98
|
+
set(v);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
function get(tracking = true) {
|
|
103
|
+
if (tracking)
|
|
104
|
+
track();
|
|
105
|
+
return source;
|
|
106
|
+
}
|
|
107
|
+
function set(value, triggering = true) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
if (value === source)
|
|
110
|
+
return;
|
|
111
|
+
const old = source;
|
|
112
|
+
if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
|
|
113
|
+
return;
|
|
114
|
+
source = value;
|
|
115
|
+
(_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
|
|
116
|
+
if (triggering)
|
|
117
|
+
trigger();
|
|
118
|
+
}
|
|
119
|
+
const untrackedGet = () => get(false);
|
|
120
|
+
const silentSet = (v) => set(v, false);
|
|
121
|
+
const peek = () => get(false);
|
|
122
|
+
const lay = (v) => set(v, false);
|
|
123
|
+
return extendRef(ref, {
|
|
124
|
+
get,
|
|
125
|
+
set,
|
|
126
|
+
untrackedGet,
|
|
127
|
+
silentSet,
|
|
128
|
+
peek,
|
|
129
|
+
lay
|
|
130
|
+
}, { enumerable: true });
|
|
171
131
|
}
|
|
172
132
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
};
|
|
195
|
-
const trigger = (param) => {
|
|
196
|
-
fns.forEach(fn => fn(param));
|
|
197
|
-
};
|
|
198
|
-
return {
|
|
199
|
-
on,
|
|
200
|
-
off,
|
|
201
|
-
trigger,
|
|
202
|
-
};
|
|
133
|
+
function createEventHook() {
|
|
134
|
+
const fns = [];
|
|
135
|
+
const off = (fn) => {
|
|
136
|
+
const index = fns.indexOf(fn);
|
|
137
|
+
if (index !== -1)
|
|
138
|
+
fns.splice(index, 1);
|
|
139
|
+
};
|
|
140
|
+
const on = (fn) => {
|
|
141
|
+
fns.push(fn);
|
|
142
|
+
return {
|
|
143
|
+
off: () => off(fn)
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const trigger = (param) => {
|
|
147
|
+
fns.forEach((fn) => fn(param));
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
on,
|
|
151
|
+
off,
|
|
152
|
+
trigger
|
|
153
|
+
};
|
|
203
154
|
}
|
|
204
155
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (!initialized) {
|
|
217
|
-
state = scope.run(stateFactory);
|
|
218
|
-
initialized = true;
|
|
219
|
-
}
|
|
220
|
-
return state;
|
|
221
|
-
};
|
|
156
|
+
function createGlobalState(stateFactory) {
|
|
157
|
+
let initialized = false;
|
|
158
|
+
let state;
|
|
159
|
+
const scope = vueDemi.effectScope(true);
|
|
160
|
+
return () => {
|
|
161
|
+
if (!initialized) {
|
|
162
|
+
state = scope.run(stateFactory);
|
|
163
|
+
initialized = true;
|
|
164
|
+
}
|
|
165
|
+
return state;
|
|
166
|
+
};
|
|
222
167
|
}
|
|
223
168
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (vueDemi.getCurrentScope()) {
|
|
231
|
-
vueDemi.onScopeDispose(fn);
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
169
|
+
function tryOnScopeDispose(fn) {
|
|
170
|
+
if (vueDemi.getCurrentScope()) {
|
|
171
|
+
vueDemi.onScopeDispose(fn);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
235
175
|
}
|
|
236
176
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
state = scope.run(() => composable(...args));
|
|
259
|
-
}
|
|
260
|
-
tryOnScopeDispose(dispose);
|
|
261
|
-
return state;
|
|
262
|
-
});
|
|
177
|
+
function createSharedComposable(composable) {
|
|
178
|
+
let subscribers = 0;
|
|
179
|
+
let state;
|
|
180
|
+
let scope;
|
|
181
|
+
const dispose = () => {
|
|
182
|
+
subscribers -= 1;
|
|
183
|
+
if (scope && subscribers <= 0) {
|
|
184
|
+
scope.stop();
|
|
185
|
+
state = void 0;
|
|
186
|
+
scope = void 0;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
return (...args) => {
|
|
190
|
+
subscribers += 1;
|
|
191
|
+
if (!state) {
|
|
192
|
+
scope = vueDemi.effectScope(true);
|
|
193
|
+
state = scope.run(() => composable(...args));
|
|
194
|
+
}
|
|
195
|
+
tryOnScopeDispose(dispose);
|
|
196
|
+
return state;
|
|
197
|
+
};
|
|
263
198
|
}
|
|
264
199
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
return t;
|
|
290
|
-
}
|
|
200
|
+
const isClient = typeof window !== "undefined";
|
|
201
|
+
const isDef = (val) => typeof val !== "undefined";
|
|
202
|
+
const assert = (condition, ...infos) => {
|
|
203
|
+
if (!condition)
|
|
204
|
+
console.warn(...infos);
|
|
205
|
+
};
|
|
206
|
+
const toString = Object.prototype.toString;
|
|
207
|
+
const isBoolean = (val) => typeof val === "boolean";
|
|
208
|
+
const isFunction = (val) => typeof val === "function";
|
|
209
|
+
const isNumber = (val) => typeof val === "number";
|
|
210
|
+
const isString = (val) => typeof val === "string";
|
|
211
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
212
|
+
const isWindow = (val) => typeof window !== "undefined" && toString.call(val) === "[object Window]";
|
|
213
|
+
const now = () => Date.now();
|
|
214
|
+
const timestamp = () => +Date.now();
|
|
215
|
+
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
216
|
+
const noop = () => {
|
|
217
|
+
};
|
|
218
|
+
const rand = (min, max) => {
|
|
219
|
+
min = Math.ceil(min);
|
|
220
|
+
max = Math.floor(max);
|
|
221
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
222
|
+
};
|
|
291
223
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const isBoolean = (val) => typeof val === 'boolean';
|
|
301
|
-
const isFunction = (val) => typeof val === 'function';
|
|
302
|
-
const isNumber = (val) => typeof val === 'number';
|
|
303
|
-
const isString = (val) => typeof val === 'string';
|
|
304
|
-
const isObject = (val) => toString.call(val) === '[object Object]';
|
|
305
|
-
const isWindow = (val) => typeof window !== 'undefined' && toString.call(val) === '[object Window]';
|
|
306
|
-
const now = () => Date.now();
|
|
307
|
-
const timestamp = () => +Date.now();
|
|
308
|
-
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
309
|
-
const noop = () => { };
|
|
310
|
-
const rand = (min, max) => {
|
|
311
|
-
min = Math.ceil(min);
|
|
312
|
-
max = Math.floor(max);
|
|
313
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
224
|
+
function createFilterWrapper(filter, fn) {
|
|
225
|
+
function wrapper(...args) {
|
|
226
|
+
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
|
|
227
|
+
}
|
|
228
|
+
return wrapper;
|
|
229
|
+
}
|
|
230
|
+
const bypassFilter = (invoke) => {
|
|
231
|
+
return invoke();
|
|
314
232
|
};
|
|
233
|
+
function debounceFilter(ms) {
|
|
234
|
+
let timer;
|
|
235
|
+
const filter = (invoke) => {
|
|
236
|
+
const duration = vueDemi.unref(ms);
|
|
237
|
+
if (timer)
|
|
238
|
+
clearTimeout(timer);
|
|
239
|
+
if (duration <= 0)
|
|
240
|
+
return invoke();
|
|
241
|
+
timer = setTimeout(invoke, duration);
|
|
242
|
+
};
|
|
243
|
+
return filter;
|
|
244
|
+
}
|
|
245
|
+
function throttleFilter(ms, trailing = true, leading = true) {
|
|
246
|
+
let lastExec = 0;
|
|
247
|
+
let timer;
|
|
248
|
+
let preventLeading = !leading;
|
|
249
|
+
const clear = () => {
|
|
250
|
+
if (timer) {
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
timer = void 0;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const filter = (invoke) => {
|
|
256
|
+
const duration = vueDemi.unref(ms);
|
|
257
|
+
const elapsed = Date.now() - lastExec;
|
|
258
|
+
clear();
|
|
259
|
+
if (duration <= 0) {
|
|
260
|
+
lastExec = Date.now();
|
|
261
|
+
return invoke();
|
|
262
|
+
}
|
|
263
|
+
if (elapsed > duration) {
|
|
264
|
+
lastExec = Date.now();
|
|
265
|
+
if (preventLeading)
|
|
266
|
+
preventLeading = false;
|
|
267
|
+
else
|
|
268
|
+
invoke();
|
|
269
|
+
} else if (trailing) {
|
|
270
|
+
timer = setTimeout(() => {
|
|
271
|
+
lastExec = Date.now();
|
|
272
|
+
if (!leading)
|
|
273
|
+
preventLeading = true;
|
|
274
|
+
clear();
|
|
275
|
+
invoke();
|
|
276
|
+
}, duration);
|
|
277
|
+
}
|
|
278
|
+
if (!leading && !timer)
|
|
279
|
+
timer = setTimeout(() => preventLeading = true, duration);
|
|
280
|
+
};
|
|
281
|
+
return filter;
|
|
282
|
+
}
|
|
283
|
+
function pausableFilter(extendFilter = bypassFilter) {
|
|
284
|
+
const isActive = vueDemi.ref(true);
|
|
285
|
+
function pause() {
|
|
286
|
+
isActive.value = false;
|
|
287
|
+
}
|
|
288
|
+
function resume() {
|
|
289
|
+
isActive.value = true;
|
|
290
|
+
}
|
|
291
|
+
const eventFilter = (...args) => {
|
|
292
|
+
if (isActive.value)
|
|
293
|
+
extendFilter(...args);
|
|
294
|
+
};
|
|
295
|
+
return { isActive, pause, resume, eventFilter };
|
|
296
|
+
}
|
|
315
297
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
if (elapsed > duration) {
|
|
369
|
-
lastExec = Date.now();
|
|
370
|
-
invoke();
|
|
371
|
-
}
|
|
372
|
-
else if (trailing) {
|
|
373
|
-
timer = setTimeout(() => {
|
|
374
|
-
lastExec = Date.now();
|
|
375
|
-
clear();
|
|
376
|
-
invoke();
|
|
377
|
-
}, duration);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
return filter;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* EventFilter that gives extra controls to pause and resume the filter
|
|
384
|
-
*
|
|
385
|
-
* @param extendFilter Extra filter to apply when the PauseableFilter is active, default to none
|
|
386
|
-
*
|
|
387
|
-
*/
|
|
388
|
-
function pausableFilter(extendFilter = bypassFilter) {
|
|
389
|
-
const isActive = vueDemi.ref(true);
|
|
390
|
-
function pause() {
|
|
391
|
-
isActive.value = false;
|
|
392
|
-
}
|
|
393
|
-
function resume() {
|
|
394
|
-
isActive.value = true;
|
|
395
|
-
}
|
|
396
|
-
const eventFilter = (...args) => {
|
|
397
|
-
if (isActive.value)
|
|
398
|
-
extendFilter(...args);
|
|
399
|
-
};
|
|
400
|
-
return { isActive, pause, resume, eventFilter };
|
|
298
|
+
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
299
|
+
return new Promise((resolve, reject) => {
|
|
300
|
+
if (throwOnTimeout)
|
|
301
|
+
setTimeout(() => reject(reason), ms);
|
|
302
|
+
else
|
|
303
|
+
setTimeout(resolve, ms);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function identity(arg) {
|
|
307
|
+
return arg;
|
|
308
|
+
}
|
|
309
|
+
function createSingletonPromise(fn) {
|
|
310
|
+
let _promise;
|
|
311
|
+
function wrapper() {
|
|
312
|
+
if (!_promise)
|
|
313
|
+
_promise = fn();
|
|
314
|
+
return _promise;
|
|
315
|
+
}
|
|
316
|
+
wrapper.reset = async () => {
|
|
317
|
+
const _prev = _promise;
|
|
318
|
+
_promise = void 0;
|
|
319
|
+
if (_prev)
|
|
320
|
+
await _prev;
|
|
321
|
+
};
|
|
322
|
+
return wrapper;
|
|
323
|
+
}
|
|
324
|
+
function invoke(fn) {
|
|
325
|
+
return fn();
|
|
326
|
+
}
|
|
327
|
+
function containsProp(obj, ...props) {
|
|
328
|
+
return props.some((k) => k in obj);
|
|
329
|
+
}
|
|
330
|
+
function increaseWithUnit(target, delta) {
|
|
331
|
+
var _a;
|
|
332
|
+
if (typeof target === "number")
|
|
333
|
+
return target + delta;
|
|
334
|
+
const value = ((_a = target.match(/^-?[0-9]+\.?[0-9]*/)) == null ? void 0 : _a[0]) || "";
|
|
335
|
+
const unit = target.slice(value.length);
|
|
336
|
+
const result = parseFloat(value) + delta;
|
|
337
|
+
if (Number.isNaN(result))
|
|
338
|
+
return target;
|
|
339
|
+
return result + unit;
|
|
340
|
+
}
|
|
341
|
+
function objectPick(obj, keys, omitUndefined = false) {
|
|
342
|
+
return keys.reduce((n, k) => {
|
|
343
|
+
if (k in obj) {
|
|
344
|
+
if (!omitUndefined || !obj[k] === void 0)
|
|
345
|
+
n[k] = obj[k];
|
|
346
|
+
}
|
|
347
|
+
return n;
|
|
348
|
+
}, {});
|
|
401
349
|
}
|
|
402
350
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
*/
|
|
426
|
-
function createSingletonPromise(fn) {
|
|
427
|
-
let _promise;
|
|
428
|
-
function wrapper() {
|
|
429
|
-
if (!_promise)
|
|
430
|
-
_promise = fn();
|
|
431
|
-
return _promise;
|
|
432
|
-
}
|
|
433
|
-
wrapper.reset = async () => {
|
|
434
|
-
const _prev = _promise;
|
|
435
|
-
_promise = undefined;
|
|
436
|
-
if (_prev)
|
|
437
|
-
await _prev;
|
|
438
|
-
};
|
|
439
|
-
return wrapper;
|
|
440
|
-
}
|
|
441
|
-
function invoke(fn) {
|
|
442
|
-
return fn();
|
|
443
|
-
}
|
|
444
|
-
function containsProp(obj, ...props) {
|
|
445
|
-
return props.some(k => k in obj);
|
|
446
|
-
}
|
|
447
|
-
function increaseWithUnit(target, delta) {
|
|
448
|
-
var _a;
|
|
449
|
-
if (typeof target === 'number')
|
|
450
|
-
return target + delta;
|
|
451
|
-
const value = ((_a = target.match(/^-?[0-9]+\.?[0-9]*/)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
452
|
-
const unit = target.slice(value.length);
|
|
453
|
-
const result = (parseFloat(value) + delta);
|
|
454
|
-
if (Number.isNaN(result))
|
|
455
|
-
return target;
|
|
456
|
-
return result + unit;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Create a new subset object by giving keys
|
|
460
|
-
*
|
|
461
|
-
* @category Object
|
|
462
|
-
*/
|
|
463
|
-
function objectPick(obj, keys, omitUndefined = false) {
|
|
464
|
-
return keys.reduce((n, k) => {
|
|
465
|
-
if (k in obj)
|
|
466
|
-
if (!omitUndefined || !obj[k] === undefined)
|
|
467
|
-
n[k] = obj[k];
|
|
468
|
-
return n;
|
|
469
|
-
}, {});
|
|
351
|
+
var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
|
|
352
|
+
var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
|
|
353
|
+
var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
|
|
354
|
+
var __objRest$5 = (source, exclude) => {
|
|
355
|
+
var target = {};
|
|
356
|
+
for (var prop in source)
|
|
357
|
+
if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
358
|
+
target[prop] = source[prop];
|
|
359
|
+
if (source != null && __getOwnPropSymbols$8)
|
|
360
|
+
for (var prop of __getOwnPropSymbols$8(source)) {
|
|
361
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
|
|
362
|
+
target[prop] = source[prop];
|
|
363
|
+
}
|
|
364
|
+
return target;
|
|
365
|
+
};
|
|
366
|
+
function watchWithFilter(source, cb, options = {}) {
|
|
367
|
+
const _a = options, {
|
|
368
|
+
eventFilter = bypassFilter
|
|
369
|
+
} = _a, watchOptions = __objRest$5(_a, [
|
|
370
|
+
"eventFilter"
|
|
371
|
+
]);
|
|
372
|
+
return vueDemi.watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
|
|
470
373
|
}
|
|
471
374
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
375
|
+
var __defProp$6 = Object.defineProperty;
|
|
376
|
+
var __defProps$3 = Object.defineProperties;
|
|
377
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
378
|
+
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
379
|
+
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
380
|
+
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
381
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
382
|
+
var __spreadValues$6 = (a, b) => {
|
|
383
|
+
for (var prop in b || (b = {}))
|
|
384
|
+
if (__hasOwnProp$7.call(b, prop))
|
|
385
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
386
|
+
if (__getOwnPropSymbols$7)
|
|
387
|
+
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
388
|
+
if (__propIsEnum$7.call(b, prop))
|
|
389
|
+
__defNormalProp$6(a, prop, b[prop]);
|
|
390
|
+
}
|
|
391
|
+
return a;
|
|
392
|
+
};
|
|
393
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
394
|
+
var __objRest$4 = (source, exclude) => {
|
|
395
|
+
var target = {};
|
|
396
|
+
for (var prop in source)
|
|
397
|
+
if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
398
|
+
target[prop] = source[prop];
|
|
399
|
+
if (source != null && __getOwnPropSymbols$7)
|
|
400
|
+
for (var prop of __getOwnPropSymbols$7(source)) {
|
|
401
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
|
|
402
|
+
target[prop] = source[prop];
|
|
403
|
+
}
|
|
404
|
+
return target;
|
|
405
|
+
};
|
|
406
|
+
function debouncedWatch(source, cb, options = {}) {
|
|
407
|
+
const _a = options, {
|
|
408
|
+
debounce = 0
|
|
409
|
+
} = _a, watchOptions = __objRest$4(_a, [
|
|
410
|
+
"debounce"
|
|
411
|
+
]);
|
|
412
|
+
return watchWithFilter(source, cb, __spreadProps$3(__spreadValues$6({}, watchOptions), {
|
|
413
|
+
eventFilter: debounceFilter(debounce)
|
|
414
|
+
}));
|
|
476
415
|
}
|
|
477
416
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
417
|
+
function eagerComputed(fn) {
|
|
418
|
+
const result = vueDemi.shallowRef();
|
|
419
|
+
vueDemi.watchSyncEffect(() => {
|
|
420
|
+
result.value = fn();
|
|
421
|
+
});
|
|
422
|
+
return vueDemi.readonly(result);
|
|
482
423
|
}
|
|
483
424
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
result.value = fn();
|
|
489
|
-
});
|
|
490
|
-
return vueDemi.readonly(result);
|
|
425
|
+
function get(obj, key) {
|
|
426
|
+
if (key == null)
|
|
427
|
+
return vueDemi.unref(obj);
|
|
428
|
+
return vueDemi.unref(obj)[key];
|
|
491
429
|
}
|
|
492
430
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
431
|
+
var __defProp$5 = Object.defineProperty;
|
|
432
|
+
var __defProps$2 = Object.defineProperties;
|
|
433
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
434
|
+
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
435
|
+
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
436
|
+
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
437
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
438
|
+
var __spreadValues$5 = (a, b) => {
|
|
439
|
+
for (var prop in b || (b = {}))
|
|
440
|
+
if (__hasOwnProp$6.call(b, prop))
|
|
441
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
442
|
+
if (__getOwnPropSymbols$6)
|
|
443
|
+
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
444
|
+
if (__propIsEnum$6.call(b, prop))
|
|
445
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
446
|
+
}
|
|
447
|
+
return a;
|
|
448
|
+
};
|
|
449
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
450
|
+
var __objRest$3 = (source, exclude) => {
|
|
451
|
+
var target = {};
|
|
452
|
+
for (var prop in source)
|
|
453
|
+
if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
454
|
+
target[prop] = source[prop];
|
|
455
|
+
if (source != null && __getOwnPropSymbols$6)
|
|
456
|
+
for (var prop of __getOwnPropSymbols$6(source)) {
|
|
457
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
|
|
458
|
+
target[prop] = source[prop];
|
|
459
|
+
}
|
|
460
|
+
return target;
|
|
461
|
+
};
|
|
462
|
+
function ignorableWatch(source, cb, options = {}) {
|
|
463
|
+
const _a = options, {
|
|
464
|
+
eventFilter = bypassFilter
|
|
465
|
+
} = _a, watchOptions = __objRest$3(_a, [
|
|
466
|
+
"eventFilter"
|
|
467
|
+
]);
|
|
468
|
+
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
469
|
+
let ignoreUpdates;
|
|
470
|
+
let ignorePrevAsyncUpdates;
|
|
471
|
+
let stop;
|
|
472
|
+
if (watchOptions.flush === "sync") {
|
|
473
|
+
const ignore = vueDemi.ref(false);
|
|
474
|
+
ignorePrevAsyncUpdates = () => {
|
|
475
|
+
};
|
|
476
|
+
ignoreUpdates = (updater) => {
|
|
477
|
+
ignore.value = true;
|
|
478
|
+
updater();
|
|
479
|
+
ignore.value = false;
|
|
480
|
+
};
|
|
481
|
+
stop = vueDemi.watch(source, (...args) => {
|
|
482
|
+
if (!ignore.value)
|
|
483
|
+
filteredCb(...args);
|
|
484
|
+
}, watchOptions);
|
|
485
|
+
} else {
|
|
486
|
+
const disposables = [];
|
|
487
|
+
const ignoreCounter = vueDemi.ref(0);
|
|
488
|
+
const syncCounter = vueDemi.ref(0);
|
|
489
|
+
ignorePrevAsyncUpdates = () => {
|
|
490
|
+
ignoreCounter.value = syncCounter.value;
|
|
491
|
+
};
|
|
492
|
+
disposables.push(vueDemi.watch(source, () => {
|
|
493
|
+
syncCounter.value++;
|
|
494
|
+
}, __spreadProps$2(__spreadValues$5({}, watchOptions), { flush: "sync" })));
|
|
495
|
+
ignoreUpdates = (updater) => {
|
|
496
|
+
const syncCounterPrev = syncCounter.value;
|
|
497
|
+
updater();
|
|
498
|
+
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
499
|
+
};
|
|
500
|
+
disposables.push(vueDemi.watch(source, (...args) => {
|
|
501
|
+
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
502
|
+
ignoreCounter.value = 0;
|
|
503
|
+
syncCounter.value = 0;
|
|
504
|
+
if (ignore)
|
|
505
|
+
return;
|
|
506
|
+
filteredCb(...args);
|
|
507
|
+
}, watchOptions));
|
|
508
|
+
stop = () => {
|
|
509
|
+
disposables.forEach((fn) => fn());
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
var __defProp$4 = Object.defineProperty;
|
|
516
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
517
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
518
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
519
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
520
|
+
var __spreadValues$4 = (a, b) => {
|
|
521
|
+
for (var prop in b || (b = {}))
|
|
522
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
523
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
524
|
+
if (__getOwnPropSymbols$5)
|
|
525
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
526
|
+
if (__propIsEnum$5.call(b, prop))
|
|
527
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
528
|
+
}
|
|
529
|
+
return a;
|
|
530
|
+
};
|
|
531
|
+
function makeDestructurable(obj, arr) {
|
|
532
|
+
if (typeof Symbol !== "undefined") {
|
|
533
|
+
const clone = __spreadValues$4({}, obj);
|
|
534
|
+
Object.defineProperty(clone, Symbol.iterator, {
|
|
535
|
+
enumerable: false,
|
|
536
|
+
value() {
|
|
537
|
+
let index = 0;
|
|
538
|
+
return {
|
|
539
|
+
next: () => ({
|
|
540
|
+
value: arr[index++],
|
|
541
|
+
done: index > arr.length
|
|
542
|
+
})
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
return clone;
|
|
547
|
+
} else {
|
|
548
|
+
return Object.assign([...arr], obj);
|
|
549
|
+
}
|
|
497
550
|
}
|
|
498
551
|
|
|
499
|
-
function
|
|
500
|
-
|
|
501
|
-
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
502
|
-
let ignoreUpdates;
|
|
503
|
-
let ignorePrevAsyncUpdates;
|
|
504
|
-
let stop;
|
|
505
|
-
if (watchOptions.flush === 'sync') {
|
|
506
|
-
const ignore = vueDemi.ref(false);
|
|
507
|
-
// no op for flush: sync
|
|
508
|
-
ignorePrevAsyncUpdates = () => { };
|
|
509
|
-
ignoreUpdates = (updater) => {
|
|
510
|
-
// Call the updater function and count how many sync updates are performed,
|
|
511
|
-
// then add them to the ignore count
|
|
512
|
-
ignore.value = true;
|
|
513
|
-
updater();
|
|
514
|
-
ignore.value = false;
|
|
515
|
-
};
|
|
516
|
-
stop = vueDemi.watch(source, (...args) => {
|
|
517
|
-
if (!ignore.value)
|
|
518
|
-
filteredCb(...args);
|
|
519
|
-
}, watchOptions);
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
// flush 'pre' and 'post'
|
|
523
|
-
const disposables = [];
|
|
524
|
-
// counters for how many following changes to be ignored
|
|
525
|
-
// ignoreCounter is incremented before there is a history operation
|
|
526
|
-
// affecting the source ref value (undo, redo, revert).
|
|
527
|
-
// syncCounter is incremented in sync with every change to the
|
|
528
|
-
// source ref value. This let us know how many times the ref
|
|
529
|
-
// was modified and support chained sync operations. If there
|
|
530
|
-
// are more sync triggers than the ignore count, the we now
|
|
531
|
-
// there are modifications in the source ref value that we
|
|
532
|
-
// need to commit
|
|
533
|
-
const ignoreCounter = vueDemi.ref(0);
|
|
534
|
-
const syncCounter = vueDemi.ref(0);
|
|
535
|
-
ignorePrevAsyncUpdates = () => {
|
|
536
|
-
ignoreCounter.value = syncCounter.value;
|
|
537
|
-
};
|
|
538
|
-
// Sync watch to count modifications to the source
|
|
539
|
-
disposables.push(vueDemi.watch(source, () => {
|
|
540
|
-
syncCounter.value++;
|
|
541
|
-
}, Object.assign(Object.assign({}, watchOptions), { flush: 'sync' })));
|
|
542
|
-
ignoreUpdates = (updater) => {
|
|
543
|
-
// Call the updater function and count how many sync updates are performed,
|
|
544
|
-
// then add them to the ignore count
|
|
545
|
-
const syncCounterPrev = syncCounter.value;
|
|
546
|
-
updater();
|
|
547
|
-
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
548
|
-
};
|
|
549
|
-
disposables.push(vueDemi.watch(source, (...args) => {
|
|
550
|
-
// If a history operation was performed (ignoreCounter > 0) and there are
|
|
551
|
-
// no other changes to the source ref value afterwards, then ignore this commit
|
|
552
|
-
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
553
|
-
ignoreCounter.value = 0;
|
|
554
|
-
syncCounter.value = 0;
|
|
555
|
-
if (ignore)
|
|
556
|
-
return;
|
|
557
|
-
filteredCb(...args);
|
|
558
|
-
}, watchOptions));
|
|
559
|
-
stop = () => {
|
|
560
|
-
disposables.forEach(fn => fn());
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
return { stop, ignoreUpdates, ignorePrevAsyncUpdates };
|
|
552
|
+
function not(v) {
|
|
553
|
+
return vueDemi.computed(() => !vueDemi.unref(v));
|
|
564
554
|
}
|
|
565
555
|
|
|
566
|
-
function
|
|
567
|
-
|
|
568
|
-
const clone = Object.assign({}, obj);
|
|
569
|
-
Object.defineProperty(clone, Symbol.iterator, {
|
|
570
|
-
enumerable: false,
|
|
571
|
-
value() {
|
|
572
|
-
let index = 0;
|
|
573
|
-
return {
|
|
574
|
-
next: () => ({
|
|
575
|
-
value: arr[index++],
|
|
576
|
-
done: index > arr.length,
|
|
577
|
-
}),
|
|
578
|
-
};
|
|
579
|
-
},
|
|
580
|
-
});
|
|
581
|
-
return clone;
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
return Object.assign([...arr], obj);
|
|
585
|
-
}
|
|
556
|
+
function or(...args) {
|
|
557
|
+
return vueDemi.computed(() => args.some((i) => vueDemi.unref(i)));
|
|
586
558
|
}
|
|
587
559
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
560
|
+
var __defProp$3 = Object.defineProperty;
|
|
561
|
+
var __defProps$1 = Object.defineProperties;
|
|
562
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
563
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
564
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
565
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
566
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
567
|
+
var __spreadValues$3 = (a, b) => {
|
|
568
|
+
for (var prop in b || (b = {}))
|
|
569
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
570
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
571
|
+
if (__getOwnPropSymbols$4)
|
|
572
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
573
|
+
if (__propIsEnum$4.call(b, prop))
|
|
574
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
575
|
+
}
|
|
576
|
+
return a;
|
|
577
|
+
};
|
|
578
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
579
|
+
var __objRest$2 = (source, exclude) => {
|
|
580
|
+
var target = {};
|
|
581
|
+
for (var prop in source)
|
|
582
|
+
if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
583
|
+
target[prop] = source[prop];
|
|
584
|
+
if (source != null && __getOwnPropSymbols$4)
|
|
585
|
+
for (var prop of __getOwnPropSymbols$4(source)) {
|
|
586
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
|
|
587
|
+
target[prop] = source[prop];
|
|
588
|
+
}
|
|
589
|
+
return target;
|
|
590
|
+
};
|
|
591
|
+
function pausableWatch(source, cb, options = {}) {
|
|
592
|
+
const _a = options, {
|
|
593
|
+
eventFilter: filter
|
|
594
|
+
} = _a, watchOptions = __objRest$2(_a, [
|
|
595
|
+
"eventFilter"
|
|
596
|
+
]);
|
|
597
|
+
const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
|
|
598
|
+
const stop = watchWithFilter(source, cb, __spreadProps$1(__spreadValues$3({}, watchOptions), {
|
|
599
|
+
eventFilter
|
|
600
|
+
}));
|
|
601
|
+
return { stop, pause, resume, isActive };
|
|
595
602
|
}
|
|
596
603
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
*/
|
|
602
|
-
function or(...args) {
|
|
603
|
-
return vueDemi.computed(() => args.some(i => vueDemi.unref(i)));
|
|
604
|
+
function reactify(fn) {
|
|
605
|
+
return function(...args) {
|
|
606
|
+
return vueDemi.computed(() => fn.apply(this, args.map((i) => vueDemi.unref(i))));
|
|
607
|
+
};
|
|
604
608
|
}
|
|
605
609
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
610
|
+
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
611
|
+
let keys = [];
|
|
612
|
+
if (Array.isArray(optionsOrKeys)) {
|
|
613
|
+
keys = optionsOrKeys;
|
|
614
|
+
} else {
|
|
615
|
+
const { includeOwnProperties = true } = optionsOrKeys;
|
|
616
|
+
keys.push(...Object.keys(obj));
|
|
617
|
+
if (includeOwnProperties)
|
|
618
|
+
keys.push(...Object.getOwnPropertyNames(obj));
|
|
619
|
+
}
|
|
620
|
+
return Object.fromEntries(keys.map((key) => {
|
|
621
|
+
const value = obj[key];
|
|
622
|
+
return [
|
|
623
|
+
key,
|
|
624
|
+
typeof value === "function" ? reactify(value.bind(obj)) : value
|
|
625
|
+
];
|
|
626
|
+
}));
|
|
612
627
|
}
|
|
613
628
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
* The converted function accepts refs as it's arguments
|
|
617
|
-
* and returns a ComputedRef, with proper typing.
|
|
618
|
-
*
|
|
619
|
-
* @param fn - Source function
|
|
620
|
-
*/
|
|
621
|
-
function reactify(fn) {
|
|
622
|
-
return function (...args) {
|
|
623
|
-
return vueDemi.computed(() => fn.apply(this, args.map(i => vueDemi.unref(i))));
|
|
624
|
-
};
|
|
629
|
+
function reactivePick(obj, ...keys) {
|
|
630
|
+
return vueDemi.reactive(Object.fromEntries(keys.map((k) => [k, vueDemi.toRef(obj, k)])));
|
|
625
631
|
}
|
|
626
632
|
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const value = obj[key];
|
|
641
|
-
return [
|
|
642
|
-
key,
|
|
643
|
-
typeof value === 'function'
|
|
644
|
-
? reactify(value.bind(obj))
|
|
645
|
-
: value,
|
|
646
|
-
];
|
|
647
|
-
}));
|
|
633
|
+
function set(...args) {
|
|
634
|
+
if (args.length === 2) {
|
|
635
|
+
const [ref, value] = args;
|
|
636
|
+
ref.value = value;
|
|
637
|
+
}
|
|
638
|
+
if (args.length === 3) {
|
|
639
|
+
if (vueDemi.isVue2) {
|
|
640
|
+
require("vue-demi").set(...args);
|
|
641
|
+
} else {
|
|
642
|
+
const [target, key, value] = args;
|
|
643
|
+
target[key] = value;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
648
646
|
}
|
|
649
647
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
648
|
+
function syncRef(source, targets, {
|
|
649
|
+
flush = "sync",
|
|
650
|
+
deep = false,
|
|
651
|
+
immediate = true
|
|
652
|
+
} = {}) {
|
|
653
|
+
if (!Array.isArray(targets))
|
|
654
|
+
targets = [targets];
|
|
655
|
+
return vueDemi.watch(source, (newValue) => {
|
|
656
|
+
targets.forEach((target) => target.value = newValue);
|
|
657
|
+
}, {
|
|
658
|
+
flush,
|
|
659
|
+
deep,
|
|
660
|
+
immediate
|
|
661
|
+
});
|
|
657
662
|
}
|
|
658
663
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
664
|
+
var __defProp$2 = Object.defineProperty;
|
|
665
|
+
var __defProps = Object.defineProperties;
|
|
666
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
667
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
668
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
669
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
670
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
671
|
+
var __spreadValues$2 = (a, b) => {
|
|
672
|
+
for (var prop in b || (b = {}))
|
|
673
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
674
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
675
|
+
if (__getOwnPropSymbols$3)
|
|
676
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
677
|
+
if (__propIsEnum$3.call(b, prop))
|
|
678
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
679
|
+
}
|
|
680
|
+
return a;
|
|
681
|
+
};
|
|
682
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
683
|
+
var __objRest$1 = (source, exclude) => {
|
|
684
|
+
var target = {};
|
|
685
|
+
for (var prop in source)
|
|
686
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
687
|
+
target[prop] = source[prop];
|
|
688
|
+
if (source != null && __getOwnPropSymbols$3)
|
|
689
|
+
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
690
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
691
|
+
target[prop] = source[prop];
|
|
692
|
+
}
|
|
693
|
+
return target;
|
|
694
|
+
};
|
|
695
|
+
function throttledWatch(source, cb, options = {}) {
|
|
696
|
+
const _a = options, {
|
|
697
|
+
throttle = 0,
|
|
698
|
+
trailing = true
|
|
699
|
+
} = _a, watchOptions = __objRest$1(_a, [
|
|
700
|
+
"throttle",
|
|
701
|
+
"trailing"
|
|
702
|
+
]);
|
|
703
|
+
return watchWithFilter(source, cb, __spreadProps(__spreadValues$2({}, watchOptions), {
|
|
704
|
+
eventFilter: throttleFilter(throttle, trailing)
|
|
705
|
+
}));
|
|
678
706
|
}
|
|
679
707
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
708
|
+
function toReactive(objectRef) {
|
|
709
|
+
if (!vueDemi.isRef(objectRef))
|
|
710
|
+
return vueDemi.reactive(objectRef);
|
|
711
|
+
const proxy = new Proxy({}, {
|
|
712
|
+
get(_, p, receiver) {
|
|
713
|
+
return Reflect.get(objectRef.value, p, receiver);
|
|
714
|
+
},
|
|
715
|
+
set(_, p, value) {
|
|
716
|
+
objectRef.value[p] = value;
|
|
717
|
+
return true;
|
|
718
|
+
},
|
|
719
|
+
deleteProperty(_, p) {
|
|
720
|
+
return Reflect.deleteProperty(objectRef.value, p);
|
|
721
|
+
},
|
|
722
|
+
has(_, p) {
|
|
723
|
+
return Reflect.has(objectRef.value, p);
|
|
724
|
+
},
|
|
725
|
+
ownKeys() {
|
|
726
|
+
return Object.keys(objectRef.value);
|
|
727
|
+
},
|
|
728
|
+
getOwnPropertyDescriptor() {
|
|
729
|
+
return {
|
|
730
|
+
enumerable: true,
|
|
731
|
+
configurable: true
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
return vueDemi.reactive(proxy);
|
|
696
736
|
}
|
|
697
737
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
738
|
+
function toRefs(objectRef) {
|
|
739
|
+
if (!vueDemi.isRef(objectRef))
|
|
740
|
+
return vueDemi.toRefs(objectRef);
|
|
741
|
+
const result = Array.isArray(objectRef.value) ? new Array(objectRef.value.length) : {};
|
|
742
|
+
for (const key in objectRef.value) {
|
|
743
|
+
result[key] = vueDemi.customRef(() => ({
|
|
744
|
+
get() {
|
|
745
|
+
return objectRef.value[key];
|
|
746
|
+
},
|
|
747
|
+
set(v) {
|
|
748
|
+
objectRef.value[key] = v;
|
|
749
|
+
}
|
|
750
|
+
}));
|
|
751
|
+
}
|
|
752
|
+
return result;
|
|
702
753
|
}
|
|
703
754
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
* @see https://vueuse.org/toReactive
|
|
708
|
-
* @param objectRef A ref of object
|
|
709
|
-
*/
|
|
710
|
-
function toReactive(objectRef) {
|
|
711
|
-
if (!vueDemi.isRef(objectRef))
|
|
712
|
-
return vueDemi.reactive(objectRef);
|
|
713
|
-
const proxy = new Proxy({}, {
|
|
714
|
-
get(_, p, receiver) {
|
|
715
|
-
return Reflect.get(objectRef.value, p, receiver);
|
|
716
|
-
},
|
|
717
|
-
set(_, p, value) {
|
|
718
|
-
objectRef.value[p] = value;
|
|
719
|
-
return true;
|
|
720
|
-
},
|
|
721
|
-
deleteProperty(_, p) {
|
|
722
|
-
return Reflect.deleteProperty(objectRef.value, p);
|
|
723
|
-
},
|
|
724
|
-
has(_, p) {
|
|
725
|
-
return Reflect.has(objectRef.value, p);
|
|
726
|
-
},
|
|
727
|
-
ownKeys() {
|
|
728
|
-
return Object.keys(objectRef.value);
|
|
729
|
-
},
|
|
730
|
-
getOwnPropertyDescriptor() {
|
|
731
|
-
return {
|
|
732
|
-
enumerable: true,
|
|
733
|
-
configurable: true,
|
|
734
|
-
};
|
|
735
|
-
},
|
|
736
|
-
});
|
|
737
|
-
return vueDemi.reactive(proxy);
|
|
755
|
+
function tryOnBeforeUnmount(fn) {
|
|
756
|
+
if (vueDemi.getCurrentInstance())
|
|
757
|
+
vueDemi.onBeforeUnmount(fn);
|
|
738
758
|
}
|
|
739
759
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (!vueDemi.isRef(objectRef))
|
|
748
|
-
return vueDemi.toRefs(objectRef);
|
|
749
|
-
const result = Array.isArray(objectRef.value)
|
|
750
|
-
? new Array(objectRef.value.length)
|
|
751
|
-
: {};
|
|
752
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
753
|
-
for (const key in objectRef.value) {
|
|
754
|
-
result[key] = vueDemi.customRef(() => ({
|
|
755
|
-
get() {
|
|
756
|
-
return objectRef.value[key];
|
|
757
|
-
},
|
|
758
|
-
set(v) {
|
|
759
|
-
objectRef.value[key] = v;
|
|
760
|
-
},
|
|
761
|
-
}));
|
|
762
|
-
}
|
|
763
|
-
return result;
|
|
760
|
+
function tryOnMounted(fn, sync = true) {
|
|
761
|
+
if (vueDemi.getCurrentInstance())
|
|
762
|
+
vueDemi.onMounted(fn);
|
|
763
|
+
else if (sync)
|
|
764
|
+
fn();
|
|
765
|
+
else
|
|
766
|
+
vueDemi.nextTick(fn);
|
|
764
767
|
}
|
|
765
768
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
* @param fn
|
|
770
|
-
*/
|
|
771
|
-
function tryOnBeforeUnmount(fn) {
|
|
772
|
-
if (vueDemi.getCurrentInstance())
|
|
773
|
-
vueDemi.onBeforeUnmount(fn);
|
|
769
|
+
function tryOnUnmounted(fn) {
|
|
770
|
+
if (vueDemi.getCurrentInstance())
|
|
771
|
+
vueDemi.onUnmounted(fn);
|
|
774
772
|
}
|
|
775
773
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
774
|
+
function until(r) {
|
|
775
|
+
let isNot = false;
|
|
776
|
+
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
777
|
+
let stop = null;
|
|
778
|
+
const watcher = new Promise((resolve) => {
|
|
779
|
+
stop = vueDemi.watch(r, (v) => {
|
|
780
|
+
if (condition(v) === !isNot) {
|
|
781
|
+
stop == null ? void 0 : stop();
|
|
782
|
+
resolve();
|
|
783
|
+
}
|
|
784
|
+
}, {
|
|
785
|
+
flush,
|
|
786
|
+
deep,
|
|
787
|
+
immediate: true
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
const promises = [watcher];
|
|
791
|
+
if (timeout) {
|
|
792
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
|
|
793
|
+
stop == null ? void 0 : stop();
|
|
794
|
+
}));
|
|
795
|
+
}
|
|
796
|
+
return Promise.race(promises);
|
|
797
|
+
}
|
|
798
|
+
function toBe(value, options) {
|
|
799
|
+
return toMatch((v) => v === vueDemi.unref(value), options);
|
|
800
|
+
}
|
|
801
|
+
function toBeTruthy(options) {
|
|
802
|
+
return toMatch((v) => Boolean(v), options);
|
|
803
|
+
}
|
|
804
|
+
function toBeNull(options) {
|
|
805
|
+
return toBe(null, options);
|
|
806
|
+
}
|
|
807
|
+
function toBeUndefined(options) {
|
|
808
|
+
return toBe(void 0, options);
|
|
809
|
+
}
|
|
810
|
+
function toBeNaN(options) {
|
|
811
|
+
return toMatch(Number.isNaN, options);
|
|
812
|
+
}
|
|
813
|
+
function toContains(value, options) {
|
|
814
|
+
return toMatch((v) => {
|
|
815
|
+
const array = Array.from(v);
|
|
816
|
+
return array.includes(value) || array.includes(vueDemi.unref(value));
|
|
817
|
+
}, options);
|
|
818
|
+
}
|
|
819
|
+
function changed(options) {
|
|
820
|
+
return changedTimes(1, options);
|
|
821
|
+
}
|
|
822
|
+
function changedTimes(n = 1, options) {
|
|
823
|
+
let count = -1;
|
|
824
|
+
return toMatch(() => {
|
|
825
|
+
count += 1;
|
|
826
|
+
return count >= n;
|
|
827
|
+
}, options);
|
|
828
|
+
}
|
|
829
|
+
if (Array.isArray(vueDemi.unref(r))) {
|
|
830
|
+
const instance = {
|
|
831
|
+
toMatch,
|
|
832
|
+
toContains,
|
|
833
|
+
changed,
|
|
834
|
+
changedTimes,
|
|
835
|
+
get not() {
|
|
836
|
+
isNot = !isNot;
|
|
837
|
+
return this;
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
return instance;
|
|
841
|
+
} else {
|
|
842
|
+
const instance = {
|
|
843
|
+
toMatch,
|
|
844
|
+
toBe,
|
|
845
|
+
toBeTruthy,
|
|
846
|
+
toBeNull,
|
|
847
|
+
toBeNaN,
|
|
848
|
+
toBeUndefined,
|
|
849
|
+
changed,
|
|
850
|
+
changedTimes,
|
|
851
|
+
get not() {
|
|
852
|
+
isNot = !isNot;
|
|
853
|
+
return this;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
return instance;
|
|
857
|
+
}
|
|
789
858
|
}
|
|
790
859
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
860
|
+
function useCounter(initialValue = 0) {
|
|
861
|
+
const count = vueDemi.ref(initialValue);
|
|
862
|
+
const inc = (delta = 1) => count.value += delta;
|
|
863
|
+
const dec = (delta = 1) => count.value -= delta;
|
|
864
|
+
const get = () => count.value;
|
|
865
|
+
const set = (val) => count.value = val;
|
|
866
|
+
const reset = (val = initialValue) => {
|
|
867
|
+
initialValue = val;
|
|
868
|
+
return set(val);
|
|
869
|
+
};
|
|
870
|
+
return { count, inc, dec, get, set, reset };
|
|
799
871
|
}
|
|
800
872
|
|
|
801
|
-
function
|
|
802
|
-
|
|
803
|
-
function toMatch(condition, { flush = 'sync', deep = false, timeout, throwOnTimeout } = {}) {
|
|
804
|
-
let stop = null;
|
|
805
|
-
const watcher = new Promise((resolve) => {
|
|
806
|
-
stop = vueDemi.watch(r, (v) => {
|
|
807
|
-
if (condition(v) === !isNot) {
|
|
808
|
-
stop === null || stop === void 0 ? void 0 : stop();
|
|
809
|
-
resolve();
|
|
810
|
-
}
|
|
811
|
-
}, {
|
|
812
|
-
flush,
|
|
813
|
-
deep,
|
|
814
|
-
immediate: true,
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
const promises = [watcher];
|
|
818
|
-
if (timeout) {
|
|
819
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).finally(() => {
|
|
820
|
-
stop === null || stop === void 0 ? void 0 : stop();
|
|
821
|
-
}));
|
|
822
|
-
}
|
|
823
|
-
return Promise.race(promises);
|
|
824
|
-
}
|
|
825
|
-
function toBe(value, options) {
|
|
826
|
-
return toMatch(v => v === vueDemi.unref(value), options);
|
|
827
|
-
}
|
|
828
|
-
function toBeTruthy(options) {
|
|
829
|
-
return toMatch(v => Boolean(v), options);
|
|
830
|
-
}
|
|
831
|
-
function toBeNull(options) {
|
|
832
|
-
return toBe(null, options);
|
|
833
|
-
}
|
|
834
|
-
function toBeUndefined(options) {
|
|
835
|
-
return toBe(undefined, options);
|
|
836
|
-
}
|
|
837
|
-
function toBeNaN(options) {
|
|
838
|
-
return toMatch(Number.isNaN, options);
|
|
839
|
-
}
|
|
840
|
-
function toContains(value, options) {
|
|
841
|
-
return toMatch((v) => {
|
|
842
|
-
const array = Array.from(v);
|
|
843
|
-
return array.includes(value) || array.includes(vueDemi.unref(value));
|
|
844
|
-
}, options);
|
|
845
|
-
}
|
|
846
|
-
function changed(options) {
|
|
847
|
-
return changedTimes(1, options);
|
|
848
|
-
}
|
|
849
|
-
function changedTimes(n = 1, options) {
|
|
850
|
-
let count = -1; // skip the immediate check
|
|
851
|
-
return toMatch(() => {
|
|
852
|
-
count += 1;
|
|
853
|
-
return count >= n;
|
|
854
|
-
}, options);
|
|
855
|
-
}
|
|
856
|
-
if (Array.isArray(vueDemi.unref(r))) {
|
|
857
|
-
const instance = {
|
|
858
|
-
toMatch,
|
|
859
|
-
toContains,
|
|
860
|
-
changed,
|
|
861
|
-
changedTimes,
|
|
862
|
-
get not() {
|
|
863
|
-
isNot = !isNot;
|
|
864
|
-
return this;
|
|
865
|
-
},
|
|
866
|
-
};
|
|
867
|
-
return instance;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
const instance = {
|
|
871
|
-
toMatch,
|
|
872
|
-
toBe,
|
|
873
|
-
toBeTruthy,
|
|
874
|
-
toBeNull,
|
|
875
|
-
toBeNaN,
|
|
876
|
-
toBeUndefined,
|
|
877
|
-
changed,
|
|
878
|
-
changedTimes,
|
|
879
|
-
get not() {
|
|
880
|
-
isNot = !isNot;
|
|
881
|
-
return this;
|
|
882
|
-
},
|
|
883
|
-
};
|
|
884
|
-
return instance;
|
|
885
|
-
}
|
|
873
|
+
function useDebounceFn(fn, ms = 200) {
|
|
874
|
+
return createFilterWrapper(debounceFilter(ms), fn);
|
|
886
875
|
}
|
|
887
876
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const dec = (delta = 1) => (count.value -= delta);
|
|
898
|
-
const get = () => count.value;
|
|
899
|
-
const set = (val) => (count.value = val);
|
|
900
|
-
const reset = (val = initialValue) => {
|
|
901
|
-
initialValue = val;
|
|
902
|
-
return set(val);
|
|
903
|
-
};
|
|
904
|
-
return { count, inc, dec, get, set, reset };
|
|
877
|
+
function useDebounce(value, ms = 200) {
|
|
878
|
+
if (ms <= 0)
|
|
879
|
+
return value;
|
|
880
|
+
const debounced = vueDemi.ref(value.value);
|
|
881
|
+
const updater = useDebounceFn(() => {
|
|
882
|
+
debounced.value = value.value;
|
|
883
|
+
}, ms);
|
|
884
|
+
vueDemi.watch(value, () => updater());
|
|
885
|
+
return debounced;
|
|
905
886
|
}
|
|
906
887
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
888
|
+
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
889
|
+
const {
|
|
890
|
+
immediate = true,
|
|
891
|
+
immediateCallback = false
|
|
892
|
+
} = options;
|
|
893
|
+
let timer = null;
|
|
894
|
+
const isActive = vueDemi.ref(false);
|
|
895
|
+
function clean() {
|
|
896
|
+
if (timer) {
|
|
897
|
+
clearInterval(timer);
|
|
898
|
+
timer = null;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function pause() {
|
|
902
|
+
isActive.value = false;
|
|
903
|
+
clean();
|
|
904
|
+
}
|
|
905
|
+
function resume() {
|
|
906
|
+
if (interval <= 0)
|
|
907
|
+
return;
|
|
908
|
+
isActive.value = true;
|
|
909
|
+
if (immediateCallback)
|
|
910
|
+
cb();
|
|
911
|
+
clean();
|
|
912
|
+
timer = setInterval(cb, interval);
|
|
913
|
+
}
|
|
914
|
+
if (immediate && isClient)
|
|
915
|
+
resume();
|
|
916
|
+
tryOnScopeDispose(pause);
|
|
917
|
+
return {
|
|
918
|
+
isActive,
|
|
919
|
+
pause,
|
|
920
|
+
resume
|
|
921
|
+
};
|
|
917
922
|
}
|
|
918
923
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
924
|
+
var __defProp$1 = Object.defineProperty;
|
|
925
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
926
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
927
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
928
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
929
|
+
var __spreadValues$1 = (a, b) => {
|
|
930
|
+
for (var prop in b || (b = {}))
|
|
931
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
932
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
933
|
+
if (__getOwnPropSymbols$2)
|
|
934
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
935
|
+
if (__propIsEnum$2.call(b, prop))
|
|
936
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
937
|
+
}
|
|
938
|
+
return a;
|
|
939
|
+
};
|
|
940
|
+
function useInterval(interval = 1e3, options = {}) {
|
|
941
|
+
const {
|
|
942
|
+
controls: exposeControls = false,
|
|
943
|
+
immediate = true
|
|
944
|
+
} = options;
|
|
945
|
+
const counter = vueDemi.ref(0);
|
|
946
|
+
const controls = useIntervalFn(() => counter.value += 1, interval, { immediate });
|
|
947
|
+
if (exposeControls) {
|
|
948
|
+
return __spreadValues$1({
|
|
949
|
+
counter
|
|
950
|
+
}, controls);
|
|
951
|
+
} else {
|
|
952
|
+
return counter;
|
|
953
|
+
}
|
|
928
954
|
}
|
|
929
955
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
* @param options
|
|
936
|
-
*/
|
|
937
|
-
function useIntervalFn(cb, interval = 1000, options = {}) {
|
|
938
|
-
const { immediate = true, immediateCallback = false, } = options;
|
|
939
|
-
let timer = null;
|
|
940
|
-
const isActive = vueDemi.ref(false);
|
|
941
|
-
function clean() {
|
|
942
|
-
if (timer) {
|
|
943
|
-
clearInterval(timer);
|
|
944
|
-
timer = null;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
function pause() {
|
|
948
|
-
isActive.value = false;
|
|
949
|
-
clean();
|
|
950
|
-
}
|
|
951
|
-
function resume() {
|
|
952
|
-
if (interval <= 0)
|
|
953
|
-
return;
|
|
954
|
-
isActive.value = true;
|
|
955
|
-
if (immediateCallback)
|
|
956
|
-
cb();
|
|
957
|
-
clean();
|
|
958
|
-
timer = setInterval(cb, interval);
|
|
959
|
-
}
|
|
960
|
-
if (immediate && isClient)
|
|
961
|
-
resume();
|
|
962
|
-
tryOnScopeDispose(pause);
|
|
963
|
-
return {
|
|
964
|
-
isActive,
|
|
965
|
-
pause,
|
|
966
|
-
resume,
|
|
967
|
-
};
|
|
956
|
+
function useLastChanged(source, options = {}) {
|
|
957
|
+
var _a;
|
|
958
|
+
const ms = vueDemi.ref((_a = options.initialValue) != null ? _a : null);
|
|
959
|
+
vueDemi.watch(source, () => ms.value = timestamp(), options);
|
|
960
|
+
return ms;
|
|
968
961
|
}
|
|
969
962
|
|
|
970
|
-
function
|
|
971
|
-
|
|
972
|
-
const counter = vueDemi.ref(0);
|
|
973
|
-
const controls = useIntervalFn(() => counter.value += 1, interval, { immediate });
|
|
974
|
-
if (exposeControls) {
|
|
975
|
-
return Object.assign({ counter }, controls);
|
|
976
|
-
}
|
|
977
|
-
else {
|
|
978
|
-
return counter;
|
|
979
|
-
}
|
|
963
|
+
function useThrottleFn(fn, ms = 200, trailing = true, leading = true) {
|
|
964
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
980
965
|
}
|
|
981
966
|
|
|
982
|
-
function
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
967
|
+
function useThrottle(value, delay = 200, trailing = true, leading = true) {
|
|
968
|
+
if (delay <= 0)
|
|
969
|
+
return value;
|
|
970
|
+
const throttled = vueDemi.ref(value.value);
|
|
971
|
+
const updater = useThrottleFn(() => {
|
|
972
|
+
throttled.value = value.value;
|
|
973
|
+
}, delay, trailing, leading);
|
|
974
|
+
vueDemi.watch(value, () => updater());
|
|
975
|
+
return throttled;
|
|
987
976
|
}
|
|
988
977
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
978
|
+
function useTimeoutFn(cb, interval, options = {}) {
|
|
979
|
+
const {
|
|
980
|
+
immediate = true
|
|
981
|
+
} = options;
|
|
982
|
+
const isPending = vueDemi.ref(false);
|
|
983
|
+
let timer = null;
|
|
984
|
+
function clear() {
|
|
985
|
+
if (timer) {
|
|
986
|
+
clearTimeout(timer);
|
|
987
|
+
timer = null;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
function stop() {
|
|
991
|
+
isPending.value = false;
|
|
992
|
+
clear();
|
|
993
|
+
}
|
|
994
|
+
function start(...args) {
|
|
995
|
+
clear();
|
|
996
|
+
isPending.value = true;
|
|
997
|
+
timer = setTimeout(() => {
|
|
998
|
+
isPending.value = false;
|
|
999
|
+
timer = null;
|
|
1000
|
+
cb(...args);
|
|
1001
|
+
}, vueDemi.unref(interval));
|
|
1002
|
+
}
|
|
1003
|
+
if (immediate) {
|
|
1004
|
+
isPending.value = true;
|
|
1005
|
+
if (isClient)
|
|
1006
|
+
start();
|
|
1007
|
+
}
|
|
1008
|
+
tryOnScopeDispose(stop);
|
|
1009
|
+
return {
|
|
1010
|
+
isPending,
|
|
1011
|
+
start,
|
|
1012
|
+
stop
|
|
1013
|
+
};
|
|
1001
1014
|
}
|
|
1002
1015
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
if (
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1016
|
+
var __defProp = Object.defineProperty;
|
|
1017
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1018
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1019
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1020
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1021
|
+
var __spreadValues = (a, b) => {
|
|
1022
|
+
for (var prop in b || (b = {}))
|
|
1023
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1024
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1025
|
+
if (__getOwnPropSymbols$1)
|
|
1026
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1027
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1028
|
+
__defNormalProp(a, prop, b[prop]);
|
|
1029
|
+
}
|
|
1030
|
+
return a;
|
|
1031
|
+
};
|
|
1032
|
+
function useTimeout(interval = 1e3, options = {}) {
|
|
1033
|
+
const {
|
|
1034
|
+
controls: exposeControls = false
|
|
1035
|
+
} = options;
|
|
1036
|
+
const controls = useTimeoutFn(noop, interval, options);
|
|
1037
|
+
const ready = vueDemi.computed(() => !controls.isPending.value);
|
|
1038
|
+
if (exposeControls) {
|
|
1039
|
+
return __spreadValues({
|
|
1040
|
+
ready
|
|
1041
|
+
}, controls);
|
|
1042
|
+
} else {
|
|
1043
|
+
return ready;
|
|
1044
|
+
}
|
|
1018
1045
|
}
|
|
1019
1046
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
if (timer) {
|
|
1033
|
-
clearTimeout(timer);
|
|
1034
|
-
timer = null;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
function stop() {
|
|
1038
|
-
isPending.value = false;
|
|
1039
|
-
clear();
|
|
1040
|
-
}
|
|
1041
|
-
function start(...args) {
|
|
1042
|
-
clear();
|
|
1043
|
-
isPending.value = true;
|
|
1044
|
-
timer = setTimeout(() => {
|
|
1045
|
-
isPending.value = false;
|
|
1046
|
-
timer = null;
|
|
1047
|
-
// eslint-disable-next-line node/no-callback-literal
|
|
1048
|
-
cb(...args);
|
|
1049
|
-
}, vueDemi.unref(interval));
|
|
1050
|
-
}
|
|
1051
|
-
if (immediate) {
|
|
1052
|
-
isPending.value = true;
|
|
1053
|
-
if (isClient)
|
|
1054
|
-
start();
|
|
1055
|
-
}
|
|
1056
|
-
tryOnScopeDispose(stop);
|
|
1057
|
-
return {
|
|
1058
|
-
isPending,
|
|
1059
|
-
start,
|
|
1060
|
-
stop,
|
|
1061
|
-
};
|
|
1047
|
+
function useToggle(initialValue = false) {
|
|
1048
|
+
if (vueDemi.isRef(initialValue)) {
|
|
1049
|
+
return (value) => {
|
|
1050
|
+
initialValue.value = typeof value === "boolean" ? value : !initialValue.value;
|
|
1051
|
+
};
|
|
1052
|
+
} else {
|
|
1053
|
+
const boolean = vueDemi.ref(initialValue);
|
|
1054
|
+
const toggle = (value) => {
|
|
1055
|
+
boolean.value = typeof value === "boolean" ? value : !boolean.value;
|
|
1056
|
+
};
|
|
1057
|
+
return [boolean, toggle];
|
|
1058
|
+
}
|
|
1062
1059
|
}
|
|
1063
1060
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1061
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1062
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1063
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1064
|
+
var __objRest = (source, exclude) => {
|
|
1065
|
+
var target = {};
|
|
1066
|
+
for (var prop in source)
|
|
1067
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1068
|
+
target[prop] = source[prop];
|
|
1069
|
+
if (source != null && __getOwnPropSymbols)
|
|
1070
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
1071
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
1072
|
+
target[prop] = source[prop];
|
|
1073
|
+
}
|
|
1074
|
+
return target;
|
|
1075
|
+
};
|
|
1076
|
+
function watchAtMost(source, cb, options) {
|
|
1077
|
+
const _a = options, {
|
|
1078
|
+
count
|
|
1079
|
+
} = _a, watchOptions = __objRest(_a, [
|
|
1080
|
+
"count"
|
|
1081
|
+
]);
|
|
1082
|
+
const current = vueDemi.ref(0);
|
|
1083
|
+
const stop = watchWithFilter(source, (...args) => {
|
|
1084
|
+
current.value += 1;
|
|
1085
|
+
if (current.value >= vueDemi.unref(count))
|
|
1086
|
+
stop();
|
|
1087
|
+
cb(...args);
|
|
1088
|
+
}, watchOptions);
|
|
1089
|
+
return { count: current, stop };
|
|
1074
1090
|
}
|
|
1075
1091
|
|
|
1076
|
-
function
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
: !initialValue.value;
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
else {
|
|
1085
|
-
const boolean = vueDemi.ref(initialValue);
|
|
1086
|
-
const toggle = (value) => {
|
|
1087
|
-
boolean.value = typeof value === 'boolean'
|
|
1088
|
-
? value
|
|
1089
|
-
: !boolean.value;
|
|
1090
|
-
};
|
|
1091
|
-
return [boolean, toggle];
|
|
1092
|
-
}
|
|
1092
|
+
function watchOnce(source, cb, options) {
|
|
1093
|
+
const stop = vueDemi.watch(source, (...args) => {
|
|
1094
|
+
stop();
|
|
1095
|
+
return cb(...args);
|
|
1096
|
+
}, options);
|
|
1093
1097
|
}
|
|
1094
1098
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
function whenever(source, cb, options) {
|
|
1101
|
-
return vueDemi.watch(source, (v, ov, onInvalidate) => { if (v)
|
|
1102
|
-
cb(v, ov, onInvalidate); }, options);
|
|
1099
|
+
function whenever(source, cb, options) {
|
|
1100
|
+
return vueDemi.watch(source, (v, ov, onInvalidate) => {
|
|
1101
|
+
if (v)
|
|
1102
|
+
cb(v, ov, onInvalidate);
|
|
1103
|
+
}, options);
|
|
1103
1104
|
}
|
|
1104
1105
|
|
|
1105
1106
|
exports.and = and;
|
|
@@ -1168,5 +1169,7 @@ exports.useThrottleFn = useThrottleFn;
|
|
|
1168
1169
|
exports.useTimeout = useTimeout;
|
|
1169
1170
|
exports.useTimeoutFn = useTimeoutFn;
|
|
1170
1171
|
exports.useToggle = useToggle;
|
|
1172
|
+
exports.watchAtMost = watchAtMost;
|
|
1173
|
+
exports.watchOnce = watchOnce;
|
|
1171
1174
|
exports.watchWithFilter = watchWithFilter;
|
|
1172
1175
|
exports.whenever = whenever;
|