functionD(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}varR;functionA(t,e){constn=e.value;returne.value=asyncfunction(e){return(await(null==n?void0:n.call(this,e)))(t)},e}functionj(t,e,n){returnA(R.RUNTIME,n)}functionx(t,e,n){returnA(R.DEVTOOL,n)}!function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(R||(R={}));classq{constructor(t){this.puppet=t}invoke(t,e){returnasyncn=>this.puppet.devtoolConnection?(n===R.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$extendsq{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)}}D([j],$.prototype,"getData",null),D([j],$.prototype,"setData",null),D([j],$.prototype,"callMethod",null),D([x],$.prototype,"getElement",null),D([x],$.prototype,"getElements",null),D([x],$.prototype,"getOffset",null),D([x],$.prototype,"getHTML",null),D([x],$.prototype,"getAttributes",null),D([x],$.prototype,"getStyles",null),D([x],$.prototype,"getDOMProperties",null),D([x],$.prototype,"getProperties",null),D([x],$.prototype,"tap",null),D([x],$.prototype,"longpress",null),D([x],$.prototype,"touchstart",null),D([x],$.prototype,"touchmove",null),D([x],$.prototype,"touchend",null),D([x],$.prototype,"triggerEvent",null),D([x],$.prototype,"callFunction",null),D([x],$.prototype,"callContextMethod",null);classS{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=new$(t,e)}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnS.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=>S.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(){returnthis.api.getOffset()}asynctext(){returnthis.domProperty("innerText")}asyncattribute(t){if(!m(t))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[t]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(t){if(!m(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._property(t)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(t){if(!m(t))throwError("name must be a string");return(awaitthis.api.getStyles({names:[t]})).styles[0]}asynctap(){returnthis.api.tap()}asynclongpress(){returnthis.nvue?this.api.longpress():(awaitthis.touchstart(),awaitv(350),this.touchend())}asynctrigger(t,e){constn={type:t};returnw(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){returnT(asynct=>(awaitthis.api.getDOMProperties({names:t})).properties,t)}_property(t){returnT(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=U;elseswitch(e.tagName){case"input":s=F;break;case"textarea":s=O;break;case"scroll-view":s=N;break;case"swiper":s=L;break;case"movable-view":s=_;break;case"switch":s=H;break;case"slider":s=B;break;case"video":s=W;break;default:s=S}returni=news(t,e,n),n.set(e.elementId,i),i}}classUextendsS{asyncsetData(t){returnthis.api.setData({data:t})}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}}classFextendsS{asyncinput(t){returnthis.callFunction("input.input",t)}}classOextendsS{asyncinput(t){returnthis.callFunction("textarea.input",t)}}classNextendsS{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")}}classLextendsS{asyncswipeTo(t){returnthis.callFunction("swiper.swipeTo",t)}}class_extendsS{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)}}classHextendsS{asynctap(){returnthis.callFunction("switch.tap")}}classBextendsS{asyncslideTo(t){returnthis.callFunction("slider.slideTo",t)}}classWextendsS{asynccallContextMethod(t,...e){returnthis.api.callContextMethod({method:t,args:e})}}classVextendsq{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)}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)}}D([j],V.prototype,"getData",null),D([j],V.prototype,"setData",null),D([j],V.prototype,"callMethod",null),D([x],V.prototype,"getElement",null),D([x],V.prototype,"getElements",null),D([x],V.prototype,"getWindowProperties",null);classz{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=newMap,this.api=newV(t,e)}asyncwaitFor(t){returny(t)?awaitv(t):h(t)?l(t):m(t)?l(async()=>(awaitthis.$$(t)).length>0):void0}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnS.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=>S.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap))}asyncdata(t){conste={};returnt&&(e.path=t),(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}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(t){conste=m(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.query=e.query,s):(s=newz(t,e),n.set(e.id,s),s)}}classJextendsq{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(t){returnthis.invoke("App.callUniMethod",t)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(t){returnthis.invoke("App.mockUniMethod",t)}asynccallFunction(t){returnthis.invoke("App.callFunction",t)}asynccaptureScreenshot(t){returnthis.invoke("App.captureScreenshot",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)}}D([j],J.prototype,"getPageStack",null),D([j],J.prototype,"callUniMethod",null),D([j],J.prototype,"getCurrentPage",null),D([j],J.prototype,"mockUniMethod",null),D([x],J.prototype,"callFunction",null),D([x],J.prototype,"captureScreenshot",null),D([x],J.prototype,"exit",null),D([x],J.prototype,"addBinding",null),D([x],J.prototype,"enableLog",null);classGextendsq{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)}}functionX(t){returnnewPromise(e=>setTimeout(e,t))}D([x],G.prototype,"getInfo",null),D([x],G.prototype,"enableRemoteDebug",null),D([x],G.prototype,"close",null),D([x],G.prototype,"getTestAccounts",null);classYextendsr.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newJ(t),this.toolApi=newG(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=>z.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();returnz.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){returnh(e)||m(s=e)&&(s=d(s),g(s,"function")||g(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){}awaitX(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=>{I.generate(n,{small:!0},e=>{process.stdout.write(e),t()})}));consts=newPromise(t=>{this.toolApi.onRemoteDebugConnected(async()=>{awaitX(1e3),t()})}),i=newPromise(t=>{this.puppet.setRemoteRuntimeConnectionCallback(()=>{t()})});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){const{data:e}=awaitthis.appApi.captureScreenshot({fullPage:null==t?void0:t.fullPage});if(!(null==t?void0:t.path))returne;awaitu.writeFile(t.path,e,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(t,e){returnawaitthis.callUniMethod(t,{url:e}),awaitX(3e3),this.currentPage()}}classK{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"))}}constQ=s("automator:puppet");functionZ(t){try{returnrequire(t)}catch(t){}}functiontt(t,e,s,i){consto=function(t,e,s){leti,o;returnprocess.env.UNI_OUTPUT_DIR?(o=n.join(process.env.UNI_OUTPUT_DIR,"../.automator/"+e,".automator.json"),i=Z(o)):(o=n.join(t,`dist/${s}/.automator/${e}`,".automator.json"),i=Z(o),i||(o=n.join(t,`unpackage/dist/${s}/.automator/${e}`,".automator.json"),i=Z(o))),Q(`${o}=>${JSON.stringify(i)}`),i}(t,s,i);if(!o||!o.wsEndpoint)return!1;constr=require("../package.json").version;if(o.version!==r)returnQ(`unmet=>${o.version}!==${r}`),!1;consta=function(t){lete;try{constt=P.v4.sync();e=f.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);returnQ("wsEndpoint=>"+a),o.wsEndpoint===a}classetextendsr.EventEmitter{constructor(t,e){if(super(),this.target=e||("h5"===t?require("@dcloudio/uni-h5/lib/h5/uni.automator.js"):require(`@dcloudio/uni-${t}/lib/uni.automator.js`)),!this.target)throwError("puppet is not provided");this.platform=t,this.adapter=newK(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){consts=this.target.devtools.required;return!s||!s.find(s=>!e.existsSync(n.join(t,s)))}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;returni?this.compiled=i(n,s):!0===n.compile?this.compiled=!0:this.compiled=!tt(t,e,this.platform,this.mode),this.compiled}getcheckProperty(){return"mp-weixin"===this.platform}getdevtools(){returnthis.target.devtools}getmode(){constt=this.target.mode;returnt||("production"===process.env.NODE_ENV?"build":"dev")}}constnt=s("automator:compiler"),st=/The\s+(.*)\s+directory is ready/;classit{constructor(t){this.puppet=t,this.puppet.setCompiler(this)}compile(t){conste=this.puppet.mode,s=this.puppet.platform;leti=t.silent;consto=t.port,r=t.host,a=process.env.UNI_NPM_PATH||(/^win/.test(process.platform)?"npm.cmd":"npm"),c=`${e}:${s}`,p=t.projectPath,l=["run",c,"--","--auto-port",E(o)];r&&(l.push("--auto-host"),l.push(r));constu={cwd:t.cliPath||t.projectPath,env:process.env};returnnewPromise((t,o)=>{constr=o=>{constr=o.toString().trim();if(!i&&console.log(r),r.includes("- Network")){conste=r.match(/Network:(.*)/)[1].trim();nt("url: "+e),t({path:e})}elseif(r.includes("DONE Build complete")){leto=`unpackage/dist/${e}/${s}`;consta=r.match(st);a&&a.length>1&&(o=a[1]),i=!0,this.stop(),t({path:n.join(p,o)})}};nt(`${a}${l.join("")}`),this.cliProcess=k.spawn(a,l,u),this.cliProcess.on("error",t=>{o(t)}),this.cliProcess.stdout.on("data",r),this.cliProcess.stderr.on("data",r)})}stop(){this.cliProcess&&this.cliProcess.kill("SIGTERM")}}classot{asynclaunch(t){lete=t[t.platform]||{};this.puppet=newet(t.platform,e.puppet);const{port:i,cliPath:o,timeout:r,projectPath:a}=awaitthis.validate(t);e=awaitthis.puppet.validateDevtools(e);letc=this.puppet.shouldCompile(a,i,t,e),p=process.env.UNI_OUTPUT_DIR||a;if(c||this.puppet.validateProject(p)||(p=n.join(a,"dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(p)||(p=n.join(a,"unpackage/dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(p)||(c=!0))),c){this.puppet.compiled=t.compile=!0,this.compiler=newit(this.puppet);conste=awaitthis.compiler.compile({host:t.host,port:i,cliPath:o,projectPath:a,silent:!!t.silent});e.path&&(p=e.path)}constl=[];returnl.push(this.createRuntimeConnection(i,r)),l.push(this.puppet.createDevtools(p,e,r)),newPromise((t,n)=>{Promise.all(l).then(([n,i])=>{n&&this.puppet.setRuntimeConnection(n),i&&this.puppet.setDevtoolConnection(i),s("automator:program")("ready");consto=e.teardown||"disconnect";t(newY(this.puppet,{teardown:o}))}).catch(t=>n(t))})}resolveCliPath(t){if(!t)returnt;try{conste=require(n.join(t,"package.json"));if(e.devDependencies&&e.devDependencies["@dcloudio/vue-cli-plugin-uni"])returnt}catch(t){}}resolveProjectPath(t,s){returnt||(t=process.env.UNI_INPUT_DIR||process.cwd()),i(t)&&(t=n.resolve(t)),e.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");return{port:awaitasyncfunction(t,e){constn=awaitM(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||1e5,projectPath:e}}asynccreateRuntimeConnection(t,e){returnC.createRuntimeConnection(t,this.puppet,e)}}module.exports=class{constructor(){this.launcher=newot}asynclaunch(t){returnthis.launcher.launch(t)}};
functionD(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}varj;functionA(t,e){constn=e.value;returne.value=asyncfunction(e){return(await(null==n?void0:n.call(this,e)))(t)},e}functionR(t,e,n){returnA(j.RUNTIME,n)}functionx(t,e,n){returnA(j.DEVTOOL,n)}!function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(j||(j={}));classq{constructor(t){this.puppet=t}invoke(t,e){returnasyncn=>this.puppet.devtoolConnection?(n===j.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}classUextendsq{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)}}D([R],U.prototype,"getData",null),D([R],U.prototype,"setData",null),D([R],U.prototype,"callMethod",null),D([x],U.prototype,"getElement",null),D([x],U.prototype,"getElements",null),D([x],U.prototype,"getOffset",null),D([x],U.prototype,"getHTML",null),D([x],U.prototype,"getAttributes",null),D([x],U.prototype,"getStyles",null),D([x],U.prototype,"getDOMProperties",null),D([x],U.prototype,"getProperties",null),D([x],U.prototype,"tap",null),D([x],U.prototype,"longpress",null),D([x],U.prototype,"touchstart",null),D([x],U.prototype,"touchmove",null),D([x],U.prototype,"touchend",null),D([x],U.prototype,"triggerEvent",null),D([x],U.prototype,"callFunction",null),D([x],U.prototype,"callContextMethod",null);classS{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=newU(t,e)}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnS.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=>S.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(){returnthis.api.getOffset()}asynctext(){returnthis.domProperty("innerText")}asyncattribute(t){if(!m(t))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[t]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(t){if(!m(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._property(t)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(t){if(!m(t))throwError("name must be a string");return(awaitthis.api.getStyles({names:[t]})).styles[0]}asynctap(){returnthis.api.tap()}asynclongpress(){returnthis.nvue?this.api.longpress():(awaitthis.touchstart(),awaitv(350),this.touchend())}asynctrigger(t,e){constn={type:t};returnw(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){returnT(asynct=>(awaitthis.api.getDOMProperties({names:t})).properties,t)}_property(t){returnT(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=$;elseswitch(e.tagName){case"input":s=N;break;case"textarea":s=O;break;case"scroll-view":s=_;break;case"swiper":s=F;break;case"movable-view":s=L;break;case"switch":s=H;break;case"slider":s=B;break;case"video":s=W;break;default:s=S}returni=news(t,e,n),n.set(e.elementId,i),i}}class$extendsS{asyncsetData(t){returnthis.api.setData({data:t})}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}}classNextendsS{asyncinput(t){returnthis.callFunction("input.input",t)}}classOextendsS{asyncinput(t){returnthis.callFunction("textarea.input",t)}}class_extendsS{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")}}classFextendsS{asyncswipeTo(t){returnthis.callFunction("swiper.swipeTo",t)}}classLextendsS{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)}}classHextendsS{asynctap(){returnthis.callFunction("switch.tap")}}classBextendsS{asyncslideTo(t){returnthis.callFunction("slider.slideTo",t)}}classWextendsS{asynccallContextMethod(t,...e){returnthis.api.callContextMethod({method:t,args:e})}}classVextendsq{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)}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)}}D([R],V.prototype,"getData",null),D([R],V.prototype,"setData",null),D([R],V.prototype,"callMethod",null),D([x],V.prototype,"getElement",null),D([x],V.prototype,"getElements",null),D([x],V.prototype,"getWindowProperties",null);classz{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=newMap,this.api=newV(t,e)}asyncwaitFor(t){returny(t)?awaitv(t):h(t)?l(t):m(t)?l(async()=>(awaitthis.$$(t)).length>0):void0}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnS.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=>S.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap))}asyncdata(t){conste={};returnt&&(e.path=t),(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}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(t){conste=m(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.query=e.query,s):(s=newz(t,e),n.set(e.id,s),s)}}classJextendsq{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(t){returnthis.invoke("App.callUniMethod",t)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(t){returnthis.invoke("App.mockUniMethod",t)}asynccallFunction(t){returnthis.invoke("App.callFunction",t)}asynccaptureScreenshot(t){returnthis.invoke("App.captureScreenshot",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)}}D([R],J.prototype,"getPageStack",null),D([R],J.prototype,"callUniMethod",null),D([R],J.prototype,"getCurrentPage",null),D([R],J.prototype,"mockUniMethod",null),D([x],J.prototype,"callFunction",null),D([x],J.prototype,"captureScreenshot",null),D([x],J.prototype,"exit",null),D([x],J.prototype,"addBinding",null),D([x],J.prototype,"enableLog",null);classGextendsq{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)}}functionX(t){returnnewPromise(e=>setTimeout(e,t))}D([x],G.prototype,"getInfo",null),D([x],G.prototype,"enableRemoteDebug",null),D([x],G.prototype,"close",null),D([x],G.prototype,"getTestAccounts",null);classYextendsr.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newJ(t),this.toolApi=newG(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=>z.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();returnz.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){returnh(e)||m(s=e)&&(s=d(s),g(s,"function")||g(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){}awaitX(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=>{C.generate(n,{small:!0},e=>{process.stdout.write(e),t()})}));consts=newPromise(t=>{this.toolApi.onRemoteDebugConnected(async()=>{awaitX(1e3),t()})}),i=newPromise(t=>{this.puppet.setRemoteRuntimeConnectionCallback(()=>{t()})});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){const{data:e}=awaitthis.appApi.captureScreenshot({fullPage:null==t?void0:t.fullPage});if(!(null==t?void0:t.path))returne;awaitu.writeFile(t.path,e,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(t,e){returnawaitthis.callUniMethod(t,{url:e}),awaitX(3e3),this.currentPage()}}classK{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"))}}constQ=s("automator:puppet");functionZ(t){try{returnrequire(t)}catch(t){}}functiontt(t,e,s,i){consto=function(t,e,s){leti,o;returnprocess.env.UNI_OUTPUT_DIR?(o=n.join(process.env.UNI_OUTPUT_DIR,"../.automator/"+e,".automator.json"),i=Z(o)):(o=n.join(t,`dist/${s}/.automator/${e}`,".automator.json"),i=Z(o),i||(o=n.join(t,`unpackage/dist/${s}/.automator/${e}`,".automator.json"),i=Z(o))),Q(`${o}=>${JSON.stringify(i)}`),i}(t,s,i);if(!o||!o.wsEndpoint)return!1;constr=require("../package.json").version;if(o.version!==r)returnQ(`unmet=>${o.version}!==${r}`),!1;consta=function(t){lete;try{constt=P.v4.sync();e=f.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);returnQ("wsEndpoint=>"+a),o.wsEndpoint===a}classetextendsr.EventEmitter{constructor(t,e){if(super(),this.target=e||("h5"===t?require("@dcloudio/uni-h5/lib/h5/uni.automator.js"):require(`@dcloudio/uni-${t}/lib/uni.automator.js`)),!this.target)throwError("puppet is not provided");this.platform=t,this.adapter=newK(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){consts=this.target.devtools.required;return!s||!s.find(s=>!e.existsSync(n.join(t,s)))}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;returni?this.compiled=i(n,s):!0===n.compile?this.compiled=!0:this.compiled=!tt(t,e,this.platform,this.mode),this.compiled}getcheckProperty(){return"mp-weixin"===this.platform}getdevtools(){returnthis.target.devtools}getmode(){constt=this.target.mode;returnt||("production"===process.env.NODE_ENV?"build":"dev")}}constnt=s("automator:compiler"),st=/The\s+(.*)\s+directory is ready/;classit{constructor(t){this.puppet=t,this.puppet.setCompiler(this)}compile(t){conste=this.puppet.mode,s=this.puppet.platform;leti=t.silent;consto=t.port,r=t.host,a=`${e}:${s}`,c=t.projectPath,[p,l]=this.getSpawnArgs(t,a);l.push("--auto-port"),l.push(E(o)),r&&(l.push("--auto-host"),l.push(r));constu={cwd:t.cliPath,env:process.env};returnnewPromise((t,o)=>{constr=o=>{constr=o.toString().trim();if(!i&&console.log(r),r.includes("- Network")){conste=r.match(/Network:(.*)/)[1].trim();nt("url: "+e),t({path:e})}elseif(r.includes("DONE Build complete")){leto=`unpackage/dist/${e}/${s}`;consta=r.match(st);a&&a.length>1&&(o=a[1]),i=!0,this.stop(),t({path:n.join(c,o)})}};nt(`${p}${l.join("")} %o`,u),this.cliProcess=k.spawn(p,l,u),this.cliProcess.on("error",t=>{o(t)}),this.cliProcess.stdout.on("data",r),this.cliProcess.stderr.on("data",r)})}stop(){this.cliProcess&&this.cliProcess.kill("SIGTERM")}getSpawnArgs(t,e){lets;consti=t.cliPath;try{s=require(n.join(i,"package.json"))}catch(t){}returns&&s.scripts&&s.npmScript?[process.env.UNI_NPM_PATH||(/^win/.test(process.platform)?"npm.cmd":"npm"),["run",e,"--"]]:(process.env.UNI_INPUT_DIR=t.projectPath,process.env.UNI_OUTPUT_DIR=n.join(t.projectPath,`unpackage/dist/${this.puppet.mode}/${this.puppet.platform}`),[process.env.UNI_NODE_PATH||"node",[n.join(i,"bin/uniapp-cli.js")]])}}classot{asynclaunch(t){lete=t[t.platform]||{};this.puppet=newet(t.platform,e.puppet);const{port:i,cliPath:o,timeout:r,projectPath:a}=awaitthis.validate(t);e=awaitthis.puppet.validateDevtools(e);letc=this.puppet.shouldCompile(a,i,t,e),p=process.env.UNI_OUTPUT_DIR||a;if(c||this.puppet.validateProject(p)||(p=n.join(a,"dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(p)||(p=n.join(a,"unpackage/dist/"+this.puppet.mode+"/"+this.puppet.platform),this.puppet.validateProject(p)||(c=!0))),c){this.puppet.compiled=t.compile=!0,this.compiler=newit(this.puppet);conste=awaitthis.compiler.compile({host:t.host,port:i,cliPath:o,projectPath:a,silent:!!t.silent});e.path&&(p=e.path)}constl=[];returnl.push(this.createRuntimeConnection(i,r)),l.push(this.puppet.createDevtools(p,e,r)),newPromise((t,n)=>{Promise.all(l).then(([n,i])=>{n&&this.puppet.setRuntimeConnection(n),i&&this.puppet.setDevtoolConnection(i),s("automator:program")("ready");consto=e.teardown||"disconnect";t(newY(this.puppet,{teardown:o}))}).catch(t=>n(t))})}resolveCliPath(t){if(!t)returnt;try{conste=require(n.join(t,"package.json"));if(e.devDependencies&&e.devDependencies["@dcloudio/vue-cli-plugin-uni"])returnt}catch(t){}}resolveProjectPath(t,s){returnt||(t=process.env.UNI_INPUT_DIR||process.cwd()),i(t)&&(t=n.resolve(t)),e.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");return{port:awaitasyncfunction(t,e){constn=awaitM(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||1e5,projectPath:e}}asynccreateRuntimeConnection(t,e){returnI.createRuntimeConnection(t,this.puppet,e)}}module.exports=class{constructor(){this.launcher=newot}asynclaunch(t){returnthis.launcher.launch(t)}};
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("os")),r=e(require("path")),s=e(require("debug")),a=e(require("licia/isWindows")),n=e(require("fs")),o=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),l=e(require("licia/waitUntil")),p=e(require("licia/concat")),u=e(require("licia/getPort")),m=e(require("licia/dateFormat"));require("address"),require("default-gateway"),require("jimp"),require("licia/isStr");vard=e(require("ws")),h=require("events"),f=e(require("licia/uuid")),g=e(require("licia/stringify"));constw=/(^[a-z][a-z0-9-]*)/i,y=/^navigator/i,E=/^swan-nav$/i;varb;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(b||(b={}));constv={[b.SELECTOR]:[{test:y,processor:e=>e.replace(y,"nav")},{test:w,processor:e=>"swan-"+e}],[b.TAGNAME]:[{test:E,processor:e=>e.replace(E,"swan-navigator")},{test:w,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},j=e=>t=>{constr=(v[e]||[]).filter(e=>e.test.test(t));for(consteofr)t=e.processor(t);returnt},P=j(b.SELECTOR),q=j(b.TAGNAME),O=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});require("qrcode-terminal"),require("qrcode-reader");classMextendsh.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",e=>{this.emit("message",e.data)}),this.ws.addEventListener("close",()=>{this.emit("close")})}send(e){this.ws.send(e)}close(){this.ws.close()}}classCextendsh.EventEmitter{constructor(e,t,r){super(),this.puppet=t,this.namespace=r,this.callbacks=newMap,this.transport=e,this.debug=s("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:s,result:a,params:n}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,n);const{callbacks:o}=this;if(t&&o.has(t)){conste=o.get(t);o.delete(t),s?e.reject(Error(s.message)):e.resolve(a)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consts=f(),a=g({id:s,method:e,params:t});returnthis.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise((e,t)=>{try{this.transport.send(a)}catch(e){t(Error("Connection closed"))}this.callbacks.set(s,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,s)=>{consta=newd(e);a.addEventListener("open",()=>{r(newC(newM(a),t,"devtool"))}),a.addEventListener("error",s)})}staticcreateRuntimeConnection(e,t,r){returnnewPromise((a,n)=>{s("automator:runtime")(`${m("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consto=newd.Server({port:e});l(async()=>{if(t.runtimeConnection)return!0},r,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),o.on("connection",(function(e){s("automator:runtime")(m("yyyy-mm-dd HH:MM:ss:l")+" connected");constr=newC(newM(e),t,"runtime");t.setRuntimeConnection(r),a(r)})),t.setRuntimeServer(o)})}}const$=s("automator:devtool");asyncfunctionS(e,t,r){const{port:s,cliPath:a,timeout:n,cwd:u="",account:d="",args:h=[],launch:f=!0}=t;letg=!1,w=!1;if(!1!==f){constt={stdio:"ignore"};u&&(t.cwd=u);letr=p(h,[]);r=p(r,["--auto"]),r=p(r,[e,"--auto-port",c(s)]),d&&(r=p(r,["--auto-account",d]));try{$("%s %o %o",a,r,t);conste=o.spawn(a,r,t);e.on("error",e=>{g=!0}),e.on("exit",()=>{setTimeout(()=>{w=!0},15e3)}),e.unref()}catch(e){g=!1}}elsesetTimeout(()=>{w=!0},15e3);consty=awaitl(async()=>{try{if(g||w)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitC.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+s},r)}catch(e){}},n,1e3);if(g)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(w)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),$(m("yyyy-mm-dd HH:MM:ss:l")+" connected"),y}constA=[];["","-rc"].forEach(e=>{a?(A.push(r.join(t.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),A.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):A.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)});constT={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:A,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(n.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);lets=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{s=awaitasyncfunction(e,t){constr=awaitu(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(s)}catch(t){e.launch=!1}else{s===awaitu(s)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:s,cliPath:r})},asynccreate(e,t,r){consta=awaitS(e,t,r);returnr.compiled?s("automator:devtool")("Waiting for runtime automator"):(s("automator:devtool")("initRuntimeAutomator"),a.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),a}},adapter:{"Tool.enableRemoteDebug":{reflect:asynce=>({qrCode:(awaite("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(awaite("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(awaite("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(r=t.selector,r.split("").map(e=>P(e)).join(""))}))).map(e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:q(t.tagName)}})};varr}},"Page.getWindowProperties":{reflect:async(e,t)=>{constr=t.names.map(e=>e.replace("document.documentElement.","")),s=(awaite("smartapp.element.getBySelector",{properties:r,selector:"html"}))[0];return{properties:r.map(e=>s.properties[e])}}},"Element.getHTML":{reflect:async(e,t)=>{constr=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:r}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:r}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returnr.forEach(e=>{e.nodeId=e.id}),{elements:r}}},"Element.getAttributes":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{attributes:r}},params:O},"Element.getStyles":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:s},t)));return{styles:r}},params:O},"Element.getDOMProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getProperty",Object.assign({property:s},t)));return{properties:r}},params:O},"Element.getProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{properties:r}},params:O},"Element.getOffset":{reflect:async(e,t)=>({left:awaite("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:awaite("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:O},"Element.tap":{reflect:"smartapp.element.touch",params:O}}};module.exports=T;
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("os")),r=e(require("path")),s=e(require("debug")),a=e(require("licia/isWindows")),n=e(require("fs")),o=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),l=e(require("licia/waitUntil")),p=e(require("licia/concat")),u=e(require("licia/getPort")),m=e(require("licia/dateFormat"));require("address"),require("default-gateway"),require("licia/isStr");vard=e(require("ws")),h=require("events"),f=e(require("licia/uuid")),g=e(require("licia/stringify"));constw=/(^[a-z][a-z0-9-]*)/i,y=/^navigator/i,E=/^swan-nav$/i;varb;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(b||(b={}));constv={[b.SELECTOR]:[{test:y,processor:e=>e.replace(y,"nav")},{test:w,processor:e=>"swan-"+e}],[b.TAGNAME]:[{test:E,processor:e=>e.replace(E,"swan-navigator")},{test:w,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},P=e=>t=>{constr=(v[e]||[]).filter(e=>e.test.test(t));for(consteofr)t=e.processor(t);returnt},j=P(b.SELECTOR),q=P(b.TAGNAME),O=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});require("qrcode-terminal"),require("qrcode-reader");classMextendsh.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",e=>{this.emit("message",e.data)}),this.ws.addEventListener("close",()=>{this.emit("close")})}send(e){this.ws.send(e)}close(){this.ws.close()}}classCextendsh.EventEmitter{constructor(e,t,r){super(),this.puppet=t,this.namespace=r,this.callbacks=newMap,this.transport=e,this.debug=s("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:s,result:a,params:n}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,n);const{callbacks:o}=this;if(t&&o.has(t)){conste=o.get(t);o.delete(t),s?e.reject(Error(s.message)):e.resolve(a)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consts=f(),a=g({id:s,method:e,params:t});returnthis.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise((e,t)=>{try{this.transport.send(a)}catch(e){t(Error("Connection closed"))}this.callbacks.set(s,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,s)=>{consta=newd(e);a.addEventListener("open",()=>{r(newC(newM(a),t,"devtool"))}),a.addEventListener("error",s)})}staticcreateRuntimeConnection(e,t,r){returnnewPromise((a,n)=>{s("automator:runtime")(`${m("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consto=newd.Server({port:e});l(async()=>{if(t.runtimeConnection)return!0},r,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),o.on("connection",(function(e){s("automator:runtime")(m("yyyy-mm-dd HH:MM:ss:l")+" connected");constr=newC(newM(e),t,"runtime");t.setRuntimeConnection(r),a(r)})),t.setRuntimeServer(o)})}}const$=s("automator:devtool");asyncfunctionS(e,t,r){const{port:s,cliPath:a,timeout:n,cwd:u="",account:d="",args:h=[],launch:f=!0}=t;letg=!1,w=!1;if(!1!==f){constt={stdio:"ignore"};u&&(t.cwd=u);letr=p(h,[]);r=p(r,["--auto"]),r=p(r,[e,"--auto-port",c(s)]),d&&(r=p(r,["--auto-account",d]));try{$("%s %o %o",a,r,t);conste=o.spawn(a,r,t);e.on("error",e=>{g=!0}),e.on("exit",()=>{setTimeout(()=>{w=!0},15e3)}),e.unref()}catch(e){g=!1}}elsesetTimeout(()=>{w=!0},15e3);consty=awaitl(async()=>{try{if(g||w)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitC.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+s},r)}catch(e){}},n,1e3);if(g)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(w)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),$(m("yyyy-mm-dd HH:MM:ss:l")+" connected"),y}constA=[];["","-rc"].forEach(e=>{a?(A.push(r.join(t.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),A.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):A.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)});constT={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:A,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(n.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);lets=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{s=awaitasyncfunction(e,t){constr=awaitu(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(s)}catch(t){e.launch=!1}else{s===awaitu(s)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:s,cliPath:r})},asynccreate(e,t,r){consta=awaitS(e,t,r);returnr.compiled?s("automator:devtool")("Waiting for runtime automator"):(s("automator:devtool")("initRuntimeAutomator"),a.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),a}},adapter:{"Tool.enableRemoteDebug":{reflect:asynce=>({qrCode:(awaite("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(awaite("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(awaite("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(r=t.selector,r.split("").map(e=>j(e)).join(""))}))).map(e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:q(t.tagName)}})};varr}},"Page.getWindowProperties":{reflect:async(e,t)=>{constr=t.names.map(e=>e.replace("document.documentElement.","")),s=(awaite("smartapp.element.getBySelector",{properties:r,selector:"html"}))[0];return{properties:r.map(e=>s.properties[e])}}},"Element.getHTML":{reflect:async(e,t)=>{constr=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:r}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:r}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returnr.forEach(e=>{e.nodeId=e.id}),{elements:r}}},"Element.getAttributes":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{attributes:r}},params:O},"Element.getStyles":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:s},t)));return{styles:r}},params:O},"Element.getDOMProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getProperty",Object.assign({property:s},t)));return{properties:r}},params:O},"Element.getProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{properties:r}},params:O},"Element.getOffset":{reflect:async(e,t)=>({left:awaite("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:awaite("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:O},"Element.tap":{reflect:"smartapp.element.touch",params:O}}};module.exports=T;
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("debug")),r=e(require("licia/isWindows"));require("address"),require("default-gateway");varo=e(require("jimp"));require("licia/isStr");varn=e(require("licia/getPort")),s=e(require("fs")),a=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),u=e(require("licia/waitUntil")),l=e(require("licia/concat")),d=e(require("licia/dateFormat")),p=e(require("ws")),m=require("events"),h=e(require("licia/uuid")),w=e(require("licia/stringify"));require("qrcode-terminal");constf=require("qrcode-reader");classyextendsm.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",e=>{this.emit("message",e.data)}),this.ws.addEventListener("close",()=>{this.emit("close")})}send(e){this.ws.send(e)}close(){this.ws.close()}}classgextendsm.EventEmitter{constructor(e,r,o){super(),this.puppet=r,this.namespace=o,this.callbacks=newMap,this.transport=e,this.debug=t("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:o,result:n,params:s}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,s);const{callbacks:a}=this;if(t&&a.has(t)){conste=a.get(t);a.delete(t),o?e.reject(Error(o.message)):e.resolve(n)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consto=h(),n=w({id:o,method:e,params:t});returnthis.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${n}`),newPromise((e,t)=>{try{this.transport.send(n)}catch(e){t(Error("Connection closed"))}this.callbacks.set(o,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,o)=>{constn=newp(e);n.addEventListener("open",()=>{r(newg(newy(n),t,"devtool"))}),n.addEventListener("error",o)})}staticcreateRuntimeConnection(e,r,o){returnnewPromise((n,s)=>{t("automator:runtime")(`${d("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newp.Server({port:e});u(async()=>{if(r.runtimeConnection)return!0},o,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),a.on("connection",(function(e){t("automator:runtime")(d("yyyy-mm-dd HH:MM:ss:l")+" connected");consto=newg(newy(e),r,"runtime");r.setRuntimeConnection(o),n(o)})),r.setRuntimeServer(a)})}}constv=t("automator:devtool");asyncfunctionb(e,t,r){const{port:o,cliPath:n,timeout:s,cwd:p="",account:m="",args:h=[],launch:w=!0}=t;letf=!1,y=!1;if(!1!==w){constt={stdio:"ignore",detached:!0};p&&(t.cwd=p);letr=l(h,[]);r=l(r,["auto","--project"]),r=l(r,[e,"--auto-port",c(o)]),m&&(r=l(r,["--auto-account",m]));try{v("%s %o %o",n,r,t);conste=a.spawn(n,r,t);e.on("error",e=>{f=!0}),e.on("exit",()=>{setTimeout(()=>{y=!0},15e3)}),e.unref()}catch(e){f=!1}}elsesetTimeout(()=>{y=!0},15e3);constb=awaitu(async()=>{try{if(f||y)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitg.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+o},r)}catch(e){}},s,1e3);if(f)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(y)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),v(d("yyyy-mm-dd HH:MM:ss:l")+" connected"),b}constq={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[r?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(s.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);leto=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{o=awaitasyncfunction(e,t){constr=awaitn(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(o)}catch(t){e.launch=!1}else{o===awaitn(o)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:o,cliPath:r})},asynccreate(e,r,o){constn=awaitb(e,r,o);returno.compiled?t("automator:devtool")("Waiting for runtime automator"):(t("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:r}=awaite("Tool.enableRemoteDebug",t,!1);returnr&&(r=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise(async(e,r)=>{constn=awaito.read(t),s=newf;s.callback=function(t,o){if(t)returnr(t);e(o.result)},s.decode(n.bitmap)})}(r)),{qrCode:r}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(r=t.functionDeclaration,"}"===r[r.length-1]?r.replace("{","{\nvar uni = wx;\n"):r.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varr}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=q;
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("debug")),r=e(require("licia/isWindows"));require("address"),require("default-gateway"),require("licia/isStr");varo=e(require("licia/getPort")),n=e(require("fs")),s=e(require("child_process")),a=e(require("licia/sleep")),i=e(require("licia/toStr")),c=e(require("licia/waitUntil")),u=e(require("licia/concat")),l=e(require("licia/dateFormat")),d=e(require("ws")),p=require("events"),m=e(require("licia/uuid")),h=e(require("licia/stringify"));require("qrcode-terminal");constw=require("qrcode-reader");classfextendsp.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",e=>{this.emit("message",e.data)}),this.ws.addEventListener("close",()=>{this.emit("close")})}send(e){this.ws.send(e)}close(){this.ws.close()}}classyextendsp.EventEmitter{constructor(e,r,o){super(),this.puppet=r,this.namespace=o,this.callbacks=newMap,this.transport=e,this.debug=t("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${l("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:o,result:n,params:s}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,s);const{callbacks:a}=this;if(t&&a.has(t)){conste=a.get(t);a.delete(t),o?e.reject(Error(o.message)):e.resolve(n)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consto=m(),n=h({id:o,method:e,params:t});returnthis.debug(`${l("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${n}`),newPromise((e,t)=>{try{this.transport.send(n)}catch(e){t(Error("Connection closed"))}this.callbacks.set(o,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,o)=>{constn=newd(e);n.addEventListener("open",()=>{r(newy(newf(n),t,"devtool"))}),n.addEventListener("error",o)})}staticcreateRuntimeConnection(e,r,o){returnnewPromise((n,s)=>{t("automator:runtime")(`${l("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newd.Server({port:e});c(async()=>{if(r.runtimeConnection)return!0},o,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),a.on("connection",(function(e){t("automator:runtime")(l("yyyy-mm-dd HH:MM:ss:l")+" connected");consto=newy(newf(e),r,"runtime");r.setRuntimeConnection(o),n(o)})),r.setRuntimeServer(a)})}}constg=t("automator:devtool");asyncfunctionv(e,t,r){const{port:o,cliPath:n,timeout:d,cwd:p="",account:m="",args:h=[],launch:w=!0}=t;letf=!1,v=!1;if(!1!==w){constt={stdio:"ignore",detached:!0};p&&(t.cwd=p);letr=u(h,[]);r=u(r,["auto","--project"]),r=u(r,[e,"--auto-port",i(o)]),m&&(r=u(r,["--auto-account",m]));try{g("%s %o %o",n,r,t);conste=s.spawn(n,r,t);e.on("error",e=>{f=!0}),e.on("exit",()=>{setTimeout(()=>{v=!0},15e3)}),e.unref()}catch(e){f=!1}}elsesetTimeout(()=>{v=!0},15e3);constb=awaitc(async()=>{try{if(f||v)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaity.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+o},r)}catch(e){}},d,1e3);if(f)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(v)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaita(5e3),g(l("yyyy-mm-dd HH:MM:ss:l")+" connected"),b}constb={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[r?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(n.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);lets=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{s=awaitasyncfunction(e,t){constr=awaito(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(s)}catch(t){e.launch=!1}else{s===awaito(s)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:s,cliPath:r})},asynccreate(e,r,o){constn=awaitv(e,r,o);returno.compiled?t("automator:devtool")("Waiting for runtime automator"):(t("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:r}=awaite("Tool.enableRemoteDebug",t,!1);returnr&&(r=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise(async(e,r)=>{consto=awaitrequire("jimp").read(t),n=neww;n.callback=function(t,o){if(t)returnr(t);e(o.result)},n.decode(o.bitmap)})}(r)),{qrCode:r}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(r=t.functionDeclaration,"}"===r[r.length-1]?r.replace("{","{\nvar uni = wx;\n"):r.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varr}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=b;