functione(){for(vare=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;varn=Array(e),o=0;for(t=0;t<r;t++)for(varu=arguments[t],i=0,c=u.length;i<c;i++,o++)n[o]=u[i];returnn}vart="undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),r=newUint8Array(16);functionn(){if(!t)thrownewError("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");returnt(r)}for(varo=[],u=0;u<256;++u)o[u]=(u+256).toString(16).substr(1);functioni(e,t,r){varu=t&&r||0;"string"==typeofe&&(t="binary"===e?newArray(16):null,e=null);vari=(e=e||{}).random||(e.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(varc=0;c<16;++c)t[u+c]=i[c];returnt||function(e,t){varr=t||0,n=o;return[n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]]].join("")}(i)}varc=Object.prototype.hasOwnProperty,a=Array.isArray,s=function(e){vart=Object.create(null);returnfunction(r){returnt[r]||(t[r]=e(r))}},l=/-(\w)/g,f=s((function(e){returne.replace(l,(function(e,t){returnt?t.toUpperCase():""}))})),p=s((function(e){returne.charAt(0).toUpperCase()+e.slice(1)})),g=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functiond(e,t){if(a(e))returne;if(t&&(r=t,n=e,c.call(r,n)))return[e];varr,n,o=[];returne.replace(g,(function(e,t,r,n){returno.push(r?n.replace(/\\(\\)?/g,"$1"):t||e),n})),o}functionm(e,t){varr,n=d(t,e);for(r=n.shift();null!=r;){if(null==(e=e[r]))return;r=n.shift()}returne}varv=newMap;functionh(e){if(!function(e){if(e){vart=e.tagName;return0===t.indexOf("UNI-")||"BODY"===t}return!1}(e))throwError("no such element");vart,r,n={elementId:(t=e,r=t._id,r||(r=i(),t._id=r,v.set(r,{id:r,element:t})),r),tagName:e.tagName.toLocaleLowerCase().replace("uni-","")},o=e.__vue__;returno&&(o.$parent&&o.$parent.$el===e&&(o=o.$parent),o&&!o.$options.isReserved&&(n.nodeId=function(e){if(e._$weex)returne._uid;if(e._$id)returne._$id;vart=function(e){for(vart=e.$parent;t;){if(t._$id)returnt;t=t.$parent}}(e);if(!e.$parent)return"-1";varr=e.$vnode,n=r.context;returnn&&n!==t&&n._$id?n._$id+";"+t._$id+","+r.data.attrs._i:t._$id+","+r.data.attrs._i}(o))),"video"===n.tagName&&(n.videoId=n.nodeId),console.log(n),n}var_={input:{input:function(e,t){varr=e.__vue__;r.valueSync=t,r.$triggerInput({},{value:t})}},textarea:{input:function(e,t){varr=e.__vue__;r.valueSync=t,r.$triggerInput({},{value:t})}},"scroll-view":{scrollTo:function(e,t,r){varn=e.__vue__.$refs.main;n.scrollLeft=t,n.scrollTop=r},scrollTop:function(e){returne.__vue__.$refs.main.scrollTop},scrollLeft:function(e){returne.__vue__.$refs.main.scrollLeft},scrollWidth:function(e){returne.__vue__.$refs.main.scrollWidth},scrollHeight:function(e){returne.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(e,t){e.__vue__.current=t}},"movable-view":{moveTo:function(e,t,r){e.__vue__._animationTo(t,r)}},switch:{tap:function(e){e.click()}},slider:{slideTo:function(e,t){varr=e.__vue__,n=r.$refs["uni-slider"],o=n.offsetWidth,u=n.getBoundingClientRect().left;r.value=t,r._onClick({x:(t-r.min)*o/(r.max-r.min)+u})}}},y={getWindow:function(e){returnwindow},getDocument:function(e){returndocument},getEl:function(e){vart=v.get(e);if(!t)throwError("element destroyed");returnt.element},getOffset:function(e){vart=e.getBoundingClientRect();returnPromise.resolve({left:t.left+window.pageXOffset,top:t.top+window.pageYOffset})},querySelector:function(e,t){return"page"===t&&(t="body"),Promise.resolve(h(e.querySelector(t)))},querySelectorAll:function(e,t){varr=[],n=document.querySelectorAll(t);return[].forEach.call(n,(function(e){try{r.push(h(e))}catch(e){}})),Promise.resolve({elements:r})},queryProperties:function(e,t){returnPromise.resolve({properties:t.map((function(t){varr=m(e,t);return"document.documentElement.scrollTop"===t&&0===r&&(r=m(e,"document.body.scrollTop")),r}))})},queryAttributes:function(e,t){returnPromise.resolve({attributes:t.map((function(t){returnString(e.getAttribute(t))}))})},queryStyles:function(e,t){varr=getComputedStyle(e);returnPromise.resolve({styles:t.map((function(e){returnr[e]}))})},queryHTML:function(e,t){returnPromise.resolve({html:(r="outer"===t?e.outerHTML:e.innerHTML,r.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1<e.indexOf("<body")?"<page>":"</body>"===e?"</page>":0!==e.indexOf("<uni-")&&0!==e.indexOf("</uni-")?"":e.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});varr},dispatchTapEvent:function(e){returne.click(),Promise.resolve()},dispatchLongpressEvent:function(e){returnPromise.resolve()},dispatchTouchEvent:function(e,t,r){r||(r={}),r.touches||(r.touches=[]),r.changedTouches||(r.changedTouches=[]),r.touches.length||r.touches.push({identifier:Date.now(),target:e});varn=r.touches.map((function(e){returnnewTouch(e)})),o=r.changedTouches.map((function(e){returnnewTouch(e)}));returne.dispatchEvent(newTouchEvent(t,{cancelable:!0,bubbles:!0,touches:n,targetTouches:[],changedTouches:o})),Promise.resolve()},callFunction:function(t,r,n){varo=m(_,r);returno?Promise.resolve({result:o.apply(null,e([t],n))}):Promise.reject(Error(r+" not exists"))},triggerEvent:function(e,t,r){varn=e.__vue__;returnn.$trigger&&n.$trigger(t,{},r),Promise.resolve()}};["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(e){returnp(f(e))}));varE=Object.assign({},function(e){return{"Page.getElement":function(t){returne.querySelector(e.getDocument(t.pageId),t.selector)},"Page.getElements":function(t){returne.querySelectorAll(e.getDocument(t.pageId),t.selector)},"Page.getWindowProperties":function(t){returne.queryProperties(e.getWindow(t.pageId),t.names)}}}(y),function(e){vart=function(t){returne.getEl(t.elementId,t.pageId)};return{"Element.getElement":function(r){returne.querySelector(t(r),r.selector)},"Element.getElements":function(r){returne.querySelectorAll(t(r),r.selector)},"Element.getDOMProperties":function(r){returne.queryProperties(t(r),r.names)},"Element.getProperties":function(r){varn=t(r),o=n.__vue__||n.attr||{};returne.queryProperties(o,r.names)},"Element.getOffset":function(r){returne.getOffset(t(r))},"Element.getAttributes":function(r){returne.queryAttributes(t(r),r.names)},"Element.getStyles":function(r){returne.queryStyles(t(r),r.names)},"Element.getHTML":function(r){returne.queryHTML(t(r),r.type)},"Element.tap":function(r){returne.dispatchTapEvent(t(r))},"Element.longpress":function(r){returne.dispatchLongpressEvent(t(r))},"Element.touchstart":function(r){returne.dispatchTouchEvent(t(r),"touchstart",r)},"Element.touchmove":function(r){returne.dispatchTouchEvent(t(r),"touchmove",r)},"Element.touchend":function(r){returne.dispatchTouchEvent(t(r),"touchend",r)},"Element.callFunction":function(r){returne.callFunction(t(r),r.functionName,r.args)},"Element.triggerEvent":function(r){returne.triggerEvent(t(r),r.type,r.detail)}}}(y));functionw(e){returnUniViewJSBridge.publishHandler("onAutoMessageReceive",e)}UniViewJSBridge.subscribe("sendAutoMessage",(function(e){vart=e.id,r=e.method,n=e.params,o={id:t},u=E[r];if(!u)returno.error={message:r+" unimplemented"},w(o);try{u(n).then((function(e){e&&(o.result=e)})).catch((function(e){o.error={message:e.message}})).finally((function(){w(o)}))}catch(e){o.error={message:e.message},w(o)}}));
functione(){for(vare=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;varr=Array(e),o=0;for(t=0;t<n;t++)for(vari=arguments[t],u=0,c=i.length;u<c;u++,o++)r[o]=i[u];returnr}!function(e,t){"object"==typeofexports&&"undefined"!=typeofmodule?t():"function"==typeofdefine&&define.amd?define(t):t()}(0,(function(){functione(e){vart=this.constructor;returnthis.then((function(n){returnt.resolve(e()).then((function(){returnn}))}),(function(n){returnt.resolve(e()).then((function(){returnt.reject(n)}))}))}functiont(e){return!(!e||void0===e.length)}functionn(){}functionr(e){if(!(thisinstanceofr))thrownewTypeError("Promises must be constructed via new");if("function"!=typeofe)thrownewTypeError("not a function");this._state=0,this._handled=!1,this._value=void0,this._deferreds=[],a(e,this)}functiono(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,r._immediateFn((function(){varn=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){varr;try{r=n(e._value)}catch(e){returnvoidu(t.promise,e)}i(t.promise,r)}else(1===e._state?i:u)(t.promise,e._value)}))):e._deferreds.push(t)}functioni(e,t){try{if(t===e)thrownewTypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeoft||"function"==typeoft)){varn=t.then;if(tinstanceofr)returne._state=3,e._value=t,voidc(e);if("function"==typeofn)returnvoida(function(e,t){returnfunction(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,c(e)}catch(t){u(e,t)}}functionu(e,t){e._state=2,e._value=t,c(e)}functionc(e){2===e._state&&0===e._deferreds.length&&r._immediateFn((function(){e._handled||r._unhandledRejectionFn(e._value)}));for(vart=0,n=e._deferreds.length;n>t;t++)o(e,e._deferreds[t]);e._deferreds=null}functiona(e,t){varn=!1;try{e((function(e){n||(n=!0,i(t,e))}),(function(e){n||(n=!0,u(t,e))}))}catch(e){if(n)return;n=!0,u(t,e)}}vars=setTimeout;r.prototype.catch=function(e){returnthis.then(null,e)},r.prototype.then=function(e,t){varr=newthis.constructor(n);returno(this,newfunction(e,t,n){this.onFulfilled="function"==typeofe?e:null,this.onRejected="function"==typeoft?t:null,this.promise=n}(e,t,r)),r},r.prototype.finally=e,r.all=function(e){returnnewr((function(n,r){functiono(e,t){try{if(t&&("object"==typeoft||"function"==typeoft)){varc=t.then;if("function"==typeofc)returnvoidc.call(t,(function(t){o(e,t)}),r)}i[e]=t,0==--u&&n(i)}catch(e){r(e)}}if(!t(e))returnr(newTypeError("Promise.all accepts an array"));vari=Array.prototype.slice.call(e);if(0===i.length)returnn([]);for(varu=i.length,c=0;i.length>c;c++)o(c,i[c])}))},r.resolve=function(e){returne&&"object"==typeofe&&e.constructor===r?e:newr((function(t){t(e)}))},r.reject=function(e){returnnewr((function(t,n){n(e)}))},r.race=function(e){returnnewr((function(n,o){if(!t(e))returno(newTypeError("Promise.race accepts an array"));for(vari=0,u=e.length;u>i;i++)r.resolve(e[i]).then(n,o)}))},r._immediateFn="function"==typeofsetImmediate&&function(e){setImmediate(e)}||function(e){s(e,0)},r._unhandledRejectionFn=function(e){void0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};varl=function(){if("undefined"!=typeofself)returnself;if("undefined"!=typeofwindow)returnwindow;if("undefined"!=typeofglobal)returnglobal;throwError("unable to locate global object")}();"Promise"inl?l.Promise.prototype.finally||(l.Promise.prototype.finally=e):l.Promise=r}));vart="undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),n=newUint8Array(16);functionr(){if(!t)thrownewError("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");returnt(n)}for(varo=[],i=0;i<256;++i)o[i]=(i+256).toString(16).substr(1);functionu(e,t,n){vari=t&&n||0;"string"==typeofe&&(t="binary"===e?newArray(16):null,e=null);varu=(e=e||{}).random||(e.rng||r)();if(u[6]=15&u[6]|64,u[8]=63&u[8]|128,t)for(varc=0;c<16;++c)t[i+c]=u[c];returnt||function(e,t){varn=t||0,r=o;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}(u)}varc=Object.prototype.hasOwnProperty,a=Array.isArray,s=function(e){vart=Object.create(null);returnfunction(n){returnt[n]||(t[n]=e(n))}},l=/-(\w)/g,f=s((function(e){returne.replace(l,(function(e,t){returnt?t.toUpperCase():""}))})),d=s((function(e){returne.charAt(0).toUpperCase()+e.slice(1)})),p=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functionm(e,t){if(a(e))returne;if(t&&(n=t,r=e,c.call(n,r)))return[e];varn,r,o=[];returne.replace(p,(function(e,t,n,r){returno.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),o}functionv(e,t){varn,r=m(t,e);for(n=r.shift();null!=n;){if(null==(e=e[n]))return;n=r.shift()}returne}varh=newMap;functiong(e){if(!function(e){if(e){vart=e.tagName;return0===t.indexOf("UNI-")||"BODY"===t}return!1}(e))throwError("no such element");vart,n,r={elementId:(t=e,n=t._id,n||(n=u(),t._id=n,h.set(n,{id:n,element:t})),n),tagName:e.tagName.toLocaleLowerCase().replace("uni-","")},o=e.__vue__;returno&&(o.$parent&&o.$parent.$el===e&&(o=o.$parent),o&&!o.$options.isReserved&&(r.nodeId=function(e){if(e._$weex)returne._uid;if(e._$id)returne._$id;vart=function(e){for(vart=e.$parent;t;){if(t._$id)returnt;t=t.$parent}}(e);if(!e.$parent)return"-1";varn=e.$vnode,r=n.context;returnr&&r!==t&&r._$id?r._$id+";"+t._$id+","+n.data.attrs._i:t._$id+","+n.data.attrs._i}(o))),"video"===r.tagName&&(r.videoId=r.nodeId),r}var_={input:{input:function(e,t){varn=e.__vue__;n.valueSync=t,n.$triggerInput({},{value:t})}},textarea:{input:function(e,t){varn=e.__vue__;n.valueSync=t,n.$triggerInput({},{value:t})}},"scroll-view":{scrollTo:function(e,t,n){varr=e.__vue__.$refs.main;r.scrollLeft=t,r.scrollTop=n},scrollTop:function(e){returne.__vue__.$refs.main.scrollTop},scrollLeft:function(e){returne.__vue__.$refs.main.scrollLeft},scrollWidth:function(e){returne.__vue__.$refs.main.scrollWidth},scrollHeight:function(e){returne.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(e,t){e.__vue__.current=t}},"movable-view":{moveTo:function(e,t,n){e.__vue__._animationTo(t,n)}},switch:{tap:function(e){e.click()}},slider:{slideTo:function(e,t){varn=e.__vue__,r=n.$refs["uni-slider"],o=r.offsetWidth,i=r.getBoundingClientRect().left;n.value=t,n._onClick({x:(t-n.min)*o/(n.max-n.min)+i})}}},y={getWindow:function(e){returnwindow},getDocument:function(e){returndocument},getEl:function(e){vart=h.get(e);if(!t)throwError("element destroyed");returnt.element},getOffset:function(e){vart=e.getBoundingClientRect();returnPromise.resolve({left:t.left+window.pageXOffset,top:t.top+window.pageYOffset})},querySelector:function(e,t){return"page"===t&&(t="body"),Promise.resolve(g(e.querySelector(t)))},querySelectorAll:function(e,t){varn=[],r=document.querySelectorAll(t);return[].forEach.call(r,(function(e){try{n.push(g(e))}catch(e){}})),Promise.resolve({elements:n})},queryProperties:function(e,t){returnPromise.resolve({properties:t.map((function(t){varn=v(e,t);return"document.documentElement.scrollTop"===t&&0===n&&(n=v(e,"document.body.scrollTop")),n}))})},queryAttributes:function(e,t){returnPromise.resolve({attributes:t.map((function(t){returnString(e.getAttribute(t))}))})},queryStyles:function(e,t){varn=getComputedStyle(e);returnPromise.resolve({styles:t.map((function(e){returnn[e]}))})},queryHTML:function(e,t){returnPromise.resolve({html:(n="outer"===t?e.outerHTML:e.innerHTML,n.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1<e.indexOf("<body")?"<page>":"</body>"===e?"</page>":0!==e.indexOf("<uni-")&&0!==e.indexOf("</uni-")?"":e.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});varn},dispatchTapEvent:function(e){returne.click(),Promise.resolve()},dispatchLongpressEvent:function(e){returnPromise.resolve()},dispatchTouchEvent:function(e,t,n){n||(n={}),n.touches||(n.touches=[]),n.changedTouches||(n.changedTouches=[]),n.touches.length||n.touches.push({identifier:Date.now(),target:e});varr=n.touches.map((function(e){returnnewTouch(e)})),o=n.changedTouches.map((function(e){returnnewTouch(e)}));returne.dispatchEvent(newTouchEvent(t,{cancelable:!0,bubbles:!0,touches:r,targetTouches:[],changedTouches:o})),Promise.resolve()},callFunction:function(t,n,r){varo=v(_,n);returno?Promise.resolve({result:o.apply(null,e([t],r))}):Promise.reject(Error(n+" not exists"))},triggerEvent:function(e,t,n){varr=e.__vue__;returnr.$trigger&&r.$trigger(t,{},n),Promise.resolve()}};["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(e){returnd(f(e))}));varw=Object.assign({},function(e){return{"Page.getElement":function(t){returne.querySelector(e.getDocument(t.pageId),t.selector)},"Page.getElements":function(t){returne.querySelectorAll(e.getDocument(t.pageId),t.selector)},"Page.getWindowProperties":function(t){returne.queryProperties(e.getWindow(t.pageId),t.names)}}}(y),function(e){vart=function(t){returne.getEl(t.elementId,t.pageId)};return{"Element.getElement":function(n){returne.querySelector(t(n),n.selector)},"Element.getElements":function(n){returne.querySelectorAll(t(n),n.selector)},"Element.getDOMProperties":function(n){returne.queryProperties(t(n),n.names)},"Element.getProperties":function(n){varr=t(n),o=r.__vue__||r.attr||{};returne.queryProperties(o,n.names)},"Element.getOffset":function(n){returne.getOffset(t(n))},"Element.getAttributes":function(n){returne.queryAttributes(t(n),n.names)},"Element.getStyles":function(n){returne.queryStyles(t(n),n.names)},"Element.getHTML":function(n){returne.queryHTML(t(n),n.type)},"Element.tap":function(n){returne.dispatchTapEvent(t(n))},"Element.longpress":function(n){returne.dispatchLongpressEvent(t(n))},"Element.touchstart":function(n){returne.dispatchTouchEvent(t(n),"touchstart",n)},"Element.touchmove":function(n){returne.dispatchTouchEvent(t(n),"touchmove",n)},"Element.touchend":function(n){returne.dispatchTouchEvent(t(n),"touchend",n)},"Element.callFunction":function(n){returne.callFunction(t(n),n.functionName,n.args)},"Element.triggerEvent":function(n){returne.triggerEvent(t(n),n.type,n.detail)}}}(y));functionE(e){returnUniViewJSBridge.publishHandler("onAutoMessageReceive",e)}UniViewJSBridge.subscribe("sendAutoMessage",(function(e){vart=e.id,n=e.method,r=e.params,o={id:t},i=w[n];if(!i)returno.error={message:n+" unimplemented"},E(o);try{i(r).then((function(e){e&&(o.result=e)})).catch((function(e){o.error={message:e.message}})).finally((function(){E(o)}))}catch(e){o.error={message:e.message},E(o)}}));
"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"),/^win/.test(process.platform);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("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"),/^win/.test(process.platform);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(()=>{o.close(),n("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"),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");/^win/.test(process.platform);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;
"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");/^win/.test(process.platform);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(()=>{a.close(),s("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;