/*! *****************************************************************************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.
***************************************************************************** */functionce(e,t,n,s){vari,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,n):s;if("object"==typeofReflect&&"function"==typeofReflect.decorate)r=Reflect.decorate(e,t,n,s);elsefor(vara=e.length-1;a>=0;a--)(i=e[a])&&(r=(o<3?i(r):o>3?i(t,n,r):i(t,n))||r);returno>3&&r&&Object.defineProperty(t,n,r),r}varpe;functionle(e,t){constn=t.value;returnt.value=asyncfunction(t){return(await(null==n?void0:n.call(this,t)))(e)},t}functionue(e,t,n){returnle(pe.RUNTIME,n)}functionhe(e,t,n){returnle(pe.DEVTOOL,n)}!function(e){e.RUNTIME="runtime",e.DEVTOOL="devtool"}(pe||(pe={}));classde{constructor(e){this.puppet=e}invoke(e,t){returnasyncn=>this.puppet.devtoolConnection?(n===pe.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(e,t):this.puppet.runtimeConnection.send(e,t)}on(e,t){this.puppet.on(e,t)}}classmeextendsde{constructor(e,t){super(e),this.id=t.elementId,this.pageId=t.pageId,this.nodeId=t.nodeId,this.videoId=t.videoId}asyncgetData(e){returnthis.invokeMethod("Element.getData",e)}asyncsetData(e){returnthis.invokeMethod("Element.setData",e)}asynccallMethod(e){returnthis.invokeMethod("Element.callMethod",e)}asyncgetElement(e){returnthis.invokeMethod("Element.getElement",e)}asyncgetElements(e){returnthis.invokeMethod("Element.getElements",e)}asyncgetOffset(){returnthis.invokeMethod("Element.getOffset")}asyncgetHTML(e){returnthis.invokeMethod("Element.getHTML",e)}asyncgetAttributes(e){returnthis.invokeMethod("Element.getAttributes",e)}asyncgetStyles(e){returnthis.invokeMethod("Element.getStyles",e)}asyncgetDOMProperties(e){returnthis.invokeMethod("Element.getDOMProperties",e)}asyncgetProperties(e){returnthis.invokeMethod("Element.getProperties",e)}asynctap(){returnthis.invokeMethod("Element.tap")}asynclongpress(){returnthis.invokeMethod("Element.longpress")}asynctouchstart(e){returnthis.invokeMethod("Element.touchstart",e)}asynctouchmove(e){returnthis.invokeMethod("Element.touchmove",e)}asynctouchend(e){returnthis.invokeMethod("Element.touchend",e)}asynctriggerEvent(e){returnthis.invokeMethod("Element.triggerEvent",e)}asynccallFunction(e){returnthis.invokeMethod("Element.callFunction",e)}asynccallContextMethod(e){returnthis.invokeMethod("Element.callContextMethod",e)}invokeMethod(e,t={}){returnt.elementId=this.id,t.pageId=this.pageId,this.nodeId&&(t.nodeId=this.nodeId),this.videoId&&(t.videoId=this.videoId),this.invoke(e,t)}}ce([ue],me.prototype,"getData",null),ce([ue],me.prototype,"setData",null),ce([ue],me.prototype,"callMethod",null),ce([he],me.prototype,"getElement",null),ce([he],me.prototype,"getElements",null),ce([he],me.prototype,"getOffset",null),ce([he],me.prototype,"getHTML",null),ce([he],me.prototype,"getAttributes",null),ce([he],me.prototype,"getStyles",null),ce([he],me.prototype,"getDOMProperties",null),ce([he],me.prototype,"getProperties",null),ce([he],me.prototype,"tap",null),ce([he],me.prototype,"longpress",null),ce([he],me.prototype,"touchstart",null),ce([he],me.prototype,"touchmove",null),ce([he],me.prototype,"touchend",null),ce([he],me.prototype,"triggerEvent",null),ce([he],me.prototype,"callFunction",null),ce([he],me.prototype,"callContextMethod",null);constge=Object.prototype.hasOwnProperty,ve=Array.isArray,ye=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functionfe(e,t){if(ve(e))returne;if(t&&(n=t,s=e,ge.call(n,s)))return[e];varn,s;consti=[];returne.replace(ye,(function(e,t,n,s){returni.push(n?s.replace(/\\(\\)?/g,"$1"):t||e),s})),i}functionwe(e,t){constn=fe(t,e);lets;for(s=n.shift();null!=s;){if(null==(e=e[s]))return;s=n.shift()}returne}constPe=require("util"),Ie=["scrollLeft","scrollTop","scrollWidth","scrollHeight"];classMe{constructor(e,t,n){this.puppet=e,this.id=t.elementId,this.pageId=t.pageId,this.nodeId=t.nodeId||null,this.videoId=t.videoId||null,this.tagName=t.tagName,this.nvue=t.nvue,this.elementMap=n,"body"!==this.tagName&&"page-body"!==this.tagName||(this.tagName="page"),this.api=newme(e,t)}toJSON(){returnJSON.stringify({id:this.id,tagName:this.tagName,pageId:this.pageId,nodeId:this.nodeId,videoId:this.videoId})}toString(){returnthis.toJSON()}[Pe.inspect.custom](){returnthis.toJSON()}async$(e){try{constt=awaitthis.api.getElement({selector:e});returnMe.create(this.puppet,Object.assign({},t,{pageId:this.pageId}),this.elementMap)}catch(e){returnnull}}async$$(e){const{elements:t}=awaitthis.api.getElements({selector:e});returnt.map((e=>Me.create(this.puppet,Object.assign({},e,{pageId:this.pageId}),this.elementMap)))}asyncsize(){const[e,t]=awaitthis.domProperty(["offsetWidth","offsetHeight"]);return{width:e,height:t}}asyncoffset(){const{left:e,top:t}=awaitthis.api.getOffset();return{left:e,top:t}}asynctext(){returnthis.domProperty("innerText")}asyncattribute(e){if(!L.default(e))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[e]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(e){if(!L.default(e))throwError("name must be a string");if(this.puppet.checkProperty){lett=this.publicProps;if(t||(this.publicProps=t=awaitthis._property("__propPublic")),!t[e])throwError(`${this.tagName}.${e} not exists`)}returnthis.puppet.isX&&"h5"===process.env.UNI_PLATFORM&&Ie.includes(e)?awaitthis.domProperty(e):this._property(e)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(e){if(!L.default(e))throwError("name must be a string");return(awaitthis.api.getStyles({names:[e]})).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(e,t){constn={type:e};returnY.default(t)||(n.detail=t),this.api.triggerEvent(n)}asynctouchstart(e){returnthis.api.touchstart(e)}asynctouchmove(e){returnthis.api.touchmove(e)}asynctouchend(e){returnthis.api.touchend(e)}asyncdomProperty(e){returnie((asynce=>(awaitthis.api.getDOMProperties({names:e})).properties),e)}_property(e){returnie((asynce=>(awaitthis.api.getProperties({names:e})).properties),e)}send(e,t){returnt.elementId=this.id,t.pageId=this.pageId,this.nodeId&&(t.nodeId=this.nodeId),this.videoId&&(t.videoId=this.videoId),this.puppet.send(e,t)}asynccallFunction(e,...t){return(awaitthis.api.callFunction({functionName:e,args:t})).result}staticcreate(e,t,n){lets,i=n.get(t.elementId);if(i)returni;if(t.nodeId)s=_e;elseswitch(t.tagName.toLowerCase()){case"input":s=ke;break;case"textarea":s=Ee;break;case"scroll-view":s=Ae;break;case"swiper":s=Ue;break;case"movable-view":s=Te;break;case"switch":s=Ne;break;case"slider":s=be;break;case"video":s=Ce;break;default:s=Me}returni=news(e,t,n),n.set(t.elementId,i),i}}class_eextendsMe{asyncsetData(e){returnthis.api.setData({data:e})}asyncdata(e){constt={};if(e&&(t.path=e),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM&&"true"!==process.env.UNI_AUTOMATOR_APP_WEBVIEW){constn=(awaitthis.api.getData(t)).data;returne?we(n,e):n}return(awaitthis.api.getData(t)).data}asynccallMethod(e,...t){return(awaitthis.api.callMethod({method:e,args:t})).result}}classkeextendsMe{asyncinput(e){returnthis.callFunction("input.input",e)}}classEeextendsMe{asyncinput(e){returnthis.callFunction("textarea.input",e)}}classAeextendsMe{asyncscrollTo(e,t){returnthis.callFunction("scroll-view.scrollTo",e,t)}asyncproperty(e){return"scrollTop"===e?this.callFunction("scroll-view.scrollTop"):"scrollLeft"===e?this.callFunction("scroll-view.scrollLeft"):super.property(e)}asyncscrollWidth(){returnthis.callFunction("scroll-view.scrollWidth")}asyncscrollHeight(){returnthis.callFunction("scroll-view.scrollHeight")}}classUeextendsMe{asyncswipeTo(e){returnthis.callFunction("swiper.swipeTo",e)}}classTeextendsMe{asyncmoveTo(e,t){returnthis.callFunction("movable-view.moveTo",e,t)}asyncproperty(e){return"x"===e?this._property("_translateX"):"y"===e?this._property("_translateY"):super.property(e)}}classNeextendsMe{asynctap(){returnthis.callFunction("switch.tap")}}classbeextendsMe{asyncslideTo(e){returnthis.callFunction("slider.slideTo",e)}}classCeextendsMe{asynccallContextMethod(e,...t){returnawaitthis.api.callContextMethod({method:e,args:t})}}classReextendsde{constructor(e,t){super(e),this.id=t.id}asyncgetData(e){returnthis.invokeMethod("Page.getData",e)}asyncsetData(e){returnthis.invokeMethod("Page.setData",e)}asynccallMethod(e){returnthis.invokeMethod("Page.callMethod",e)}asynccallMethodWithCallback(e){returnthis.invokeMethod("Page.callMethodWithCallback",e)}asyncgetElement(e){returnthis.invokeMethod("Page.getElement",e)}asyncgetElements(e){returnthis.invokeMethod("Page.getElements",e)}asyncgetWindowProperties(e){returnthis.invokeMethod("Page.getWindowProperties",e)}invokeMethod(e,t={}){returnt.pageId=this.id,this.invoke(e,t)}}ce([ue],Re.prototype,"getData",null),ce([ue],Re.prototype,"setData",null),ce([ue],Re.prototype,"callMethod",null),ce([ue],Re.prototype,"callMethodWithCallback",null),ce([he],Re.prototype,"getElement",null),ce([he],Re.prototype,"getElements",null),ce([he],Re.prototype,"getWindowProperties",null);constOe=require("util");classDe{constructor(e,t){this.puppet=e,this.id=t.id,this.path=t.path,this.query=t.query,this.elementMap=newMap,this.api=newRe(e,t)}toJSON(){returnJSON.stringify({id:this.id,path:this.path,query:this.query})}toString(){returnthis.toJSON()}[Oe.inspect.custom](){returnthis.toJSON()}asyncwaitFor(e){returnG.default(e)?awaitz.default(e):B.default(e)?x.default(e,0,50):L.default(e)?x.default((async()=>{if("true"===process.env.UNI_APP_X){return!!awaitthis.$(e)}return(awaitthis.$$(e)).length>0}),0,50):void0}async$(e){try{constt=awaitthis.api.getElement({selector:e});returnMe.create(this.puppet,Object.assign({selector:e},t,{pageId:this.id}),this.elementMap)}catch(e){returnnull}}async$$(e){const{elements:t}=awaitthis.api.getElements({selector:e});returnt.map((t=>Me.create(this.puppet,Object.assign({selector:e},t,{pageId:this.id}),this.elementMap)))}asyncdata(e){constt={};if(e&&(t.path=e),"true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM&&"true"!==process.env.UNI_AUTOMATOR_APP_WEBVIEW){constn=(awaitthis.api.getData(t)).data;returne?we(n,e):n}return(awaitthis.api.getData(t)).data}asyncsetData(e){returnthis.api.setData({data:e})}asyncsize(){const[e,t]=awaitthis.windowProperty(["document.documentElement.scrollWidth","document.documentElement.scrollHeight"]);return{width:e,height:t}}asynccallMethod(e,...t){return(awaitthis.api.callMethod({method:e,args:t})).result}asynccallMethodWithCallback(e,...t){returnawaitthis.api.callMethodWithCallback({method:e,args:t})}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(e){constt=L.default(e);t&&(e=[e]);const{properties:n}=awaitthis.api.getWindowProperties({names:e});returnt?n[0]:n}staticcreate(e,t,n){lets=n.get(t.id);returns?(s.path=t.path,s.query=t.query,s):(s=newDe(e,t),n.set(t.id,s),s)}}classSeextendsde{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(e){returnthis.invoke("App.callUniMethod",e)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(e){returnthis.invoke("App.mockUniMethod",e)}asynccaptureScreenshotByRuntime(e){returnthis.invoke("App.captureScreenshot",e)}asynccaptureScreenshotWithDeviceByRuntime(e){returnthis.invoke("App.captureScreenshotWithDevice",e)}asyncsocketEmitter(e){returnthis.invoke("App.socketEmitter",e)}asynccallFunction(e){returnthis.invoke("App.callFunction",e)}asynccaptureScreenshot(e){returnthis.invoke("App.captureScreenshot",e)}asyncadbCommand(e){returnthis.invoke("App.adbCommand",e)}asyncexit(){returnthis.invoke("App.exit")}asyncaddBinding(e){returnthis.invoke("App.addBinding",e)}asyncenableLog(){returnthis.invoke("App.enableLog")}onLogAdded(e){returnthis.on("App.logAdded",e)}onBindingCalled(e){returnthis.on("App.bindingCalled",e)}onExceptionThrown(e){returnthis.on("App.exceptionThrown",e)}}ce([ue],Se.prototype,"getPageStack",null),ce([ue],Se.prototype,"callUniMethod",null),ce([ue],Se.prototype,"getCurrentPage",null),ce([ue],Se.prototype,"mockUniMethod",null),ce([ue],Se.prototype,"captureScreenshotByRuntime",null),ce([ue],Se.prototype,"captureScreenshotWithDeviceByRuntime",null),ce([ue],Se.prototype,"socketEmitter",null),ce([he],Se.prototype,"callFunction",null),ce([he],Se.prototype,"captureScreenshot",null),ce([he],Se.prototype,"adbCommand",null),ce([he],Se.prototype,"exit",null),ce([he],Se.prototype,"addBinding",null),ce([he],Se.prototype,"enableLog",null);classjeextendsde{asyncgetInfo(){returnthis.invoke("Tool.getInfo")}asyncenableRemoteDebug(e){returnthis.invoke("Tool.enableRemoteDebug")}asyncclose(){returnthis.invoke("Tool.close")}asyncgetTestAccounts(){returnthis.invoke("Tool.getTestAccounts")}onRemoteDebugConnected(e){this.puppet.once("Tool.onRemoteDebugConnected",e),this.puppet.once("Tool.onPreviewConnected",e)}}functionxe(e){returnnewPromise((t=>setTimeout(t,e)))}ce([he],je.prototype,"getInfo",null),ce([he],je.prototype,"enableRemoteDebug",null),ce([he],je.prototype,"close",null),ce([he],je.prototype,"getTestAccounts",null);class$eextendsa.EventEmitter{constructor(e,t){super(),this.puppet=e,this.options=t,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newSe(e),this.toolApi=newje(e),this.appApi.onLogAdded((e=>{this.emit("console",e)})),this.appApi.onBindingCalled((({name:e,args:t})=>{try{constn=this.appBindings.get(e);n&&n(...t)}catch(e){}})),this.appApi.onExceptionThrown((e=>{this.emit("exception",e)}))}asyncpageStack(){return(awaitthis.appApi.getPageStack()).pageStack.map((e=>De.create(this.puppet,e,this.pageMap)))}asyncnavigateTo(e){returnthis.changeRoute("navigateTo",e)}asyncredirectTo(e){returnthis.changeRoute("redirectTo",e)}asyncnavigateBack(){returnthis.changeRoute("navigateBack")}asyncreLaunch(e){returnthis.changeRoute("reLaunch",e)}asyncswitchTab(e){returnthis.changeRoute("switchTab",e)}asynccurrentPage(){const{id:e,path:t,query:n}=awaitthis.appApi.getCurrentPage();returnDe.create(this.puppet,{id:e,path:t,query:n},this.pageMap)}asyncsystemInfo(){returnthis.callUniMethod("getSystemInfoSync")}asynccallUniMethod(e,...t){return(awaitthis.appApi.callUniMethod({method:e,args:t})).result}asyncmockUniMethod(e,t,...n){returnB.default(t)||(s=t,L.default(s)&&(s=V.default(s),J.default(s,"function")||J.default(s,"() =>")))?this.appApi.mockUniMethod({method:e,functionDeclaration:t.toString(),args:n}):this.appApi.mockUniMethod({method:e,result:t});vars}asyncrestoreUniMethod(e){returnthis.appApi.mockUniMethod({method:e})}asyncevaluate(e,...t){return(awaitthis.appApi.callFunction({functionDeclaration:e.toString(),args:t})).result}asyncpageScrollTo(e){awaitthis.callUniMethod("pageScrollTo",{scrollTop:e,duration:0})}asyncclose(){try{awaitthis.appApi.exit()}catch(e){}awaitxe(1e3),this.puppet.disposeRuntimeServer(),awaitthis.toolApi.close(),this.disconnect()}asyncteardown(){returnthis["disconnect"===this.options.teardown?"disconnect":"close"]()}asyncremote(e){if(!this.puppet.devtools.remote)returnconsole.warn(`Failed to enable remote, ${this.puppet.devtools.name} is unimplemented`);const{qrCode:t}=awaitthis.toolApi.enableRemoteDebug({auto:e});varn;t&&await(n=t,newPromise((e=>{W.default.generate(n,{small:!0},(t=>{process.stdout.write(t),e(void0)}))})));consts=newPromise((e=>{this.toolApi.onRemoteDebugConnected((async()=>{awaitxe(1e3),e(void0)}))})),i=newPromise((e=>{this.puppet.setRemoteRuntimeConnectionCallback((()=>{e(void0)}))}));returnPromise.all([s,i])}disconnect(){this.puppet.dispose()}on(e,t){return"console"===e&&this.appApi.enableLog(),super.on(e,t),this}asyncexposeFunction(e,t){if(this.appBindings.has(e))throwError(`Failed to expose function with name ${e}: already exists!`);this.appBindings.set(e,t),awaitthis.appApi.addBinding({name:e})}asynccheckVersion(){}asyncscreenshot(e){constt=this.puppet.isX&&"app-plus"===this.puppet.platform?(null==e?void0:e.deviceShot)?"captureScreenshotWithDeviceByRuntime":"captureScreenshotByRuntime":"captureScreenshot",{data:n}=awaitthis.appApi[t]({id:null==e?void0:e.id,fullPage:null==e?void0:e.fullPage,area:null==e?void0:e.area,offsetX:null==e?void0:e.offsetX,offsetY:null==e?void0:e.offsetY});if(!(null==e?void0:e.path))returnn;awaitX.default.writeFile(e.path,n,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(e,t){if(this.puppet.isVue3&&"h5"===process.env.UNI_PLATFORM&&"navigateBack"!==e){const{__id__:n}=awaitthis.callUniMethod(e,{url:t,isAutomatedTesting:!0}),s=Date.now();returnawaitx.default((async()=>{if(Date.now()-s>1e4)throwError(`${e} to ${t} failed, unable to get the correct current page`);leti;try{i=awaitthis.currentPage()}catch(e){return!1}returni.id===n&&i}),0,1e3)}returnawaitthis.callUniMethod(e,{url:t}),awaitxe(1e3),awaitthis.currentPage()}asyncsocketEmitter(e){returnthis.appApi.socketEmitter(e)}asyncadbCommand(e){return"android"===process.env.UNI_APP_PLATFORM?awaitthis.appApi.adbCommand(e):Error("Program.adbCommand is only supported on the app android platform")}}classqe{constructor(e){this.options=e}has(e){return!!this.options[e]}send(e,t,n){consts=this.options[t];if(!s)returnPromise.reject(Error(`adapter for ${t} not found`));consti=s.reflect;returni?(s.params&&(n=s.params(n)),"function"==typeofi?i(e.send.bind(e),n):(t=i,e.send(t,n))):Promise.reject(Error(`${t}'s reflect is required`))}}constFe=C.default("automator:puppet"),Le=".automator.json";functionHe(e){try{returnrequire(e)}catch(e){}}functionWe(e,t,n,s){consti=function(e,t,n){lets,i;returnprocess.env.UNI_OUTPUT_DIR?(i=b.default.join(process.env.UNI_OUTPUT_DIR,`../.automator/${t}`,Le),s=He(i)):(i=b.default.join(e,`dist/${n}/.automator/${t}`,Le),s=He(i),s||(i=b.default.join(e,`unpackage/dist/${n}/.automator/${t}`,Le),s=He(i))),Fe(`${i}=>${JSON.stringify(s)}`),s}(e,n,s);if(!i||!i.wsEndpoint)return!1;consto=require("../package.json").version;if(i.version!==o)returnFe(`unmet=>${i.version}!==${o}`),!1;constr=function(e){lett;try{conste=F.default.v4.sync();t=q.default.ip(e&&e.interface),t&&(/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(t)||(t=void0))}catch(e){}return"ws://"+(t||"localhost")+":"+e}(t);returnFe(`wsEndpoint=>${r}`),i.wsEndpoint===r}classXeextendsa.EventEmitter{constructor(e,t){if(super(),this.isX=!1,this.isVue3=!1,"true"===process.env.UNI_APP_X&&(this.isX=!0),t)this.target=t;else{if(this.target=null,"h5"===e)try{this.target=oe("@dcloudio/uni-h5/lib/h5/uni.automator.js")}catch(e){}this.target||(this.target=oe(`@dcloudio/uni-${"app"===e?"app-plus":e}/lib/uni.automator.js`))}if(!this.target)throwError("puppet is not provided");this.platform=e,this.adapter=newqe(this.target.adapter||{})}setCompiler(e){this.compiler=e}setRuntimeServer(e){this.wss=e}setRemoteRuntimeConnectionCallback(e){this.remoteRuntimeConnectionCallback=e}setRuntimeConnection(e){this.runtimeConnection=e,this.remoteRuntimeConnectionCallback&&(this.remoteRuntimeConnectionCallback(),this.remoteRuntimeConnectionCallback=null)}setDevtoolConnection(e){this.devtoolConnection=e}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(e,t){returnthis.runtimeConnection.send(e,t)}validateProject(e){constt=this.target.devtools.required;return!t||!t.find((t=>!N.default.existsSync(b.default.join(e,t))))}validateDevtools(e){constt=this.target.devtools.validate;returnt?t(e,this):Promise.resolve(e)}createDevtools(e,t,n){consts=this.target.devtools.create;returns?(t.timeout=n,s(e,t,this)):Promise.resolve()}shouldCompile(e,t,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=!We(e,t,this.platform,this.mode)}returnthis.compiled}getcheckProperty(){return"mp-weixin"===this.platform}getdevtools(){returnthis.target.devtools}getmode(){conste=this.target.mode;returne||("production"===process.env.NODE_ENV?"build":"dev")}}constBe=C.default("automator:compiler"),Ve=/The\s+(.*)\s+directory is ready/;classJe{constructor(e){this.puppet=e,this.puppet.setCompiler(this)}compile(e){constt=this.puppet.mode,n=this.puppet.platform;lets=e.silent;consti=e.port,o=e.host,r=`${t}:${n}`,a=e.projectPath,[c,p]=this.getSpawnArgs(e,r);p.push("--auto-port"),p.push(K.default(i)),o&&(p.push("--auto-host"),p.push(o));constl={cwd:e.cliPath,env:Object.assign(Object.assign({},process.env),{NODE_ENV:"build"===t?"production":"development"})};returnnewPromise(((e,i)=>{consto=o=>{constr=o.toString().trim();if(!s&&console.log(r),r.includes("- Network")||r.includes("> Network")||r.includes("➜ Network")){constt=r.match(/Network:(.*)/)[1].trim();Be(`url: ${t}`),e({path:t})}elseif(r.includes("DONE Build failed"))i(r);elseif(r.includes("DONE Build complete")){consti=r.match(Ve);leto="";if(i&&i.length>1)o=b.default.join(a,i[1]);else{conste=this.puppet.isX&&"app-plus"===n?"app":n;o=b.default.join(a,`dist/${t}/${e}`),U.existsSync(o)||(o=b.default.join(a,`unpackage/dist/${t}/${e}`))}s=!0,this.stop(),e({path:"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW?process.env.UNI_OUTPUT_DIR:o})}};Be(`${c}${p.join("")} %o`,l),this.cliProcess=E.spawn(c,p,l),this.cliProcess.on("error",(e=>{i(e)})),this.cliProcess.stdout.on("data",o),this.cliProcess.stderr.on("data",o)}))}stop(){this.cliProcess&&this.cliProcess.kill("SIGTERM")}getSpawnArgs(e,t){letn;consts=e.cliPath;try{n=require(b.default.join(s,"package.json"))}catch(e){}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[t]))return[process.env.UNI_NPM_PATH||(/^win/.test(process.platform)?"npm.cmd":"npm"),["run",t,"--"]];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=e.projectPath,process.env.UNI_OUTPUT_DIR=b.default.join(e.projectPath,`unpackage/dist/${this.puppet.mode}/${o}`),this.prepare(),process.env.UNI_HBUILDERX_PLUGINS||U.existsSync(b.default.resolve(s,"../about"))&&(process.env.UNI_HBUILDERX_PLUGINS=b.default.dirname(s)),i){conste="app-plus"===this.puppet.platform?"app":this.puppet.platform;returnprocess.env.UNI_PLATFORM=e,[process.env.UNI_NODE_PATH||"node",[require.resolve("@dcloudio/vite-plugin-uni/bin/uni.js",{paths:[s]}),"-p",e]]}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){conste=i.parse(U.readFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8")),t=b.default.resolve(process.env.UNI_INPUT_DIR,"unpackage",".automator","app-webview");process.env.UNI_INPUT_DIR=b.default.resolve(t,"src"),process.env.UNI_OUTPUT_DIR=b.default.resolve(t,"unpackage","dist","dev"),U.existsSync(process.env.UNI_INPUT_DIR)&&U.emptyDirSync(process.env.UNI_INPUT_DIR),U.copySync(b.default.resolve(__dirname,"..","lib","app-webview","project"),process.env.UNI_INPUT_DIR);constn=i.parse(U.readFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8"));U.writeFileSync(b.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),JSON.stringify(Object.assign(Object.assign({},n),{name:e.name||"",appid:e.appid||""}),null,2))}}}constGe=C.default("automator:launcher"),ze="true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM?12e4:24e4;classYe{asynclaunch(e){const{port:t,cliPath:n,timeout:i,projectPath:o}=awaitthis.validate(e);letr={};"app"===e.platform||"app-plus"===e.platform?(r=e.app||e["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=e[e.platform],r||(r={}),r.projectPath=o,Ge(r),this.puppet=newXe(e.platform,r.puppet),r=awaitthis.puppet.validateDevtools(r);leta=this.puppet.shouldCompile(o,t,e,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=e.compile=!0,this.compiler=newJe(this.puppet);consts=awaitthis.compiler.compile({host:e.host,port:t,cliPath:n,projectPath:o,silent:!!e.silent});s.path&&(c=s.path)}constp=[];returnp.push(this.createRuntimeConnection(t,i)),p.push(this.puppet.createDevtools(c,r,i)),newPromise(((e,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";e(new$e(this.puppet,{teardown:i,port:t}))})).catch((e=>n(e)))}))}resolveCliPath(e){if(!e)returne;try{const{dependencies:t,devDependencies:n}=require(b.default.join(e,"package.json"));if(Ke(n)||Ke(t))returne}catch(e){}}resolveProjectPath(e,t){returne||(e=process.env.UNI_INPUT_DIR||process.cwd()),R.default(e)&&(e=b.default.resolve(e)),N.default.existsSync(e)||function(e){throwError(e)}(`Project path ${e} doesn't exist`),e}asyncvalidate(e){constt=this.resolveProjectPath(e.projectPath,e);letn=process.env.UNI_CLI_PATH||e.cliPath;if(n=this.resolveCliPath(n||""),!n&&(n=this.resolveCliPath(process.cwd())),!n&&(n=this.resolveCliPath(t)),!n)throwError("cliPath is not provided");if("false"!==process.env.UNI_APP_X){conste=this.getManifestJson(t);("true"===process.env.UNI_APP_X||"uni-app-x"ine)&&(process.env.UNI_APP_X="true",e.appid&&(process.env.UNI_APP_ID=e.appid))}process.env.UNI_AUTOMATOR_HOST&&(e.host=process.env.UNI_AUTOMATOR_HOST),process.env.UNI_AUTOMATOR_PORT&&(e.port=parseInt(process.env.UNI_AUTOMATOR_PORT));return{port:awaitasyncfunction(e,t){constn=awaitH.default(e||t);if(e&&n!==e)throwError(`Port ${e} is in use, please specify another port`);returnn}(e.port||9520),cliPath:n,timeout:e.timeout||ze,projectPath:t}}getManifestJson(e){if(e){constt=b.default.join(e,"manifest.json");if(N.default.existsSync(t))returni.parse(N.default.readFileSync(t,"utf8"))}return{}}asynccreateRuntimeConnection(e,t){returnae.createRuntimeConnection(e,this.puppet,t)}}functionKe(e){return!!e&&!(!e["@dcloudio/vue-cli-plugin-uni"]&&!e["@dcloudio/vite-plugin-uni"])}exports.Automator=class{constructor(){this.launcher=newYe}asynclaunch(e){returnthis.launcher.launch(e)}},exports.initUni=e=>newProxy({},{get(t,n){return"connectSocket"===n?async(...t)=>{consts=`${Date.now()}-${Math.random()}`;returnt[0].id=s,awaite.callUniMethod(n,...t).then((n=>{ne(t[0],n),te.set(s,newMap);consti={id:s,onMessage:t=>{e.socketEmitter({id:s,method:"onMessage"}),te.get(s).set("onMessage",t)},send:t=>{e.socketEmitter({id:s,method:"send",data:t.data}).then((e=>{ne(t,e)})).catch((e=>{se(t,e)}))},close:t=>{e.socketEmitter({id:s,method:"close",code:t.code,reason:t.reason}).then((e=>{ne(t,e),te.delete(s)})).catch((e=>{se(t,e)}))},onOpen:t=>{e.socketEmitter({id:s,method:"onOpen"}),te.get(s).set("onOpen",t)},onClose:t=>{e.socketEmitter({id:s,method:"onClose"}),te.get(s).set("onClose",t)},onError:t=>{e.socketEmitter({id:s,method:"onError"}),te.get(s).set("onError",t)}};returnte.get(s).set("socketTask",i),i})).catch((e=>(se(t[0],e),null)))}:(s=n,ee.includes(s)?t=>{Z.has(n)||Z.set(n,newMap);consts=Z.get(n),i=`${Date.now()}-${Math.random()}`;s.set(i,t),e.callUniMethod(n,i)}:function(e){returne.startsWith("off")&&ee.includes(e.replace("off","on"))}(n)?asynct=>{consts=n.replace("off","on");if(Z.has(s))if(t){consti=Z.get(s);i.forEach(((s,o)=>{s===t&&(i.delete(o),e.callUniMethod(n,o))}))}elseZ.delete(s),e.callUniMethod(n)}:async(...t)=>awaite.callUniMethod(n,...t).then((e=>(ne(t[0],e),e))).catch((e=>(se(t[0],e),e))));vars}});