import{__read as n,__rest as i,__assign as r}from"../../../../node_modules/tslib/tslib.es6.js";import{resolveVariant as t}from"./variants.js";import{startAnimation as o}from"../../animation/utils/transitions.js";import{setTarget as e}from"./setters.js";function a(n,i,r){var o;if(void 0===r&&(r={}),n.notifyAnimationStart(),Array.isArray(i)){var e=i.map((function(i){return s(n,i,r)}));o=Promise.all(e)}else if("string"==typeof i)o=s(n,i,r);else{var a="function"==typeof i?t(n,i,r.custom):i;o=u(n,a,r)}return o.then((function(){return n.notifyAnimationComplete(i)}))}function s(i,o,e){var a;void 0===e&&(e={});var d=t(i,o,e.custom),f=(d||{}).transition,l=void 0===f?i.getDefaultTransition()||{}:f;e.transitionOverride&&(l=e.transitionOverride);var m=d?function(){return u(i,d,e)}:function(){return Promise.resolve()},c=(null===(a=i.variantChildren)||void 0===a?void 0:a.size)?function(n){void 0===n&&(n=0);var t=l.delayChildren,a=void 0===t?0:t,u=l.staggerChildren,d=l.staggerDirection;return function(n,i,t,o,e,a){void 0===t&&(t=0);void 0===o&&(o=0);void 0===e&&(e=1);var u=[],d=(n.variantChildren.size-1)*o,f=1===e?function(n){return void 0===n&&(n=0),n*o}:function(n){return void 0===n&&(n=0),d-n*o};return Array.from(n.variantChildren).sort(v).forEach((function(n,o){u.push(s(n,i,r(r({},a),{delay:t+f(o)})).then((function(){return n.notifyAnimationComplete(i)})))})),Promise.all(u)}(i,o,a+n,u,d,e)}:function(){return Promise.resolve()},y=l.when;if(y){var h=n("beforeChildren"===y?[m,c]:[c,m],2),p=h[0],g=h[1];return p().then(g)}return Promise.all([m(),c(e.delay)])}function u(n,t,a){var s,u=void 0===a?{}:a,v=u.delay,f=void 0===v?0:v,l=u.transitionOverride,m=u.type,c=n.makeTargetAnimatable(t),y=c.transition,h=void 0===y?n.getDefaultTransition():y,p=c.transitionEnd,g=i(c,["transition","transitionEnd"]);l&&(h=l);var A=[],C=m&&(null===(s=n.animationState)||void 0===s?void 0:s.getState()[m]);for(var P in g){var b=n.getValue(P),j=g[P];if(!(!b||void 0===j||C&&d(C,P))){var O=o(P,b,j,r({delay:f},h));A.push(O)}}return Promise.all(A).then((function(){p&&e(n,p)}))}function v(n,i){return n.sortNodePosition(i)}function d(n,i){var r=n.protectedKeys,t=n.needsAnimating,o=r.hasOwnProperty(i)&&!0!==t[i];return t[i]=!1,o}export{a as animateVisualElement,v as sortByTreeOrder};
//# sourceMappingURL=animation.js.map
