import { V as c, c as Q } from "./maths-0ab39ae9.esm.mjs";
function Z(s, t) {
  if (typeof s != "object" || s === null)
    return s;
  var e = s[Symbol.toPrimitive];
  if (e !== void 0) {
    var i = e.call(s, t || "default");
    if (typeof i != "object")
      return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (t === "string" ? String : Number)(s);
}
function tt(s) {
  var t = Z(s, "string");
  return typeof t == "symbol" ? t : String(t);
}
function _(s, t, e) {
  return t = tt(t), t in s ? Object.defineProperty(s, t, {
    value: e,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : s[t] = e, s;
}
function O(s, t) {
  var e = Object.keys(s);
  if (Object.getOwnPropertySymbols) {
    var i = Object.getOwnPropertySymbols(s);
    t && (i = i.filter(function(n) {
      return Object.getOwnPropertyDescriptor(s, n).enumerable;
    })), e.push.apply(e, i);
  }
  return e;
}
function u(s) {
  for (var t = 1; t < arguments.length; t++) {
    var e = arguments[t] != null ? arguments[t] : {};
    t % 2 ? O(Object(e), !0).forEach(function(i) {
      _(s, i, e[i]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(s, Object.getOwnPropertyDescriptors(e)) : O(Object(e)).forEach(function(i) {
      Object.defineProperty(s, i, Object.getOwnPropertyDescriptor(e, i));
    });
  }
  return s;
}
const Y = {
  pointer: {
    start: "down",
    change: "move",
    end: "up"
  },
  mouse: {
    start: "down",
    change: "move",
    end: "up"
  },
  touch: {
    start: "start",
    change: "move",
    end: "end"
  },
  gesture: {
    start: "start",
    change: "change",
    end: "end"
  }
};
function P(s) {
  return s ? s[0].toUpperCase() + s.slice(1) : "";
}
const et = ["enter", "leave"];
function st(s = !1, t) {
  return s && !et.includes(t);
}
function Mt(s, t = "", e = !1) {
  const i = Y[s], n = i && i[t] || t;
  return "on" + P(s) + P(n) + (st(e, n) ? "Capture" : "");
}
const it = ["gotpointercapture", "lostpointercapture"];
function Lt(s) {
  let t = s.substring(2).toLowerCase();
  const e = !!~t.indexOf("passive");
  e && (t = t.replace("passive", ""));
  const i = it.includes(t) ? "capturecapture" : "capture", n = !!~t.indexOf(i);
  return n && (t = t.replace("capture", "")), {
    device: t,
    capture: n,
    passive: e
  };
}
function Nt(s, t = "") {
  const e = Y[s], i = e && e[t] || t;
  return s + i;
}
function x(s) {
  return "touches" in s;
}
function j(s) {
  return x(s) ? "touch" : "pointerType" in s ? s.pointerType : "mouse";
}
function nt(s) {
  return Array.from(s.touches).filter((t) => {
    var e, i;
    return t.target === s.currentTarget || ((e = s.currentTarget) === null || e === void 0 || (i = e.contains) === null || i === void 0 ? void 0 : i.call(e, t.target));
  });
}
function rt(s) {
  return s.type === "touchend" || s.type === "touchcancel" ? s.changedTouches : s.targetTouches;
}
function H(s) {
  return x(s) ? rt(s)[0] : s;
}
function k(s, t) {
  try {
    const e = t.clientX - s.clientX, i = t.clientY - s.clientY, n = (t.clientX + s.clientX) / 2, r = (t.clientY + s.clientY) / 2, o = Math.hypot(e, i);
    return {
      angle: -(Math.atan2(e, i) * 180) / Math.PI,
      distance: o,
      origin: [n, r]
    };
  } catch (e) {
  }
  return null;
}
function Vt(s) {
  return nt(s).map((t) => t.identifier);
}
function C(s, t) {
  const [e, i] = Array.from(s.touches).filter((n) => t.includes(n.identifier));
  return k(e, i);
}
function A(s) {
  const t = H(s);
  return x(s) ? t.identifier : t.pointerId;
}
function M(s) {
  const t = H(s);
  return [t.clientX, t.clientY];
}
const L = 40, N = 800;
function ot(s) {
  let {
    deltaX: t,
    deltaY: e,
    deltaMode: i
  } = s;
  return i === 1 ? (t *= L, e *= L) : i === 2 && (t *= N, e *= N), [t, e];
}
function at(s) {
  const t = {};
  if ("buttons" in s && (t.buttons = s.buttons), "shiftKey" in s) {
    const {
      shiftKey: e,
      altKey: i,
      metaKey: n,
      ctrlKey: r
    } = s;
    Object.assign(t, {
      shiftKey: e,
      altKey: i,
      metaKey: n,
      ctrlKey: r
    });
  }
  return t;
}
function D(s, ...t) {
  return typeof s == "function" ? s(...t) : s;
}
function ct() {
}
function Kt(...s) {
  return s.length === 0 ? ct : s.length === 1 ? s[0] : function() {
    let t;
    for (const e of s)
      t = e.apply(this, arguments) || t;
    return t;
  };
}
function V(s, t) {
  return Object.assign({}, t, s || {});
}
const ut = 32;
class X {
  constructor(t, e, i) {
    this.ctrl = t, this.args = e, this.key = i, this.state || (this.state = {}, this.computeValues([0, 0]), this.computeInitial(), this.init && this.init(), this.reset());
  }
  get state() {
    return this.ctrl.state[this.key];
  }
  set state(t) {
    this.ctrl.state[this.key] = t;
  }
  get shared() {
    return this.ctrl.state.shared;
  }
  get eventStore() {
    return this.ctrl.gestureEventStores[this.key];
  }
  get timeoutStore() {
    return this.ctrl.gestureTimeoutStores[this.key];
  }
  get config() {
    return this.ctrl.config[this.key];
  }
  get sharedConfig() {
    return this.ctrl.config.shared;
  }
  get handler() {
    return this.ctrl.handlers[this.key];
  }
  reset() {
    const {
      state: t,
      shared: e,
      ingKey: i,
      args: n
    } = this;
    e[i] = t._active = t.active = t._blocked = t._force = !1, t._step = [!1, !1], t.intentional = !1, t._movement = [0, 0], t._distance = [0, 0], t._direction = [0, 0], t._delta = [0, 0], t._bounds = [[-1 / 0, 1 / 0], [-1 / 0, 1 / 0]], t.args = n, t.axis = void 0, t.memo = void 0, t.elapsedTime = t.timeDelta = 0, t.direction = [0, 0], t.distance = [0, 0], t.overflow = [0, 0], t._movementBound = [!1, !1], t.velocity = [0, 0], t.movement = [0, 0], t.delta = [0, 0], t.timeStamp = 0;
  }
  start(t) {
    const e = this.state, i = this.config;
    e._active || (this.reset(), this.computeInitial(), e._active = !0, e.target = t.target, e.currentTarget = t.currentTarget, e.lastOffset = i.from ? D(i.from, e) : e.offset, e.offset = e.lastOffset, e.startTime = e.timeStamp = t.timeStamp);
  }
  computeValues(t) {
    const e = this.state;
    e._values = t, e.values = this.config.transform(t);
  }
  computeInitial() {
    const t = this.state;
    t._initial = t._values, t.initial = t.values;
  }
  compute(t) {
    const {
      state: e,
      config: i,
      shared: n
    } = this;
    e.args = this.args;
    let r = 0;
    if (t && (e.event = t, i.preventDefault && t.cancelable && e.event.preventDefault(), e.type = t.type, n.touches = this.ctrl.pointerIds.size || this.ctrl.touchIds.size, n.locked = !!document.pointerLockElement, Object.assign(n, at(t)), n.down = n.pressed = n.buttons % 2 === 1 || n.touches > 0, r = t.timeStamp - e.timeStamp, e.timeStamp = t.timeStamp, e.elapsedTime = e.timeStamp - e.startTime), e._active) {
      const p = e._delta.map(Math.abs);
      c.addTo(e._distance, p);
    }
    this.axisIntent && this.axisIntent(t);
    const [o, h] = e._movement, [d, m] = i.threshold, {
      _step: a,
      values: g
    } = e;
    if (i.hasCustomTransform ? (a[0] === !1 && (a[0] = Math.abs(o) >= d && g[0]), a[1] === !1 && (a[1] = Math.abs(h) >= m && g[1])) : (a[0] === !1 && (a[0] = Math.abs(o) >= d && Math.sign(o) * d), a[1] === !1 && (a[1] = Math.abs(h) >= m && Math.sign(h) * m)), e.intentional = a[0] !== !1 || a[1] !== !1, !e.intentional)
      return;
    const l = [0, 0];
    if (i.hasCustomTransform) {
      const [p, J] = g;
      l[0] = a[0] !== !1 ? p - a[0] : 0, l[1] = a[1] !== !1 ? J - a[1] : 0;
    } else
      l[0] = a[0] !== !1 ? o - a[0] : 0, l[1] = a[1] !== !1 ? h - a[1] : 0;
    this.restrictToAxis && !e._blocked && this.restrictToAxis(l);
    const b = e.offset, E = e._active && !e._blocked || e.active;
    E && (e.first = e._active && !e.active, e.last = !e._active && e.active, e.active = n[this.ingKey] = e._active, t && (e.first && ("bounds" in i && (e._bounds = D(i.bounds, e)), this.setup && this.setup()), e.movement = l, this.computeOffset()));
    const [w, T] = e.offset, [[I, W], [$, F]] = e._bounds;
    e.overflow = [w < I ? -1 : w > W ? 1 : 0, T < $ ? -1 : T > F ? 1 : 0], e._movementBound[0] = e.overflow[0] ? e._movementBound[0] === !1 ? e._movement[0] : e._movementBound[0] : !1, e._movementBound[1] = e.overflow[1] ? e._movementBound[1] === !1 ? e._movement[1] : e._movementBound[1] : !1;
    const q = e._active ? i.rubberband || [0, 0] : [0, 0];
    if (e.offset = Q(e._bounds, e.offset, q), e.delta = c.sub(e.offset, b), this.computeMovement(), E && (!e.last || r > ut)) {
      e.delta = c.sub(e.offset, b);
      const p = e.delta.map(Math.abs);
      c.addTo(e.distance, p), e.direction = e.delta.map(Math.sign), e._direction = e._delta.map(Math.sign), !e.first && r > 0 && (e.velocity = [p[0] / r, p[1] / r], e.timeDelta = r);
    }
  }
  emit() {
    const t = this.state, e = this.shared, i = this.config;
    if (t._active || this.clean(), (t._blocked || !t.intentional) && !t._force && !i.triggerAllEvents)
      return;
    const n = this.handler(u(u(u({}, e), t), {}, {
      [this.aliasKey]: t.values
    }));
    n !== void 0 && (t.memo = n);
  }
  clean() {
    this.eventStore.clean(), this.timeoutStore.clean();
  }
}
function ht([s, t], e) {
  const i = Math.abs(s), n = Math.abs(t);
  if (i > n && i > e)
    return "x";
  if (n > i && n > e)
    return "y";
}
class ft extends X {
  constructor(...t) {
    super(...t), _(this, "aliasKey", "xy");
  }
  reset() {
    super.reset(), this.state.axis = void 0;
  }
  init() {
    this.state.offset = [0, 0], this.state.lastOffset = [0, 0];
  }
  computeOffset() {
    this.state.offset = c.add(this.state.lastOffset, this.state.movement);
  }
  computeMovement() {
    this.state.movement = c.sub(this.state.offset, this.state.lastOffset);
  }
  axisIntent(t) {
    const e = this.state, i = this.config;
    if (!e.axis && t) {
      const n = typeof i.axisThreshold == "object" ? i.axisThreshold[j(t)] : i.axisThreshold;
      e.axis = ht(e._movement, n);
    }
    e._blocked = (i.lockDirection || !!i.axis) && !e.axis || !!i.axis && i.axis !== e.axis;
  }
  restrictToAxis(t) {
    if (this.config.axis || this.config.lockDirection)
      switch (this.state.axis) {
        case "x":
          t[1] = 0;
          break;
        case "y":
          t[0] = 0;
          break;
      }
  }
}
const K = (s) => s, R = 0.15, S = {
  enabled(s = !0) {
    return s;
  },
  eventOptions(s, t, e) {
    return u(u({}, e.shared.eventOptions), s);
  },
  preventDefault(s = !1) {
    return s;
  },
  triggerAllEvents(s = !1) {
    return s;
  },
  rubberband(s = 0) {
    switch (s) {
      case !0:
        return [R, R];
      case !1:
        return [0, 0];
      default:
        return c.toVector(s);
    }
  },
  from(s) {
    if (typeof s == "function")
      return s;
    if (s != null)
      return c.toVector(s);
  },
  transform(s, t, e) {
    const i = s || e.shared.transform;
    if (this.hasCustomTransform = !!i, process.env.NODE_ENV === "development") {
      const n = i || K;
      return (r) => {
        const o = n(r);
        return (!isFinite(o[0]) || !isFinite(o[1])) && console.warn(`[@use-gesture]: config.transform() must produce a valid result, but it was: [${o[0]},${[1]}]`), o;
      };
    }
    return i || K;
  },
  threshold(s) {
    return c.toVector(s, 0);
  }
};
process.env.NODE_ENV === "development" && Object.assign(S, {
  domTarget(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `domTarget` option has been renamed to `target`.");
    return NaN;
  },
  lockDirection(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `lockDirection` option has been merged with `axis`. Use it as in `{ axis: 'lock' }`");
    return NaN;
  },
  initial(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `initial` option has been renamed to `from`.");
    return NaN;
  }
});
const lt = 0, y = u(u({}, S), {}, {
  axis(s, t, {
    axis: e
  }) {
    if (this.lockDirection = e === "lock", !this.lockDirection)
      return e;
  },
  axisThreshold(s = lt) {
    return s;
  },
  bounds(s = {}) {
    if (typeof s == "function")
      return (r) => y.bounds(s(r));
    if ("current" in s)
      return () => s.current;
    if (typeof HTMLElement == "function" && s instanceof HTMLElement)
      return s;
    const {
      left: t = -1 / 0,
      right: e = 1 / 0,
      top: i = -1 / 0,
      bottom: n = 1 / 0
    } = s;
    return [[t, e], [i, n]];
  }
}), U = {
  ArrowRight: (s, t = 1) => [s * t, 0],
  ArrowLeft: (s, t = 1) => [-1 * s * t, 0],
  ArrowUp: (s, t = 1) => [0, -1 * s * t],
  ArrowDown: (s, t = 1) => [0, s * t]
};
class dt extends ft {
  constructor(...t) {
    super(...t), _(this, "ingKey", "dragging");
  }
  reset() {
    super.reset();
    const t = this.state;
    t._pointerId = void 0, t._pointerActive = !1, t._keyboardActive = !1, t._preventScroll = !1, t._delayed = !1, t.swipe = [0, 0], t.tap = !1, t.canceled = !1, t.cancel = this.cancel.bind(this);
  }
  setup() {
    const t = this.state;
    if (t._bounds instanceof HTMLElement) {
      const e = t._bounds.getBoundingClientRect(), i = t.currentTarget.getBoundingClientRect(), n = {
        left: e.left - i.left + t.offset[0],
        right: e.right - i.right + t.offset[0],
        top: e.top - i.top + t.offset[1],
        bottom: e.bottom - i.bottom + t.offset[1]
      };
      t._bounds = y.bounds(n);
    }
  }
  cancel() {
    const t = this.state;
    t.canceled || (t.canceled = !0, t._active = !1, setTimeout(() => {
      this.compute(), this.emit();
    }, 0));
  }
  setActive() {
    this.state._active = this.state._pointerActive || this.state._keyboardActive;
  }
  clean() {
    this.pointerClean(), this.state._pointerActive = !1, this.state._keyboardActive = !1, super.clean();
  }
  pointerDown(t) {
    const e = this.config, i = this.state;
    if (t.buttons != null && (Array.isArray(e.pointerButtons) ? !e.pointerButtons.includes(t.buttons) : e.pointerButtons !== -1 && e.pointerButtons !== t.buttons))
      return;
    const n = this.ctrl.setEventIds(t);
    e.pointerCapture && t.target.setPointerCapture(t.pointerId), !(n && n.size > 1 && i._pointerActive) && (this.start(t), this.setupPointer(t), i._pointerId = A(t), i._pointerActive = !0, this.computeValues(M(t)), this.computeInitial(), e.preventScrollAxis && j(t) !== "mouse" ? (i._active = !1, this.setupScrollPrevention(t)) : e.delay > 0 ? (this.setupDelayTrigger(t), e.triggerAllEvents && (this.compute(t), this.emit())) : this.startPointerDrag(t));
  }
  startPointerDrag(t) {
    const e = this.state;
    e._active = !0, e._preventScroll = !0, e._delayed = !1, this.compute(t), this.emit();
  }
  pointerMove(t) {
    const e = this.state, i = this.config;
    if (!e._pointerActive)
      return;
    const n = A(t);
    if (e._pointerId !== void 0 && n !== e._pointerId)
      return;
    const r = M(t);
    if (document.pointerLockElement === t.target ? e._delta = [t.movementX, t.movementY] : (e._delta = c.sub(r, e._values), this.computeValues(r)), c.addTo(e._movement, e._delta), this.compute(t), e._delayed && e.intentional) {
      this.timeoutStore.remove("dragDelay"), e.active = !1, this.startPointerDrag(t);
      return;
    }
    if (i.preventScrollAxis && !e._preventScroll)
      if (e.axis)
        if (e.axis === i.preventScrollAxis || i.preventScrollAxis === "xy") {
          e._active = !1, this.clean();
          return;
        } else {
          this.timeoutStore.remove("startPointerDrag"), this.startPointerDrag(t);
          return;
        }
      else
        return;
    this.emit();
  }
  pointerUp(t) {
    this.ctrl.setEventIds(t);
    try {
      this.config.pointerCapture && t.target.hasPointerCapture(t.pointerId) && t.target.releasePointerCapture(t.pointerId);
    } catch (h) {
      process.env.NODE_ENV === "development" && console.warn("[@use-gesture]: If you see this message, it's likely that you're using an outdated version of `@react-three/fiber`. \n\nPlease upgrade to the latest version.");
    }
    const e = this.state, i = this.config;
    if (!e._active || !e._pointerActive)
      return;
    const n = A(t);
    if (e._pointerId !== void 0 && n !== e._pointerId)
      return;
    this.state._pointerActive = !1, this.setActive(), this.compute(t);
    const [r, o] = e._distance;
    if (e.tap = r <= i.tapsThreshold && o <= i.tapsThreshold, e.tap && i.filterTaps)
      e._force = !0;
    else {
      const [h, d] = e._delta, [m, a] = e._movement, [g, l] = i.swipe.velocity, [b, E] = i.swipe.distance, w = i.swipe.duration;
      if (e.elapsedTime < w) {
        const T = Math.abs(h / e.timeDelta), I = Math.abs(d / e.timeDelta);
        T > g && Math.abs(m) > b && (e.swipe[0] = Math.sign(h)), I > l && Math.abs(a) > E && (e.swipe[1] = Math.sign(d));
      }
    }
    this.emit();
  }
  pointerClick(t) {
    !this.state.tap && t.detail > 0 && (t.preventDefault(), t.stopPropagation());
  }
  setupPointer(t) {
    const e = this.config, i = e.device;
    if (process.env.NODE_ENV === "development")
      try {
        if (i === "pointer" && e.preventScrollDelay === void 0) {
          const n = "uv" in t ? t.sourceEvent.currentTarget : t.currentTarget;
          window.getComputedStyle(n).touchAction === "auto" && console.warn("[@use-gesture]: The drag target has its `touch-action` style property set to `auto`. It is recommended to add `touch-action: 'none'` so that the drag gesture behaves correctly on touch-enabled devices. For more information read this: https://use-gesture.netlify.app/docs/extras/#touch-action.\n\nThis message will only show in development mode. It won't appear in production. If this is intended, you can ignore it.", n);
        }
      } catch (n) {
      }
    e.pointerLock && t.currentTarget.requestPointerLock(), e.pointerCapture || (this.eventStore.add(this.sharedConfig.window, i, "change", this.pointerMove.bind(this)), this.eventStore.add(this.sharedConfig.window, i, "end", this.pointerUp.bind(this)), this.eventStore.add(this.sharedConfig.window, i, "cancel", this.pointerUp.bind(this)));
  }
  pointerClean() {
    this.config.pointerLock && document.pointerLockElement === this.state.currentTarget && document.exitPointerLock();
  }
  preventScroll(t) {
    this.state._preventScroll && t.cancelable && t.preventDefault();
  }
  setupScrollPrevention(t) {
    this.state._preventScroll = !1, pt(t);
    const e = this.eventStore.add(this.sharedConfig.window, "touch", "change", this.preventScroll.bind(this), {
      passive: !1
    });
    this.eventStore.add(this.sharedConfig.window, "touch", "end", e), this.eventStore.add(this.sharedConfig.window, "touch", "cancel", e), this.timeoutStore.add("startPointerDrag", this.startPointerDrag.bind(this), this.config.preventScrollDelay, t);
  }
  setupDelayTrigger(t) {
    this.state._delayed = !0, this.timeoutStore.add("dragDelay", () => {
      this.state._step = [0, 0], this.startPointerDrag(t);
    }, this.config.delay);
  }
  keyDown(t) {
    const e = U[t.key];
    if (e) {
      const i = this.state, n = t.shiftKey ? 10 : t.altKey ? 0.1 : 1;
      this.start(t), i._delta = e(this.config.keyboardDisplacement, n), i._keyboardActive = !0, c.addTo(i._movement, i._delta), this.compute(t), this.emit();
    }
  }
  keyUp(t) {
    t.key in U && (this.state._keyboardActive = !1, this.setActive(), this.compute(t), this.emit());
  }
  bind(t) {
    const e = this.config.device;
    t(e, "start", this.pointerDown.bind(this)), this.config.pointerCapture && (t(e, "change", this.pointerMove.bind(this)), t(e, "end", this.pointerUp.bind(this)), t(e, "cancel", this.pointerUp.bind(this)), t("lostPointerCapture", "", this.pointerUp.bind(this))), this.config.keys && (t("key", "down", this.keyDown.bind(this)), t("key", "up", this.keyUp.bind(this))), this.config.filterTaps && t("click", "", this.pointerClick.bind(this), {
      capture: !0,
      passive: !1
    });
  }
}
function pt(s) {
  "persist" in s && typeof s.persist == "function" && s.persist();
}
const v = typeof window != "undefined" && window.document && window.document.createElement;
function z() {
  return v && "ontouchstart" in window;
}
function mt() {
  return z() || v && window.navigator.maxTouchPoints > 1;
}
function gt() {
  return v && "onpointerdown" in window;
}
function _t() {
  return v && "exitPointerLock" in window.document;
}
function yt() {
  try {
    return "constructor" in GestureEvent;
  } catch (s) {
    return !1;
  }
}
const f = {
  isBrowser: v,
  gesture: yt(),
  touch: z(),
  touchscreen: mt(),
  pointer: gt(),
  pointerLock: _t()
}, vt = 250, bt = 180, Et = 0.5, wt = 50, Tt = 250, Dt = 10, B = {
  mouse: 0,
  touch: 0,
  pen: 8
}, G = u(u({}, y), {}, {
  device(s, t, {
    pointer: {
      touch: e = !1,
      lock: i = !1,
      mouse: n = !1
    } = {}
  }) {
    return this.pointerLock = i && f.pointerLock, f.touch && e ? "touch" : this.pointerLock ? "mouse" : f.pointer && !n ? "pointer" : f.touch ? "touch" : "mouse";
  },
  preventScrollAxis(s, t, {
    preventScroll: e
  }) {
    if (this.preventScrollDelay = typeof e == "number" ? e : e || e === void 0 && s ? vt : void 0, !(!f.touchscreen || e === !1))
      return s || (e !== void 0 ? "y" : void 0);
  },
  pointerCapture(s, t, {
    pointer: {
      capture: e = !0,
      buttons: i = 1,
      keys: n = !0
    } = {}
  }) {
    return this.pointerButtons = i, this.keys = n, !this.pointerLock && this.device === "pointer" && e;
  },
  threshold(s, t, {
    filterTaps: e = !1,
    tapsThreshold: i = 3,
    axis: n = void 0
  }) {
    const r = c.toVector(s, e ? i : n ? 1 : 0);
    return this.filterTaps = e, this.tapsThreshold = i, r;
  },
  swipe({
    velocity: s = Et,
    distance: t = wt,
    duration: e = Tt
  } = {}) {
    return {
      velocity: this.transform(c.toVector(s)),
      distance: this.transform(c.toVector(t)),
      duration: e
    };
  },
  delay(s = 0) {
    switch (s) {
      case !0:
        return bt;
      case !1:
        return 0;
      default:
        return s;
    }
  },
  axisThreshold(s) {
    return s ? u(u({}, B), s) : B;
  },
  keyboardDisplacement(s = Dt) {
    return s;
  }
});
process.env.NODE_ENV === "development" && Object.assign(G, {
  useTouch(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `useTouch` option has been renamed to `pointer.touch`. Use it as in `{ pointer: { touch: true } }`.");
    return NaN;
  },
  experimental_preventWindowScrollY(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `experimental_preventWindowScrollY` option has been renamed to `preventScroll`.");
    return NaN;
  },
  swipeVelocity(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `swipeVelocity` option has been renamed to `swipe.velocity`. Use it as in `{ swipe: { velocity: 0.5 } }`.");
    return NaN;
  },
  swipeDistance(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `swipeDistance` option has been renamed to `swipe.distance`. Use it as in `{ swipe: { distance: 50 } }`.");
    return NaN;
  },
  swipeDuration(s) {
    if (s !== void 0)
      throw Error("[@use-gesture]: `swipeDuration` option has been renamed to `swipe.duration`. Use it as in `{ swipe: { duration: 250 } }`.");
    return NaN;
  }
});
function It(s) {
  const [t, e] = s.overflow, [i, n] = s._delta, [r, o] = s._direction;
  (t < 0 && i > 0 && r < 0 || t > 0 && i < 0 && r > 0) && (s._movement[0] = s._movementBound[0]), (e < 0 && n > 0 && o < 0 || e > 0 && n < 0 && o > 0) && (s._movement[1] = s._movementBound[1]);
}
const At = 30, kt = 100;
class xt extends X {
  constructor(...t) {
    super(...t), _(this, "ingKey", "pinching"), _(this, "aliasKey", "da");
  }
  init() {
    this.state.offset = [1, 0], this.state.lastOffset = [1, 0], this.state._pointerEvents = /* @__PURE__ */ new Map();
  }
  reset() {
    super.reset();
    const t = this.state;
    t._touchIds = [], t.canceled = !1, t.cancel = this.cancel.bind(this), t.turns = 0;
  }
  computeOffset() {
    const {
      type: t,
      movement: e,
      lastOffset: i
    } = this.state;
    t === "wheel" ? this.state.offset = c.add(e, i) : this.state.offset = [(1 + e[0]) * i[0], e[1] + i[1]];
  }
  computeMovement() {
    const {
      offset: t,
      lastOffset: e
    } = this.state;
    this.state.movement = [t[0] / e[0], t[1] - e[1]];
  }
  axisIntent() {
    const t = this.state, [e, i] = t._movement;
    if (!t.axis) {
      const n = Math.abs(e) * At - Math.abs(i);
      n < 0 ? t.axis = "angle" : n > 0 && (t.axis = "scale");
    }
  }
  restrictToAxis(t) {
    this.config.lockDirection && (this.state.axis === "scale" ? t[1] = 0 : this.state.axis === "angle" && (t[0] = 0));
  }
  cancel() {
    const t = this.state;
    t.canceled || setTimeout(() => {
      t.canceled = !0, t._active = !1, this.compute(), this.emit();
    }, 0);
  }
  touchStart(t) {
    this.ctrl.setEventIds(t);
    const e = this.state, i = this.ctrl.touchIds;
    if (e._active && e._touchIds.every((r) => i.has(r)) || i.size < 2)
      return;
    this.start(t), e._touchIds = Array.from(i).slice(0, 2);
    const n = C(t, e._touchIds);
    n && this.pinchStart(t, n);
  }
  pointerStart(t) {
    if (t.buttons != null && t.buttons % 2 !== 1)
      return;
    this.ctrl.setEventIds(t), t.target.setPointerCapture(t.pointerId);
    const e = this.state, i = e._pointerEvents, n = this.ctrl.pointerIds;
    if (e._active && Array.from(i.keys()).every((o) => n.has(o)) || (i.size < 2 && i.set(t.pointerId, t), e._pointerEvents.size < 2))
      return;
    this.start(t);
    const r = k(...Array.from(i.values()));
    r && this.pinchStart(t, r);
  }
  pinchStart(t, e) {
    const i = this.state;
    i.origin = e.origin, this.computeValues([e.distance, e.angle]), this.computeInitial(), this.compute(t), this.emit();
  }
  touchMove(t) {
    if (!this.state._active)
      return;
    const e = C(t, this.state._touchIds);
    e && this.pinchMove(t, e);
  }
  pointerMove(t) {
    const e = this.state._pointerEvents;
    if (e.has(t.pointerId) && e.set(t.pointerId, t), !this.state._active)
      return;
    const i = k(...Array.from(e.values()));
    i && this.pinchMove(t, i);
  }
  pinchMove(t, e) {
    const i = this.state, n = i._values[1], r = e.angle - n;
    let o = 0;
    Math.abs(r) > 270 && (o += Math.sign(r)), this.computeValues([e.distance, e.angle - 360 * o]), i.origin = e.origin, i.turns = o, i._movement = [i._values[0] / i._initial[0] - 1, i._values[1] - i._initial[1]], this.compute(t), this.emit();
  }
  touchEnd(t) {
    this.ctrl.setEventIds(t), this.state._active && this.state._touchIds.some((e) => !this.ctrl.touchIds.has(e)) && (this.state._active = !1, this.compute(t), this.emit());
  }
  pointerEnd(t) {
    const e = this.state;
    this.ctrl.setEventIds(t);
    try {
      t.target.releasePointerCapture(t.pointerId);
    } catch (i) {
    }
    e._pointerEvents.has(t.pointerId) && e._pointerEvents.delete(t.pointerId), e._active && e._pointerEvents.size < 2 && (e._active = !1, this.compute(t), this.emit());
  }
  gestureStart(t) {
    t.cancelable && t.preventDefault();
    const e = this.state;
    e._active || (this.start(t), this.computeValues([t.scale, t.rotation]), e.origin = [t.clientX, t.clientY], this.compute(t), this.emit());
  }
  gestureMove(t) {
    if (t.cancelable && t.preventDefault(), !this.state._active)
      return;
    const e = this.state;
    this.computeValues([t.scale, t.rotation]), e.origin = [t.clientX, t.clientY];
    const i = e._movement;
    e._movement = [t.scale - 1, t.rotation], e._delta = c.sub(e._movement, i), this.compute(t), this.emit();
  }
  gestureEnd(t) {
    this.state._active && (this.state._active = !1, this.compute(t), this.emit());
  }
  wheel(t) {
    const e = this.config.modifierKey;
    e && (Array.isArray(e) ? !e.find((i) => t[i]) : !t[e]) || (this.state._active ? this.wheelChange(t) : this.wheelStart(t), this.timeoutStore.add("wheelEnd", this.wheelEnd.bind(this)));
  }
  wheelStart(t) {
    this.start(t), this.wheelChange(t);
  }
  wheelChange(t) {
    "uv" in t || (t.cancelable && t.preventDefault(), process.env.NODE_ENV === "development" && !t.defaultPrevented && console.warn("[@use-gesture]: To properly support zoom on trackpads, try using the `target` option.\n\nThis message will only appear in development mode."));
    const i = this.state;
    i._delta = [-ot(t)[1] / kt * i.offset[0], 0], c.addTo(i._movement, i._delta), It(i), this.state.origin = [t.clientX, t.clientY], this.compute(t), this.emit();
  }
  wheelEnd() {
    this.state._active && (this.state._active = !1, this.compute(), this.emit());
  }
  bind(t) {
    const e = this.config.device;
    e && (t(e, "start", this[e + "Start"].bind(this)), t(e, "change", this[e + "Move"].bind(this)), t(e, "end", this[e + "End"].bind(this)), t(e, "cancel", this[e + "End"].bind(this)), t("lostPointerCapture", "", this[e + "End"].bind(this))), this.config.pinchOnWheel && t("wheel", "", this.wheel.bind(this), {
      passive: !1
    });
  }
}
const St = u(u({}, S), {}, {
  device(s, t, {
    shared: e,
    pointer: {
      touch: i = !1
    } = {}
  }) {
    if (e.target && !f.touch && f.gesture)
      return "gesture";
    if (f.touch && i)
      return "touch";
    if (f.touchscreen) {
      if (f.pointer)
        return "pointer";
      if (f.touch)
        return "touch";
    }
  },
  bounds(s, t, {
    scaleBounds: e = {},
    angleBounds: i = {}
  }) {
    const n = (o) => {
      const h = V(D(e, o), {
        min: -1 / 0,
        max: 1 / 0
      });
      return [h.min, h.max];
    }, r = (o) => {
      const h = V(D(i, o), {
        min: -1 / 0,
        max: 1 / 0
      });
      return [h.min, h.max];
    };
    return typeof e != "function" && typeof i != "function" ? [n(), r()] : (o) => [n(o), r(o)];
  },
  threshold(s, t, e) {
    return this.lockDirection = e.axis === "lock", c.toVector(s, this.lockDirection ? [0.1, 3] : 0);
  },
  modifierKey(s) {
    return s === void 0 ? "ctrlKey" : s;
  },
  pinchOnWheel(s = !0) {
    return s;
  }
});
u(u({}, y), {}, {
  mouseOnly: (s = !0) => s
});
u(u({}, y), {}, {
  mouseOnly: (s = !0) => s
});
const Ot = /* @__PURE__ */ new Map(), Pt = /* @__PURE__ */ new Map();
function Rt(s) {
  Ot.set(s.key, s.engine), Pt.set(s.key, s.resolver);
}
const Ut = {
  key: "drag",
  engine: dt,
  resolver: G
}, Bt = {
  key: "pinch",
  engine: xt,
  resolver: St
};
export {
  Pt as C,
  Ot as E,
  f as S,
  u as _,
  _ as a,
  Vt as b,
  Kt as c,
  Mt as d,
  Ut as e,
  Bt as f,
  x as i,
  Lt as p,
  Rt as r,
  Nt as t
};
