gsap-vue
Version:
Composable Vue 3 para usar GSAP con contexto (inspirado en @gsap/react)
45 lines (44 loc) • 1.51 kB
JavaScript
import { ref as c, onMounted as w, onBeforeUnmount as R, watch as b, isRef as G } from "vue";
import P from "gsap";
let A = P;
const y = (e) => e && !Array.isArray(e) && typeof e == "object", f = [], j = {};
function g(e) {
return e ? G(e) ? e.value : e instanceof HTMLElement || typeof e == "string" ? e : (console.warn("⚠️ Invalid scope provided to useGSAP:", e), null) : null;
}
function x(e, s) {
let r = null, o = f, n = j;
y(e) ? (n = e, o = n.dependencies || f) : (r = e, y(s) ? (n = s, o = n.dependencies || f) : o = s || f), r && typeof r != "function" && console.warn("First parameter must be a function or config object");
const l = c(g(n.scope)), t = c(null), d = c(!1), v = () => {
m(), t.value = A.context(() => {
}, l.value), r && t.value.add(() => {
l.value && r();
}, l.value);
}, S = (a) => (...i) => {
var u;
return (u = t.value) == null ? void 0 : u.add(() => a(...i));
}, m = () => {
var a, i, u, p;
if (t.value)
try {
(i = (a = t.value).kill) == null || i.call(a), (p = (u = t.value).revert) == null || p.call(u), t.value = null;
} catch (h) {
n.debug && console.warn("useGSAP: error during safeRevert()", h);
}
};
return w(() => {
l.value = g(n.scope), d.value = !0, v();
}), R(() => m()), o.length > 0 && b(
o,
() => {
d.value && v();
},
{ immediate: !0 }
), { context: t, contextSafe: S };
}
x.register = (e) => {
A = e;
};
x.headless = !0;
export {
x as useGSAP
};