/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],u=0,a=i.length;u<a;u++,o++)r[o]=i[u];return r}var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),r=new Uint8Array(16);function o(){if(!n)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(r)}for(var i=[],u=0;u<256;++u)i[u]=(u+256).toString(16).substr(1);function a(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var u=(e=e||{}).random||(e.rng||o)();if(u[6]=15&u[6]|64,u[8]=63&u[8]|128,t)for(var a=0;a<16;++a)t[r+a]=u[a];return t||function(e,t){var n=t||0,r=i;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)}var c=Object.prototype.hasOwnProperty,s=function(e){return null==e},l=Array.isArray,f=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function g(e,t){if(l(e))return e;if(t&&(n=t,r=e,c.call(n,r)))return[e];var n,r,o=[];return e.replace(f,(function(e,t,n,r){return o.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),o}function d(e,t){var n,r=g(t,e);for(n=r.shift();!s(n);){if(null==(e=e[n]))return;n=r.shift()}return e}var p=new Map;function m(e){if(!function(e){if(e){var t=e.tagName;return 0===t.indexOf("UNI-")||"BODY"===t}return!1}(e))throw Error("no such element");var t,n,r={elementId:(t=e,n=t._id,n||(n=a(),t._id=n,p.set(n,{id:n,element:t})),n),tagName:e.tagName.toLocaleLowerCase().replace("uni-","")},o=e.__vue__;return o&&(o.$parent&&o.$parent.$el===e&&(o=o.$parent),o&&!o.$options.isReserved&&(r.nodeId=function(e){return e._uid}(o))),"video"===r.tagName&&(r.videoId=r.nodeId),r}var v={input:{input:function(e,t){var n=e.__vue__;n.valueSync=t,n.$triggerInput({},{value:t})}},textarea:{input:function(e,t){var n=e.__vue__;n.valueSync=t,n.$triggerInput({},{value:t})}},"scroll-view":{scrollTo:function(e,t,n){var r=e.__vue__.$refs.main;r.scrollLeft=t,r.scrollTop=n},scrollTop:function(e){return e.__vue__.$refs.main.scrollTop},scrollLeft:function(e){return e.__vue__.$refs.main.scrollLeft},scrollWidth:function(e){return e.__vue__.$refs.main.scrollWidth},scrollHeight:function(e){return e.__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){var n=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})}}};function h(e){var t,n=e.map((function(e){return function(e){if(document.createTouch)return document.createTouch(window,e.target,e.identifier,e.pageX,e.pageY,e.screenX,e.screenY);return new Touch(e)}(e)}));return document.createTouchList?(t=document).createTouchList.apply(t,n):n}var _={getWindow:function(e){return window},getDocument:function(e){return document},getEl:function(e){var t=p.get(e);if(!t)throw Error("element destroyed");return t.element},getOffset:function(e){var t=e.getBoundingClientRect();return Promise.resolve({left:t.left+window.pageXOffset,top:t.top+window.pageYOffset})},querySelector:function(e,t){return"page"===t&&(t="body"),Promise.resolve(m(e.querySelector(t)))},querySelectorAll:function(e,t){var n=[],r=document.querySelectorAll(t);return[].forEach.call(r,(function(e){try{n.push(m(e))}catch(e){}})),Promise.resolve({elements:n})},queryProperties:function(e,t){return Promise.resolve({properties:t.map((function(t){var n=d(e,t);return"document.documentElement.scrollTop"===t&&0===n&&(n=d(e,"document.body.scrollTop")),n}))})},queryAttributes:function(e,t){return Promise.resolve({attributes:t.map((function(t){return String(e.getAttribute(t))}))})},queryStyles:function(e,t){var n=getComputedStyle(e);return Promise.resolve({styles:t.map((function(e){return n[e]}))})},queryHTML:function(e,t){return Promise.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,"")})))});var n},dispatchTapEvent:function(e){return e.click(),Promise.resolve()},dispatchLongpressEvent:function(e){return Promise.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});var r=h(n.touches),o=h(n.changedTouches),i=h([]);return e.dispatchEvent(new TouchEvent(t,{cancelable:!0,bubbles:!0,touches:r,targetTouches:i,changedTouches:o})),Promise.resolve()},callFunction:function(e,n,r){var o=d(v,n);return o?Promise.resolve({result:o.apply(null,t([e],r))}):Promise.reject(Error(n+" not exists"))},triggerEvent:function(e,t,n){var r=e.__vue__;return r.$trigger&&r.$trigger(t,{},n),Promise.resolve()}};var y,S=Object.assign({},function(e){return{"Page.getElement":function(t){return e.querySelector(e.getDocument(t.pageId),t.selector)},"Page.getElements":function(t){return e.querySelectorAll(e.getDocument(t.pageId),t.selector)},"Page.getWindowProperties":function(t){return e.queryProperties(e.getWindow(t.pageId),t.names)}}}(_),function(e){var t=function(t){return e.getEl(t.elementId,t.pageId)};return{"Element.getElement":function(n){return e.querySelector(t(n),n.selector)},"Element.getElements":function(n){return e.querySelectorAll(t(n),n.selector)},"Element.getDOMProperties":function(n){return e.queryProperties(t(n),n.names)},"Element.getProperties":function(n){var r=t(n),o=r.__vue__||r.attr||{};return e.queryProperties(o,n.names)},"Element.getOffset":function(n){return e.getOffset(t(n))},"Element.getAttributes":function(n){return e.queryAttributes(t(n),n.names)},"Element.getStyles":function(n){return e.queryStyles(t(n),n.names)},"Element.getHTML":function(n){return e.queryHTML(t(n),n.type)},"Element.tap":function(n){return e.dispatchTapEvent(t(n))},"Element.longpress":function(n){return e.dispatchLongpressEvent(t(n))},"Element.touchstart":function(n){return e.dispatchTouchEvent(t(n),"touchstart",n)},"Element.touchmove":function(n){return e.dispatchTouchEvent(t(n),"touchmove",n)},"Element.touchend":function(n){return e.dispatchTouchEvent(t(n),"touchend",n)},"Element.callFunction":function(n){return e.callFunction(t(n),n.functionName,n.args)},"Element.triggerEvent":function(n){return e.triggerEvent(t(n),n.type,n.detail)}}}(_));function T(e){return UniViewJSBridge.publishHandler("onAutoMessageReceive",e)}function E(e){return e.__wxWebviewId__?e.__wxWebviewId__:e.privateProperties?e.privateProperties.slaveId:e.$page?e.$page.id:void 0}function w(e){return e.route||e.uri}function P(e){return e.options||e.$page&&e.$page.options||{}}function O(e){return{id:E(e),path:w(e),query:P(e)}}function b(e){var t=function(e){return getCurrentPages().find((function(t){return E(t)===e}))}(e);return t&&t.$vm}function I(e,t){var n;return e&&(!function(e,t){return e._uid===t}(e,t)?e.$children.find((function(e){return n=I(e,t)})):n=e),n}function M(e,t){var n=b(e);return n&&I(n,t)}function C(e,t){var n;return e&&(n=t?d(e.$data,t):Object.assign({},e.$data)),Promise.resolve({data:n})}function k(e,t){return e&&Object.keys(t).forEach((function(n){e[n]=t[n]})),Promise.resolve()}function $(e,t,n){return new Promise((function(r,o){if(!e)return o(y.VM_NOT_EXISTS);if(!e[t])return o(y.METHOD_NOT_EXISTS);var i,u=e[t].apply(e,n);!(i=u)||"object"!=typeof i&&"function"!=typeof i||"function"!=typeof i.then?r({result:u}):u.then((function(e){r({result:e})}))}))}UniViewJSBridge.subscribe("sendAutoMessage",(function(e){var t=e.id,n=e.method,r=e.params,o={id:t},i=S[n];if(!i)return o.error={message:n+" unimplemented"},T(o);try{i(r).then((function(e){e&&(o.result=e)})).catch((function(e){o.error={message:e.message}})).finally((function(){T(o)}))}catch(e){o.error={message:e.message},T(o)}})),function(e){e.VM_NOT_EXISTS="VM_NOT_EXISTS",e.METHOD_NOT_EXISTS="METHOD_NOT_EXISTS"}(y||(y={}));var x=new Map,A=function(t){return new Promise((function(n,r){var o=x.values().next().value;if(o){var i=t.method;if("onOpen"===i)return N(o,n);if(i.startsWith("on"))return o.instance[i]((function(e){n(e)}));"sendMessage"===i&&(i="send"),o.instance[i](e(e({},t),{success:function(e){n({result:e}),"close"===i&&x.delete(x.keys().next().value)},fail:function(e){r(e)}}))}else r({errMsg:"socketTask not exists."})}))};function N(e,t){if(e.isOpend)t({data:e.openData});else{var n=setInterval((function(){e.isOpend&&(clearInterval(n),t(e.openData))}),200);setTimeout((function(){clearInterval(n)}),2e3)}}var W=["stopRecord","getRecorderManager","pauseVoice","stopVoice","pauseBackgroundAudio","stopBackgroundAudio","getBackgroundAudioManager","createAudioContext","createInnerAudioContext","createVideoContext","createCameraContext","createMapContext","canIUse","startAccelerometer","stopAccelerometer","startCompass","stopCompass","hideToast","hideLoading","showNavigationBarLoading","hideNavigationBarLoading","navigateBack","createAnimation","pageScrollTo","createSelectorQuery","createCanvasContext","createContext","drawCanvas","hideKeyboard","stopPullDownRefresh","arrayBufferToBase64","base64ToArrayBuffer"],B=new Map,D=["onCompassChange","onThemeChange","onUserCaptureScreen","onWindowResize","onMemoryWarning","onAccelerometerChange","onKeyboardHeightChange","onNetworkStatusChange","onPushMessage","onLocationChange","onGetWifiList","onWifiConnected","onWifiConnectedWithPartialInfo","onSocketOpen","onSocketError","onSocketMessage","onSocketClose"],q={},L=/^\$|Sync$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback|getWindowInfo|getDeviceInfo|getAppBaseInfo|getSystemSetting|getAppAuthorizeSetting|initUTS|requireUTS|registerUTS/,V=/^on|^off/;function H(e){return L.test(e)||-1!==W.indexOf(e)}var R={getPageStack:function(){return Promise.resolve({pageStack:getCurrentPages().map((function(e){return O(e)}))})},getCurrentPage:function(){var e=getCurrentPages(),t=e.length;return new Promise((function(n,r){t?n(O(e[t-1])):r(Error("getCurrentPages().length=0"))}))},callUniMethod:function(t){var n=t.method,r=t.args;return new Promise((function(t,o){if("connectSocket"!==n){var i,u;if(D.includes(n)){B.has(n)||B.set(n,new Map);var a=r[0],c=function(e){z({id:a,result:{method:n,data:e}})};return n.startsWith("onSocket")?A({method:n.replace("Socket","")}).then((function(e){return c(e)})).catch((function(e){return c(e)})):(B.get(n).set(a,c),uni[n](c)),t({result:null})}if(n.startsWith("off")&&D.includes(n.replace("off","on"))){var s=n.replace("off","on");if(B.has(s)){var l=r[0];if(void 0!==l){var f=B.get(s).get(l);uni[n](f),B.get(s).delete(l)}else{B.get(s).forEach((function(e){uni[n](e)})),B.delete(s)}}return t({result:null})}if(n.indexOf("Socket")>0)return A(e({method:n.replace("Socket","")},r[0])).then((function(e){return t(e)})).catch((function(e){return o(e)}));if(!uni[n])return o(Error("uni."+n+" not exists"));if(H(n))return t({result:uni[n].apply(uni,r)});var g=[Object.assign({},r[0]||{},{success:function(e){setTimeout((function(){t({result:e})}),"pageScrollTo"===n?350:0)},fail:function(e){o(Error(e.errMsg.replace(n+":fail ","")))}})];uni[n].apply(uni,g)}else(i=r[0].id,u=r[0].url,new Promise((function(e,t){var n=uni.connectSocket({url:u,success:function(){e({result:{errMsg:"connectSocket:ok"}})},fail:function(){t({result:{errMsg:"connectSocket:fail"}})}});x.set(i,{instance:n,isOpend:!1}),n.onOpen((function(e){x.get(i).isOpend=!0,x.get(i).openData=e}))}))).then((function(e){return t(e)})).catch((function(e){return o(e)}))}))},mockUniMethod:function(e){var t=e.method;if(!uni[t])throw Error("uni."+t+" not exists");if(!function(e){return!V.test(e)}(t))throw Error("You can't mock uni."+t);var n,r=e.result,o=e.functionDeclaration;return s(r)&&s(o)?(q[t]&&(uni[t]=q[t],delete q[t]),Promise.resolve()):(n=s(o)?H(t)?function(){return r}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)}:function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new Function("return "+o)().apply(n,t.concat(e.args))},n.origin=q[t]||uni[t],q[t]||(q[t]=uni[t]),uni[t]=n,Promise.resolve())},captureScreenshot:function(e){return new Promise((function(t,n){var r=getCurrentPages(),o=r.length;if(o){var i=r[o-1];if(i){var u=i.$getAppWebview(),a=new plus.nativeObj.Bitmap("captureScreenshot","captureScreenshot.png");u.draw(a,(function(e){var n=a.toBase64Data().replace("data:image/png;base64,","");a.clear(),t({data:n})}),(function(e){n(Error("captureScreenshot fail: "+e.message))}),{wholeContent:!!e.fullPage})}}else n(Error("getCurrentPage fail."))}))},socketEmitter:function(t){return new Promise((function(n,r){(function(t){return new Promise((function(n,r){if(x.has(t.id)){var o=x.get(t.id),i=o.instance,u=t.method,a=t.id;if("onOpen"==u)return N(o,n);if(u.startsWith("on"))return i[u]((function(e){n({method:"Socket."+u,id:a,data:e})}));i[u](e(e({},t),{success:function(e){n(e),"close"===u&&x.delete(t.id)},fail:function(e){r(e)}}))}else r({errMsg:"socketTask not exists."})}))})(t).then((function(e){return n(e)})).catch((function(e){return r(e)}))}))}},U=R,j={getData:function(e){return C(b(e.pageId),e.path)},setData:function(e){return k(b(e.pageId),e.data)},callMethod:function(e){var t,n=((t={})[y.VM_NOT_EXISTS]="Page["+e.pageId+"] not exists",t[y.METHOD_NOT_EXISTS]="page."+e.method+" not exists",t);return new Promise((function(t,r){$(b(e.pageId),e.method,e.args).then((function(e){return t(e)})).catch((function(e){r(Error(n[e]))}))}))},callMethodWithCallback:function(e){var t,n=((t={})[y.VM_NOT_EXISTS]="callMethodWithCallback:fail, Page["+e.pageId+"] not exists",t[y.METHOD_NOT_EXISTS]="callMethodWithCallback:fail, page."+e.method+" not exists",t),r=e.args[e.args.length-1];$(b(e.pageId),e.method,e.args).catch((function(e){r({errMsg:n[e]})}))}};function X(e){return e.nodeId||e.elementId}var J={getData:function(e){return C(M(e.pageId,X(e)),e.path)},setData:function(e){return k(M(e.pageId,X(e)),e.data)},callMethod:function(e){var t,n=X(e),r=((t={})[y.VM_NOT_EXISTS]="Component["+e.pageId+":"+n+"] not exists",t[y.METHOD_NOT_EXISTS]="component."+e.method+" not exists",t);return new Promise((function(t,o){$(M(e.pageId,n),e.method,e.args).then((function(e){return t(e)})).catch((function(e){o(Error(r[e]))}))}))}},Y={};Object.keys(U).forEach((function(e){Y["App."+e]=U[e]})),Object.keys(j).forEach((function(e){Y["Page."+e]=j[e]})),Object.keys(J).forEach((function(e){Y["Element."+e]=J[e]}));var F,G,K=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function z(e){G.send({data:JSON.stringify(e)})}function Q(e){var t=JSON.parse(e.data),n=t.id,r=t.method,o=t.params,i={id:n},u=Y[r];if(!u){if(F){var a=F(n,r,o,i);if(!0===a)return;u=a}if(!u)return i.error={message:r+" unimplemented"},z(i)}try{u(o).then((function(e){e&&(i.result=e)})).catch((function(e){i.error={message:e.message}})).finally((function(){z(i)}))}catch(e){i.error={message:e.message},z(i)}}F=function(e,t,n,r){var o=n.pageId,i=function(e){var t=getCurrentPages();if(!e)return t[t.length-1];return t.find((function(t){return t.$page.id===e}))}(o);return i?(i.$page.meta.isNVue,UniServiceJSBridge.publishHandler("sendAutoMessage",{id:e,method:t,params:n},o),!0):(r.error={message:"page["+o+"] not exists"},z(r),!0)},UniServiceJSBridge.subscribe("onAutoMessageReceive",(function(e){z(e)})),setTimeout((function(){var e;void 0===e&&(e={}),(G=uni.connectSocket({url:K,complete:function(){}})).onMessage(Q),G.onOpen((function(t){e.success&&e.success(),console.log("已开启自动化测试...")})),G.onError((function(e){console.log("automator.onError",e)})),G.onClose((function(){e.fail&&e.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))}),500);
