import { jsxs as ve, jsx as q } from "react/jsx-runtime";
import { e as dt, u as ft, a as pt, c as mt, i as ht, E as bt, B as vt, b as Et, d as yt, f as B, g as gt, A as wt } from "../../AICharacter-C0ER6vqS.js";
import { g as Pt, _ as we } from "../../index-k8aZRcq6.js";
import * as p from "react";
import { useState as ye, useRef as ze, useEffect as Q, useMemo as Ot, Suspense as Tt } from "react";
import { aq as Mt, ar as xt, as as jt, V as I, at as G, au as $, Q as Ce, a7 as ce, a8 as ue, av as ke, d as z, aw as _t } from "../../three.module-g4QKgdLf.js";
var Dt = Object.defineProperty, Lt = (r, n, a) => n in r ? Dt(r, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[n] = a, l = (r, n, a) => (Lt(r, typeof n != "symbol" ? n + "" : n, a), a);
const de = new Mt(), Ye = new xt(), Rt = Math.cos(70 * (Math.PI / 180)), Fe = (r, n) => (r % n + n) % n;
let At = class extends jt {
  constructor(n, a) {
    super(), l(this, "object"), l(this, "domElement"), l(this, "enabled", !0), l(this, "target", new I()), l(this, "minDistance", 0), l(this, "maxDistance", 1 / 0), l(this, "minZoom", 0), l(this, "maxZoom", 1 / 0), l(this, "minPolarAngle", 0), l(this, "maxPolarAngle", Math.PI), l(this, "minAzimuthAngle", -1 / 0), l(this, "maxAzimuthAngle", 1 / 0), l(this, "enableDamping", !1), l(this, "dampingFactor", 0.05), l(this, "enableZoom", !0), l(this, "zoomSpeed", 1), l(this, "enableRotate", !0), l(this, "rotateSpeed", 1), l(this, "enablePan", !0), l(this, "panSpeed", 1), l(this, "screenSpacePanning", !0), l(this, "keyPanSpeed", 7), l(this, "zoomToCursor", !1), l(this, "autoRotate", !1), l(this, "autoRotateSpeed", 2), l(this, "reverseOrbit", !1), l(this, "reverseHorizontalOrbit", !1), l(this, "reverseVerticalOrbit", !1), l(this, "keys", { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }), l(this, "mouseButtons", {
      LEFT: G.ROTATE,
      MIDDLE: G.DOLLY,
      RIGHT: G.PAN
    }), l(this, "touches", { ONE: $.ROTATE, TWO: $.DOLLY_PAN }), l(this, "target0"), l(this, "position0"), l(this, "zoom0"), l(this, "_domElementKeyEvents", null), l(this, "getPolarAngle"), l(this, "getAzimuthalAngle"), l(this, "setPolarAngle"), l(this, "setAzimuthalAngle"), l(this, "getDistance"), l(this, "listenToKeyEvents"), l(this, "stopListenToKeyEvents"), l(this, "saveState"), l(this, "reset"), l(this, "update"), l(this, "connect"), l(this, "dispose"), this.object = n, this.domElement = a, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this.getPolarAngle = () => f.phi, this.getAzimuthalAngle = () => f.theta, this.setPolarAngle = (t) => {
      let o = Fe(t, 2 * Math.PI), c = f.phi;
      c < 0 && (c += 2 * Math.PI), o < 0 && (o += 2 * Math.PI);
      let b = Math.abs(o - c);
      2 * Math.PI - b < b && (o < c ? o += 2 * Math.PI : c += 2 * Math.PI), w.phi = o - c, e.update();
    }, this.setAzimuthalAngle = (t) => {
      let o = Fe(t, 2 * Math.PI), c = f.theta;
      c < 0 && (c += 2 * Math.PI), o < 0 && (o += 2 * Math.PI);
      let b = Math.abs(o - c);
      2 * Math.PI - b < b && (o < c ? o += 2 * Math.PI : c += 2 * Math.PI), w.theta = o - c, e.update();
    }, this.getDistance = () => e.object.position.distanceTo(e.target), this.listenToKeyEvents = (t) => {
      t.addEventListener("keydown", he), this._domElementKeyEvents = t;
    }, this.stopListenToKeyEvents = () => {
      this._domElementKeyEvents.removeEventListener("keydown", he), this._domElementKeyEvents = null;
    }, this.saveState = () => {
      e.target0.copy(e.target), e.position0.copy(e.object.position), e.zoom0 = e.object.zoom;
    }, this.reset = () => {
      e.target.copy(e.target0), e.object.position.copy(e.position0), e.object.zoom = e.zoom0, e.object.updateProjectionMatrix(), e.dispatchEvent(d), e.update(), i = s.NONE;
    }, this.update = (() => {
      const t = new I(), o = new I(0, 1, 0), c = new Ce().setFromUnitVectors(n.up, o), b = c.clone().invert(), M = new I(), F = new Ce(), X = 2 * Math.PI;
      return function() {
        const Ie = e.object.position;
        c.setFromUnitVectors(n.up, o), b.copy(c).invert(), t.copy(Ie).sub(e.target), t.applyQuaternion(c), f.setFromVector3(t), e.autoRotate && i === s.NONE && K(re()), e.enableDamping ? (f.theta += w.theta * e.dampingFactor, f.phi += w.phi * e.dampingFactor) : (f.theta += w.theta, f.phi += w.phi);
        let H = e.minAzimuthAngle, U = e.maxAzimuthAngle;
        isFinite(H) && isFinite(U) && (H < -Math.PI ? H += X : H > Math.PI && (H -= X), U < -Math.PI ? U += X : U > Math.PI && (U -= X), H <= U ? f.theta = Math.max(H, Math.min(U, f.theta)) : f.theta = f.theta > (H + U) / 2 ? Math.max(H, f.theta) : Math.min(U, f.theta)), f.phi = Math.max(e.minPolarAngle, Math.min(e.maxPolarAngle, f.phi)), f.makeSafe(), e.enableDamping === !0 ? e.target.addScaledVector(D, e.dampingFactor) : e.target.add(D), e.zoomToCursor && N || e.object.isOrthographicCamera ? f.radius = W(f.radius) : f.radius = W(f.radius * x), t.setFromSpherical(f), t.applyQuaternion(b), Ie.copy(e.target).add(t), e.object.matrixAutoUpdate || e.object.updateMatrix(), e.object.lookAt(e.target), e.enableDamping === !0 ? (w.theta *= 1 - e.dampingFactor, w.phi *= 1 - e.dampingFactor, D.multiplyScalar(1 - e.dampingFactor)) : (w.set(0, 0, 0), D.set(0, 0, 0));
        let te = !1;
        if (e.zoomToCursor && N) {
          let ne = null;
          if (e.object instanceof ce && e.object.isPerspectiveCamera) {
            const oe = t.length();
            ne = W(oe * x);
            const le = oe - ne;
            e.object.position.addScaledVector(C, le), e.object.updateMatrixWorld();
          } else if (e.object.isOrthographicCamera) {
            const oe = new I(R.x, R.y, 0);
            oe.unproject(e.object), e.object.zoom = Math.max(e.minZoom, Math.min(e.maxZoom, e.object.zoom / x)), e.object.updateProjectionMatrix(), te = !0;
            const le = new I(R.x, R.y, 0);
            le.unproject(e.object), e.object.position.sub(le).add(oe), e.object.updateMatrixWorld(), ne = t.length();
          } else
            console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), e.zoomToCursor = !1;
          ne !== null && (e.screenSpacePanning ? e.target.set(0, 0, -1).transformDirection(e.object.matrix).multiplyScalar(ne).add(e.object.position) : (de.origin.copy(e.object.position), de.direction.set(0, 0, -1).transformDirection(e.object.matrix), Math.abs(e.object.up.dot(de.direction)) < Rt ? n.lookAt(e.target) : (Ye.setFromNormalAndCoplanarPoint(e.object.up, e.target), de.intersectPlane(Ye, e.target))));
        } else
          e.object instanceof ue && e.object.isOrthographicCamera && (te = x !== 1, te && (e.object.zoom = Math.max(e.minZoom, Math.min(e.maxZoom, e.object.zoom / x)), e.object.updateProjectionMatrix()));
        return x = 1, N = !1, te || M.distanceToSquared(e.object.position) > T || 8 * (1 - F.dot(e.object.quaternion)) > T ? (e.dispatchEvent(d), M.copy(e.object.position), F.copy(e.object.quaternion), te = !1, !0) : !1;
      };
    })(), this.connect = (t) => {
      t === document && console.error(
        'THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'
      ), e.domElement = t, e.domElement.style.touchAction = "none", e.domElement.addEventListener("contextmenu", Ae), e.domElement.addEventListener("pointerdown", De), e.domElement.addEventListener("pointercancel", Le), e.domElement.addEventListener("wheel", Re);
    }, this.dispose = () => {
      var t, o, c, b, M, F;
      (t = e.domElement) == null || t.removeEventListener("contextmenu", Ae), (o = e.domElement) == null || o.removeEventListener("pointerdown", De), (c = e.domElement) == null || c.removeEventListener("pointercancel", Le), (b = e.domElement) == null || b.removeEventListener("wheel", Re), (M = e.domElement) == null || M.ownerDocument.removeEventListener("pointermove", pe), (F = e.domElement) == null || F.ownerDocument.removeEventListener("pointerup", me), e._domElementKeyEvents !== null && e._domElementKeyEvents.removeEventListener("keydown", he);
    };
    const e = this, d = { type: "change" }, u = { type: "start" }, y = { type: "end" }, s = {
      NONE: -1,
      ROTATE: 0,
      DOLLY: 1,
      PAN: 2,
      TOUCH_ROTATE: 3,
      TOUCH_PAN: 4,
      TOUCH_DOLLY_PAN: 5,
      TOUCH_DOLLY_ROTATE: 6
    };
    let i = s.NONE;
    const T = 1e-6, f = new ke(), w = new ke();
    let x = 1;
    const D = new I(), P = new z(), h = new z(), j = new z(), O = new z(), g = new z(), L = new z(), _ = new z(), v = new z(), E = new z(), C = new I(), R = new z();
    let N = !1;
    const m = [], A = {};
    function re() {
      return 2 * Math.PI / 60 / 60 * e.autoRotateSpeed;
    }
    function V() {
      return Math.pow(0.95, e.zoomSpeed);
    }
    function K(t) {
      e.reverseOrbit || e.reverseHorizontalOrbit ? w.theta += t : w.theta -= t;
    }
    function ae(t) {
      e.reverseOrbit || e.reverseVerticalOrbit ? w.phi += t : w.phi -= t;
    }
    const J = (() => {
      const t = new I();
      return function(c, b) {
        t.setFromMatrixColumn(b, 0), t.multiplyScalar(-c), D.add(t);
      };
    })(), ie = (() => {
      const t = new I();
      return function(c, b) {
        e.screenSpacePanning === !0 ? t.setFromMatrixColumn(b, 1) : (t.setFromMatrixColumn(b, 0), t.crossVectors(e.object.up, t)), t.multiplyScalar(c), D.add(t);
      };
    })(), S = (() => {
      const t = new I();
      return function(c, b) {
        const M = e.domElement;
        if (M && e.object instanceof ce && e.object.isPerspectiveCamera) {
          const F = e.object.position;
          t.copy(F).sub(e.target);
          let X = t.length();
          X *= Math.tan(e.object.fov / 2 * Math.PI / 180), J(2 * c * X / M.clientHeight, e.object.matrix), ie(2 * b * X / M.clientHeight, e.object.matrix);
        } else
          M && e.object instanceof ue && e.object.isOrthographicCamera ? (J(
            c * (e.object.right - e.object.left) / e.object.zoom / M.clientWidth,
            e.object.matrix
          ), ie(
            b * (e.object.top - e.object.bottom) / e.object.zoom / M.clientHeight,
            e.object.matrix
          )) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), e.enablePan = !1);
      };
    })();
    function ee(t) {
      e.object instanceof ce && e.object.isPerspectiveCamera || e.object instanceof ue && e.object.isOrthographicCamera ? x /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), e.enableZoom = !1);
    }
    function Z(t) {
      e.object instanceof ce && e.object.isPerspectiveCamera || e.object instanceof ue && e.object.isOrthographicCamera ? x *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), e.enableZoom = !1);
    }
    function k(t) {
      if (!e.zoomToCursor || !e.domElement)
        return;
      N = !0;
      const o = e.domElement.getBoundingClientRect(), c = t.clientX - o.left, b = t.clientY - o.top, M = o.width, F = o.height;
      R.x = c / M * 2 - 1, R.y = -(b / F) * 2 + 1, C.set(R.x, R.y, 1).unproject(e.object).sub(e.object.position).normalize();
    }
    function W(t) {
      return Math.max(e.minDistance, Math.min(e.maxDistance, t));
    }
    function Y(t) {
      P.set(t.clientX, t.clientY);
    }
    function fe(t) {
      k(t), _.set(t.clientX, t.clientY);
    }
    function se(t) {
      O.set(t.clientX, t.clientY);
    }
    function $e(t) {
      h.set(t.clientX, t.clientY), j.subVectors(h, P).multiplyScalar(e.rotateSpeed);
      const o = e.domElement;
      o && (K(2 * Math.PI * j.x / o.clientHeight), ae(2 * Math.PI * j.y / o.clientHeight)), P.copy(h), e.update();
    }
    function Qe(t) {
      v.set(t.clientX, t.clientY), E.subVectors(v, _), E.y > 0 ? ee(V()) : E.y < 0 && Z(V()), _.copy(v), e.update();
    }
    function Je(t) {
      g.set(t.clientX, t.clientY), L.subVectors(g, O).multiplyScalar(e.panSpeed), S(L.x, L.y), O.copy(g), e.update();
    }
    function et(t) {
      k(t), t.deltaY < 0 ? Z(V()) : t.deltaY > 0 && ee(V()), e.update();
    }
    function tt(t) {
      let o = !1;
      switch (t.code) {
        case e.keys.UP:
          S(0, e.keyPanSpeed), o = !0;
          break;
        case e.keys.BOTTOM:
          S(0, -e.keyPanSpeed), o = !0;
          break;
        case e.keys.LEFT:
          S(e.keyPanSpeed, 0), o = !0;
          break;
        case e.keys.RIGHT:
          S(-e.keyPanSpeed, 0), o = !0;
          break;
      }
      o && (t.preventDefault(), e.update());
    }
    function Oe() {
      if (m.length == 1)
        P.set(m[0].pageX, m[0].pageY);
      else {
        const t = 0.5 * (m[0].pageX + m[1].pageX), o = 0.5 * (m[0].pageY + m[1].pageY);
        P.set(t, o);
      }
    }
    function Te() {
      if (m.length == 1)
        O.set(m[0].pageX, m[0].pageY);
      else {
        const t = 0.5 * (m[0].pageX + m[1].pageX), o = 0.5 * (m[0].pageY + m[1].pageY);
        O.set(t, o);
      }
    }
    function Me() {
      const t = m[0].pageX - m[1].pageX, o = m[0].pageY - m[1].pageY, c = Math.sqrt(t * t + o * o);
      _.set(0, c);
    }
    function nt() {
      e.enableZoom && Me(), e.enablePan && Te();
    }
    function ot() {
      e.enableZoom && Me(), e.enableRotate && Oe();
    }
    function xe(t) {
      if (m.length == 1)
        h.set(t.pageX, t.pageY);
      else {
        const c = be(t), b = 0.5 * (t.pageX + c.x), M = 0.5 * (t.pageY + c.y);
        h.set(b, M);
      }
      j.subVectors(h, P).multiplyScalar(e.rotateSpeed);
      const o = e.domElement;
      o && (K(2 * Math.PI * j.x / o.clientHeight), ae(2 * Math.PI * j.y / o.clientHeight)), P.copy(h);
    }
    function je(t) {
      if (m.length == 1)
        g.set(t.pageX, t.pageY);
      else {
        const o = be(t), c = 0.5 * (t.pageX + o.x), b = 0.5 * (t.pageY + o.y);
        g.set(c, b);
      }
      L.subVectors(g, O).multiplyScalar(e.panSpeed), S(L.x, L.y), O.copy(g);
    }
    function _e(t) {
      const o = be(t), c = t.pageX - o.x, b = t.pageY - o.y, M = Math.sqrt(c * c + b * b);
      v.set(0, M), E.set(0, Math.pow(v.y / _.y, e.zoomSpeed)), ee(E.y), _.copy(v);
    }
    function rt(t) {
      e.enableZoom && _e(t), e.enablePan && je(t);
    }
    function at(t) {
      e.enableZoom && _e(t), e.enableRotate && xe(t);
    }
    function De(t) {
      var o, c;
      e.enabled !== !1 && (m.length === 0 && ((o = e.domElement) == null || o.ownerDocument.addEventListener("pointermove", pe), (c = e.domElement) == null || c.ownerDocument.addEventListener("pointerup", me)), ut(t), t.pointerType === "touch" ? lt(t) : it(t));
    }
    function pe(t) {
      e.enabled !== !1 && (t.pointerType === "touch" ? ct(t) : st(t));
    }
    function me(t) {
      var o, c, b;
      Ne(t), m.length === 0 && ((o = e.domElement) == null || o.releasePointerCapture(t.pointerId), (c = e.domElement) == null || c.ownerDocument.removeEventListener("pointermove", pe), (b = e.domElement) == null || b.ownerDocument.removeEventListener("pointerup", me)), e.dispatchEvent(y), i = s.NONE;
    }
    function Le(t) {
      Ne(t);
    }
    function it(t) {
      let o;
      switch (t.button) {
        case 0:
          o = e.mouseButtons.LEFT;
          break;
        case 1:
          o = e.mouseButtons.MIDDLE;
          break;
        case 2:
          o = e.mouseButtons.RIGHT;
          break;
        default:
          o = -1;
      }
      switch (o) {
        case G.DOLLY:
          if (e.enableZoom === !1)
            return;
          fe(t), i = s.DOLLY;
          break;
        case G.ROTATE:
          if (t.ctrlKey || t.metaKey || t.shiftKey) {
            if (e.enablePan === !1)
              return;
            se(t), i = s.PAN;
          } else {
            if (e.enableRotate === !1)
              return;
            Y(t), i = s.ROTATE;
          }
          break;
        case G.PAN:
          if (t.ctrlKey || t.metaKey || t.shiftKey) {
            if (e.enableRotate === !1)
              return;
            Y(t), i = s.ROTATE;
          } else {
            if (e.enablePan === !1)
              return;
            se(t), i = s.PAN;
          }
          break;
        default:
          i = s.NONE;
      }
      i !== s.NONE && e.dispatchEvent(u);
    }
    function st(t) {
      if (e.enabled !== !1)
        switch (i) {
          case s.ROTATE:
            if (e.enableRotate === !1)
              return;
            $e(t);
            break;
          case s.DOLLY:
            if (e.enableZoom === !1)
              return;
            Qe(t);
            break;
          case s.PAN:
            if (e.enablePan === !1)
              return;
            Je(t);
            break;
        }
    }
    function Re(t) {
      e.enabled === !1 || e.enableZoom === !1 || i !== s.NONE && i !== s.ROTATE || (t.preventDefault(), e.dispatchEvent(u), et(t), e.dispatchEvent(y));
    }
    function he(t) {
      e.enabled === !1 || e.enablePan === !1 || tt(t);
    }
    function lt(t) {
      switch (Se(t), m.length) {
        case 1:
          switch (e.touches.ONE) {
            case $.ROTATE:
              if (e.enableRotate === !1)
                return;
              Oe(), i = s.TOUCH_ROTATE;
              break;
            case $.PAN:
              if (e.enablePan === !1)
                return;
              Te(), i = s.TOUCH_PAN;
              break;
            default:
              i = s.NONE;
          }
          break;
        case 2:
          switch (e.touches.TWO) {
            case $.DOLLY_PAN:
              if (e.enableZoom === !1 && e.enablePan === !1)
                return;
              nt(), i = s.TOUCH_DOLLY_PAN;
              break;
            case $.DOLLY_ROTATE:
              if (e.enableZoom === !1 && e.enableRotate === !1)
                return;
              ot(), i = s.TOUCH_DOLLY_ROTATE;
              break;
            default:
              i = s.NONE;
          }
          break;
        default:
          i = s.NONE;
      }
      i !== s.NONE && e.dispatchEvent(u);
    }
    function ct(t) {
      switch (Se(t), i) {
        case s.TOUCH_ROTATE:
          if (e.enableRotate === !1)
            return;
          xe(t), e.update();
          break;
        case s.TOUCH_PAN:
          if (e.enablePan === !1)
            return;
          je(t), e.update();
          break;
        case s.TOUCH_DOLLY_PAN:
          if (e.enableZoom === !1 && e.enablePan === !1)
            return;
          rt(t), e.update();
          break;
        case s.TOUCH_DOLLY_ROTATE:
          if (e.enableZoom === !1 && e.enableRotate === !1)
            return;
          at(t), e.update();
          break;
        default:
          i = s.NONE;
      }
    }
    function Ae(t) {
      e.enabled !== !1 && t.preventDefault();
    }
    function ut(t) {
      m.push(t);
    }
    function Ne(t) {
      delete A[t.pointerId];
      for (let o = 0; o < m.length; o++)
        if (m[o].pointerId == t.pointerId) {
          m.splice(o, 1);
          return;
        }
    }
    function Se(t) {
      let o = A[t.pointerId];
      o === void 0 && (o = new z(), A[t.pointerId] = o), o.set(t.pageX, t.pageY);
    }
    function be(t) {
      const o = t.pointerId === m[0].pointerId ? m[1] : m[0];
      return A[o.pointerId];
    }
    a !== void 0 && this.connect(a), this.update();
  }
};
function ge(r, n, a) {
  var e, d, u, y, s;
  n == null && (n = 100);
  function i() {
    var f = Date.now() - y;
    f < n && f >= 0 ? e = setTimeout(i, n - f) : (e = null, a || (s = r.apply(u, d), u = d = null));
  }
  var T = function() {
    u = this, d = arguments, y = Date.now();
    var f = a && !e;
    return e || (e = setTimeout(i, n)), f && (s = r.apply(u, d), u = d = null), s;
  };
  return T.clear = function() {
    e && (clearTimeout(e), e = null);
  }, T.flush = function() {
    e && (s = r.apply(u, d), u = d = null, clearTimeout(e), e = null);
  }, T;
}
ge.debounce = ge;
var Nt = ge;
const He = /* @__PURE__ */ Pt(Nt);
function St(r) {
  let {
    debounce: n,
    scroll: a,
    polyfill: e,
    offsetSize: d
  } = r === void 0 ? {
    debounce: 0,
    scroll: !1,
    offsetSize: !1
  } : r;
  const u = e || (typeof window > "u" ? class {
  } : window.ResizeObserver);
  if (!u)
    throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
  const [y, s] = ye({
    left: 0,
    top: 0,
    width: 0,
    height: 0,
    bottom: 0,
    right: 0,
    x: 0,
    y: 0
  }), i = ze({
    element: null,
    scrollContainers: null,
    resizeObserver: null,
    lastBounds: y
  }), T = n ? typeof n == "number" ? n : n.scroll : null, f = n ? typeof n == "number" ? n : n.resize : null, w = ze(!1);
  Q(() => (w.current = !0, () => void (w.current = !1)));
  const [x, D, P] = Ot(() => {
    const g = () => {
      if (!i.current.element)
        return;
      const {
        left: L,
        top: _,
        width: v,
        height: E,
        bottom: C,
        right: R,
        x: N,
        y: m
      } = i.current.element.getBoundingClientRect(), A = {
        left: L,
        top: _,
        width: v,
        height: E,
        bottom: C,
        right: R,
        x: N,
        y: m
      };
      i.current.element instanceof HTMLElement && d && (A.height = i.current.element.offsetHeight, A.width = i.current.element.offsetWidth), Object.freeze(A), w.current && !kt(i.current.lastBounds, A) && s(i.current.lastBounds = A);
    };
    return [g, f ? He(g, f) : g, T ? He(g, T) : g];
  }, [s, d, T, f]);
  function h() {
    i.current.scrollContainers && (i.current.scrollContainers.forEach((g) => g.removeEventListener("scroll", P, !0)), i.current.scrollContainers = null), i.current.resizeObserver && (i.current.resizeObserver.disconnect(), i.current.resizeObserver = null);
  }
  function j() {
    i.current.element && (i.current.resizeObserver = new u(P), i.current.resizeObserver.observe(i.current.element), a && i.current.scrollContainers && i.current.scrollContainers.forEach((g) => g.addEventListener("scroll", P, {
      capture: !0,
      passive: !0
    })));
  }
  const O = (g) => {
    !g || g === i.current.element || (h(), i.current.element = g, i.current.scrollContainers = Ke(g), j());
  };
  return zt(P, !!a), It(D), Q(() => {
    h(), j();
  }, [a, P, D]), Q(() => h, []), [O, y, x];
}
function It(r) {
  Q(() => {
    const n = r;
    return window.addEventListener("resize", n), () => void window.removeEventListener("resize", n);
  }, [r]);
}
function zt(r, n) {
  Q(() => {
    if (n) {
      const a = r;
      return window.addEventListener("scroll", a, {
        capture: !0,
        passive: !0
      }), () => void window.removeEventListener("scroll", a, !0);
    }
  }, [r, n]);
}
function Ke(r) {
  const n = [];
  if (!r || r === document.body)
    return n;
  const {
    overflow: a,
    overflowX: e,
    overflowY: d
  } = window.getComputedStyle(r);
  return [a, e, d].some((u) => u === "auto" || u === "scroll") && n.push(r), [...n, ...Ke(r.parentElement)];
}
const Ct = ["x", "y", "top", "bottom", "left", "right", "width", "height"], kt = (r, n) => Ct.every((a) => r[a] === n[a]);
var Yt = Object.defineProperty, Ft = Object.defineProperties, Ht = Object.getOwnPropertyDescriptors, Ue = Object.getOwnPropertySymbols, Ut = Object.prototype.hasOwnProperty, Zt = Object.prototype.propertyIsEnumerable, Ze = (r, n, a) => n in r ? Yt(r, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[n] = a, Xe = (r, n) => {
  for (var a in n || (n = {}))
    Ut.call(n, a) && Ze(r, a, n[a]);
  if (Ue)
    for (var a of Ue(n))
      Zt.call(n, a) && Ze(r, a, n[a]);
  return r;
}, Xt = (r, n) => Ft(r, Ht(n));
function We(r, n, a) {
  if (!r)
    return;
  if (a(r) === !0)
    return r;
  let e = n ? r.return : r.child;
  for (; e; ) {
    const d = We(e, n, a);
    if (d)
      return d;
    e = n ? null : e.sibling;
  }
}
function qe(r) {
  try {
    return Object.defineProperties(r, {
      _currentRenderer: {
        get() {
          return null;
        },
        set() {
        }
      },
      _currentRenderer2: {
        get() {
          return null;
        },
        set() {
        }
      }
    });
  } catch {
    return r;
  }
}
const Pe = qe(p.createContext(null));
class Ge extends p.Component {
  render() {
    return /* @__PURE__ */ p.createElement(Pe.Provider, {
      value: this._reactInternals
    }, this.props.children);
  }
}
const { ReactCurrentOwner: Be, ReactCurrentDispatcher: Ve } = p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function Bt() {
  const r = p.useContext(Pe);
  if (r === null)
    throw new Error("its-fine: useFiber must be called within a <FiberProvider />!");
  const n = p.useId();
  return p.useMemo(() => {
    for (const e of [Be == null ? void 0 : Be.current, r, r == null ? void 0 : r.alternate]) {
      if (!e)
        continue;
      const d = We(e, !1, (u) => {
        let y = u.memoizedState;
        for (; y; ) {
          if (y.memoizedState === n)
            return !0;
          y = y.next;
        }
      });
      if (d)
        return d;
    }
  }, [r, n]);
}
function Vt() {
  var r, n;
  const a = Bt(), [e] = p.useState(() => /* @__PURE__ */ new Map());
  e.clear();
  let d = a;
  for (; d; ) {
    const u = (r = d.type) == null ? void 0 : r._context;
    u && u !== Pe && !e.has(u) && e.set(u, (n = Ve == null ? void 0 : Ve.current) == null ? void 0 : n.readContext(qe(u))), d = d.return;
  }
  return e;
}
function Kt() {
  const r = Vt();
  return p.useMemo(
    () => Array.from(r.keys()).reduce(
      (n, a) => (e) => /* @__PURE__ */ p.createElement(n, null, /* @__PURE__ */ p.createElement(a.Provider, Xt(Xe({}, e), {
        value: r.get(a)
      }))),
      (n) => /* @__PURE__ */ p.createElement(Ge, Xe({}, n))
    ),
    [r]
  );
}
const Ee = {
  onClick: ["click", !1],
  onContextMenu: ["contextmenu", !1],
  onDoubleClick: ["dblclick", !1],
  onWheel: ["wheel", !0],
  onPointerDown: ["pointerdown", !0],
  onPointerUp: ["pointerup", !0],
  onPointerLeave: ["pointerleave", !0],
  onPointerMove: ["pointermove", !0],
  onPointerCancel: ["pointercancel", !0],
  onLostPointerCapture: ["lostpointercapture", !0]
};
function Wt(r) {
  const {
    handlePointer: n
  } = yt(r);
  return {
    priority: 1,
    enabled: !0,
    compute(a, e, d) {
      e.pointer.set(a.offsetX / e.size.width * 2 - 1, -(a.offsetY / e.size.height) * 2 + 1), e.raycaster.setFromCamera(e.pointer, e.camera);
    },
    connected: void 0,
    handlers: Object.keys(Ee).reduce((a, e) => ({
      ...a,
      [e]: n(e)
    }), {}),
    update: () => {
      var a;
      const {
        events: e,
        internal: d
      } = r.getState();
      (a = d.lastEvent) != null && a.current && e.handlers && e.handlers.onPointerMove(d.lastEvent.current);
    },
    connect: (a) => {
      var e;
      const {
        set: d,
        events: u
      } = r.getState();
      u.disconnect == null || u.disconnect(), d((y) => ({
        events: {
          ...y.events,
          connected: a
        }
      })), Object.entries((e = u.handlers) != null ? e : []).forEach(([y, s]) => {
        const [i, T] = Ee[y];
        a.addEventListener(i, s, {
          passive: T
        });
      });
    },
    disconnect: () => {
      const {
        set: a,
        events: e
      } = r.getState();
      if (e.connected) {
        var d;
        Object.entries((d = e.handlers) != null ? d : []).forEach(([u, y]) => {
          if (e && e.connected instanceof HTMLElement) {
            const [s] = Ee[u];
            e.connected.removeEventListener(s, y);
          }
        }), a((u) => ({
          events: {
            ...u.events,
            connected: void 0
          }
        }));
      }
    }
  };
}
const qt = /* @__PURE__ */ p.forwardRef(function({
  children: n,
  fallback: a,
  resize: e,
  style: d,
  gl: u,
  events: y = Wt,
  eventSource: s,
  eventPrefix: i,
  shadows: T,
  linear: f,
  flat: w,
  legacy: x,
  orthographic: D,
  frameloop: P,
  dpr: h,
  performance: j,
  raycaster: O,
  camera: g,
  scene: L,
  onPointerMissed: _,
  onCreated: v,
  ...E
}, C) {
  p.useMemo(() => dt(_t), []);
  const R = Kt(), [N, m] = St({
    scroll: !0,
    debounce: {
      scroll: 50,
      resize: 0
    },
    ...e
  }), A = p.useRef(null), re = p.useRef(null);
  p.useImperativeHandle(C, () => A.current);
  const V = ft(_), [K, ae] = p.useState(!1), [J, ie] = p.useState(!1);
  if (K)
    throw K;
  if (J)
    throw J;
  const S = p.useRef(null);
  pt(() => {
    const Z = A.current;
    m.width > 0 && m.height > 0 && Z && (S.current || (S.current = mt(Z)), S.current.configure({
      gl: u,
      events: y,
      shadows: T,
      linear: f,
      flat: w,
      legacy: x,
      orthographic: D,
      frameloop: P,
      dpr: h,
      performance: j,
      raycaster: O,
      camera: g,
      scene: L,
      size: m,
      // Pass mutable reference to onPointerMissed so it's free to update
      onPointerMissed: (...k) => V.current == null ? void 0 : V.current(...k),
      onCreated: (k) => {
        k.events.connect == null || k.events.connect(s ? ht(s) ? s.current : s : re.current), i && k.setEvents({
          compute: (W, Y) => {
            const fe = W[i + "X"], se = W[i + "Y"];
            Y.pointer.set(fe / Y.size.width * 2 - 1, -(se / Y.size.height) * 2 + 1), Y.raycaster.setFromCamera(Y.pointer, Y.camera);
          }
        }), v == null || v(k);
      }
    }), S.current.render(/* @__PURE__ */ p.createElement(R, null, /* @__PURE__ */ p.createElement(bt, {
      set: ie
    }, /* @__PURE__ */ p.createElement(p.Suspense, {
      fallback: /* @__PURE__ */ p.createElement(vt, {
        set: ae
      })
    }, n)))));
  }), p.useEffect(() => {
    const Z = A.current;
    if (Z)
      return () => Et(Z);
  }, []);
  const ee = s ? "none" : "auto";
  return /* @__PURE__ */ p.createElement("div", we({
    ref: re,
    style: {
      position: "relative",
      width: "100%",
      height: "100%",
      overflow: "hidden",
      pointerEvents: ee,
      ...d
    }
  }, E), /* @__PURE__ */ p.createElement("div", {
    ref: N,
    style: {
      width: "100%",
      height: "100%"
    }
  }, /* @__PURE__ */ p.createElement("canvas", {
    ref: A,
    style: {
      display: "block"
    }
  }, a)));
}), Gt = /* @__PURE__ */ p.forwardRef(function(n, a) {
  return /* @__PURE__ */ p.createElement(Ge, null, /* @__PURE__ */ p.createElement(qt, we({}, n, {
    ref: a
  })));
}), $t = /* @__PURE__ */ p.forwardRef(({
  makeDefault: r,
  camera: n,
  regress: a,
  domElement: e,
  enableDamping: d = !0,
  keyEvents: u = !1,
  onChange: y,
  onStart: s,
  onEnd: i,
  ...T
}, f) => {
  const w = B((E) => E.invalidate), x = B((E) => E.camera), D = B((E) => E.gl), P = B((E) => E.events), h = B((E) => E.setEvents), j = B((E) => E.set), O = B((E) => E.get), g = B((E) => E.performance), L = n || x, _ = e || P.connected || D.domElement, v = p.useMemo(() => new At(L), [L]);
  return gt(() => {
    v.enabled && v.update();
  }, -1), p.useEffect(() => (u && v.connect(u === !0 ? _ : u), v.connect(_), () => void v.dispose()), [u, _, a, v, w]), p.useEffect(() => {
    const E = (N) => {
      w(), a && g.regress(), y && y(N);
    }, C = (N) => {
      s && s(N);
    }, R = (N) => {
      i && i(N);
    };
    return v.addEventListener("change", E), v.addEventListener("start", C), v.addEventListener("end", R), () => {
      v.removeEventListener("start", C), v.removeEventListener("end", R), v.removeEventListener("change", E);
    };
  }, [y, s, i, v, w, h]), p.useEffect(() => {
    if (r) {
      const E = O().controls;
      return j({
        controls: v
      }), () => j({
        controls: E
      });
    }
  }, [r, v]), /* @__PURE__ */ p.createElement("primitive", we({
    ref: f,
    object: v,
    enableDamping: d
  }, T));
}), sn = ({
  animation: r,
  modelUrl: n,
  onAudioEnd: a,
  aside: e,
  speakCount: d = 0,
  emotion: u,
  zoom: y,
  position: s,
  loadingText: i,
  modelConfigs: T,
  currentVrm: f,
  setCurrentVrm: w,
  onProgressChange: x,
  onLoadErr: D,
  scale: P,
  sceneConfigs: h,
  LoadingComponent: j
}) => {
  const [O, g] = ye(0), [L, _] = ye();
  return Q(() => {
    x && x(O);
  }, [O]), /* @__PURE__ */ ve(
    "div",
    {
      className: "virtual-lg:rounded-3xl virtual-flex virtual-relative virtual-items-center virtual-justify-center virtual-h-full virtual-w-full",
      children: [
        j ? n === "" || O >= 100 ? void 0 : j : /* @__PURE__ */ ve(
          "div",
          {
            className: `virtual-absolute virtual-top-1/2 virtual-left-1/2 virtual--translate-x-1/2 virtual--translate-y-1/2 virtual-rounded-2xl virtual-px-4 virtual-py-2 virtual-bg-black/30 virtual-flex virtual-items-center virtual-justify-center virtual-pointer-events-none virtual-flex-col ${n === "" || O >= 100 ? "virtual-fadeOut" : ""}`,
            children: [
              /* @__PURE__ */ q(
                "p",
                {
                  className: "virtual-font-wenhei virtual-text-lg virtual-text-white virtual-animate-flicker virtual-text-center virtual-w-fit",
                  children: `${i ?? "Your Virtual is Dressing Up..."}`
                }
              ),
              /* @__PURE__ */ q("div", { className: "virtual-bg-white/20 virtual-h-[4px] virtual-w-[80%] virtual-rounded-3xl virtual-mb-2 virtual-mt-4", children: /* @__PURE__ */ q(
                "div",
                {
                  className: "virtual-bg-white virtual-h-[4px] virtual-rounded-3xl",
                  style: {
                    width: `${O}%`
                  }
                }
              ) })
            ]
          }
        ),
        /* @__PURE__ */ q(Tt, { fallback: null, children: /* @__PURE__ */ ve(
          Gt,
          {
            camera: {
              position: [0, 3, 15],
              zoom: y || 2
            },
            linear: (h == null ? void 0 : h.linear) ?? !0,
            flat: (h == null ? void 0 : h.flat) ?? !0,
            shadows: (h == null ? void 0 : h.shadows) ?? !0,
            children: [
              /* @__PURE__ */ q(
                $t,
                {
                  makeDefault: (h == null ? void 0 : h.enableZoom) ?? !0,
                  enabled: (h == null ? void 0 : h.enableZoom) ?? !0,
                  maxDistance: 40,
                  minDistance: 5
                }
              ),
              !!n && /* @__PURE__ */ q(
                wt,
                {
                  sceneConfigs: h,
                  animation: r,
                  url: n,
                  speakCount: d,
                  onAudioEnd: a,
                  onLoad: (v) => {
                    g(v);
                  },
                  zoom: y ?? 2,
                  aside: e,
                  emotion: u,
                  position: s,
                  modelConfigs: T,
                  currentVrm: f || L,
                  setCurrentVrm: w || _,
                  onLoadErr: D,
                  scale: P
                }
              )
            ]
          }
        ) })
      ]
    }
  );
};
export {
  sn as CharacterScene
};
