/*! *****************************************************************************Copyright (c) Microsoft Corporation.Permission to use, copy, modify, and/or distribute this software for anypurpose with or without fee is hereby granted.THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITHREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITYAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROMLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OROTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE ORPERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */functionct(t,e,n,s){vari,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeofReflect&&"function"==typeofReflect.decorate)r=Reflect.decorate(t,e,n,s);elsefor(vara=t.length-1;a>=0;a--)(i=t[a])&&(r=(o<3?i(r):o>3?i(e,n,r):i(e,n))||r);returno>3&&r&&Object.defineProperty(e,n,r),r}varpt;functionlt(t,e){constn=e.value;returne.value=asyncfunction(e){return(await(null==n?void0:n.call(this,e)))(t)},e}functionut(t,e,n){returnlt(pt.RUNTIME,n)}functionht(t,e,n){returnlt(pt.DEVTOOL,n)}!function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(pt||(pt={}));classdt{constructor(t){this.puppet=t}invoke(t,e){returnasyncn=>this.puppet.devtoolConnection?(n===pt.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}classmtextendsdt{constructor(t,e){super(t),this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId,this.videoId=e.videoId}asyncgetData(t){returnthis.invokeMethod("Element.getData",t)}asyncsetData(t){returnthis.invokeMethod("Element.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Element.callMethod",t)}asyncgetElement(t){returnthis.invokeMethod("Element.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Element.getElements",t)}asyncgetOffset(){returnthis.invokeMethod("Element.getOffset")}asyncgetHTML(t){returnthis.invokeMethod("Element.getHTML",t)}asyncgetAttributes(t){returnthis.invokeMethod("Element.getAttributes",t)}asyncgetStyles(t){returnthis.invokeMethod("Element.getStyles",t)}asyncgetDOMProperties(t){returnthis.invokeMethod("Element.getDOMProperties",t)}asyncgetProperties(t){returnthis.invokeMethod("Element.getProperties",t)}asynctap(){returnthis.invokeMethod("Element.tap")}asynclongpress(){returnthis.invokeMethod("Element.longpress")}asynctouchstart(t){returnthis.invokeMethod("Element.touchstart",t)}asynctouchmove(t){returnthis.invokeMethod("Element.touchmove",t)}asynctouchend(t){returnthis.invokeMethod("Element.touchend",t)}asynctriggerEvent(t){returnthis.invokeMethod("Element.triggerEvent",t)}asynccallFunction(t){returnthis.invokeMethod("Element.callFunction",t)}asynccallContextMethod(t){returnthis.invokeMethod("Element.callContextMethod",t)}invokeMethod(t,e={}){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.invoke(t,e)}}ct([ut],mt.prototype,"getData",null),ct([ut],mt.prototype,"setData",null),ct([ut],mt.prototype,"callMethod",null),ct([ht],mt.prototype,"getElement",null),ct([ht],mt.prototype,"getElements",null),ct([ht],mt.prototype,"getOffset",null),ct([ht],mt.prototype,"getHTML",null),ct([ht],mt.prototype,"getAttributes",null),ct([ht],mt.prototype,"getStyles",null),ct([ht],mt.prototype,"getDOMProperties",null),ct([ht],mt.prototype,"getProperties",null),ct([ht],mt.prototype,"tap",null),ct([ht],mt.prototype,"longpress",null),ct([ht],mt.prototype,"touchstart",null),ct([ht],mt.prototype,"touchmove",null),ct([ht],mt.prototype,"touchend",null),ct([ht],mt.prototype,"triggerEvent",null),ct([ht],mt.prototype,"callFunction",null),ct([ht],mt.prototype,"callContextMethod",null);constgt=Object.prototype.hasOwnProperty,vt=Array.isArray,yt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functionft(t,e){if(vt(t))returnt;if(e&&(n=e,s=t,gt.call(n,s)))return[t];varn,s;consti=[];returnt.replace(yt,(function(t,e,n,s){returni.push(n?s.replace(/\\(\\)?/g,"$1"):e||t),s})),i}functionwt(t,e){constn=ft(e,t);lets;for(s=n.shift();null!=s;){if(null==(t=t[s]))return;s=n.shift()}returnt}constPt=require("util"),It=["scrollLeft","scrollTop","scrollWidth","scrollHeight"];classMt{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,"body"!==this.tagName&&"page-body"!==this.tagName||(this.tagName="page"),this.api=newmt(t,e)}toJSON(){returnJSON.stringify({id:this.id,tagName:this.tagName,pageId:this.pageId,nodeId:this.nodeId,videoId:this.videoId})}toString(){returnthis.toJSON()}[Pt.inspect.custom](){returnthis.toJSON()}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnMt.create(this.puppet,Object.assign({},e,{pageId:this.pageId}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map((t=>Mt.create(this.puppet,Object.assign({},t,{pageId:this.pageId}),this.elementMap)))}asyncsize(){const[t,e]=awaitthis.domProperty(["offsetWidth","offsetHeight"]);return{width:t,height:e}}asyncoffset(){const{left:t,top:e}=awaitthis.api.getOffset();return{left:t,top:e}}asynctext(){returnthis.domProperty("innerText")}asyncattribute(t){if(!L.default(t))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[t]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(t){if(!L.default(t))throwError("name must be a string");if(this.puppet.checkProperty){lete=this.publicProps;if(e||(this.publicProps=e=awaitthis._property("__propPublic")),!e[t])throwError(`${this.tagName}.${t} not exists`)}returnthis.puppet.isX&&"h5"===process.env.UNI_PLATFORM&&It.includes(t)?awaitthis.domProperty(t):this._property(t)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(t){if(!L.default(t))throwError("name must be a string");return(awaitthis.api.getStyles({names:[t]})).styles[0]}asynctap(){returnthis.api.tap()}asynclongpress(){returnthis.nvue||"true"===process.env.UNI_APP_X?this.api.longpress():(awaitthis.touchstart(),awaitz.default(350),this.touchend())}asynctrigger(t,e){constn={type:t};returnY.default(e)||(n.detail=e),this.api.triggerEvent(n)}asynctouchstart(t){returnthis.api.touchstart(t)}asynctouchmove(t){returnthis.api.touchmove(t)}asynctouchend(t){returnthis.api.touchend(t)}asyncdomProperty(t){returnit((asynct=>(awaitthis.api.getDOMProperties({names:t})).properties),t)}_property(t){returnit((asynct=>(awaitthis.api.getProperties({names:t})).properties),t)}send(t,e){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.puppet.send(t,e)}asynccallFunction(t,...e){return(awaitthis.api.callFunction({functionName:t,args:e})).result}staticcreate(t,e,n){lets,i=n.get(e.elementId);if(i)returni;if(e.nodeId)s=_t;elseswitch(e.tagName.toLowerCase()){case"input":s=kt;break;case"textarea":s=Et;break;case"scroll-view":s=Ut;break;case"swiper":s=At;break;case"movable-view":s=Tt;break;case"switch":s=Nt;break;case"slider":s=bt;break;case"video":s=Ct;break;default:s=Mt}returni=news(t,e,n),n.set(e.elementId,i),i}}class_textendsMt{asyncsetData(t){returnthis.api.setData({data:t})}asyncdata(t){conste={};if(t&&(e.path=t),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){constn=(awaitthis.api.getData(e)).data;returnt?wt(n,t):n}return(awaitthis.api.getData(e)).data}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}}classktextendsMt{asyncinput(t){returnthis.callFunction("input.input",t)}}classEtextendsMt{asyncinput(t){returnthis.callFunction("textarea.input",t)}}classUtextendsMt{asyncscrollTo(t,e){returnthis.callFunction("scroll-view.scrollTo",t,e)}asyncproperty(t){return"scrollTop"===t?this.callFunction("scroll-view.scrollTop"):"scrollLeft"===t?this.callFunction("scroll-view.scrollLeft"):super.property(t)}asyncscrollWidth(){returnthis.callFunction("scroll-view.scrollWidth")}asyncscrollHeight(){returnthis.callFunction("scroll-view.scrollHeight")}}classAtextendsMt{asyncswipeTo(t){returnthis.callFunction("swiper.swipeTo",t)}}classTtextendsMt{asyncmoveTo(t,e){returnthis.callFunction("movable-view.moveTo",t,e)}asyncproperty(t){return"x"===t?this._property("_translateX"):"y"===t?this._property("_translateY"):super.property(t)}}classNtextendsMt{asynctap(){returnthis.callFunction("switch.tap")}}classbtextendsMt{asyncslideTo(t){returnthis.callFunction("slider.slideTo",t)}}classCtextendsMt{asynccallContextMethod(t,...e){returnawaitthis.api.callContextMethod({method:t,args:e})}}classRtextendsdt{constructor(t,e){super(t),this.id=e.id}asyncgetData(t){returnthis.invokeMethod("Page.getData",t)}asyncsetData(t){returnthis.invokeMethod("Page.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Page.callMethod",t)}asynccallMethodWithCallback(t){returnthis.invokeMethod("Page.callMethodWithCallback",t)}asyncgetElement(t){returnthis.invokeMethod("Page.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Page.getElements",t)}asyncgetWindowProperties(t){returnthis.invokeMethod("Page.getWindowProperties",t)}invokeMethod(t,e={}){returne.pageId=this.id,this.invoke(t,e)}}ct([ut],Rt.prototype,"getData",null),ct([ut],Rt.prototype,"setData",null),ct([ut],Rt.prototype,"callMethod",null),ct([ut],Rt.prototype,"callMethodWithCallback",null),ct([ht],Rt.prototype,"getElement",null),ct([ht],Rt.prototype,"getElements",null),ct([ht],Rt.prototype,"getWindowProperties",null);constDt=require("util");classOt{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=newMap,this.api=newRt(t,e)}toJSON(){returnJSON.stringify({id:this.id,path:this.path,query:this.query})}toString(){returnthis.toJSON()}[Dt.inspect.custom](){returnthis.toJSON()}asyncwaitFor(t){returnG.default(t)?awaitz.default(t):B.default(t)?x.default(t,0,50):L.default(t)?x.default((async()=>{if("true"===process.env.UNI_APP_X){return!!awaitthis.$(t)}return(awaitthis.$$(t)).length>0}),0,50):void0}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnMt.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map((e=>Mt.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)))}asyncdata(t){conste={};if(t&&(e.path=t),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){constn=(awaitthis.api.getData(e)).data;returnt?wt(n,t):n}return(awaitthis.api.getData(e)).data}asyncsetData(t){returnthis.api.setData({data:t})}asyncsize(){const[t,e]=awaitthis.windowProperty(["document.documentElement.scrollWidth","document.documentElement.scrollHeight"]);return{width:t,height:e}}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}asynccallMethodWithCallback(t,...e){returnawaitthis.api.callMethodWithCallback({method:t,args:e})}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(t){conste=L.default(t);e&&(t=[t]);const{properties:n}=awaitthis.api.getWindowProperties({names:t});returne?n[0]:n}staticcreate(t,e,n){lets=n.get(e.id);returns?(s.path=e.path,s.query=e.query,s):(s=newOt(t,e),n.set(e.id,s),s)}}classStextendsdt{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(t){returnthis.invoke("App.callUniMethod",t)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(t){returnthis.invoke("App.mockUniMethod",t)}asynccaptureScreenshotByRuntime(t){returnthis.invoke("App.captureScreenshot",t)}asynccaptureScreenshotWithDeviceByRuntime(t){returnthis.invoke("App.captureScreenshotWithDevice",t)}asyncsocketEmitter(t){returnthis.invoke("App.socketEmitter",t)}asynccallFunction(t){returnthis.invoke("App.callFunction",t)}asynccaptureScreenshot(t){returnthis.invoke("App.captureScreenshot",t)}asyncadbCommand(t){returnthis.invoke("App.adbCommand",t)}asyncexit(){returnthis.invoke("App.exit")}asyncaddBinding(t){returnthis.invoke("App.addBinding",t)}asyncenableLog(){returnthis.invoke("App.enableLog")}onLogAdded(t){returnthis.on("App.logAdded",t)}onBindingCalled(t){returnthis.on("App.bindingCalled",t)}onExceptionThrown(t){returnthis.on("App.exceptionThrown",t)}}ct([ut],St.prototype,"getPageStack",null),ct([ut],St.prototype,"callUniMethod",null),ct([ut],St.prototype,"getCurrentPage",null),ct([ut],St.prototype,"mockUniMethod",null),ct([ut],St.prototype,"captureScreenshotByRuntime",null),ct([ut],St.prototype,"captureScreenshotWithDeviceByRuntime",null),ct([ut],St.prototype,"socketEmitter",null),ct([ht],St.prototype,"callFunction",null),ct([ht],St.prototype,"captureScreenshot",null),ct([ht],St.prototype,"adbCommand",null),ct([ht],St.prototype,"exit",null),ct([ht],St.prototype,"addBinding",null),ct([ht],St.prototype,"enableLog",null);classjtextendsdt{asyncgetInfo(){returnthis.invoke("Tool.getInfo")}asyncenableRemoteDebug(t){returnthis.invoke("Tool.enableRemoteDebug")}asyncclose(){returnthis.invoke("Tool.close")}asyncgetTestAccounts(){returnthis.invoke("Tool.getTestAccounts")}onRemoteDebugConnected(t){this.puppet.once("Tool.onRemoteDebugConnected",t),this.puppet.once("Tool.onPreviewConnected",t)}}functionxt(t){returnnewPromise((e=>setTimeout(e,t)))}ct([ht],jt.prototype,"getInfo",null),ct([ht],jt.prototype,"enableRemoteDebug",null),ct([ht],jt.prototype,"close",null),ct([ht],jt.prototype,"getTestAccounts",null);class$textendsa.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newSt(t),this.toolApi=newjt(t),this.appApi.onLogAdded((t=>{this.emit("console",t)})),this.appApi.onBindingCalled((({name:t,args:e})=>{try{constn=this.appBindings.get(t);n&&n(...e)}catch(t){}})),this.appApi.onExceptionThrown((t=>{this.emit("exception",t)}))}asyncpageStack(){return(awaitthis.appApi.getPageStack()).pageStack.map((t=>Ot.create(this.puppet,t,this.pageMap)))}asyncnavigateTo(t){returnthis.changeRoute("navigateTo",t)}asyncredirectTo(t){returnthis.changeRoute("redirectTo",t)}asyncnavigateBack(){returnthis.changeRoute("navigateBack")}asyncreLaunch(t){returnthis.changeRoute("reLaunch",t)}asyncswitchTab(t){returnthis.changeRoute("switchTab",t)}asynccurrentPage(){const{id:t,path:e,query:n}=awaitthis.appApi.getCurrentPage();returnOt.create(this.puppet,{id:t,path:e,query:n},this.pageMap)}asyncsystemInfo(){returnthis.callUniMethod("getSystemInfoSync")}asynccallUniMethod(t,...e){return(awaitthis.appApi.callUniMethod({method:t,args:e})).result}asyncmockUniMethod(t,e,...n){returnB.default(e)||(s=e,L.default(s)&&(s=J.default(s),V.default(s,"function")||V.default(s,"() =>")))?this.appApi.mockUniMethod({method:t,functionDeclaration:e.toString(),args:n}):this.appApi.mockUniMethod({method:t,result:e});vars}asyncrestoreUniMethod(t){returnthis.appApi.mockUniMethod({method:t})}asyncevaluate(t,...e){return(awaitthis.appApi.callFunction({functionDeclaration:t.toString(),args:e})).result}asyncpageScrollTo(t){awaitthis.callUniMethod("pageScrollTo",{scrollTop:t,duration:0})}asyncclose(){try{awaitthis.appApi.exit()}catch(t){}awaitxt(1e3),this.puppet.disposeRuntimeServer(),awaitthis.toolApi.close(),this.disconnect()}asyncteardown(){returnthis["disconnect"===this.options.teardown?"disconnect":"close"]()}asyncremote(t){if(!this.puppet.devtools.remote)returnconsole.warn(`Failed to enable remote, ${this.puppet.devtools.name} is unimplemented`);const{qrCode:e}=awaitthis.toolApi.enableRemoteDebug({auto:t});varn;e&&await(n=e,newPromise((t=>{W.default.generate(n,{small:!0},(e=>{process.stdout.write(e),t(void0)}))})));consts=newPromise((t=>{this.toolApi.onRemoteDebugConnected((async()=>{awaitxt(1e3),t(void0)}))})),i=newPromise((t=>{this.puppet.setRemoteRuntimeConnectionCallback((()=>{t(void0)}))}));returnPromise.all([s,i])}disconnect(){this.puppet.dispose()}on(t,e){return"console"===t&&this.appApi.enableLog(),super.on(t,e),this}asyncexposeFunction(t,e){if(this.appBindings.has(t))throwError(`Failed to expose function with name ${t}: already exists!`);this.appBindings.set(t,e),awaitthis.appApi.addBinding({name:t})}asynccheckVersion(){}asyncscreenshot(t){conste=this.puppet.isX&&"app-plus"===this.puppet.platform?(null==t?void0:t.deviceShot)?"captureScreenshotWithDeviceByRuntime":"captureScreenshotByRuntime":"captureScreenshot",{data:n}=awaitthis.appApi[e]({id:null==t?void0:t.id,fullPage:null==t?void0:t.fullPage,area:null==t?void0:t.area,offsetX:null==t?void0:t.offsetX,offsetY:null==t?void0:t.offsetY});if(!(null==t?void0:t.path))returnn;awaitX.default.writeFile(t.path,n,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(t,e){if(this.puppet.isVue3&&"h5"===process.env.UNI_PLATFORM&&"navigateBack"!==t){const{__id__:n}=awaitthis.callUniMethod(t,{url:e,isAutomatedTesting:!0}),s=Date.now();returnawaitx.default((async()=>{if(Date.now()-s>1e4)throwError(`${t} to ${e} failed, unable to get the correct current page`);leti;try{i=awaitthis.currentPage()}catch(t){return!1}returni.id===n&&i}),0,1e3)}returnawaitthis.callUniMethod(t,{url:e}),awaitxt(1e3),awaitthis.currentPage()}asyncsocketEmitter(t){returnthis.appApi.socketEmitter(t)}asyncadbCommand(t){return"android"===process.env.UNI_APP_PLATFORM?awaitthis.appApi.adbCommand(t):Error("Program.adbCommand is only supported on the app android platform")}}classqt{constructor(t){this.options=t}has(t){return!!this.options[t]}send(t,e,n){consts=this.options[e];if(!s)returnPromise.reject(Error(`adapter for ${e} not found`));consti=s.reflect;returni?(s.params&&(n=s.params(n)),"function"==typeofi?i(t.send.bind(t),n):(e=i,t.send(e,n))):Promise.reject(Error(`${e}'s reflect is required`))}}constFt=C.default("automator:puppet"),Lt=".automator.json";functionHt(t){try{returnrequire(t)}catch(t){}}functionWt(t,e,n,s){consti=function(t,e,n){lets,i;returnprocess.env.UNI_OUTPUT_DIR?(i=b.default.join(process.env.UNI_OUTPUT_DIR,`../.automator/${e}`,Lt),s=Ht(i)):(i=b.default.join(t,`dist/${n}/.automator/${e}`,Lt),s=Ht(i),s||(i=b.default.join(t,`unpackage/dist/${n}/.automator/${e}`,Lt),s=Ht(i))),Ft(`${i}=>${JSON.stringify(s)}`),s}(t,n,s);if(!i||!i.wsEndpoint)return!1;consto=require("../package.json").version;if(i.version!==o)returnFt(`unmet=>${i.version}!==${o}`),!1;constr=function(t){lete;try{constt=F.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=void0))}catch(t){}return"ws://"+(e||"localhost")+":"+t}(e);returnFt(`wsEndpoint=>${r}`),i.wsEndpoint===r}classXtextendsa.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{this.target=ot("@dcloudio/uni-h5/lib/h5/uni.automator.js")}catch(t){}this.target||(this.target=ot(`@dcloudio/uni-${"app"===t?"app-plus":t}/lib/uni.automator.js`))}if(!this.target)throwError("puppet is not provided");this.platform=t,this.adapter=newqt(this.target.adapter||{})}setCompiler(t){this.compiler=t}setRuntimeServer(t){this.wss=t}setRemoteRuntimeConnectionCallback(t){this.remoteRuntimeConnectionCallback=t}setRuntimeConnection(t){this.runtimeConnection=t,this.remoteRuntimeConnectionCallback&&(this.remoteRuntimeConnectionCallback(),this.remoteRuntimeConnectionCallback=null)}setDevtoolConnection(t){this.devtoolConnection=t}disposeRuntimeServer(){this.wss&&this.wss.close()}disposeRuntime(){this.runtimeConnection.dispose()}disposeDevtool(){this.compiler&&this.compiler.stop(),this.devtoolConnection&&this.devtoolConnection.dispose()}dispose(){this.disposeRuntime(),this.disposeDevtool(),this.disposeRuntimeServer()}send(t,e){returnthis.runtimeConnection.send(t,e)}validateProject(t){conste=this.target.devtools.required;return!e||!e.find((e=>!N.default.existsSync(b.default.join(t,e))))}validateDevtools(t){conste=this.target.devtools.validate;returne?e(t,this):Promise.resolve(t)}createDevtools(t,e,n){consts=this.target.devtools.create;returns?(e.timeout=n,s(t,e,this)):Promise.resolve()}shouldCompile(t,e,n,s){this.compiled=!0;consti=this.target.shouldCompile;if(i)this.compiled=i(n,s);elseif(!0===n.compile)this.compiled=!0;else{if("false"===process.env.UNI_AUTOMATOR_COMPILE)return!1;this.compiled=!Wt(t,e,this.platform,this.mode)}returnthis.compiled}getcheckProperty(){return"mp-weixin"===this.platform}getdevtools(){returnthis.target.devtools}getmode(){constt=this.target.mode;returnt||("production"===process.env.NODE_ENV?"build":"dev")}}constBt=C.default("automator:compiler"),Jt=/The\s+(.*)\s+directory is ready/;classVt{constructor(t){this.puppet=t,this.puppet.setCompiler(this)}compile(t){conste=this.puppet.mode,n=this.puppet.platform;lets=t.silent;consti=t.port,o=t.host,r=`${e}:${n}`,a=t.projectPath,[c,p]=this.getSpawnArgs(t,r);p.push("--auto-port"),p.push(K.default(i)),o&&(p.push("--auto-host"),p.push(o));constl={cwd:t.cliPath,env:Object.assign(Object.assign({},process.env),{NODE_ENV:"build"===e?"production":"development"})};returnnewPromise(((t,i)=>{consto=o=>{constr=o.toString().trim();if(!s&&console.log(r),r.includes("- Network")||r.includes("> Network")||r.includes("➜ Network")){conste=r.match(/Network:(.*)/)[1].trim();Bt(`url: ${e}`),t({path:e})}elseif(r.includes("DONE Build failed"))i(r);elseif(r.includes("DONE Build complete")){consti=r.match(Jt);leto="";if(i&&i.length>1)o=b.default.join(a,i[1]);else{constt=this.puppet.isX&&"app-plus"===n?"app":n;o=b.default.join(a,`dist/${e}/${t}`),A.existsSync(o)||(o=b.default.join(a,`unpackage/dist/${e}/${t}`))}s=!0,this.stop(),t({path:"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW?process.env.UNI_OUTPUT_DIR:o})}};Bt(`${c}${p.join("")} %o`,l),this.cliProcess=E.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")}getSpawnArgs(t,e){letn;consts=t.cliPath;try{n=require(b.default.join(s,"package.json"))}catch(t){}leti=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]))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);leto=this.puppet.platform;if("app-plus"===this.puppet.platform&&this.puppet.isX&&(o="app"),process.env.UNI_INPUT_DIR=t.projectPath,process.env.UNI_OUTPUT_DIR=b.default.join(t.projectPath,`unpackage/dist/${this.puppet.mode}/${o}`),this.prepare(),process.env.UNI_HBUILDERX_PLUGINS||A.existsSync(b.default.resolve(s,"../about"))&&(process.env.UNI_HBUILDERX_PLUGINS=b.default.dirname(s)),i){constt="app-plus"===this.puppet.platform?"app":this.puppet.platform;returnprocess.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",[b.default.join(s,"bin/uniapp-cli.js")]]}prepare(){if(process.env.UNI_INPUT_DIR&&"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW){constt=i.parse(A.readFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8")),e=b.default.resolve(process.env.UNI_INPUT_DIR,"unpackage",".automator","app-webview");process.env.UNI_INPUT_DIR=b.default.resolve(e,"src"),process.env.UNI_OUTPUT_DIR=b.default.resolve(e,"unpackage","dist","dev"),A.existsSync(process.env.UNI_INPUT_DIR)&&A.emptyDirSync(process.env.UNI_INPUT_DIR),A.copySync(b.default.resolve(__dirname,"..","lib","app-webview","project"),process.env.UNI_INPUT_DIR);constn=i.parse(A.readFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8"));A.writeFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),JSON.stringify(Object.assign(Object.assign({},n),{name:t.name||"",appid:t.appid||""}),null,2))}}}constGt=C.default("automator:launcher"),zt="true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM?12e4:24e4;classYt{asynclaunch(t){const{port:e,cliPath:n,timeout:i,projectPath:o}=awaitthis.validate(t);letr={};"app"===t.platform||"app-plus"===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"])),deleter["uni-app-x"]):r=t[t.platform],r||(r={}),r.projectPath=o,Gt(r),this.puppet=newXt(t.platform,r.puppet),r=awaitthis.puppet.validateDevtools(r);leta=this.puppet.shouldCompile(o,e,t,r),c=process.env.UNI_OUTPUT_DIR||o;if(a||this.puppet.validateProject(c)||(c=b.default.join(o,"dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(c)||(c=b.default.join(o,"unpackage/dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(c)||(a=!0))),a){this.puppet.compiled=t.compile=!0,this.compiler=newVt(this.puppet);consts=awaitthis.compiler.compile({host:t.host,port:e,cliPath:n,projectPath:o,silent:!!t.silent});s.path&&(c=s.path)}constp=[];returnp.push(this.createRuntimeConnection(e,i)),p.push(this.puppet.createDevtools(c,r,i)),newPromise(((t,n)=>{Promise.all(p).then((([n,s])=>{n&&this.puppet.setRuntimeConnection(n),s&&this.puppet.setDevtoolConnection(s),C.default("automator:program")("ready");consti=r.teardown||"disconnect";t(new$t(this.puppet,{teardown:i,port:e}))})).catch((t=>n(t)))}))}resolveCliPath(t){if(!t)returnt;try{const{dependencies:e,devDependencies:n}=require(b.default.join(t,"package.json"));if(Kt(n)||Kt(e))returnt}catch(t){}}resolveProjectPath(t,e){returnt||(t=process.env.UNI_INPUT_DIR||process.cwd()),R.default(t)&&(t=b.default.resolve(t)),N.default.existsSync(t)||function(t){throwError(t)}(`Project path ${t} doesn't exist`),t}asyncvalidate(t){conste=this.resolveProjectPath(t.projectPath,t);letn=process.env.UNI_CLI_PATH||t.cliPath;if(n=this.resolveCliPath(n||""),!n&&(n=this.resolveCliPath(process.cwd())),!n&&(n=this.resolveCliPath(e)),!n)throwError("cliPath is not provided");if("false"!==process.env.UNI_APP_X){constt=this.getManifestJson(e);("true"===process.env.UNI_APP_X||"uni-app-x"int)&&(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:awaitasyncfunction(t,e){constn=awaitH.default(t||e);if(t&&n!==t)throwError(`Port ${t} is in use, please specify another port`);returnn}(t.port||9520),cliPath:n,timeout:t.timeout||zt,projectPath:e}}getManifestJson(t){if(t){conste=b.default.join(t,"manifest.json");if(N.default.existsSync(e))returni.parse(N.default.readFileSync(e,"utf8"))}return{}}asynccreateRuntimeConnection(t,e){returnat.createRuntimeConnection(t,this.puppet,e)}}functionKt(t){return!!t&&!(!t["@dcloudio/vue-cli-plugin-uni"]&&!t["@dcloudio/vite-plugin-uni"])}exports.Automator=class{constructor(){this.launcher=newYt}asynclaunch(t){returnthis.launcher.launch(t)}},exports.initUni=t=>newProxy({},{get(e,n){return"connectSocket"===n?async(...e)=>{consts=`${Date.now()}-${Math.random()}`;returne[0].id=s,awaitt.callUniMethod(n,...e).then((n=>{nt(e[0],n),et.set(s,newMap);consti={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)}};returnet.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,newMap);consts=Z.get(n),i=`${Date.now()}-${Math.random()}`;s.set(i,e),t.callUniMethod(n,i)}:function(t){returnt.startsWith("off")&&tt.includes(t.replace("off","on"))}(n)?asynce=>{consts=n.replace("off","on");if(Z.has(s))if(e){consti=Z.get(s);i.forEach(((s,o)=>{s===e&&(i.delete(o),t.callUniMethod(n,o))}))}elseZ.delete(s),t.callUniMethod(n)}:async(...e)=>awaitt.callUniMethod(n,...e).then((t=>(nt(e[0],t),t))).catch((t=>(st(e[0],t),t))));vars}});