@bud-fe/h5-native-bridge 1.0.4
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.
- package/README.md +352 -0
- package/dist/examples/index.d.ts +0 -0
- package/dist/index.d.ts +3 -0
- package/dist/native-bridge.es.js +3316 -0
- package/dist/native-bridge.es.js.map +1 -0
- package/dist/native-bridge.umd.js +2 -0
- package/dist/native-bridge.umd.js.map +1 -0
- package/dist/src/core/errors.d.ts +14 -0
- package/dist/src/core/index.d.ts +172 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/plugins/authentication.d.ts +30 -0
- package/dist/src/plugins/bluetooth.d.ts +399 -0
- package/dist/src/plugins/device.d.ts +117 -0
- package/dist/src/plugins/location.d.ts +89 -0
- package/dist/src/plugins/media.d.ts +157 -0
- package/dist/src/plugins/navigate.d.ts +84 -0
- package/dist/src/plugins/request.d.ts +89 -0
- package/dist/src/plugins/storage.d.ts +52 -0
- package/dist/src/plugins/toast.d.ts +47 -0
- package/dist/src/plugins/userInfo.d.ts +30 -0
- package/dist/src/plugins/wifi.d.ts +65 -0
- package/package.json +46 -0
|
@@ -0,0 +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"}})});
|
|
2
|
+
//# sourceMappingURL=native-bridge.umd.js.map
|