"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var noop=function(){},webviewInMiniappBridgeReadyPromise,webviewInMiniappBridgeInit=function(){return webviewInMiniappBridgeReadyPromise||(webviewInMiniappBridgeReadyPromise=new Promise(function(e,i){window.AlipayJSBridge?e():document.addEventListener("AlipayJSBridgeReady",function(){e()},!1)})),webviewInMiniappBridgeReadyPromise},webviewInMiniappBridge=function(e,i){return webviewInMiniappBridgeInit().then(function(){return new Promise(function(n,r){var a=i.onSuccess||noop,o=i.onFail||noop;if(delete i.onSuccess,delete i.onFail,AlipayJSBridge){var p=e.split("."),t=p.pop()||"",d=p.join(".");AlipayJSBridge.call.apply(null,["webDdExec",{serviceName:d,actionName:t,args:i},function(e){var i={},p=e.content;if(p)try{i=JSON.parse(p)}catch(e){console.error("parse dt api result error",p,e)}e.success?(a.apply(null,[i]),n(i)):(o.apply(null,[i]),r(i))}])}else{var s=new Error("Fatal error, cannot find bridge ,current env is WebView in MiniApp");o(s),r(s)}})})};exports.default=webviewInMiniappBridge;