react-await-util
Version:
Processing asynchronous data in react functional components.
2 lines (1 loc) • 21.1 kB
JavaScript
import{isValidElement as e,createContext as n,useRef as t,useContext as r,useState as o,useCallback as c,useEffect as s,forwardRef as a,useMemo as l,useImperativeHandle as i,cloneElement as u,createElement as d,Fragment as p,Suspense as m,useLayoutEffect as f}from"react";const h=Symbol(),v=Symbol(),y=Symbol();function E(e){return e.then((n=>Object.defineProperty(e,h,{value:n})),(n=>Object.defineProperty(e,v,{value:n}))).finally((()=>Object.defineProperty(e,y,{value:!0})))}function F(e,n){return e!==n}function C(e,n){return Object.entries(e).some((([e,t])=>t!==n[e]))}function g(e,n){return e.some(((e,t)=>e!==n[t]))}function P(e){return e.isIntersecting}function S(){let e,n;return{promise:new Promise(((t,r)=>{e=t,n=r})),resolve:e,reject:n}}function j(n,t){return e(n)&&t()&&!n.props.jumpFirst}const w=Symbol("pending"),b=Symbol("resolve"),x=Symbol("reject");function A(e){return e===w}function L(e){return e===b}function I(e){return e===x}function T({resolve:e,init:n,delay:r=200,jumpFirst:o=!1,cleanup:c=!0,onStart:s,onEnd:a,onError:l,onFinal:i}){const u=D(),d=t(!0),p=t(new Map).current,m=t(null),f=t(w),E=t(n),F=t(null);return d.current?(d.current=!1,!o&&e instanceof Promise?P(!0):(f.current=b,g(!1,void 0))):e instanceof Promise&&m.current!==e&&P(!1),F.current;function C(e){if(Reflect.has(e,h)){f.current=b;const n=Reflect.get(e,h);E.current=n,a?.(n)}else f.current=x,l?.(Reflect.get(e,v))}function g(e,n){F.current={first:e,status:f.current,value:E.current,error:n}}function P(n){if(Reflect.has(e,y))m.current=e,C(e);else{e=Object.defineProperty(e,y,{value:!0}),c&&p.get(m.current)?.(),m.current=e;let t=!0;c&&p.set(e,(()=>{t=!1,p.delete(e)})),f.current=w,s?.(n);const o=Date.now();e.then((n=>Object.defineProperty(e,h,{value:n})),(n=>Object.defineProperty(e,v,{value:n}))).finally((()=>{const s=Date.now()-o;setTimeout((()=>{t&&(c&&p.delete(e),C(e),i?.(n),g(!1,Reflect.get(e,v)),u())}),s>=r?0:r-s)}))}g(n,Reflect.get(e,v))}}const k=n((function(e){return e}));function O({deps:e,handle:n,init:s,delay:a=200,jumpFirst:l=!1,cleanup:i=!0,onStart:u,onEnd:d,onError:p,onFinal:m}){const f=t(void 0);f.current=e;const h=r(k),[v,y]=o((()=>l?void 0:h(n(e)))),E=c((e=>{y(h(e instanceof Promise?e.then((e=>n(f.current,e))):n(f.current,e)))}),[]);return[T({resolve:v,init:s,delay:a,jumpFirst:l,cleanup:i,onStart:u,onEnd:d,onError:p,onFinal:m}),E]}function $({deps:e,handle:n,reducersDeps:r,reducers:s,init:a,delay:l=200,jumpFirst:i=!1,cleanup:u=!0,onStart:d,onEnd:p,onError:m,onFinal:f}){const[h,v]=O({deps:e,handle:n,init:a,delay:l,jumpFirst:i,cleanup:u,onStart:d,onEnd:p,onError:m,onFinal:f}),y=t(void 0);y.current=r;const E=o((()=>"function"==typeof s?s():s??{}))[0];return[h,c((e=>{if(e){const{type:n,payload:t}=e,r=E[n];"function"==typeof r&&v(r({type:n,payload:t,deps:y.current?.[n]}))}else v()}),[]),o((()=>Object.keys(E).reduce(((e,n)=>(e[n]=e=>({type:n,payload:e}),e)),{})))[0]]}function R(e,n){return e(n)}const M=n(R);function q({deps:e,compare:n=F,handle:o,init:c,delay:s=200,jumpFirst:a=!1,cleanup:l=!0,onStart:i,onEnd:u,onError:d,onFinal:p}){const m=t(null),f=t(null),h=t(!0),[v,y,E]=W(),C=r(M);h.current?(h.current=!1,a||(m.current=C(o,e))):E.current&&(y.current||n(e,f.current))&&(y.current=!1,m.current=C(o,e)),f.current=e;return[T({resolve:m.current,init:c,delay:s,jumpFirst:a,cleanup:l,onStart:i,onEnd:u,onError:d,onFinal:p}),v]}function N({deps:e={},compare:n=C,handle:t,init:r,delay:o=200,jumpFirst:c=!1,cleanup:s=!0,onStart:a,onEnd:l,onError:i,onFinal:u}){return q({deps:e,compare:n,handle:t,init:r,delay:o,jumpFirst:c,cleanup:s,onStart:a,onEnd:l,onError:i,onFinal:u})}function B({deps:e=[],compare:n=g,handle:t,init:r,delay:o=200,jumpFirst:c=!1,cleanup:s=!0,onStart:a,onEnd:l,onError:i,onFinal:u}){return q({deps:e,compare:n,handle:t,init:r,delay:o,jumpFirst:c,cleanup:s,onStart:a,onEnd:l,onError:i,onFinal:u})}function D(){const e=o(!0)[1];return c((()=>{e((e=>!e))}),[])}function W(){const e=D(),n=t(!1),r=t(!0);return[o((()=>{const t=()=>{n.current=!0,e()};return{update:t,unWatch:()=>{r.current&&(r.current=!1,e())},reWatch:()=>{r.current||(r.current=!0,t())},get isWatching(){return r.current}}}))[0],n,r]}function z(e,n,r,o,c,a){const l=t(null),i=t(!1);return s((()=>{if(l.current?.nodeType===Node.ELEMENT_NODE){let t=new IntersectionObserver((n=>{const r=n[0];a(r)&&(i.current=!0,t.disconnect(),t=null,l.current=null,e())}),{root:r?l.current.parentElement:n?.current,rootMargin:o,threshold:c});return t.observe(l.current),()=>{t&&(t.disconnect(),t=null)}}i.current=!0,e()}),[]),{placeholder:l,flag:i}}function K({resolve:e,init:n,delay:t=200,jumpFirst:r=!1,cleanup:o=!0,onStart:c,onEnd:s,onError:a,onFinal:i,onComputed:u,placeholder:d,children:p}){const m=T({resolve:e,init:n,delay:t,jumpFirst:r,cleanup:o,onStart:c,onEnd:s,onError:a,onFinal:i}),f=l((()=>u?.(m)),[m]);if(e!==ne)return p({...m,computed:f,placeholder:d})}const V=a((function({deps:e,handle:n,init:t,delay:r=200,jumpFirst:o=!1,cleanup:c=!0,onStart:s,onEnd:a,onError:u,onFinal:d,onComputed:p,placeholder:m,children:f},h){const[v,y]=O({deps:e,handle:n,init:t,delay:r,jumpFirst:o,cleanup:c,onStart:s,onEnd:a,onError:u,onFinal:d}),E=l((()=>p?.(v)),[v]);return i(h,(()=>({setResolve:y})),[]),f({...v,computed:E,setResolve:y,placeholder:m})})),_=a((function({deps:e,handle:n,reducersDeps:t,reducers:r,init:o,delay:c=200,jumpFirst:s=!1,cleanup:a=!0,onStart:u,onEnd:d,onError:p,onFinal:m,onComputed:f,placeholder:h,children:v},y){const[E,F,C]=$({deps:e,handle:n,reducersDeps:t,reducers:r,init:o,delay:c,jumpFirst:s,cleanup:a,onStart:u,onEnd:d,onError:p,onFinal:m}),g=l((()=>f?.(E)),[E]);return i(y,(()=>({dispatch:F,actions:C})),[]),v({...E,computed:g,dispatch:F,actions:C,placeholder:h})})),G=new Set([V,_]);function H({root:e,rootIsParent:n,rootMargin:t,threshold:r,children:c,onIntersection:s=P}){const[a]=o((()=>j(c,(()=>G.has(c.type))))),[l,i]=o((()=>{const{promise:e,resolve:n}=S();let t;return[n=>(t=n,m.current?t:e),()=>{a&&n(E(t))}]}))[0],{placeholder:p,flag:m}=z(i,e,n,t,r,s);if(a){const e=m.current?c:u(c,{placeholder:p});return d(k.Provider,{value:l},e)}}const J=a((function({deps:e,compare:n=F,handle:t,init:r,delay:o=200,jumpFirst:c=!1,cleanup:s=!0,onStart:a,onEnd:u,onError:d,onFinal:p,onComputed:m,placeholder:f,children:h},v){const[y,E]=q({deps:e,compare:n,handle:t,init:r,delay:o,jumpFirst:c,cleanup:s,onStart:a,onEnd:u,onError:d,onFinal:p}),C=l((()=>m?.(y)),[y]);return i(v,(()=>E),[]),h({...y,computed:C,watchOptions:E,placeholder:f})})),Q=a((function({deps:e={},compare:n=C,handle:t,init:r,delay:o=200,jumpFirst:c=!1,cleanup:s=!0,onStart:a,onEnd:u,onError:d,onFinal:p,onComputed:m,placeholder:f,children:h},v){const[y,E]=q({deps:e,compare:n,handle:t,init:r,delay:o,jumpFirst:c,cleanup:s,onStart:a,onEnd:u,onError:d,onFinal:p}),F=l((()=>m?.(y)),[y]);return i(v,(()=>E),[]),h({...y,computed:F,watchOptions:E,placeholder:f})})),U=a((function({deps:e=[],compare:n=g,handle:t,init:r,delay:o=200,jumpFirst:c=!1,cleanup:s=!0,onStart:a,onEnd:u,onError:d,onFinal:p,onComputed:m,placeholder:f,children:h},v){const[y,E]=q({deps:e,compare:n,handle:t,init:r,delay:o,jumpFirst:c,cleanup:s,onStart:a,onEnd:u,onError:d,onFinal:p}),F=l((()=>m?.(y)),[y]);return i(v,(()=>E),[]),h({...y,computed:F,watchOptions:E,placeholder:f})})),X=new Set([J,Q,U]);function Y({root:e,rootIsParent:n,rootMargin:t,threshold:r,children:c,onIntersection:s=P}){const[a]=o((()=>j(c,(()=>X.has(c.type))))),[l,i]=o((()=>{const{promise:e,resolve:n}=S();let t;return[(n,r)=>(t=R(n,r),m.current?t:e),()=>{a&&n(E(t))}]}))[0],{placeholder:p,flag:m}=z(i,e,n,t,r,s);if(a){const e=m.current?c:u(c,{placeholder:p});return d(M.Provider,{value:l},e)}}const Z=new Set(["forwards","backwards","together"]),ee=Symbol(),ne=Symbol();function te(e,n){e.forEach(n)}function re(e,n){for(let t=e.length-1;t>=0;--t)n(e[t],t)}function oe({order:e,tail:n,gap:t=200,children:r}){const o=D();if(!Z.has(e))return r;Array.isArray(r)||(r=[r]);const c=r.map((e=>e?.type===K?e.props.resolve:ee));if("together"===e){const e=[],n=[];if(c.forEach(((t,r)=>{t instanceof Promise&&!Reflect.has(t,y)&&(e.push(E(t)),n.push(r))})),e.length>0){const t=Promise.allSettled(e);n.forEach(((n,r)=>c[n]=t.then((()=>e[r]))))}}else switch(n){case"collapsed":{let n=!1;("forwards"===e?te:re)(c,((e,r)=>{e instanceof Promise&&!Reflect.has(e,y)&&(n?c[r]=ne:(n=!0,c[r]=E(e).finally((()=>setTimeout(o,t)))))}));break}default:c["forwards"===e?"reduce":"reduceRight"](((e,n,r)=>{if(n instanceof Promise&&!Reflect.has(n,y)){const o=E(n),s=()=>{return e=t,n=o,new Promise((t=>setTimeout(t,e,n)));var e,n};return c[r]=e.then(s,s)}return e}),Promise.resolve())}return d(p,null,...c.map(((e,n)=>{const t=r[n];return e===ee?t:u(t,{resolve:e})})))}function ce({root:e,rootIsParent:n=!1,rootMargin:r,threshold:c,children:s,onIntersection:a=P}){const l=t(null),[i]=o((()=>j(s,(()=>s.type===K)))),[d,p]=o((()=>{const{promise:e,resolve:n}=S();return[e,()=>{i&&(n(E(l.current.props.resolve)),l.current=null)}]}))[0],{placeholder:m,flag:f}=z(p,e,n,r,c,a);if(i)return f.current?s:(l.current=s,u(s,{resolve:d,placeholder:m}))}function se(e){return e()}const ae=n(se),le=Symbol(),ie=a((function({wrap:e,compare:n=C,init:o,delay:c=200,jumpFirst:s=!1,cleanup:a=!0,onStart:u,onEnd:d,onError:p,onFinal:m,onComputed:f,placeholder:h,children:v},y){if("function"!=typeof e.type)throw new Error("wrap type must be a function component.");const E=t(null),F=t(null),g=t(null),P=t(!0),S=r(ae),[j,w,b]=W();i(y,(()=>j),[]);const x=()=>e.type(e.props);P.current?(P.current=!1,s||(E.current=S(x))):b.current&&(w.current||e.type!==F.current||n(e.props,g.current))&&(w.current=!1,E.current=S(x)),F.current=e.type,g.current=e.props;const A=T({resolve:E.current,init:o,delay:c,jumpFirst:s,cleanup:a,onStart:u,onEnd:d,onError:p,onFinal:m}),L=l((()=>f?.(A)),[A]);return v({...A,computed:L,placeholder:h,watchOptions:j})}));function ue({root:e,rootIsParent:n,rootMargin:t,threshold:r,children:c,onIntersection:s=P}){const a=o((()=>j(c,(()=>Reflect.has(c.type,le)))))[0],[l,i]=o((()=>{const{promise:e,resolve:n}=S();let t;return[n=>(t=se(n),m.current?t:e),()=>{a&&n(E(t))}]}))[0],{placeholder:p,flag:m}=z(i,e,n,t,r,s);if(a){const e=m.current?c:u(c,{placeholder:p});return d(ae.Provider,{value:l},e)}}Object.defineProperty(ie,le,{value:!0});const de=n(void 0);function pe(){return r(de)}function me(){}function fe(){}function he({name:e="AsyncComponent",init:n=me,compare:c=C,delay:s=200,jumpFirst:u=!1,cleanup:p=!0,onStart:m,onEnd:f,onError:h,onFinal:v,onComputed:y,useAction:E=fe,loader:F,Component:g}){const P=a((function({placeholder:e,...a},C){const P=t(null),S=t(null),j=t(!0),w=r(ae),[b,x,A]=W(),L=o((()=>n(a)))[0],I=E(a,b),k=t(void 0);i(C,(()=>b),[]);const O=()=>F(a,I);j.current?(j.current=!1,u||(P.current=w(O))):A.current&&(x.current||c(a,S.current,I,k.current))&&(x.current=!1,P.current=w(O)),S.current=a,k.current=I;const $=T({resolve:P.current,init:L,delay:s,jumpFirst:u,cleanup:p,onStart:m,onEnd:f,onError:h,onFinal:v}),R=l((()=>y?.($)),[$]);return d(de.Provider,{value:{...$,computed:R,action:I,placeholder:e,watchOptions:b}},d(g,a))}));return Object.defineProperties(P,{displayName:{value:e},[le]:{value:!0}})}function ve({useAction:e,options:n,children:t}){return t(e(n))}function ye({condition:e,not:n=!1,children:t,fallback:r}){return("function"==typeof e?e():e)^n?t:r}function Ee({condition:e,not:n=!1,children:t}){const r=("function"==typeof e?e():e)^!n;return d(m,null,d(Fe,{valid:r,children:t}))}function Fe({valid:e,children:n}){const r=t(null),[c,s]=o((()=>({current:!0})));if(f((()=>{e?s({current:!1}):c.current=!1}),[]),!c.current){if(e)throw null===r.current&&(r.current=new Promise((e=>e))),r.current;r.current=null}return n}function Ce({items:e,keyPath:n,children:t}){const r=void 0!==n;r&&(n=[n].flat());const o=[];let c=0;for(const s of e)o.push(t({item:s,index:c,key:r?n.reduce(((e,n)=>e[n]),s):void 0})),c+=1;return o}function ge({deps:e=[],children:n}){return l((()=>n),e)}const Pe=n(void 0);function Se({children:e}){e=[e].flat();const n={parent:r(Pe),tmplChildren:e.slice(1).reduce(((e,n)=>{if(n?.type===je){const{name:t="default",children:r}=n.props;e[t]??=r}return e}),{})};return d(Pe.Provider,{value:n},e[0])}function je(){}function we({name:e="default",children:n,...t}){const{parent:o,tmplChildren:c}=r(Pe)??{},s=c?.[e],a=s?"function"==typeof s?s(t):s:n;return d(Pe.Provider,{value:o},a)}const be=n(void 0);function xe({children:e}){const n={index:0,array:(e=[e].flat()).slice(1).reduce(((e,n)=>(n?.type===Ae&&e.push(n.props.children),e)),[])};return d(be.Provider,{value:n},e[0])}function Ae(){}function Le({children:e,...n}){const t=r(be);if(t){const{index:e,array:r}=t;if(e===r.length)return;const o=r[e],c="function"==typeof o?o(n):o,s={index:e+1,array:r};return d(be.Provider,{value:s},c)}}const Ie=n(void 0);function Te(){return!0}const ke=a((function({uniqueKey:e,include:n=Te,max:r=0,meta:a,children:l},u){const p=o(!0)[1],m=c((()=>p((e=>!e))),[]),f=t(new Re).current,h=t(new Re).current,v=t({}).current,y=t(null),E=c(((e,n)=>{f.remove(n.originItem),h.remove(n.sortedItem),delete v[e]}),[]),F=()=>{const e=v[y.current];e&&(e.cache?e.show=!1:E(y.current,e))};i(u,(()=>({get current(){return[y.current,v[y.current].meta]},get length(){return f.length},get:()=>{const n={};return f.forEach((t=>{n[t.value]=v[e].meta})),n},remove:e=>{if(e!==y.current){const n=v[e];n&&(E(e,n),m())}}})),[]),s((()=>{const n=v[e];if(n.valid=!1,n.activated.length>0){for(let e=n.activated.length-1;e>=0;--e){const t=n.activated[e].reduce(((e,n)=>{const t=n();return"function"==typeof t&&e.push(t),e}),[]);t.length>0&&n.deactivated.push(t)}if(n.deactivated.length>0)return()=>{for(let e=n.deactivated.length-1;e>=0;--e)n.deactivated[e].forEach((e=>e()));n.deactivated.length=0}}}),[e]);const C=v[e];if(void 0===C){const t=f.add(e),o=h.add(e);if(v[e]={element:l,show:!0,cache:n(e),originItem:t,sortedItem:o,valid:!0,activated:[],deactivated:[],meta:a},F(),r>0&&f.length>r){const e=h.removeFirst().value;f.remove(v[e].originItem),delete v[e]}}else e!==y.current&&(C.show=!0,h.moveLast(C.sortedItem),F()),C.element=l,C.meta=a;return y.current=e,f.map((({value:e})=>{const n=v[e];return d(Ee,{key:e,condition:n.show},d(Ie.Provider,{value:n},n.element))}))}));function Oe(e){const n=r(Ie);n&&n.valid&&n.activated.push([e].flat())}function $e(){const e=r(Ie);return e?.meta}class Re{#e=null;#n=null;#t=0;#r(e){return{value:e,prev:null,next:null}}#o(e){return null===this.#e?(this.#e=this.#n=e,e.prev=e.next=null):(this.#n.next=e,e.prev=this.#n,this.#n=e,e.next=null),this.#t+=1,e}add(e){const n=this.#r(e);return this.#o(n)}remove(e){if(0===this.#t)return null;if(1===this.#t)this.#e=this.#n=null;else if(e===this.#e)this.#e=this.#e.next,this.#e.prev=null;else if(e===this.#n)this.#n=this.#n.prev,this.#n.next=null;else{const{prev:n,next:t}=e;n.next=t,t.prev=n}return this.#t-=1,e}removeFirst(){return this.remove(this.#e)}moveLast(e){return this.remove(e),this.#o(e)}get length(){return this.#t}map(e){const n=[];let t=this.#e,r=0;for(;null!==t;)n.push(e(t,r)),r+=1,t=t.next;return n}forEach(e){let n=this.#e,t=0;for(;null!==n;)e(n,t),t+=1,n=n.next}}const Me=a((function({uniqueKey:e,tag:n="div",name:r="v",type:c,duration:s,appear:a=!1,enterFromClass:l,enterActiveClass:u,enterToClass:p,leaveFromClass:m,leaveActiveClass:h,leaveToClass:v,onEnter:y,onLeave:E,className:F,style:C,children:g},P){const[S,j]=o((()=>({current:!1}))),w=t(null);i(P,(()=>w.current),[]);const b=t(!0),x=t(e),A=t(g),L=We(r,l,u,p,m,h,v);return x.current===e?A.current=g:x.current=e,f((()=>{const e=w.current;let n=!0;const t=()=>{n&&j({current:!0})};switch(c){case"transition":if(b.current){if(a){const n=_e(e,L,b.current,s);requestAnimationFrame((()=>{requestAnimationFrame(n)}))}b.current=!1}else requestAnimationFrame(Ge(e,L,t,s));break;case"animation":b.current?(a&&He(e,L,b.current,s),b.current=!1):Je(e,L,t,s);break;case"animate":b.current?(a&&Qe(e,y,b.current),b.current=!1):function(e,n,t){n(e,(()=>{Ke(e),t()}))}(e,E,t)}return()=>{n=!1}}),[x.current]),f((()=>{if(S.current){S.current=!1;const e=w.current;switch(c){case"transition":requestAnimationFrame(_e(e,L,b.current,s));break;case"animation":He(e,L,b.current,s);break;case"animate":Qe(e,y,b.current)}}}),[S.current]),d(n,{ref:w,className:F,style:C,children:A.current})})),qe=new Set(["transition","animation","animate"]),Ne={position:"relative"},Be={x:"x",y:"y"},De=a((function({tag:e="div",name:n="v",type:r,duration:o,appear:c=!1,enterFromClass:s,enterActiveClass:a,enterToClass:l,leaveFromClass:u,leaveActiveClass:p,leaveToClass:m,moveClass:h,onEnter:v,onLeave:y,onMove:E,cssVars:F=Be,items:C,keyPath:g,className:P,style:S=Ne,children:j},w){const b=t(null);i(w,(()=>b.current),[]);const x=t(null),A=t(!0),L=We(n,s,a,l,u,p,m,h),I=void 0!==g;I&&(g=[g].flat());const T=[];let k=0;for(const e of C)T.push(j({item:e,index:k,key:I?g.reduce(((e,n)=>e[n]),e):void 0})),k+=1;return f((()=>{if(!qe.has(r))return;null===x.current&&(x.current=new Map);const e=b.current,n=new Map;if(T.forEach(((t,r)=>{const o=t.key;if(void 0!==o){const t=e.children.item(r);n.set(o,{element:t,x:t.offsetLeft,y:t.offsetTop})}})),A.current&&!c)A.current=!1;else if(n.size>0){let t,c,s;const a=[],l=[],i=[],u=[],d=[],p=[];switch(r){case"transition":t=e=>{a.push(_e(e,L,!0,o))},c=e=>{l.push(Ge(e,L,(()=>e.remove()),o))},s=(e,n,t)=>{i.push(function(e,n,t,r,o){return e.style.setProperty("transform",`translate(${t}px, ${r}px)`,"important"),()=>{e.classList.add(...n.moveClass),e.style.removeProperty("transform");const t=()=>{e.classList.remove(...n.moveClass)};Ve(e,"transitionend",t,o,"move")}}(e,L,n,t,o))};break;case"animation":t=e=>{He(e,L,!0,o)},c=e=>{Je(e,L,(()=>e.remove()),o)},s=(e,n,t)=>{!function(e,n,t,r,o,c){const s=`--${t.x}`,a=`--${t.y}`;e.style.setProperty(s,`${r}px`),e.style.setProperty(a,`${o}px`),e.classList.add(...n.moveClass);const l=()=>{e.style.removeProperty(s),e.style.removeProperty(a),e.classList.remove(...n.moveClass)};Ve(e,"animationend",l,c,"move")}(e,L,F,n,t,o)};break;case"animate":t=e=>{u.push(e)},c=e=>{d.push({element:e,done:()=>e.remove()})},s=(e,n,t)=>{p.push({element:e,x:n,y:t})}}switch(n.forEach(((e,n)=>{const r=x.current.get(n);if(r){const t=r.x-e.x,o=r.y-e.y;0===t&&0===o||s(e.element,t,o),x.current.delete(n)}else t(e.element)})),x.current.size>0&&x.current.forEach((n=>{const{element:t,x:r,y:o}=n;e.append(t),t.style.position="relative";const s=r-t.offsetLeft,a=o-t.offsetTop;0===s&&0===a||(t.style.left=`${s}px`,t.style.top=`${a}px`),c(t)})),r){case"transition":requestAnimationFrame((()=>{const e=()=>{[a,l,i].forEach((e=>{e.length>0&&e.forEach((e=>e()))}))};A.current?(A.current=!1,requestAnimationFrame(e)):e()}));break;case"animate":v(u),y(d),E(p)}}x.current=n})),d(e,{ref:b,className:P,style:S,children:T})}));function We(e,n,t,r,o,c,s,a){return l((()=>({enterFromClass:(n??`${e}-enter-from`).split(" ").filter(Boolean),enterActiveClass:(t??`${e}-enter-active`).split(" ").filter(Boolean),enterToClass:(r??`${e}-enter-to`).split(" ").filter(Boolean),leaveFromClass:(o??`${e}-leave-from`).split(" ").filter(Boolean),leaveActiveClass:(c??`${e}-leave-active`).split(" ").filter(Boolean),leaveToClass:(s??`${e}-leave-to`).split(" ").filter(Boolean),moveClass:(a??`${e}-move`).split(" ").filter(Boolean)})),[e,n,t,r,o,c,s,a])}function ze(e){e.style.removeProperty("opacity")}function Ke(e){e.style.setProperty("opacity","0","important")}function Ve(e,n,t,r,o){if(void 0===r)e.addEventListener(n,t,{once:!0});else{const e="number"==typeof r?r:r[o];setTimeout(t,e)}}function _e(e,n,t,r){return t||(ze(e),e.classList.remove(...n.leaveActiveClass,...n.leaveToClass)),e.classList.add(...n.enterFromClass),()=>{e.classList.remove(...n.enterFromClass),e.classList.add(...n.enterActiveClass,...n.enterToClass);Ve(e,"transitionend",(()=>{e.classList.remove(...n.enterActiveClass,...n.enterToClass)}),r,"enter")}}function Ge(e,n,t,r){return e.classList.remove(...n.enterActiveClass,...n.enterToClass),e.classList.add(...n.leaveFromClass),()=>{e.classList.remove(...n.leaveFromClass),e.classList.add(...n.leaveActiveClass,...n.leaveToClass);Ve(e,"transitionend",(()=>{Ke(e),t()}),r,"leave")}}function He(e,n,t,r){t||(ze(e),e.classList.remove(...n.leaveActiveClass)),e.classList.add(...n.enterActiveClass);Ve(e,"animationend",(()=>{e.classList.remove(...n.enterActiveClass)}),r,"enter")}function Je(e,n,t,r){e.classList.remove(...n.enterActiveClass),e.classList.add(...n.leaveActiveClass);Ve(e,"animationend",(()=>{e.classList.remove(...n.leaveActiveClass),Ke(e),t()}),r,"leave")}function Qe(e,n,t){t||ze(e),n(e)}export{ve as Action,ie as Async,ue as AsyncView,K as Await,oe as AwaitList,_ as AwaitReducer,V as AwaitState,H as AwaitStateView,ce as AwaitView,J as AwaitWatch,U as AwaitWatchArray,Q as AwaitWatchObject,Y as AwaitWatchView,Ce as For,xe as Gen,Se as Host,ye as If,ke as KeepAlive,ge as Memo,Le as Next,Ee as Show,we as Slotted,je as Tmpl,Me as Transition,De as TransitionGroup,Ae as Yield,he as defineAsyncComponent,A as isPending,I as isReject,L as isResolve,Oe as useActivated,pe as useAsyncValue,T as useAwait,$ as useAwaitReducer,O as useAwaitState,q as useAwaitWatch,B as useAwaitWatchArray,N as useAwaitWatchObject,$e as useKeepAliveMeta};