@hatiolab/things-scene 10.0.0-beta.120 → 10.0.0-beta.122

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.
@@ -1,6 +1,6 @@
1
- function t(...t){return e=>{const s=Object.getPrototypeOf(e),i=Array.isArray(s?.capabilities)?s.capabilities:[],r=new Set([...i,...t]);return Object.defineProperty(e,"capabilities",{value:Object.freeze([...r]),writable:!1,configurable:!0}),e}}const e=new Map;function s(t){e.set(t.name,t)}function i(t){return e.get(t)}function r(){return[...e.values()]}const n={x:0,y:0,z:0,w:1};function o(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function a(t,e){const s=t.rotation,i=e.rotation,r=e.position,n=s.w*r.x+s.y*r.z-s.z*r.y,o=s.w*r.y+s.z*r.x-s.x*r.z,a=s.w*r.z+s.x*r.y-s.y*r.x,h=-s.x*r.x-s.y*r.y-s.z*r.z,c=n*s.w+h*-s.x+o*-s.z-a*-s.y,l=o*s.w+h*-s.y+a*-s.x-n*-s.z,u=a*s.w+h*-s.z+n*-s.y-o*-s.x,d={x:s.w*i.x+s.x*i.w+s.y*i.z-s.z*i.y,y:s.w*i.y-s.x*i.z+s.y*i.w+s.z*i.x,z:s.w*i.z+s.x*i.y-s.y*i.x+s.z*i.w,w:s.w*i.w-s.x*i.x-s.y*i.y-s.z*i.z};return{position:{x:t.position.x+c,y:t.position.y+l,z:t.position.z+u},rotation:d}}const h={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function c(t){const{carrierWorld:e,width:s,depth:i,entryHeight:r,approachDistance:n,sides:c,toolType:l,tolerance:u,priority:d}=t,y=s/2,p=i/2;return c.map(t=>{const s=h[t],i="string"==typeof l?l:l[t]??"unknown",c={position:{x:s.axis.x*("east"===t||"west"===t?y:0),y:r,z:s.axis.z*("north"===t||"south"===t?p:0)},rotation:o(s.yaw)},_={position:{x:c.position.x+s.axis.x*n,y:r,z:c.position.z+s.axis.z*n},rotation:o(s.yaw)};return{id:`entry-${s.idSuffix}`,toolType:i,approach:a(e,_),engage:a(e,c),tolerance:u,priority:d}})}function l(t){const{carrierWorld:e,topY:s,approachDistance:i,toolType:r,tolerance:o,priority:h,id:c}=t,l={position:{x:0,y:s,z:0},rotation:{...n}};return{id:c??"top",toolType:r,approach:a(e,{position:{x:0,y:s+i,z:0},rotation:{...n}}),engage:a(e,l),tolerance:o,priority:h}}function u(t,e){return t.filter(t=>t.toolType===e.toolType)}function d(t,e){if(0===t.length)return null;const s=t.map(t=>{const s=t.approach.position.x-e.x,i=t.approach.position.y-e.y,r=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(s*s+i*i+r*r)}});return s.sort((t,e)=>{const s=t.f.priority??0,i=e.f.priority??0;return s!==i?s-i:t.dist-e.dist}),s[0].f}class y{positionAt(t,e,s){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const p=new y;class _{constructor(t){this.owner=t}positionAt(t,e,s,i){if(0!==t)return null;const r=this.owner?.state?.width??0,n=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(r-o)/2),y:Math.max(0,(n-a)/2),z:0}}capacity(t){return t.maxCount??1}}
1
+ function t(...t){return e=>{const s=Object.getPrototypeOf(e),i=Array.isArray(s?.capabilities)?s.capabilities:[],r=new Set([...i,...t]);return Object.defineProperty(e,"capabilities",{value:Object.freeze([...r]),writable:!1,configurable:!0}),e}}const e=new Map;function s(t){e.set(t.name,t)}function i(t){return e.get(t)}function r(){return[...e.values()]}const n={x:0,y:0,z:0,w:1};function o(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function a(t,e){const s=t.rotation,i=e.rotation,r=e.position,n=s.w*r.x+s.y*r.z-s.z*r.y,o=s.w*r.y+s.z*r.x-s.x*r.z,a=s.w*r.z+s.x*r.y-s.y*r.x,h=-s.x*r.x-s.y*r.y-s.z*r.z,c=n*s.w+h*-s.x+o*-s.z-a*-s.y,l=o*s.w+h*-s.y+a*-s.x-n*-s.z,d=a*s.w+h*-s.z+n*-s.y-o*-s.x,u={x:s.w*i.x+s.x*i.w+s.y*i.z-s.z*i.y,y:s.w*i.y-s.x*i.z+s.y*i.w+s.z*i.x,z:s.w*i.z+s.x*i.y-s.y*i.x+s.z*i.w,w:s.w*i.w-s.x*i.x-s.y*i.y-s.z*i.z};return{position:{x:t.position.x+c,y:t.position.y+l,z:t.position.z+d},rotation:u}}const h={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function c(t){const{carrierWorld:e,width:s,depth:i,entryHeight:r,approachDistance:n,sides:c,toolType:l,tolerance:d,priority:u}=t,y=s/2,p=i/2;return c.map(t=>{const s=h[t],i="string"==typeof l?l:l[t]??"unknown",c={position:{x:s.axis.x*("east"===t||"west"===t?y:0),y:r,z:s.axis.z*("north"===t||"south"===t?p:0)},rotation:o(s.yaw)},_={position:{x:c.position.x+s.axis.x*n,y:r,z:c.position.z+s.axis.z*n},rotation:o(s.yaw)};return{id:`entry-${s.idSuffix}`,toolType:i,approach:a(e,_),engage:a(e,c),tolerance:d,priority:u}})}function l(t){const{carrierWorld:e,topY:s,approachDistance:i,toolType:r,tolerance:o,priority:h,id:c}=t,l={position:{x:0,y:s,z:0},rotation:{...n}};return{id:c??"top",toolType:r,approach:a(e,{position:{x:0,y:s+i,z:0},rotation:{...n}}),engage:a(e,l),tolerance:o,priority:h}}function d(t,e){return t.filter(t=>t.toolType===e.toolType)}function u(t,e){if(0===t.length)return null;const s=t.map(t=>{const s=t.approach.position.x-e.x,i=t.approach.position.y-e.y,r=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(s*s+i*i+r*r)}});return s.sort((t,e)=>{const s=t.f.priority??0,i=e.f.priority??0;return s!==i?s-i:t.dist-e.dist}),s[0].f}class y{positionAt(t,e,s){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const p=new y;class _{constructor(t){this.owner=t}positionAt(t,e,s,i){if(0!==t)return null;const r=this.owner?.state?.width??0,n=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(r-o)/2),y:Math.max(0,(n-a)/2),z:0}}capacity(t){return t.maxCount??1}}
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2010-2026 Three.js Authors
5
5
  * SPDX-License-Identifier: MIT
6
- */const m=2e3;function f(...t){t=function(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return t}(t);const e="THREE."+t.shift();{const s=t[0];s&&s.isStackTrace?console.warn(s.getError(e)):console.warn(e,...t)}}function x(t,e,s){return Math.max(e,Math.min(s,t))}class g{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let a=s[i+0],h=s[i+1],c=s[i+2],l=s[i+3],u=r[n+0],d=r[n+1],y=r[n+2],p=r[n+3];if(l!==p||a!==u||h!==d||c!==y){let t=a*u+h*d+c*y+l*p;t<0&&(u=-u,d=-d,y=-y,p=-p,t=-t);let e=1-o;if(t<.9995){const s=Math.acos(t),i=Math.sin(s);e=Math.sin(e*s)/i,a=a*e+u*(o=Math.sin(o*s)/i),h=h*e+d*o,c=c*e+y*o,l=l*e+p*o}else{a=a*e+u*o,h=h*e+d*o,c=c*e+y*o,l=l*e+p*o;const t=1/Math.sqrt(a*a+h*h+c*c+l*l);a*=t,h*=t,c*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=c,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],c=s[i+3],l=r[n],u=r[n+1],d=r[n+2],y=r[n+3];return t[e]=o*y+c*l+a*d-h*u,t[e+1]=a*y+c*u+h*l-o*d,t[e+2]=h*y+c*d+o*u-a*l,t[e+3]=c*y-o*l-a*u-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),c=o(i/2),l=o(r/2),u=a(s/2),d=a(i/2),y=a(r/2);switch(n){case"XYZ":this._x=u*c*l+h*d*y,this._y=h*d*l-u*c*y,this._z=h*c*y+u*d*l,this._w=h*c*l-u*d*y;break;case"YXZ":this._x=u*c*l+h*d*y,this._y=h*d*l-u*c*y,this._z=h*c*y-u*d*l,this._w=h*c*l+u*d*y;break;case"ZXY":this._x=u*c*l-h*d*y,this._y=h*d*l+u*c*y,this._z=h*c*y+u*d*l,this._w=h*c*l-u*d*y;break;case"ZYX":this._x=u*c*l-h*d*y,this._y=h*d*l+u*c*y,this._z=h*c*y-u*d*l,this._w=h*c*l+u*d*y;break;case"YZX":this._x=u*c*l+h*d*y,this._y=h*d*l+u*c*y,this._z=h*c*y-u*d*l,this._w=h*c*l-u*d*y;break;case"XZY":this._x=u*c*l-h*d*y,this._y=h*d*l-u*c*y,this._z=h*c*y+u*d*l,this._w=h*c*l+u*d*y;break;default:f("Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],c=e[6],l=e[10],u=s+o+l;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(c-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(c-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+c)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(x(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,c=e._w;return this._x=s*c+n*o+i*h-r*a,this._y=i*c+n*a+r*o-s*h,this._z=r*c+n*h+s*a-i*o,this._w=n*c-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){let s=t._x,i=t._y,r=t._z,n=t._w,o=this.dot(t);o<0&&(s=-s,i=-i,r=-r,n=-n,o=-o);let a=1-e;if(o<.9995){const t=Math.acos(o),h=Math.sin(t);a=Math.sin(a*t)/h,e=Math.sin(e*t)/h,this._x=this._x*a+s*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+n*e,this._onChangeCallback()}else this._x=this._x*a+s*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+n*e,this.normalize();return this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class z{constructor(t=0,e=0,s=0){z.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(b.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(b.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),c=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*c,this.y=s+a*c+o*h-r*l,this.z=i+a*l+r*c-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=x(this.x,t.x,e.x),this.y=x(this.y,t.y,e.y),this.z=x(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=x(this.x,t,e),this.y=x(this.y,t,e),this.z=x(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(x(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return M.copy(this).projectOnVector(t),this.sub(M)}reflect(t){return this.sub(M.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(x(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const M=new z,b=new g;class w{constructor(t,e,s,i,r,n,o,a,h,c,l,u,d,y,p,_){w.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,c,l,u,d,y,p,_)}set(t,e,s,i,r,n,o,a,h,c,l,u,d,y,p,_){const m=this.elements;return m[0]=t,m[4]=e,m[8]=s,m[12]=i,m[1]=r,m[5]=n,m[9]=o,m[13]=a,m[2]=h,m[6]=c,m[10]=l,m[14]=u,m[3]=d,m[7]=y,m[11]=p,m[15]=_,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new w).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,s=t.elements,i=1/S.setFromMatrixColumn(t,0).length(),r=1/S.setFromMatrixColumn(t,1).length(),n=1/S.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),c=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=a*c,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*c,s=a*l,i=h*c,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*c,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*c,s=a*l,i=h*c,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*c,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=a*c,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*c,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*c,e[9]=-o*c,e[2]=-h*c,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*c,e[4]=-l,e[8]=h*c,e[1]=t*l+r,e[5]=n*c,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*c,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(C,t,R)}lookAt(t,e,s){const i=this.elements;return E.subVectors(t,e),0===E.lengthSq()&&(E.z=1),E.normalize(),k.crossVectors(s,E),0===k.lengthSq()&&(1===Math.abs(s.z)?E.x+=1e-4:E.z+=1e-4,E.normalize(),k.crossVectors(s,E)),k.normalize(),I.crossVectors(E,k),i[0]=k.x,i[4]=I.x,i[8]=E.x,i[1]=k.y,i[5]=I.y,i[9]=E.y,i[2]=k.z,i[6]=I.z,i[10]=E.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],c=s[1],l=s[5],u=s[9],d=s[13],y=s[2],p=s[6],_=s[10],m=s[14],f=s[3],x=s[7],g=s[11],z=s[15],M=i[0],b=i[4],w=i[8],S=i[12],v=i[1],C=i[5],R=i[9],k=i[13],I=i[2],E=i[6],A=i[10],F=i[14],N=i[3],j=i[7],P=i[11],T=i[15];return r[0]=n*M+o*v+a*I+h*N,r[4]=n*b+o*C+a*E+h*j,r[8]=n*w+o*R+a*A+h*P,r[12]=n*S+o*k+a*F+h*T,r[1]=c*M+l*v+u*I+d*N,r[5]=c*b+l*C+u*E+d*j,r[9]=c*w+l*R+u*A+d*P,r[13]=c*S+l*k+u*F+d*T,r[2]=y*M+p*v+_*I+m*N,r[6]=y*b+p*C+_*E+m*j,r[10]=y*w+p*R+_*A+m*P,r[14]=y*S+p*k+_*F+m*T,r[3]=f*M+x*v+g*I+z*N,r[7]=f*b+x*C+g*E+z*j,r[11]=f*w+x*R+g*A+z*P,r[15]=f*S+x*k+g*F+z*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],c=t[2],l=t[6],u=t[10],d=t[14],y=t[3],p=t[7],_=t[11],m=t[15],f=a*d-h*u,x=o*d-h*l,g=o*u-a*l,z=n*d-h*c,M=n*u-a*c,b=n*l-o*c;return e*(p*f-_*x+m*g)-s*(y*f-_*z+m*M)+i*(y*x-p*z+m*b)-r*(y*g-p*M+_*b)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],c=t[8],l=t[9],u=t[10],d=t[11],y=t[12],p=t[13],_=t[14],m=t[15],f=e*o-s*n,x=e*a-i*n,g=e*h-r*n,z=s*a-i*o,M=s*h-r*o,b=i*h-r*a,w=c*p-l*y,S=c*_-u*y,v=c*m-d*y,C=l*_-u*p,R=l*m-d*p,k=u*m-d*_,I=f*k-x*R+g*C+z*v-M*S+b*w;if(0===I)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/I;return t[0]=(o*k-a*R+h*C)*E,t[1]=(i*R-s*k-r*C)*E,t[2]=(p*b-_*M+m*z)*E,t[3]=(u*M-l*b-d*z)*E,t[4]=(a*v-n*k-h*S)*E,t[5]=(e*k-i*v+r*S)*E,t[6]=(_*g-y*b-m*x)*E,t[7]=(c*b-u*g+d*x)*E,t[8]=(n*R-o*v+h*w)*E,t[9]=(s*v-e*R-r*w)*E,t[10]=(y*M-p*g+m*f)*E,t[11]=(l*g-c*M-d*f)*E,t[12]=(o*S-n*C-a*w)*E,t[13]=(e*C-s*S+i*w)*E,t[14]=(p*x-y*z-_*f)*E,t[15]=(c*z-l*x+u*f)*E,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,c=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,c*o+s,c*a-i*n,0,h*a-i*o,c*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,c=n+n,l=o+o,u=r*h,d=r*c,y=r*l,p=n*c,_=n*l,m=o*l,f=a*h,x=a*c,g=a*l,z=s.x,M=s.y,b=s.z;return i[0]=(1-(p+m))*z,i[1]=(d+g)*z,i[2]=(y-x)*z,i[3]=0,i[4]=(d-g)*M,i[5]=(1-(u+m))*M,i[6]=(_+f)*M,i[7]=0,i[8]=(y+x)*b,i[9]=(_-f)*b,i[10]=(1-(u+p))*b,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return s.set(1,1,1),e.identity(),this;let n=S.set(i[0],i[1],i[2]).length();const o=S.set(i[4],i[5],i[6]).length(),a=S.set(i[8],i[9],i[10]).length();r<0&&(n=-n),v.copy(this);const h=1/n,c=1/o,l=1/a;return v.elements[0]*=h,v.elements[1]*=h,v.elements[2]*=h,v.elements[4]*=c,v.elements[5]*=c,v.elements[6]*=c,v.elements[8]*=l,v.elements[9]*=l,v.elements[10]*=l,e.setFromRotationMatrix(v),s.x=n,s.y=o,s.z=a,this}makePerspective(t,e,s,i,r,n,o=2e3,a=!1){const h=this.elements,c=2*r/(e-t),l=2*r/(s-i),u=(e+t)/(e-t),d=(s+i)/(s-i);let y,p;if(a)y=r/(n-r),p=n*r/(n-r);else if(o===m)y=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);y=-n/(n-r),p=-n*r/(n-r)}return h[0]=c,h[4]=0,h[8]=u,h[12]=0,h[1]=0,h[5]=l,h[9]=d,h[13]=0,h[2]=0,h[6]=0,h[10]=y,h[14]=p,h[3]=0,h[7]=0,h[11]=-1,h[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3,a=!1){const h=this.elements,c=2/(e-t),l=2/(s-i),u=-(e+t)/(e-t),d=-(s+i)/(s-i);let y,p;if(a)y=1/(n-r),p=n/(n-r);else if(o===m)y=-2/(n-r),p=-(n+r)/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);y=-1/(n-r),p=-r/(n-r)}return h[0]=c,h[4]=0,h[8]=0,h[12]=u,h[1]=0,h[5]=l,h[9]=0,h[13]=d,h[2]=0,h[6]=0,h[10]=y,h[14]=p,h[3]=0,h[7]=0,h[11]=0,h[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const S=new z,v=new w,C=new z(0,0,0),R=new z(1,1,1),k=new z,I=new z,E=new z,A=new w,F=new g;class N{constructor(t=0,e=0,s=0,i=N.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],c=i[9],l=i[2],u=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(x(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-x(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(x(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-x(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(x(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-x(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-c,d),this._y=0);break;default:f("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return A.makeRotationFromQuaternion(t),this.setFromRotationMatrix(A,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return F.setFromEuler(this),this.setFromQuaternion(F,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}N.DEFAULT_ORDER="XYZ","undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"183"}})),"undefined"!=typeof window&&(window.__THREE__?f("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="183");const j=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=j);let P=null;const T=[],O=new Set;function q(t){if(!t)return;const e=t?.state?.id??t?.id??t?.refid;return void 0!==e?String(e):void 0}const Y={beginContext(t){P=t},endContext(){P=null},current:()=>P,log(t){const e={role:t.role,contract:t.contract,componentId:t.componentId??q(t.component),componentType:t.componentType??(s=t.component,s?.state?.type??s?.type),atSimMs:j.now,args:t.args,result:t.result,error:t.error};var s;P?P.pushTrace(e):(T.push(e),T.length>500&&T.shift(),O.forEach(t=>{try{t(e)}catch{}}))},standaloneEvents:()=>[...T],onStandalone:t=>(O.add(t),()=>{O.delete(t)}),clearStandalone(){T.length=0}};function L(t){if(!t)return;const e=t?.state?.id??t?.id;return"string"==typeof e?e:void 0}function W(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},s=t.sourceId??L(t.source),i=t.targetId??L(t.target),r=t.carrierId??L(t.carrier);return void 0!==s&&(e.sourceId=s),void 0!==i&&(e.targetId=i),void 0!==r&&(e.carrierId=r),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}let X=1;class Z{constructor(t){this._phase="pending",this._slot=null,this._traceEvents=[],this.meta={},this.id="xfer-"+X++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:j.now}}pushTrace(t){this._traceEvents.push({atSimMs:t.atSimMs??j.now,...t})}get phase(){return this._phase}get timeline(){return this._timeline}async execute(){Y.beginContext(this),Y.log({role:"transfer",contract:"execute:begin",args:{transferId:this.id,source:L(this.source),target:L(this.target),carrier:L(this.carrier)}});try{return await this._executeImpl()}finally{Y.log({role:"transfer",contract:"execute:end",args:{transferId:this.id,phase:this._phase}}),Y.endContext()}}executeSync(){Y.beginContext(this),Y.log({role:"transfer",contract:"executeSync:begin",args:{transferId:this.id,source:L(this.source),target:L(this.target),carrier:L(this.carrier)}});try{this._phase="planning",this._timeline.planStartAt=j.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return V.append(e),e}this._slot=t.slot}else if("function"==typeof this.target.canReceive){if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return V.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}else this._slot=null;if(this._timeline.planEndAt=j.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=j.now;try{const t=this.physical();t instanceof Promise&&t.catch(()=>{})}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return V.append(e),e}this._timeline.physicalEndAt=j.now}this._phase="handoff",this._timeline.handoffAt=j.now;const e=this.target.accept??this.target.receive;if("function"==typeof e)try{const t=e.call(this.target,this.carrier,this.options);t instanceof Promise&&t.catch(()=>{})}catch(t){this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();throw V.append(e),t}else Y.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}});this._phase="committed",this._timeline.committedAt=j.now;const s=this._buildReceipt();return V.append(s),s}finally{Y.log({role:"transfer",contract:"executeSync:end",args:{transferId:this.id,phase:this._phase}}),Y.endContext()}}async _executeImpl(){this._phase="planning",this._timeline.planStartAt=j.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return V.append(e),e}this._slot=t.slot}else if("function"==typeof this.target.canReceive){if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return V.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}else this._slot=null;if(this._timeline.planEndAt=j.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=j.now;try{await this.physical()}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return V.append(e),e}this._timeline.physicalEndAt=j.now}this._phase="handoff",this._timeline.handoffAt=j.now;const e=this.target.accept??this.target.receive;if("function"==typeof e)try{await e.call(this.target,this.carrier,this.options)}catch(t){this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();throw V.append(e),t}else Y.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method (physical phase handled handoff)"}});this._phase="committed",this._timeline.committedAt=j.now;const s=this._buildReceipt();return V.append(s),s}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",V.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:L(this.source),targetId:L(this.target),carrierId:L(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason,traceEvents:[...this._traceEvents],meta:Object.keys(this.meta).length>0?{...this.meta}:void 0}}}const V=new class{constructor(){this._entries=[],this._maxEntries=1e3,this._listeners=new Set}append(t){this._entries.push(t),this._entries.length>this._maxEntries&&this._entries.shift(),this._listeners.forEach(e=>e(t))}entries(){return[...this._entries]}forCarrier(t){const e=L(t);return this._entries.filter(s=>s.carrier===t||e&&s.carrierId===e)}forCarrierId(t){return this._entries.filter(e=>e.carrierId===t)}forSourceId(t){return this._entries.filter(e=>e.sourceId===t)}forTargetId(t){return this._entries.filter(e=>e.targetId===t)}forPhase(t){return this._entries.filter(e=>e.phase===t)}inTimeRange(t,e,s="init"){return"init"===s?this._entries.filter(s=>s.timeline.initiatedAt>=t&&s.timeline.initiatedAt<=e):this._entries.filter(s=>{const i=s.timeline.initiatedAt,r=s.timeline.committedAt??s.timeline.handoffAt??s.timeline.physicalEndAt??s.timeline.planEndAt??i;return i<=e&&r>=t})}groupByRejectReason(){const t=new Map;for(const e of this._entries)if(e.rejectReason){const s=t.get(e.rejectReason)??[];s.push(e),t.set(e.rejectReason,s)}return t}stats(){const t=this._entries.length,e={};let s=0,i=0;for(const t of this._entries)e[t.phase]=(e[t.phase]??0)+1,"committed"===t.phase&&void 0!==t.timeline.committedAt&&(s+=t.timeline.committedAt-t.timeline.initiatedAt,i++);const r=e["rolled-back"]??0;return{total:t,byPhase:e,committed:e.committed??0,rolledBack:r,rejectionRate:t>0?r/t:0,avgTransferDurationMs:i>0?s/i:0}}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._entries.length=0}setMaxEntries(t){this._maxEntries=Math.max(1,t)}toJSON(){return this._entries.map(W)}fromJSON(t){this._entries=t.map(t=>({transferId:t.transferId,source:void 0,target:void 0,carrier:void 0,sourceId:t.sourceId,targetId:t.targetId,carrierId:t.carrierId,phase:t.phase,timeline:{...t.timeline},slotId:t.slotId,rejectReason:t.rejectReason}))}replayTo(t){for(const e of this._entries)t(e)}};function Q(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=V);const D=new N;function H(t,e){D.setFromQuaternion(new g(e.x,e.y,e.z,e.w),"XYZ"),t.rotationX=D.x,t.rotation=-D.y,t.rotationY=D.z}const $="_transferSlotId";function G(t){const e=class extends t{get slots(){return[]}get arrangementStrategy(){return p}canReceive(t){const e=null!==this.findSlot(t);return Y.log({role:"target",contract:"canReceive",component:this,args:{carrier:Q(t)},result:e}),e}findSlot(t){const e=this.slots;if(!e.length)return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:Q(t)},result:null}),null;for(const s of e){if(s.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!s.allowedTypes.includes(e))continue}const e=s.maxCount??this.arrangementStrategy.capacity(s),i=this._countOccupied(s.id);if(!(i>=e))return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:Q(t)},result:{slotId:s.id,occupied:i,max:e}}),s}return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:Q(t)},result:null}),null}async receive(t,e={}){Y.log({role:"target",contract:"receive:enter",component:this,args:{carrier:Q(t),options:e}});const s=this.findSlot(t);if(!s){Y.log({role:"target",contract:"receive:reject",component:this,args:{carrier:Q(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}const i=this._countOccupied(s.id),r=this.arrangementStrategy.positionAt(i,s,i,t);Y.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:i,slotId:s.id,occupantCount:i,carrier:Q(t)},result:r}),t[$]=s.id;const n=t._realObject;let o,a;n?.object3d&&(n.object3d.updateWorldMatrix(!0,!1),o=new z,a=new g,n.object3d.getWorldPosition(o),n.object3d.getWorldQuaternion(a));const{animated:h=!1,duration:c,ease:l}=e;this.reparent?.(t,{animated:h,duration:c,ease:l}),!h&&t._realObject&&(t._realObject.suppressTransform=!1);{const e={},n=this.placementFor?.(t,{slot:s,index:i,occupantCount:i})??null;if(Y.log({role:"target",contract:"placementFor",component:this,args:{carrier:Q(t),slotId:s.id,index:i},result:n}),n){const i=t.state??{},r=this.state??{};e.left=n.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,e.top=n.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(n.position.y,i.depth,s);null!==o&&(e.zPos=o),n.rotation&&H(e,n.rotation)}else{r&&(e.left=r.x,e.top=r.y);if(0!==(this._realObject?.receivingSurfaceY??0))e.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const t=this._realObject?.geometricOffsetY??0;e.zPos=s.localPosition.z+t}const i=this.acceptanceRotation?.(t,s);Y.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:Q(t),slotId:s.id},result:i}),i&&H(e,i)}const o=this.normalizePose?.(t,s);"function"==typeof this.normalizePose&&Y.log({role:"target",contract:"normalizePose",component:this,args:{carrier:Q(t),slotId:s.id},result:o}),o&&Object.assign(e,o),Object.keys(e).length&&(t.setState?.(e),Y.log({role:"target",contract:"receive:setState",component:this,args:{carrier:Q(t),keys:Object.keys(e)}}))}this.trigger("transfer-received",{type:"transfer-received",component:t,container:this,slotId:s.id,preReceiveWorldPos:o,preReceiveWorldQuat:a}),Y.log({role:"target",contract:"receive:done",component:this,args:{carrier:Q(t),slotId:s.id}})}async dispatch(t,e,s={}){const i=new Z({source:this,target:e,carrier:t,options:s,physical:async()=>{delete t[$]}}),r=await i.execute();"rolled-back"!==r.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:r.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}acceptanceRotation(t,e){}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const s=this.findSlot(t);if(!s){const s=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!s||t.allowedTypes.includes(s))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:s}})();return Y.log({role:"target",contract:"canAccept",component:this,args:{carrier:Q(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}deliveryWorldRotation(t){const e=this.acceptanceRotation?.(t);if(!e)return;const s=this._realObject?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new g;s.getWorldQuaternion(i);const r=new g(e.x,e.y,e.z,e.w);return i.clone().multiply(r)}deliveryWorldPosition(t){const e=this._realObject,s=e?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new z;s.getWorldPosition(i);const r=this._receivingSurfaceLocalY();if(null!==r){const t=new z(0,r,0);return s.localToWorld(t),{x:i.x,y:t.y,z:i.z}}return{x:i.x,y:i.y,z:i.z}}attachPointFor(t){const e=t?.[$];if(!e)return null;const s=this.slots.find(t=>t.id===e);return s?{position:s.localPosition??{x:0,y:0,z:0},rotation:s.localRotation??{x:0,y:0,z:0},slotId:s.id}:null}placementFor(t,e={}){const s=t&&"object"==typeof t&&"state"in t?t:void 0,i=s?s.state??{}:t??{},r={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},n=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!n)return null;const o=e.index??this._countOccupied(n.id),a=e.occupantCount??o,h=this.arrangementStrategy.positionAt(o,n,a,s??{state:{...r}});if(!h)return null;const c=Number(this.state?.width)||0,l=Number(this.state?.height)||0,u=h.x+r.width/2-c/2,d=h.y+r.height/2-l/2,y=this._realObject,p=y?.placementMode??"floor",_="space"===p?0:"inverted"===p?-r.depth/2:r.depth/2,m=this._receivingSurfaceLocalY();let f;f=null!==m?m+_:n.localPosition&&Number.isFinite(n.localPosition.z)?n.localPosition.z+_:_-(y?.geometricOffsetY??0);const x=this.acceptanceRotation?.(s??r,n)??void 0;return x?{position:{x:u,y:f,z:d},rotation:x}:{position:{x:u,y:f,z:d}}}_zPosFromSeatY(t,e,s){const i=this._realObject,r=i?.receivingSurfaceY??0,n=!(!s.localPosition||!Number.isFinite(s.localPosition.z));if(0===r&&!n)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-r}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this.components;return e?e.filter(e=>e.parent===this&&e[$]===t).length:0}};return e.capabilities=[...t.capabilities??[],"ContainerCapacity","PlacementSurface"],e}function J(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.canReserveAtJoinPoint&&"function"==typeof e.reserveAtJoinPoint&&"function"==typeof e.commitReservation&&"function"==typeof e.releaseReservation&&e.carrierMap instanceof Map}function B(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.slotAt&&"function"==typeof e.findFreeSlot&&"function"==typeof e.findSlotsWithSKU&&"function"==typeof e.reservePut&&"function"==typeof e.reservePick&&"function"==typeof e.commitReservation&&"function"==typeof e.releaseReservation&&e.slots instanceof Map}function U(t){return`${t.level}.${t.bay}.${t.depth}`}function K(t){const e=t.split(".");if(3!==e.length)return null;const[s,i,r]=e.map(t=>Number.parseInt(t,10));return Number.isFinite(s)&&Number.isFinite(i)&&Number.isFinite(r)?{level:s,bay:i,depth:r}:null}s({name:"ContainerCapacity",description:"Carrier slot topology + reservation / commit / release 의 default 구현을 Mixin 으로 제공. 컨테이너 (chute, induct, dock 등) 가 Transferable contract 의 standard impl 을 1줄 Mixin 으로 획득. subclass 는 *slots* 만 override.",methods:["get slots","reserveSlot","commitReservation","releaseReservation","isSlotAvailable","occupancyAt"],stateFields:["capacity","maxCapacity","slotArrangement"],sourceFile:"src/transfer/container-capacity.ts"}),s({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 ContainerCapacity 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/transfer/container-capacity.ts"}),s({name:"CarrierLine",description:"carrier slot 들을 연속 경로 위에서 운영하는 컴포넌트의 추상 contract. cross-belt-line, loop-sorter, monorail, AGV-fleet 등 각각 다른 concrete class 들이 같은 capability 를 노출 — source (induct, station 등) 는 concrete class 모르고 capability 만 사용.",methods:["canReserveAtJoinPoint","reserveAtJoinPoint","commitReservation","releaseReservation"],models:["CarrierReservation","CarrierSlotState","JoinPoint"],stateFields:["speed","carrierPitch","direction","orientation"],sourceFile:"src/transfer/carrier-line-capability.ts"}),s({name:"StorageRack",description:"고정 grid 위의 addressable slot 들을 운영하는 컴포넌트 (rack, AS/RS, AutoStore-style bin-stack 등) 의 추상 contract. stacker crane, mini-load shuttle, 자율 forklift, AGV 등의 retrieval / putaway 작업이 같은 interface 로 동작.",methods:["slotAt","findFreeSlot","findSlotsWithSKU","reservePut","reservePick","commitReservation","releaseReservation"],models:["StorageSlotAddress","StorageSlotState","StorageReservation","SlotSearchCriteria"],stateFields:["levels","bays","depths","maxLoad"],sourceFile:"src/transfer/storage-rack-capability.ts"});let tt=1;function et(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const st={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class it{constructor(t=st){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+tt++},s=(this._byResource.get(e.resource)??[]).filter(t=>et(t.timeWindow,e.timeWindow));if(0===s.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=s.map(t=>{const s=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:s}});if(i.every(t=>"b-yields"===t.decision)){const i=s.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:s.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>et(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const s=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);s<0?e.push(t):e.splice(s,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const s=e.findIndex(e=>e.id===t.id);if(s<0)return!1;e.splice(s,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const rt=new it;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=rt);class nt{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,s=1/0;for(const i of this.nodes.values()){const r=ot(i.position,t);r<s&&(s=r,e=i)}return e}}function ot(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}function at(t,e){return Math.sqrt(ot(t,e))}function ht(t,e,s={}){const i=new nt,r=s.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const s=`${e.id}:start`,n=`${e.id}:end`;i.addNode({id:s,position:t[0],type:"lane-start"}),i.addNode({id:n,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:s,endNodeId:n});let o=0;for(let e=1;e<t.length;e++)o+=at(t[e-1],t[e]);const a=o/(e.speedLimit??r)*1e3;i.addEdge({fromNode:s,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:n,toNode:s,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const s of t.lanes){const r=i.laneEndpoints.get(s);if(!r)continue;const n=i.nodes.get(r.startNodeId).position,o=i.nodes.get(r.endNodeId).position;let a=0,h=0,c=0;for(const e of t.lanes){if(e===s)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const r=i.nodes.get(t.startNodeId).position,l=i.nodes.get(t.endNodeId).position;a+=Math.min(ot(n,r),ot(n,l)),h+=Math.min(ot(o,r),ot(o,l)),c++}if(0===c)continue;const l=a<h?r.startNodeId:r.endNodeId;e.push({laneId:s,nodeId:l,pos:i.nodes.get(l).position})}for(let s=0;s<e.length;s++)for(let r=0;r<e.length;r++){if(s===r)continue;const n=e[s],o=e[r],a=at(n.pos,o.pos);i.addEdge({fromNode:n.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function ct(t,e,s,i={}){const r=t.nodes.get(e),n=t.nodes.get(s);if(!r||!n)return null;const o=i.speed?.max??100,a=e=>{const s=t.nodes.get(e);var i,r;return(i=s.position,r=n.position,Math.sqrt(function(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}(i,r)))/o*1e3},h=new Map,c=new Set,l=new Set,u={nodeId:e,gScore:0,fScore:a(e)};h.set(e,u),c.add(e);const d=i.startSimMs??0,y=i.deadlineSimMs;for(;c.size>0;){let e=null,i=null;for(const t of c){const s=h.get(t);(!i||s.fScore<i.fScore||s.fScore===i.fScore&&t<e)&&(i=s,e=t)}if(!i||!e)return null;if(e===s){const t=[];let e=i,s=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,r=d+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:r,endSimMs:r+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),s+=i.distance,e=h.get(i.fromNodeId)}const r=i.gScore;return void 0!==y&&d+r>y?null:{segments:t,totalDurationMs:r,totalDistance:s}}c.delete(e),l.add(e);for(const s of t.edgesFrom(e)){if(l.has(s.toNode))continue;const e=i.gScore+s.durationMs,r=h.get(s.toNode);if(!r||e<r.gScore){const i=t.nodes.get(s.fromNode),r=t.nodes.get(s.toNode),n={nodeId:s.toNode,gScore:e,fScore:e+a(s.toNode),cameFromEdge:{fromNodeId:s.fromNode,resource:s.resource,distance:s.distance,durationMs:s.durationMs,fromPos:i.position,toPos:r.position}};h.set(s.toNode,n),c.add(s.toNode)}}}return null}function lt(t,e,s=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:s,metadata:i}))}const ut=.5;function dt(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=.5}function yt(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n||!Number.isFinite(s)||Math.abs(s)<1e-9)return null;const o=Math.abs(s),a=(n*n+4*o*o)/(8*o),h=s>0?1:-1,c=a-o,l=(t.x+e.x)/2-h*(r/n)*c,u=(t.y+e.y)/2-h*-(i/n)*c;return{cx:l,cy:u,radius:a,startAngle:Math.atan2(t.y-u,t.x-l),endAngle:Math.atan2(e.y-u,e.x-l),clockwise:s<0}}function pt(t,e,s=0,i=16){const r=e.x-t.x,n=e.y-t.y,o=Math.sqrt(r*r+n*n);if(0===o)return null;const a=n/o,h=-(r/o),c=Number.isFinite(s)?s:0,l=Math.abs(c)>=1e-6?c:i;return{x:(t.x+e.x)/2+a*l,y:(t.y+e.y)/2+h*l,perpX:a,perpY:h}}function _t(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n)return 0;const o=r/n,a=-(i/n),h=(t.x+e.x)/2,c=(t.y+e.y)/2;let l=(s.x-h)*o+(s.y-c)*a;if(Math.abs(l)<.5)return 0;return l>n&&(l=n),l<-n&&(l=-n),l}function mt(t,e){const s=t.radius,i=Number.isFinite(e)?e:0;return null!=s&&Number.isFinite(s)?Math.max(0,s):Math.max(0,i)}function ft(t,e,s,i,r=16){const n=t.x-e.x,o=t.y-e.y,a=Math.sqrt(n*n+o*o);if(0===a)return null;const h=s.x-e.x,c=s.y-e.y,l=Math.sqrt(h*h+c*c);if(0===l)return null;const u=n/a+h/l,d=o/a+c/l,y=Math.sqrt(u*u+d*d);if(y<1e-9)return null;const p=u/y,_=d/y,m=Math.max(i,r);return{x:e.x+p*m,y:e.y+_*m,bisectorX:p,bisectorY:_}}function xt(t,e,s,i){const r=t.x-e.x,n=t.y-e.y,o=Math.sqrt(r*r+n*n),a=s.x-e.x,h=s.y-e.y,c=Math.sqrt(a*a+h*h);if(0===o||0===c)return 0;const l=r/o+a/c,u=n/o+h/c,d=Math.sqrt(l*l+u*u);if(d<1e-9)return 0;const y=l/d,p=u/d,_=(i.x-e.x)*y+(i.y-e.y)*p,m=Math.min(o,c)/2;return Math.max(0,Math.min(_,m))}function gt(t){if(0===t.length)return 0;let e;for(const s of t){const t=s.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}const zt={closed:!0,round:0,divisions:24};class Mt{constructor(t,e){this.points=t,this.closed=e;const s=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,r=t[e].y-t[e-1].y;s.push(s[e-1]+Math.sqrt(i*i+r*r))}this.cumulative=s,this.length=s[s.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let s=t;this.closed?s=(t%e+e)%e:s<0?s=0:s>e&&(s=e);const i=this.cumulative;let r=0,n=i.length-2;for(;r<n;){const t=r+n>>1;i[t+1]<=s?r=t+1:n=t}const o=i[r+1]-i[r],a=o>0?(s-i[r])/o:0,h=this.points[r],c=this.points[r+1],l=c.x-h.x,u=c.y-h.y;return{x:h.x+l*a,y:h.y+u*a,theta:0===l&&0===u?0:Math.atan2(u,l)}}}function bt(t,e={}){const s={...zt,...e},i=t.length;if(0===i)return new Mt([],s.closed);if(1===i)return new Mt([{x:t[0].x,y:t[0].y}],s.closed);const r=[],n=(t,e)=>{if(r.length>0){const s=r[r.length-1];if(Math.abs(s.x-t)<1e-9&&Math.abs(s.y-e)<1e-9)return}r.push({x:t,y:e})},o=(s.closed,i);for(let e=0;e<o;e++){const r=0===e?s.closed?i-1:-1:e-1,o=e===i-1?s.closed?0:-1:e+1,a=r>=0?t[r]:null,h=t[e],c=o>=0?t[o]:null;if(a&&a.x===h.x&&a.y===h.y)continue;const l=a&&c?mt(h,s.round):0;let u,d,y,p;if(a){const t=Math.sqrt((a.x-h.x)**2+(a.y-h.y)**2),e=0!==t?Math.atan2(a.x-h.x,a.y-h.y):0,s=Math.min(l,t/2);u=Math.sin(e)*s+h.x,d=Math.cos(e)*s+h.y}else u=h.x,d=h.y;if(c){const t=Math.sqrt((c.x-h.x)**2+(c.y-h.y)**2),e=0!==t?Math.atan2(c.x-h.x,c.y-h.y):0,s=Math.min(l,t/2);y=Math.sin(e)*s+h.x,p=Math.cos(e)*s+h.y}else y=h.x,p=h.y;if(n(u,d),l>0&&a&&c)for(let t=1;t<=s.divisions;t++){const e=t/s.divisions,i=1-e;n(i*i*u+2*i*e*h.x+e*e*y,i*i*d+2*i*e*h.y+e*e*p)}else u===y&&d===p||n(y,p);if(c&&dt(h)){const t=mt(c,s.round),e=Math.sqrt((h.x-c.x)**2+(h.y-c.y)**2),i=0!==e?Math.atan2(h.x-c.x,h.y-c.y):0,r=Math.min(t,e/2),o=yt({x:y,y:p},{x:Math.sin(i)*r+c.x,y:Math.cos(i)*r+c.y},h.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=s.divisions;e++){const i=e/s.divisions,r=o.startAngle+t*i;n(o.cx+o.radius*Math.cos(r),o.cy+o.radius*Math.sin(r))}}}}if(s.closed&&r.length>0){const t=r[0],e=r[r.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&r.push({x:t.x,y:t.y})}return new Mt(r,s.closed)}function wt(t,e){return bt(t,e).length}export{ut as BULGE_EPSILON,_ as CenteringSlotStrategy,G as ContainerCapacity,y as FixedSlotStrategy,nt as NavGraph,Mt as PolygonPathPolyline,it as ReservationTable,$ as TRANSFER_SLOT_KEY,Z as Transfer,U as addressKey,ht as buildNavGraph,_t as bulgeFromDrag,pt as bulgeHandlePosition,t as capability,d as chooseNearestPickupFrame,yt as computeArcParams,ft as cornerHandlePosition,xt as cornerRadiusFromDrag,mt as effectiveCornerRadius,u as filterByToolType,p as fixedSlotStrategy,bt as flattenPolygonPath,r as getAllCapabilityMeta,i as getCapabilityMeta,j as globalSimClock,dt as hasArc,J as isCarrierLine,B as isStorageRack,K as parseAddressKey,ct as planPathAStar,lt as planToReservations,wt as polygonPathLength,o as quatFromYaw,W as receiptToJSON,c as rectangularFootprintFrames,s as registerCapabilityMeta,rt as reservationTable,st as standardYieldPolicy,l as topApproachFrame,V as transferLog,Y as transferTracer,gt as uniformZ};
6
+ */const f=2e3;function m(...t){t=function(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return t}(t);const e="THREE."+t.shift();{const s=t[0];s&&s.isStackTrace?console.warn(s.getError(e)):console.warn(e,...t)}}function x(t,e,s){return Math.max(e,Math.min(s,t))}class g{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let a=s[i+0],h=s[i+1],c=s[i+2],l=s[i+3],d=r[n+0],u=r[n+1],y=r[n+2],p=r[n+3];if(l!==p||a!==d||h!==u||c!==y){let t=a*d+h*u+c*y+l*p;t<0&&(d=-d,u=-u,y=-y,p=-p,t=-t);let e=1-o;if(t<.9995){const s=Math.acos(t),i=Math.sin(s);e=Math.sin(e*s)/i,a=a*e+d*(o=Math.sin(o*s)/i),h=h*e+u*o,c=c*e+y*o,l=l*e+p*o}else{a=a*e+d*o,h=h*e+u*o,c=c*e+y*o,l=l*e+p*o;const t=1/Math.sqrt(a*a+h*h+c*c+l*l);a*=t,h*=t,c*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=c,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],c=s[i+3],l=r[n],d=r[n+1],u=r[n+2],y=r[n+3];return t[e]=o*y+c*l+a*u-h*d,t[e+1]=a*y+c*d+h*l-o*u,t[e+2]=h*y+c*u+o*d-a*l,t[e+3]=c*y-o*l-a*d-h*u,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),c=o(i/2),l=o(r/2),d=a(s/2),u=a(i/2),y=a(r/2);switch(n){case"XYZ":this._x=d*c*l+h*u*y,this._y=h*u*l-d*c*y,this._z=h*c*y+d*u*l,this._w=h*c*l-d*u*y;break;case"YXZ":this._x=d*c*l+h*u*y,this._y=h*u*l-d*c*y,this._z=h*c*y-d*u*l,this._w=h*c*l+d*u*y;break;case"ZXY":this._x=d*c*l-h*u*y,this._y=h*u*l+d*c*y,this._z=h*c*y+d*u*l,this._w=h*c*l-d*u*y;break;case"ZYX":this._x=d*c*l-h*u*y,this._y=h*u*l+d*c*y,this._z=h*c*y-d*u*l,this._w=h*c*l+d*u*y;break;case"YZX":this._x=d*c*l+h*u*y,this._y=h*u*l+d*c*y,this._z=h*c*y-d*u*l,this._w=h*c*l-d*u*y;break;case"XZY":this._x=d*c*l-h*u*y,this._y=h*u*l-d*c*y,this._z=h*c*y+d*u*l,this._w=h*c*l+d*u*y;break;default:m("Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],c=e[6],l=e[10],d=s+o+l;if(d>0){const t=.5/Math.sqrt(d+1);this._w=.25/t,this._x=(c-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(c-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+c)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<1e-8?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(x(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,c=e._w;return this._x=s*c+n*o+i*h-r*a,this._y=i*c+n*a+r*o-s*h,this._z=r*c+n*h+s*a-i*o,this._w=n*c-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){let s=t._x,i=t._y,r=t._z,n=t._w,o=this.dot(t);o<0&&(s=-s,i=-i,r=-r,n=-n,o=-o);let a=1-e;if(o<.9995){const t=Math.acos(o),h=Math.sin(t);a=Math.sin(a*t)/h,e=Math.sin(e*t)/h,this._x=this._x*a+s*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+n*e,this._onChangeCallback()}else this._x=this._x*a+s*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+n*e,this.normalize();return this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class z{constructor(t=0,e=0,s=0){z.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(b.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(b.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),c=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*c,this.y=s+a*c+o*h-r*l,this.z=i+a*l+r*c-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=x(this.x,t.x,e.x),this.y=x(this.y,t.y,e.y),this.z=x(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=x(this.x,t,e),this.y=x(this.y,t,e),this.z=x(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(x(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return M.copy(this).projectOnVector(t),this.sub(M)}reflect(t){return this.sub(M.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(x(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const M=new z,b=new g;class w{constructor(t,e,s,i,r,n,o,a,h,c,l,d,u,y,p,_){w.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,c,l,d,u,y,p,_)}set(t,e,s,i,r,n,o,a,h,c,l,d,u,y,p,_){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=c,f[10]=l,f[14]=d,f[3]=u,f[7]=y,f[11]=p,f[15]=_,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new w).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),s.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this)}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,s=t.elements,i=1/v.setFromMatrixColumn(t,0).length(),r=1/v.setFromMatrixColumn(t,1).length(),n=1/v.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),c=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=a*c,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*c,s=a*l,i=h*c,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*c,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*c,s=a*l,i=h*c,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*c,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*c,s=n*l,i=o*c,r=o*l;e[0]=a*c,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*c,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*c,e[9]=-o*c,e[2]=-h*c,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*c,e[4]=-l,e[8]=h*c,e[1]=t*l+r,e[5]=n*c,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*c,e[10]=r*l+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(C,t,R)}lookAt(t,e,s){const i=this.elements;return E.subVectors(t,e),0===E.lengthSq()&&(E.z=1),E.normalize(),k.crossVectors(s,E),0===k.lengthSq()&&(1===Math.abs(s.z)?E.x+=1e-4:E.z+=1e-4,E.normalize(),k.crossVectors(s,E)),k.normalize(),I.crossVectors(E,k),i[0]=k.x,i[4]=I.x,i[8]=E.x,i[1]=k.y,i[5]=I.y,i[9]=E.y,i[2]=k.z,i[6]=I.z,i[10]=E.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],c=s[1],l=s[5],d=s[9],u=s[13],y=s[2],p=s[6],_=s[10],f=s[14],m=s[3],x=s[7],g=s[11],z=s[15],M=i[0],b=i[4],w=i[8],v=i[12],S=i[1],C=i[5],R=i[9],k=i[13],I=i[2],E=i[6],A=i[10],F=i[14],j=i[3],N=i[7],P=i[11],T=i[15];return r[0]=n*M+o*S+a*I+h*j,r[4]=n*b+o*C+a*E+h*N,r[8]=n*w+o*R+a*A+h*P,r[12]=n*v+o*k+a*F+h*T,r[1]=c*M+l*S+d*I+u*j,r[5]=c*b+l*C+d*E+u*N,r[9]=c*w+l*R+d*A+u*P,r[13]=c*v+l*k+d*F+u*T,r[2]=y*M+p*S+_*I+f*j,r[6]=y*b+p*C+_*E+f*N,r[10]=y*w+p*R+_*A+f*P,r[14]=y*v+p*k+_*F+f*T,r[3]=m*M+x*S+g*I+z*j,r[7]=m*b+x*C+g*E+z*N,r[11]=m*w+x*R+g*A+z*P,r[15]=m*v+x*k+g*F+z*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],c=t[2],l=t[6],d=t[10],u=t[14],y=t[3],p=t[7],_=t[11],f=t[15],m=a*u-h*d,x=o*u-h*l,g=o*d-a*l,z=n*u-h*c,M=n*d-a*c,b=n*l-o*c;return e*(p*m-_*x+f*g)-s*(y*m-_*z+f*M)+i*(y*x-p*z+f*b)-r*(y*g-p*M+_*b)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],c=t[8],l=t[9],d=t[10],u=t[11],y=t[12],p=t[13],_=t[14],f=t[15],m=e*o-s*n,x=e*a-i*n,g=e*h-r*n,z=s*a-i*o,M=s*h-r*o,b=i*h-r*a,w=c*p-l*y,v=c*_-d*y,S=c*f-u*y,C=l*_-d*p,R=l*f-u*p,k=d*f-u*_,I=m*k-x*R+g*C+z*S-M*v+b*w;if(0===I)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/I;return t[0]=(o*k-a*R+h*C)*E,t[1]=(i*R-s*k-r*C)*E,t[2]=(p*b-_*M+f*z)*E,t[3]=(d*M-l*b-u*z)*E,t[4]=(a*S-n*k-h*v)*E,t[5]=(e*k-i*S+r*v)*E,t[6]=(_*g-y*b-f*x)*E,t[7]=(c*b-d*g+u*x)*E,t[8]=(n*R-o*S+h*w)*E,t[9]=(s*S-e*R-r*w)*E,t[10]=(y*M-p*g+f*m)*E,t[11]=(l*g-c*M-u*m)*E,t[12]=(o*v-n*C-a*w)*E,t[13]=(e*C-s*v+i*w)*E,t[14]=(p*x-y*z-_*m)*E,t[15]=(c*z-l*x+d*m)*E,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,c=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,c*o+s,c*a-i*n,0,h*a-i*o,c*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,c=n+n,l=o+o,d=r*h,u=r*c,y=r*l,p=n*c,_=n*l,f=o*l,m=a*h,x=a*c,g=a*l,z=s.x,M=s.y,b=s.z;return i[0]=(1-(p+f))*z,i[1]=(u+g)*z,i[2]=(y-x)*z,i[3]=0,i[4]=(u-g)*M,i[5]=(1-(d+f))*M,i[6]=(_+m)*M,i[7]=0,i[8]=(y+x)*b,i[9]=(_-m)*b,i[10]=(1-(d+p))*b,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return s.set(1,1,1),e.identity(),this;let n=v.set(i[0],i[1],i[2]).length();const o=v.set(i[4],i[5],i[6]).length(),a=v.set(i[8],i[9],i[10]).length();r<0&&(n=-n),S.copy(this);const h=1/n,c=1/o,l=1/a;return S.elements[0]*=h,S.elements[1]*=h,S.elements[2]*=h,S.elements[4]*=c,S.elements[5]*=c,S.elements[6]*=c,S.elements[8]*=l,S.elements[9]*=l,S.elements[10]*=l,e.setFromRotationMatrix(S),s.x=n,s.y=o,s.z=a,this}makePerspective(t,e,s,i,r,n,o=2e3,a=!1){const h=this.elements,c=2*r/(e-t),l=2*r/(s-i),d=(e+t)/(e-t),u=(s+i)/(s-i);let y,p;if(a)y=r/(n-r),p=n*r/(n-r);else if(o===f)y=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);y=-n/(n-r),p=-n*r/(n-r)}return h[0]=c,h[4]=0,h[8]=d,h[12]=0,h[1]=0,h[5]=l,h[9]=u,h[13]=0,h[2]=0,h[6]=0,h[10]=y,h[14]=p,h[3]=0,h[7]=0,h[11]=-1,h[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3,a=!1){const h=this.elements,c=2/(e-t),l=2/(s-i),d=-(e+t)/(e-t),u=-(s+i)/(s-i);let y,p;if(a)y=1/(n-r),p=n/(n-r);else if(o===f)y=-2/(n-r),p=-(n+r)/(n-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);y=-1/(n-r),p=-r/(n-r)}return h[0]=c,h[4]=0,h[8]=0,h[12]=d,h[1]=0,h[5]=l,h[9]=0,h[13]=u,h[2]=0,h[6]=0,h[10]=y,h[14]=p,h[3]=0,h[7]=0,h[11]=0,h[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const v=new z,S=new w,C=new z(0,0,0),R=new z(1,1,1),k=new z,I=new z,E=new z,A=new w,F=new g;class j{constructor(t=0,e=0,s=0,i=j.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],c=i[9],l=i[2],d=i[6],u=i[10];switch(e){case"XYZ":this._y=Math.asin(x(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,u),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(d,h),this._z=0);break;case"YXZ":this._x=Math.asin(-x(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(o,u),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin(x(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-l,u),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-x(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(d,u),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(x(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,u));break;case"XZY":this._z=Math.asin(-x(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(d,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-c,u),this._y=0);break;default:m("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return A.makeRotationFromQuaternion(t),this.setFromRotationMatrix(A,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return F.setFromEuler(this),this.setFromQuaternion(F,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}j.DEFAULT_ORDER="XYZ","undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"183"}})),"undefined"!=typeof window&&(window.__THREE__?m("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="183");const N=new class{constructor(){this._now=0,this._speed=1,this._paused=!1,this._listeners=new Set}get now(){return this._now}get speed(){return this._speed}set speed(t){this._speed=Math.max(0,t),this._speed>0&&(this._paused=!1)}get isPaused(){return this._paused}pause(){this._paused=!0}resume(){this._paused=!1}tick(t){if(this._paused||0===this._speed)return 0;const e=Math.min(t,200)*this._speed;return this._now+=e,this._notify(e),e}step(t){t<=0||(this._now+=t,this._notify(t))}onTick(t){return this._listeners.add(t),()=>this._listeners.delete(t)}_notify(t){this._listeners.forEach(e=>e(t))}};"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_SIM_CLOCK__=N);let P=null;const T=[],O=new Set;function q(t){if(!t)return;const e=t?.state?.id??t?.id??t?.refid;return void 0!==e?String(e):void 0}const Y={beginContext(t){P=t},endContext(){P=null},current:()=>P,log(t){const e={role:t.role,contract:t.contract,componentId:t.componentId??q(t.component),componentType:t.componentType??(s=t.component,s?.state?.type??s?.type),atSimMs:N.now,args:t.args,result:t.result,error:t.error};var s;P?P.pushTrace(e):(T.push(e),T.length>500&&T.shift(),O.forEach(t=>{try{t(e)}catch{}}))},standaloneEvents:()=>[...T],onStandalone:t=>(O.add(t),()=>{O.delete(t)}),clearStandalone(){T.length=0}};function W(t){if(!t)return;const e=t?.state?.id??t?.id;return"string"==typeof e?e:void 0}function L(t){const e={transferId:t.transferId,phase:t.phase,timeline:{...t.timeline}},s=t.sourceId??W(t.source),i=t.targetId??W(t.target),r=t.carrierId??W(t.carrier);return void 0!==s&&(e.sourceId=s),void 0!==i&&(e.targetId=i),void 0!==r&&(e.carrierId=r),void 0!==t.slotId&&(e.slotId=t.slotId),void 0!==t.rejectReason&&(e.rejectReason=t.rejectReason),e}let H=1;class X{constructor(t){this._phase="pending",this._slot=null,this._traceEvents=[],this.meta={},this.id="xfer-"+H++,this.source=t.source,this.target=t.target,this.carrier=t.carrier,this.options=t.options??{},this.physical=t.physical??null,this._timeline={initiatedAt:N.now}}pushTrace(t){this._traceEvents.push({atSimMs:t.atSimMs??N.now,...t})}get phase(){return this._phase}get timeline(){return this._timeline}async execute(){Y.beginContext(this),Y.log({role:"transfer",contract:"execute:begin",args:{transferId:this.id,source:W(this.source),target:W(this.target),carrier:W(this.carrier)}});try{return await this._executeImpl()}finally{Y.log({role:"transfer",contract:"execute:end",args:{transferId:this.id,phase:this._phase}}),Y.endContext()}}executeSync(){Y.beginContext(this),Y.log({role:"transfer",contract:"executeSync:begin",args:{transferId:this.id,source:W(this.source),target:W(this.target),carrier:W(this.carrier)}});try{this._phase="planning",this._timeline.planStartAt=N.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return Z.append(e),e}this._slot=t.slot}else if("function"==typeof this.target.canReceive){if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return Z.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}else this._slot=null;if(this._timeline.planEndAt=N.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=N.now;try{const t=this.physical();t instanceof Promise&&t.catch(()=>{})}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return Z.append(e),e}this._timeline.physicalEndAt=N.now}this._phase="handoff",this._timeline.handoffAt=N.now;const e=this.target.accept??this.target.receive;if("function"==typeof e)try{const t=e.call(this.target,this.carrier,this.options);t instanceof Promise&&t.catch(()=>{})}catch(t){this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();throw Z.append(e),t}else Y.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method"}});this._phase="committed",this._timeline.committedAt=N.now;const s=this._buildReceipt();return Z.append(s),s}finally{Y.log({role:"transfer",contract:"executeSync:end",args:{transferId:this.id,phase:this._phase}}),Y.endContext()}}async _executeImpl(){this._phase="planning",this._timeline.planStartAt=N.now;const t=this.target.canAccept?.(this.carrier);if(t){if(!t.ok){this._rejectReason=t.reason,this._phase="rolled-back";const e=this._buildReceipt();return Z.append(e),e}this._slot=t.slot}else if("function"==typeof this.target.canReceive){if(!this.target.canReceive(this.carrier)){this._rejectReason="cannot-receive",this._phase="rolled-back";const t=this._buildReceipt();return Z.append(t),t}this._slot="function"==typeof this.target.findSlot?this.target.findSlot(this.carrier):null}else this._slot=null;if(this._timeline.planEndAt=N.now,this.physical){this._phase="physical",this._timeline.physicalStartAt=N.now;try{await this.physical()}catch(t){this._rejectReason=`physical-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();return Z.append(e),e}this._timeline.physicalEndAt=N.now}this._phase="handoff",this._timeline.handoffAt=N.now;const e=this.target.accept??this.target.receive;if("function"==typeof e)try{await e.call(this.target,this.carrier,this.options)}catch(t){this._rejectReason=`handoff-failed: ${t.message??"unknown"}`,this._phase="rolled-back";const e=this._buildReceipt();throw Z.append(e),t}else Y.log({role:"target",contract:"handoff:noop",component:this.target,args:{reason:"no-accept-method (physical phase handled handoff)"}});this._phase="committed",this._timeline.committedAt=N.now;const s=this._buildReceipt();return Z.append(s),s}rollback(){if("committed"===this._phase)throw new Error("Cannot rollback a committed transfer");this._rejectReason=this._rejectReason??"manual-rollback",this._phase="rolled-back",Z.append(this._buildReceipt())}_buildReceipt(){return{transferId:this.id,source:this.source,target:this.target,carrier:this.carrier,sourceId:W(this.source),targetId:W(this.target),carrierId:W(this.carrier),phase:this._phase,timeline:{...this._timeline},slotId:this._slot?.id,rejectReason:this._rejectReason,traceEvents:[...this._traceEvents],meta:Object.keys(this.meta).length>0?{...this.meta}:void 0}}}const Z=new class{constructor(){this._entries=[],this._maxEntries=1e3,this._listeners=new Set}append(t){this._entries.push(t),this._entries.length>this._maxEntries&&this._entries.shift(),this._listeners.forEach(e=>e(t))}entries(){return[...this._entries]}forCarrier(t){const e=W(t);return this._entries.filter(s=>s.carrier===t||e&&s.carrierId===e)}forCarrierId(t){return this._entries.filter(e=>e.carrierId===t)}forSourceId(t){return this._entries.filter(e=>e.sourceId===t)}forTargetId(t){return this._entries.filter(e=>e.targetId===t)}forPhase(t){return this._entries.filter(e=>e.phase===t)}inTimeRange(t,e,s="init"){return"init"===s?this._entries.filter(s=>s.timeline.initiatedAt>=t&&s.timeline.initiatedAt<=e):this._entries.filter(s=>{const i=s.timeline.initiatedAt,r=s.timeline.committedAt??s.timeline.handoffAt??s.timeline.physicalEndAt??s.timeline.planEndAt??i;return i<=e&&r>=t})}groupByRejectReason(){const t=new Map;for(const e of this._entries)if(e.rejectReason){const s=t.get(e.rejectReason)??[];s.push(e),t.set(e.rejectReason,s)}return t}stats(){const t=this._entries.length,e={};let s=0,i=0;for(const t of this._entries)e[t.phase]=(e[t.phase]??0)+1,"committed"===t.phase&&void 0!==t.timeline.committedAt&&(s+=t.timeline.committedAt-t.timeline.initiatedAt,i++);const r=e["rolled-back"]??0;return{total:t,byPhase:e,committed:e.committed??0,rolledBack:r,rejectionRate:t>0?r/t:0,avgTransferDurationMs:i>0?s/i:0}}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}clear(){this._entries.length=0}setMaxEntries(t){this._maxEntries=Math.max(1,t)}toJSON(){return this._entries.map(L)}fromJSON(t){this._entries=t.map(t=>({transferId:t.transferId,source:void 0,target:void 0,carrier:void 0,sourceId:t.sourceId,targetId:t.targetId,carrierId:t.carrierId,phase:t.phase,timeline:{...t.timeline},slotId:t.slotId,rejectReason:t.rejectReason}))}replayTo(t){for(const e of this._entries)t(e)}};function V(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_TRANSFER_LOG__=Z);const D=new j;function Q(t,e){D.setFromQuaternion(new g(e.x,e.y,e.z,e.w),"XYZ"),t.rotationX=D.x,t.rotation=-D.y,t.rotationY=D.z}const $="_transferSlotId";function G(t){const e=class extends t{get slots(){return[]}get arrangementStrategy(){return p}canReceive(t){const e=null!==this.findSlot(t);return Y.log({role:"target",contract:"canReceive",component:this,args:{carrier:V(t)},result:e}),e}findSlot(t){const e=this.slots;if(!e.length)return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:V(t)},result:null}),null;for(const s of e){if(s.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!s.allowedTypes.includes(e))continue}const e=s.maxCount??this.arrangementStrategy.capacity(s),i=this._countOccupied(s.id);if(!(i>=e))return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:V(t)},result:{slotId:s.id,occupied:i,max:e}}),s}return Y.log({role:"target",contract:"findSlot",component:this,args:{carrier:V(t)},result:null}),null}async receive(t,e={}){Y.log({role:"target",contract:"receive:enter",component:this,args:{carrier:V(t),options:e}});const s=this.findSlot(t);if(!s){Y.log({role:"target",contract:"receive:reject",component:this,args:{carrier:V(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}const i=this._countOccupied(s.id),r=this.arrangementStrategy.positionAt(i,s,i,t);Y.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:i,slotId:s.id,occupantCount:i,carrier:V(t)},result:r}),t[$]=s.id;const n=t._realObject;let o,a;n?.object3d&&(n.object3d.updateWorldMatrix(!0,!1),o=new z,a=new g,n.object3d.getWorldPosition(o),n.object3d.getWorldQuaternion(a));const{animated:h=!1,duration:c,ease:l}=e;"function"==typeof this.handoverIn?this.handoverIn(t):this.reparent?.(t,{animated:h,duration:c,ease:l}),!h&&t._realObject&&(t._realObject.suppressTransform=!1);{const e={},n=this.placementFor?.(t,{slot:s,index:i,occupantCount:i})??null;if(Y.log({role:"target",contract:"placementFor",component:this,args:{carrier:V(t),slotId:s.id,index:i},result:n}),n){const i=t.state??{},r=this.state??{};e.left=n.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,e.top=n.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(n.position.y,i.depth,s);null!==o&&(e.zPos=o),n.rotation&&Q(e,n.rotation)}else{r&&(e.left=r.x,e.top=r.y);if(0!==(this._realObject?.receivingSurfaceY??0))e.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const t=this._realObject?.geometricOffsetY??0;e.zPos=s.localPosition.z+t}const i=this.acceptanceRotation?.(t,s);Y.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:V(t),slotId:s.id},result:i}),i&&Q(e,i)}const o=this.normalizePose?.(t,s);"function"==typeof this.normalizePose&&Y.log({role:"target",contract:"normalizePose",component:this,args:{carrier:V(t),slotId:s.id},result:o}),o&&Object.assign(e,o),Object.keys(e).length&&(t.setState?.(e),Y.log({role:"target",contract:"receive:setState",component:this,args:{carrier:V(t),keys:Object.keys(e)}}))}this.trigger("transfer-received",{type:"transfer-received",component:t,container:this,slotId:s.id,preReceiveWorldPos:o,preReceiveWorldQuat:a}),Y.log({role:"target",contract:"receive:done",component:this,args:{carrier:V(t),slotId:s.id}})}async dispatch(t,e,s={}){const i=new X({source:this,target:e,carrier:t,options:s,physical:async()=>{delete t[$]}}),r=await i.execute();"rolled-back"!==r.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:r.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}acceptanceRotation(t,e){}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const s=this.findSlot(t);if(!s){const s=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!s||t.allowedTypes.includes(s))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:s}})();return Y.log({role:"target",contract:"canAccept",component:this,args:{carrier:V(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}deliveryWorldRotation(t){const e=this.acceptanceRotation?.(t);if(!e)return;const s=this._realObject?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new g;s.getWorldQuaternion(i);const r=new g(e.x,e.y,e.z,e.w);return i.clone().multiply(r)}deliveryWorldPosition(t){const e=this._realObject,s=e?.object3d;if(!s)return;s.updateWorldMatrix(!0,!1);const i=new z;s.getWorldPosition(i);const r=this._receivingSurfaceLocalY();if(null!==r){const t=new z(0,r,0);return s.localToWorld(t),{x:i.x,y:t.y,z:i.z}}return{x:i.x,y:i.y,z:i.z}}attachPointFor(t){const e=t?.[$];if(!e)return null;const s=this.slots.find(t=>t.id===e);return s?{position:s.localPosition??{x:0,y:0,z:0},rotation:s.localRotation??{x:0,y:0,z:0},slotId:s.id}:null}placementFor(t,e={}){const s=t&&"object"==typeof t&&"state"in t?t:void 0,i=s?s.state??{}:t??{},r={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},n=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!n)return null;const o=e.index??this._countOccupied(n.id),a=e.occupantCount??o,h=this.arrangementStrategy.positionAt(o,n,a,s??{state:{...r}});if(!h)return null;const c=Number(this.state?.width)||0,l=Number(this.state?.height)||0,d=h.x+r.width/2-c/2,u=h.y+r.height/2-l/2,y=this._realObject,p=y?.placementMode??"floor",_="space"===p?0:"inverted"===p?-r.depth/2:r.depth/2,f=this._receivingSurfaceLocalY();let m;m=null!==f?f+_:n.localPosition&&Number.isFinite(n.localPosition.z)?n.localPosition.z+_:_-(y?.geometricOffsetY??0);const x=this.acceptanceRotation?.(s??r,n)??void 0;return x?{position:{x:d,y:m,z:u},rotation:x}:{position:{x:d,y:m,z:u}}}_zPosFromSeatY(t,e,s){const i=this._realObject,r=i?.receivingSurfaceY??0,n=!(!s.localPosition||!Number.isFinite(s.localPosition.z));if(0===r&&!n)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-r}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this.components;return e?e.filter(e=>e.parent===this&&e[$]===t).length:0}};return e.capabilities=[...t.capabilities??[],"ContainerCapacity","PlacementSurface"],e}function J(t){const e=class extends t{constructor(){super(...arguments),this._holdings=[]}addHolding(t){if(!t)return;if(-1!==this._holdings.indexOf(t))return;const e=t.parent;e&&"function"==typeof e.removeHolding&&e!==this&&e.removeHolding(t),this._holdings.push(t),t.parent=this}removeHolding(t){if(!t)return;const e=this._holdings.indexOf(t);-1!==e&&(this._holdings.splice(e,1),t.parent=null)}forEachHolding(t,e){this._holdings.forEach(t,e)}get holdings(){return this._holdings}dispose(){const t=this._holdings.slice();this._holdings.length=0;for(const e of t)try{e.dispose?.()}catch{}super.dispose()}handoverIn(t,e){if(!t)return;const s=t.parent;s&&("function"==typeof s.removeComponent&&-1!==s._components?.indexOf?.(t)&&s.removeComponent(t,!0),s!==this&&"function"==typeof s.removeHolding&&-1!==s._holdings?.indexOf?.(t)&&s.removeHolding(t)),t.realObject;const i=e?.toParent3D??this._realObject?.object3d,r=t._realObject?.object3d;i&&r&&(i.updateWorldMatrix(!0,!1),r.updateWorldMatrix(!0,!1),i.attach(r),t._realObject&&(t._realObject.suppressTransform=!0)),-1===this._holdings.indexOf(t)&&this._holdings.push(t),t.parent=this,t.added?.(this)}handoverOut(t){this.removeHolding(t)}_drawHoldings(t){const e=this.root?.transitionEffect;for(const t of this._holdings)e?.isReparenting?.(t)||t.draw?.(this.getContext?.(t))}_captureHoldings(t,e,s,i,r){for(let n=this._holdings.length-1;n>=0;n--){const o=this._holdings[n],a="static"===o.position?o.capture?.(t,e,r):o.capture?.(s,i,r);if(a)return a}return null}};return e.capabilities=[...t.capabilities??[],"Holdable"],e}function B(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.canReserveAtJoinPoint&&"function"==typeof e.reserveAtJoinPoint&&"function"==typeof e.commitReservation&&"function"==typeof e.releaseReservation&&e.carrierMap instanceof Map}function U(t){if(!t||"object"!=typeof t)return!1;const e=t;return"function"==typeof e.slotAt&&"function"==typeof e.findFreeSlot&&"function"==typeof e.findSlotsWithSKU&&"function"==typeof e.reservePut&&"function"==typeof e.reservePick&&"function"==typeof e.commitReservation&&"function"==typeof e.releaseReservation&&e.slots instanceof Map}function K(t){return`${t.level}.${t.bay}.${t.depth}`}function tt(t){const e=t.split(".");if(3!==e.length)return null;const[s,i,r]=e.map(t=>Number.parseInt(t,10));return Number.isFinite(s)&&Number.isFinite(i)&&Number.isFinite(r)?{level:s,bay:i,depth:r}:null}s({name:"ContainerCapacity",description:"Carrier slot topology + reservation / commit / release 의 default 구현을 Mixin 으로 제공. 컨테이너 (chute, induct, dock 등) 가 Transferable contract 의 standard impl 을 1줄 Mixin 으로 획득. subclass 는 *slots* 만 override.",methods:["get slots","reserveSlot","commitReservation","releaseReservation","isSlotAvailable","occupancyAt"],stateFields:["capacity","maxCapacity","slotArrangement"],sourceFile:"src/transfer/container-capacity.ts"}),s({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 ContainerCapacity 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/transfer/container-capacity.ts"}),s({name:"Holdable",description:"Component 가 자식 시스템 외에 *_보유 (holdings)_* 자식 array 를 추가로 가짐. `_components` (모델링 자식, 정적, board JSON) 와 직교한 별도 `_holdings` (런타임, DataSource bind 양방향). carrier 의 parent 는 holder 유지 — 2D 렌더 / 좌표 / 변환 / lifecycle 자연 상속. handoverIn / handoverOut 으로 carrier 이동.",methods:["addHolding","removeHolding","forEachHolding","handoverIn","handoverOut"],sourceFile:"src/components/mixins/holdable.ts"}),s({name:"CarrierLine",description:"carrier slot 들을 연속 경로 위에서 운영하는 컴포넌트의 추상 contract. cross-belt-line, loop-sorter, monorail, AGV-fleet 등 각각 다른 concrete class 들이 같은 capability 를 노출 — source (induct, station 등) 는 concrete class 모르고 capability 만 사용.",methods:["canReserveAtJoinPoint","reserveAtJoinPoint","commitReservation","releaseReservation"],models:["CarrierReservation","CarrierSlotState","JoinPoint"],stateFields:["speed","carrierPitch","direction","orientation"],sourceFile:"src/transfer/carrier-line-capability.ts"}),s({name:"StorageRack",description:"고정 grid 위의 addressable slot 들을 운영하는 컴포넌트 (rack, AS/RS, AutoStore-style bin-stack 등) 의 추상 contract. stacker crane, mini-load shuttle, 자율 forklift, AGV 등의 retrieval / putaway 작업이 같은 interface 로 동작.",methods:["slotAt","findFreeSlot","findSlotsWithSKU","reservePut","reservePick","commitReservation","releaseReservation"],models:["StorageSlotAddress","StorageSlotState","StorageReservation","SlotSearchCriteria"],stateFields:["levels","bays","depths","maxLoad"],sourceFile:"src/transfer/storage-rack-capability.ts"});let et=1;function st(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const it={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class rt{constructor(t=it){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+et++},s=(this._byResource.get(e.resource)??[]).filter(t=>st(t.timeWindow,e.timeWindow));if(0===s.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=s.map(t=>{const s=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:s}});if(i.every(t=>"b-yields"===t.decision)){const i=s.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:s.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>st(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const s=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);s<0?e.push(t):e.splice(s,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const s=e.findIndex(e=>e.id===t.id);if(s<0)return!1;e.splice(s,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const nt=new rt;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=nt);class ot{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,s=1/0;for(const i of this.nodes.values()){const r=at(i.position,t);r<s&&(s=r,e=i)}return e}}function at(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}function ht(t,e){return Math.sqrt(at(t,e))}function ct(t,e,s={}){const i=new ot,r=s.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const s=`${e.id}:start`,n=`${e.id}:end`;i.addNode({id:s,position:t[0],type:"lane-start"}),i.addNode({id:n,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:s,endNodeId:n});let o=0;for(let e=1;e<t.length;e++)o+=ht(t[e-1],t[e]);const a=o/(e.speedLimit??r)*1e3;i.addEdge({fromNode:s,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:n,toNode:s,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const s of t.lanes){const r=i.laneEndpoints.get(s);if(!r)continue;const n=i.nodes.get(r.startNodeId).position,o=i.nodes.get(r.endNodeId).position;let a=0,h=0,c=0;for(const e of t.lanes){if(e===s)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const r=i.nodes.get(t.startNodeId).position,l=i.nodes.get(t.endNodeId).position;a+=Math.min(at(n,r),at(n,l)),h+=Math.min(at(o,r),at(o,l)),c++}if(0===c)continue;const l=a<h?r.startNodeId:r.endNodeId;e.push({laneId:s,nodeId:l,pos:i.nodes.get(l).position})}for(let s=0;s<e.length;s++)for(let r=0;r<e.length;r++){if(s===r)continue;const n=e[s],o=e[r],a=ht(n.pos,o.pos);i.addEdge({fromNode:n.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function lt(t,e,s,i={}){const r=t.nodes.get(e),n=t.nodes.get(s);if(!r||!n)return null;const o=i.speed?.max??100,a=e=>{const s=t.nodes.get(e);var i,r;return(i=s.position,r=n.position,Math.sqrt(function(t,e){const s=t.x-e.x,i=t.y-e.y,r=t.z-e.z;return s*s+i*i+r*r}(i,r)))/o*1e3},h=new Map,c=new Set,l=new Set,d={nodeId:e,gScore:0,fScore:a(e)};h.set(e,d),c.add(e);const u=i.startSimMs??0,y=i.deadlineSimMs;for(;c.size>0;){let e=null,i=null;for(const t of c){const s=h.get(t);(!i||s.fScore<i.fScore||s.fScore===i.fScore&&t<e)&&(i=s,e=t)}if(!i||!e)return null;if(e===s){const t=[];let e=i,s=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,r=u+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:r,endSimMs:r+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),s+=i.distance,e=h.get(i.fromNodeId)}const r=i.gScore;return void 0!==y&&u+r>y?null:{segments:t,totalDurationMs:r,totalDistance:s}}c.delete(e),l.add(e);for(const s of t.edgesFrom(e)){if(l.has(s.toNode))continue;const e=i.gScore+s.durationMs,r=h.get(s.toNode);if(!r||e<r.gScore){const i=t.nodes.get(s.fromNode),r=t.nodes.get(s.toNode),n={nodeId:s.toNode,gScore:e,fScore:e+a(s.toNode),cameFromEdge:{fromNodeId:s.fromNode,resource:s.resource,distance:s.distance,durationMs:s.durationMs,fromPos:i.position,toPos:r.position}};h.set(s.toNode,n),c.add(s.toNode)}}}return null}function dt(t,e,s=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:s,metadata:i}))}const ut=.5;function yt(t){const e=t.bulge;return null!=e&&Number.isFinite(e)&&Math.abs(e)>=.5}function pt(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n||!Number.isFinite(s)||Math.abs(s)<1e-9)return null;const o=Math.abs(s),a=(n*n+4*o*o)/(8*o),h=s>0?1:-1,c=a-o,l=(t.x+e.x)/2-h*(r/n)*c,d=(t.y+e.y)/2-h*-(i/n)*c;return{cx:l,cy:d,radius:a,startAngle:Math.atan2(t.y-d,t.x-l),endAngle:Math.atan2(e.y-d,e.x-l),clockwise:s<0}}function _t(t,e,s=0,i=16){const r=e.x-t.x,n=e.y-t.y,o=Math.sqrt(r*r+n*n);if(0===o)return null;const a=n/o,h=-(r/o),c=Number.isFinite(s)?s:0,l=Math.abs(c)>=1e-6?c:i;return{x:(t.x+e.x)/2+a*l,y:(t.y+e.y)/2+h*l,perpX:a,perpY:h}}function ft(t,e,s){const i=e.x-t.x,r=e.y-t.y,n=Math.sqrt(i*i+r*r);if(0===n)return 0;const o=r/n,a=-(i/n),h=(t.x+e.x)/2,c=(t.y+e.y)/2;let l=(s.x-h)*o+(s.y-c)*a;if(Math.abs(l)<.5)return 0;return l>n&&(l=n),l<-n&&(l=-n),l}function mt(t,e){const s=t.radius,i=Number.isFinite(e)?e:0;return null!=s&&Number.isFinite(s)?Math.max(0,s):Math.max(0,i)}function xt(t,e,s,i,r=16){const n=t.x-e.x,o=t.y-e.y,a=Math.sqrt(n*n+o*o);if(0===a)return null;const h=s.x-e.x,c=s.y-e.y,l=Math.sqrt(h*h+c*c);if(0===l)return null;const d=n/a+h/l,u=o/a+c/l,y=Math.sqrt(d*d+u*u);if(y<1e-9)return null;const p=d/y,_=u/y,f=Math.max(i,r);return{x:e.x+p*f,y:e.y+_*f,bisectorX:p,bisectorY:_}}function gt(t,e,s,i){const r=t.x-e.x,n=t.y-e.y,o=Math.sqrt(r*r+n*n),a=s.x-e.x,h=s.y-e.y,c=Math.sqrt(a*a+h*h);if(0===o||0===c)return 0;const l=r/o+a/c,d=n/o+h/c,u=Math.sqrt(l*l+d*d);if(u<1e-9)return 0;const y=l/u,p=d/u,_=(i.x-e.x)*y+(i.y-e.y)*p,f=Math.min(o,c)/2;return Math.max(0,Math.min(_,f))}function zt(t){if(0===t.length)return 0;let e;for(const s of t){const t=s.z??0;if(!Number.isFinite(t))return null;if(void 0===e)e=t;else if(Math.abs(t-e)>1e-9)return null}return e??0}const Mt={closed:!0,round:0,divisions:24};class bt{constructor(t,e){this.points=t,this.closed=e;const s=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,r=t[e].y-t[e-1].y;s.push(s[e-1]+Math.sqrt(i*i+r*r))}this.cumulative=s,this.length=s[s.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let s=t;this.closed?s=(t%e+e)%e:s<0?s=0:s>e&&(s=e);const i=this.cumulative;let r=0,n=i.length-2;for(;r<n;){const t=r+n>>1;i[t+1]<=s?r=t+1:n=t}const o=i[r+1]-i[r],a=o>0?(s-i[r])/o:0,h=this.points[r],c=this.points[r+1],l=c.x-h.x,d=c.y-h.y;return{x:h.x+l*a,y:h.y+d*a,theta:0===l&&0===d?0:Math.atan2(d,l)}}}function wt(t,e={}){const s={...Mt,...e},i=t.length;if(0===i)return new bt([],s.closed);if(1===i)return new bt([{x:t[0].x,y:t[0].y}],s.closed);const r=[],n=(t,e)=>{if(r.length>0){const s=r[r.length-1];if(Math.abs(s.x-t)<1e-9&&Math.abs(s.y-e)<1e-9)return}r.push({x:t,y:e})},o=(s.closed,i);for(let e=0;e<o;e++){const r=0===e?s.closed?i-1:-1:e-1,o=e===i-1?s.closed?0:-1:e+1,a=r>=0?t[r]:null,h=t[e],c=o>=0?t[o]:null;if(a&&a.x===h.x&&a.y===h.y)continue;const l=a&&c?mt(h,s.round):0;let d,u,y,p;if(a){const t=Math.sqrt((a.x-h.x)**2+(a.y-h.y)**2),e=0!==t?Math.atan2(a.x-h.x,a.y-h.y):0,s=Math.min(l,t/2);d=Math.sin(e)*s+h.x,u=Math.cos(e)*s+h.y}else d=h.x,u=h.y;if(c){const t=Math.sqrt((c.x-h.x)**2+(c.y-h.y)**2),e=0!==t?Math.atan2(c.x-h.x,c.y-h.y):0,s=Math.min(l,t/2);y=Math.sin(e)*s+h.x,p=Math.cos(e)*s+h.y}else y=h.x,p=h.y;if(n(d,u),l>0&&a&&c)for(let t=1;t<=s.divisions;t++){const e=t/s.divisions,i=1-e;n(i*i*d+2*i*e*h.x+e*e*y,i*i*u+2*i*e*h.y+e*e*p)}else d===y&&u===p||n(y,p);if(c&&yt(h)){const t=mt(c,s.round),e=Math.sqrt((h.x-c.x)**2+(h.y-c.y)**2),i=0!==e?Math.atan2(h.x-c.x,h.y-c.y):0,r=Math.min(t,e/2),o=pt({x:y,y:p},{x:Math.sin(i)*r+c.x,y:Math.cos(i)*r+c.y},h.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=s.divisions;e++){const i=e/s.divisions,r=o.startAngle+t*i;n(o.cx+o.radius*Math.cos(r),o.cy+o.radius*Math.sin(r))}}}}if(s.closed&&r.length>0){const t=r[0],e=r[r.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&r.push({x:t.x,y:t.y})}return new bt(r,s.closed)}function vt(t,e){return wt(t,e).length}export{ut as BULGE_EPSILON,_ as CenteringSlotStrategy,G as ContainerCapacity,y as FixedSlotStrategy,J as Holdable,ot as NavGraph,bt as PolygonPathPolyline,rt as ReservationTable,$ as TRANSFER_SLOT_KEY,X as Transfer,K as addressKey,ct as buildNavGraph,ft as bulgeFromDrag,_t as bulgeHandlePosition,t as capability,u as chooseNearestPickupFrame,pt as computeArcParams,xt as cornerHandlePosition,gt as cornerRadiusFromDrag,mt as effectiveCornerRadius,d as filterByToolType,p as fixedSlotStrategy,wt as flattenPolygonPath,r as getAllCapabilityMeta,i as getCapabilityMeta,N as globalSimClock,yt as hasArc,B as isCarrierLine,U as isStorageRack,tt as parseAddressKey,lt as planPathAStar,dt as planToReservations,vt as polygonPathLength,o as quatFromYaw,L as receiptToJSON,c as rectangularFootprintFrames,s as registerCapabilityMeta,nt as reservationTable,it as standardYieldPolicy,l as topApproachFrame,Z as transferLog,Y as transferTracer,zt as uniformZ};