@bud-fe/h5-native-bridge 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).NativeBridge={})}(this,function(e){"use strict";var t=Object.defineProperty,i=(e,i,s)=>(((e,i,s)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s})(e,"symbol"!=typeof i?i+"":i,s),s),s=(e=>(e[e.SUCCESS=0]="SUCCESS",e[e.JSON_ERROR=1]="JSON_ERROR",e[e.SYSTEM_ERROR=2]="SYSTEM_ERROR",e[e.TIMEOUT=3]="TIMEOUT",e[e.PLUGIN_NOT_INITIALIZED=4]="PLUGIN_NOT_INITIALIZED",e[e.INVALID_ACTION=5]="INVALID_ACTION",e))(s||{});const o=(e,t,i)=>{const s=new Error(t);return s.code=e,s.details=i,s},r=class e{constructor(e={}){i(this,"callbackMap"),i(this,"callbackId"),i(this,"isReady"),i(this,"readyCallbacks"),i(this,"debugMode"),i(this,"defaultTimeout"),i(this,"plugins"),i(this,"pendingCalls"),i(this,"errorHandler"),i(this,"eventListeners",new Map),i(this,"nativeEventHandlers",new Map),i(this,"VERSION","1.0.0"),i(this,"API_VERSION","1"),i(this,"methodRegistry",new Map),this.callbackMap=new Map,this.callbackId=1,this.isReady=!1,this.readyCallbacks=[],this.debugMode=e.debug||!0,this.defaultTimeout=e.timeout||1e7,this.plugins=new Map,this.pendingCalls=new Map,this.errorHandler=e.errorHandler,this.setupBridge(),e.plugins&&e.plugins.length>0&&e.plugins.forEach(e=>this.use(e))}static getInstance(t={}){return e.instance?t.plugins&&t.plugins.length>0&&t.plugins.forEach(t=>{e.instance.use(t)}):e.instance=new e(t),e.instance}onNativeEvent(e,t){this.nativeEventHandlers.has(e)||this.nativeEventHandlers.set(e,new Set),this.nativeEventHandlers.get(e).add(t)}offNativeEvent(e,t){var i;null==(i=this.nativeEventHandlers.get(e))||i.delete(t)}dispatchNativeEvent(e,t){var i;this.debugMode&&this.log(`分发原生事件: ${e}`,t),null==(i=this.nativeEventHandlers.get(e))||i.forEach(i=>{try{i({type:e,data:t})}catch(s){this.error(`分发原生事件 ${e} 失败`,s)}})}registerMethod(e,t){this.methodRegistry.has(e)&&this.warn(`方法 ${e} 已注册,将被覆盖`),this.methodRegistry.set(e,t),this[e]=t}use(e){if(!e||!e.name||!e.install||"function"!=typeof e.install)throw o(s.PLUGIN_NOT_INITIALIZED,`无效的插件: ${(null==e?void 0:e.name)||"未命名"}`);if(this.plugins.has(e.name))return this.warn(`插件 ${e.name} 已经安装`),this;try{const t={bridge:this};e.install(t),this.plugins.set(e.name,e),this.log(`插件 ${e.name}@${e.version} 安装成功`)}catch(t){throw o(s.SYSTEM_ERROR,`安装插件 ${e.name} 失败`,t)}return this}hasPlugin(e){return this.plugins.has(e)}getPlugin(e){return this.plugins.get(e)}setupBridge(){try{if(this.checkIsInApp()){window.nativeBridgeCallback=this.handleNativeCallback.bind(this),window.nativeBridgeDispatchEvent=(e,t)=>{this.dispatchNativeEvent(e,t)},this.callNative({action:"ready",params:{version:this.VERSION,apiVersion:this.API_VERSION}},{success:()=>{this.log("App已准备就绪=====>"),this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]},fail:e=>{this.error("App准备就绪失败",e)}});const e=()=>{this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]};document.addEventListener("NativeBridgeReady",e),this.eventListeners.set("NativeBridgeReady",e)}else setTimeout(()=>{this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]},0)}catch(e){this.error("设置桥接环境失败",e)}}destroy(){this.eventListeners.forEach((e,t)=>{document.removeEventListener(t,e)}),this.eventListeners.clear(),this.callbackMap.clear(),this.pendingCalls.forEach(e=>clearTimeout(e)),this.pendingCalls.clear(),window.nativeBridgeCallback=void 0}checkIsInApp(){var e;try{const t=navigator.userAgent.toLowerCase();return console.log(`[NativeBridge]--userAgent ${t}`),console.log(`[NativeBridge]--messageHandlers ${JSON.stringify(null==(e=window.webkit)?void 0:e.messageHandlers)}`),!0}catch(t){return this.error("检测App环境失败",t),!1}}ready(e){this.isReady?e():this.readyCallbacks.push(e)}callNative(e,t){var i;const r=`cb_${this.callbackId++}_${Date.now()}`,{action:a,params:n={},timeout:c=this.defaultTimeout,retryCount:l=0,retryDelay:h=1e3}=e;if(t&&(this.callbackMap.set(r,t),c>0)){const e=new AbortController,i=setTimeout(()=>{var i,d;if(!e.signal.aborted&&this.callbackMap.has(r))if(this.callbackMap.delete(r),this.pendingCalls.delete(r),l>0)this.log(`调用 ${a} 超时,${h}ms后重试 (剩余重试次数: ${l})`),setTimeout(()=>{e.signal.aborted||this.callNative({action:a,params:n,timeout:c,retryCount:l-1,retryDelay:h},t)},h);else{const e=o(s.TIMEOUT,`调用 ${a} 超时 (${c}ms)`);null==(i=t.fail)||i.call(t,e),null==(d=t.complete)||d.call(t),this.error(`调用超时: ${a}`,e)}},c);this.pendingCalls.set(r,i),e.signal.addEventListener("abort",()=>{clearTimeout(i),this.pendingCalls.delete(r)})}const d={action:a,params:n,timeout:c,callbackId:r};this.debugMode&&this.log(`调用原生方法: ${a}`,n);try{this.checkIsInApp()?this.sendToNative(d):this.mockNativeCall(d)}catch(I){this.error(`调用原生方法 ${a} 失败`,I),null==(i=null==t?void 0:t.fail)||i.call(t,I),this.releaseCallback(r)}return r}callNativeSync(e,t,i){var r,a,c,l,h,d,I;let u;try{const n=JSON.stringify({action:e,params:t}),d="undefined"!=typeof window?window:void 0;if(null==(c=null==(a=null==(r=null==d?void 0:d.webkit)?void 0:r.messageHandlers)?void 0:a.nativeBridge)?void 0:c.postSyncMessage)this.log(`发送消息到 iOS WKWebView: ${n}`),u=d.webkit.messageHandlers.nativeBridge.postSyncMessage(n);else if(null==(l=null==d?void 0:d.AndroidBridge)?void 0:l.postSyncMessage)this.log(`发送消息到安卓原生App: ${n}`),u=d.AndroidBridge.postSyncMessage(n);else if(d)try{const e=document.createElement("iframe");return e.style.display="none",e.src=`yourapp://bridge?message=${encodeURIComponent(n)}`,document.body.appendChild(e),void setTimeout(()=>{document.body.removeChild(e)},0)}catch(g){throw null==(h=null==i?void 0:i.fail)||h.call(i,g),o(s.SYSTEM_ERROR,`创建 iframe 失败: ${g.message}`)}}catch(N){throw null==(d=null==i?void 0:i.fail)||d.call(i,N),o(s.SYSTEM_ERROR,`发送消息到原生App失败: ${N.message}`)}return this.debugMode&&this.log("收到原生回调: success",u),null==(I=null==i?void 0:i.success)||I.call(i,n(u)),n(u)}sendToNative(e){try{const t=JSON.stringify(e);if("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.nativeBridge)this.log(`发送消息到 iOS WKWebView: ${t}`),window.webkit.messageHandlers.nativeBridge.postMessage(t);else if(window.AndroidBridge&&window.AndroidBridge.postMessage)this.log(`发送消息到安卓原生App: ${t}`),window.AndroidBridge.postMessage(t);else{const e=document.createElement("iframe");e.style.display="none",e.src=`yourapp://bridge?message=${encodeURIComponent(t)}`,document.body.appendChild(e),setTimeout(()=>{document.body.removeChild(e)},0)}}catch(t){throw o(s.SYSTEM_ERROR,`发送消息到原生App失败: ${t.message}`)}}handleNativeCallback(e,t,i){const s=this.callbackMap.get(e);if(s){this.pendingCalls.has(e)&&(clearTimeout(this.pendingCalls.get(e)),this.pendingCalls.delete(e)),this.debugMode&&this.log(`收到原生回调: ${t}`,i);try{if("success"===t&&s.success)s.success(n(i));else if("fail"===t&&s.fail){let e;i instanceof Error?e=i:"string"==typeof i?e=new Error(i):i&&i.message?(e=new Error(i.message),i.code&&(e.code=i.code)):e=new Error("未知错误"),s.fail(e)}s.complete&&s.complete()}catch(o){this.error("执行回调函数时出错",o)}this.callbackMap.delete(e)}else this.warn(`未找到回调ID: ${e}`)}mockNativeCall(e){if(this.debugMode&&this.log("模拟原生调用:",e),"ready"===e.action)setTimeout(()=>{const e=new Event("NativeBridgeReady");document.dispatchEvent(e)},100);else{for(const[t]of this.plugins.entries())if(t.mockAction&&"function"==typeof t.mockAction&&t.mockAction(e))return;this.warn(`未实现的模拟功能: ${e.action}`)}}releaseCallback(e){this.callbackMap.has(e)&&this.callbackMap.delete(e),this.pendingCalls.has(e)&&(clearTimeout(this.pendingCalls.get(e)),this.pendingCalls.delete(e))}setDebug(e){this.debugMode=e,e?console.log("[NativeBridge] 调试模式已开启 ✅"):console.log("[NativeBridge] 调试模式已关闭 ❌")}setErrorHandler(e){this.errorHandler=e}getInstalledPlugins(){return Array.from(this.plugins.keys())}isDebugMode(){return this.debugMode}log(e,...t){e.includes("调试模式已")?console.log(`[NativeBridge] 📢 ${e}`,...t):this.debugMode&&console.log(`[NativeBridge] ${e}`,...t)}warn(e,...t){this.debugMode&&console.warn(`[NativeBridge] ⚠️ ${e}`,...t)}error(e,t){if(console.error(`[NativeBridge] 🛑 ${e}:`,t),this.errorHandler)try{this.errorHandler(t,e)}catch(i){console.error("[NativeBridge] 错误处理器执行失败:",i)}}getCallBackMap(){return this.callbackMap}};i(r,"instance");let a=r;function n(e){if(null==e)return e;if("string"!=typeof e)return e;if(""===e)return e;try{const t=e.trim();return t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")?(JSON.parse(e),JSON.parse(e)):e}catch(t){return e}}const c=e=>a.getInstance(e);a.getInstance();const l=new class{constructor(){i(this,"name","location"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getLocationSync",this.getLocationSync.bind(this)),e.bridge.registerMethod("getLocation",this.getLocation.bind(this)),e.bridge.log(`位置服务插件 v${this.version} 已安装`)}getLocation(e={targetAccuracy:200,coordinate:1,withReGeocode:!0,useCache:!0}){return e.useCache=e.useCache??!0,new Promise((t,i)=>{this.getLocationSync({...e,success:e=>{t(e)},fail:e=>i(e)})})}getLocationSync(e={targetAccuracy:200,coordinate:1,withReGeocode:!0,useCache:!0}){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if("number"!=typeof e.targetAccuracy)throw o(s.INVALID_ACTION,"targetAccuracy参数格式错误");if("number"!=typeof e.coordinate)throw o(s.INVALID_ACTION,"coordinate参数格式错误");if("boolean"!=typeof e.withReGeocode)throw o(s.INVALID_ACTION,"withReGeocode参数格式错误");if("boolean"!=typeof e.useCache)throw o(s.INVALID_ACTION,"useCache参数格式错误");e.useCache=e.useCache??!0;const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"getLocation",params:e},t)})}};const h=new class{constructor(){i(this,"name","device"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getSystemInfo",this.getSystemInfo.bind(this)),e.bridge.registerMethod("getSystemInfoSync",this.getSystemInfoSync.bind(this)),e.bridge.registerMethod("getWifiList",this.getWifiList.bind(this)),e.bridge.registerMethod("getUUID",this.getUUID.bind(this)),e.bridge.registerMethod("setKeepScreenOn",this.setKeepScreenOn.bind(this)),e.bridge.log(`设备信息插件 v${this.version} 已安装`)}setKeepScreenOn(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0===e.isKeep||null===e.isKeep)throw o(s.JSON_ERROR,"缺少必需参数:isKeep");if(void 0!==e.isKeep&&"boolean"!=typeof e.isKeep)throw o(s.JSON_ERROR,"isKeep参数格式不正确");const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"setKeepScreenOn",params:{isKeep:e.isKeep}},t)})}getSystemInfoSync(e={}){var t;if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};return null==(t=this.context)?void 0:t.bridge.callNativeSync("getSystemInfoSync",{},i)}getSystemInfo(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{t(e)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getSystemInfo",params:{}},i)})})}getWifiList(e={}){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0||!Number.isInteger(e.timeout)))throw o(s.INVALID_ACTION,"timeout参数格式错误");if(void 0!==e.cacheTime&&("number"!=typeof e.cacheTime||e.cacheTime<=0||!Number.isInteger(e.cacheTime)))throw o(s.INVALID_ACTION,"cacheTime参数格式错误");const r={success:e=>{t(e)},fail:e=>{const t={resultCode:1,resultMessage:e.message,wifiList:[]};console.error("保存失败:",t),i(t)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getWifiList",params:{...e}},r)})})}getUUID(){return new Promise((e,t)=>{const i={success:t=>{e(t)},fail:e=>{t(e)}};if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getUUID",params:{}},i)})})}};const d=new class{constructor(){i(this,"name","media"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("saveImage",this.saveImage.bind(this)),e.bridge.registerMethod("scan",this.scan.bind(this)),e.bridge.registerMethod("chooseImage",this.chooseImage.bind(this)),e.bridge.registerMethod("previewImage",this.previewImage.bind(this)),e.bridge.registerMethod("compressImage",this.compressImage.bind(this)),e.bridge.registerMethod("chooseVideo",this.chooseVideo.bind(this)),e.bridge.log(`设备信息插件 v${this.version} 已安装`)}scan(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.key&&"string"!=typeof e.key||void 0!==e.key&&!["qr","bar"].includes(e.key))throw o(s.INVALID_ACTION,"key参数格式不正确");if(void 0!==e.isSupportAlbum&&"boolean"!=typeof e.isSupportAlbum)throw o(s.INVALID_ACTION,"isSupportAlbum参数格式不正确");e.key=e.key||"qr",e.isSupportAlbum=e.isSupportAlbum??!0;const r={success:e=>{t(e)},fail:e=>{i(o(s.SYSTEM_ERROR,"扫码失败",e))},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"scan",params:{...e}},r)})})}saveImage(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需参数:url");if("string"!=typeof e.url||!e.url.trim())throw o(s.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");const r={success:e=>{console.log("保存成功:",e);t({code:1,message:"保存成功",data:e})},fail:e=>{const t={code:2,message:"保存失败",data:e};console.error("保存失败:",t),i(t)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"saveImage",params:{url:e.url}},r)})})}chooseImage(e={}){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.count&&("number"!=typeof e.count||e.count<=0||!Number.isInteger(e.count)))throw o(s.PLUGIN_NOT_INITIALIZED,"count参数格式不正确");const r=["camera","album"];if(e.sourceType&&!Array.isArray(e.sourceType)||e.sourceType&&0===e.sourceType.length)throw o(s.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");if(e.sourceType&&e.sourceType.some(e=>!r.includes(e)))throw o(s.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");e.count=e.count||1,e.sourceType=e.sourceType||["camera","album"];const a={success:e=>{t(e||{filePaths:[],fileRealPaths:[]})},fail:e=>{console.error("选择图片失败:",e),i(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"chooseImage",params:e},a)})})}previewImage(e){return new Promise((t,i)=>{var r;if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.urls||!Array.isArray(e.urls)||0===e.urls.length)throw o(s.PLUGIN_NOT_INITIALIZED,"urls参数格式不正确");e.current=e.current||0;const a={success:e=>{t(e)},fail:e=>{i(e)},complete:()=>{}};null==(r=this.context)||r.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"previewImage",params:e},a)})})}compressImage(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.filePaths||!Array.isArray(e.filePaths)||0===e.filePaths.length)throw o(s.PLUGIN_NOT_INITIALIZED,"filePaths参数格式不正确");if(void 0!==e.compressLevel&&("number"!=typeof e.compressLevel||e.compressLevel<0||e.compressLevel>4||!Number.isInteger(e.compressLevel)))throw o(s.PLUGIN_NOT_INITIALIZED,"compressLevel参数格式不正确");e.compressLevel=e.compressLevel??4;const r={success:e=>{t(e||{filePaths:""})},fail:e=>{console.error("压缩图片失败:",e),i(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"compressImage",params:e},r)})})}chooseVideo(e={}){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const r=["camera","album"];if(e.sourceType&&!Array.isArray(e.sourceType)||e.sourceType&&0===e.sourceType.length)throw o(s.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");if(e.sourceType&&e.sourceType.some(e=>!r.includes(e)))throw o(s.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");let a=5;if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)&&(a=15),void 0!==e.maxDuration&&("number"!=typeof e.maxDuration||e.maxDuration<a||e.maxDuration>60||!Number.isInteger(e.maxDuration)))throw o(s.PLUGIN_NOT_INITIALIZED,"maxDuration参数格式不正确");e.sourceType=e.sourceType||["album","camera"],e.maxDuration=e.maxDuration??60;const n={success:e=>{t(e||{filePath:"",duration:0,size:0,height:0,width:0})},fail:e=>{console.error("选择视频失败:",e),i(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"chooseVideo",params:e},n)})})}};const I=new class{constructor(){i(this,"name","navigate"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("navigateTo",this.navigateTo.bind(this)),e.bridge.registerMethod("redirectTo",this.redirectTo.bind(this)),e.bridge.registerMethod("reLaunch",this.reLaunch.bind(this)),e.bridge.registerMethod("navigateBack",this.navigateBack.bind(this)),e.bridge.registerMethod("setNavigationBar",this.setNavigationBar.bind(this)),e.bridge.registerMethod("openLink",this.openLink.bind(this)),e.bridge.log(`导航插件 v${this.version} 已安装`)}setNavigationBar(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.isShowBar&&"boolean"!=typeof e.isShowBar)throw o(s.INVALID_ACTION,"缺少必需的参数: isShowBar");if(void 0!==e.title&&"string"!=typeof e.title)throw o(s.INVALID_ACTION,"title参数格式不正确");if(void 0!==e.backgroundColor&&("string"!=typeof e.backgroundColor||!/^#[0-9A-Fa-f]{6}$/.test(e.backgroundColor)))throw o(s.INVALID_ACTION,"backgroundColor参数格式不正确");if(void 0!==e.reset&&"boolean"!=typeof e.reset)throw o(s.INVALID_ACTION,"reset参数格式不正确");e.isShowBar=e.isShowBar??!0;const r={success:()=>{t()},fail:e=>{i(o(s.SYSTEM_ERROR,"设置导航栏失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"setNavigationBar",params:{...e}},r)})})}navigate(e,t){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e||!e.url)throw o(s.INVALID_ACTION,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw o(s.INVALID_ACTION,"url参数格式错误");const i={success:t=>{var i;const o={code:s.SUCCESS,message:"跳转成功",data:t};null==(i=e.success)||i.call(e,o)},fail:t=>{var i;const o={code:s.SYSTEM_ERROR,message:"跳转失败",details:t,name:""};null==(i=e.fail)||i.call(e,o)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var s;null==(s=this.context)||s.bridge.callNative({action:t||"navigateTo",params:{...e}},i)})}navigateTo(e){this.navigate(e,"navigateTo")}redirectTo(e){this.navigate(e,"redirectTo")}reLaunch(e){this.navigate(e,"reLaunch")}navigateBack(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.delta&&("number"!=typeof e.delta||e.delta<=0||!Number.isInteger(e.delta)))throw o(s.INVALID_ACTION,"delta参数格式不正确");e.delta=e.delta??1;const t={success:t=>{var i;const o={code:s.SUCCESS,message:"跳转成功",data:t};null==(i=e.success)||i.call(e,o)},fail:t=>{var i;const o={code:s.SYSTEM_ERROR,message:"跳转失败",details:t,name:""};null==(i=e.fail)||i.call(e,o)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"navigateBack",params:e},t)})}async openLink(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw o(s.INVALID_ACTION,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw o(s.INVALID_ACTION,"url参数格式错误");if(void 0!==e.enableShare&&"boolean"!=typeof e.enableShare)throw o(s.INVALID_ACTION,"enableShare参数格式不正确");e.enableShare=e.enableShare||!1;const r={success:()=>{t()},fail:e=>{i(o(s.SYSTEM_ERROR,"打开链接失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"openLink",params:{...e}},r)})})}};const u=new class{constructor(){i(this,"name","toast"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("showToast",this.showToast.bind(this)),e.bridge.registerMethod("hideToast",this.hideToast.bind(this)),e.bridge.registerMethod("showLoading",this.showLoading.bind(this)),e.bridge.registerMethod("hideLoading",this.hideLoading.bind(this)),e.bridge.log(`导航插件 v${this.version} 已安装`)}hideLoading(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{const i={code:s.SYSTEM_ERROR,message:"显示失败",details:e,name:""};t(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"hideLoading",params:{}},i)})})}showLoading(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.content&&"string"!=typeof e.content)throw o(s.INVALID_ACTION,"content参数格式不正确");const r={success:e=>{t(e)},fail:e=>{const t={code:s.SYSTEM_ERROR,message:"显示失败",details:e,name:""};i(t)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"showLoading",params:e},r)})})}showToast(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.type&&"string"!=typeof e.type||void 0!==e.type&&!["none","success","fail","exception"].includes(e.type))throw o(s.INVALID_ACTION,"type参数格式不正确");if(!e.content)throw o(s.INVALID_ACTION,"缺少必需的参数: content");if("string"!=typeof e.content)throw o(s.INVALID_ACTION,"content参数格式不正确");if(void 0!==e.duration&&("number"!=typeof e.duration||e.duration<=0||!Number.isInteger(e.duration)))throw o(s.INVALID_ACTION,"duration参数格式不正确");const{type:r,content:a,duration:n}=e,c={success:e=>{t(e)},fail:e=>{const t={code:s.SYSTEM_ERROR,message:"显示失败",details:e,name:""};i(t)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"showToast",params:{type:r||"none",content:a,duration:n||2e3}},c)})})}hideToast(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{const i={code:s.SYSTEM_ERROR,message:"显示失败",details:e,name:""};t(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"hideToast",params:{}},i)})})}};const g=new class{constructor(){i(this,"name","UserInfo"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getUserInfo",this.getUserInfo.bind(this)),e.bridge.log(`导航插件 v${this.version} 已安装`)}getUserInfo(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{const i={code:s.SYSTEM_ERROR,message:"显示失败",details:e,name:""};t(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getUserInfo",params:{}},i)})})}};const N=new class{constructor(){i(this,"name","bluetooth"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("openBluetoothAdapter",this.openBluetoothAdapter.bind(this)),e.bridge.registerMethod("closeBluetoothAdapter",this.closeBluetoothAdapter.bind(this)),e.bridge.registerMethod("startBluetoothDevicesDiscovery",this.startBluetoothDevicesDiscovery.bind(this)),e.bridge.registerMethod("stopBluetoothDevicesDiscovery",this.stopBluetoothDevicesDiscovery.bind(this)),e.bridge.registerMethod("onBluetoothDeviceFound",this.onBluetoothDeviceFound.bind(this)),e.bridge.registerMethod("offBluetoothDeviceFound",this.offBluetoothDeviceFound.bind(this)),e.bridge.registerMethod("writeBLECharacteristicValue",this.writeBLECharacteristicValue.bind(this)),e.bridge.registerMethod("readBLECharacteristicValue",this.readBLECharacteristicValue.bind(this)),e.bridge.registerMethod("connectBLEDevice",this.connectBLEDevice.bind(this)),e.bridge.registerMethod("disconnectBLEDevice",this.disconnectBLEDevice.bind(this)),e.bridge.registerMethod("getBLEDeviceCharacteristics",this.getBLEDeviceCharacteristics.bind(this)),e.bridge.registerMethod("getBLEDeviceServices",this.getBLEDeviceServices.bind(this)),e.bridge.registerMethod("onBLECharacteristicValueChange",this.onBLECharacteristicValueChange.bind(this)),e.bridge.registerMethod("offBLECharacteristicValueChange",this.offBLECharacteristicValueChange.bind(this)),e.bridge.registerMethod("onBLEConnectionStateChanged",this.onBLEConnectionStateChanged.bind(this)),e.bridge.registerMethod("offBLEConnectionStateChanged",this.offBLEConnectionStateChanged.bind(this)),e.bridge.log(`蓝牙插件 v${this.version} 已安装`)}offBLEConnectionStateChanged(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("offBLEConnectionStateChanged",()=>{e&&e()})})}onBLEConnectionStateChanged(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBLEConnectionStateChanged",t=>{e(t.data)})})}offBLECharacteristicValueChange(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("onBLECharacteristicValueChange",()=>{e&&e()})})}onBLECharacteristicValueChange(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBLECharacteristicValueChange",t=>{e(t.data)})})}readBLECharacteristicValue(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId||!e.serviceId||!e.characteristicId)throw o(s.INVALID_ACTION,"缺少必需的参数");const t={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"readBLECharacteristicValue",params:e},t)})}writeBLECharacteristicValue(e){var t;if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!(e.deviceId&&e.serviceId&&e.characteristicId&&e.value))throw o(s.INVALID_ACTION,"缺少必需的参数");if("string"!=typeof e.deviceId)throw o(s.JSON_ERROR,"deviceId参数格式错误");if("string"!=typeof e.serviceId)throw o(s.JSON_ERROR,"serviceId参数格式错误");if("string"!=typeof e.characteristicId)throw o(s.JSON_ERROR,"characteristicId参数格式错误");if("string"!=typeof e.value||!/^[0-9A-Fa-f]+$/.test(e.value)||(null==(t=e.value)?void 0:t.length)>20)throw o(s.JSON_ERROR,"value参数格式错误");const i={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"writeBLECharacteristicValue",params:e},i)})}getBLEDeviceServices(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw o(s.INVALID_ACTION,"缺少必需的参数: deviceId");if("string"!=typeof e.deviceId)throw o(s.JSON_ERROR,"deviceId参数格式错误");const t={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"getBLEDeviceServices",params:e},t)})}connectBLEDevice(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw o(s.INVALID_ACTION,"缺少必需的参数: deviceId");const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"connectBLEDevice",params:e},t)})}disconnectBLEDevice(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw o(s.INVALID_ACTION,"缺少必需的参数: deviceId");if("string"!=typeof e.deviceId)throw o(s.JSON_ERROR,"deviceId参数格式错误");const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"disconnectBLEDevice",params:e},t)})}getBLEDeviceCharacteristics(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId||!e.serviceId)throw o(s.INVALID_ACTION,"缺少必需的参数: deviceId 或 serviceId");if("string"!=typeof e.deviceId)throw o(s.JSON_ERROR,"deviceId参数格式错误");if("string"!=typeof e.serviceId)throw o(s.JSON_ERROR,"serviceId参数格式错误");const t={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:t=>{var i;null==(i=e.fail)||i.call(e,t)},complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"getBLEDeviceCharacteristics",params:e},t)})}offBluetoothDeviceFound(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("offBluetoothDeviceFound",()=>{e&&e()})})}onBluetoothDeviceFound(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBluetoothDeviceFound",t=>{e(t.data?JSON.parse(t.data):[])})})}stopBluetoothDevicesDiscovery(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const t={success:null==e?void 0:e.success,fail:null==e?void 0:e.fail,complete:null==e?void 0:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"stopBluetoothDevicesDiscovery",params:e},t)})}startBluetoothDevicesDiscovery(e={}){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.services&&!Array.isArray(e.services)&&"string"!=typeof e.services)throw o(s.INVALID_ACTION,"services参数格式不正确");if(void 0!==e.allowDuplicatesKey&&"boolean"!=typeof e.allowDuplicatesKey)throw o(s.INVALID_ACTION,"allowDuplicatesKey参数格式不正确");if(void 0!==e.interval&&("number"!=typeof e.interval||!Number.isInteger(e.interval)))throw o(s.INVALID_ACTION,"interval参数格式不正确");e.interval=(null==e?void 0:e.interval)||0;const t={success:null==e?void 0:e.success,fail:null==e?void 0:e.fail,complete:null==e?void 0:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"startBluetoothDevicesDiscovery",params:e},t)})}closeBluetoothAdapter(e={}){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"closeBluetoothAdapter",params:e},t)})}openBluetoothAdapter(e={}){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.autoClose&&"boolean"!=typeof e.autoClose)throw o(s.JSON_ERROR,"autoClose参数格式不正确");e.autoClose=e.autoClose??!0;const t={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"openBluetoothAdapter",params:e},t)})}getBluetoothDevices(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("getBluetoothDevices",t=>{e(t.data)})})}};const f=new class{constructor(){i(this,"context"),i(this,"name","storage"),i(this,"version","1.0.0")}install(e){this.context=e,e.bridge.registerMethod("setStorage",this.setStorage.bind(this)),e.bridge.registerMethod("setStorageSync",this.setStorageSync.bind(this)),e.bridge.registerMethod("getStorage",this.getStorage.bind(this)),e.bridge.registerMethod("getStorageSync",this.getStorageSync.bind(this)),e.bridge.registerMethod("removeStorage",this.removeStorage.bind(this)),e.bridge.log(`本地存储插件 v${this.version} 已安装`)}_createCallbacks(e){return{success:e.success,fail:e.fail,complete:e.complete}}async _callNativeMethod(e,t,i){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");return new Promise((s,o)=>{var r;null==(r=this.context)||r.bridge.ready(()=>{var r;null==(r=this.context)||r.bridge.callNative({action:e,params:t},{...i,success:e=>{i.success&&i.success(e),s(e)},fail:e=>{i.fail&&i.fail(e),o(e)}})})})}setStorageSync(e){var t;if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i=e.key;if(!i)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if(!e.data)throw o(s.INVALID_ACTION,"缺少必需的参数: data");if("string"!=typeof i)throw o(s.INVALID_ACTION,"key参数格式不正确");if("object"!=typeof e.data&&"string"!=typeof e.data)throw o(s.INVALID_ACTION,"data参数格式不正确");if("object"==typeof e.data&&0===Object.keys(e.data).length)throw o(s.INVALID_ACTION,"data参数格式不正确");const r=this._createCallbacks(e);null==(t=this.context)||t.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"setStorageSync",params:e},r)})}async setStorage(e){const t=e.key;if(!t)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if(!e.data)throw o(s.INVALID_ACTION,"缺少必需的参数: data");if("string"!=typeof t)throw o(s.INVALID_ACTION,"key参数格式不正确");if("object"!=typeof e.data&&"string"!=typeof e.data)throw o(s.INVALID_ACTION,"data参数格式不正确");if("object"==typeof e.data&&0===Object.keys(e.data).length)throw o(s.INVALID_ACTION,"data参数格式不正确");const i=this._createCallbacks(e);return this._callNativeMethod("setStorage",{key:e.key,data:e.data},i)}getStorageSync(e){var t;if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i=e.key;if(!i)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof i)throw o(s.INVALID_ACTION,"key参数格式不正确");const r=this._createCallbacks(e);return null==(t=this.context)?void 0:t.bridge.callNativeSync("getStorageSync",e,r)}async getStorage(e){const t=e.key;if(!t)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof t)throw o(s.INVALID_ACTION,"key参数格式不正确");const i=this._createCallbacks(e);return this._callNativeMethod("getStorage",{key:e.key},i)}async removeStorage(e){const t=e.key;if(!t)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof t)throw o(s.INVALID_ACTION,"key参数格式不正确");const i=this._createCallbacks(e);return this._callNativeMethod("removeStorage",{key:t},i)}};const v=new class{constructor(){i(this,"context"),i(this,"name","authentication"),i(this,"version","1.0.0")}install(e){this.context=e,e.bridge.log(`实人认证插件 v${this.version} 已安装`),e.bridge.registerMethod("exclusiveLiveCheck",this.exclusiveLiveCheck.bind(this))}exclusiveLiveCheck(e={}){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const r={success:e=>{t(e)},fail:e=>{i(e)},complete:e.complete};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"exclusiveLiveCheck",params:{}},r)})})}};const p=new class{constructor(){i(this,"name","request"),i(this,"version","1.0.0"),i(this,"context")}install(e){this.context=e,e.bridge.registerMethod("httpRequest",this.httpRequest.bind(this)),e.bridge.registerMethod("httpRequestSync",this.httpRequestSync.bind(this)),e.bridge.registerMethod("uploadFile",this.uploadFile.bind(this)),e.bridge.registerMethod("downloadFile",this.downloadFile.bind(this)),e.bridge.log(`网络请求插件 v${this.version} 已安装`)}httpRequest(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw o(s.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");if(void 0!==e.method&&!["GET","POST"].includes(e.method.toUpperCase()))throw o(s.PLUGIN_NOT_INITIALIZED,"method参数格式不正确");if(void 0!==e.headers&&"object"!=typeof e.headers)throw o(s.PLUGIN_NOT_INITIALIZED,"headers参数格式不正确");if(void 0!==e.data&&"object"!=typeof e.data)throw o(s.PLUGIN_NOT_INITIALIZED,"data参数格式不正确");if(void 0!==e.dataType&&!["json","text","base64"].includes(e.dataType.toLowerCase()))throw o(s.PLUGIN_NOT_INITIALIZED,"dataType参数格式不正确");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0))throw o(s.PLUGIN_NOT_INITIALIZED,"timeout参数格式不正确");if(void 0!==e.cacheModel&&"string"!=typeof e.cacheModel||void 0!==e.cacheModel&&!["noStore","noCache","smartCache","firstCache"].includes(e.cacheModel))throw o(s.PLUGIN_NOT_INITIALIZED,"cacheModel参数格式不正确");e.method=e.method||"GET",e.headers=e.headers&&Object.keys(e.headers).length>0?e.headers:{"Content-Type":"application/x-www-form-urlencoded"},e.data=e.data||{},e.dataType=e.dataType||"json",e.timeout=e.timeout||3e4,e.cacheModel=e.cacheModel||"noStore";const r={success:i=>{var s;null==(s=null==e?void 0:e.success)||s.call(e,i),t(i)},fail:t=>{var s;null==(s=e.fail)||s.call(e,t),i(t)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"httpRequest",params:e,timeout:e.timeout},r)})})}httpRequestSync(e){if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw o(s.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");if(void 0!==e.method&&!["GET","POST"].includes(e.method.toUpperCase()))throw o(s.PLUGIN_NOT_INITIALIZED,"method参数格式不正确");if(void 0!==e.headers&&"object"!=typeof e.headers)throw o(s.PLUGIN_NOT_INITIALIZED,"headers参数格式不正确");if(void 0!==e.data&&"object"!=typeof e.data)throw o(s.PLUGIN_NOT_INITIALIZED,"data参数格式不正确");if(void 0!==e.dataType&&!["json","text","base64"].includes(e.dataType.toLowerCase()))throw o(s.PLUGIN_NOT_INITIALIZED,"dataType参数格式不正确");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0))throw o(s.PLUGIN_NOT_INITIALIZED,"timeout参数格式不正确");if(void 0!==e.cacheModel&&"string"!=typeof e.cacheModel||void 0!==e.cacheModel&&!["noStore","noCache","smartCache","firstCache"].includes(e.cacheModel))throw o(s.PLUGIN_NOT_INITIALIZED,"cacheModel参数格式不正确");e.method=e.method||"GET",e.headers=e.headers&&Object.keys(e.headers).length>0?e.headers:{"Content-Type":"application/x-www-form-urlencoded"},e.data=e.data||{},e.dataType=e.dataType||"json",e.timeout=e.timeout||3e4,e.cacheModel=e.cacheModel||"noStore";const t={success:t=>{var i;null==(i=null==e?void 0:e.success)||i.call(e,t)},fail:t=>{var i;null==(i=e.fail)||i.call(e,t)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var i;null==(i=this.context)||i.bridge.callNative({action:"httpRequest",params:e,timeout:e.timeout},t)})}uploadFile(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!(e.url&&e.filePath&&e.fileName&&e.fileType))return i(o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url, filePath, fileName, fileType"));if("string"!=typeof e.url||!e.url.trim())return i(o(s.PLUGIN_NOT_INITIALIZED,"url参数格式不正确"));if("string"!=typeof e.filePath||!e.filePath.trim())return i(o(s.PLUGIN_NOT_INITIALIZED,"filePath参数格式不正确"));if("string"!=typeof e.fileName||!e.fileName.trim())return i(o(s.PLUGIN_NOT_INITIALIZED,"fileName参数格式不正确"));if(!["image","video","audio"].includes(e.fileType))return i(o(s.PLUGIN_NOT_INITIALIZED,`不支持的文件类型: ${e.fileType}`));if(void 0!==e.header&&"object"!=typeof e.header)return i(o(s.PLUGIN_NOT_INITIALIZED,"header参数格式不正确"));if(void 0!==e.formData&&"object"!=typeof e.formData)return i(o(s.PLUGIN_NOT_INITIALIZED,"formData参数格式不正确"));const r={success:e=>{t(e)},fail:e=>{i(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"uploadFile",params:e},r)})})}downloadFile(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)return i(o(s.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url"));if("string"!=typeof e.url||!e.url.trim())return i(o(s.PLUGIN_NOT_INITIALIZED,"url参数格式不正确"));if(void 0!==e.header&&"object"!=typeof e.header)return i(o(s.PLUGIN_NOT_INITIALIZED,"header参数格式不正确"));const r={success:e=>{t(e)},fail:e=>{i(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"downloadFile",params:e},r)})})}};const m=new class{constructor(){i(this,"context"),i(this,"name","wifi"),i(this,"version","1.0.0")}install(e){this.context=e,e.bridge.registerMethod("startWifi",this.startWifi.bind(this)),e.bridge.registerMethod("stopWifi",this.stopWifi.bind(this)),e.bridge.registerMethod("connectWifi",this.connectWifi.bind(this)),e.bridge.registerMethod("getScanWifiListAsync",this.getScanWifiListAsync.bind(this)),e.bridge.log(`Wi-Fi 插件 v${this.version} 已安装`)}startWifi(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{t(e)}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"startWifi",params:{}},i)})})}stopWifi(){return new Promise((e,t)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const i={success:t=>{e(t)},fail:e=>{t(e)}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"stopWifi",params:{}},i)})})}connectWifi(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.SSID)throw o(s.INVALID_ACTION,"缺少必需的参数: SSID");if("string"!=typeof e.SSID)throw o(s.INVALID_ACTION,"SSID参数格式错误");if(void 0!==e.BSSID&&"string"!=typeof e.BSSID)throw o(s.INVALID_ACTION,"BSSID参数格式错误");if(void 0!==e.password&&"string"!=typeof e.password)throw o(s.INVALID_ACTION,"password参数格式错误");if(void 0!==e.isWEP&&"boolean"!=typeof e.isWEP)throw o(s.INVALID_ACTION,"isWEP参数格式错误");e.isWEP=e.isWEP??!1;const r={success:e=>{t(e)},fail:e=>{i(e)},complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"connectWifi",params:e},r)})})}async getScanWifiListAsync(e){return new Promise((t,i)=>{if(!this.context)throw o(s.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if("number"!=typeof e.timeout)throw o(s.INVALID_ACTION,"timeout参数格式错误");if("number"!=typeof e.cacheTime)throw o(s.INVALID_ACTION,"cacheTime参数格式错误");const r={success:e=>{t(e)},fail:e=>{i(e)},complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getScanWifiListAsync",params:e,timeout:e.timeout},r)})})}},b=c({plugins:[l,h,d,I,u,g,N,f,v,p,m],debug:!0,errorHandler:(e,t)=>{console.error(`[NativeBridge Error] ${t}:`,e)}});e.NativeBridgeCore=a,e.authenticationPlugin=v,e.bluetoothPlugin=N,e.createNativeBridge=c,e.default=b,e.devicePlugin=h,e.locationPlugin=l,e.mediaPlugin=d,e.navigatePlugin=I,e.requestPlugin=p,e.storagePlugin=f,e.toastPlugin=u,e.userinfoPlugin=g,e.wifiPlugin=m,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).NativeBridge={})}(this,function(e){"use strict";var t=(e=>(e[e.SUCCESS=0]="SUCCESS",e[e.JSON_ERROR=1]="JSON_ERROR",e[e.SYSTEM_ERROR=2]="SYSTEM_ERROR",e[e.TIMEOUT=3]="TIMEOUT",e[e.PLUGIN_NOT_INITIALIZED=4]="PLUGIN_NOT_INITIALIZED",e[e.INVALID_ACTION=5]="INVALID_ACTION",e))(t||{});const i=(e,t,i)=>{const r=new Error(t);return r.code=e,r.details=i,r};var r=Object.defineProperty,o=(e,t,i)=>(((e,t,i)=>{t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);let s;s="undefined"==typeof AbortController?class{constructor(){o(this,"signal"),this.signal={aborted:!1,_listeners:[],addEventListener:function(e,t){this._listeners.push(t)},removeEventListener:function(e,t){const i=this._listeners.indexOf(t);-1!==i&&this._listeners.splice(i,1)},dispatchEvent:function(e){this._listeners.forEach(t=>t(e))}}}abort(){this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort"})}}:AbortController;const a=class e{constructor(e={}){o(this,"callbackMap"),o(this,"callbackId"),o(this,"isReady"),o(this,"readyCallbacks"),o(this,"debugMode"),o(this,"defaultTimeout"),o(this,"plugins"),o(this,"pendingCalls"),o(this,"errorHandler"),o(this,"eventListeners",new Map),o(this,"nativeEventHandlers",new Map),o(this,"VERSION","1.0.0"),o(this,"API_VERSION","1"),o(this,"methodRegistry",new Map),this.callbackMap=new Map,this.callbackId=1,this.isReady=!1,this.readyCallbacks=[],this.debugMode=e.debug||!0,this.defaultTimeout=e.timeout||1e7,this.plugins=new Map,this.pendingCalls=new Map,this.errorHandler=e.errorHandler,this.setupBridge(),e.plugins&&e.plugins.length>0&&e.plugins.forEach(e=>this.use(e))}static getInstance(t={}){return e.instance?t.plugins&&t.plugins.length>0&&t.plugins.forEach(t=>{e.instance.use(t)}):e.instance=new e(t),e.instance}onNativeEvent(e,t){this.nativeEventHandlers.has(e)||this.nativeEventHandlers.set(e,new Set),this.nativeEventHandlers.get(e).add(t)}offNativeEvent(e,t){var i;null==(i=this.nativeEventHandlers.get(e))||i.delete(t)}dispatchNativeEvent(e,t){var i;this.debugMode&&this.log(`分发原生事件: ${e}`,t),null==(i=this.nativeEventHandlers.get(e))||i.forEach(i=>{try{i({type:e,data:t})}catch(r){this.error(`分发原生事件 ${e} 失败`,r)}})}registerMethod(e,t){this.methodRegistry.has(e)&&this.warn(`方法 ${e} 已注册,将被覆盖`),this.methodRegistry.set(e,t),this[e]=t}use(e){if(!e||!e.name||!e.install||"function"!=typeof e.install)throw i(t.PLUGIN_NOT_INITIALIZED,`无效的插件: ${(null==e?void 0:e.name)||"未命名"}`);if(this.plugins.has(e.name))return this.warn(`插件 ${e.name} 已经安装`),this;try{const t={bridge:this};e.install(t),this.plugins.set(e.name,e),this.log(`插件 ${e.name}@${e.version} 安装成功`)}catch(r){throw i(t.SYSTEM_ERROR,`安装插件 ${e.name} 失败`,r)}return this}hasPlugin(e){return this.plugins.has(e)}getPlugin(e){return this.plugins.get(e)}setupBridge(){try{if(this.checkIsInApp()){window.nativeBridgeCallback=this.handleNativeCallback.bind(this),window.nativeBridgeDispatchEvent=(e,t)=>{this.dispatchNativeEvent(e,t)},this.callNative({action:"ready",params:{version:this.VERSION,apiVersion:this.API_VERSION}},{success:()=>{this.log("App已准备就绪=====>"),this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]},fail:e=>{this.error("App准备就绪失败",e)}});const e=()=>{this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]};document.addEventListener("NativeBridgeReady",e),this.eventListeners.set("NativeBridgeReady",e)}else setTimeout(()=>{this.isReady=!0,this.readyCallbacks.forEach(e=>e()),this.readyCallbacks=[]},0)}catch(e){this.error("设置桥接环境失败",e)}}destroy(){this.eventListeners.forEach((e,t)=>{document.removeEventListener(t,e)}),this.eventListeners.clear(),this.callbackMap.clear(),this.pendingCalls.forEach(e=>clearTimeout(e)),this.pendingCalls.clear(),window.nativeBridgeCallback=void 0}checkIsInApp(){var e;try{const t=navigator.userAgent.toLowerCase();return console.log(`[NativeBridge]--userAgent ${t}`),console.log(`[NativeBridge]--messageHandlers ${JSON.stringify(null==(e=window.webkit)?void 0:e.messageHandlers)}`),!0}catch(t){return this.error("检测App环境失败",t),!1}}ready(e){this.isReady?e():this.readyCallbacks.push(e)}callNative(e,r){var o;const a=`cb_${this.callbackId++}_${Date.now()}`,{action:n,params:c={},timeout:l=this.defaultTimeout,retryCount:h=0,retryDelay:d=1e3}=e;if(r&&(this.callbackMap.set(a,r),l>0)){const e=new s,o=setTimeout(()=>{var o,s;if(!e.signal.aborted&&this.callbackMap.has(a))if(this.callbackMap.delete(a),this.pendingCalls.delete(a),h>0)this.log(`调用 ${n} 超时,${d}ms后重试 (剩余重试次数: ${h})`),setTimeout(()=>{e.signal.aborted||this.callNative({action:n,params:c,timeout:l,retryCount:h-1,retryDelay:d},r)},d);else{const e=i(t.TIMEOUT,`调用 ${n} 超时 (${l}ms)`);null==(o=r.fail)||o.call(r,e),null==(s=r.complete)||s.call(r),this.error(`调用超时: ${n}`,e)}},l);this.pendingCalls.set(a,o),e.signal.addEventListener("abort",()=>{clearTimeout(o),this.pendingCalls.delete(a)})}const I={action:n,params:c,timeout:l,callbackId:a};this.debugMode&&this.log(`调用原生方法: ${n}`,c);try{this.checkIsInApp()?this.sendToNative(I):this.mockNativeCall(I)}catch(u){this.error(`调用原生方法 ${n} 失败`,u),null==(o=null==r?void 0:r.fail)||o.call(r,u),this.releaseCallback(a)}return a}isIOS(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)}callNativeSync(e,r,o){var s,a,n,l;let h;try{const n=JSON.stringify({action:e,params:r}),c="undefined"!=typeof window?window:void 0;if(this.isIOS())this.log(`发送消息到 iOS WKWebView: ${n}`),h=prompt(n);else if(null==(s=null==c?void 0:c.AndroidBridge)?void 0:s.postSyncMessage)this.log(`发送消息到安卓原生App: ${n}`),h=c.AndroidBridge.postSyncMessage(n);else if(c)try{const e=document.createElement("iframe");return e.style.display="none",e.src=`yourapp://bridge?message=${encodeURIComponent(n)}`,document.body.appendChild(e),void setTimeout(()=>{document.body.removeChild(e)},0)}catch(d){throw null==(a=null==o?void 0:o.fail)||a.call(o,d),i(t.SYSTEM_ERROR,`创建 iframe 失败: ${d.message}`)}}catch(I){throw null==(n=null==o?void 0:o.fail)||n.call(o,I),i(t.SYSTEM_ERROR,`发送消息到原生App失败: ${I.message}`)}return this.debugMode&&this.log("收到原生回调: success",h),null==(l=null==o?void 0:o.success)||l.call(o,c(h)),c(h)}sendToNative(e){try{const t=JSON.stringify(e);if("undefined"!=typeof window&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.nativeBridge)this.log(`发送消息到 iOS WKWebView: ${t}`),window.webkit.messageHandlers.nativeBridge.postMessage(t);else if(window.AndroidBridge&&window.AndroidBridge.postMessage)this.log(`发送消息到安卓原生App: ${t}`),window.AndroidBridge.postMessage(t);else{const e=document.createElement("iframe");e.style.display="none",e.src=`yourapp://bridge?message=${encodeURIComponent(t)}`,document.body.appendChild(e),setTimeout(()=>{document.body.removeChild(e)},0)}}catch(r){throw i(t.SYSTEM_ERROR,`发送消息到原生App失败: ${r.message}`)}}handleNativeCallback(e,t,i){const r=this.callbackMap.get(e);if(r){this.pendingCalls.has(e)&&(clearTimeout(this.pendingCalls.get(e)),this.pendingCalls.delete(e)),this.debugMode&&this.log(`收到原生回调: ${t}`,i);try{if("success"===t&&r.success)r.success(c(i));else if("fail"===t&&r.fail){let e;i instanceof Error?e=i:"string"==typeof i?e=new Error(i):i&&i.message?(e=new Error(i.message),i.code&&(e.code=i.code)):e=new Error("未知错误"),r.fail(e)}r.complete&&r.complete()}catch(o){this.error("执行回调函数时出错",o)}this.callbackMap.delete(e)}else this.warn(`未找到回调ID: ${e}`)}mockNativeCall(e){if(this.debugMode&&this.log("模拟原生调用:",e),"ready"===e.action)setTimeout(()=>{const e=new Event("NativeBridgeReady");document.dispatchEvent(e)},100);else{const t=Array.from(this.plugins.entries());for(let i=0;i<t.length;i++){const[r]=t[i];if(r.mockAction&&"function"==typeof r.mockAction&&r.mockAction(e))return}setTimeout(()=>{this.handleNativeCallback(e.callbackId,"success",{message:"Mock成功",data:null})},100)}}releaseCallback(e){var r,o;if(this.callbackMap.has(e)){const s=this.callbackMap.get(e);null==(r=null==s?void 0:s.fail)||r.call(s,i(t.SYSTEM_ERROR,"调用原生方法失败")),null==(o=null==s?void 0:s.complete)||o.call(s),this.callbackMap.delete(e)}this.pendingCalls.has(e)&&(clearTimeout(this.pendingCalls.get(e)),this.pendingCalls.delete(e))}setDebug(e){this.debugMode=e,e?console.log("[NativeBridge] 调试模式已开启 ✅"):console.log("[NativeBridge] 调试模式已关闭 ❌")}setErrorHandler(e){this.errorHandler=e}getInstalledPlugins(){return Array.from(this.plugins.keys())}isDebugMode(){return this.debugMode}log(e,...t){this.debugMode&&console.log(`[NativeBridge] ${e}`,...t)}error(e,t){console.error(`[NativeBridge Error] ${e}`,t),this.errorHandler&&t&&this.errorHandler(t,e)}warn(e){console.warn(`[NativeBridge Warn] ${e}`)}getCallBackMap(){return this.callbackMap}};o(a,"instance");let n=a;function c(e){if(null==e)return e;if("string"!=typeof e)return e;if(""===e)return e;try{const t=e.trim();return t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")?(JSON.parse(e),JSON.parse(e)):e}catch(t){return e}}const l=e=>n.getInstance(e);n.getInstance();var h=Object.defineProperty,d=Object.defineProperties,I=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable,N=(e,t,i)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,p=(e,t,i)=>(N(e,"symbol"!=typeof t?t+"":t,i),i);const v=new class{constructor(){p(this,"name","location"),p(this,"version","1.0.0"),p(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getLocationSync",this.getLocationSync.bind(this)),e.bridge.registerMethod("getLocation",this.getLocation.bind(this))}getLocation(e={targetAccuracy:200,coordinate:1,withReGeocode:!0,useCache:!0}){var t;return e.useCache=null==(t=e.useCache)||t,new Promise((t,i)=>{var r;this.getLocationSync((r=((e,t)=>{for(var i in t||(t={}))g.call(t,i)&&N(e,i,t[i]);if(u)for(var i of u(t))f.call(t,i)&&N(e,i,t[i]);return e})({},e),d(r,I({success:e=>{t(e)},fail:e=>i(e)}))))})}getLocationSync(e={targetAccuracy:200,coordinate:1,withReGeocode:!0,useCache:!0}){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if("number"!=typeof e.targetAccuracy)throw i(t.INVALID_ACTION,"targetAccuracy参数格式错误");if("number"!=typeof e.coordinate)throw i(t.INVALID_ACTION,"coordinate参数格式错误");if("boolean"!=typeof e.withReGeocode)throw i(t.INVALID_ACTION,"withReGeocode参数格式错误");if("boolean"!=typeof e.useCache)throw i(t.INVALID_ACTION,"useCache参数格式错误");e.useCache=null==(r=e.useCache)||r;const o={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getLocation",params:e},o)})}};var b=Object.defineProperty,m=Object.getOwnPropertySymbols,y=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,L=(e,t,i)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,w=(e,t)=>{for(var i in t||(t={}))y.call(t,i)&&L(e,i,t[i]);if(m)for(var i of m(t))T.call(t,i)&&L(e,i,t[i]);return e},_=(e,t,i)=>(L(e,"symbol"!=typeof t?t+"":t,i),i);const O=new class{constructor(){_(this,"name","device"),_(this,"version","1.0.0"),_(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getSystemInfo",this.getSystemInfo.bind(this)),e.bridge.registerMethod("getSystemInfoSync",this.getSystemInfoSync.bind(this)),e.bridge.registerMethod("getWifiList",this.getWifiList.bind(this)),e.bridge.registerMethod("getUUID",this.getUUID.bind(this)),e.bridge.registerMethod("setKeepScreenOn",this.setKeepScreenOn.bind(this))}setKeepScreenOn(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0===e.isKeep||null===e.isKeep)throw i(t.JSON_ERROR,"缺少必需参数:isKeep");if(void 0!==e.isKeep&&"boolean"!=typeof e.isKeep)throw i(t.JSON_ERROR,"isKeep参数格式不正确");const r={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"setKeepScreenOn",params:{isKeep:e.isKeep}},r)})}getSystemInfoSync(e={}){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};return null==(r=this.context)?void 0:r.bridge.callNativeSync("getSystemInfoSync",{},o)}getSystemInfo(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{r(e)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getSystemInfo",params:{}},o)})})}getWifiList(e={}){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0||!Number.isInteger(e.timeout)))throw i(t.INVALID_ACTION,"timeout参数格式错误");if(void 0!==e.cacheTime&&("number"!=typeof e.cacheTime||e.cacheTime<=0||!Number.isInteger(e.cacheTime)))throw i(t.INVALID_ACTION,"cacheTime参数格式错误");const s={success:e=>{r(e)},fail:e=>{const t={resultCode:1,resultMessage:e.message,wifiList:[]};console.error("保存失败:",t),o(t)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getWifiList",params:w({},e)},s)})})}getUUID(){return new Promise((e,r)=>{const o={success:t=>{e(t)},fail:e=>{r(e)}};if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getUUID",params:{}},o)})})}};var A=Object.defineProperty,E=Object.getOwnPropertySymbols,D=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable,x=(e,t,i)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,S=(e,t)=>{for(var i in t||(t={}))D.call(t,i)&&x(e,i,t[i]);if(E)for(var i of E(t))P.call(t,i)&&x(e,i,t[i]);return e},C=(e,t,i)=>(x(e,"symbol"!=typeof t?t+"":t,i),i);const M=new class{constructor(){C(this,"name","media"),C(this,"version","1.0.0"),C(this,"context")}install(e){this.context=e,e.bridge.registerMethod("saveImage",this.saveImage.bind(this)),e.bridge.registerMethod("scan",this.scan.bind(this)),e.bridge.registerMethod("chooseImage",this.chooseImage.bind(this)),e.bridge.registerMethod("previewImage",this.previewImage.bind(this)),e.bridge.registerMethod("compressImage",this.compressImage.bind(this)),e.bridge.registerMethod("compressVideo",this.compressVideo.bind(this)),e.bridge.registerMethod("chooseVideo",this.chooseVideo.bind(this)),e.bridge.registerMethod("onUploadProgress",this.onUploadProgress.bind(this))}scan(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.key&&"string"!=typeof e.key||void 0!==e.key&&!["qr","bar"].includes(e.key))throw i(t.INVALID_ACTION,"key参数格式不正确");if(void 0!==e.isSupportAlbum&&"boolean"!=typeof e.isSupportAlbum)throw i(t.INVALID_ACTION,"isSupportAlbum参数格式不正确");e.key=e.key||"qr",e.isSupportAlbum=null==(s=e.isSupportAlbum)||s;const a={success:e=>{r(e)},fail:e=>{o(i(t.SYSTEM_ERROR,"扫码失败",e))},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"scan",params:S({},e)},a)})})}saveImage(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需参数:url");if("string"!=typeof e.url||!e.url.trim())throw i(t.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");const s={success:e=>{console.log("保存成功:",e);r({code:1,message:"保存成功",data:e})},fail:e=>{const t={code:2,message:"保存失败",data:e};console.error("保存失败:",t),o(t)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"saveImage",params:{url:e.url}},s)})})}chooseImage(e={}){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.count&&("number"!=typeof e.count||e.count<=0||!Number.isInteger(e.count)))throw i(t.PLUGIN_NOT_INITIALIZED,"count参数格式不正确");const s=["camera","album"];if(e.sourceType&&!Array.isArray(e.sourceType)||e.sourceType&&0===e.sourceType.length)throw i(t.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");if(e.sourceType&&e.sourceType.some(e=>!s.includes(e)))throw i(t.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");e.count=e.count||1,e.sourceType=e.sourceType||["camera","album"];const a={success:e=>{r(e||{filePaths:[],fileRealPaths:[]})},fail:e=>{console.error("选择图片失败:",e),o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"chooseImage",params:e},a)})})}previewImage(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.urls||!Array.isArray(e.urls)||0===e.urls.length)throw i(t.PLUGIN_NOT_INITIALIZED,"urls参数格式不正确");e.current=e.current||0;const a={success:e=>{r(e)},fail:e=>{o(e)},complete:()=>{}};null==(s=this.context)||s.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"previewImage",params:e},a)})})}compressImage(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.filePaths||!Array.isArray(e.filePaths)||0===e.filePaths.length)throw i(t.PLUGIN_NOT_INITIALIZED,"filePaths参数格式不正确");if(void 0!==e.compressLevel&&("number"!=typeof e.compressLevel||e.compressLevel<0||e.compressLevel>4||!Number.isInteger(e.compressLevel)))throw i(t.PLUGIN_NOT_INITIALIZED,"compressLevel参数格式不正确");e.compressLevel=null!=(s=e.compressLevel)?s:4;const a={success:e=>{r(e||{filePaths:""})},fail:e=>{console.error("压缩图片失败:",e),o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"compressImage",params:e},a)})})}compressVideo(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.filePath||"string"!=typeof e.filePath||!e.filePath.trim())throw i(t.PLUGIN_NOT_INITIALIZED,"filePath参数格式不正确");if(void 0!==e.compressLevel&&("number"!=typeof e.compressLevel||e.compressLevel<0||e.compressLevel>3||!Number.isInteger(e.compressLevel)))throw i(t.PLUGIN_NOT_INITIALIZED,"compressLevel参数格式不正确");e.compressLevel=null!=(s=e.compressLevel)?s:3;const a={success:e=>{r(e||{filePath:""})},fail:e=>{console.error("压缩视频失败:",e),o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"compressVideo",params:e},a)})})}chooseVideo(e={}){return new Promise((r,o)=>{var s,a;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const n=["camera","album"];if(e.sourceType&&!Array.isArray(e.sourceType)||e.sourceType&&0===e.sourceType.length)throw i(t.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");if(e.sourceType&&e.sourceType.some(e=>!n.includes(e)))throw i(t.PLUGIN_NOT_INITIALIZED,"sourceType参数格式不正确");let c=5;if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)&&(c=15),void 0!==e.maxDuration&&("number"!=typeof e.maxDuration||e.maxDuration<c||e.maxDuration>60||!Number.isInteger(e.maxDuration)))throw i(t.PLUGIN_NOT_INITIALIZED,"maxDuration参数格式不正确");if(void 0!==e.compressLevel&&("number"!=typeof e.compressLevel||e.compressLevel<0||e.compressLevel>3||!Number.isInteger(e.compressLevel)))throw i(t.PLUGIN_NOT_INITIALIZED,"compressLevel参数格式不正确");e.sourceType=e.sourceType||["album","camera"],e.maxDuration=null!=(s=e.maxDuration)?s:60,e.compressLevel=null!=(a=e.compressLevel)?a:3;const l={success:e=>{r(e||{filePath:"",duration:0,size:0,height:0,width:0})},fail:e=>{console.error("选择视频失败:",e),o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"chooseVideo",params:e},l)})})}onUploadProgress(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onUploadProgress",t=>{e(t.data?JSON.parse(t.data):{})})})}};var U=Object.defineProperty,R=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,k=(e,t,i)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Z=(e,t)=>{for(var i in t||(t={}))G.call(t,i)&&k(e,i,t[i]);if(R)for(var i of R(t))B.call(t,i)&&k(e,i,t[i]);return e},V=(e,t,i)=>(k(e,"symbol"!=typeof t?t+"":t,i),i);const j=new class{constructor(){V(this,"name","navigate"),V(this,"version","1.0.0"),V(this,"context")}install(e){this.context=e,e.bridge.registerMethod("navigateTo",this.navigateTo.bind(this)),e.bridge.registerMethod("redirectTo",this.redirectTo.bind(this)),e.bridge.registerMethod("reLaunch",this.reLaunch.bind(this)),e.bridge.registerMethod("navigateBack",this.navigateBack.bind(this)),e.bridge.registerMethod("setNavigationBar",this.setNavigationBar.bind(this)),e.bridge.registerMethod("openLink",this.openLink.bind(this)),e.bridge.registerMethod("navigateToNativePage",this.navigateToNativePage.bind(this)),e.bridge.registerMethod("closeCurrentPage",this.closeCurrentPage.bind(this))}setNavigationBar(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.isShowBar&&"boolean"!=typeof e.isShowBar)throw i(t.INVALID_ACTION,"缺少必需的参数: isShowBar");if(void 0!==e.title&&"string"!=typeof e.title)throw i(t.INVALID_ACTION,"title参数格式不正确");if(void 0!==e.backgroundColor&&("string"!=typeof e.backgroundColor||!/^#[0-9A-Fa-f]{6}$/.test(e.backgroundColor)))throw i(t.INVALID_ACTION,"backgroundColor参数格式不正确");if(void 0!==e.reset&&"boolean"!=typeof e.reset)throw i(t.INVALID_ACTION,"reset参数格式不正确");e.isShowBar=null==(s=e.isShowBar)||s;const a={success:()=>{r()},fail:e=>{o(i(t.SYSTEM_ERROR,"设置导航栏失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"setNavigationBar",params:Z({},e)},a)})})}navigate(e,r){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e||!e.url)throw i(t.INVALID_ACTION,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw i(t.INVALID_ACTION,"url参数格式错误");const o={success:i=>{var r;const o={code:t.SUCCESS,message:"跳转成功",data:i};null==(r=e.success)||r.call(e,o)},fail:i=>{var r;const o={code:t.SYSTEM_ERROR,message:"跳转失败",details:i,name:""};null==(r=e.fail)||r.call(e,o)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:r||"navigateTo",params:Z({},e)},o)})}navigateTo(e){this.navigate(e,"navigateTo")}redirectTo(e){this.navigate(e,"redirectTo")}reLaunch(e){this.navigate(e,"reLaunch")}navigateBack(e){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.delta&&("number"!=typeof e.delta||e.delta<=0||!Number.isInteger(e.delta)))throw i(t.INVALID_ACTION,"delta参数格式不正确");e.delta=null!=(r=e.delta)?r:1;const o={success:i=>{var r;const o={code:t.SUCCESS,message:"跳转成功",data:i};null==(r=e.success)||r.call(e,o)},fail:i=>{var r;const o={code:t.SYSTEM_ERROR,message:"跳转失败",details:i,name:""};null==(r=e.fail)||r.call(e,o)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"navigateBack",params:e},o)})}openLink(e){return r=this,o=null,s=function*(){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw i(t.INVALID_ACTION,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw i(t.INVALID_ACTION,"url参数格式错误");if(void 0!==e.enableShare&&"boolean"!=typeof e.enableShare)throw i(t.INVALID_ACTION,"enableShare参数格式不正确");e.enableShare=e.enableShare||!1;const s={success:()=>{r()},fail:e=>{o(i(t.SYSTEM_ERROR,"打开链接失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"openLink",params:Z({},e)},s)})})},new Promise((e,t)=>{var i=e=>{try{n(s.next(e))}catch(i){t(i)}},a=e=>{try{n(s.throw(e))}catch(i){t(i)}},n=t=>t.done?e(t.value):Promise.resolve(t.value).then(i,a);n((s=s.apply(r,o)).next())});var r,o,s}navigateToNativePage(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e||"string"!=typeof e||!e.trim())throw i(t.INVALID_ACTION,"url参数格式不正确");const s={success:()=>{r()},fail:e=>{o(i(t.SYSTEM_ERROR,"跳转原生页面失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"navigateToNativePage",params:{url:e}},s)})})}closeCurrentPage(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:()=>{e()},fail:e=>{r(i(t.SYSTEM_ERROR,"关闭页面失败",e))},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"closeCurrentPage",params:{}},o)})})}};var $=Object.defineProperty,W=(e,t,i)=>(((e,t,i)=>{t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const J=new class{constructor(){W(this,"name","toast"),W(this,"version","1.0.0"),W(this,"context")}install(e){this.context=e,e.bridge.registerMethod("showToast",this.showToast.bind(this)),e.bridge.registerMethod("hideToast",this.hideToast.bind(this)),e.bridge.registerMethod("showLoading",this.showLoading.bind(this)),e.bridge.registerMethod("hideLoading",this.hideLoading.bind(this))}hideLoading(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{const i={code:t.SYSTEM_ERROR,message:"显示失败",details:e,name:""};r(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"hideLoading",params:{}},o)})})}showLoading(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.content&&"string"!=typeof e.content)throw i(t.INVALID_ACTION,"content参数格式不正确");const s={success:e=>{r(e)},fail:e=>{const i={code:t.SYSTEM_ERROR,message:"显示失败",details:e,name:""};o(i)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"showLoading",params:e},s)})})}showToast(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.type&&"string"!=typeof e.type||void 0!==e.type&&!["none","success","fail","exception"].includes(e.type))throw i(t.INVALID_ACTION,"type参数格式不正确");if(!e.content)throw i(t.INVALID_ACTION,"缺少必需的参数: content");if("string"!=typeof e.content)throw i(t.INVALID_ACTION,"content参数格式不正确");if(void 0!==e.duration&&("number"!=typeof e.duration||e.duration<=0||!Number.isInteger(e.duration)))throw i(t.INVALID_ACTION,"duration参数格式不正确");const{type:s,content:a,duration:n}=e,c={success:e=>{r(e)},fail:e=>{const i={code:t.SYSTEM_ERROR,message:"显示失败",details:e,name:""};o(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"showToast",params:{type:s||"none",content:a,duration:n||2e3}},c)})})}hideToast(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{const i={code:t.SYSTEM_ERROR,message:"显示失败",details:e,name:""};r(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"hideToast",params:{}},o)})})}};var H=Object.defineProperty,Y=(e,t,i)=>(((e,t,i)=>{t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const F=new class{constructor(){Y(this,"name","UserInfo"),Y(this,"version","1.0.0"),Y(this,"context")}install(e){this.context=e,e.bridge.registerMethod("getUserInfo",this.getUserInfo.bind(this))}getUserInfo(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{const i={code:t.SYSTEM_ERROR,message:"显示失败",details:e,name:""};r(i)},complete:()=>{}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"getUserInfo",params:{}},o)})})}};var K=Object.defineProperty,q=(e,t,i)=>(((e,t,i)=>{t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const z=new class{constructor(){q(this,"name","bluetooth"),q(this,"version","1.0.0"),q(this,"context")}install(e){this.context=e,e.bridge.registerMethod("openBluetoothAdapter",this.openBluetoothAdapter.bind(this)),e.bridge.registerMethod("closeBluetoothAdapter",this.closeBluetoothAdapter.bind(this)),e.bridge.registerMethod("startBluetoothDevicesDiscovery",this.startBluetoothDevicesDiscovery.bind(this)),e.bridge.registerMethod("stopBluetoothDevicesDiscovery",this.stopBluetoothDevicesDiscovery.bind(this)),e.bridge.registerMethod("onBluetoothDeviceFound",this.onBluetoothDeviceFound.bind(this)),e.bridge.registerMethod("offBluetoothDeviceFound",this.offBluetoothDeviceFound.bind(this)),e.bridge.registerMethod("writeBLECharacteristicValue",this.writeBLECharacteristicValue.bind(this)),e.bridge.registerMethod("readBLECharacteristicValue",this.readBLECharacteristicValue.bind(this)),e.bridge.registerMethod("connectBLEDevice",this.connectBLEDevice.bind(this)),e.bridge.registerMethod("disconnectBLEDevice",this.disconnectBLEDevice.bind(this)),e.bridge.registerMethod("getBLEDeviceCharacteristics",this.getBLEDeviceCharacteristics.bind(this)),e.bridge.registerMethod("getBLEDeviceServices",this.getBLEDeviceServices.bind(this)),e.bridge.registerMethod("onBLECharacteristicValueChange",this.onBLECharacteristicValueChange.bind(this)),e.bridge.registerMethod("offBLECharacteristicValueChange",this.offBLECharacteristicValueChange.bind(this)),e.bridge.registerMethod("onBLEConnectionStateChanged",this.onBLEConnectionStateChanged.bind(this)),e.bridge.registerMethod("offBLEConnectionStateChanged",this.offBLEConnectionStateChanged.bind(this))}offBLEConnectionStateChanged(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("offBLEConnectionStateChanged",()=>{e&&e()})})}onBLEConnectionStateChanged(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBLEConnectionStateChanged",t=>{e(t.data)})})}offBLECharacteristicValueChange(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("onBLECharacteristicValueChange",()=>{e&&e()})})}onBLECharacteristicValueChange(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBLECharacteristicValueChange",t=>{e(t.data)})})}readBLECharacteristicValue(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId||!e.serviceId||!e.characteristicId)throw i(t.INVALID_ACTION,"缺少必需的参数");const r={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"readBLECharacteristicValue",params:e},r)})}writeBLECharacteristicValue(e){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!(e.deviceId&&e.serviceId&&e.characteristicId&&e.value))throw i(t.INVALID_ACTION,"缺少必需的参数");if("string"!=typeof e.deviceId)throw i(t.JSON_ERROR,"deviceId参数格式错误");if("string"!=typeof e.serviceId)throw i(t.JSON_ERROR,"serviceId参数格式错误");if("string"!=typeof e.characteristicId)throw i(t.JSON_ERROR,"characteristicId参数格式错误");if("string"!=typeof e.value||!/^[0-9A-Fa-f]+$/.test(e.value)||(null==(r=e.value)?void 0:r.length)>200)throw i(t.JSON_ERROR,"value参数格式错误");const o={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"writeBLECharacteristicValue",params:e},o)})}getBLEDeviceServices(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw i(t.INVALID_ACTION,"缺少必需的参数: deviceId");if("string"!=typeof e.deviceId)throw i(t.JSON_ERROR,"deviceId参数格式错误");const r={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getBLEDeviceServices",params:e},r)})}connectBLEDevice(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw i(t.INVALID_ACTION,"缺少必需的参数: deviceId");const r={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"connectBLEDevice",params:e},r)})}disconnectBLEDevice(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId)throw i(t.INVALID_ACTION,"缺少必需的参数: deviceId");if("string"!=typeof e.deviceId)throw i(t.JSON_ERROR,"deviceId参数格式错误");const r={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"disconnectBLEDevice",params:e},r)})}getBLEDeviceCharacteristics(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.deviceId||!e.serviceId)throw i(t.INVALID_ACTION,"缺少必需的参数: deviceId 或 serviceId");if("string"!=typeof e.deviceId)throw i(t.JSON_ERROR,"deviceId参数格式错误");if("string"!=typeof e.serviceId)throw i(t.JSON_ERROR,"serviceId参数格式错误");const r={success:t=>{var i;null==(i=e.success)||i.call(e,t)},fail:t=>{var i;null==(i=e.fail)||i.call(e,t)},complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getBLEDeviceCharacteristics",params:e},r)})}offBluetoothDeviceFound(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.offNativeEvent("offBluetoothDeviceFound",()=>{e&&e()})})}onBluetoothDeviceFound(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("onBluetoothDeviceFound",t=>{e(t.data?JSON.parse(t.data):[])})})}stopBluetoothDevicesDiscovery(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const r={success:null==e?void 0:e.success,fail:null==e?void 0:e.fail,complete:null==e?void 0:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"stopBluetoothDevicesDiscovery",params:e},r)})}startBluetoothDevicesDiscovery(e={}){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.services&&!Array.isArray(e.services)&&"string"!=typeof e.services)throw i(t.INVALID_ACTION,"services参数格式不正确");if(void 0!==e.allowDuplicatesKey&&"boolean"!=typeof e.allowDuplicatesKey)throw i(t.INVALID_ACTION,"allowDuplicatesKey参数格式不正确");if(void 0!==e.interval&&("number"!=typeof e.interval||!Number.isInteger(e.interval)))throw i(t.INVALID_ACTION,"interval参数格式不正确");e.interval=(null==e?void 0:e.interval)||0;const r={success:null==e?void 0:e.success,fail:null==e?void 0:e.fail,complete:null==e?void 0:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"startBluetoothDevicesDiscovery",params:e},r)})}closeBluetoothAdapter(e={}){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const r={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"closeBluetoothAdapter",params:e},r)})}openBluetoothAdapter(e={}){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(void 0!==e.autoClose&&"boolean"!=typeof e.autoClose)throw i(t.JSON_ERROR,"autoClose参数格式不正确");e.autoClose=null==(r=e.autoClose)||r;const o={success:e.success,fail:e.fail,complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"openBluetoothAdapter",params:e},o)})}getBluetoothDevices(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.onNativeEvent("getBluetoothDevices",t=>{e(t.data)})})}};var Q=Object.defineProperty,X=Object.defineProperties,ee=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,ie=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable,oe=(e,t,i)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,se=(e,t,i)=>(oe(e,"symbol"!=typeof t?t+"":t,i),i),ae=(e,t,i)=>new Promise((r,o)=>{var s=e=>{try{n(i.next(e))}catch(t){o(t)}},a=e=>{try{n(i.throw(e))}catch(t){o(t)}},n=e=>e.done?r(e.value):Promise.resolve(e.value).then(s,a);n((i=i.apply(e,t)).next())});const ne=new class{constructor(){se(this,"context"),se(this,"name","storage"),se(this,"version","1.0.0")}install(e){this.context=e,e.bridge.registerMethod("setStorage",this.setStorage.bind(this)),e.bridge.registerMethod("setStorageSync",this.setStorageSync.bind(this)),e.bridge.registerMethod("getStorage",this.getStorage.bind(this)),e.bridge.registerMethod("getStorageSync",this.getStorageSync.bind(this)),e.bridge.registerMethod("removeStorage",this.removeStorage.bind(this))}_createCallbacks(e){return{success:e.success,fail:e.fail,complete:e.complete}}_callNativeMethod(e,r,o){return ae(this,null,function*(){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");return new Promise((t,i)=>{var s;null==(s=this.context)||s.bridge.ready(()=>{var s,a;null==(s=this.context)||s.bridge.callNative({action:e,params:r},(a=((e,t)=>{for(var i in t||(t={}))ie.call(t,i)&&oe(e,i,t[i]);if(te)for(var i of te(t))re.call(t,i)&&oe(e,i,t[i]);return e})({},o),X(a,ee({success:e=>{o.success&&o.success(e),t(e)},fail:e=>{o.fail&&o.fail(e),i(e)}}))))})})})}setStorageSync(e){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o=e.key;if(!o)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if(!e.data)throw i(t.INVALID_ACTION,"缺少必需的参数: data");if("string"!=typeof o)throw i(t.INVALID_ACTION,"key参数格式不正确");if("object"!=typeof e.data&&"string"!=typeof e.data)throw i(t.INVALID_ACTION,"data参数格式不正确");if("object"==typeof e.data&&0===Object.keys(e.data).length)throw i(t.INVALID_ACTION,"data参数格式不正确");const s=this._createCallbacks(e);null==(r=this.context)||r.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"setStorageSync",params:e},s)})}setStorage(e){return ae(this,null,function*(){const r=e.key;if(!r)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if(!e.data)throw i(t.INVALID_ACTION,"缺少必需的参数: data");if("string"!=typeof r)throw i(t.INVALID_ACTION,"key参数格式不正确");if("object"!=typeof e.data&&"string"!=typeof e.data)throw i(t.INVALID_ACTION,"data参数格式不正确");if("object"==typeof e.data&&0===Object.keys(e.data).length)throw i(t.INVALID_ACTION,"data参数格式不正确");const o=this._createCallbacks(e);return this._callNativeMethod("setStorage",{key:e.key,data:e.data},o)})}getStorageSync(e){var r;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o=e.key;if(!o)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof o)throw i(t.INVALID_ACTION,"key参数格式不正确");const s=this._createCallbacks(e);return null==(r=this.context)?void 0:r.bridge.callNativeSync("getStorageSync",e,s)}getStorage(e){return ae(this,null,function*(){const r=e.key;if(!r)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof r)throw i(t.INVALID_ACTION,"key参数格式不正确");const o=this._createCallbacks(e);return this._callNativeMethod("getStorage",{key:e.key},o)})}removeStorage(e){return ae(this,null,function*(){const r=e.key;if(!r)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: key");if("string"!=typeof r)throw i(t.INVALID_ACTION,"key参数格式不正确");const o=this._createCallbacks(e);return this._callNativeMethod("removeStorage",{key:r},o)})}};var ce=Object.defineProperty,le=(e,t,i)=>(((e,t,i)=>{t in e?ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const he=new class{constructor(){le(this,"context"),le(this,"name","authentication"),le(this,"version","1.0.0")}install(e){this.context=e,e.bridge.registerMethod("exclusiveLiveCheck",this.exclusiveLiveCheck.bind(this))}exclusiveLiveCheck(e={}){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const s={success:e=>{r(e)},fail:e=>{o(e)},complete:e.complete};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"exclusiveLiveCheck",params:{}},s)})})}};var de=Object.defineProperty,Ie=(e,t,i)=>(((e,t,i)=>{t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const ue=new class{constructor(){Ie(this,"name","request"),Ie(this,"version","1.0.0"),Ie(this,"context")}install(e){this.context=e,e.bridge.registerMethod("httpRequest",this.httpRequest.bind(this)),e.bridge.registerMethod("httpRequestSync",this.httpRequestSync.bind(this)),e.bridge.registerMethod("uploadFile",this.uploadFile.bind(this)),e.bridge.registerMethod("downloadFile",this.downloadFile.bind(this))}httpRequest(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw i(t.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");if(void 0!==e.method&&!["GET","POST"].includes(e.method.toUpperCase()))throw i(t.PLUGIN_NOT_INITIALIZED,"method参数格式不正确");if(void 0!==e.headers&&"object"!=typeof e.headers)throw i(t.PLUGIN_NOT_INITIALIZED,"headers参数格式不正确");if(void 0!==e.data&&"object"!=typeof e.data)throw i(t.PLUGIN_NOT_INITIALIZED,"data参数格式不正确");if(void 0!==e.dataType&&!["json","text","base64"].includes(e.dataType.toLowerCase()))throw i(t.PLUGIN_NOT_INITIALIZED,"dataType参数格式不正确");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0))throw i(t.PLUGIN_NOT_INITIALIZED,"timeout参数格式不正确");if(void 0!==e.cacheModel&&"string"!=typeof e.cacheModel||void 0!==e.cacheModel&&!["noStore","noCache","smartCache","firstCache"].includes(e.cacheModel))throw i(t.PLUGIN_NOT_INITIALIZED,"cacheModel参数格式不正确");e.method=e.method||"GET",e.headers=e.headers&&Object.keys(e.headers).length>0?e.headers:{"Content-Type":"application/x-www-form-urlencoded"},e.data=e.data||{},e.dataType=e.dataType||"json",e.timeout=e.timeout||3e4,e.cacheModel=e.cacheModel||"noStore";const s={success:e=>{r(e)},fail:e=>{o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"httpRequest",params:e,timeout:e.timeout},s)})})}httpRequestSync(e){if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)throw i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url");if("string"!=typeof e.url||!e.url.trim())throw i(t.PLUGIN_NOT_INITIALIZED,"url参数格式不正确");if(void 0!==e.method&&!["GET","POST"].includes(e.method.toUpperCase()))throw i(t.PLUGIN_NOT_INITIALIZED,"method参数格式不正确");if(void 0!==e.headers&&"object"!=typeof e.headers)throw i(t.PLUGIN_NOT_INITIALIZED,"headers参数格式不正确");if(void 0!==e.data&&"object"!=typeof e.data)throw i(t.PLUGIN_NOT_INITIALIZED,"data参数格式不正确");if(void 0!==e.dataType&&!["json","text","base64"].includes(e.dataType.toLowerCase()))throw i(t.PLUGIN_NOT_INITIALIZED,"dataType参数格式不正确");if(void 0!==e.timeout&&("number"!=typeof e.timeout||e.timeout<=0))throw i(t.PLUGIN_NOT_INITIALIZED,"timeout参数格式不正确");if(void 0!==e.cacheModel&&"string"!=typeof e.cacheModel||void 0!==e.cacheModel&&!["noStore","noCache","smartCache","firstCache"].includes(e.cacheModel))throw i(t.PLUGIN_NOT_INITIALIZED,"cacheModel参数格式不正确");e.method=e.method||"GET",e.headers=e.headers&&Object.keys(e.headers).length>0?e.headers:{"Content-Type":"application/x-www-form-urlencoded"},e.data=e.data||{},e.dataType=e.dataType||"json",e.timeout=e.timeout||3e4,e.cacheModel=e.cacheModel||"noStore";const r={success:t=>{var i;null==(i=null==e?void 0:e.success)||i.call(e,t)},fail:t=>{var i;null==(i=e.fail)||i.call(e,t)},complete:()=>{var t;null==(t=e.complete)||t.call(e)}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"httpRequest",params:e,timeout:e.timeout},r)})}uploadFile(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!(e.url&&e.filePath&&e.fileName&&e.fileType))return o(i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url, filePath, fileName, fileType"));if("string"!=typeof e.url||!e.url.trim())return o(i(t.PLUGIN_NOT_INITIALIZED,"url参数格式不正确"));if("string"!=typeof e.filePath||!e.filePath.trim())return o(i(t.PLUGIN_NOT_INITIALIZED,"filePath参数格式不正确"));if("string"!=typeof e.fileName||!e.fileName.trim())return o(i(t.PLUGIN_NOT_INITIALIZED,"fileName参数格式不正确"));if(!["image","video","audio"].includes(e.fileType))return o(i(t.PLUGIN_NOT_INITIALIZED,`不支持的文件类型: ${e.fileType}`));if(void 0!==e.header&&"object"!=typeof e.header)return o(i(t.PLUGIN_NOT_INITIALIZED,"header参数格式不正确"));if(void 0!==e.formData&&"object"!=typeof e.formData)return o(i(t.PLUGIN_NOT_INITIALIZED,"formData参数格式不正确"));const s={success:e=>{r(e)},fail:e=>{o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"uploadFile",params:e},s)})})}downloadFile(e){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.url)return o(i(t.PLUGIN_NOT_INITIALIZED,"缺少必需的参数: url"));if("string"!=typeof e.url||!e.url.trim())return o(i(t.PLUGIN_NOT_INITIALIZED,"url参数格式不正确"));if(void 0!==e.header&&"object"!=typeof e.header)return o(i(t.PLUGIN_NOT_INITIALIZED,"header参数格式不正确"));const s={success:e=>{r(e)},fail:e=>{o(e)},complete:()=>{}};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"downloadFile",params:e},s)})})}};var ge=Object.defineProperty,fe=(e,t,i)=>(((e,t,i)=>{t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i})(e,"symbol"!=typeof t?t+"":t,i),i);const Ne=new class{constructor(){fe(this,"context"),fe(this,"name","wifi"),fe(this,"version","1.0.0")}install(e){this.context=e,e.bridge.registerMethod("startWifi",this.startWifi.bind(this)),e.bridge.registerMethod("stopWifi",this.stopWifi.bind(this)),e.bridge.registerMethod("connectWifi",this.connectWifi.bind(this)),e.bridge.registerMethod("getScanWifiListAsync",this.getScanWifiListAsync.bind(this))}startWifi(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{r(e)}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"startWifi",params:{}},o)})})}stopWifi(){return new Promise((e,r)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");const o={success:t=>{e(t)},fail:e=>{r(e)}};this.context.bridge.ready(()=>{var e;null==(e=this.context)||e.bridge.callNative({action:"stopWifi",params:{}},o)})})}connectWifi(e){return new Promise((r,o)=>{var s;if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if(!e.SSID)throw i(t.INVALID_ACTION,"缺少必需的参数: SSID");if("string"!=typeof e.SSID)throw i(t.INVALID_ACTION,"SSID参数格式错误");if(void 0!==e.BSSID&&"string"!=typeof e.BSSID)throw i(t.INVALID_ACTION,"BSSID参数格式错误");if(void 0!==e.password&&"string"!=typeof e.password)throw i(t.INVALID_ACTION,"password参数格式错误");if(void 0!==e.isWEP&&"boolean"!=typeof e.isWEP)throw i(t.INVALID_ACTION,"isWEP参数格式错误");e.isWEP=null!=(s=e.isWEP)&&s;const a={success:e=>{r(e)},fail:e=>{o(e)},complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"connectWifi",params:e},a)})})}getScanWifiListAsync(e){return r=this,o=null,s=function*(){return new Promise((r,o)=>{if(!this.context)throw i(t.PLUGIN_NOT_INITIALIZED,"插件未正确初始化");if("number"!=typeof e.timeout)throw i(t.INVALID_ACTION,"timeout参数格式错误");if("number"!=typeof e.cacheTime)throw i(t.INVALID_ACTION,"cacheTime参数格式错误");const s={success:e=>{r(e)},fail:e=>{o(e)},complete:e.complete};this.context.bridge.ready(()=>{var t;null==(t=this.context)||t.bridge.callNative({action:"getScanWifiListAsync",params:e,timeout:e.timeout},s)})})},new Promise((e,t)=>{var i=e=>{try{n(s.next(e))}catch(i){t(i)}},a=e=>{try{n(s.throw(e))}catch(i){t(i)}},n=t=>t.done?e(t.value):Promise.resolve(t.value).then(i,a);n((s=s.apply(r,o)).next())});var r,o,s}},pe=l({plugins:[v,O,M,j,J,F,z,ne,he,ue,Ne],debug:!0,errorHandler:(e,t)=>{console.error(`[NativeBridge Error] ${t}:`,e)}});e.NativeBridgeCore=n,e.authenticationPlugin=he,e.bluetoothPlugin=z,e.createNativeBridge=l,e.default=pe,e.devicePlugin=O,e.locationPlugin=v,e.mediaPlugin=M,e.navigatePlugin=j,e.requestPlugin=ue,e.storagePlugin=ne,e.toastPlugin=J,e.userinfoPlugin=F,e.wifiPlugin=Ne,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
2
  //# sourceMappingURL=native-bridge.umd.js.map