@ssgoi/react
Version:
React bindings for SSGOI - Native app-like page transitions for React applications
44 lines (43 loc) • 1.36 kB
JavaScript
"use client";
import { jsx as g } from "react/jsx-runtime";
import a, { useMemo as m, useRef as c, useCallback as v } from "react";
import { SsgoiProvider as y } from "./context.js";
import { createSggoiTransitionContext as R, createAnyOrderDetector as S } from "@ssgoi/core";
function d(t) {
const n = c(null), r = c(null);
t !== null && n.current !== t && (r.current = n.current, n.current = t);
const e = c({ from: null, to: "" });
return t !== null && (e.current = { from: r.current, to: t }), v(() => e.current, []);
}
function p(t) {
return {
trigger() {
},
get(n) {
const { from: r, to: e } = t();
return !r || !e || r === e ? Promise.resolve(null) : Promise.resolve({ from: r, to: e });
}
};
}
const C = a.memo(
({ config: t, children: n, usePathname: r }) => {
const e = r?.() ?? null, o = d(e), l = m(() => {
const { getTransition: s, hasMatchingTransition: f } = R(t, {
createNavigationDetector: r ? () => p(o) : S
});
return {
getTransition: s,
getInitialStyle: () => {
if (!r)
return {};
const { from: i, to: u } = o();
return !i || i === u ? {} : f(i, u) ? { visibility: "hidden" } : {};
}
};
}, [t, r, o]);
return /* @__PURE__ */ g(y, { value: l, children: n });
}
);
export {
C as Ssgoi
};