// @bun
var{defineProperty:I,getOwnPropertyNames:U,getOwnPropertyDescriptor:V}=Object,W=Object.prototype.hasOwnProperty;function X(j){return this[j]}var _=(j)=>{var q=(M??=new WeakMap).get(j),A;if(q)return q;if(q=I({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var F of U(j))if(!W.call(q,F))I(q,F,{get:X.bind(j,F),enumerable:!(A=V(j,F))||A.enumerable})}return M.set(j,q),q},M;var Y=(j)=>j;function Z(j,q){this[j]=Y.bind(null,q)}var $=(j,q)=>{for(var A in q)I(j,A,{get:q[A],enumerable:!0,configurable:!0,set:Z.bind(q,A)})};var x=(j,q)=>()=>(j&&(q=j(j=0)),q);var B=import.meta.require;function O(){return typeof window<"u"&&"BroadcastChannel"in window}function E(j,q={}){let A=O(),F=new Set,G=new Map,z={isSupported:A,isClosed:!1,channel:null,lastMessage:null,error:null};function H(){F.forEach((w)=>w(z))}function J(w,D){let K=G.get(w);if(K)K.forEach((T)=>T(D))}if(A)try{let w=new BroadcastChannel(j);w.onmessage=(D)=>{z={...z,lastMessage:D.data},H(),J("message",D),q.onMessage?.(D)},w.onmessageerror=(D)=>{z={...z,error:Error("Message error")},H(),J("error",D),q.onError?.(D)},z={...z,channel:w}}catch(w){z={...z,error:w}}function P(w){if(z.channel&&!z.isClosed)z.channel.postMessage(w)}function Q(){if(z.channel&&!z.isClosed)z.channel.close(),z={...z,isClosed:!0,channel:null},H()}function R(w,D){if(!G.has(w))G.set(w,new Set);return G.get(w).add(D),()=>{G.get(w)?.delete(D)}}return{get:()=>z,subscribe:(w)=>{return F.add(w),w(z),()=>{F.delete(w)}},post:P,close:Q,isSupported:()=>A,on:R}}function S(j,q){if(!O())return;let A=new BroadcastChannel(j);A.postMessage(q),A.close()}export{E as useBroadcastChannel,O as isBroadcastChannelSupported,S as broadcast};
