adverich-kun-ui
Version:
Una librería de componentes Vue.js con Tailwind CSS
48 lines (47 loc) • 1.01 kB
JavaScript
import { ref as m, watch as a, onBeforeUnmount as f } from "vue";
function d(u, s, e = {}) {
const r = m(null);
let t = null;
const v = {
root: null,
rootMargin: "0px",
threshold: 0
}, l = () => {
var i;
const o = u, c = ((i = e.root) == null ? void 0 : i.value) || e.root || null;
if (!o) {
t = setTimeout(() => {
l();
}, 100);
return;
}
r.value || (clearTimeout(t), t = null, r.value = new IntersectionObserver(s, {
...v,
...e,
root: c
}), r.value.observe(o));
}, n = () => {
r.value && (r.value.disconnect(), r.value = null), t && (clearTimeout(t), t = null);
};
a(
() => u,
(o) => {
n(), requestAnimationFrame(() => {
l();
});
},
{ immediate: !0 }
), e.root && e.root.value !== void 0 && a(
() => e.root.value,
(o) => {
n(), requestAnimationFrame(() => {
l();
});
}
), f(() => {
n();
});
}
export {
d as useIntersectionObserver
};