import{__spread as t,__assign as n,__rest as i}from"../../../../node_modules/tslib/tslib.es6.js";import{isVariantLabels as e,resolveVariant as r,isVariantLabel as o}from"./variants.js";import{isKeyframesTarget as a}from"../../animation/utils/is-keyframes-target.js";import{AnimationType as s}from"./types.js";import{animateVisualElement as u}from"./animation.js";import{isAnimationControls as v}from"../../animation/animation-controls.js";import{shallowCompare as l}from"../../utils/shallow-compare.js";var m=[s.Animate,s.Hover,s.Tap,s.Drag,s.Focus,s.Exit],c=t(m).reverse(),p=m.length;function f(e){var m,f=function(t){return function(n){return Promise.all(n.map((function(n){var i=n.animation,e=n.options;return u(t,i,e)})))}}(e),y=((m={})[s.Animate]=A(!0),m[s.Hover]=A(),m[s.Tap]=A(),m[s.Drag]=A(),m[s.Focus]=A(),m[s.Exit]=A(),m),g={},h=!0,P=function(t,o){var a=r(e,o);if(a){a.transition;var s=a.transitionEnd,u=i(a,["transition","transitionEnd"]);t=n(n(n({},t),u),s)}return t};function j(i,r){for(var s=e.getProps(),u=e.getVariantContext(!0)||{},m=[],A=new Set,j={},E=1/0,b=function(p){var f=c[p],g=y[f],b=null!==(O=s[f])&&void 0!==O?O:u[f],x=o(b),K=f===r?g.isActive:null;!1===K&&(E=p);var V=b===u[f]&&b!==s[f]&&x;if(V&&h&&e.manuallyAnimateOnMount&&(V=!1),g.protectedKeys=n({},j),!g.isActive&&null===K||!b&&!g.prevProp||v(b)||"boolean"==typeof b)return"continue";var w=d(g.prevProp,b)||f===r&&g.isActive&&!V&&x||p>E&&x,C=Array.isArray(b)?b:[b],F=C.reduce(P,{});!1===K&&(F={});var O=g.prevResolvedValues,R=void 0===O?{}:O,S=n(n({},R),F),T=function(t){w=!0,A.delete(t),g.needsAnimating[t]=!0};for(var k in S){var B=F[k],D=R[k];j.hasOwnProperty(k)||(B!==D?a(B)&&a(D)?l(B,D)?g.protectedKeys[k]=!0:T(k):void 0!==B?T(k):A.add(k):void 0!==B&&A.has(k)?T(k):g.protectedKeys[k]=!0)}g.prevProp=b,g.prevResolvedValues=F,g.isActive&&(j=n(n({},j),F)),h&&e.blockInitialAnimation&&(w=!1),w&&!V&&m.push.apply(m,t(C.map((function(t){return{animation:t,options:n({type:f},i)}}))))},x=0;x<p;x++)b(x);if(g=n({},j),A.size){var K={};A.forEach((function(t){var n=e.getBaseTarget(t);void 0!==n&&(K[t]=n)})),m.push({animation:K})}var V=Boolean(m.length);return h&&!1===s.initial&&!e.manuallyAnimateOnMount&&(V=!1),h=!1,V?f(m):Promise.resolve()}return{isAnimated:function(t){return void 0!==g[t]},animateChanges:j,setActive:function(t,n,i){var r;return y[t].isActive===n?Promise.resolve():(null===(r=e.variantChildren)||void 0===r||r.forEach((function(i){var e;return null===(e=i.animationState)||void 0===e?void 0:e.setActive(t,n)})),y[t].isActive=n,j(i,t))},setAnimateFunction:function(t){f=t(e)},getState:function(){return y}}}function d(t,n){return"string"==typeof n?n!==t:!!e(n)&&!l(n,t)}function A(t){return void 0===t&&(t=!1),{isActive:t,protectedKeys:{},needsAnimating:{},prevResolvedValues:{}}}export{f as createAnimationState,m as variantPriorityOrder,d as variantsHaveChanged};
//# sourceMappingURL=animation-state.js.map
