@mptool/skyline-enhance
Version:
Lifetime enhance for Wechat dist 3.0 miniapp
3 lines (2 loc) • 9.49 kB
JavaScript
;for(var g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",b=typeof Uint8Array=="undefined"?[]:new Uint8Array(256),y=0;y<g.length;y++)b[g.charCodeAt(y)]=y;var ee=function(e){var t=new Uint8Array(e),n,r=t.length,i="";for(n=0;n<r;n+=3)i+=g[t[n]>>2],i+=g[(t[n]&3)<<4|t[n+1]>>4],i+=g[(t[n+1]&15)<<2|t[n+2]>>6],i+=g[t[n+2]&63];return r%3===2?i=i.substring(0,i.length-1)+"=":r%3===1&&(i=i.substring(0,i.length-2)+"=="),i},te=function(e){var t=e.length*.75,n=e.length,r,i=0,o,s,c,a;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);var l=new ArrayBuffer(t),d=new Uint8Array(l);for(r=0;r<n;r+=4)o=b[e.charCodeAt(r)],s=b[e.charCodeAt(r+1)],c=b[e.charCodeAt(r+2)],a=b[e.charCodeAt(r+3)],d[i++]=o<<2|s>>4,d[i++]=(s&15)<<4|c>>2,d[i++]=(c&3)<<6|a&63;return l};const x=typeof qq=="object"?"qq":typeof wx=="object"?"miniapp"in wx?"donut":"wx":"js";var ne=(e,t,n)=>new Promise((r,i)=>{var o=a=>{try{c(n.next(a))}catch(l){i(l)}},s=a=>{try{c(n.throw(a))}catch(l){i(l)}},c=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,s);c((n=n.apply(e,t)).next())});function C(e=new Map){return{all:e,on:(t,n)=>{const r=e.get(t);r?r.push(n):e.set(t,[n])},off:(t,n)=>{const r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:(t,n)=>{let r=e.get(t);r&&r.slice().map(i=>i(n)),r=e.get("*"),r&&r.slice().map(i=>i(t,n))},emitAsync:(t,n)=>ne(this,null,function*(){var r,i;yield Promise.all(((r=e.get(t))!=null?r:[]).slice().map(o=>o(n))),yield Promise.all(((i=e.get("*"))!=null?i:[]).slice().map(o=>o(t,n)))})}}var re=Object.defineProperty,ie=(e,t,n)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oe=(e,t,n)=>ie(e,t+"",n);let ae=class extends Error{constructor({code:t,message:n}){super(n),oe(this,"code"),this.code=t!=null?t:null}toString(){return`code: ${this.code}, message: ${this.message}`}};var S;const u=x==="js"?console:((S=wx.getRealtimeLogManager)==null?void 0:S.call(wx))||wx.getLogManager({level:1}),k=x!=="js"&&"getRealtimeLogManager"in wx,se=(...e)=>{wx.env.DEBUG&&(k?u.info("debug",...e):u.debug(...e)),u!==console&&console.debug(...e)},ce=(...e)=>{u.info(...e),u!==console&&console.info(...e)},le=(...e)=>{u.warn(...e),u!==console&&console.warn(...e)},ue=(...e)=>{k?u.error(...e):u.warn("error",...e),u!==console&&console.error(...e)},fe=e=>{k&&u.setFilterMsg(e)};var h=Object.freeze({__proto__:null,debug:se,error:ue,filter:fe,info:ce,warn:le});const he=(e="",t="&")=>{const n={},r=e?e.split(t):void 0;return r&&r.length>0&&r.forEach(i=>{const[o,s]=i.split("=");n[o]=s}),n},M=(e={},t="&",n=!1)=>Object.keys(e).map(r=>{const i=e[r];return`${r}=${n?i:encodeURIComponent(i)}`}).join(t),pe=(e,t,n=!1)=>{const r=M(t,"&",n);return r?`${e}${/[?&]$/u.test(e)?"":e.includes("?")?"&":"?"}${r}`:e};var de=Object.freeze({__proto__:null,join:pe,parse:he,stringify:M});const U=e=>{if(e===void 0)return"undefined";const t=typeof e;if(t==="object"){if(e===null)return"null";const n=/\[object (\w+)\]/u.exec(Object.prototype.toString.call(e));return n?n[1].toLowerCase():""}return t},B=e=>U(e)==="function";var ge=Object.defineProperty,$e=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Q=(e,t,n)=>$e(e,typeof t!="symbol"?t+"":t,n);function p(e,t){return function(...n){if(t.apply(this,n),e)return e.apply(this,n)}}const be=(e,t)=>{let n;return function(...r){if(!n)return n=!0,e.apply(t!=null?t:this,[()=>{n=!1},...r])}},me=(e,t)=>{let n;return function(...r){if(!n)return n=!0,e.apply(t!=null?t:null,r)}};class q{constructor(t=1){this.capacity=t,Q(this,"funcQueue",[]),Q(this,"running",0)}next(){const t=this.funcQueue.shift();if(t){const{func:n,ctx:r,args:i}=t,o=()=>{n.apply(r,[()=>{this.running-=1,this.next()},...[].slice.call(i,0)])};this.running+=1,o()}}add(t,n,...r){this.funcQueue.push({func:t,ctx:n,args:[].slice.call(r,0)}),this.running<this.capacity&&this.next()}clear(){this.funcQueue=[]}}const ye=(e,t=1)=>{const n=new q(t);return function(...r){n.add(e,this,...r)}},E="a",ve="al",v=C(),f=C(),$={launch:!1,lOpt:{},hide:0},we=e=>{$.launch=!0,$.lOpt=e,v.emit(ve,e)},Pe=()=>{$.hide&&(v.emit(E,new Date().getTime()-$.hide),$.hide=0)},Ae=()=>{$.hide=new Date().getTime()},Oe=e=>{e.onLaunch=p(e.onLaunch,we),e.onShow=p(e.onShow,Pe),e.onHide=p(e.onHide,Ae),e.onAwake&&(v.on(E,t=>{h.debug(`App: awake after ${t}ms`),e.onAwake(t)}),h.debug("App: registered onAwake")),e.$on=f.on,e.$off=f.off,e.$emit=f.emit,e.$emitAsync=f.emitAsync,App(e)},R={},F=e=>R[e],je=(e,t)=>{R[e]=t},xe=e=>{delete R[e]};var Ce=Object.defineProperty,ke=Object.defineProperties,Ee=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,z=(e,t,n)=>t in e?Ce(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))H.call(t,n)&&z(e,n,t[n]);if(w)for(var n of w(t))N.call(t,n)&&z(e,n,t[n]);return e},W=(e,t)=>ke(e,Ee(t)),Re=(e,t)=>{var n={};for(var r in e)H.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&w)for(var r of w(e))t.indexOf(r)<0&&N.call(e,r)&&(n[r]=e[r]);return n};let P;const Le=e=>{const t=e,{defaultPage:n,getPath:r,pages:i=[]}=t,o=Re(t,["defaultPage","getPath","pages"]);if(B(r)){P=W(G({},o),{getPath:r});return}let s={};const c=(a,l)=>{const d=l.replace(/\$name/g,a);s[a]=d};Array.isArray(i)?i.forEach(([a,l])=>{typeof a=="string"?c(a,l):a.forEach(d=>c(d,l))}):typeof i=="object"&&(s=i),P=W(G({},o),{getPath:a=>s[a]||n.replace(/\$name/g,a)})},m=()=>{if(!P)throw new Error("$Config is not called");return P},De=e=>{const t=m(),[n,r]=e.split("?");return`${n.startsWith("/")?n:t.getPath(n)}${r?`?${r}`:""}`};function A(e){return t=>wx[e]({url:De(t)})}const L=A("navigateTo"),D=A("redirectTo"),I=A("switchTab"),O=A("reLaunch");function j(e){return function(t){if(t){const{before:n,after:r,url:i}=t.currentTarget.dataset;if(this&&n&&typeof this[n]=="function"&&this[n](t),i)return e(i).then(()=>{this&&r&&typeof this[r]=="function"&&this[r](t)})}}}const Ie=j(L),_e=j(D),Te=j(I),Se=j(O),J=(e=1)=>{const{home:t}=m();return getCurrentPages().length<=e&&t?O(t):wx.navigateBack({delta:e})},Me=function(e){if(e){const{before:t,after:n,delta:r=1}=e.currentTarget.dataset;return this&&t&&typeof this[t]=="function"&&this[t](e),Promise.resolve(J(Number(r))).then(()=>{this&&n&&typeof this[n]=="function"&&this[n](e)})}},Ue=()=>getCurrentPages().slice(0).pop();function K(e){const{args:t,event:n,id:r}=e.detail;switch(n){case"$attached":{const i=F(r);if(!i)break;const o=i.$refID;o&&(this.$refs[o]=i),i.$attached(this);break}default:{const i=this[n];i&&i.apply(this,t)}}}function V(e){const t=m();e.$=K,e.$refs={},e.$on=f.on,e.$off=f.off,e.$emit=f.emit,e.$emitAsync=f.emitAsync,e.$go=L,e.$redirect=D,e.$switch=I,e.$reLaunch=O,e.$back=J,e.$currentPage=Ue,e.$getPath=t.getPath,e.$bindGo=Ie,e.$bindRedirect=_e,e.$bindSwitch=Te,e.$bindRelaunch=Se,e.$bindBack=Me}var Be=Object.defineProperty,Qe=Object.defineProperties,qe=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,Y=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_=(e,t)=>{for(var n in t||(t={}))Fe.call(t,n)&&Y(e,n,t[n]);if(X)for(var n of X(t))He.call(t,n)&&Y(e,n,t[n]);return e},T=(e,t)=>Qe(e,qe(t));let Ne=0;const ze=(e={})=>{const t={};return Object.keys(e).forEach(n=>{const r=e[n];if(r===null||typeof r=="function")t[n]=r;else{const{type:i}=r;i===null?t[n]={type:null,value:r.default}:Array.isArray(i)?t[n]={type:i[0],value:r.default,optionalTypes:i.slice(1)}:t[n]={type:i,value:r.default}}}),T(_({},t),{ref:{type:String,value:""}})},Ge=e=>{const{extendComponent:t,injectComponent:n}=m();return t&&t(e),e.lifetimes||(e.lifetimes={}),e.lifetimes.created=p(e.lifetimes.created,function(){V(this),n&&n(e)}),e.lifetimes.attached=p(e.lifetimes.attached,function(){const r=Ne+=1;this.$id=r,je(r,this),this.$refID=this.data.ref,this.triggerEvent("ing",{id:this.$id,event:"$attached"})}),e.lifetimes.detached=p(e.lifetimes.detached,function(){var r;xe(this.$id);const i=(r=this.$parent)==null?void 0:r.$refs,o=this.$refID;o&&i&&delete i[o],delete this.$parent}),e.methods=T(_({},e.methods),{$call(r,...i){h.debug(`Component ${this.$id} call ${r}:`,i),this.triggerEvent("ing",{id:this.$id,event:r,args:i})},$getRef:F,$attached(r){this.$root=r.$root||r,this.$parent=r},$:K}),e.observers=T(_({},e.observers),{ref(r){var i;this.$refID&&this.$refID!==r&&((i=this.$parent)!=null&&i.$refs&&delete this.$parent.$refs[this.$refID],this.$refID=r,h.debug(`Component ${this.$id} ref: ${r}`))}}),e.properties=ze(e.props),delete e.props,Component(e)};let Z=!0;const We=(e,t)=>{const{extendPage:n,injectPage:r}=m(),i=(s,c)=>h.debug(`Page ${e}: ${s} has been invoked`,""),o=s=>h.debug(`Page ${e}: registered ${s}`);n&&n(e,t),t.$name=e,t.$state={firstOpen:!1},t.onLoad=p(t.onLoad,()=>{t.onAwake&&(v.on(E,s=>{i("onAwake"),t.onAwake(s)}),o("onAwake")),Z&&(Z=!1,t.$state.firstOpen=!0)}),V(t),r&&r(e,t),t.onRegister&&(i("onRegister"),t.onRegister()),Page(t),h.debug(`Registered: Page ${e}`)};exports.$App=Oe,exports.$Component=Ge,exports.$Config=Le,exports.$Page=We,exports.Emitter=C,exports.MpError=ae,exports.Queue=q,exports.decodeBase64=te,exports.emitter=f,exports.encodeBase64=ee,exports.env=x,exports.funcQueue=ye,exports.go=L,exports.isFunction=B,exports.lock=be,exports.logger=h,exports.once=me,exports.query=de,exports.reLaunch=O,exports.redirect=D,exports.switchTab=I,exports.type=U,exports.wrapFunction=p;
//# sourceMappingURL=index.js.map