bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
104 lines (103 loc) • 2.92 kB
JavaScript
require("./chunk-CoQrYLCe.js");
const require_dist = require("./dist-B_c893QG.js");
let vue = require("vue");
//#region src/composables/useCountdown.ts
/**
* A simple interval timer that counts down the remaining seconds
*
* @param {MaybeRefOrGetter<number>} length the total amount of time to loop through in ms
* @param {MaybeRefOrGetter<number>} interval how often the interval should refresh. Default 1000
* @param {Readonly<UseIntervalFnOptions>} intervalOpts opts to pass to the interval fn. Default {}
*/
var useCountdown = (length, interval, timestampOpts = {}) => {
const resolvedLength = (0, vue.readonly)((0, vue.toRef)(length));
const isPaused = (0, vue.ref)(false);
const target = (0, vue.ref)(Date.now() + resolvedLength.value);
const { isActive, pause, resume, timestamp } = require_dist.useTimestamp({
interval,
controls: true,
callback: (v) => {
if (v >= target.value) {
isPaused.value = false;
pause();
}
},
...timestampOpts
});
(0, vue.watch)(require_dist.useDocumentVisibility(), (newVisibility) => {
if (newVisibility === "visible" && isActive.value && !isPaused.value) {
if (Date.now() >= target.value) {
isPaused.value = false;
pause();
}
}
});
const value = (0, vue.computed)(() => target.value - timestamp.value);
const restart = () => {
target.value = Date.now() + resolvedLength.value;
resume();
};
(0, vue.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: (0, vue.readonly)(isActive),
isPaused: (0, vue.readonly)(isPaused),
stop,
pause: myPause,
resume: myResume,
restart,
value
};
};
//#endregion
//#region src/composables/useCountdownHover.ts
var useCountdownHover = (element, { modelValueIgnoresHover, noHoverPause, noResumeOnHoverLeave }, actions) => {
const isHovering = require_dist.useElementHover(element);
const onMouseEnter = () => {
if ((0, vue.toValue)(noHoverPause)) return;
actions.pause();
};
const onMouseLeave = () => {
if ((0, vue.toValue)(noResumeOnHoverLeave)) return;
actions.resume();
};
(0, vue.watch)(isHovering, (newValue) => {
if ((0, vue.toValue)(modelValueIgnoresHover)) return;
if (newValue) {
onMouseEnter();
return;
}
onMouseLeave();
});
return { isHovering };
};
//#endregion
Object.defineProperty(exports, "useCountdown", {
enumerable: true,
get: function() {
return useCountdown;
}
});
Object.defineProperty(exports, "useCountdownHover", {
enumerable: true,
get: function() {
return useCountdownHover;
}
});
//# sourceMappingURL=useCountdownHover-D044mFuX.js.map