motion-plus-vue
Version:
Motion Plus Vue
39 lines (38 loc) • 917 B
JavaScript
import { noop as s } from "motion-v";
import { ref as d, watch as f } from "vue";
let r = null;
function m() {
const e = /* @__PURE__ */ new Set();
function n() {
e.forEach((t) => t.show());
}
function o() {
e.forEach((t) => t.hide());
}
function i() {
document.body.addEventListener("mouseenter", n), document.body.addEventListener("mouseleave", o);
}
function u() {
document.body.removeEventListener("mouseenter", n), document.body.removeEventListener("mouseleave", o);
}
return {
on: (t) => typeof window > "u" ? s : (e.size || i(), e.add(t), () => {
e.delete(t), e.size === 0 && u();
})
};
}
function c() {
return r || (r = m()), r;
}
function l(e) {
const n = d(!0);
return f(n, () => c().on({
show: () => {
n.value || (e(), n.value = !0);
},
hide: () => n.value = !1
}), { immediate: !0 }), n;
}
export {
l as useCursorIsInView
};