UNPKG

@aigamo/nostalgic-diva

Version:

React function components for imperatively controlling embedded players (audio, Niconico, SoundCloud and YouTube) using refs.

58 lines (57 loc) 1.35 kB
import y, { useRef as u, useState as C, useEffect as i } from "react"; import { L as M, n as E, P as d } from "./index-DzXJDFxB.js"; function D() { const t = u(!0); return t.current ? (t.current = !1, !0) : t.current; } const V = (t, e) => t === e; function b(t, e = V) { const r = u(), n = u(t); return !D() && !e(n.current, t) && (r.current = n.current, n.current = t), r.current; } const w = ({ logger: t, type: e, loadScript: r, playerFactory: n, onControllerChange: l, videoId: c, options: P, controllerFactory: m, children: F }) => { t.log(M.Debug, "PlayerContainer"); const f = u(c), R = u(void 0), [a, L] = C(), [o, h] = C(E); i(() => { l?.(o); }, [o, l]), i(() => { (r?.() ?? Promise.resolve()).then(() => { n(R.current, f.current).then( (s) => { L(s); } ); }); }, [r, n]), i(() => { if (a === void 0) return; const s = new d( t, e, a, P, m ); return s.attach(f.current).then(() => h(s)), () => { s.detach().finally(() => h(E)); }; }, [t, e, r, a, P, m]); const v = b(c); return i(() => { v !== void 0 && o.loadVideo(c); }, [v, c, o]), /* @__PURE__ */ y.createElement(y.Fragment, null, F(R, f.current)); }; export { w as P }; //# sourceMappingURL=PlayerContainer-BSDtKMGl.js.map