UNPKG

bootstrap-vue-next

Version:

BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.

84 lines (83 loc) 2.06 kB
import { k as useTimestamp, l as useElementHover } from "./index-Cv338r2J.mjs"; import { readonly, toRef, ref, computed, watch, toValue } from "vue"; const useCountdown = (length, interval, timestampOpts = {}) => { const resolvedLength = readonly(toRef(length)); const isPaused = ref(false); const target = ref(Date.now() + resolvedLength.value); const { isActive, pause, resume, timestamp } = useTimestamp({ interval, controls: true, callback: (v) => { if (v >= target.value) { isPaused.value = false; pause(); } }, ...timestampOpts }); const value = computed(() => target.value - timestamp.value); const restart = () => { target.value = Date.now() + resolvedLength.value; resume(); }; watch(resolvedLength, () => { if (resolvedLength.value > 0) { restart(); } }); const myPause = () => { isPaused.value = true; pause(); }; const myResume = () => { isPaused.value = false; const remainingTime = target.value - timestamp.value; target.value = Date.now() + remainingTime; resume(); }; const stop = () => { pause(); timestamp.value = target.value; isPaused.value = false; }; return { isActive: readonly(isActive), isPaused: readonly(isPaused), stop, pause: myPause, resume: myResume, restart, value }; }; const useCountdownHover = (element, { modelValueIgnoresHover, noHoverPause, noResumeOnHoverLeave }, actions) => { const isHovering = useElementHover(element); const onMouseEnter = () => { if (toValue(noHoverPause)) return; actions.pause(); }; const onMouseLeave = () => { if (toValue(noResumeOnHoverLeave)) return; actions.resume(); }; watch(isHovering, (newValue) => { if (toValue(modelValueIgnoresHover)) return; if (newValue) { onMouseEnter(); return; } onMouseLeave(); }); return { isHovering }; }; export { useCountdownHover as a, useCountdown as u }; //# sourceMappingURL=useCountdownHover-CU-yyYxs.mjs.map