@reactive-vscode/vueuse 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const reactivity = require("@reactive-vscode/reactivity");
4
- function computedWithControl(source, fn) {
4
+ function computedWithControl(source, fn, options = {}) {
5
5
  let v = void 0;
6
6
  let track;
7
7
  let trigger;
8
- const dirty = reactivity.shallowRef(true);
8
+ let dirty = true;
9
9
  const update = () => {
10
- dirty.value = true;
10
+ dirty = true;
11
11
  trigger();
12
12
  };
13
- reactivity.watch(source, update, { flush: "sync" });
13
+ reactivity.watch(source, update, { flush: "sync", ...options });
14
14
  const get2 = typeof fn === "function" ? fn : fn.get;
15
15
  const set2 = typeof fn === "function" ? void 0 : fn.set;
16
16
  const result = reactivity.customRef((_track, _trigger) => {
@@ -18,9 +18,9 @@ function computedWithControl(source, fn) {
18
18
  trigger = _trigger;
19
19
  return {
20
20
  get() {
21
- if (dirty.value) {
21
+ if (dirty) {
22
22
  v = get2(v);
23
- dirty.value = false;
23
+ dirty = false;
24
24
  }
25
25
  track();
26
26
  return v;
@@ -30,8 +30,7 @@ function computedWithControl(source, fn) {
30
30
  }
31
31
  };
32
32
  });
33
- if (Object.isExtensible(result))
34
- result.trigger = update;
33
+ result.trigger = update;
35
34
  return result;
36
35
  }
37
36
  function tryOnScopeDispose(fn) {
@@ -41,6 +40,7 @@ function tryOnScopeDispose(fn) {
41
40
  }
42
41
  return false;
43
42
  }
43
+ // @__NO_SIDE_EFFECTS__
44
44
  function createEventHook() {
45
45
  const fns = /* @__PURE__ */ new Set();
46
46
  const off = (fn) => {
@@ -67,6 +67,7 @@ function createEventHook() {
67
67
  clear
68
68
  };
69
69
  }
70
+ // @__NO_SIDE_EFFECTS__
70
71
  function createGlobalState(stateFactory) {
71
72
  let initialized = false;
72
73
  let state;
@@ -79,6 +80,7 @@ function createGlobalState(stateFactory) {
79
80
  return state;
80
81
  };
81
82
  }
83
+ // @__NO_SIDE_EFFECTS__
82
84
  function createRef(value, deep) {
83
85
  if (deep === true) {
84
86
  return reactivity.ref(value);
@@ -86,6 +88,7 @@ function createRef(value, deep) {
86
88
  return reactivity.shallowRef(value);
87
89
  }
88
90
  }
91
+ // @__NO_SIDE_EFFECTS__
89
92
  function createSharedComposable(composable) {
90
93
  let subscribers = 0;
91
94
  let state;
@@ -136,6 +139,7 @@ function get(obj, key) {
136
139
  function isDefined(v) {
137
140
  return reactivity.unref(v) != null;
138
141
  }
142
+ // @__NO_SIDE_EFFECTS__
139
143
  function makeDestructurable(obj, arr) {
140
144
  if (typeof Symbol !== "undefined") {
141
145
  const clone = { ...obj };
@@ -156,12 +160,14 @@ function makeDestructurable(obj, arr) {
156
160
  return Object.assign([...arr], obj);
157
161
  }
158
162
  }
163
+ // @__NO_SIDE_EFFECTS__
159
164
  function reactify(fn, options) {
160
165
  const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? reactivity.unref : reactivity.toValue;
161
166
  return function(...args) {
162
167
  return reactivity.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
163
168
  };
164
169
  }
170
+ // @__NO_SIDE_EFFECTS__
165
171
  function reactifyObject(obj, optionsOrKeys = {}) {
166
172
  let keys = [];
167
173
  let options;
@@ -179,7 +185,7 @@ function reactifyObject(obj, optionsOrKeys = {}) {
179
185
  const value = obj[key];
180
186
  return [
181
187
  key,
182
- typeof value === "function" ? reactify(value.bind(obj), options) : value
188
+ typeof value === "function" ? /* @__PURE__ */ reactify(value.bind(obj), options) : value
183
189
  ];
184
190
  })
185
191
  );
@@ -245,6 +251,43 @@ const rand = (min, max) => {
245
251
  return Math.floor(Math.random() * (max - min + 1)) + min;
246
252
  };
247
253
  const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
254
+ function toRef(...args) {
255
+ if (args.length !== 1)
256
+ return reactivity.toRef(...args);
257
+ const r = args[0];
258
+ return typeof r === "function" ? reactivity.readonly(reactivity.customRef(() => ({ get: r, set: noop }))) : reactivity.ref(r);
259
+ }
260
+ const resolveRef = toRef;
261
+ function reactivePick(obj, ...keys) {
262
+ const flatKeys = keys.flat();
263
+ const predicate = flatKeys[0];
264
+ return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(reactivity.toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
265
+ }
266
+ function refAutoReset(defaultValue, afterMs = 1e4) {
267
+ return reactivity.customRef((track, trigger) => {
268
+ let value = reactivity.toValue(defaultValue);
269
+ let timer;
270
+ const resetAfter = () => setTimeout(() => {
271
+ value = reactivity.toValue(defaultValue);
272
+ trigger();
273
+ }, reactivity.toValue(afterMs));
274
+ tryOnScopeDispose(() => {
275
+ clearTimeout(timer);
276
+ });
277
+ return {
278
+ get() {
279
+ track();
280
+ return value;
281
+ },
282
+ set(newValue) {
283
+ value = newValue;
284
+ trigger();
285
+ clearTimeout(timer);
286
+ timer = resetAfter();
287
+ }
288
+ };
289
+ });
290
+ }
248
291
  function createFilterWrapper(filter, fn) {
249
292
  function wrapper(...args) {
250
293
  return new Promise((resolve, reject) => {
@@ -274,7 +317,7 @@ function debounceFilter(ms, options = {}) {
274
317
  if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
275
318
  if (maxTimer) {
276
319
  _clearTimeout(maxTimer);
277
- maxTimer = null;
320
+ maxTimer = void 0;
278
321
  }
279
322
  return Promise.resolve(invoke2());
280
323
  }
@@ -285,14 +328,14 @@ function debounceFilter(ms, options = {}) {
285
328
  maxTimer = setTimeout(() => {
286
329
  if (timer)
287
330
  _clearTimeout(timer);
288
- maxTimer = null;
331
+ maxTimer = void 0;
289
332
  resolve(lastInvoker());
290
333
  }, maxDuration);
291
334
  }
292
335
  timer = setTimeout(() => {
293
336
  if (maxTimer)
294
337
  _clearTimeout(maxTimer);
295
- maxTimer = null;
338
+ maxTimer = void 0;
296
339
  resolve(invoke2());
297
340
  }, duration);
298
341
  });
@@ -370,19 +413,6 @@ function pausableFilter(extendFilter = bypassFilter, options = {}) {
370
413
  };
371
414
  return { isActive: reactivity.readonly(isActive), pause, resume, eventFilter };
372
415
  }
373
- function cacheStringFunction(fn) {
374
- const cache = /* @__PURE__ */ Object.create(null);
375
- return (str) => {
376
- const hit = cache[str];
377
- return hit || (cache[str] = fn(str));
378
- };
379
- }
380
- const hyphenateRE = /\B([A-Z])/g;
381
- const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
382
- const camelizeRE = /-(\w)/g;
383
- const camelize = cacheStringFunction((str) => {
384
- return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
385
- });
386
416
  function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
387
417
  return new Promise((resolve, reject) => {
388
418
  if (throwOnTimeout)
@@ -443,49 +473,26 @@ function objectOmit(obj, keys, omitUndefined = false) {
443
473
  function objectEntries(obj) {
444
474
  return Object.entries(obj);
445
475
  }
446
- function getLifeCycleTarget(target) {
447
- return target || null;
448
- }
449
476
  function toArray(value) {
450
477
  return Array.isArray(value) ? value : [value];
451
478
  }
452
- function toRef(...args) {
453
- if (args.length !== 1)
454
- return reactivity.toRef(...args);
455
- const r = args[0];
456
- return typeof r === "function" ? reactivity.readonly(reactivity.customRef(() => ({ get: r, set: noop }))) : reactivity.ref(r);
457
- }
458
- const resolveRef = toRef;
459
- function reactivePick(obj, ...keys) {
460
- const flatKeys = keys.flat();
461
- const predicate = flatKeys[0];
462
- return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(reactivity.toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
479
+ function cacheStringFunction(fn) {
480
+ const cache = /* @__PURE__ */ Object.create(null);
481
+ return (str) => {
482
+ const hit = cache[str];
483
+ return hit || (cache[str] = fn(str));
484
+ };
463
485
  }
464
- function refAutoReset(defaultValue, afterMs = 1e4) {
465
- return reactivity.customRef((track, trigger) => {
466
- let value = reactivity.toValue(defaultValue);
467
- let timer;
468
- const resetAfter = () => setTimeout(() => {
469
- value = reactivity.toValue(defaultValue);
470
- trigger();
471
- }, reactivity.toValue(afterMs));
472
- tryOnScopeDispose(() => {
473
- clearTimeout(timer);
474
- });
475
- return {
476
- get() {
477
- track();
478
- return value;
479
- },
480
- set(newValue) {
481
- value = newValue;
482
- trigger();
483
- clearTimeout(timer);
484
- timer = resetAfter();
485
- }
486
- };
487
- });
486
+ const hyphenateRE = /\B([A-Z])/g;
487
+ const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
488
+ const camelizeRE = /-(\w)/g;
489
+ const camelize = cacheStringFunction((str) => {
490
+ return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
491
+ });
492
+ function getLifeCycleTarget(target) {
493
+ return target || null;
488
494
  }
495
+ // @__NO_SIDE_EFFECTS__
489
496
  function useDebounceFn(fn, ms = 200, options = {}) {
490
497
  return createFilterWrapper(
491
498
  debounceFilter(ms, options),
@@ -493,13 +500,14 @@ function useDebounceFn(fn, ms = 200, options = {}) {
493
500
  );
494
501
  }
495
502
  function refDebounced(value, ms = 200, options = {}) {
496
- const debounced = reactivity.ref(value.value);
497
- const updater = useDebounceFn(() => {
503
+ const debounced = reactivity.ref(reactivity.toValue(value));
504
+ const updater = /* @__PURE__ */ useDebounceFn(() => {
498
505
  debounced.value = value.value;
499
506
  }, ms, options);
500
507
  reactivity.watch(value, () => updater());
501
- return debounced;
508
+ return reactivity.shallowReadonly(debounced);
502
509
  }
510
+ // @__NO_SIDE_EFFECTS__
503
511
  function refDefault(source, defaultValue) {
504
512
  return reactivity.computed({
505
513
  get() {
@@ -511,6 +519,7 @@ function refDefault(source, defaultValue) {
511
519
  }
512
520
  });
513
521
  }
522
+ // @__NO_SIDE_EFFECTS__
514
523
  function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
515
524
  return createFilterWrapper(
516
525
  throttleFilter(ms, trailing, leading, rejectOnCancel),
@@ -520,13 +529,14 @@ function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnC
520
529
  function refThrottled(value, delay = 200, trailing = true, leading = true) {
521
530
  if (delay <= 0)
522
531
  return value;
523
- const throttled = reactivity.ref(value.value);
524
- const updater = useThrottleFn(() => {
532
+ const throttled = reactivity.ref(reactivity.toValue(value));
533
+ const updater = /* @__PURE__ */ useThrottleFn(() => {
525
534
  throttled.value = value.value;
526
535
  }, delay, trailing, leading);
527
536
  reactivity.watch(value, () => updater());
528
537
  return throttled;
529
538
  }
539
+ // @__NO_SIDE_EFFECTS__
530
540
  function refWithControl(initial, options = {}) {
531
541
  let source = initial;
532
542
  let track;
@@ -703,7 +713,10 @@ function toRefs(objectRef, options = {}) {
703
713
  const toValue = reactivity.toValue;
704
714
  const resolveUnref = reactivity.toValue;
705
715
  function tryOnMounted(fn, sync = true, target) {
706
- if (sync)
716
+ const instance = getLifeCycleTarget(target);
717
+ if (instance)
718
+ ;
719
+ else if (sync)
707
720
  fn();
708
721
  else
709
722
  reactivity.nextTick(fn);
@@ -835,6 +848,7 @@ function until(r) {
835
848
  function defaultComparator(value, othVal) {
836
849
  return value === othVal;
837
850
  }
851
+ // @__NO_SIDE_EFFECTS__
838
852
  function useArrayDifference(...args) {
839
853
  var _a, _b;
840
854
  const list = args[0];
@@ -855,17 +869,21 @@ function useArrayDifference(...args) {
855
869
  return diff1;
856
870
  }
857
871
  }
872
+ // @__NO_SIDE_EFFECTS__
858
873
  function useArrayEvery(list, fn) {
859
874
  return reactivity.computed(() => reactivity.toValue(list).every((element, index, array) => fn(reactivity.toValue(element), index, array)));
860
875
  }
876
+ // @__NO_SIDE_EFFECTS__
861
877
  function useArrayFilter(list, fn) {
862
878
  return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).filter(fn));
863
879
  }
880
+ // @__NO_SIDE_EFFECTS__
864
881
  function useArrayFind(list, fn) {
865
882
  return reactivity.computed(() => reactivity.toValue(
866
883
  reactivity.toValue(list).find((element, index, array) => fn(reactivity.toValue(element), index, array))
867
884
  ));
868
885
  }
886
+ // @__NO_SIDE_EFFECTS__
869
887
  function useArrayFindIndex(list, fn) {
870
888
  return reactivity.computed(() => reactivity.toValue(list).findIndex((element, index, array) => fn(reactivity.toValue(element), index, array)));
871
889
  }
@@ -877,6 +895,7 @@ function findLast(arr, cb) {
877
895
  }
878
896
  return void 0;
879
897
  }
898
+ // @__NO_SIDE_EFFECTS__
880
899
  function useArrayFindLast(list, fn) {
881
900
  return reactivity.computed(() => reactivity.toValue(
882
901
  !Array.prototype.findLast ? findLast(reactivity.toValue(list), (element, index, array) => fn(reactivity.toValue(element), index, array)) : reactivity.toValue(list).findLast((element, index, array) => fn(reactivity.toValue(element), index, array))
@@ -885,6 +904,7 @@ function useArrayFindLast(list, fn) {
885
904
  function isArrayIncludesOptions(obj) {
886
905
  return isObject(obj) && containsProp(obj, "formIndex", "comparator");
887
906
  }
907
+ // @__NO_SIDE_EFFECTS__
888
908
  function useArrayIncludes(...args) {
889
909
  var _a;
890
910
  const list = args[0];
@@ -907,12 +927,15 @@ function useArrayIncludes(...args) {
907
927
  reactivity.toValue(array)
908
928
  )));
909
929
  }
930
+ // @__NO_SIDE_EFFECTS__
910
931
  function useArrayJoin(list, separator) {
911
932
  return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).join(reactivity.toValue(separator)));
912
933
  }
934
+ // @__NO_SIDE_EFFECTS__
913
935
  function useArrayMap(list, fn) {
914
936
  return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).map(fn));
915
937
  }
938
+ // @__NO_SIDE_EFFECTS__
916
939
  function useArrayReduce(list, reducer, ...args) {
917
940
  const reduceCallback = (sum, value, index) => reducer(reactivity.toValue(sum), reactivity.toValue(value), index);
918
941
  return reactivity.computed(() => {
@@ -920,6 +943,7 @@ function useArrayReduce(list, reducer, ...args) {
920
943
  return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? reactivity.toValue(args[0]()) : reactivity.toValue(args[0])) : resolved.reduce(reduceCallback);
921
944
  });
922
945
  }
946
+ // @__NO_SIDE_EFFECTS__
923
947
  function useArraySome(list, fn) {
924
948
  return reactivity.computed(() => reactivity.toValue(list).some((element, index, array) => fn(reactivity.toValue(element), index, array)));
925
949
  }
@@ -933,6 +957,7 @@ function uniqueElementsBy(array, fn) {
933
957
  return acc;
934
958
  }, []);
935
959
  }
960
+ // @__NO_SIDE_EFFECTS__
936
961
  function useArrayUnique(list, compareFn) {
937
962
  return reactivity.computed(() => {
938
963
  const resolvedList = reactivity.toValue(list).map((element) => reactivity.toValue(element));
@@ -954,7 +979,7 @@ function useCounter(initialValue = 0, options = {}) {
954
979
  _initialValue = val;
955
980
  return set2(val);
956
981
  };
957
- return { count, inc, dec, get: get2, set: set2, reset };
982
+ return { count: reactivity.shallowReadonly(count), inc, dec, get: get2, set: set2, reset };
958
983
  }
959
984
  const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
960
985
  const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
@@ -1044,6 +1069,7 @@ function normalizeDate(date) {
1044
1069
  }
1045
1070
  return new Date(date);
1046
1071
  }
1072
+ // @__NO_SIDE_EFFECTS__
1047
1073
  function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
1048
1074
  return reactivity.computed(() => formatDate(normalizeDate(reactivity.toValue(date)), reactivity.toValue(formatStr), options));
1049
1075
  }
@@ -1086,7 +1112,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
1086
1112
  }
1087
1113
  tryOnScopeDispose(pause);
1088
1114
  return {
1089
- isActive,
1115
+ isActive: reactivity.shallowReadonly(isActive),
1090
1116
  pause,
1091
1117
  resume
1092
1118
  };
@@ -1112,12 +1138,12 @@ function useInterval(interval = 1e3, options = {}) {
1112
1138
  );
1113
1139
  if (exposeControls) {
1114
1140
  return {
1115
- counter,
1141
+ counter: reactivity.shallowReadonly(counter),
1116
1142
  reset,
1117
1143
  ...controls
1118
1144
  };
1119
1145
  } else {
1120
- return counter;
1146
+ return reactivity.shallowReadonly(counter);
1121
1147
  }
1122
1148
  }
1123
1149
  function useLastChanged(source, options = {}) {
@@ -1128,7 +1154,7 @@ function useLastChanged(source, options = {}) {
1128
1154
  () => ms.value = timestamp(),
1129
1155
  options
1130
1156
  );
1131
- return ms;
1157
+ return reactivity.shallowReadonly(ms);
1132
1158
  }
1133
1159
  function useTimeoutFn(cb, interval, options = {}) {
1134
1160
  const {
@@ -1136,11 +1162,11 @@ function useTimeoutFn(cb, interval, options = {}) {
1136
1162
  immediateCallback = false
1137
1163
  } = options;
1138
1164
  const isPending = reactivity.shallowRef(false);
1139
- let timer = null;
1165
+ let timer;
1140
1166
  function clear() {
1141
1167
  if (timer) {
1142
1168
  clearTimeout(timer);
1143
- timer = null;
1169
+ timer = void 0;
1144
1170
  }
1145
1171
  }
1146
1172
  function stop() {
@@ -1154,7 +1180,7 @@ function useTimeoutFn(cb, interval, options = {}) {
1154
1180
  isPending.value = true;
1155
1181
  timer = setTimeout(() => {
1156
1182
  isPending.value = false;
1157
- timer = null;
1183
+ timer = void 0;
1158
1184
  cb(...args);
1159
1185
  }, reactivity.toValue(interval));
1160
1186
  }
@@ -1165,7 +1191,7 @@ function useTimeoutFn(cb, interval, options = {}) {
1165
1191
  }
1166
1192
  tryOnScopeDispose(stop);
1167
1193
  return {
1168
- isPending: reactivity.readonly(isPending),
1194
+ isPending: reactivity.shallowReadonly(isPending),
1169
1195
  start,
1170
1196
  stop
1171
1197
  };
@@ -1190,6 +1216,7 @@ function useTimeout(interval = 1e3, options = {}) {
1190
1216
  return ready;
1191
1217
  }
1192
1218
  }
1219
+ // @__NO_SIDE_EFFECTS__
1193
1220
  function useToNumber(value, options = {}) {
1194
1221
  const {
1195
1222
  method = "parseFloat",
@@ -1207,9 +1234,11 @@ function useToNumber(value, options = {}) {
1207
1234
  return resolved;
1208
1235
  });
1209
1236
  }
1237
+ // @__NO_SIDE_EFFECTS__
1210
1238
  function useToString(value) {
1211
1239
  return reactivity.computed(() => `${reactivity.toValue(value)}`);
1212
1240
  }
1241
+ // @__NO_SIDE_EFFECTS__
1213
1242
  function useToggle(initialValue = false, options = {}) {
1214
1243
  const {
1215
1244
  truthyValue = true,
@@ -1310,50 +1339,50 @@ function watchIgnorable(source, cb, options = {}) {
1310
1339
  let ignorePrevAsyncUpdates;
1311
1340
  let stop;
1312
1341
  if (watchOptions.flush === "sync") {
1313
- const ignore = reactivity.shallowRef(false);
1342
+ let ignore = false;
1314
1343
  ignorePrevAsyncUpdates = () => {
1315
1344
  };
1316
1345
  ignoreUpdates = (updater) => {
1317
- ignore.value = true;
1346
+ ignore = true;
1318
1347
  updater();
1319
- ignore.value = false;
1348
+ ignore = false;
1320
1349
  };
1321
1350
  stop = reactivity.watch(
1322
1351
  source,
1323
1352
  (...args) => {
1324
- if (!ignore.value)
1353
+ if (!ignore)
1325
1354
  filteredCb(...args);
1326
1355
  },
1327
1356
  watchOptions
1328
1357
  );
1329
1358
  } else {
1330
1359
  const disposables = [];
1331
- const ignoreCounter = reactivity.shallowRef(0);
1332
- const syncCounter = reactivity.shallowRef(0);
1360
+ let ignoreCounter = 0;
1361
+ let syncCounter = 0;
1333
1362
  ignorePrevAsyncUpdates = () => {
1334
- ignoreCounter.value = syncCounter.value;
1363
+ ignoreCounter = syncCounter;
1335
1364
  };
1336
1365
  disposables.push(
1337
1366
  reactivity.watch(
1338
1367
  source,
1339
1368
  () => {
1340
- syncCounter.value++;
1369
+ syncCounter++;
1341
1370
  },
1342
1371
  { ...watchOptions, flush: "sync" }
1343
1372
  )
1344
1373
  );
1345
1374
  ignoreUpdates = (updater) => {
1346
- const syncCounterPrev = syncCounter.value;
1375
+ const syncCounterPrev = syncCounter;
1347
1376
  updater();
1348
- ignoreCounter.value += syncCounter.value - syncCounterPrev;
1377
+ ignoreCounter += syncCounter - syncCounterPrev;
1349
1378
  };
1350
1379
  disposables.push(
1351
1380
  reactivity.watch(
1352
1381
  source,
1353
1382
  (...args) => {
1354
- const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
1355
- ignoreCounter.value = 0;
1356
- syncCounter.value = 0;
1383
+ const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
1384
+ ignoreCounter = 0;
1385
+ syncCounter = 0;
1357
1386
  if (ignore)
1358
1387
  return;
1359
1388
  filteredCb(...args);
@@ -1378,11 +1407,14 @@ function watchImmediate(source, cb, options) {
1378
1407
  );
1379
1408
  }
1380
1409
  function watchOnce(source, cb, options) {
1381
- const stop = reactivity.watch(source, (...args) => {
1382
- reactivity.nextTick(() => stop());
1383
- return cb(...args);
1384
- }, options);
1385
- return stop;
1410
+ return reactivity.watch(
1411
+ source,
1412
+ cb,
1413
+ {
1414
+ ...options,
1415
+ once: true
1416
+ }
1417
+ );
1386
1418
  }
1387
1419
  function watchThrottled(source, cb, options = {}) {
1388
1420
  const {
@@ -1458,6 +1490,7 @@ function whenever(source, cb, options) {
1458
1490
  return stop;
1459
1491
  }
1460
1492
  function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1493
+ var _a;
1461
1494
  let options;
1462
1495
  if (reactivity.isRef(optionsOrRef)) {
1463
1496
  options = {
@@ -1468,9 +1501,10 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1468
1501
  }
1469
1502
  const {
1470
1503
  lazy = false,
1504
+ flush = "pre",
1471
1505
  evaluating = void 0,
1472
1506
  shallow = true,
1473
- onError = noop
1507
+ onError = (_a = globalThis.reportError) != null ? _a : noop
1474
1508
  } = options;
1475
1509
  const started = reactivity.shallowRef(!lazy);
1476
1510
  const current = shallow ? reactivity.shallowRef(initialState) : reactivity.ref(initialState);
@@ -1504,7 +1538,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1504
1538
  evaluating.value = false;
1505
1539
  hasFinished = true;
1506
1540
  }
1507
- });
1541
+ }, { flush });
1508
1542
  if (lazy) {
1509
1543
  return reactivity.computed(() => {
1510
1544
  started.value = true;
@@ -1514,6 +1548,7 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
1514
1548
  return current;
1515
1549
  }
1516
1550
  }
1551
+ // @__NO_SIDE_EFFECTS__
1517
1552
  function createUnrefFn(fn) {
1518
1553
  return function(...args) {
1519
1554
  return fn.apply(this, args.map((i) => reactivity.toValue(i)));
@@ -1572,12 +1607,14 @@ function useEventListener(...args) {
1572
1607
  tryOnScopeDispose(cleanup);
1573
1608
  return stop;
1574
1609
  }
1610
+ // @__NO_SIDE_EFFECTS__
1575
1611
  function useMounted() {
1576
1612
  const isMounted = reactivity.shallowRef(false);
1577
1613
  return isMounted;
1578
1614
  }
1615
+ // @__NO_SIDE_EFFECTS__
1579
1616
  function useSupported(callback) {
1580
- const isMounted = useMounted();
1617
+ const isMounted = /* @__PURE__ */ useMounted();
1581
1618
  return reactivity.computed(() => {
1582
1619
  isMounted.value;
1583
1620
  return Boolean(callback());
@@ -1711,10 +1748,11 @@ function whenAborted(signal) {
1711
1748
  });
1712
1749
  }
1713
1750
  function useAsyncState(promise, initialState, options) {
1751
+ var _a;
1714
1752
  const {
1715
1753
  immediate = true,
1716
1754
  delay = 0,
1717
- onError = noop,
1755
+ onError = (_a = globalThis.reportError) != null ? _a : noop,
1718
1756
  onSuccess = noop,
1719
1757
  resetOnExecute = true,
1720
1758
  shallow = true,
@@ -1726,7 +1764,7 @@ function useAsyncState(promise, initialState, options) {
1726
1764
  const error = reactivity.shallowRef(void 0);
1727
1765
  async function execute(delay2 = 0, ...args) {
1728
1766
  if (resetOnExecute)
1729
- state.value = initialState;
1767
+ state.value = reactivity.toValue(initialState);
1730
1768
  error.value = void 0;
1731
1769
  isReady.value = false;
1732
1770
  isLoading.value = true;
@@ -1756,7 +1794,8 @@ function useAsyncState(promise, initialState, options) {
1756
1794
  isReady,
1757
1795
  isLoading,
1758
1796
  error,
1759
- execute
1797
+ execute,
1798
+ executeImmediate: (...args) => execute(0, ...args)
1760
1799
  };
1761
1800
  function waitUntilIsLoaded() {
1762
1801
  return new Promise((resolve, reject) => {
@@ -1872,7 +1911,7 @@ function useBroadcastChannel(options) {
1872
1911
  name,
1873
1912
  window: window2 = defaultWindow
1874
1913
  } = options;
1875
- const isSupported = useSupported(() => window2 && "BroadcastChannel" in window2);
1914
+ const isSupported = /* @__PURE__ */ useSupported(() => window2 && "BroadcastChannel" in window2);
1876
1915
  const isClosed = reactivity.shallowRef(false);
1877
1916
  const channel = reactivity.ref();
1878
1917
  const data = reactivity.ref();
@@ -1919,7 +1958,7 @@ function useBroadcastChannel(options) {
1919
1958
  }
1920
1959
  function useCached(refValue, comparator = (a, b) => a === b, options) {
1921
1960
  const { deepRefs = true, ...watchOptions } = options || {};
1922
- const cachedValue = createRef(refValue.value, deepRefs);
1961
+ const cachedValue = /* @__PURE__ */ createRef(refValue.value, deepRefs);
1923
1962
  reactivity.watch(() => refValue.value, (value) => {
1924
1963
  if (!comparator(value, cachedValue.value))
1925
1964
  cachedValue.value = value;
@@ -2095,7 +2134,8 @@ function useRefHistory(source, options = {}) {
2095
2134
  const {
2096
2135
  deep = false,
2097
2136
  flush = "pre",
2098
- eventFilter
2137
+ eventFilter,
2138
+ shouldCommit = () => true
2099
2139
  } = options;
2100
2140
  const {
2101
2141
  eventFilter: composedFilter,
@@ -2103,6 +2143,7 @@ function useRefHistory(source, options = {}) {
2103
2143
  resume: resumeTracking,
2104
2144
  isActive: isTracking
2105
2145
  } = pausableFilter(eventFilter);
2146
+ let lastRawValue = source.value;
2106
2147
  const {
2107
2148
  ignoreUpdates,
2108
2149
  ignorePrevAsyncUpdates,
@@ -2116,12 +2157,16 @@ function useRefHistory(source, options = {}) {
2116
2157
  ignorePrevAsyncUpdates();
2117
2158
  ignoreUpdates(() => {
2118
2159
  source2.value = value;
2160
+ lastRawValue = value;
2119
2161
  });
2120
2162
  }
2121
2163
  const manualHistory = useManualRefHistory(source, { ...options, clone: options.clone || deep, setSource });
2122
2164
  const { clear, commit: manualCommit } = manualHistory;
2123
2165
  function commit() {
2124
2166
  ignorePrevAsyncUpdates();
2167
+ if (!shouldCommit(lastRawValue, source.value))
2168
+ return;
2169
+ lastRawValue = source.value;
2125
2170
  manualCommit();
2126
2171
  }
2127
2172
  function resume(commitNow) {
@@ -2160,6 +2205,7 @@ function useDebouncedRefHistory(source, options = {}) {
2160
2205
  };
2161
2206
  }
2162
2207
  const events = /* @__PURE__ */ new Map();
2208
+ // @__NO_SIDE_EFFECTS__
2163
2209
  function useEventBus(key) {
2164
2210
  const scope = reactivity.getCurrentScope();
2165
2211
  function on(listener) {
@@ -2281,7 +2327,7 @@ function createFetch(config = {}) {
2281
2327
  return useFactoryFetch;
2282
2328
  }
2283
2329
  function useFetch(url, ...args) {
2284
- var _a;
2330
+ var _a, _b;
2285
2331
  const supportsAbort = typeof AbortController === "function";
2286
2332
  let fetchOptions = {};
2287
2333
  let options = {
@@ -2306,13 +2352,13 @@ function useFetch(url, ...args) {
2306
2352
  options = { ...options, ...args[1] };
2307
2353
  }
2308
2354
  const {
2309
- fetch = (_a = defaultWindow) == null ? void 0 : _a.fetch,
2355
+ fetch = (_b = (_a = defaultWindow) == null ? void 0 : _a.fetch) != null ? _b : globalThis == null ? void 0 : globalThis.fetch,
2310
2356
  initialData,
2311
2357
  timeout
2312
2358
  } = options;
2313
- const responseEvent = createEventHook();
2314
- const errorEvent = createEventHook();
2315
- const finallyEvent = createEventHook();
2359
+ const responseEvent = /* @__PURE__ */ createEventHook();
2360
+ const errorEvent = /* @__PURE__ */ createEventHook();
2361
+ const finallyEvent = /* @__PURE__ */ createEventHook();
2316
2362
  const isFinished = reactivity.shallowRef(false);
2317
2363
  const isFetching = reactivity.shallowRef(false);
2318
2364
  const aborted = reactivity.shallowRef(false);
@@ -2323,9 +2369,9 @@ function useFetch(url, ...args) {
2323
2369
  const canAbort = reactivity.computed(() => supportsAbort && isFetching.value);
2324
2370
  let controller;
2325
2371
  let timer;
2326
- const abort = () => {
2372
+ const abort = (reason) => {
2327
2373
  if (supportsAbort) {
2328
- controller == null ? void 0 : controller.abort();
2374
+ controller == null ? void 0 : controller.abort(reason);
2329
2375
  controller = new AbortController();
2330
2376
  controller.signal.onabort = () => aborted.value = true;
2331
2377
  fetchOptions = {
@@ -2342,7 +2388,7 @@ function useFetch(url, ...args) {
2342
2388
  timer = useTimeoutFn(abort, timeout, { immediate: false });
2343
2389
  let executeCounter = 0;
2344
2390
  const execute = async (throwOnFailed = false) => {
2345
- var _a2, _b;
2391
+ var _a2, _b2;
2346
2392
  abort();
2347
2393
  loading(true);
2348
2394
  error.value = null;
@@ -2391,7 +2437,7 @@ function useFetch(url, ...args) {
2391
2437
  ...context.options,
2392
2438
  headers: {
2393
2439
  ...headersToObject(defaultFetchOptions.headers),
2394
- ...headersToObject((_b = context.options) == null ? void 0 : _b.headers)
2440
+ ...headersToObject((_b2 = context.options) == null ? void 0 : _b2.headers)
2395
2441
  }
2396
2442
  }
2397
2443
  ).then(async (fetchResponse) => {
@@ -2576,7 +2622,8 @@ function useIdle(timeout = oneMinute, options = {}) {
2576
2622
  onEvent();
2577
2623
  }, listenerOptions);
2578
2624
  }
2579
- reset();
2625
+ if (!initialState)
2626
+ reset();
2580
2627
  }
2581
2628
  return {
2582
2629
  idle,
@@ -2584,14 +2631,16 @@ function useIdle(timeout = oneMinute, options = {}) {
2584
2631
  reset
2585
2632
  };
2586
2633
  }
2634
+ // @__NO_SIDE_EFFECTS__
2587
2635
  function useNow(options = {}) {
2588
2636
  const {
2589
2637
  controls: exposeControls = false,
2590
- interval = "requestAnimationFrame"
2638
+ interval = "requestAnimationFrame",
2639
+ immediate = true
2591
2640
  } = options;
2592
2641
  const now2 = reactivity.ref(/* @__PURE__ */ new Date());
2593
2642
  const update = () => now2.value = /* @__PURE__ */ new Date();
2594
- const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate: true }) : useIntervalFn(update, interval, { immediate: true });
2643
+ const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate }) : useIntervalFn(update, interval, { immediate });
2595
2644
  if (exposeControls) {
2596
2645
  return {
2597
2646
  now: now2,
@@ -2620,6 +2669,7 @@ function useObjectUrl(object) {
2620
2669
  tryOnScopeDispose(release);
2621
2670
  return reactivity.readonly(url);
2622
2671
  }
2672
+ // @__NO_SIDE_EFFECTS__
2623
2673
  function useClamp(value, min, max) {
2624
2674
  if (typeof value === "function" || reactivity.isReadonly(value))
2625
2675
  return reactivity.computed(() => clamp(reactivity.toValue(value), reactivity.toValue(min), reactivity.toValue(max)));
@@ -2642,12 +2692,12 @@ function useOffsetPagination(options) {
2642
2692
  onPageSizeChange = noop,
2643
2693
  onPageCountChange = noop
2644
2694
  } = options;
2645
- const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
2695
+ const currentPageSize = /* @__PURE__ */ useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
2646
2696
  const pageCount = reactivity.computed(() => Math.max(
2647
2697
  1,
2648
2698
  Math.ceil(reactivity.toValue(total) / reactivity.toValue(currentPageSize))
2649
2699
  ));
2650
- const currentPage = useClamp(page, 1, pageCount);
2700
+ const currentPage = /* @__PURE__ */ useClamp(page, 1, pageCount);
2651
2701
  const isFirstPage = reactivity.computed(() => currentPage.value === 1);
2652
2702
  const isLastPage = reactivity.computed(() => currentPage.value === pageCount.value);
2653
2703
  if (reactivity.isRef(page)) {
@@ -2730,6 +2780,7 @@ function useSorted(...args) {
2730
2780
  });
2731
2781
  return source;
2732
2782
  }
2783
+ // @__NO_SIDE_EFFECTS__
2733
2784
  function useStepper(steps, initialStep) {
2734
2785
  const stepsRef = reactivity.ref(steps);
2735
2786
  const stepNames = reactivity.computed(() => Array.isArray(stepsRef.value) ? stepsRef.value : Object.keys(stepsRef.value));
@@ -2837,12 +2888,13 @@ const DEFAULT_MESSAGES = {
2837
2888
  function DEFAULT_FORMATTER(date) {
2838
2889
  return date.toISOString().slice(0, 10);
2839
2890
  }
2891
+ // @__NO_SIDE_EFFECTS__
2840
2892
  function useTimeAgo(time, options = {}) {
2841
2893
  const {
2842
2894
  controls: exposeControls = false,
2843
2895
  updateInterval = 3e4
2844
2896
  } = options;
2845
- const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
2897
+ const { now: now2, ...controls } = /* @__PURE__ */ useNow({ interval: updateInterval, controls: true });
2846
2898
  const timeAgo = reactivity.computed(() => formatTimeAgo(new Date(reactivity.toValue(time)), options, reactivity.toValue(now2)));
2847
2899
  if (exposeControls) {
2848
2900
  return {
@@ -2963,7 +3015,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
2963
3015
  removeFalsyValues = false,
2964
3016
  write: enableWrite = true,
2965
3017
  writeMode = "replace",
2966
- window: window2 = defaultWindow
3018
+ window: window2 = defaultWindow,
3019
+ stringify = (params) => params.toString()
2967
3020
  } = options;
2968
3021
  if (!window2)
2969
3022
  return reactivity.reactive(initialValue);
@@ -2980,7 +3033,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
2980
3033
  }
2981
3034
  }
2982
3035
  function constructQuery(params) {
2983
- const stringified = params.toString();
3036
+ const stringified = stringify(params);
2984
3037
  if (mode === "history")
2985
3038
  return `${stringified ? `?${stringified}` : ""}${window2.location.hash || ""}`;
2986
3039
  if (mode === "hash-params")
@@ -3022,7 +3075,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
3022
3075
  },
3023
3076
  { deep: true }
3024
3077
  );
3025
- function write(params, shouldUpdate) {
3078
+ function write(params, shouldUpdate, shouldWriteHistory = true) {
3026
3079
  pause();
3027
3080
  if (shouldUpdate)
3028
3081
  updateState(params);
@@ -3033,18 +3086,20 @@ function useUrlSearchParams(mode = "history", options = {}) {
3033
3086
  window2.location.pathname + constructQuery(params)
3034
3087
  );
3035
3088
  } else {
3036
- window2.history.pushState(
3037
- window2.history.state,
3038
- window2.document.title,
3039
- window2.location.pathname + constructQuery(params)
3040
- );
3089
+ if (shouldWriteHistory) {
3090
+ window2.history.pushState(
3091
+ window2.history.state,
3092
+ window2.document.title,
3093
+ window2.location.pathname + constructQuery(params)
3094
+ );
3095
+ }
3041
3096
  }
3042
- resume();
3097
+ reactivity.nextTick(() => resume());
3043
3098
  }
3044
3099
  function onChanged() {
3045
3100
  if (!enableWrite)
3046
3101
  return;
3047
- write(read(), true);
3102
+ write(read(), true, false);
3048
3103
  }
3049
3104
  const listenerOptions = { passive: true };
3050
3105
  useEventListener(window2, "popstate", onChanged, listenerOptions);