import{I as a,v as u}from"./bootstrap-DlNJH-GE.js";class h{local=new a;runtime;tabs;fanOutToTabs;listener;constructor(t={}){const s=globalThis.chrome;this.runtime=t.runtime??s?.runtime,this.tabs=t.tabs??s?.tabs,this.fanOutToTabs=t.fanOutToTabs??!!s?.tabs,this.runtime&&(this.listener=i=>{o(i)&&this.local.publish(i.subject,i.payload)},this.runtime.onMessage.addListener(this.listener))}async close(){this.runtime&&this.listener&&this.runtime.onMessage.removeListener(this.listener),this.listener=void 0}async publish(t,s){const i={_wkmsBus:!0,subject:t,payload:s,ts:new Date().toISOString()};if(await this.local.publish(t,s),!!this.runtime){try{await this.runtime.sendMessage(i)}catch{}if(this.fanOutToTabs&&this.tabs)try{const r=await this.tabs.query({});for(const n of r)n.id!=null&&await this.tabs.sendMessage(n.id,i).catch(()=>{})}catch{}}}subscribe(t,s){return this.local.subscribe(t,s)}hasSubscribers(t){return this.local.hasSubscribers(t)}}function o(e){return typeof e=="object"&&e!==null&&e._wkmsBus===!0&&typeof e.subject=="string"}function b(e,t){return u(e,t)}export{h as ChromeRuntimeBus,b as _testSubjectMatches};
//# sourceMappingURL=chrome_runtime_bus-BAzfdk6Q.js.map
