import{Component as t,createElement as i}from"react";import{__extends as n,__rest as o,__read as e,__assign as r}from"../../../../../node_modules/tslib/tslib.es6.js";import{usePresence as a}from"../../../components/AnimatePresence/use-presence.js";import{VisibilityAction as s}from"../../../components/AnimateSharedLayout/types.js";import{axisBox as m}from"../../../utils/geometry/index.js";import{eachAxis as u}from"../../../utils/each-axis.js";import{startAnimation as l}from"../../../animation/utils/transitions.js";import{tweenAxis as p}from"./utils.js";var c=function(t){function i(){var i=null!==t&&t.apply(this,arguments)||this;return i.frameTarget=m(),i.currentAnimationTarget=m(),i.isAnimating={x:!1,y:!1},i.stopAxisAnimation={x:void 0,y:void 0},i.isAnimatingTree=!1,i.animate=function(t,n,e){void 0===e&&(e={});var r=e.originBox,a=e.targetBox,m=e.visibilityAction,l=e.shouldStackAnimate,p=e.onComplete,c=o(e,["originBox","targetBox","visibilityAction","shouldStackAnimate","onComplete"]),f=i.props,y=f.visualElement,A=f.layout;if(!1===l)return i.isAnimatingTree=!1,i.safeToRemove();if(!i.isAnimatingTree||!0===l){l&&(i.isAnimatingTree=!0);var d=v(n=r||n,t=a||t),h=u((function(o){if("position"===A){var e=t[o].max-t[o].min;n[o].max=n[o].min+e}if(!y.projection.isTargetLocked)return void 0===m?d?i.animateAxis(o,t[o],n[o],c):y.setProjectionTargetAxis(o,t[o].min,t[o].max):void y.setVisibility(m===s.Show)}));return y.syncRender(),Promise.all(h).then((function(){i.isAnimatingTree=!1,p&&p(),y.notifyLayoutAnimationComplete()}))}},i}return n(i,t),i.prototype.componentDidMount=function(){var t=this,i=this.props.visualElement;i.animateMotionValue=l,i.enableLayoutProjection(),this.unsubLayoutReady=i.onLayoutUpdate(this.animate),i.layoutSafeToRemove=function(){return t.safeToRemove()}},i.prototype.componentWillUnmount=function(){var t=this;this.unsubLayoutReady(),u((function(i){var n,o;return null===(o=(n=t.stopAxisAnimation)[i])||void 0===o?void 0:o.call(n)}))},i.prototype.animateAxis=function(t,i,n,o){var e,r,a=this,s=(void 0===o?{}:o).transition;if(!this.isAnimating[t]||!d(i,this.currentAnimationTarget[t])){null===(r=(e=this.stopAxisAnimation)[t])||void 0===r||r.call(e),this.isAnimating[t]=!0;var m=this.props.visualElement,u=this.frameTarget[t],c=m.getProjectionAnimationProgress()[t];c.clearListeners(),c.set(0),c.set(0);var f=function(){var o=c.get()/1e3;p(u,n,i,o),m.setProjectionTargetAxis(t,u.min,u.max)};f(),m.updateLayoutProjection();var v=c.onChange(f);return this.stopAxisAnimation[t]=function(){a.isAnimating[t]=!1,c.stop(),v()},this.currentAnimationTarget[t]=i,l("x"===t?"layoutX":"layoutY",c,1e3,s||this.props.transition||h).then(this.stopAxisAnimation[t])}},i.prototype.safeToRemove=function(){var t,i;null===(i=(t=this.props).safeToRemove)||void 0===i||i.call(t)},i.prototype.render=function(){return null},i}(t);function f(t){var n=e(a(),2)[1];return i(c,r({},t,{safeToRemove:n}))}function v(t,i){return!(A(t)||A(i)||d(t.x,i.x)&&d(t.y,i.y))}var y={min:0,max:0};function A(t){return d(t.x,y)&&d(t.y,y)}function d(t,i){return t.min===i.min&&t.max===i.max}var h={duration:.45,ease:[.4,0,.1,1]},x={key:"animate-layout",shouldRender:function(t){return!!t.layout||void 0!==t.layoutId},getComponent:function(){return f}};export{x as AnimateLayout};
//# sourceMappingURL=Animate.js.map
