@aplus-frontend/ui
Version:
52 lines (51 loc) • 1.26 kB
JavaScript
import { isClient as d } from "@vueuse/core";
import { ref as c, computed as f, isRef as v, unref as u, watch as p } from "vue";
const a = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set();
d && document.addEventListener("fullscreenchange", () => {
if (o.forEach((e) => e.value = !1), document.fullscreenElement) {
const e = a.get(
document.fullscreenElement
);
e && (e.value = !0);
}
});
const E = (e = c(null)) => {
const i = f({
get: () => u(e),
set: (t) => {
v(e) && (e.value = t);
}
}), l = c(!1);
o.add(l), p(
() => e.value,
(t, n) => {
t && a.set(t, l), n && a.delete(n);
},
{
immediate: !0,
flush: "post"
}
);
async function r(t = !1) {
await s();
const n = u(e);
return n && (t || !document.fullscreenElement) ? (await n.requestFullscreen(), l.value = !0, !0) : !1;
}
async function s(t = !1) {
const n = u(e);
return t || n && document.fullscreenElement === n ? (await document.exitFullscreen(), l.value = !1, !0) : !1;
}
async function m(t = !1) {
return await (u(l) ? s(t) : r(t));
}
return {
target: i,
full: f(() => u(l)),
enter: r,
exit: s,
toggle: m
};
};
export {
E as useFullScreen
};