@guoquan.net/flow-engine 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/flow.es.js CHANGED
@@ -1,8 +1,8 @@
1
- import * as n from "three";
2
- import { Controls as v, Vector3 as _, MOUSE as b, TOUCH as y, Quaternion as T, Spherical as S, Vector2 as m, Ray as x, Plane as N, MathUtils as I } from "three";
3
- import { WebGPURenderer as j } from "three/webgpu";
4
- import { GLTFLoader as k } from "three/examples/jsm/loaders/GLTFLoader.js";
5
- const L = { type: "change" }, A = { type: "start" }, R = { type: "end" }, E = new x(), C = new N(), H = Math.cos(70 * I.DEG2RAD), d = new _(), p = 2 * Math.PI, l = {
1
+ import * as d from "three";
2
+ import { Controls as Nt, Vector3 as R, MOUSE as K, TOUCH as W, Quaternion as Ae, Spherical as Ze, Vector2 as C, Ray as Rt, Plane as Lt, MathUtils as jt } from "three";
3
+ import { WebGPURenderer as xt } from "three/webgpu";
4
+ import { GLTFLoader as nt } from "three/examples/jsm/loaders/GLTFLoader.js";
5
+ const Ie = { type: "change" }, be = { type: "start" }, ot = { type: "end" }, q = new Rt(), $e = new Lt(), Ft = Math.cos(70 * jt.DEG2RAD), E = new R(), Z = 2 * Math.PI, b = {
6
6
  NONE: -1,
7
7
  ROTATE: 0,
8
8
  DOLLY: 1,
@@ -11,16 +11,16 @@ const L = { type: "change" }, A = { type: "start" }, R = { type: "end" }, E = ne
11
11
  TOUCH_PAN: 4,
12
12
  TOUCH_DOLLY_PAN: 5,
13
13
  TOUCH_DOLLY_ROTATE: 6
14
- }, D = 1e-6;
15
- class U extends v {
14
+ }, de = 1e-6;
15
+ class Ut extends Nt {
16
16
  /**
17
17
  * Constructs a new controls instance.
18
18
  *
19
19
  * @param {Object3D} object - The object that is managed by the controls.
20
20
  * @param {?HTMLElement} domElement - The HTML element used for event listeners.
21
21
  */
22
- constructor(t, e = null) {
23
- super(t, e), this.state = l.NONE, this.target = new _(), this.cursor = new _(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: b.ROTATE, MIDDLE: b.DOLLY, RIGHT: b.PAN }, this.touches = { ONE: y.ROTATE, TWO: y.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new _(), this._lastQuaternion = new T(), this._lastTargetPosition = new _(), this._quat = new T().setFromUnitVectors(t.up, new _(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new S(), this._sphericalDelta = new S(), this._scale = 1, this._panOffset = new _(), this._rotateStart = new m(), this._rotateEnd = new m(), this._rotateDelta = new m(), this._panStart = new m(), this._panEnd = new m(), this._panDelta = new m(), this._dollyStart = new m(), this._dollyEnd = new m(), this._dollyDelta = new m(), this._dollyDirection = new _(), this._mouse = new m(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = F.bind(this), this._onPointerDown = Y.bind(this), this._onPointerUp = z.bind(this), this._onContextMenu = X.bind(this), this._onMouseWheel = W.bind(this), this._onKeyDown = Z.bind(this), this._onTouchStart = B.bind(this), this._onTouchMove = Q.bind(this), this._onMouseDown = G.bind(this), this._onMouseMove = K.bind(this), this._interceptControlDown = V.bind(this), this._interceptControlUp = q.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
22
+ constructor(t, n = null) {
23
+ super(t, n), this.state = b.NONE, this.target = new R(), this.cursor = new R(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: K.ROTATE, MIDDLE: K.DOLLY, RIGHT: K.PAN }, this.touches = { ONE: W.ROTATE, TWO: W.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new R(), this._lastQuaternion = new Ae(), this._lastTargetPosition = new R(), this._quat = new Ae().setFromUnitVectors(t.up, new R(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new Ze(), this._sphericalDelta = new Ze(), this._scale = 1, this._panOffset = new R(), this._rotateStart = new C(), this._rotateEnd = new C(), this._rotateDelta = new C(), this._panStart = new C(), this._panEnd = new C(), this._panDelta = new C(), this._dollyStart = new C(), this._dollyEnd = new C(), this._dollyDelta = new C(), this._dollyDirection = new R(), this._mouse = new C(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = Vt.bind(this), this._onPointerDown = Gt.bind(this), this._onPointerUp = Wt.bind(this), this._onContextMenu = Qt.bind(this), this._onMouseWheel = Bt.bind(this), this._onKeyDown = Yt.bind(this), this._onTouchStart = Jt.bind(this), this._onTouchMove = Xt.bind(this), this._onMouseDown = Ht.bind(this), this._onMouseMove = Kt.bind(this), this._interceptControlDown = qt.bind(this), this._interceptControlUp = en.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
24
24
  }
25
25
  connect(t) {
26
26
  super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
@@ -81,49 +81,49 @@ class U extends v {
81
81
  * was called, or the initial state.
82
82
  */
83
83
  reset() {
84
- this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(L), this.update(), this.state = l.NONE;
84
+ this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(Ie), this.update(), this.state = b.NONE;
85
85
  }
86
86
  update(t = null) {
87
- const e = this.object.position;
88
- d.copy(e).sub(this.target), d.applyQuaternion(this._quat), this._spherical.setFromVector3(d), this.autoRotate && this.state === l.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
89
- let i = this.minAzimuthAngle, s = this.maxAzimuthAngle;
90
- isFinite(i) && isFinite(s) && (i < -Math.PI ? i += p : i > Math.PI && (i -= p), s < -Math.PI ? s += p : s > Math.PI && (s -= p), i <= s ? this._spherical.theta = Math.max(i, Math.min(s, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (i + s) / 2 ? Math.max(i, this._spherical.theta) : Math.min(s, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
91
- let a = !1;
87
+ const n = this.object.position;
88
+ E.copy(n).sub(this.target), E.applyQuaternion(this._quat), this._spherical.setFromVector3(E), this.autoRotate && this.state === b.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
89
+ let o = this.minAzimuthAngle, r = this.maxAzimuthAngle;
90
+ isFinite(o) && isFinite(r) && (o < -Math.PI ? o += Z : o > Math.PI && (o -= Z), r < -Math.PI ? r += Z : r > Math.PI && (r -= Z), o <= r ? this._spherical.theta = Math.max(o, Math.min(r, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (o + r) / 2 ? Math.max(o, this._spherical.theta) : Math.min(r, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
91
+ let i = !1;
92
92
  if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
93
93
  this._spherical.radius = this._clampDistance(this._spherical.radius);
94
94
  else {
95
- const r = this._spherical.radius;
96
- this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), a = r != this._spherical.radius;
95
+ const s = this._spherical.radius;
96
+ this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), i = s != this._spherical.radius;
97
97
  }
98
- if (d.setFromSpherical(this._spherical), d.applyQuaternion(this._quatInverse), e.copy(this.target).add(d), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
99
- let r = null;
98
+ if (E.setFromSpherical(this._spherical), E.applyQuaternion(this._quatInverse), n.copy(this.target).add(E), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
99
+ let s = null;
100
100
  if (this.object.isPerspectiveCamera) {
101
- const h = d.length();
102
- r = this._clampDistance(h * this._scale);
103
- const c = h - r;
104
- this.object.position.addScaledVector(this._dollyDirection, c), this.object.updateMatrixWorld(), a = !!c;
101
+ const a = E.length();
102
+ s = this._clampDistance(a * this._scale);
103
+ const c = a - s;
104
+ this.object.position.addScaledVector(this._dollyDirection, c), this.object.updateMatrixWorld(), i = !!c;
105
105
  } else if (this.object.isOrthographicCamera) {
106
- const h = new _(this._mouse.x, this._mouse.y, 0);
107
- h.unproject(this.object);
106
+ const a = new R(this._mouse.x, this._mouse.y, 0);
107
+ a.unproject(this.object);
108
108
  const c = this.object.zoom;
109
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), a = c !== this.object.zoom;
110
- const f = new _(this._mouse.x, this._mouse.y, 0);
111
- f.unproject(this.object), this.object.position.sub(f).add(h), this.object.updateMatrixWorld(), r = d.length();
109
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), i = c !== this.object.zoom;
110
+ const l = new R(this._mouse.x, this._mouse.y, 0);
111
+ l.unproject(this.object), this.object.position.sub(l).add(a), this.object.updateMatrixWorld(), s = E.length();
112
112
  } else
113
113
  console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
114
- r !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(r).add(this.object.position) : (E.origin.copy(this.object.position), E.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(E.direction)) < H ? this.object.lookAt(this.target) : (C.setFromNormalAndCoplanarPoint(this.object.up, this.target), E.intersectPlane(C, this.target))));
114
+ s !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(s).add(this.object.position) : (q.origin.copy(this.object.position), q.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(q.direction)) < Ft ? this.object.lookAt(this.target) : ($e.setFromNormalAndCoplanarPoint(this.object.up, this.target), q.intersectPlane($e, this.target))));
115
115
  } else if (this.object.isOrthographicCamera) {
116
- const r = this.object.zoom;
117
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), r !== this.object.zoom && (this.object.updateProjectionMatrix(), a = !0);
116
+ const s = this.object.zoom;
117
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), s !== this.object.zoom && (this.object.updateProjectionMatrix(), i = !0);
118
118
  }
119
- return this._scale = 1, this._performCursorZoom = !1, a || this._lastPosition.distanceToSquared(this.object.position) > D || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > D || this._lastTargetPosition.distanceToSquared(this.target) > D ? (this.dispatchEvent(L), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
119
+ return this._scale = 1, this._performCursorZoom = !1, i || this._lastPosition.distanceToSquared(this.object.position) > de || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > de || this._lastTargetPosition.distanceToSquared(this.target) > de ? (this.dispatchEvent(Ie), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
120
120
  }
121
121
  _getAutoRotationAngle(t) {
122
- return t !== null ? p / 60 * this.autoRotateSpeed * t : p / 60 / 60 * this.autoRotateSpeed;
122
+ return t !== null ? Z / 60 * this.autoRotateSpeed * t : Z / 60 / 60 * this.autoRotateSpeed;
123
123
  }
124
124
  _getZoomScale(t) {
125
- const e = Math.abs(t * 0.01);
126
- return Math.pow(0.95, this.zoomSpeed * e);
125
+ const n = Math.abs(t * 0.01);
126
+ return Math.pow(0.95, this.zoomSpeed * n);
127
127
  }
128
128
  _rotateLeft(t) {
129
129
  this._sphericalDelta.theta -= t;
@@ -131,21 +131,21 @@ class U extends v {
131
131
  _rotateUp(t) {
132
132
  this._sphericalDelta.phi -= t;
133
133
  }
134
- _panLeft(t, e) {
135
- d.setFromMatrixColumn(e, 0), d.multiplyScalar(-t), this._panOffset.add(d);
134
+ _panLeft(t, n) {
135
+ E.setFromMatrixColumn(n, 0), E.multiplyScalar(-t), this._panOffset.add(E);
136
136
  }
137
- _panUp(t, e) {
138
- this.screenSpacePanning === !0 ? d.setFromMatrixColumn(e, 1) : (d.setFromMatrixColumn(e, 0), d.crossVectors(this.object.up, d)), d.multiplyScalar(t), this._panOffset.add(d);
137
+ _panUp(t, n) {
138
+ this.screenSpacePanning === !0 ? E.setFromMatrixColumn(n, 1) : (E.setFromMatrixColumn(n, 0), E.crossVectors(this.object.up, E)), E.multiplyScalar(t), this._panOffset.add(E);
139
139
  }
140
140
  // deltaX and deltaY are in pixels; right and down are positive
141
- _pan(t, e) {
142
- const i = this.domElement;
141
+ _pan(t, n) {
142
+ const o = this.domElement;
143
143
  if (this.object.isPerspectiveCamera) {
144
- const s = this.object.position;
145
- d.copy(s).sub(this.target);
146
- let a = d.length();
147
- a *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * a / i.clientHeight, this.object.matrix), this._panUp(2 * e * a / i.clientHeight, this.object.matrix);
148
- } else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / i.clientWidth, this.object.matrix), this._panUp(e * (this.object.top - this.object.bottom) / this.object.zoom / i.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
144
+ const r = this.object.position;
145
+ E.copy(r).sub(this.target);
146
+ let i = E.length();
147
+ i *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * i / o.clientHeight, this.object.matrix), this._panUp(2 * n * i / o.clientHeight, this.object.matrix);
148
+ } else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / o.clientWidth, this.object.matrix), this._panUp(n * (this.object.top - this.object.bottom) / this.object.zoom / o.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
149
149
  }
150
150
  _dollyOut(t) {
151
151
  this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
@@ -153,12 +153,12 @@ class U extends v {
153
153
  _dollyIn(t) {
154
154
  this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
155
155
  }
156
- _updateZoomParameters(t, e) {
156
+ _updateZoomParameters(t, n) {
157
157
  if (!this.zoomToCursor)
158
158
  return;
159
159
  this._performCursorZoom = !0;
160
- const i = this.domElement.getBoundingClientRect(), s = t - i.left, a = e - i.top, r = i.width, h = i.height;
161
- this._mouse.x = s / r * 2 - 1, this._mouse.y = -(a / h) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
160
+ const o = this.domElement.getBoundingClientRect(), r = t - o.left, i = n - o.top, s = o.width, a = o.height;
161
+ this._mouse.x = r / s * 2 - 1, this._mouse.y = -(i / a) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
162
162
  }
163
163
  _clampDistance(t) {
164
164
  return Math.max(this.minDistance, Math.min(this.maxDistance, t));
@@ -177,8 +177,8 @@ class U extends v {
177
177
  }
178
178
  _handleMouseMoveRotate(t) {
179
179
  this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
180
- const e = this.domElement;
181
- this._rotateLeft(p * this._rotateDelta.x / e.clientHeight), this._rotateUp(p * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
180
+ const n = this.domElement;
181
+ this._rotateLeft(Z * this._rotateDelta.x / n.clientHeight), this._rotateUp(Z * this._rotateDelta.y / n.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
182
182
  }
183
183
  _handleMouseMoveDolly(t) {
184
184
  this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
@@ -190,42 +190,42 @@ class U extends v {
190
190
  this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
191
191
  }
192
192
  _handleKeyDown(t) {
193
- let e = !1;
193
+ let n = !1;
194
194
  switch (t.code) {
195
195
  case this.keys.UP:
196
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), e = !0;
196
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(Z * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), n = !0;
197
197
  break;
198
198
  case this.keys.BOTTOM:
199
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), e = !0;
199
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-Z * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), n = !0;
200
200
  break;
201
201
  case this.keys.LEFT:
202
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), e = !0;
202
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(Z * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), n = !0;
203
203
  break;
204
204
  case this.keys.RIGHT:
205
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), e = !0;
205
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-Z * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), n = !0;
206
206
  break;
207
207
  }
208
- e && (t.preventDefault(), this.update());
208
+ n && (t.preventDefault(), this.update());
209
209
  }
210
210
  _handleTouchStartRotate(t) {
211
211
  if (this._pointers.length === 1)
212
212
  this._rotateStart.set(t.pageX, t.pageY);
213
213
  else {
214
- const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
215
- this._rotateStart.set(i, s);
214
+ const n = this._getSecondPointerPosition(t), o = 0.5 * (t.pageX + n.x), r = 0.5 * (t.pageY + n.y);
215
+ this._rotateStart.set(o, r);
216
216
  }
217
217
  }
218
218
  _handleTouchStartPan(t) {
219
219
  if (this._pointers.length === 1)
220
220
  this._panStart.set(t.pageX, t.pageY);
221
221
  else {
222
- const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
223
- this._panStart.set(i, s);
222
+ const n = this._getSecondPointerPosition(t), o = 0.5 * (t.pageX + n.x), r = 0.5 * (t.pageY + n.y);
223
+ this._panStart.set(o, r);
224
224
  }
225
225
  }
226
226
  _handleTouchStartDolly(t) {
227
- const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, a = Math.sqrt(i * i + s * s);
228
- this._dollyStart.set(0, a);
227
+ const n = this._getSecondPointerPosition(t), o = t.pageX - n.x, r = t.pageY - n.y, i = Math.sqrt(o * o + r * r);
228
+ this._dollyStart.set(0, i);
229
229
  }
230
230
  _handleTouchStartDollyPan(t) {
231
231
  this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
@@ -237,27 +237,27 @@ class U extends v {
237
237
  if (this._pointers.length == 1)
238
238
  this._rotateEnd.set(t.pageX, t.pageY);
239
239
  else {
240
- const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), a = 0.5 * (t.pageY + i.y);
241
- this._rotateEnd.set(s, a);
240
+ const o = this._getSecondPointerPosition(t), r = 0.5 * (t.pageX + o.x), i = 0.5 * (t.pageY + o.y);
241
+ this._rotateEnd.set(r, i);
242
242
  }
243
243
  this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
244
- const e = this.domElement;
245
- this._rotateLeft(p * this._rotateDelta.x / e.clientHeight), this._rotateUp(p * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd);
244
+ const n = this.domElement;
245
+ this._rotateLeft(Z * this._rotateDelta.x / n.clientHeight), this._rotateUp(Z * this._rotateDelta.y / n.clientHeight), this._rotateStart.copy(this._rotateEnd);
246
246
  }
247
247
  _handleTouchMovePan(t) {
248
248
  if (this._pointers.length === 1)
249
249
  this._panEnd.set(t.pageX, t.pageY);
250
250
  else {
251
- const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
252
- this._panEnd.set(i, s);
251
+ const n = this._getSecondPointerPosition(t), o = 0.5 * (t.pageX + n.x), r = 0.5 * (t.pageY + n.y);
252
+ this._panEnd.set(o, r);
253
253
  }
254
254
  this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
255
255
  }
256
256
  _handleTouchMoveDolly(t) {
257
- const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, a = Math.sqrt(i * i + s * s);
258
- this._dollyEnd.set(0, a), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
259
- const r = (t.pageX + e.x) * 0.5, h = (t.pageY + e.y) * 0.5;
260
- this._updateZoomParameters(r, h);
257
+ const n = this._getSecondPointerPosition(t), o = t.pageX - n.x, r = t.pageY - n.y, i = Math.sqrt(o * o + r * r);
258
+ this._dollyEnd.set(0, i), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
259
+ const s = (t.pageX + n.x) * 0.5, a = (t.pageY + n.y) * 0.5;
260
+ this._updateZoomParameters(s, a);
261
261
  }
262
262
  _handleTouchMoveDollyPan(t) {
263
263
  this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
@@ -271,63 +271,63 @@ class U extends v {
271
271
  }
272
272
  _removePointer(t) {
273
273
  delete this._pointerPositions[t.pointerId];
274
- for (let e = 0; e < this._pointers.length; e++)
275
- if (this._pointers[e] == t.pointerId) {
276
- this._pointers.splice(e, 1);
274
+ for (let n = 0; n < this._pointers.length; n++)
275
+ if (this._pointers[n] == t.pointerId) {
276
+ this._pointers.splice(n, 1);
277
277
  return;
278
278
  }
279
279
  }
280
280
  _isTrackingPointer(t) {
281
- for (let e = 0; e < this._pointers.length; e++)
282
- if (this._pointers[e] == t.pointerId) return !0;
281
+ for (let n = 0; n < this._pointers.length; n++)
282
+ if (this._pointers[n] == t.pointerId) return !0;
283
283
  return !1;
284
284
  }
285
285
  _trackPointer(t) {
286
- let e = this._pointerPositions[t.pointerId];
287
- e === void 0 && (e = new m(), this._pointerPositions[t.pointerId] = e), e.set(t.pageX, t.pageY);
286
+ let n = this._pointerPositions[t.pointerId];
287
+ n === void 0 && (n = new C(), this._pointerPositions[t.pointerId] = n), n.set(t.pageX, t.pageY);
288
288
  }
289
289
  _getSecondPointerPosition(t) {
290
- const e = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
291
- return this._pointerPositions[e];
290
+ const n = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
291
+ return this._pointerPositions[n];
292
292
  }
293
293
  //
294
294
  _customWheelEvent(t) {
295
- const e = t.deltaMode, i = {
295
+ const n = t.deltaMode, o = {
296
296
  clientX: t.clientX,
297
297
  clientY: t.clientY,
298
298
  deltaY: t.deltaY
299
299
  };
300
- switch (e) {
300
+ switch (n) {
301
301
  case 1:
302
- i.deltaY *= 16;
302
+ o.deltaY *= 16;
303
303
  break;
304
304
  case 2:
305
- i.deltaY *= 100;
305
+ o.deltaY *= 100;
306
306
  break;
307
307
  }
308
- return t.ctrlKey && !this._controlActive && (i.deltaY *= 10), i;
308
+ return t.ctrlKey && !this._controlActive && (o.deltaY *= 10), o;
309
309
  }
310
310
  }
311
- function Y(o) {
312
- this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(o.pointerId), this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(o) && (this._addPointer(o), o.pointerType === "touch" ? this._onTouchStart(o) : this._onMouseDown(o)));
311
+ function Gt(e) {
312
+ this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(e.pointerId), this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(e) && (this._addPointer(e), e.pointerType === "touch" ? this._onTouchStart(e) : this._onMouseDown(e)));
313
313
  }
314
- function F(o) {
315
- this.enabled !== !1 && (o.pointerType === "touch" ? this._onTouchMove(o) : this._onMouseMove(o));
314
+ function Vt(e) {
315
+ this.enabled !== !1 && (e.pointerType === "touch" ? this._onTouchMove(e) : this._onMouseMove(e));
316
316
  }
317
- function z(o) {
318
- switch (this._removePointer(o), this._pointers.length) {
317
+ function Wt(e) {
318
+ switch (this._removePointer(e), this._pointers.length) {
319
319
  case 0:
320
- this.domElement.releasePointerCapture(o.pointerId), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(R), this.state = l.NONE;
320
+ this.domElement.releasePointerCapture(e.pointerId), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(ot), this.state = b.NONE;
321
321
  break;
322
322
  case 1:
323
- const t = this._pointers[0], e = this._pointerPositions[t];
324
- this._onTouchStart({ pointerId: t, pageX: e.x, pageY: e.y });
323
+ const t = this._pointers[0], n = this._pointerPositions[t];
324
+ this._onTouchStart({ pointerId: t, pageX: n.x, pageY: n.y });
325
325
  break;
326
326
  }
327
327
  }
328
- function G(o) {
328
+ function Ht(e) {
329
329
  let t;
330
- switch (o.button) {
330
+ switch (e.button) {
331
331
  case 0:
332
332
  t = this.mouseButtons.LEFT;
333
333
  break;
@@ -341,125 +341,125 @@ function G(o) {
341
341
  t = -1;
342
342
  }
343
343
  switch (t) {
344
- case b.DOLLY:
344
+ case K.DOLLY:
345
345
  if (this.enableZoom === !1) return;
346
- this._handleMouseDownDolly(o), this.state = l.DOLLY;
346
+ this._handleMouseDownDolly(e), this.state = b.DOLLY;
347
347
  break;
348
- case b.ROTATE:
349
- if (o.ctrlKey || o.metaKey || o.shiftKey) {
348
+ case K.ROTATE:
349
+ if (e.ctrlKey || e.metaKey || e.shiftKey) {
350
350
  if (this.enablePan === !1) return;
351
- this._handleMouseDownPan(o), this.state = l.PAN;
351
+ this._handleMouseDownPan(e), this.state = b.PAN;
352
352
  } else {
353
353
  if (this.enableRotate === !1) return;
354
- this._handleMouseDownRotate(o), this.state = l.ROTATE;
354
+ this._handleMouseDownRotate(e), this.state = b.ROTATE;
355
355
  }
356
356
  break;
357
- case b.PAN:
358
- if (o.ctrlKey || o.metaKey || o.shiftKey) {
357
+ case K.PAN:
358
+ if (e.ctrlKey || e.metaKey || e.shiftKey) {
359
359
  if (this.enableRotate === !1) return;
360
- this._handleMouseDownRotate(o), this.state = l.ROTATE;
360
+ this._handleMouseDownRotate(e), this.state = b.ROTATE;
361
361
  } else {
362
362
  if (this.enablePan === !1) return;
363
- this._handleMouseDownPan(o), this.state = l.PAN;
363
+ this._handleMouseDownPan(e), this.state = b.PAN;
364
364
  }
365
365
  break;
366
366
  default:
367
- this.state = l.NONE;
367
+ this.state = b.NONE;
368
368
  }
369
- this.state !== l.NONE && this.dispatchEvent(A);
369
+ this.state !== b.NONE && this.dispatchEvent(be);
370
370
  }
371
- function K(o) {
371
+ function Kt(e) {
372
372
  switch (this.state) {
373
- case l.ROTATE:
373
+ case b.ROTATE:
374
374
  if (this.enableRotate === !1) return;
375
- this._handleMouseMoveRotate(o);
375
+ this._handleMouseMoveRotate(e);
376
376
  break;
377
- case l.DOLLY:
377
+ case b.DOLLY:
378
378
  if (this.enableZoom === !1) return;
379
- this._handleMouseMoveDolly(o);
379
+ this._handleMouseMoveDolly(e);
380
380
  break;
381
- case l.PAN:
381
+ case b.PAN:
382
382
  if (this.enablePan === !1) return;
383
- this._handleMouseMovePan(o);
383
+ this._handleMouseMovePan(e);
384
384
  break;
385
385
  }
386
386
  }
387
- function W(o) {
388
- this.enabled === !1 || this.enableZoom === !1 || this.state !== l.NONE || (o.preventDefault(), this.dispatchEvent(A), this._handleMouseWheel(this._customWheelEvent(o)), this.dispatchEvent(R));
387
+ function Bt(e) {
388
+ this.enabled === !1 || this.enableZoom === !1 || this.state !== b.NONE || (e.preventDefault(), this.dispatchEvent(be), this._handleMouseWheel(this._customWheelEvent(e)), this.dispatchEvent(ot));
389
389
  }
390
- function Z(o) {
391
- this.enabled !== !1 && this._handleKeyDown(o);
390
+ function Yt(e) {
391
+ this.enabled !== !1 && this._handleKeyDown(e);
392
392
  }
393
- function B(o) {
394
- switch (this._trackPointer(o), this._pointers.length) {
393
+ function Jt(e) {
394
+ switch (this._trackPointer(e), this._pointers.length) {
395
395
  case 1:
396
396
  switch (this.touches.ONE) {
397
- case y.ROTATE:
397
+ case W.ROTATE:
398
398
  if (this.enableRotate === !1) return;
399
- this._handleTouchStartRotate(o), this.state = l.TOUCH_ROTATE;
399
+ this._handleTouchStartRotate(e), this.state = b.TOUCH_ROTATE;
400
400
  break;
401
- case y.PAN:
401
+ case W.PAN:
402
402
  if (this.enablePan === !1) return;
403
- this._handleTouchStartPan(o), this.state = l.TOUCH_PAN;
403
+ this._handleTouchStartPan(e), this.state = b.TOUCH_PAN;
404
404
  break;
405
405
  default:
406
- this.state = l.NONE;
406
+ this.state = b.NONE;
407
407
  }
408
408
  break;
409
409
  case 2:
410
410
  switch (this.touches.TWO) {
411
- case y.DOLLY_PAN:
411
+ case W.DOLLY_PAN:
412
412
  if (this.enableZoom === !1 && this.enablePan === !1) return;
413
- this._handleTouchStartDollyPan(o), this.state = l.TOUCH_DOLLY_PAN;
413
+ this._handleTouchStartDollyPan(e), this.state = b.TOUCH_DOLLY_PAN;
414
414
  break;
415
- case y.DOLLY_ROTATE:
415
+ case W.DOLLY_ROTATE:
416
416
  if (this.enableZoom === !1 && this.enableRotate === !1) return;
417
- this._handleTouchStartDollyRotate(o), this.state = l.TOUCH_DOLLY_ROTATE;
417
+ this._handleTouchStartDollyRotate(e), this.state = b.TOUCH_DOLLY_ROTATE;
418
418
  break;
419
419
  default:
420
- this.state = l.NONE;
420
+ this.state = b.NONE;
421
421
  }
422
422
  break;
423
423
  default:
424
- this.state = l.NONE;
424
+ this.state = b.NONE;
425
425
  }
426
- this.state !== l.NONE && this.dispatchEvent(A);
426
+ this.state !== b.NONE && this.dispatchEvent(be);
427
427
  }
428
- function Q(o) {
429
- switch (this._trackPointer(o), this.state) {
430
- case l.TOUCH_ROTATE:
428
+ function Xt(e) {
429
+ switch (this._trackPointer(e), this.state) {
430
+ case b.TOUCH_ROTATE:
431
431
  if (this.enableRotate === !1) return;
432
- this._handleTouchMoveRotate(o), this.update();
432
+ this._handleTouchMoveRotate(e), this.update();
433
433
  break;
434
- case l.TOUCH_PAN:
434
+ case b.TOUCH_PAN:
435
435
  if (this.enablePan === !1) return;
436
- this._handleTouchMovePan(o), this.update();
436
+ this._handleTouchMovePan(e), this.update();
437
437
  break;
438
- case l.TOUCH_DOLLY_PAN:
438
+ case b.TOUCH_DOLLY_PAN:
439
439
  if (this.enableZoom === !1 && this.enablePan === !1) return;
440
- this._handleTouchMoveDollyPan(o), this.update();
440
+ this._handleTouchMoveDollyPan(e), this.update();
441
441
  break;
442
- case l.TOUCH_DOLLY_ROTATE:
442
+ case b.TOUCH_DOLLY_ROTATE:
443
443
  if (this.enableZoom === !1 && this.enableRotate === !1) return;
444
- this._handleTouchMoveDollyRotate(o), this.update();
444
+ this._handleTouchMoveDollyRotate(e), this.update();
445
445
  break;
446
446
  default:
447
- this.state = l.NONE;
447
+ this.state = b.NONE;
448
448
  }
449
449
  }
450
- function X(o) {
451
- this.enabled !== !1 && o.preventDefault();
450
+ function Qt(e) {
451
+ this.enabled !== !1 && e.preventDefault();
452
452
  }
453
- function V(o) {
454
- o.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
453
+ function qt(e) {
454
+ e.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
455
455
  }
456
- function q(o) {
457
- o.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
456
+ function en(e) {
457
+ e.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
458
458
  }
459
- class $ {
459
+ class tn {
460
460
  loader;
461
461
  constructor() {
462
- this.loader = new k();
462
+ this.loader = new nt();
463
463
  }
464
464
  /**
465
465
  * 加载数字人
@@ -469,29 +469,29 @@ class $ {
469
469
  async load(t) {
470
470
  console.log(`[Flow] Loading avatar config from: ${t}`);
471
471
  try {
472
- const e = await fetch(t);
473
- if (!e.ok)
474
- throw new Error(`Failed to load config: ${e.statusText}`);
475
- const i = await e.json(), a = t.substring(0, t.lastIndexOf("/") + 1) + i.modelSrc;
476
- console.log(`[Flow] Config loaded. Loading model from: ${a}`);
477
- let r, h = [];
472
+ const n = await fetch(t);
473
+ if (!n.ok)
474
+ throw new Error(`Failed to load config: ${n.statusText}`);
475
+ const o = await n.json(), i = t.substring(0, t.lastIndexOf("/") + 1) + o.modelSrc;
476
+ console.log(`[Flow] Config loaded. Loading model from: ${i}`);
477
+ let s, a = [];
478
478
  try {
479
- const c = await this.loader.loadAsync(a);
480
- r = c.scene, h = c.animations || [];
479
+ const c = await this.loader.loadAsync(i);
480
+ s = c.scene, a = c.animations || [];
481
481
  } catch (c) {
482
- console.warn(`[Flow] Failed to load 3D model at ${a}. Using fallback placeholder.`, c), r = this.createFallbackAvatar();
482
+ console.warn(`[Flow] Failed to load 3D model at ${i}. Using fallback placeholder.`, c), s = this.createFallbackAvatar();
483
483
  }
484
- return this.applyConfig(r, i), { model: r, config: i, animations: h };
485
- } catch (e) {
486
- throw console.error("[Flow] Error loading avatar:", e), e;
484
+ return this.applyConfig(s, o), { model: s, config: o, animations: a };
485
+ } catch (n) {
486
+ throw console.error("[Flow] Error loading avatar:", n), n;
487
487
  }
488
488
  }
489
489
  /**
490
490
  * 应用配置到模型
491
491
  */
492
- applyConfig(t, e) {
493
- e.scale && t.scale.setScalar(e.scale), e.initialPosition && t.position.set(...e.initialPosition), t.traverse((i) => {
494
- i.isMesh && (i.castShadow = !0, i.receiveShadow = !0);
492
+ applyConfig(t, n) {
493
+ n.scale && t.scale.setScalar(n.scale), n.initialPosition && t.position.set(...n.initialPosition), t.traverse((o) => {
494
+ o.isMesh && (o.castShadow = !0, o.receiveShadow = !0);
495
495
  });
496
496
  }
497
497
  /**
@@ -499,82 +499,82 @@ class $ {
499
499
  * 生成一个简单的机器人形状
500
500
  */
501
501
  createFallbackAvatar() {
502
- const t = new n.Group(), e = new n.MeshStandardMaterial({
502
+ const t = new d.Group(), n = new d.MeshStandardMaterial({
503
503
  color: 54015,
504
504
  roughness: 0.3,
505
505
  metalness: 0.8
506
- }), i = new n.BoxGeometry(0.8, 0.9, 0.8), s = new n.Mesh(i, e);
507
- s.position.y = 1.5, s.name = "Head", t.add(s);
508
- const a = new n.SphereGeometry(0.1), r = new n.MeshBasicMaterial({ color: 16777215 }), h = new n.Mesh(a, r);
509
- h.position.set(-0.2, 1.5, 0.4), t.add(h);
510
- const c = new n.Mesh(a, r);
506
+ }), o = new d.BoxGeometry(0.8, 0.9, 0.8), r = new d.Mesh(o, n);
507
+ r.position.y = 1.5, r.name = "Head", t.add(r);
508
+ const i = new d.SphereGeometry(0.1), s = new d.MeshBasicMaterial({ color: 16777215 }), a = new d.Mesh(i, s);
509
+ a.position.set(-0.2, 1.5, 0.4), t.add(a);
510
+ const c = new d.Mesh(i, s);
511
511
  c.position.set(0.2, 1.5, 0.4), t.add(c);
512
- const f = new n.CylinderGeometry(0.6, 0.4, 1.5, 8), g = new n.Mesh(f, e);
513
- g.position.y = 0.5, g.name = "Body", t.add(g);
514
- const w = new n.CapsuleGeometry(0.15, 1), P = new n.Mesh(w, e);
515
- P.position.set(-0.9, 0.8, 0), P.rotation.z = Math.PI / 4, P.name = "LeftArm", t.add(P);
516
- const M = new n.Mesh(w, e);
517
- return M.position.set(0.9, 0.8, 0), M.rotation.z = -Math.PI / 4, M.name = "RightArm", t.add(M), t;
512
+ const l = new d.CylinderGeometry(0.6, 0.4, 1.5, 8), h = new d.Mesh(l, n);
513
+ h.position.y = 0.5, h.name = "Body", t.add(h);
514
+ const _ = new d.CapsuleGeometry(0.15, 1), p = new d.Mesh(_, n);
515
+ p.position.set(-0.9, 0.8, 0), p.rotation.z = Math.PI / 4, p.name = "LeftArm", t.add(p);
516
+ const m = new d.Mesh(_, n);
517
+ return m.position.set(0.9, 0.8, 0), m.rotation.z = -Math.PI / 4, m.name = "RightArm", t.add(m), t;
518
518
  }
519
519
  }
520
- class J {
520
+ class nn {
521
521
  loader;
522
522
  constructor() {
523
- this.loader = new k();
523
+ this.loader = new nt();
524
524
  }
525
525
  async load(t) {
526
526
  try {
527
- const e = await fetch(t);
528
- if (!e.ok) throw new Error("Failed to load stage config");
529
- const i = await e.json();
530
- let s, a = [];
531
- if (i.modelSrc) {
532
- const h = t.substring(0, t.lastIndexOf("/") + 1) + i.modelSrc, c = await this.loader.loadAsync(h);
533
- s = c.scene, a = c.animations || [];
527
+ const n = await fetch(t);
528
+ if (!n.ok) throw new Error("Failed to load stage config");
529
+ const o = await n.json();
530
+ let r, i = [];
531
+ if (o.modelSrc) {
532
+ const a = t.substring(0, t.lastIndexOf("/") + 1) + o.modelSrc, c = await this.loader.loadAsync(a);
533
+ r = c.scene, i = c.animations || [];
534
534
  } else
535
- s = this.createProceduralStage();
536
- return this.applyConfig(s, i), { model: s, config: i, animations: a };
537
- } catch (e) {
538
- throw console.error("[Flow] Stage load error:", e), e;
535
+ r = this.createProceduralStage();
536
+ return this.applyConfig(r, o), { model: r, config: o, animations: i };
537
+ } catch (n) {
538
+ throw console.error("[Flow] Stage load error:", n), n;
539
539
  }
540
540
  }
541
- applyConfig(t, e) {
542
- e.scale && t.scale.setScalar(e.scale), e.position && t.position.set(...e.position), e.rotation && t.rotation.set(...e.rotation), t.traverse((i) => {
543
- i.isMesh && (i.receiveShadow = !0, i.castShadow = !0);
541
+ applyConfig(t, n) {
542
+ n.scale && t.scale.setScalar(n.scale), n.position && t.position.set(...n.position), n.rotation && t.rotation.set(...n.rotation), t.traverse((o) => {
543
+ o.isMesh && (o.receiveShadow = !0, o.castShadow = !0);
544
544
  });
545
545
  }
546
546
  /**
547
547
  * Generates a cool Sci-Fi Podium if no model is provided
548
548
  */
549
549
  createProceduralStage() {
550
- const t = new n.Group(), e = new n.CylinderGeometry(2, 2.2, 0.2, 32), i = new n.MeshStandardMaterial({ color: 2236962, roughness: 0.2, metalness: 0.8 }), s = new n.Mesh(e, i);
551
- s.position.y = -0.1, t.add(s);
552
- const a = new n.TorusGeometry(1.8, 0.05, 16, 100), r = new n.MeshBasicMaterial({ color: 54015 }), h = new n.Mesh(a, r);
553
- h.rotation.x = -Math.PI / 2, h.position.y = 0.01, t.add(h);
554
- const c = new n.BoxGeometry(0.5, 0.05, 0.5);
555
- for (let f = 0; f < 4; f++) {
556
- const g = new n.Mesh(c, i), w = f / 4 * Math.PI * 2;
557
- g.position.set(Math.cos(w) * 2.5, 0, Math.sin(w) * 2.5), g.lookAt(0, 0, 0), t.add(g);
550
+ const t = new d.Group(), n = new d.CylinderGeometry(2, 2.2, 0.2, 32), o = new d.MeshStandardMaterial({ color: 2236962, roughness: 0.2, metalness: 0.8 }), r = new d.Mesh(n, o);
551
+ r.position.y = -0.1, t.add(r);
552
+ const i = new d.TorusGeometry(1.8, 0.05, 16, 100), s = new d.MeshBasicMaterial({ color: 54015 }), a = new d.Mesh(i, s);
553
+ a.rotation.x = -Math.PI / 2, a.position.y = 0.01, t.add(a);
554
+ const c = new d.BoxGeometry(0.5, 0.05, 0.5);
555
+ for (let l = 0; l < 4; l++) {
556
+ const h = new d.Mesh(c, o), _ = l / 4 * Math.PI * 2;
557
+ h.position.set(Math.cos(_) * 2.5, 0, Math.sin(_) * 2.5), h.lookAt(0, 0, 0), t.add(h);
558
558
  }
559
559
  return t;
560
560
  }
561
561
  }
562
- class O {
562
+ class De {
563
563
  mixer;
564
564
  clips;
565
565
  states = {};
566
566
  activeActions = /* @__PURE__ */ new Map();
567
567
  currentState = null;
568
568
  defaultState = "idle";
569
- constructor(t, e) {
570
- this.mixer = new n.AnimationMixer(t), this.clips = e, this.mixer.addEventListener("finished", this.onFinished.bind(this));
569
+ constructor(t, n) {
570
+ this.mixer = new d.AnimationMixer(t), this.clips = n, this.mixer.addEventListener("finished", this.onFinished.bind(this));
571
571
  }
572
572
  /**
573
573
  * Initialize with configuration
574
574
  */
575
575
  init(t) {
576
- this.defaultState = t.defaultState, this.states = t.states, Object.entries(this.states).forEach(([e, i]) => {
577
- this.findClip(i.clipName) || console.warn(`[AnimationController] Clip "${i.clipName}" for state "${e}" not found.`);
576
+ this.defaultState = t.defaultState, this.states = t.states, Object.entries(this.states).forEach(([n, o]) => {
577
+ this.findClip(o.clipName) || console.warn(`[AnimationController] Clip "${o.clipName}" for state "${n}" not found.`);
578
578
  }), this.play(this.defaultState);
579
579
  }
580
580
  /**
@@ -586,66 +586,67 @@ class O {
586
586
  /**
587
587
  * Play a state
588
588
  */
589
- play(t, e = !1) {
590
- const i = this.states[t];
591
- if (!i) {
589
+ play(t, n = !1) {
590
+ const o = this.states[t];
591
+ if (!o) {
592
592
  console.warn(`[AnimationController] State "${t}" not defined.`);
593
593
  return;
594
594
  }
595
- const s = this.findClip(i.clipName);
596
- if (!s || this.currentState === t && !e) return;
597
- const a = this.mixer.clipAction(s);
598
- a.setLoop(i.loop ? n.LoopRepeat : n.LoopOnce, i.loop ? 1 / 0 : 1), a.clampWhenFinished = !i.loop, a.timeScale = i.timeScale ?? 1;
599
- const r = i.fadeDuration ?? 0.3;
595
+ const r = this.findClip(o.clipName);
596
+ if (!r || this.currentState === t && !n) return;
597
+ const i = this.mixer.clipAction(r);
598
+ i.setLoop(o.loop ? d.LoopRepeat : d.LoopOnce, o.loop ? 1 / 0 : 1), i.clampWhenFinished = !o.loop, i.timeScale = o.timeScale ?? 1;
599
+ const s = o.fadeDuration ?? 0.3;
600
600
  if (this.currentState) {
601
- const h = this.activeActions.get(this.currentState);
602
- h && h !== a ? (h.fadeOut(r), a.reset(), a.fadeIn(r), a.play()) : a.reset().play();
601
+ const a = this.activeActions.get(this.currentState);
602
+ a && a !== i ? (a.fadeOut(s), i.reset(), i.fadeIn(s), i.play()) : i.reset().play();
603
603
  } else
604
- a.reset().play();
605
- this.activeActions.set(t, a), this.currentState = t, console.log(`[Anim] Transition to: ${t} (Loop: ${i.loop})`);
604
+ i.reset().play();
605
+ this.activeActions.set(t, i), this.currentState = t, console.log(`[Anim] Transition to: ${t} (Loop: ${o.loop})`);
606
606
  }
607
607
  onFinished(t) {
608
608
  if (this.currentState && this.activeActions.get(this.currentState) === t.action) {
609
- const e = this.states[this.currentState], i = () => {
610
- e && e.next ? this.play(e.next) : !e.loop && this.currentState !== this.defaultState && this.play(this.defaultState);
609
+ const n = this.states[this.currentState], o = () => {
610
+ n && n.next ? this.play(n.next) : !n.loop && this.currentState !== this.defaultState && this.play(this.defaultState);
611
611
  };
612
- e.holdDuration && e.holdDuration > 0 ? setTimeout(i, e.holdDuration * 1e3) : i();
612
+ n.holdDuration && n.holdDuration > 0 ? setTimeout(o, n.holdDuration * 1e3) : o();
613
613
  }
614
614
  }
615
615
  /**
616
616
  * Finds an animation clip by name using exact, case-insensitive, or fuzzy matching.
617
617
  */
618
618
  findClip(t) {
619
- let e = this.clips.find((i) => i.name === t);
620
- return e || (e = this.clips.find((i) => i.name.toLowerCase() === t.toLowerCase())), e || (e = this.clips.find((i) => i.name.toLowerCase().includes(t.toLowerCase()))), e;
619
+ let n = this.clips.find((o) => o.name === t);
620
+ return n || (n = this.clips.find((o) => o.name.toLowerCase() === t.toLowerCase())), n || (n = this.clips.find((o) => o.name.toLowerCase().includes(t.toLowerCase()))), n;
621
621
  }
622
622
  }
623
- const u = {
623
+ const D = {
624
624
  IDLE: "IDLE",
625
625
  TRACKING: "TRACKING",
626
- HOLDING: "HOLDING"
627
- }, tt = 5, et = 1.5, it = Number.EPSILON;
628
- class st {
629
- raycaster = new n.Raycaster();
630
- mouse = new n.Vector2();
626
+ HOLDING: "HOLDING",
627
+ OVERRIDE: "OVERRIDE"
628
+ }, on = 5, rn = 1.5, sn = Number.EPSILON;
629
+ class an {
630
+ raycaster = new d.Raycaster();
631
+ mouse = new d.Vector2();
631
632
  // State Machine
632
- state = u.IDLE;
633
+ state = D.IDLE;
633
634
  stateTimer = 0;
634
635
  // Core Data
635
- lookAtTarget = new n.Vector3();
636
+ lookAtTarget = new d.Vector3();
636
637
  // Desired World Target
637
- currentLookAt = new n.Vector3();
638
+ currentLookAt = new d.Vector3();
638
639
  // Smoothed World Target (For debug visualization)
639
- activePlane = new n.Plane(new n.Vector3(0, 0, 1), -2.5);
640
- planeCenter = new n.Vector3(0, 1.5, 2.5);
640
+ activePlane = new d.Plane(new d.Vector3(0, 0, 1), -2.5);
641
+ planeCenter = new d.Vector3(0, 1.5, 2.5);
641
642
  // Visual center of the plane
642
643
  // Physics / Math Helpers
643
- lookAtProxy = new n.Object3D();
644
+ lookAtProxy = new d.Object3D();
644
645
  // Reusable temporaries to reduce GC
645
- _targetQuat = new n.Quaternion();
646
- _dummyVec = new n.Vector3();
647
- _offsetQuat = new n.Quaternion();
648
- _parentWorldQuat = new n.Quaternion();
646
+ _targetQuat = new d.Quaternion();
647
+ _dummyVec = new d.Vector3();
648
+ _offsetQuat = new d.Quaternion();
649
+ _parentWorldQuat = new d.Quaternion();
649
650
  // V6 Architecture: Persistent State Tracker
650
651
  outputQuaternion = null;
651
652
  weight = 0;
@@ -660,86 +661,98 @@ class st {
660
661
  boundOnPointerDown;
661
662
  boundOnPointerMove;
662
663
  boundOnPointerUp;
663
- constructor(t, e, i, s, a) {
664
- this.container = t, this.camera = e, this.getHeadBone = i, this.getConfig = s, this.getModels = a, this.boundOnPointerDown = this.onPointerDown.bind(this), this.boundOnPointerMove = this.onPointerMove.bind(this), this.boundOnPointerUp = this.onPointerUp.bind(this), this.container.addEventListener("pointerdown", this.boundOnPointerDown), this.container.addEventListener("pointermove", this.boundOnPointerMove), window.addEventListener("pointerup", this.boundOnPointerUp);
665
- }
666
- update(t, e) {
667
- const i = this.getHeadBone(), s = this.getConfig();
668
- if (!i || !s || s.lookAt?.enabled === !1) return;
669
- const a = i.quaternion.clone();
670
- this.outputQuaternion || (this.outputQuaternion = a.clone()), this.updateState(t, s);
671
- const r = this.state === u.TRACKING || this.state === u.HOLDING;
672
- r ? (this.calculateLookAtRotation(i, s, this._targetQuat), this.weight = 1) : (this._targetQuat.copy(a), this.weight = 0);
673
- const h = s.lookAt?.damping ?? tt, c = 1 - Math.exp(-h * e);
674
- this.outputQuaternion.slerp(this._targetQuat, c), i.quaternion.copy(this.outputQuaternion), r && this.currentLookAt.lerp(this.lookAtTarget, c);
675
- }
676
- calculateLookAtRotation(t, e, i) {
677
- const s = this._dummyVec;
678
- t.getWorldPosition(s), this.lookAtProxy.position.copy(s), this.lookAtProxy.lookAt(this.lookAtTarget), this.lookAtProxy.updateMatrixWorld();
679
- const a = e.lookAt?.rotationOffset || [0, 0, 0];
680
- this._offsetQuat.setFromEuler(new n.Euler(...a));
681
- const r = this.lookAtProxy.quaternion.multiply(this._offsetQuat), h = t.parent;
682
- if (h) {
683
- h.getWorldQuaternion(this._parentWorldQuat);
664
+ constructor(t, n, o, r, i) {
665
+ this.container = t, this.camera = n, this.getHeadBone = o, this.getConfig = r, this.getModels = i, this.boundOnPointerDown = this.onPointerDown.bind(this), this.boundOnPointerMove = this.onPointerMove.bind(this), this.boundOnPointerUp = this.onPointerUp.bind(this), this.container.addEventListener("pointerdown", this.boundOnPointerDown), this.container.addEventListener("pointermove", this.boundOnPointerMove), window.addEventListener("pointerup", this.boundOnPointerUp);
666
+ }
667
+ update(t, n) {
668
+ const o = this.getHeadBone(), r = this.getConfig();
669
+ if (!o || !r || r.lookAt?.enabled === !1) return;
670
+ const i = o.quaternion.clone();
671
+ this.outputQuaternion || (this.outputQuaternion = i.clone()), this.updateState(t, r);
672
+ const s = this.state !== D.IDLE;
673
+ s ? (this.calculateLookAtRotation(o, r, this._targetQuat), this.weight = 1) : (this._targetQuat.copy(i), this.weight = 0);
674
+ const a = r.lookAt?.damping ?? on, c = 1 - Math.exp(-a * n);
675
+ this.outputQuaternion.slerp(this._targetQuat, c), o.quaternion.copy(this.outputQuaternion), s && this.currentLookAt.lerp(this.lookAtTarget, c);
676
+ }
677
+ calculateLookAtRotation(t, n, o) {
678
+ const r = this._dummyVec;
679
+ t.getWorldPosition(r), this.lookAtProxy.position.copy(r), this.lookAtProxy.lookAt(this.lookAtTarget), this.lookAtProxy.updateMatrixWorld();
680
+ const i = n.lookAt?.rotationOffset || [0, 0, 0];
681
+ this._offsetQuat.setFromEuler(new d.Euler(...i));
682
+ const s = this.lookAtProxy.quaternion.multiply(this._offsetQuat), a = t.parent;
683
+ if (a) {
684
+ a.getWorldQuaternion(this._parentWorldQuat);
684
685
  const c = this._parentWorldQuat.invert();
685
- i.copy(c.multiply(r));
686
+ o.copy(c.multiply(s));
686
687
  } else
687
- i.copy(r);
688
+ o.copy(s);
688
689
  }
689
- updateState(t, e) {
690
- const i = e.lookAt?.holdDuration ?? 2e3;
690
+ updateState(t, n) {
691
+ const o = n.lookAt?.holdDuration ?? 2e3;
691
692
  switch (this.state) {
692
- case u.TRACKING:
693
+ case D.TRACKING:
693
694
  this.calculateLookAtTarget();
694
695
  break;
695
- case u.HOLDING:
696
- t - this.stateTimer > i && (this.state = u.IDLE, console.log("[Flow] LookAt: Holding finished, releasing to animation."));
696
+ case D.HOLDING:
697
+ t - this.stateTimer > o && (this.state = D.IDLE, console.log("[Flow] LookAt: Holding finished, releasing to animation."));
697
698
  break;
698
699
  }
699
700
  }
701
+ /**
702
+ * Set a manual world-space target for the avatar to look at.
703
+ */
704
+ setTarget(t) {
705
+ this.state = D.OVERRIDE, this.stateTimer = performance.now(), this.lookAtTarget.copy(t);
706
+ }
707
+ /**
708
+ * Return the LookAt system to IDLE state.
709
+ */
710
+ reset() {
711
+ this.state = D.IDLE;
712
+ }
700
713
  onPointerDown(t) {
701
714
  this.updateMouse(t);
702
- const e = this.getHeadBone();
703
- if (e) {
704
- const i = new n.Vector3();
705
- e.getWorldPosition(i);
706
- const s = this.camera.position.clone(), a = new n.Vector3().subVectors(s, i), r = new n.Vector3();
707
- if (a.lengthSq() < 1e-6) {
715
+ const n = this.getHeadBone();
716
+ if (n) {
717
+ const o = new d.Vector3();
718
+ n.getWorldPosition(o);
719
+ const r = this.camera.position.clone(), i = new d.Vector3().subVectors(r, o), s = new d.Vector3();
720
+ if (i.lengthSq() < 1e-6) {
708
721
  const c = this.camera;
709
- "getWorldDirection" in c && typeof c.getWorldDirection == "function" ? (c.getWorldDirection(r), r.negate()) : r.set(0, 0, 1);
722
+ "getWorldDirection" in c && typeof c.getWorldDirection == "function" ? (c.getWorldDirection(s), s.negate()) : s.set(0, 0, 1);
710
723
  } else
711
- r.copy(a).normalize();
712
- const h = r.clone().multiplyScalar(et);
713
- this.planeCenter.copy(i).add(h), this.activePlane.setFromNormalAndCoplanarPoint(r, this.planeCenter);
724
+ s.copy(i).normalize();
725
+ const a = s.clone().multiplyScalar(rn);
726
+ this.planeCenter.copy(o).add(a), this.activePlane.setFromNormalAndCoplanarPoint(s, this.planeCenter);
714
727
  }
715
- this.state = u.TRACKING, this.calculateLookAtTarget(), this.outputQuaternion || this.currentLookAt.copy(this.lookAtTarget);
728
+ this.state = D.TRACKING, this.calculateLookAtTarget(), this.outputQuaternion || this.currentLookAt.copy(this.lookAtTarget);
716
729
  }
717
730
  onPointerMove(t) {
718
- this.state === u.TRACKING && this.updateMouse(t);
731
+ this.state === D.TRACKING && this.updateMouse(t);
719
732
  }
720
733
  onPointerUp() {
721
- this.state === u.TRACKING && (this.state = u.HOLDING, this.stateTimer = performance.now());
734
+ this.state === D.TRACKING && (this.state = D.HOLDING, this.stateTimer = performance.now());
722
735
  }
723
736
  updateMouse(t) {
724
- const e = this.container.getBoundingClientRect();
725
- this.mouse.x = (t.clientX - e.left) / e.width * 2 - 1, this.mouse.y = -((t.clientY - e.top) / e.height) * 2 + 1;
737
+ const n = this.container.getBoundingClientRect();
738
+ this.mouse.x = (t.clientX - n.left) / n.width * 2 - 1, this.mouse.y = -((t.clientY - n.top) / n.height) * 2 + 1;
726
739
  }
727
740
  calculateLookAtTarget() {
728
741
  this.raycaster.setFromCamera(this.mouse, this.camera);
729
- const t = this.getModels().filter((i) => !!i);
742
+ const t = this.getModels().filter((o) => !!o);
730
743
  if (t.length > 0) {
731
- const i = this.raycaster.intersectObjects(t, !0);
732
- if (i.length > 0) {
733
- this.lookAtTarget.copy(i[0].point);
744
+ const o = this.raycaster.intersectObjects(t, !0);
745
+ if (o.length > 0) {
746
+ this.lookAtTarget.copy(o[0].point);
734
747
  return;
735
748
  }
736
749
  }
737
- const e = this._dummyVec;
738
- this.activePlane.normal.lengthSq() > it && this.raycaster.ray.intersectPlane(this.activePlane, e) && this.lookAtTarget.copy(e);
750
+ const n = this._dummyVec;
751
+ this.activePlane.normal.lengthSq() > sn && this.raycaster.ray.intersectPlane(this.activePlane, n) && this.lookAtTarget.copy(n);
739
752
  }
740
753
  getDebugInfo() {
741
754
  return {
742
- isEngaged: this.state !== u.IDLE,
755
+ isEngaged: this.state !== D.IDLE,
743
756
  currentLookAt: this.currentLookAt,
744
757
  activePlane: this.activePlane,
745
758
  planeCenter: this.planeCenter,
@@ -747,13 +760,2876 @@ class st {
747
760
  };
748
761
  }
749
762
  interrupt() {
750
- this.state = u.IDLE;
763
+ this.state = D.IDLE;
751
764
  }
752
765
  dispose() {
753
766
  this.container.removeEventListener("pointerdown", this.boundOnPointerDown), this.container.removeEventListener("pointermove", this.boundOnPointerMove), window.removeEventListener("pointerup", this.boundOnPointerUp);
754
767
  }
755
768
  }
756
- class rt {
769
+ const N = {
770
+ IDLE: "IDLE",
771
+ TALKING: "TALKING",
772
+ THINKING: "THINKING",
773
+ LISTENING: "LISTENING",
774
+ EMOTIONAL: "EMOTIONAL"
775
+ };
776
+ class cn {
777
+ currentState = N.IDLE;
778
+ stateStartTime = 0;
779
+ stateTimeout = null;
780
+ isTransitioning = !1;
781
+ debug = !1;
782
+ /**
783
+ * Optional callback triggered when the behavioral state changes.
784
+ */
785
+ onStateChange;
786
+ /**
787
+ * @param options.debug Enable verbose logging for transitions
788
+ */
789
+ constructor(t) {
790
+ this.debug = !!t?.debug;
791
+ }
792
+ /**
793
+ * Toggles debug logging mode without re-initializing the controller.
794
+ */
795
+ setDebugMode(t) {
796
+ this.debug = t;
797
+ }
798
+ /**
799
+ * @returns Whether debug mode is currently enabled.
800
+ */
801
+ isDebugEnabled() {
802
+ return this.debug;
803
+ }
804
+ /**
805
+ * Drives the brain logic.
806
+ * @param timeMs Consistent external timestamp (usually from requestAnimationFrame).
807
+ */
808
+ update(t) {
809
+ this.stateStartTime === 0 && (this.stateStartTime = t), this.stateTimeout !== null && t - this.stateStartTime >= this.stateTimeout && (this.debug && console.log(`[Brain] State ${this.currentState} timed out, reverting to IDLE.`), this.stateTimeout = null, this.setIntent({ state: N.IDLE }, t));
810
+ }
811
+ /**
812
+ * Core API: Submit a behavioral intent to the brain.
813
+ * @param intent The desired behavior change
814
+ * @param timeMs Optional current time (defaults to performance.now())
815
+ */
816
+ setIntent(t, n) {
817
+ if (this.isTransitioning || this.currentState === t.state && t.state !== N.EMOTIONAL)
818
+ return;
819
+ const o = n ?? performance.now();
820
+ this.debug && console.log(`[Brain] Transition: ${this.currentState} -> ${t.state}`), this.isTransitioning = !0;
821
+ try {
822
+ this.currentState = t.state, this.stateStartTime = o, this.stateTimeout = t.duration ?? null, this.onStateChange && this.onStateChange(this.currentState, t);
823
+ } finally {
824
+ this.isTransitioning = !1;
825
+ }
826
+ }
827
+ /**
828
+ * @returns The current high-level behavior state.
829
+ */
830
+ getState() {
831
+ return this.currentState;
832
+ }
833
+ }
834
+ const un = 1.2;
835
+ class ln {
836
+ scene;
837
+ sprite;
838
+ target = null;
839
+ offset = new d.Vector3(0, un, 0);
840
+ visible = !1;
841
+ // Canvas configuration
842
+ canvas;
843
+ ctx;
844
+ texture;
845
+ constructor(t) {
846
+ this.scene = t, this.canvas = document.createElement("canvas"), this.canvas.width = 512, this.canvas.height = 256;
847
+ const n = this.canvas.getContext("2d");
848
+ if (!n) throw new Error("Failed to get 2D context for BubbleManager");
849
+ this.ctx = n, this.texture = new d.CanvasTexture(this.canvas), this.texture.minFilter = d.LinearFilter;
850
+ const o = new d.SpriteMaterial({
851
+ map: this.texture,
852
+ transparent: !0,
853
+ depthTest: !1,
854
+ depthWrite: !1
855
+ });
856
+ this.sprite = new d.Sprite(o), this.sprite.scale.set(1.5, 0.75, 1), this.sprite.visible = !1, this.sprite.renderOrder = 999, this.scene.add(this.sprite);
857
+ }
858
+ setTarget(t) {
859
+ this.target = t;
860
+ }
861
+ show(t, n = "speech") {
862
+ this.drawBubble(t, n), this.sprite.visible = !0, this.visible = !0, this.update();
863
+ }
864
+ hide() {
865
+ this.sprite.visible = !1, this.visible = !1;
866
+ }
867
+ update() {
868
+ if (!this.visible || !this.target) return;
869
+ const t = new d.Vector3();
870
+ this.target.getWorldPosition(t), this.sprite.position.copy(t).add(this.offset);
871
+ }
872
+ drawBubble(t, n) {
873
+ const o = this.canvas.width, r = this.canvas.height, i = this.ctx;
874
+ i.clearRect(0, 0, o, r);
875
+ const s = 20, a = 40, c = 40;
876
+ i.font = 'bold 40px "Segoe UI", Roboto, Helvetica, Arial, sans-serif', i.textAlign = "center", i.textBaseline = "middle", i.fillStyle = "rgba(255, 255, 255, 0.95)", i.shadowColor = "rgba(0, 0, 0, 0.2)", i.shadowBlur = 10, i.shadowOffsetX = 0, i.shadowOffsetY = 5;
877
+ let l = o - s * 2;
878
+ const h = r - c - s * 2, _ = s, p = s;
879
+ n === "speech" ? (this.drawRoundedRect(i, _, p, l, h, a), i.beginPath(), i.moveTo(o / 2 - 20, p + h), i.lineTo(o / 2, p + h + c), i.lineTo(o / 2 + 20, p + h), i.fill()) : (this.drawCloud(i, _, p, l, h), i.beginPath(), i.arc(o / 2 - 20, p + h + 15, 8, 0, Math.PI * 2), i.arc(o / 2 - 10, p + h + 35, 5, 0, Math.PI * 2), i.fill()), i.fillStyle = "#000000", i.shadowBlur = 0;
880
+ const m = t.split(" ");
881
+ let k = "";
882
+ const z = 50, V = l - 60, x = [];
883
+ for (let y = 0; y < m.length; y++) {
884
+ const A = k + m[y] + " ";
885
+ i.measureText(A).width > V && y > 0 ? (x.push(k), k = m[y] + " ") : k = A;
886
+ }
887
+ x.push(k);
888
+ const he = x.length * z;
889
+ let $ = p + (h - he) / 2 + z / 2;
890
+ for (let y = 0; y < x.length; y++)
891
+ i.fillText(x[y], o / 2, $), $ += z;
892
+ this.texture.needsUpdate = !0;
893
+ }
894
+ drawRoundedRect(t, n, o, r, i, s) {
895
+ t.beginPath(), t.moveTo(n + s, o), t.lineTo(n + r - s, o), t.quadraticCurveTo(n + r, o, n + r, o + s), t.lineTo(n + r, o + i - s), t.quadraticCurveTo(n + r, o + i, n + r - s, o + i), t.lineTo(n + s, o + i), t.quadraticCurveTo(n, o + i, n, o + i - s), t.lineTo(n, o + s), t.quadraticCurveTo(n, o, n + s, o), t.closePath(), t.fill();
896
+ }
897
+ drawCloud(t, n, o, r, i) {
898
+ t.beginPath();
899
+ const s = n + r * 0.2, a = o + i * 0.8;
900
+ t.moveTo(s, a), t.bezierCurveTo(n - 20, o + i * 0.8, n - 20, o + i * 0.3, n + r * 0.1, o + i * 0.3), t.bezierCurveTo(n + r * 0.1, o - 20, n + r * 0.4, o - 20, n + r * 0.5, o + i * 0.1), t.bezierCurveTo(n + r * 0.6, o - 20, n + r + 20, o + i * 0.1, n + r * 0.9, o + i * 0.4), t.bezierCurveTo(n + r + 30, o + i * 0.5, n + r + 10, o + i + 10, n + r * 0.7, o + i * 0.9), t.bezierCurveTo(n + r * 0.5, o + i + 20, n + r * 0.3, o + i + 10, s, a), t.closePath(), t.fill();
901
+ }
902
+ }
903
+ function u(e, t, n) {
904
+ function o(a, c) {
905
+ if (a._zod || Object.defineProperty(a, "_zod", {
906
+ value: {
907
+ def: c,
908
+ constr: s,
909
+ traits: /* @__PURE__ */ new Set()
910
+ },
911
+ enumerable: !1
912
+ }), a._zod.traits.has(e))
913
+ return;
914
+ a._zod.traits.add(e), t(a, c);
915
+ const l = s.prototype, h = Object.keys(l);
916
+ for (let _ = 0; _ < h.length; _++) {
917
+ const p = h[_];
918
+ p in a || (a[p] = l[p].bind(a));
919
+ }
920
+ }
921
+ const r = n?.Parent ?? Object;
922
+ class i extends r {
923
+ }
924
+ Object.defineProperty(i, "name", { value: e });
925
+ function s(a) {
926
+ var c;
927
+ const l = n?.Parent ? new i() : this;
928
+ o(l, a), (c = l._zod).deferred ?? (c.deferred = []);
929
+ for (const h of l._zod.deferred)
930
+ h();
931
+ return l;
932
+ }
933
+ return Object.defineProperty(s, "init", { value: o }), Object.defineProperty(s, Symbol.hasInstance, {
934
+ value: (a) => n?.Parent && a instanceof n.Parent ? !0 : a?._zod?.traits?.has(e)
935
+ }), Object.defineProperty(s, "name", { value: e }), s;
936
+ }
937
+ class B extends Error {
938
+ constructor() {
939
+ super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
940
+ }
941
+ }
942
+ class rt extends Error {
943
+ constructor(t) {
944
+ super(`Encountered unidirectional transform during encode: ${t}`), this.name = "ZodEncodeError";
945
+ }
946
+ }
947
+ const it = {};
948
+ function F(e) {
949
+ return it;
950
+ }
951
+ function st(e) {
952
+ const t = Object.values(e).filter((o) => typeof o == "number");
953
+ return Object.entries(e).filter(([o, r]) => t.indexOf(+o) === -1).map(([o, r]) => r);
954
+ }
955
+ function me(e, t) {
956
+ return typeof t == "bigint" ? t.toString() : t;
957
+ }
958
+ function ye(e) {
959
+ return {
960
+ get value() {
961
+ {
962
+ const t = e();
963
+ return Object.defineProperty(this, "value", { value: t }), t;
964
+ }
965
+ }
966
+ };
967
+ }
968
+ function ve(e) {
969
+ return e == null;
970
+ }
971
+ function we(e) {
972
+ const t = e.startsWith("^") ? 1 : 0, n = e.endsWith("$") ? e.length - 1 : e.length;
973
+ return e.slice(t, n);
974
+ }
975
+ function hn(e, t) {
976
+ const n = (e.toString().split(".")[1] || "").length, o = t.toString();
977
+ let r = (o.split(".")[1] || "").length;
978
+ if (r === 0 && /\d?e-\d?/.test(o)) {
979
+ const c = o.match(/\d?e-(\d?)/);
980
+ c?.[1] && (r = Number.parseInt(c[1]));
981
+ }
982
+ const i = n > r ? n : r, s = Number.parseInt(e.toFixed(i).replace(".", "")), a = Number.parseInt(t.toFixed(i).replace(".", ""));
983
+ return s % a / 10 ** i;
984
+ }
985
+ const Me = /* @__PURE__ */ Symbol("evaluating");
986
+ function g(e, t, n) {
987
+ let o;
988
+ Object.defineProperty(e, t, {
989
+ get() {
990
+ if (o !== Me)
991
+ return o === void 0 && (o = Me, o = n()), o;
992
+ },
993
+ set(r) {
994
+ Object.defineProperty(e, t, {
995
+ value: r
996
+ // configurable: true,
997
+ });
998
+ },
999
+ configurable: !0
1000
+ });
1001
+ }
1002
+ function G(e, t, n) {
1003
+ Object.defineProperty(e, t, {
1004
+ value: n,
1005
+ writable: !0,
1006
+ enumerable: !0,
1007
+ configurable: !0
1008
+ });
1009
+ }
1010
+ function L(...e) {
1011
+ const t = {};
1012
+ for (const n of e) {
1013
+ const o = Object.getOwnPropertyDescriptors(n);
1014
+ Object.assign(t, o);
1015
+ }
1016
+ return Object.defineProperties({}, t);
1017
+ }
1018
+ function Ce(e) {
1019
+ return JSON.stringify(e);
1020
+ }
1021
+ function dn(e) {
1022
+ return e.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
1023
+ }
1024
+ const at = "captureStackTrace" in Error ? Error.captureStackTrace : (...e) => {
1025
+ };
1026
+ function oe(e) {
1027
+ return typeof e == "object" && e !== null && !Array.isArray(e);
1028
+ }
1029
+ const pn = ye(() => {
1030
+ if (typeof navigator < "u" && navigator?.userAgent?.includes("Cloudflare"))
1031
+ return !1;
1032
+ try {
1033
+ const e = Function;
1034
+ return new e(""), !0;
1035
+ } catch {
1036
+ return !1;
1037
+ }
1038
+ });
1039
+ function X(e) {
1040
+ if (oe(e) === !1)
1041
+ return !1;
1042
+ const t = e.constructor;
1043
+ if (t === void 0 || typeof t != "function")
1044
+ return !0;
1045
+ const n = t.prototype;
1046
+ return !(oe(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
1047
+ }
1048
+ function ct(e) {
1049
+ return X(e) ? { ...e } : Array.isArray(e) ? [...e] : e;
1050
+ }
1051
+ const fn = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
1052
+ function ae(e) {
1053
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1054
+ }
1055
+ function j(e, t, n) {
1056
+ const o = new e._zod.constr(t ?? e._zod.def);
1057
+ return (!t || n?.parent) && (o._zod.parent = e), o;
1058
+ }
1059
+ function f(e) {
1060
+ const t = e;
1061
+ if (!t)
1062
+ return {};
1063
+ if (typeof t == "string")
1064
+ return { error: () => t };
1065
+ if (t?.message !== void 0) {
1066
+ if (t?.error !== void 0)
1067
+ throw new Error("Cannot specify both `message` and `error` params");
1068
+ t.error = t.message;
1069
+ }
1070
+ return delete t.message, typeof t.error == "string" ? { ...t, error: () => t.error } : t;
1071
+ }
1072
+ function mn(e) {
1073
+ return Object.keys(e).filter((t) => e[t]._zod.optin === "optional" && e[t]._zod.optout === "optional");
1074
+ }
1075
+ const _n = {
1076
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
1077
+ int32: [-2147483648, 2147483647],
1078
+ uint32: [0, 4294967295],
1079
+ float32: [-34028234663852886e22, 34028234663852886e22],
1080
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
1081
+ };
1082
+ function gn(e, t) {
1083
+ const n = e._zod.def, o = n.checks;
1084
+ if (o && o.length > 0)
1085
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
1086
+ const i = L(e._zod.def, {
1087
+ get shape() {
1088
+ const s = {};
1089
+ for (const a in t) {
1090
+ if (!(a in n.shape))
1091
+ throw new Error(`Unrecognized key: "${a}"`);
1092
+ t[a] && (s[a] = n.shape[a]);
1093
+ }
1094
+ return G(this, "shape", s), s;
1095
+ },
1096
+ checks: []
1097
+ });
1098
+ return j(e, i);
1099
+ }
1100
+ function bn(e, t) {
1101
+ const n = e._zod.def, o = n.checks;
1102
+ if (o && o.length > 0)
1103
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
1104
+ const i = L(e._zod.def, {
1105
+ get shape() {
1106
+ const s = { ...e._zod.def.shape };
1107
+ for (const a in t) {
1108
+ if (!(a in n.shape))
1109
+ throw new Error(`Unrecognized key: "${a}"`);
1110
+ t[a] && delete s[a];
1111
+ }
1112
+ return G(this, "shape", s), s;
1113
+ },
1114
+ checks: []
1115
+ });
1116
+ return j(e, i);
1117
+ }
1118
+ function yn(e, t) {
1119
+ if (!X(t))
1120
+ throw new Error("Invalid input to extend: expected a plain object");
1121
+ const n = e._zod.def.checks;
1122
+ if (n && n.length > 0) {
1123
+ const i = e._zod.def.shape;
1124
+ for (const s in t)
1125
+ if (Object.getOwnPropertyDescriptor(i, s) !== void 0)
1126
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
1127
+ }
1128
+ const r = L(e._zod.def, {
1129
+ get shape() {
1130
+ const i = { ...e._zod.def.shape, ...t };
1131
+ return G(this, "shape", i), i;
1132
+ }
1133
+ });
1134
+ return j(e, r);
1135
+ }
1136
+ function vn(e, t) {
1137
+ if (!X(t))
1138
+ throw new Error("Invalid input to safeExtend: expected a plain object");
1139
+ const n = L(e._zod.def, {
1140
+ get shape() {
1141
+ const o = { ...e._zod.def.shape, ...t };
1142
+ return G(this, "shape", o), o;
1143
+ }
1144
+ });
1145
+ return j(e, n);
1146
+ }
1147
+ function wn(e, t) {
1148
+ const n = L(e._zod.def, {
1149
+ get shape() {
1150
+ const o = { ...e._zod.def.shape, ...t._zod.def.shape };
1151
+ return G(this, "shape", o), o;
1152
+ },
1153
+ get catchall() {
1154
+ return t._zod.def.catchall;
1155
+ },
1156
+ checks: []
1157
+ // delete existing checks
1158
+ });
1159
+ return j(e, n);
1160
+ }
1161
+ function kn(e, t, n) {
1162
+ const r = t._zod.def.checks;
1163
+ if (r && r.length > 0)
1164
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
1165
+ const s = L(t._zod.def, {
1166
+ get shape() {
1167
+ const a = t._zod.def.shape, c = { ...a };
1168
+ if (n)
1169
+ for (const l in n) {
1170
+ if (!(l in a))
1171
+ throw new Error(`Unrecognized key: "${l}"`);
1172
+ n[l] && (c[l] = e ? new e({
1173
+ type: "optional",
1174
+ innerType: a[l]
1175
+ }) : a[l]);
1176
+ }
1177
+ else
1178
+ for (const l in a)
1179
+ c[l] = e ? new e({
1180
+ type: "optional",
1181
+ innerType: a[l]
1182
+ }) : a[l];
1183
+ return G(this, "shape", c), c;
1184
+ },
1185
+ checks: []
1186
+ });
1187
+ return j(t, s);
1188
+ }
1189
+ function zn(e, t, n) {
1190
+ const o = L(t._zod.def, {
1191
+ get shape() {
1192
+ const r = t._zod.def.shape, i = { ...r };
1193
+ if (n)
1194
+ for (const s in n) {
1195
+ if (!(s in i))
1196
+ throw new Error(`Unrecognized key: "${s}"`);
1197
+ n[s] && (i[s] = new e({
1198
+ type: "nonoptional",
1199
+ innerType: r[s]
1200
+ }));
1201
+ }
1202
+ else
1203
+ for (const s in r)
1204
+ i[s] = new e({
1205
+ type: "nonoptional",
1206
+ innerType: r[s]
1207
+ });
1208
+ return G(this, "shape", i), i;
1209
+ }
1210
+ });
1211
+ return j(t, o);
1212
+ }
1213
+ function H(e, t = 0) {
1214
+ if (e.aborted === !0)
1215
+ return !0;
1216
+ for (let n = t; n < e.issues.length; n++)
1217
+ if (e.issues[n]?.continue !== !0)
1218
+ return !0;
1219
+ return !1;
1220
+ }
1221
+ function ut(e, t) {
1222
+ return t.map((n) => {
1223
+ var o;
1224
+ return (o = n).path ?? (o.path = []), n.path.unshift(e), n;
1225
+ });
1226
+ }
1227
+ function ee(e) {
1228
+ return typeof e == "string" ? e : e?.message;
1229
+ }
1230
+ function U(e, t, n) {
1231
+ const o = { ...e, path: e.path ?? [] };
1232
+ if (!e.message) {
1233
+ const r = ee(e.inst?._zod.def?.error?.(e)) ?? ee(t?.error?.(e)) ?? ee(n.customError?.(e)) ?? ee(n.localeError?.(e)) ?? "Invalid input";
1234
+ o.message = r;
1235
+ }
1236
+ return delete o.inst, delete o.continue, t?.reportInput || delete o.input, o;
1237
+ }
1238
+ function ke(e) {
1239
+ return Array.isArray(e) ? "array" : typeof e == "string" ? "string" : "unknown";
1240
+ }
1241
+ function Q(...e) {
1242
+ const [t, n, o] = e;
1243
+ return typeof t == "string" ? {
1244
+ message: t,
1245
+ code: "custom",
1246
+ input: n,
1247
+ inst: o
1248
+ } : { ...t };
1249
+ }
1250
+ const lt = (e, t) => {
1251
+ e.name = "$ZodError", Object.defineProperty(e, "_zod", {
1252
+ value: e._zod,
1253
+ enumerable: !1
1254
+ }), Object.defineProperty(e, "issues", {
1255
+ value: t,
1256
+ enumerable: !1
1257
+ }), e.message = JSON.stringify(t, me, 2), Object.defineProperty(e, "toString", {
1258
+ value: () => e.message,
1259
+ enumerable: !1
1260
+ });
1261
+ }, ht = u("$ZodError", lt), dt = u("$ZodError", lt, { Parent: Error });
1262
+ function Pn(e, t = (n) => n.message) {
1263
+ const n = {}, o = [];
1264
+ for (const r of e.issues)
1265
+ r.path.length > 0 ? (n[r.path[0]] = n[r.path[0]] || [], n[r.path[0]].push(t(r))) : o.push(t(r));
1266
+ return { formErrors: o, fieldErrors: n };
1267
+ }
1268
+ function Tn(e, t = (n) => n.message) {
1269
+ const n = { _errors: [] }, o = (r) => {
1270
+ for (const i of r.issues)
1271
+ if (i.code === "invalid_union" && i.errors.length)
1272
+ i.errors.map((s) => o({ issues: s }));
1273
+ else if (i.code === "invalid_key")
1274
+ o({ issues: i.issues });
1275
+ else if (i.code === "invalid_element")
1276
+ o({ issues: i.issues });
1277
+ else if (i.path.length === 0)
1278
+ n._errors.push(t(i));
1279
+ else {
1280
+ let s = n, a = 0;
1281
+ for (; a < i.path.length; ) {
1282
+ const c = i.path[a];
1283
+ a === i.path.length - 1 ? (s[c] = s[c] || { _errors: [] }, s[c]._errors.push(t(i))) : s[c] = s[c] || { _errors: [] }, s = s[c], a++;
1284
+ }
1285
+ }
1286
+ };
1287
+ return o(e), n;
1288
+ }
1289
+ const ze = (e) => (t, n, o, r) => {
1290
+ const i = o ? Object.assign(o, { async: !1 }) : { async: !1 }, s = t._zod.run({ value: n, issues: [] }, i);
1291
+ if (s instanceof Promise)
1292
+ throw new B();
1293
+ if (s.issues.length) {
1294
+ const a = new (r?.Err ?? e)(s.issues.map((c) => U(c, i, F())));
1295
+ throw at(a, r?.callee), a;
1296
+ }
1297
+ return s.value;
1298
+ }, Pe = (e) => async (t, n, o, r) => {
1299
+ const i = o ? Object.assign(o, { async: !0 }) : { async: !0 };
1300
+ let s = t._zod.run({ value: n, issues: [] }, i);
1301
+ if (s instanceof Promise && (s = await s), s.issues.length) {
1302
+ const a = new (r?.Err ?? e)(s.issues.map((c) => U(c, i, F())));
1303
+ throw at(a, r?.callee), a;
1304
+ }
1305
+ return s.value;
1306
+ }, ce = (e) => (t, n, o) => {
1307
+ const r = o ? { ...o, async: !1 } : { async: !1 }, i = t._zod.run({ value: n, issues: [] }, r);
1308
+ if (i instanceof Promise)
1309
+ throw new B();
1310
+ return i.issues.length ? {
1311
+ success: !1,
1312
+ error: new (e ?? ht)(i.issues.map((s) => U(s, r, F())))
1313
+ } : { success: !0, data: i.value };
1314
+ }, En = /* @__PURE__ */ ce(dt), ue = (e) => async (t, n, o) => {
1315
+ const r = o ? Object.assign(o, { async: !0 }) : { async: !0 };
1316
+ let i = t._zod.run({ value: n, issues: [] }, r);
1317
+ return i instanceof Promise && (i = await i), i.issues.length ? {
1318
+ success: !1,
1319
+ error: new e(i.issues.map((s) => U(s, r, F())))
1320
+ } : { success: !0, data: i.value };
1321
+ }, Sn = /* @__PURE__ */ ue(dt), On = (e) => (t, n, o) => {
1322
+ const r = o ? Object.assign(o, { direction: "backward" }) : { direction: "backward" };
1323
+ return ze(e)(t, n, r);
1324
+ }, An = (e) => (t, n, o) => ze(e)(t, n, o), Zn = (e) => async (t, n, o) => {
1325
+ const r = o ? Object.assign(o, { direction: "backward" }) : { direction: "backward" };
1326
+ return Pe(e)(t, n, r);
1327
+ }, In = (e) => async (t, n, o) => Pe(e)(t, n, o), $n = (e) => (t, n, o) => {
1328
+ const r = o ? Object.assign(o, { direction: "backward" }) : { direction: "backward" };
1329
+ return ce(e)(t, n, r);
1330
+ }, Dn = (e) => (t, n, o) => ce(e)(t, n, o), Mn = (e) => async (t, n, o) => {
1331
+ const r = o ? Object.assign(o, { direction: "backward" }) : { direction: "backward" };
1332
+ return ue(e)(t, n, r);
1333
+ }, Cn = (e) => async (t, n, o) => ue(e)(t, n, o), Nn = /^[cC][^\s-]{8,}$/, Rn = /^[0-9a-z]+$/, Ln = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/, jn = /^[0-9a-vA-V]{20}$/, xn = /^[A-Za-z0-9]{27}$/, Fn = /^[a-zA-Z0-9_-]{21}$/, Un = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/, Gn = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/, Ne = (e) => e ? new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`) : /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/, Vn = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/, Wn = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
1334
+ function Hn() {
1335
+ return new RegExp(Wn, "u");
1336
+ }
1337
+ const Kn = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, Bn = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/, Yn = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/, Jn = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, Xn = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, pt = /^[A-Za-z0-9_-]*$/, Qn = /^\+[1-9]\d{6,14}$/, ft = "(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))", qn = /* @__PURE__ */ new RegExp(`^${ft}$`);
1338
+ function mt(e) {
1339
+ const t = "(?:[01]\\d|2[0-3]):[0-5]\\d";
1340
+ return typeof e.precision == "number" ? e.precision === -1 ? `${t}` : e.precision === 0 ? `${t}:[0-5]\\d` : `${t}:[0-5]\\d\\.\\d{${e.precision}}` : `${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;
1341
+ }
1342
+ function eo(e) {
1343
+ return new RegExp(`^${mt(e)}$`);
1344
+ }
1345
+ function to(e) {
1346
+ const t = mt({ precision: e.precision }), n = ["Z"];
1347
+ e.local && n.push(""), e.offset && n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");
1348
+ const o = `${t}(?:${n.join("|")})`;
1349
+ return new RegExp(`^${ft}T(?:${o})$`);
1350
+ }
1351
+ const no = (e) => {
1352
+ const t = e ? `[\\s\\S]{${e?.minimum ?? 0},${e?.maximum ?? ""}}` : "[\\s\\S]*";
1353
+ return new RegExp(`^${t}$`);
1354
+ }, oo = /^-?\d+$/, ro = /^-?\d+(?:\.\d+)?$/, io = /^[^A-Z]*$/, so = /^[^a-z]*$/, I = /* @__PURE__ */ u("$ZodCheck", (e, t) => {
1355
+ var n;
1356
+ e._zod ?? (e._zod = {}), e._zod.def = t, (n = e._zod).onattach ?? (n.onattach = []);
1357
+ }), _t = {
1358
+ number: "number",
1359
+ bigint: "bigint",
1360
+ object: "date"
1361
+ }, gt = /* @__PURE__ */ u("$ZodCheckLessThan", (e, t) => {
1362
+ I.init(e, t);
1363
+ const n = _t[typeof t.value];
1364
+ e._zod.onattach.push((o) => {
1365
+ const r = o._zod.bag, i = (t.inclusive ? r.maximum : r.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
1366
+ t.value < i && (t.inclusive ? r.maximum = t.value : r.exclusiveMaximum = t.value);
1367
+ }), e._zod.check = (o) => {
1368
+ (t.inclusive ? o.value <= t.value : o.value < t.value) || o.issues.push({
1369
+ origin: n,
1370
+ code: "too_big",
1371
+ maximum: typeof t.value == "object" ? t.value.getTime() : t.value,
1372
+ input: o.value,
1373
+ inclusive: t.inclusive,
1374
+ inst: e,
1375
+ continue: !t.abort
1376
+ });
1377
+ };
1378
+ }), bt = /* @__PURE__ */ u("$ZodCheckGreaterThan", (e, t) => {
1379
+ I.init(e, t);
1380
+ const n = _t[typeof t.value];
1381
+ e._zod.onattach.push((o) => {
1382
+ const r = o._zod.bag, i = (t.inclusive ? r.minimum : r.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
1383
+ t.value > i && (t.inclusive ? r.minimum = t.value : r.exclusiveMinimum = t.value);
1384
+ }), e._zod.check = (o) => {
1385
+ (t.inclusive ? o.value >= t.value : o.value > t.value) || o.issues.push({
1386
+ origin: n,
1387
+ code: "too_small",
1388
+ minimum: typeof t.value == "object" ? t.value.getTime() : t.value,
1389
+ input: o.value,
1390
+ inclusive: t.inclusive,
1391
+ inst: e,
1392
+ continue: !t.abort
1393
+ });
1394
+ };
1395
+ }), ao = /* @__PURE__ */ u("$ZodCheckMultipleOf", (e, t) => {
1396
+ I.init(e, t), e._zod.onattach.push((n) => {
1397
+ var o;
1398
+ (o = n._zod.bag).multipleOf ?? (o.multipleOf = t.value);
1399
+ }), e._zod.check = (n) => {
1400
+ if (typeof n.value != typeof t.value)
1401
+ throw new Error("Cannot mix number and bigint in multiple_of check.");
1402
+ (typeof n.value == "bigint" ? n.value % t.value === BigInt(0) : hn(n.value, t.value) === 0) || n.issues.push({
1403
+ origin: typeof n.value,
1404
+ code: "not_multiple_of",
1405
+ divisor: t.value,
1406
+ input: n.value,
1407
+ inst: e,
1408
+ continue: !t.abort
1409
+ });
1410
+ };
1411
+ }), co = /* @__PURE__ */ u("$ZodCheckNumberFormat", (e, t) => {
1412
+ I.init(e, t), t.format = t.format || "float64";
1413
+ const n = t.format?.includes("int"), o = n ? "int" : "number", [r, i] = _n[t.format];
1414
+ e._zod.onattach.push((s) => {
1415
+ const a = s._zod.bag;
1416
+ a.format = t.format, a.minimum = r, a.maximum = i, n && (a.pattern = oo);
1417
+ }), e._zod.check = (s) => {
1418
+ const a = s.value;
1419
+ if (n) {
1420
+ if (!Number.isInteger(a)) {
1421
+ s.issues.push({
1422
+ expected: o,
1423
+ format: t.format,
1424
+ code: "invalid_type",
1425
+ continue: !1,
1426
+ input: a,
1427
+ inst: e
1428
+ });
1429
+ return;
1430
+ }
1431
+ if (!Number.isSafeInteger(a)) {
1432
+ a > 0 ? s.issues.push({
1433
+ input: a,
1434
+ code: "too_big",
1435
+ maximum: Number.MAX_SAFE_INTEGER,
1436
+ note: "Integers must be within the safe integer range.",
1437
+ inst: e,
1438
+ origin: o,
1439
+ inclusive: !0,
1440
+ continue: !t.abort
1441
+ }) : s.issues.push({
1442
+ input: a,
1443
+ code: "too_small",
1444
+ minimum: Number.MIN_SAFE_INTEGER,
1445
+ note: "Integers must be within the safe integer range.",
1446
+ inst: e,
1447
+ origin: o,
1448
+ inclusive: !0,
1449
+ continue: !t.abort
1450
+ });
1451
+ return;
1452
+ }
1453
+ }
1454
+ a < r && s.issues.push({
1455
+ origin: "number",
1456
+ input: a,
1457
+ code: "too_small",
1458
+ minimum: r,
1459
+ inclusive: !0,
1460
+ inst: e,
1461
+ continue: !t.abort
1462
+ }), a > i && s.issues.push({
1463
+ origin: "number",
1464
+ input: a,
1465
+ code: "too_big",
1466
+ maximum: i,
1467
+ inclusive: !0,
1468
+ inst: e,
1469
+ continue: !t.abort
1470
+ });
1471
+ };
1472
+ }), uo = /* @__PURE__ */ u("$ZodCheckMaxLength", (e, t) => {
1473
+ var n;
1474
+ I.init(e, t), (n = e._zod.def).when ?? (n.when = (o) => {
1475
+ const r = o.value;
1476
+ return !ve(r) && r.length !== void 0;
1477
+ }), e._zod.onattach.push((o) => {
1478
+ const r = o._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
1479
+ t.maximum < r && (o._zod.bag.maximum = t.maximum);
1480
+ }), e._zod.check = (o) => {
1481
+ const r = o.value;
1482
+ if (r.length <= t.maximum)
1483
+ return;
1484
+ const s = ke(r);
1485
+ o.issues.push({
1486
+ origin: s,
1487
+ code: "too_big",
1488
+ maximum: t.maximum,
1489
+ inclusive: !0,
1490
+ input: r,
1491
+ inst: e,
1492
+ continue: !t.abort
1493
+ });
1494
+ };
1495
+ }), lo = /* @__PURE__ */ u("$ZodCheckMinLength", (e, t) => {
1496
+ var n;
1497
+ I.init(e, t), (n = e._zod.def).when ?? (n.when = (o) => {
1498
+ const r = o.value;
1499
+ return !ve(r) && r.length !== void 0;
1500
+ }), e._zod.onattach.push((o) => {
1501
+ const r = o._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
1502
+ t.minimum > r && (o._zod.bag.minimum = t.minimum);
1503
+ }), e._zod.check = (o) => {
1504
+ const r = o.value;
1505
+ if (r.length >= t.minimum)
1506
+ return;
1507
+ const s = ke(r);
1508
+ o.issues.push({
1509
+ origin: s,
1510
+ code: "too_small",
1511
+ minimum: t.minimum,
1512
+ inclusive: !0,
1513
+ input: r,
1514
+ inst: e,
1515
+ continue: !t.abort
1516
+ });
1517
+ };
1518
+ }), ho = /* @__PURE__ */ u("$ZodCheckLengthEquals", (e, t) => {
1519
+ var n;
1520
+ I.init(e, t), (n = e._zod.def).when ?? (n.when = (o) => {
1521
+ const r = o.value;
1522
+ return !ve(r) && r.length !== void 0;
1523
+ }), e._zod.onattach.push((o) => {
1524
+ const r = o._zod.bag;
1525
+ r.minimum = t.length, r.maximum = t.length, r.length = t.length;
1526
+ }), e._zod.check = (o) => {
1527
+ const r = o.value, i = r.length;
1528
+ if (i === t.length)
1529
+ return;
1530
+ const s = ke(r), a = i > t.length;
1531
+ o.issues.push({
1532
+ origin: s,
1533
+ ...a ? { code: "too_big", maximum: t.length } : { code: "too_small", minimum: t.length },
1534
+ inclusive: !0,
1535
+ exact: !0,
1536
+ input: o.value,
1537
+ inst: e,
1538
+ continue: !t.abort
1539
+ });
1540
+ };
1541
+ }), le = /* @__PURE__ */ u("$ZodCheckStringFormat", (e, t) => {
1542
+ var n, o;
1543
+ I.init(e, t), e._zod.onattach.push((r) => {
1544
+ const i = r._zod.bag;
1545
+ i.format = t.format, t.pattern && (i.patterns ?? (i.patterns = /* @__PURE__ */ new Set()), i.patterns.add(t.pattern));
1546
+ }), t.pattern ? (n = e._zod).check ?? (n.check = (r) => {
1547
+ t.pattern.lastIndex = 0, !t.pattern.test(r.value) && r.issues.push({
1548
+ origin: "string",
1549
+ code: "invalid_format",
1550
+ format: t.format,
1551
+ input: r.value,
1552
+ ...t.pattern ? { pattern: t.pattern.toString() } : {},
1553
+ inst: e,
1554
+ continue: !t.abort
1555
+ });
1556
+ }) : (o = e._zod).check ?? (o.check = () => {
1557
+ });
1558
+ }), po = /* @__PURE__ */ u("$ZodCheckRegex", (e, t) => {
1559
+ le.init(e, t), e._zod.check = (n) => {
1560
+ t.pattern.lastIndex = 0, !t.pattern.test(n.value) && n.issues.push({
1561
+ origin: "string",
1562
+ code: "invalid_format",
1563
+ format: "regex",
1564
+ input: n.value,
1565
+ pattern: t.pattern.toString(),
1566
+ inst: e,
1567
+ continue: !t.abort
1568
+ });
1569
+ };
1570
+ }), fo = /* @__PURE__ */ u("$ZodCheckLowerCase", (e, t) => {
1571
+ t.pattern ?? (t.pattern = io), le.init(e, t);
1572
+ }), mo = /* @__PURE__ */ u("$ZodCheckUpperCase", (e, t) => {
1573
+ t.pattern ?? (t.pattern = so), le.init(e, t);
1574
+ }), _o = /* @__PURE__ */ u("$ZodCheckIncludes", (e, t) => {
1575
+ I.init(e, t);
1576
+ const n = ae(t.includes), o = new RegExp(typeof t.position == "number" ? `^.{${t.position}}${n}` : n);
1577
+ t.pattern = o, e._zod.onattach.push((r) => {
1578
+ const i = r._zod.bag;
1579
+ i.patterns ?? (i.patterns = /* @__PURE__ */ new Set()), i.patterns.add(o);
1580
+ }), e._zod.check = (r) => {
1581
+ r.value.includes(t.includes, t.position) || r.issues.push({
1582
+ origin: "string",
1583
+ code: "invalid_format",
1584
+ format: "includes",
1585
+ includes: t.includes,
1586
+ input: r.value,
1587
+ inst: e,
1588
+ continue: !t.abort
1589
+ });
1590
+ };
1591
+ }), go = /* @__PURE__ */ u("$ZodCheckStartsWith", (e, t) => {
1592
+ I.init(e, t);
1593
+ const n = new RegExp(`^${ae(t.prefix)}.*`);
1594
+ t.pattern ?? (t.pattern = n), e._zod.onattach.push((o) => {
1595
+ const r = o._zod.bag;
1596
+ r.patterns ?? (r.patterns = /* @__PURE__ */ new Set()), r.patterns.add(n);
1597
+ }), e._zod.check = (o) => {
1598
+ o.value.startsWith(t.prefix) || o.issues.push({
1599
+ origin: "string",
1600
+ code: "invalid_format",
1601
+ format: "starts_with",
1602
+ prefix: t.prefix,
1603
+ input: o.value,
1604
+ inst: e,
1605
+ continue: !t.abort
1606
+ });
1607
+ };
1608
+ }), bo = /* @__PURE__ */ u("$ZodCheckEndsWith", (e, t) => {
1609
+ I.init(e, t);
1610
+ const n = new RegExp(`.*${ae(t.suffix)}$`);
1611
+ t.pattern ?? (t.pattern = n), e._zod.onattach.push((o) => {
1612
+ const r = o._zod.bag;
1613
+ r.patterns ?? (r.patterns = /* @__PURE__ */ new Set()), r.patterns.add(n);
1614
+ }), e._zod.check = (o) => {
1615
+ o.value.endsWith(t.suffix) || o.issues.push({
1616
+ origin: "string",
1617
+ code: "invalid_format",
1618
+ format: "ends_with",
1619
+ suffix: t.suffix,
1620
+ input: o.value,
1621
+ inst: e,
1622
+ continue: !t.abort
1623
+ });
1624
+ };
1625
+ }), yo = /* @__PURE__ */ u("$ZodCheckOverwrite", (e, t) => {
1626
+ I.init(e, t), e._zod.check = (n) => {
1627
+ n.value = t.tx(n.value);
1628
+ };
1629
+ });
1630
+ class vo {
1631
+ constructor(t = []) {
1632
+ this.content = [], this.indent = 0, this && (this.args = t);
1633
+ }
1634
+ indented(t) {
1635
+ this.indent += 1, t(this), this.indent -= 1;
1636
+ }
1637
+ write(t) {
1638
+ if (typeof t == "function") {
1639
+ t(this, { execution: "sync" }), t(this, { execution: "async" });
1640
+ return;
1641
+ }
1642
+ const o = t.split(`
1643
+ `).filter((s) => s), r = Math.min(...o.map((s) => s.length - s.trimStart().length)), i = o.map((s) => s.slice(r)).map((s) => " ".repeat(this.indent * 2) + s);
1644
+ for (const s of i)
1645
+ this.content.push(s);
1646
+ }
1647
+ compile() {
1648
+ const t = Function, n = this?.args, r = [...(this?.content ?? [""]).map((i) => ` ${i}`)];
1649
+ return new t(...n, r.join(`
1650
+ `));
1651
+ }
1652
+ }
1653
+ const wo = {
1654
+ major: 4,
1655
+ minor: 3,
1656
+ patch: 5
1657
+ }, P = /* @__PURE__ */ u("$ZodType", (e, t) => {
1658
+ var n;
1659
+ e ?? (e = {}), e._zod.def = t, e._zod.bag = e._zod.bag || {}, e._zod.version = wo;
1660
+ const o = [...e._zod.def.checks ?? []];
1661
+ e._zod.traits.has("$ZodCheck") && o.unshift(e);
1662
+ for (const r of o)
1663
+ for (const i of r._zod.onattach)
1664
+ i(e);
1665
+ if (o.length === 0)
1666
+ (n = e._zod).deferred ?? (n.deferred = []), e._zod.deferred?.push(() => {
1667
+ e._zod.run = e._zod.parse;
1668
+ });
1669
+ else {
1670
+ const r = (s, a, c) => {
1671
+ let l = H(s), h;
1672
+ for (const _ of a) {
1673
+ if (_._zod.def.when) {
1674
+ if (!_._zod.def.when(s))
1675
+ continue;
1676
+ } else if (l)
1677
+ continue;
1678
+ const p = s.issues.length, m = _._zod.check(s);
1679
+ if (m instanceof Promise && c?.async === !1)
1680
+ throw new B();
1681
+ if (h || m instanceof Promise)
1682
+ h = (h ?? Promise.resolve()).then(async () => {
1683
+ await m, s.issues.length !== p && (l || (l = H(s, p)));
1684
+ });
1685
+ else {
1686
+ if (s.issues.length === p)
1687
+ continue;
1688
+ l || (l = H(s, p));
1689
+ }
1690
+ }
1691
+ return h ? h.then(() => s) : s;
1692
+ }, i = (s, a, c) => {
1693
+ if (H(s))
1694
+ return s.aborted = !0, s;
1695
+ const l = r(a, o, c);
1696
+ if (l instanceof Promise) {
1697
+ if (c.async === !1)
1698
+ throw new B();
1699
+ return l.then((h) => e._zod.parse(h, c));
1700
+ }
1701
+ return e._zod.parse(l, c);
1702
+ };
1703
+ e._zod.run = (s, a) => {
1704
+ if (a.skipChecks)
1705
+ return e._zod.parse(s, a);
1706
+ if (a.direction === "backward") {
1707
+ const l = e._zod.parse({ value: s.value, issues: [] }, { ...a, skipChecks: !0 });
1708
+ return l instanceof Promise ? l.then((h) => i(h, s, a)) : i(l, s, a);
1709
+ }
1710
+ const c = e._zod.parse(s, a);
1711
+ if (c instanceof Promise) {
1712
+ if (a.async === !1)
1713
+ throw new B();
1714
+ return c.then((l) => r(l, o, a));
1715
+ }
1716
+ return r(c, o, a);
1717
+ };
1718
+ }
1719
+ g(e, "~standard", () => ({
1720
+ validate: (r) => {
1721
+ try {
1722
+ const i = En(e, r);
1723
+ return i.success ? { value: i.data } : { issues: i.error?.issues };
1724
+ } catch {
1725
+ return Sn(e, r).then((s) => s.success ? { value: s.data } : { issues: s.error?.issues });
1726
+ }
1727
+ },
1728
+ vendor: "zod",
1729
+ version: 1
1730
+ }));
1731
+ }), Te = /* @__PURE__ */ u("$ZodString", (e, t) => {
1732
+ P.init(e, t), e._zod.pattern = [...e?._zod.bag?.patterns ?? []].pop() ?? no(e._zod.bag), e._zod.parse = (n, o) => {
1733
+ if (t.coerce)
1734
+ try {
1735
+ n.value = String(n.value);
1736
+ } catch {
1737
+ }
1738
+ return typeof n.value == "string" || n.issues.push({
1739
+ expected: "string",
1740
+ code: "invalid_type",
1741
+ input: n.value,
1742
+ inst: e
1743
+ }), n;
1744
+ };
1745
+ }), v = /* @__PURE__ */ u("$ZodStringFormat", (e, t) => {
1746
+ le.init(e, t), Te.init(e, t);
1747
+ }), ko = /* @__PURE__ */ u("$ZodGUID", (e, t) => {
1748
+ t.pattern ?? (t.pattern = Gn), v.init(e, t);
1749
+ }), zo = /* @__PURE__ */ u("$ZodUUID", (e, t) => {
1750
+ if (t.version) {
1751
+ const o = {
1752
+ v1: 1,
1753
+ v2: 2,
1754
+ v3: 3,
1755
+ v4: 4,
1756
+ v5: 5,
1757
+ v6: 6,
1758
+ v7: 7,
1759
+ v8: 8
1760
+ }[t.version];
1761
+ if (o === void 0)
1762
+ throw new Error(`Invalid UUID version: "${t.version}"`);
1763
+ t.pattern ?? (t.pattern = Ne(o));
1764
+ } else
1765
+ t.pattern ?? (t.pattern = Ne());
1766
+ v.init(e, t);
1767
+ }), Po = /* @__PURE__ */ u("$ZodEmail", (e, t) => {
1768
+ t.pattern ?? (t.pattern = Vn), v.init(e, t);
1769
+ }), To = /* @__PURE__ */ u("$ZodURL", (e, t) => {
1770
+ v.init(e, t), e._zod.check = (n) => {
1771
+ try {
1772
+ const o = n.value.trim(), r = new URL(o);
1773
+ t.hostname && (t.hostname.lastIndex = 0, t.hostname.test(r.hostname) || n.issues.push({
1774
+ code: "invalid_format",
1775
+ format: "url",
1776
+ note: "Invalid hostname",
1777
+ pattern: t.hostname.source,
1778
+ input: n.value,
1779
+ inst: e,
1780
+ continue: !t.abort
1781
+ })), t.protocol && (t.protocol.lastIndex = 0, t.protocol.test(r.protocol.endsWith(":") ? r.protocol.slice(0, -1) : r.protocol) || n.issues.push({
1782
+ code: "invalid_format",
1783
+ format: "url",
1784
+ note: "Invalid protocol",
1785
+ pattern: t.protocol.source,
1786
+ input: n.value,
1787
+ inst: e,
1788
+ continue: !t.abort
1789
+ })), t.normalize ? n.value = r.href : n.value = o;
1790
+ return;
1791
+ } catch {
1792
+ n.issues.push({
1793
+ code: "invalid_format",
1794
+ format: "url",
1795
+ input: n.value,
1796
+ inst: e,
1797
+ continue: !t.abort
1798
+ });
1799
+ }
1800
+ };
1801
+ }), Eo = /* @__PURE__ */ u("$ZodEmoji", (e, t) => {
1802
+ t.pattern ?? (t.pattern = Hn()), v.init(e, t);
1803
+ }), So = /* @__PURE__ */ u("$ZodNanoID", (e, t) => {
1804
+ t.pattern ?? (t.pattern = Fn), v.init(e, t);
1805
+ }), Oo = /* @__PURE__ */ u("$ZodCUID", (e, t) => {
1806
+ t.pattern ?? (t.pattern = Nn), v.init(e, t);
1807
+ }), Ao = /* @__PURE__ */ u("$ZodCUID2", (e, t) => {
1808
+ t.pattern ?? (t.pattern = Rn), v.init(e, t);
1809
+ }), Zo = /* @__PURE__ */ u("$ZodULID", (e, t) => {
1810
+ t.pattern ?? (t.pattern = Ln), v.init(e, t);
1811
+ }), Io = /* @__PURE__ */ u("$ZodXID", (e, t) => {
1812
+ t.pattern ?? (t.pattern = jn), v.init(e, t);
1813
+ }), $o = /* @__PURE__ */ u("$ZodKSUID", (e, t) => {
1814
+ t.pattern ?? (t.pattern = xn), v.init(e, t);
1815
+ }), Do = /* @__PURE__ */ u("$ZodISODateTime", (e, t) => {
1816
+ t.pattern ?? (t.pattern = to(t)), v.init(e, t);
1817
+ }), Mo = /* @__PURE__ */ u("$ZodISODate", (e, t) => {
1818
+ t.pattern ?? (t.pattern = qn), v.init(e, t);
1819
+ }), Co = /* @__PURE__ */ u("$ZodISOTime", (e, t) => {
1820
+ t.pattern ?? (t.pattern = eo(t)), v.init(e, t);
1821
+ }), No = /* @__PURE__ */ u("$ZodISODuration", (e, t) => {
1822
+ t.pattern ?? (t.pattern = Un), v.init(e, t);
1823
+ }), Ro = /* @__PURE__ */ u("$ZodIPv4", (e, t) => {
1824
+ t.pattern ?? (t.pattern = Kn), v.init(e, t), e._zod.bag.format = "ipv4";
1825
+ }), Lo = /* @__PURE__ */ u("$ZodIPv6", (e, t) => {
1826
+ t.pattern ?? (t.pattern = Bn), v.init(e, t), e._zod.bag.format = "ipv6", e._zod.check = (n) => {
1827
+ try {
1828
+ new URL(`http://[${n.value}]`);
1829
+ } catch {
1830
+ n.issues.push({
1831
+ code: "invalid_format",
1832
+ format: "ipv6",
1833
+ input: n.value,
1834
+ inst: e,
1835
+ continue: !t.abort
1836
+ });
1837
+ }
1838
+ };
1839
+ }), jo = /* @__PURE__ */ u("$ZodCIDRv4", (e, t) => {
1840
+ t.pattern ?? (t.pattern = Yn), v.init(e, t);
1841
+ }), xo = /* @__PURE__ */ u("$ZodCIDRv6", (e, t) => {
1842
+ t.pattern ?? (t.pattern = Jn), v.init(e, t), e._zod.check = (n) => {
1843
+ const o = n.value.split("/");
1844
+ try {
1845
+ if (o.length !== 2)
1846
+ throw new Error();
1847
+ const [r, i] = o;
1848
+ if (!i)
1849
+ throw new Error();
1850
+ const s = Number(i);
1851
+ if (`${s}` !== i)
1852
+ throw new Error();
1853
+ if (s < 0 || s > 128)
1854
+ throw new Error();
1855
+ new URL(`http://[${r}]`);
1856
+ } catch {
1857
+ n.issues.push({
1858
+ code: "invalid_format",
1859
+ format: "cidrv6",
1860
+ input: n.value,
1861
+ inst: e,
1862
+ continue: !t.abort
1863
+ });
1864
+ }
1865
+ };
1866
+ });
1867
+ function yt(e) {
1868
+ if (e === "")
1869
+ return !0;
1870
+ if (e.length % 4 !== 0)
1871
+ return !1;
1872
+ try {
1873
+ return atob(e), !0;
1874
+ } catch {
1875
+ return !1;
1876
+ }
1877
+ }
1878
+ const Fo = /* @__PURE__ */ u("$ZodBase64", (e, t) => {
1879
+ t.pattern ?? (t.pattern = Xn), v.init(e, t), e._zod.bag.contentEncoding = "base64", e._zod.check = (n) => {
1880
+ yt(n.value) || n.issues.push({
1881
+ code: "invalid_format",
1882
+ format: "base64",
1883
+ input: n.value,
1884
+ inst: e,
1885
+ continue: !t.abort
1886
+ });
1887
+ };
1888
+ });
1889
+ function Uo(e) {
1890
+ if (!pt.test(e))
1891
+ return !1;
1892
+ const t = e.replace(/[-_]/g, (o) => o === "-" ? "+" : "/"), n = t.padEnd(Math.ceil(t.length / 4) * 4, "=");
1893
+ return yt(n);
1894
+ }
1895
+ const Go = /* @__PURE__ */ u("$ZodBase64URL", (e, t) => {
1896
+ t.pattern ?? (t.pattern = pt), v.init(e, t), e._zod.bag.contentEncoding = "base64url", e._zod.check = (n) => {
1897
+ Uo(n.value) || n.issues.push({
1898
+ code: "invalid_format",
1899
+ format: "base64url",
1900
+ input: n.value,
1901
+ inst: e,
1902
+ continue: !t.abort
1903
+ });
1904
+ };
1905
+ }), Vo = /* @__PURE__ */ u("$ZodE164", (e, t) => {
1906
+ t.pattern ?? (t.pattern = Qn), v.init(e, t);
1907
+ });
1908
+ function Wo(e, t = null) {
1909
+ try {
1910
+ const n = e.split(".");
1911
+ if (n.length !== 3)
1912
+ return !1;
1913
+ const [o] = n;
1914
+ if (!o)
1915
+ return !1;
1916
+ const r = JSON.parse(atob(o));
1917
+ return !("typ" in r && r?.typ !== "JWT" || !r.alg || t && (!("alg" in r) || r.alg !== t));
1918
+ } catch {
1919
+ return !1;
1920
+ }
1921
+ }
1922
+ const Ho = /* @__PURE__ */ u("$ZodJWT", (e, t) => {
1923
+ v.init(e, t), e._zod.check = (n) => {
1924
+ Wo(n.value, t.alg) || n.issues.push({
1925
+ code: "invalid_format",
1926
+ format: "jwt",
1927
+ input: n.value,
1928
+ inst: e,
1929
+ continue: !t.abort
1930
+ });
1931
+ };
1932
+ }), vt = /* @__PURE__ */ u("$ZodNumber", (e, t) => {
1933
+ P.init(e, t), e._zod.pattern = e._zod.bag.pattern ?? ro, e._zod.parse = (n, o) => {
1934
+ if (t.coerce)
1935
+ try {
1936
+ n.value = Number(n.value);
1937
+ } catch {
1938
+ }
1939
+ const r = n.value;
1940
+ if (typeof r == "number" && !Number.isNaN(r) && Number.isFinite(r))
1941
+ return n;
1942
+ const i = typeof r == "number" ? Number.isNaN(r) ? "NaN" : Number.isFinite(r) ? void 0 : "Infinity" : void 0;
1943
+ return n.issues.push({
1944
+ expected: "number",
1945
+ code: "invalid_type",
1946
+ input: r,
1947
+ inst: e,
1948
+ ...i ? { received: i } : {}
1949
+ }), n;
1950
+ };
1951
+ }), Ko = /* @__PURE__ */ u("$ZodNumberFormat", (e, t) => {
1952
+ co.init(e, t), vt.init(e, t);
1953
+ }), Bo = /* @__PURE__ */ u("$ZodUnknown", (e, t) => {
1954
+ P.init(e, t), e._zod.parse = (n) => n;
1955
+ }), Yo = /* @__PURE__ */ u("$ZodNever", (e, t) => {
1956
+ P.init(e, t), e._zod.parse = (n, o) => (n.issues.push({
1957
+ expected: "never",
1958
+ code: "invalid_type",
1959
+ input: n.value,
1960
+ inst: e
1961
+ }), n);
1962
+ });
1963
+ function Re(e, t, n) {
1964
+ e.issues.length && t.issues.push(...ut(n, e.issues)), t.value[n] = e.value;
1965
+ }
1966
+ const Jo = /* @__PURE__ */ u("$ZodArray", (e, t) => {
1967
+ P.init(e, t), e._zod.parse = (n, o) => {
1968
+ const r = n.value;
1969
+ if (!Array.isArray(r))
1970
+ return n.issues.push({
1971
+ expected: "array",
1972
+ code: "invalid_type",
1973
+ input: r,
1974
+ inst: e
1975
+ }), n;
1976
+ n.value = Array(r.length);
1977
+ const i = [];
1978
+ for (let s = 0; s < r.length; s++) {
1979
+ const a = r[s], c = t.element._zod.run({
1980
+ value: a,
1981
+ issues: []
1982
+ }, o);
1983
+ c instanceof Promise ? i.push(c.then((l) => Re(l, n, s))) : Re(c, n, s);
1984
+ }
1985
+ return i.length ? Promise.all(i).then(() => n) : n;
1986
+ };
1987
+ });
1988
+ function re(e, t, n, o, r) {
1989
+ if (e.issues.length) {
1990
+ if (r && !(n in o))
1991
+ return;
1992
+ t.issues.push(...ut(n, e.issues));
1993
+ }
1994
+ e.value === void 0 ? n in o && (t.value[n] = void 0) : t.value[n] = e.value;
1995
+ }
1996
+ function wt(e) {
1997
+ const t = Object.keys(e.shape);
1998
+ for (const o of t)
1999
+ if (!e.shape?.[o]?._zod?.traits?.has("$ZodType"))
2000
+ throw new Error(`Invalid element at key "${o}": expected a Zod schema`);
2001
+ const n = mn(e.shape);
2002
+ return {
2003
+ ...e,
2004
+ keys: t,
2005
+ keySet: new Set(t),
2006
+ numKeys: t.length,
2007
+ optionalKeys: new Set(n)
2008
+ };
2009
+ }
2010
+ function kt(e, t, n, o, r, i) {
2011
+ const s = [], a = r.keySet, c = r.catchall._zod, l = c.def.type, h = c.optout === "optional";
2012
+ for (const _ in t) {
2013
+ if (a.has(_))
2014
+ continue;
2015
+ if (l === "never") {
2016
+ s.push(_);
2017
+ continue;
2018
+ }
2019
+ const p = c.run({ value: t[_], issues: [] }, o);
2020
+ p instanceof Promise ? e.push(p.then((m) => re(m, n, _, t, h))) : re(p, n, _, t, h);
2021
+ }
2022
+ return s.length && n.issues.push({
2023
+ code: "unrecognized_keys",
2024
+ keys: s,
2025
+ input: t,
2026
+ inst: i
2027
+ }), e.length ? Promise.all(e).then(() => n) : n;
2028
+ }
2029
+ const Xo = /* @__PURE__ */ u("$ZodObject", (e, t) => {
2030
+ if (P.init(e, t), !Object.getOwnPropertyDescriptor(t, "shape")?.get) {
2031
+ const a = t.shape;
2032
+ Object.defineProperty(t, "shape", {
2033
+ get: () => {
2034
+ const c = { ...a };
2035
+ return Object.defineProperty(t, "shape", {
2036
+ value: c
2037
+ }), c;
2038
+ }
2039
+ });
2040
+ }
2041
+ const o = ye(() => wt(t));
2042
+ g(e._zod, "propValues", () => {
2043
+ const a = t.shape, c = {};
2044
+ for (const l in a) {
2045
+ const h = a[l]._zod;
2046
+ if (h.values) {
2047
+ c[l] ?? (c[l] = /* @__PURE__ */ new Set());
2048
+ for (const _ of h.values)
2049
+ c[l].add(_);
2050
+ }
2051
+ }
2052
+ return c;
2053
+ });
2054
+ const r = oe, i = t.catchall;
2055
+ let s;
2056
+ e._zod.parse = (a, c) => {
2057
+ s ?? (s = o.value);
2058
+ const l = a.value;
2059
+ if (!r(l))
2060
+ return a.issues.push({
2061
+ expected: "object",
2062
+ code: "invalid_type",
2063
+ input: l,
2064
+ inst: e
2065
+ }), a;
2066
+ a.value = {};
2067
+ const h = [], _ = s.shape;
2068
+ for (const p of s.keys) {
2069
+ const m = _[p], k = m._zod.optout === "optional", z = m._zod.run({ value: l[p], issues: [] }, c);
2070
+ z instanceof Promise ? h.push(z.then((V) => re(V, a, p, l, k))) : re(z, a, p, l, k);
2071
+ }
2072
+ return i ? kt(h, l, a, c, o.value, e) : h.length ? Promise.all(h).then(() => a) : a;
2073
+ };
2074
+ }), Qo = /* @__PURE__ */ u("$ZodObjectJIT", (e, t) => {
2075
+ Xo.init(e, t);
2076
+ const n = e._zod.parse, o = ye(() => wt(t)), r = (p) => {
2077
+ const m = new vo(["shape", "payload", "ctx"]), k = o.value, z = ($) => {
2078
+ const y = Ce($);
2079
+ return `shape[${y}]._zod.run({ value: input[${y}], issues: [] }, ctx)`;
2080
+ };
2081
+ m.write("const input = payload.value;");
2082
+ const V = /* @__PURE__ */ Object.create(null);
2083
+ let x = 0;
2084
+ for (const $ of k.keys)
2085
+ V[$] = `key_${x++}`;
2086
+ m.write("const newResult = {};");
2087
+ for (const $ of k.keys) {
2088
+ const y = V[$], A = Ce($), Oe = p[$]?._zod?.optout === "optional";
2089
+ m.write(`const ${y} = ${z($)};`), Oe ? m.write(`
2090
+ if (${y}.issues.length) {
2091
+ if (${A} in input) {
2092
+ payload.issues = payload.issues.concat(${y}.issues.map(iss => ({
2093
+ ...iss,
2094
+ path: iss.path ? [${A}, ...iss.path] : [${A}]
2095
+ })));
2096
+ }
2097
+ }
2098
+
2099
+ if (${y}.value === undefined) {
2100
+ if (${A} in input) {
2101
+ newResult[${A}] = undefined;
2102
+ }
2103
+ } else {
2104
+ newResult[${A}] = ${y}.value;
2105
+ }
2106
+
2107
+ `) : m.write(`
2108
+ if (${y}.issues.length) {
2109
+ payload.issues = payload.issues.concat(${y}.issues.map(iss => ({
2110
+ ...iss,
2111
+ path: iss.path ? [${A}, ...iss.path] : [${A}]
2112
+ })));
2113
+ }
2114
+
2115
+ if (${y}.value === undefined) {
2116
+ if (${A} in input) {
2117
+ newResult[${A}] = undefined;
2118
+ }
2119
+ } else {
2120
+ newResult[${A}] = ${y}.value;
2121
+ }
2122
+
2123
+ `);
2124
+ }
2125
+ m.write("payload.value = newResult;"), m.write("return payload;");
2126
+ const he = m.compile();
2127
+ return ($, y) => he(p, $, y);
2128
+ };
2129
+ let i;
2130
+ const s = oe, a = !it.jitless, l = a && pn.value, h = t.catchall;
2131
+ let _;
2132
+ e._zod.parse = (p, m) => {
2133
+ _ ?? (_ = o.value);
2134
+ const k = p.value;
2135
+ return s(k) ? a && l && m?.async === !1 && m.jitless !== !0 ? (i || (i = r(t.shape)), p = i(p, m), h ? kt([], k, p, m, _, e) : p) : n(p, m) : (p.issues.push({
2136
+ expected: "object",
2137
+ code: "invalid_type",
2138
+ input: k,
2139
+ inst: e
2140
+ }), p);
2141
+ };
2142
+ });
2143
+ function Le(e, t, n, o) {
2144
+ for (const i of e)
2145
+ if (i.issues.length === 0)
2146
+ return t.value = i.value, t;
2147
+ const r = e.filter((i) => !H(i));
2148
+ return r.length === 1 ? (t.value = r[0].value, r[0]) : (t.issues.push({
2149
+ code: "invalid_union",
2150
+ input: t.value,
2151
+ inst: n,
2152
+ errors: e.map((i) => i.issues.map((s) => U(s, o, F())))
2153
+ }), t);
2154
+ }
2155
+ const qo = /* @__PURE__ */ u("$ZodUnion", (e, t) => {
2156
+ P.init(e, t), g(e._zod, "optin", () => t.options.some((r) => r._zod.optin === "optional") ? "optional" : void 0), g(e._zod, "optout", () => t.options.some((r) => r._zod.optout === "optional") ? "optional" : void 0), g(e._zod, "values", () => {
2157
+ if (t.options.every((r) => r._zod.values))
2158
+ return new Set(t.options.flatMap((r) => Array.from(r._zod.values)));
2159
+ }), g(e._zod, "pattern", () => {
2160
+ if (t.options.every((r) => r._zod.pattern)) {
2161
+ const r = t.options.map((i) => i._zod.pattern);
2162
+ return new RegExp(`^(${r.map((i) => we(i.source)).join("|")})$`);
2163
+ }
2164
+ });
2165
+ const n = t.options.length === 1, o = t.options[0]._zod.run;
2166
+ e._zod.parse = (r, i) => {
2167
+ if (n)
2168
+ return o(r, i);
2169
+ let s = !1;
2170
+ const a = [];
2171
+ for (const c of t.options) {
2172
+ const l = c._zod.run({
2173
+ value: r.value,
2174
+ issues: []
2175
+ }, i);
2176
+ if (l instanceof Promise)
2177
+ a.push(l), s = !0;
2178
+ else {
2179
+ if (l.issues.length === 0)
2180
+ return l;
2181
+ a.push(l);
2182
+ }
2183
+ }
2184
+ return s ? Promise.all(a).then((c) => Le(c, r, e, i)) : Le(a, r, e, i);
2185
+ };
2186
+ }), er = /* @__PURE__ */ u("$ZodIntersection", (e, t) => {
2187
+ P.init(e, t), e._zod.parse = (n, o) => {
2188
+ const r = n.value, i = t.left._zod.run({ value: r, issues: [] }, o), s = t.right._zod.run({ value: r, issues: [] }, o);
2189
+ return i instanceof Promise || s instanceof Promise ? Promise.all([i, s]).then(([c, l]) => je(n, c, l)) : je(n, i, s);
2190
+ };
2191
+ });
2192
+ function _e(e, t) {
2193
+ if (e === t)
2194
+ return { valid: !0, data: e };
2195
+ if (e instanceof Date && t instanceof Date && +e == +t)
2196
+ return { valid: !0, data: e };
2197
+ if (X(e) && X(t)) {
2198
+ const n = Object.keys(t), o = Object.keys(e).filter((i) => n.indexOf(i) !== -1), r = { ...e, ...t };
2199
+ for (const i of o) {
2200
+ const s = _e(e[i], t[i]);
2201
+ if (!s.valid)
2202
+ return {
2203
+ valid: !1,
2204
+ mergeErrorPath: [i, ...s.mergeErrorPath]
2205
+ };
2206
+ r[i] = s.data;
2207
+ }
2208
+ return { valid: !0, data: r };
2209
+ }
2210
+ if (Array.isArray(e) && Array.isArray(t)) {
2211
+ if (e.length !== t.length)
2212
+ return { valid: !1, mergeErrorPath: [] };
2213
+ const n = [];
2214
+ for (let o = 0; o < e.length; o++) {
2215
+ const r = e[o], i = t[o], s = _e(r, i);
2216
+ if (!s.valid)
2217
+ return {
2218
+ valid: !1,
2219
+ mergeErrorPath: [o, ...s.mergeErrorPath]
2220
+ };
2221
+ n.push(s.data);
2222
+ }
2223
+ return { valid: !0, data: n };
2224
+ }
2225
+ return { valid: !1, mergeErrorPath: [] };
2226
+ }
2227
+ function je(e, t, n) {
2228
+ const o = /* @__PURE__ */ new Map();
2229
+ let r;
2230
+ for (const a of t.issues)
2231
+ if (a.code === "unrecognized_keys") {
2232
+ r ?? (r = a);
2233
+ for (const c of a.keys)
2234
+ o.has(c) || o.set(c, {}), o.get(c).l = !0;
2235
+ } else
2236
+ e.issues.push(a);
2237
+ for (const a of n.issues)
2238
+ if (a.code === "unrecognized_keys")
2239
+ for (const c of a.keys)
2240
+ o.has(c) || o.set(c, {}), o.get(c).r = !0;
2241
+ else
2242
+ e.issues.push(a);
2243
+ const i = [...o].filter(([, a]) => a.l && a.r).map(([a]) => a);
2244
+ if (i.length && r && e.issues.push({ ...r, keys: i }), H(e))
2245
+ return e;
2246
+ const s = _e(t.value, n.value);
2247
+ if (!s.valid)
2248
+ throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);
2249
+ return e.value = s.data, e;
2250
+ }
2251
+ const tr = /* @__PURE__ */ u("$ZodEnum", (e, t) => {
2252
+ P.init(e, t);
2253
+ const n = st(t.entries), o = new Set(n);
2254
+ e._zod.values = o, e._zod.pattern = new RegExp(`^(${n.filter((r) => fn.has(typeof r)).map((r) => typeof r == "string" ? ae(r) : r.toString()).join("|")})$`), e._zod.parse = (r, i) => {
2255
+ const s = r.value;
2256
+ return o.has(s) || r.issues.push({
2257
+ code: "invalid_value",
2258
+ values: n,
2259
+ input: s,
2260
+ inst: e
2261
+ }), r;
2262
+ };
2263
+ }), nr = /* @__PURE__ */ u("$ZodTransform", (e, t) => {
2264
+ P.init(e, t), e._zod.parse = (n, o) => {
2265
+ if (o.direction === "backward")
2266
+ throw new rt(e.constructor.name);
2267
+ const r = t.transform(n.value, n);
2268
+ if (o.async)
2269
+ return (r instanceof Promise ? r : Promise.resolve(r)).then((s) => (n.value = s, n));
2270
+ if (r instanceof Promise)
2271
+ throw new B();
2272
+ return n.value = r, n;
2273
+ };
2274
+ });
2275
+ function xe(e, t) {
2276
+ return e.issues.length && t === void 0 ? { issues: [], value: void 0 } : e;
2277
+ }
2278
+ const zt = /* @__PURE__ */ u("$ZodOptional", (e, t) => {
2279
+ P.init(e, t), e._zod.optin = "optional", e._zod.optout = "optional", g(e._zod, "values", () => t.innerType._zod.values ? /* @__PURE__ */ new Set([...t.innerType._zod.values, void 0]) : void 0), g(e._zod, "pattern", () => {
2280
+ const n = t.innerType._zod.pattern;
2281
+ return n ? new RegExp(`^(${we(n.source)})?$`) : void 0;
2282
+ }), e._zod.parse = (n, o) => {
2283
+ if (t.innerType._zod.optin === "optional") {
2284
+ const r = t.innerType._zod.run(n, o);
2285
+ return r instanceof Promise ? r.then((i) => xe(i, n.value)) : xe(r, n.value);
2286
+ }
2287
+ return n.value === void 0 ? n : t.innerType._zod.run(n, o);
2288
+ };
2289
+ }), or = /* @__PURE__ */ u("$ZodExactOptional", (e, t) => {
2290
+ zt.init(e, t), g(e._zod, "values", () => t.innerType._zod.values), g(e._zod, "pattern", () => t.innerType._zod.pattern), e._zod.parse = (n, o) => t.innerType._zod.run(n, o);
2291
+ }), rr = /* @__PURE__ */ u("$ZodNullable", (e, t) => {
2292
+ P.init(e, t), g(e._zod, "optin", () => t.innerType._zod.optin), g(e._zod, "optout", () => t.innerType._zod.optout), g(e._zod, "pattern", () => {
2293
+ const n = t.innerType._zod.pattern;
2294
+ return n ? new RegExp(`^(${we(n.source)}|null)$`) : void 0;
2295
+ }), g(e._zod, "values", () => t.innerType._zod.values ? /* @__PURE__ */ new Set([...t.innerType._zod.values, null]) : void 0), e._zod.parse = (n, o) => n.value === null ? n : t.innerType._zod.run(n, o);
2296
+ }), ir = /* @__PURE__ */ u("$ZodDefault", (e, t) => {
2297
+ P.init(e, t), e._zod.optin = "optional", g(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (n, o) => {
2298
+ if (o.direction === "backward")
2299
+ return t.innerType._zod.run(n, o);
2300
+ if (n.value === void 0)
2301
+ return n.value = t.defaultValue, n;
2302
+ const r = t.innerType._zod.run(n, o);
2303
+ return r instanceof Promise ? r.then((i) => Fe(i, t)) : Fe(r, t);
2304
+ };
2305
+ });
2306
+ function Fe(e, t) {
2307
+ return e.value === void 0 && (e.value = t.defaultValue), e;
2308
+ }
2309
+ const sr = /* @__PURE__ */ u("$ZodPrefault", (e, t) => {
2310
+ P.init(e, t), e._zod.optin = "optional", g(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (n, o) => (o.direction === "backward" || n.value === void 0 && (n.value = t.defaultValue), t.innerType._zod.run(n, o));
2311
+ }), ar = /* @__PURE__ */ u("$ZodNonOptional", (e, t) => {
2312
+ P.init(e, t), g(e._zod, "values", () => {
2313
+ const n = t.innerType._zod.values;
2314
+ return n ? new Set([...n].filter((o) => o !== void 0)) : void 0;
2315
+ }), e._zod.parse = (n, o) => {
2316
+ const r = t.innerType._zod.run(n, o);
2317
+ return r instanceof Promise ? r.then((i) => Ue(i, e)) : Ue(r, e);
2318
+ };
2319
+ });
2320
+ function Ue(e, t) {
2321
+ return !e.issues.length && e.value === void 0 && e.issues.push({
2322
+ code: "invalid_type",
2323
+ expected: "nonoptional",
2324
+ input: e.value,
2325
+ inst: t
2326
+ }), e;
2327
+ }
2328
+ const cr = /* @__PURE__ */ u("$ZodCatch", (e, t) => {
2329
+ P.init(e, t), g(e._zod, "optin", () => t.innerType._zod.optin), g(e._zod, "optout", () => t.innerType._zod.optout), g(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (n, o) => {
2330
+ if (o.direction === "backward")
2331
+ return t.innerType._zod.run(n, o);
2332
+ const r = t.innerType._zod.run(n, o);
2333
+ return r instanceof Promise ? r.then((i) => (n.value = i.value, i.issues.length && (n.value = t.catchValue({
2334
+ ...n,
2335
+ error: {
2336
+ issues: i.issues.map((s) => U(s, o, F()))
2337
+ },
2338
+ input: n.value
2339
+ }), n.issues = []), n)) : (n.value = r.value, r.issues.length && (n.value = t.catchValue({
2340
+ ...n,
2341
+ error: {
2342
+ issues: r.issues.map((i) => U(i, o, F()))
2343
+ },
2344
+ input: n.value
2345
+ }), n.issues = []), n);
2346
+ };
2347
+ }), ur = /* @__PURE__ */ u("$ZodPipe", (e, t) => {
2348
+ P.init(e, t), g(e._zod, "values", () => t.in._zod.values), g(e._zod, "optin", () => t.in._zod.optin), g(e._zod, "optout", () => t.out._zod.optout), g(e._zod, "propValues", () => t.in._zod.propValues), e._zod.parse = (n, o) => {
2349
+ if (o.direction === "backward") {
2350
+ const i = t.out._zod.run(n, o);
2351
+ return i instanceof Promise ? i.then((s) => te(s, t.in, o)) : te(i, t.in, o);
2352
+ }
2353
+ const r = t.in._zod.run(n, o);
2354
+ return r instanceof Promise ? r.then((i) => te(i, t.out, o)) : te(r, t.out, o);
2355
+ };
2356
+ });
2357
+ function te(e, t, n) {
2358
+ return e.issues.length ? (e.aborted = !0, e) : t._zod.run({ value: e.value, issues: e.issues }, n);
2359
+ }
2360
+ const lr = /* @__PURE__ */ u("$ZodReadonly", (e, t) => {
2361
+ P.init(e, t), g(e._zod, "propValues", () => t.innerType._zod.propValues), g(e._zod, "values", () => t.innerType._zod.values), g(e._zod, "optin", () => t.innerType?._zod?.optin), g(e._zod, "optout", () => t.innerType?._zod?.optout), e._zod.parse = (n, o) => {
2362
+ if (o.direction === "backward")
2363
+ return t.innerType._zod.run(n, o);
2364
+ const r = t.innerType._zod.run(n, o);
2365
+ return r instanceof Promise ? r.then(Ge) : Ge(r);
2366
+ };
2367
+ });
2368
+ function Ge(e) {
2369
+ return e.value = Object.freeze(e.value), e;
2370
+ }
2371
+ const hr = /* @__PURE__ */ u("$ZodCustom", (e, t) => {
2372
+ I.init(e, t), P.init(e, t), e._zod.parse = (n, o) => n, e._zod.check = (n) => {
2373
+ const o = n.value, r = t.fn(o);
2374
+ if (r instanceof Promise)
2375
+ return r.then((i) => Ve(i, n, o, e));
2376
+ Ve(r, n, o, e);
2377
+ };
2378
+ });
2379
+ function Ve(e, t, n, o) {
2380
+ if (!e) {
2381
+ const r = {
2382
+ code: "custom",
2383
+ input: n,
2384
+ inst: o,
2385
+ // incorporates params.error into issue reporting
2386
+ path: [...o._zod.def.path ?? []],
2387
+ // incorporates params.error into issue reporting
2388
+ continue: !o._zod.def.abort
2389
+ // params: inst._zod.def.params,
2390
+ };
2391
+ o._zod.def.params && (r.params = o._zod.def.params), t.issues.push(Q(r));
2392
+ }
2393
+ }
2394
+ var We;
2395
+ class dr {
2396
+ constructor() {
2397
+ this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map();
2398
+ }
2399
+ add(t, ...n) {
2400
+ const o = n[0];
2401
+ return this._map.set(t, o), o && typeof o == "object" && "id" in o && this._idmap.set(o.id, t), this;
2402
+ }
2403
+ clear() {
2404
+ return this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map(), this;
2405
+ }
2406
+ remove(t) {
2407
+ const n = this._map.get(t);
2408
+ return n && typeof n == "object" && "id" in n && this._idmap.delete(n.id), this._map.delete(t), this;
2409
+ }
2410
+ get(t) {
2411
+ const n = t._zod.parent;
2412
+ if (n) {
2413
+ const o = { ...this.get(n) ?? {} };
2414
+ delete o.id;
2415
+ const r = { ...o, ...this._map.get(t) };
2416
+ return Object.keys(r).length ? r : void 0;
2417
+ }
2418
+ return this._map.get(t);
2419
+ }
2420
+ has(t) {
2421
+ return this._map.has(t);
2422
+ }
2423
+ }
2424
+ function pr() {
2425
+ return new dr();
2426
+ }
2427
+ (We = globalThis).__zod_globalRegistry ?? (We.__zod_globalRegistry = pr());
2428
+ const J = globalThis.__zod_globalRegistry;
2429
+ // @__NO_SIDE_EFFECTS__
2430
+ function fr(e, t) {
2431
+ return new e({
2432
+ type: "string",
2433
+ ...f(t)
2434
+ });
2435
+ }
2436
+ // @__NO_SIDE_EFFECTS__
2437
+ function mr(e, t) {
2438
+ return new e({
2439
+ type: "string",
2440
+ format: "email",
2441
+ check: "string_format",
2442
+ abort: !1,
2443
+ ...f(t)
2444
+ });
2445
+ }
2446
+ // @__NO_SIDE_EFFECTS__
2447
+ function He(e, t) {
2448
+ return new e({
2449
+ type: "string",
2450
+ format: "guid",
2451
+ check: "string_format",
2452
+ abort: !1,
2453
+ ...f(t)
2454
+ });
2455
+ }
2456
+ // @__NO_SIDE_EFFECTS__
2457
+ function _r(e, t) {
2458
+ return new e({
2459
+ type: "string",
2460
+ format: "uuid",
2461
+ check: "string_format",
2462
+ abort: !1,
2463
+ ...f(t)
2464
+ });
2465
+ }
2466
+ // @__NO_SIDE_EFFECTS__
2467
+ function gr(e, t) {
2468
+ return new e({
2469
+ type: "string",
2470
+ format: "uuid",
2471
+ check: "string_format",
2472
+ abort: !1,
2473
+ version: "v4",
2474
+ ...f(t)
2475
+ });
2476
+ }
2477
+ // @__NO_SIDE_EFFECTS__
2478
+ function br(e, t) {
2479
+ return new e({
2480
+ type: "string",
2481
+ format: "uuid",
2482
+ check: "string_format",
2483
+ abort: !1,
2484
+ version: "v6",
2485
+ ...f(t)
2486
+ });
2487
+ }
2488
+ // @__NO_SIDE_EFFECTS__
2489
+ function yr(e, t) {
2490
+ return new e({
2491
+ type: "string",
2492
+ format: "uuid",
2493
+ check: "string_format",
2494
+ abort: !1,
2495
+ version: "v7",
2496
+ ...f(t)
2497
+ });
2498
+ }
2499
+ // @__NO_SIDE_EFFECTS__
2500
+ function vr(e, t) {
2501
+ return new e({
2502
+ type: "string",
2503
+ format: "url",
2504
+ check: "string_format",
2505
+ abort: !1,
2506
+ ...f(t)
2507
+ });
2508
+ }
2509
+ // @__NO_SIDE_EFFECTS__
2510
+ function wr(e, t) {
2511
+ return new e({
2512
+ type: "string",
2513
+ format: "emoji",
2514
+ check: "string_format",
2515
+ abort: !1,
2516
+ ...f(t)
2517
+ });
2518
+ }
2519
+ // @__NO_SIDE_EFFECTS__
2520
+ function kr(e, t) {
2521
+ return new e({
2522
+ type: "string",
2523
+ format: "nanoid",
2524
+ check: "string_format",
2525
+ abort: !1,
2526
+ ...f(t)
2527
+ });
2528
+ }
2529
+ // @__NO_SIDE_EFFECTS__
2530
+ function zr(e, t) {
2531
+ return new e({
2532
+ type: "string",
2533
+ format: "cuid",
2534
+ check: "string_format",
2535
+ abort: !1,
2536
+ ...f(t)
2537
+ });
2538
+ }
2539
+ // @__NO_SIDE_EFFECTS__
2540
+ function Pr(e, t) {
2541
+ return new e({
2542
+ type: "string",
2543
+ format: "cuid2",
2544
+ check: "string_format",
2545
+ abort: !1,
2546
+ ...f(t)
2547
+ });
2548
+ }
2549
+ // @__NO_SIDE_EFFECTS__
2550
+ function Tr(e, t) {
2551
+ return new e({
2552
+ type: "string",
2553
+ format: "ulid",
2554
+ check: "string_format",
2555
+ abort: !1,
2556
+ ...f(t)
2557
+ });
2558
+ }
2559
+ // @__NO_SIDE_EFFECTS__
2560
+ function Er(e, t) {
2561
+ return new e({
2562
+ type: "string",
2563
+ format: "xid",
2564
+ check: "string_format",
2565
+ abort: !1,
2566
+ ...f(t)
2567
+ });
2568
+ }
2569
+ // @__NO_SIDE_EFFECTS__
2570
+ function Sr(e, t) {
2571
+ return new e({
2572
+ type: "string",
2573
+ format: "ksuid",
2574
+ check: "string_format",
2575
+ abort: !1,
2576
+ ...f(t)
2577
+ });
2578
+ }
2579
+ // @__NO_SIDE_EFFECTS__
2580
+ function Or(e, t) {
2581
+ return new e({
2582
+ type: "string",
2583
+ format: "ipv4",
2584
+ check: "string_format",
2585
+ abort: !1,
2586
+ ...f(t)
2587
+ });
2588
+ }
2589
+ // @__NO_SIDE_EFFECTS__
2590
+ function Ar(e, t) {
2591
+ return new e({
2592
+ type: "string",
2593
+ format: "ipv6",
2594
+ check: "string_format",
2595
+ abort: !1,
2596
+ ...f(t)
2597
+ });
2598
+ }
2599
+ // @__NO_SIDE_EFFECTS__
2600
+ function Zr(e, t) {
2601
+ return new e({
2602
+ type: "string",
2603
+ format: "cidrv4",
2604
+ check: "string_format",
2605
+ abort: !1,
2606
+ ...f(t)
2607
+ });
2608
+ }
2609
+ // @__NO_SIDE_EFFECTS__
2610
+ function Ir(e, t) {
2611
+ return new e({
2612
+ type: "string",
2613
+ format: "cidrv6",
2614
+ check: "string_format",
2615
+ abort: !1,
2616
+ ...f(t)
2617
+ });
2618
+ }
2619
+ // @__NO_SIDE_EFFECTS__
2620
+ function $r(e, t) {
2621
+ return new e({
2622
+ type: "string",
2623
+ format: "base64",
2624
+ check: "string_format",
2625
+ abort: !1,
2626
+ ...f(t)
2627
+ });
2628
+ }
2629
+ // @__NO_SIDE_EFFECTS__
2630
+ function Dr(e, t) {
2631
+ return new e({
2632
+ type: "string",
2633
+ format: "base64url",
2634
+ check: "string_format",
2635
+ abort: !1,
2636
+ ...f(t)
2637
+ });
2638
+ }
2639
+ // @__NO_SIDE_EFFECTS__
2640
+ function Mr(e, t) {
2641
+ return new e({
2642
+ type: "string",
2643
+ format: "e164",
2644
+ check: "string_format",
2645
+ abort: !1,
2646
+ ...f(t)
2647
+ });
2648
+ }
2649
+ // @__NO_SIDE_EFFECTS__
2650
+ function Cr(e, t) {
2651
+ return new e({
2652
+ type: "string",
2653
+ format: "jwt",
2654
+ check: "string_format",
2655
+ abort: !1,
2656
+ ...f(t)
2657
+ });
2658
+ }
2659
+ // @__NO_SIDE_EFFECTS__
2660
+ function Nr(e, t) {
2661
+ return new e({
2662
+ type: "string",
2663
+ format: "datetime",
2664
+ check: "string_format",
2665
+ offset: !1,
2666
+ local: !1,
2667
+ precision: null,
2668
+ ...f(t)
2669
+ });
2670
+ }
2671
+ // @__NO_SIDE_EFFECTS__
2672
+ function Rr(e, t) {
2673
+ return new e({
2674
+ type: "string",
2675
+ format: "date",
2676
+ check: "string_format",
2677
+ ...f(t)
2678
+ });
2679
+ }
2680
+ // @__NO_SIDE_EFFECTS__
2681
+ function Lr(e, t) {
2682
+ return new e({
2683
+ type: "string",
2684
+ format: "time",
2685
+ check: "string_format",
2686
+ precision: null,
2687
+ ...f(t)
2688
+ });
2689
+ }
2690
+ // @__NO_SIDE_EFFECTS__
2691
+ function jr(e, t) {
2692
+ return new e({
2693
+ type: "string",
2694
+ format: "duration",
2695
+ check: "string_format",
2696
+ ...f(t)
2697
+ });
2698
+ }
2699
+ // @__NO_SIDE_EFFECTS__
2700
+ function xr(e, t) {
2701
+ return new e({
2702
+ type: "number",
2703
+ checks: [],
2704
+ ...f(t)
2705
+ });
2706
+ }
2707
+ // @__NO_SIDE_EFFECTS__
2708
+ function Fr(e, t) {
2709
+ return new e({
2710
+ type: "number",
2711
+ check: "number_format",
2712
+ abort: !1,
2713
+ format: "safeint",
2714
+ ...f(t)
2715
+ });
2716
+ }
2717
+ // @__NO_SIDE_EFFECTS__
2718
+ function Ur(e) {
2719
+ return new e({
2720
+ type: "unknown"
2721
+ });
2722
+ }
2723
+ // @__NO_SIDE_EFFECTS__
2724
+ function Gr(e, t) {
2725
+ return new e({
2726
+ type: "never",
2727
+ ...f(t)
2728
+ });
2729
+ }
2730
+ // @__NO_SIDE_EFFECTS__
2731
+ function Ke(e, t) {
2732
+ return new gt({
2733
+ check: "less_than",
2734
+ ...f(t),
2735
+ value: e,
2736
+ inclusive: !1
2737
+ });
2738
+ }
2739
+ // @__NO_SIDE_EFFECTS__
2740
+ function pe(e, t) {
2741
+ return new gt({
2742
+ check: "less_than",
2743
+ ...f(t),
2744
+ value: e,
2745
+ inclusive: !0
2746
+ });
2747
+ }
2748
+ // @__NO_SIDE_EFFECTS__
2749
+ function Be(e, t) {
2750
+ return new bt({
2751
+ check: "greater_than",
2752
+ ...f(t),
2753
+ value: e,
2754
+ inclusive: !1
2755
+ });
2756
+ }
2757
+ // @__NO_SIDE_EFFECTS__
2758
+ function fe(e, t) {
2759
+ return new bt({
2760
+ check: "greater_than",
2761
+ ...f(t),
2762
+ value: e,
2763
+ inclusive: !0
2764
+ });
2765
+ }
2766
+ // @__NO_SIDE_EFFECTS__
2767
+ function Ye(e, t) {
2768
+ return new ao({
2769
+ check: "multiple_of",
2770
+ ...f(t),
2771
+ value: e
2772
+ });
2773
+ }
2774
+ // @__NO_SIDE_EFFECTS__
2775
+ function Pt(e, t) {
2776
+ return new uo({
2777
+ check: "max_length",
2778
+ ...f(t),
2779
+ maximum: e
2780
+ });
2781
+ }
2782
+ // @__NO_SIDE_EFFECTS__
2783
+ function ie(e, t) {
2784
+ return new lo({
2785
+ check: "min_length",
2786
+ ...f(t),
2787
+ minimum: e
2788
+ });
2789
+ }
2790
+ // @__NO_SIDE_EFFECTS__
2791
+ function Tt(e, t) {
2792
+ return new ho({
2793
+ check: "length_equals",
2794
+ ...f(t),
2795
+ length: e
2796
+ });
2797
+ }
2798
+ // @__NO_SIDE_EFFECTS__
2799
+ function Vr(e, t) {
2800
+ return new po({
2801
+ check: "string_format",
2802
+ format: "regex",
2803
+ ...f(t),
2804
+ pattern: e
2805
+ });
2806
+ }
2807
+ // @__NO_SIDE_EFFECTS__
2808
+ function Wr(e) {
2809
+ return new fo({
2810
+ check: "string_format",
2811
+ format: "lowercase",
2812
+ ...f(e)
2813
+ });
2814
+ }
2815
+ // @__NO_SIDE_EFFECTS__
2816
+ function Hr(e) {
2817
+ return new mo({
2818
+ check: "string_format",
2819
+ format: "uppercase",
2820
+ ...f(e)
2821
+ });
2822
+ }
2823
+ // @__NO_SIDE_EFFECTS__
2824
+ function Kr(e, t) {
2825
+ return new _o({
2826
+ check: "string_format",
2827
+ format: "includes",
2828
+ ...f(t),
2829
+ includes: e
2830
+ });
2831
+ }
2832
+ // @__NO_SIDE_EFFECTS__
2833
+ function Br(e, t) {
2834
+ return new go({
2835
+ check: "string_format",
2836
+ format: "starts_with",
2837
+ ...f(t),
2838
+ prefix: e
2839
+ });
2840
+ }
2841
+ // @__NO_SIDE_EFFECTS__
2842
+ function Yr(e, t) {
2843
+ return new bo({
2844
+ check: "string_format",
2845
+ format: "ends_with",
2846
+ ...f(t),
2847
+ suffix: e
2848
+ });
2849
+ }
2850
+ // @__NO_SIDE_EFFECTS__
2851
+ function Y(e) {
2852
+ return new yo({
2853
+ check: "overwrite",
2854
+ tx: e
2855
+ });
2856
+ }
2857
+ // @__NO_SIDE_EFFECTS__
2858
+ function Jr(e) {
2859
+ return /* @__PURE__ */ Y((t) => t.normalize(e));
2860
+ }
2861
+ // @__NO_SIDE_EFFECTS__
2862
+ function Xr() {
2863
+ return /* @__PURE__ */ Y((e) => e.trim());
2864
+ }
2865
+ // @__NO_SIDE_EFFECTS__
2866
+ function Qr() {
2867
+ return /* @__PURE__ */ Y((e) => e.toLowerCase());
2868
+ }
2869
+ // @__NO_SIDE_EFFECTS__
2870
+ function qr() {
2871
+ return /* @__PURE__ */ Y((e) => e.toUpperCase());
2872
+ }
2873
+ // @__NO_SIDE_EFFECTS__
2874
+ function ei() {
2875
+ return /* @__PURE__ */ Y((e) => dn(e));
2876
+ }
2877
+ // @__NO_SIDE_EFFECTS__
2878
+ function ti(e, t, n) {
2879
+ return new e({
2880
+ type: "array",
2881
+ element: t,
2882
+ // get element() {
2883
+ // return element;
2884
+ // },
2885
+ ...f(n)
2886
+ });
2887
+ }
2888
+ // @__NO_SIDE_EFFECTS__
2889
+ function ni(e, t, n) {
2890
+ return new e({
2891
+ type: "custom",
2892
+ check: "custom",
2893
+ fn: t,
2894
+ ...f(n)
2895
+ });
2896
+ }
2897
+ // @__NO_SIDE_EFFECTS__
2898
+ function oi(e) {
2899
+ const t = /* @__PURE__ */ ri((n) => (n.addIssue = (o) => {
2900
+ if (typeof o == "string")
2901
+ n.issues.push(Q(o, n.value, t._zod.def));
2902
+ else {
2903
+ const r = o;
2904
+ r.fatal && (r.continue = !1), r.code ?? (r.code = "custom"), r.input ?? (r.input = n.value), r.inst ?? (r.inst = t), r.continue ?? (r.continue = !t._zod.def.abort), n.issues.push(Q(r));
2905
+ }
2906
+ }, e(n.value, n)));
2907
+ return t;
2908
+ }
2909
+ // @__NO_SIDE_EFFECTS__
2910
+ function ri(e, t) {
2911
+ const n = new I({
2912
+ check: "custom",
2913
+ ...f(t)
2914
+ });
2915
+ return n._zod.check = e, n;
2916
+ }
2917
+ function Et(e) {
2918
+ let t = e?.target ?? "draft-2020-12";
2919
+ return t === "draft-4" && (t = "draft-04"), t === "draft-7" && (t = "draft-07"), {
2920
+ processors: e.processors ?? {},
2921
+ metadataRegistry: e?.metadata ?? J,
2922
+ target: t,
2923
+ unrepresentable: e?.unrepresentable ?? "throw",
2924
+ override: e?.override ?? (() => {
2925
+ }),
2926
+ io: e?.io ?? "output",
2927
+ counter: 0,
2928
+ seen: /* @__PURE__ */ new Map(),
2929
+ cycles: e?.cycles ?? "ref",
2930
+ reused: e?.reused ?? "inline",
2931
+ external: e?.external ?? void 0
2932
+ };
2933
+ }
2934
+ function S(e, t, n = { path: [], schemaPath: [] }) {
2935
+ var o;
2936
+ const r = e._zod.def, i = t.seen.get(e);
2937
+ if (i)
2938
+ return i.count++, n.schemaPath.includes(e) && (i.cycle = n.path), i.schema;
2939
+ const s = { schema: {}, count: 1, cycle: void 0, path: n.path };
2940
+ t.seen.set(e, s);
2941
+ const a = e._zod.toJSONSchema?.();
2942
+ if (a)
2943
+ s.schema = a;
2944
+ else {
2945
+ const h = {
2946
+ ...n,
2947
+ schemaPath: [...n.schemaPath, e],
2948
+ path: n.path
2949
+ };
2950
+ if (e._zod.processJSONSchema)
2951
+ e._zod.processJSONSchema(t, s.schema, h);
2952
+ else {
2953
+ const p = s.schema, m = t.processors[r.type];
2954
+ if (!m)
2955
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);
2956
+ m(e, t, p, h);
2957
+ }
2958
+ const _ = e._zod.parent;
2959
+ _ && (s.ref || (s.ref = _), S(_, t, h), t.seen.get(_).isParent = !0);
2960
+ }
2961
+ const c = t.metadataRegistry.get(e);
2962
+ return c && Object.assign(s.schema, c), t.io === "input" && O(e) && (delete s.schema.examples, delete s.schema.default), t.io === "input" && s.schema._prefault && ((o = s.schema).default ?? (o.default = s.schema._prefault)), delete s.schema._prefault, t.seen.get(e).schema;
2963
+ }
2964
+ function St(e, t) {
2965
+ const n = e.seen.get(t);
2966
+ if (!n)
2967
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2968
+ const o = /* @__PURE__ */ new Map();
2969
+ for (const s of e.seen.entries()) {
2970
+ const a = e.metadataRegistry.get(s[0])?.id;
2971
+ if (a) {
2972
+ const c = o.get(a);
2973
+ if (c && c !== s[0])
2974
+ throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
2975
+ o.set(a, s[0]);
2976
+ }
2977
+ }
2978
+ const r = (s) => {
2979
+ const a = e.target === "draft-2020-12" ? "$defs" : "definitions";
2980
+ if (e.external) {
2981
+ const _ = e.external.registry.get(s[0])?.id, p = e.external.uri ?? ((k) => k);
2982
+ if (_)
2983
+ return { ref: p(_) };
2984
+ const m = s[1].defId ?? s[1].schema.id ?? `schema${e.counter++}`;
2985
+ return s[1].defId = m, { defId: m, ref: `${p("__shared")}#/${a}/${m}` };
2986
+ }
2987
+ if (s[1] === n)
2988
+ return { ref: "#" };
2989
+ const l = `#/${a}/`, h = s[1].schema.id ?? `__schema${e.counter++}`;
2990
+ return { defId: h, ref: l + h };
2991
+ }, i = (s) => {
2992
+ if (s[1].schema.$ref)
2993
+ return;
2994
+ const a = s[1], { ref: c, defId: l } = r(s);
2995
+ a.def = { ...a.schema }, l && (a.defId = l);
2996
+ const h = a.schema;
2997
+ for (const _ in h)
2998
+ delete h[_];
2999
+ h.$ref = c;
3000
+ };
3001
+ if (e.cycles === "throw")
3002
+ for (const s of e.seen.entries()) {
3003
+ const a = s[1];
3004
+ if (a.cycle)
3005
+ throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
3006
+
3007
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
3008
+ }
3009
+ for (const s of e.seen.entries()) {
3010
+ const a = s[1];
3011
+ if (t === s[0]) {
3012
+ i(s);
3013
+ continue;
3014
+ }
3015
+ if (e.external) {
3016
+ const l = e.external.registry.get(s[0])?.id;
3017
+ if (t !== s[0] && l) {
3018
+ i(s);
3019
+ continue;
3020
+ }
3021
+ }
3022
+ if (e.metadataRegistry.get(s[0])?.id) {
3023
+ i(s);
3024
+ continue;
3025
+ }
3026
+ if (a.cycle) {
3027
+ i(s);
3028
+ continue;
3029
+ }
3030
+ if (a.count > 1 && e.reused === "ref") {
3031
+ i(s);
3032
+ continue;
3033
+ }
3034
+ }
3035
+ }
3036
+ function Ot(e, t) {
3037
+ const n = e.seen.get(t);
3038
+ if (!n)
3039
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
3040
+ const o = (s) => {
3041
+ const a = e.seen.get(s);
3042
+ if (a.ref === null)
3043
+ return;
3044
+ const c = a.def ?? a.schema, l = { ...c }, h = a.ref;
3045
+ if (a.ref = null, h) {
3046
+ o(h);
3047
+ const p = e.seen.get(h), m = p.schema;
3048
+ if (m.$ref && (e.target === "draft-07" || e.target === "draft-04" || e.target === "openapi-3.0") ? (c.allOf = c.allOf ?? [], c.allOf.push(m)) : Object.assign(c, m), Object.assign(c, l), s._zod.parent === h)
3049
+ for (const z in c)
3050
+ z === "$ref" || z === "allOf" || z in l || delete c[z];
3051
+ if (m.$ref)
3052
+ for (const z in c)
3053
+ z === "$ref" || z === "allOf" || z in p.def && JSON.stringify(c[z]) === JSON.stringify(p.def[z]) && delete c[z];
3054
+ }
3055
+ const _ = s._zod.parent;
3056
+ if (_ && _ !== h) {
3057
+ o(_);
3058
+ const p = e.seen.get(_);
3059
+ if (p?.schema.$ref && (c.$ref = p.schema.$ref, p.def))
3060
+ for (const m in c)
3061
+ m === "$ref" || m === "allOf" || m in p.def && JSON.stringify(c[m]) === JSON.stringify(p.def[m]) && delete c[m];
3062
+ }
3063
+ e.override({
3064
+ zodSchema: s,
3065
+ jsonSchema: c,
3066
+ path: a.path ?? []
3067
+ });
3068
+ };
3069
+ for (const s of [...e.seen.entries()].reverse())
3070
+ o(s[0]);
3071
+ const r = {};
3072
+ if (e.target === "draft-2020-12" ? r.$schema = "https://json-schema.org/draft/2020-12/schema" : e.target === "draft-07" ? r.$schema = "http://json-schema.org/draft-07/schema#" : e.target === "draft-04" ? r.$schema = "http://json-schema.org/draft-04/schema#" : e.target, e.external?.uri) {
3073
+ const s = e.external.registry.get(t)?.id;
3074
+ if (!s)
3075
+ throw new Error("Schema is missing an `id` property");
3076
+ r.$id = e.external.uri(s);
3077
+ }
3078
+ Object.assign(r, n.def ?? n.schema);
3079
+ const i = e.external?.defs ?? {};
3080
+ for (const s of e.seen.entries()) {
3081
+ const a = s[1];
3082
+ a.def && a.defId && (i[a.defId] = a.def);
3083
+ }
3084
+ e.external || Object.keys(i).length > 0 && (e.target === "draft-2020-12" ? r.$defs = i : r.definitions = i);
3085
+ try {
3086
+ const s = JSON.parse(JSON.stringify(r));
3087
+ return Object.defineProperty(s, "~standard", {
3088
+ value: {
3089
+ ...t["~standard"],
3090
+ jsonSchema: {
3091
+ input: se(t, "input", e.processors),
3092
+ output: se(t, "output", e.processors)
3093
+ }
3094
+ },
3095
+ enumerable: !1,
3096
+ writable: !1
3097
+ }), s;
3098
+ } catch {
3099
+ throw new Error("Error converting schema to JSON.");
3100
+ }
3101
+ }
3102
+ function O(e, t) {
3103
+ const n = t ?? { seen: /* @__PURE__ */ new Set() };
3104
+ if (n.seen.has(e))
3105
+ return !1;
3106
+ n.seen.add(e);
3107
+ const o = e._zod.def;
3108
+ if (o.type === "transform")
3109
+ return !0;
3110
+ if (o.type === "array")
3111
+ return O(o.element, n);
3112
+ if (o.type === "set")
3113
+ return O(o.valueType, n);
3114
+ if (o.type === "lazy")
3115
+ return O(o.getter(), n);
3116
+ if (o.type === "promise" || o.type === "optional" || o.type === "nonoptional" || o.type === "nullable" || o.type === "readonly" || o.type === "default" || o.type === "prefault")
3117
+ return O(o.innerType, n);
3118
+ if (o.type === "intersection")
3119
+ return O(o.left, n) || O(o.right, n);
3120
+ if (o.type === "record" || o.type === "map")
3121
+ return O(o.keyType, n) || O(o.valueType, n);
3122
+ if (o.type === "pipe")
3123
+ return O(o.in, n) || O(o.out, n);
3124
+ if (o.type === "object") {
3125
+ for (const r in o.shape)
3126
+ if (O(o.shape[r], n))
3127
+ return !0;
3128
+ return !1;
3129
+ }
3130
+ if (o.type === "union") {
3131
+ for (const r of o.options)
3132
+ if (O(r, n))
3133
+ return !0;
3134
+ return !1;
3135
+ }
3136
+ if (o.type === "tuple") {
3137
+ for (const r of o.items)
3138
+ if (O(r, n))
3139
+ return !0;
3140
+ return !!(o.rest && O(o.rest, n));
3141
+ }
3142
+ return !1;
3143
+ }
3144
+ const ii = (e, t = {}) => (n) => {
3145
+ const o = Et({ ...n, processors: t });
3146
+ return S(e, o), St(o, e), Ot(o, e);
3147
+ }, se = (e, t, n = {}) => (o) => {
3148
+ const { libraryOptions: r, target: i } = o ?? {}, s = Et({ ...r ?? {}, target: i, io: t, processors: n });
3149
+ return S(e, s), St(s, e), Ot(s, e);
3150
+ }, si = {
3151
+ guid: "uuid",
3152
+ url: "uri",
3153
+ datetime: "date-time",
3154
+ json_string: "json-string",
3155
+ regex: ""
3156
+ // do not set
3157
+ }, ai = (e, t, n, o) => {
3158
+ const r = n;
3159
+ r.type = "string";
3160
+ const { minimum: i, maximum: s, format: a, patterns: c, contentEncoding: l } = e._zod.bag;
3161
+ if (typeof i == "number" && (r.minLength = i), typeof s == "number" && (r.maxLength = s), a && (r.format = si[a] ?? a, r.format === "" && delete r.format, a === "time" && delete r.format), l && (r.contentEncoding = l), c && c.size > 0) {
3162
+ const h = [...c];
3163
+ h.length === 1 ? r.pattern = h[0].source : h.length > 1 && (r.allOf = [
3164
+ ...h.map((_) => ({
3165
+ ...t.target === "draft-07" || t.target === "draft-04" || t.target === "openapi-3.0" ? { type: "string" } : {},
3166
+ pattern: _.source
3167
+ }))
3168
+ ]);
3169
+ }
3170
+ }, ci = (e, t, n, o) => {
3171
+ const r = n, { minimum: i, maximum: s, format: a, multipleOf: c, exclusiveMaximum: l, exclusiveMinimum: h } = e._zod.bag;
3172
+ typeof a == "string" && a.includes("int") ? r.type = "integer" : r.type = "number", typeof h == "number" && (t.target === "draft-04" || t.target === "openapi-3.0" ? (r.minimum = h, r.exclusiveMinimum = !0) : r.exclusiveMinimum = h), typeof i == "number" && (r.minimum = i, typeof h == "number" && t.target !== "draft-04" && (h >= i ? delete r.minimum : delete r.exclusiveMinimum)), typeof l == "number" && (t.target === "draft-04" || t.target === "openapi-3.0" ? (r.maximum = l, r.exclusiveMaximum = !0) : r.exclusiveMaximum = l), typeof s == "number" && (r.maximum = s, typeof l == "number" && t.target !== "draft-04" && (l <= s ? delete r.maximum : delete r.exclusiveMaximum)), typeof c == "number" && (r.multipleOf = c);
3173
+ }, ui = (e, t, n, o) => {
3174
+ n.not = {};
3175
+ }, li = (e, t, n, o) => {
3176
+ }, hi = (e, t, n, o) => {
3177
+ const r = e._zod.def, i = st(r.entries);
3178
+ i.every((s) => typeof s == "number") && (n.type = "number"), i.every((s) => typeof s == "string") && (n.type = "string"), n.enum = i;
3179
+ }, di = (e, t, n, o) => {
3180
+ if (t.unrepresentable === "throw")
3181
+ throw new Error("Custom types cannot be represented in JSON Schema");
3182
+ }, pi = (e, t, n, o) => {
3183
+ if (t.unrepresentable === "throw")
3184
+ throw new Error("Transforms cannot be represented in JSON Schema");
3185
+ }, fi = (e, t, n, o) => {
3186
+ const r = n, i = e._zod.def, { minimum: s, maximum: a } = e._zod.bag;
3187
+ typeof s == "number" && (r.minItems = s), typeof a == "number" && (r.maxItems = a), r.type = "array", r.items = S(i.element, t, { ...o, path: [...o.path, "items"] });
3188
+ }, mi = (e, t, n, o) => {
3189
+ const r = n, i = e._zod.def;
3190
+ r.type = "object", r.properties = {};
3191
+ const s = i.shape;
3192
+ for (const l in s)
3193
+ r.properties[l] = S(s[l], t, {
3194
+ ...o,
3195
+ path: [...o.path, "properties", l]
3196
+ });
3197
+ const a = new Set(Object.keys(s)), c = new Set([...a].filter((l) => {
3198
+ const h = i.shape[l]._zod;
3199
+ return t.io === "input" ? h.optin === void 0 : h.optout === void 0;
3200
+ }));
3201
+ c.size > 0 && (r.required = Array.from(c)), i.catchall?._zod.def.type === "never" ? r.additionalProperties = !1 : i.catchall ? i.catchall && (r.additionalProperties = S(i.catchall, t, {
3202
+ ...o,
3203
+ path: [...o.path, "additionalProperties"]
3204
+ })) : t.io === "output" && (r.additionalProperties = !1);
3205
+ }, _i = (e, t, n, o) => {
3206
+ const r = e._zod.def, i = r.inclusive === !1, s = r.options.map((a, c) => S(a, t, {
3207
+ ...o,
3208
+ path: [...o.path, i ? "oneOf" : "anyOf", c]
3209
+ }));
3210
+ i ? n.oneOf = s : n.anyOf = s;
3211
+ }, gi = (e, t, n, o) => {
3212
+ const r = e._zod.def, i = S(r.left, t, {
3213
+ ...o,
3214
+ path: [...o.path, "allOf", 0]
3215
+ }), s = S(r.right, t, {
3216
+ ...o,
3217
+ path: [...o.path, "allOf", 1]
3218
+ }), a = (l) => "allOf" in l && Object.keys(l).length === 1, c = [
3219
+ ...a(i) ? i.allOf : [i],
3220
+ ...a(s) ? s.allOf : [s]
3221
+ ];
3222
+ n.allOf = c;
3223
+ }, bi = (e, t, n, o) => {
3224
+ const r = e._zod.def, i = S(r.innerType, t, o), s = t.seen.get(e);
3225
+ t.target === "openapi-3.0" ? (s.ref = r.innerType, n.nullable = !0) : n.anyOf = [i, { type: "null" }];
3226
+ }, yi = (e, t, n, o) => {
3227
+ const r = e._zod.def;
3228
+ S(r.innerType, t, o);
3229
+ const i = t.seen.get(e);
3230
+ i.ref = r.innerType;
3231
+ }, vi = (e, t, n, o) => {
3232
+ const r = e._zod.def;
3233
+ S(r.innerType, t, o);
3234
+ const i = t.seen.get(e);
3235
+ i.ref = r.innerType, n.default = JSON.parse(JSON.stringify(r.defaultValue));
3236
+ }, wi = (e, t, n, o) => {
3237
+ const r = e._zod.def;
3238
+ S(r.innerType, t, o);
3239
+ const i = t.seen.get(e);
3240
+ i.ref = r.innerType, t.io === "input" && (n._prefault = JSON.parse(JSON.stringify(r.defaultValue)));
3241
+ }, ki = (e, t, n, o) => {
3242
+ const r = e._zod.def;
3243
+ S(r.innerType, t, o);
3244
+ const i = t.seen.get(e);
3245
+ i.ref = r.innerType;
3246
+ let s;
3247
+ try {
3248
+ s = r.catchValue(void 0);
3249
+ } catch {
3250
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3251
+ }
3252
+ n.default = s;
3253
+ }, zi = (e, t, n, o) => {
3254
+ const r = e._zod.def, i = t.io === "input" ? r.in._zod.def.type === "transform" ? r.out : r.in : r.out;
3255
+ S(i, t, o);
3256
+ const s = t.seen.get(e);
3257
+ s.ref = i;
3258
+ }, Pi = (e, t, n, o) => {
3259
+ const r = e._zod.def;
3260
+ S(r.innerType, t, o);
3261
+ const i = t.seen.get(e);
3262
+ i.ref = r.innerType, n.readOnly = !0;
3263
+ }, At = (e, t, n, o) => {
3264
+ const r = e._zod.def;
3265
+ S(r.innerType, t, o);
3266
+ const i = t.seen.get(e);
3267
+ i.ref = r.innerType;
3268
+ }, Ti = /* @__PURE__ */ u("ZodISODateTime", (e, t) => {
3269
+ Do.init(e, t), w.init(e, t);
3270
+ });
3271
+ function Ei(e) {
3272
+ return /* @__PURE__ */ Nr(Ti, e);
3273
+ }
3274
+ const Si = /* @__PURE__ */ u("ZodISODate", (e, t) => {
3275
+ Mo.init(e, t), w.init(e, t);
3276
+ });
3277
+ function Oi(e) {
3278
+ return /* @__PURE__ */ Rr(Si, e);
3279
+ }
3280
+ const Ai = /* @__PURE__ */ u("ZodISOTime", (e, t) => {
3281
+ Co.init(e, t), w.init(e, t);
3282
+ });
3283
+ function Zi(e) {
3284
+ return /* @__PURE__ */ Lr(Ai, e);
3285
+ }
3286
+ const Ii = /* @__PURE__ */ u("ZodISODuration", (e, t) => {
3287
+ No.init(e, t), w.init(e, t);
3288
+ });
3289
+ function $i(e) {
3290
+ return /* @__PURE__ */ jr(Ii, e);
3291
+ }
3292
+ const Di = (e, t) => {
3293
+ ht.init(e, t), e.name = "ZodError", Object.defineProperties(e, {
3294
+ format: {
3295
+ value: (n) => Tn(e, n)
3296
+ // enumerable: false,
3297
+ },
3298
+ flatten: {
3299
+ value: (n) => Pn(e, n)
3300
+ // enumerable: false,
3301
+ },
3302
+ addIssue: {
3303
+ value: (n) => {
3304
+ e.issues.push(n), e.message = JSON.stringify(e.issues, me, 2);
3305
+ }
3306
+ // enumerable: false,
3307
+ },
3308
+ addIssues: {
3309
+ value: (n) => {
3310
+ e.issues.push(...n), e.message = JSON.stringify(e.issues, me, 2);
3311
+ }
3312
+ // enumerable: false,
3313
+ },
3314
+ isEmpty: {
3315
+ get() {
3316
+ return e.issues.length === 0;
3317
+ }
3318
+ // enumerable: false,
3319
+ }
3320
+ });
3321
+ }, M = u("ZodError", Di, {
3322
+ Parent: Error
3323
+ }), Mi = /* @__PURE__ */ ze(M), Ci = /* @__PURE__ */ Pe(M), Ni = /* @__PURE__ */ ce(M), Ri = /* @__PURE__ */ ue(M), Li = /* @__PURE__ */ On(M), ji = /* @__PURE__ */ An(M), xi = /* @__PURE__ */ Zn(M), Fi = /* @__PURE__ */ In(M), Ui = /* @__PURE__ */ $n(M), Gi = /* @__PURE__ */ Dn(M), Vi = /* @__PURE__ */ Mn(M), Wi = /* @__PURE__ */ Cn(M), T = /* @__PURE__ */ u("ZodType", (e, t) => (P.init(e, t), Object.assign(e["~standard"], {
3324
+ jsonSchema: {
3325
+ input: se(e, "input"),
3326
+ output: se(e, "output")
3327
+ }
3328
+ }), e.toJSONSchema = ii(e, {}), e.def = t, e.type = t.type, Object.defineProperty(e, "_def", { value: t }), e.check = (...n) => e.clone(L(t, {
3329
+ checks: [
3330
+ ...t.checks ?? [],
3331
+ ...n.map((o) => typeof o == "function" ? { _zod: { check: o, def: { check: "custom" }, onattach: [] } } : o)
3332
+ ]
3333
+ }), {
3334
+ parent: !0
3335
+ }), e.with = e.check, e.clone = (n, o) => j(e, n, o), e.brand = () => e, e.register = ((n, o) => (n.add(e, o), e)), e.parse = (n, o) => Mi(e, n, o, { callee: e.parse }), e.safeParse = (n, o) => Ni(e, n, o), e.parseAsync = async (n, o) => Ci(e, n, o, { callee: e.parseAsync }), e.safeParseAsync = async (n, o) => Ri(e, n, o), e.spa = e.safeParseAsync, e.encode = (n, o) => Li(e, n, o), e.decode = (n, o) => ji(e, n, o), e.encodeAsync = async (n, o) => xi(e, n, o), e.decodeAsync = async (n, o) => Fi(e, n, o), e.safeEncode = (n, o) => Ui(e, n, o), e.safeDecode = (n, o) => Gi(e, n, o), e.safeEncodeAsync = async (n, o) => Vi(e, n, o), e.safeDecodeAsync = async (n, o) => Wi(e, n, o), e.refine = (n, o) => e.check(Ls(n, o)), e.superRefine = (n) => e.check(js(n)), e.overwrite = (n) => e.check(/* @__PURE__ */ Y(n)), e.optional = () => qe(e), e.exactOptional = () => Ts(e), e.nullable = () => et(e), e.nullish = () => qe(et(e)), e.nonoptional = (n) => Is(e, n), e.array = () => ms(e), e.or = (n) => bs([e, n]), e.and = (n) => vs(e, n), e.transform = (n) => tt(e, zs(n)), e.default = (n) => Os(e, n), e.prefault = (n) => Zs(e, n), e.catch = (n) => Ds(e, n), e.pipe = (n) => tt(e, n), e.readonly = () => Ns(e), e.describe = (n) => {
3336
+ const o = e.clone();
3337
+ return J.add(o, { description: n }), o;
3338
+ }, Object.defineProperty(e, "description", {
3339
+ get() {
3340
+ return J.get(e)?.description;
3341
+ },
3342
+ configurable: !0
3343
+ }), e.meta = (...n) => {
3344
+ if (n.length === 0)
3345
+ return J.get(e);
3346
+ const o = e.clone();
3347
+ return J.add(o, n[0]), o;
3348
+ }, e.isOptional = () => e.safeParse(void 0).success, e.isNullable = () => e.safeParse(null).success, e.apply = (n) => n(e), e)), Zt = /* @__PURE__ */ u("_ZodString", (e, t) => {
3349
+ Te.init(e, t), T.init(e, t), e._zod.processJSONSchema = (o, r, i) => ai(e, o, r);
3350
+ const n = e._zod.bag;
3351
+ e.format = n.format ?? null, e.minLength = n.minimum ?? null, e.maxLength = n.maximum ?? null, e.regex = (...o) => e.check(/* @__PURE__ */ Vr(...o)), e.includes = (...o) => e.check(/* @__PURE__ */ Kr(...o)), e.startsWith = (...o) => e.check(/* @__PURE__ */ Br(...o)), e.endsWith = (...o) => e.check(/* @__PURE__ */ Yr(...o)), e.min = (...o) => e.check(/* @__PURE__ */ ie(...o)), e.max = (...o) => e.check(/* @__PURE__ */ Pt(...o)), e.length = (...o) => e.check(/* @__PURE__ */ Tt(...o)), e.nonempty = (...o) => e.check(/* @__PURE__ */ ie(1, ...o)), e.lowercase = (o) => e.check(/* @__PURE__ */ Wr(o)), e.uppercase = (o) => e.check(/* @__PURE__ */ Hr(o)), e.trim = () => e.check(/* @__PURE__ */ Xr()), e.normalize = (...o) => e.check(/* @__PURE__ */ Jr(...o)), e.toLowerCase = () => e.check(/* @__PURE__ */ Qr()), e.toUpperCase = () => e.check(/* @__PURE__ */ qr()), e.slugify = () => e.check(/* @__PURE__ */ ei());
3352
+ }), Hi = /* @__PURE__ */ u("ZodString", (e, t) => {
3353
+ Te.init(e, t), Zt.init(e, t), e.email = (n) => e.check(/* @__PURE__ */ mr(Ki, n)), e.url = (n) => e.check(/* @__PURE__ */ vr(Bi, n)), e.jwt = (n) => e.check(/* @__PURE__ */ Cr(us, n)), e.emoji = (n) => e.check(/* @__PURE__ */ wr(Yi, n)), e.guid = (n) => e.check(/* @__PURE__ */ He(Je, n)), e.uuid = (n) => e.check(/* @__PURE__ */ _r(ne, n)), e.uuidv4 = (n) => e.check(/* @__PURE__ */ gr(ne, n)), e.uuidv6 = (n) => e.check(/* @__PURE__ */ br(ne, n)), e.uuidv7 = (n) => e.check(/* @__PURE__ */ yr(ne, n)), e.nanoid = (n) => e.check(/* @__PURE__ */ kr(Ji, n)), e.guid = (n) => e.check(/* @__PURE__ */ He(Je, n)), e.cuid = (n) => e.check(/* @__PURE__ */ zr(Xi, n)), e.cuid2 = (n) => e.check(/* @__PURE__ */ Pr(Qi, n)), e.ulid = (n) => e.check(/* @__PURE__ */ Tr(qi, n)), e.base64 = (n) => e.check(/* @__PURE__ */ $r(ss, n)), e.base64url = (n) => e.check(/* @__PURE__ */ Dr(as, n)), e.xid = (n) => e.check(/* @__PURE__ */ Er(es, n)), e.ksuid = (n) => e.check(/* @__PURE__ */ Sr(ts, n)), e.ipv4 = (n) => e.check(/* @__PURE__ */ Or(ns, n)), e.ipv6 = (n) => e.check(/* @__PURE__ */ Ar(os, n)), e.cidrv4 = (n) => e.check(/* @__PURE__ */ Zr(rs, n)), e.cidrv6 = (n) => e.check(/* @__PURE__ */ Ir(is, n)), e.e164 = (n) => e.check(/* @__PURE__ */ Mr(cs, n)), e.datetime = (n) => e.check(Ei(n)), e.date = (n) => e.check(Oi(n)), e.time = (n) => e.check(Zi(n)), e.duration = (n) => e.check($i(n));
3354
+ });
3355
+ function Ee(e) {
3356
+ return /* @__PURE__ */ fr(Hi, e);
3357
+ }
3358
+ const w = /* @__PURE__ */ u("ZodStringFormat", (e, t) => {
3359
+ v.init(e, t), Zt.init(e, t);
3360
+ }), Ki = /* @__PURE__ */ u("ZodEmail", (e, t) => {
3361
+ Po.init(e, t), w.init(e, t);
3362
+ }), Je = /* @__PURE__ */ u("ZodGUID", (e, t) => {
3363
+ ko.init(e, t), w.init(e, t);
3364
+ }), ne = /* @__PURE__ */ u("ZodUUID", (e, t) => {
3365
+ zo.init(e, t), w.init(e, t);
3366
+ }), Bi = /* @__PURE__ */ u("ZodURL", (e, t) => {
3367
+ To.init(e, t), w.init(e, t);
3368
+ }), Yi = /* @__PURE__ */ u("ZodEmoji", (e, t) => {
3369
+ Eo.init(e, t), w.init(e, t);
3370
+ }), Ji = /* @__PURE__ */ u("ZodNanoID", (e, t) => {
3371
+ So.init(e, t), w.init(e, t);
3372
+ }), Xi = /* @__PURE__ */ u("ZodCUID", (e, t) => {
3373
+ Oo.init(e, t), w.init(e, t);
3374
+ }), Qi = /* @__PURE__ */ u("ZodCUID2", (e, t) => {
3375
+ Ao.init(e, t), w.init(e, t);
3376
+ }), qi = /* @__PURE__ */ u("ZodULID", (e, t) => {
3377
+ Zo.init(e, t), w.init(e, t);
3378
+ }), es = /* @__PURE__ */ u("ZodXID", (e, t) => {
3379
+ Io.init(e, t), w.init(e, t);
3380
+ }), ts = /* @__PURE__ */ u("ZodKSUID", (e, t) => {
3381
+ $o.init(e, t), w.init(e, t);
3382
+ }), ns = /* @__PURE__ */ u("ZodIPv4", (e, t) => {
3383
+ Ro.init(e, t), w.init(e, t);
3384
+ }), os = /* @__PURE__ */ u("ZodIPv6", (e, t) => {
3385
+ Lo.init(e, t), w.init(e, t);
3386
+ }), rs = /* @__PURE__ */ u("ZodCIDRv4", (e, t) => {
3387
+ jo.init(e, t), w.init(e, t);
3388
+ }), is = /* @__PURE__ */ u("ZodCIDRv6", (e, t) => {
3389
+ xo.init(e, t), w.init(e, t);
3390
+ }), ss = /* @__PURE__ */ u("ZodBase64", (e, t) => {
3391
+ Fo.init(e, t), w.init(e, t);
3392
+ }), as = /* @__PURE__ */ u("ZodBase64URL", (e, t) => {
3393
+ Go.init(e, t), w.init(e, t);
3394
+ }), cs = /* @__PURE__ */ u("ZodE164", (e, t) => {
3395
+ Vo.init(e, t), w.init(e, t);
3396
+ }), us = /* @__PURE__ */ u("ZodJWT", (e, t) => {
3397
+ Ho.init(e, t), w.init(e, t);
3398
+ }), It = /* @__PURE__ */ u("ZodNumber", (e, t) => {
3399
+ vt.init(e, t), T.init(e, t), e._zod.processJSONSchema = (o, r, i) => ci(e, o, r), e.gt = (o, r) => e.check(/* @__PURE__ */ Be(o, r)), e.gte = (o, r) => e.check(/* @__PURE__ */ fe(o, r)), e.min = (o, r) => e.check(/* @__PURE__ */ fe(o, r)), e.lt = (o, r) => e.check(/* @__PURE__ */ Ke(o, r)), e.lte = (o, r) => e.check(/* @__PURE__ */ pe(o, r)), e.max = (o, r) => e.check(/* @__PURE__ */ pe(o, r)), e.int = (o) => e.check(Xe(o)), e.safe = (o) => e.check(Xe(o)), e.positive = (o) => e.check(/* @__PURE__ */ Be(0, o)), e.nonnegative = (o) => e.check(/* @__PURE__ */ fe(0, o)), e.negative = (o) => e.check(/* @__PURE__ */ Ke(0, o)), e.nonpositive = (o) => e.check(/* @__PURE__ */ pe(0, o)), e.multipleOf = (o, r) => e.check(/* @__PURE__ */ Ye(o, r)), e.step = (o, r) => e.check(/* @__PURE__ */ Ye(o, r)), e.finite = () => e;
3400
+ const n = e._zod.bag;
3401
+ e.minValue = Math.max(n.minimum ?? Number.NEGATIVE_INFINITY, n.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null, e.maxValue = Math.min(n.maximum ?? Number.POSITIVE_INFINITY, n.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null, e.isInt = (n.format ?? "").includes("int") || Number.isSafeInteger(n.multipleOf ?? 0.5), e.isFinite = !0, e.format = n.format ?? null;
3402
+ });
3403
+ function $t(e) {
3404
+ return /* @__PURE__ */ xr(It, e);
3405
+ }
3406
+ const ls = /* @__PURE__ */ u("ZodNumberFormat", (e, t) => {
3407
+ Ko.init(e, t), It.init(e, t);
3408
+ });
3409
+ function Xe(e) {
3410
+ return /* @__PURE__ */ Fr(ls, e);
3411
+ }
3412
+ const hs = /* @__PURE__ */ u("ZodUnknown", (e, t) => {
3413
+ Bo.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => li();
3414
+ });
3415
+ function Qe() {
3416
+ return /* @__PURE__ */ Ur(hs);
3417
+ }
3418
+ const ds = /* @__PURE__ */ u("ZodNever", (e, t) => {
3419
+ Yo.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => ui(e, n, o);
3420
+ });
3421
+ function ps(e) {
3422
+ return /* @__PURE__ */ Gr(ds, e);
3423
+ }
3424
+ const fs = /* @__PURE__ */ u("ZodArray", (e, t) => {
3425
+ Jo.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => fi(e, n, o, r), e.element = t.element, e.min = (n, o) => e.check(/* @__PURE__ */ ie(n, o)), e.nonempty = (n) => e.check(/* @__PURE__ */ ie(1, n)), e.max = (n, o) => e.check(/* @__PURE__ */ Pt(n, o)), e.length = (n, o) => e.check(/* @__PURE__ */ Tt(n, o)), e.unwrap = () => e.element;
3426
+ });
3427
+ function ms(e, t) {
3428
+ return /* @__PURE__ */ ti(fs, e, t);
3429
+ }
3430
+ const _s = /* @__PURE__ */ u("ZodObject", (e, t) => {
3431
+ Qo.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => mi(e, n, o, r), g(e, "shape", () => t.shape), e.keyof = () => ws(Object.keys(e._zod.def.shape)), e.catchall = (n) => e.clone({ ...e._zod.def, catchall: n }), e.passthrough = () => e.clone({ ...e._zod.def, catchall: Qe() }), e.loose = () => e.clone({ ...e._zod.def, catchall: Qe() }), e.strict = () => e.clone({ ...e._zod.def, catchall: ps() }), e.strip = () => e.clone({ ...e._zod.def, catchall: void 0 }), e.extend = (n) => yn(e, n), e.safeExtend = (n) => vn(e, n), e.merge = (n) => wn(e, n), e.pick = (n) => gn(e, n), e.omit = (n) => bn(e, n), e.partial = (...n) => kn(Dt, e, n[0]), e.required = (...n) => zn(Mt, e, n[0]);
3432
+ });
3433
+ function Se(e, t) {
3434
+ const n = {
3435
+ type: "object",
3436
+ shape: e ?? {},
3437
+ ...f(t)
3438
+ };
3439
+ return new _s(n);
3440
+ }
3441
+ const gs = /* @__PURE__ */ u("ZodUnion", (e, t) => {
3442
+ qo.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => _i(e, n, o, r), e.options = t.options;
3443
+ });
3444
+ function bs(e, t) {
3445
+ return new gs({
3446
+ type: "union",
3447
+ options: e,
3448
+ ...f(t)
3449
+ });
3450
+ }
3451
+ const ys = /* @__PURE__ */ u("ZodIntersection", (e, t) => {
3452
+ er.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => gi(e, n, o, r);
3453
+ });
3454
+ function vs(e, t) {
3455
+ return new ys({
3456
+ type: "intersection",
3457
+ left: e,
3458
+ right: t
3459
+ });
3460
+ }
3461
+ const ge = /* @__PURE__ */ u("ZodEnum", (e, t) => {
3462
+ tr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (o, r, i) => hi(e, o, r), e.enum = t.entries, e.options = Object.values(t.entries);
3463
+ const n = new Set(Object.keys(t.entries));
3464
+ e.extract = (o, r) => {
3465
+ const i = {};
3466
+ for (const s of o)
3467
+ if (n.has(s))
3468
+ i[s] = t.entries[s];
3469
+ else
3470
+ throw new Error(`Key ${s} not found in enum`);
3471
+ return new ge({
3472
+ ...t,
3473
+ checks: [],
3474
+ ...f(r),
3475
+ entries: i
3476
+ });
3477
+ }, e.exclude = (o, r) => {
3478
+ const i = { ...t.entries };
3479
+ for (const s of o)
3480
+ if (n.has(s))
3481
+ delete i[s];
3482
+ else
3483
+ throw new Error(`Key ${s} not found in enum`);
3484
+ return new ge({
3485
+ ...t,
3486
+ checks: [],
3487
+ ...f(r),
3488
+ entries: i
3489
+ });
3490
+ };
3491
+ });
3492
+ function ws(e, t) {
3493
+ const n = Array.isArray(e) ? Object.fromEntries(e.map((o) => [o, o])) : e;
3494
+ return new ge({
3495
+ type: "enum",
3496
+ entries: n,
3497
+ ...f(t)
3498
+ });
3499
+ }
3500
+ const ks = /* @__PURE__ */ u("ZodTransform", (e, t) => {
3501
+ nr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => pi(e, n), e._zod.parse = (n, o) => {
3502
+ if (o.direction === "backward")
3503
+ throw new rt(e.constructor.name);
3504
+ n.addIssue = (i) => {
3505
+ if (typeof i == "string")
3506
+ n.issues.push(Q(i, n.value, t));
3507
+ else {
3508
+ const s = i;
3509
+ s.fatal && (s.continue = !1), s.code ?? (s.code = "custom"), s.input ?? (s.input = n.value), s.inst ?? (s.inst = e), n.issues.push(Q(s));
3510
+ }
3511
+ };
3512
+ const r = t.transform(n.value, n);
3513
+ return r instanceof Promise ? r.then((i) => (n.value = i, n)) : (n.value = r, n);
3514
+ };
3515
+ });
3516
+ function zs(e) {
3517
+ return new ks({
3518
+ type: "transform",
3519
+ transform: e
3520
+ });
3521
+ }
3522
+ const Dt = /* @__PURE__ */ u("ZodOptional", (e, t) => {
3523
+ zt.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => At(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3524
+ });
3525
+ function qe(e) {
3526
+ return new Dt({
3527
+ type: "optional",
3528
+ innerType: e
3529
+ });
3530
+ }
3531
+ const Ps = /* @__PURE__ */ u("ZodExactOptional", (e, t) => {
3532
+ or.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => At(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3533
+ });
3534
+ function Ts(e) {
3535
+ return new Ps({
3536
+ type: "optional",
3537
+ innerType: e
3538
+ });
3539
+ }
3540
+ const Es = /* @__PURE__ */ u("ZodNullable", (e, t) => {
3541
+ rr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => bi(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3542
+ });
3543
+ function et(e) {
3544
+ return new Es({
3545
+ type: "nullable",
3546
+ innerType: e
3547
+ });
3548
+ }
3549
+ const Ss = /* @__PURE__ */ u("ZodDefault", (e, t) => {
3550
+ ir.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => vi(e, n, o, r), e.unwrap = () => e._zod.def.innerType, e.removeDefault = e.unwrap;
3551
+ });
3552
+ function Os(e, t) {
3553
+ return new Ss({
3554
+ type: "default",
3555
+ innerType: e,
3556
+ get defaultValue() {
3557
+ return typeof t == "function" ? t() : ct(t);
3558
+ }
3559
+ });
3560
+ }
3561
+ const As = /* @__PURE__ */ u("ZodPrefault", (e, t) => {
3562
+ sr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => wi(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3563
+ });
3564
+ function Zs(e, t) {
3565
+ return new As({
3566
+ type: "prefault",
3567
+ innerType: e,
3568
+ get defaultValue() {
3569
+ return typeof t == "function" ? t() : ct(t);
3570
+ }
3571
+ });
3572
+ }
3573
+ const Mt = /* @__PURE__ */ u("ZodNonOptional", (e, t) => {
3574
+ ar.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => yi(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3575
+ });
3576
+ function Is(e, t) {
3577
+ return new Mt({
3578
+ type: "nonoptional",
3579
+ innerType: e,
3580
+ ...f(t)
3581
+ });
3582
+ }
3583
+ const $s = /* @__PURE__ */ u("ZodCatch", (e, t) => {
3584
+ cr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => ki(e, n, o, r), e.unwrap = () => e._zod.def.innerType, e.removeCatch = e.unwrap;
3585
+ });
3586
+ function Ds(e, t) {
3587
+ return new $s({
3588
+ type: "catch",
3589
+ innerType: e,
3590
+ catchValue: typeof t == "function" ? t : () => t
3591
+ });
3592
+ }
3593
+ const Ms = /* @__PURE__ */ u("ZodPipe", (e, t) => {
3594
+ ur.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => zi(e, n, o, r), e.in = t.in, e.out = t.out;
3595
+ });
3596
+ function tt(e, t) {
3597
+ return new Ms({
3598
+ type: "pipe",
3599
+ in: e,
3600
+ out: t
3601
+ // ...util.normalizeParams(params),
3602
+ });
3603
+ }
3604
+ const Cs = /* @__PURE__ */ u("ZodReadonly", (e, t) => {
3605
+ lr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => Pi(e, n, o, r), e.unwrap = () => e._zod.def.innerType;
3606
+ });
3607
+ function Ns(e) {
3608
+ return new Cs({
3609
+ type: "readonly",
3610
+ innerType: e
3611
+ });
3612
+ }
3613
+ const Rs = /* @__PURE__ */ u("ZodCustom", (e, t) => {
3614
+ hr.init(e, t), T.init(e, t), e._zod.processJSONSchema = (n, o, r) => di(e, n);
3615
+ });
3616
+ function Ls(e, t = {}) {
3617
+ return /* @__PURE__ */ ni(Rs, e, t);
3618
+ }
3619
+ function js(e) {
3620
+ return /* @__PURE__ */ oi(e);
3621
+ }
3622
+ const xs = Se({
3623
+ text: Ee().describe("The text content to speak."),
3624
+ duration: $t().default(3e3).describe("Duration in milliseconds to stay in the talking state.")
3625
+ }), Fs = Se({
3626
+ text: Ee().default("...").describe("The thought text content (e.g., '...')."),
3627
+ duration: $t().default(3e3).describe("Duration in milliseconds to stay in the thinking state.")
3628
+ });
3629
+ Se({
3630
+ action: Ee().describe("The name of the animation clip to play (e.g., 'wave', 'bow', 'dance').")
3631
+ });
3632
+ class Ws {
757
3633
  container;
758
3634
  scene;
759
3635
  camera;
@@ -769,110 +3645,220 @@ class rt {
769
3645
  stageAnimController = null;
770
3646
  // Components
771
3647
  lookAtProcessor;
3648
+ brain;
3649
+ bubbleManager;
772
3650
  currentAvatarConfig = null;
773
3651
  // Debug Helpers
774
3652
  isDebug = !1;
775
3653
  debugTargetMesh = null;
776
3654
  debugPlaneMesh = null;
3655
+ resizeObserver;
777
3656
  constructor(t) {
778
- const e = document.getElementById(t);
779
- if (!e) throw new Error(`Container #${t} not found`);
780
- this.container = e, this.clock = new n.Clock(), this.loader = new $(), this.stageLoader = new J(), this.scene = new n.Scene(), this.scene.background = new n.Color(1710618), this.scene.fog = new n.Fog(1710618, 10, 50), this.camera = new n.PerspectiveCamera(
3657
+ const n = document.getElementById(t);
3658
+ if (!n) throw new Error(`Container #${t} not found`);
3659
+ this.container = n, this.clock = new d.Clock(), this.loader = new tn(), this.stageLoader = new nn(), this.brain = new cn(), this.scene = new d.Scene(), this.scene.background = new d.Color(1710618), this.scene.fog = new d.Fog(1710618, 10, 50), this.camera = new d.PerspectiveCamera(
781
3660
  45,
782
- window.innerWidth / window.innerHeight,
3661
+ this.container.clientWidth / this.container.clientHeight,
783
3662
  0.1,
784
3663
  100
785
- ), this.camera.position.set(0, 1.5, 5), this.renderer = new j({ antialias: !0, alpha: !0 }), this.renderer.setSize(window.innerWidth, window.innerHeight), this.renderer.setPixelRatio(window.devicePixelRatio), this.container.appendChild(this.renderer.domElement), this.setupLights(), this.controls = new U(this.camera, this.renderer.domElement), this.controls.enableDamping = !0, this.controls.target.set(0, 1, 0), this.lookAtProcessor = new st(
3664
+ ), this.camera.position.set(0, 1.5, 5), this.renderer = new xt({ antialias: !0, alpha: !0 }), this.renderer.setSize(this.container.clientWidth, this.container.clientHeight), this.renderer.setPixelRatio(window.devicePixelRatio), this.container.appendChild(this.renderer.domElement), this.setupLights(), this.controls = new Ut(this.camera, this.renderer.domElement), this.controls.enableDamping = !0, this.controls.target.set(0, 1, 0), this.lookAtProcessor = new an(
786
3665
  this.container,
787
3666
  this.camera,
788
3667
  () => this.headBone,
789
3668
  () => this.currentAvatarConfig,
790
3669
  () => {
791
- const i = [];
792
- return this.avatarModel && i.push(this.avatarModel), this.stageModel && i.push(this.stageModel), i;
3670
+ const o = [];
3671
+ return this.avatarModel && o.push(this.avatarModel), this.stageModel && o.push(this.stageModel), o;
793
3672
  }
794
- ), window.addEventListener("resize", this.onWindowResize.bind(this)), this.renderer.setAnimationLoop(this.animate.bind(this));
3673
+ ), this.bubbleManager = new ln(this.scene), this.brain.onStateChange = (o, r) => {
3674
+ if (this.animController)
3675
+ switch (o) {
3676
+ case N.IDLE:
3677
+ this.animController.play("idle"), this.lookAtProcessor.reset(), this.bubbleManager.hide();
3678
+ break;
3679
+ case N.TALKING:
3680
+ this.animController.play("talk"), this.lookAtProcessor.setTarget(this.camera.position.clone()), r.text && this.bubbleManager.show(r.text, "speech");
3681
+ break;
3682
+ case N.THINKING:
3683
+ this.animController.play("thinking"), this.bubbleManager.show(r.text || "...", "thought");
3684
+ break;
3685
+ case N.LISTENING:
3686
+ this.animController.play("idle"), this.lookAtProcessor.setTarget(this.camera.position.clone()), this.bubbleManager.hide();
3687
+ break;
3688
+ case N.EMOTIONAL:
3689
+ this.animController.play("idle"), this.lookAtProcessor.setTarget(this.camera.position.clone()), this.bubbleManager.hide();
3690
+ break;
3691
+ }
3692
+ }, this.resizeObserver = new ResizeObserver((o) => {
3693
+ const r = o[0];
3694
+ this.onWindowResize(r.contentRect.width, r.contentRect.height);
3695
+ }), this.resizeObserver.observe(this.container), this.renderer.setAnimationLoop(this.animate.bind(this));
3696
+ }
3697
+ dispose() {
3698
+ this.resizeObserver.disconnect(), this.renderer.setAnimationLoop(null), this.renderer.dispose(), this.controls.dispose();
795
3699
  }
796
3700
  setupLights() {
797
- const t = new n.AmbientLight(16777215, 0.6);
3701
+ const t = new d.AmbientLight(16777215, 0.6);
798
3702
  this.scene.add(t);
799
- const e = new n.DirectionalLight(16777215, 1);
800
- e.position.set(5, 10, 7), e.castShadow = !0, this.scene.add(e);
801
- const i = new n.SpotLight(54015, 5);
802
- i.position.set(-5, 5, -5), i.lookAt(0, 1, 0), this.scene.add(i);
3703
+ const n = new d.DirectionalLight(16777215, 1);
3704
+ n.position.set(5, 10, 7), n.castShadow = !0, this.scene.add(n);
3705
+ const o = new d.SpotLight(54015, 5);
3706
+ o.position.set(-5, 5, -5), o.lookAt(0, 1, 0), this.scene.add(o);
803
3707
  }
804
3708
  /**
805
3709
  * Load an avatar by config URL
806
3710
  */
807
3711
  async loadAvatar(t) {
808
3712
  this.avatarModel && this.scene.remove(this.avatarModel);
809
- const { model: e, config: i, animations: s } = await this.loader.load(t);
810
- this.avatarModel = e, this.currentAvatarConfig = i, this.scene.add(this.avatarModel);
811
- const a = i.lookAt?.headBoneName || "Head";
812
- if (this.headBone = this.avatarModel.getObjectByName(a) || null, this.headBone || this.avatarModel.traverse((r) => {
813
- !this.headBone && r.name.toLowerCase().includes("head") && (this.headBone = r);
814
- }), s.length > 0) {
815
- this.animController = new O(this.avatarModel, s);
816
- const r = i.animations || {
3713
+ const { model: n, config: o, animations: r } = await this.loader.load(t);
3714
+ this.avatarModel = n, this.currentAvatarConfig = o, this.scene.add(this.avatarModel);
3715
+ const i = o.lookAt?.headBoneName || "Head";
3716
+ if (this.headBone = this.avatarModel.getObjectByName(i) || null, this.headBone || this.avatarModel.traverse((s) => {
3717
+ !this.headBone && s.name.toLowerCase().includes("head") && (this.headBone = s);
3718
+ }), r.length > 0) {
3719
+ this.animController = new De(this.avatarModel, r);
3720
+ const s = o.animations || {
817
3721
  defaultState: "idle",
818
3722
  states: {
819
3723
  idle: { clipName: "Idle", loop: !0 },
820
3724
  walk: { clipName: "Walking", loop: !0 },
821
3725
  wave: { clipName: "Wave", loop: !1, next: "idle" },
3726
+ talk: { clipName: "Talk", loop: !0 },
3727
+ thinking: { clipName: "Thinking", loop: !0 },
822
3728
  dance: { clipName: "Dance", loop: !1, next: "idle" },
823
3729
  bow: { clipName: "Bow", loop: !1, next: "idle" }
824
3730
  }
825
3731
  };
826
- this.animController.init(r);
3732
+ this.animController.init(s);
827
3733
  }
828
- console.log(`[Flow] Avatar "${i.name}" loaded.`);
3734
+ this.headBone && this.bubbleManager.setTarget(this.headBone), console.log(`[Flow] Avatar "${o.name}" loaded.`);
829
3735
  }
830
3736
  /**
831
3737
  * Load a stage (podium/scene) by config URL
832
3738
  */
833
3739
  async loadStage(t) {
834
3740
  this.stageModel && this.scene.remove(this.stageModel);
835
- const { model: e, config: i, animations: s } = await this.stageLoader.load(t);
836
- this.stageModel = e, this.scene.add(this.stageModel), s.length > 0 && i.animations && (this.stageAnimController = new O(this.stageModel, s), this.stageAnimController.init(i.animations));
3741
+ const { model: n, config: o, animations: r } = await this.stageLoader.load(t);
3742
+ this.stageModel = n, this.scene.add(this.stageModel), r.length > 0 && o.animations && (this.stageAnimController = new De(this.stageModel, r), this.stageAnimController.init(o.animations));
837
3743
  }
838
3744
  setDebug(t) {
839
- this.isDebug = t, t ? this.createDebugHelpers() : this.removeDebugHelpers();
3745
+ this.isDebug = t, t ? (this.createDebugHelpers(), this.brain.setDebugMode(!0)) : (this.removeDebugHelpers(), this.brain.setDebugMode(!1));
840
3746
  }
841
3747
  createDebugHelpers() {
842
- if (this.debugTargetMesh || (this.debugTargetMesh = new n.Mesh(
843
- new n.SphereGeometry(0.1, 8, 8),
844
- new n.MeshBasicMaterial({ color: 16711680, wireframe: !0, depthTest: !1 })
3748
+ if (this.debugTargetMesh || (this.debugTargetMesh = new d.Mesh(
3749
+ new d.SphereGeometry(0.1, 8, 8),
3750
+ new d.MeshBasicMaterial({ color: 16711680, wireframe: !0, depthTest: !1 })
845
3751
  ), this.debugTargetMesh.renderOrder = 999, this.scene.add(this.debugTargetMesh)), !this.debugPlaneMesh) {
846
- const t = new n.GridHelper(5, 10, 65280, 34816);
3752
+ const t = new d.GridHelper(5, 10, 65280, 34816);
847
3753
  t.material.transparent = !0, t.material.opacity = 0.5, t.rotateX(Math.PI / 2), this.debugPlaneMesh = t, this.scene.add(this.debugPlaneMesh);
848
3754
  }
849
3755
  }
850
3756
  updateDebugHelpers() {
851
3757
  if (!this.isDebug || !this.lookAtProcessor) return;
852
- const t = this.lookAtProcessor.getDebugInfo(), e = !!(t.planeCenter && t.activePlane);
853
- if (this.debugTargetMesh && (this.debugTargetMesh.position.copy(t.currentLookAt), this.debugTargetMesh.visible = t.isEngaged), this.debugPlaneMesh && (this.debugPlaneMesh.visible = e, e)) {
3758
+ const t = this.lookAtProcessor.getDebugInfo(), n = !!(t.planeCenter && t.activePlane);
3759
+ if (this.debugTargetMesh && (this.debugTargetMesh.position.copy(t.currentLookAt), this.debugTargetMesh.visible = t.isEngaged), this.debugPlaneMesh && (this.debugPlaneMesh.visible = n, n)) {
854
3760
  this.debugPlaneMesh.position.copy(t.planeCenter);
855
- const i = t.activePlane.normal, s = this.debugPlaneMesh.position.clone().add(i);
856
- this.debugPlaneMesh.lookAt(s), this.debugPlaneMesh.rotateX(Math.PI / 2);
3761
+ const o = t.activePlane.normal, r = this.debugPlaneMesh.position.clone().add(o);
3762
+ this.debugPlaneMesh.lookAt(r), this.debugPlaneMesh.rotateX(Math.PI / 2);
857
3763
  }
858
3764
  }
859
3765
  removeDebugHelpers() {
860
3766
  this.debugTargetMesh && (this.scene.remove(this.debugTargetMesh), this.debugTargetMesh = null), this.debugPlaneMesh && (this.scene.remove(this.debugPlaneMesh), this.debugPlaneMesh = null);
861
3767
  }
862
- onWindowResize() {
863
- this.camera.aspect = window.innerWidth / window.innerHeight, this.camera.updateProjectionMatrix(), this.renderer.setSize(window.innerWidth, window.innerHeight);
3768
+ onWindowResize(t, n) {
3769
+ !t || !n || (this.camera.aspect = t / n, this.camera.updateProjectionMatrix(), this.renderer.setSize(t, n));
864
3770
  }
865
3771
  isAutoRotate = !1;
3772
+ /**
3773
+ * HIGH-LEVEL BEHAVIOR API
3774
+ */
3775
+ /**
3776
+ * Submit a 'TALKING' intent to the brain.
3777
+ * @param params Conversation parameters (text, duration)
3778
+ */
3779
+ say(t) {
3780
+ const n = typeof t == "string" ? { text: t } : t, o = xs.parse(n);
3781
+ this.brain.setIntent({
3782
+ state: N.TALKING,
3783
+ text: o.text,
3784
+ duration: o.duration
3785
+ });
3786
+ }
3787
+ /**
3788
+ * Submit a 'THINKING' intent to the brain.
3789
+ * @param params Thought parameters (text, duration)
3790
+ */
3791
+ think(t) {
3792
+ const n = typeof t == "string" ? { text: t } : t || {}, o = Fs.parse(n);
3793
+ this.brain.setIntent({
3794
+ state: N.THINKING,
3795
+ text: o.text,
3796
+ duration: o.duration
3797
+ });
3798
+ }
3799
+ /**
3800
+ * Submit a complex behavior intent.
3801
+ * @param intent The behavior intent object
3802
+ */
3803
+ setBehavior(t) {
3804
+ this.brain.setIntent(t);
3805
+ }
3806
+ /**
3807
+ * Processes a structured response from an AI Agent.
3808
+ * This is the primary bridge for Agent-to-Avatar interaction.
3809
+ * @param response The structured message according to the Unified Action Protocol
3810
+ */
3811
+ processAgentResponse(t) {
3812
+ if (!t || typeof t != "object") {
3813
+ console.warn("[Flow] Invalid AgentResponse received:", t);
3814
+ return;
3815
+ }
3816
+ console.log("[Flow] Processing Agent Response:", t), t.state ? this.brain.setIntent({
3817
+ state: t.state,
3818
+ text: t.text,
3819
+ emotion: t.emotion
3820
+ }) : t.text && this.say(t.text), t.actions && Array.isArray(t.actions) && t.actions.forEach((n) => {
3821
+ setTimeout(() => {
3822
+ this.executeCommand(n);
3823
+ }, n.delay || 0);
3824
+ });
3825
+ }
3826
+ /**
3827
+ * Internal executor for discrete action commands.
3828
+ * Note: Actions scheduled with delay may conflict if state changes rapidly.
3829
+ */
3830
+ executeCommand(t) {
3831
+ if (!(!t || !t.type))
3832
+ switch (t.type) {
3833
+ case "animation":
3834
+ this.animController && this.animController.play(t.name.toLowerCase());
3835
+ break;
3836
+ case "expression":
3837
+ break;
3838
+ case "interaction":
3839
+ t.name === "lookAt" && t.value instanceof d.Vector3 && this.lookAtProcessor.setTarget(t.value);
3840
+ break;
3841
+ default:
3842
+ console.warn("[Flow] Unknown action command type received:", t.type, t);
3843
+ break;
3844
+ }
3845
+ }
3846
+ /**
3847
+ * Play a manual low-level action. Interrupts high-level brain state.
3848
+ * @param action State name defined in config.animations.states
3849
+ */
866
3850
  playAction(t) {
867
- this.lookAtProcessor.interrupt(), this.animController && this.animController.play(t.toLowerCase());
3851
+ this.lookAtProcessor.interrupt(), this.brain.setIntent({ state: N.IDLE }), this.animController && this.animController.play(t.toLowerCase());
868
3852
  }
869
3853
  animate(t) {
870
- const e = this.clock.getDelta();
871
- this.avatarModel && (this.animController && this.animController.update(e), this.lookAtProcessor.update(t, e)), this.updateDebugHelpers(), this.stageModel && this.stageAnimController && this.stageAnimController.update(e), this.controls.autoRotate = this.isAutoRotate, this.controls.update(), this.renderer.render(this.scene, this.camera);
3854
+ const n = this.clock.getDelta();
3855
+ this.brain.update(t), this.avatarModel && (this.animController && this.animController.update(n), this.lookAtProcessor.update(t, n), this.bubbleManager.update()), this.updateDebugHelpers(), this.stageModel && this.stageAnimController && this.stageAnimController.update(n), this.controls.autoRotate = this.isAutoRotate, this.controls.update(), this.renderer.render(this.scene, this.camera);
872
3856
  }
873
3857
  }
874
3858
  export {
875
- O as AnimationController,
876
- $ as AvatarLoader,
877
- rt as FlowEngine
3859
+ De as AnimationController,
3860
+ N as AvatarBehaviorStates,
3861
+ tn as AvatarLoader,
3862
+ cn as BehaviorController,
3863
+ Ws as FlowEngine
878
3864
  };