UNPKG

@mptool/skyline-enhance

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