mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-05 19:42:07 +08:00
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{d as Q,t as W,c as U}from"./lodash@4.17.21-Cw59kuJw.js";import"./js-cookie@3.0.5-Z_8Sd105.js";import{s as p}from"./screenfull@5.2.0-DmMZCkhi.js";const M=(n,{manual:e,ready:t=!0,refreshDeps:s=[],refreshDepsAction:r})=>{const u=Vue.ref(!1);return Vue.watchEffect(()=>{!e&&n.options.refreshDeps!==!0&&(u.value=Vue.unref(t))}),s instanceof Array?Vue.watch([u,...s],([i])=>{i&&!e&&i&&(r?r():n.refresh())},{deep:!0,immediate:!1}):Vue.watch(u,i=>{!e&&i&&(r?r():n.refresh())}),{name:"autoRunPlugin",onBefore:()=>{if(!Vue.unref(t))return{stopNow:!0}}}};M.onInit=({ready:n=!0,manual:e})=>({loading:!e&&Vue.unref(n)});const S=new Map,G=(n,e,t)=>{const s=S.get(n);s!=null&&s.timer&&clearTimeout(s.timer);let r;e>-1&&(r=setTimeout(()=>{S.delete(n)},e)),S.set(n,{...t,timer:r})},Y=n=>S.get(n),O=new Map,z=n=>O.get(n),J=(n,e)=>{O.set(n,e),e.then(t=>(O.delete(n),t)).catch(t=>{throw O.delete(n),t})},w={},X=[],Z=(n,e)=>{w[n]&&(w[n].forEach(t=>t(e)),X.forEach(t=>t({type:n,data:e})))},D=(n,e)=>(w[n]||(w[n]=[]),w[n].push(e),function(){const s=w[n].indexOf(e);w[n].splice(s,1)}),K=(n,{cacheKey:e,cacheTime:t=5*60*1e3,staleTime:s=0,setCache:r,getCache:u})=>{const i=Vue.ref(),a=Vue.ref(),o=(l,c)=>{r?r(c):G(l,t,c),Z(l,c.data)},d=(l,c=[])=>u?u(c):Y(l);return Vue.watchEffect(()=>{if(!e)return;const l=d(e);l&&Object.hasOwnProperty.call(l,"data")&&(n.state.data=l.data,n.state.params=l.params,(s===-1||new Date().getTime()-l.time<=s)&&(n.state.loading=!1)),i.value=D(e,c=>{n.setState({data:c})})}),Vue.onScopeDispose(()=>{var l;(l=i.value)==null||l.call(i)}),e?{name:"cachePlugin",onBefore:l=>{const c=d(e,l);return!c||!Object.hasOwnProperty.call(c,"data")?{}:s===-1||new Date().getTime()-c.time<=s?{loading:!1,data:c==null?void 0:c.data,returnNow:!0}:{data:c==null?void 0:c.data}},onRequest:(l,c)=>{let h=z(e);return h&&h!==a.value?{servicePromise:h}:(h=l(...c),a.value=h,J(e,h),{servicePromise:h})},onSuccess:(l,c)=>{var h;e&&((h=i.value)==null||h.call(i),o(e,{data:l,params:c,time:new Date().getTime()}),i.value=D(e,f=>{n.setState({data:f})}))},onMutate:l=>{var c;e&&((c=i.value)==null||c.call(i),o(e,{data:l,params:n.state.params,time:new Date().getTime()}),i.value=D(e,h=>{n.setState({data:h})}))}}:{}},k=(n,{debounceWait:e,debounceLeading:t,debounceTrailing:s,debounceMaxWait:r})=>{const u=Vue.ref(),i=Vue.computed(()=>{const a={},o=Vue.unref(t),d=Vue.unref(s),l=Vue.unref(r);return o!==void 0&&(a.leading=o),d!==void 0&&(a.trailing=d),l!==void 0&&(a.maxWait=l),a});return Vue.watchEffect(a=>{if(Vue.unref(e)){const o=n.runAsync.bind(n);u.value=Q(d=>{d()},Vue.unref(e),i.value),n.runAsync=(...d)=>new Promise((l,c)=>{var h;(h=u.value)==null||h.call(u,()=>{o(...d).then(l).catch(c)})}),a(()=>{var d;(d=u.value)==null||d.cancel(),n.runAsync=o})}}),Vue.unref(e)?{name:"debouncePlugin",onCancel:()=>{var a;(a=u.value)==null||a.cancel()}}:{}};var ee=Object.defineProperty,te=(n,e,t)=>e in n?ee(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,L=(n,e,t)=>(te(n,typeof e!="symbol"?e+"":e,t),t);class ne{constructor(){L(this,"table",{}),L(this,"hashTable",{})}insert(e){const t=Symbol(e);return this.table[e]=!0,this.hashTable[t]=e,t}find(e){return this.hashTable[e]}}new ne;var se=Object.defineProperty,re=(n,e,t)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,$=(n,e,t)=>(re(n,typeof e!="symbol"?e+"":e,t),t);class ie{constructor(){$(this,"requestInstances",new Map),$(this,"listeners",[])}emit(e){this.listeners.forEach(t=>t(e))}subscribe(e){return this.listeners.push(e),()=>{const t=this.listeners.indexOf(e);this.listeners.splice(t,1)}}insert(e,t){this.requestInstances.set(e,{...t}),this.emit({key:e,...t})}update(e,t){this.has(e)&&this.requestInstances.set(e,{...this.requestInstances.get(e),...t})}has(e){return this.requestInstances.has(e)}reset(e){if(this.requestInstances.has(e)){const t=this.requestInstances.get(e);this.requestInstances.clear(),this.insert(e,t)}else this.requestInstances.clear()}getAll(){return this.requestInstances}}new ie;const ue=(n,{loadingDelay:e})=>{const t=Vue.ref(),s=()=>{t.value&&(clearTimeout(Vue.unref(t.value)),t.value=void 0)};return{name:"loadingDelayPlugin",onFinally:()=>{s();const r=Vue.unref(e);r&&(n.setState({loading:!0}),t.value=setTimeout(()=>{n.setState({loading:!1})},r))},onError:()=>{s()}}};function T(){return!!(typeof window<"u"&&window.document&&window.document.createElement)}const oe=!!(typeof window<"u"&&window.document&&window.document.createElement);function F(){return T()?document.visibilityState!=="hidden":!0}const E=[];function le(n){return E.push(n),function(){const t=E.indexOf(n);E.splice(t,1)}}if(T()){const n=()=>{if(F())for(let e=0;e<E.length;e++){const t=E[e];t()}};window.addEventListener("visibilitychange",n,!1)}const ae=(n,{pollingInterval:e,pollingWhenHidden:t=!0,pollingErrorRetryCount:s=-1})=>{let r;const u=Vue.ref(),i=Vue.ref(0),a=()=>{var o;r&&clearTimeout(r),(o=u.value)==null||o.call(u)};return Vue.watchEffect(()=>{Vue.unref(e)||a()}),Vue.unref(e)?{name:"pollingPlugin",onBefore:()=>{a()},onError:()=>{i.value+=1},onSuccess:()=>{i.value=0},onFinally:()=>{s===-1||s!==-1&&i.value<=s?r=setTimeout(()=>{!t&&!F()?u.value=le(()=>{n.refresh()}):n.refresh()},Vue.unref(e)):i.value=0},onCancel:()=>{a()}}:{}};function ce(n,e){let t=!1;return(...s)=>{t||(t=!0,n(...s),setTimeout(()=>{t=!1},e))}}function fe(){return T()&&typeof navigator.onLine<"u"?navigator.onLine:!0}const P=[];function de(n){return P.push(n),function(){const t=P.indexOf(n);t>-1&&P.splice(t,1)}}if(oe){const n=()=>{if(!(!F()||!fe()))for(let e=0;e<P.length;e++){const t=P[e];t()}};window.addEventListener("visibilitychange",n,!1),window.addEventListener("focus",n,!1)}const he=(n,{refreshOnWindowFocus:e,focusTimespan:t=5e3})=>{const s=Vue.ref(),r=()=>{var u;(u=s.value)==null||u.call(s)};return Vue.watchEffect(u=>{if(Vue.unref(e)){const i=ce(n.refresh.bind(n),Vue.unref(t));s.value=de(()=>{i()})}u(()=>{r()})}),Vue.onScopeDispose(()=>{r()}),{name:"refreshOnWindowFocusPlugin"}},ve=(n,{retryInterval:e,retryCount:t})=>{const s=Vue.ref(),r=Vue.ref(0),u=Vue.ref(!1);return t?{name:"retryPlugin",onBefore:()=>{u.value||(r.value=0),u.value=!1,s.value&&clearTimeout(s.value)},onSuccess:()=>{r.value=0},onError:()=>{if(r.value+=1,t===-1||r.value<=t){const i=e??Math.min(1e3*2**r.value,3e4);s.value=setTimeout(()=>{u.value=!0,n.refresh()},i)}else r.value=0},onCancel:()=>{r.value=0,s.value&&clearTimeout(s.value)}}:{}},me=(n,{throttleWait:e,throttleLeading:t,throttleTrailing:s})=>{const r=Vue.computed(()=>{const i={};return Vue.unref(t)!==void 0&&(i.leading=Vue.unref(t)),Vue.unref(s)!==void 0&&(i.trailing=Vue.unref(s)),i}),u=Vue.computed(()=>W(i=>{i()},Vue.unref(e),r.value));return Vue.watchEffect(i=>{if(Vue.unref(e)){const a=n.runAsync.bind(n);n.runAsync=(...o)=>new Promise((d,l)=>{var c;(c=u.value)==null||c.call(u,()=>{a(...o).then(d).catch(l)})}),i(()=>{var o;n.runAsync=a,(o=u.value)==null||o.cancel()})}}),Vue.unref(e)?{name:"throttlePlugin",onCancel:()=>{var i;(i=u.value)==null||i.cancel()}}:{}},H=n=>typeof n=="function",pe=n=>typeof n=="boolean";var be=Object.defineProperty,ge=(n,e,t)=>e in n?be(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,R=(n,e,t)=>(ge(n,typeof e!="symbol"?e+"":e,t),t);class _e{constructor(e,t,s,r={}){R(this,"pluginImpls"),R(this,"count",0),R(this,"state",{loading:!1,params:void 0,data:void 0,error:void 0}),R(this,"previousValidData"),this.serviceRef=e,this.options=t,this.setUpdateData=s,this.initState=r,this.state={...this.state,loading:!t.manual,...r}}setState(e={}){this.state={...this.state,...e},this.setUpdateData(this.state)}setData(e,t){console.warn("Please use 'setFetchState' instead of 'setData'"),t instanceof Array?t.forEach(s=>{this.state[s]=e,this.setUpdateData(e,s)}):(this.state[t]=e,this.setUpdateData(e,t))}setFetchState(e,t){t instanceof Array?t.forEach(s=>{this.state[s]=e,this.setUpdateData(e,s)}):(this.state[t]=e,this.setUpdateData(e,t))}runPluginHandler(e,...t){var s,r,u;const i=(u=(r=(s=this.pluginImpls)==null?void 0:s.map(a=>{var o;return(o=a[e])==null?void 0:o.call(a,...t)}))!=null?r:[])==null?void 0:u.filter(Boolean);return Object.assign({},...i)}async runAsync(...e){var t,s,r,u,i,a,o,d,l,c,h;this.count+=1;const f=this.count,{stopNow:g=!1,returnNow:v=!1,...b}=this.runPluginHandler("onBefore",e);if(g)return new Promise(()=>{});if(this.setState({loading:!0,params:e,...b}),v)return Promise.resolve(b.data);try{(s=(t=this.options).onBefore)==null||s.call(t,e)}catch(m){return this.setState({error:m,loading:!1}),(u=(r=this.options).onError)==null||u.call(r,m,e),this.runPluginHandler("onError",m,e),new Promise(()=>{})}try{let{servicePromise:m}=this.runPluginHandler("onRequest",this.serviceRef.value,e);const I=y=>{var q,C,B,x;if(f!==this.count)return new Promise(()=>{});const _=this.options.formatResult?this.options.formatResult(y):y;return this.setState({data:_,error:void 0,loading:!1}),(C=(q=this.options).onSuccess)==null||C.call(q,_,e),this.runPluginHandler("onSuccess",_,e),this.previousValidData=_,(x=(B=this.options).onFinally)==null||x.call(B,e,_,void 0),f===this.count&&this.runPluginHandler("onFinally",e,_,void 0),_};m||(m=this.serviceRef.value(...e));const j=await m;return I(j)}catch(m){if(f!==this.count)return new Promise(()=>{});throw this.setState({error:m,loading:!1}),(a=(i=this.options).onError)==null||a.call(i,m,e),this.runPluginHandler("onError",m,e),(H((o=this.options)==null?void 0:o.rollbackOnError)&&((d=this.options)!=null&&d.rollbackOnError(e))||pe((l=this.options)==null?void 0:l.rollbackOnError)&&this.options.rollbackOnError)&&this.setState({data:this.previousValidData}),(h=(c=this.options).onFinally)==null||h.call(c,e,void 0,m),f===this.count&&this.runPluginHandler("onFinally",e,void 0,m),m}}run(...e){this.runAsync(...e).catch(t=>{this.options.onError||console.error(t)})}cancel(){this.count+=1,this.setState({loading:!1}),this.runPluginHandler("onCancel")}refresh(){this.run(...this.state.params||[])}refreshAsync(){return this.runAsync(...this.state.params||[])}mutate(e){const t=H(e)?e(this.state.data):e;this.runPluginHandler("onMutate",t),this.setState({data:t})}}const Ve=Symbol("USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY");function we(n){return Object.keys(n).filter(t=>["data","loading","params","error"].includes(t)).length===4}function Ee(n,e={},t=[]){const s=Vue.inject(Ve,{}),{initialData:r=void 0,manual:u=!1,ready:i=!0,...a}={...s??{},...e??{}},o={manual:u,ready:i,initialData:r,...a},d=Vue.ref(n),l=Vue.reactive({data:r,loading:!1,params:void 0,error:void 0}),c=(v,b)=>{b?l[b]=v:we(v)&&(l.data=v.data,l.loading=v.loading,l.error=v.error,l.params=v.params)},h=t.map(v=>{var b;return(b=v==null?void 0:v.onInit)==null?void 0:b.call(v,o)}).filter(Boolean),f=new _e(d,o,c,Object.assign({},...h,l));f.options=o,f.pluginImpls=t.map(v=>v(f,o));const g=Vue.computed(()=>Vue.isRef(i)?i.value:i);if(Vue.watchEffect(()=>{if(!u){const v=f.state.params||e.defaultParams||[];g.value&&f.options.refreshDeps===!0&&d.value&&f.run(...v)}}),!u&&f.options.refreshDeps!==!0){const v=f.state.params||e.defaultParams||[];Vue.unref(i)&&f.run(...v)}return Vue.onScopeDispose(()=>{f.cancel()}),{...Vue.toRefs(l),cancel:f.cancel.bind(f),refresh:f.refresh.bind(f),refreshAsync:f.refreshAsync.bind(f),run:f.run.bind(f),runAsync:f.runAsync.bind(f),mutate:f.mutate.bind(f)}}const Pe=(n,e)=>function(s,r={},u=[]){let i=n;const a=e||[];for(let o=a.length;o--;)i=a[o](i);return i(s,r,u)};function qe(n,e,t){var s;const r=(s=[null,k,ue,ae,he,me,M,K,ve])==null?void 0:s.filter(Boolean);return Pe(Ee,e==null?void 0:e.use)(n,e,[...r])}const Re=!!(typeof window<"u"&&window.document&&window.document.createElement);function A(n,e){var t,s;if(!Re)return;if(!n)return e;let r;return typeof n=="function"?r=n():Vue.isRef(n)?r=(s=(t=n.value)==null?void 0:t.$el)!=null?s:n.value:r=n,r}function N(n,e){if(n===e)return!0;for(let t=0;t<n.length;t++)if(!Object.is(n[t],e[t]))return!1;return!0}const Se=n=>(t,s,r)=>{const u=Vue.ref(!1),i=Vue.ref([]),a=Vue.ref([]),o=Vue.ref();n(()=>{var d;const c=(Array.isArray(r)?r:[r]).map(h=>A(h));if(!u.value){u.value=!0,i.value=c,a.value=s,o.value=t();return}(c.length!==i.value.length||!N(c,i.value)||!N(s,a.value))&&((d=o.value)==null||d.call(o),i.value=c,a.value=s,o.value=t())}),Vue.onUnmounted(()=>{var d;(d=o.value)==null||d.call(o),u.value=!1})};Se(Vue.watchEffect);var Oe=Object.defineProperty,Ae=(n,e,t)=>e in n?Oe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,V=(n,e,t)=>(Ae(n,typeof e!="symbol"?e+"":e,t),t);class De{constructor(){V(this,"subscriptions",new Map),V(this,"emitEffectCache",new Map),V(this,"useSubscription",(e,t)=>{const s=Vue.ref();Vue.watchEffect(r=>{var u,i;s.value=t;function a(d){s.value&&s.value(d)}const o=(i=(u=this.subscriptions)==null?void 0:u.get(e))!=null?i:[];o.push(a),this.subscriptions.set(e,o),this.emitEffect(e),r(()=>{this.subscriptions.delete(e)})})}),V(this,"emit",(e,...t)=>{if(typeof e=="string"||typeof e=="number"){const s=this.subscriptions.get(e);s==null||s.forEach(r=>{r==null||r({params:U(t),event:e})}),this.emitEffectCache.set(e,{params:U(t),event:e})}else throw new TypeError("event must be string or number !")}),V(this,"emitEffect",e=>{const t=this.emitEffectCache.get(e),s=this.subscriptions.get(e);t&&(s==null||s.forEach(r=>{r==null||r({...t})}))}),V(this,"removeListener",e=>{this.subscriptions.delete(e)}),V(this,"clear",()=>{this.subscriptions.clear()}),this.clear()}}new De;const Ce=(n,e)=>{const{onExit:t,onEnter:s,defaultElement:r=document.documentElement}={},u=Vue.ref(t),i=Vue.ref(s),a=Vue.ref(!1),o=f=>{a.value=f},d=()=>{var f,g,v;if(p.isEnabled){const b=A(n,r);if(!p.element)(f=u.value)==null||f.call(u),o(!1),p.off("change",d);else{const m=p.element===b;m?(g=i.value)==null||g.call(i):(v=u.value)==null||v.call(u),o(m)}}},l=()=>{const f=A(n,r);if(f&&p.isEnabled)try{p.request(f),p.on("change",d)}catch(g){console.error(g)}},c=()=>{const f=A(n,r);p.isEnabled&&p.element===f&&p.exit()},h=()=>{a.value?c():l()};return Vue.onUnmounted(()=>{p.isEnabled&&p.off("change",d)}),[Vue.readonly(a),{enterFullscreen:l,exitFullscreen:c,toggleFullscreen:h,isEnabled:p.isEnabled}]};export{qe as a,Ce as u};
|