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