import { __spreadArray as I, __read as q, __assign as L } from "../../../../../tslib/tslib.es6.es.js";
import O, { cancelSync as X, flushSync as z } from "../../../../../framesync/dist/es/index.es.js";
import { animate as dt } from "../../animation/animate.es.js";
import { SubscriptionManager as ct } from "../../utils/subscription-manager.es.js";
import { mixValues as pt } from "../animation/mix-values.es.js";
import { copyBoxInto as P } from "../geometry/copy.es.js";
import { translateAxis as D, transformBox as b, applyBoxDelta as ft, applyTreeDeltas as vt } from "../geometry/delta-apply.es.js";
import { calcRelativePosition as k, calcRelativeBox as mt, calcBoxDelta as F, calcLength as Y } from "../geometry/delta-calc.es.js";
import { removeBoxTransforms as Z } from "../geometry/delta-remove.es.js";
import { createBox as T, createDelta as U } from "../geometry/models.es.js";
import { getValueTransition as gt } from "../../animation/utils/transitions.es.js";
import { boxEquals as st, isDeltaZero as nt } from "../geometry/utils.es.js";
import { NodeStack as yt } from "../shared/stack.es.js";
import { scaleCorrectors as J } from "../styles/scale-correction.es.js";
import { buildProjectionTransform as K } from "../styles/transform.es.js";
import { eachAxis as Q } from "../utils/each-axis.es.js";
import { hasTransform as R, hasScale as Tt } from "../utils/has-transform.es.js";
import { transformAxes as $ } from "../../render/html/utils/transform.es.js";
import { FlatTree as St } from "../../render/utils/flat-tree.es.js";
import { resolveMotionValue as W } from "../../value/utils/resolve-motion-value.es.js";
import { globalProjectionState as H } from "./state.es.js";
import { mix as w } from "../../../../../popmotion/dist/es/utils/mix.es.js";
var tt = 1e3;
function ie(r) {
  var h = r.attachResizeListener, d = r.defaultParent, g = r.measureScroll, V = r.checkIsScrollRoot, f = r.resetTransform;
  return function() {
    function s(t, i, e) {
      var a = this;
      i === void 0 && (i = {}), e === void 0 && (e = d == null ? void 0 : d()), this.children = /* @__PURE__ */ new Set(), this.options = {}, this.isTreeAnimating = !1, this.isAnimationBlocked = !1, this.isLayoutDirty = !1, this.updateManuallyBlocked = !1, this.updateBlockedByResize = !1, this.isUpdating = !1, this.isSVG = !1, this.needsReset = !1, this.shouldResetTransform = !1, this.treeScale = { x: 1, y: 1 }, this.eventHandlers = /* @__PURE__ */ new Map(), this.potentialNodes = /* @__PURE__ */ new Map(), this.checkUpdateFailed = function() {
        a.isUpdating && (a.isUpdating = !1, a.clearAllSnapshots());
      }, this.updateProjection = function() {
        a.nodes.forEach(Rt), a.nodes.forEach(Et);
      }, this.hasProjected = !1, this.isVisible = !0, this.animationProgress = 0, this.sharedNodes = /* @__PURE__ */ new Map(), this.id = t, this.latestValues = i, this.root = e ? e.root || e : this, this.path = e ? I(I([], q(e.path), !1), [e], !1) : [], this.parent = e, this.depth = e ? e.depth + 1 : 0, t && this.root.registerPotentialNode(t, this);
      for (var o = 0; o < this.path.length; o++)
        this.path[o].shouldResetTransform = !0;
      this.root === this && (this.nodes = new St());
    }
    return s.prototype.addEventListener = function(t, i) {
      return this.eventHandlers.has(t) || this.eventHandlers.set(t, new ct()), this.eventHandlers.get(t).add(i);
    }, s.prototype.notifyListeners = function(t) {
      for (var i = [], e = 1; e < arguments.length; e++)
        i[e - 1] = arguments[e];
      var a = this.eventHandlers.get(t);
      a == null || a.notify.apply(a, I([], q(i), !1));
    }, s.prototype.hasListeners = function(t) {
      return this.eventHandlers.has(t);
    }, s.prototype.registerPotentialNode = function(t, i) {
      this.potentialNodes.set(t, i);
    }, s.prototype.mount = function(t, i) {
      var e = this, a;
      if (i === void 0 && (i = !1), !this.instance) {
        this.isSVG = t instanceof SVGElement && t.tagName !== "svg", this.instance = t;
        var o = this.options, n = o.layoutId, c = o.layout, l = o.visualElement;
        if (l && !l.getInstance() && l.mount(t), this.root.nodes.add(this), (a = this.parent) === null || a === void 0 || a.children.add(this), this.id && this.root.potentialNodes.delete(this.id), i && (c || n) && (this.isLayoutDirty = !0), h) {
          var v, p = function() {
            return e.root.updateBlockedByResize = !1;
          };
          h(t, function() {
            e.root.updateBlockedByResize = !0, clearTimeout(v), v = window.setTimeout(p, 250), H.hasAnimatedSinceResize && (H.hasAnimatedSinceResize = !1, e.nodes.forEach(Vt));
          });
        }
        n && this.root.registerSharedNode(n, this), this.options.animate !== !1 && l && (n || c) && this.addEventListener("didUpdate", function(y) {
          var u, m, S, A, x, C = y.delta, _ = y.hasLayoutChanged, E = y.hasRelativeTargetChanged, B = y.layout;
          if (e.isTreeAnimationBlocked()) {
            e.target = void 0, e.relativeTarget = void 0;
            return;
          }
          var M = (m = (u = e.options.transition) !== null && u !== void 0 ? u : l.getDefaultTransition()) !== null && m !== void 0 ? m : kt, j = l.getProps(), lt = j.onLayoutAnimationStart, ht = j.onLayoutAnimationComplete, ut = !e.targetLayout || !st(e.targetLayout, B) || E, G = !_ && E;
          if (((S = e.resumeFrom) === null || S === void 0 ? void 0 : S.instance) || G || _ && (ut || !e.currentAnimation)) {
            e.resumeFrom && (e.resumingFrom = e.resumeFrom, e.resumingFrom.resumingFrom = void 0), e.setAnimationOrigin(C, G);
            var N = L(L({}, gt(M, "layout")), { onPlay: lt, onComplete: ht });
            l.shouldReduceMotion && (N.delay = 0, N.type = !1), e.startAnimation(N);
          } else
            !_ && e.animationProgress === 0 && e.finishAnimation(), e.isLead() && ((x = (A = e.options).onExitComplete) === null || x === void 0 || x.call(A));
          e.targetLayout = B;
        });
      }
    }, s.prototype.unmount = function() {
      var t, i;
      this.options.layoutId && this.willUpdate(), this.root.nodes.remove(this), (t = this.getStack()) === null || t === void 0 || t.remove(this), (i = this.parent) === null || i === void 0 || i.children.delete(this), this.instance = void 0, X.preRender(this.updateProjection);
    }, s.prototype.blockUpdate = function() {
      this.updateManuallyBlocked = !0;
    }, s.prototype.unblockUpdate = function() {
      this.updateManuallyBlocked = !1;
    }, s.prototype.isUpdateBlocked = function() {
      return this.updateManuallyBlocked || this.updateBlockedByResize;
    }, s.prototype.isTreeAnimationBlocked = function() {
      var t;
      return this.isAnimationBlocked || ((t = this.parent) === null || t === void 0 ? void 0 : t.isTreeAnimationBlocked()) || !1;
    }, s.prototype.startUpdate = function() {
      var t;
      this.isUpdateBlocked() || (this.isUpdating = !0, (t = this.nodes) === null || t === void 0 || t.forEach(jt));
    }, s.prototype.willUpdate = function(t) {
      var i, e, a;
      if (t === void 0 && (t = !0), this.root.isUpdateBlocked()) {
        (e = (i = this.options).onExitComplete) === null || e === void 0 || e.call(i);
        return;
      }
      if (!this.root.isUpdating && this.root.startUpdate(), !this.isLayoutDirty) {
        this.isLayoutDirty = !0;
        for (var o = 0; o < this.path.length; o++) {
          var n = this.path[o];
          n.shouldResetTransform = !0, n.updateScroll();
        }
        var c = this.options, l = c.layoutId, v = c.layout;
        if (!(l === void 0 && !v)) {
          var p = (a = this.options.visualElement) === null || a === void 0 ? void 0 : a.getProps().transformTemplate;
          this.prevTransformTemplateValue = p == null ? void 0 : p(this.latestValues, ""), this.updateSnapshot(), t && this.notifyListeners("willUpdate");
        }
      }
    }, s.prototype.didUpdate = function() {
      var t = this.isUpdateBlocked();
      if (t) {
        this.unblockUpdate(), this.clearAllSnapshots(), this.nodes.forEach(et);
        return;
      }
      !this.isUpdating || (this.isUpdating = !1, this.potentialNodes.size && (this.potentialNodes.forEach(Ft), this.potentialNodes.clear()), this.nodes.forEach(Lt), this.nodes.forEach(Pt), this.nodes.forEach(At), this.clearAllSnapshots(), z.update(), z.preRender(), z.render());
    }, s.prototype.clearAllSnapshots = function() {
      this.nodes.forEach(xt), this.sharedNodes.forEach(Dt);
    }, s.prototype.scheduleUpdateProjection = function() {
      O.preRender(this.updateProjection, !1, !0);
    }, s.prototype.scheduleCheckAfterUnmount = function() {
      var t = this;
      O.postRender(function() {
        t.isLayoutDirty ? t.root.didUpdate() : t.root.checkUpdateFailed();
      });
    }, s.prototype.updateSnapshot = function() {
      if (!(this.snapshot || !this.instance)) {
        var t = this.measure(), i = this.removeTransform(this.removeElementScroll(t));
        ot(i), this.snapshot = {
          measured: t,
          layout: i,
          latestValues: {}
        };
      }
    }, s.prototype.updateLayout = function() {
      var t;
      if (!!this.instance && (this.updateScroll(), !(!(this.options.alwaysMeasureLayout && this.isLead()) && !this.isLayoutDirty))) {
        if (this.resumeFrom && !this.resumeFrom.instance)
          for (var i = 0; i < this.path.length; i++) {
            var e = this.path[i];
            e.updateScroll();
          }
        var a = this.measure();
        ot(a);
        var o = this.layout;
        this.layout = {
          measured: a,
          actual: this.removeElementScroll(a)
        }, this.layoutCorrected = T(), this.isLayoutDirty = !1, this.projectionDelta = void 0, this.notifyListeners("measure", this.layout.actual), (t = this.options.visualElement) === null || t === void 0 || t.notifyLayoutMeasure(this.layout.actual, o == null ? void 0 : o.actual);
      }
    }, s.prototype.updateScroll = function() {
      this.options.layoutScroll && this.instance && (this.isScrollRoot = V(this.instance), this.scroll = g(this.instance));
    }, s.prototype.resetTransform = function() {
      var t;
      if (!!f) {
        var i = this.isLayoutDirty || this.shouldResetTransform, e = this.projectionDelta && !nt(this.projectionDelta), a = (t = this.options.visualElement) === null || t === void 0 ? void 0 : t.getProps().transformTemplate, o = a == null ? void 0 : a(this.latestValues, ""), n = o !== this.prevTransformTemplateValue;
        i && (e || R(this.latestValues) || n) && (f(this.instance, o), this.shouldResetTransform = !1, this.scheduleRender());
      }
    }, s.prototype.measure = function() {
      var t = this.options.visualElement;
      if (!t)
        return T();
      var i = t.measureViewportBox(), e = this.root.scroll;
      return e && (D(i.x, e.x), D(i.y, e.y)), i;
    }, s.prototype.removeElementScroll = function(t) {
      var i = T();
      P(i, t);
      for (var e = 0; e < this.path.length; e++) {
        var a = this.path[e], o = a.scroll, n = a.options, c = a.isScrollRoot;
        if (a !== this.root && o && n.layoutScroll) {
          if (c) {
            P(i, t);
            var l = this.root.scroll;
            l && (D(i.x, -l.x), D(i.y, -l.y));
          }
          D(i.x, o.x), D(i.y, o.y);
        }
      }
      return i;
    }, s.prototype.applyTransform = function(t, i) {
      i === void 0 && (i = !1);
      var e = T();
      P(e, t);
      for (var a = 0; a < this.path.length; a++) {
        var o = this.path[a];
        !i && o.options.layoutScroll && o.scroll && o !== o.root && b(e, {
          x: -o.scroll.x,
          y: -o.scroll.y
        }), R(o.latestValues) && b(e, o.latestValues);
      }
      return R(this.latestValues) && b(e, this.latestValues), e;
    }, s.prototype.removeTransform = function(t) {
      var i, e = T();
      P(e, t);
      for (var a = 0; a < this.path.length; a++) {
        var o = this.path[a];
        if (!!o.instance && !!R(o.latestValues)) {
          Tt(o.latestValues) && o.updateSnapshot();
          var n = T(), c = o.measure();
          P(n, c), Z(e, o.latestValues, (i = o.snapshot) === null || i === void 0 ? void 0 : i.layout, n);
        }
      }
      return R(this.latestValues) && Z(e, this.latestValues), e;
    }, s.prototype.setTargetDelta = function(t) {
      this.targetDelta = t, this.root.scheduleUpdateProjection();
    }, s.prototype.setOptions = function(t) {
      var i;
      this.options = L(L(L({}, this.options), t), { crossfade: (i = t.crossfade) !== null && i !== void 0 ? i : !0 });
    }, s.prototype.clearMeasurements = function() {
      this.scroll = void 0, this.layout = void 0, this.snapshot = void 0, this.prevTransformTemplateValue = void 0, this.targetDelta = void 0, this.target = void 0, this.isLayoutDirty = !1;
    }, s.prototype.resolveTargetDelta = function() {
      var t, i = this.options, e = i.layout, a = i.layoutId;
      !this.layout || !(e || a) || (!this.targetDelta && !this.relativeTarget && (this.relativeParent = this.getClosestProjectingParent(), this.relativeParent && this.relativeParent.layout && (this.relativeTarget = T(), this.relativeTargetOrigin = T(), k(this.relativeTargetOrigin, this.layout.actual, this.relativeParent.layout.actual), P(this.relativeTarget, this.relativeTargetOrigin))), !(!this.relativeTarget && !this.targetDelta) && (this.target || (this.target = T(), this.targetWithTransforms = T()), this.relativeTarget && this.relativeTargetOrigin && ((t = this.relativeParent) === null || t === void 0 ? void 0 : t.target) ? mt(this.target, this.relativeTarget, this.relativeParent.target) : this.targetDelta ? (Boolean(this.resumingFrom) ? this.target = this.applyTransform(this.layout.actual) : P(this.target, this.layout.actual), ft(this.target, this.targetDelta)) : P(this.target, this.layout.actual), this.attemptToResolveRelativeTarget && (this.attemptToResolveRelativeTarget = !1, this.relativeParent = this.getClosestProjectingParent(), this.relativeParent && Boolean(this.relativeParent.resumingFrom) === Boolean(this.resumingFrom) && !this.relativeParent.options.layoutScroll && this.relativeParent.target && (this.relativeTarget = T(), this.relativeTargetOrigin = T(), k(this.relativeTargetOrigin, this.target, this.relativeParent.target), P(this.relativeTarget, this.relativeTargetOrigin)))));
    }, s.prototype.getClosestProjectingParent = function() {
      if (!(!this.parent || R(this.parent.latestValues)))
        return (this.parent.relativeTarget || this.parent.targetDelta) && this.parent.layout ? this.parent : this.parent.getClosestProjectingParent();
    }, s.prototype.calcProjection = function() {
      var t, i = this.options, e = i.layout, a = i.layoutId;
      if (this.isTreeAnimating = Boolean(((t = this.parent) === null || t === void 0 ? void 0 : t.isTreeAnimating) || this.currentAnimation || this.pendingAnimation), this.isTreeAnimating || (this.targetDelta = this.relativeTarget = void 0), !(!this.layout || !(e || a))) {
        var o = this.getLead();
        P(this.layoutCorrected, this.layout.actual), vt(this.layoutCorrected, this.treeScale, this.path, Boolean(this.resumingFrom) || this !== o);
        var n = o.target;
        if (!!n) {
          this.projectionDelta || (this.projectionDelta = U(), this.projectionDeltaWithTransform = U());
          var c = this.treeScale.x, l = this.treeScale.y, v = this.projectionTransform;
          F(this.projectionDelta, this.layoutCorrected, n, this.latestValues), this.projectionTransform = K(this.projectionDelta, this.treeScale), (this.projectionTransform !== v || this.treeScale.x !== c || this.treeScale.y !== l) && (this.hasProjected = !0, this.scheduleRender(), this.notifyListeners("projectionUpdate", n));
        }
      }
    }, s.prototype.hide = function() {
      this.isVisible = !1;
    }, s.prototype.show = function() {
      this.isVisible = !0;
    }, s.prototype.scheduleRender = function(t) {
      var i, e, a;
      t === void 0 && (t = !0), (e = (i = this.options).scheduleRender) === null || e === void 0 || e.call(i), t && ((a = this.getStack()) === null || a === void 0 || a.scheduleRender()), this.resumingFrom && !this.resumingFrom.instance && (this.resumingFrom = void 0);
    }, s.prototype.setAnimationOrigin = function(t, i) {
      var e = this, a;
      i === void 0 && (i = !1);
      var o = this.snapshot, n = (o == null ? void 0 : o.latestValues) || {}, c = L({}, this.latestValues), l = U();
      this.relativeTarget = this.relativeTargetOrigin = void 0, this.attemptToResolveRelativeTarget = !i;
      var v = T(), p = o == null ? void 0 : o.isShared, y = (((a = this.getStack()) === null || a === void 0 ? void 0 : a.members.length) || 0) <= 1, u = Boolean(p && !y && this.options.crossfade === !0 && !this.path.some(Bt));
      this.animationProgress = 0, this.mixTargetDelta = function(m) {
        var S, A = m / 1e3;
        it(l.x, t.x, A), it(l.y, t.y, A), e.setTargetDelta(l), e.relativeTarget && e.relativeTargetOrigin && e.layout && ((S = e.relativeParent) === null || S === void 0 ? void 0 : S.layout) && (k(v, e.layout.actual, e.relativeParent.layout.actual), _t(e.relativeTarget, e.relativeTargetOrigin, v, A)), p && (e.animationValues = c, pt(c, n, e.latestValues, A, u, y)), e.root.scheduleUpdateProjection(), e.scheduleRender(), e.animationProgress = A;
      }, this.mixTargetDelta(0);
    }, s.prototype.startAnimation = function(t) {
      var i = this, e, a;
      this.notifyListeners("animationStart"), (e = this.currentAnimation) === null || e === void 0 || e.stop(), this.resumingFrom && ((a = this.resumingFrom.currentAnimation) === null || a === void 0 || a.stop()), this.pendingAnimation && (X.update(this.pendingAnimation), this.pendingAnimation = void 0), this.pendingAnimation = O.update(function() {
        H.hasAnimatedSinceResize = !0, i.currentAnimation = dt(0, tt, L(L({}, t), { onUpdate: function(o) {
          var n;
          i.mixTargetDelta(o), (n = t.onUpdate) === null || n === void 0 || n.call(t, o);
        }, onComplete: function() {
          var o;
          (o = t.onComplete) === null || o === void 0 || o.call(t), i.completeAnimation();
        } })), i.resumingFrom && (i.resumingFrom.currentAnimation = i.currentAnimation), i.pendingAnimation = void 0;
      });
    }, s.prototype.completeAnimation = function() {
      var t;
      this.resumingFrom && (this.resumingFrom.currentAnimation = void 0, this.resumingFrom.preserveOpacity = void 0), (t = this.getStack()) === null || t === void 0 || t.exitAnimationComplete(), this.resumingFrom = this.currentAnimation = this.animationValues = void 0, this.notifyListeners("animationComplete");
    }, s.prototype.finishAnimation = function() {
      var t;
      this.currentAnimation && ((t = this.mixTargetDelta) === null || t === void 0 || t.call(this, tt), this.currentAnimation.stop()), this.completeAnimation();
    }, s.prototype.applyTransformsToTarget = function() {
      var t = this.getLead(), i = t.targetWithTransforms, e = t.target, a = t.layout, o = t.latestValues;
      !i || !e || !a || (P(i, e), b(i, o), F(this.projectionDeltaWithTransform, this.layoutCorrected, i, o));
    }, s.prototype.registerSharedNode = function(t, i) {
      var e, a, o;
      this.sharedNodes.has(t) || this.sharedNodes.set(t, new yt());
      var n = this.sharedNodes.get(t);
      n.add(i), i.promote({
        transition: (e = i.options.initialPromotionConfig) === null || e === void 0 ? void 0 : e.transition,
        preserveFollowOpacity: (o = (a = i.options.initialPromotionConfig) === null || a === void 0 ? void 0 : a.shouldPreserveFollowOpacity) === null || o === void 0 ? void 0 : o.call(a, i)
      });
    }, s.prototype.isLead = function() {
      var t = this.getStack();
      return t ? t.lead === this : !0;
    }, s.prototype.getLead = function() {
      var t, i = this.options.layoutId;
      return i ? ((t = this.getStack()) === null || t === void 0 ? void 0 : t.lead) || this : this;
    }, s.prototype.getPrevLead = function() {
      var t, i = this.options.layoutId;
      return i ? (t = this.getStack()) === null || t === void 0 ? void 0 : t.prevLead : void 0;
    }, s.prototype.getStack = function() {
      var t = this.options.layoutId;
      if (t)
        return this.root.sharedNodes.get(t);
    }, s.prototype.promote = function(t) {
      var i = t === void 0 ? {} : t, e = i.needsReset, a = i.transition, o = i.preserveFollowOpacity, n = this.getStack();
      n && n.promote(this, o), e && (this.projectionDelta = void 0, this.needsReset = !0), a && this.setOptions({ transition: a });
    }, s.prototype.relegate = function() {
      var t = this.getStack();
      return t ? t.relegate(this) : !1;
    }, s.prototype.resetRotation = function() {
      var t = this.options.visualElement;
      if (!!t) {
        for (var i = !1, e = {}, a = 0; a < $.length; a++) {
          var o = $[a], n = "rotate" + o;
          !t.getStaticValue(n) || (i = !0, e[n] = t.getStaticValue(n), t.setStaticValue(n, 0));
        }
        if (!!i) {
          t == null || t.syncRender();
          for (var n in e)
            t.setStaticValue(n, e[n]);
          t.scheduleRender();
        }
      }
    }, s.prototype.getProjectionStyles = function(t) {
      var i, e, a, o, n, c;
      t === void 0 && (t = {});
      var l = {};
      if (!this.instance || this.isSVG)
        return l;
      if (this.isVisible)
        l.visibility = "";
      else
        return { visibility: "hidden" };
      var v = (i = this.options.visualElement) === null || i === void 0 ? void 0 : i.getProps().transformTemplate;
      if (this.needsReset)
        return this.needsReset = !1, l.opacity = "", l.pointerEvents = W(t.pointerEvents) || "", l.transform = v ? v(this.latestValues, "") : "none", l;
      var p = this.getLead();
      if (!this.projectionDelta || !this.layout || !p.target) {
        var y = {};
        return this.options.layoutId && (y.opacity = (e = this.latestValues.opacity) !== null && e !== void 0 ? e : 1, y.pointerEvents = W(t.pointerEvents) || ""), this.hasProjected && !R(this.latestValues) && (y.transform = v ? v({}, "") : "none", this.hasProjected = !1), y;
      }
      var u = p.animationValues || p.latestValues;
      this.applyTransformsToTarget(), l.transform = K(this.projectionDeltaWithTransform, this.treeScale, u), v && (l.transform = v(u, l.transform));
      var m = this.projectionDelta, S = m.x, A = m.y;
      l.transformOrigin = "".concat(S.origin * 100, "% ").concat(A.origin * 100, "% 0"), p.animationValues ? l.opacity = p === this ? (o = (a = u.opacity) !== null && a !== void 0 ? a : this.latestValues.opacity) !== null && o !== void 0 ? o : 1 : this.preserveOpacity ? this.latestValues.opacity : u.opacityExit : l.opacity = p === this ? (n = u.opacity) !== null && n !== void 0 ? n : "" : (c = u.opacityExit) !== null && c !== void 0 ? c : 0;
      for (var x in J)
        if (u[x] !== void 0) {
          var C = J[x], _ = C.correct, E = C.applyTo, B = _(u[x], p);
          if (E)
            for (var M = E.length, j = 0; j < M; j++)
              l[E[j]] = B;
          else
            l[x] = B;
        }
      return this.options.layoutId && (l.pointerEvents = p === this ? W(t.pointerEvents) || "" : "none"), l;
    }, s.prototype.clearSnapshot = function() {
      this.resumeFrom = this.snapshot = void 0;
    }, s.prototype.resetTree = function() {
      this.root.nodes.forEach(function(t) {
        var i;
        return (i = t.currentAnimation) === null || i === void 0 ? void 0 : i.stop();
      }), this.root.nodes.forEach(et), this.root.sharedNodes.clear();
    }, s;
  }();
}
function Pt(r) {
  r.updateLayout();
}
function At(r) {
  var h, d, g, V, f = (d = (h = r.resumeFrom) === null || h === void 0 ? void 0 : h.snapshot) !== null && d !== void 0 ? d : r.snapshot;
  if (r.isLead() && r.layout && f && r.hasListeners("didUpdate")) {
    var s = r.layout, t = s.actual, i = s.measured;
    r.options.animationType === "size" ? Q(function(u) {
      var m = f.isShared ? f.measured[u] : f.layout[u], S = Y(m);
      m.min = t[u].min, m.max = m.min + S;
    }) : r.options.animationType === "position" && Q(function(u) {
      var m = f.isShared ? f.measured[u] : f.layout[u], S = Y(t[u]);
      m.max = m.min + S;
    });
    var e = U();
    F(e, t, f.layout);
    var a = U();
    f.isShared ? F(a, r.applyTransform(i, !0), f.measured) : F(a, t, f.layout);
    var o = !nt(e), n = !1;
    if (!r.resumeFrom && (r.relativeParent = r.getClosestProjectingParent(), r.relativeParent && !r.relativeParent.resumeFrom)) {
      var c = r.relativeParent, l = c.snapshot, v = c.layout;
      if (l && v) {
        var p = T();
        k(p, f.layout, l.layout);
        var y = T();
        k(y, t, v.actual), st(p, y) || (n = !0);
      }
    }
    r.notifyListeners("didUpdate", {
      layout: t,
      snapshot: f,
      delta: a,
      layoutDelta: e,
      hasLayoutChanged: o,
      hasRelativeTargetChanged: n
    });
  } else
    r.isLead() && ((V = (g = r.options).onExitComplete) === null || V === void 0 || V.call(g));
  r.options.transition = void 0;
}
function xt(r) {
  r.clearSnapshot();
}
function et(r) {
  r.clearMeasurements();
}
function Lt(r) {
  var h = r.options.visualElement;
  h != null && h.getProps().onBeforeLayoutMeasure && h.notifyBeforeLayoutMeasure(), r.resetTransform();
}
function Vt(r) {
  r.finishAnimation(), r.targetDelta = r.relativeTarget = r.target = void 0;
}
function Rt(r) {
  r.resolveTargetDelta();
}
function Et(r) {
  r.calcProjection();
}
function jt(r) {
  r.resetRotation();
}
function Dt(r) {
  r.removeLeadSnapshot();
}
function it(r, h, d) {
  r.translate = w(h.translate, 0, d), r.scale = w(h.scale, 1, d), r.origin = h.origin, r.originPoint = h.originPoint;
}
function at(r, h, d, g) {
  r.min = w(h.min, d.min, g), r.max = w(h.max, d.max, g);
}
function _t(r, h, d, g) {
  at(r.x, h.x, d.x, g), at(r.y, h.y, d.y, g);
}
function Bt(r) {
  return r.animationValues && r.animationValues.opacityExit !== void 0;
}
var kt = {
  duration: 0.45,
  ease: [0.4, 0, 0.1, 1]
};
function Ft(r, h) {
  for (var d = r.root, g = r.path.length - 1; g >= 0; g--)
    if (Boolean(r.path[g].instance)) {
      d = r.path[g];
      break;
    }
  var V = d && d !== r.root ? d.instance : document, f = V.querySelector('[data-projection-id="'.concat(h, '"]'));
  f && r.mount(f, !0);
}
function rt(r) {
  r.min = Math.round(r.min), r.max = Math.round(r.max);
}
function ot(r) {
  rt(r.x), rt(r.y);
}
export {
  ie as createProjectionNode,
  at as mixAxis,
  it as mixAxisDelta,
  _t as mixBox
};
//# sourceMappingURL=create-projection-node.es.js.map
