@vrojs/use 0.0.3 → 0.0.5

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.d.ts CHANGED
@@ -68,7 +68,17 @@ declare function useComposition(): {
68
68
  handleCompositionEnd: (event: CompositionEvent) => void;
69
69
  };
70
70
 
71
- declare function useCountDown(start?: number): readonly [vue.Ref<number, number>, (st?: number) => void];
71
+ interface UseCountDownOptions {
72
+ /**
73
+ * 每次倒计时值变化时触发,包括初始值和最终的 0
74
+ */
75
+ onChange?: (count: number) => void;
76
+ /**
77
+ * 倒计时结束时触发
78
+ */
79
+ onFinish?: () => void;
80
+ }
81
+ declare function useCountDown(start?: number, options?: UseCountDownOptions): readonly [vue.Ref<number, number>, (st?: number) => void];
72
82
 
73
83
  type Loose<T> = T & {
74
84
  [key: string]: any;
@@ -273,4 +283,4 @@ declare function useVisible<T extends Record<string, any>, R = any>(options?: Us
273
283
  hide: (reason?: any) => Promise<void>;
274
284
  };
275
285
 
276
- export { type TransferOptions, type UseAsyncTaskOptions, type UseAsyncTaskResult, type UseBodyScrollLockReturn, type UseEventListenerOptions, type UseKeepAliveOptions, type UseKeepAliveState$1 as UseKeepAliveState, type UseKeepPositionOptions, type UseKeepPositionState, type UsePagingOptions, type UsePagingStatus, type UsePagingTask, type UsePagingTaskOptions, type UsePagingTaskResult, type UsePagingTriggerOptions, type UseSetState, type UseSetStateAction, type UseTransitionNameOptions, type UseTransitionNameState, type UseVisibleOptions, type UseVisibleShowOptions, debounceRef, useAsyncTask, useBodyScrollLock, useComposition, useCountDown, useEventListener, useId, useKeepAlive, useKeepAliveByPosition, useKeepPosition, usePaging, useParams, useQuery, useState, useToggle, useTransfer, useTransitionName, useVisible };
286
+ export { type TransferOptions, type UseAsyncTaskOptions, type UseAsyncTaskResult, type UseBodyScrollLockReturn, type UseCountDownOptions, type UseEventListenerOptions, type UseKeepAliveOptions, type UseKeepAliveState$1 as UseKeepAliveState, type UseKeepPositionOptions, type UseKeepPositionState, type UsePagingOptions, type UsePagingStatus, type UsePagingTask, type UsePagingTaskOptions, type UsePagingTaskResult, type UsePagingTriggerOptions, type UseSetState, type UseSetStateAction, type UseTransitionNameOptions, type UseTransitionNameState, type UseVisibleOptions, type UseVisibleShowOptions, debounceRef, useAsyncTask, useBodyScrollLock, useComposition, useCountDown, useEventListener, useId, useKeepAlive, useKeepAliveByPosition, useKeepPosition, usePaging, useParams, useQuery, useState, useToggle, useTransfer, useTransitionName, useVisible };
package/dist/index.js CHANGED
@@ -197,20 +197,22 @@ function useComposition() {
197
197
 
198
198
  // src/useCountDown/index.ts
199
199
  import { ref as ref3 } from "vue";
200
- function useCountDown(start = 60) {
200
+ function useCountDown(start = 60, options = {}) {
201
201
  const countRef = ref3(0);
202
202
  let timer;
203
203
  const trigger = (st = start) => {
204
204
  clearTimeout(timer);
205
205
  let loop;
206
206
  (loop = (count) => {
207
+ var _a, _b;
208
+ count = Math.max(count, 0);
207
209
  countRef.value = count;
210
+ (_a = options.onChange) == null ? void 0 : _a.call(options, count);
208
211
  if (count <= 0) {
209
- countRef.value = 0;
212
+ (_b = options.onFinish) == null ? void 0 : _b.call(options);
210
213
  return;
211
214
  }
212
- count--;
213
- timer = setTimeout(loop, 1e3, count);
215
+ timer = setTimeout(loop, 1e3, count - 1);
214
216
  })(st);
215
217
  };
216
218
  return [countRef, trigger];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrojs/use",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "vrojs composables",
6
6
  "main": "dist/index.js",