{"version":3,"file":"useCountdownHover-Ds0unFZR.mjs","sources":["../src/composables/useCountdown.ts","../src/composables/useCountdownHover.ts"],"sourcesContent":["import {useTimestamp, type UseTimestampOptions} from '@vueuse/core'\nimport {computed, type MaybeRefOrGetter, readonly, ref, toRef, watch} from 'vue'\n\n/**\n * A simple interval timer that counts down the remaining seconds\n *\n * @param {MaybeRefOrGetter<number>} length the total amount of time to loop through in ms\n * @param {MaybeRefOrGetter<number>} interval how often the interval should refresh. Default 1000\n * @param {Readonly<UseIntervalFnOptions>} intervalOpts opts to pass to the interval fn. Default {}\n */\nexport const useCountdown = (\n  length: MaybeRefOrGetter<number>,\n  interval: number | 'requestAnimationFrame',\n  timestampOpts: UseTimestampOptions<true> = {}\n) => {\n  const resolvedLength = readonly(toRef(length))\n\n  const isPaused = ref(false)\n\n  const target = ref(Date.now() + resolvedLength.value)\n\n  const {isActive, pause, resume, timestamp} = useTimestamp({\n    interval,\n    controls: true,\n    callback: (v) => {\n      if (v >= target.value) {\n        isPaused.value = false\n        pause()\n      }\n    },\n    ...timestampOpts,\n  })\n\n  const value = computed(() => target.value - timestamp.value)\n\n  const restart = () => {\n    target.value = Date.now() + resolvedLength.value\n    resume()\n  }\n  watch(resolvedLength, () => {\n    restart()\n  })\n\n  const myPause = () => {\n    isPaused.value = true\n    pause()\n  }\n  const myResume = () => {\n    isPaused.value = false\n    const remainingTime = target.value - timestamp.value\n    target.value = Date.now() + remainingTime\n    resume()\n  }\n  const stop = () => {\n    pause()\n    timestamp.value = target.value\n    isPaused.value = false\n  }\n\n  return {\n    isActive: readonly(isActive),\n    isPaused: readonly(isPaused),\n    stop,\n    pause: myPause,\n    resume: myResume,\n    restart,\n    value,\n  }\n}\n","import {useElementHover} from '@vueuse/core'\nimport {type MaybeRefOrGetter, type Ref, toValue, watch} from 'vue'\n\nexport const useCountdownHover = (\n  element: Ref<HTMLElement | null>,\n  props: MaybeRefOrGetter<{\n    noHoverPause?: boolean\n    noResumeOnHoverLeave?: boolean\n  }>,\n  actions: {\n    pause: () => void\n    resume: () => void\n  }\n) => {\n  const isHovering = useElementHover(element)\n\n  const onMouseEnter = () => {\n    if (toValue(props).noHoverPause) return\n    actions.pause()\n  }\n  const onMouseLeave = () => {\n    if (toValue(props).noResumeOnHoverLeave) return\n    actions.resume()\n  }\n\n  watch(isHovering, (newValue) => {\n    if (newValue) {\n      onMouseEnter()\n      return\n    }\n    onMouseLeave()\n  })\n\n  return {\n    isHovering,\n  }\n}\n"],"names":[],"mappings":";;AAUO,MAAM,eAAe,CAC1B,QACA,UACA,gBAA2C,CAAA,MACxC;AACH,QAAM,iBAAiB,SAAS,MAAM,MAAM,CAAC;AAEvC,QAAA,WAAW,IAAI,KAAK;AAE1B,QAAM,SAAS,IAAI,KAAK,IAAI,IAAI,eAAe,KAAK;AAEpD,QAAM,EAAC,UAAU,OAAO,QAAQ,UAAA,IAAa,aAAa;AAAA,IACxD;AAAA,IACA,UAAU;AAAA,IACV,UAAU,CAAC,MAAM;AACX,UAAA,KAAK,OAAO,OAAO;AACrB,iBAAS,QAAQ;AACX;MACR;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EAAA,CACJ;AAED,QAAM,QAAQ,SAAS,MAAM,OAAO,QAAQ,UAAU,KAAK;AAE3D,QAAM,UAAU,MAAM;AACpB,WAAO,QAAQ,KAAK,IAAI,IAAI,eAAe;AACpC;EAAA;AAET,QAAM,gBAAgB,MAAM;AAClB;EAAA,CACT;AAED,QAAM,UAAU,MAAM;AACpB,aAAS,QAAQ;AACX;EAAA;AAER,QAAM,WAAW,MAAM;AACrB,aAAS,QAAQ;AACX,UAAA,gBAAgB,OAAO,QAAQ,UAAU;AACxC,WAAA,QAAQ,KAAK,IAAA,IAAQ;AACrB;EAAA;AAET,QAAM,OAAO,MAAM;AACX;AACN,cAAU,QAAQ,OAAO;AACzB,aAAS,QAAQ;AAAA,EAAA;AAGZ,SAAA;AAAA,IACL,UAAU,SAAS,QAAQ;AAAA,IAC3B,UAAU,SAAS,QA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