@vueuse/shared 12.5.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) {
@@ -332,7 +332,7 @@ function debounceFilter(ms, options = {}) {
332
332
  const maxDuration = toValue$1(options.maxWait);
333
333
  if (timer)
334
334
  _clearTimeout(timer);
335
- if (duration <= 0 || maxDuration !== undefined && maxDuration <= 0) {
335
+ if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
336
336
  if (maxTimer) {
337
337
  _clearTimeout(maxTimer);
338
338
  maxTimer = null;
@@ -377,7 +377,7 @@ function throttleFilter(...args) {
377
377
  const clear = () => {
378
378
  if (timer) {
379
379
  clearTimeout(timer);
380
- timer = undefined;
380
+ timer = void 0;
381
381
  lastRejector();
382
382
  lastRejector = noop;
383
383
  }
@@ -414,8 +414,11 @@ function throttleFilter(...args) {
414
414
  };
415
415
  return filter;
416
416
  }
417
- function pausableFilter(extendFilter = bypassFilter) {
418
- const isActive = ref(true);
417
+ function pausableFilter(extendFilter = bypassFilter, options = {}) {
418
+ const {
419
+ initialState = "active"
420
+ } = options;
421
+ const isActive = toRef(initialState === "active");
419
422
  function pause() {
420
423
  isActive.value = false;
421
424
  }
@@ -463,7 +466,7 @@ function createSingletonPromise(fn) {
463
466
  }
464
467
  wrapper.reset = async () => {
465
468
  const _prev = _promise;
466
- _promise = undefined;
469
+ _promise = void 0;
467
470
  if (_prev)
468
471
  await _prev;
469
472
  };
@@ -479,7 +482,7 @@ function increaseWithUnit(target, delta) {
479
482
  var _a;
480
483
  if (typeof target === "number")
481
484
  return target + delta;
482
- const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? undefined : _a[0]) || "";
485
+ const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
483
486
  const unit = target.slice(value.length);
484
487
  const result = Number.parseFloat(value) + delta;
485
488
  if (Number.isNaN(result))
@@ -492,7 +495,7 @@ function pxValue(px) {
492
495
  function objectPick(obj, keys, omitUndefined = false) {
493
496
  return keys.reduce((n, k) => {
494
497
  if (k in obj) {
495
- if (!omitUndefined || obj[k] !== undefined)
498
+ if (!omitUndefined || obj[k] !== void 0)
496
499
  n[k] = obj[k];
497
500
  }
498
501
  return n;
@@ -500,7 +503,7 @@ function objectPick(obj, keys, omitUndefined = false) {
500
503
  }
501
504
  function objectOmit(obj, keys, omitUndefined = false) {
502
505
  return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
503
- return (!omitUndefined || value !== undefined) && !keys.includes(key);
506
+ return (!omitUndefined || value !== void 0) && !keys.includes(key);
504
507
  }));
505
508
  }
506
509
  function objectEntries(obj) {
@@ -625,10 +628,10 @@ function refWithControl(initial, options = {}) {
625
628
  if (value === source)
626
629
  return;
627
630
  const old = source;
628
- 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)
629
632
  return;
630
633
  source = value;
631
- (_b = options.onChanged) == null ? undefined : _b.call(options, value, old);
634
+ (_b = options.onChanged) == null ? void 0 : _b.call(options, value, old);
632
635
  if (triggering)
633
636
  trigger();
634
637
  }
@@ -680,9 +683,10 @@ function watchWithFilter(source, cb, options = {}) {
680
683
  function watchPausable(source, cb, options = {}) {
681
684
  const {
682
685
  eventFilter: filter,
686
+ initialState = "active",
683
687
  ...watchOptions
684
688
  } = options;
685
- const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
689
+ const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
686
690
  const stop = watchWithFilter(
687
691
  source,
688
692
  cb,
@@ -824,7 +828,7 @@ function createUntil(r, isNot = false) {
824
828
  if (stop)
825
829
  stop();
826
830
  else
827
- nextTick(() => stop == null ? undefined : stop());
831
+ nextTick(() => stop == null ? void 0 : stop());
828
832
  resolve(v);
829
833
  }
830
834
  },
@@ -838,7 +842,7 @@ function createUntil(r, isNot = false) {
838
842
  const promises = [watcher];
839
843
  if (timeout != null) {
840
844
  promises.push(
841
- 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())
842
846
  );
843
847
  }
844
848
  return Promise.race(promises);
@@ -856,7 +860,7 @@ function createUntil(r, isNot = false) {
856
860
  if (stop)
857
861
  stop();
858
862
  else
859
- nextTick(() => stop == null ? undefined : stop());
863
+ nextTick(() => stop == null ? void 0 : stop());
860
864
  resolve(v1);
861
865
  }
862
866
  },
@@ -871,7 +875,7 @@ function createUntil(r, isNot = false) {
871
875
  if (timeout != null) {
872
876
  promises.push(
873
877
  promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => {
874
- stop == null ? undefined : stop();
878
+ stop == null ? void 0 : stop();
875
879
  return toValue$1(r);
876
880
  })
877
881
  );
@@ -885,7 +889,7 @@ function createUntil(r, isNot = false) {
885
889
  return toBe(null, options);
886
890
  }
887
891
  function toBeUndefined(options) {
888
- return toBe(undefined, options);
892
+ return toBe(void 0, options);
889
893
  }
890
894
  function toBeNaN(options) {
891
895
  return toMatch(Number.isNaN, options);
@@ -986,7 +990,7 @@ function findLast(arr, cb) {
986
990
  if (cb(arr[index], index, arr))
987
991
  return arr[index];
988
992
  }
989
- return undefined;
993
+ return void 0;
990
994
  }
991
995
  function useArrayFindLast(list, fn) {
992
996
  return computed(() => toValue$1(
@@ -1076,7 +1080,7 @@ function useCounter(initialValue = 0, options = {}) {
1076
1080
  }
1077
1081
 
1078
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;
1079
- 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;
1080
1084
  function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
1081
1085
  let m = hours < 12 ? "AM" : "PM";
1082
1086
  if (hasPeriod)
@@ -1099,6 +1103,10 @@ function formatDate(date, formatStr, options = {}) {
1099
1103
  const milliseconds = date.getMilliseconds();
1100
1104
  const day = date.getDay();
1101
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
+ };
1102
1110
  const matches = {
1103
1111
  Yo: () => formatOrdinal(years),
1104
1112
  YY: () => String(years).slice(-2),
@@ -1131,17 +1139,21 @@ function formatDate(date, formatStr, options = {}) {
1131
1139
  A: () => meridiem(hours, minutes),
1132
1140
  AA: () => meridiem(hours, minutes, false, true),
1133
1141
  a: () => meridiem(hours, minutes, true),
1134
- 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" }))
1135
1147
  };
1136
1148
  return formatStr.replace(REGEX_FORMAT, (match, $1) => {
1137
1149
  var _a2, _b;
1138
- 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;
1139
1151
  });
1140
1152
  }
1141
1153
  function normalizeDate(date) {
1142
1154
  if (date === null)
1143
1155
  return new Date(Number.NaN);
1144
- if (date === undefined)
1156
+ if (date === void 0)
1145
1157
  return /* @__PURE__ */ new Date();
1146
1158
  if (date instanceof Date)
1147
1159
  return new Date(date);
@@ -1247,7 +1259,8 @@ function useLastChanged(source, options = {}) {
1247
1259
 
1248
1260
  function useTimeoutFn(cb, interval, options = {}) {
1249
1261
  const {
1250
- immediate = true
1262
+ immediate = true,
1263
+ immediateCallback = false
1251
1264
  } = options;
1252
1265
  const isPending = ref(false);
1253
1266
  let timer = null;
@@ -1262,6 +1275,8 @@ function useTimeoutFn(cb, interval, options = {}) {
1262
1275
  clear();
1263
1276
  }
1264
1277
  function start(...args) {
1278
+ if (immediateCallback)
1279
+ cb();
1265
1280
  clear();
1266
1281
  isPending.value = true;
1267
1282
  timer = setTimeout(() => {
@@ -1350,7 +1365,7 @@ function useToggle(initialValue = false, options = {}) {
1350
1365
  }
1351
1366
 
1352
1367
  function watchArray(source, cb, options) {
1353
- 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)];
1354
1369
  return watch(source, (newList, _, onCleanup) => {
1355
1370
  const oldListRemains = Array.from({ length: oldList.length });
1356
1371
  const added = [];
@@ -1394,7 +1409,7 @@ function watchAtMost(source, cb, options) {
1394
1409
  function watchDebounced(source, cb, options = {}) {
1395
1410
  const {
1396
1411
  debounce = 0,
1397
- maxWait = undefined,
1412
+ maxWait = void 0,
1398
1413
  ...watchOptions
1399
1414
  } = options;
1400
1415
  return watchWithFilter(
@@ -1531,7 +1546,7 @@ function watchTriggerable(source, cb, options = {}) {
1531
1546
  if (!cleanupFn)
1532
1547
  return;
1533
1548
  const fn = cleanupFn;
1534
- cleanupFn = undefined;
1549
+ cleanupFn = void 0;
1535
1550
  fn();
1536
1551
  }
1537
1552
  function onCleanup(callback) {
@@ -1563,7 +1578,7 @@ function getWatchSources(sources) {
1563
1578
  return toValue$1(sources);
1564
1579
  }
1565
1580
  function getOldValue(source) {
1566
- return Array.isArray(source) ? source.map(() => undefined) : undefined;
1581
+ return Array.isArray(source) ? source.map(() => void 0) : void 0;
1567
1582
  }
1568
1583
 
1569
1584
  function whenever(source, cb, options) {
@@ -1571,7 +1586,7 @@ function whenever(source, cb, options) {
1571
1586
  source,
1572
1587
  (v, ov, onInvalidate) => {
1573
1588
  if (v) {
1574
- if (options == null ? undefined : options.once)
1589
+ if (options == null ? void 0 : options.once)
1575
1590
  nextTick(() => stop());
1576
1591
  cb(v, ov, onInvalidate);
1577
1592
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vueuse/shared",
3
3
  "type": "module",
4
- "version": "12.5.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",