Socket
Socket
Sign inDemoInstall

@huolala-tech/page-spy-alipay

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huolala-tech/page-spy-alipay - npm Package Compare versions

Comparing version 1.8.10 to 1.9.0

2

dist/cjs/index.min.js

@@ -1,2 +0,2 @@

"use strict";const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[r,n]=e;t.push("".concat(r,"=").concat(n))})),t.join("&")};let t;const r=()=>{if(!t)throw Error("the mp sdk is not set");return t};let n={};const s={setStorage(e,r){var n;return null===(n=t)||void 0===n?void 0:n.setStorageSync(e,r)},getStorage(e){var r;return null===(r=t)||void 0===r?void 0:r.getStorageSync(e)},removeStorage(e){var r;return null===(r=t)||void 0===r?void 0:r.getStorageSync(e)}};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:t+""}function i(e,t,r){return(t=a(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(){return Math.random().toString(36).slice(2)}function l(e){return Object.prototype.toString.call(e)}function u(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function h(e){return"[object BigInt]"===l(e)}function d(e){return e instanceof Array}function p(e){return"object"==typeof e&&null!==e}function g(e){return!(!p(e)||"[object Object]"!==l(e))}const m=e=>"".concat(e),f=e=>({ok:!0,value:e});function y(e){return void 0===e?f(m(e)):null===e?f(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?f(m(e)):h(e)?f("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?f(m(e.toString())):e instanceof Error?f(m(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:f(e)}function S(e){return void 0===e?"undefined":null===e?"null":h(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const b={...console},v=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...r)},e.unproxy[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];b[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...r)},e)),{unproxy:{}});function E(e){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},E(e)}function C(e){var t=function(e,t){if("object"!=E(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=E(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==E(t)?t:t+""}function w(e,t,r){return(t=C(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const k="message",x="broadcast",I="ping",T="updateRoomInfo";var O=Object.freeze({__proto__:null,BROADCAST:x,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:k,PING:I,PONG:"pong",UPDATE_ROOM_INFO:T});function j(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:c()},...t}}}class N{constructor(){w(this,"store",{}),w(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:r}=y(e);return r?{id:c(),type:S(e),value:t}:this.add(e)}get(e){const t=this.store[e],r=this.instanceStore[e];if(!t)return null;const n={},s=Object.getOwnPropertyDescriptors(t);Object.keys(s).forEach((e=>{const t=s[e];u(t,"value")&&(t.value=this.transformToAtom(t.value)),n[e]=N.getAtomOverview({atomId:c(),instanceId:r,value:t})}));const o=this.addExtraProperty(e);return{...n,...o}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const r=c();let n=r;var s;p(s=e)&&u(s,"constructor")&&"function"==typeof s.constructor&&(n=t),this.store[r]=e,this.instanceStore[r]=n;const o=N.getSemanticValue(e);return N.getAtomOverview({atomId:r,value:o,instanceId:n})}static getAtomOverview(e){let{instanceId:t="",atomId:r,value:n}=e;return{id:c(),type:"atom",__atomId:r,instanceId:t,value:n}}static getSemanticValue(e){if(g(e))return"Object {...}";if(d(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],r=this.instanceStore[e],n={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(n["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let r=0;for(const n of t)e[r++]=n;e.size=t.size,n["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let r=0;for(const[n,s]of t.entries())e[r++]={key:n,value:s};e.size=t.size,n["[[Entries]]"]=this.transformToAtom(e)}var s;return(d(t)||(s=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&s instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&s instanceof HTMLCollection))&&(n.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?n["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),r):n.___proto___=this.transformToAtom(null),n}}var P=new N;const R=e=>{let{osType:t,osVersion:r,browserType:n,browserVersion:s}=e;return"".concat(t,"/").concat(r," ").concat(n,"/").concat(s)};class H{static makeClientInfoMsg(){const e=H.info.ua||R(H.info);return{sdk:H.info.sdk,isDevTools:H.info.isDevTools,ua:e,plugins:H.plugins}}}var D;w(H,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"}),w(H,"plugins",[]),function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(D||(D={}));const U=2e3,M=Math.pow(1.5,4)*U;class q{constructor(){w(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class F{constructor(){w(this,"socketUrl",""),w(this,"socketConnection",null),w(this,"debuggerConnection",null),w(this,"pingTimer",null),w(this,"pongTimer",null),w(this,"retryTimer",null),w(this,"isOffline",!1),w(this,"messageCapacity",0),w(this,"messages",[]),w(this,"events",{debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[]}),w(this,"retryInterval",U),w(this,"connectable",!0),this.addListener("atom-detail",F.handleResolveAtom),this.addListener("atom-getter",F.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}async init(e){try{var t,r,n,s,o;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===D.OPEN&&await new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()})),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(r=this.socketWrapper)||void 0===r||r.onMessage((e=>{this.handleMessage(e)})),null===(n=this.socketWrapper)||void 0===n||n.onClose((()=>{this.connectOffline()})),null===(s=this.socketWrapper)||void 0===s||s.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(o=this.socketWrapper)||void 0===o||o.init(e)}catch(e){v.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=function(e){return{type:x,content:{data:e}}}(e);this.send(r,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,r]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||r.splice(0)}))}connectOnline(){this.retryInterval=U,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<M&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;F.messageFilters.length&&F.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:r,MESSAGE:n,ERROR:s,JOIN:o,PING:a,PONG:i,LEAVE:c,CLOSE:l,BROADCAST:u}=O,h=JSON.parse(e.data),{type:d}=h;switch(d){case r:const{selfConnection:e,roomConnections:a}=h.content;this.socketConnection=e,this.debuggerConnection=a.find((e=>"Debugger"===e.userId))||null;break;case o:case c:const{connection:i}=h.content;"Debugger"===i.userId&&(d===o?(this.debuggerConnection=i,this.sendClientInfo()):this.debuggerConnection=null);break;case n:const{data:u,from:p,to:g}=h.content;g.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:p,to:g});break;case l:case s:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var r;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(r=this.events[e])||void 0===r||r.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const r=function(e,t,r){return{type:k,content:{data:e,from:t,to:r}}}(e,this.socketConnection,t);this.send(r)}handleFlushBuffer(e){const{latestId:t}=e.source.data,r=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(r+1).forEach((t=>{const r={type:k,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(r,!0)}))}static handleResolveAtom(e,t){let{source:r}=e;const{type:n,data:s}=r;if("atom-detail"===n){const e=P.get(s)||{};t(j("atom-detail-".concat(s),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:r}=e;const{type:n,data:s}=r;if("atom-getter"===n){const{id:e,parentId:r,key:n,instanceId:a}=s,i=P.getOrigin(a),c=P.getOrigin(r);let l={};var o;if(i&&c)l=null===(o=Object.getOwnPropertyDescriptor(c,n))||void 0===o||null===(o=o.get)||void 0===o?void 0:o.call(i);else l=new Error("Getter computed failed");t(j("atom-getter-".concat(e),P.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.checkIfSend(e))try{var r;const t=e;t.createdAt=Date.now(),t.requestId=c();const n=function(e){const{ok:t,value:r}=y(e);return t?r:JSON.stringify(e,((e,t)=>y(t).value),2)}(t);null===(r=this.socketWrapper)||void 0===r||r.send(n)}catch(e){v.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,t)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===D.OPEN&&(!![T,I].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![k,I].includes(e.type)}sendClientInfo(){const e=H.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}w(F,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}async init(e){this.state=D.CONNECTING;const t=r(),n=e=>{this.state=D.CLOSED,this.emit("close",e)},s=e=>{this.state=D.OPEN,this.emit("open",e)},o=e=>{this.state=D.CLOSED,this.emit("error",e)},a=e=>{this.emit("message",e)};if(L.isSingleSocket)t.connectSocket({url:e}),t.onSocketClose(n),t.onSocketError(o),t.onSocketMessage(a),t.onSocketOpen(s);else{let r=t.connectSocket({url:e,multiple:!0,complete(){}});r instanceof Promise&&(r=await r),r.onClose(n),r.onError(o),r.onOpen(s),r.onMessage(a),this.socketInstance=r}}send(e){var t;L.isSingleSocket?r().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?r().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=D.CLOSED}getState(){return this.state}}i(L,"isSingleSocket",!1);var V=new class extends F{constructor(){super(...arguments),i(this,"socketWrapper",new L),i(this,"getPageSpyConfig",null)}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),r=R(H.info);this.send({type:T,content:{info:{name:r,group:e,tags:{title:t,name:r,group:e}}}},!0)}}getSocket(){return this.socketWrapper}onOffline(){s.removeStorage(A)}};class G extends Error{}class W extends SyntaxError{}class _ extends ReferenceError{}class B extends TypeError{}class J extends G{}class K extends W{}class z extends _{}const $={UnknownError:[3001,"%0",J],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",J],NodeTypeSyntaxError:[1001,"Unknown node type: %0",z],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",z],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",z],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",z],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",z],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",z],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",z],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",z],ParamTypeSyntaxError:[1009,"Unknown param type: %0",z],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",z],FunctionUndefinedReferenceError:[2001,"%0 is not a function",_],VariableUndefinedReferenceError:[2002,"%0 is not defined",_],IsNotConstructor:[2003,"%0 is not a constructor",B]};function Q(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}const X=Object.prototype.hasOwnProperty,Y=Symbol("Break"),Z=Symbol("Continue"),ee=Symbol("DefaultCase"),te=Symbol("EmptyStatementReturn"),re=Symbol("WithScopeName"),ne=Symbol("SuperScopeName"),se=Symbol("RootScopeName"),oe=Symbol("GlobalScopeName");function ae(e){return"function"==typeof e}class ie{constructor(e){i(this,"value",void 0),this.value=e}}class ce{constructor(e){i(this,"value",void 0),this.value=e}}class le{constructor(e){i(this,"value",void 0),this.value=e}}class ue{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2?arguments[2]:void 0;i(this,"name",void 0),i(this,"parent",void 0),i(this,"data",void 0),i(this,"labelStack",void 0),this.name=r,this.parent=t,this.data=e,this.labelStack=[]}}function he(){}const de={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(de.JSON=JSON),"undefined"!=typeof Promise&&(de.Promise=Promise),"undefined"!=typeof Set&&(de.Set=Set),"undefined"!=typeof Map&&(de.Map=Map),"undefined"!=typeof Symbol&&(de.Symbol=Symbol),"undefined"!=typeof Proxy&&(de.Proxy=Proxy),"undefined"!=typeof WeakMap&&(de.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(de.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(de.Reflect=Reflect);class pe{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:pe.global,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};i(this,"value",void 0),i(this,"context",void 0),i(this,"globalContext",void 0),i(this,"source",void 0),i(this,"sourceList",[]),i(this,"currentScope",void 0),i(this,"globalScope",void 0),i(this,"currentContext",void 0),i(this,"options",void 0),i(this,"callStack",void 0),i(this,"collectDeclVars",Object.create(null)),i(this,"collectDeclFuncs",Object.create(null)),i(this,"isVarDeclMode",!1),i(this,"lastExecNode",null),i(this,"isRunning",!1),i(this,"execStartTime",void 0),i(this,"execEndTime",void 0),this.options={timeout:t.timeout||0,rootContext:t.rootContext,globalContextInFunction:void 0===t.globalContextInFunction?pe.globalContextInFunction:t.globalContextInFunction,_initEnv:t._initEnv},this.context=e||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}initEnvironment(e){let t;if(e instanceof ue)t=e;else{let n=null;const s=this.createSuperScope(e);this.options.rootContext&&(n=new ue((r=this.options.rootContext,Object.create(r)),s,se)),t=new ue(e,n||s,oe)}var r;this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;const n=this.options._initEnv;n&&n.call(this)}getExecStartTime(){return this.execStartTime}getExecutionTime(){return this.execEndTime-this.execStartTime}setExecTimeout(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.options.timeout=e}getOptions(){return this.options}getCurrentScope(){return this.currentScope}getCurrentContext(){return this.currentContext}isInterruptThrow(e){return e instanceof J||e instanceof z||e instanceof K}createSuperScope(e){let t={...de};return Object.keys(t).forEach((r=>{r in e&&delete t[r]})),new ue(t,null,ne)}setCurrentContext(e){this.currentContext=e}setCurrentScope(e){this.currentScope=e}evaluateNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const r=this.getCurrentScope(),n=this.getCurrentContext(),s=r.labelStack.concat([]),o=this.callStack.concat([]),a=()=>{this.setCurrentScope(r),this.setCurrentContext(n),r.labelStack=s,this.callStack=o};try{const t=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),t()}catch(e){throw e}finally{a(),this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()}createErrorMessage(e,t,r){let n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n}createError(e,t){return new t(e)}createThrowError(e,t){return this.createError(e,t)}createInternalThrowError(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])}checkTimeout(){if(!this.isRunning)return!1;const e=this.options.timeout||0;return Date.now()-this.execStartTime>e}getNodePosition(e){if(e){const t="";return e.loc?" [".concat(e.loc.start.line,":").concat(e.loc.start.column,"]").concat(t):""}return""}createClosure(e){var t=this;let r;switch(e.type){case"BinaryExpression":r=this.binaryExpressionHandler(e);break;case"LogicalExpression":r=this.logicalExpressionHandler(e);break;case"UnaryExpression":r=this.unaryExpressionHandler(e);break;case"UpdateExpression":r=this.updateExpressionHandler(e);break;case"ObjectExpression":r=this.objectExpressionHandler(e);break;case"ArrayExpression":r=this.arrayExpressionHandler(e);break;case"CallExpression":r=this.callExpressionHandler(e);break;case"NewExpression":r=this.newExpressionHandler(e);break;case"MemberExpression":r=this.memberExpressionHandler(e);break;case"ThisExpression":r=this.thisExpressionHandler(e);break;case"SequenceExpression":r=this.sequenceExpressionHandler(e);break;case"Literal":r=this.literalHandler(e);break;case"Identifier":r=this.identifierHandler(e);break;case"AssignmentExpression":r=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":r=this.functionDeclarationHandler(e);break;case"VariableDeclaration":r=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":r=this.programHandler(e);break;case"ExpressionStatement":r=this.expressionStatementHandler(e);break;case"EmptyStatement":r=this.emptyStatementHandler(e);break;case"ReturnStatement":r=this.returnStatementHandler(e);break;case"FunctionExpression":r=this.functionExpressionHandler(e);break;case"IfStatement":r=this.ifStatementHandler(e);break;case"ConditionalExpression":r=this.conditionalExpressionHandler(e);break;case"ForStatement":r=this.forStatementHandler(e);break;case"WhileStatement":r=this.whileStatementHandler(e);break;case"DoWhileStatement":r=this.doWhileStatementHandler(e);break;case"ForInStatement":r=this.forInStatementHandler(e);break;case"WithStatement":r=this.withStatementHandler(e);break;case"ThrowStatement":r=this.throwStatementHandler(e);break;case"TryStatement":r=this.tryStatementHandler(e);break;case"ContinueStatement":r=this.continueStatementHandler(e);break;case"BreakStatement":r=this.breakStatementHandler(e);break;case"SwitchStatement":r=this.switchStatementHandler(e);break;case"LabeledStatement":r=this.labeledStatementHandler(e);break;case"DebuggerStatement":r=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError($.NodeTypeSyntaxError,e.type,e)}return function(){const n=t.options.timeout;if(n&&n>0&&t.checkTimeout())throw t.createInternalThrowError($.ExecutionTimeOutError,n,null);return t.lastExecNode=e,r(...arguments)}}binaryExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{const n=t(),s=r();switch(e.operator){case"==":return n==s;case"!=":return n!=s;case"===":return n===s;case"!==":return n!==s;case"<":return n<s;case"<=":return n<=s;case">":return n>s;case">=":return n>=s;case"<<":return n<<s;case">>":return n>>s;case">>>":return n>>>s;case"+":return n+s;case"-":return n-s;case"*":return n*s;case"**":return Math.pow(n,s);case"/":return n/s;case"%":return n%s;case"|":return n|s;case"^":return n^s;case"&":return n&s;case"in":return n in s;case"instanceof":return n instanceof s;default:throw this.createInternalThrowError($.BinaryOperatorSyntaxError,e.operator,e)}}}logicalExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{switch(e.operator){case"||":return t()||r();case"&&":return t()&&r();default:throw this.createInternalThrowError($.LogicalOperatorSyntaxError,e.operator,e)}}}unaryExpressionHandler(e){if("delete"===e.operator){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>delete t()[r()]}{let t;if("typeof"===e.operator&&"Identifier"===e.argument.type){const r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);t=()=>r()[n()]}else t=this.createClosure(e.argument);return()=>{const r=t();switch(e.operator){case"-":return-r;case"+":return+r;case"!":return!r;case"~":return~r;case"void":return;case"typeof":return typeof r;default:throw this.createInternalThrowError($.UnaryOperatorSyntaxError,e.operator,e)}}}}updateExpressionHandler(e){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>{const n=t(),s=r();switch(this.assertVariable(n,s,e),e.operator){case"++":return e.prefix?++n[s]:n[s]++;case"--":return e.prefix?--n[s]:n[s]--;default:throw this.createInternalThrowError($.UpdateOperatorSyntaxError,e.operator,e)}}}objectExpressionHandler(e){const t=[],r=Object.create(null);return e.properties.forEach((e=>{const n=e.kind,s=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError($.ObjectStructureSyntaxError,e.type,e)}(e.key);r[s]&&"init"!==n||(r[s]={}),r[s][n]=this.createClosure(e.value),t.push({key:s,property:e})})),()=>{const e={},n=t.length;for(let s=0;s<n;s++){const n=t[s],o=n.key,a=r[o],i=a.init?a.init():void 0,c=a.get?a.get():function(){},l=a.set?a.set():function(e){};if("set"in a||"get"in a){const t={configurable:!0,enumerable:!0,get:c,set:l};Object.defineProperty(e,o,t)}else{const t=n.property,r=t.kind;"Identifier"!==t.key.type||"FunctionExpression"!==t.value.type||"init"!==r||t.value.id||Q(i,t.key.name),e[o]=i}}return e}}arrayExpressionHandler(e){const t=e.elements.map((e=>e?this.createClosure(e):e));return()=>{const e=t.length,r=Array(e);for(let n=0;n<e;n++){const e=t[n];e&&(r[n]=e())}return r}}safeObjectGet(e,t,r){return e[t]}createCallFunctionGetter(e){if("MemberExpression"===e.type){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e),n=this.source;return()=>{const s=t(),o=r(),a=this.safeObjectGet(s,o,e);if(!a||!ae(a)){const t=n.slice(e.start,e.end);throw this.createInternalThrowError($.FunctionUndefinedReferenceError,t,e)}return a.bind(s)}}{const t=this.createClosure(e);return()=>{let r="";"Identifier"===e.type&&(r=e.name);const n=t();if(!n||!ae(n))throw this.createInternalThrowError($.FunctionUndefinedReferenceError,r,e);let s=this.options.globalContextInFunction;if("Identifier"===e.type){const t=this.getIdentifierScope(e);t.name===re&&(s=t.data)}return n.bind(s)}}}callExpressionHandler(e){const t=this.createCallFunctionGetter(e.callee),r=e.arguments.map((e=>this.createClosure(e)));return()=>t()(...r.map((e=>e())))}functionExpressionHandler(e){const t=this,r=this.source,n=this.collectDeclVars,s=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const o=e.id?e.id.name:"",a=e.params.length,i=e.params.map((e=>this.createParamNameGetter(e))),c=this.createClosure(e.body),l=this.collectDeclVars,u=this.collectDeclFuncs;return this.collectDeclVars=n,this.collectDeclFuncs=s,()=>{const n=t.getCurrentScope(),s=function(){for(var e=arguments.length,r=new Array(e),a=0;a<e;a++)r[a]=arguments[a];t.callStack.push("".concat(o));const h=t.getCurrentScope(),d=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0;return new ue(Object.create(null),e,t)}(n,"FunctionScope(".concat(o,")"));t.setCurrentScope(d),t.addDeclarationsToScope(l,u,d),o&&(d.data[o]=s),d.data.arguments=arguments,i.forEach(((e,t)=>{d.data[e()]=r[t]}));const p=t.getCurrentContext();t.setCurrentContext(this);const g=c();if(t.setCurrentContext(p),t.setCurrentScope(h),t.callStack.pop(),g instanceof ie)return g.value};return Q(s,o),Object.defineProperty(s,"length",{value:a,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(s,"toString",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(s,"valueOf",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),s}}newExpressionHandler(e){const t=this.source,r=this.createClosure(e.callee),n=e.arguments.map((e=>this.createClosure(e)));return()=>{const s=r();if(!ae(s)||s.__IS_EVAL_FUNC){const r=e.callee,n=t.slice(r.start,r.end);throw this.createInternalThrowError($.IsNotConstructor,n,e)}return new s(...n.map((e=>e())))}}memberExpressionHandler(e){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return()=>t()[r()]}thisExpressionHandler(e){return()=>this.getCurrentContext()}sequenceExpressionHandler(e){const t=e.expressions.map((e=>this.createClosure(e)));return()=>{let e;const r=t.length;for(let n=0;n<r;n++)e=(0,t[n])();return e}}literalHandler(e){return()=>e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}identifierHandler(e){return()=>{const t=this.getCurrentScope(),r=this.getScopeDataFromName(e.name,t);return this.assertVariable(r,e.name,e),r[e.name]}}getIdentifierScope(e){const t=this.getCurrentScope();return this.getScopeFromName(e.name,t)}assignmentExpressionHandler(e){"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});const t=this.createObjectGetter(e.left),r=this.createNameGetter(e.left),n=this.createClosure(e.right);return()=>{const s=t(),o=r(),a=n();switch("="!==e.operator&&this.assertVariable(s,o,e),e.operator){case"=":return s[o]=a;case"+=":return s[o]+=a;case"-=":return s[o]-=a;case"*=":return s[o]*=a;case"**=":return s[o]=Math.pow(s[o],a);case"/=":return s[o]/=a;case"%=":return s[o]%=a;case"<<=":return s[o]<<=a;case">>=":return s[o]>>=a;case">>>=":return s[o]>>>=a;case"&=":return s[o]&=a;case"^=":return s[o]^=a;case"|=":return s[o]|=a;default:throw this.createInternalThrowError($.AssignmentExpressionSyntaxError,e.type,e)}}}functionDeclarationHandler(e){if(e.id){const t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return()=>te}getVariableName(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError($.VariableTypeSyntaxError,e.type,e)}variableDeclarationHandler(e){let t;const r=[];for(let t=0;t<e.declarations.length;t++){const n=e.declarations[t];this.varDeclaration(this.getVariableName(n.id)),n.init&&r.push({type:"AssignmentExpression",operator:"=",left:n.id,right:n.init})}return r.length&&(t=this.createClosure({type:"BlockStatement",body:r})),()=>{if(t){const e=this.isVarDeclMode;this.isVarDeclMode=!0,t(),this.isVarDeclMode=e}return te}}assertVariable(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError($.VariableUndefinedReferenceError,t,r)}programHandler(e){const t=e.body.map((e=>this.createClosure(e)));return()=>{let e=te;for(let r=0;r<t.length;r++){const n=t[r],s=this.setValue(n());if(s!==te&&(e=s,e instanceof ie||e instanceof ce||e instanceof le||e===Y||e===Z))break}return e}}expressionStatementHandler(e){return this.createClosure(e.expression)}emptyStatementHandler(e){return()=>te}returnStatementHandler(e){const t=e.argument?this.createClosure(e.argument):he;return()=>new ie(t())}ifStatementHandler(e){const t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/()=>te;return()=>t()?r():n()}conditionalExpressionHandler(e){return this.ifStatementHandler(e)}forStatementHandler(e){let t=he,r=e.test?this.createClosure(e.test):()=>!0,n=he;const s=this.createClosure(e.body);return"ForStatement"===e.type&&(t=e.init?this.createClosure(e.init):t,n=e.update?this.createClosure(e.update):he),o=>{let a,i=te,c="DoWhileStatement"===e.type;for(o&&"LabeledStatement"===o.type&&(a=o.label.name),t();c||r();n()){c=!1;const e=this.setValue(s());if(e!==te&&e!==Z){if(e===Y)break;if(i=e,i instanceof le&&i.value===a)i=te;else if(i instanceof ie||i instanceof ce||i instanceof le)break}}return i}}whileStatementHandler(e){return this.forStatementHandler(e)}doWhileStatementHandler(e){return this.forStatementHandler(e)}forInStatementHandler(e){let t=e.left;const r=this.createClosure(e.right),n=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),t=e.left.declarations[0].id),e=>{let s,o,a=te;e&&"LabeledStatement"===e.type&&(s=e.label.name);const i=r();for(o in i){this.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:t,right:{type:"Literal",value:o}})();const e=this.setValue(n());if(e!==te&&e!==Z){if(e===Y)break;if(a=e,a instanceof le&&a.value===s)a=te;else if(a instanceof ie||a instanceof ce||a instanceof le)break}}return a}}withStatementHandler(e){const t=this.createClosure(e.object),r=this.createClosure(e.body);return()=>{const e=t(),n=this.getCurrentScope(),s=new ue(e,n,re);this.setCurrentScope(s);const o=this.setValue(r());return this.setCurrentScope(n),o}}throwStatementHandler(e){const t=this.createClosure(e.argument);return()=>{throw this.setValue(void 0),t()}}tryStatementHandler(e){const t=this.createClosure(e.block),r=e.handler?this.catchClauseHandler(e.handler):null,n=e.finalizer?this.createClosure(e.finalizer):null;return()=>{const e=this.getCurrentScope(),s=this.getCurrentContext(),o=e.labelStack.concat([]),a=this.callStack.concat([]);let i,c,l=te;const u=()=>{this.setCurrentScope(e),this.setCurrentContext(s),e.labelStack=o,this.callStack=a};try{l=this.setValue(t()),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;if(r)try{l=this.setValue(r(e)),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}}if(n)try{l=n(),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}if(c)throw c;return i||l}}catchClauseHandler(e){const t=this.createParamNameGetter(e.param),r=this.createClosure(e.body);return e=>{let n;const s=this.getCurrentScope().data,o=t(),a=X.call(s,o),i=s[o];return s[o]=e,n=r(),a?s[o]=i:delete s[o],n}}continueStatementHandler(e){return()=>e.label?new le(e.label.name):Z}breakStatementHandler(e){return()=>e.label?new ce(e.label.name):Y}switchStatementHandler(e){const t=this.createClosure(e.discriminant),r=e.cases.map((e=>this.switchCaseHandler(e)));return()=>{const e=t();let n,s,o,a=!1;for(let t=0;t<r.length;t++){const i=r[t](),c=i.testClosure();if(c!==ee){if(a||c===e){if(a=!0,s=this.setValue(i.bodyClosure()),s===te)continue;if(s===Y)break;if(n=s,n instanceof ie||n instanceof ce||n instanceof le||n===Z)break}}else o=i}return!a&&o&&(s=this.setValue(o.bodyClosure()),s===te||s===Y||(n=s)),n}}switchCaseHandler(e){const t=e.test?this.createClosure(e.test):()=>ee,r=this.createClosure({type:"BlockStatement",body:e.consequent});return()=>({testClosure:t,bodyClosure:r})}labeledStatementHandler(e){const t=e.label.name,r=this.createClosure(e.body);return()=>{let n;const s=this.getCurrentScope();return s.labelStack.push(t),n=r(e),n instanceof ce&&n.value===t&&(n=te),s.labelStack.pop(),n}}debuggerStatementHandler(e){return()=>te}createParamNameGetter(e){if("Identifier"===e.type)return()=>e.name;throw this.createInternalThrowError($.ParamTypeSyntaxError,e.type,e)}createObjectKeyGetter(e){let t;return t="Identifier"===e.type?()=>e.name:this.createClosure(e),function(){return t()}}createMemberKeyGetter(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)}createObjectGetter(e){switch(e.type){case"Identifier":return()=>this.getScopeDataFromName(e.name,this.getCurrentScope());case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError($.AssignmentTypeSyntaxError,e.type,e)}}createNameGetter(e){switch(e.type){case"Identifier":return()=>e.name;case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError($.AssignmentTypeSyntaxError,e.type,e)}}varDeclaration(e){this.collectDeclVars[e]=void 0}funcDeclaration(e,t){this.collectDeclFuncs[e]=t}addDeclarationsToScope(e,t,r){const n=r.data;for(let e in t){const r=t[e];n[e]=r?r():r}for(let t in e)t in n||(n[t]=void 0)}getScopeValue(e,t){return this.getScopeFromName(e,t).data[e]}getScopeDataFromName(e,t){return this.getScopeFromName(e,t).data}getScopeFromName(e,t){let r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope}setValue(e){const t=this.callStack.length;return this.isVarDeclMode||t||e===te||e===Y||e===Z||e instanceof ce||e instanceof le||(this.value=e instanceof ie?e.value:e),e}getValue(){return this.value}}i(pe,"version","0.0.0"),i(pe,"ecmaVersion",5),i(pe,"globalContextInFunction",void 0),i(pe,"global",Object.create(null));class ge{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(ge.hasInitd)return;ge.hasInitd=!0,V.addListener("debug",ge.handleDebugger);const t=this;this.proxyTypes.forEach((r=>{this.console[r]=console[r]||console.log||(()=>{}),Object.defineProperty(console,r,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+e(n.options)));for(var o=arguments.length,a=new Array(o),i=0;i<o;i++)a[i]=arguments[i];t.printLog({logType:r,logs:a,url:s})},configurable:!0,enumerable:!0,writable:!0})})),ge.interpreter||(ge.interpreter=new pe((()=>{let e={};return"undefined"!=typeof globalThis?e=globalThis:"undefined"!=typeof window?e=window:"object"==typeof global&&Object.keys(global).length>1&&(e=global),n&&Object.assign(e,n),e})()))}onReset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)})),ge.hasInitd=!1,ge.interpreter=null}static handleDebugger(e,t){let{source:r}=e;const{type:n,data:s}=r;if("debug"===n){const{code:e,nodes:r}=s;t(j("console",{logType:"debug-origin",logs:[{id:c(),type:"debug-origin",value:e}]}));try{var o;const e=null===(o=ge.interpreter)||void 0===o?void 0:o.evaluateNode(r);t(j("console",{logType:"debug-eval",logs:[P.transformToAtom(e)]}))}catch(e){t(j("console",{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>P.transformToAtom(e)));const t=j("console",{time:Date.now(),...e});V.dispatchEvent("public-data",t),V.broadcastMessage(t)}}}i(ge,"hasInitd",!1),i(ge,"interpreter",null);class me{constructor(){i(this,"name","ErrorPlugin")}onInit(){me.hasInitd||(me.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=r();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),me.hasInitd=!1}errorHandler(e){if(me.hasInitd)if(e.stack||e.message){const{message:t,stack:r}=e;me.sendMessage(r||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:r,stack:n}=Object(e);return!1===[t,r,n].every(Boolean)?null:{name:t,message:r,stack:n}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";me.sendMessage(e,null)}}unhandledRejectionHandler(e){me.hasInitd&&me.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=r();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=r();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const r=j("console",{logType:"error",logs:[P.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t});V.dispatchEvent("public-data",r),V.broadcastMessage(r)}}var fe;function ye(e,t){try{let r,n;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:s,href:o}=new URL(e,t);r=o,n=[...s.entries()]}else r=e.toString(),n=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=decodeURIComponent(n[1]),t=decodeURIComponent(n[2]);r.push([e,t])}return r}(r);const s=r.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:r,name:s,query:n}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}i(me,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(fe||(fe={}));class Se{constructor(e){w(this,"id",""),w(this,"name",""),w(this,"method",""),w(this,"url",""),w(this,"requestType","xhr"),w(this,"requestHeader",null),w(this,"status",0),w(this,"statusText",""),w(this,"readyState",0),w(this,"responseReason",null),w(this,"responseType",""),w(this,"responseHeader",null),w(this,"startTime",0),w(this,"endTime",0),w(this,"costTime",0),w(this,"getData",null),w(this,"postData",null),w(this,"requestPayload",null),w(this,"withCredentials",!1),this.id=e}}class be{constructor(e){w(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(v.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new Se(e),!0):(v.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){try{this.reqMap[e]||(this.reqMap[e]=t);const r=j("network",{...t},!1);Number(t.readyState)===fe.DONE&&this.socketStore.dispatchEvent("public-data",r),this.socketStore.broadcastMessage(r,t.readyState!==fe.DONE),this.deferDeleteRequest(e)}catch(e){v.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===fe.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class ve extends be{constructor(){super(V)}}class Ee extends ve{constructor(){super(),i(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=r();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=r(),n=t.request;n&&(this.request=n,Object.defineProperty(t,"request",{value(t){const r=c();e.createRequest(r);const s=e.getRequest(r);if(s){const o=t.method||"GET",{url:a}=t;s.requestHeader=[];const i=ye(a);if(s.url=i.url,s.name=i.name,s.getData=i.query,s.method=o.toUpperCase(),s.requestType="mp-request",s.status=0,s.statusText="Pending",s.startTime=Date.now(),s.readyState=fe.UNSENT,g(t.header)&&(s.requestHeader=Object.entries(t.header).map((e=>{let[t,r]=e;return[String(t),String(r)]}))),"GET"!==s.method){s.requestHeader.push(["Content-Type","application/json"]);const{data:e}=t;if(e)if("string"==typeof e)s.requestPayload=e;else if(e instanceof ArrayBuffer)s.requestPayload="[object ArrayBuffer]";else try{s.requestPayload=JSON.stringify(e)}catch(t){s.requestPayload=l(e)}}e.sendRequestItem(r,s);const c=t.success,u=t.fail,h=t.complete,d=()=>{s.endTime=Date.now(),s.costTime=s.endTime-(s.startTime||s.endTime)};t.success=function(t){d(),s.status=(null==t?void 0:t.statusCode)||200,s.statusText="Done",s.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],s.readyState=fe.HEADERS_RECEIVED,e.sendRequestItem(r,s);const n=function(e){const t=Object.keys(e),r={};for(let n=0;n<t.length;n++){const s=t[n];r[s.toLowerCase()]=e[s]}return r}((null==t?void 0:t.header)||{}),o=n["content-type"];switch(o&&(o.includes("application/json")&&(s.responseType="json"),(o.includes("text/html")||o.includes("text/plain"))&&(s.responseType="text")),s.responseType||(s.responseType="arraybuffer"),s.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{s.response=JSON.parse(t.data)}catch(e){s.response=t.data,s.responseType="text"}else s.response=null==t?void 0:t.data;break;case"arraybuffer":s.response="[object ArrayBuffer]"}null==c||c(t)},t.fail=function(e){d(),null==u||u(e)},t.complete=function(t){s.readyState=fe.DONE,e.sendRequestItem(r,s),null==h||h(t)};return n(t)}return v.warn("The request object is not found on request event"),null}}))}}class Ce{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){Ce.hasInitd||(Ce.hasInitd=!0,this.requestProxy=new Ee)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),Ce.hasInitd=!1}}i(Ce,"hasInitd",!1);class we{constructor(){i(this,"name","SystemPlugin")}onInit(){we.hasInitd||(we.hasInitd=!0,V.addListener("refresh",((e,t)=>{let{source:r}=e;const{data:n}=r;if("system"===n){const e=we.getSystemInfo();V.dispatchEvent("public-data",e),t(e)}})))}onReset(){we.hasInitd=!1}static getSystemInfo(){const e=H.info;return j("system",{system:{ua:R(e)},features:{}})}}function ke(e){const t=typeof e;let r=e;return"string"===t||"boolean"===t||"number"===t?r=String(e):"object"===t&&(r=e instanceof Date?e.toDateString():JSON.stringify(e)),r}i(we,"hasInitd",!1);class xe{constructor(){i(this,"name","StoragePlugin")}onInit(){xe.hasInitd||(xe.hasInitd=!0,xe.initStorageProxy(),xe.listenRefreshEvent())}onReset(){const e=r();Object.entries(xe.originFunctions).forEach((t=>{let[r,n]=t;Object.defineProperty(e,r,{value:n})})),xe.hasInitd=!1}static sendRefresh(){const e=r();try{const t=e.getStorageInfoSync(),r={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:ke(s.getStorage(e))})))};xe.sendStorageItem(r)}catch(e){}}static listenRefreshEvent(){V.addListener("refresh",(async e=>{let{source:t}=e;const{data:r}=t;"mpStorage"===r&&xe.sendRefresh()}))}static initStorageProxy(){const e=r(),{sendClearItem:t,sendRemoveItem:n,sendSetItem:s}=xe;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(xe.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>xe.originFunctions.setStorage({...e,success(t){var r;s(e.key,e.data),null===(r=e.success)||void 0===r||r.call(e,t)}})},setStorageSync:{value(e,t){try{let r;if("mp-alipay"!==H.info.browserType||H.info.framework&&"unknown"!==H.info.framework){const n=e;r=xe.originFunctions.setStorageSync(n,t),s(n,t)}else{const t=e;r=xe.originFunctions.setStorageSync(t),s(t.key,t.data)}return r}catch(t){throw v.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>xe.originFunctions.removeStorage({...e,success(t){var r;n(e.key),null===(r=e.success)||void 0===r||r.call(e,t)}})},removeStorageSync:{value(e){try{const t=xe.originFunctions.removeStorageSync(e);return n(t),t}catch(t){throw v.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>xe.originFunctions.clearStorage({...e,success(r){var n;t(),null===(n=e.success)||void 0===n||n.call(e,r)}})},clearStorageSync:{value(){try{const e=xe.originFunctions.clearStorageSync();return t(),e}catch(e){throw v.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=xe.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{s(e.key,e.value)})),t}catch(t){throw v.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>xe.originFunctions.batchSetStorage({...e,success(t){var r;e.kvList.forEach((e=>{s(e.key,e.value)})),null===(r=e.success)||void 0===r||r.call(e,t)}})})}static sendSetItem(e,t){xe.sendStorageItem({type:"mpStorage",action:"set",name:e,value:ke(t)})}static sendRemoveItem(e){xe.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){xe.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=j("storage",e);V.dispatchEvent("public-data",t),V.broadcastMessage(t,!0)}}i(xe,"hasInitd",!1),i(xe,"originFunctions",{});const Ie=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Te{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:t,project:n,title:s,useSecret:o,secret:a}=this.config.get(),i=Ie(t),c=R(H.info),l=e({group:n,title:s,name:encodeURIComponent(c)});return(u=r().request,e=>new Promise(((t,r)=>{u({...e,success(e){t(e)},fail(e){r(e)}})})))({url:"".concat(i[0]).concat(this.base,"/api/v1/room/create?").concat(l),method:"POST",data:JSON.stringify({useSecret:o,secret:a})}).then((e=>{var t;const{name:r,address:n}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(n),address:n,name:r}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var u}getRoomUrl(t){const r=this.config.get(),n=Ie(r.enableSSL);return"".concat(n[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e({address:t,name:"client:".concat(c()),userId:"Client",forceCreate:!0,useSecret:r.useSecret,secret:r.secret}))}}class Oe{defaultConfig(){return{}}constructor(){w(this,"mergeConfig",(e=>{const t=Object.entries(e).reduce(((e,t)=>{let[r,n]=t;return this.privateKeys.includes(r)||(e[r]=n),e}),{});return this.value={...this.defaultConfig(),...t},this.value})),this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}class je extends Oe{constructor(){super(...arguments),i(this,"privateKeys",["secret"])}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:""}}}class Ne{constructor(e){if(i(this,"root",null),i(this,"version","1.8.10"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",V),i(this,"config",new je),i(this,"cacheTimer",null),Ne.instance)return v.warn("Cannot initialize PageSpy multiple times"),Ne.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const n=r();if(n.canIUse("getAccountInfoSync")){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void v.warn("PageSpy is not allowed on release env of mini program")}Ne.instance=this;const s="!!!WARNING!!!: When submitting the mini program for review, be sure to delete the SDK in the code, otherwise the review will fail.";v.log(s),v.info(s),v.warn(s),this.request=new Te(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:V,config:t}),H.plugins=Ne.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=s.getStorage(A),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),v.log("Room Secret: ".concat(t))}V.connectable=!0,V.getPageSpyConfig=()=>this.config.get(),V.messageCapacity=e}async init(){const e=r(),t=this.config.get(),n=s.getStorage(A);if(n&&"object"==typeof n){const{name:e,address:r,roomUrl:s,project:o}=n;t.project!==o?await this.createNewConnection():(this.name=e,this.address=r,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=V.getSocket().getState();e!==D.CLOSED&&e!==D.CLOSING||this.useOldConnection()})),v.log("Plugins inited")}async createNewConnection(){if(!this.request)return void v.error("Cannot get the Request");const e=await this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),V.init(e.roomUrl)}useOldConnection(){this.refreshRoomInfo(),V.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{V.getSocket().getState()===D.OPEN&&this.saveSession()}),15e3),v.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:r,config:n}=this,{useSecret:o,secret:a,project:i}=n.get(),c={name:e,address:t,roomUrl:r,project:i,useSecret:o,secret:a};s.setStorage(A,c)}triggerPlugins(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];const{disabledPlugins:s}=this.config.get();Ne.pluginsWithOrder.forEach((t=>{var n;d(s)&&s.length&&s.includes(t.name)||null===(n=t[e])||void 0===n||n.apply(t,r)}))}abort(){this.triggerPlugins("onReset"),V.close(),Ne.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:r}=e;t&&this.config.set("project",String(t)),r&&this.config.set("title",String(r)),V.updateRoomInfo()}static get pluginsWithOrder(){return[...Ne.plugins.pre,...Ne.plugins.normal,...Ne.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void v.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void v.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));const r=Ne.pluginsWithOrder.some((t=>t.name===e.name));if(r)return void v.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Ne.plugins[e.enforce||"normal"].push(e)}}i(Ne,"instance",null),i(Ne,"plugins",{pre:[],normal:[],post:[]});var Pe;[new ge,new me,new Ce,new xe,new we].forEach((e=>{Ne.registerPlugin(e)})),Pe=my,t=Pe,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const Re=my.getSystemInfoSync();H.info.sdk="mp-alipay",H.info.osType=Re.platform.toLowerCase(),H.info.browserType="mp-alipay",H.info.osVersion=Re.system,H.info.browserVersion=Re.version,F.messageFilters.push((e=>e.data)),module.exports=Ne;
"use strict";const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t},s={setStorage(e,n){var s;return null===(s=t)||void 0===s?void 0:s.setStorageSync(e,n)},getStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)},removeStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)}};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function r(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t||"default");if("object"!=o(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:t+""}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){return Math.random().toString(36).slice(2)}function c(e){return Object.prototype.toString.call(e)}function l(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function u(e){return"[object BigInt]"===c(e)}function h(e){return e instanceof Array}function g(e){return"object"==typeof e&&null!==e}function d(e){return!(!g(e)||"[object Object]"!==c(e))}const p=e=>"".concat(e),f=e=>({ok:!0,value:e});function m(e){return void 0===e?f(p(e)):null===e?f(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?f(p(e)):u(e)?f("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?f(p(e.toString())):e instanceof Error?f(p(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:f(e)}function y(e){return void 0===e?"undefined":null===e?"null":u(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const S={...console},v=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];S[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const b="message",I="broadcast",O="ping",E="updateRoomInfo";var T=Object.freeze({__proto__:null,BROADCAST:I,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:b,PING:O,PONG:"pong",UPDATE_ROOM_INFO:E});function k(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:a()},...t}}}class w{constructor(){i(this,"store",{}),i(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=m(e);return n?{id:a(),type:y(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];l(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=w.getAtomOverview({atomId:a(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=a();let s=n;var o;g(o=e)&&l(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=w.getSemanticValue(e);return w.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:a(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(d(e))return"Object {...}";if(h(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(h(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var C=new w;const P=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class j{static makeClientInfoMsg(){const e=j.info.ua||P(j.info);return{sdk:j.info.sdk,isDevTools:j.info.isDevTools,ua:e,plugins:j.plugins}}}var R;i(j,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"}),i(j,"plugins",[]),function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));const N=2e3,q=Math.pow(1.5,4)*N;class A{constructor(){i(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){i(this,"socketUrl",""),i(this,"socketConnection",null),i(this,"debuggerConnection",null),i(this,"pingTimer",null),i(this,"pongTimer",null),i(this,"retryTimer",null),i(this,"isOffline",!1),i(this,"messageCapacity",0),i(this,"messages",[]),i(this,"events",{debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[]}),i(this,"retryInterval",N),i(this,"connectable",!0),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}async init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===R.OPEN&&await new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()})),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){v.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:I,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=N,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<q&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:g}=h;switch(g){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(g===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:d,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:d,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:b,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:b,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=C.get(o)||{};t(k("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-getter"===s){const{id:e,parentId:n,key:s,instanceId:i}=o,a=C.getOrigin(i),c=C.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(k("atom-getter-".concat(e),C.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.checkIfSend(e))try{var n;const t=e;t.createdAt=Date.now(),t.requestId=a();const s=function(e){const{ok:t,value:n}=m(e);return t?n:JSON.stringify(e,((e,t)=>m(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){v.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,t)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===R.OPEN&&(!![E,O].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![b,O].includes(e.type)}sendClientInfo(){const e=j.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}i(D,"messageFilters",[]);const L="page-spy-room";class M extends A{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}async init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};if(M.isSingleSocket)t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o);else{let n=t.connectSocket({url:e,multiple:!0,complete(){}});n instanceof Promise&&(n=await n),n.onClose(s),n.onError(r),n.onOpen(o),n.onMessage(i),this.socketInstance=n}}send(e){var t;M.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;M.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED}getState(){return this.state}}i(M,"isSingleSocket",!1);var U,x=new class extends D{constructor(){super(...arguments),i(this,"socketWrapper",new M),i(this,"getPageSpyConfig",null)}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=P(j.info);this.send({type:E,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}getSocket(){return this.socketWrapper}onOffline(){s.removeStorage(L)}};class F{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(F.hasInitd)return;F.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)})),F.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>C.transformToAtom(e)));const t=k("console",{time:Date.now(),...e});x.dispatchEvent("public-data",t),x.broadcastMessage(t)}}}i(F,"hasInitd",!1);class H{constructor(){i(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n=k("console",{logType:"error",logs:[C.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t});x.dispatchEvent("public-data",n),x.broadcastMessage(n)}}i(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class W{constructor(e){i(this,"id",""),i(this,"name",""),i(this,"method",""),i(this,"url",""),i(this,"requestType","xhr"),i(this,"requestHeader",null),i(this,"status",0),i(this,"statusText",""),i(this,"readyState",0),i(this,"responseReason",null),i(this,"responseType",""),i(this,"responseHeader",null),i(this,"startTime",0),i(this,"endTime",0),i(this,"costTime",0),i(this,"getData",null),i(this,"postData",null),i(this,"requestPayload",null),i(this,"withCredentials",!1),this.id=e}}class G{constructor(e){i(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(v.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new W(e),!0):(v.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){try{this.reqMap[e]||(this.reqMap[e]=t);const n=k("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}catch(e){v.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class _ extends G{constructor(){super(x)}}class V extends _{constructor(){super(),i(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=a();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t;o.requestHeader=[],o.url=i,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,d(t.header)&&(o.requestHeader=Object.entries(t.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),o.requestHeader.push(["Content-Type","application/json"]);const{data:a}=t;if(a)if("string"==typeof a)o.requestPayload=a;else if(a instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(a)}catch(e){o.requestPayload=c(a)}e.sendRequestItem(n,o);const l=t.success,u=t.fail,h=t.complete,g=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){g(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o);const s=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(s&&(s.includes("application/json")&&(o.responseType="json"),(s.includes("text/html")||s.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}null==l||l(t)},t.fail=function(e){g(),null==u||u(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==h||h(t)};return s(t)}return v.warn("The request object is not found on request event"),null}}))}}class B{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new V)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}i(B,"hasInitd",!1);class J{constructor(){i(this,"name","SystemPlugin")}onInit(){J.hasInitd||(J.hasInitd=!0,x.addListener("refresh",((e,t)=>{let{source:n}=e;const{data:s}=n;if("system"===s){const e=J.getSystemInfo();x.dispatchEvent("public-data",e),t(e)}})))}onReset(){J.hasInitd=!1}static getSystemInfo(){const e=j.info;return k("system",{system:{ua:P(e)},features:{}})}}function z(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}i(J,"hasInitd",!1);class K{constructor(){i(this,"name","StoragePlugin")}onInit(){K.hasInitd||(K.hasInitd=!0,K.initStorageProxy(),K.listenRefreshEvent())}onReset(){const e=n();Object.entries(K.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),K.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:z(s.getStorage(e))})))};K.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){x.addListener("refresh",(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&K.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=K;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(K.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>K.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{let n;if("mp-alipay"!==j.info.browserType||j.info.framework&&"unknown"!==j.info.framework){const s=e;n=K.originFunctions.setStorageSync(s,t),o(s,t)}else{const t=e;n=K.originFunctions.setStorageSync(t),o(t.key,t.data)}return n}catch(t){throw v.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>K.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=K.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw v.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>K.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=K.originFunctions.clearStorageSync();return t(),e}catch(e){throw v.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=K.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw v.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>K.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){K.sendStorageItem({type:"mpStorage",action:"set",name:e,value:z(t)})}static sendRemoveItem(e){K.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){K.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=k("storage",e);x.dispatchEvent("public-data",t),x.broadcastMessage(t,!0)}}i(K,"hasInitd",!1),i(K,"originFunctions",{});const Q=e=>!1===e?["http://","ws://"]:["https://","wss://"];class X{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:t,project:s,title:o,useSecret:r,secret:i}=this.config.get(),a=Q(t),c=P(j.info),l=e({group:s,title:o,name:encodeURIComponent(c)});return(u=n().request,e=>new Promise(((t,n)=>{u({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(a[0]).concat(this.base,"/api/v1/room/create?").concat(l),method:"POST",data:JSON.stringify({useSecret:r,secret:i})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var u}getRoomUrl(t){const n=this.config.get(),s=Q(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e({address:t,name:"client:".concat(a()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class Y{defaultConfig(){return{}}constructor(){i(this,"mergeConfig",(e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value={...this.defaultConfig(),...t},this.value})),this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}class Z extends Y{constructor(){super(...arguments),i(this,"privateKeys",["secret"])}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:""}}}class ${constructor(e){if(i(this,"root",null),i(this,"version","1.9.0"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",x),i(this,"config",new Z),i(this,"cacheTimer",null),$.instance)return v.warn("Cannot initialize PageSpy multiple times"),$.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(M.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")&&s.getAccountInfoSync){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void v.warn("PageSpy is not allowed on release env of mini program")}$.instance=this;const o="!!!WARNING!!!: When submitting the mini program for review, be sure to delete the SDK in the code, otherwise the review will fail.";v.log(o),v.info(o),v.warn(o),this.request=new X(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:C}),j.plugins=$.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=s.getStorage(L),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),v.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}async init(){const e=n(),t=this.config.get(),o=s.getStorage(L);if(o&&"object"==typeof o){const{name:e,address:n,roomUrl:s,project:r}=o;t.project!==r?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),v.log("Plugins inited")}async createNewConnection(){if(!this.request)return void v.error("Cannot get the Request");const e=await this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===R.OPEN&&this.saveSession()}),15e3),v.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:o}=this,{useSecret:r,secret:i,project:a}=o.get(),c={name:e,address:t,roomUrl:n,project:a,useSecret:r,secret:i};s.setStorage(L,c)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();$.pluginsWithOrder.forEach((t=>{var s;h(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),$.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...$.plugins.pre,...$.plugins.normal,...$.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void v.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void v.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if($.pluginsWithOrder.some((t=>t.name===e.name)))return void v.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));$.plugins[e.enforce||"normal"].push(e)}}i($,"instance",null),i($,"plugins",{pre:[],normal:[],post:[]});var ee;[new F,new H,new B,new K,new J].forEach((e=>{$.registerPlugin(e)})),ee=my,t=ee,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const te=my.getSystemInfoSync();j.info.sdk="mp-alipay",j.info.osType=te.platform.toLowerCase(),j.info.browserType="mp-alipay",j.info.osVersion=te.system,j.info.browserVersion=te.version,D.messageFilters.push((e=>e.data)),module.exports=$;
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[r,n]=e;t.push("".concat(r,"=").concat(n))})),t.join("&")};let t;const r=()=>{if(!t)throw Error("the mp sdk is not set");return t};let n={};const s={setStorage(e,r){var n;return null===(n=t)||void 0===n?void 0:n.setStorageSync(e,r)},getStorage(e){var r;return null===(r=t)||void 0===r?void 0:r.getStorageSync(e)},removeStorage(e){var r;return null===(r=t)||void 0===r?void 0:r.getStorageSync(e)}};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:t+""}function i(e,t,r){return(t=a(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(){return Math.random().toString(36).slice(2)}function l(e){return Object.prototype.toString.call(e)}function u(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function h(e){return"[object BigInt]"===l(e)}function d(e){return e instanceof Array}function p(e){return"object"==typeof e&&null!==e}function g(e){return!(!p(e)||"[object Object]"!==l(e))}const m=e=>"".concat(e),f=e=>({ok:!0,value:e});function y(e){return void 0===e?f(m(e)):null===e?f(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?f(m(e)):h(e)?f("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?f(m(e.toString())):e instanceof Error?f(m(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:f(e)}function S(e){return void 0===e?"undefined":null===e?"null":h(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const b={...console},v=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...r)},e.unproxy[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];b[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...r)},e)),{unproxy:{}});function E(e){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},E(e)}function C(e){var t=function(e,t){if("object"!=E(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=E(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==E(t)?t:t+""}function w(e,t,r){return(t=C(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const k="message",x="broadcast",I="ping",T="updateRoomInfo";var O=Object.freeze({__proto__:null,BROADCAST:x,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:k,PING:I,PONG:"pong",UPDATE_ROOM_INFO:T});function j(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:c()},...t}}}class N{constructor(){w(this,"store",{}),w(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:r}=y(e);return r?{id:c(),type:S(e),value:t}:this.add(e)}get(e){const t=this.store[e],r=this.instanceStore[e];if(!t)return null;const n={},s=Object.getOwnPropertyDescriptors(t);Object.keys(s).forEach((e=>{const t=s[e];u(t,"value")&&(t.value=this.transformToAtom(t.value)),n[e]=N.getAtomOverview({atomId:c(),instanceId:r,value:t})}));const o=this.addExtraProperty(e);return{...n,...o}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const r=c();let n=r;var s;p(s=e)&&u(s,"constructor")&&"function"==typeof s.constructor&&(n=t),this.store[r]=e,this.instanceStore[r]=n;const o=N.getSemanticValue(e);return N.getAtomOverview({atomId:r,value:o,instanceId:n})}static getAtomOverview(e){let{instanceId:t="",atomId:r,value:n}=e;return{id:c(),type:"atom",__atomId:r,instanceId:t,value:n}}static getSemanticValue(e){if(g(e))return"Object {...}";if(d(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],r=this.instanceStore[e],n={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(n["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let r=0;for(const n of t)e[r++]=n;e.size=t.size,n["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let r=0;for(const[n,s]of t.entries())e[r++]={key:n,value:s};e.size=t.size,n["[[Entries]]"]=this.transformToAtom(e)}var s;return(d(t)||(s=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&s instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&s instanceof HTMLCollection))&&(n.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?n["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),r):n.___proto___=this.transformToAtom(null),n}}var P=new N;const R=e=>{let{osType:t,osVersion:r,browserType:n,browserVersion:s}=e;return"".concat(t,"/").concat(r," ").concat(n,"/").concat(s)};class H{static makeClientInfoMsg(){const e=H.info.ua||R(H.info);return{sdk:H.info.sdk,isDevTools:H.info.isDevTools,ua:e,plugins:H.plugins}}}var D;w(H,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"}),w(H,"plugins",[]),function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(D||(D={}));const U=2e3,M=Math.pow(1.5,4)*U;class q{constructor(){w(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class F{constructor(){w(this,"socketUrl",""),w(this,"socketConnection",null),w(this,"debuggerConnection",null),w(this,"pingTimer",null),w(this,"pongTimer",null),w(this,"retryTimer",null),w(this,"isOffline",!1),w(this,"messageCapacity",0),w(this,"messages",[]),w(this,"events",{debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[]}),w(this,"retryInterval",U),w(this,"connectable",!0),this.addListener("atom-detail",F.handleResolveAtom),this.addListener("atom-getter",F.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}async init(e){try{var t,r,n,s,o;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===D.OPEN&&await new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()})),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(r=this.socketWrapper)||void 0===r||r.onMessage((e=>{this.handleMessage(e)})),null===(n=this.socketWrapper)||void 0===n||n.onClose((()=>{this.connectOffline()})),null===(s=this.socketWrapper)||void 0===s||s.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(o=this.socketWrapper)||void 0===o||o.init(e)}catch(e){v.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const r=function(e){return{type:x,content:{data:e}}}(e);this.send(r,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,r]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||r.splice(0)}))}connectOnline(){this.retryInterval=U,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<M&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;F.messageFilters.length&&F.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:r,MESSAGE:n,ERROR:s,JOIN:o,PING:a,PONG:i,LEAVE:c,CLOSE:l,BROADCAST:u}=O,h=JSON.parse(e.data),{type:d}=h;switch(d){case r:const{selfConnection:e,roomConnections:a}=h.content;this.socketConnection=e,this.debuggerConnection=a.find((e=>"Debugger"===e.userId))||null;break;case o:case c:const{connection:i}=h.content;"Debugger"===i.userId&&(d===o?(this.debuggerConnection=i,this.sendClientInfo()):this.debuggerConnection=null);break;case n:const{data:u,from:p,to:g}=h.content;g.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:p,to:g});break;case l:case s:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var r;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(r=this.events[e])||void 0===r||r.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const r=function(e,t,r){return{type:k,content:{data:e,from:t,to:r}}}(e,this.socketConnection,t);this.send(r)}handleFlushBuffer(e){const{latestId:t}=e.source.data,r=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(r+1).forEach((t=>{const r={type:k,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(r,!0)}))}static handleResolveAtom(e,t){let{source:r}=e;const{type:n,data:s}=r;if("atom-detail"===n){const e=P.get(s)||{};t(j("atom-detail-".concat(s),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:r}=e;const{type:n,data:s}=r;if("atom-getter"===n){const{id:e,parentId:r,key:n,instanceId:a}=s,i=P.getOrigin(a),c=P.getOrigin(r);let l={};var o;if(i&&c)l=null===(o=Object.getOwnPropertyDescriptor(c,n))||void 0===o||null===(o=o.get)||void 0===o?void 0:o.call(i);else l=new Error("Getter computed failed");t(j("atom-getter-".concat(e),P.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.checkIfSend(e))try{var r;const t=e;t.createdAt=Date.now(),t.requestId=c();const n=function(e){const{ok:t,value:r}=y(e);return t?r:JSON.stringify(e,((e,t)=>y(t).value),2)}(t);null===(r=this.socketWrapper)||void 0===r||r.send(n)}catch(e){v.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,t)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===D.OPEN&&(!![T,I].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![k,I].includes(e.type)}sendClientInfo(){const e=H.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}w(F,"messageFilters",[]);const A="page-spy-room";class L extends q{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}async init(e){this.state=D.CONNECTING;const t=r(),n=e=>{this.state=D.CLOSED,this.emit("close",e)},s=e=>{this.state=D.OPEN,this.emit("open",e)},o=e=>{this.state=D.CLOSED,this.emit("error",e)},a=e=>{this.emit("message",e)};if(L.isSingleSocket)t.connectSocket({url:e}),t.onSocketClose(n),t.onSocketError(o),t.onSocketMessage(a),t.onSocketOpen(s);else{let r=t.connectSocket({url:e,multiple:!0,complete(){}});r instanceof Promise&&(r=await r),r.onClose(n),r.onError(o),r.onOpen(s),r.onMessage(a),this.socketInstance=r}}send(e){var t;L.isSingleSocket?r().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;L.isSingleSocket?r().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=D.CLOSED}getState(){return this.state}}i(L,"isSingleSocket",!1);var V=new class extends F{constructor(){super(...arguments),i(this,"socketWrapper",new L),i(this,"getPageSpyConfig",null)}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),r=R(H.info);this.send({type:T,content:{info:{name:r,group:e,tags:{title:t,name:r,group:e}}}},!0)}}getSocket(){return this.socketWrapper}onOffline(){s.removeStorage(A)}};class G extends Error{}class W extends SyntaxError{}class _ extends ReferenceError{}class B extends TypeError{}class J extends G{}class K extends W{}class z extends _{}const $={UnknownError:[3001,"%0",J],ExecutionTimeOutError:[3002,"Script execution timed out after %0ms",J],NodeTypeSyntaxError:[1001,"Unknown node type: %0",z],BinaryOperatorSyntaxError:[1002,"Unknown binary operator: %0",z],LogicalOperatorSyntaxError:[1003,"Unknown logical operator: %0",z],UnaryOperatorSyntaxError:[1004,"Unknown unary operator: %0",z],UpdateOperatorSyntaxError:[1005,"Unknown update operator: %0",z],ObjectStructureSyntaxError:[1006,"Unknown object structure: %0",z],AssignmentExpressionSyntaxError:[1007,"Unknown assignment expression: %0",z],VariableTypeSyntaxError:[1008,"Unknown variable type: %0",z],ParamTypeSyntaxError:[1009,"Unknown param type: %0",z],AssignmentTypeSyntaxError:[1010,"Unknown assignment type: %0",z],FunctionUndefinedReferenceError:[2001,"%0 is not a function",_],VariableUndefinedReferenceError:[2002,"%0 is not defined",_],IsNotConstructor:[2003,"%0 is not a constructor",B]};function Q(e,t){Object.defineProperty(e,"name",{value:t,writable:!1,enumerable:!1,configurable:!0})}const X=Object.prototype.hasOwnProperty,Y=Symbol("Break"),Z=Symbol("Continue"),ee=Symbol("DefaultCase"),te=Symbol("EmptyStatementReturn"),re=Symbol("WithScopeName"),ne=Symbol("SuperScopeName"),se=Symbol("RootScopeName"),oe=Symbol("GlobalScopeName");function ae(e){return"function"==typeof e}class ie{constructor(e){i(this,"value",void 0),this.value=e}}class ce{constructor(e){i(this,"value",void 0),this.value=e}}class le{constructor(e){i(this,"value",void 0),this.value=e}}class ue{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2?arguments[2]:void 0;i(this,"name",void 0),i(this,"parent",void 0),i(this,"data",void 0),i(this,"labelStack",void 0),this.name=r,this.parent=t,this.data=e,this.labelStack=[]}}function he(){}const de={NaN:NaN,Infinity:1/0,undefined:void 0,Object:Object,Array:Array,String:String,Boolean:Boolean,Number:Number,Date:Date,RegExp:RegExp,Error:Error,URIError:URIError,TypeError:TypeError,RangeError:RangeError,SyntaxError:SyntaxError,ReferenceError:ReferenceError,Math:Math,parseInt:parseInt,parseFloat:parseFloat,isNaN:isNaN,isFinite:isFinite,decodeURI:decodeURI,decodeURIComponent:decodeURIComponent,encodeURI:encodeURI,encodeURIComponent:encodeURIComponent,escape:escape,unescape:unescape};"undefined"!=typeof JSON&&(de.JSON=JSON),"undefined"!=typeof Promise&&(de.Promise=Promise),"undefined"!=typeof Set&&(de.Set=Set),"undefined"!=typeof Map&&(de.Map=Map),"undefined"!=typeof Symbol&&(de.Symbol=Symbol),"undefined"!=typeof Proxy&&(de.Proxy=Proxy),"undefined"!=typeof WeakMap&&(de.WeakMap=WeakMap),"undefined"!=typeof WeakSet&&(de.WeakSet=WeakSet),"undefined"!=typeof Reflect&&(de.Reflect=Reflect);class pe{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:pe.global,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};i(this,"value",void 0),i(this,"context",void 0),i(this,"globalContext",void 0),i(this,"source",void 0),i(this,"sourceList",[]),i(this,"currentScope",void 0),i(this,"globalScope",void 0),i(this,"currentContext",void 0),i(this,"options",void 0),i(this,"callStack",void 0),i(this,"collectDeclVars",Object.create(null)),i(this,"collectDeclFuncs",Object.create(null)),i(this,"isVarDeclMode",!1),i(this,"lastExecNode",null),i(this,"isRunning",!1),i(this,"execStartTime",void 0),i(this,"execEndTime",void 0),this.options={timeout:t.timeout||0,rootContext:t.rootContext,globalContextInFunction:void 0===t.globalContextInFunction?pe.globalContextInFunction:t.globalContextInFunction,_initEnv:t._initEnv},this.context=e||Object.create(null),this.callStack=[],this.initEnvironment(this.context)}initEnvironment(e){let t;if(e instanceof ue)t=e;else{let n=null;const s=this.createSuperScope(e);this.options.rootContext&&(n=new ue((r=this.options.rootContext,Object.create(r)),s,se)),t=new ue(e,n||s,oe)}var r;this.globalScope=t,this.currentScope=this.globalScope,this.globalContext=t.data,this.currentContext=t.data,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null),this.execStartTime=Date.now(),this.execEndTime=this.execStartTime;const n=this.options._initEnv;n&&n.call(this)}getExecStartTime(){return this.execStartTime}getExecutionTime(){return this.execEndTime-this.execStartTime}setExecTimeout(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.options.timeout=e}getOptions(){return this.options}getCurrentScope(){return this.currentScope}getCurrentContext(){return this.currentContext}isInterruptThrow(e){return e instanceof J||e instanceof z||e instanceof K}createSuperScope(e){let t={...de};return Object.keys(t).forEach((r=>{r in e&&delete t[r]})),new ue(t,null,ne)}setCurrentContext(e){this.currentContext=e}setCurrentScope(e){this.currentScope=e}evaluateNode(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";this.value=void 0,this.source=t,this.sourceList.push(t),this.isRunning=!0,this.execStartTime=Date.now(),this.execEndTime=this.execStartTime,this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const r=this.getCurrentScope(),n=this.getCurrentContext(),s=r.labelStack.concat([]),o=this.callStack.concat([]),a=()=>{this.setCurrentScope(r),this.setCurrentContext(n),r.labelStack=s,this.callStack=o};try{const t=this.createClosure(e);this.addDeclarationsToScope(this.collectDeclVars,this.collectDeclFuncs,this.getCurrentScope()),t()}catch(e){throw e}finally{a(),this.execEndTime=Date.now()}return this.isRunning=!1,this.getValue()}createErrorMessage(e,t,r){let n=e[1].replace("%0",String(t));return null!==r&&(n+=this.getNodePosition(r||this.lastExecNode)),n}createError(e,t){return new t(e)}createThrowError(e,t){return this.createError(e,t)}createInternalThrowError(e,t,r){return this.createError(this.createErrorMessage(e,t,r),e[2])}checkTimeout(){if(!this.isRunning)return!1;const e=this.options.timeout||0;return Date.now()-this.execStartTime>e}getNodePosition(e){if(e){const t="";return e.loc?" [".concat(e.loc.start.line,":").concat(e.loc.start.column,"]").concat(t):""}return""}createClosure(e){var t=this;let r;switch(e.type){case"BinaryExpression":r=this.binaryExpressionHandler(e);break;case"LogicalExpression":r=this.logicalExpressionHandler(e);break;case"UnaryExpression":r=this.unaryExpressionHandler(e);break;case"UpdateExpression":r=this.updateExpressionHandler(e);break;case"ObjectExpression":r=this.objectExpressionHandler(e);break;case"ArrayExpression":r=this.arrayExpressionHandler(e);break;case"CallExpression":r=this.callExpressionHandler(e);break;case"NewExpression":r=this.newExpressionHandler(e);break;case"MemberExpression":r=this.memberExpressionHandler(e);break;case"ThisExpression":r=this.thisExpressionHandler(e);break;case"SequenceExpression":r=this.sequenceExpressionHandler(e);break;case"Literal":r=this.literalHandler(e);break;case"Identifier":r=this.identifierHandler(e);break;case"AssignmentExpression":r=this.assignmentExpressionHandler(e);break;case"FunctionDeclaration":r=this.functionDeclarationHandler(e);break;case"VariableDeclaration":r=this.variableDeclarationHandler(e);break;case"BlockStatement":case"Program":r=this.programHandler(e);break;case"ExpressionStatement":r=this.expressionStatementHandler(e);break;case"EmptyStatement":r=this.emptyStatementHandler(e);break;case"ReturnStatement":r=this.returnStatementHandler(e);break;case"FunctionExpression":r=this.functionExpressionHandler(e);break;case"IfStatement":r=this.ifStatementHandler(e);break;case"ConditionalExpression":r=this.conditionalExpressionHandler(e);break;case"ForStatement":r=this.forStatementHandler(e);break;case"WhileStatement":r=this.whileStatementHandler(e);break;case"DoWhileStatement":r=this.doWhileStatementHandler(e);break;case"ForInStatement":r=this.forInStatementHandler(e);break;case"WithStatement":r=this.withStatementHandler(e);break;case"ThrowStatement":r=this.throwStatementHandler(e);break;case"TryStatement":r=this.tryStatementHandler(e);break;case"ContinueStatement":r=this.continueStatementHandler(e);break;case"BreakStatement":r=this.breakStatementHandler(e);break;case"SwitchStatement":r=this.switchStatementHandler(e);break;case"LabeledStatement":r=this.labeledStatementHandler(e);break;case"DebuggerStatement":r=this.debuggerStatementHandler(e);break;default:throw this.createInternalThrowError($.NodeTypeSyntaxError,e.type,e)}return function(){const n=t.options.timeout;if(n&&n>0&&t.checkTimeout())throw t.createInternalThrowError($.ExecutionTimeOutError,n,null);return t.lastExecNode=e,r(...arguments)}}binaryExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{const n=t(),s=r();switch(e.operator){case"==":return n==s;case"!=":return n!=s;case"===":return n===s;case"!==":return n!==s;case"<":return n<s;case"<=":return n<=s;case">":return n>s;case">=":return n>=s;case"<<":return n<<s;case">>":return n>>s;case">>>":return n>>>s;case"+":return n+s;case"-":return n-s;case"*":return n*s;case"**":return Math.pow(n,s);case"/":return n/s;case"%":return n%s;case"|":return n|s;case"^":return n^s;case"&":return n&s;case"in":return n in s;case"instanceof":return n instanceof s;default:throw this.createInternalThrowError($.BinaryOperatorSyntaxError,e.operator,e)}}}logicalExpressionHandler(e){const t=this.createClosure(e.left),r=this.createClosure(e.right);return()=>{switch(e.operator){case"||":return t()||r();case"&&":return t()&&r();default:throw this.createInternalThrowError($.LogicalOperatorSyntaxError,e.operator,e)}}}unaryExpressionHandler(e){if("delete"===e.operator){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>delete t()[r()]}{let t;if("typeof"===e.operator&&"Identifier"===e.argument.type){const r=this.createObjectGetter(e.argument),n=this.createNameGetter(e.argument);t=()=>r()[n()]}else t=this.createClosure(e.argument);return()=>{const r=t();switch(e.operator){case"-":return-r;case"+":return+r;case"!":return!r;case"~":return~r;case"void":return;case"typeof":return typeof r;default:throw this.createInternalThrowError($.UnaryOperatorSyntaxError,e.operator,e)}}}}updateExpressionHandler(e){const t=this.createObjectGetter(e.argument),r=this.createNameGetter(e.argument);return()=>{const n=t(),s=r();switch(this.assertVariable(n,s,e),e.operator){case"++":return e.prefix?++n[s]:n[s]++;case"--":return e.prefix?--n[s]:n[s]--;default:throw this.createInternalThrowError($.UpdateOperatorSyntaxError,e.operator,e)}}}objectExpressionHandler(e){const t=[],r=Object.create(null);return e.properties.forEach((e=>{const n=e.kind,s=function(e){return"Identifier"===e.type?e.name:"Literal"===e.type?e.value:this.throwError($.ObjectStructureSyntaxError,e.type,e)}(e.key);r[s]&&"init"!==n||(r[s]={}),r[s][n]=this.createClosure(e.value),t.push({key:s,property:e})})),()=>{const e={},n=t.length;for(let s=0;s<n;s++){const n=t[s],o=n.key,a=r[o],i=a.init?a.init():void 0,c=a.get?a.get():function(){},l=a.set?a.set():function(e){};if("set"in a||"get"in a){const t={configurable:!0,enumerable:!0,get:c,set:l};Object.defineProperty(e,o,t)}else{const t=n.property,r=t.kind;"Identifier"!==t.key.type||"FunctionExpression"!==t.value.type||"init"!==r||t.value.id||Q(i,t.key.name),e[o]=i}}return e}}arrayExpressionHandler(e){const t=e.elements.map((e=>e?this.createClosure(e):e));return()=>{const e=t.length,r=Array(e);for(let n=0;n<e;n++){const e=t[n];e&&(r[n]=e())}return r}}safeObjectGet(e,t,r){return e[t]}createCallFunctionGetter(e){if("MemberExpression"===e.type){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e),n=this.source;return()=>{const s=t(),o=r(),a=this.safeObjectGet(s,o,e);if(!a||!ae(a)){const t=n.slice(e.start,e.end);throw this.createInternalThrowError($.FunctionUndefinedReferenceError,t,e)}return a.bind(s)}}{const t=this.createClosure(e);return()=>{let r="";"Identifier"===e.type&&(r=e.name);const n=t();if(!n||!ae(n))throw this.createInternalThrowError($.FunctionUndefinedReferenceError,r,e);let s=this.options.globalContextInFunction;if("Identifier"===e.type){const t=this.getIdentifierScope(e);t.name===re&&(s=t.data)}return n.bind(s)}}}callExpressionHandler(e){const t=this.createCallFunctionGetter(e.callee),r=e.arguments.map((e=>this.createClosure(e)));return()=>t()(...r.map((e=>e())))}functionExpressionHandler(e){const t=this,r=this.source,n=this.collectDeclVars,s=this.collectDeclFuncs;this.collectDeclVars=Object.create(null),this.collectDeclFuncs=Object.create(null);const o=e.id?e.id.name:"",a=e.params.length,i=e.params.map((e=>this.createParamNameGetter(e))),c=this.createClosure(e.body),l=this.collectDeclVars,u=this.collectDeclFuncs;return this.collectDeclVars=n,this.collectDeclFuncs=s,()=>{const n=t.getCurrentScope(),s=function(){for(var e=arguments.length,r=new Array(e),a=0;a<e;a++)r[a]=arguments[a];t.callStack.push("".concat(o));const h=t.getCurrentScope(),d=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0;return new ue(Object.create(null),e,t)}(n,"FunctionScope(".concat(o,")"));t.setCurrentScope(d),t.addDeclarationsToScope(l,u,d),o&&(d.data[o]=s),d.data.arguments=arguments,i.forEach(((e,t)=>{d.data[e()]=r[t]}));const p=t.getCurrentContext();t.setCurrentContext(this);const g=c();if(t.setCurrentContext(p),t.setCurrentScope(h),t.callStack.pop(),g instanceof ie)return g.value};return Q(s,o),Object.defineProperty(s,"length",{value:a,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(s,"toString",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(s,"valueOf",{value:()=>r.slice(e.start,e.end),writable:!0,configurable:!0,enumerable:!1}),s}}newExpressionHandler(e){const t=this.source,r=this.createClosure(e.callee),n=e.arguments.map((e=>this.createClosure(e)));return()=>{const s=r();if(!ae(s)||s.__IS_EVAL_FUNC){const r=e.callee,n=t.slice(r.start,r.end);throw this.createInternalThrowError($.IsNotConstructor,n,e)}return new s(...n.map((e=>e())))}}memberExpressionHandler(e){const t=this.createClosure(e.object),r=this.createMemberKeyGetter(e);return()=>t()[r()]}thisExpressionHandler(e){return()=>this.getCurrentContext()}sequenceExpressionHandler(e){const t=e.expressions.map((e=>this.createClosure(e)));return()=>{let e;const r=t.length;for(let n=0;n<r;n++)e=(0,t[n])();return e}}literalHandler(e){return()=>e.regex?new RegExp(e.regex.pattern,e.regex.flags):e.value}identifierHandler(e){return()=>{const t=this.getCurrentScope(),r=this.getScopeDataFromName(e.name,t);return this.assertVariable(r,e.name,e),r[e.name]}}getIdentifierScope(e){const t=this.getCurrentScope();return this.getScopeFromName(e.name,t)}assignmentExpressionHandler(e){"Identifier"!==e.left.type||"FunctionExpression"!==e.right.type||e.right.id||(e.right.id={type:"Identifier",name:e.left.name});const t=this.createObjectGetter(e.left),r=this.createNameGetter(e.left),n=this.createClosure(e.right);return()=>{const s=t(),o=r(),a=n();switch("="!==e.operator&&this.assertVariable(s,o,e),e.operator){case"=":return s[o]=a;case"+=":return s[o]+=a;case"-=":return s[o]-=a;case"*=":return s[o]*=a;case"**=":return s[o]=Math.pow(s[o],a);case"/=":return s[o]/=a;case"%=":return s[o]%=a;case"<<=":return s[o]<<=a;case">>=":return s[o]>>=a;case">>>=":return s[o]>>>=a;case"&=":return s[o]&=a;case"^=":return s[o]^=a;case"|=":return s[o]|=a;default:throw this.createInternalThrowError($.AssignmentExpressionSyntaxError,e.type,e)}}}functionDeclarationHandler(e){if(e.id){const t=this.functionExpressionHandler(e);Object.defineProperty(t,"isFunctionDeclareClosure",{value:!0,writable:!1,configurable:!1,enumerable:!1}),this.funcDeclaration(e.id.name,t)}return()=>te}getVariableName(e){if("Identifier"===e.type)return e.name;throw this.createInternalThrowError($.VariableTypeSyntaxError,e.type,e)}variableDeclarationHandler(e){let t;const r=[];for(let t=0;t<e.declarations.length;t++){const n=e.declarations[t];this.varDeclaration(this.getVariableName(n.id)),n.init&&r.push({type:"AssignmentExpression",operator:"=",left:n.id,right:n.init})}return r.length&&(t=this.createClosure({type:"BlockStatement",body:r})),()=>{if(t){const e=this.isVarDeclMode;this.isVarDeclMode=!0,t(),this.isVarDeclMode=e}return te}}assertVariable(e,t,r){if(e===this.globalScope.data&&!(t in e))throw this.createInternalThrowError($.VariableUndefinedReferenceError,t,r)}programHandler(e){const t=e.body.map((e=>this.createClosure(e)));return()=>{let e=te;for(let r=0;r<t.length;r++){const n=t[r],s=this.setValue(n());if(s!==te&&(e=s,e instanceof ie||e instanceof ce||e instanceof le||e===Y||e===Z))break}return e}}expressionStatementHandler(e){return this.createClosure(e.expression)}emptyStatementHandler(e){return()=>te}returnStatementHandler(e){const t=e.argument?this.createClosure(e.argument):he;return()=>new ie(t())}ifStatementHandler(e){const t=this.createClosure(e.test),r=this.createClosure(e.consequent),n=e.alternate?this.createClosure(e.alternate):/*!important*/()=>te;return()=>t()?r():n()}conditionalExpressionHandler(e){return this.ifStatementHandler(e)}forStatementHandler(e){let t=he,r=e.test?this.createClosure(e.test):()=>!0,n=he;const s=this.createClosure(e.body);return"ForStatement"===e.type&&(t=e.init?this.createClosure(e.init):t,n=e.update?this.createClosure(e.update):he),o=>{let a,i=te,c="DoWhileStatement"===e.type;for(o&&"LabeledStatement"===o.type&&(a=o.label.name),t();c||r();n()){c=!1;const e=this.setValue(s());if(e!==te&&e!==Z){if(e===Y)break;if(i=e,i instanceof le&&i.value===a)i=te;else if(i instanceof ie||i instanceof ce||i instanceof le)break}}return i}}whileStatementHandler(e){return this.forStatementHandler(e)}doWhileStatementHandler(e){return this.forStatementHandler(e)}forInStatementHandler(e){let t=e.left;const r=this.createClosure(e.right),n=this.createClosure(e.body);return"VariableDeclaration"===e.left.type&&(this.createClosure(e.left)(),t=e.left.declarations[0].id),e=>{let s,o,a=te;e&&"LabeledStatement"===e.type&&(s=e.label.name);const i=r();for(o in i){this.assignmentExpressionHandler({type:"AssignmentExpression",operator:"=",left:t,right:{type:"Literal",value:o}})();const e=this.setValue(n());if(e!==te&&e!==Z){if(e===Y)break;if(a=e,a instanceof le&&a.value===s)a=te;else if(a instanceof ie||a instanceof ce||a instanceof le)break}}return a}}withStatementHandler(e){const t=this.createClosure(e.object),r=this.createClosure(e.body);return()=>{const e=t(),n=this.getCurrentScope(),s=new ue(e,n,re);this.setCurrentScope(s);const o=this.setValue(r());return this.setCurrentScope(n),o}}throwStatementHandler(e){const t=this.createClosure(e.argument);return()=>{throw this.setValue(void 0),t()}}tryStatementHandler(e){const t=this.createClosure(e.block),r=e.handler?this.catchClauseHandler(e.handler):null,n=e.finalizer?this.createClosure(e.finalizer):null;return()=>{const e=this.getCurrentScope(),s=this.getCurrentContext(),o=e.labelStack.concat([]),a=this.callStack.concat([]);let i,c,l=te;const u=()=>{this.setCurrentScope(e),this.setCurrentContext(s),e.labelStack=o,this.callStack=a};try{l=this.setValue(t()),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;if(r)try{l=this.setValue(r(e)),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}}if(n)try{l=n(),l instanceof ie&&(i=l)}catch(e){if(u(),this.isInterruptThrow(e))throw e;c=e}if(c)throw c;return i||l}}catchClauseHandler(e){const t=this.createParamNameGetter(e.param),r=this.createClosure(e.body);return e=>{let n;const s=this.getCurrentScope().data,o=t(),a=X.call(s,o),i=s[o];return s[o]=e,n=r(),a?s[o]=i:delete s[o],n}}continueStatementHandler(e){return()=>e.label?new le(e.label.name):Z}breakStatementHandler(e){return()=>e.label?new ce(e.label.name):Y}switchStatementHandler(e){const t=this.createClosure(e.discriminant),r=e.cases.map((e=>this.switchCaseHandler(e)));return()=>{const e=t();let n,s,o,a=!1;for(let t=0;t<r.length;t++){const i=r[t](),c=i.testClosure();if(c!==ee){if(a||c===e){if(a=!0,s=this.setValue(i.bodyClosure()),s===te)continue;if(s===Y)break;if(n=s,n instanceof ie||n instanceof ce||n instanceof le||n===Z)break}}else o=i}return!a&&o&&(s=this.setValue(o.bodyClosure()),s===te||s===Y||(n=s)),n}}switchCaseHandler(e){const t=e.test?this.createClosure(e.test):()=>ee,r=this.createClosure({type:"BlockStatement",body:e.consequent});return()=>({testClosure:t,bodyClosure:r})}labeledStatementHandler(e){const t=e.label.name,r=this.createClosure(e.body);return()=>{let n;const s=this.getCurrentScope();return s.labelStack.push(t),n=r(e),n instanceof ce&&n.value===t&&(n=te),s.labelStack.pop(),n}}debuggerStatementHandler(e){return()=>te}createParamNameGetter(e){if("Identifier"===e.type)return()=>e.name;throw this.createInternalThrowError($.ParamTypeSyntaxError,e.type,e)}createObjectKeyGetter(e){let t;return t="Identifier"===e.type?()=>e.name:this.createClosure(e),function(){return t()}}createMemberKeyGetter(e){return e.computed?this.createClosure(e.property):this.createObjectKeyGetter(e.property)}createObjectGetter(e){switch(e.type){case"Identifier":return()=>this.getScopeDataFromName(e.name,this.getCurrentScope());case"MemberExpression":return this.createClosure(e.object);default:throw this.createInternalThrowError($.AssignmentTypeSyntaxError,e.type,e)}}createNameGetter(e){switch(e.type){case"Identifier":return()=>e.name;case"MemberExpression":return this.createMemberKeyGetter(e);default:throw this.createInternalThrowError($.AssignmentTypeSyntaxError,e.type,e)}}varDeclaration(e){this.collectDeclVars[e]=void 0}funcDeclaration(e,t){this.collectDeclFuncs[e]=t}addDeclarationsToScope(e,t,r){const n=r.data;for(let e in t){const r=t[e];n[e]=r?r():r}for(let t in e)t in n||(n[t]=void 0)}getScopeValue(e,t){return this.getScopeFromName(e,t).data[e]}getScopeDataFromName(e,t){return this.getScopeFromName(e,t).data}getScopeFromName(e,t){let r=t;do{if(e in r.data)return r}while(r=r.parent);return this.globalScope}setValue(e){const t=this.callStack.length;return this.isVarDeclMode||t||e===te||e===Y||e===Z||e instanceof ce||e instanceof le||(this.value=e instanceof ie?e.value:e),e}getValue(){return this.value}}i(pe,"version","0.0.0"),i(pe,"ecmaVersion",5),i(pe,"globalContextInFunction",void 0),i(pe,"global",Object.create(null));class ge{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(ge.hasInitd)return;ge.hasInitd=!0,V.addListener("debug",ge.handleDebugger);const t=this;this.proxyTypes.forEach((r=>{this.console[r]=console[r]||console.log||(()=>{}),Object.defineProperty(console,r,{value(){const n=getCurrentPages().pop();let s="/";n&&(s=n.route,n.options&&Object.keys(n.options).length>0&&(s+="?"+e(n.options)));for(var o=arguments.length,a=new Array(o),i=0;i<o;i++)a[i]=arguments[i];t.printLog({logType:r,logs:a,url:s})},configurable:!0,enumerable:!0,writable:!0})})),ge.interpreter||(ge.interpreter=new pe((()=>{let e={};return"undefined"!=typeof globalThis?e=globalThis:"undefined"!=typeof window?e=window:"object"==typeof global&&Object.keys(global).length>1&&(e=global),n&&Object.assign(e,n),e})()))}onReset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)})),ge.hasInitd=!1,ge.interpreter=null}static handleDebugger(e,t){let{source:r}=e;const{type:n,data:s}=r;if("debug"===n){const{code:e,nodes:r}=s;t(j("console",{logType:"debug-origin",logs:[{id:c(),type:"debug-origin",value:e}]}));try{var o;const e=null===(o=ge.interpreter)||void 0===o?void 0:o.evaluateNode(r);t(j("console",{logType:"debug-eval",logs:[P.transformToAtom(e)]}))}catch(e){t(j("console",{logType:"error",logs:[{type:"error",value:e.stack}]}))}}}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>P.transformToAtom(e)));const t=j("console",{time:Date.now(),...e});V.dispatchEvent("public-data",t),V.broadcastMessage(t)}}}i(ge,"hasInitd",!1),i(ge,"interpreter",null);class me{constructor(){i(this,"name","ErrorPlugin")}onInit(){me.hasInitd||(me.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=r();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnHandledRejection")&&e.offUnHandledRejection(this.unhandledRejectionHandler),me.hasInitd=!1}errorHandler(e){if(me.hasInitd)if(e.stack||e.message){const{message:t,stack:r}=e;me.sendMessage(r||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:r,stack:n}=Object(e);return!1===[t,r,n].every(Boolean)?null:{name:t,message:r,stack:n}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";me.sendMessage(e,null)}}unhandledRejectionHandler(e){me.hasInitd&&me.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=r();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=r();e.canIUse("onUnHandledRejection")&&e.onUnHandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const r=j("console",{logType:"error",logs:[P.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t});V.dispatchEvent("public-data",r),V.broadcastMessage(r)}}var fe;function ye(e,t){try{let r,n;if("object"==typeof window&&"object"==typeof document&&"[object HTMLDocument]"===Object.prototype.toString.call(document)){const{searchParams:s,href:o}=new URL(e,t);r=o,n=[...s.entries()]}else r=e.toString(),n=function(e){const t=/[?&]([^=#]+)=([^&#]*)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=decodeURIComponent(n[1]),t=decodeURIComponent(n[2]);r.push([e,t])}return r}(r);const s=r.replace(/^.*?([^/]+)(\/)*(\?.*?)?$/,"$1$2$3")||"";return{url:r,name:s,query:n}}catch(e){return{url:"Unknown",name:"Unknown",query:null}}}i(me,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(fe||(fe={}));class Se{constructor(e){w(this,"id",""),w(this,"name",""),w(this,"method",""),w(this,"url",""),w(this,"requestType","xhr"),w(this,"requestHeader",null),w(this,"status",0),w(this,"statusText",""),w(this,"readyState",0),w(this,"responseReason",null),w(this,"responseType",""),w(this,"responseHeader",null),w(this,"startTime",0),w(this,"endTime",0),w(this,"costTime",0),w(this,"getData",null),w(this,"postData",null),w(this,"requestPayload",null),w(this,"withCredentials",!1),this.id=e}}class be{constructor(e){w(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(v.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new Se(e),!0):(v.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){try{this.reqMap[e]||(this.reqMap[e]=t);const r=j("network",{...t},!1);Number(t.readyState)===fe.DONE&&this.socketStore.dispatchEvent("public-data",r),this.socketStore.broadcastMessage(r,t.readyState!==fe.DONE),this.deferDeleteRequest(e)}catch(e){v.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===fe.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class ve extends be{constructor(){super(V)}}class Ee extends ve{constructor(){super(),i(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=r();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=r(),n=t.request;n&&(this.request=n,Object.defineProperty(t,"request",{value(t){const r=c();e.createRequest(r);const s=e.getRequest(r);if(s){const o=t.method||"GET",{url:a}=t;s.requestHeader=[];const i=ye(a);if(s.url=i.url,s.name=i.name,s.getData=i.query,s.method=o.toUpperCase(),s.requestType="mp-request",s.status=0,s.statusText="Pending",s.startTime=Date.now(),s.readyState=fe.UNSENT,g(t.header)&&(s.requestHeader=Object.entries(t.header).map((e=>{let[t,r]=e;return[String(t),String(r)]}))),"GET"!==s.method){s.requestHeader.push(["Content-Type","application/json"]);const{data:e}=t;if(e)if("string"==typeof e)s.requestPayload=e;else if(e instanceof ArrayBuffer)s.requestPayload="[object ArrayBuffer]";else try{s.requestPayload=JSON.stringify(e)}catch(t){s.requestPayload=l(e)}}e.sendRequestItem(r,s);const c=t.success,u=t.fail,h=t.complete,d=()=>{s.endTime=Date.now(),s.costTime=s.endTime-(s.startTime||s.endTime)};t.success=function(t){d(),s.status=(null==t?void 0:t.statusCode)||200,s.statusText="Done",s.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],s.readyState=fe.HEADERS_RECEIVED,e.sendRequestItem(r,s);const n=function(e){const t=Object.keys(e),r={};for(let n=0;n<t.length;n++){const s=t[n];r[s.toLowerCase()]=e[s]}return r}((null==t?void 0:t.header)||{}),o=n["content-type"];switch(o&&(o.includes("application/json")&&(s.responseType="json"),(o.includes("text/html")||o.includes("text/plain"))&&(s.responseType="text")),s.responseType||(s.responseType="arraybuffer"),s.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{s.response=JSON.parse(t.data)}catch(e){s.response=t.data,s.responseType="text"}else s.response=null==t?void 0:t.data;break;case"arraybuffer":s.response="[object ArrayBuffer]"}null==c||c(t)},t.fail=function(e){d(),null==u||u(e)},t.complete=function(t){s.readyState=fe.DONE,e.sendRequestItem(r,s),null==h||h(t)};return n(t)}return v.warn("The request object is not found on request event"),null}}))}}class Ce{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){Ce.hasInitd||(Ce.hasInitd=!0,this.requestProxy=new Ee)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),Ce.hasInitd=!1}}i(Ce,"hasInitd",!1);class we{constructor(){i(this,"name","SystemPlugin")}onInit(){we.hasInitd||(we.hasInitd=!0,V.addListener("refresh",((e,t)=>{let{source:r}=e;const{data:n}=r;if("system"===n){const e=we.getSystemInfo();V.dispatchEvent("public-data",e),t(e)}})))}onReset(){we.hasInitd=!1}static getSystemInfo(){const e=H.info;return j("system",{system:{ua:R(e)},features:{}})}}function ke(e){const t=typeof e;let r=e;return"string"===t||"boolean"===t||"number"===t?r=String(e):"object"===t&&(r=e instanceof Date?e.toDateString():JSON.stringify(e)),r}i(we,"hasInitd",!1);class xe{constructor(){i(this,"name","StoragePlugin")}onInit(){xe.hasInitd||(xe.hasInitd=!0,xe.initStorageProxy(),xe.listenRefreshEvent())}onReset(){const e=r();Object.entries(xe.originFunctions).forEach((t=>{let[r,n]=t;Object.defineProperty(e,r,{value:n})})),xe.hasInitd=!1}static sendRefresh(){const e=r();try{const t=e.getStorageInfoSync(),r={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:ke(s.getStorage(e))})))};xe.sendStorageItem(r)}catch(e){}}static listenRefreshEvent(){V.addListener("refresh",(async e=>{let{source:t}=e;const{data:r}=t;"mpStorage"===r&&xe.sendRefresh()}))}static initStorageProxy(){const e=r(),{sendClearItem:t,sendRemoveItem:n,sendSetItem:s}=xe;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(xe.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>xe.originFunctions.setStorage({...e,success(t){var r;s(e.key,e.data),null===(r=e.success)||void 0===r||r.call(e,t)}})},setStorageSync:{value(e,t){try{let r;if("mp-alipay"!==H.info.browserType||H.info.framework&&"unknown"!==H.info.framework){const n=e;r=xe.originFunctions.setStorageSync(n,t),s(n,t)}else{const t=e;r=xe.originFunctions.setStorageSync(t),s(t.key,t.data)}return r}catch(t){throw v.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>xe.originFunctions.removeStorage({...e,success(t){var r;n(e.key),null===(r=e.success)||void 0===r||r.call(e,t)}})},removeStorageSync:{value(e){try{const t=xe.originFunctions.removeStorageSync(e);return n(t),t}catch(t){throw v.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>xe.originFunctions.clearStorage({...e,success(r){var n;t(),null===(n=e.success)||void 0===n||n.call(e,r)}})},clearStorageSync:{value(){try{const e=xe.originFunctions.clearStorageSync();return t(),e}catch(e){throw v.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=xe.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{s(e.key,e.value)})),t}catch(t){throw v.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>xe.originFunctions.batchSetStorage({...e,success(t){var r;e.kvList.forEach((e=>{s(e.key,e.value)})),null===(r=e.success)||void 0===r||r.call(e,t)}})})}static sendSetItem(e,t){xe.sendStorageItem({type:"mpStorage",action:"set",name:e,value:ke(t)})}static sendRemoveItem(e){xe.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){xe.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=j("storage",e);V.dispatchEvent("public-data",t),V.broadcastMessage(t,!0)}}i(xe,"hasInitd",!1),i(xe,"originFunctions",{});const Ie=e=>!1===e?["http://","ws://"]:["https://","wss://"];class Te{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:t,project:n,title:s,useSecret:o,secret:a}=this.config.get(),i=Ie(t),c=R(H.info),l=e({group:n,title:s,name:encodeURIComponent(c)});return(u=r().request,e=>new Promise(((t,r)=>{u({...e,success(e){t(e)},fail(e){r(e)}})})))({url:"".concat(i[0]).concat(this.base,"/api/v1/room/create?").concat(l),method:"POST",data:JSON.stringify({useSecret:o,secret:a})}).then((e=>{var t;const{name:r,address:n}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(n),address:n,name:r}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var u}getRoomUrl(t){const r=this.config.get(),n=Ie(r.enableSSL);return"".concat(n[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e({address:t,name:"client:".concat(c()),userId:"Client",forceCreate:!0,useSecret:r.useSecret,secret:r.secret}))}}class Oe{defaultConfig(){return{}}constructor(){w(this,"mergeConfig",(e=>{const t=Object.entries(e).reduce(((e,t)=>{let[r,n]=t;return this.privateKeys.includes(r)||(e[r]=n),e}),{});return this.value={...this.defaultConfig(),...t},this.value})),this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}class je extends Oe{constructor(){super(...arguments),i(this,"privateKeys",["secret"])}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:""}}}class Ne{constructor(e){if(i(this,"root",null),i(this,"version","1.8.10"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",V),i(this,"config",new je),i(this,"cacheTimer",null),Ne.instance)return v.warn("Cannot initialize PageSpy multiple times"),Ne.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(L.isSingleSocket=!0);const n=r();if(n.canIUse("getAccountInfoSync")){if("release"===n.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void v.warn("PageSpy is not allowed on release env of mini program")}Ne.instance=this;const s="!!!WARNING!!!: When submitting the mini program for review, be sure to delete the SDK in the code, otherwise the review will fail.";v.log(s),v.info(s),v.warn(s),this.request=new Te(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:V,config:t}),H.plugins=Ne.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=s.getStorage(A),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),v.log("Room Secret: ".concat(t))}V.connectable=!0,V.getPageSpyConfig=()=>this.config.get(),V.messageCapacity=e}async init(){const e=r(),t=this.config.get(),n=s.getStorage(A);if(n&&"object"==typeof n){const{name:e,address:r,roomUrl:s,project:o}=n;t.project!==o?await this.createNewConnection():(this.name=e,this.address=r,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=V.getSocket().getState();e!==D.CLOSED&&e!==D.CLOSING||this.useOldConnection()})),v.log("Plugins inited")}async createNewConnection(){if(!this.request)return void v.error("Cannot get the Request");const e=await this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),V.init(e.roomUrl)}useOldConnection(){this.refreshRoomInfo(),V.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{V.getSocket().getState()===D.OPEN&&this.saveSession()}),15e3),v.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:r,config:n}=this,{useSecret:o,secret:a,project:i}=n.get(),c={name:e,address:t,roomUrl:r,project:i,useSecret:o,secret:a};s.setStorage(A,c)}triggerPlugins(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];const{disabledPlugins:s}=this.config.get();Ne.pluginsWithOrder.forEach((t=>{var n;d(s)&&s.length&&s.includes(t.name)||null===(n=t[e])||void 0===n||n.apply(t,r)}))}abort(){this.triggerPlugins("onReset"),V.close(),Ne.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:r}=e;t&&this.config.set("project",String(t)),r&&this.config.set("title",String(r)),V.updateRoomInfo()}static get pluginsWithOrder(){return[...Ne.plugins.pre,...Ne.plugins.normal,...Ne.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void v.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void v.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));const r=Ne.pluginsWithOrder.some((t=>t.name===e.name));if(r)return void v.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));Ne.plugins[e.enforce||"normal"].push(e)}}i(Ne,"instance",null),i(Ne,"plugins",{pre:[],normal:[],post:[]});var Pe;[new ge,new me,new Ce,new xe,new we].forEach((e=>{Ne.registerPlugin(e)})),Pe=my,t=Pe,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const Re=my.getSystemInfoSync();H.info.sdk="mp-alipay",H.info.osType=Re.platform.toLowerCase(),H.info.browserType="mp-alipay",H.info.osVersion=Re.system,H.info.browserVersion=Re.version,F.messageFilters.push((e=>e.data));export{Ne as default};
const e=e=>{const t=[];return Object.entries(e).forEach((e=>{let[n,s]=e;t.push("".concat(n,"=").concat(s))})),t.join("&")};let t;const n=()=>{if(!t)throw Error("the mp sdk is not set");return t},s={setStorage(e,n){var s;return null===(s=t)||void 0===s?void 0:s.setStorageSync(e,n)},getStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)},removeStorage(e){var n;return null===(n=t)||void 0===n?void 0:n.getStorageSync(e)}};function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function r(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t||"default");if("object"!=o(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:t+""}function i(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){return Math.random().toString(36).slice(2)}function c(e){return Object.prototype.toString.call(e)}function l(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function u(e){return"[object BigInt]"===c(e)}function h(e){return e instanceof Array}function g(e){return"object"==typeof e&&null!==e}function d(e){return!(!g(e)||"[object Object]"!==c(e))}const p=e=>"".concat(e),f=e=>({ok:!0,value:e});function m(e){return void 0===e?f(p(e)):null===e?f(e):function(e){return"number"==typeof e}(e)&&(e===-1/0||e===1/0||Number.isNaN(e))?f(p(e)):u(e)?f("".concat(e,"n")):"symbol"==typeof e||"function"==typeof e?f(p(e.toString())):e instanceof Error?f(p(e.stack)):e===Object.prototype?{value:null,ok:!1}:e instanceof Object||"object"==typeof e?{value:e,ok:!1}:f(e)}function y(e){return void 0===e?"undefined":null===e?"null":u(e)?"bigint":e instanceof Object?e instanceof Error?"error":"function"==typeof e?"function":"object":typeof e}const S={...console},v=["log","info","error","warn","debug"].reduce(((e,t)=>(e[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];console[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e.unproxy[t]=function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];S[t]("[PageSpy] [".concat(t.toLocaleUpperCase(),"] "),...n)},e)),{unproxy:{}});const b="message",I="broadcast",O="ping",E="updateRoomInfo";var T=Object.freeze({__proto__:null,BROADCAST:I,CLOSE:"close",CONNECT:"connect",ERROR:"error",JOIN:"join",LEAVE:"leave",MESSAGE:b,PING:O,PONG:"pong",UPDATE_ROOM_INFO:E});function k(e,t){return{role:"client",type:e,data:{...(!(arguments.length>2&&void 0!==arguments[2])||arguments[2])&&{id:a()},...t}}}class w{constructor(){i(this,"store",{}),i(this,"instanceStore",{})}getStore(){return this.store}resetStore(){this.store={}}getInstanceStore(){return this.instanceStore}resetInstanceStore(){this.instanceStore={}}transformToAtom(e){const{value:t,ok:n}=m(e);return n?{id:a(),type:y(e),value:t}:this.add(e)}get(e){const t=this.store[e],n=this.instanceStore[e];if(!t)return null;const s={},o=Object.getOwnPropertyDescriptors(t);Object.keys(o).forEach((e=>{const t=o[e];l(t,"value")&&(t.value=this.transformToAtom(t.value)),s[e]=w.getAtomOverview({atomId:a(),instanceId:n,value:t})}));const r=this.addExtraProperty(e);return{...s,...r}}getOrigin(e){const t=this.store[e];return t||null}add(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const n=a();let s=n;var o;g(o=e)&&l(o,"constructor")&&"function"==typeof o.constructor&&(s=t),this.store[n]=e,this.instanceStore[n]=s;const r=w.getSemanticValue(e);return w.getAtomOverview({atomId:n,value:r,instanceId:s})}static getAtomOverview(e){let{instanceId:t="",atomId:n,value:s}=e;return{id:a(),type:"atom",__atomId:n,instanceId:t,value:s}}static getSemanticValue(e){if(d(e))return"Object {...}";if(h(e))return"Array (".concat(e.length,")");return e.constructor.name}addExtraProperty(e){const t=this.store[e],n=this.instanceStore[e],s={};if((t instanceof String||t instanceof Number||t instanceof Boolean)&&(s["[[PrimitiveValue]]"]=this.transformToAtom(t.valueOf())),t instanceof Set){const e={};let n=0;for(const s of t)e[n++]=s;e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}if(t instanceof Map){const e={};let n=0;for(const[s,o]of t.entries())e[n++]={key:s,value:o};e.size=t.size,s["[[Entries]]"]=this.transformToAtom(e)}var o;return(h(t)||(o=t,"function"==typeof NodeList&&"NodeList"===NodeList.name&&o instanceof NodeList||"function"==typeof HTMLCollection&&"HTMLCollection"===HTMLCollection.name&&o instanceof HTMLCollection))&&(s.length=this.transformToAtom(t.length)),null!==Object.getPrototypeOf(t)?s["[[Prototype]]"]=this.add(Object.getPrototypeOf(t),n):s.___proto___=this.transformToAtom(null),s}}var C=new w;const P=e=>{let{osType:t,osVersion:n,browserType:s,browserVersion:o}=e;return"".concat(t,"/").concat(n," ").concat(s,"/").concat(o)};class j{static makeClientInfoMsg(){const e=j.info.ua||P(j.info);return{sdk:j.info.sdk,isDevTools:j.info.isDevTools,ua:e,plugins:j.plugins}}}var R;i(j,"info",{osType:"unknown",osVersion:"unknown",browserType:"unknown",browserVersion:"unknown",framework:"unknown",isDevTools:!1,sdk:"browser"}),i(j,"plugins",[]),function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(R||(R={}));const N=2e3,q=Math.pow(1.5,4)*N;class A{constructor(){i(this,"events",{open:[],close:[],error:[],message:[]})}emit(e,t){this.events[e].forEach((e=>{e(t)})),"close"!==e&&"error"!==e||this.clearListeners()}onOpen(e){this.events.open.push(e)}onClose(e){this.events.close.push(e)}onError(e){this.events.error.push(e)}onMessage(e){this.events.message.push(e)}clearListeners(){Object.entries(this.events).forEach((e=>{let[,t]=e;t.splice(0)}))}}class D{constructor(){i(this,"socketUrl",""),i(this,"socketConnection",null),i(this,"debuggerConnection",null),i(this,"pingTimer",null),i(this,"pongTimer",null),i(this,"retryTimer",null),i(this,"isOffline",!1),i(this,"messageCapacity",0),i(this,"messages",[]),i(this,"events",{debug:[],refresh:[],"atom-detail":[],"atom-getter":[],"debugger-online":[],"database-pagination":[],"public-data":[]}),i(this,"retryInterval",N),i(this,"connectable",!0),this.addListener("atom-detail",D.handleResolveAtom),this.addListener("atom-getter",D.handleAtomPropertyGetter),this.addListener("debugger-online",this.handleFlushBuffer)}async init(e){try{var t,n,s,o,r;if(!e)throw Error("WebSocket url cannot be empty");this.socketWrapper.clearListeners(),this.socketWrapper.getState()===R.OPEN&&await new Promise((e=>{this.socketWrapper.onClose((()=>{this.socketWrapper.clearListeners(),e()})),this.socketWrapper.close()})),null===(t=this.socketWrapper)||void 0===t||t.onOpen((()=>{this.connectOnline()})),null===(n=this.socketWrapper)||void 0===n||n.onMessage((e=>{this.handleMessage(e)})),null===(s=this.socketWrapper)||void 0===s||s.onClose((()=>{this.connectOffline()})),null===(o=this.socketWrapper)||void 0===o||o.onError((()=>{this.connectOffline()})),this.socketUrl=e,null===(r=this.socketWrapper)||void 0===r||r.init(e)}catch(e){v.error(e.message)}}addListener(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}removeListener(e,t){const n=this.events[e]||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}broadcastMessage(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const n=function(e){return{type:I,content:{data:e}}}(e);this.send(n,t)}close(){var e;this.connectable=!1,this.clearPing(),null===(e=this.socketWrapper)||void 0===e||e.close(),this.messages=[],Object.entries(this.events).forEach((e=>{let[t,n]=e;["atom-detail","atom-getter","debugger-online"].includes(t)||n.splice(0)}))}connectOnline(){this.retryInterval=N,this.updateRoomInfo(),this.ping()}connectOffline(){this.socketConnection=null,this.debuggerConnection=null,this.clearPing(),this.retryTimer&&clearTimeout(this.retryTimer),this.connectable&&(this.retryTimer=setTimeout((()=>{this.retryInterval<q&&(this.retryInterval*=1.5),this.retryTimer=null,this.tryReconnect()}),this.retryInterval))}tryReconnect(){this.init(this.socketUrl)}ping(){this.pingTimer&&clearTimeout(this.pingTimer),this.pongTimer&&clearTimeout(this.pongTimer),this.pingTimer=setTimeout((()=>{this.send({type:"ping",content:null}),this.pingTimer=null,this.pongTimer=setTimeout((()=>{this.connectOffline(),this.pongTimer=null}),5e3)}),5e3)}clearPing(){this.pingTimer&&(clearTimeout(this.pingTimer),this.pingTimer=null),this.pongTimer&&(clearTimeout(this.pongTimer),this.pongTimer=null)}handlePong(){clearTimeout(this.pongTimer),this.pongTimer=null,this.ping()}handleMessage(e){var t;D.messageFilters.length&&D.messageFilters.forEach((t=>{e=t(e)}));const{CONNECT:n,MESSAGE:s,ERROR:o,JOIN:r,PING:i,PONG:a,LEAVE:c,CLOSE:l,BROADCAST:u}=T,h=JSON.parse(e.data),{type:g}=h;switch(g){case n:const{selfConnection:e,roomConnections:i}=h.content;this.socketConnection=e,this.debuggerConnection=i.find((e=>"Debugger"===e.userId))||null;break;case r:case c:const{connection:a}=h.content;"Debugger"===a.userId&&(g===r?(this.debuggerConnection=a,this.sendClientInfo()):this.debuggerConnection=null);break;case s:const{data:u,from:d,to:p}=h.content;p.address===(null===(t=this.socketConnection)||void 0===t?void 0:t.address)&&this.dispatchEvent(u.type,{source:u,from:d,to:p});break;case l:case o:this.connectOffline()}this.handlePong()}dispatchEvent(e,t){var n;["public-data"].includes(e)?this.events["public-data"].forEach((e=>{e(t)})):null===(n=this.events[e])||void 0===n||n.forEach((e=>{e.call(this,t,(e=>{this.unicastMessage(e,t.from)}))}))}unicastMessage(e,t){const n=function(e,t,n){return{type:b,content:{data:e,from:t,to:n}}}(e,this.socketConnection,t);this.send(n)}handleFlushBuffer(e){const{latestId:t}=e.source.data,n=this.messages.findIndex((e=>e.content.data.data.id===t));this.messages.slice(n+1).forEach((t=>{const n={type:b,content:{data:t.content.data,from:this.socketConnection,to:e.from}};this.send(n,!0)}))}static handleResolveAtom(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-detail"===s){const e=C.get(o)||{};t(k("atom-detail-".concat(o),e,!1))}}static handleAtomPropertyGetter(e,t){let{source:n}=e;const{type:s,data:o}=n;if("atom-getter"===s){const{id:e,parentId:n,key:s,instanceId:i}=o,a=C.getOrigin(i),c=C.getOrigin(n);let l={};var r;if(a&&c)l=null===(r=Object.getOwnPropertyDescriptor(c,s))||void 0===r||null===(r=r.get)||void 0===r?void 0:r.call(a);else l=new Error("Getter computed failed");t(k("atom-getter-".concat(e),C.transformToAtom(l)))}}send(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.checkIfSend(e))try{var n;const t=e;t.createdAt=Date.now(),t.requestId=a();const s=function(e){const{ok:t,value:n}=m(e);return t?n:JSON.stringify(e,((e,t)=>m(t).value),2)}(t);null===(n=this.socketWrapper)||void 0===n||n.send(s)}catch(e){v.error("Incompatible: ".concat(e.message)),this.connectOffline()}this.checkIfCache(e,t)&&(0!==this.messageCapacity&&this.messages.length>=this.messageCapacity&&this.messages.shift(),this.messages.push(e))}checkIfSend(e){return this.socketWrapper.getState()===R.OPEN&&(!![E,O].includes(e.type)||!!this.debuggerConnection)}checkIfCache(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.isOffline&&!t&&![b,O].includes(e.type)}sendClientInfo(){const e=j.makeClientInfoMsg();this.broadcastMessage({role:"client",type:"client-info",data:e},!0)}}i(D,"messageFilters",[]);const L="page-spy-room";class M extends A{constructor(){super(...arguments),i(this,"socketInstance",null),i(this,"state",0)}async init(e){this.state=R.CONNECTING;const t=n(),s=e=>{this.state=R.CLOSED,this.emit("close",e)},o=e=>{this.state=R.OPEN,this.emit("open",e)},r=e=>{this.state=R.CLOSED,this.emit("error",e)},i=e=>{this.emit("message",e)};if(M.isSingleSocket)t.connectSocket({url:e}),t.onSocketClose(s),t.onSocketError(r),t.onSocketMessage(i),t.onSocketOpen(o);else{let n=t.connectSocket({url:e,multiple:!0,complete(){}});n instanceof Promise&&(n=await n),n.onClose(s),n.onError(r),n.onOpen(o),n.onMessage(i),this.socketInstance=n}}send(e){var t;M.isSingleSocket?n().sendSocketMessage({data:e}):null===(t=this.socketInstance)||void 0===t||t.send({data:e})}close(){var e;M.isSingleSocket?n().closeSocket({}):null===(e=this.socketInstance)||void 0===e||e.close({});this.state=R.CLOSED}getState(){return this.state}}i(M,"isSingleSocket",!1);var U,x=new class extends D{constructor(){super(...arguments),i(this,"socketWrapper",new M),i(this,"getPageSpyConfig",null)}updateRoomInfo(){if(this.getPageSpyConfig){const{project:e,title:t}=this.getPageSpyConfig(),n=P(j.info);this.send({type:E,content:{info:{name:n,group:e,tags:{title:t,name:n,group:e}}}},!0)}}getSocket(){return this.socketWrapper}onOffline(){s.removeStorage(L)}};class F{constructor(){i(this,"name","ConsolePlugin"),i(this,"console",{}),i(this,"proxyTypes",["log","info","error","warn","debug"])}async onInit(){if(F.hasInitd)return;F.hasInitd=!0;const t=this;this.proxyTypes.forEach((n=>{this.console[n]=console[n]||console.log||(()=>{}),Object.defineProperty(console,n,{value(){const s=getCurrentPages().pop();let o="/";s&&(o=s.route,s.options&&Object.keys(s.options).length>0&&(o+="?"+e(s.options)));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];t.printLog({logType:n,logs:i,url:o})},configurable:!0,enumerable:!0,writable:!0})}))}onReset(){this.proxyTypes.forEach((e=>{const t=this.console[e];t&&(console[e]=t)})),F.hasInitd=!1}printLog(e){if(e.logs&&e.logs.length){this.console[e.logType](...e.logs),e.logs=e.logs.map((e=>C.transformToAtom(e)));const t=k("console",{time:Date.now(),...e});x.dispatchEvent("public-data",t),x.broadcastMessage(t)}}}i(F,"hasInitd",!1);class H{constructor(){i(this,"name","ErrorPlugin")}onInit(){H.hasInitd||(H.hasInitd=!0,this.onUncaughtError(),this.onUnhandledRejectionError())}onReset(){const e=n();e.canIUse("offError")&&e.offError(this.errorHandler),e.canIUse("offUnhandledRejection")&&e.offUnhandledRejection(this.unhandledRejectionHandler),H.hasInitd=!1}errorHandler(e){if(H.hasInitd)if(e.stack||e.message){const{message:t,stack:n}=e;H.sendMessage(n||t,(e=>{if("object"!=typeof e)return null;const{name:t,message:n,stack:s}=Object(e);return!1===[t,n,s].every(Boolean)?null:{name:t,message:n,stack:s}})(e))}else{const e="[PageSpy] An unknown error occurred and no message or stack trace available";H.sendMessage(e,null)}}unhandledRejectionHandler(e){H.hasInitd&&H.sendMessage("UnHandled Rejection",{name:"unhandledrejection",message:e.reason})}onUncaughtError(){const e=n();e.canIUse("onError")&&e.onError(this.errorHandler)}onUnhandledRejectionError(){const e=n();e.canIUse("onUnhandledRejection")&&e.onUnhandledRejection(this.unhandledRejectionHandler)}static sendMessage(e,t){const n=k("console",{logType:"error",logs:[C.transformToAtom(e)],time:Date.now(),url:"wx:light-app",errorDetail:t});x.dispatchEvent("public-data",n),x.broadcastMessage(n)}}i(H,"hasInitd",!1),function(e){e[e.UNSENT=0]="UNSENT",e[e.OPENED=1]="OPENED",e[e.HEADERS_RECEIVED=2]="HEADERS_RECEIVED",e[e.LOADING=3]="LOADING",e[e.DONE=4]="DONE"}(U||(U={}));class W{constructor(e){i(this,"id",""),i(this,"name",""),i(this,"method",""),i(this,"url",""),i(this,"requestType","xhr"),i(this,"requestHeader",null),i(this,"status",0),i(this,"statusText",""),i(this,"readyState",0),i(this,"responseReason",null),i(this,"responseType",""),i(this,"responseHeader",null),i(this,"startTime",0),i(this,"endTime",0),i(this,"costTime",0),i(this,"getData",null),i(this,"postData",null),i(this,"requestPayload",null),i(this,"withCredentials",!1),this.id=e}}class G{constructor(e){i(this,"reqMap",Object.create(null)),this.socketStore=e}getRequestMap(){return this.reqMap}getRequest(e){return this.reqMap[e]}removeRequest(e){delete this.reqMap[e]}createRequest(e){return e?this.reqMap[e]?(v.warn("The request object has been in store, disallow duplicate create"),!1):(this.reqMap[e]=new W(e),!0):(v.warn('The "id" is required when init request object'),!1)}setRequest(e,t){return!(!e||!t)&&(this.reqMap[e]=t,!0)}sendRequestItem(e,t){try{this.reqMap[e]||(this.reqMap[e]=t);const n=k("network",{...t},!1);Number(t.readyState)===U.DONE&&this.socketStore.dispatchEvent("public-data",n),this.socketStore.broadcastMessage(n,t.readyState!==U.DONE),this.deferDeleteRequest(e)}catch(e){v.error(e.message)}}deferDeleteRequest(e){const t=this.getRequest(e);t&&t.readyState===U.DONE&&setTimeout((()=>{delete this.reqMap[e]}),3e3)}}class _ extends G{constructor(){super(x)}}class V extends _{constructor(){super(),i(this,"request",null),this.initProxyHandler()}reset(){if(this.request){const e=n();Object.defineProperty(e,"request",{value:this.request})}}initProxyHandler(){const e=this,t=n(),s=t.request;s&&(this.request=s,Object.defineProperty(t,"request",{value(t){const n=a();e.createRequest(n);const o=e.getRequest(n);if(o){const r=t.method||"GET",{url:i}=t;o.requestHeader=[],o.url=i,o.method=r.toUpperCase(),o.requestType="mp-request",o.status=0,o.statusText="Pending",o.startTime=Date.now(),o.readyState=U.UNSENT,d(t.header)&&(o.requestHeader=Object.entries(t.header).map((e=>{let[t,n]=e;return[String(t),String(n)]}))),o.requestHeader.push(["Content-Type","application/json"]);const{data:a}=t;if(a)if("string"==typeof a)o.requestPayload=a;else if(a instanceof ArrayBuffer)o.requestPayload="[object ArrayBuffer]";else try{o.requestPayload=JSON.stringify(a)}catch(e){o.requestPayload=c(a)}e.sendRequestItem(n,o);const l=t.success,u=t.fail,h=t.complete,g=()=>{o.endTime=Date.now(),o.costTime=o.endTime-(o.startTime||o.endTime)};t.success=function(t){g(),o.status=(null==t?void 0:t.statusCode)||200,o.statusText="Done",o.responseHeader=[...Object.entries((null==t?void 0:t.header)||{})],o.readyState=U.HEADERS_RECEIVED,e.sendRequestItem(n,o);const s=function(e){const t=Object.keys(e),n={};for(let s=0;s<t.length;s++){const o=t[s];n[o.toLowerCase()]=e[o]}return n}((null==t?void 0:t.header)||{})["content-type"];switch(s&&(s.includes("application/json")&&(o.responseType="json"),(s.includes("text/html")||s.includes("text/plain"))&&(o.responseType="text")),o.responseType||(o.responseType="arraybuffer"),o.responseType){case"json":case"text":if("string"==typeof(null==t?void 0:t.data))try{o.response=JSON.parse(t.data)}catch(e){o.response=t.data,o.responseType="text"}else o.response=null==t?void 0:t.data;break;case"arraybuffer":o.response="[object ArrayBuffer]"}null==l||l(t)},t.fail=function(e){g(),null==u||u(e)},t.complete=function(t){o.readyState=U.DONE,e.sendRequestItem(n,o),null==h||h(t)};return s(t)}return v.warn("The request object is not found on request event"),null}}))}}class B{constructor(){i(this,"name","NetworkPlugin"),i(this,"requestProxy",null)}onInit(){B.hasInitd||(B.hasInitd=!0,this.requestProxy=new V)}onReset(){var e;null===(e=this.requestProxy)||void 0===e||e.reset(),B.hasInitd=!1}}i(B,"hasInitd",!1);class J{constructor(){i(this,"name","SystemPlugin")}onInit(){J.hasInitd||(J.hasInitd=!0,x.addListener("refresh",((e,t)=>{let{source:n}=e;const{data:s}=n;if("system"===s){const e=J.getSystemInfo();x.dispatchEvent("public-data",e),t(e)}})))}onReset(){J.hasInitd=!1}static getSystemInfo(){const e=j.info;return k("system",{system:{ua:P(e)},features:{}})}}function z(e){const t=typeof e;let n=e;return"string"===t||"boolean"===t||"number"===t?n=String(e):"object"===t&&(n=e instanceof Date?e.toDateString():JSON.stringify(e)),n}i(J,"hasInitd",!1);class K{constructor(){i(this,"name","StoragePlugin")}onInit(){K.hasInitd||(K.hasInitd=!0,K.initStorageProxy(),K.listenRefreshEvent())}onReset(){const e=n();Object.entries(K.originFunctions).forEach((t=>{let[n,s]=t;Object.defineProperty(e,n,{value:s})})),K.hasInitd=!1}static sendRefresh(){const e=n();try{const t=e.getStorageInfoSync(),n={type:"mpStorage",action:"get",data:t.keys.map((e=>({name:e,value:z(s.getStorage(e))})))};K.sendStorageItem(n)}catch(e){}}static listenRefreshEvent(){x.addListener("refresh",(async e=>{let{source:t}=e;const{data:n}=t;"mpStorage"===n&&K.sendRefresh()}))}static initStorageProxy(){const e=n(),{sendClearItem:t,sendRemoveItem:s,sendSetItem:o}=K;["setStorage","setStorageSync","removeStorage","removeStorageSync","clearStorage","clearStorageSync","batchSetStorageSync","batchSetStorage"].forEach((t=>{e[t]&&(K.originFunctions[t]=e[t])})),Object.defineProperties(e,{setStorage:{value:e=>K.originFunctions.setStorage({...e,success(t){var n;o(e.key,e.data),null===(n=e.success)||void 0===n||n.call(e,t)}})},setStorageSync:{value(e,t){try{let n;if("mp-alipay"!==j.info.browserType||j.info.framework&&"unknown"!==j.info.framework){const s=e;n=K.originFunctions.setStorageSync(s,t),o(s,t)}else{const t=e;n=K.originFunctions.setStorageSync(t),o(t.key,t.data)}return n}catch(t){throw v.error("Failed to set storage synchronously: ".concat(e)),t}}},removeStorage:{value:e=>K.originFunctions.removeStorage({...e,success(t){var n;s(e.key),null===(n=e.success)||void 0===n||n.call(e,t)}})},removeStorageSync:{value(e){try{const t=K.originFunctions.removeStorageSync(e);return s(t),t}catch(t){throw v.error("Failed to remove storage synchronously: ".concat(e)),t}}},clearStorage:{value:e=>K.originFunctions.clearStorage({...e,success(n){var s;t(),null===(s=e.success)||void 0===s||s.call(e,n)}})},clearStorageSync:{value(){try{const e=K.originFunctions.clearStorageSync();return t(),e}catch(e){throw v.error("Failed to clear storage synchronously"),e}}}}),e.canIUse("batchSetStorageSync")&&Object.defineProperty(e,"batchSetStorageSync",{value(e){try{const t=K.originFunctions.batchSetStorageSync(e);return e.forEach((e=>{o(e.key,e.value)})),t}catch(t){throw v.error("Failed to batch set storage synchronously: ".concat(JSON.stringify(e.map((e=>e.key))))),t}}}),e.canIUse("batchSetStorage")&&Object.defineProperty(e,"batchSetStorage",{value:e=>K.originFunctions.batchSetStorage({...e,success(t){var n;e.kvList.forEach((e=>{o(e.key,e.value)})),null===(n=e.success)||void 0===n||n.call(e,t)}})})}static sendSetItem(e,t){K.sendStorageItem({type:"mpStorage",action:"set",name:e,value:z(t)})}static sendRemoveItem(e){K.sendStorageItem({type:"mpStorage",action:"remove",name:e})}static sendClearItem(){K.sendStorageItem({type:"mpStorage",action:"clear"})}static sendStorageItem(e){const t=k("storage",e);x.dispatchEvent("public-data",t),x.broadcastMessage(t,!0)}}i(K,"hasInitd",!1),i(K,"originFunctions",{});const Q=e=>!1===e?["http://","ws://"]:["https://","wss://"];class X{constructor(e){if(this.config=e,!e.get().api)throw Error("The api base url cannot be empty")}get base(){return this.config.get().api}createRoom(){const{enableSSL:t,project:s,title:o,useSecret:r,secret:i}=this.config.get(),a=Q(t),c=P(j.info),l=e({group:s,title:o,name:encodeURIComponent(c)});return(u=n().request,e=>new Promise(((t,n)=>{u({...e,success(e){t(e)},fail(e){n(e)}})})))({url:"".concat(a[0]).concat(this.base,"/api/v1/room/create?").concat(l),method:"POST",data:JSON.stringify({useSecret:r,secret:i})}).then((e=>{var t;const{name:n,address:s}=(null===(t=e.data)||void 0===t?void 0:t.data)||{};return{roomUrl:this.getRoomUrl(s),address:s,name:n}}),(e=>{throw Error("Request create room failed: ".concat(e.message))}));var u}getRoomUrl(t){const n=this.config.get(),s=Q(n.enableSSL);return"".concat(s[1]).concat(this.base,"/api/v1/ws/room/join?").concat(e({address:t,name:"client:".concat(a()),userId:"Client",forceCreate:!0,useSecret:n.useSecret,secret:n.secret}))}}class Y{defaultConfig(){return{}}constructor(){i(this,"mergeConfig",(e=>{const t=Object.entries(e).reduce(((e,t)=>{let[n,s]=t;return this.privateKeys.includes(n)||(e[n]=s),e}),{});return this.value={...this.defaultConfig(),...t},this.value})),this.value=this.defaultConfig()}get(){return this.value}set(e,t){this.value[e]=t}}class Z extends Y{constructor(){super(...arguments),i(this,"privateKeys",["secret"])}defaultConfig(){return{api:"",project:"default",title:"",enableSSL:null,disabledOnProd:!0,disabledPlugins:[],singletonSocket:!1,messageCapacity:1e3,useSecret:!1,secret:""}}}class ${constructor(e){if(i(this,"root",null),i(this,"version","1.9.0"),i(this,"request",null),i(this,"name",""),i(this,"address",""),i(this,"roomUrl",""),i(this,"socketStore",x),i(this,"config",new Z),i(this,"cacheTimer",null),$.instance)return v.warn("Cannot initialize PageSpy multiple times"),$.instance;const t=this.config.mergeConfig(e);t.singletonSocket&&(M.isSingleSocket=!0);const s=n();if(s.canIUse("getAccountInfoSync")&&s.getAccountInfoSync){if("release"===s.getAccountInfoSync().miniProgram.envVersion&&!1!==t.disabledOnProd)return void v.warn("PageSpy is not allowed on release env of mini program")}$.instance=this;const o="!!!WARNING!!!: When submitting the mini program for review, be sure to delete the SDK in the code, otherwise the review will fail.";v.log(o),v.info(o),v.warn(o),this.request=new X(this.config),this.updateConfiguration(),this.triggerPlugins("onInit",{socketStore:x,config:t,atom:C}),j.plugins=$.pluginsWithOrder.map((e=>e.name)),this.init()}updateConfiguration(){const{messageCapacity:e,useSecret:t}=this.config.get();if(!0===t){const e=s.getStorage(L),t=(null==e?void 0:e.secret)||function(){const e=Math.floor(1e6*Math.random());return String(e).padStart(6,"0")}();this.config.set("secret",t),v.log("Room Secret: ".concat(t))}x.connectable=!0,x.getPageSpyConfig=()=>this.config.get(),x.messageCapacity=e}async init(){const e=n(),t=this.config.get(),o=s.getStorage(L);if(o&&"object"==typeof o){const{name:e,address:n,roomUrl:s,project:r}=o;t.project!==r?await this.createNewConnection():(this.name=e,this.address=n,this.roomUrl=s,this.useOldConnection())}else await this.createNewConnection();e.canIUse("onAppShow")&&e.onAppShow((()=>{const e=x.getSocket().getState();e!==R.CLOSED&&e!==R.CLOSING||this.useOldConnection()})),v.log("Plugins inited")}async createNewConnection(){if(!this.request)return void v.error("Cannot get the Request");const e=await this.request.createRoom();this.name=e.name,this.address=e.address,this.roomUrl=e.roomUrl,this.refreshRoomInfo(),x.init(e.roomUrl)}useOldConnection(){this.refreshRoomInfo(),x.init(this.roomUrl)}refreshRoomInfo(){this.saveSession(),this.cacheTimer=setInterval((()=>{x.getSocket().getState()===R.OPEN&&this.saveSession()}),15e3),v.log("Room ID: ".concat(this.address.slice(0,4)))}saveSession(){const{name:e,address:t,roomUrl:n,config:o}=this,{useSecret:r,secret:i,project:a}=o.get(),c={name:e,address:t,roomUrl:n,project:a,useSecret:r,secret:i};s.setStorage(L,c)}triggerPlugins(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),s=1;s<t;s++)n[s-1]=arguments[s];const{disabledPlugins:o}=this.config.get();$.pluginsWithOrder.forEach((t=>{var s;h(o)&&o.length&&o.includes(t.name)||null===(s=t[e])||void 0===s||s.apply(t,n)}))}abort(){this.triggerPlugins("onReset"),x.close(),$.instance=null}updateRoomInfo(e){if(!e)return;const{project:t,title:n}=e;t&&this.config.set("project",String(t)),n&&this.config.set("title",String(n)),x.updateRoomInfo()}static get pluginsWithOrder(){return[...$.plugins.pre,...$.plugins.normal,...$.plugins.post]}static registerPlugin(e){if(!e)return;if("function"==typeof(t=e)&&void 0!==t.prototype)return void v.error("PageSpy.registerPlugin() expect to pass an instance, not a class");var t;if(!e.name)return void v.error("The ".concat(e.constructor.name,' plugin should provide a "name" property'));if($.pluginsWithOrder.some((t=>t.name===e.name)))return void v.error("The ".concat(e.name,' has registered. Consider the following reasons:\n - Duplicate register one same plugin;\n - Plugin\'s "name" conflict with others, you can print all registered plugins by "PageSpy.plugins";'));$.plugins[e.enforce||"normal"].push(e)}}i($,"instance",null),i($,"plugins",{pre:[],normal:[],post:[]});var ee;[new F,new H,new B,new K,new J].forEach((e=>{$.registerPlugin(e)})),ee=my,t=ee,s.getStorage=e=>{const t=my.getStorageSync({key:e});if(t.success)return t.data},s.setStorage=(e,t)=>my.setStorageSync({key:e,data:t}),s.removeStorage=e=>my.removeStorageSync({key:e});const te=my.getSystemInfoSync();j.info.sdk="mp-alipay",j.info.osType=te.platform.toLowerCase(),j.info.browserType="mp-alipay",j.info.osVersion=te.system,j.info.browserVersion=te.version,D.messageFilters.push((e=>e.data));export{$ as default};
//# sourceMappingURL=index.min.js.map
{
"name": "@huolala-tech/page-spy-alipay",
"version": "1.8.10",
"version": "1.9.0",
"description": "A developer tool for debugging alipay miniprogram",

@@ -34,3 +34,3 @@ "license": "MIT",

"@babel/runtime": "^7.13.0",
"@huolala-tech/page-spy-types": "^1.8.9"
"@huolala-tech/page-spy-types": "^1.9.0"
},

@@ -42,3 +42,2 @@ "devDependencies": {

"@babel/preset-typescript": "^7.13.0",
"@huolala-tech/eval5": "^0.0.1",
"@rollup/plugin-alias": "^4.0.3",

@@ -76,3 +75,3 @@ "@rollup/plugin-babel": "^6.0.3",

},
"gitHead": "ac4420682a89afe7e2a0145d28d67d7f73efd24c"
"gitHead": "2649c52819a354410fd3f0ee65e53fa1790a829c"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc