// @bun
var{defineProperty:J,getOwnPropertyNames:U,getOwnPropertyDescriptor:X}=Object,Y=Object.prototype.hasOwnProperty;function Z(j){return this[j]}var x=(j)=>{var z=(N??=new WeakMap).get(j),D;if(z)return z;if(z=J({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var E of U(j))if(!Y.call(z,E))J(z,E,{get:Z.bind(j,E),enumerable:!(D=X(j,E))||D.enumerable})}return N.set(j,z),z},N;var _=(j)=>j;function $(j,z){this[j]=_.bind(null,z)}var B=(j,z)=>{for(var D in z)J(j,D,{get:z[D],enumerable:!0,configurable:!0,set:$.bind(z,D)})};var R=(j,z)=>()=>(j&&(z=j(j=0)),z);var S=import.meta.require;function m(){return typeof navigator<"u"&&"wakeLock"in navigator}function O(){let j=m(),z=new Set,D={isSupported:j,isActive:!1,type:null,error:null},E=null,G=null;function H(){z.forEach((F)=>F(D))}function Q(){D={...D,isActive:!1,type:null},E=null,H()}function K(){if(document.visibilityState==="visible"&&D.isActive===!1&&E===null);}async function M(){if(!j)return D={...D,error:Error("Wake Lock API not supported")},H(),!1;try{if(E=await navigator.wakeLock.request("screen"),E.addEventListener("release",Q),!G)document.addEventListener("visibilitychange",K),G=()=>{document.removeEventListener("visibilitychange",K)};return D={...D,isActive:!0,type:"screen",error:null},H(),!0}catch(F){return D={...D,isActive:!1,error:F},H(),!1}}async function I(){if(E)await E.release(),E=null;D={...D,isActive:!1,type:null},H()}async function T(){if(D.isActive)return await I(),!1;else return M()}return{get:()=>D,subscribe:(F)=>{return z.add(F),F(D),()=>{if(z.delete(F),z.size===0)I(),G?.(),G=null}},request:M,release:I,toggle:T,isSupported:()=>j,isActive:()=>D.isActive}}function A(){let j=O();if(j.isSupported())j.request();if(typeof document<"u"){let z=async()=>{if(document.visibilityState==="visible"&&!j.isActive())await j.request()};document.addEventListener("visibilitychange",z);let D=j.subscribe;return{...j,subscribe:(E)=>{let G=D(E);return()=>{G(),document.removeEventListener("visibilitychange",z),j.release()}}}}return j}function C(j){let z=O();async function D(){let E=j();if(E&&!z.isActive())await z.request();else if(!E&&z.isActive())await z.release()}return{...z,check:D}}export{O as useWakeLock,C as useConditionalWakeLock,A as useAutoWakeLock,m as isWakeLockSupported};
