import { animateSingleValue as at } from "../../animation/animate/single-value.es.js";
import { getOptimisedAppearId as rt } from "../../animation/optimized-appear/get-appear-id.es.js";
import { FlatTree as nt } from "../../render/utils/flat-tree.es.js";
import { delay as ht } from "../../utils/delay.es.js";
import { resolveMotionValue as C } from "../../value/utils/resolve-motion-value.es.js";
import { mixValues as lt } from "../animation/mix-values.es.js";
import { copyBoxInto as f, copyAxisDeltaInto as b } from "../geometry/copy.es.js";
import { translateAxis as E, transformBox as w, applyBoxDelta as ut, applyTreeDeltas as ct } from "../geometry/delta-apply.es.js";
import { calcLength as S, calcRelativePosition as k, calcRelativeBox as dt, calcBoxDelta as L, isNear as mt } from "../geometry/delta-calc.es.js";
import { removeBoxTransforms as W } from "../geometry/delta-remove.es.js";
import { createBox as d, createDelta as B } from "../geometry/models.es.js";
import { boxEqualsRounded as et, isDeltaZero as it, axisDeltaEquals as z, boxEquals as ft, aspectRatio as N } from "../geometry/utils.es.js";
import { NodeStack as pt } from "../shared/stack.es.js";
import { scaleCorrectors as H } from "../styles/scale-correction.es.js";
import { buildProjectionTransform as yt } from "../styles/transform.es.js";
import { eachAxis as G } from "../utils/each-axis.es.js";
import { hasTransform as P, hasScale as q, has2DTranslate as gt } from "../utils/has-transform.es.js";
import { globalProjectionState as O } from "./state.es.js";
import { SubscriptionManager as vt } from "../../../../../../../motion-utils@12.23.6/node_modules/motion-utils/dist/es/subscription-manager.es.js";
import { isSVGElement as Tt } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/utils/is-svg-element.es.js";
import { isSVGSVGElement as xt } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/utils/is-svg-svg-element.es.js";
import { frame as V, cancelFrame as X, frameSteps as F, frameData as y } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/frameloop/frame.es.js";
import { getValueTransition as Dt } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/animation/utils/get-value-transition.es.js";
import { time as Pt } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/frameloop/sync-time.es.js";
import { microtask as St } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/frameloop/microtask.es.js";
import { motionValue as Bt } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/value/index.es.js";
import { clamp as jt } from "../../../../../../../motion-utils@12.23.6/node_modules/motion-utils/dist/es/clamp.es.js";
import { mixNumber as U } from "../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/utils/mix/number.es.js";
import { noop as At } from "../../../../../../../motion-utils@12.23.6/node_modules/motion-utils/dist/es/noop.es.js";
const I = ["", "X", "Y", "Z"], Rt = 1e3;
let Vt = 0;
function M(e, n, c, u) {
  const { latestValues: v } = n;
  v[e] && (c[e] = v[e], n.setStaticValue(e, 0), u && (u[e] = 0));
}
function st(e) {
  if (e.hasCheckedOptimisedAppear = !0, e.root === e)
    return;
  const { visualElement: n } = e.options;
  if (!n)
    return;
  const c = rt(n);
  if (window.MotionHasOptimisedAnimation(c, "transform")) {
    const { layout: v, layoutId: j } = e.options;
    window.MotionCancelOptimisedAnimation(c, "transform", V, !(v || j));
  }
  const { parent: u } = e;
  u && !u.hasCheckedOptimisedAppear && st(u);
}
function xe({ attachResizeListener: e, defaultParent: n, measureScroll: c, checkIsScrollRoot: u, resetTransform: v }) {
  return class {
    constructor(t = {}, i = n == null ? void 0 : n()) {
      this.id = Vt++, this.animationId = 0, this.animationCommitId = 0, this.children = /* @__PURE__ */ new Set(), this.options = {}, this.isTreeAnimating = !1, this.isAnimationBlocked = !1, this.isLayoutDirty = !1, this.isProjectionDirty = !1, this.isSharedProjectionDirty = !1, this.isTransformDirty = !1, this.updateManuallyBlocked = !1, this.updateBlockedByResize = !1, this.isUpdating = !1, this.isSVG = !1, this.needsReset = !1, this.shouldResetTransform = !1, this.hasCheckedOptimisedAppear = !1, this.treeScale = { x: 1, y: 1 }, this.eventHandlers = /* @__PURE__ */ new Map(), this.hasTreeAnimated = !1, this.updateScheduled = !1, this.scheduleUpdate = () => this.update(), this.projectionUpdateScheduled = !1, this.checkUpdateFailed = () => {
        this.isUpdating && (this.isUpdating = !1, this.clearAllSnapshots());
      }, this.updateProjection = () => {
        this.projectionUpdateScheduled = !1, this.nodes.forEach(Et), this.nodes.forEach(Ot), this.nodes.forEach(Ft), this.nodes.forEach(wt);
      }, this.resolvedRelativeTargetAt = 0, this.hasProjected = !1, this.isVisible = !0, this.animationProgress = 0, this.sharedNodes = /* @__PURE__ */ new Map(), this.latestValues = t, this.root = i ? i.root || i : this, this.path = i ? [...i.path, i] : [], this.parent = i, this.depth = i ? i.depth + 1 : 0;
      for (let s = 0; s < this.path.length; s++)
        this.path[s].shouldResetTransform = !0;
      this.root === this && (this.nodes = new nt());
    }
    addEventListener(t, i) {
      return this.eventHandlers.has(t) || this.eventHandlers.set(t, new vt()), this.eventHandlers.get(t).add(i);
    }
    notifyListeners(t, ...i) {
      const s = this.eventHandlers.get(t);
      s && s.notify(...i);
    }
    hasListeners(t) {
      return this.eventHandlers.has(t);
    }
    /**
     * Lifecycles
     */
    mount(t) {
      if (this.instance)
        return;
      this.isSVG = Tt(t) && !xt(t), this.instance = t;
      const { layoutId: i, layout: s, visualElement: o } = this.options;
      if (o && !o.current && o.mount(t), this.root.nodes.add(this), this.parent && this.parent.children.add(this), this.root.hasTreeAnimated && (s || i) && (this.isLayoutDirty = !0), e) {
        let a, r = 0;
        const l = () => this.root.updateBlockedByResize = !1;
        V.read(() => {
          r = window.innerWidth;
        }), e(t, () => {
          const h = window.innerWidth;
          h !== r && (r = h, this.root.updateBlockedByResize = !0, a && a(), a = ht(l, 250), O.hasAnimatedSinceResize && (O.hasAnimatedSinceResize = !1, this.nodes.forEach(Z)));
        });
      }
      i && this.root.registerSharedNode(i, this), this.options.animate !== !1 && o && (i || s) && this.addEventListener("didUpdate", ({ delta: a, hasLayoutChanged: r, hasRelativeLayoutChanged: l, layout: h }) => {
        if (this.isTreeAnimationBlocked()) {
          this.target = void 0, this.relativeTarget = void 0;
          return;
        }
        const m = this.options.transition || o.getDefaultTransition() || zt, { onLayoutAnimationStart: g, onLayoutAnimationComplete: T } = o.getProps(), D = !this.targetLayout || !et(this.targetLayout, h), x = !r && l;
        if (this.options.layoutRoot || this.resumeFrom || x || r && (D || !this.currentAnimation)) {
          this.resumeFrom && (this.resumingFrom = this.resumeFrom, this.resumingFrom.resumingFrom = void 0);
          const p = {
            ...Dt(m, "layout"),
            onPlay: g,
            onComplete: T
          };
          (o.shouldReduceMotion || this.options.layoutRoot) && (p.delay = 0, p.type = !1), this.startAnimation(p), this.setAnimationOrigin(a, x);
        } else
          r || Z(this), this.isLead() && this.options.onExitComplete && this.options.onExitComplete();
        this.targetLayout = h;
      });
    }
    unmount() {
      this.options.layoutId && this.willUpdate(), this.root.nodes.remove(this);
      const t = this.getStack();
      t && t.remove(this), this.parent && this.parent.children.delete(this), this.instance = void 0, this.eventHandlers.clear(), X(this.updateProjection);
    }
    // only on the root
    blockUpdate() {
      this.updateManuallyBlocked = !0;
    }
    unblockUpdate() {
      this.updateManuallyBlocked = !1;
    }
    isUpdateBlocked() {
      return this.updateManuallyBlocked || this.updateBlockedByResize;
    }
    isTreeAnimationBlocked() {
      return this.isAnimationBlocked || this.parent && this.parent.isTreeAnimationBlocked() || !1;
    }
    // Note: currently only running on root node
    startUpdate() {
      this.isUpdateBlocked() || (this.isUpdating = !0, this.nodes && this.nodes.forEach(It), this.animationId++);
    }
    getTransformTemplate() {
      const { visualElement: t } = this.options;
      return t && t.getProps().transformTemplate;
    }
    willUpdate(t = !0) {
      if (this.root.hasTreeAnimated = !0, this.root.isUpdateBlocked()) {
        this.options.onExitComplete && this.options.onExitComplete();
        return;
      }
      if (window.MotionCancelOptimisedAnimation && !this.hasCheckedOptimisedAppear && st(this), !this.root.isUpdating && this.root.startUpdate(), this.isLayoutDirty)
        return;
      this.isLayoutDirty = !0;
      for (let a = 0; a < this.path.length; a++) {
        const r = this.path[a];
        r.shouldResetTransform = !0, r.updateScroll("snapshot"), r.options.layoutRoot && r.willUpdate(!1);
      }
      const { layoutId: i, layout: s } = this.options;
      if (i === void 0 && !s)
        return;
      const o = this.getTransformTemplate();
      this.prevTransformTemplateValue = o ? o(this.latestValues, "") : void 0, this.updateSnapshot(), t && this.notifyListeners("willUpdate");
    }
    update() {
      if (this.updateScheduled = !1, this.isUpdateBlocked()) {
        this.unblockUpdate(), this.clearAllSnapshots(), this.nodes.forEach(Y);
        return;
      }
      if (this.animationId <= this.animationCommitId) {
        this.nodes.forEach($);
        return;
      }
      this.animationCommitId = this.animationId, this.isUpdating ? (this.isUpdating = !1, this.nodes.forEach(Ct), this.nodes.forEach(kt), this.nodes.forEach(Lt)) : this.nodes.forEach($), this.clearAllSnapshots();
      const i = Pt.now();
      y.delta = jt(0, 1e3 / 60, i - y.timestamp), y.timestamp = i, y.isProcessing = !0, F.update.process(y), F.preRender.process(y), F.render.process(y), y.isProcessing = !1;
    }
    didUpdate() {
      this.updateScheduled || (this.updateScheduled = !0, St.read(this.scheduleUpdate));
    }
    clearAllSnapshots() {
      this.nodes.forEach(Ut), this.sharedNodes.forEach(Mt);
    }
    scheduleUpdateProjection() {
      this.projectionUpdateScheduled || (this.projectionUpdateScheduled = !0, V.preRender(this.updateProjection, !1, !0));
    }
    scheduleCheckAfterUnmount() {
      V.postRender(() => {
        this.isLayoutDirty ? this.root.didUpdate() : this.root.checkUpdateFailed();
      });
    }
    /**
     * Update measurements
     */
    updateSnapshot() {
      this.snapshot || !this.instance || (this.snapshot = this.measure(), this.snapshot && !S(this.snapshot.measuredBox.x) && !S(this.snapshot.measuredBox.y) && (this.snapshot = void 0));
    }
    updateLayout() {
      if (!this.instance || (this.updateScroll(), !(this.options.alwaysMeasureLayout && this.isLead()) && !this.isLayoutDirty))
        return;
      if (this.resumeFrom && !this.resumeFrom.instance)
        for (let s = 0; s < this.path.length; s++)
          this.path[s].updateScroll();
      const t = this.layout;
      this.layout = this.measure(!1), this.layoutCorrected = d(), this.isLayoutDirty = !1, this.projectionDelta = void 0, this.notifyListeners("measure", this.layout.layoutBox);
      const { visualElement: i } = this.options;
      i && i.notify("LayoutMeasure", this.layout.layoutBox, t ? t.layoutBox : void 0);
    }
    updateScroll(t = "measure") {
      let i = !!(this.options.layoutScroll && this.instance);
      if (this.scroll && this.scroll.animationId === this.root.animationId && this.scroll.phase === t && (i = !1), i && this.instance) {
        const s = u(this.instance);
        this.scroll = {
          animationId: this.root.animationId,
          phase: t,
          isRoot: s,
          offset: c(this.instance),
          wasRoot: this.scroll ? this.scroll.isRoot : s
        };
      }
    }
    resetTransform() {
      if (!v)
        return;
      const t = this.isLayoutDirty || this.shouldResetTransform || this.options.alwaysMeasureLayout, i = this.projectionDelta && !it(this.projectionDelta), s = this.getTransformTemplate(), o = s ? s(this.latestValues, "") : void 0, a = o !== this.prevTransformTemplateValue;
      t && this.instance && (i || P(this.latestValues) || a) && (v(this.instance, o), this.shouldResetTransform = !1, this.scheduleRender());
    }
    measure(t = !0) {
      const i = this.measurePageBox();
      let s = this.removeElementScroll(i);
      return t && (s = this.removeTransform(s)), Nt(s), {
        animationId: this.root.animationId,
        measuredBox: i,
        layoutBox: s,
        latestValues: {},
        source: this.id
      };
    }
    measurePageBox() {
      var o;
      const { visualElement: t } = this.options;
      if (!t)
        return d();
      const i = t.measureViewportBox();
      if (!(((o = this.scroll) == null ? void 0 : o.wasRoot) || this.path.some(Ht))) {
        const { scroll: a } = this.root;
        a && (E(i.x, a.offset.x), E(i.y, a.offset.y));
      }
      return i;
    }
    removeElementScroll(t) {
      var s;
      const i = d();
      if (f(i, t), (s = this.scroll) != null && s.wasRoot)
        return i;
      for (let o = 0; o < this.path.length; o++) {
        const a = this.path[o], { scroll: r, options: l } = a;
        a !== this.root && r && l.layoutScroll && (r.wasRoot && f(i, t), E(i.x, r.offset.x), E(i.y, r.offset.y));
      }
      return i;
    }
    applyTransform(t, i = !1) {
      const s = d();
      f(s, t);
      for (let o = 0; o < this.path.length; o++) {
        const a = this.path[o];
        !i && a.options.layoutScroll && a.scroll && a !== a.root && w(s, {
          x: -a.scroll.offset.x,
          y: -a.scroll.offset.y
        }), P(a.latestValues) && w(s, a.latestValues);
      }
      return P(this.latestValues) && w(s, this.latestValues), s;
    }
    removeTransform(t) {
      const i = d();
      f(i, t);
      for (let s = 0; s < this.path.length; s++) {
        const o = this.path[s];
        if (!o.instance || !P(o.latestValues))
          continue;
        q(o.latestValues) && o.updateSnapshot();
        const a = d(), r = o.measurePageBox();
        f(a, r), W(i, o.latestValues, o.snapshot ? o.snapshot.layoutBox : void 0, a);
      }
      return P(this.latestValues) && W(i, this.latestValues), i;
    }
    setTargetDelta(t) {
      this.targetDelta = t, this.root.scheduleUpdateProjection(), this.isProjectionDirty = !0;
    }
    setOptions(t) {
      this.options = {
        ...this.options,
        ...t,
        crossfade: t.crossfade !== void 0 ? t.crossfade : !0
      };
    }
    clearMeasurements() {
      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;
    }
    forceRelativeParentToResolveTarget() {
      this.relativeParent && this.relativeParent.resolvedRelativeTargetAt !== y.timestamp && this.relativeParent.resolveTargetDelta(!0);
    }
    resolveTargetDelta(t = !1) {
      var l;
      const i = this.getLead();
      this.isProjectionDirty || (this.isProjectionDirty = i.isProjectionDirty), this.isTransformDirty || (this.isTransformDirty = i.isTransformDirty), this.isSharedProjectionDirty || (this.isSharedProjectionDirty = i.isSharedProjectionDirty);
      const s = !!this.resumingFrom || this !== i;
      if (!(t || s && this.isSharedProjectionDirty || this.isProjectionDirty || (l = this.parent) != null && l.isProjectionDirty || this.attemptToResolveRelativeTarget || this.root.updateBlockedByResize))
        return;
      const { layout: a, layoutId: r } = this.options;
      if (!(!this.layout || !(a || r))) {
        if (this.resolvedRelativeTargetAt = y.timestamp, !this.targetDelta && !this.relativeTarget) {
          const h = this.getClosestProjectingParent();
          h && h.layout && this.animationProgress !== 1 ? (this.relativeParent = h, this.forceRelativeParentToResolveTarget(), this.relativeTarget = d(), this.relativeTargetOrigin = d(), k(this.relativeTargetOrigin, this.layout.layoutBox, h.layout.layoutBox), f(this.relativeTarget, this.relativeTargetOrigin)) : this.relativeParent = this.relativeTarget = void 0;
        }
        if (!(!this.relativeTarget && !this.targetDelta) && (this.target || (this.target = d(), this.targetWithTransforms = d()), this.relativeTarget && this.relativeTargetOrigin && this.relativeParent && this.relativeParent.target ? (this.forceRelativeParentToResolveTarget(), dt(this.target, this.relativeTarget, this.relativeParent.target)) : this.targetDelta ? (this.resumingFrom ? this.target = this.applyTransform(this.layout.layoutBox) : f(this.target, this.layout.layoutBox), ut(this.target, this.targetDelta)) : f(this.target, this.layout.layoutBox), this.attemptToResolveRelativeTarget)) {
          this.attemptToResolveRelativeTarget = !1;
          const h = this.getClosestProjectingParent();
          h && !!h.resumingFrom == !!this.resumingFrom && !h.options.layoutScroll && h.target && this.animationProgress !== 1 ? (this.relativeParent = h, this.forceRelativeParentToResolveTarget(), this.relativeTarget = d(), this.relativeTargetOrigin = d(), k(this.relativeTargetOrigin, this.target, h.target), f(this.relativeTarget, this.relativeTargetOrigin)) : this.relativeParent = this.relativeTarget = void 0;
        }
      }
    }
    getClosestProjectingParent() {
      if (!(!this.parent || q(this.parent.latestValues) || gt(this.parent.latestValues)))
        return this.parent.isProjecting() ? this.parent : this.parent.getClosestProjectingParent();
    }
    isProjecting() {
      return !!((this.relativeTarget || this.targetDelta || this.options.layoutRoot) && this.layout);
    }
    calcProjection() {
      var m;
      const t = this.getLead(), i = !!this.resumingFrom || this !== t;
      let s = !0;
      if ((this.isProjectionDirty || (m = this.parent) != null && m.isProjectionDirty) && (s = !1), i && (this.isSharedProjectionDirty || this.isTransformDirty) && (s = !1), this.resolvedRelativeTargetAt === y.timestamp && (s = !1), s)
        return;
      const { layout: o, layoutId: a } = this.options;
      if (this.isTreeAnimating = !!(this.parent && this.parent.isTreeAnimating || this.currentAnimation || this.pendingAnimation), this.isTreeAnimating || (this.targetDelta = this.relativeTarget = void 0), !this.layout || !(o || a))
        return;
      f(this.layoutCorrected, this.layout.layoutBox);
      const r = this.treeScale.x, l = this.treeScale.y;
      ct(this.layoutCorrected, this.treeScale, this.path, i), t.layout && !t.target && (this.treeScale.x !== 1 || this.treeScale.y !== 1) && (t.target = t.layout.layoutBox, t.targetWithTransforms = d());
      const { target: h } = t;
      if (!h) {
        this.prevProjectionDelta && (this.createProjectionDeltas(), this.scheduleRender());
        return;
      }
      !this.projectionDelta || !this.prevProjectionDelta ? this.createProjectionDeltas() : (b(this.prevProjectionDelta.x, this.projectionDelta.x), b(this.prevProjectionDelta.y, this.projectionDelta.y)), L(this.projectionDelta, this.layoutCorrected, h, this.latestValues), (this.treeScale.x !== r || this.treeScale.y !== l || !z(this.projectionDelta.x, this.prevProjectionDelta.x) || !z(this.projectionDelta.y, this.prevProjectionDelta.y)) && (this.hasProjected = !0, this.scheduleRender(), this.notifyListeners("projectionUpdate", h));
    }
    hide() {
      this.isVisible = !1;
    }
    show() {
      this.isVisible = !0;
    }
    scheduleRender(t = !0) {
      var i;
      if ((i = this.options.visualElement) == null || i.scheduleRender(), t) {
        const s = this.getStack();
        s && s.scheduleRender();
      }
      this.resumingFrom && !this.resumingFrom.instance && (this.resumingFrom = void 0);
    }
    createProjectionDeltas() {
      this.prevProjectionDelta = B(), this.projectionDelta = B(), this.projectionDeltaWithTransform = B();
    }
    setAnimationOrigin(t, i = !1) {
      const s = this.snapshot, o = s ? s.latestValues : {}, a = { ...this.latestValues }, r = B();
      (!this.relativeParent || !this.relativeParent.options.layoutRoot) && (this.relativeTarget = this.relativeTargetOrigin = void 0), this.attemptToResolveRelativeTarget = !i;
      const l = d(), h = s ? s.source : void 0, m = this.layout ? this.layout.source : void 0, g = h !== m, T = this.getStack(), D = !T || T.members.length <= 1, x = !!(g && !D && this.options.crossfade === !0 && !this.path.some(Wt));
      this.animationProgress = 0;
      let p;
      this.mixTargetDelta = (A) => {
        const R = A / 1e3;
        J(r.x, t.x, R), J(r.y, t.y, R), this.setTargetDelta(r), this.relativeTarget && this.relativeTargetOrigin && this.layout && this.relativeParent && this.relativeParent.layout && (k(l, this.layout.layoutBox, this.relativeParent.layout.layoutBox), bt(this.relativeTarget, this.relativeTargetOrigin, l, R), p && ft(this.relativeTarget, p) && (this.isProjectionDirty = !1), p || (p = d()), f(p, this.relativeTarget)), g && (this.animationValues = a, lt(a, o, this.latestValues, R, x, D)), this.root.scheduleUpdateProjection(), this.scheduleRender(), this.animationProgress = R;
      }, this.mixTargetDelta(this.options.layoutRoot ? 1e3 : 0);
    }
    startAnimation(t) {
      var i, s, o;
      this.notifyListeners("animationStart"), (i = this.currentAnimation) == null || i.stop(), (o = (s = this.resumingFrom) == null ? void 0 : s.currentAnimation) == null || o.stop(), this.pendingAnimation && (X(this.pendingAnimation), this.pendingAnimation = void 0), this.pendingAnimation = V.update(() => {
        O.hasAnimatedSinceResize = !0, this.motionValue || (this.motionValue = Bt(0)), this.currentAnimation = at(this.motionValue, [0, 1e3], {
          ...t,
          velocity: 0,
          isSync: !0,
          onUpdate: (a) => {
            this.mixTargetDelta(a), t.onUpdate && t.onUpdate(a);
          },
          onStop: () => {
          },
          onComplete: () => {
            t.onComplete && t.onComplete(), this.completeAnimation();
          }
        }), this.resumingFrom && (this.resumingFrom.currentAnimation = this.currentAnimation), this.pendingAnimation = void 0;
      });
    }
    completeAnimation() {
      this.resumingFrom && (this.resumingFrom.currentAnimation = void 0, this.resumingFrom.preserveOpacity = void 0);
      const t = this.getStack();
      t && t.exitAnimationComplete(), this.resumingFrom = this.currentAnimation = this.animationValues = void 0, this.notifyListeners("animationComplete");
    }
    finishAnimation() {
      this.currentAnimation && (this.mixTargetDelta && this.mixTargetDelta(Rt), this.currentAnimation.stop()), this.completeAnimation();
    }
    applyTransformsToTarget() {
      const t = this.getLead();
      let { targetWithTransforms: i, target: s, layout: o, latestValues: a } = t;
      if (!(!i || !s || !o)) {
        if (this !== t && this.layout && o && ot(this.options.animationType, this.layout.layoutBox, o.layoutBox)) {
          s = this.target || d();
          const r = S(this.layout.layoutBox.x);
          s.x.min = t.target.x.min, s.x.max = s.x.min + r;
          const l = S(this.layout.layoutBox.y);
          s.y.min = t.target.y.min, s.y.max = s.y.min + l;
        }
        f(i, s), w(i, a), L(this.projectionDeltaWithTransform, this.layoutCorrected, i, a);
      }
    }
    registerSharedNode(t, i) {
      this.sharedNodes.has(t) || this.sharedNodes.set(t, new pt()), this.sharedNodes.get(t).add(i);
      const o = i.options.initialPromotionConfig;
      i.promote({
        transition: o ? o.transition : void 0,
        preserveFollowOpacity: o && o.shouldPreserveFollowOpacity ? o.shouldPreserveFollowOpacity(i) : void 0
      });
    }
    isLead() {
      const t = this.getStack();
      return t ? t.lead === this : !0;
    }
    getLead() {
      var i;
      const { layoutId: t } = this.options;
      return t ? ((i = this.getStack()) == null ? void 0 : i.lead) || this : this;
    }
    getPrevLead() {
      var i;
      const { layoutId: t } = this.options;
      return t ? (i = this.getStack()) == null ? void 0 : i.prevLead : void 0;
    }
    getStack() {
      const { layoutId: t } = this.options;
      if (t)
        return this.root.sharedNodes.get(t);
    }
    promote({ needsReset: t, transition: i, preserveFollowOpacity: s } = {}) {
      const o = this.getStack();
      o && o.promote(this, s), t && (this.projectionDelta = void 0, this.needsReset = !0), i && this.setOptions({ transition: i });
    }
    relegate() {
      const t = this.getStack();
      return t ? t.relegate(this) : !1;
    }
    resetSkewAndRotation() {
      const { visualElement: t } = this.options;
      if (!t)
        return;
      let i = !1;
      const { latestValues: s } = t;
      if ((s.z || s.rotate || s.rotateX || s.rotateY || s.rotateZ || s.skewX || s.skewY) && (i = !0), !i)
        return;
      const o = {};
      s.z && M("z", t, o, this.animationValues);
      for (let a = 0; a < I.length; a++)
        M(`rotate${I[a]}`, t, o, this.animationValues), M(`skew${I[a]}`, t, o, this.animationValues);
      t.render();
      for (const a in o)
        t.setStaticValue(a, o[a]), this.animationValues && (this.animationValues[a] = o[a]);
      t.scheduleRender();
    }
    applyProjectionStyles(t, i) {
      if (!this.instance || this.isSVG)
        return;
      if (!this.isVisible) {
        t.visibility = "hidden";
        return;
      }
      const s = this.getTransformTemplate();
      if (this.needsReset) {
        this.needsReset = !1, t.visibility = "", t.opacity = "", t.pointerEvents = C(i == null ? void 0 : i.pointerEvents) || "", t.transform = s ? s(this.latestValues, "") : "none";
        return;
      }
      const o = this.getLead();
      if (!this.projectionDelta || !this.layout || !o.target) {
        this.options.layoutId && (t.opacity = this.latestValues.opacity !== void 0 ? this.latestValues.opacity : 1, t.pointerEvents = C(i == null ? void 0 : i.pointerEvents) || ""), this.hasProjected && !P(this.latestValues) && (t.transform = s ? s({}, "") : "none", this.hasProjected = !1);
        return;
      }
      t.visibility = "";
      const a = o.animationValues || o.latestValues;
      this.applyTransformsToTarget();
      let r = yt(this.projectionDeltaWithTransform, this.treeScale, a);
      s && (r = s(a, r)), t.transform = r;
      const { x: l, y: h } = this.projectionDelta;
      t.transformOrigin = `${l.origin * 100}% ${h.origin * 100}% 0`, o.animationValues ? t.opacity = o === this ? a.opacity ?? this.latestValues.opacity ?? 1 : this.preserveOpacity ? this.latestValues.opacity : a.opacityExit : t.opacity = o === this ? a.opacity !== void 0 ? a.opacity : "" : a.opacityExit !== void 0 ? a.opacityExit : 0;
      for (const m in H) {
        if (a[m] === void 0)
          continue;
        const { correct: g, applyTo: T, isCSSVariable: D } = H[m], x = r === "none" ? a[m] : g(a[m], o);
        if (T) {
          const p = T.length;
          for (let A = 0; A < p; A++)
            t[T[A]] = x;
        } else
          D ? this.options.visualElement.renderState.vars[m] = x : t[m] = x;
      }
      this.options.layoutId && (t.pointerEvents = o === this ? C(i == null ? void 0 : i.pointerEvents) || "" : "none");
    }
    clearSnapshot() {
      this.resumeFrom = this.snapshot = void 0;
    }
    // Only run on root
    resetTree() {
      this.root.nodes.forEach((t) => {
        var i;
        return (i = t.currentAnimation) == null ? void 0 : i.stop();
      }), this.root.nodes.forEach(Y), this.root.sharedNodes.clear();
    }
  };
}
function kt(e) {
  e.updateLayout();
}
function Lt(e) {
  var c;
  const n = ((c = e.resumeFrom) == null ? void 0 : c.snapshot) || e.snapshot;
  if (e.isLead() && e.layout && n && e.hasListeners("didUpdate")) {
    const { layoutBox: u, measuredBox: v } = e.layout, { animationType: j } = e.options, t = n.source !== e.layout.source;
    j === "size" ? G((r) => {
      const l = t ? n.measuredBox[r] : n.layoutBox[r], h = S(l);
      l.min = u[r].min, l.max = l.min + h;
    }) : ot(j, n.layoutBox, u) && G((r) => {
      const l = t ? n.measuredBox[r] : n.layoutBox[r], h = S(u[r]);
      l.max = l.min + h, e.relativeTarget && !e.currentAnimation && (e.isProjectionDirty = !0, e.relativeTarget[r].max = e.relativeTarget[r].min + h);
    });
    const i = B();
    L(i, u, n.layoutBox);
    const s = B();
    t ? L(s, e.applyTransform(v, !0), n.measuredBox) : L(s, u, n.layoutBox);
    const o = !it(i);
    let a = !1;
    if (!e.resumeFrom) {
      const r = e.getClosestProjectingParent();
      if (r && !r.resumeFrom) {
        const { snapshot: l, layout: h } = r;
        if (l && h) {
          const m = d();
          k(m, n.layoutBox, l.layoutBox);
          const g = d();
          k(g, u, h.layoutBox), et(m, g) || (a = !0), r.options.layoutRoot && (e.relativeTarget = g, e.relativeTargetOrigin = m, e.relativeParent = r);
        }
      }
    }
    e.notifyListeners("didUpdate", {
      layout: u,
      snapshot: n,
      delta: s,
      layoutDelta: i,
      hasLayoutChanged: o,
      hasRelativeLayoutChanged: a
    });
  } else if (e.isLead()) {
    const { onExitComplete: u } = e.options;
    u && u();
  }
  e.options.transition = void 0;
}
function Et(e) {
  e.parent && (e.isProjecting() || (e.isProjectionDirty = e.parent.isProjectionDirty), e.isSharedProjectionDirty || (e.isSharedProjectionDirty = !!(e.isProjectionDirty || e.parent.isProjectionDirty || e.parent.isSharedProjectionDirty)), e.isTransformDirty || (e.isTransformDirty = e.parent.isTransformDirty));
}
function wt(e) {
  e.isProjectionDirty = e.isSharedProjectionDirty = e.isTransformDirty = !1;
}
function Ut(e) {
  e.clearSnapshot();
}
function Y(e) {
  e.clearMeasurements();
}
function $(e) {
  e.isLayoutDirty = !1;
}
function Ct(e) {
  const { visualElement: n } = e.options;
  n && n.getProps().onBeforeLayoutMeasure && n.notify("BeforeLayoutMeasure"), e.resetTransform();
}
function Z(e) {
  e.finishAnimation(), e.targetDelta = e.relativeTarget = e.target = void 0, e.isProjectionDirty = !0;
}
function Ot(e) {
  e.resolveTargetDelta();
}
function Ft(e) {
  e.calcProjection();
}
function It(e) {
  e.resetSkewAndRotation();
}
function Mt(e) {
  e.removeLeadSnapshot();
}
function J(e, n, c) {
  e.translate = U(n.translate, 0, c), e.scale = U(n.scale, 1, c), e.origin = n.origin, e.originPoint = n.originPoint;
}
function K(e, n, c, u) {
  e.min = U(n.min, c.min, u), e.max = U(n.max, c.max, u);
}
function bt(e, n, c, u) {
  K(e.x, n.x, c.x, u), K(e.y, n.y, c.y, u);
}
function Wt(e) {
  return e.animationValues && e.animationValues.opacityExit !== void 0;
}
const zt = {
  duration: 0.45,
  ease: [0.4, 0, 0.1, 1]
}, Q = (e) => typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().includes(e), _ = Q("applewebkit/") && !Q("chrome/") ? Math.round : At;
function tt(e) {
  e.min = _(e.min), e.max = _(e.max);
}
function Nt(e) {
  tt(e.x), tt(e.y);
}
function ot(e, n, c) {
  return e === "position" || e === "preserve-aspect" && !mt(N(n), N(c), 0.2);
}
function Ht(e) {
  var n;
  return e !== e.root && ((n = e.scroll) == null ? void 0 : n.wasRoot);
}
export {
  wt as cleanDirtyNodes,
  xe as createProjectionNode,
  K as mixAxis,
  J as mixAxisDelta,
  bt as mixBox,
  Et as propagateDirtyNodes
};
//# sourceMappingURL=create-projection-node.es.js.map
