"use strict";const shared=require("@min-kit/shared"),taro=require("@tarojs/taro");function hasNavBar(){return(taro.Current.page?.config?.navigationStyle??taro.Current.app.config?.window?.navigationStyle)!=="custom"}function hasTabBar(S){if(S===void 0&&(S=taro.Current.router?.path),!S)return!1;const m=taro.Current.app.config?.tabBar;return m?m.list.findIndex(b=>shared.Route.equals(b.pagePath,S))>-1:!1}var l=Object.defineProperty,u=(S,m,b)=>m in S?l(S,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):S[m]=b,g=(S,m,b)=>(u(S,typeof m!="symbol"?m+"":m,b),b);const k=shared.attempt(taro.getSystemInfoSync)?.platform==="devtools";class Logger{constructor(m,b={}){g(this,"name"),g(this,"option",{reporter:{realtime:!0,feedback:!1},timestamp:!0,meta:!0}),g(this,"feedbackReporter"),g(this,"realtimeReporter"),this.name=m,this.setOption(b)}setOption(m){const b={...this.option.reporter,...m.reporter};Object.assign(this.option,m),k&&(b.realtime=!1,b.feedback=!1,this.option.timestamp=!1),taro.canIUse("getRealtimeLogManager")&&b.realtime?shared.attempt(()=>{this.realtimeReporter||(this.realtimeReporter=taro.getRealtimeLogManager()),this.realtimeReporter.setFilterMsg(this.name)}):b.realtime=!1,taro.canIUse("getLogManager")&&b.feedback?shared.attempt(()=>{this.feedbackReporter||(this.feedbackReporter=taro.getLogManager())}):b.feedback=!1,this.option.reporter=b,this.debug("#Logger",this.option)}report(m,b,y){const C=this.option.reporter??{},O=()=>({name:this.name,filters:y,route:taro.Current.router?shared.Route.generate(taro.Current.router.path,taro.Current.router.params):void 0,timestamp:Date.now()});return{report:()=>{m!=="debug"&&(C.realtime&&this.realtimeReporter&&shared.attempt(()=>{taro.Current.page&&this.realtimeReporter.in(taro.Current.page),y.forEach(q=>this.realtimeReporter.addFilterMsg(q));const v=this.option.meta?[O(),...b]:b;this.realtimeReporter[m](...v)}),C.feedback&&this.feedbackReporter&&shared.attempt(()=>{const v=this.option.meta?[O(),...b]:b;switch(m){case"error":this.feedbackReporter.warn({level:m,filters:y},...v);break;case"warn":this.feedbackReporter.warn({level:m,filters:y},...v);break;case"info":this.feedbackReporter.info({level:m,filters:y},...v);break}}),shared.isFunction(C.custom)&&shared.attempt(()=>{C.custom({level:m,messages:b,meta:O()})}))}}}output(m,b){const y=console[m]??console.log;if(this.option.timestamp){const C=new Date,O=C.getHours().toString().padStart(2,"0"),v=C.getMinutes().toString().padStart(2,"0"),q=C.getSeconds().toString().padStart(2,"0"),I=C.getMilliseconds().toString().padStart(3,"0");b.unshift(`${O}:${v}:${q}.${I}`)}y.apply(null,b)}logging(m,b){const y=[],C=[];let O=-1;return b.forEach((v,q)=>{shared.isString(v)&&v.startsWith("#")&&O+1===q?(O=q,y.push(v.slice(1))):C.push(v)}),this.output(m,[this.name].concat(y.map(v=>`[${v}]`),C)),this.report(m,C,y)}error(...m){this.logging("error",m).report()}warn(...m){return this.logging("warn",m)}info(...m){return this.logging("info",m)}debug(...m){this.logging("debug",m)}}function getLogger(S,m){return new Logger(S,m)}const logger=getLogger("\u{1F47D}");async function copy(S){if(shared.isEmpty(S))return!1;try{const m=shared.isString(S)?S:JSON.stringify(S);return await taro.setClipboardData({data:m}),!0}catch(m){return logger.error("#copy",m),!1}}let e=null;const r=S=>{logger.warn("#toast",S)},i$1={timers:[],start:S=>new Promise(m=>{i$1.timers.push(setTimeout(m,S))}),clear:()=>{i$1.timers.splice(0).forEach(S=>clearTimeout(S))}},toast=(S,m)=>toast.clear().then(()=>taro.showToast({title:S,icon:"none",duration:1500,...m})).then(()=>{e="toast"}).then(()=>i$1.start(m?.duration||1500)).then(()=>{i$1.clear(),e=null}).catch(r);toast.success=(S="\u64CD\u4F5C\u6210\u529F",m)=>toast(S,{...m,icon:"success"}),toast.error=(S="\u64CD\u4F5C\u5931\u8D25",m)=>toast(S,{...m,icon:"error"}),toast.loading=(S="\u52A0\u8F7D\u4E2D...",m=!0)=>toast.clear().then(()=>taro.showLoading({title:S,mask:m})).then(()=>{e="loading"}).catch(r),toast.clear=()=>{if(!e)return Promise.resolve();const S=e==="toast";return Promise.race([S?taro.hideToast():taro.hideLoading(),i$1.start(200)]).then(()=>{i$1.clear(),e=null}).catch(r)};var n$4=Object.defineProperty,s$1=(S,m,b)=>m in S?n$4(S,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):S[m]=b,t=(S,m,b)=>(s$1(S,typeof m!="symbol"?m+"":m,b),b);class w{constructor(m){this.adUnitId=m,t(this,"ad"),t(this,"eventName"),t(this,"error"),t(this,"done",!1),this.eventName="RewardedVideoAdOnClose#"+m,this.ad=taro.createRewardedVideoAd({adUnitId:m}),this.ad.onError(b=>{this.error=b,logger.error("#ad","#RewardedVideoAd","onError",this.adUnitId,b)}),this.ad.onLoad(()=>{this.error=null,logger.debug("#ad","#RewardedVideoAd","onLoad",this.adUnitId)}),this.ad.onClose(b=>{this.done=!!b?.isEnded,taro.eventCenter.trigger(this.eventName,this.done),logger.debug("#ad","#RewardedVideoAd","onClose",this.adUnitId,b)})}showAd(){return this.ad.show().catch(()=>this.ad.load().then(()=>this.ad.show()))}show(){return new Promise(m=>{taro.eventCenter.off(this.eventName).once(this.eventName,m),toast.loading().then(()=>this.showAd()).catch(()=>m(!0)).then(toast.clear)})}showOnce(){return this.done?Promise.resolve(!0):this.show()}}function createRewardedVideoAd(S){return new w(S)}const o=document;function n$3(){const S=taro.Current.page?.$taroPath;return S?o.getElementById(S):null}const go=(S,m,b={})=>{const y=shared.Route.generate(S,m,b.generate);return b.reLaunch?taro.reLaunch({url:y}):hasTabBar(S)?taro.switchTab({url:shared.Route.extract(S)}):b.redirect?taro.redirectTo({url:y}):taro.navigateTo({url:y})};go.redirect=(S,m,b)=>go(S,m,{redirect:!0,generate:b}),go.reLaunch=(S,m,b)=>go(S,m,{reLaunch:!0,generate:b}),go.back=S=>taro.navigateBack().catch(m=>{if(m.errMsg?.includes("at first")&&S)return logger.warn("#go.back","fallback to "+S,"when",m.errMsg),go.redirect(S);throw m}),go.miniProgram=S=>(logger.debug("#go.miniProgram",S),taro.navigateToMiniProgram(S));var i=Object.defineProperty,n$2=(S,m,b)=>m in S?i(S,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):S[m]=b,s=(S,m,b)=>(n$2(S,typeof m!="symbol"?m+"":m,b),b);class AbortControllerImpl{constructor(){s(this,"aborted",!1),s(this,"reason"),s(this,"listeners",[])}get signal(){return{aborted:this.aborted,reason:this.reason}}abort(m){this.aborted||(this.aborted=!0,this.reason=m,this.emit())}emit(){this.listeners.splice(0).forEach(m=>{m()})}on(m){this.listeners.push(m)}}function compose(S){return(m,b)=>{let y=-1;return C(0).catch(O=>m.throw(O));async function C(O){if(O<=y)throw new Error("next() called multiple times");y=O;const v=O===S.length?b:S[O];if(v)return await v(m,()=>C(O+1))}}}var a$1=Object.defineProperty,c=(S,m,b)=>m in S?a$1(S,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):S[m]=b,n$1=(S,m,b)=>(c(S,typeof m!="symbol"?m+"":m,b),b);class RequestError extends Error{constructor(m,b){const y=m;super(y.message??y),n$1(this,"name","RequestError"),n$1(this,"ctx"),y.stack&&(this.stack=y.stack),this.ctx=b}static is(m){return m instanceof RequestError}}function joinUrl(S,m){return!m||S.indexOf("://")>-1?S:m.replace(/\/+$/,"")+"/"+S.replace(/^\/+/,"")}function cloneObj(S){return JSON.parse(JSON.stringify(S))}function omit(S,m){return Object.keys(S).reduce((b,y)=>(m.includes(y)||(b[y]=S[y]),b),{})}var d=Object.defineProperty,p=(S,m,b)=>m in S?d(S,m,{enumerable:!0,configurable:!0,writable:!0,value:b}):S[m]=b,n=(S,m,b)=>(p(S,typeof m!="symbol"?m+"":m,b),b);class Request{constructor(m={}){n(this,"config"),n(this,"middlewares",[]),this.config=m}use(m){return this.middlewares.push(m),this}createRequest(m){const b=Object.assign({header:{},method:"GET"},this.config,m);return b.url=joinUrl(b.url,b.baseUrl),b}createContext(m){const b=this;return{request:this.createRequest(m),ok:!1,statusCode:-1,data:void 0,header:{},errMsg:"Before Request",set(y,C){return this.statusCode!==-1&&this.throw("Cannot set request headers after next()."),C==null?delete this.request.header[y]:this.request.header[y]=C,this},abort(){this.statusCode!==-1&&this.throw("Cannot abort request after next()."),this.request.abort||(this.request.abort=new AbortControllerImpl),this.request.abort.abort()},throw(y){const C=y instanceof RequestError?y:new RequestError(y,this),O=this.request,v={statusCode:this.statusCode,header:this.header,data:this.data};throw console.error(C,{request:O,response:v}),C},async replay(){this.statusCode===-1&&this.throw("Cannot replay request before next()."),this.request.replayed=(this.request.replayed??0)+1;const y=await b.request(cloneObj(this.request));Object.assign(this,y)}}}async invoke(m){m.request.abort?.signal.aborted&&m.throw("request aborted");const b=taro.request(omit(m.request,["abort","baseUrl","replayed"]));m.request.abort?.on(()=>b.abort());const y=await b;Object.assign(m,y,{ok:!!y.statusCode&&y.statusCode>=200&&y.statusCode<300})}async request(m){const b=this.createContext(m);return await compose(this.middlewares)(b,this.invoke.bind(this)),b.ok||b.throw(`${b.request.method} ${b.request.url} ${b.statusCode} (${b.errMsg})`),b}get(m,b,y){return this.request({...y,url:m,data:b,method:"GET"})}delete(m,b,y){return this.request({...y,url:m,data:b,method:"DELETE"})}head(m,b,y){return this.request({...y,url:m,data:b,method:"HEAD"})}options(m,b,y){return this.request({...y,url:m,data:b,method:"OPTIONS"})}post(m,b,y){return this.request({...y,url:m,data:b,method:"POST"})}put(m,b,y){return this.request({...y,url:m,data:b,method:"PUT"})}patch(m,b,y){return this.request({...y,url:m,data:b,method:"PATCH"})}}function createRequest(S){return new Request(S)}var E=(S=>(S[S.SINGLE_CHAT=1007]="SINGLE_CHAT",S[S.GROUP_CHAT=1008]="GROUP_CHAT",S[S.QRCODE_SCAN=1011]="QRCODE_SCAN",S[S.QRCODE_LONG_PRESS=1012]="QRCODE_LONG_PRESS",S[S.QRCODE_SCAN_FROM_ALBUM=1013]="QRCODE_SCAN_FROM_ALBUM",S[S.SUBSCRIPTION=1014]="SUBSCRIPTION",S[S.SUBSCRIPTION2=1107]="SUBSCRIPTION2",S[S.TIMELINE_TO_SINGLE_PAGE=1154]="TIMELINE_TO_SINGLE_PAGE",S[S.FROM_SINGLE_PAGE_MODE=1155]="FROM_SINGLE_PAGE_MODE",S))(E||{});const scene={get current(){return shared.attempt(taro.getEnterOptionsSync)?.scene??0},get isSinglePageMode(){return scene.current===1154},get isFromSubscription(){return[1014,1107].includes(scene.current)},get isFromShare(){return[1007,1008,1155].includes(scene.current)},get isFromQrcode(){return[1012,1011,1013].includes(scene.current)}};async function hideShareMenu(){try{await taro.hideShareMenu(),logger.debug("#hideShareMenu")}catch(S){logger.error("#hideShareMenu",S)}}async function showShareMenu(S={showShareItems:["shareAppMessage","shareTimeline"]}){try{await taro.showShareMenu(S),logger.debug("#showShareMenu",S)}catch(m){logger.error("#showShareMenu",m)}}function getStorageSync(S){return shared.attempt(()=>taro.getStorageSync(S))}async function getStorage(S){return(await shared.attempt.async(()=>taro.getStorage({key:S})))?.data}function setStorageSync(S,m){shared.attempt(()=>taro.setStorageSync(S,m))}async function setStorage(S,m){await shared.attempt.async(()=>taro.setStorage({key:S,data:m}))}function removeStorageSync(S){shared.attempt(()=>taro.removeStorageSync(S))}async function removeStorage(S){await shared.attempt.async(()=>taro.removeStorage({key:S}))}var f=(S=>(S[S.OFF=20004]="OFF",S[S.REJECT_BY_SETTING=-1]="REJECT_BY_SETTING",S[S.REJECT_BY_USER=-2]="REJECT_BY_USER",S))(f||{}),T=(S=>(S.ACCEPT="accept",S.ACCEPT_WITH_AUDIO="acceptWithAudio",S.REJECT="reject",S.BAN="ban",S.FILTER="filter",S))(T||{});const R={confirm:()=>taro.showModal({content:"\u9700\u524D\u5F80\u8BBE\u7F6E\u754C\u9762\u5F00\u542F\u63A5\u6536\u901A\u77E5",confirmText:"\u53BB\u8BBE\u7F6E"}).then(S=>S.confirm)},a=(S,m)=>{const b=[],y=[];for(const C of S)switch(m[C]??"reject"){case"reject":b.push(C);break;case"ban":case"filter":y.push(C);break}return y.length&&logger.error("#requestSubscription","#ban",y),b},h=async(S,m)=>{try{if(await m()){const{subscriptionsSetting:b}=await taro.openSetting({withSubscriptions:!0});if(logger.debug("#requestSubscription","openSetting",b),b?.mainSwitch&&b.itemSettings)return a(S,b.itemSettings).length===0}}catch(b){logger.error("#requestSubscription","requestOpenSetting",b)}return!1};async function requestSubscription(S,m){const b={...R,...m};try{const y=a(S,await taro.requestSubscribeMessage({tmplIds:S}));if(y.length===0)return!0;const{subscriptionsSetting:C}=await taro.getSetting({withSubscriptions:!0});logger.debug("#requestSubscription","getSetting",C,{rejects:y});const O=C?.itemSettings??{},v=a(Object.keys(O),O);throw v.length&&y.every(q=>v.includes(q))?{errCode:-1}:{errCode:-2}}catch(y){switch(y.errCode){case-1:case 20004:if(await h(S,b.confirm))return!0;toast("\u672A\u6388\u6743\u8BA2\u9605\u6D88\u606F"),logger.warn("#requestSubscription","REJECT_BY_SETTING");break;case-2:toast("\u672A\u6388\u6743\u8BA2\u9605\u6D88\u606F"),logger.warn("#requestSubscription","REJECT_BY_USER");break;default:toast("\u7F51\u7EDC\u9519\u8BEF \u8BF7\u7A0D\u540E\u518D\u8BD5"),logger.error("#requestSubscription",y,S);break}}return!1}const SystemInfo={menuButtonRect:{bottom:0,height:0,left:0,right:0,top:0,width:0},safeArea:{bottom:0,height:0,left:0,right:0,top:0,width:0},isiPad:!1,isiOS:!1,isiPhoneX:!1,isAndroid:!1,isDevtools:!1,brand:"",model:"",pixelRatio:0,screenWidth:0,screenHeight:0,windowWidth:0,windowHeight:0,language:"",system:"",platform:"",benchmarkLevel:0,statusBarHeight:0,SDKVersion:"",version:""};function getSystemInfo(){try{const m=taro.getSystemInfoSync();if(!m)throw new Error("getSystemInfoSync is nil");const{system:b,model:y,platform:C}=m,O=/Android/i.test(b),v=/iOS/i.test(b),q=v&&/^iPhone (X|\d{2})/i.test(y),I=/iPad/i.test(y);Object.assign(SystemInfo,m,{isAndroid:O,isiPad:I,isiOS:v,isiPhoneX:q,isDevtools:C==="devtools"})}catch(m){logger.error("#SystemInfo",m)}const S=shared.attempt(taro.getMenuButtonBoundingClientRect);return S&&Object.assign(SystemInfo,{menuButtonRect:S}),logger.debug("#SystemInfo",SystemInfo),SystemInfo}getSystemInfo(),exports.Current=taro.Current,exports.AbortControllerImpl=AbortControllerImpl,exports.Request=Request,exports.RequestError=RequestError,exports.SystemInfo=SystemInfo,exports.copy=copy,exports.createRequest=createRequest,exports.createRewardedVideoAd=createRewardedVideoAd,exports.document=o,exports.getLogger=getLogger,exports.getRootElement=n$3,exports.getStorage=getStorage,exports.getStorageSync=getStorageSync,exports.getSystemInfo=getSystemInfo,exports.go=go,exports.hasNavBar=hasNavBar,exports.hasTabBar=hasTabBar,exports.hideShareMenu=hideShareMenu,exports.logger=logger,exports.removeStorage=removeStorage,exports.removeStorageSync=removeStorageSync,exports.requestSubscription=requestSubscription,exports.scene=scene,exports.setStorage=setStorage,exports.setStorageSync=setStorageSync,exports.showShareMenu=showShareMenu,exports.toast=toast;