Files
OpenMaopaoya/frontend-uni/node_modules/@dcloudio/uni-automator/dist/index.js
T

2 lines
41 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("fs"),e=require("path"),n=require("debug"),s=require("merge"),i=require("jsonc-parser"),o=require("licia/isRelative"),r=require("ws"),a=require("events"),c=require("licia/uuid"),p=require("licia/stringify"),l=require("licia/dateFormat"),u=require("licia/waitUntil"),h=require("os"),d=require("address"),m=require("default-gateway"),y=require("licia/isStr"),g=require("licia/getPort"),v=require("qrcode-terminal"),f=require("licia/fs"),w=require("licia/isFn"),P=require("licia/trim"),M=require("licia/startWith"),A=require("licia/isNum"),_=require("licia/sleep"),I=require("licia/isUndef"),k=require("child_process"),E=require("licia/toStr"),T=require("fs-extra");function b(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var O=b(t),U=b(e),N=b(n),C=b(o),R=b(r),S=b(c),D=b(p),x=b(l),j=b(u),L=b(h),q=b(d),$=b(m),F=b(y),W=b(g),H=b(v),B=b(f),X=b(w),V=b(P),J=b(M),K=b(A),G=b(_),Y=b(I),z=b(E);class Q extends a.EventEmitter{constructor(t){super(),this.ws=t,this.ws.addEventListener("message",(t=>{this.emit("message",t.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(t,e){this.ws.send(t,e)}close(){this.ws.close()}}const Z=new Map,tt=["onCompassChange","onThemeChange","onUserCaptureScreen","onWindowResize","onMemoryWarning","onAccelerometerChange","onKeyboardHeightChange","onNetworkStatusChange","onPushMessage","onLocationChange","onGetWifiList","onWifiConnected","onWifiConnectedWithPartialInfo","onSocketOpen","onSocketError","onSocketMessage","onSocketClose"];const et=new Map;function nt(t,e){(null==t?void 0:t.success)&&"function"==typeof(null==t?void 0:t.success)&&(e?t.success(e):t.success()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}function st(t,e){(null==t?void 0:t.fail)&&"function"==typeof(null==t?void 0:t.fail)&&(e?t.fail(e):t.fail()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}async function it(t,e){const[n,s]=function(t){return F.default(t)?[!0,[t]]:[!1,t]}(e),i=await t(s);return n?i[0]:i}function ot(t){try{return require(t)}catch(e){return require(require.resolve(t,{paths:[process.cwd()]}))}}/^win/.test(process.platform);const rt="__UNI_AUTOMATOR_SOCKET_CONNECTION_CLOSED__";const at="Connection closed";class ct extends a.EventEmitter{constructor(t,e,n){super(),this.puppet=e,this.namespace=n,this.callbacks=new Map,this.transport=t,this.isAlive=!0,this.id=Date.now(),this.exConnectionClosed=!1,this.debug=N.default("automator:protocol:"+this.namespace),this.onMessage=t=>{var e,n,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&'"pong"'===t)return;const{id:i,method:o,error:r,result:a,params:c}=JSON.parse(t);if((null===(e=null==a?void 0:a.data)||void 0===e?void 0:e.length)>10240){let t=JSON.stringify({id:i,method:o,error:r,result:Object.assign(Object.assign({},a),{data:a.data.substring(0,30)+"...<more>"}),params:c});this.debug(`${x.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`)}else this.debug(`${x.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`);if(null===(n=null==a?void 0:a.method)||void 0===n?void 0:n.startsWith("on"))return void((t,e)=>{const n=Z.get(t.method);(null==n?void 0:n.has(e))&&n.get(e)(t.data)})(a,i);if(null===(s=null==a?void 0:a.method)||void 0===s?void 0:s.startsWith("Socket.")){return void((t,e,n)=>{const s=et.get(e);(null==s?void 0:s.has(t))&&s.get(t)(n)})(a.method.replace("Socket.",""),a.id,a.data)}if(!i)return this.puppet.emit(o,c);const{callbacks:p}=this;if(i&&p.has(i)){const t=p.get(i);p.delete(i),r?t.reject(Error(r.message||r.detailMessage||r.errMsg)):t.resolve(a)}},this.onClose=()=>{const t=Error(at);this.exConnectionClosed=t,global[rt]=!0,this.callbacks.forEach((e=>{e.reject(t)})),this.callbacks.clear()},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}isBroken(){return!!this.exConnectionClosed}handleSocketRetryRejection(t){return"true"===process.env.UNI_AUTOMATOR_RETRY_ON_SOCKET_CLOSE&&t.catch((()=>{})),t}send(t,e={},n=!0){if(n&&this.puppet.adapter.has(t))return this.puppet.adapter.send(this,t,e);if(this.exConnectionClosed)return this.handleSocketRetryRejection(Promise.reject(this.exConnectionClosed));const s=S.default(),i=D.default({id:s,method:t,params:e});"ping"!==t&&this.debug(`${x.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${i}`);const o=new Promise(((t,e)=>{try{this.transport.send(i,(t=>{t&&e(Error(at))}))}catch(t){e(Error(at))}this.callbacks.set(s,{resolve:t,reject:e})})).catch((t=>{throw t.message===at&&(this.exConnectionClosed=t,global[rt]=!0),t}));return this.handleSocketRetryRejection(o)}dispose(){this.callbacks.clear(),this.transport.close()}startHeartbeat(){"true"===process.env.UNI_APP_X&&("android"===process.env.UNI_APP_PLATFORM?this.startXAndroidHeartbeat():"ios"===process.env.UNI_APP_PLATFORM&&this.startXIosHeartbeat())}startXAndroidHeartbeat(){const t=new Map,e=ot("adbkit"),n=L.default.platform();let s="",i="";"darwin"===n?(s='ps | grep "u0_a"',i="logcat -b crash | grep -C 10 io.dcloud.uniappx"):"win32"===n&&(s='dumpsys activity | findstr "Run"',i="logcat | findstr UncaughtExceptionHandler"),t.set(this.id,setInterval((async()=>{if(!this.isAlive){const o=e.createClient(),r=await o.listDevices();if(!r.length)throw Error("Device not found");const a=r[0].id,c=await o.getProperties(a);return("1"===c["ro.kernel.qemu"]||"goldfish"===c["ro.hardware"])&&"win32"===n&&(i="logcat | grep UncaughtExceptionHandler"),o.shell(a,s).then((function(t){let e,n="";t.on("data",(function(t){n+=t.toString(),e&&clearTimeout(e),e=setTimeout((()=>{n.includes("io.dcloud.uniapp")||(o.shell(a,"screencap -p /sdcard/uni-automator-screenshot-when-uniapp-un-active.png"),console.log("ADBCommandAppIsLaunch",s),console.log("ADBCommandAppIsLaunch res",n))}),50)}))})),o.shell(a,i).then((t=>{let e,n="";t.on("data",(t=>{n+=t.toString(),e&&clearTimeout(e),e=setTimeout((()=>{console.log(`crash log: ${n}`)}),50)}))})),clearInterval(t.get(this.id)),t.delete(this.id),void this.dispose()}this.send("ping").catch((t=>{})),this.isAlive=!1}),5e3))}startXIosHeartbeat(){const t=new Map;t.set(this.id,setInterval((async()=>{if(!this.isAlive)return clearInterval(t.get(this.id)),t.delete(this.id),void this.dispose();this.send("ping").catch((t=>{})),this.isAlive=!1}),5e3))}static createDevtoolConnection(t,e){return new Promise(((n,s)=>{const i=new R.default(t);i.addEventListener("open",(()=>{n(new ct(new Q(i),e,"devtool"))})),i.addEventListener("error",s)}))}static createRuntimeConnection(t,e,n){return new Promise(((s,i)=>{let o=!1,r=!1;N.default("automator:runtime")(`${x.default("yyyy-mm-dd HH:MM:ss:l")} port=${t}`);const a=new R.default.Server({port:t});a.cancelPendingConnection=()=>{r=!0},a.once("close",(()=>{o||(r=!0,i("Runtime connection was closed before it was established"))})),j.default((async()=>!!r||(!!e.runtimeConnection||void 0)),n,1e3).catch((()=>{a.cancelPendingConnection(),a.close(),i("Failed to connect to runtime, please make sure the project is running")})),a.on("connection",(function(t){if(r)return void t.close();o=!0,N.default("automator:runtime")(`${x.default("yyyy-mm-dd HH:MM:ss:l")} connected`);const n=new ct(new Q(t),e,"runtime");e.setRuntimeConnection(n),global.socketConnected=!0,process.env.UNI_AUTOMATOR_NEED_RESTART_BETWEEN_TEST||n.startHeartbeat(),s(n)})),e.setRuntimeServer(a)}))}}function pt(t,e,n,s){var i,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(o<3?i(r):o>3?i(e,n,r):i(e,n))||r);return o>3&&r&&Object.defineProperty(e,n,r),r}var lt;function ut(t,e){const n=e.value;return e.value=async function(e){return(await(null==n?void 0:n.call(this,e)))(t)},e}function ht(t,e,n){return ut(lt.RUNTIME,n)}function dt(t,e,n){return ut(lt.DEVTOOL,n)}"function"==typeof SuppressedError&&SuppressedError,function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(lt||(lt={}));class mt{constructor(t){this.puppet=t}invoke(t,e){return async n=>this.puppet.devtoolConnection?(n===lt.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}class yt extends mt{constructor(t,e){super(t),this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId,this.videoId=e.videoId}async getData(t){return this.invokeMethod("Element.getData",t)}async setData(t){return this.invokeMethod("Element.setData",t)}async callMethod(t){return this.invokeMethod("Element.callMethod",t)}async getElement(t){return this.invokeMethod("Element.getElement",t)}async getElements(t){return this.invokeMethod("Element.getElements",t)}async getOffset(){return this.invokeMethod("Element.getOffset")}async getHTML(t){return this.invokeMethod("Element.getHTML",t)}async getAttributes(t){return this.invokeMethod("Element.getAttributes",t)}async getStyles(t){return this.invokeMethod("Element.getStyles",t)}async getDOMProperties(t){return this.invokeMethod("Element.getDOMProperties",t)}async getProperties(t){return this.invokeMethod("Element.getProperties",t)}async tap(){return this.invokeMethod("Element.tap")}async longpress(){return this.invokeMethod("Element.longpress")}async touchstart(t){return this.invokeMethod("Element.touchstart",t)}async touchmove(t){return this.invokeMethod("Element.touchmove",t)}async touchend(t){return this.invokeMethod("Element.touchend",t)}async triggerEvent(t){return this.invokeMethod("Element.triggerEvent",t)}async callFunction(t){return this.invokeMethod("Element.callFunction",t)}async callContextMethod(t){return this.invokeMethod("Element.callContextMethod",t)}invokeMethod(t,e={}){return e.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.invoke(t,e)}}pt([ht],yt.prototype,"getData",null),pt([ht],yt.prototype,"setData",null),pt([ht],yt.prototype,"callMethod",null),pt([dt],yt.prototype,"getElement",null),pt([dt],yt.prototype,"getElements",null),pt([dt],yt.prototype,"getOffset",null),pt([dt],yt.prototype,"getHTML",null),pt([dt],yt.prototype,"getAttributes",null),pt([dt],yt.prototype,"getStyles",null),pt([dt],yt.prototype,"getDOMProperties",null),pt([dt],yt.prototype,"getProperties",null),pt([dt],yt.prototype,"tap",null),pt([dt],yt.prototype,"longpress",null),pt([dt],yt.prototype,"touchstart",null),pt([dt],yt.prototype,"touchmove",null),pt([dt],yt.prototype,"touchend",null),pt([dt],yt.prototype,"triggerEvent",null),pt([dt],yt.prototype,"callFunction",null),pt([dt],yt.prototype,"callContextMethod",null);const gt=Object.prototype.hasOwnProperty,vt=Array.isArray,ft=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function wt(t,e){if(vt(t))return t;if(e&&(n=e,s=t,gt.call(n,s)))return[t];var n,s;const i=[];return t.replace(ft,(function(t,e,n,s){return i.push(n?s.replace(/\\(\\)?/g,"$1"):e||t),s})),i}function Pt(t,e){const n=wt(e,t);let s;for(s=n.shift();null!=s;){if(null==(t=t[s]))return;s=n.shift()}return t}const Mt=require("util"),At=["scrollLeft","scrollTop","scrollWidth","scrollHeight"];class _t{constructor(t,e,n){this.puppet=t,this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId||null,this.videoId=e.videoId||null,this.tagName=e.tagName,this.nvue=e.nvue,this.elementMap=n,_t.allElementMaps.add(n),"body"!==this.tagName&&"page-body"!==this.tagName||(this.tagName="page"),this.api=new yt(t,e)}toJSON(){return JSON.stringify({id:this.id,tagName:this.tagName,pageId:this.pageId,nodeId:this.nodeId,videoId:this.videoId})}toString(){return this.toJSON()}[Mt.inspect.custom](){return this.toJSON()}async $(t){try{const e=await this.api.getElement({selector:t});return _t.create(this.puppet,Object.assign({},e,{pageId:this.pageId}),this.elementMap)}catch(t){return null}}async $$(t){const{elements:e}=await this.api.getElements({selector:t});return e.map((t=>_t.create(this.puppet,Object.assign({},t,{pageId:this.pageId}),this.elementMap)))}async size(){const[t,e]=await this.domProperty(["offsetWidth","offsetHeight"]);return{width:t,height:e}}async offset(){const{left:t,top:e}=await this.api.getOffset();return{left:t,top:e}}async text(){return this.domProperty("innerText")}async attribute(t){if(!F.default(t))throw Error("name must be a string");return(await this.api.getAttributes({names:[t]})).attributes[0]}async value(){return!this.puppet.isX||"ios"!==process.env.UNI_APP_PLATFORM&&"h5"!=process.env.UNI_PLATFORM?this.property("value"):this.domProperty("value")}async property(t){if(!F.default(t))throw Error("name must be a string");if(this.puppet.checkProperty){let e=this.publicProps;if(e||(this.publicProps=e=await this._property("__propPublic")),!e[t])throw Error(`${this.tagName}.${t} not exists`)}return this.puppet.isX&&"h5"===process.env.UNI_PLATFORM&&At.includes(t)?await this.domProperty(t):this._property(t)}async html(){return(await this.api.getHTML({type:"inner"})).html}async outerHtml(){return(await this.api.getHTML({type:"outer"})).html}async style(t){if(!F.default(t))throw Error("name must be a string");return(await this.api.getStyles({names:[t]})).styles[0]}async tap(){return this.api.tap()}async longpress(){return this.nvue||"mp-alipay"===this.puppet.platform||"true"===process.env.UNI_APP_X&&("ios"===process.env.UNI_APP_PLATFORM||"android"===process.env.UNI_APP_PLATFORM||"h5"==process.env.UNI_PLATFORM||"app-harmony"==process.env.UNI_PLATFORM)?this.api.longpress():(await this.touchstart(),await G.default(350),this.touchend())}async trigger(t,e){const n={type:t};return Y.default(e)||(n.detail=e),this.api.triggerEvent(n)}async touchstart(t){return this.api.touchstart(t)}async touchmove(t){return this.api.touchmove(t)}async touchend(t){return this.api.touchend(t)}async domProperty(t){return it((async t=>(await this.api.getDOMProperties({names:t})).properties),t)}_property(t){return it((async t=>(await this.api.getProperties({names:t})).properties),t)}send(t,e){return e.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.puppet.send(t,e)}async callFunction(t,...e){return(await this.api.callFunction({functionName:t,args:e})).result}static create(t,e,n){let s,i=n.get(e.elementId);if(i)return i;if(e.nodeId)s=kt;else switch(e.tagName.toLowerCase()){case"input":s=Et;break;case"textarea":s=Tt;break;case"scroll-view":s=bt;break;case"swiper":s=Ot;break;case"movable-view":s=Ut;break;case"switch":s=Nt;break;case"slider":s=Ct;break;case"video":s=Rt;break;default:s=_t}return i=new s(t,e,n),n.set(e.elementId,i),i}static clearAllElementMaps(){_t.allElementMaps.forEach((t=>t.clear()))}}_t.allElementMaps=new Set;var It=_t;class kt extends _t{async setData(t){return this.api.setData({data:t})}async data(t){const e={};if(t&&(e.path=t),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM&&"true"!==process.env.UNI_AUTOMATOR_APP_WEBVIEW&&"true"!==process.env.UNI_APP_X_DOM2){const n=(await this.api.getData(e)).data;return t?Pt(n,t):n}return(await this.api.getData(e)).data}async callMethod(t,...e){return(await this.api.callMethod({method:t,args:e})).result}}class Et extends _t{async input(t){return this.callFunction("input.input",t)}}class Tt extends _t{async input(t){return this.callFunction("textarea.input",t)}}class bt extends _t{async scrollTo(t,e){return this.callFunction("scroll-view.scrollTo",t,e)}async property(t){return"scrollTop"===t?this.callFunction("scroll-view.scrollTop"):"scrollLeft"===t?this.callFunction("scroll-view.scrollLeft"):super.property(t)}async scrollWidth(){return this.callFunction("scroll-view.scrollWidth")}async scrollHeight(){return this.callFunction("scroll-view.scrollHeight")}}class Ot extends _t{async swipeTo(t){return this.callFunction("swiper.swipeTo",t)}}class Ut extends _t{async moveTo(t,e){return this.callFunction("movable-view.moveTo",t,e)}async property(t){return"x"===t?this._property("_translateX"):"y"===t?this._property("_translateY"):super.property(t)}}class Nt extends _t{async tap(){return this.callFunction("switch.tap")}}class Ct extends _t{async slideTo(t){return this.callFunction("slider.slideTo",t)}}class Rt extends _t{async callContextMethod(t,...e){return await this.api.callContextMethod({method:t,args:e})}}class St extends mt{constructor(t,e){super(t),this.id=e.id}async getData(t){return this.invokeMethod("Page.getData",t)}async setData(t){return this.invokeMethod("Page.setData",t)}async callMethod(t){return this.invokeMethod("Page.callMethod",t)}async nextTick(){return this.invokeMethod("Page.pageNextTick")}async callMethodWithCallback(t){return this.invokeMethod("Page.callMethodWithCallback",t)}async getElement(t){return this.invokeMethod("Page.getElement",t)}async getElements(t){return this.invokeMethod("Page.getElements",t)}async getWindowProperties(t){return this.invokeMethod("Page.getWindowProperties",t)}invokeMethod(t,e={}){return e.pageId=this.id,this.invoke(t,e)}}pt([ht],St.prototype,"getData",null),pt([ht],St.prototype,"setData",null),pt([ht],St.prototype,"callMethod",null),pt([ht],St.prototype,"nextTick",null),pt([ht],St.prototype,"callMethodWithCallback",null),pt([dt],St.prototype,"getElement",null),pt([dt],St.prototype,"getElements",null),pt([dt],St.prototype,"getWindowProperties",null);const Dt=require("util");class xt{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=new Map,this.api=new St(t,e)}toJSON(){return JSON.stringify({id:this.id,path:this.path,query:this.query})}toString(){return this.toJSON()}[Dt.inspect.custom](){return this.toJSON()}async waitFor(t,e=0){return K.default(t)?await G.default(t):X.default(t)?j.default(t,e,50):F.default(t)?"nextTick"===t?j.default((()=>this.nextTick())):j.default((async()=>{if("true"===process.env.UNI_APP_X){return!!await this.$(t)}return(await this.$$(t)).length>0}),e,50):void 0}async $(t){try{const e=await this.api.getElement({selector:t});return It.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)}catch(t){return null}}async $$(t){const{elements:e}=await this.api.getElements({selector:t});return e.map((e=>It.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)))}async data(t){const e={};if(t&&(e.path=t),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM&&"true"!==process.env.UNI_AUTOMATOR_APP_WEBVIEW&&"true"!==process.env.UNI_APP_X_DOM2){const n=(await this.api.getData(e)).data;return t?Pt(n,t):n}return(await this.api.getData(e)).data}async setData(t){return this.api.setData({data:t})}async size(){const[t,e]=await this.windowProperty(["document.documentElement.scrollWidth","document.documentElement.scrollHeight"]);return{width:t,height:e}}async callMethod(t,...e){return(await this.api.callMethod({method:t,args:e})).result}async callMethodWithCallback(t,...e){return await this.api.callMethodWithCallback({method:t,args:e})}async scrollTop(){return this.windowProperty("document.documentElement.scrollTop")}async nextTick(){return this.api.nextTick()}async windowProperty(t){const e=F.default(t);e&&(t=[t]);const{properties:n}=await this.api.getWindowProperties({names:t});return e?n[0]:n}static create(t,e,n){let s=n.get(e.id);return s?(s.path=e.path,s.query=e.query,s):(s=new xt(t,e),n.set(e.id,s),s)}}class jt extends mt{async getPageStack(){return this.invoke("App.getPageStack")}async callUniMethod(t){return this.invoke("App.callUniMethod",t)}async getCurrentPage(){return this.invoke("App.getCurrentPage")}async mockUniMethod(t){return this.invoke("App.mockUniMethod",t)}async captureScreenshotByRuntime(t){return this.invoke("App.captureScreenshot",t)}async captureScreenshotWithDeviceByRuntime(t){return this.invoke("App.captureScreenshotWithDevice",t)}async socketEmitter(t){return this.invoke("App.socketEmitter",t)}async callFunction(t){return this.invoke("App.callFunction",t)}async captureScreenshot(t){return this.invoke("App.captureScreenshot",t)}async adbCommand(t){return this.invoke("App.adbCommand",t)}async swipe(t){return this.invoke("App.swipe",t)}async tap(t){return this.invoke("App.tap",t)}async setScreenOrientation(t){return this.invoke("App.setScreenOrientation",t)}async keyboardInput(t){return this.invoke("App.keyboardInput",t)}async start(t){return this.invoke("App.start",t)}async exit(){return this.invoke("App.exit")}async addBinding(t){return this.invoke("App.addBinding",t)}async enableLog(){return this.invoke("App.enableLog")}onLogAdded(t){return this.on("App.logAdded",t)}onBindingCalled(t){return this.on("App.bindingCalled",t)}onExceptionThrown(t){return this.on("App.exceptionThrown",t)}}pt([ht],jt.prototype,"getPageStack",null),pt([ht],jt.prototype,"callUniMethod",null),pt([ht],jt.prototype,"getCurrentPage",null),pt([ht],jt.prototype,"mockUniMethod",null),pt([ht],jt.prototype,"captureScreenshotByRuntime",null),pt([ht],jt.prototype,"captureScreenshotWithDeviceByRuntime",null),pt([ht],jt.prototype,"socketEmitter",null),pt([dt],jt.prototype,"callFunction",null),pt([dt],jt.prototype,"captureScreenshot",null),pt([dt],jt.prototype,"adbCommand",null),pt([dt],jt.prototype,"swipe",null),pt([dt],jt.prototype,"tap",null),pt([dt],jt.prototype,"setScreenOrientation",null),pt([dt],jt.prototype,"keyboardInput",null),pt([dt],jt.prototype,"start",null),pt([dt],jt.prototype,"exit",null),pt([dt],jt.prototype,"addBinding",null),pt([dt],jt.prototype,"enableLog",null);class Lt{constructor(t){this.device=t}async input(t,e){await this.device.requestKeyboardInput({text:t,x:null==e?void 0:e.x,y:null==e?void 0:e.y,delay:null==e?void 0:e.delay})}}class qt extends mt{constructor(t){super(t),this.keyboard=new Lt(this)}async screenshot(t){const{data:e}=await this.requestScreenshot({area:null==t?void 0:t.area});if(!(null==t?void 0:t.path))return e;await B.default.writeFile(t.path,e,"base64")}async tap(t,e,n){await this.requestTap({x:t,y:e,duration:null==n?void 0:n.duration})}async swipe(t,e,n,s,i){if(i&&"boolean"==typeof i.keepTouch&&!this.isHarmonyAppPlatform())throw new Error("program.device.swipe keepTouch is only supported on the app-harmony platform");const o={startPoint:{x:t,y:e},endPoint:{x:n,y:s}};i&&"number"==typeof i.duration&&(o.duration=i.duration),i&&"boolean"==typeof i.keepTouch&&(o.keepTouch=i.keepTouch),await this.requestSwipe(o)}async setScreenOrientation(t){await this.requestSetScreenOrientation(t)}async requestScreenshot(t){return this.invoke("Device.screenshot",t)}async requestTap(t){return this.invoke("Device.tap",t)}async requestSwipe(t){return this.invoke("Device.swipe",t)}async requestSetScreenOrientation(t){return this.invoke("Device.setScreenOrientation",t)}async requestKeyboardInput(t){return this.invoke("Device.keyboard.input",t)}isHarmonyAppPlatform(){return"app-harmony"===this.puppet.platform||"harmony"===process.env.UNI_OS_NAME||"harmony"===process.env.UNI_APP_PLATFORM}}pt([dt],qt.prototype,"requestScreenshot",null),pt([dt],qt.prototype,"requestTap",null),pt([dt],qt.prototype,"requestSwipe",null),pt([dt],qt.prototype,"requestSetScreenOrientation",null),pt([dt],qt.prototype,"requestKeyboardInput",null);class $t extends mt{async getInfo(){return this.invoke("Tool.getInfo")}async enableRemoteDebug(t){return this.invoke("Tool.enableRemoteDebug")}async close(){return this.invoke("Tool.close")}async getTestAccounts(){return this.invoke("Tool.getTestAccounts")}onRemoteDebugConnected(t){this.puppet.once("Tool.onRemoteDebugConnected",t),this.puppet.once("Tool.onPreviewConnected",t)}}function Ft(t){return"number"==typeof t&&Number.isFinite(t)}function Wt(t){return new Error(`Invalid screenshot area: x=${t.x}, y=${t.y}, width=${t.width}, height=${t.height}`)}async function Ht(t,e,n){const s=require("jimp"),i=Buffer.isBuffer(t)?t:Buffer.from(t.replace(/^data:image\/[^;]+;base64,/,""),"base64");return async function(t){const e=require("jimp");return(await t.getBase64Async(e.MIME_PNG)).replace(/^data:image\/png;base64,/,"")}(function(t,e,n){const s=Number.isFinite(n)&&n>0?n:1,i=t.bitmap.width,o=t.bitmap.height,r=Ft(e.x)?e.x:0,a=Ft(e.y)?e.y:0,c=void 0!==e.width&&null!==e.width,p=void 0!==e.height&&null!==e.height;if(c&&(!Ft(e.width)||e.width<=0)||p&&(!Ft(e.height)||e.height<=0))throw Wt(e);const l=Math.round(r*s),u=Math.round(a*s),h=c?l+Math.round(e.width*s):i,d=p?u+Math.round(e.height*s):o,m=Math.max(0,Math.min(i,l)),y=Math.max(0,Math.min(o,u)),g=Math.max(0,Math.min(i,h))-m,v=Math.max(0,Math.min(o,d))-y;if(!Number.isFinite(m)||!Number.isFinite(y)||!Number.isFinite(g)||!Number.isFinite(v)||g<=0||v<=0)throw Wt(e);return t.crop(m,y,g,v)}(await s.read(i),e,n))}function Bt(t){return new Promise((e=>setTimeout(e,t)))}pt([dt],$t.prototype,"getInfo",null),pt([dt],$t.prototype,"enableRemoteDebug",null),pt([dt],$t.prototype,"close",null),pt([dt],$t.prototype,"getTestAccounts",null);class Xt extends a.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=new Map,this.appBindings=new Map,this.appApi=new jt(t),this.device=new qt(t),this.toolApi=new $t(t),this.appApi.onLogAdded((t=>{this.emit("console",t)})),this.appApi.onBindingCalled((({name:t,args:e})=>{try{const n=this.appBindings.get(t);n&&n(...e)}catch(t){}})),this.appApi.onExceptionThrown((t=>{this.emit("exception",t)}))}async pageStack(){return(await this.appApi.getPageStack()).pageStack.map((t=>xt.create(this.puppet,t,this.pageMap)))}async navigateTo(t){return this.changeRoute("navigateTo",t)}async redirectTo(t){return this.changeRoute("redirectTo",t)}async navigateBack(){return this.changeRoute("navigateBack")}async reLaunch(t){return process.env.UNI_AUTOMATOR_FAILOVER_ON_RELAUNCH&&this.puppet.runtimeConnection.isBroken()&&("app-plus"!==this.puppet.platform&&"app-harmony"!==this.puppet.platform||(console.warn("【UNI_AUTOMATOR_FAILOVER_ON_RELAUNCH】应用已断开,重新拉起"),await this.start("jest"),await j.default((()=>!this.puppet.runtimeConnection.isBroken()),5e3,50).catch((t=>{throw new Error("re-launch failed")})))),this.changeRoute("reLaunch",t)}async switchTab(t){return this.changeRoute("switchTab",t)}async currentPage(){const{id:t,path:e,query:n}=await this.appApi.getCurrentPage();return xt.create(this.puppet,{id:t,path:e,query:n},this.pageMap)}async systemInfo(){return this.callUniMethod("getSystemInfoSync")}async callUniMethod(t,...e){return(await this.appApi.callUniMethod({method:t,args:e})).result}async mockUniMethod(t,e,...n){return X.default(e)||(s=e,F.default(s)&&(s=V.default(s),J.default(s,"function")||J.default(s,"() =>")))?this.appApi.mockUniMethod({method:t,functionDeclaration:e.toString(),args:n}):this.appApi.mockUniMethod({method:t,result:e});var s}async restoreUniMethod(t){return this.appApi.mockUniMethod({method:t})}async evaluate(t,...e){return(await this.appApi.callFunction({functionDeclaration:t.toString(),args:e})).result}async pageScrollTo(t){await this.callUniMethod("pageScrollTo",{scrollTop:t,duration:0})}async close(){try{await this.appApi.exit()}catch(t){}await Bt(1e3),this.puppet.disposeRuntimeServer(),await this.toolApi.close(),this.disconnect()}async start(t){t&&_t.clearAllElementMaps(),await this.appApi.start(t)}async teardown(){return this["disconnect"===this.options.teardown?"disconnect":"close"]()}async remote(t){if(!this.puppet.devtools.remote)return console.warn(`Failed to enable remote, ${this.puppet.devtools.name} is unimplemented`);const{qrCode:e}=await this.toolApi.enableRemoteDebug({auto:t});var n;e&&await(n=e,new Promise((t=>{H.default.generate(n,{small:!0},(e=>{process.stdout.write(e),t(void 0)}))})));const s=new Promise((t=>{this.toolApi.onRemoteDebugConnected((async()=>{await Bt(1e3),t(void 0)}))})),i=new Promise((t=>{this.puppet.setRemoteRuntimeConnectionCallback((()=>{t(void 0)}))}));return Promise.all([s,i])}disconnect(){this.puppet.dispose()}on(t,e){return"console"===t&&this.appApi.enableLog(),super.on(t,e),this}async exposeFunction(t,e){if(this.appBindings.has(t))throw Error(`Failed to expose function with name ${t}: already exists!`);this.appBindings.set(t,e),await this.appApi.addBinding({name:t})}async checkVersion(){}async screenshot(t){let e="captureScreenshot";this.puppet.isX&&("app-plus"!==this.puppet.platform&&"app-harmony"!==this.puppet.platform||(e=(null==t?void 0:t.deviceShot)&&"真机"!==process.env.UNI_DEVICE_TYPE?"captureScreenshotWithDeviceByRuntime":"captureScreenshotByRuntime"));let{data:n}=await this.appApi[e]({id:null==t?void 0:t.id,fullPage:null==t?void 0:t.fullPage,deviceShot:null==t?void 0:t.deviceShot,area:null==t?void 0:t.area,offsetX:null==t?void 0:t.offsetX,offsetY:null==t?void 0:t.offsetY});const s=null==t?void 0:t.area;if("captureScreenshotByRuntime"===e&&function(t){return!(!t||void 0===t.x&&void 0===t.y&&void 0===t.width&&void 0===t.height)}(s)){const t=await this.systemInfo();n=await Ht(n,s,Number(t.pixelRatio))}if(!(null==t?void 0:t.path))return n;await B.default.writeFile(t.path,n,"base64")}async testAccounts(){return(await this.toolApi.getTestAccounts()).accounts}async changeRoute(t,e){if(this.puppet.isVue3&&"h5"===process.env.UNI_PLATFORM&&"navigateBack"!==t){const{__id__:n}=await this.callUniMethod(t,{url:e,isAutomatedTesting:!0}),s=Date.now();return await j.default((async()=>{if(Date.now()-s>15e3)throw Error(`${t} to ${e} failed, unable to get the correct current page`);let i;try{i=await this.currentPage()}catch(t){return!1}return i.id===n&&i}),0,1e3)}if(await this.callUniMethod(t,{url:e}),await Bt(1e3),"mp-alipay"===this.puppet.platform){const n=function(t){return null==t?void 0:t.split("?",1)[0].replace(/^\//,"")}(e);try{return await j.default((async()=>{try{const t=await this.currentPage();return(!n||t.path===n)&&t}catch(t){return!1}}),15e3,100)}catch(n){throw new Error(`${t} to ${e} failed, unable to get the correct current page`)}}return await this.currentPage()}async socketEmitter(t){return this.appApi.socketEmitter(t)}async adbCommand(t){return"android"===process.env.UNI_APP_PLATFORM?await this.appApi.adbCommand(t):Error("Program.adbCommand is only supported on the app android platform")}async swipe(t){const e=Object.prototype.hasOwnProperty.call(t,"keepTouch"),n="app-harmony"===this.puppet.platform;if(e&&!n)throw new Error("Program.swipe keepTouch is only supported on the app-harmony platform");return await this.appApi.swipe(t)}async tap(t){return await this.appApi.tap(t)}async setScreenOrientation(t){return await this.appApi.setScreenOrientation(t)}async keyboardInput(t){return await this.appApi.keyboardInput(t)}}class Vt{constructor(t){this.options=t}has(t){return!!this.options[t]}send(t,e,n){const s=this.options[e];if(!s)return Promise.reject(Error(`adapter for ${e} not found`));const i=s.reflect;return i?(s.params&&(n=s.params(n)),"function"==typeof i?i(t.send.bind(t),n):(e=i,t.send(e,n))):Promise.reject(Error(`${e}'s reflect is required`))}}const Jt=N.default("automator:puppet"),Kt=".automator.json";function Gt(t){try{return require(t)}catch(t){}}function Yt(t,e,n,s){const i=function(t,e,n){let s,i;return process.env.UNI_OUTPUT_DIR?(i=U.default.join(process.env.UNI_OUTPUT_DIR,`../.automator/${e}`,Kt),s=Gt(i)):(i=U.default.join(t,`dist/${n}/.automator/${e}`,Kt),s=Gt(i),s||(i=U.default.join(t,`${process.env.UNI_AUTOMATOR_CUSTOM_UNPACKAGE_DIR||"unpackage"}/dist/${n}/.automator/${e}`,Kt),s=Gt(i))),Jt(`${i}=>${JSON.stringify(s)}`),s}(t,n,s);if(!i||!i.wsEndpoint)return!1;const o=require("../package.json").version;if(i.version!==o)return Jt(`unmet=>${i.version}!==${o}`),!1;const r=function(t){let e;try{const t=$.default.v4.sync();e=q.default.ip(t&&t.interface),e&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(e)||(e=void 0))}catch(t){}return"ws://"+(e||"localhost")+":"+t}(e);return Jt(`wsEndpoint=>${r}`),i.wsEndpoint===r}class zt extends a.EventEmitter{constructor(t,e){if(super(),this.isX=!1,this.isVue3=!1,"true"===process.env.UNI_APP_X&&(this.isX=!0),e)this.target=e;else{if(this.target=null,"h5"===t)try{const t=ot("@dcloudio/uni-h5/lib/h5/uni.automator.js");this.target=t.default||t}catch(t){}if(!this.target){const e=ot(`@dcloudio/uni-${"app"===t?"app-plus":t}/lib/uni.automator.js`);this.target=e.default||e}}if(!this.target)throw Error("puppet is not provided");this.platform=t,this.adapter=new Vt(this.target.adapter||{})}setCompiler(t){this.compiler=t}setRuntimeServer(t){this.wss=t}setRemoteRuntimeConnectionCallback(t){this.remoteRuntimeConnectionCallback=t}setRuntimeConnection(t){global[rt]=!1,this.runtimeConnection=t,this.remoteRuntimeConnectionCallback&&(this.remoteRuntimeConnectionCallback(),this.remoteRuntimeConnectionCallback=null)}setDevtoolConnection(t){this.devtoolConnection=t}disposeRuntimeServer(){var t,e;this.wss&&(null===(e=(t=this.wss).cancelPendingConnection)||void 0===e||e.call(t),this.wss.close())}disposeRuntime(){this.runtimeConnection&&this.runtimeConnection.dispose()}disposeDevtool(){this.compiler&&this.compiler.stop(),this.devtoolConnection&&this.devtoolConnection.dispose()}setLauncherWithRuntimeLogs(t){this.launcherWithRuntimeLogs=t}disposeLauncherWithRuntimeLogs(){this.launcherWithRuntimeLogs&&this.launcherWithRuntimeLogs.exit()}dispose(){this.disposeRuntime(),this.disposeDevtool(),this.disposeRuntimeServer(),this.disposeLauncherWithRuntimeLogs()}async disposeAfterLaunchFailure(){this.disposeRuntime(),this.disposeDevtool(),this.disposeRuntimeServer(),this.disposeLauncherWithRuntimeLogs(),await this.closeDevtools()}async closeDevtools(){const t=this.target.devtools.close;t&&await t()}send(t,e){return this.runtimeConnection.send(t,e)}validateProject(t){const e=this.target.devtools.required;return!e||!e.find((e=>!O.default.existsSync(U.default.join(t,e))))}validateDevtools(t){const e=this.target.devtools.validate;return e?e(t,this):Promise.resolve(t)}createDevtools(t,e,n){const s=this.target.devtools.create;return s?(e.timeout=n,s(t,e,this)):Promise.resolve()}shouldCompile(t,e,n,s){this.compiled=!0;const i=this.target.shouldCompile;if(i)this.compiled=i(n,s);else if(!0===n.compile)this.compiled=!0;else{if("false"===process.env.UNI_AUTOMATOR_COMPILE)return!1;this.compiled=!Yt(t,e,this.platform,this.mode)}return this.compiled}async beforeCompile(){this.target.beforeCompile&&await this.target.beforeCompile(U.default.resolve(__dirname,".."),this)}afterCompile(){this.target.afterCompile&&this.target.afterCompile()}get checkProperty(){return"mp-weixin"===this.platform}get devtools(){return this.target.devtools}get mode(){const t=this.target.mode;return t||("production"===process.env.NODE_ENV?"build":"dev")}}const Qt=N.default("automator:compiler"),Zt=/The\s+(.*)\s+directory is ready/;class te{constructor(t){this.puppet=t,this.puppet.setCompiler(this)}async compile(t){const e=this.puppet.mode,n=this.puppet.platform;let s=t.silent;const i=t.port,o=t.host,r=`${e}:${n}`,a=t.projectPath,[c,p]=await this.getSpawnArgs(t,r);p.push("--auto-port"),p.push(z.default(i)),o&&(p.push("--auto-host"),p.push(o));const l={cwd:t.cliPath,env:Object.assign(Object.assign({},process.env),{NODE_ENV:"build"===e?"production":"development"})};return new Promise(((t,i)=>{const o=o=>{const r=o.toString().trim();if(!s&&console.log(r),r.includes("- Network")||r.includes("> Network")||r.includes("➜ Network")){const e=r.match(/Network:(.*)/)[1].trim();Qt(`url: ${e}`),t({path:e})}else if(r.includes("DONE Build failed"))i(r);else if(r.includes("DONE Build complete")){const i=r.match(Zt);let o="";if(i&&i.length>1)o=U.default.join(a,i[1]);else{const t=this.puppet.isX&&"app-plus"===n?"app":n;o=U.default.join(a,`dist/${e}/${t}`),!T.existsSync(o)&&o.endsWith("app-plus")&&(o=o.substring(0,o.length-8)+"app"),T.existsSync(o)||(o=process.env.UNI_OUTPUT_DIR)}this.puppet.afterCompile(),s=!0,this.stop(),t({path:"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW?process.env.UNI_OUTPUT_DIR:o})}};Qt(`${c} ${p.join(" ")} %o`,l),this.cliProcess=k.spawn(c,p,l),this.cliProcess.on("error",(t=>{i(t)})),this.cliProcess.stdout.on("data",o),this.cliProcess.stderr.on("data",o)}))}stop(){this.cliProcess&&this.cliProcess.kill("SIGTERM")}initInputDir(t){const e=U.default.join(t,"src");if(T.existsSync(e)){const t=U.default.join(e,"manifest.json"),n=U.default.join(e,"pages.json");if(T.existsSync(t)&&T.existsSync(n))return void(process.env.UNI_INPUT_DIR=e)}process.env.UNI_INPUT_DIR=t}async getSpawnArgs(t,e){let n;const s=t.cliPath;try{n=require(U.default.join(s,"package.json"))}catch(t){}let i=this.puppet.isX;if(n&&(n.devDependencies&&n.devDependencies["@dcloudio/vite-plugin-uni"]&&(i=!0),!i&&n.dependencies&&n.dependencies["@dcloudio/vite-plugin-uni"]&&(i=!0),n.scripts&&(!n.scripts[e]&&e.endsWith("app-plus")&&(e=e.substring(0,e.length-8)+"app"),n.scripts[e])))return[process.env.UNI_NPM_PATH||(/^win/.test(process.platform)?"npm.cmd":"npm"),["run",e,"--"]];this.puppet.isVue3=i,["android","ios"].includes(process.env.UNI_OS_NAME)&&(process.env.UNI_APP_PLATFORM=process.env.UNI_OS_NAME);let o=this.puppet.platform;if("app-plus"===this.puppet.platform&&this.puppet.isX&&(o="android"===process.env.UNI_APP_PLATFORM?"app-android":"ios"===process.env.UNI_APP_PLATFORM?"app-ios":"app"),this.initInputDir(t.projectPath),process.env.UNI_OUTPUT_DIR=U.default.join(t.projectPath,`${process.env.UNI_AUTOMATOR_CUSTOM_UNPACKAGE_DIR||"unpackage"}/dist/${this.puppet.mode}/${o}`),process.env.UNI_HBUILDERX_PLUGINS||T.existsSync(U.default.resolve(s,"../about"))&&(process.env.UNI_HBUILDERX_PLUGINS=U.default.dirname(s)),await this.puppet.beforeCompile(),i){const t="app-plus"===this.puppet.platform?"app":this.puppet.platform;return process.env.UNI_PLATFORM=t,[process.env.UNI_NODE_PATH||"node",[require.resolve("@dcloudio/vite-plugin-uni/bin/uni.js",{paths:[s]}),"-p",t]]}return[process.env.UNI_NODE_PATH||"node",[U.default.join(s,"bin/uniapp-cli.js")]]}}const ee=N.default("automator:launcher");let ne=24e4;"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM&&(ne=12e4),"true"===process.env.UNI_APP_X_DOM2&&(ne=3e6);class se{async launch(t){const{port:e,cliPath:n,timeout:i,projectPath:o}=await this.validate(t);let r={};"app"===t.platform||"app-plus"===t.platform||"app-harmony"===t.platform?(r=t.app||t["app-plus"],"true"===process.env.UNI_APP_X&&r["uni-app-x"]&&(r=s.recursive(!0,r,r["uni-app-x"])),delete r["uni-app-x"]):r=t[t.platform],r||(r={}),r.projectPath=o,ee(r),this.puppet=new zt(t.platform,r.puppet),r=await this.puppet.validateDevtools(r);let a=this.puppet.shouldCompile(o,e,t,r),c=process.env.UNI_OUTPUT_DIR||o;if(a||this.puppet.validateProject(c)||(c=U.default.join(o,"dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(c)||(c=U.default.join(o,`${process.env.UNI_AUTOMATOR_CUSTOM_UNPACKAGE_DIR||"unpackage"}/dist/${this.puppet.mode}/${this.puppet.platform}`),this.puppet.validateProject(c)||(a=!0))),a){this.puppet.compiled=t.compile=!0,this.compiler=new te(this.puppet);const s=await this.compiler.compile({host:t.host,port:e,cliPath:n,projectPath:o,silent:!!t.silent});s.path&&(c=s.path)}const p=this.createRuntimeConnection(e,i).then((t=>(this.puppet.setRuntimeConnection(t),t)));let l=!1;const u=this.puppet.createDevtools(c,r,i).then((async t=>l?(t&&t.dispose(),void await this.puppet.closeDevtools().catch((()=>{}))):(t&&this.puppet.setDevtoolConnection(t),t)));try{await Promise.all([p,u])}catch(t){throw l=!0,await this.puppet.disposeAfterLaunchFailure(),t}N.default("automator:program")("ready");const h=r.teardown||"disconnect";return new Xt(this.puppet,{teardown:h,port:e})}resolveCliPath(t){if(!t)return t;try{const{dependencies:e,devDependencies:n}=require(U.default.join(t,"package.json"));if(ie(n)||ie(e))return t}catch(t){}}resolveProjectPath(t,e){return t||(t=process.env.UNI_INPUT_DIR||process.cwd()),C.default(t)&&(t=U.default.resolve(t)),O.default.existsSync(t)||function(t){throw Error(t)}(`Project path ${t} doesn't exist`),t}async validate(t){const e=this.resolveProjectPath(t.projectPath,t);let n=process.env.UNI_CLI_PATH||t.cliPath;if(n=this.resolveCliPath(n||""),!n&&(n=this.resolveCliPath(process.cwd())),!n&&(n=this.resolveCliPath(e)),!n)throw Error("cliPath is not provided");if("false"!==process.env.UNI_APP_X){const t=this.getManifestJson(e);("true"===process.env.UNI_APP_X||"uni-app-x"in t)&&(process.env.UNI_APP_X="true",t.appid&&(process.env.UNI_APP_ID=t.appid))}process.env.UNI_AUTOMATOR_HOST&&(t.host=process.env.UNI_AUTOMATOR_HOST),process.env.UNI_AUTOMATOR_PORT&&(t.port=parseInt(process.env.UNI_AUTOMATOR_PORT));return{port:await async function(t,e){const n=await W.default(t||e);if(t&&n!==t)throw Error(`Port ${t} is in use, please specify another port`);return n}(t.port||9520),cliPath:n,timeout:t.timeout||ne,projectPath:e}}getManifestJson(t){if(t){const e=U.default.join(t,"manifest.json");if(O.default.existsSync(e))return i.parse(O.default.readFileSync(e,"utf8"))}return{}}async createRuntimeConnection(t,e){return ct.createRuntimeConnection(t,this.puppet,e)}}function ie(t){return!!t&&!(!t["@dcloudio/vue-cli-plugin-uni"]&&!t["@dcloudio/vite-plugin-uni"])}exports.Automator=class{constructor(){this.launcher=new se}async launch(t){return this.launcher.launch(t)}},exports.initUni=t=>new Proxy({},{get(e,n){return"connectSocket"===n?async(...e)=>{const s=`${Date.now()}-${Math.random()}`;return e[0].id=s,await t.callUniMethod(n,...e).then((n=>{nt(e[0],n),et.set(s,new Map);const i={id:s,onMessage:e=>{t.socketEmitter({id:s,method:"onMessage"}),et.get(s).set("onMessage",e)},send:e=>{t.socketEmitter({id:s,method:"send",data:e.data}).then((t=>{nt(e,t)})).catch((t=>{st(e,t)}))},close:e=>{t.socketEmitter({id:s,method:"close",code:e.code,reason:e.reason}).then((t=>{nt(e,t),et.delete(s)})).catch((t=>{st(e,t)}))},onOpen:e=>{t.socketEmitter({id:s,method:"onOpen"}),et.get(s).set("onOpen",e)},onClose:e=>{t.socketEmitter({id:s,method:"onClose"}),et.get(s).set("onClose",e)},onError:e=>{t.socketEmitter({id:s,method:"onError"}),et.get(s).set("onError",e)}};return et.get(s).set("socketTask",i),i})).catch((t=>(st(e[0],t),null)))}:(s=n,tt.includes(s)?e=>{Z.has(n)||Z.set(n,new Map);const s=Z.get(n),i=`${Date.now()}-${Math.random()}`;s.set(i,e),t.callUniMethod(n,i)}:function(t){return t.startsWith("off")&&tt.includes(t.replace("off","on"))}(n)?async e=>{const s=n.replace("off","on");if(Z.has(s))if(e){const i=Z.get(s);i.forEach(((s,o)=>{s===e&&(i.delete(o),t.callUniMethod(n,o))}))}else Z.delete(s),t.callUniMethod(n)}:async(...e)=>await t.callUniMethod(n,...e).then((t=>(nt(e[0],t),t))).catch((t=>(st(e[0],t),t))));var s}});