/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@apps-in-toss/bridge-core@2.4.7/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var NativeWindow=class{get _window(){return"undefined"!=typeof window?window:{ReactNativeWebView:{postMessage:()=>{}},__GRANITE_NATIVE_EMITTER:{on:()=>()=>{}},__CONSTANT_HANDLER_MAP:{}}}postMessage(e){const n=this._window.ReactNativeWebView;if(!n)throw new Error("ReactNativeWebView is not available in browser environment");n.postMessage(JSON.stringify(e))}on(e,n){const t=this._window.__GRANITE_NATIVE_EMITTER;if(!t)throw new Error("__GRANITE_NATIVE_EMITTER is not available");return t.on(e,n)}getConstant(e){const n=this._window.__CONSTANT_HANDLER_MAP;if(n&&e in n)return n[e];throw new Error(`${e} is not a constant handler`)}},nativeWindow=new NativeWindow,createEventId=()=>Math.random().toString(36).substring(2,15),deserializeError=e=>{if(e&&e.__isError){const n=new Error(e.message);for(const[t,r]of Object.entries(e))n[t]=r;return n}return e};function createAsyncBridge(e){return(...n)=>{const t=createEventId(),r=[],o=()=>{for(const e of r)e()};return new Promise(((i,s)=>{r.push(nativeWindow.on(`${e}/resolve/${t}`,(e=>{o(),i(e)}))),r.push(nativeWindow.on(`${e}/reject/${t}`,(e=>{o(),s(deserializeError(e))}))),nativeWindow.postMessage({type:"method",functionName:e,eventId:t,args:n})}))}}function createEventBridge(e){return n=>{const t=createEventId(),r=[nativeWindow.on(`${e}/onEvent/${t}`,(e=>{n.onEvent(e)})),nativeWindow.on(`${e}/onError/${t}`,(e=>{n.onError(deserializeError(e))}))];return nativeWindow.postMessage({type:"addEventListener",functionName:e,eventId:t,args:n.options}),()=>{nativeWindow.postMessage({type:"removeEventListener",functionName:e,eventId:t}),r.forEach((e=>e()))}}}function createConstantBridge(e){return()=>nativeWindow.getConstant(e)}export{createAsyncBridge,createConstantBridge,createEventBridge};
//# sourceMappingURL=/sm/9cbe28b32412c51cad9827565097ca133701897fc58e15078a94f0463f7df2ab.map