@vueuse/shared 12.4.0 → 12.6.0

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.mjs CHANGED
@@ -7,13 +7,13 @@ function computedEager(fn, options) {
7
7
  result.value = fn();
8
8
  }, {
9
9
  ...options,
10
- flush: (_a = options == null ? undefined : options.flush) != null ? _a : "sync"
10
+ flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
11
11
  });
12
12
  return readonly(result);
13
13
  }
14
14
 
15
15
  function computedWithControl(source, fn) {
16
- let v = undefined;
16
+ let v = void 0;
17
17
  let track;
18
18
  let trigger;
19
19
  const dirty = ref(true);
@@ -23,7 +23,7 @@ function computedWithControl(source, fn) {
23
23
  };
24
24
  watch(source, update, { flush: "sync" });
25
25
  const get = typeof fn === "function" ? fn : fn.get;
26
- const set = typeof fn === "function" ? undefined : fn.set;
26
+ const set = typeof fn === "function" ? void 0 : fn.set;
27
27
  const result = customRef((_track, _trigger) => {
28
28
  track = _track;
29
29
  trigger = _trigger;
@@ -37,7 +37,7 @@ function computedWithControl(source, fn) {
37
37
  return v;
38
38
  },
39
39
  set(v2) {
40
- set == null ? undefined : set(v2);
40
+ set == null ? void 0 : set(v2);
41
41
  }
42
42
  };
43
43
  });
@@ -99,7 +99,7 @@ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
99
99
  const injectLocal = (...args) => {
100
100
  var _a;
101
101
  const key = args[0];
102
- const instance = (_a = getCurrentInstance()) == null ? undefined : _a.proxy;
102
+ const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
103
103
  if (instance == null && !hasInjectionContext())
104
104
  throw new Error("injectLocal must be called in setup");
105
105
  if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
@@ -109,7 +109,7 @@ const injectLocal = (...args) => {
109
109
 
110
110
  const provideLocal = (key, value) => {
111
111
  var _a;
112
- const instance = (_a = getCurrentInstance()) == null ? undefined : _a.proxy;
112
+ const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
113
113
  if (instance == null)
114
114
  throw new Error("provideLocal must be called in setup");
115
115
  if (!localProvidedStateMap.has(instance))
@@ -120,8 +120,8 @@ const provideLocal = (key, value) => {
120
120
  };
121
121
 
122
122
  function createInjectionState(composable, options) {
123
- const key = (options == null ? undefined : options.injectionKey) || Symbol(composable.name || "InjectionState");
124
- const defaultValue = options == null ? undefined : options.defaultValue;
123
+ const key = (options == null ? void 0 : options.injectionKey) || Symbol(composable.name || "InjectionState");
124
+ const defaultValue = options == null ? void 0 : options.defaultValue;
125
125
  const useProvidingState = (...args) => {
126
126
  const state = composable(...args);
127
127
  provideLocal(key, state);
@@ -139,8 +139,8 @@ function createSharedComposable(composable) {
139
139
  subscribers -= 1;
140
140
  if (scope && subscribers <= 0) {
141
141
  scope.stop();
142
- state = undefined;
143
- scope = undefined;
142
+ state = void 0;
143
+ scope = void 0;
144
144
  }
145
145
  };
146
146
  return (...args) => {
@@ -207,7 +207,7 @@ function makeDestructurable(obj, arr) {
207
207
  }
208
208
 
209
209
  function reactify(fn, options) {
210
- const unrefFn = (options == null ? undefined : options.computedGetter) === false ? unref : toValue$1;
210
+ const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue$1;
211
211
  return function(...args) {
212
212
  return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
213
213
  };
@@ -303,7 +303,7 @@ const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
303
303
  const isIOS = /* @__PURE__ */ getIsIOS();
304
304
  function getIsIOS() {
305
305
  var _a, _b;
306
- return isClient && ((_a = window == null ? undefined : window.navigator) == null ? undefined : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? undefined : window.navigator) == null ? undefined : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? undefined : window.navigator.userAgent));
306
+ return isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? void 0 : window.navigator) == null ? void 0 : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? void 0 : window.navigator.userAgent));
307
307
  }
308
308
 
309
309
  function createFilterWrapper(filter, fn) {
@@ -326,12 +326,13 @@ function debounceFilter(ms, options = {}) {
326
326
  lastRejector();
327
327
  lastRejector = noop;
328
328
  };
329
+ let lastInvoker;
329
330
  const filter = (invoke) => {
330
331
  const duration = toValue$1(ms);
331
332
  const maxDuration = toValue$1(options.maxWait);
332
333
  if (timer)
333
334
  _clearTimeout(timer);
334
- if (duration <= 0 || maxDuration !== undefined && maxDuration <= 0) {
335
+ if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
335
336
  if (maxTimer) {
336
337
  _clearTimeout(maxTimer);
337
338
  maxTimer = null;
@@ -340,12 +341,13 @@ function debounceFilter(ms, options = {}) {
340
341
  }
341
342
  return new Promise((resolve, reject) => {
342
343
  lastRejector = options.rejectOnCancel ? reject : resolve;
344
+ lastInvoker = invoke;
343
345
  if (maxDuration && !maxTimer) {
344
346
  maxTimer = setTimeout(() => {
345
347
  if (timer)
346
348
  _clearTimeout(timer);
347
349
  maxTimer = null;
348
- resolve(invoke());
350
+ resolve(lastInvoker());
349
351
  }, maxDuration);
350
352
  }
351
353
  timer = setTimeout(() => {
@@ -375,7 +377,7 @@ function throttleFilter(...args) {
375
377
  const clear = () => {
376
378
  if (timer) {
377
379
  clearTimeout(timer);
378
- timer = undefined;
380
+ timer = void 0;
379
381
  lastRejector();
380
382
  lastRejector = noop;
381
383
  }
@@ -412,8 +414,11 @@ function throttleFilter(...args) {
412
414
  };
413
415
  return filter;
414
416
  }
415
- function pausableFilter(extendFilter = bypassFilter) {
416
- const isActive = ref(true);
417
+ function pausableFilter(extendFilter = bypassFilter, options = {}) {
418
+ const {
419
+ initialState = "active"
420
+ } = options;
421
+ const isActive = toRef(initialState === "active");
417
422
  function pause() {
418
423
  isActive.value = false;
419
424
  }
@@ -461,7 +466,7 @@ function createSingletonPromise(fn) {
461
466
  }
462
467
  wrapper.reset = async () => {
463
468
  const _prev = _promise;
464
- _promise = undefined;
469
+ _promise = void 0;
465
470
  if (_prev)
466
471
  await _prev;
467
472
  };
@@ -477,7 +482,7 @@ function increaseWithUnit(target, delta) {
477
482
  var _a;
478
483
  if (typeof target === "number")
479
484
  return target + delta;
480
- const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? undefined : _a[0]) || "";
485
+ const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
481
486
  const unit = target.slice(value.length);
482
487
  const result = Number.parseFloat(value) + delta;
483
488
  if (Number.isNaN(result))
@@ -490,7 +495,7 @@ function pxValue(px) {
490
495
  function objectPick(obj, keys, omitUndefined = false) {
491
496
  return keys.reduce((n, k) => {
492
497
  if (k in obj) {
493
- if (!omitUndefined || obj[k] !== undefined)
498
+ if (!omitUndefined || obj[k] !== void 0)
494
499
  n[k] = obj[k];
495
500
  }
496
501
  return n;
@@ -498,7 +503,7 @@ function objectPick(obj, keys, omitUndefined = false) {
498
503
  }
499
504
  function objectOmit(obj, keys, omitUndefined = false) {
500
505
  return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
501
- return (!omitUndefined || value !== undefined) && !keys.includes(key);
506
+ return (!omitUndefined || value !== void 0) && !keys.includes(key);
502
507
  }));
503
508
  }
504
509
  function objectEntries(obj) {
@@ -623,10 +628,10 @@ function refWithControl(initial, options = {}) {
623
628
  if (value === source)
624
629
  return;
625
630
  const old = source;
626
- if (((_a = options.onBeforeChange) == null ? undefined : _a.call(options, value, old)) === false)
631
+ if (((_a = options.onBeforeChange) == null ? void 0 : _a.call(options, value, old)) === false)
627
632
  return;
628
633
  source = value;
629
- (_b = options.onChanged) == null ? undefined : _b.call(options, value, old);
634
+ (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
630
635
  if (triggering)
631
636
  trigger();
632
637
  }
@@ -678,9 +683,10 @@ function watchWithFilter(source, cb, options = {}) {
678
683
  function watchPausable(source, cb, options = {}) {
679
684
  const {
680
685
  eventFilter: filter,
686
+ initialState = "active",
681
687
  ...watchOptions
682
688
  } = options;
683
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
689
+ const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
684
690
  const stop = watchWithFilter(
685
691
  source,
686
692
  cb,
@@ -822,7 +828,7 @@ function createUntil(r, isNot = false) {
822
828
  if (stop)
823
829
  stop();
824
830
  else
825
- nextTick(() => stop == null ? undefined : stop());
831
+ nextTick(() => stop == null ? void 0 : stop());
826
832
  resolve(v);
827
833
  }
828
834
  },
@@ -836,7 +842,7 @@ function createUntil(r, isNot = false) {
836
842
  const promises = [watcher];
837
843
  if (timeout != null) {
838
844
  promises.push(
839
- promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => stop == null ? undefined : stop())
845
+ promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => stop == null ? void 0 : stop())
840
846
  );
841
847
  }
842
848
  return Promise.race(promises);
@@ -854,7 +860,7 @@ function createUntil(r, isNot = false) {
854
860
  if (stop)
855
861
  stop();
856
862
  else
857
- nextTick(() => stop == null ? undefined : stop());
863
+ nextTick(() => stop == null ? void 0 : stop());
858
864
  resolve(v1);
859
865
  }
860
866
  },
@@ -869,7 +875,7 @@ function createUntil(r, isNot = false) {
869
875
  if (timeout != null) {
870
876
  promises.push(
871
877
  promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => {
872
- stop == null ? undefined : stop();
878
+ stop == null ? void 0 : stop();
873
879
  return toValue$1(r);
874
880
  })
875
881
  );
@@ -883,7 +889,7 @@ function createUntil(r, isNot = false) {
883
889
  return toBe(null, options);
884
890
  }
885
891
  function toBeUndefined(options) {
886
- return toBe(undefined, options);
892
+ return toBe(void 0, options);
887
893
  }
888
894
  function toBeNaN(options) {
889
895
  return toMatch(Number.isNaN, options);
@@ -984,7 +990,7 @@ function findLast(arr, cb) {
984
990
  if (cb(arr[index], index, arr))
985
991
  return arr[index];
986
992
  }
987
- return undefined;
993
+ return void 0;
988
994
  }
989
995
  function useArrayFindLast(list, fn) {
990
996
  return computed(() => toValue$1(
@@ -1074,7 +1080,7 @@ function useCounter(initialValue = 0, options = {}) {
1074
1080
  }
1075
1081
 
1076
1082
  const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
1077
- 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}|SSS/g;
1083
+ 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;
1078
1084
  function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
1079
1085
  let m = hours < 12 ? "AM" : "PM";
1080
1086
  if (hasPeriod)
@@ -1097,6 +1103,10 @@ function formatDate(date, formatStr, options = {}) {
1097
1103
  const milliseconds = date.getMilliseconds();
1098
1104
  const day = date.getDay();
1099
1105
  const meridiem = (_a = options.customMeridiem) != null ? _a : defaultMeridiem;
1106
+ const stripTimeZone = (dateString) => {
1107
+ var _a2;
1108
+ return (_a2 = dateString.split(" ")[1]) != null ? _a2 : "";
1109
+ };
1100
1110
  const matches = {
1101
1111
  Yo: () => formatOrdinal(years),
1102
1112
  YY: () => String(years).slice(-2),
@@ -1129,17 +1139,21 @@ function formatDate(date, formatStr, options = {}) {
1129
1139
  A: () => meridiem(hours, minutes),
1130
1140
  AA: () => meridiem(hours, minutes, false, true),
1131
1141
  a: () => meridiem(hours, minutes, true),
1132
- aa: () => meridiem(hours, minutes, true, true)
1142
+ aa: () => meridiem(hours, minutes, true, true),
1143
+ z: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1144
+ zz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1145
+ zzz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "shortOffset" })),
1146
+ zzzz: () => stripTimeZone(date.toLocaleDateString(toValue$1(options.locales), { timeZoneName: "longOffset" }))
1133
1147
  };
1134
1148
  return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1135
1149
  var _a2, _b;
1136
- return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? undefined : _a2.call(matches)) != null ? _b : match;
1150
+ return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? void 0 : _a2.call(matches)) != null ? _b : match;
1137
1151
  });
1138
1152
  }
1139
1153
  function normalizeDate(date) {
1140
1154
  if (date === null)
1141
1155
  return new Date(Number.NaN);
1142
- if (date === undefined)
1156
+ if (date === void 0)
1143
1157
  return /* @__PURE__ */ new Date();
1144
1158
  if (date instanceof Date)
1145
1159
  return new Date(date);
@@ -1245,7 +1259,8 @@ function useLastChanged(source, options = {}) {
1245
1259
 
1246
1260
  function useTimeoutFn(cb, interval, options = {}) {
1247
1261
  const {
1248
- immediate = true
1262
+ immediate = true,
1263
+ immediateCallback = false
1249
1264
  } = options;
1250
1265
  const isPending = ref(false);
1251
1266
  let timer = null;
@@ -1260,6 +1275,8 @@ function useTimeoutFn(cb, interval, options = {}) {
1260
1275
  clear();
1261
1276
  }
1262
1277
  function start(...args) {
1278
+ if (immediateCallback)
1279
+ cb();
1263
1280
  clear();
1264
1281
  isPending.value = true;
1265
1282
  timer = setTimeout(() => {
@@ -1348,7 +1365,7 @@ function useToggle(initialValue = false, options = {}) {
1348
1365
  }
1349
1366
 
1350
1367
  function watchArray(source, cb, options) {
1351
- let oldList = (options == null ? undefined : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
1368
+ let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
1352
1369
  return watch(source, (newList, _, onCleanup) => {
1353
1370
  const oldListRemains = Array.from({ length: oldList.length });
1354
1371
  const added = [];
@@ -1392,7 +1409,7 @@ function watchAtMost(source, cb, options) {
1392
1409
  function watchDebounced(source, cb, options = {}) {
1393
1410
  const {
1394
1411
  debounce = 0,
1395
- maxWait = undefined,
1412
+ maxWait = void 0,
1396
1413
  ...watchOptions
1397
1414
  } = options;
1398
1415
  return watchWithFilter(
@@ -1529,7 +1546,7 @@ function watchTriggerable(source, cb, options = {}) {
1529
1546
  if (!cleanupFn)
1530
1547
  return;
1531
1548
  const fn = cleanupFn;
1532
- cleanupFn = undefined;
1549
+ cleanupFn = void 0;
1533
1550
  fn();
1534
1551
  }
1535
1552
  function onCleanup(callback) {
@@ -1561,7 +1578,7 @@ function getWatchSources(sources) {
1561
1578
  return toValue$1(sources);
1562
1579
  }
1563
1580
  function getOldValue(source) {
1564
- return Array.isArray(source) ? source.map(() => undefined) : undefined;
1581
+ return Array.isArray(source) ? source.map(() => void 0) : void 0;
1565
1582
  }
1566
1583
 
1567
1584
  function whenever(source, cb, options) {
@@ -1569,7 +1586,7 @@ function whenever(source, cb, options) {
1569
1586
  source,
1570
1587
  (v, ov, onInvalidate) => {
1571
1588
  if (v) {
1572
- if (options == null ? undefined : options.once)
1589
+ if (options == null ? void 0 : options.once)
1573
1590
  nextTick(() => stop());
1574
1591
  cb(v, ov, onInvalidate);
1575
1592
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vueuse/shared",
3
3
  "type": "module",
4
- "version": "12.4.0",
4
+ "version": "12.6.0",
5
5
  "author": "Anthony Fu <https://github.com/antfu>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/antfu",